问题
I want to implement Notify event CallBack in CsipSimple here is the C code i have written
My C/C++ files
The pjsip_event_notification.h file
#include <pjsip-simple/evsub.h>
class EventCallBack {
public:
virtual ~EventCallBack() {}
virtual void on_evsub_state(pjsip_evsub *sub, pjsip_event *event){}
virtual void on_tsx_state(pjsip_evsub *sub, pjsip_transaction *tsx,
pjsip_event *event){}
virtual void on_rx_refresh(pjsip_evsub *sub, pjsip_rx_data *rdata,
int p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr,
pjsip_msg_body **p_body){}
virtual void on_rx_notify(pjsip_evsub *sub, pjsip_rx_data *rdata, int *p_st_code,
pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body){}
virtual void on_client_refresh(pjsip_evsub *sub){}
virtual void on_server_timeout(pjsip_evsub *sub){}
};
extern "C" {
void setEventCallbackObject(EventCallBack* eventCallBack);
}
pjsip_event_notification.cpp file
#include "pjsip_event_notification.h"
static EventCallBack* registeredCallbackObject = NULL;
extern "C" {
void on_evsub_state_wrapper(pjsip_evsub *sub, pjsip_event *event){
registeredCallbackObject->on_evsub_state(sub,event);
}
void on_tsx_state_wrapper(pjsip_evsub *sub, pjsip_transaction *tsx,
pjsip_event *event){
registeredCallbackObject-> on_tsx_state(sub,tsx,event);
}
void on_rx_refresh_wrapper(pjsip_evsub *sub, pjsip_rx_data *rdata,
int p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr,
pjsip_msg_body **p_body){
registeredCallbackObject->on_rx_refresh(sub,rdata,p_st_code,p_st_text,res_hdr,p_body);
}
void on_rx_notify_wrapper(pjsip_evsub *sub, pjsip_rx_data *rdata, int *p_st_code,
pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body){
registeredCallbackObject->on_rx_notify(sub,rdata,p_st_code,p_st_text,res_hdr,p_body);
}
void on_client_refresh_wrapper(pjsip_evsub *sub){
registeredCallbackObject->on_client_refresh(sub);
}
void on_server_timeout_wrapper(pjsip_evsub *sub){
registeredCallbackObject->on_server_timeout(sub);
}
// struct event_callback wrapper_callback_event_struct = {
// &on_evsub_state_wrapper,
// &on_tsx_state_wrapper,
// &on_rx_refresh_wrapper,
// &on_rx_notify_wrapper,
// &on_client_refresh_wrapper,
// &on_server_timeout_wrapper
// };
void setEventCallbackObject(EventCallBack* eventCallBack){
registeredCallbackObject=eventCallBack;
}
and the Java files used to implement
package com.csipsimple.events;
import org.pjsip.pjsua.EventCallBack;
import org.pjsip.pjsua.SWIGTYPE_p_int;
import org.pjsip.pjsua.SWIGTYPE_p_p_pj_str_t;
import org.pjsip.pjsua.SWIGTYPE_p_p_pjsip_msg_body;
import org.pjsip.pjsua.SWIGTYPE_p_pjsip_evsub;
import org.pjsip.pjsua.SWIGTYPE_p_pjsip_hdr;
import org.pjsip.pjsua.SWIGTYPE_p_pjsip_rx_data;
import org.pjsip.pjsua.SWIGTYPE_p_pjsip_transaction;
import org.pjsip.pjsua.pjsip_event;
public class EventNotify extends EventCallBack{
@Override
public void on_evsub_state(SWIGTYPE_p_pjsip_evsub sub, pjsip_event event) {
System.out.println("EventNotify on_evsub_state");
super.on_evsub_state(sub, event);
}
@Override
public void on_tsx_state(SWIGTYPE_p_pjsip_evsub sub,
SWIGTYPE_p_pjsip_transaction tsx, pjsip_event event) {
System.out.println("EventNotify on_tsx_state");
super.on_tsx_state(sub, tsx, event);
}
@Override
public void on_rx_refresh(SWIGTYPE_p_pjsip_evsub sub,
SWIGTYPE_p_pjsip_rx_data rdata, int p_st_code,
SWIGTYPE_p_p_pj_str_t p_st_text, SWIGTYPE_p_pjsip_hdr res_hdr,
SWIGTYPE_p_p_pjsip_msg_body p_body) {
System.out.println("EventNotify on_rx_refresh");
super.on_rx_refresh(sub, rdata, p_st_code, p_st_text, res_hdr, p_body);
}
@Override
public void on_rx_notify(SWIGTYPE_p_pjsip_evsub sub,
SWIGTYPE_p_pjsip_rx_data rdata, SWIGTYPE_p_int p_st_code,
SWIGTYPE_p_p_pj_str_t p_st_text, SWIGTYPE_p_pjsip_hdr res_hdr,
SWIGTYPE_p_p_pjsip_msg_body p_body) {
System.out.println("EventNotify on_rx_notify");
super.on_rx_notify(sub, rdata, p_st_code, p_st_text, res_hdr, p_body);
}
@Override
public void on_client_refresh(SWIGTYPE_p_pjsip_evsub sub) {
System.out.println("EventNotify on_client_refresh");
super.on_client_refresh(sub);
}
@Override
public void on_server_timeout(SWIGTYPE_p_pjsip_evsub sub) {
System.out.println("EventNotify on_server_timeout");
super.on_server_timeout(sub);
}
}
}
I wanted to ask how can i get call back to these methods
The complete Src can be cloned at git clone https://Rs9766@bitbucket.org/Rs9766/csipsimple_virtualbox.git
回答1:
This can be done using the the below pjsip_event_notification.cpp
#include "pjsip_event_notification.h"
#include <pjsip.h>
#include <pjsip_ua.h>
#include <pjlib-util.h>
#include <pjlib.h>
#include <pjlib.h>
#include <pjsua.h>
#include <pjsua-lib/pjsua_internal.h>
static EventCallBack* registeredCallbackObject = NULL;
extern "C" {
pj_bool_t on_rx_response_wrapper(pjsip_rx_data *rdata){
registeredCallbackObject->on_rx_response(rdata);
return PJ_FALSE;
}
pj_bool_t on_rx_request_wrapper(pjsip_rx_data *rdata){
registeredCallbackObject->on_rx_request(rdata);
return PJ_FALSE;
}
/* The module instance. */
static pjsip_module mod_event_handler =
{
NULL, NULL, /* prev, next. */
{ (char*)"mod-reg-event", 12 }, /* Name. */
-1, /* Id */
PJSIP_MOD_PRIORITY_TSX_LAYER - 1, /* Priority */
NULL, /* load() */
NULL, /* start() */
NULL, /* stop() */
NULL, /* unload() */
&on_rx_response_wrapper, /* on_rx_request() */
&on_rx_response_wrapper, /* on_rx_response() */
NULL, /* on_tx_request. */
NULL, /* on_tx_response() */
NULL, /* on_tsx_state() */
};
PJ_DECL(pj_status_t) event_callback_init() {
return pjsip_endpt_register_module(pjsua_get_pjsip_endpt(),
&mod_event_handler);
}
void setEventCallbackObject(EventCallBack* eventCallBack){
registeredCallbackObject=eventCallBack;
}
}
the h file for the same pjsip_event_notification.h
#include <pj/config_site.h>
#include <pjsua-lib/pjsua.h>
class EventCallBack {
public:
virtual ~EventCallBack() {}
virtual void on_rx_response(pjsip_rx_data *rdata){
// Target Call Back for Notify message
}
virtual void on_rx_request(pjsip_rx_data *rdata){
}
};
extern "C" {
pj_status_t event_callback_init();
void setEventCallbackObject(EventCallBack* eventCallBack);
}
来源:https://stackoverflow.com/questions/15294920/pjsip-use-sip-specific-event-notification-for-notify-message