#define FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 25)
static int ok = 1;
static void *phone_rdc_cls;
-static GNUNET_MICROPHONE_RecordedDataCallback call_rdc;
+static GNUNET_SCHEDULER_TaskIdentifier phone_task;
-static void *call_rdc_cls;
+/**
+ * Variable for recognizing caller1
+ */
+static const char *caller1 = "caller1";
-static GNUNET_SCHEDULER_TaskIdentifier phone_task;
+/**
+ * Variable for recognizing caller2
+ */
+static const char *caller2 = "caller2";
-static GNUNET_SCHEDULER_TaskIdentifier call_task;
+/**
+ * Variable for recognizing callee
+ */
+static const char *phone0 = "phone";
+
+#define CALLER1 &caller1
+#define CALLER2 &caller2
+#define PHONE0 &phone0
+
+#define CLS_STR(caller) (*((char **)caller))
+
+struct MicContext
+{
+ GNUNET_MICROPHONE_RecordedDataCallback rdc;
+
+ void *rdc_cls;
+
+ GNUNET_SCHEDULER_TaskIdentifier call_task;
+
+ char sym;
+};
+
+static struct MicContext call1_mic_ctx;
+static struct MicContext call2_mic_ctx;
+//static struct MicContext phone_mic_ctx;
static void
GNUNET_assert (NULL != phone_rdc);
GNUNET_snprintf (buf, sizeof (buf), "phone");
phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf);
+ fprintf (stderr, "+");
phone_task = GNUNET_SCHEDULER_add_delayed (FREQ,
&phone_send, NULL);
}
call_send (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ struct MicContext *mc = cls;
char buf[32];
- GNUNET_assert (NULL != call_rdc);
+ GNUNET_assert (NULL != mc->rdc);
GNUNET_snprintf (buf, sizeof (buf), "call");
- call_rdc (call_rdc_cls, strlen (buf) + 1, buf);
- call_task = GNUNET_SCHEDULER_add_delayed (FREQ,
- &call_send, NULL);
+ mc->rdc (mc->rdc_cls, strlen (buf) + 1, buf);
+ fprintf (stderr, "%c", mc->sym);
+ mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ,
+ &call_send, mc);
}
static int
enable_speaker (void *cls)
{
- const char *origin = cls;
+ const char *origin = CLS_STR (cls);
fprintf (stderr,
"Speaker %s enabled\n",
static void
disable_speaker (void *cls)
{
- const char *origin = cls;
+ const char *origin = CLS_STR (cls);
fprintf (stderr,
"Speaker %s disabled\n",
static unsigned int phone_i;
static unsigned int call_i;
+ write (2, data, data_size);
if (0 == strncmp ("call", data, data_size))
call_i++;
else if (0 == strncmp ("phone", data, data_size))
if ( (20 < call_i) &&
(20 < phone_i) &&
- (NULL != call2) )
+ (CALLER2 == cls) )
{
/* time to hang up ... */
GNUNET_CONVERSATION_call_stop (call2);
}
if ( (20 < call_i) &&
(20 < phone_i) &&
- (NULL != call1) )
+ (CALLER1 == cls) )
{
/* time to hang up ... */
GNUNET_CONVERSATION_call_stop (call1);
static void
destroy_speaker (void *cls)
{
- const char *origin = cls;
+ const char *origin = CLS_STR (cls);
fprintf (stderr, "Speaker %s destroyed\n", origin);
}
-static struct GNUNET_SPEAKER_Handle call_speaker = {
+static struct GNUNET_SPEAKER_Handle call1_speaker = {
&enable_speaker,
&play,
&disable_speaker,
&destroy_speaker,
- "caller"
+ CALLER1
+};
+
+
+static struct GNUNET_SPEAKER_Handle call2_speaker = {
+ &enable_speaker,
+ &play,
+ &disable_speaker,
+ &destroy_speaker,
+ CALLER2
};
&play,
&disable_speaker,
&destroy_speaker,
- "phone"
+ PHONE0
};
GNUNET_MICROPHONE_RecordedDataCallback rdc,
void *rdc_cls)
{
- const char *origin = cls;
+ const char *origin = CLS_STR (cls);
+ struct MicContext *mc;
fprintf (stderr,
"Mic %s enabled\n",
origin);
- if (0 == strcmp (origin, "phone"))
+ if (PHONE0 == cls)
{
phone_rdc = rdc;
phone_rdc_cls = rdc_cls;
GNUNET_break (GNUNET_SCHEDULER_NO_TASK == phone_task);
phone_task = GNUNET_SCHEDULER_add_now (&phone_send, NULL);
+ return GNUNET_OK;
}
- else
- {
- call_rdc = rdc;
- call_rdc_cls = rdc_cls;
- GNUNET_break (GNUNET_SCHEDULER_NO_TASK == call_task);
- call_task = GNUNET_SCHEDULER_add_now (&call_send, NULL);
- }
+ mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx;
+ mc->sym = (CALLER1 == cls) ? '1': '2';
+ mc->rdc = rdc;
+ mc->rdc_cls = rdc_cls;
+ GNUNET_break (GNUNET_SCHEDULER_NO_TASK == mc->call_task);
+ mc->call_task = GNUNET_SCHEDULER_add_now (&call_send, mc);
return GNUNET_OK;
}
static void
disable_mic (void *cls)
{
- const char *origin = cls;
+ const char *origin = CLS_STR (cls);
+ struct MicContext *mc;
fprintf (stderr,
"Mic %s disabled\n",
origin);
- if (0 == strcmp (origin, "phone"))
+ if (PHONE0 == cls)
{
phone_rdc = NULL;
phone_rdc_cls = NULL;
GNUNET_SCHEDULER_cancel (phone_task);
phone_task = GNUNET_SCHEDULER_NO_TASK;
+ return;
}
- else
- {
- call_rdc = NULL;
- call_rdc_cls = NULL;
- GNUNET_SCHEDULER_cancel (call_task);
- call_task = GNUNET_SCHEDULER_NO_TASK;
- }
+ mc = (CALLER1 == cls) ? &call1_mic_ctx : &call2_mic_ctx;
+ mc->rdc = NULL;
+ mc->rdc_cls = NULL;
+ GNUNET_SCHEDULER_cancel (mc->call_task);
+ mc->call_task = GNUNET_SCHEDULER_NO_TASK;
}
static void
destroy_mic (void *cls)
{
- const char *origin = cls;
+ const char *origin = CLS_STR (cls);
fprintf (stderr,
"Mic %s destroyed\n",
}
-static struct GNUNET_MICROPHONE_Handle call_mic = {
+static struct GNUNET_MICROPHONE_Handle call1_mic = {
&enable_mic,
&disable_mic,
&destroy_mic,
- "caller"
+ CALLER1
+};
+
+
+static struct GNUNET_MICROPHONE_Handle call2_mic = {
+ &enable_mic,
+ &disable_mic,
+ &destroy_mic,
+ CALLER2
};
&enable_mic,
&disable_mic,
&destroy_mic,
- "phone"
+ PHONE0
};
case GNUNET_CONVERSATION_EC_CALL_RINGING:
break;
case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
+ fprintf (stderr, "\t Call %s picked\n", cid);
break;
case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
+ fprintf (stderr, "\t Call %s GNS lookup failed \n", cid);
case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
+ fprintf (stderr, "\t Call %s hungup\n", cid);
if (0 == strcmp (cid, "call1"))
call1 = NULL;
else
call2 = NULL;
break;
case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
+ fprintf (stderr, "\t Call %s suspended\n", cid);
+ break;
case GNUNET_CONVERSATION_EC_CALL_RESUMED:
+ fprintf (stderr, "\t Call %s resumed\n", cid);
break;
}
}
call1 = GNUNET_CONVERSATION_call_start (cfg,
ego,
gns_name,
- &call_speaker,
- &call_mic,
+ &call1_speaker,
+ &call1_mic,
&call_event_handler,
(void *) "call1");
call2 = GNUNET_CONVERSATION_call_start (cfg,
ego,
gns_name,
- &call_speaker,
- &call_mic,
+ &call2_speaker,
+ &call2_mic,
&call_event_handler,
(void *) "call2");
return;