pjsip callbacks in C++

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here is what I do in C++ with PJSIP and it works just fine. I create  
a class with a pjmedia_port as the first element. I then pass that as  
the pjmedia_port. Then in the call back, I just cast the pjmedia_port  
to my port class. I do this in a static function that is used for the  
callbacks. The call backs can then do whatever they need to, or call  
a member function using the this:

pj_status_t PlayPort::file_get_frame_get(pjmedia_port *this_port,  
pjmedia_frame *frame)
{
     PlayPort *port = (PlayPort *) this_port;
     port->CallMemberFunction();
}

I've done similar things, including using a "user data field" (if  
supported) for ages with many APIs.

Norman Franke
ASD, Inc.

On Dec 12, 2007, at 12:23 PM, Klaus Darilion wrote:

> Hi Thiago!
>
> Thanks for this hint. I did it similar. I stored the pointer to my  
> main
> object in a global variable. Then, the registered C callback function
> just calls the real callback (a member of my main object).
>
> Unfortunately sometimes my application crashes and I have no idea  
> why :-(
>
> thanks
> klaus
>
>
>
> tloginbr-pjsip at yahoo.com.br schrieb:
>> I have one application in c++. My solution  is not the
>> most pretty, but it works just fine. I have one file
>> called app_main.cpp that has all my callback functions
>> in plain C that I register with pjsua. When the call
>> comes in (on_incoming_call) I use
>> pjsua_call_set_user_data to save the pointer to the
>> object that I have my callback function (the real
>> one). All my callbacks that are inside app_main.cpp
>> only get the address of the object with
>> pjsua_call_get_user_data and then call the real
>> callback function from this object. Bellow is one
>> example for the callback that receives dtmf:
>>
>> static void on_dtmf_digit(pjsua_call_id call_id, int
>> digit )
>> {	
>> void *tpjcCallPtr;
>> tpjcCallPtr = pjsua_call_get_user_data(call_id);
>> 	((TPJCall*)tpjcCallPtr)->ReceiveDTMF((char)digit);
>> }
>>
>>
>> My object that holds the code for the callback is of
>> type TPJCall that has a member function called
>> ReceiveDTMF. It doesn't even need to be static or
>> anything.
>>
>> Thiago
>>
>>> Hi!
>>>
>>> I'm trying to add pjsip to a QT C++ application.
>>> This gives me headaches
>>>   as I have no clue how to make callbacks in C++.
>>> There are lots of
>>> different approaches (static member function as
>>> wrapper, templates ...).
>>>
>>> I tried the static member function wrapper with
>>> logging callbacks but my
>>> application crashes ~50%.
>>>
>>> I wonder if someone have practical tips for my how
>>> to connect pjsip's
>>> callbacks to member functions.
>>>
>>> thanks
>>> klaus
>>>
>>> _______________________________________________
>>> Visit our blog: http://blog.pjsip.org
>>>
>>> pjsip mailing list
>>> pjsip at lists.pjsip.org
>>>
>> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>>
>>
>>
>>       Abra sua conta no Yahoo! Mail, o ?nico sem limite de espa?o  
>> para armazenamento!
>> http://br.mail.yahoo.com/
>>
>> _______________________________________________
>> Visit our blog: http://blog.pjsip.org
>>
>> pjsip mailing list
>> pjsip at lists.pjsip.org
>> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org
>
> _______________________________________________
> Visit our blog: http://blog.pjsip.org
>
> pjsip mailing list
> pjsip at lists.pjsip.org
> http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20071213/31c92ae6/attachment-0001.html 


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux