diff options
Diffstat (limited to 'src/conversation/conversation_api.c')
-rw-r--r-- | src/conversation/conversation_api.c | 668 |
1 files changed, 338 insertions, 330 deletions
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c index 4c19a7d2d..eb070e56e 100644 --- a/src/conversation/conversation_api.c +++ b/src/conversation/conversation_api.c | |||
@@ -33,7 +33,8 @@ | |||
33 | /** | 33 | /** |
34 | * Possible states of a caller. | 34 | * Possible states of a caller. |
35 | */ | 35 | */ |
36 | enum CallerState { | 36 | enum CallerState |
37 | { | ||
37 | /** | 38 | /** |
38 | * The phone is ringing (user knows about incoming call). | 39 | * The phone is ringing (user knows about incoming call). |
39 | */ | 40 | */ |
@@ -65,7 +66,8 @@ enum CallerState { | |||
65 | /** | 66 | /** |
66 | * A caller is the handle we have for an incoming call. | 67 | * A caller is the handle we have for an incoming call. |
67 | */ | 68 | */ |
68 | struct GNUNET_CONVERSATION_Caller { | 69 | struct GNUNET_CONVERSATION_Caller |
70 | { | ||
69 | /** | 71 | /** |
70 | * We keep all callers in a DLL. | 72 | * We keep all callers in a DLL. |
71 | */ | 73 | */ |
@@ -121,7 +123,8 @@ struct GNUNET_CONVERSATION_Caller { | |||
121 | /** | 123 | /** |
122 | * Possible states of a phone. | 124 | * Possible states of a phone. |
123 | */ | 125 | */ |
124 | enum PhoneState { | 126 | enum PhoneState |
127 | { | ||
125 | /** | 128 | /** |
126 | * We still need to register the phone. | 129 | * We still need to register the phone. |
127 | */ | 130 | */ |
@@ -145,7 +148,8 @@ enum PhoneState { | |||
145 | * something rather internal to a phone and not obvious from it). | 148 | * something rather internal to a phone and not obvious from it). |
146 | * You can only have one conversation per phone at any time. | 149 | * You can only have one conversation per phone at any time. |
147 | */ | 150 | */ |
148 | struct GNUNET_CONVERSATION_Phone { | 151 | struct GNUNET_CONVERSATION_Phone |
152 | { | ||
149 | /** | 153 | /** |
150 | * Our configuration. | 154 | * Our configuration. |
151 | */ | 155 | */ |
@@ -204,7 +208,7 @@ struct GNUNET_CONVERSATION_Phone { | |||
204 | * @param phone phone to reconnect | 208 | * @param phone phone to reconnect |
205 | */ | 209 | */ |
206 | static void | 210 | static void |
207 | reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone); | 211 | reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone); |
208 | 212 | ||
209 | 213 | ||
210 | /** | 214 | /** |
@@ -215,24 +219,24 @@ reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone); | |||
215 | * @param data audio data to play | 219 | * @param data audio data to play |
216 | */ | 220 | */ |
217 | static void | 221 | static void |
218 | transmit_phone_audio(void *cls, | 222 | transmit_phone_audio (void *cls, |
219 | size_t data_size, | 223 | size_t data_size, |
220 | const void *data) | 224 | const void *data) |
221 | { | 225 | { |
222 | struct GNUNET_CONVERSATION_Caller *caller = cls; | 226 | struct GNUNET_CONVERSATION_Caller *caller = cls; |
223 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 227 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
224 | struct GNUNET_MQ_Envelope *e; | 228 | struct GNUNET_MQ_Envelope *e; |
225 | struct ClientAudioMessage *am; | 229 | struct ClientAudioMessage *am; |
226 | 230 | ||
227 | e = GNUNET_MQ_msg_extra(am, | 231 | e = GNUNET_MQ_msg_extra (am, |
228 | data_size, | 232 | data_size, |
229 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); | 233 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO); |
230 | am->cid = caller->cid; | 234 | am->cid = caller->cid; |
231 | GNUNET_memcpy(&am[1], | 235 | GNUNET_memcpy (&am[1], |
232 | data, | 236 | data, |
233 | data_size); | 237 | data_size); |
234 | GNUNET_MQ_send(phone->mq, | 238 | GNUNET_MQ_send (phone->mq, |
235 | e); | 239 | e); |
236 | } | 240 | } |
237 | 241 | ||
238 | 242 | ||
@@ -243,33 +247,33 @@ transmit_phone_audio(void *cls, | |||
243 | * @param ring the message | 247 | * @param ring the message |
244 | */ | 248 | */ |
245 | static void | 249 | static void |
246 | handle_phone_ring(void *cls, | 250 | handle_phone_ring (void *cls, |
247 | const struct ClientPhoneRingMessage *ring) | 251 | const struct ClientPhoneRingMessage *ring) |
248 | { | 252 | { |
249 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 253 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
250 | struct GNUNET_CONVERSATION_Caller *caller; | 254 | struct GNUNET_CONVERSATION_Caller *caller; |
251 | 255 | ||
252 | switch (phone->state) | 256 | switch (phone->state) |
253 | { | 257 | { |
254 | case PS_REGISTER: | 258 | case PS_REGISTER: |
255 | GNUNET_assert(0); | 259 | GNUNET_assert (0); |
256 | break; | 260 | break; |
257 | 261 | ||
258 | case PS_READY: | 262 | case PS_READY: |
259 | caller = GNUNET_new(struct GNUNET_CONVERSATION_Caller); | 263 | caller = GNUNET_new (struct GNUNET_CONVERSATION_Caller); |
260 | caller->phone = phone; | 264 | caller->phone = phone; |
261 | GNUNET_CONTAINER_DLL_insert(phone->caller_head, | 265 | GNUNET_CONTAINER_DLL_insert (phone->caller_head, |
262 | phone->caller_tail, | 266 | phone->caller_tail, |
263 | caller); | 267 | caller); |
264 | caller->caller_id = ring->caller_id; | 268 | caller->caller_id = ring->caller_id; |
265 | caller->cid = ring->cid; | 269 | caller->cid = ring->cid; |
266 | caller->state = CS_RINGING; | 270 | caller->state = CS_RINGING; |
267 | phone->event_handler(phone->event_handler_cls, | 271 | phone->event_handler (phone->event_handler_cls, |
268 | GNUNET_CONVERSATION_EC_PHONE_RING, | 272 | GNUNET_CONVERSATION_EC_PHONE_RING, |
269 | caller, | 273 | caller, |
270 | &caller->caller_id); | 274 | &caller->caller_id); |
271 | break; | 275 | break; |
272 | } | 276 | } |
273 | } | 277 | } |
274 | 278 | ||
275 | 279 | ||
@@ -281,8 +285,8 @@ handle_phone_ring(void *cls, | |||
281 | * @return NULL if @a cid was not found | 285 | * @return NULL if @a cid was not found |
282 | */ | 286 | */ |
283 | static struct GNUNET_CONVERSATION_Caller * | 287 | static struct GNUNET_CONVERSATION_Caller * |
284 | find_caller(struct GNUNET_CONVERSATION_Phone *phone, | 288 | find_caller (struct GNUNET_CONVERSATION_Phone *phone, |
285 | uint32_t cid) | 289 | uint32_t cid) |
286 | { | 290 | { |
287 | struct GNUNET_CONVERSATION_Caller *caller; | 291 | struct GNUNET_CONVERSATION_Caller *caller; |
288 | 292 | ||
@@ -300,56 +304,56 @@ find_caller(struct GNUNET_CONVERSATION_Phone *phone, | |||
300 | * @param msg the message | 304 | * @param msg the message |
301 | */ | 305 | */ |
302 | static void | 306 | static void |
303 | handle_phone_hangup(void *cls, | 307 | handle_phone_hangup (void *cls, |
304 | const struct ClientPhoneHangupMessage *hang) | 308 | const struct ClientPhoneHangupMessage *hang) |
305 | { | 309 | { |
306 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 310 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
307 | struct GNUNET_CONVERSATION_Caller *caller; | 311 | struct GNUNET_CONVERSATION_Caller *caller; |
308 | 312 | ||
309 | caller = find_caller(phone, | 313 | caller = find_caller (phone, |
310 | hang->cid); | 314 | hang->cid); |
311 | if (NULL == caller) | 315 | if (NULL == caller) |
312 | { | 316 | { |
313 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
314 | "Received HANG_UP message for unknown caller ID %u\n", | 318 | "Received HANG_UP message for unknown caller ID %u\n", |
315 | (unsigned int)hang->cid); | 319 | (unsigned int) hang->cid); |
316 | return; | 320 | return; |
317 | } | 321 | } |
318 | 322 | ||
319 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
320 | "Received HANG_UP message, terminating call with `%s'\n", | 324 | "Received HANG_UP message, terminating call with `%s'\n", |
321 | GNUNET_GNSRECORD_pkey_to_zkey(&caller->caller_id)); | 325 | GNUNET_GNSRECORD_pkey_to_zkey (&caller->caller_id)); |
322 | switch (caller->state) | 326 | switch (caller->state) |
323 | { | 327 | { |
324 | case CS_RINGING: | 328 | case CS_RINGING: |
325 | phone->event_handler(phone->event_handler_cls, | 329 | phone->event_handler (phone->event_handler_cls, |
326 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | 330 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, |
327 | caller, | 331 | caller, |
328 | &caller->caller_id); | 332 | &caller->caller_id); |
329 | break; | 333 | break; |
330 | 334 | ||
331 | case CS_ACTIVE: | 335 | case CS_ACTIVE: |
332 | caller->speaker->disable_speaker(caller->speaker->cls); | 336 | caller->speaker->disable_speaker (caller->speaker->cls); |
333 | caller->mic->disable_microphone(caller->mic->cls); | 337 | caller->mic->disable_microphone (caller->mic->cls); |
334 | phone->event_handler(phone->event_handler_cls, | 338 | phone->event_handler (phone->event_handler_cls, |
335 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | 339 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, |
336 | caller, | 340 | caller, |
337 | &caller->caller_id); | 341 | &caller->caller_id); |
338 | break; | 342 | break; |
339 | 343 | ||
340 | case CS_CALLEE_SUSPENDED: | 344 | case CS_CALLEE_SUSPENDED: |
341 | case CS_CALLER_SUSPENDED: | 345 | case CS_CALLER_SUSPENDED: |
342 | case CS_BOTH_SUSPENDED: | 346 | case CS_BOTH_SUSPENDED: |
343 | phone->event_handler(phone->event_handler_cls, | 347 | phone->event_handler (phone->event_handler_cls, |
344 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | 348 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, |
345 | caller, | 349 | caller, |
346 | &caller->caller_id); | 350 | &caller->caller_id); |
347 | break; | 351 | break; |
348 | } | 352 | } |
349 | GNUNET_CONTAINER_DLL_remove(phone->caller_head, | 353 | GNUNET_CONTAINER_DLL_remove (phone->caller_head, |
350 | phone->caller_tail, | 354 | phone->caller_tail, |
351 | caller); | 355 | caller); |
352 | GNUNET_free(caller); | 356 | GNUNET_free (caller); |
353 | } | 357 | } |
354 | 358 | ||
355 | 359 | ||
@@ -360,41 +364,41 @@ handle_phone_hangup(void *cls, | |||
360 | * @param suspend the message | 364 | * @param suspend the message |
361 | */ | 365 | */ |
362 | static void | 366 | static void |
363 | handle_phone_suspend(void *cls, | 367 | handle_phone_suspend (void *cls, |
364 | const struct ClientPhoneSuspendMessage *suspend) | 368 | const struct ClientPhoneSuspendMessage *suspend) |
365 | { | 369 | { |
366 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 370 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
367 | struct GNUNET_CONVERSATION_Caller *caller; | 371 | struct GNUNET_CONVERSATION_Caller *caller; |
368 | 372 | ||
369 | caller = find_caller(phone, | 373 | caller = find_caller (phone, |
370 | suspend->cid); | 374 | suspend->cid); |
371 | if (NULL == caller) | 375 | if (NULL == caller) |
372 | return; | 376 | return; |
373 | switch (caller->state) | 377 | switch (caller->state) |
374 | { | 378 | { |
375 | case CS_RINGING: | 379 | case CS_RINGING: |
376 | GNUNET_break_op(0); | 380 | GNUNET_break_op (0); |
377 | break; | 381 | break; |
378 | 382 | ||
379 | case CS_ACTIVE: | 383 | case CS_ACTIVE: |
380 | caller->state = CS_CALLER_SUSPENDED; | 384 | caller->state = CS_CALLER_SUSPENDED; |
381 | caller->speaker->disable_speaker(caller->speaker->cls); | 385 | caller->speaker->disable_speaker (caller->speaker->cls); |
382 | caller->mic->disable_microphone(caller->mic->cls); | 386 | caller->mic->disable_microphone (caller->mic->cls); |
383 | caller->event_handler(caller->event_handler_cls, | 387 | caller->event_handler (caller->event_handler_cls, |
384 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); | 388 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); |
385 | break; | 389 | break; |
386 | 390 | ||
387 | case CS_CALLEE_SUSPENDED: | 391 | case CS_CALLEE_SUSPENDED: |
388 | caller->state = CS_BOTH_SUSPENDED; | 392 | caller->state = CS_BOTH_SUSPENDED; |
389 | caller->event_handler(caller->event_handler_cls, | 393 | caller->event_handler (caller->event_handler_cls, |
390 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); | 394 | GNUNET_CONVERSATION_EC_CALLER_SUSPEND); |
391 | break; | 395 | break; |
392 | 396 | ||
393 | case CS_CALLER_SUSPENDED: | 397 | case CS_CALLER_SUSPENDED: |
394 | case CS_BOTH_SUSPENDED: | 398 | case CS_BOTH_SUSPENDED: |
395 | GNUNET_break_op(0); | 399 | GNUNET_break_op (0); |
396 | break; | 400 | break; |
397 | } | 401 | } |
398 | } | 402 | } |
399 | 403 | ||
400 | 404 | ||
@@ -405,43 +409,43 @@ handle_phone_suspend(void *cls, | |||
405 | * @param resume the message | 409 | * @param resume the message |
406 | */ | 410 | */ |
407 | static void | 411 | static void |
408 | handle_phone_resume(void *cls, | 412 | handle_phone_resume (void *cls, |
409 | const struct ClientPhoneResumeMessage *resume) | 413 | const struct ClientPhoneResumeMessage *resume) |
410 | { | 414 | { |
411 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 415 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
412 | struct GNUNET_CONVERSATION_Caller *caller; | 416 | struct GNUNET_CONVERSATION_Caller *caller; |
413 | 417 | ||
414 | caller = find_caller(phone, | 418 | caller = find_caller (phone, |
415 | resume->cid); | 419 | resume->cid); |
416 | if (NULL == caller) | 420 | if (NULL == caller) |
417 | return; | 421 | return; |
418 | switch (caller->state) | 422 | switch (caller->state) |
419 | { | 423 | { |
420 | case CS_RINGING: | 424 | case CS_RINGING: |
421 | GNUNET_break_op(0); | 425 | GNUNET_break_op (0); |
422 | break; | 426 | break; |
423 | 427 | ||
424 | case CS_ACTIVE: | 428 | case CS_ACTIVE: |
425 | case CS_CALLEE_SUSPENDED: | 429 | case CS_CALLEE_SUSPENDED: |
426 | GNUNET_break_op(0); | 430 | GNUNET_break_op (0); |
427 | break; | 431 | break; |
428 | 432 | ||
429 | case CS_CALLER_SUSPENDED: | 433 | case CS_CALLER_SUSPENDED: |
430 | caller->state = CS_ACTIVE; | 434 | caller->state = CS_ACTIVE; |
431 | caller->speaker->enable_speaker(caller->speaker->cls); | 435 | caller->speaker->enable_speaker (caller->speaker->cls); |
432 | caller->mic->enable_microphone(caller->mic->cls, | 436 | caller->mic->enable_microphone (caller->mic->cls, |
433 | &transmit_phone_audio, | 437 | &transmit_phone_audio, |
434 | caller); | 438 | caller); |
435 | caller->event_handler(caller->event_handler_cls, | 439 | caller->event_handler (caller->event_handler_cls, |
436 | GNUNET_CONVERSATION_EC_CALLER_RESUME); | 440 | GNUNET_CONVERSATION_EC_CALLER_RESUME); |
437 | break; | 441 | break; |
438 | 442 | ||
439 | case CS_BOTH_SUSPENDED: | 443 | case CS_BOTH_SUSPENDED: |
440 | caller->state = CS_CALLEE_SUSPENDED; | 444 | caller->state = CS_CALLEE_SUSPENDED; |
441 | caller->event_handler(caller->event_handler_cls, | 445 | caller->event_handler (caller->event_handler_cls, |
442 | GNUNET_CONVERSATION_EC_CALLER_RESUME); | 446 | GNUNET_CONVERSATION_EC_CALLER_RESUME); |
443 | break; | 447 | break; |
444 | } | 448 | } |
445 | } | 449 | } |
446 | 450 | ||
447 | 451 | ||
@@ -453,11 +457,11 @@ handle_phone_resume(void *cls, | |||
453 | * @return #GNUNET_OK if @a am is well-formed | 457 | * @return #GNUNET_OK if @a am is well-formed |
454 | */ | 458 | */ |
455 | static int | 459 | static int |
456 | check_phone_audio(void *cls, | 460 | check_phone_audio (void *cls, |
457 | const struct ClientAudioMessage *am) | 461 | const struct ClientAudioMessage *am) |
458 | { | 462 | { |
459 | (void)cls; | 463 | (void) cls; |
460 | (void)am; | 464 | (void) am; |
461 | 465 | ||
462 | /* any variable-size payload is OK */ | 466 | /* any variable-size payload is OK */ |
463 | return GNUNET_OK; | 467 | return GNUNET_OK; |
@@ -471,33 +475,34 @@ check_phone_audio(void *cls, | |||
471 | * @param am the message | 475 | * @param am the message |
472 | */ | 476 | */ |
473 | static void | 477 | static void |
474 | handle_phone_audio(void *cls, | 478 | handle_phone_audio (void *cls, |
475 | const struct ClientAudioMessage *am) | 479 | const struct ClientAudioMessage *am) |
476 | { | 480 | { |
477 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 481 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
478 | struct GNUNET_CONVERSATION_Caller *caller; | 482 | struct GNUNET_CONVERSATION_Caller *caller; |
479 | 483 | ||
480 | caller = find_caller(phone, | 484 | caller = find_caller (phone, |
481 | am->cid); | 485 | am->cid); |
482 | if (NULL == caller) | 486 | if (NULL == caller) |
483 | return; | 487 | return; |
484 | switch (caller->state) | 488 | switch (caller->state) |
485 | { | 489 | { |
486 | case CS_RINGING: | 490 | case CS_RINGING: |
487 | GNUNET_break_op(0); | 491 | GNUNET_break_op (0); |
488 | break; | 492 | break; |
489 | 493 | ||
490 | case CS_ACTIVE: | 494 | case CS_ACTIVE: |
491 | caller->speaker->play(caller->speaker->cls, | 495 | caller->speaker->play (caller->speaker->cls, |
492 | ntohs(am->header.size) - sizeof(struct ClientAudioMessage), | 496 | ntohs (am->header.size) - sizeof(struct |
493 | &am[1]); | 497 | ClientAudioMessage), |
494 | break; | 498 | &am[1]); |
495 | 499 | break; | |
496 | case CS_CALLEE_SUSPENDED: | 500 | |
497 | case CS_CALLER_SUSPENDED: | 501 | case CS_CALLEE_SUSPENDED: |
498 | case CS_BOTH_SUSPENDED: | 502 | case CS_CALLER_SUSPENDED: |
499 | break; | 503 | case CS_BOTH_SUSPENDED: |
500 | } | 504 | break; |
505 | } | ||
501 | } | 506 | } |
502 | 507 | ||
503 | 508 | ||
@@ -508,15 +513,16 @@ handle_phone_audio(void *cls, | |||
508 | * @param error details about the error | 513 | * @param error details about the error |
509 | */ | 514 | */ |
510 | static void | 515 | static void |
511 | phone_error_handler(void *cls, | 516 | phone_error_handler (void *cls, |
512 | enum GNUNET_MQ_Error error) | 517 | enum GNUNET_MQ_Error error) |
513 | { | 518 | { |
514 | struct GNUNET_CONVERSATION_Phone *phone = cls; | 519 | struct GNUNET_CONVERSATION_Phone *phone = cls; |
515 | 520 | ||
516 | (void)error; | 521 | (void) error; |
517 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 522 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
518 | _("Connection to conversation service lost, trying to reconnect\n")); | 523 | _ ( |
519 | reconnect_phone(phone); | 524 | "Connection to conversation service lost, trying to reconnect\n")); |
525 | reconnect_phone (phone); | ||
520 | } | 526 | } |
521 | 527 | ||
522 | 528 | ||
@@ -526,25 +532,25 @@ phone_error_handler(void *cls, | |||
526 | * @param phone phone to clean up callers for | 532 | * @param phone phone to clean up callers for |
527 | */ | 533 | */ |
528 | static void | 534 | static void |
529 | clean_up_callers(struct GNUNET_CONVERSATION_Phone *phone) | 535 | clean_up_callers (struct GNUNET_CONVERSATION_Phone *phone) |
530 | { | 536 | { |
531 | struct GNUNET_CONVERSATION_Caller *caller; | 537 | struct GNUNET_CONVERSATION_Caller *caller; |
532 | 538 | ||
533 | while (NULL != (caller = phone->caller_head)) | 539 | while (NULL != (caller = phone->caller_head)) |
540 | { | ||
541 | /* make sure mic/speaker are disabled *before* callback */ | ||
542 | if (CS_ACTIVE == caller->state) | ||
534 | { | 543 | { |
535 | /* make sure mic/speaker are disabled *before* callback */ | 544 | caller->speaker->disable_speaker (caller->speaker->cls); |
536 | if (CS_ACTIVE == caller->state) | 545 | caller->mic->disable_microphone (caller->mic->cls); |
537 | { | 546 | caller->state = CS_CALLER_SUSPENDED; |
538 | caller->speaker->disable_speaker(caller->speaker->cls); | ||
539 | caller->mic->disable_microphone(caller->mic->cls); | ||
540 | caller->state = CS_CALLER_SUSPENDED; | ||
541 | } | ||
542 | phone->event_handler(phone->event_handler_cls, | ||
543 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | ||
544 | caller, | ||
545 | &caller->caller_id); | ||
546 | GNUNET_CONVERSATION_caller_hang_up(caller); | ||
547 | } | 547 | } |
548 | phone->event_handler (phone->event_handler_cls, | ||
549 | GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, | ||
550 | caller, | ||
551 | &caller->caller_id); | ||
552 | GNUNET_CONVERSATION_caller_hang_up (caller); | ||
553 | } | ||
548 | } | 554 | } |
549 | 555 | ||
550 | 556 | ||
@@ -554,53 +560,53 @@ clean_up_callers(struct GNUNET_CONVERSATION_Phone *phone) | |||
554 | * @param phone phone to reconnect | 560 | * @param phone phone to reconnect |
555 | */ | 561 | */ |
556 | static void | 562 | static void |
557 | reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone) | 563 | reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone) |
558 | { | 564 | { |
559 | struct GNUNET_MQ_MessageHandler handlers[] = { | 565 | struct GNUNET_MQ_MessageHandler handlers[] = { |
560 | GNUNET_MQ_hd_fixed_size(phone_ring, | 566 | GNUNET_MQ_hd_fixed_size (phone_ring, |
561 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING, | 567 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING, |
562 | struct ClientPhoneRingMessage, | 568 | struct ClientPhoneRingMessage, |
563 | phone), | 569 | phone), |
564 | GNUNET_MQ_hd_fixed_size(phone_hangup, | 570 | GNUNET_MQ_hd_fixed_size (phone_hangup, |
565 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, | 571 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, |
566 | struct ClientPhoneHangupMessage, | 572 | struct ClientPhoneHangupMessage, |
567 | phone), | 573 | phone), |
568 | GNUNET_MQ_hd_fixed_size(phone_suspend, | 574 | GNUNET_MQ_hd_fixed_size (phone_suspend, |
569 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, | 575 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, |
570 | struct ClientPhoneSuspendMessage, | 576 | struct ClientPhoneSuspendMessage, |
571 | phone), | 577 | phone), |
572 | GNUNET_MQ_hd_fixed_size(phone_resume, | 578 | GNUNET_MQ_hd_fixed_size (phone_resume, |
573 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, | 579 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, |
574 | struct ClientPhoneResumeMessage, | 580 | struct ClientPhoneResumeMessage, |
575 | phone), | 581 | phone), |
576 | GNUNET_MQ_hd_var_size(phone_audio, | 582 | GNUNET_MQ_hd_var_size (phone_audio, |
577 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, | 583 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, |
578 | struct ClientAudioMessage, | 584 | struct ClientAudioMessage, |
579 | phone), | 585 | phone), |
580 | GNUNET_MQ_handler_end() | 586 | GNUNET_MQ_handler_end () |
581 | }; | 587 | }; |
582 | struct GNUNET_MQ_Envelope *e; | 588 | struct GNUNET_MQ_Envelope *e; |
583 | struct ClientPhoneRegisterMessage *reg; | 589 | struct ClientPhoneRegisterMessage *reg; |
584 | 590 | ||
585 | clean_up_callers(phone); | 591 | clean_up_callers (phone); |
586 | if (NULL != phone->mq) | 592 | if (NULL != phone->mq) |
587 | { | 593 | { |
588 | GNUNET_MQ_destroy(phone->mq); | 594 | GNUNET_MQ_destroy (phone->mq); |
589 | phone->mq = NULL; | 595 | phone->mq = NULL; |
590 | } | 596 | } |
591 | phone->state = PS_REGISTER; | 597 | phone->state = PS_REGISTER; |
592 | phone->mq = GNUNET_CLIENT_connect(phone->cfg, | 598 | phone->mq = GNUNET_CLIENT_connect (phone->cfg, |
593 | "conversation", | 599 | "conversation", |
594 | handlers, | 600 | handlers, |
595 | &phone_error_handler, | 601 | &phone_error_handler, |
596 | phone); | 602 | phone); |
597 | if (NULL == phone->mq) | 603 | if (NULL == phone->mq) |
598 | return; | 604 | return; |
599 | e = GNUNET_MQ_msg(reg, | 605 | e = GNUNET_MQ_msg (reg, |
600 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER); | 606 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER); |
601 | reg->line_port = phone->my_record.line_port; | 607 | reg->line_port = phone->my_record.line_port; |
602 | GNUNET_MQ_send(phone->mq, | 608 | GNUNET_MQ_send (phone->mq, |
603 | e); | 609 | e); |
604 | phone->state = PS_READY; | 610 | phone->state = PS_READY; |
605 | } | 611 | } |
606 | 612 | ||
@@ -616,54 +622,55 @@ reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone) | |||
616 | * @return NULL on error (no valid line configured) | 622 | * @return NULL on error (no valid line configured) |
617 | */ | 623 | */ |
618 | struct GNUNET_CONVERSATION_Phone * | 624 | struct GNUNET_CONVERSATION_Phone * |
619 | GNUNET_CONVERSATION_phone_create(const struct GNUNET_CONFIGURATION_Handle *cfg, | 625 | GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg, |
620 | const struct GNUNET_IDENTITY_Ego *ego, | 626 | const struct GNUNET_IDENTITY_Ego *ego, |
621 | GNUNET_CONVERSATION_PhoneEventHandler event_handler, | 627 | GNUNET_CONVERSATION_PhoneEventHandler |
622 | void *event_handler_cls) | 628 | event_handler, |
629 | void *event_handler_cls) | ||
623 | { | 630 | { |
624 | struct GNUNET_CONVERSATION_Phone *phone; | 631 | struct GNUNET_CONVERSATION_Phone *phone; |
625 | char *line; | 632 | char *line; |
626 | struct GNUNET_HashCode line_port; | 633 | struct GNUNET_HashCode line_port; |
627 | 634 | ||
628 | if (GNUNET_OK != | 635 | if (GNUNET_OK != |
629 | GNUNET_CONFIGURATION_get_value_string(cfg, | 636 | GNUNET_CONFIGURATION_get_value_string (cfg, |
630 | "CONVERSATION", | 637 | "CONVERSATION", |
631 | "LINE", | 638 | "LINE", |
632 | &line)) | 639 | &line)) |
633 | { | 640 | { |
634 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 641 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
635 | "CONVERSATION", | 642 | "CONVERSATION", |
636 | "LINE"); | 643 | "LINE"); |
637 | return NULL; | 644 | return NULL; |
638 | } | 645 | } |
639 | GNUNET_CRYPTO_hash(line, | 646 | GNUNET_CRYPTO_hash (line, |
640 | strlen(line), | 647 | strlen (line), |
641 | &line_port); | 648 | &line_port); |
642 | phone = GNUNET_new(struct GNUNET_CONVERSATION_Phone); | 649 | phone = GNUNET_new (struct GNUNET_CONVERSATION_Phone); |
643 | if (GNUNET_OK != | 650 | if (GNUNET_OK != |
644 | GNUNET_CRYPTO_get_peer_identity(cfg, | 651 | GNUNET_CRYPTO_get_peer_identity (cfg, |
645 | &phone->my_record.peer)) | 652 | &phone->my_record.peer)) |
646 | { | 653 | { |
647 | GNUNET_break(0); | 654 | GNUNET_break (0); |
648 | GNUNET_free(phone); | 655 | GNUNET_free (phone); |
649 | return NULL; | 656 | return NULL; |
650 | } | 657 | } |
651 | phone->cfg = cfg; | 658 | phone->cfg = cfg; |
652 | phone->my_zone = *GNUNET_IDENTITY_ego_get_private_key(ego); | 659 | phone->my_zone = *GNUNET_IDENTITY_ego_get_private_key (ego); |
653 | phone->event_handler = event_handler; | 660 | phone->event_handler = event_handler; |
654 | phone->event_handler_cls = event_handler_cls; | 661 | phone->event_handler_cls = event_handler_cls; |
655 | phone->ns = GNUNET_NAMESTORE_connect(cfg); | 662 | phone->ns = GNUNET_NAMESTORE_connect (cfg); |
656 | phone->my_record.version = htonl(1); | 663 | phone->my_record.version = htonl (1); |
657 | phone->my_record.reserved = htonl(0); | 664 | phone->my_record.reserved = htonl (0); |
658 | phone->my_record.line_port = line_port; | 665 | phone->my_record.line_port = line_port; |
659 | reconnect_phone(phone); | 666 | reconnect_phone (phone); |
660 | if ((NULL == phone->mq) || | 667 | if ((NULL == phone->mq) || |
661 | (NULL == phone->ns)) | 668 | (NULL == phone->ns)) |
662 | { | 669 | { |
663 | GNUNET_break(0); | 670 | GNUNET_break (0); |
664 | GNUNET_CONVERSATION_phone_destroy(phone); | 671 | GNUNET_CONVERSATION_phone_destroy (phone); |
665 | return NULL; | 672 | return NULL; |
666 | } | 673 | } |
667 | return phone; | 674 | return phone; |
668 | } | 675 | } |
669 | 676 | ||
@@ -677,8 +684,8 @@ GNUNET_CONVERSATION_phone_create(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
677 | * @param rd namestore record to fill in | 684 | * @param rd namestore record to fill in |
678 | */ | 685 | */ |
679 | void | 686 | void |
680 | GNUNET_CONVERSATION_phone_get_record(struct GNUNET_CONVERSATION_Phone *phone, | 687 | GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone, |
681 | struct GNUNET_GNSRECORD_Data *rd) | 688 | struct GNUNET_GNSRECORD_Data *rd) |
682 | { | 689 | { |
683 | rd->data = &phone->my_record; | 690 | rd->data = &phone->my_record; |
684 | rd->expiration_time = 0; | 691 | rd->expiration_time = 0; |
@@ -699,31 +706,32 @@ GNUNET_CONVERSATION_phone_get_record(struct GNUNET_CONVERSATION_Phone *phone, | |||
699 | * @param mic microphone to use | 706 | * @param mic microphone to use |
700 | */ | 707 | */ |
701 | void | 708 | void |
702 | GNUNET_CONVERSATION_caller_pick_up(struct GNUNET_CONVERSATION_Caller *caller, | 709 | GNUNET_CONVERSATION_caller_pick_up (struct GNUNET_CONVERSATION_Caller *caller, |
703 | GNUNET_CONVERSATION_CallerEventHandler event_handler, | 710 | GNUNET_CONVERSATION_CallerEventHandler |
704 | void *event_handler_cls, | 711 | event_handler, |
705 | struct GNUNET_SPEAKER_Handle *speaker, | 712 | void *event_handler_cls, |
706 | struct GNUNET_MICROPHONE_Handle *mic) | 713 | struct GNUNET_SPEAKER_Handle *speaker, |
714 | struct GNUNET_MICROPHONE_Handle *mic) | ||
707 | { | 715 | { |
708 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 716 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
709 | struct GNUNET_MQ_Envelope *e; | 717 | struct GNUNET_MQ_Envelope *e; |
710 | struct ClientPhonePickupMessage *pick; | 718 | struct ClientPhonePickupMessage *pick; |
711 | 719 | ||
712 | GNUNET_assert(CS_RINGING == caller->state); | 720 | GNUNET_assert (CS_RINGING == caller->state); |
713 | caller->speaker = speaker; | 721 | caller->speaker = speaker; |
714 | caller->mic = mic; | 722 | caller->mic = mic; |
715 | e = GNUNET_MQ_msg(pick, | 723 | e = GNUNET_MQ_msg (pick, |
716 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP); | 724 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_PICK_UP); |
717 | pick->cid = caller->cid; | 725 | pick->cid = caller->cid; |
718 | GNUNET_MQ_send(phone->mq, | 726 | GNUNET_MQ_send (phone->mq, |
719 | e); | 727 | e); |
720 | caller->state = CS_ACTIVE; | 728 | caller->state = CS_ACTIVE; |
721 | caller->event_handler = event_handler; | 729 | caller->event_handler = event_handler; |
722 | caller->event_handler_cls = event_handler_cls; | 730 | caller->event_handler_cls = event_handler_cls; |
723 | caller->speaker->enable_speaker(caller->speaker->cls); | 731 | caller->speaker->enable_speaker (caller->speaker->cls); |
724 | caller->mic->enable_microphone(caller->mic->cls, | 732 | caller->mic->enable_microphone (caller->mic->cls, |
725 | &transmit_phone_audio, | 733 | &transmit_phone_audio, |
726 | caller); | 734 | caller); |
727 | } | 735 | } |
728 | 736 | ||
729 | 737 | ||
@@ -734,31 +742,31 @@ GNUNET_CONVERSATION_caller_pick_up(struct GNUNET_CONVERSATION_Caller *caller, | |||
734 | * @param caller conversation to hang up on | 742 | * @param caller conversation to hang up on |
735 | */ | 743 | */ |
736 | void | 744 | void |
737 | GNUNET_CONVERSATION_caller_hang_up(struct GNUNET_CONVERSATION_Caller *caller) | 745 | GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller) |
738 | { | 746 | { |
739 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 747 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
740 | struct GNUNET_MQ_Envelope *e; | 748 | struct GNUNET_MQ_Envelope *e; |
741 | struct ClientPhoneHangupMessage *hang; | 749 | struct ClientPhoneHangupMessage *hang; |
742 | 750 | ||
743 | switch (caller->state) | 751 | switch (caller->state) |
744 | { | 752 | { |
745 | case CS_ACTIVE: | 753 | case CS_ACTIVE: |
746 | caller->speaker->disable_speaker(caller->speaker->cls); | 754 | caller->speaker->disable_speaker (caller->speaker->cls); |
747 | caller->mic->disable_microphone(caller->mic->cls); | 755 | caller->mic->disable_microphone (caller->mic->cls); |
748 | break; | 756 | break; |
749 | 757 | ||
750 | default: | 758 | default: |
751 | break; | 759 | break; |
752 | } | 760 | } |
753 | GNUNET_CONTAINER_DLL_remove(phone->caller_head, | 761 | GNUNET_CONTAINER_DLL_remove (phone->caller_head, |
754 | phone->caller_tail, | 762 | phone->caller_tail, |
755 | caller); | 763 | caller); |
756 | e = GNUNET_MQ_msg(hang, | 764 | e = GNUNET_MQ_msg (hang, |
757 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); | 765 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP); |
758 | hang->cid = caller->cid; | 766 | hang->cid = caller->cid; |
759 | GNUNET_MQ_send(phone->mq, | 767 | GNUNET_MQ_send (phone->mq, |
760 | e); | 768 | e); |
761 | GNUNET_free(caller); | 769 | GNUNET_free (caller); |
762 | } | 770 | } |
763 | 771 | ||
764 | 772 | ||
@@ -768,20 +776,20 @@ GNUNET_CONVERSATION_caller_hang_up(struct GNUNET_CONVERSATION_Caller *caller) | |||
768 | * @param phone phone to destroy | 776 | * @param phone phone to destroy |
769 | */ | 777 | */ |
770 | void | 778 | void |
771 | GNUNET_CONVERSATION_phone_destroy(struct GNUNET_CONVERSATION_Phone *phone) | 779 | GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone) |
772 | { | 780 | { |
773 | clean_up_callers(phone); | 781 | clean_up_callers (phone); |
774 | if (NULL != phone->ns) | 782 | if (NULL != phone->ns) |
775 | { | 783 | { |
776 | GNUNET_NAMESTORE_disconnect(phone->ns); | 784 | GNUNET_NAMESTORE_disconnect (phone->ns); |
777 | phone->ns = NULL; | 785 | phone->ns = NULL; |
778 | } | 786 | } |
779 | if (NULL != phone->mq) | 787 | if (NULL != phone->mq) |
780 | { | 788 | { |
781 | GNUNET_MQ_destroy(phone->mq); | 789 | GNUNET_MQ_destroy (phone->mq); |
782 | phone->mq = NULL; | 790 | phone->mq = NULL; |
783 | } | 791 | } |
784 | GNUNET_free(phone); | 792 | GNUNET_free (phone); |
785 | } | 793 | } |
786 | 794 | ||
787 | 795 | ||
@@ -793,26 +801,26 @@ GNUNET_CONVERSATION_phone_destroy(struct GNUNET_CONVERSATION_Phone *phone) | |||
793 | * @param caller call to suspend | 801 | * @param caller call to suspend |
794 | */ | 802 | */ |
795 | void | 803 | void |
796 | GNUNET_CONVERSATION_caller_suspend(struct GNUNET_CONVERSATION_Caller *caller) | 804 | GNUNET_CONVERSATION_caller_suspend (struct GNUNET_CONVERSATION_Caller *caller) |
797 | { | 805 | { |
798 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 806 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
799 | struct GNUNET_MQ_Envelope *e; | 807 | struct GNUNET_MQ_Envelope *e; |
800 | struct ClientPhoneSuspendMessage *suspend; | 808 | struct ClientPhoneSuspendMessage *suspend; |
801 | 809 | ||
802 | GNUNET_assert((CS_ACTIVE == caller->state) || | 810 | GNUNET_assert ((CS_ACTIVE == caller->state) || |
803 | (CS_CALLER_SUSPENDED == caller->state)); | 811 | (CS_CALLER_SUSPENDED == caller->state)); |
804 | if (CS_ACTIVE == caller->state) | 812 | if (CS_ACTIVE == caller->state) |
805 | { | 813 | { |
806 | caller->speaker->disable_speaker(caller->speaker->cls); | 814 | caller->speaker->disable_speaker (caller->speaker->cls); |
807 | caller->mic->disable_microphone(caller->mic->cls); | 815 | caller->mic->disable_microphone (caller->mic->cls); |
808 | } | 816 | } |
809 | caller->speaker = NULL; | 817 | caller->speaker = NULL; |
810 | caller->mic = NULL; | 818 | caller->mic = NULL; |
811 | e = GNUNET_MQ_msg(suspend, | 819 | e = GNUNET_MQ_msg (suspend, |
812 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); | 820 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND); |
813 | suspend->cid = caller->cid; | 821 | suspend->cid = caller->cid; |
814 | GNUNET_MQ_send(phone->mq, | 822 | GNUNET_MQ_send (phone->mq, |
815 | e); | 823 | e); |
816 | if (CS_ACTIVE == caller->state) | 824 | if (CS_ACTIVE == caller->state) |
817 | caller->state = CS_CALLEE_SUSPENDED; | 825 | caller->state = CS_CALLEE_SUSPENDED; |
818 | else | 826 | else |
@@ -828,35 +836,35 @@ GNUNET_CONVERSATION_caller_suspend(struct GNUNET_CONVERSATION_Caller *caller) | |||
828 | * @param mic microphone to use | 836 | * @param mic microphone to use |
829 | */ | 837 | */ |
830 | void | 838 | void |
831 | GNUNET_CONVERSATION_caller_resume(struct GNUNET_CONVERSATION_Caller *caller, | 839 | GNUNET_CONVERSATION_caller_resume (struct GNUNET_CONVERSATION_Caller *caller, |
832 | struct GNUNET_SPEAKER_Handle *speaker, | 840 | struct GNUNET_SPEAKER_Handle *speaker, |
833 | struct GNUNET_MICROPHONE_Handle *mic) | 841 | struct GNUNET_MICROPHONE_Handle *mic) |
834 | { | 842 | { |
835 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; | 843 | struct GNUNET_CONVERSATION_Phone *phone = caller->phone; |
836 | struct GNUNET_MQ_Envelope *e; | 844 | struct GNUNET_MQ_Envelope *e; |
837 | struct ClientPhoneResumeMessage *resume; | 845 | struct ClientPhoneResumeMessage *resume; |
838 | 846 | ||
839 | GNUNET_assert((CS_CALLEE_SUSPENDED == caller->state) || | 847 | GNUNET_assert ((CS_CALLEE_SUSPENDED == caller->state) || |
840 | (CS_BOTH_SUSPENDED == caller->state)); | 848 | (CS_BOTH_SUSPENDED == caller->state)); |
841 | caller->speaker = speaker; | 849 | caller->speaker = speaker; |
842 | caller->mic = mic; | 850 | caller->mic = mic; |
843 | e = GNUNET_MQ_msg(resume, | 851 | e = GNUNET_MQ_msg (resume, |
844 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); | 852 | GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME); |
845 | resume->cid = caller->cid; | 853 | resume->cid = caller->cid; |
846 | GNUNET_MQ_send(phone->mq, | 854 | GNUNET_MQ_send (phone->mq, |
847 | e); | 855 | e); |
848 | if (CS_CALLEE_SUSPENDED == caller->state) | 856 | if (CS_CALLEE_SUSPENDED == caller->state) |
849 | { | 857 | { |
850 | caller->state = CS_ACTIVE; | 858 | caller->state = CS_ACTIVE; |
851 | caller->speaker->enable_speaker(caller->speaker->cls); | 859 | caller->speaker->enable_speaker (caller->speaker->cls); |
852 | caller->mic->enable_microphone(caller->mic->cls, | 860 | caller->mic->enable_microphone (caller->mic->cls, |
853 | &transmit_phone_audio, | 861 | &transmit_phone_audio, |
854 | caller); | 862 | caller); |
855 | } | 863 | } |
856 | else | 864 | else |
857 | { | 865 | { |
858 | caller->state = CS_CALLER_SUSPENDED; | 866 | caller->state = CS_CALLER_SUSPENDED; |
859 | } | 867 | } |
860 | } | 868 | } |
861 | 869 | ||
862 | /* end of conversation_api.c */ | 870 | /* end of conversation_api.c */ |