-misc doxygen fixes
[oweals/gnunet.git] / src / include / gnunet_client_lib.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001-2013 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 3, 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  * @file include/gnunet_client_lib.h
23  * @brief functions related to accessing services
24  * @author Christian Grothoff
25  * @defgroup client Generic client-side communication with services
26  * @{
27  */
28
29 #ifndef GNUNET_CLIENT_LIB_H
30 #define GNUNET_CLIENT_LIB_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "gnunet_common.h"
41 #include "gnunet_configuration_lib.h"
42 #include "gnunet_connection_lib.h"
43 #include "gnunet_scheduler_lib.h"
44 #include "gnunet_time_lib.h"
45
46 /**
47  * Opaque handle for a connection to a service.
48  */
49 struct GNUNET_CLIENT_Connection;
50
51 /**
52  * Get a connection with a service.
53  *
54  * @param service_name name of the service
55  * @param cfg configuration to use
56  * @return NULL on error (service unknown to configuration)
57  */
58 struct GNUNET_CLIENT_Connection *
59 GNUNET_CLIENT_connect (const char *service_name,
60                        const struct GNUNET_CONFIGURATION_Handle *cfg);
61
62
63 /**
64  * Destroy connection with the service.  This will automatically
65  * cancel any pending "receive" request (however, the handler will
66  * *NOT* be called, not even with a NULL message).  Any pending
67  * transmission request will also be cancelled UNLESS the callback for
68  * the transmission request has already been called, in which case the
69  * transmission 'finish_pending_write' argument determines whether or
70  * not the write is guaranteed to complete before the socket is fully
71  * destroyed (unless, of course, there is an error with the server in
72  * which case the message may still be lost).
73  *
74  * @param client handle to the service connection
75  */
76 void
77 GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *client);
78
79
80 /**
81  * Type of a function to call when we receive a message
82  * from the service.
83  *
84  * @param cls closure
85  * @param msg message received, NULL on timeout or fatal error
86  */
87 typedef void (*GNUNET_CLIENT_MessageHandler) (void *cls,
88                                               const struct GNUNET_MessageHeader
89                                               *msg);
90
91
92 /**
93  * Read from the service.
94  *
95  * @param client connection to the service
96  * @param handler function to call with the message
97  * @param handler_cls closure for @a handler
98  * @param timeout how long to wait until timing out
99  */
100 void
101 GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client,
102                        GNUNET_CLIENT_MessageHandler handler, void *handler_cls,
103                        struct GNUNET_TIME_Relative timeout);
104
105
106 /**
107  * Transmit handle for client connections.
108  */
109 struct GNUNET_CLIENT_TransmitHandle;
110
111
112 /**
113  * Ask the client to call us once the specified number of bytes
114  * are free in the transmission buffer.  May call the notify
115  * method immediately if enough space is available.
116  *
117  * @param client connection to the service
118  * @param size number of bytes to send
119  * @param timeout after how long should we give up (and call
120  *        @a notify with buf NULL and size 0)?
121  * @param auto_retry if the connection to the service dies, should we
122  *        automatically re-connect and retry (within the timeout period)
123  *        or should we immediately fail in this case?  Pass #GNUNET_YES
124  *        if the caller does not care about temporary connection errors,
125  *        for example because the protocol is stateless
126  * @param notify function to call
127  * @param notify_cls closure for @a notify
128  * @return NULL if someone else is already waiting to be notified
129  *         non-NULL if the notify callback was queued (can be used to cancel
130  *         using #GNUNET_CONNECTION_notify_transmit_ready_cancel)
131  */
132 struct GNUNET_CLIENT_TransmitHandle *
133 GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *client,
134                                      size_t size,
135                                      struct GNUNET_TIME_Relative timeout,
136                                      int auto_retry,
137                                      GNUNET_CONNECTION_TransmitReadyNotify
138                                      notify, void *notify_cls);
139
140
141 /**
142  * Cancel a request for notification.
143  *
144  * @param th handle from the original request.
145  */
146 void
147 GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle
148                                             *th);
149
150
151 /**
152  * Convenience API that combines sending a request
153  * to the service and waiting for a response.
154  * If either operation times out, the callback
155  * will be called with a "NULL" response (in which
156  * case the connection should probably be destroyed).
157  *
158  * @param client connection to use
159  * @param hdr message to transmit
160  * @param timeout when to give up (for both transmission
161  *         and for waiting for a response)
162  * @param auto_retry if the connection to the service dies, should we
163  *        automatically re-connect and retry (within the timeout period)
164  *        or should we immediately fail in this case?  Pass #GNUNET_YES
165  *        if the caller does not care about temporary connection errors,
166  *        for example because the protocol is stateless
167  * @param rn function to call with the response
168  * @param rn_cls closure for @a rn
169  * @return #GNUNET_OK on success, #GNUNET_SYSERR if a request
170  *         is already pending
171  */
172 int
173 GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *client,
174                                          const struct GNUNET_MessageHeader *hdr,
175                                          struct GNUNET_TIME_Relative timeout,
176                                          int auto_retry,
177                                          GNUNET_CLIENT_MessageHandler rn,
178                                          void *rn_cls);
179
180
181 /**
182  * Handle for a test to check if a service is running.
183  */
184 struct GNUNET_CLIENT_TestHandle;
185
186 /**
187  * Function called with the result on the service test.
188  *
189  * @param cls closure
190  * @param result #GNUNET_YES if the service is running,
191  *               #GNUNET_NO if the service is not running
192  *               #GNUNET_SYSERR if the configuration is invalid
193  */
194 typedef void (*GNUNET_CLIENT_TestResultCallback)(void *cls,
195                                                  int result);
196
197
198 /**
199  * Test if the service is running.  If we are given a UNIXPATH or a
200  * local address, we do this NOT by trying to connect to the service,
201  * but by trying to BIND to the same port.  If the BIND fails, we know
202  * the service is running.
203  *
204  * @param service name of the service to wait for
205  * @param cfg configuration to use
206  * @param timeout how long to wait at most
207  * @param cb function to call with the result
208  * @param cb_cls closure for @a cb
209  * @return handle to cancel the test
210  */
211 struct GNUNET_CLIENT_TestHandle *
212 GNUNET_CLIENT_service_test (const char *service,
213                             const struct GNUNET_CONFIGURATION_Handle *cfg,
214                             struct GNUNET_TIME_Relative timeout,
215                             GNUNET_CLIENT_TestResultCallback cb, void *cb_cls);
216
217
218 /**
219  * Abort testing for service.
220  *
221  * @param th test handle
222  */
223 void
224 GNUNET_CLIENT_service_test_cancel (struct GNUNET_CLIENT_TestHandle *th);
225
226
227 #if 0                           /* keep Emacsens' auto-indent happy */
228 {
229 #endif
230 #ifdef __cplusplus
231 }
232 #endif
233
234 /** @} */ /* end of group client */
235
236 /* ifndef GNUNET_CLIENT_LIB_H */
237 #endif
238 /* end of gnunet_client_lib.h */