diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-05 10:50:56 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-05 10:50:56 +0000 |
commit | 270a6392703fe1cb99f69ed8a35c1be0c864b11f (patch) | |
tree | 1c65d01fefab939684c58757880987d2a00fd060 /src/testbed/test_testbed_api.c | |
parent | c09edda8e8071c6e5ca6b76e7c75a7b8402010ed (diff) | |
download | gnunet-270a6392703fe1cb99f69ed8a35c1be0c864b11f.tar.gz gnunet-270a6392703fe1cb99f69ed8a35c1be0c864b11f.zip |
changed testbed API to include convenience callbacks
Diffstat (limited to 'src/testbed/test_testbed_api.c')
-rw-r--r-- | src/testbed/test_testbed_api.c | 95 |
1 files changed, 68 insertions, 27 deletions
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index caa3d09fd..529072cee 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c | |||
@@ -207,6 +207,64 @@ dht_disconnect_adapter (void *cls, void *op_result) | |||
207 | } | 207 | } |
208 | 208 | ||
209 | 209 | ||
210 | /** | ||
211 | * Callback to be called when an operation is completed | ||
212 | * | ||
213 | * @param cls the callback closure from functions generating an operation | ||
214 | * @param op the operation that has been finished | ||
215 | * @param emsg error message in case the operation has failed; will be NULL if | ||
216 | * operation has executed successfully. | ||
217 | */ | ||
218 | static void | ||
219 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | ||
220 | { | ||
221 | switch (sub_test) | ||
222 | { | ||
223 | case PEER_SERVICE_CONNECT: | ||
224 | GNUNET_assert (operation == op); | ||
225 | GNUNET_assert (NULL == emsg); | ||
226 | GNUNET_assert (NULL == cls); | ||
227 | GNUNET_TESTBED_operation_done (operation); /* This results in call to | ||
228 | * disconnect adapter */ | ||
229 | break; | ||
230 | default: | ||
231 | GNUNET_assert (0); | ||
232 | } | ||
233 | } | ||
234 | |||
235 | |||
236 | /** | ||
237 | * Callback to be called when the requested peer information is available | ||
238 | * | ||
239 | * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() | ||
240 | * @param op the operation this callback corresponds to | ||
241 | * @param pinfo the result; will be NULL if the operation has failed | ||
242 | * @param emsg error message if the operation has failed; will be NULL if the | ||
243 | * operation is successfull | ||
244 | */ | ||
245 | static void | ||
246 | peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | ||
247 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
248 | const char *emsg) | ||
249 | { | ||
250 | switch (sub_test) | ||
251 | { | ||
252 | case PEER_GETCONFIG: | ||
253 | GNUNET_assert (NULL != pinfo); | ||
254 | GNUNET_assert (NULL == emsg); | ||
255 | GNUNET_assert (NULL == cb_cls); | ||
256 | GNUNET_assert (operation == op); | ||
257 | GNUNET_assert (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit); | ||
258 | GNUNET_assert (NULL != pinfo->result.cfg); | ||
259 | sub_test = PEER_DESTROY; | ||
260 | GNUNET_TESTBED_operation_done (operation); | ||
261 | operation = GNUNET_TESTBED_peer_destroy (peer); | ||
262 | break; | ||
263 | default: | ||
264 | GNUNET_assert (0); | ||
265 | } | ||
266 | } | ||
267 | |||
210 | 268 | ||
211 | /** | 269 | /** |
212 | * Signature of the event handler function called by the | 270 | * Signature of the event handler function called by the |
@@ -223,25 +281,11 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
223 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | 281 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
224 | switch (sub_test) | 282 | switch (sub_test) |
225 | { | 283 | { |
226 | case PEER_GETCONFIG: | ||
227 | GNUNET_assert (event->details.operation_finished.operation == operation); | ||
228 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | ||
229 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
230 | GNUNET_assert (GNUNET_TESTBED_PIT_CONFIGURATION == | ||
231 | event->details.operation_finished.pit); | ||
232 | GNUNET_assert (NULL != event->details.operation_finished.op_result.cfg); | ||
233 | sub_test = PEER_DESTROY; | ||
234 | GNUNET_TESTBED_operation_done (operation); | ||
235 | operation = GNUNET_TESTBED_peer_destroy (peer); | ||
236 | break; | ||
237 | case PEER_DESTROY: | 284 | case PEER_DESTROY: |
238 | GNUNET_assert (event->details.operation_finished.operation == operation); | 285 | GNUNET_assert (event->details.operation_finished.operation == operation); |
239 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | 286 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); |
240 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | 287 | GNUNET_assert (NULL == event->details.operation_finished.emsg); |
241 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == | 288 | GNUNET_assert (NULL == event->details.operation_finished.generic); |
242 | event->details.operation_finished.pit); | ||
243 | GNUNET_assert (NULL == | ||
244 | event->details.operation_finished.op_result.generic); | ||
245 | GNUNET_TESTBED_operation_done (operation); | 289 | GNUNET_TESTBED_operation_done (operation); |
246 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 290 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
247 | break; | 291 | break; |
@@ -249,15 +293,10 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
249 | GNUNET_assert (event->details.operation_finished.operation == operation); | 293 | GNUNET_assert (event->details.operation_finished.operation == operation); |
250 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | 294 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); |
251 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | 295 | GNUNET_assert (NULL == event->details.operation_finished.emsg); |
252 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == | ||
253 | event->details.operation_finished.pit); | ||
254 | GNUNET_assert (NULL != dht_handle); | 296 | GNUNET_assert (NULL != dht_handle); |
255 | GNUNET_assert (event->details.operation_finished.op_result.generic == | 297 | GNUNET_assert (event->details.operation_finished.generic == dht_handle); |
256 | dht_handle); | ||
257 | GNUNET_TESTBED_operation_done (operation); /* This results in call to | ||
258 | * disconnect adapter */ | ||
259 | break; | 298 | break; |
260 | case OTHER: | 299 | default: |
261 | GNUNET_assert (0); | 300 | GNUNET_assert (0); |
262 | break; | 301 | break; |
263 | } | 302 | } |
@@ -268,8 +307,9 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
268 | GNUNET_assert (OTHER == sub_test); | 307 | GNUNET_assert (OTHER == sub_test); |
269 | GNUNET_TESTBED_operation_done (operation); | 308 | GNUNET_TESTBED_operation_done (operation); |
270 | operation = | 309 | operation = |
271 | GNUNET_TESTBED_service_connect (NULL, peer, "dht", &dht_connect_adapter, | 310 | GNUNET_TESTBED_service_connect (NULL, peer, "dht", &op_comp_cb, NULL, |
272 | &dht_disconnect_adapter, NULL); | 311 | &dht_connect_adapter, |
312 | &dht_disconnect_adapter, NULL); | ||
273 | GNUNET_assert (NULL != operation); | 313 | GNUNET_assert (NULL != operation); |
274 | break; | 314 | break; |
275 | case GNUNET_TESTBED_ET_PEER_STOP: | 315 | case GNUNET_TESTBED_ET_PEER_STOP: |
@@ -278,9 +318,10 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
278 | result = GNUNET_YES; | 318 | result = GNUNET_YES; |
279 | sub_test = PEER_GETCONFIG; | 319 | sub_test = PEER_GETCONFIG; |
280 | GNUNET_TESTBED_operation_done (operation); | 320 | GNUNET_TESTBED_operation_done (operation); |
281 | operation = | 321 | operation = |
282 | GNUNET_TESTBED_peer_get_information (peer, | 322 | GNUNET_TESTBED_peer_get_information (peer, |
283 | GNUNET_TESTBED_PIT_CONFIGURATION); | 323 | GNUNET_TESTBED_PIT_CONFIGURATION, |
324 | &peerinfo_cb, NULL); | ||
284 | break; | 325 | break; |
285 | default: | 326 | default: |
286 | GNUNET_assert (0); /* We should never reach this state */ | 327 | GNUNET_assert (0); /* We should never reach this state */ |