diff options
Diffstat (limited to 'src/testing/testing_api_cmd_block_until_external_trigger.c')
-rw-r--r-- | src/testing/testing_api_cmd_block_until_external_trigger.c | 116 |
1 files changed, 63 insertions, 53 deletions
diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c index 2439afeaf..aeb9ffda3 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c | |||
@@ -39,25 +39,15 @@ | |||
39 | struct BlockState | 39 | struct BlockState |
40 | { | 40 | { |
41 | /** | 41 | /** |
42 | * Flag to indicate if all peers have started. | 42 | * Context for our asynchronous completion. |
43 | * | ||
44 | */ | 43 | */ |
45 | unsigned int *stop_blocking; | 44 | struct GNUNET_TESTING_AsyncContext ac; |
46 | }; | ||
47 | |||
48 | 45 | ||
49 | /** | 46 | /** |
50 | * Trait function of this cmd does nothing. | 47 | * The label of this command. |
51 | * | 48 | */ |
52 | */ | 49 | const char *label; |
53 | static int | 50 | }; |
54 | block_until_all_peers_started_traits (void *cls, | ||
55 | const void **ret, | ||
56 | const char *trait, | ||
57 | unsigned int index) | ||
58 | { | ||
59 | return GNUNET_OK; | ||
60 | } | ||
61 | 51 | ||
62 | 52 | ||
63 | /** | 53 | /** |
@@ -65,47 +55,68 @@ block_until_all_peers_started_traits (void *cls, | |||
65 | * | 55 | * |
66 | */ | 56 | */ |
67 | static void | 57 | static void |
68 | block_until_all_peers_started_cleanup (void *cls, | 58 | block_until_all_peers_started_cleanup (void *cls) |
69 | const struct GNUNET_TESTING_Command *cmd) | ||
70 | { | 59 | { |
71 | struct BlockState *bs = cls; | 60 | struct BlockState *bs = cls; |
72 | 61 | ||
73 | GNUNET_free (bs); | 62 | GNUNET_free (bs); |
74 | } | 63 | } |
75 | 64 | ||
65 | static int | ||
66 | block_until_external_trigger_traits (void *cls, | ||
67 | const void **ret, | ||
68 | const char *trait, | ||
69 | unsigned int index) | ||
70 | { | ||
71 | struct BlockState *bs = cls; | ||
72 | struct GNUNET_TESTING_AsyncContext *ac = &bs->ac; | ||
73 | struct GNUNET_TESTING_Trait traits[] = { | ||
74 | { | ||
75 | .index = 0, | ||
76 | .trait_name = "async_context", | ||
77 | .ptr = (const void *) ac, | ||
78 | }, | ||
79 | GNUNET_TESTING_trait_end () | ||
80 | }; | ||
81 | |||
82 | return GNUNET_TESTING_get_trait (traits, | ||
83 | ret, | ||
84 | trait, | ||
85 | index); | ||
86 | } | ||
87 | |||
76 | 88 | ||
77 | /** | 89 | /** |
78 | * This function does nothing but to start the cmd. | 90 | * Function to get the trait with the async context. |
79 | * | 91 | * |
92 | * @param[out] ac GNUNET_TESTING_AsyncContext. | ||
93 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
80 | */ | 94 | */ |
81 | static void | 95 | int |
82 | block_until_all_peers_started_run (void *cls, | 96 | GNUNET_TESTING_get_trait_async_context ( |
83 | const struct GNUNET_TESTING_Command *cmd, | 97 | const struct GNUNET_TESTING_Command *cmd, |
84 | struct GNUNET_TESTING_Interpreter *is) | 98 | struct GNUNET_TESTING_AsyncContext **ac) |
85 | { | 99 | { |
86 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 100 | return cmd->traits (cmd->cls, |
87 | "block_until_all_peers_started_run!\n"); | 101 | (const void **) ac, |
102 | "async_context", | ||
103 | (unsigned int) 0); | ||
88 | } | 104 | } |
89 | 105 | ||
90 | 106 | ||
91 | /** | 107 | /** |
92 | * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called. | 108 | * This function does nothing but to start the cmd. |
93 | * | 109 | * |
94 | */ | 110 | */ |
95 | static int | 111 | static void |
96 | block_until_all_peers_started_finish (void *cls, | 112 | block_until_all_peers_started_run (void *cls, |
97 | GNUNET_SCHEDULER_TaskCallback cont, | 113 | struct GNUNET_TESTING_Interpreter *is) |
98 | void *cont_cls) | ||
99 | { | 114 | { |
100 | struct BlockState *bs = cls; | 115 | struct BlockState *bs = cls; |
101 | unsigned int *ret = bs->stop_blocking; | ||
102 | 116 | ||
103 | if (GNUNET_YES == *ret) | 117 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
104 | { | 118 | "block %s running!\n", |
105 | cont (cont_cls); | 119 | bs->label); |
106 | } | ||
107 | |||
108 | return *ret; | ||
109 | } | 120 | } |
110 | 121 | ||
111 | 122 | ||
@@ -117,23 +128,22 @@ block_until_all_peers_started_finish (void *cls, | |||
117 | * @return command. | 128 | * @return command. |
118 | */ | 129 | */ |
119 | struct GNUNET_TESTING_Command | 130 | struct GNUNET_TESTING_Command |
120 | GNUNET_TESTING_cmd_block_until_external_trigger (const char *label, | 131 | GNUNET_TESTING_cmd_block_until_external_trigger (const char *label) |
121 | unsigned int * | ||
122 | stop_blocking) | ||
123 | { | 132 | { |
124 | struct BlockState *bs; | 133 | struct BlockState *bs; |
125 | 134 | ||
126 | bs = GNUNET_new (struct BlockState); | 135 | bs = GNUNET_new (struct BlockState); |
127 | bs->stop_blocking = stop_blocking; | 136 | bs->label = label; |
128 | 137 | { | |
129 | struct GNUNET_TESTING_Command cmd = { | 138 | struct GNUNET_TESTING_Command cmd = { |
130 | .cls = bs, | 139 | .cls = bs, |
131 | .label = label, | 140 | .label = label, |
132 | .run = &block_until_all_peers_started_run, | 141 | .run = &block_until_all_peers_started_run, |
133 | .finish = &block_until_all_peers_started_finish, | 142 | .ac = &bs->ac, |
134 | .cleanup = &block_until_all_peers_started_cleanup, | 143 | .cleanup = &block_until_all_peers_started_cleanup, |
135 | .traits = &block_until_all_peers_started_traits | 144 | .traits = block_until_external_trigger_traits |
136 | }; | 145 | }; |
137 | 146 | ||
138 | return cmd; | 147 | return cmd; |
148 | } | ||
139 | } | 149 | } |