0

我想在 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克隆

4

1 回答 1

0

这可以使用下面的 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;
 }


}

相同 pjsip_event_notification.h 的 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);
}
于 2013-03-12T13:04:44.790 回答