[Freeswitch-dev] Event dispatch overview

Ola Bäckström Ola.Backstrom at loxysoft.se
Wed Aug 28 17:46:07 MSD 2013


Hi all,

I've been trying to control eavesdrop with events the last couple of days, but not succeeded. Since I needed to know more how events are dispatched internally to the different channels I've been diving into Freeswitch source code to get some insight.
I thought I could share what I found, and hopefully get some comments or correction. Especially on what I did not find out ... in particular I haven't understood where/how the event dispatch to channels work, I call it "Magic" below...

** Overview of the Freeswitch event system
(see the file src/include/switch_event.h for an overview in the code)


1.       At the core there is an event dispatch queue. (see switch_events.c)

2.       Subscribers can request to be notified when specific events are handled. All mod_xxx stuff does this, see mod_erlang_event, mod_dptools etc (see switch_event_bind(...) function, used to register a handler function for specific events)

3.       Events can be created anywhere in any thread (see switch_event_create*-functions) and edited, by adding key-value pairs called headers (see switch_event_add_header(...) function). Example of this can be found in mod_event_test.c function torture_thread(...).

4.       Such an "unsent" event can be put into the event dispatch queue (see switch_event_fire(...), that function calls switch_event_queue_dispatch(...) that finally calls switch_queue_push(...) to push it onto the queue)

5.       Later... will all relevant subscribers will get their callback handler function called with the event.

**Event handling inside a channel

Each channel contains a couple of queues: event_queue, message_queue, signal_data_queue, private_event_queue, private_event_queue_pri. (see the type switch_core_session_t that equals the struct switch_core_session found in include/private/switch_core_pvt.h)
To make sure an event ends up in one specific channel queue the correct headers must be added between step 3 and 4 above. (see switch_channel_event_set_data(...) ). Example of this can be found in switch_ivr_async.c function switch_ivr_broadcast(...), or in mod_dptools.c where all dialplan commands are implemented.
Then by some unclear mechanism "Magic" will the event leave the central event dispatch queue and end up in one of the channel queues.

**Core State machine
Unclear what role it has, but switch_core_state_machine.c has a mechanism to call driver state handlers depending on the channel state. Events does not seem to be directly involved in those calls.

Regards
/Ola
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-dev/attachments/20130828/99cd461a/attachment-0001.html 


Join us at ClueCon 2013 Aug 6-8, 2013
More information about the FreeSWITCH-dev mailing list