diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/conversation/gnunet-conversation-test.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/conversation/gnunet-conversation-test.c')
-rw-r--r-- | src/conversation/gnunet-conversation-test.c | 189 |
1 files changed, 96 insertions, 93 deletions
diff --git a/src/conversation/gnunet-conversation-test.c b/src/conversation/gnunet-conversation-test.c index 871058233..c03723fc3 100644 --- a/src/conversation/gnunet-conversation-test.c +++ b/src/conversation/gnunet-conversation-test.c | |||
@@ -31,13 +31,14 @@ | |||
31 | /** | 31 | /** |
32 | * How long do we record before we replay? | 32 | * How long do we record before we replay? |
33 | */ | 33 | */ |
34 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * A recording we made. | 38 | * A recording we made. |
39 | */ | 39 | */ |
40 | struct Recording { | 40 | struct Recording |
41 | { | ||
41 | /** | 42 | /** |
42 | * Kept in a DLL. | 43 | * Kept in a DLL. |
43 | */ | 44 | */ |
@@ -73,12 +74,12 @@ static struct GNUNET_SPEAKER_Handle *speaker; | |||
73 | /** | 74 | /** |
74 | * Task scheduled to switch from recording to playback. | 75 | * Task scheduled to switch from recording to playback. |
75 | */ | 76 | */ |
76 | static struct GNUNET_SCHEDULER_Task * switch_task; | 77 | static struct GNUNET_SCHEDULER_Task *switch_task; |
77 | 78 | ||
78 | /** | 79 | /** |
79 | * The shutdown task. | 80 | * The shutdown task. |
80 | */ | 81 | */ |
81 | static struct GNUNET_SCHEDULER_Task * st; | 82 | static struct GNUNET_SCHEDULER_Task *st; |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * Head of DLL with recorded frames. | 85 | * Head of DLL with recorded frames. |
@@ -97,26 +98,26 @@ static struct Recording *rec_tail; | |||
97 | * @param cls NULL | 98 | * @param cls NULL |
98 | */ | 99 | */ |
99 | static void | 100 | static void |
100 | do_shutdown(void *cls) | 101 | do_shutdown (void *cls) |
101 | { | 102 | { |
102 | struct Recording *rec; | 103 | struct Recording *rec; |
103 | 104 | ||
104 | (void)cls; | 105 | (void) cls; |
105 | if (NULL != switch_task) | 106 | if (NULL != switch_task) |
106 | GNUNET_SCHEDULER_cancel(switch_task); | 107 | GNUNET_SCHEDULER_cancel (switch_task); |
107 | if (NULL != microphone) | 108 | if (NULL != microphone) |
108 | GNUNET_MICROPHONE_destroy(microphone); | 109 | GNUNET_MICROPHONE_destroy (microphone); |
109 | if (NULL != speaker) | 110 | if (NULL != speaker) |
110 | GNUNET_SPEAKER_destroy(speaker); | 111 | GNUNET_SPEAKER_destroy (speaker); |
111 | while (NULL != (rec = rec_head)) | 112 | while (NULL != (rec = rec_head)) |
112 | { | 113 | { |
113 | GNUNET_CONTAINER_DLL_remove(rec_head, | 114 | GNUNET_CONTAINER_DLL_remove (rec_head, |
114 | rec_tail, | 115 | rec_tail, |
115 | rec); | 116 | rec); |
116 | GNUNET_free(rec); | 117 | GNUNET_free (rec); |
117 | } | 118 | } |
118 | fprintf(stderr, | 119 | fprintf (stderr, |
119 | _("\nEnd of transmission. Have a GNU day.\n")); | 120 | _ ("\nEnd of transmission. Have a GNU day.\n")); |
120 | } | 121 | } |
121 | 122 | ||
122 | 123 | ||
@@ -126,35 +127,36 @@ do_shutdown(void *cls) | |||
126 | * @param cls NULL | 127 | * @param cls NULL |
127 | */ | 128 | */ |
128 | static void | 129 | static void |
129 | switch_to_speaker(void *cls) | 130 | switch_to_speaker (void *cls) |
130 | { | 131 | { |
131 | (void)cls; | 132 | (void) cls; |
132 | switch_task = NULL; | 133 | switch_task = NULL; |
133 | microphone->disable_microphone(microphone->cls); | 134 | microphone->disable_microphone (microphone->cls); |
134 | if (GNUNET_OK != | 135 | if (GNUNET_OK != |
135 | speaker->enable_speaker(speaker->cls)) | 136 | speaker->enable_speaker (speaker->cls)) |
136 | { | 137 | { |
137 | fprintf(stderr, | 138 | fprintf (stderr, |
138 | "Failed to enable microphone\n"); | 139 | "Failed to enable microphone\n"); |
139 | ret = 1; | 140 | ret = 1; |
140 | GNUNET_SCHEDULER_shutdown(); | 141 | GNUNET_SCHEDULER_shutdown (); |
141 | return; | 142 | return; |
142 | } | 143 | } |
143 | fprintf(stderr, | 144 | fprintf (stderr, |
144 | _("\nWe are now playing your recording back. If you can hear it, your audio settings are working...")); | 145 | _ ( |
146 | "\nWe are now playing your recording back. If you can hear it, your audio settings are working...")); | ||
145 | for (struct Recording *rec = rec_head; NULL != rec; rec = rec->next) | 147 | for (struct Recording *rec = rec_head; NULL != rec; rec = rec->next) |
146 | { | 148 | { |
147 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
148 | "Replaying %u bytes\n", | 150 | "Replaying %u bytes\n", |
149 | (unsigned int)rec->size); | 151 | (unsigned int) rec->size); |
150 | speaker->play(speaker->cls, | 152 | speaker->play (speaker->cls, |
151 | rec->size, | 153 | rec->size, |
152 | &rec[1]); | 154 | &rec[1]); |
153 | } | 155 | } |
154 | GNUNET_SCHEDULER_cancel(st); | 156 | GNUNET_SCHEDULER_cancel (st); |
155 | st = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 157 | st = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
156 | &do_shutdown, | 158 | &do_shutdown, |
157 | NULL); | 159 | NULL); |
158 | } | 160 | } |
159 | 161 | ||
160 | 162 | ||
@@ -166,22 +168,22 @@ switch_to_speaker(void *cls) | |||
166 | * @param data audio data to play | 168 | * @param data audio data to play |
167 | */ | 169 | */ |
168 | static void | 170 | static void |
169 | record(void *cls, | 171 | record (void *cls, |
170 | size_t data_size, | 172 | size_t data_size, |
171 | const void *data) | 173 | const void *data) |
172 | { | 174 | { |
173 | struct Recording *rec; | 175 | struct Recording *rec; |
174 | 176 | ||
175 | (void)cls; | 177 | (void) cls; |
176 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
177 | "Recorded %u bytes\n", | 179 | "Recorded %u bytes\n", |
178 | (unsigned int)data_size); | 180 | (unsigned int) data_size); |
179 | rec = GNUNET_malloc(sizeof(struct Recording) + data_size); | 181 | rec = GNUNET_malloc (sizeof(struct Recording) + data_size); |
180 | rec->size = data_size; | 182 | rec->size = data_size; |
181 | GNUNET_memcpy(&rec[1], data, data_size); | 183 | GNUNET_memcpy (&rec[1], data, data_size); |
182 | GNUNET_CONTAINER_DLL_insert_tail(rec_head, | 184 | GNUNET_CONTAINER_DLL_insert_tail (rec_head, |
183 | rec_tail, | 185 | rec_tail, |
184 | rec); | 186 | rec); |
185 | } | 187 | } |
186 | 188 | ||
187 | 189 | ||
@@ -194,36 +196,37 @@ record(void *cls, | |||
194 | * @param cfg configuration | 196 | * @param cfg configuration |
195 | */ | 197 | */ |
196 | static void | 198 | static void |
197 | run(void *cls, | 199 | run (void *cls, |
198 | char *const *args, | 200 | char *const *args, |
199 | const char *cfgfile, | 201 | const char *cfgfile, |
200 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 202 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
201 | { | 203 | { |
202 | (void)cls; | 204 | (void) cls; |
203 | (void)args; | 205 | (void) args; |
204 | (void)cfgfile; | 206 | (void) cfgfile; |
205 | microphone = GNUNET_MICROPHONE_create_from_hardware(cfg); | 207 | microphone = GNUNET_MICROPHONE_create_from_hardware (cfg); |
206 | GNUNET_assert(NULL != microphone); | 208 | GNUNET_assert (NULL != microphone); |
207 | speaker = GNUNET_SPEAKER_create_from_hardware(cfg); | 209 | speaker = GNUNET_SPEAKER_create_from_hardware (cfg); |
208 | GNUNET_assert(NULL != speaker); | 210 | GNUNET_assert (NULL != speaker); |
209 | switch_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 211 | switch_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
210 | &switch_to_speaker, | 212 | &switch_to_speaker, |
211 | NULL); | 213 | NULL); |
212 | st = GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 214 | st = GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
213 | NULL); | 215 | NULL); |
214 | fprintf(stderr, | 216 | fprintf (stderr, |
215 | _("We will now be recording you for %s. After that time, the recording will be played back to you..."), | 217 | _ ( |
216 | GNUNET_STRINGS_relative_time_to_string(TIMEOUT, GNUNET_YES)); | 218 | "We will now be recording you for %s. After that time, the recording will be played back to you..."), |
219 | GNUNET_STRINGS_relative_time_to_string (TIMEOUT, GNUNET_YES)); | ||
217 | if (GNUNET_OK != | 220 | if (GNUNET_OK != |
218 | microphone->enable_microphone(microphone->cls, | 221 | microphone->enable_microphone (microphone->cls, |
219 | &record, NULL)) | 222 | &record, NULL)) |
220 | { | 223 | { |
221 | fprintf(stderr, | 224 | fprintf (stderr, |
222 | "Failed to enable microphone\n"); | 225 | "Failed to enable microphone\n"); |
223 | ret = 1; | 226 | ret = 1; |
224 | GNUNET_SCHEDULER_shutdown(); | 227 | GNUNET_SCHEDULER_shutdown (); |
225 | return; | 228 | return; |
226 | } | 229 | } |
227 | } | 230 | } |
228 | 231 | ||
229 | 232 | ||
@@ -235,26 +238,26 @@ run(void *cls, | |||
235 | * @return 0 ok, 1 on error | 238 | * @return 0 ok, 1 on error |
236 | */ | 239 | */ |
237 | int | 240 | int |
238 | main(int argc, | 241 | main (int argc, |
239 | char *const *argv) | 242 | char *const *argv) |
240 | { | 243 | { |
241 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 244 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
242 | GNUNET_GETOPT_OPTION_END | 245 | GNUNET_GETOPT_OPTION_END |
243 | }; | 246 | }; |
244 | 247 | ||
245 | if (GNUNET_OK != | 248 | if (GNUNET_OK != |
246 | GNUNET_STRINGS_get_utf8_args(argc, argv, | 249 | GNUNET_STRINGS_get_utf8_args (argc, argv, |
247 | &argc, &argv)) | 250 | &argc, &argv)) |
248 | return 2; | 251 | return 2; |
249 | 252 | ||
250 | ret = (GNUNET_OK == | 253 | ret = (GNUNET_OK == |
251 | GNUNET_PROGRAM_run(argc, argv, | 254 | GNUNET_PROGRAM_run (argc, argv, |
252 | "gnunet-conversation-test", | 255 | "gnunet-conversation-test", |
253 | gettext_noop("help text"), | 256 | gettext_noop ("help text"), |
254 | options, | 257 | options, |
255 | &run, | 258 | &run, |
256 | NULL)) ? ret : 1; | 259 | NULL)) ? ret : 1; |
257 | GNUNET_free((void*)argv); | 260 | GNUNET_free ((void*) argv); |
258 | return ret; | 261 | return ret; |
259 | } | 262 | } |
260 | 263 | ||