0

I'm using CSipSimple for android and trying to set log callback to receive pjsip library log messages. In log configuration there is a function setCb but I don't understand how declare callback and use it.

pjsua_logging_config logCfg = new pjsua_logging_config();
logCfg.setLevel(1);
logCfg.setMsg_logging(pjsuaConstants.PJ_TRUE);
logCfg.setCb(?????);

In CSipSimple pjsua_logging_config setCb declared as:

public void setCb(SWIGTYPE_p_f_int_p_q_const__char_int__void value) {
pjsuaJNI.pjsua_logging_config_cb_set(swigCPtr, this, SWIGTYPE_p_f_int_p_q_const__char_int__void.getCPtr(value));

In pjsip - http://www.pjsip.org/pjsip/docs/html/structpjsua__logging__config.htm

Thanks for any help.

Sergey L
  • 11
  • 1
  • 4

1 Answers1

0

Use something like this:

logCfg.setCb(new pjsua_callback(pjsuaJNI.WRAPPER_CALLBACK_STRUCT_get(), false));

You can refer this project for sample: https://github.com/tqcenglish/CSipSimple

Edit:

logCfg.setCb(new SWIGTYPE_p_f_int_p_q_const__char_int__void(pjsua_logging_config.getCPtr(logCfg), false));
Cao Minh Vu
  • 1,900
  • 1
  • 16
  • 21
  • I get compile error - The method setCb(SWIGTYPE_p_f_int_p_q_const__char_int__void) in the type pjsua_logging_config is not applicable for the arguments (pjsua_callback) . And pjsua_callback has no declaration of log callback. – Sergey L Mar 21 '18 at 10:03
  • Yes now its compiled but in SWIGTYPE_p_f_int_p_q_const__char_int__void no callback declared. This is set of callback but where is callback? As I understand in this class must be something like: public void on_log_message(int level, char[] data, int len) – Sergey L Mar 21 '18 at 10:30
  • yes, this is just the answer for your question :). You should not use the api setCb() directly. Please have a look on the setCb in this class: https://github.com/tqcenglish/CSipSimple/blob/260776a210a4673e30b4bb5e47e25cd7e348d0ed/app/src/main/java/org/pjsip/pjsua/pjsua_config.java, you should use this setCb() api instead – Cao Minh Vu Mar 21 '18 at 10:33
  • I see that cfg.setCb(pjsuaConstants.WRAPPER_CALLBACK_STRUCT) setting callback same way. But can't understand how its running, where its declared. I see only pjsua.setCallbackObject(userAgentReceiver) and UAStateReceiver extends Callback wich has all events on_icoming_call, on_call_state. I'm confused( – Sergey L Mar 21 '18 at 11:08
  • If you read the source code, you will see that you do not need to setCb(), it will set itself in getCb(). This is an example how to use pjsua_logging_config: https://www.programcreek.com/java-api-examples/index.php?source_dir=CSipSimple-master/app/src/main/java/com/csipsimple/pjsip/PjSipService.java – Cao Minh Vu Mar 22 '18 at 02:46
  • I found in CSipSimple library source log_cfg->cb = &pj_android_log_msg; .... PJ_DEF(void) pj_android_log_msg(int level, const char *data, int len) { const char delims[] = "\n"; char* cpy = strndup(data, len); char *line = strtok(cpy, delims); while(line != NULL){ if (level <= 1) { LOGE("%s", line); ... Is that mean that log callback set inside libpjsipjni library and can't be used outside? If yes - I can't set callback outside library( – Sergey L Mar 23 '18 at 09:13