[SR-Users] callback function of tm module

Timo Reimann timo.reimann at 1und1.de
Mon Jun 6 12:40:07 CEST 2011


Hi Bruno,


On 03.06.2011 20:00, Bruno Bresciani wrote:
> Actually I'm migrating my call routing module of version 1.5.0 of
> kamailio to version 3.1.2. I want to understand why the tm module
> registers an event callback after the INVITE message is processed by my
> routing module.
> When I use the dispatcher module for routing, no event callback is
> registered by the tm module.

I am certain that the tm module isn't doing any callback registrations
itself -- at least not by calling register_tmcb() which is used by other
modules exclusively. Some grep'ing and cscope'ing acknowledges that.

It seems to me that some other, intermediary module registers a callback
instead. If it's not a problem for you, run SR in gdb and post a
backtrace from the instance the callback you are wondering about is
allegedly registered. That way, we can take a look at the call flow and
figure out how things work.


Cheers,

--Timo



> 2011/6/3 Timo Reimann <timo.reimann at 1und1.de <mailto:timo.reimann at 1und1.de>>
> 
>     Hey Bruno,
> 
> 
>     On 03.06.2011 16:21, Bruno Bresciani wrote:
>     > In file t_hook.c line 386 "*cbp->callback( trans, cbp->types,
>     params )*"
>     > calls the function to record register_tmcb when I received a
>     INVITE. I'd
>     > like to now how register_tmcb function is call by the function
>     callback.
> 
>     register_tmcb() isn't called by a callback function, it rather works the
>     other way around. For clarity, here's the call flow:
> 
>     (1) A user is interested in being called back on a particular tm event,
>     e.g., TMCB_DESTROY. To be notified of such events, he calls
>     tmcb_register() and passes the set of events (callback types) he is
>     interested in (e.g., TMCB_DESTROY and possibly others) together with the
>     desired callback function and a few other parameters.
>     (2) In tmcb_register(), a few sanity checks are done first (e.g.,
>     callback type is valid, callback function is not NULL, transaction
>     exists, etc.). If they pass, the callback function and the parameters
>     are stored in a list of callbacks (called cb_list in register_tmcb()).
>     (3) When a particular tm event occurs, the tm module checks if any
>     callbacks were registered for that specific event. If so, it executes
>     each registered callback function in sequence, with each function being
>     passed the callback type and callback-specific parameter. The call of
>     the callback is exactly what
> 
>      cbp->callback( trans, type, params )
> 
>     does, at least for call types other than TMCB_REQUEST_IN.
> 
>     For TMCB_REQUEST_IN, the handling is slightly different because
>     callbacks for new SIP requests cannot be associated with an already
>     existing transaction (after all, they are new). With regards to how
>     TMCB_REQUEST_IN-typed callback functions are called, the only difference
>     is that the callback function is being passed the set of all callback
>     types the registering user was interested in, and not just
>     TMCB_REQUEST_IN:
> 
>      cbp->callback( trans, cbp->types, params )
> 
>     (This is line 386.) Actually, I am not quite sure why the extent of
>     returned callback types differs here. I'm using tm callbacks myself but
>     never had to take advantage of that.
> 
> 
>     Anyways, if all you want to do is use tm callbacks from a module of
>     yours, just call register_tmcb() passing
> 
>     - a callback function,
>     - a transaction cell (unless you're registering for TMCB_REQUEST_IN),
>     - a void pointer to something you want to be passed back on callback
>     execution, and
>     - an optional release function for cleanup purposes.
> 
>     Implement your callback-specific logic in the callback function, and
>     that's it. Naturally, your callback function must fit the callback
>     signature defined in t_hooks.h.
> 
> 
>     I hope this answers your question. If not, let us know what you
>     specifically have in mind, i.e., whether you would like to use tm
>     callbacks, change the framework, or whatever.
> 
> 
>     Cheers,
> 
>     --Timo
> 
> 
> 
>     > 2011/6/3 Timo Reimann <timo.reimann at 1und1.de
>     <mailto:timo.reimann at 1und1.de> <mailto:timo.reimann at 1und1.de
>     <mailto:timo.reimann at 1und1.de>>>
>     >
>     >     Hi Bruno,
>     >
>     >
>     >     On 03.06.2011 00:07, Bruno Bresciani wrote:
>     >     > I'm having doubts in the implementation of the callback function
>     >     module
>     >     > tm. As she calls the function to record register_tmcb ()?
>     >     > Can someome help me?
>     >
>     >     Could you be more specific on which part of the tm module you
>     are having
>     >     trouble with?
>     >
>     >     If you need an example on how to use tm's callbacks you may
>     take a look
>     >     at the dialog module, specifically the files dialog.c and
>     >     dlg_handlers.c.
>     >
>     >
>     >     Cheers,
>     >
>     >     --Timo



More information about the sr-users mailing list