aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/test_conversation_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-11-18 19:44:50 +0000
committerChristian Grothoff <christian@grothoff.org>2013-11-18 19:44:50 +0000
commit5ffeabe7928665df01fcd2a6ec1cef556b27179e (patch)
tree858fceb2a1fa174d26283899894a0a35c1e9881b /src/conversation/test_conversation_api.c
parent0018daf05f889a759964ae8f2a89e18922e72b74 (diff)
downloadgnunet-5ffeabe7928665df01fcd2a6ec1cef556b27179e.tar.gz
gnunet-5ffeabe7928665df01fcd2a6ec1cef556b27179e.zip
-expanding conversation test
Diffstat (limited to 'src/conversation/test_conversation_api.c')
-rw-r--r--src/conversation/test_conversation_api.c129
1 files changed, 116 insertions, 13 deletions
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c
index 592eeacd1..f7aa53c90 100644
--- a/src/conversation/test_conversation_api.c
+++ b/src/conversation/test_conversation_api.c
@@ -45,25 +45,36 @@ static struct GNUNET_CONVERSATION_Call *call;
45 45
46static struct GNUNET_NAMESTORE_QueueEntry *qe; 46static struct GNUNET_NAMESTORE_QueueEntry *qe;
47 47
48static struct GNUNET_CONVERSATION_Caller *active_caller;
49
48static char *gns_name; 50static char *gns_name;
49 51
52static char *gns_caller_id;
53
54
50static int 55static int
51enable_speaker (void *cls) 56enable_speaker (void *cls)
52{ 57{
53 const char *origin = cls; 58 const char *origin = cls;
54 59
55 fprintf (stderr, "Speaker %s enabled\n", origin); 60 fprintf (stderr,
61 "Speaker %s enabled\n",
62 origin);
56 return GNUNET_OK; 63 return GNUNET_OK;
57} 64}
58 65
66
59static void 67static void
60disable_speaker (void *cls) 68disable_speaker (void *cls)
61{ 69{
62 const char *origin = cls; 70 const char *origin = cls;
63 71
64 fprintf (stderr, "Speaker %s disabled\n", origin); 72 fprintf (stderr,
73 "Speaker %s disabled\n",
74 origin);
65} 75}
66 76
77
67static void 78static void
68play (void *cls, 79play (void *cls,
69 size_t data_size, 80 size_t data_size,
@@ -71,9 +82,13 @@ play (void *cls,
71{ 82{
72 const char *origin = cls; 83 const char *origin = cls;
73 84
74 fprintf (stderr, "Speaker %s plays %u bytes\n", origin, (unsigned int) data_size); 85 fprintf (stderr,
86 "Speaker %s plays %u bytes\n",
87 origin,
88 (unsigned int) data_size);
75} 89}
76 90
91
77static void 92static void
78destroy_speaker (void *cls) 93destroy_speaker (void *cls)
79{ 94{
@@ -92,6 +107,15 @@ static struct GNUNET_SPEAKER_Handle caller_speaker = {
92}; 107};
93 108
94 109
110static struct GNUNET_SPEAKER_Handle phone_speaker = {
111 &enable_speaker,
112 &play,
113 &disable_speaker,
114 &destroy_speaker,
115 "caller"
116};
117
118
95static int 119static int
96enable_mic (void *cls, 120enable_mic (void *cls,
97 GNUNET_MICROPHONE_RecordedDataCallback rdc, 121 GNUNET_MICROPHONE_RecordedDataCallback rdc,
@@ -99,24 +123,32 @@ enable_mic (void *cls,
99{ 123{
100 const char *origin = cls; 124 const char *origin = cls;
101 125
102 fprintf (stderr, "Mic %s enabled\n", origin); 126 fprintf (stderr,
127 "Mic %s enabled\n",
128 origin);
103 return GNUNET_OK; 129 return GNUNET_OK;
104} 130}
105 131
132
106static void 133static void
107disable_mic (void *cls) 134disable_mic (void *cls)
108{ 135{
109 const char *origin = cls; 136 const char *origin = cls;
110 137
111 fprintf (stderr, "Mic %s disabled\n", origin); 138 fprintf (stderr,
139 "Mic %s disabled\n",
140 origin);
112} 141}
113 142
143
114static void 144static void
115destroy_mic (void *cls) 145destroy_mic (void *cls)
116{ 146{
117 const char *origin = cls; 147 const char *origin = cls;
118 148
119 fprintf (stderr, "Mic %s destroyed\n", origin); 149 fprintf (stderr,
150 "Mic %s destroyed\n",
151 origin);
120} 152}
121 153
122 154
@@ -127,6 +159,15 @@ static struct GNUNET_MICROPHONE_Handle caller_mic = {
127 "caller" 159 "caller"
128}; 160};
129 161
162
163static struct GNUNET_MICROPHONE_Handle phone_mic = {
164 &enable_mic,
165 &disable_mic,
166 &destroy_mic,
167 "caller"
168};
169
170
130/** 171/**
131 * Signature of the main function of a task. 172 * Signature of the main function of a task.
132 * 173 *
@@ -172,22 +213,80 @@ end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
172 213
173 214
174static void 215static void
216caller_event_handler (void *cls,
217 enum GNUNET_CONVERSATION_CallerEventCode code)
218{
219 switch (code)
220 {
221 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
222 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
223 fprintf (stderr, "Unexpected caller code: %d\n", code);
224 break;
225 }
226}
227
228
229static void
175phone_event_handler (void *cls, 230phone_event_handler (void *cls,
176 enum GNUNET_CONVERSATION_PhoneEventCode code, 231 enum GNUNET_CONVERSATION_PhoneEventCode code,
177 struct GNUNET_CONVERSATION_Caller *caller, 232 struct GNUNET_CONVERSATION_Caller *caller,
178 const char *caller_id) 233 const char *caller_id)
179{ 234{
180 fprintf (stderr, "Phone code: %d - %s\n", code, caller_id); 235 static enum GNUNET_CONVERSATION_PhoneEventCode expect
181 ok = 0; 236 = GNUNET_CONVERSATION_EC_PHONE_RING;
182 GNUNET_SCHEDULER_shutdown (); 237
238 GNUNET_break (0 == strcmp (caller_id,
239 gns_caller_id));
240 GNUNET_break (code == expect);
241 switch (code)
242 {
243 case GNUNET_CONVERSATION_EC_PHONE_RING:
244 active_caller = caller;
245 GNUNET_CONVERSATION_caller_pick_up (caller,
246 &caller_event_handler,
247 NULL,
248 &phone_speaker,
249 &phone_mic);
250 expect = GNUNET_CONVERSATION_EC_PHONE_HUNG_UP;
251 break;
252 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP:
253 GNUNET_break (caller == active_caller);
254 active_caller = NULL;
255 ok = 0;
256 GNUNET_SCHEDULER_shutdown ();
257 break;
258 default:
259 fprintf (stderr, "Unexpected phone code: %d\n", code);
260 break;
261 }
183} 262}
184 263
185 264
186static void 265static void
187caller_event_handler (void *cls, 266call_event_handler (void *cls,
188 enum GNUNET_CONVERSATION_CallEventCode code) 267 enum GNUNET_CONVERSATION_CallEventCode code)
189{ 268{
190 fprintf (stderr, "Caller code: %d\n", code); 269 static enum GNUNET_CONVERSATION_CallEventCode expect
270 = GNUNET_CONVERSATION_EC_CALL_RINGING;
271
272 GNUNET_break (code == expect);
273 switch (code)
274 {
275 case GNUNET_CONVERSATION_EC_CALL_RINGING:
276 expect = GNUNET_CONVERSATION_EC_CALL_PICKED_UP;
277 break;
278 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
279 expect = -1;
280 GNUNET_CONVERSATION_call_stop (call);
281 call = NULL;
282 break;
283 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
284 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
285 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
286 case GNUNET_CONVERSATION_EC_CALL_RESUMED:
287 fprintf (stderr, "Unexpected call code: %d\n", code);
288 break;
289 }
191} 290}
192 291
193 292
@@ -253,12 +352,16 @@ identity_cb (void *cls,
253 } 352 }
254 if (0 == strcmp (name, "caller-ego")) 353 if (0 == strcmp (name, "caller-ego"))
255 { 354 {
355 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
356 GNUNET_asprintf (&gns_caller_id,
357 "%s",
358 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
256 call = GNUNET_CONVERSATION_call_start (cfg, 359 call = GNUNET_CONVERSATION_call_start (cfg,
257 ego, 360 ego,
258 gns_name, 361 gns_name,
259 &caller_speaker, 362 &caller_speaker,
260 &caller_mic, 363 &caller_mic,
261 &caller_event_handler, 364 &call_event_handler,
262 NULL); 365 NULL);
263 return; 366 return;
264 } 367 }