*
* @{
*/
-#ifndef GNUNET_MQ_H
-#define GNUNET_MQ_H
+#ifndef GNUNET_MQ_LIB_H
+#define GNUNET_MQ_LIB_H
/**
* @param mh message to nest
* @return a newly allocated 'struct GNUNET_MQ_Envelope *'
*/
-#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) GNUNET_MQ_msg_nested_mh_((((void)(mvar)->header), (struct GNUNET_MessageHeader**) &(mvar)), sizeof (*(mvar)), (type), mh)
+#define GNUNET_MQ_msg_nested_mh(mvar, type, mh) \
+ ({struct GNUNET_MQ_Envelope *_ev;\
+ _ev = GNUNET_MQ_msg_nested_mh_((struct GNUNET_MessageHeader**) &(mvar),\
+ sizeof (*(mvar)),\
+ (type),\
+ (mh));\
+ (void)(mvar)->header; /* type check */\
+ _ev;})
/**
void *impl_state);
-/**
- * Callback used for notifications
- *
- * @param cls closure
- */
-typedef void
-(*GNUNET_MQ_NotifyCallback) (void *cls);
-
-
/**
* Generic error handler, called with the appropriate
* error code and the same closure specified at the creation of
enum GNUNET_MQ_Error error);
+/**
+ * Insert @a env into the envelope DLL starting at @a env_head
+ * Note that @a env must not be in any MQ while this function
+ * is used with DLLs defined outside of the MQ module. This
+ * is just in case some application needs to also manage a
+ * FIFO of envelopes independent of MQ itself and wants to
+ * re-use the pointers internal to @a env. Use with caution.
+ *
+ * @param[in|out] env_head of envelope DLL
+ * @param[in|out] env_tail tail of envelope DLL
+ * @param[in|out] env element to insert at the tail
+ */
+void
+GNUNET_MQ_dll_insert_tail (struct GNUNET_MQ_Envelope **env_head,
+ struct GNUNET_MQ_Envelope **env_tail,
+ struct GNUNET_MQ_Envelope *env);
+
+
+/**
+ * Remove @a env from the envelope DLL starting at @a env_head.
+ * Note that @a env must not be in any MQ while this function
+ * is used with DLLs defined outside of the MQ module. This
+ * is just in case some application needs to also manage a
+ * FIFO of envelopes independent of MQ itself and wants to
+ * re-use the pointers internal to @a env. Use with caution.
+ *
+ * @param[in|out] env_head of envelope DLL
+ * @param[in|out] env_tail tail of envelope DLL
+ * @param[in|out] env element to remove from the DLL
+ */
+void
+GNUNET_MQ_dll_remove (struct GNUNET_MQ_Envelope **env_head,
+ struct GNUNET_MQ_Envelope **env_tail,
+ struct GNUNET_MQ_Envelope *env);
+
+
+/**
+ * Copy an array of handlers.
+ *
+ * Useful if the array has been delared in local memory and needs to be
+ * persisted for future use.
+ *
+ * @param handlers Array of handlers to be copied.
+ * @return A newly allocated array of handlers.
+ * Needs to be freed with #GNUNET_free.
+ */
+struct GNUNET_MQ_MessageHandler *
+GNUNET_MQ_copy_handlers (const struct GNUNET_MQ_MessageHandler *handlers);
+
+
+/**
+ * Count the handlers in a handler array.
+ *
+ * @param handlers Array of handlers to be counted.
+ * @return The number of handlers in the array.
+ */
+unsigned int
+GNUNET_MQ_count_handlers (const struct GNUNET_MQ_MessageHandler *handlers);
+
+
/**
* Message handler for a specific message type.
*/
* @param ctx context for the callbacks
*/
#define GNUNET_MQ_hd_var_size(name,code,str,ctx) \
- ({ \
+ __extension__ ({ \
int (*_mv)(void *cls, const str *msg) = &check_##name; \
void (*_cb)(void *cls, const str *msg) = &handle_##name; \
((struct GNUNET_MQ_MessageHandler) \
*/
struct GNUNET_MQ_Envelope *
GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp,
-
uint16_t size,
uint16_t type);
GNUNET_MQ_get_current_envelope (struct GNUNET_MQ_Handle *mq);
+/**
+ * Function to copy an envelope. The envelope must not yet
+ * be in any queue or have any options or callbacks set.
+ *
+ * @param env envelope to copy
+ * @return copy of @a env
+ */
+struct GNUNET_MQ_Envelope *
+GNUNET_MQ_env_copy (struct GNUNET_MQ_Envelope *env);
+
+
/**
* Function to obtain the last envelope in the queue.
*
uint64_t *flags);
+/**
+ * Remove the first envelope that has not yet been sent from the message
+ * queue and return it.
+ *
+ * @param mq queue to remove envelope from
+ * @return NULL if queue is empty (or has no envelope that is not under transmission)
+ */
+struct GNUNET_MQ_Envelope *
+GNUNET_MQ_unsent_head (struct GNUNET_MQ_Handle *mq);
+
+
/**
* Set application-specific options for this queue.
*
*/
void
GNUNET_MQ_notify_sent (struct GNUNET_MQ_Envelope *ev,
- GNUNET_MQ_NotifyCallback cb,
+ GNUNET_SCHEDULER_TaskCallback cb,
void *cb_cls);
* try to send the next message until #gnunet_mq_impl_send_continue
* is called.
*
- * only useful for implementing message queues, results in undefined
+ * Only useful for implementing message queues, results in undefined
* behavior if not used carefully.
*
* @param mq message queue to send the next message with