diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-13 18:07:10 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-13 18:07:10 +0000 |
commit | 8f82d7a873a738b9345cd79d03a8b47350fdbcc1 (patch) | |
tree | 566937e423b10ff1b506fb0b084c6d4fbedd47f9 /src/lockmanager | |
parent | fc73a3da5ded1ff8488d7e13ab4ae4a1d0680f96 (diff) | |
download | gnunet-8f82d7a873a738b9345cd79d03a8b47350fdbcc1.tar.gz gnunet-8f82d7a873a738b9345cd79d03a8b47350fdbcc1.zip |
change in API documentation and function for finding lockingRequest in hashmap
Diffstat (limited to 'src/lockmanager')
-rw-r--r-- | src/lockmanager/lockmanager_api.c | 85 |
1 files changed, 58 insertions, 27 deletions
diff --git a/src/lockmanager/lockmanager_api.c b/src/lockmanager/lockmanager_api.c index 1545717ee..a6757d538 100644 --- a/src/lockmanager/lockmanager_api.c +++ b/src/lockmanager/lockmanager_api.c | |||
@@ -124,6 +124,45 @@ get_key (const char *domain_name, | |||
124 | 124 | ||
125 | 125 | ||
126 | /** | 126 | /** |
127 | * Function to find a LockingRequest associated with the given domain and lock | ||
128 | * attributes in the map | ||
129 | * | ||
130 | * @param map the map where the LockingRequests are stored | ||
131 | * @param domain the locking domain name | ||
132 | * @param lock the lock number | ||
133 | * @return the found LockingRequest; NULL if a matching LockingRequest wasn't | ||
134 | * found | ||
135 | */ | ||
136 | static struct GNUNET_LOCKMANAGER_LockingRequest * | ||
137 | hashmap_find_lockingrequest (const struct GNUNET_CONTAINER_MultiHashMap *map, | ||
138 | const char *domain, | ||
139 | uint32_t lock) | ||
140 | { | ||
141 | struct GNUNET_LOCKMANAGER_LockingRequest *lr; | ||
142 | struct GNUNET_HashCode hash; | ||
143 | int match_found; | ||
144 | |||
145 | int match_iterator (void *cls, const GNUNET_HashCode *key, void *value) | ||
146 | { | ||
147 | lr = value; | ||
148 | if ( (lock == lr->lock) && (0 == strcmp (domain, lr->domain)) ) | ||
149 | { | ||
150 | match_found = GNUNET_YES; | ||
151 | return GNUNET_NO; | ||
152 | } | ||
153 | return GNUNET_YES; | ||
154 | } | ||
155 | get_key (domain, lock, &hash); | ||
156 | match_found = GNUNET_NO; | ||
157 | GNUNET_CONTAINER_multihashmap_get_multiple (map, | ||
158 | &hash, | ||
159 | &match_iterator, | ||
160 | NULL); | ||
161 | return (GNUNET_YES == match_found) ? lr : NULL; | ||
162 | } | ||
163 | |||
164 | |||
165 | /** | ||
127 | * Task for calling status change callback for a lock | 166 | * Task for calling status change callback for a lock |
128 | * | 167 | * |
129 | * @param cls the LockingRequest associated with this lock | 168 | * @param cls the LockingRequest associated with this lock |
@@ -159,9 +198,9 @@ handle_replies (void *cls, | |||
159 | { | 198 | { |
160 | struct GNUNET_LOCKMANAGER_Handle *handle = cls; | 199 | struct GNUNET_LOCKMANAGER_Handle *handle = cls; |
161 | const struct GNUNET_LOCKMANAGER_Message *m; | 200 | const struct GNUNET_LOCKMANAGER_Message *m; |
201 | struct GNUNET_LOCKMANAGER_LockingRequest *lr; | ||
162 | const char *domain; | 202 | const char *domain; |
163 | struct GNUNET_HashCode hash; | 203 | struct GNUNET_HashCode hash; |
164 | int match_found; | ||
165 | uint32_t lock; | 204 | uint32_t lock; |
166 | uint16_t msize; | 205 | uint16_t msize; |
167 | 206 | ||
@@ -196,32 +235,25 @@ handle_replies (void *cls, | |||
196 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 235 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
197 | "Received SUCCESS message for lock: %d, domain %s\n", | 236 | "Received SUCCESS message for lock: %d, domain %s\n", |
198 | lock, domain); | 237 | lock, domain); |
199 | int match_iterator(void *cls, const GNUNET_HashCode *key, void *value) | 238 | if (NULL == (lr = hashmap_find_lockingrequest (handle->hashmap, |
239 | domain, | ||
240 | lock))) | ||
200 | { | 241 | { |
201 | struct GNUNET_LOCKMANAGER_LockingRequest *r = value; | 242 | GNUNET_break (0); |
202 | 243 | return; | |
203 | if ( !((0 == strcmp (domain, r->domain)) | ||
204 | && (lock == r->lock))) | ||
205 | return GNUNET_YES; | ||
206 | match_found = GNUNET_YES; | ||
207 | if (GNUNET_LOCKMANAGER_SUCCESS != r->status) | ||
208 | { | ||
209 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
210 | "Changing status for lock: %d in domain: %s to SUCCESS\n", | ||
211 | r->lock, r->domain); | ||
212 | r->status = GNUNET_LOCKMANAGER_SUCCESS; | ||
213 | GNUNET_SCHEDULER_add_continuation (&call_status_cb_task, | ||
214 | r, | ||
215 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
216 | } | ||
217 | return GNUNET_NO; | ||
218 | } | 244 | } |
219 | match_found = GNUNET_NO; | 245 | if (GNUNET_LOCKMANAGER_SUCCESS == lr->status) |
220 | GNUNET_CONTAINER_multihashmap_get_multiple (handle->hashmap, | 246 | { |
221 | &hash, | 247 | GNUNET_break (0); |
222 | &match_iterator, | 248 | return; |
223 | NULL); | 249 | } |
224 | GNUNET_break (GNUNET_YES == match_found); | 250 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
251 | "Changing status for lock: %d in domain: %s to SUCCESS\n", | ||
252 | lr->lock, lr->domain); | ||
253 | lr->status = GNUNET_LOCKMANAGER_SUCCESS; | ||
254 | GNUNET_SCHEDULER_add_continuation (&call_status_cb_task, | ||
255 | lr, | ||
256 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
225 | } | 257 | } |
226 | 258 | ||
227 | 259 | ||
@@ -363,8 +395,7 @@ GNUNET_LOCKMANAGER_disconnect (struct GNUNET_LOCKMANAGER_Handle *handle) | |||
363 | * | 395 | * |
364 | * @param status_cb_cls the closure to the above callback | 396 | * @param status_cb_cls the closure to the above callback |
365 | * | 397 | * |
366 | * @return the locking request handle for this request. It will be invalidated | 398 | * @return the locking request handle for this request |
367 | * when status_cb is called. | ||
368 | */ | 399 | */ |
369 | struct GNUNET_LOCKMANAGER_LockingRequest * | 400 | struct GNUNET_LOCKMANAGER_LockingRequest * |
370 | GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, | 401 | GNUNET_LOCKMANAGER_acquire_lock (struct GNUNET_LOCKMANAGER_Handle *handle, |