-remove trailing whitespace
[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 3, 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.
97  */
98 typedef void
99 (*GNUNET_LOCKMANAGER_StatusCallback) (void *cls,
100                                       const char *domain_name,
101                                       uint32_t lock,
102                                       enum GNUNET_LOCKMANAGER_Status
103                                       status);
104
105
106 /**
107  * Opaque handle to locking request
108  */
109 struct GNUNET_LOCKMANAGER_LockingRequest;
110
111
112 /**
113  * Tries to acquire the given lock(even if the lock has been lost) until the
114  * request is called. If the lock is available the status_cb will be
115  * called. If the lock is busy then the request is queued and status_cb
116  * will be called when the lock has been made available and acquired by us.
117  *
118  * @param handle the handle to the lockmanager service
119  *
120  * @param domain_name name of the locking domain. Clients who want to share
121  *          locks must use the same name for the locking domain. Also the
122  *          domain_name should be selected with the prefix
123  *          "GNUNET_<PROGRAM_NAME>_" to avoid domain name collisions.
124  *
125  *
126  * @param lock which lock to lock
127  *
128  * @param status_cb the callback for signalling when the lock is acquired and
129  *          when it is lost
130  *
131  * @param status_cb_cls the closure to the above callback
132  *
133  * @return the locking request handle for this request
134  */
135 struct GNUNET_LOCKMANAGER_LockingRequest *
136 GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle,
137                                  const char *domain_name,
138                                  uint32_t lock,
139                                  GNUNET_LOCKMANAGER_StatusCallback
140                                  status_cb,
141                                  void *status_cb_cls);
142
143
144 /**
145  * Function to cancel the locking request generated by
146  * GNUNET_LOCKMANAGER_acquire_lock. If the lock is acquired by us then the lock
147  * is released. GNUNET_LOCKMANAGER_StatusCallback will not be called upon any
148  * status changes resulting due to this call.
149  *
150  * @param request the LockingRequest to cancel
151  */
152 void
153 GNUNET_LOCKMANAGER_cancel_request (struct GNUNET_LOCKMANAGER_LockingRequest
154                                    *request);
155
156
157 #if 0                           /* keep Emacsens' auto-indent happy */
158 {
159 #endif
160 #ifdef __cplusplus
161 }
162 #endif
163
164 /* ifndef GNUNET_LOCKMANAGER_SERVICE_H */
165 #endif
166 /* end of gnunet_lockmanager_service.h */