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