summaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_services.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-09-05 10:50:56 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-09-05 10:50:56 +0000
commit270a6392703fe1cb99f69ed8a35c1be0c864b11f (patch)
tree1c65d01fefab939684c58757880987d2a00fd060 /src/testbed/testbed_api_services.c
parentc09edda8e8071c6e5ca6b76e7c75a7b8402010ed (diff)
downloadgnunet-270a6392703fe1cb99f69ed8a35c1be0c864b11f.tar.gz
gnunet-270a6392703fe1cb99f69ed8a35c1be0c864b11f.zip
changed testbed API to include convenience callbacks
Diffstat (limited to 'src/testbed/testbed_api_services.c')
-rw-r--r--src/testbed/testbed_api_services.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c
index f37ada310..3e8484022 100644
--- a/src/testbed/testbed_api_services.c
+++ b/src/testbed/testbed_api_services.c
@@ -49,9 +49,6 @@ enum State
49 */ 49 */
50 SERVICE_CONNECTED, 50 SERVICE_CONNECTED,
51 51
52 /**
53 *
54 */
55}; 52};
56 53
57 54
@@ -111,6 +108,16 @@ struct ServiceConnectData
111 void *op_result; 108 void *op_result;
112 109
113 /** 110 /**
111 * The operation completion callback
112 */
113 GNUNET_TESTBED_OperationCompletionCallback cb;
114
115 /**
116 * The closure for operation completion callback
117 */
118 void *cb_cls;
119
120 /**
114 * State information 121 * State information
115 */ 122 */
116 enum State state; 123 enum State state;
@@ -132,7 +139,13 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
132 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; 139 const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg;
133 struct GNUNET_TESTBED_Controller *c; 140 struct GNUNET_TESTBED_Controller *c;
134 struct GNUNET_TESTBED_EventInformation info; 141 struct GNUNET_TESTBED_EventInformation info;
142 uint16_t mtype;
135 143
144 mtype = ntohs (msg->type);
145 if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONEVENT == mtype)
146 {
147 GNUNET_assert (0); /* FIXME: Add notification for failure */
148 }
136 imsg = 149 imsg =
137 (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; 150 (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg;
138 data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg); 151 data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg);
@@ -141,13 +154,14 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg)
141 info.details.operation_finished.operation = data->operation; 154 info.details.operation_finished.operation = data->operation;
142 info.details.operation_finished.op_cls = data->op_cls; 155 info.details.operation_finished.op_cls = data->op_cls;
143 info.details.operation_finished.emsg = NULL; 156 info.details.operation_finished.emsg = NULL;
144 info.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; 157 info.details.operation_finished.generic = data->op_result;
145 info.details.operation_finished.op_result.generic = data->op_result;
146 c = data->peer->controller; 158 c = data->peer->controller;
147 data->state = SERVICE_CONNECTED; 159 data->state = SERVICE_CONNECTED;
148 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && 160 if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) &&
149 (NULL != c->cc)) 161 (NULL != c->cc))
150 c->cc (c->cc_cls, &info); 162 c->cc (c->cc_cls, &info);
163 if (NULL != data->cb)
164 data->cb (data->cb_cls, data->operation, NULL);
151} 165}
152 166
153 167
@@ -214,7 +228,7 @@ oprelease_service_connect (void *cls)
214 * maintain connections with other systems. The actual service 228 * maintain connections with other systems. The actual service
215 * handle is then returned via the 'op_result' member in the event 229 * handle is then returned via the 'op_result' member in the event
216 * callback. The 'ca' callback is used to create the connection 230 * callback. The 'ca' callback is used to create the connection
217 * when the time is right; the 'da' callback will be used to 231 * when the time is right; the 'da' callback will be used to
218 * destroy the connection (upon 'GNUNET_TESTBED_operation_done'). 232 * destroy the connection (upon 'GNUNET_TESTBED_operation_done').
219 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this 233 * 'GNUNET_TESTBED_operation_cancel' can be used to abort this
220 * operation until the event callback has been called. 234 * operation until the event callback has been called.
@@ -222,17 +236,22 @@ oprelease_service_connect (void *cls)
222 * @param op_cls closure to pass in operation event 236 * @param op_cls closure to pass in operation event
223 * @param peer peer that runs the service 237 * @param peer peer that runs the service
224 * @param service_name name of the service to connect to 238 * @param service_name name of the service to connect to
239 * @param cb the callback to call when this operation finishes
240 * @param cb_cls closure for the above callback
225 * @param ca helper function to establish the connection 241 * @param ca helper function to establish the connection
226 * @param da helper function to close the connection 242 * @param da helper function to close the connection
227 * @param cada_cls closure for ca and da 243 * @param cada_cls closure for ca and da
228 * @return handle for the operation 244 * @return handle for the operation
229 */ 245 */
230struct GNUNET_TESTBED_Operation * 246struct GNUNET_TESTBED_Operation *
231GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, 247GNUNET_TESTBED_service_connect (void *op_cls,
232 const char *service_name, 248 struct GNUNET_TESTBED_Peer *peer,
233 GNUNET_TESTBED_ConnectAdapter ca, 249 const char *service_name,
234 GNUNET_TESTBED_DisconnectAdapter da, 250 GNUNET_TESTBED_OperationCompletionCallback cb,
235 void *cada_cls) 251 void *cb_cls,
252 GNUNET_TESTBED_ConnectAdapter ca,
253 GNUNET_TESTBED_DisconnectAdapter da,
254 void *cada_cls)
236{ 255{
237 struct ServiceConnectData *data; 256 struct ServiceConnectData *data;
238 257
@@ -243,6 +262,8 @@ GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer,
243 data->op_cls = op_cls; 262 data->op_cls = op_cls;
244 data->peer = peer; 263 data->peer = peer;
245 data->state = INIT; 264 data->state = INIT;
265 data->cb = cb;
266 data->cb_cls = cb_cls;
246 data->operation = 267 data->operation =
247 GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, 268 GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect,
248 &oprelease_service_connect); 269 &oprelease_service_connect);