summaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-conversation-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/conversation/gnunet-conversation-test.c')
-rw-r--r--src/conversation/gnunet-conversation-test.c191
1 files changed, 95 insertions, 96 deletions
diff --git a/src/conversation/gnunet-conversation-test.c b/src/conversation/gnunet-conversation-test.c
index 201156f7f..871058233 100644
--- a/src/conversation/gnunet-conversation-test.c
+++ b/src/conversation/gnunet-conversation-test.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file conversation/gnunet-conversation-test.c 22 * @file conversation/gnunet-conversation-test.c
@@ -31,14 +31,13 @@
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 */
40struct Recording 40struct Recording {
41{
42 /** 41 /**
43 * Kept in a DLL. 42 * Kept in a DLL.
44 */ 43 */
@@ -98,26 +97,26 @@ static struct Recording *rec_tail;
98 * @param cls NULL 97 * @param cls NULL
99 */ 98 */
100static void 99static void
101do_shutdown (void *cls) 100do_shutdown(void *cls)
102{ 101{
103 struct Recording *rec; 102 struct Recording *rec;
104 103
105 (void) cls; 104 (void)cls;
106 if (NULL != switch_task) 105 if (NULL != switch_task)
107 GNUNET_SCHEDULER_cancel (switch_task); 106 GNUNET_SCHEDULER_cancel(switch_task);
108 if (NULL != microphone) 107 if (NULL != microphone)
109 GNUNET_MICROPHONE_destroy (microphone); 108 GNUNET_MICROPHONE_destroy(microphone);
110 if (NULL != speaker) 109 if (NULL != speaker)
111 GNUNET_SPEAKER_destroy (speaker); 110 GNUNET_SPEAKER_destroy(speaker);
112 while (NULL != (rec = rec_head)) 111 while (NULL != (rec = rec_head))
113 { 112 {
114 GNUNET_CONTAINER_DLL_remove (rec_head, 113 GNUNET_CONTAINER_DLL_remove(rec_head,
115 rec_tail, 114 rec_tail,
116 rec); 115 rec);
117 GNUNET_free (rec); 116 GNUNET_free(rec);
118 } 117 }
119 fprintf (stderr, 118 fprintf(stderr,
120 _("\nEnd of transmission. Have a GNU day.\n")); 119 _("\nEnd of transmission. Have a GNU day.\n"));
121} 120}
122 121
123 122
@@ -127,35 +126,35 @@ do_shutdown (void *cls)
127 * @param cls NULL 126 * @param cls NULL
128 */ 127 */
129static void 128static void
130switch_to_speaker (void *cls) 129switch_to_speaker(void *cls)
131{ 130{
132 (void) cls; 131 (void)cls;
133 switch_task = NULL; 132 switch_task = NULL;
134 microphone->disable_microphone (microphone->cls); 133 microphone->disable_microphone(microphone->cls);
135 if (GNUNET_OK != 134 if (GNUNET_OK !=
136 speaker->enable_speaker (speaker->cls)) 135 speaker->enable_speaker(speaker->cls))
137 { 136 {
138 fprintf (stderr, 137 fprintf(stderr,
139 "Failed to enable microphone\n"); 138 "Failed to enable microphone\n");
140 ret = 1; 139 ret = 1;
141 GNUNET_SCHEDULER_shutdown (); 140 GNUNET_SCHEDULER_shutdown();
142 return; 141 return;
143 } 142 }
144 fprintf (stderr, 143 fprintf(stderr,
145 _("\nWe are now playing your recording back. If you can hear it, your audio settings are working...")); 144 _("\nWe are now playing your recording back. If you can hear it, your audio settings are working..."));
146 for (struct Recording *rec=rec_head; NULL != rec; rec = rec->next) 145 for (struct Recording *rec = rec_head; NULL != rec; rec = rec->next)
147 { 146 {
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
149 "Replaying %u bytes\n", 148 "Replaying %u bytes\n",
150 (unsigned int) rec->size); 149 (unsigned int)rec->size);
151 speaker->play (speaker->cls, 150 speaker->play(speaker->cls,
152 rec->size, 151 rec->size,
153 &rec[1]); 152 &rec[1]);
154 } 153 }
155 GNUNET_SCHEDULER_cancel (st); 154 GNUNET_SCHEDULER_cancel(st);
156 st = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 155 st = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
157 &do_shutdown, 156 &do_shutdown,
158 NULL); 157 NULL);
159} 158}
160 159
161 160
@@ -167,22 +166,22 @@ switch_to_speaker (void *cls)
167 * @param data audio data to play 166 * @param data audio data to play
168 */ 167 */
169static void 168static void
170record (void *cls, 169record(void *cls,
171 size_t data_size, 170 size_t data_size,
172 const void *data) 171 const void *data)
173{ 172{
174 struct Recording *rec; 173 struct Recording *rec;
175 174
176 (void) cls; 175 (void)cls;
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 176 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
178 "Recorded %u bytes\n", 177 "Recorded %u bytes\n",
179 (unsigned int) data_size); 178 (unsigned int)data_size);
180 rec = GNUNET_malloc (sizeof (struct Recording) + data_size); 179 rec = GNUNET_malloc(sizeof(struct Recording) + data_size);
181 rec->size = data_size; 180 rec->size = data_size;
182 GNUNET_memcpy (&rec[1], data, data_size); 181 GNUNET_memcpy(&rec[1], data, data_size);
183 GNUNET_CONTAINER_DLL_insert_tail (rec_head, 182 GNUNET_CONTAINER_DLL_insert_tail(rec_head,
184 rec_tail, 183 rec_tail,
185 rec); 184 rec);
186} 185}
187 186
188 187
@@ -195,36 +194,36 @@ record (void *cls,
195 * @param cfg configuration 194 * @param cfg configuration
196 */ 195 */
197static void 196static void
198run (void *cls, 197run(void *cls,
199 char *const *args, 198 char *const *args,
200 const char *cfgfile, 199 const char *cfgfile,
201 const struct GNUNET_CONFIGURATION_Handle *cfg) 200 const struct GNUNET_CONFIGURATION_Handle *cfg)
202{ 201{
203 (void) cls; 202 (void)cls;
204 (void) args; 203 (void)args;
205 (void) cfgfile; 204 (void)cfgfile;
206 microphone = GNUNET_MICROPHONE_create_from_hardware (cfg); 205 microphone = GNUNET_MICROPHONE_create_from_hardware(cfg);
207 GNUNET_assert (NULL != microphone); 206 GNUNET_assert(NULL != microphone);
208 speaker = GNUNET_SPEAKER_create_from_hardware (cfg); 207 speaker = GNUNET_SPEAKER_create_from_hardware(cfg);
209 GNUNET_assert (NULL != speaker); 208 GNUNET_assert(NULL != speaker);
210 switch_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 209 switch_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
211 &switch_to_speaker, 210 &switch_to_speaker,
212 NULL); 211 NULL);
213 st = GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 212 st = GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
214 NULL); 213 NULL);
215 fprintf (stderr, 214 fprintf(stderr,
216 _("We will now be recording you for %s. After that time, the recording will be played back to you..."), 215 _("We will now be recording you for %s. After that time, the recording will be played back to you..."),
217 GNUNET_STRINGS_relative_time_to_string (TIMEOUT, GNUNET_YES)); 216 GNUNET_STRINGS_relative_time_to_string(TIMEOUT, GNUNET_YES));
218 if (GNUNET_OK != 217 if (GNUNET_OK !=
219 microphone->enable_microphone (microphone->cls, 218 microphone->enable_microphone(microphone->cls,
220 &record, NULL)) 219 &record, NULL))
221 { 220 {
222 fprintf (stderr, 221 fprintf(stderr,
223 "Failed to enable microphone\n"); 222 "Failed to enable microphone\n");
224 ret = 1; 223 ret = 1;
225 GNUNET_SCHEDULER_shutdown (); 224 GNUNET_SCHEDULER_shutdown();
226 return; 225 return;
227 } 226 }
228} 227}
229 228
230 229
@@ -236,26 +235,26 @@ run (void *cls,
236 * @return 0 ok, 1 on error 235 * @return 0 ok, 1 on error
237 */ 236 */
238int 237int
239main (int argc, 238main(int argc,
240 char *const *argv) 239 char *const *argv)
241{ 240{
242 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 241 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
243 GNUNET_GETOPT_OPTION_END 242 GNUNET_GETOPT_OPTION_END
244 }; 243 };
245 244
246 if (GNUNET_OK != 245 if (GNUNET_OK !=
247 GNUNET_STRINGS_get_utf8_args (argc, argv, 246 GNUNET_STRINGS_get_utf8_args(argc, argv,
248 &argc, &argv)) 247 &argc, &argv))
249 return 2; 248 return 2;
250 249
251 ret = (GNUNET_OK == 250 ret = (GNUNET_OK ==
252 GNUNET_PROGRAM_run (argc, argv, 251 GNUNET_PROGRAM_run(argc, argv,
253 "gnunet-conversation-test", 252 "gnunet-conversation-test",
254 gettext_noop ("help text"), 253 gettext_noop("help text"),
255 options, 254 options,
256 &run, 255 &run,
257 NULL)) ? ret : 1; 256 NULL)) ? ret : 1;
258 GNUNET_free ((void*) argv); 257 GNUNET_free((void*)argv);
259 return ret; 258 return ret;
260} 259}
261 260