2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 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 * @file include/gnunet_client_lib.h
23 * @brief functions related to accessing services
24 * @author Christian Grothoff
27 #ifndef GNUNET_CLIENT_LIB_H
28 #define GNUNET_CLIENT_LIB_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_common.h"
39 #include "gnunet_configuration_lib.h"
40 #include "gnunet_connection_lib.h"
41 #include "gnunet_scheduler_lib.h"
42 #include "gnunet_time_lib.h"
45 * Opaque handle for a connection to a service.
47 struct GNUNET_CLIENT_Connection;
50 * Get a connection with a service.
52 * @param sched scheduler to use
53 * @param service_name name of the service
54 * @param cfg configuration to use
55 * @return NULL on error (service unknown to configuration)
57 struct GNUNET_CLIENT_Connection *GNUNET_CLIENT_connect (struct
58 GNUNET_SCHEDULER_Handle
63 GNUNET_CONFIGURATION_Handle
67 * Destroy connection with the service. This will
68 * automatically cancel any pending "receive" request
69 * (however, the handler will *NOT* be called, not
70 * even with a NULL message).
72 void GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock);
75 * Type of a function to call when we receive a message
79 * @param msg message received, NULL on timeout or fatal error
81 typedef void (*GNUNET_CLIENT_MessageHandler) (void *cls,
83 GNUNET_MessageHeader * msg);
86 * Read from the service.
88 * @param sched scheduler to use
89 * @param sock the service
90 * @param handler function to call with the message
91 * @param cls closure for handler
92 * @param timeout how long to wait until timing out
94 void GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
95 GNUNET_CLIENT_MessageHandler handler,
96 void *cls, struct GNUNET_TIME_Relative timeout);
100 * Ask the client to call us once the specified number of bytes
101 * are free in the transmission buffer. May call the notify
102 * method immediately if enough space is available.
104 * @param client connection to the service
105 * @param size number of bytes to send
106 * @param timeout after how long should we give up (and call
107 * notify with buf NULL and size 0)?
108 * @param notify function to call
109 * @param notify_cls closure for notify
110 * @return NULL if someone else is already waiting to be notified
111 * non-NULL if the notify callback was queued (can be used to cancel
112 * using GNUNET_CONNECTION_notify_transmit_ready_cancel)
114 struct GNUNET_NETWORK_TransmitHandle
115 *GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
117 struct GNUNET_TIME_Relative timeout,
118 GNUNET_NETWORK_TransmitReadyNotify
119 notify, void *notify_cls);
123 * Request that the service should shutdown.
124 * Afterwards, the connection should be disconnected.
126 * @param sched scheduler to use
127 * @param sock the socket connected to the service
129 void GNUNET_CLIENT_service_shutdown (struct GNUNET_CLIENT_Connection *sock);
133 * Wait until the service is running.
135 * @param sched scheduler to use
136 * @param service name of the service to wait for
137 * @param cfg configuration to use
138 * @param timeout how long to wait at most in ms
139 * @param task task to run if service is running
140 * (reason will be "PREREQ_DONE" (service running)
141 * or "TIMEOUT" (service not known to be running))
142 * @param task_cls closure for task
144 void GNUNET_CLIENT_service_test (struct GNUNET_SCHEDULER_Handle *sched,
146 const struct GNUNET_CONFIGURATION_Handle *cfg,
147 struct GNUNET_TIME_Relative timeout,
148 GNUNET_SCHEDULER_Task task, void *task_cls);
151 #if 0 /* keep Emacsens' auto-indent happy */
158 /* ifndef GNUNET_CLIENT_LIB_H */
160 /* end of gnunet_client_lib.h */