diff options
Diffstat (limited to 'src/pq/pq_event.c')
-rw-r--r-- | src/pq/pq_event.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/src/pq/pq_event.c b/src/pq/pq_event.c index 74b8b3653..e1134a5fa 100644 --- a/src/pq/pq_event.c +++ b/src/pq/pq_event.c | |||
@@ -29,8 +29,8 @@ | |||
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Handle for an active LISTENer to the database. | 31 | * Handle for an active LISTENer to the database. |
32 | */ | 32 | */ |
33 | struct GNUNET_PQ_EventHandler | 33 | struct GNUNET_DB_EventHandler |
34 | { | 34 | { |
35 | /** | 35 | /** |
36 | * Channel name. | 36 | * Channel name. |
@@ -40,7 +40,7 @@ struct GNUNET_PQ_EventHandler | |||
40 | /** | 40 | /** |
41 | * Function to call on events. | 41 | * Function to call on events. |
42 | */ | 42 | */ |
43 | GNUNET_PQ_EventCallback cb; | 43 | GNUNET_DB_EventCallback cb; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Closure for @e cb. | 46 | * Closure for @e cb. |
@@ -54,8 +54,6 @@ struct GNUNET_PQ_EventHandler | |||
54 | }; | 54 | }; |
55 | 55 | ||
56 | 56 | ||
57 | |||
58 | |||
59 | /** | 57 | /** |
60 | * Convert @a es to a short hash. | 58 | * Convert @a es to a short hash. |
61 | * | 59 | * |
@@ -63,7 +61,7 @@ struct GNUNET_PQ_EventHandler | |||
63 | * @param[out] sh short hash to set | 61 | * @param[out] sh short hash to set |
64 | */ | 62 | */ |
65 | static void | 63 | static void |
66 | es_to_sh (const struct GNUNET_PQ_EventHeaderP *es, | 64 | es_to_sh (const struct GNUNET_DB_EventHeaderP *es, |
67 | struct GNUNET_ShortHashCode *sh) | 65 | struct GNUNET_ShortHashCode *sh) |
68 | { | 66 | { |
69 | struct GNUNET_HashCode h_channel; | 67 | struct GNUNET_HashCode h_channel; |
@@ -111,7 +109,7 @@ sh_to_channel (struct GNUNET_ShortHashCode *sh, | |||
111 | * @return end position of the identifier | 109 | * @return end position of the identifier |
112 | */ | 110 | */ |
113 | static char * | 111 | static char * |
114 | es_to_channel (const struct GNUNET_PQ_EventHeaderP *es, | 112 | es_to_channel (const struct GNUNET_DB_EventHeaderP *es, |
115 | char identifier[64]) | 113 | char identifier[64]) |
116 | { | 114 | { |
117 | struct GNUNET_ShortHashCode sh; | 115 | struct GNUNET_ShortHashCode sh; |
@@ -141,12 +139,12 @@ struct NotifyContext | |||
141 | 139 | ||
142 | 140 | ||
143 | /** | 141 | /** |
144 | * Function called on every event handler that | 142 | * Function called on every event handler that |
145 | * needs to be triggered. | 143 | * needs to be triggered. |
146 | * | 144 | * |
147 | * @param cls a `struct NotifyContext` | 145 | * @param cls a `struct NotifyContext` |
148 | * @param sh channel name | 146 | * @param sh channel name |
149 | * @param value a `struct GNUNET_PQ_EventHandler` | 147 | * @param value a `struct GNUNET_DB_EventHandler` |
150 | * @return #GNUNET_OK continue to iterate | 148 | * @return #GNUNET_OK continue to iterate |
151 | */ | 149 | */ |
152 | static int | 150 | static int |
@@ -155,13 +153,13 @@ do_notify (void *cls, | |||
155 | void *value) | 153 | void *value) |
156 | { | 154 | { |
157 | struct NotifyContext *ctx = cls; | 155 | struct NotifyContext *ctx = cls; |
158 | struct GNUNET_PQ_EventHandler *eh = value; | 156 | struct GNUNET_DB_EventHandler *eh = value; |
159 | 157 | ||
160 | eh->cb (eh->cb_cls, | 158 | eh->cb (eh->cb_cls, |
161 | ctx->extra, | 159 | ctx->extra, |
162 | ctx->extra_size); | 160 | ctx->extra_size); |
163 | return GNUNET_OK; | 161 | return GNUNET_OK; |
164 | } | 162 | } |
165 | 163 | ||
166 | 164 | ||
167 | void | 165 | void |
@@ -265,7 +263,7 @@ do_scheduler_notify (void *cls) | |||
265 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO, | 263 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO, |
266 | db->rfd, | 264 | db->rfd, |
267 | &do_scheduler_notify, | 265 | &do_scheduler_notify, |
268 | db); | 266 | db); |
269 | } | 267 | } |
270 | 268 | ||
271 | 269 | ||
@@ -281,7 +279,7 @@ scheduler_fd_cb (void *cls, | |||
281 | int fd) | 279 | int fd) |
282 | { | 280 | { |
283 | struct GNUNET_PQ_Context *db = cls; | 281 | struct GNUNET_PQ_Context *db = cls; |
284 | 282 | ||
285 | if (NULL != db->event_task) | 283 | if (NULL != db->event_task) |
286 | { | 284 | { |
287 | GNUNET_SCHEDULER_cancel (db->event_task); | 285 | GNUNET_SCHEDULER_cancel (db->event_task); |
@@ -305,7 +303,7 @@ void | |||
305 | GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db) | 303 | GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db) |
306 | { | 304 | { |
307 | int fd; | 305 | int fd; |
308 | 306 | ||
309 | GNUNET_assert (! db->scheduler_on); | 307 | GNUNET_assert (! db->scheduler_on); |
310 | GNUNET_assert (NULL == db->sc); | 308 | GNUNET_assert (NULL == db->sc); |
311 | db->scheduler_on = true; | 309 | db->scheduler_on = true; |
@@ -335,7 +333,7 @@ GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db) | |||
335 | static void | 333 | static void |
336 | manage_subscribe (struct GNUNET_PQ_Context *db, | 334 | manage_subscribe (struct GNUNET_PQ_Context *db, |
337 | const char *cmd, | 335 | const char *cmd, |
338 | struct GNUNET_PQ_EventHandler *eh) | 336 | struct GNUNET_DB_EventHandler *eh) |
339 | { | 337 | { |
340 | char sql[16 + 64]; | 338 | char sql[16 + 64]; |
341 | char *end; | 339 | char *end; |
@@ -379,13 +377,13 @@ register_notify (void *cls, | |||
379 | void *value) | 377 | void *value) |
380 | { | 378 | { |
381 | struct GNUNET_PQ_Context *db = cls; | 379 | struct GNUNET_PQ_Context *db = cls; |
382 | struct GNUNET_PQ_EventHandler *eh = value; | 380 | struct GNUNET_DB_EventHandler *eh = value; |
383 | 381 | ||
384 | manage_subscribe (db, | 382 | manage_subscribe (db, |
385 | "LISTEN ", | 383 | "LISTEN ", |
386 | eh); | 384 | eh); |
387 | return GNUNET_OK; | 385 | return GNUNET_OK; |
388 | } | 386 | } |
389 | 387 | ||
390 | 388 | ||
391 | void | 389 | void |
@@ -401,16 +399,16 @@ GNUNET_PQ_event_reconnect_ (struct GNUNET_PQ_Context *db) | |||
401 | } | 399 | } |
402 | 400 | ||
403 | 401 | ||
404 | struct GNUNET_PQ_EventHandler * | 402 | struct GNUNET_DB_EventHandler * |
405 | GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | 403 | GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, |
406 | const struct GNUNET_PQ_EventHeaderP *es, | 404 | const struct GNUNET_DB_EventHeaderP *es, |
407 | GNUNET_PQ_EventCallback cb, | 405 | GNUNET_DB_EventCallback cb, |
408 | void *cb_cls) | 406 | void *cb_cls) |
409 | { | 407 | { |
410 | struct GNUNET_PQ_EventHandler *eh; | 408 | struct GNUNET_DB_EventHandler *eh; |
411 | bool was_zero; | 409 | bool was_zero; |
412 | 410 | ||
413 | eh = GNUNET_new (struct GNUNET_PQ_EventHandler); | 411 | eh = GNUNET_new (struct GNUNET_DB_EventHandler); |
414 | eh->db = db; | 412 | eh->db = db; |
415 | es_to_sh (es, | 413 | es_to_sh (es, |
416 | &eh->sh); | 414 | &eh->sh); |
@@ -421,14 +419,14 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | |||
421 | was_zero = (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map)); | 419 | was_zero = (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map)); |
422 | GNUNET_assert (GNUNET_OK == | 420 | GNUNET_assert (GNUNET_OK == |
423 | GNUNET_CONTAINER_multishortmap_put (db->channel_map, | 421 | GNUNET_CONTAINER_multishortmap_put (db->channel_map, |
424 | &eh->sh, | 422 | &eh->sh, |
425 | eh, | 423 | eh, |
426 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 424 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
427 | if ( (NULL != db->sc) && | 425 | if ( (NULL != db->sc) && |
428 | was_zero) | 426 | was_zero) |
429 | { | 427 | { |
430 | int fd = PQsocket (db->conn); | 428 | int fd = PQsocket (db->conn); |
431 | 429 | ||
432 | if (-1 != fd) | 430 | if (-1 != fd) |
433 | db->sc (db->sc_cls, | 431 | db->sc (db->sc_cls, |
434 | fd); | 432 | fd); |
@@ -443,7 +441,7 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db, | |||
443 | 441 | ||
444 | 442 | ||
445 | void | 443 | void |
446 | GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh) | 444 | GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh) |
447 | { | 445 | { |
448 | struct GNUNET_PQ_Context *db = eh->db; | 446 | struct GNUNET_PQ_Context *db = eh->db; |
449 | 447 | ||
@@ -451,9 +449,9 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh) | |||
451 | pthread_mutex_lock (&db->notify_lock)); | 449 | pthread_mutex_lock (&db->notify_lock)); |
452 | GNUNET_assert (GNUNET_OK == | 450 | GNUNET_assert (GNUNET_OK == |
453 | GNUNET_CONTAINER_multishortmap_remove (db->channel_map, | 451 | GNUNET_CONTAINER_multishortmap_remove (db->channel_map, |
454 | &eh->sh, | 452 | &eh->sh, |
455 | eh)); | 453 | eh)); |
456 | 454 | ||
457 | manage_subscribe (db, | 455 | manage_subscribe (db, |
458 | "UNLISTEN ", | 456 | "UNLISTEN ", |
459 | eh); | 457 | eh); |
@@ -471,7 +469,7 @@ GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh) | |||
471 | 469 | ||
472 | void | 470 | void |
473 | GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, | 471 | GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, |
474 | const struct GNUNET_PQ_EventHeaderP *es, | 472 | const struct GNUNET_DB_EventHeaderP *es, |
475 | const void *extra, | 473 | const void *extra, |
476 | size_t extra_size) | 474 | size_t extra_size) |
477 | { | 475 | { |
@@ -512,5 +510,5 @@ GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db, | |||
512 | PQclear (result); | 510 | PQclear (result); |
513 | } | 511 | } |
514 | 512 | ||
515 | /* end of pq_event.c */ | ||
516 | 513 | ||
514 | /* end of pq_event.c */ | ||