aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/test_conversation_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-11-19 15:06:33 +0000
committerChristian Grothoff <christian@grothoff.org>2013-11-19 15:06:33 +0000
commit060527201fe3cdfc6d892bc7b90e6e6a6745cb78 (patch)
tree756d70b1c46b8f518854ab39e5de79bcdcf2aaa8 /src/conversation/test_conversation_api.c
parent06e79ff3d4ef352ad14d520f4ec503e842e76593 (diff)
downloadgnunet-060527201fe3cdfc6d892bc7b90e6e6a6745cb78.tar.gz
gnunet-060527201fe3cdfc6d892bc7b90e6e6a6745cb78.zip
-cleaner callback sequencing
Diffstat (limited to 'src/conversation/test_conversation_api.c')
-rw-r--r--src/conversation/test_conversation_api.c100
1 files changed, 93 insertions, 7 deletions
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c
index b6481c54b..4417317fe 100644
--- a/src/conversation/test_conversation_api.c
+++ b/src/conversation/test_conversation_api.c
@@ -34,6 +34,8 @@
34#include "gnunet_identity_service.h" 34#include "gnunet_identity_service.h"
35#include "gnunet_namestore_service.h" 35#include "gnunet_namestore_service.h"
36 36
37#define FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250)
38
37static int ok = 1; 39static int ok = 1;
38 40
39static const struct GNUNET_CONFIGURATION_Handle *cfg; 41static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -56,6 +58,48 @@ static char *gns_name;
56 58
57static char *gns_caller_id; 59static char *gns_caller_id;
58 60
61static GNUNET_MICROPHONE_RecordedDataCallback phone_rdc;
62
63static void *phone_rdc_cls;
64
65static GNUNET_MICROPHONE_RecordedDataCallback call_rdc;
66
67static void *call_rdc_cls;
68
69static GNUNET_SCHEDULER_TaskIdentifier phone_task;
70
71static GNUNET_SCHEDULER_TaskIdentifier call_task;
72
73
74static void
75phone_send (void *cls,
76 const struct GNUNET_SCHEDULER_TaskContext *tc)
77{
78 static unsigned int i;
79 char buf[32];
80
81 GNUNET_assert (NULL != phone_rdc);
82 GNUNET_snprintf (buf, sizeof (buf), "phone-%u", i++);
83 phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf);
84 phone_task = GNUNET_SCHEDULER_add_delayed (FREQ,
85 &phone_send, NULL);
86}
87
88
89static void
90call_send (void *cls,
91 const struct GNUNET_SCHEDULER_TaskContext *tc)
92{
93 static unsigned int i;
94 char buf[32];
95
96 GNUNET_assert (NULL != call_rdc);
97 GNUNET_snprintf (buf, sizeof (buf), "call-%u", i++);
98 call_rdc (call_rdc_cls, strlen (buf) + 1, buf);
99 call_task = GNUNET_SCHEDULER_add_delayed (FREQ,
100 &call_send, NULL);
101}
102
59 103
60static int 104static int
61enable_speaker (void *cls) 105enable_speaker (void *cls)
@@ -86,11 +130,30 @@ play (void *cls,
86 const void *data) 130 const void *data)
87{ 131{
88 const char *origin = cls; 132 const char *origin = cls;
89 133 static unsigned int phone_i;
90 fprintf (stderr, 134 static unsigned int call_i;
91 "Speaker %s plays %u bytes\n", 135 char buf[32];
92 origin, 136
93 (unsigned int) data_size); 137 if (0 == strcmp (origin, "phone"))
138 GNUNET_snprintf (buf, sizeof (buf), "phone-%u", phone_i++);
139 else
140 GNUNET_snprintf (buf, sizeof (buf), "call-%u", call_i++);
141 if ( (data_size != strlen (buf) + 1) ||
142 (0 != strncmp (buf, data, data_size)) )
143 {
144 fprintf (stderr,
145 "Expected %s, received %.*s\n",
146 buf,
147 (int) data_size,
148 (const char *) data);
149 }
150 if ( (20 < call_i) &&
151 (20 < phone_i) )
152 {
153 /* time to hang up ... */
154 GNUNET_CONVERSATION_call_stop (call);
155 call = NULL;
156 }
94} 157}
95 158
96 159
@@ -131,6 +194,18 @@ enable_mic (void *cls,
131 fprintf (stderr, 194 fprintf (stderr,
132 "Mic %s enabled\n", 195 "Mic %s enabled\n",
133 origin); 196 origin);
197 if (0 == strcmp (origin, "phone"))
198 {
199 phone_rdc = rdc;
200 phone_rdc_cls = rdc_cls;
201 phone_task = GNUNET_SCHEDULER_add_now (&phone_send, NULL);
202 }
203 else
204 {
205 call_rdc = rdc;
206 call_rdc_cls = rdc_cls;
207 call_task = GNUNET_SCHEDULER_add_now (&call_send, NULL);
208 }
134 return GNUNET_OK; 209 return GNUNET_OK;
135} 210}
136 211
@@ -143,6 +218,19 @@ disable_mic (void *cls)
143 fprintf (stderr, 218 fprintf (stderr,
144 "Mic %s disabled\n", 219 "Mic %s disabled\n",
145 origin); 220 origin);
221 if (0 == strcmp (origin, "phone"))
222 {
223 phone_rdc = NULL;
224 phone_rdc_cls = NULL;
225 GNUNET_SCHEDULER_cancel (phone_task);
226 }
227 else
228 {
229 call_rdc = NULL;
230 call_rdc_cls = NULL;
231 GNUNET_SCHEDULER_cancel (call_task);
232 }
233
146} 234}
147 235
148 236
@@ -282,8 +370,6 @@ call_event_handler (void *cls,
282 break; 370 break;
283 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: 371 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
284 expect = -1; 372 expect = -1;
285 GNUNET_CONVERSATION_call_stop (call);
286 call = NULL;
287 break; 373 break;
288 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: 374 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
289 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: 375 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: