-modified lockmanager and added protocol messages
[oweals/gnunet.git] / src / include / gnunet_lockmanager_service.h
1 /*
2      This file is part of GNUnet.
3      (C) 2012 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 2, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_lockmanager_service.h
23  * @brief API for the lockmanger service
24  * @author Sree Harsha Totakura
25  */
26
27 #ifndef GNUNET_LOCKMANAGER_SERVICE_H
28 #define GNUNET_LOCKMANAGER_SERVICE_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 /**
39  * Opaque handle for the lockmanager service
40  */
41 struct GNUNET_LOCKMANAGER_Handle;
42
43
44 /**
45  * Connect to the lockmanager service
46  *
47  * @param cfg the configuration to use
48  *
49  * @return upon success the handle to the service; NULL upon error
50  */
51 struct GNUNET_LOCKMANAGER_Handle *
52 GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
53
54
55 /**
56  * Disconnect from the lockmanager service
57  *
58  * @param handle the handle to the lockmanager service
59  */
60 void
61 GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle);
62
63
64 /**
65  * Enumeration for status
66  */
67 enum GNUNET_LOCKMANAGER_Status
68   {
69     /**
70      * Signifies a successful operation
71      */
72     GNUNET_LOCKMANAGER_SUCCESS = 1,
73
74     /**
75      * Used to signal that a lock is no longer valid. It must then be released
76      */
77     GNUNET_LOCKMANAGER_RELEASE
78   };
79
80
81 /**
82  * This callback will be called when a lock has been successfully acquired or
83  * when an acquired lock has been lost (happens when the lockmanager service
84  * crashes/restarts).
85  *
86  * @param cls the closure from GNUNET_LOCKMANAGER_lock call
87  *
88  * @param domain_name the locking domain of the lock 
89  *
90  * @param lock the lock for which this status is relevant
91  *
92  * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully
93  *          acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is lost
94  */
95 typedef void 
96 (*GNUNET_LOCKMANAGER_StatusCallback) (void *cls,
97                                       const char *domain_name,
98                                       uint32_t lock,
99                                       enum GNUNET_LOCKMANAGER_Status 
100                                       status);
101
102
103 /**
104  * Opaque handle to locking request
105  */
106 struct GNUNET_LOCKMANAGER_LockingRequest;
107
108
109 /**
110  * Tries to acquire the given lock(even if the lock has been lost) until the
111  * request is called. If the lock is available the status_cb will be
112  * called. If the lock is busy then the request is queued and status_cb
113  * will be called when the lock has been made available and acquired by us.
114  *
115  * @param handle the handle to the lockmanager service
116  *
117  * @param domain_name name of the locking domain. Clients who want to share
118  *          locks must use the same name for the locking domain. Also the
119  *          domain_name should be selected with the prefix
120  *          "GNUNET_<PROGRAM_NAME>_" to avoid domain name collisions.
121  *
122  *
123  * @param lock which lock to lock
124  *
125  * @param status_cb the callback for signalling when the lock is acquired and
126  *          when it is lost
127  *
128  * @param status_cb_cls the closure to the above callback
129  *
130  * @return the locking request handle for this request. It will be invalidated
131  *           when status_cb is called.
132  */
133 struct GNUNET_LOCKMANAGER_LockingRequest *
134 GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle,
135                                  const char *domain_name,
136                                  uint32_t lock,
137                                  GNUNET_LOCKMANAGER_StatusCallback
138                                  status_cb,
139                                  void *status_cb_cls);
140
141
142 /**
143  * Function to cancel the locking request generated by
144  * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired us then the lock is
145  * released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any
146  * status changes resulting due to this call.
147  *
148  * @param request the LockingRequest to cancel
149  */
150 void
151 GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest
152                                    *request);
153
154
155 #if 0                           /* keep Emacsens' auto-indent happy */
156 {
157 #endif
158 #ifdef __cplusplus
159 }
160 #endif
161
162 /* ifndef GNUNET_LOCKMANAGER_SERVICE_H */
163 #endif
164 /* end of gnunet_lockmanager_service.h */