aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-conversation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-11-15 19:06:55 +0000
committerChristian Grothoff <christian@grothoff.org>2013-11-15 19:06:55 +0000
commitdd594a4b0a7dbc57ea49f8a797a7a412e53baa53 (patch)
tree6a651b061395ebd9370cef01f14655ff50e81a66 /src/conversation/gnunet-conversation.c
parent1c405f3fb76f509113526678dbe9a5736dfce394 (diff)
downloadgnunet-dd594a4b0a7dbc57ea49f8a797a7a412e53baa53.tar.gz
gnunet-dd594a4b0a7dbc57ea49f8a797a7a412e53baa53.zip
-towards enabling call waiting in conversation -- creates FTBFS
Diffstat (limited to 'src/conversation/gnunet-conversation.c')
-rw-r--r--src/conversation/gnunet-conversation.c201
1 files changed, 125 insertions, 76 deletions
diff --git a/src/conversation/gnunet-conversation.c b/src/conversation/gnunet-conversation.c
index ea2ba9ac8..0287114f2 100644
--- a/src/conversation/gnunet-conversation.c
+++ b/src/conversation/gnunet-conversation.c
@@ -86,16 +86,64 @@ enum ConversationState
86 86
87 87
88/** 88/**
89 * List of incoming calls
90 */
91struct CallList
92{
93
94 /**
95 * A DLL.
96 */
97 struct CallList *prev;
98
99 /**
100 * A DLL.
101 */
102 struct CallList *next;
103
104 /**
105 * Handle to hang up or activate.
106 */
107 struct GNUNET_CONVERSATION_Caller *caller;
108
109 /**
110 * String identifying the caller.
111 */
112 const char *caller_id;
113
114 /**
115 * Unique number of the call.
116 */
117 unsigned int caller_num;
118};
119
120
121/**
89 * Phone handle 122 * Phone handle
90 */ 123 */
91static struct GNUNET_CONVERSATION_Phone *phone; 124static struct GNUNET_CONVERSATION_Phone *phone;
92 125
93/** 126/**
94 * Call handle 127 * Call handle (for active outgoing call).
95 */ 128 */
96static struct GNUNET_CONVERSATION_Call *call; 129static struct GNUNET_CONVERSATION_Call *call;
97 130
98/** 131/**
132 * Caller handle (for active incoming call).
133 */
134static struct CallList *cl_active;
135
136/**
137 * Head of calls waiting to be accepted.
138 */
139static struct CallList *cl_head;
140
141/**
142 * Tail of calls waiting to be accepted.
143 */
144static struct CallList *cl_tail;
145
146/**
99 * Desired phone line. 147 * Desired phone line.
100 */ 148 */
101static unsigned int line; 149static unsigned int line;
@@ -151,6 +199,11 @@ static struct GNUNET_DISK_FileHandle *stdin_fh;
151static enum ConversationState state; 199static enum ConversationState state;
152 200
153/** 201/**
202 * Counts the number of incoming calls we have had so far.
203 */
204static unsigned int caller_num_gen;
205
206/**
154 * GNS address for this phone. 207 * GNS address for this phone.
155 */ 208 */
156static char *address; 209static char *address;
@@ -165,50 +218,55 @@ static int verbose;
165 * Function called with an event emitted by a phone. 218 * Function called with an event emitted by a phone.
166 * 219 *
167 * @param cls closure 220 * @param cls closure
168 * @param code type of the event on the phone 221 * @param code type of the event
169 * @param ... additional information, depends on @a code 222 * @param caller handle for the caller
223 * @param caller_id name of the caller in GNS
170 */ 224 */
171static void 225static void
172phone_event_handler (void *cls, 226phone_event_handler (void *cls,
173 enum GNUNET_CONVERSATION_EventCode code, 227 enum GNUNET_CONVERSATION_PhoneEventCode code,
174 ...) 228 struct GNUNET_CONVERSATION_Caller *caller,
229 const char *caller_id)
175{ 230{
176 va_list va;
177
178 va_start (va, code);
179 switch (code) 231 switch (code)
180 { 232 {
181 case GNUNET_CONVERSATION_EC_RING: 233 case GNUNET_CONVERSATION_EC_PHONE_RING:
182 GNUNET_break (CS_LISTEN == state); 234 // FIXME: update state!
183 GNUNET_free_non_null (peer_name);
184 peer_name = GNUNET_strdup (va_arg (va, const char *));
185 FPRINTF (stdout, 235 FPRINTF (stdout,
186 _("Incoming call from `%s'.\nPlease /accept or /cancel the call.\n"), 236 _("Incoming call from `%s'.\nPlease /accept #%u or /cancel %u the call.\n"),
187 peer_name); 237 caller_id,
188 state = CS_RING; 238 caller_num_gen,
189 break; 239 caller_num_gen);
190 case GNUNET_CONVERSATION_EC_RINGING:
191 GNUNET_break (0);
192 break;
193 case GNUNET_CONVERSATION_EC_READY:
194 GNUNET_break (0);
195 break;
196 case GNUNET_CONVERSATION_EC_GNS_FAIL:
197 GNUNET_break (0);
198 break;
199 case GNUNET_CONVERSATION_EC_BUSY:
200 GNUNET_break (0);
201 break; 240 break;
202 case GNUNET_CONVERSATION_EC_TERMINATED: 241 case GNUNET_CONVERSATION_EC_PHONE_HUNG_UP:
203 GNUNET_break ( (CS_RING == state) || 242 // FIXME: update state!
204 (CS_ACCEPTED == state) );
205 FPRINTF (stdout, 243 FPRINTF (stdout,
206 _("Call terminated: %s\n"), 244 _("Call terminated: %s\n"),
207 va_arg (va, const char *)); 245 caller_id);
208 state = CS_LISTEN; 246 break;
247 }
248}
249
250
251/**
252 * Function called with an event emitted by a caller.
253 *
254 * @param cls closure with the `struct CallList` of the caller
255 * @param code type of the event issued by the caller
256 */
257static void
258caller_event_handler (void *cls,
259 enum GNUNET_CONVERSATION_CallerEventCode code)
260{
261 switch (code)
262 {
263 case GNUNET_CONVERSATION_EC_CALLER_SUSPEND:
264 // FIXME: notify user!
265 break;
266 case GNUNET_CONVERSATION_EC_CALLER_RESUME:
267 // FIXME: notify user!
209 break; 268 break;
210 } 269 }
211 va_end (va);
212} 270}
213 271
214 272
@@ -257,26 +315,18 @@ start_phone ()
257 315
258 316
259/** 317/**
260 * Function called with an event emitted by a phone. 318 * Function called with an event emitted by a call.
261 * 319 *
262 * @param cls closure 320 * @param cls closure
263 * @param code type of the event on the phone 321 * @param code type of the event on the call
264 * @param ... additional information, depends on @a code
265 */ 322 */
266static void 323static void
267call_event_handler (void *cls, 324call_event_handler (void *cls,
268 enum GNUNET_CONVERSATION_EventCode code, 325 enum GNUNET_CONVERSATION_CallEventCode code)
269 ...)
270{ 326{
271 va_list va;
272
273 va_start (va, code);
274 switch (code) 327 switch (code)
275 { 328 {
276 case GNUNET_CONVERSATION_EC_RING: 329 case GNUNET_CONVERSATION_EC_CALL_RINGING:
277 GNUNET_break (0);
278 break;
279 case GNUNET_CONVERSATION_EC_RINGING:
280 GNUNET_break (CS_RESOLVING == state); 330 GNUNET_break (CS_RESOLVING == state);
281 if (verbose) 331 if (verbose)
282 FPRINTF (stdout, 332 FPRINTF (stdout,
@@ -284,41 +334,37 @@ call_event_handler (void *cls,
284 _("Resolved address. Now ringing other party.\n")); 334 _("Resolved address. Now ringing other party.\n"));
285 state = CS_RINGING; 335 state = CS_RINGING;
286 break; 336 break;
287 case GNUNET_CONVERSATION_EC_READY: 337 case GNUNET_CONVERSATION_EC_CALL_PICKED_UP:
288 GNUNET_break (CS_RINGING == state); 338 GNUNET_break (CS_RINGING == state);
289 FPRINTF (stdout, 339 FPRINTF (stdout,
290 _("Connection established to `%s': %s\n"), 340 _("Connection established to `%s'\n"),
291 peer_name, 341 peer_name);
292 va_arg (va, const char *));
293 state = CS_CONNECTED; 342 state = CS_CONNECTED;
294 break; 343 break;
295 case GNUNET_CONVERSATION_EC_GNS_FAIL: 344 case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL:
296 GNUNET_break (CS_RESOLVING == state); 345 GNUNET_break (CS_RESOLVING == state);
297 FPRINTF (stdout, 346 FPRINTF (stdout,
298 _("Failed to resolve `%s'\n"), 347 _("Failed to resolve `%s'\n"),
299 ego_name); 348 ego_name);
300 call = NULL; 349 call = NULL;
301 start_phone (); 350 state = CS_LISTEN;
302 break; 351 break;
303 case GNUNET_CONVERSATION_EC_BUSY: 352 case GNUNET_CONVERSATION_EC_CALL_HUNG_UP:
304 GNUNET_break (CS_RINGING == state);
305 FPRINTF (stdout, 353 FPRINTF (stdout,
306 "%s", 354 "%s",
307 _("Line busy\n")); 355 _("Call terminated\n"));
308 call = NULL; 356 call = NULL;
309 start_phone (); 357 state = CS_LISTEN;
310 break; 358 break;
311 case GNUNET_CONVERSATION_EC_TERMINATED: 359 case GNUNET_CONVERSATION_EC_CALL_SUSPENDED:
312 GNUNET_break ( (CS_RINGING == state) || 360 // FIXME: notify user
313 (CS_CONNECTED == state) ); 361 // state = CS_SUSPENDED_CALL;
314 FPRINTF (stdout, 362 break;
315 _("Call terminated: %s\n"), 363 case GNUNET_CONVERSATION_EC_CALL_RESUMED:
316 va_arg (va, const char *)); 364 // FIXME: notify user
317 call = NULL; 365 // state = CS_CONNECTED;
318 start_phone ();
319 break; 366 break;
320 } 367 }
321 va_end (va);
322} 368}
323 369
324 370
@@ -417,7 +463,7 @@ do_call (const char *arg)
417 _("Hanging up on incoming phone call from `%s' to call `%s'.\n"), 463 _("Hanging up on incoming phone call from `%s' to call `%s'.\n"),
418 peer_name, 464 peer_name,
419 arg); 465 arg);
420 GNUNET_CONVERSATION_phone_hang_up (phone, NULL); 466 // GNUNET_CONVERSATION_caller_hang_up (caller);
421 break; 467 break;
422 case CS_ACCEPTED: 468 case CS_ACCEPTED:
423 FPRINTF (stderr, 469 FPRINTF (stderr,
@@ -430,7 +476,8 @@ do_call (const char *arg)
430 FPRINTF (stderr, 476 FPRINTF (stderr,
431 _("Aborting call to `%s'\n"), 477 _("Aborting call to `%s'\n"),
432 peer_name); 478 peer_name);
433 GNUNET_CONVERSATION_call_stop (call, NULL); 479 // GNUNET_CONVERSATION_caller_hang_up (caller);
480 // GNUNET_CONVERSATION_call_stop (call);
434 call = NULL; 481 call = NULL;
435 break; 482 break;
436 case CS_CONNECTED: 483 case CS_CONNECTED:
@@ -497,11 +544,12 @@ do_accept (const char *args)
497 peer_name); 544 peer_name);
498 return; 545 return;
499 } 546 }
500 GNUNET_assert (NULL != phone); 547 GNUNET_assert (NULL != cl_active);
501 GNUNET_CONVERSATION_phone_pick_up (phone, 548 GNUNET_CONVERSATION_caller_pick_up (cl_active->caller,
502 args, 549 &caller_event_handler,
503 speaker, 550 cl_active,
504 mic); 551 speaker,
552 mic);
505 state = CS_ACCEPTED; 553 state = CS_ACCEPTED;
506} 554}
507 555
@@ -604,14 +652,15 @@ do_reject (const char *args)
604 } 652 }
605 if (NULL == call) 653 if (NULL == call)
606 { 654 {
607 GNUNET_assert (NULL != phone); 655#if 0
608 GNUNET_CONVERSATION_phone_hang_up (phone, 656 GNUNET_assert (NULL != caller);
609 args); 657 GNUNET_CONVERSATION_caller_hang_up (caller);
658#endif
610 state = CS_LISTEN; 659 state = CS_LISTEN;
611 } 660 }
612 else 661 else
613 { 662 {
614 GNUNET_CONVERSATION_call_stop (call, args); 663 GNUNET_CONVERSATION_call_stop (call);
615 call = NULL; 664 call = NULL;
616 start_phone (); 665 start_phone ();
617 } 666 }
@@ -699,7 +748,7 @@ do_stop_task (void *cls,
699{ 748{
700 if (NULL != call) 749 if (NULL != call)
701 { 750 {
702 GNUNET_CONVERSATION_call_stop (call, NULL); 751 GNUNET_CONVERSATION_call_stop (call);
703 call = NULL; 752 call = NULL;
704 } 753 }
705 if (NULL != phone) 754 if (NULL != phone)