GNUnet  0.11.x
Data Structures | Enumerations | Functions
conversation_api.c File Reference

phone and caller API to the conversation service More...

#include "platform.h"
#include "gnunet_conversation_service.h"
#include "conversation.h"
Include dependency graph for conversation_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CONVERSATION_Caller
 A caller is the handle we have for an incoming call. More...
 
struct  GNUNET_CONVERSATION_Phone
 A phone is a device that can ring to signal an incoming call and that you can pick up to answer the call and hang up to terminate the call. More...
 

Enumerations

enum  CallerState {
  CS_RINGING , CS_ACTIVE , CS_CALLEE_SUSPENDED , CS_CALLER_SUSPENDED ,
  CS_BOTH_SUSPENDED
}
 Possible states of a caller. More...
 
enum  PhoneState {
  PS_REGISTER = 0 , PS_READY , PS_LOOKUP_EGO , PS_LISTEN ,
  PS_ACCEPTED , PS_ERROR
}
 Possible states of a phone. More...
 

Functions

static void reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone)
 The phone got disconnected, reconnect to the service. More...
 
static void transmit_phone_audio (void *cls, size_t data_size, const void *data)
 Process recorded audio data. More...
 
static void handle_phone_ring (void *cls, const struct ClientPhoneRingMessage *ring)
 We received a struct ClientPhoneRingMessage More...
 
static struct GNUNET_CONVERSATION_Callerfind_caller (struct GNUNET_CONVERSATION_Phone *phone, uint32_t cid)
 Find the record of the caller matching the cid. More...
 
static void handle_phone_hangup (void *cls, const struct ClientPhoneHangupMessage *hang)
 We received a struct ClientPhoneHangupMessage. More...
 
static void handle_phone_suspend (void *cls, const struct ClientPhoneSuspendMessage *suspend)
 We received a struct ClientPhoneSuspendMessage. More...
 
static void handle_phone_resume (void *cls, const struct ClientPhoneResumeMessage *resume)
 We received a struct ClientPhoneResumeMessage. More...
 
static int check_phone_audio (void *cls, const struct ClientAudioMessage *am)
 We received a struct ClientAudioMessage, check it is well-formed. More...
 
static void handle_phone_audio (void *cls, const struct ClientAudioMessage *am)
 We received a struct ClientAudioMessage More...
 
static void phone_error_handler (void *cls, enum GNUNET_MQ_Error error)
 We encountered an error talking with the conversation service. More...
 
static void clean_up_callers (struct GNUNET_CONVERSATION_Phone *phone)
 Clean up all callers of the given phone. More...
 
struct GNUNET_CONVERSATION_PhoneGNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_IDENTITY_Ego *ego, GNUNET_CONVERSATION_PhoneEventHandler event_handler, void *event_handler_cls)
 Create a new phone. More...
 
void GNUNET_CONVERSATION_phone_get_record (struct GNUNET_CONVERSATION_Phone *phone, struct GNUNET_GNSRECORD_Data *rd)
 Fill in a namestore record with the contact information for this phone. More...
 
void GNUNET_CONVERSATION_caller_pick_up (struct GNUNET_CONVERSATION_Caller *caller, GNUNET_CONVERSATION_CallerEventHandler event_handler, void *event_handler_cls, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic)
 Picks up a (ringing) phone. More...
 
void GNUNET_CONVERSATION_caller_hang_up (struct GNUNET_CONVERSATION_Caller *caller)
 Hang up up a (possibly ringing) phone. More...
 
void GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone)
 Destroys a phone. More...
 
void GNUNET_CONVERSATION_caller_suspend (struct GNUNET_CONVERSATION_Caller *caller)
 Pause conversation of an active call. More...
 
void GNUNET_CONVERSATION_caller_resume (struct GNUNET_CONVERSATION_Caller *caller, struct GNUNET_SPEAKER_Handle *speaker, struct GNUNET_MICROPHONE_Handle *mic)
 Resume suspended conversation of a phone. More...
 

