-restrictions on using GNUNET_LOCKMANAGER_cancel_request()
[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 #include "gnunet_configuration_lib.h"
39
40 /**
41  * Opaque handle for the lockmanager service
42  */
43 struct GNUNET_LOCKMANAGER_Handle;
44
45
46 /**
47  * Connect to the lockmanager service
48  *
49  * @param cfg the configuration to use
50  *
51  * @return upon success the handle to the service; NULL upon error
52  */
53 struct GNUNET_LOCKMANAGER_Handle *
54 GNUNET_LOCKMANAGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
55
56
57 /**
58  * Disconnect from the lockmanager service
59  *
60  * @param handle the handle to the lockmanager service
61  */
62 void
63 GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle);
64
65
66 /**
67  * Enumeration for status
68  */
69 enum GNUNET_LOCKMANAGER_Status
70   {
71     /**
72      * Signifies a successful operation
73      */
74     GNUNET_LOCKMANAGER_SUCCESS = 1,
75
76     /**
77      * Used to signal that a lock is no longer valid. It must then be released
78      */
79     GNUNET_LOCKMANAGER_RELEASE
80   };
81
82
83 /**
84  * This callback will be called when a lock has been successfully acquired or
85  * when an acquired lock has been lost (happens when the lockmanager service
86  * crashes/restarts).
87  *
88  * @param cls the closure from GNUNET_LOCKMANAGER_lock call
89  *
90  * @param domain_name the locking domain of the lock 
91  *
92  * @param lock the lock for which this status is relevant
93  *
94  * @param status GNUNET_LOCKMANAGER_SUCCESS if the lock has been successfully
95  *          acquired; GNUNET_LOCKMANAGER_RELEASE when the acquired lock is
96  *          lost. GNUNET_LOCKMANAGER_cancel_request must NOT be called in this
97  *          callback when status == GNUNET_LOCKMANAGER_RELEASE
98  */
99 typedef void 
100 (*GNUNET_LOCKMANAGER_StatusCallback) (void *cls,
101                                       const char *domain_name,
102                                       uint32_t lock,
103                                       enum GNUNET_LOCKMANAGER_Status 
104                                       status);
105
106
107 /**
108  * Opaque handle to locking request
109  */
110 struct GNUNET_LOCKMANAGER_LockingRequest;
111
112
113 /**
114  * Tries to acquire the given lock(even if the lock has been lost) until the
115  * request is called. If the lock is available the status_cb will be
116  * called. If the lock is busy then the request is queued and status_cb
117  * will be called when the lock has been made available and acquired by us.
118  *
119  * @param handle the handle to the lockmanager service
120  *
121  * @param domain_name name of the locking domain. Clients who want to share
122  *          locks must use the same name for the locking domain. Also the
123  *          domain_name should be selected with the prefix
124  *          "GNUNET_<PROGRAM_NAME>_" to avoid domain name collisions.
125  *
126  *
127  * @param lock which lock to lock
128  *
129  * @param status_cb the callback for signalling when the lock is acquired and
130  *          when it is lost
131  *
132  * @param status_cb_cls the closure to the above callback
133  *
134  * @return the locking request handle for this request
135  */
136 struct GNUNET_LOCKMANAGER_LockingRequest *
137 GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle,
138                                  const char *domain_name,
139                                  uint32_t lock,
140                                  GNUNET_LOCKMANAGER_StatusCallback
141                                  status_cb,
142                                  void *status_cb_cls);
143
144
145 /**
146  * Function to cancel the locking request generated by
147  * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired by us then the lock
148  * is released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any
149  * status changes resulting due to this call.
150  *
151  * @param request the LockingRequest to cancel
152  */
153 void
154 GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest
155                                    *request);
156
157
158 #if 0                           /* keep Emacsens' auto-indent happy */
159 {
160 #endif
161 #ifdef __cplusplus
162 }
163 #endif
164
165 /* ifndef GNUNET_LOCKMANAGER_SERVICE_H */
166 #endif
167 /* end of gnunet_lockmanager_service.h */