diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-11-18 19:44:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-11-18 19:44:50 +0000 |
commit | 5ffeabe7928665df01fcd2a6ec1cef556b27179e (patch) | |
tree | 858fceb2a1fa174d26283899894a0a35c1e9881b /src/conversation/test_conversation_api.c | |
parent | 0018daf05f889a759964ae8f2a89e18922e72b74 (diff) | |
download | gnunet-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.c | 129 |
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 | ||
46 | static struct GNUNET_NAMESTORE_QueueEntry *qe; | 46 | static struct GNUNET_NAMESTORE_QueueEntry *qe; |
47 | 47 | ||
48 | static struct GNUNET_CONVERSATION_Caller *active_caller; | ||
49 | |||
48 | static char *gns_name; | 50 | static char *gns_name; |
49 | 51 | ||
52 | static char *gns_caller_id; | ||
53 | |||
54 | |||
50 | static int | 55 | static int |
51 | enable_speaker (void *cls) | 56 | enable_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 | |||
59 | static void | 67 | static void |
60 | disable_speaker (void *cls) | 68 | disable_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 | |||
67 | static void | 78 | static void |
68 | play (void *cls, | 79 | play (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 | |||
77 | static void | 92 | static void |
78 | destroy_speaker (void *cls) | 93 | destroy_speaker (void *cls) |
79 | { | 94 | { |
@@ -92,6 +107,15 @@ static struct GNUNET_SPEAKER_Handle caller_speaker = { | |||
92 | }; | 107 | }; |
93 | 108 | ||
94 | 109 | ||
110 | static struct GNUNET_SPEAKER_Handle phone_speaker = { | ||
111 | &enable_speaker, | ||
112 | &play, | ||
113 | &disable_speaker, | ||
114 | &destroy_speaker, | ||
115 | "caller" | ||
116 | }; | ||
117 | |||
118 | |||
95 | static int | 119 | static int |
96 | enable_mic (void *cls, | 120 | enable_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 | |||
106 | static void | 133 | static void |
107 | disable_mic (void *cls) | 134 | disable_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 | |||
114 | static void | 144 | static void |
115 | destroy_mic (void *cls) | 145 | destroy_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 | |||
163 | static 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 | ||
174 | static void | 215 | static void |
216 | caller_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 | |||
229 | static void | ||
175 | phone_event_handler (void *cls, | 230 | phone_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 | ||
186 | static void | 265 | static void |
187 | caller_event_handler (void *cls, | 266 | call_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 | } |