diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-11-19 15:06:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-11-19 15:06:33 +0000 |
commit | 060527201fe3cdfc6d892bc7b90e6e6a6745cb78 (patch) | |
tree | 756d70b1c46b8f518854ab39e5de79bcdcf2aaa8 /src | |
parent | 06e79ff3d4ef352ad14d520f4ec503e842e76593 (diff) | |
download | gnunet-060527201fe3cdfc6d892bc7b90e6e6a6745cb78.tar.gz gnunet-060527201fe3cdfc6d892bc7b90e6e6a6745cb78.zip |
-cleaner callback sequencing
Diffstat (limited to 'src')
-rw-r--r-- | src/conversation/conversation_api_call.c | 8 | ||||
-rw-r--r-- | src/conversation/test_conversation_api.c | 100 |
2 files changed, 97 insertions, 11 deletions
diff --git a/src/conversation/conversation_api_call.c b/src/conversation/conversation_api_call.c index 20992c6b5..8722e2452 100644 --- a/src/conversation/conversation_api_call.c +++ b/src/conversation/conversation_api_call.c | |||
@@ -254,12 +254,12 @@ handle_call_resume (void *cls, | |||
254 | break; | 254 | break; |
255 | case CS_SUSPENDED_CALLEE: | 255 | case CS_SUSPENDED_CALLEE: |
256 | call->state = CS_ACTIVE; | 256 | call->state = CS_ACTIVE; |
257 | call->event_handler (call->event_handler_cls, | ||
258 | GNUNET_CONVERSATION_EC_CALL_RESUMED); | ||
259 | call->speaker->enable_speaker (call->speaker->cls); | 257 | call->speaker->enable_speaker (call->speaker->cls); |
260 | call->mic->enable_microphone (call->mic->cls, | 258 | call->mic->enable_microphone (call->mic->cls, |
261 | &transmit_call_audio, | 259 | &transmit_call_audio, |
262 | call); | 260 | call); |
261 | call->event_handler (call->event_handler_cls, | ||
262 | GNUNET_CONVERSATION_EC_CALL_RESUMED); | ||
263 | break; | 263 | break; |
264 | case CS_SUSPENDED_BOTH: | 264 | case CS_SUSPENDED_BOTH: |
265 | call->state = CS_SUSPENDED_CALLER; | 265 | call->state = CS_SUSPENDED_CALLER; |
@@ -296,12 +296,12 @@ handle_call_picked_up (void *cls, | |||
296 | break; | 296 | break; |
297 | case CS_RINGING: | 297 | case CS_RINGING: |
298 | call->state = CS_ACTIVE; | 298 | call->state = CS_ACTIVE; |
299 | call->event_handler (call->event_handler_cls, | ||
300 | GNUNET_CONVERSATION_EC_CALL_PICKED_UP); | ||
301 | call->speaker->enable_speaker (call->speaker->cls); | 299 | call->speaker->enable_speaker (call->speaker->cls); |
302 | call->mic->enable_microphone (call->mic->cls, | 300 | call->mic->enable_microphone (call->mic->cls, |
303 | &transmit_call_audio, | 301 | &transmit_call_audio, |
304 | call); | 302 | call); |
303 | call->event_handler (call->event_handler_cls, | ||
304 | GNUNET_CONVERSATION_EC_CALL_PICKED_UP); | ||
305 | break; | 305 | break; |
306 | case CS_SUSPENDED_CALLER: | 306 | case CS_SUSPENDED_CALLER: |
307 | case CS_SUSPENDED_CALLEE: | 307 | case CS_SUSPENDED_CALLEE: |
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 | |||
37 | static int ok = 1; | 39 | static int ok = 1; |
38 | 40 | ||
39 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 41 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -56,6 +58,48 @@ static char *gns_name; | |||
56 | 58 | ||
57 | static char *gns_caller_id; | 59 | static char *gns_caller_id; |
58 | 60 | ||
61 | static GNUNET_MICROPHONE_RecordedDataCallback phone_rdc; | ||
62 | |||
63 | static void *phone_rdc_cls; | ||
64 | |||
65 | static GNUNET_MICROPHONE_RecordedDataCallback call_rdc; | ||
66 | |||
67 | static void *call_rdc_cls; | ||
68 | |||
69 | static GNUNET_SCHEDULER_TaskIdentifier phone_task; | ||
70 | |||
71 | static GNUNET_SCHEDULER_TaskIdentifier call_task; | ||
72 | |||
73 | |||
74 | static void | ||
75 | phone_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 | |||
89 | static void | ||
90 | call_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 | ||
60 | static int | 104 | static int |
61 | enable_speaker (void *cls) | 105 | enable_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: |