partial docs
[oweals/gnunet.git] / src / set / mq.h
1 /*
2      This file is part of GNUnet.
3      (C) 2012 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @author Florian Dold
23  * @file mq/mq.h
24  * @brief general purpose request queue
25  */
26 #ifndef MQ_H
27 #define MQ_H
28
29 #include "platform.h"
30 #include "gnunet_common.h"
31 #include "gnunet_util_lib.h"
32 #include "gnunet_connection_lib.h"
33
34
35 #define GNUNET_MQ_msg_extra(mvar, esize, type) GNUNET_MQ_msg_(((void) mvar->header, (struct GNUNET_MessageHeader**) &mvar), (esize) + sizeof *mvar, type)
36
37 #define GNUNET_MQ_msg(mvar, type) GNUNET_MQ_msg_extra(mvar, 0, type)
38
39 #define GNUNET_MQ_msg_raw(type) GNUNET_MQ_msg_ (NULL, sizeof (struct GNUNET_MessageHeader), type)
40
41 #define GNUNET_MQ_HANDLERS_END {NULL, 0}
42
43 struct GNUNET_MQ_MessageQueue;
44
45 struct GNUNET_MQ_Message;
46
47 struct GNUNET_MQ_Handler
48 {
49   void *cb;
50   uint16_t type;
51 };
52
53 /**
54  * Callback used for notifications
55  *
56  * @param cls closure
57  */
58 typedef void (*GNUNET_MQ_NotifyCallback) (void *cls);
59
60 /**
61  * Create a new message for MQ.
62  * 
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
67  */
68 struct GNUNET_MQ_Message *
69 GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type);
70
71 void
72 GNUNET_MQ_send (struct GNUNET_MQ_MessageQueue *mq, struct GNUNET_MQ_Message *mqm);
73
74
75 /**
76  * Associate the assoc_data in mq with a unique request id.
77  *
78  * @param mq message queue, id will be unique for the queue
79  * @param mqm message to associate
80  * @param data to associate
81  */
82 uint32_t
83 GNUNET_MQ_assoc_add (struct GNUNET_MQ_MessageQueue *mq,
84                      struct GNUNET_MQ_Message *mqm,
85                      void *assoc_data);
86
87 void *
88 GNUNET_MQ_assoc_get (struct GNUNET_MQ_MessageQueue *mq, uint32_t request_id);
89
90 void *
91 GNUNET_MQ_assoc_remove (struct GNUNET_MQ_MessageQueue *mq, uint32_t request_id);
92
93
94
95 struct GNUNET_MQ_MessageQueue *
96 GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connection,
97                                        const struct GNUNET_MQ_Handler *handlers,
98                                        void *cls);
99
100
101 void
102 GNUNET_MQ_notify_sent (struct GNUNET_MQ_Message *mqm,
103                        void (*)(void*),
104                        void *cls);
105
106
107 void
108 GNUNET_MQ_notify_timeout (struct GNUNET_MQ_Message *mqm,
109                           void (*)(void*),
110                           void *cls);
111
112
113 void
114 GNUNET_MQ_notify_destroy (struct GNUNET_MQ_Message *mqm,
115                           void (*)(void*),
116                           void *cls);
117
118 void
119 GNUNET_MQ_destroy (struct GNUNET_MQ_MessageQueue *mq);
120
121 #endif