我想在 CsipSimple 中实现通知事件回调这里是我写的 C 代码
我的 C/C++ 文件
pjsip_event_notification.h 文件
#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 文件
#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;
}
以及用于实现的 Java 文件
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);
}
}
}
我想问我如何才能回电这些方法
完整的 Src 可以在 git clone https://Rs9766@bitbucket.org/Rs9766/csipsimple_virtualbox.git克隆