Detailed Description

phone and caller API to the conversation service

Author
Simon Dieterle
Andreas Fuchs
Christian Grothoff

Definition in file conversation_api.c.

Enumeration Type Documentation

◆ CallerState

Possible states of a caller.

Enumerator
CS_RINGING 

The phone is ringing (user knows about incoming call).

CS_ACTIVE 

The phone is in an active conversation.

CS_CALLEE_SUSPENDED 

We suspended the conversation.

CS_CALLER_SUSPENDED 

Caller suspended the conversation.

CS_BOTH_SUSPENDED 

Both sides suspended the conversation.

Definition at line 36 of file conversation_api.c.

37 {
41  CS_RINGING,
42 
46  CS_ACTIVE,
47 
52 
57 
62 };
@ CS_CALLEE_SUSPENDED
We suspended the conversation.
@ CS_BOTH_SUSPENDED
Both sides suspended the conversation.
@ CS_ACTIVE
The phone is in an active conversation.
@ CS_CALLER_SUSPENDED
Caller suspended the conversation.
@ CS_RINGING
The phone is ringing (user knows about incoming call).

◆ PhoneState

enum PhoneState

Possible states of a phone.

Enumerator
PS_REGISTER 

We still need to register the phone.

PS_READY 

We are waiting for calls.

PS_LOOKUP_EGO 

We're waiting for our own idenitty.

PS_LISTEN 

We're listening for calls.

PS_ACCEPTED 

We accepted an incoming phone call.

PS_ERROR 

Internal error.

Definition at line 125 of file conversation_api.c.

126 {
130  PS_REGISTER = 0,
131 
135  PS_READY
136 };
@ PS_REGISTER
We still need to register the phone.
@ PS_READY
We are waiting for calls.

Function Documentation

◆ reconnect_phone()

static void reconnect_phone ( struct GNUNET_CONVERSATION_Phone phone)
static

The phone got disconnected, reconnect to the service.

Parameters
phonephone to reconnect

Definition at line 562 of file conversation_api.c.

563 {
565  GNUNET_MQ_hd_fixed_size (phone_ring,
567  struct ClientPhoneRingMessage,
568  phone),
569  GNUNET_MQ_hd_fixed_size (phone_hangup,
572  phone),
573  GNUNET_MQ_hd_fixed_size (phone_suspend,
576  phone),
577  GNUNET_MQ_hd_fixed_size (phone_resume,
580  phone),
581  GNUNET_MQ_hd_var_size (phone_audio,
583  struct ClientAudioMessage,
584  phone),
586  };
587  struct GNUNET_MQ_Envelope *e;
588  struct ClientPhoneRegisterMessage *reg;
589 
591  if (NULL != phone->mq)
592  {
594  phone->mq = NULL;
595  }
598  "conversation",
599  handlers,
601  phone);
602  if (NULL == phone->mq)
603  return;
604  e = GNUNET_MQ_msg (reg,
608  e);
609  phone->state = PS_READY;
610 }
static void clean_up_callers(struct GNUNET_CONVERSATION_Phone *phone)
Clean up all callers of the given phone.
static void phone_error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error talking with the conversation service.
static struct Experiment * e
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_CONVERSATION_Phone * phone
Phone handle.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1064
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME
Client <-> Server message to resume connection.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER
Client -> Server message to register a phone.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND
Client <-> Server message to suspend connection.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP
Client -> Server message to reject/hangup a call.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO
Client <-> Server message to send audio data.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING
Client <- Server message to indicate a ringing phone.
Message Client <-> Service to transmit the audio.
Definition: conversation.h:191
Client <-> Service hang up phone that may or may not be ringing.
Definition: conversation.h:173
Client -> Service message to register a phone.
Definition: conversation.h:73
struct GNUNET_HashCode line_port
Phone line / CADET port to register.
Definition: conversation.h:87
Service <-> Client message for phone was resumed.
Definition: conversation.h:136
Service -> Client message for phone is ringing.
Definition: conversation.h:95
Service <-> Client message for phone was suspended.
Definition: conversation.h:118
struct GNUNET_HashCode line_port
Phone line (CADET port) to connect to.
struct GNUNET_MQ_Handle * mq
Handle for transmitting to the CONVERSATION service.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_CONVERSATION_PhoneRecord my_record
This phone's record.
enum PhoneState state
State machine for the phone.
Message handler for a specific message type.

References GNUNET_CONVERSATION_Phone::cfg, clean_up_callers(), e, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_HANG_UP, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_REGISTER, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RESUME, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_RING, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_PHONE_SUSPEND, GNUNET_MQ_destroy(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), handlers, ClientPhoneRegisterMessage::line_port, GNUNET_CONVERSATION_PhoneRecord::line_port, GNUNET_CONVERSATION_Phone::mq, GNUNET_CONVERSATION_Phone::my_record, phone, phone_error_handler(), PS_READY, PS_REGISTER, and GNUNET_CONVERSATION_Phone::state.

Referenced by GNUNET_CONVERSATION_phone_create(), and phone_error_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_phone_audio()

static void transmit_phone_audio ( void *  cls,
size_t  data_size,
const void *  data 
)
static

Process recorded audio data.

Parameters
clsclosure with the struct GNUNET_CONVERSATION_Caller
data_sizenumber of bytes in data
dataaudio data to play

Definition at line 221 of file conversation_api.c.

224 {
225  struct GNUNET_CONVERSATION_Caller *caller = cls;
226  struct GNUNET_CONVERSATION_Phone *phone = caller->phone;
227  struct GNUNET_MQ_Envelope *e;
228  struct ClientAudioMessage *am;
229 
230  e = GNUNET_MQ_msg_extra (am,
231  data_size,
233  am->cid = caller->cid;
234  GNUNET_memcpy (&am[1],
235  data,
236  data_size);
238  e);
239 }
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
uint32_t data
The data value.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:52
uint32_t cid
CID, internal caller ID to identify which active call we are sending data to.
Definition: conversation.h:201
A caller is the handle we have for an incoming call.
uint32_t cid
Internal handle to identify the caller with the service.
struct GNUNET_CONVERSATION_Phone * phone
Our phone.
A phone is a device that can ring to signal an incoming call and that you can pick up to answer the c...

References ClientAudioMessage::cid, GNUNET_CONVERSATION_Caller::cid, data, data_size, e, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_CONVERSATION_Phone::mq, GNUNET_CONVERSATION_Caller::phone, and phone.

Referenced by GNUNET_CONVERSATION_caller_pick_up(), GNUNET_CONVERSATION_caller_resume(), and handle_phone_resume().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_phone_ring()

static void handle_phone_ring ( void *  cls,
const struct ClientPhoneRingMessage ring 
)
static

We received a struct ClientPhoneRingMessage

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
ringthe message

Definition at line 249 of file conversation_api.c.

251 {
252  struct GNUNET_CONVERSATION_Phone *phone = cls;
253  struct GNUNET_CONVERSATION_Caller *caller;
254 
255  switch (phone->state)
256  {
257  case PS_REGISTER:
258  GNUNET_assert (0);
259  break;
260 
261  case PS_READY:
262  caller = GNUNET_new (struct GNUNET_CONVERSATION_Caller);
263  caller->phone = phone;
266  caller);
267  caller->caller_id = ring->caller_id;
268  caller->cid = ring->cid;
269  caller->state = CS_RINGING;
272  caller,
273  &caller->caller_id);
274  break;
275  }
276 }
@ GNUNET_CONVERSATION_EC_PHONE_RING
We are the callee and the phone is ringing.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_IDENTITY_PublicKey caller_id
Who is calling us?
Definition: conversation.h:110
uint32_t cid
CID, internal caller ID number used in the future to identify which active call we are talking about.
Definition: conversation.h:105
enum CallerState state
State machine for the phone.
struct GNUNET_IDENTITY_PublicKey caller_id
Identity of the person calling us.
GNUNET_CONVERSATION_PhoneEventHandler event_handler
Function to call for phone events.
struct GNUNET_CONVERSATION_Caller * caller_tail
We keep all callers in a DLL.
struct GNUNET_CONVERSATION_Caller * caller_head
We keep all callers in a DLL.
void * event_handler_cls
Closure for event_handler.

References GNUNET_CONVERSATION_Phone::caller_head, ClientPhoneRingMessage::caller_id, GNUNET_CONVERSATION_Caller::caller_id, GNUNET_CONVERSATION_Phone::caller_tail, ClientPhoneRingMessage::cid, GNUNET_CONVERSATION_Caller::cid, CS_RINGING, GNUNET_CONVERSATION_Phone::event_handler, GNUNET_CONVERSATION_Phone::event_handler_cls, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONVERSATION_EC_PHONE_RING, GNUNET_new, GNUNET_CONVERSATION_Caller::phone, phone, PS_READY, PS_REGISTER, GNUNET_CONVERSATION_Caller::state, and GNUNET_CONVERSATION_Phone::state.

◆ find_caller()

static struct GNUNET_CONVERSATION_Caller* find_caller ( struct GNUNET_CONVERSATION_Phone phone,
uint32_t  cid 
)
static

Find the record of the caller matching the cid.

Parameters
phonephone to search
cidcaller ID to search for (in NBO)
Returns
NULL if cid was not found

Definition at line 287 of file conversation_api.c.

289 {
290  struct GNUNET_CONVERSATION_Caller *caller;
291 
292  for (caller = phone->caller_head; NULL != caller; caller = caller->next)
293  if (cid == caller->cid)
294  return caller;
295  return NULL;
296 }
struct GNUNET_CONVERSATION_Caller * next
We keep all callers in a DLL.

References GNUNET_CONVERSATION_Phone::caller_head, GNUNET_CONVERSATION_Caller::cid, GNUNET_CONVERSATION_Caller::next, and phone.

Referenced by handle_phone_audio(), handle_phone_hangup(), handle_phone_resume(), and handle_phone_suspend().

Here is the caller graph for this function:

◆ handle_phone_hangup()

static void handle_phone_hangup ( void *  cls,
const struct ClientPhoneHangupMessage hang 
)
static

We received a struct ClientPhoneHangupMessage.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone *
msgthe message

Definition at line 306 of file conversation_api.c.

308 {
309  struct GNUNET_CONVERSATION_Phone *phone = cls;
310  struct GNUNET_CONVERSATION_Caller *caller;
311 
312  caller = find_caller (phone,
313  hang->cid);
314  if (NULL == caller)
315  {
317  "Received HANG_UP message for unknown caller ID %u\n",
318  (unsigned int) hang->cid);
319  return;
320  }
321 
323  "Received HANG_UP message, terminating call with `%s'\n",
325  switch (caller->state)
326  {
327  case CS_RINGING:
330  caller,
331  &caller->caller_id);
332  break;
333 
334  case CS_ACTIVE:
335  caller->speaker->disable_speaker (caller->speaker->cls);
336  caller->mic->disable_microphone (caller->mic->cls);
339  caller,
340  &caller->caller_id);
341  break;
342 
343  case CS_CALLEE_SUSPENDED:
344  case CS_CALLER_SUSPENDED:
345  case CS_BOTH_SUSPENDED:
348  caller,
349  &caller->caller_id);
350  break;
351  }
354  caller);
355  GNUNET_free (caller);
356 }
static struct GNUNET_CONVERSATION_Caller * find_caller(struct GNUNET_CONVERSATION_Phone *phone, uint32_t cid)
Find the record of the caller matching the cid.
#define GNUNET_log(kind,...)
@ GNUNET_CONVERSATION_EC_PHONE_HUNG_UP
The conversation was terminated by the caller.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
const char * GNUNET_GNSRECORD_pkey_to_zkey(const struct GNUNET_IDENTITY_PublicKey *pkey)
Convert public key to the respective absolute domain name in the ".zkey" pTLD.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
uint32_t cid
CID, internal caller ID to identify which active call we are talking about.
Definition: conversation.h:183
struct GNUNET_MICROPHONE_Handle * mic
Microphone, or NULL if none is attached.
struct GNUNET_SPEAKER_Handle * speaker
Speaker, or NULL if none is attached.
void * cls
Closure for the callbacks.
GNUNET_MICROPHONE_DisableCallback disable_microphone
Turn the microphone off.
void * cls
Closure for the callbacks.
GNUNET_SPEAKER_DisableCallback disable_speaker
Turn the speaker off.

