2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
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 2, or (at your
8 option) any later version.
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.
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.
22 * @author Florian Dold
24 * @brief general purpose request queue
30 #include "gnunet_common.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_connection_lib.h"
35 #define GNUNET_MQ_msg_extra(mvar, esize, type) GNUNET_MQ_msg_(((void) mvar->header, (struct GNUNET_MessageHeader**) &mvar), (esize) + sizeof *mvar, type)
37 #define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type)
39 #define GNUNET_MQ_msg_raw(type) GNUNET_MQ_msg_ (NULL, sizeof (struct GNUNET_MessageHeader), type)
41 #define GNUNET_MQ_HANDLERS_END {NULL, 0}
43 struct GNUNET_MQ_MessageQueue;
45 struct GNUNET_MQ_Message;
47 struct GNUNET_MQ_Handler
54 * Callback used for notifications
58 typedef void (*GNUNET_MQ_NotifyCallback) (void *cls);
61 * Create a new message for MQ.
63 * @param mhp message header to store the allocated message header in, can be NULL
64 * @param size size of the message to allocate
65 * @param type type of the message, will be set in the allocated message
66 * @param return the allocated MQ message
68 struct GNUNET_MQ_Message *
69 GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type);
72 GNUNET_MQ_send (struct GNUNET_MQ_MessageQueue *mq, struct GNUNET_MQ_Message *mqm);
76 * Associate the assoc_data in mq with a unique request id.
78 * @param mq message queue, id will be unique for the queue
79 * @param mqm message to associate
80 * @param data to associate
83 GNUNET_MQ_assoc_add (struct GNUNET_MQ_MessageQueue *mq,
84 struct GNUNET_MQ_Message *mqm,
88 GNUNET_MQ_assoc_get (struct GNUNET_MQ_MessageQueue *mq, uint32_t request_id);
91 GNUNET_MQ_assoc_remove (struct GNUNET_MQ_MessageQueue *mq, uint32_t request_id);
95 struct GNUNET_MQ_MessageQueue *
96 GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connection,
97 const struct GNUNET_MQ_Handler *handlers,
102 GNUNET_MQ_notify_sent (struct GNUNET_MQ_Message *mqm,
108 GNUNET_MQ_notify_timeout (struct GNUNET_MQ_Message *mqm,
114 GNUNET_MQ_notify_destroy (struct GNUNET_MQ_Message *mqm,
119 GNUNET_MQ_destroy (struct GNUNET_MQ_MessageQueue *mq);