1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
|
/*
Copyright (C) 2005-2009 Michel de Boer <michel@twinklephone.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* @file
* Threads communicate by passing events via event queues.
*/
#ifndef _EVENTS_H
#define _EVENTS_H
#include <queue>
#include "protocol.h"
#include "timekeeper.h"
#include "stun/stun.h"
#include "audio/audio_codecs.h"
#include "parser/sip_message.h"
#include "sockets/socket.h"
#include "sockets/url.h"
#include "threads/mutex.h"
#include "threads/sema.h"
using namespace std;
// Forward declarations
class t_userintf;
/** Different types of events. */
enum t_event_type {
EV_QUIT, /**< Generic quit event */
EV_NETWORK, /**< Network event, eg. SIP message from/to network */
EV_USER, /**< User event, eg. SIP message from/to user */
EV_TIMEOUT, /**< Timer expiry */
EV_FAILURE, /**< Failure, eg. transport failure */
EV_START_TIMER, /**< Start timer */
EV_STOP_TIMER, /**< Stop timer */
EV_ABORT_TRANS, /**< Abort transaction */
EV_STUN_REQUEST, /**< Outgoing STUN request */
EV_STUN_RESPONSE, /**< Received STUN response */
EV_NAT_KEEPALIVE, /**< Send a NAT keep alive packet */
EV_ICMP, /**< ICMP error */
EV_UI, /**< User interface event */
EV_ASYNC_RESPONSE, /**< Response on an asynchronous question */
EV_BROKEN_CONNECTION, /**< Persitent connection to SIP proxy broken */
EV_TCP_PING, /**< Send a TCP ping (double CRLF) */
EV_FN_CALL, /**< Queued function call */
};
/** Abstract parent class for all events */
class t_event {
public:
virtual ~t_event() {}
/** Get the type of this event. */
virtual t_event_type get_type(void) const = 0;
};
/**
* Generic quit event.
* The quit event instructs a thread to exit gracefully.
*/
class t_event_quit : public t_event {
public:
virtual ~t_event_quit();
virtual t_event_type get_type(void) const;
};
/**
* Network events.
* A network event is a SIP message going from the transaction manager
* to the network or v.v.
*/
class t_event_network : public t_event {
private:
/** The SIP message. */
t_sip_message *msg;
public:
unsigned int src_addr; /**< Source IP address of the SIP message (host order). */
unsigned short src_port; /**< Source port of the SIP message (host order). */
unsigned int dst_addr; /**< Destination IP address of the SIP message (host order). */
unsigned short dst_port; /**< Destination port of the SIP message (host order). */
string transport; /**< Transport protocol */
/**
* Constructor.
* The event will keep a copy of the SIP message.
* @param m [in] The SIP message.
*/
t_event_network(t_sip_message *m);
~t_event_network();
t_event_type get_type(void) const;
/**
* Get the SIP message.
* @return Pointer to the SIP message inside this event.
*/
t_sip_message *get_msg(void) const;
};
/**
* User events.
* A user event is a SIP message going from the user to the
* transaction manager or v.v.
*/
class t_event_user : public t_event {
private:
t_sip_message *msg; /**< The SIP message. */
unsigned short tuid; /**< Transaction user id. */
unsigned short tid; /**< Transaction id. */
/**
* Transaction id that is the target of the CANCEL message.
* Only set if tid is a CANCEL transaction and the event
* is sent towards the user.
*/
unsigned short tid_cancel_target;
/** User profile of the user sending/receiving the SIP message. */
t_user *user_config;
public:
/** Constructor.
* @param u [in] User profile.
* @param m [in] SIP message
* @param _tuid [in] Transaction user id associated with this message.
* @param _tid [in] Transaction id of the transaction for this message.
*/
t_event_user(t_user *u, t_sip_message *m, unsigned short _tuid,
unsigned short _tid);
/** Constructor for CANCEL request towards the user.
* @param u [in] User profile.
* @param m [in] SIP message.
* @param _tuid [in] Transaction user id associated with this message.
* @param _tid [in] Transaction id of the transaction for this message.
* @param _tid_cancel_target [in] Id of the target transaction of a CANCEL request.
*/
t_event_user(t_user *u, t_sip_message *m, unsigned short _tuid,
unsigned short _tid, unsigned short _tid_cancel_target);
~t_event_user();
t_event_type get_type(void) const;
/**
* Get the SIP message.
* @return Pointer to the SIP message inside this event.
*/
t_sip_message *get_msg(void) const;
/** Get transaction user id. */
unsigned short get_tuid(void) const;
/** Get transaction id. */
unsigned short get_tid(void) const;
/** Get the CANCEL target transaction id. */
unsigned short get_tid_cancel_target(void) const;
/**
* Get the user profile.
* @return Pointer to the user profile inside the event.
*/
t_user *get_user_config(void) const;
};
/**
* Time out events.
* Expiration of a timer is signalled by a time out event.
*/
class t_event_timeout : public t_event {
private:
/**
* The epxired timer.
* @note Timer pointer will be deleted upon destruction of the object.
*/
t_timer *timer;
public:
/**
* Constructor.
* @param t [in] The expired timer.
* @note The event will keep a copy of the timer.
*/
t_event_timeout(t_timer *t);
~t_event_timeout();
t_event_type get_type(void) const;
/**
* Get the timer from the event.
* @return The timer.
*/
t_timer *get_timer(void) const;
};
/**
* Failure events.
*/
class t_event_failure : public t_event {
private:
t_failure failure; /**< Type of failure. */
/**
* Indicates if the tid value is populated. If the tid value is not
* populated, then the branch and cseq_method are populated.
*/
bool tid_populated;
unsigned short tid; /**< Id of transaction that failed. */
string branch; /**< Branch parameter of SIP message that failed. */
t_method cseq_method; /**< CSeq method of SIP message that failed. */
public:
/**
* Constructor.
* @param f [in] Type of failure.
* @param _tid [in] Transaction id.
*/
t_event_failure(t_failure f, unsigned short _tid);
/** Constructor */
t_event_failure(t_failure f, const string &_branch, const t_method &_cseq_method);
t_event_type get_type(void) const;
/**
* Get the type of failure.
* @return Type of failure.
*/
t_failure get_failure(void) const;
/**
* Get the transaction id.
* @return Transaction id.
*/
unsigned short get_tid(void) const;
/** Get branch parameter. */
string get_branch(void) const;
/** Get CSeq method. */
t_method get_cseq_method(void) const;
/** Check if tid is populated. */
bool is_tid_populated(void) const;
};
/**
* Start timer event.
* A start timer event instructs the time keeper to start a timer.
*/
class t_event_start_timer : public t_event {
private:
t_timer *timer; /**< The timer to start. */
public:
/**
* Constructor.
* @param t [in] The timer to start.
*/
t_event_start_timer(t_timer *t);
t_event_type get_type(void) const;
/**
* Get the timer.
* @return Timer.
*/
t_timer *get_timer(void) const;
};
/**
* Stop timer event
* A stop timer event instructs the time keeper to stop a timer.
*/
class t_event_stop_timer : public t_event {
private:
/** Id of the timer to stop. */
unsigned short timer_id;
public:
/**
* Constructor.
* @param id [in] Id of the timer to stop.
*/
t_event_stop_timer(unsigned short id);
t_event_type get_type(void) const;
/**
* Get the timer id.
* @return Timer id.
*/
unsigned short get_timer_id(void) const;
};
/**
* Abort transaction event.
* With an abort transaction event, the requester asks the transaction
* manager to abort a pending transaction.
*/
class t_event_abort_trans : public t_event {
private:
unsigned short tid; /**< Id of the transaction to abort. */
public:
/**
* Constructor.
* @param _tid [in] Transaction id.
*/
t_event_abort_trans(unsigned short _tid);
t_event_type get_type(void) const;
/**
* Get transaction id.
* @return Transaction id.
*/
unsigned short get_tid(void) const;
};
/** STUN event types. */
enum t_stun_event_type {
TYPE_STUN_SIP, /**< Request to open a port for SIP. */
TYPE_STUN_MEDIA, /**< Request to open a port for media. */
};
/**
* STUN request event.
*/
class t_event_stun_request : public t_event {
private:
StunMessage *msg; /**< STUN request to send. */
unsigned short tuid; /**< Transaction user id. */
unsigned short tid; /**< Transaction id. */
t_stun_event_type stun_event_type; /**< Type of STUN event. */
t_user *user_config; /**< User profile associated with this request. */
public:
unsigned int dst_addr; /**< Destination address of request (host order). */
unsigned short dst_port; /**< Destination port of request (host order). */
unsigned short src_port; /**< Source port for media event type (host order). */
/** Constructor. */
t_event_stun_request(t_user *u, StunMessage *m, t_stun_event_type ev_type,
unsigned short _tuid, unsigned short _tid);
~t_event_stun_request();
t_event_type get_type(void) const;
/** Get STUN message. */
StunMessage *get_msg(void) const;
/** Get transaction user id. */
unsigned short get_tuid(void) const;
/** Get transaction id. */
unsigned short get_tid(void) const;
/** Get STUN event type. */
t_stun_event_type get_stun_event_type(void) const;
/** Get user profile. */
t_user *get_user_config(void) const;
};
/**
* STUN response event.
*/
class t_event_stun_response : public t_event {
private:
StunMessage *msg; /**< STUN request to send. */
unsigned short tuid; /**< Transaction user id. */
unsigned short tid; /**< Transaction id. */
public:
/** Constructor. */
t_event_stun_response(StunMessage *m, unsigned short _tuid,
unsigned short _tid);
~t_event_stun_response();
t_event_type get_type(void) const;
/** Get STUN message. */
StunMessage *get_msg(void) const;
/** Get transaction user id. */
unsigned short get_tuid(void) const;
/** Get transaction id. */
unsigned short get_tid(void) const;
};
/**
* NAT keep alive event.
* Request to send a NAT keep alive message.
*/
class t_event_nat_keepalive : public t_event {
public:
unsigned int dst_addr; /**< Destination address for keepalive (host order) */
unsigned short dst_port; /**< Destination port (host order) */
t_event_type get_type(void) const;
};
/**
* ICMP event.
* This event signals the reception of an ICMP error.
*/
class t_event_icmp : public t_event {
private:
t_icmp_msg icmp; /**< The received ICMP message. */
public:
/**
* Constructor.
* @param m [in] ICMP message.
*/
t_event_icmp(const t_icmp_msg &m);
t_event_type get_type(void) const;
/**
* Get the ICMP message.
* @return ICMP message.
*/
t_icmp_msg get_icmp(void) const;
};
/** User interface callback types. */
enum t_ui_event_type {
TYPE_UI_CB_DISPLAY_MSG, /**< Display a message */
TYPE_UI_CB_DTMF_DETECTED, /**< DTMF tone detected */
TYPE_UI_CB_SEND_DTMF, /**< Sending DTMF */
TYPE_UI_CB_RECV_CODEC_CHANGED, /**< Codec changed */
TYPE_UI_CB_LINE_STATE_CHANGED, /**< Line state changed */
TYPE_UI_CB_LINE_ENCRYPTED, /**< Line is now encrypted */
TYPE_UI_CB_SHOW_ZRTP_SAS, /**< Show the ZRTP SAS */
TYPE_UI_CB_ZRTP_CONFIRM_GO_CLEAR, /**< ZRTP Confirm go-clear */
TYPE_UI_CB_QUIT /**< Quit the user interface */
};
/** Display message priorities. */
enum t_msg_priority {
MSG_NO_PRIO,
MSG_INFO,
MSG_WARNING,
MSG_CRITICAL
};
/**
* User interface event.
* Send a user interface callback to the user interface.
* Most callbacks are called directly as a function call.
* Sometimes an asynchronous callback is needed. That's where
* this event is used for.
*/
class t_event_ui : public t_event {
private:
t_ui_event_type type; /**< User interface callback type. */
/** @name Parameters for call back functions */
//@{
int line; /**< Line number. */
t_audio_codec codec; /**< Audio codec. */
char dtmf_event; /**< DTMF event. */
bool encrypted; /**< Encryption indication. */
string cipher_mode; /**< Cipher mode (algorithm name). */
string zrtp_sas; /**< ZRTP SAS/ */
t_msg_priority msg_priority; /**< Priority of a display message. */
string msg; /**> Message to display. */
//@}
public:
/**
* Constructor.
* @param _type [in] Type of callback.
*/
t_event_ui(t_ui_event_type _type);
t_event_type get_type(void) const;
/** @name Set parameters for call back functions */
//@{
void set_line(int _line);
void set_codec(t_audio_codec _codec);
void set_dtmf_event(char _dtmf_event);
void set_encrypted(bool on);
void set_cipher_mode(const string &_cipher_mode);
void set_zrtp_sas(const string &sas);
void set_display_msg(const string &_msg, t_msg_priority &_msg_priority);
//@}
/**
* Call the callback function.
* @param user_intf [in] The user interface that receives the callback.
*/
void exec(t_userintf *user_intf);
};
/**
* Asynchronous response event.
* A user interface can open an asynchronous message box to request
* information from the user. Via this event the user interface signals
* the response from the user.
*/
class t_event_async_response : public t_event {
public:
/** Response type */
enum t_response_type {
RESP_REFER_PERMISSION /**< Response on permission to refer question */
};
private:
t_response_type response_type; /**< Response type. */
bool bool_response; /**< Boolean response. */
public:
/**
* Constructor.
* @param type [in] The response type.
*/
t_event_async_response(t_response_type type);
t_event_type get_type(void) const;
/**
* Set the boolean response.
* @param b [in] The response.
*/
void set_bool_response(bool b);
/**
* Get response type.
* @return Response type.
*/
t_response_type get_response_type(void) const;
/**
* Get boolean response.
* @return The response.
*/
bool get_bool_response(void) const;
};
/**
* Broken connection event.
* A persistent connection to a SIP proxy is broken. With this event
* the transport layer signals the transaction layer that a connection
* is broken.
*/
class t_event_broken_connection : public t_event {
private:
/** The user URI (AoR) that the connection was associated with. */
t_url user_uri_;
public:
/** Constructor */
t_event_broken_connection(const t_url &url);
t_event_type get_type(void) const;
/**
* Get the user URI.
* @return The user URI.
*/
t_url get_user_uri(void) const;
};
/**
* TCP ping event.
* Send a TCP ping (double CRLF).
*/
class t_event_tcp_ping : public t_event {
private:
/** The user URI (AoR) for which the ping must be sent. */
t_url user_uri_;
unsigned int dst_addr_; /**< Destination address for ping (host order) */
unsigned short dst_port_; /**< Destination port (host order) */
public:
/** Constructor */
t_event_tcp_ping(const t_url &url, unsigned int dst_addr, unsigned short dst_port);
t_event_type get_type(void) const;
/** @name Getters */
//@{
t_url get_user_uri(void) const;
unsigned int get_dst_addr(void) const;
unsigned short get_dst_port(void) const;
//@}
};
class t_event_fncall : public t_event {
public:
t_event_fncall(std::function<void()> fn);
void invoke();
virtual t_event_type get_type(void) const override;
private:
std::function<void()> m_fn;
};
/**
* Event queue.
* An event queue is the communication pipe between multiple
* threads. Multiple threads write events into the queue and
* one thread reads the events from the queue and processes them
* Access to the queue is protected by a mutex. A semaphore is
* used to synchronize the reader with the writers of the queue.
*/
class t_event_queue {
private:
queue<t_event *> ev_queue; /**< Queue of events. */
t_mutex mutex_evq; /**< Mutex to protect access to the queue. */
t_semaphore sema_evq; /**< Semephore counting the number of events. */
/**
* Semaphore to signal an interrupt.
* Will be posted when the interrupt method is called.
*/
t_semaphore sema_caught_interrupt;
public:
/** Constructor. */
t_event_queue();
~t_event_queue();
/**
* Push an event into the queue.
* @param e [in] Event
*/
void push(t_event *e);
/** Push a quit event into the queue. */
void push_quit(void);
/** Push a queued function call */
void push_fncall(std::function<void()> fn);
/**
* Create a network event and push it into the queue.
* @param m [in] SIP message.
* @param ipaddr [in] Destination address of the message (host order).
* @param port [in] Port of the message (host order).
*/
void push_network(t_sip_message *m, const t_ip_port &ip_port);
/**
* Create a user event and push it into the queue.
* The user event must be associated with a user profile.
* @param user_config [in] The user profile.
* @param m [in] SIP message.
* @param tuid [in] Transaction user id.
* @param tid [in] Transaction id.
*/
void push_user(t_user *user_config, t_sip_message *m, unsigned short tuid,
unsigned short tid);
/**
* Create a user event and push it into the queue.
* The user event must be unrelated to a particular user profile.
* @param m [in] SIP message.
* @param tuid [in] Transaction user id.
* @param tid [in] Transaction id.
*/
void push_user(t_sip_message *m, unsigned short tuid,
unsigned short tid);
/**
* Create a cancel event for a user.
* @param user_config [in] The user profile.
* @param m [in] SIP message.
* @param tuid [in] Transaction user id.
* @param tid [in] Transaction id.
*/
void push_user_cancel(t_user *user_config, t_sip_message *m, unsigned short tuid,
unsigned short tid, unsigned short target_tid);
/**
* Create a cancel event for a user.
* @param m [in] SIP message.
* @param tuid [in] Transaction user id.
* @param tid [in] Transaction id.
*/
void push_user_cancel(t_sip_message *m, unsigned short tuid,
unsigned short tid, unsigned short target_tid);
/**
* Create a timeout event and push it into the queue.
* @param t [in] The timer that expired.
*/
void push_timeout(t_timer *t);
/**
* Create failure event and push it into the queue.
* @param f [in] Type of failure.
* @param tid [in] Transaction id of failed transaction.
*/
void push_failure(t_failure f, unsigned short tid);
/**
* Create failure event and push it into the queue.
* @param f [in] Type of failure.
* @param branch [in] Branch parameter of failed transaction.
* @param cseq_method [in] CSeq method of failed transaction.
*/
void push_failure(t_failure f, const string &branch, const t_method &cseq_method);
/**
* Create a start timer event.
* @param t [in] Timer to start.
*/
void push_start_timer(t_timer *t);
/**
* Create a stop timer event.
* @param timer_id [in] Timer id of timer to stop.
*/
void push_stop_timer(unsigned short timer_id);
/**
* Create an abort transaction event.
* @param tid [in] Transaction id of transaction to abort.
*/
void push_abort_trans(unsigned short tid);
/**
* Create a STUN request event.
* @param user_config [in] The user profile associated with the request.
* @param m [in] STUN request.
* @param ev_type [in] Type of STUN event.
* @param tuid [in] Transaction user id.
* @param tid [in] Transaction id.
* @param ipaddr [in] Destination address (host order)
* @param port [in] Destination port (host order)
* @param src_port [in] Source port of media. This must only be passed for
* a media STUN event.
*/
void push_stun_request(t_user *user_config, StunMessage *m, t_stun_event_type ev_type,
unsigned short tuid, unsigned short tid,
unsigned long ipaddr, unsigned short port, unsigned short src_port = 0);
/**
* Create a STUN response event.
* @param m [in] STUN response.
* @param tuid [in] Transaction user id.
* @param tid [in] Transaction id.
*/
void push_stun_response(StunMessage *m,
unsigned short tuid, unsigned short tid);
/**
* Create a NAT keepalive event.
* @param ipaddr [in] Destination address (host order)
* @param port [in] Destination port (host order)
*/
void push_nat_keepalive(unsigned long ipaddr, unsigned short port);
/**
* Create ICMP event.
* @param m [in] ICMP message.
*/
void push_icmp(const t_icmp_msg &m);
/**
* Create a REFER pemission response event.
* @param permission [in] Permission allowed?.
*/
void push_refer_permission_response(bool permission);
/**
* Create a broken connection event.
* @param user_uri [in] The user URI (AoR) associated with the connection.
*/
void push_broken_connection(const t_url &user_uri);
/**
* Create a TCP ping event.
* @param user_uri [in] The user URI (AoR) for which the TCP ping must be sent.
* @param dst_addr [in] The destination IPv4 address for the ping.
* @param dst_port [in] The destination TCP port for the ping.
*/
void push_tcp_ping(const t_url &user_uri, unsigned int dst_addr, unsigned short dst_port);
/**
* Pop an event from the queue.
* If the queue is empty then the thread will be blocked until an
* event arrives.
* @return The popped event.
*/
t_event *pop(void);
/**
* Pop an event from the queue.
* Same method as above, but this one can be interrupted by
* calling the method interrupt.
* @param interrupted [out] When the pop operation is interrupted this
* parameter is set to true. Otherwise it is false.
* @return NULL, when interrupted.
* @return The popped event, otherwise.
*/
t_event *pop(bool &interrupted);
/**
* Send an interrupt.
* This will cause the interruptable pop to return.
* A non-interruptable pop will ignore the interrupt.
* If pop is currently not suspending the thread execution then the
* next call to pop will catch the interrupt.
*/
void interrupt(void);
};
#endif
|