aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/test_conversation_api_twocalls.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-12-12 16:39:52 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-12-12 16:39:52 +0000
commitbd296395cf22a5357b5284a706b45cc497c3bcc0 (patch)
treef2f24c4f476f9ce6cfb741b66c4247d4e29a1d65 /src/conversation/test_conversation_api_twocalls.c
parent58cda642bdd13b46cb85b109a9d54f9c37dceebd (diff)
downloadgnunet-bd296395cf22a5357b5284a706b45cc497c3bcc0.tar.gz
gnunet-bd296395cf22a5357b5284a706b45cc497c3bcc0.zip
- fix testcase crash; debug code added
Diffstat (limited to 'src/conversation/test_conversation_api_twocalls.c')
-rw-r--r--src/conversation/test_conversation_api_twocalls.c144
1 files changed, 101 insertions, 43 deletions
diff --git a/src/conversation/test_conversation_api_twocalls.c b/src/conversation/test_conversation_api_twocalls.c
index 71b8f758c..7aa52f953 100644
--- a/src/conversation/test_conversation_api_twocalls.c
+++ b/src/conversation/test_conversation_api_twocalls.c
@@ -37,7 +37,7 @@
37 37
38#define FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) 38#define FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
39 39
40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25) 40#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 25)
41 41
42static int ok = 1; 42static int ok = 1;
43 43
@@ -69,13 +69,43 @@ static GNUNET_MICROPHONE_RecordedDataCallback phone_rdc;
69 69
70static void *phone_rdc_cls; 70static void *phone_rdc_cls;
71 71
72static GNUNET_MICROPHONE_RecordedDataCallback call_rdc; 72static GNUNET_SCHEDULER_TaskIdentifier phone_task;
73 73
74static void *call_rdc_cls; 74/**
75 * Variable for recognizing caller1
76 */
77static const char *caller1 = "caller1";
75 78
76static GNUNET_SCHEDULER_TaskIdentifier phone_task; 79/**
80 * Variable for recognizing caller2
81 */
82static const char *caller2 = "caller2";
77 83
78static GNUNET_SCHEDULER_TaskIdentifier call_task; 84/**
85 * Variable for recognizing callee
86 */
87static const char *phone0 = "phone";
88
89#define CALLER1 &caller1
90#define CALLER2 &caller2
91#define PHONE0 &phone0
92
93#define CLS_STR(caller) (*((char **)caller))
94
95struct MicContext
96{
97 GNUNET_MICROPHONE_RecordedDataCallback rdc;
98
99 void *rdc_cls;
100
101 GNUNET_SCHEDULER_TaskIdentifier call_task;
102
103 char sym;
104};
105
106static struct MicContext call1_mic_ctx;
107static struct MicContext call2_mic_ctx;
108//static struct MicContext phone_mic_ctx;
79 109
80 110
81static void 111static void
@@ -87,6 +117,7 @@ phone_send (void *cls,
87 GNUNET_assert (NULL != phone_rdc); 117 GNUNET_assert (NULL != phone_rdc);
88 GNUNET_snprintf (buf, sizeof (buf), "phone"); 118 GNUNET_snprintf (buf, sizeof (buf), "phone");
89 phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf); 119 phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf);
120 fprintf (stderr, "+");
90 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, 121 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ,
91 &phone_send, NULL); 122 &phone_send, NULL);
92} 123}
@@ -96,20 +127,22 @@ static void
96call_send (void *cls, 127call_send (void *cls,
97 const struct GNUNET_SCHEDULER_TaskContext *tc) 128 const struct GNUNET_SCHEDULER_TaskContext *tc)
98{ 129{
130 struct MicContext *mc = cls;
99 char buf[32]; 131 char buf[32];
100 132
101 GNUNET_assert (NULL != call_rdc); 133 GNUNET_assert (NULL != mc->rdc);
102 GNUNET_snprintf (buf, sizeof (buf), "call"); 134 GNUNET_snprintf (buf, sizeof (buf), "call");
103 call_rdc (call_rdc_cls, strlen (buf) + 1, buf); 135 mc->rdc (mc->rdc_cls, strlen (buf) + 1, buf);
104 call_task = GNUNET_SCHEDULER_add_delayed (FREQ, 136 fprintf (stderr, "%c", mc->sym);
105 &call_send, NULL); 137 mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ,
138 &call_send, mc);
106} 139}
107 140
108 141
109static int 142static int
110enable_speaker (void *cls) 143enable_speaker (void *cls)
111{ 144{
112 const char *origin = cls; 145 const char *origin = CLS_STR (cls);
113 146
114 fprintf (stderr, 147 fprintf (stderr,
115 "Speaker %s enabled\n", 148 "Speaker %s enabled\n",
@@ -121,7 +154,7 @@ enable_speaker (void *cls)
121static void 154static void
122disable_speaker (void *cls) 155disable_speaker (void *cls)
123{ 156{
124 const char *origin = cls; 157 const char *origin = CLS_STR (cls);
125 158
126 fprintf (stderr, 159 fprintf (stderr,
127 "Speaker %s disabled\n", 160 "Speaker %s disabled\n",
@@ -137,6 +170,7 @@ play (void *cls,
137 static unsigned int phone_i; 170 static unsigned int phone_i;
138 static unsigned int call_i; 171 static unsigned int call_i;
139 172
173 write (2, data, data_size);
140 if (0 == strncmp ("call", data, data_size)) 174 if (0 == strncmp ("call", data, data_size))
141 call_i++; 175 call_i++;
142 else if (0 == strncmp ("phone", data, data_size)) 176 else if (0 == strncmp ("phone", data, data_size))
@@ -151,7 +185,7 @@ play (void *cls,
151 185
152 if ( (20 < call_i) && 186 if ( (20 < call_i) &&
153 (20 < phone_i) && 187 (20 < phone_i) &&
154 (NULL != call2) ) 188 (CALLER2 == cls) )
155 { 189 {
156 /* time to hang up ... */ 190 /* time to hang up ... */
157 GNUNET_CONVERSATION_call_stop (call2); 191 GNUNET_CONVERSATION_call_stop (call2);
@@ -162,7 +196,7 @@ play (void *cls,
162 } 196 }
163 if ( (20 < call_i) && 197 if ( (20 < call_i) &&
164 (20 < phone_i) && 198 (20 < phone_i) &&
165 (NULL != call1) ) 199 (CALLER1 == cls) )
166 { 200 {
167 /* time to hang up ... */ 201 /* time to hang up ... */
168 GNUNET_CONVERSATION_call_stop (call1); 202 GNUNET_CONVERSATION_call_stop (call1);
@@ -174,18 +208,27 @@ play (void *cls,
174static void 208static void
175destroy_speaker (void *cls) 209destroy_speaker (void *cls)
176{ 210{
177 const char *origin = cls; 211 const char *origin = CLS_STR (cls);
178 212
179 fprintf (stderr, "Speaker %s destroyed\n", origin); 213 fprintf (stderr, "Speaker %s destroyed\n", origin);
180} 214}
181 215
182 216
183static struct GNUNET_SPEAKER_Handle call_speaker = { 217static struct GNUNET_SPEAKER_Handle call1_speaker = {
184 &enable_speaker, 218 &enable_speaker,
185 &play, 219 &play,
186 &disable_speaker, 220 &disable_speaker,
187 &destroy_speaker, 221 &destroy_speaker,
188 "caller" 222 CALLER1
223};
224
225
226static struct GNUNET_SPEAKER_Handle call2_speaker = {
227 &enable_speaker,
228 &play,
229 &disable_speaker,
230 &destroy_speaker,
231 CALLER2
189}; 232};
190 233
191 234
@@ -194,7 +237,7 @@ static struct GNUNET_SPEAKER_Handle phone_speaker = {
194 &play, 237 &play,
195 &disable_speaker, 238 &disable_speaker,
196 &destroy_speaker, 239 &destroy_speaker,
197 "phone" 240 PHONE0
198}; 241};
199 242
200 243
@@ -203,25 +246,26 @@ enable_mic (void *cls,
203 GNUNET_MICROPHONE_RecordedDataCallback rdc, 246 GNUNET_MICROPHONE_RecordedDataCallback rdc,
204 void *rdc_cls) 247 void *rdc_cls)
205{ 248{
206 const char *origin = cls; 249 const char *origin = CLS_STR (cls);
250 struct MicContext *mc;
207 251
208 fprintf (stderr, 252 fprintf (stderr,
209 "Mic %s enabled\n", 253 "Mic %s enabled\n",
210 origin); 254 origin);
211 if (0 == strcmp (origin, "phone")) 255 if (PHONE0 == cls)
212 { 256 {
213 phone_rdc = rdc; 257 phone_rdc = rdc;
214 phone_rdc_cls = rdc_cls; 258 phone_rdc_cls = rdc_cls;
215 GNUNET_break (GNUNET_SCHEDULER_NO_TASK == phone_task); 259 GNUNET_break (GNUNET_SCHEDULER_NO_TASK == phone_task);
216 phone_task = GNUNET_SCHEDULER_add_now (&phone_send, NULL); 260 phone_task = GNUNET_SCHEDULER_add_now (&phone_send, NULL);
261 return GNUNET_OK;
217 } 262 }
218 else 263 mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx;
219 { 264 mc->sym = (CALLER1 == cls) ? '1': '2';
220 call_rdc = rdc; 265 mc->rdc = rdc;
221 call_rdc_cls = rdc_cls; 266 mc->rdc_cls = rdc_cls;
222 GNUNET_break (GNUNET_SCHEDULER_NO_TASK == call_task); 267 GNUNET_break (GNUNET_SCHEDULER_NO_TASK == mc->call_task);
223 call_task = GNUNET_SCHEDULER_add_now (&call_send, NULL); 268 mc->call_task = GNUNET_SCHEDULER_add_now (&call_send, mc);
224 }
225 return GNUNET_OK; 269 return GNUNET_OK;
226} 270}
227 271
@@ -229,32 +273,32 @@ enable_mic (void *cls,
229static void 273static void
230disable_mic (void *cls) 274disable_mic (void *cls)
231{ 275{
232 const char *origin = cls; 276 const char *origin = CLS_STR (cls);
277 struct MicContext *mc;
233 278
234 fprintf (stderr, 279 fprintf (stderr,
235 "Mic %s disabled\n", 280 "Mic %s disabled\n",
236 origin); 281 origin);
237 if (0 == strcmp (origin, "phone")) 282 if (PHONE0 == cls)
238 { 283 {
239 phone_rdc = NULL; 284 phone_rdc = NULL;
240 phone_rdc_cls = NULL; 285 phone_rdc_cls = NULL;
241 GNUNET_SCHEDULER_cancel (phone_task); 286 GNUNET_SCHEDULER_cancel (phone_task);
242 phone_task = GNUNET_SCHEDULER_NO_TASK; 287 phone_task = GNUNET_SCHEDULER_NO_TASK;
288 return;
243 } 289 }
244 else 290 mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx;
245 { 291 mc->rdc = NULL;
246 call_rdc = NULL; 292 mc->rdc_cls = NULL;
247 call_rdc_cls = NULL; 293 GNUNET_SCHEDULER_cancel (mc->call_task);
248 GNUNET_SCHEDULER_cancel (call_task); 294 mc->call_task = GNUNET_SCHEDULER_NO_TASK;
249 call_task = GNUNET_SCHEDULER_NO_TASK;
250 }
251} 295}
252 296
253 297
254static void 298static void
255destroy_mic (void *cls) 299destroy_mic (void *cls)
256{ 300{
257 const char *origin = cls; 301 const char *origin = CLS_STR (cls);
258 302
259 fprintf (stderr, 303 fprintf (stderr,
260 "Mic %s destroyed\n", 304 "Mic %s destroyed\n",
@@ -262,11 +306,19 @@ destroy_mic (void *cls)
262} 306}
263 307
264 308
265static struct GNUNET_MICROPHONE_Handle call_mic = { 309static struct GNUNET_MICROPHONE_Handle call1_mic = {
266 &enable_mic, 310 &enable_mic,
267 &disable_mic, 311 &disable_mic,
268 &destroy_mic, 312 &destroy_mic,
269 "caller" 313 CALLER1
314};
315
316
317static struct GNUNET_MICROPHONE_Handle call2_mic = {
318 &enable_mic,
319 &disable_mic,
320 &destroy_mic,
321 CALLER2
270}; 322};
271 323
272 324
@@ -274,7 +326,7 @@ static struct GNUNET_MICROPHONE_Handle phone_mic = {
274 &enable_mic, 326 &enable_mic,
275 &disable_mic, 327 &disable_mic,
276 &destroy_mic, 328 &destroy_mic,
277 "phone" 329 PHONE0
278}; 330};
279 331
280 332
@@ -410,16 +462,22 @@ call_event_handler (void *cls,
410 case GNUNET_CONVERSATION_EC_CALL_RINGING: 462 case GNUNET_CONVERSATION_EC_CALL_RINGING:
411 break; 463 break;
412 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: 464 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
465 fprintf (stderr, "\t Call %s picked\n", cid);
413 break; 466 break;
414 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: 467 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
468 fprintf (stderr, "\t Call %s GNS lookup failed \n", cid);
415 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: 469 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
470 fprintf (stderr, "\t Call %s hungup\n", cid);
416 if (0 == strcmp (cid, "call1")) 471 if (0 == strcmp (cid, "call1"))
417 call1 = NULL; 472 call1 = NULL;
418 else 473 else
419 call2 = NULL; 474 call2 = NULL;
420 break; 475 break;
421 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: 476 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
477 fprintf (stderr, "\t Call %s suspended\n", cid);
478 break;
422 case GNUNET_CONVERSATION_EC_CALL_RESUMED: 479 case GNUNET_CONVERSATION_EC_CALL_RESUMED:
480 fprintf (stderr, "\t Call %s resumed\n", cid);
423 break; 481 break;
424 } 482 }
425} 483}
@@ -494,15 +552,15 @@ identity_cb (void *cls,
494 call1 = GNUNET_CONVERSATION_call_start (cfg, 552 call1 = GNUNET_CONVERSATION_call_start (cfg,
495 ego, 553 ego,
496 gns_name, 554 gns_name,
497 &call_speaker, 555 &call1_speaker,
498 &call_mic, 556 &call1_mic,
499 &call_event_handler, 557 &call_event_handler,
500 (void *) "call1"); 558 (void *) "call1");
501 call2 = GNUNET_CONVERSATION_call_start (cfg, 559 call2 = GNUNET_CONVERSATION_call_start (cfg,
502 ego, 560 ego,
503 gns_name, 561 gns_name,
504 &call_speaker, 562 &call2_speaker,
505 &call_mic, 563 &call2_mic,
506 &call_event_handler, 564 &call_event_handler,
507 (void *) "call2"); 565 (void *) "call2");
508 return; 566 return;