References GNUNET_CONVERSATION_Phone::caller_head, GNUNET_CONVERSATION_Caller::caller_id, GNUNET_CONVERSATION_Phone::caller_tail, ClientPhoneHangupMessage::cid, GNUNET_MICROPHONE_Handle::cls, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_BOTH_SUSPENDED, CS_CALLEE_SUSPENDED, CS_CALLER_SUSPENDED, CS_RINGING, GNUNET_MICROPHONE_Handle::disable_microphone, GNUNET_SPEAKER_Handle::disable_speaker, GNUNET_CONVERSATION_Phone::event_handler, GNUNET_CONVERSATION_Phone::event_handler_cls, find_caller(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_pkey_to_zkey(), GNUNET_log, GNUNET_CONVERSATION_Caller::mic, phone, GNUNET_CONVERSATION_Caller::speaker, and GNUNET_CONVERSATION_Caller::state.

Here is the call graph for this function:

◆ handle_phone_suspend()

static void handle_phone_suspend ( void *  cls,
const struct ClientPhoneSuspendMessage suspend 
)
static

We received a struct ClientPhoneSuspendMessage.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
suspendthe message

Definition at line 366 of file conversation_api.c.

368 {
369  struct GNUNET_CONVERSATION_Phone *phone = cls;
370  struct GNUNET_CONVERSATION_Caller *caller;
371 
372  caller = find_caller (phone,
373  suspend->cid);
374  if (NULL == caller)
375  return;
376  switch (caller->state)
377  {
378  case CS_RINGING:
379  GNUNET_break_op (0);
380  break;
381 
382  case CS_ACTIVE:
383  caller->state = CS_CALLER_SUSPENDED;
384  caller->speaker->disable_speaker (caller->speaker->cls);
385  caller->mic->disable_microphone (caller->mic->cls);
386  caller->event_handler (caller->event_handler_cls,
388  break;
389 
390  case CS_CALLEE_SUSPENDED:
391  caller->state = CS_BOTH_SUSPENDED;
392  caller->event_handler (caller->event_handler_cls,
394  break;
395 
396  case CS_CALLER_SUSPENDED:
397  case CS_BOTH_SUSPENDED:
398  GNUNET_break_op (0);
399  break;
400  }
401 }
@ GNUNET_CONVERSATION_EC_CALLER_SUSPEND
We are the callee and the caller suspended the call.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint32_t cid
CID, internal caller ID to identify which active call we are talking about.
Definition: conversation.h:128
void * event_handler_cls
Closure for event_handler.
GNUNET_CONVERSATION_CallerEventHandler event_handler
Function to call for phone events.

References ClientPhoneSuspendMessage::cid, GNUNET_MICROPHONE_Handle::cls, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_BOTH_SUSPENDED, CS_CALLEE_SUSPENDED, CS_CALLER_SUSPENDED, CS_RINGING, GNUNET_MICROPHONE_Handle::disable_microphone, GNUNET_SPEAKER_Handle::disable_speaker, GNUNET_CONVERSATION_Caller::event_handler, GNUNET_CONVERSATION_Caller::event_handler_cls, find_caller(), GNUNET_break_op, GNUNET_CONVERSATION_EC_CALLER_SUSPEND, GNUNET_CONVERSATION_Caller::mic, phone, GNUNET_CONVERSATION_Caller::speaker, and GNUNET_CONVERSATION_Caller::state.

Here is the call graph for this function:

◆ handle_phone_resume()

static void handle_phone_resume ( void *  cls,
const struct ClientPhoneResumeMessage resume 
)
static

We received a struct ClientPhoneResumeMessage.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
resumethe message

Definition at line 411 of file conversation_api.c.

413 {
414  struct GNUNET_CONVERSATION_Phone *phone = cls;
415  struct GNUNET_CONVERSATION_Caller *caller;
416 
417  caller = find_caller (phone,
418  resume->cid);
419  if (NULL == caller)
420  return;
421  switch (caller->state)
422  {
423  case CS_RINGING:
424  GNUNET_break_op (0);
425  break;
426 
427  case CS_ACTIVE:
428  case CS_CALLEE_SUSPENDED:
429  GNUNET_break_op (0);
430  break;
431 
432  case CS_CALLER_SUSPENDED:
433  caller->state = CS_ACTIVE;
434  caller->speaker->enable_speaker (caller->speaker->cls);
435  caller->mic->enable_microphone (caller->mic->cls,
437  caller);
438  caller->event_handler (caller->event_handler_cls,
440  break;
441 
442  case CS_BOTH_SUSPENDED:
443  caller->state = CS_CALLEE_SUSPENDED;
444  caller->event_handler (caller->event_handler_cls,
446  break;
447  }
448 }
static void transmit_phone_audio(void *cls, size_t data_size, const void *data)
Process recorded audio data.
@ GNUNET_CONVERSATION_EC_CALLER_RESUME
We are the callee and the caller resumed the call.
uint32_t cid
CID, internal caller ID to identify which active call we are talking about.
Definition: conversation.h:146
GNUNET_MICROPHONE_EnableCallback enable_microphone
Turn on the microphone.
GNUNET_SPEAKER_EnableCallback enable_speaker
Turn on the speaker.

References ClientPhoneResumeMessage::cid, GNUNET_MICROPHONE_Handle::cls, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_BOTH_SUSPENDED, CS_CALLEE_SUSPENDED, CS_CALLER_SUSPENDED, CS_RINGING, GNUNET_MICROPHONE_Handle::enable_microphone, GNUNET_SPEAKER_Handle::enable_speaker, GNUNET_CONVERSATION_Caller::event_handler, GNUNET_CONVERSATION_Caller::event_handler_cls, find_caller(), GNUNET_break_op, GNUNET_CONVERSATION_EC_CALLER_RESUME, GNUNET_CONVERSATION_Caller::mic, phone, GNUNET_CONVERSATION_Caller::speaker, GNUNET_CONVERSATION_Caller::state, and transmit_phone_audio().

Here is the call graph for this function:

◆ check_phone_audio()

static int check_phone_audio ( void *  cls,
const struct ClientAudioMessage am 
)
static

We received a struct ClientAudioMessage, check it is well-formed.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
amthe message
Returns
GNUNET_OK if am is well-formed

Definition at line 459 of file conversation_api.c.

461 {
462  (void) cls;
463  (void) am;
464 
465  /* any variable-size payload is OK */
466  return GNUNET_OK;
467 }
@ GNUNET_OK
Definition: gnunet_common.h:95

References GNUNET_OK.

◆ handle_phone_audio()

static void handle_phone_audio ( void *  cls,
const struct ClientAudioMessage am 
)
static

We received a struct ClientAudioMessage

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
amthe message

Definition at line 477 of file conversation_api.c.

479 {
480  struct GNUNET_CONVERSATION_Phone *phone = cls;
481  struct GNUNET_CONVERSATION_Caller *caller;
482 
483  caller = find_caller (phone,
484  am->cid);
485  if (NULL == caller)
486  return;
487  switch (caller->state)
488  {
489  case CS_RINGING:
490  GNUNET_break_op (0);
491  break;
492 
493  case CS_ACTIVE:
494  caller->speaker->play (caller->speaker->cls,
495  ntohs (am->header.size) - sizeof(struct
497  &am[1]);
498  break;
499 
500  case CS_CALLEE_SUSPENDED:
501  case CS_CALLER_SUSPENDED:
502  case CS_BOTH_SUSPENDED:
503  break;
504  }
505 }
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_CS_AUDIO.
Definition: conversation.h:195
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
GNUNET_SPEAKER_PlayCallback play
Play audio.

References ClientAudioMessage::cid, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_BOTH_SUSPENDED, CS_CALLEE_SUSPENDED, CS_CALLER_SUSPENDED, CS_RINGING, find_caller(), GNUNET_break_op, ClientAudioMessage::header, phone, GNUNET_SPEAKER_Handle::play, GNUNET_MessageHeader::size, GNUNET_CONVERSATION_Caller::speaker, and GNUNET_CONVERSATION_Caller::state.

Here is the call graph for this function:

◆ phone_error_handler()

static void phone_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

We encountered an error talking with the conversation service.

Parameters
clsthe struct GNUNET_CONVERSATION_Phone
errordetails about the error

Definition at line 515 of file conversation_api.c.

517 {
518  struct GNUNET_CONVERSATION_Phone *phone = cls;
519 
520  (void) error;
522  _ (
523  "Connection to conversation service lost, trying to reconnect\n"));
525 }
static void reconnect_phone(struct GNUNET_CONVERSATION_Phone *phone)
The phone got disconnected, reconnect to the service.
@ GNUNET_ERROR_TYPE_WARNING
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

References _, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, phone, and reconnect_phone().

Referenced by reconnect_phone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clean_up_callers()

static void clean_up_callers ( struct GNUNET_CONVERSATION_Phone phone)
static

Clean up all callers of the given phone.

Parameters
phonephone to clean up callers for

Definition at line 534 of file conversation_api.c.

535 {
536  struct GNUNET_CONVERSATION_Caller *caller;
537 
538  while (NULL != (caller = phone->caller_head))
539  {
540  /* make sure mic/speaker are disabled *before* callback */
541  if (CS_ACTIVE == caller->state)
542  {
543  caller->speaker->disable_speaker (caller->speaker->cls);
544  caller->mic->disable_microphone (caller->mic->cls);
545  caller->state = CS_CALLER_SUSPENDED;
546  }
549  caller,
550  &caller->caller_id);
552  }
553 }
void GNUNET_CONVERSATION_caller_hang_up(struct GNUNET_CONVERSATION_Caller *caller)
Hang up up a (possibly ringing) phone.

References GNUNET_CONVERSATION_Phone::caller_head, GNUNET_CONVERSATION_Caller::caller_id, GNUNET_MICROPHONE_Handle::cls, GNUNET_SPEAKER_Handle::cls, CS_ACTIVE, CS_CALLER_SUSPENDED, GNUNET_MICROPHONE_Handle::disable_microphone, GNUNET_SPEAKER_Handle::disable_speaker, GNUNET_CONVERSATION_Phone::event_handler, GNUNET_CONVERSATION_Phone::event_handler_cls, GNUNET_CONVERSATION_caller_hang_up(), GNUNET_CONVERSATION_EC_PHONE_HUNG_UP, GNUNET_CONVERSATION_Caller::mic, phone, GNUNET_CONVERSATION_Caller::speaker, and GNUNET_CONVERSATION_Caller::state.

Referenced by GNUNET_CONVERSATION_phone_destroy(), and reconnect_phone().

Here is the call graph for this function:
Here is the caller graph for this function: