[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] branch master updated: -move DB-agnostic types to GNUNET_DB
From: |
gnunet |
Subject: |
[gnunet] branch master updated: -move DB-agnostic types to GNUNET_DB |
Date: |
Sun, 01 Aug 2021 13:24:16 +0200 |
This is an automated email from the git hooks/post-receive script.
grothoff pushed a commit to branch master
in repository gnunet.
The following commit(s) were added to refs/heads/master by this push:
new 06f45b04a -move DB-agnostic types to GNUNET_DB
06f45b04a is described below
commit 06f45b04aaa8a9832599035cafee142f09700b9b
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Aug 1 13:20:49 2021 +0200
-move DB-agnostic types to GNUNET_DB
---
src/include/gnunet_db_lib.h | 43 +++++++++++++++++++++++++++++
src/include/gnunet_pq_lib.h | 67 +++++++--------------------------------------
src/pq/pq_event.c | 64 +++++++++++++++++++++----------------------
3 files changed, 84 insertions(+), 90 deletions(-)
diff --git a/src/include/gnunet_db_lib.h b/src/include/gnunet_db_lib.h
index 85ad13e31..63c45112d 100644
--- a/src/include/gnunet_db_lib.h
+++ b/src/include/gnunet_db_lib.h
@@ -61,4 +61,47 @@ enum GNUNET_DB_QueryStatus
that returned more than one result.
*/
};
+
+/**
+ * Handle for an active LISTENer to a database.
+ */
+struct GNUNET_DB_EventHandler;
+
+/**
+ * Function called on events received from Postgres.
+ *
+ * @param cls closure
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+typedef void
+(*GNUNET_DB_EventCallback)(void *cls,
+ const void *extra,
+ size_t extra_size);
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+
+/**
+ * Header of a structure that describes an
+ * event channel we may subscribe to or notify on.
+ */
+struct GNUNET_DB_EventHeaderP
+{
+ /**
+ * The length of the struct (in bytes, including the length field itself),
+ * in big-endian format.
+ */
+ uint16_t size GNUNET_PACKED;
+
+ /**
+ * The type of the message (GNUNET_DB_EVENT_TYPE_XXXX), in big-endian format.
+ */
+ uint16_t type GNUNET_PACKED;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
#endif
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 1f2915165..ecc2b9719 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -853,7 +853,7 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db);
/**
- * Function called whenever the socket needed for
+ * Function called whenever the socket needed for
* notifications from postgres changes.
*
* @param cls closure
@@ -868,7 +868,7 @@ typedef void
* Obtain the file descriptor to poll on for notifications.
* Useful if the GNUnet scheduler is NOT to be used for
* such notifications.
- *
+ *
* @param db database handle
* @param sc function to call with the socket
* @param sc_cls closure for @a sc
@@ -910,56 +910,9 @@ void
GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db);
-/**
- * Handle for an active LISTENer to the database.
- */
-struct GNUNET_PQ_EventHandler;
-
-/**
- * Function called on events received from Postgres.
- *
- * @param cls closure
- * @param extra additional event data provided
- * @param extra_size number of bytes in @a extra
- */
-typedef void
-(*GNUNET_PQ_EventCallback)(void *cls,
- const void *extra,
- size_t extra_size);
-
-GNUNET_NETWORK_STRUCT_BEGIN
-
-
-/**
- * Header of a structure that describes an
- * event channel we may subscribe to or notify on.
- */
-struct GNUNET_PQ_EventHeaderP
-{
- /**
- * The length of the struct (in bytes, including the length field itself),
- * in big-endian format.
- */
- uint16_t size GNUNET_PACKED;
-
- /**
- * The type of the message (GNUNET_PQ_EVENT_TYPE_XXXX), in big-endian format.
- */
- uint16_t type GNUNET_PACKED;
-
-};
-
-GNUNET_NETWORK_STRUCT_END
-
-
-/**
- * Handle for an active LISTENer to the database.
- */
-struct GNUNET_PQ_EventHandler;
-
/**
* Register callback to be invoked on events of type @a es.
- *
+ *
* Unlike many other calls, this function is thread-safe
* and may be called from threads that are different
* from the one that setup @a db. However, the @a cb
@@ -973,16 +926,16 @@ struct GNUNET_PQ_EventHandler;
* @param cb_cls closure for @a cb
* @return handle useful to cancel the listener
*/
-struct GNUNET_PQ_EventHandler *
+struct GNUNET_DB_EventHandler *
GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db,
- const struct GNUNET_PQ_EventHeaderP *es,
- GNUNET_PQ_EventCallback cb,
+ const struct GNUNET_DB_EventHeaderP *es,
+ GNUNET_DB_EventCallback cb,
void *cb_cls);
/**
* Stop notifications.
- *
+ *
* Unlike many other calls, this function is thread-safe
* and may be called from threads that are different
* from the one that setup @a db. However, the @a cb
@@ -992,12 +945,12 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db,
* @param eh handle to unregister.
*/
void
-GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh);
+GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh);
/**
* Notify all that listen on @a es of an event.
- *
+ *
* Unlike many other calls, this function is thread-safe
* and may be called from threads that are different
* from the one that setup @a db. However, the @a cb
@@ -1011,7 +964,7 @@ GNUNET_PQ_event_listen_cancel (struct
GNUNET_PQ_EventHandler *eh);
*/
void
GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
- const struct GNUNET_PQ_EventHeaderP *es,
+ const struct GNUNET_DB_EventHeaderP *es,
const void *extra,
size_t extra_size);
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 @@
/**
* Handle for an active LISTENer to the database.
- */
-struct GNUNET_PQ_EventHandler
+ */
+struct GNUNET_DB_EventHandler
{
/**
* Channel name.
@@ -40,7 +40,7 @@ struct GNUNET_PQ_EventHandler
/**
* Function to call on events.
*/
- GNUNET_PQ_EventCallback cb;
+ GNUNET_DB_EventCallback cb;
/**
* Closure for @e cb.
@@ -54,8 +54,6 @@ struct GNUNET_PQ_EventHandler
};
-
-
/**
* Convert @a es to a short hash.
*
@@ -63,7 +61,7 @@ struct GNUNET_PQ_EventHandler
* @param[out] sh short hash to set
*/
static void
-es_to_sh (const struct GNUNET_PQ_EventHeaderP *es,
+es_to_sh (const struct GNUNET_DB_EventHeaderP *es,
struct GNUNET_ShortHashCode *sh)
{
struct GNUNET_HashCode h_channel;
@@ -111,7 +109,7 @@ sh_to_channel (struct GNUNET_ShortHashCode *sh,
* @return end position of the identifier
*/
static char *
-es_to_channel (const struct GNUNET_PQ_EventHeaderP *es,
+es_to_channel (const struct GNUNET_DB_EventHeaderP *es,
char identifier[64])
{
struct GNUNET_ShortHashCode sh;
@@ -141,12 +139,12 @@ struct NotifyContext
/**
- * Function called on every event handler that
+ * Function called on every event handler that
* needs to be triggered.
*
* @param cls a `struct NotifyContext`
* @param sh channel name
- * @param value a `struct GNUNET_PQ_EventHandler`
+ * @param value a `struct GNUNET_DB_EventHandler`
* @return #GNUNET_OK continue to iterate
*/
static int
@@ -155,13 +153,13 @@ do_notify (void *cls,
void *value)
{
struct NotifyContext *ctx = cls;
- struct GNUNET_PQ_EventHandler *eh = value;
+ struct GNUNET_DB_EventHandler *eh = value;
eh->cb (eh->cb_cls,
ctx->extra,
ctx->extra_size);
return GNUNET_OK;
-}
+}
void
@@ -265,7 +263,7 @@ do_scheduler_notify (void *cls)
= GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_ZERO,
db->rfd,
&do_scheduler_notify,
- db);
+ db);
}
@@ -281,7 +279,7 @@ scheduler_fd_cb (void *cls,
int fd)
{
struct GNUNET_PQ_Context *db = cls;
-
+
if (NULL != db->event_task)
{
GNUNET_SCHEDULER_cancel (db->event_task);
@@ -305,7 +303,7 @@ void
GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db)
{
int fd;
-
+
GNUNET_assert (! db->scheduler_on);
GNUNET_assert (NULL == db->sc);
db->scheduler_on = true;
@@ -335,7 +333,7 @@ GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context
*db)
static void
manage_subscribe (struct GNUNET_PQ_Context *db,
const char *cmd,
- struct GNUNET_PQ_EventHandler *eh)
+ struct GNUNET_DB_EventHandler *eh)
{
char sql[16 + 64];
char *end;
@@ -379,13 +377,13 @@ register_notify (void *cls,
void *value)
{
struct GNUNET_PQ_Context *db = cls;
- struct GNUNET_PQ_EventHandler *eh = value;
-
+ struct GNUNET_DB_EventHandler *eh = value;
+
manage_subscribe (db,
"LISTEN ",
eh);
return GNUNET_OK;
-}
+}
void
@@ -401,16 +399,16 @@ GNUNET_PQ_event_reconnect_ (struct GNUNET_PQ_Context *db)
}
-struct GNUNET_PQ_EventHandler *
+struct GNUNET_DB_EventHandler *
GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db,
- const struct GNUNET_PQ_EventHeaderP *es,
- GNUNET_PQ_EventCallback cb,
+ const struct GNUNET_DB_EventHeaderP *es,
+ GNUNET_DB_EventCallback cb,
void *cb_cls)
{
- struct GNUNET_PQ_EventHandler *eh;
+ struct GNUNET_DB_EventHandler *eh;
bool was_zero;
- eh = GNUNET_new (struct GNUNET_PQ_EventHandler);
+ eh = GNUNET_new (struct GNUNET_DB_EventHandler);
eh->db = db;
es_to_sh (es,
&eh->sh);
@@ -421,14 +419,14 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db,
was_zero = (0 == GNUNET_CONTAINER_multishortmap_size (db->channel_map));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multishortmap_put (db->channel_map,
- &eh->sh,
- eh,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ &eh->sh,
+ eh,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
if ( (NULL != db->sc) &&
was_zero)
{
int fd = PQsocket (db->conn);
-
+
if (-1 != fd)
db->sc (db->sc_cls,
fd);
@@ -443,7 +441,7 @@ GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db,
void
-GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh)
+GNUNET_PQ_event_listen_cancel (struct GNUNET_DB_EventHandler *eh)
{
struct GNUNET_PQ_Context *db = eh->db;
@@ -451,9 +449,9 @@ GNUNET_PQ_event_listen_cancel (struct
GNUNET_PQ_EventHandler *eh)
pthread_mutex_lock (&db->notify_lock));
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multishortmap_remove (db->channel_map,
- &eh->sh,
- eh));
-
+ &eh->sh,
+ eh));
+
manage_subscribe (db,
"UNLISTEN ",
eh);
@@ -471,7 +469,7 @@ GNUNET_PQ_event_listen_cancel (struct
GNUNET_PQ_EventHandler *eh)
void
GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
- const struct GNUNET_PQ_EventHeaderP *es,
+ const struct GNUNET_DB_EventHeaderP *es,
const void *extra,
size_t extra_size)
{
@@ -512,5 +510,5 @@ GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
PQclear (result);
}
-/* end of pq_event.c */
+/* end of pq_event.c */
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnunet] branch master updated: -move DB-agnostic types to GNUNET_DB,
gnunet <=