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 | 61 |
1 files changed, 40 insertions, 21 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 7ff554280..9360dd02e 100644 --- a/src/testing/testing_api_cmd_block_until_external_trigger.c +++ b/src/testing/testing_api_cmd_block_until_external_trigger.c | |||
@@ -33,23 +33,6 @@ | |||
33 | */ | 33 | */ |
34 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) |
35 | 35 | ||
36 | /** | ||
37 | * Struct with information for callbacks. | ||
38 | * | ||
39 | */ | ||
40 | struct BlockState | ||
41 | { | ||
42 | /** | ||
43 | * Context for our asynchronous completion. | ||
44 | */ | ||
45 | struct GNUNET_TESTING_AsyncContext ac; | ||
46 | |||
47 | /** | ||
48 | * The label of this command. | ||
49 | */ | ||
50 | const char *label; | ||
51 | }; | ||
52 | |||
53 | 36 | ||
54 | /** | 37 | /** |
55 | * The cleanup function of this cmd frees resources the cmd allocated. | 38 | * The cleanup function of this cmd frees resources the cmd allocated. |
@@ -77,6 +60,11 @@ block_until_external_trigger_traits (void *cls, | |||
77 | .trait_name = "async_context", | 60 | .trait_name = "async_context", |
78 | .ptr = (const void *) ac, | 61 | .ptr = (const void *) ac, |
79 | }, | 62 | }, |
63 | { | ||
64 | .index = 1, | ||
65 | .trait_name = "block_state", | ||
66 | .ptr = (const void *) bs, | ||
67 | }, | ||
80 | GNUNET_TESTING_trait_end () | 68 | GNUNET_TESTING_trait_end () |
81 | }; | 69 | }; |
82 | 70 | ||
@@ -88,9 +76,27 @@ block_until_external_trigger_traits (void *cls, | |||
88 | 76 | ||
89 | 77 | ||
90 | /** | 78 | /** |
79 | * Function to get the trait with the internal command state BlockState. | ||
80 | * | ||
81 | * * @param[out] ac struct BlockState. | ||
82 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | ||
83 | */ | ||
84 | int | ||
85 | GNUNET_TESTING_get_trait_block_state ( | ||
86 | const struct GNUNET_TESTING_Command *cmd, | ||
87 | struct BlockState **bs) | ||
88 | { | ||
89 | return cmd->traits (cmd->cls, | ||
90 | (const void **) bs, | ||
91 | "block_state", | ||
92 | (unsigned int) 1); | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
91 | * Function to get the trait with the async context. | 97 | * Function to get the trait with the async context. |
92 | * | 98 | * |
93 | * @param[out] ac GNUNET_TESTING_AsyncContext. | 99 | * @param[out] ac struct GNUNET_TESTING_AsyncContext. |
94 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. | 100 | * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise. |
95 | */ | 101 | */ |
96 | int | 102 | int |
@@ -114,10 +120,20 @@ block_until_all_peers_started_run (void *cls, | |||
114 | struct GNUNET_TESTING_Interpreter *is) | 120 | struct GNUNET_TESTING_Interpreter *is) |
115 | { | 121 | { |
116 | struct BlockState *bs = cls; | 122 | struct BlockState *bs = cls; |
123 | struct GNUNET_TESTING_Command *cmd = | ||
124 | GNUNET_TESTING_interpreter_get_current_command (is); | ||
117 | 125 | ||
118 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 126 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
119 | "block %s running!\n", | 127 | "block %s running %u!\n", |
120 | bs->label); | 128 | bs->label, |
129 | bs->asynchronous_finish); | ||
130 | if (GNUNET_YES == bs->asynchronous_finish) | ||
131 | { | ||
132 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
133 | "block %s running asynchronous!\n", | ||
134 | bs->label); | ||
135 | cmd->asynchronous_finish = bs->asynchronous_finish; | ||
136 | } | ||
121 | } | 137 | } |
122 | 138 | ||
123 | 139 | ||
@@ -126,15 +142,18 @@ block_until_all_peers_started_run (void *cls, | |||
126 | * | 142 | * |
127 | * @param label name for command. | 143 | * @param label name for command. |
128 | * @param all_peers_started Flag which will be set from outside. | 144 | * @param all_peers_started Flag which will be set from outside. |
145 | * @param asynchronous_finish If GNUNET_YES this command will not block. Can be NULL. | ||
129 | * @return command. | 146 | * @return command. |
130 | */ | 147 | */ |
131 | struct GNUNET_TESTING_Command | 148 | struct GNUNET_TESTING_Command |
132 | GNUNET_TESTING_cmd_block_until_external_trigger (const char *label) | 149 | GNUNET_TESTING_cmd_block_until_external_trigger ( |
150 | const char *label) | ||
133 | { | 151 | { |
134 | struct BlockState *bs; | 152 | struct BlockState *bs; |
135 | 153 | ||
136 | bs = GNUNET_new (struct BlockState); | 154 | bs = GNUNET_new (struct BlockState); |
137 | bs->label = label; | 155 | bs->label = label; |
156 | bs->asynchronous_finish = GNUNET_NO; | ||
138 | { | 157 | { |
139 | struct GNUNET_TESTING_Command cmd = { | 158 | struct GNUNET_TESTING_Command cmd = { |
140 | .cls = bs, | 159 | .cls = bs, |