From 27896c14e3d5edab41fca3f87c39221dd1a06668 Mon Sep 17 00:00:00 2001 From: Riza Sulistyo Date: Wed, 24 Apr 2013 04:55:00 +0000 Subject: Re #1655: pjsua app CLI for android git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4496 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/pjsua/android/jni/Android.mk | 61 +++++++++++ pjsip-apps/src/pjsua/android/jni/pjsua.i | 29 ++++++ .../src/pjsua/android/jni/pjsua_app_callback.cpp | 113 +++++++++++++++++++++ .../src/pjsua/android/jni/pjsua_app_callback.h | 36 +++++++ 4 files changed, 239 insertions(+) create mode 100644 pjsip-apps/src/pjsua/android/jni/Android.mk create mode 100755 pjsip-apps/src/pjsua/android/jni/pjsua.i create mode 100644 pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp create mode 100644 pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h (limited to 'pjsip-apps/src/pjsua/android/jni') diff --git a/pjsip-apps/src/pjsua/android/jni/Android.mk b/pjsip-apps/src/pjsua/android/jni/Android.mk new file mode 100644 index 00000000..bcbdbbd6 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/jni/Android.mk @@ -0,0 +1,61 @@ +# $id$ + +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +# Get PJ build settings +include ../../../../build.mak +include $(PJDIR)/build/common.mak + +# Path to SWIG +MY_SWIG := swig + +#======================================================================== +# Choose console application to load +#======================================================================== + +# pjlib test +#MY_MODULE := $(PJDIR)/pjlib/build/output/pjlib-test-$(TARGET_NAME)/*.o + +# pjlib-util test +#MY_MODULE := $(PJDIR)/pjlib-util/build/output/pjlib-util-test-$(TARGET_NAME)/*.o + +# pjsip test +#MY_MODULE := $(PJDIR)/pjsip/build/output/pjsip-test-$(TARGET_NAME)/*.o + +# pjnath test +#MY_MODULE := $(PJDIR)/pjnath/build/output/pjnath-test-$(TARGET_NAME)/*.o + +# pjmedia test +# Note: jbuf test requires Jbtest.dat, this jbuf test must be disabled (for now). +#MY_MODULE := $(PJDIR)/pjmedia/build/output/pjmedia-test-$(TARGET_NAME)/*.o + +# pjsystest app (not supported yet) +# Todo: this test requires some input and output files (log & WAV). +#MY_MODULE := $(PJDIR)/pjsip-apps/build/output/pjsystest-$(TARGET_NAME)/*.o + +# pjsua app +# Note: must set USE_GUI to zero in config_site.h +MY_MODULE := $(PJDIR)/pjsip-apps/build/output/pjsua-$(TARGET_NAME)/*.o + +#======================================================================== + +# Constants +MY_JNI_WRAP := pjsua_wrap.cpp +MY_JNI_DIR := jni + +# Android build settings +LOCAL_MODULE := libpjsua +LOCAL_CFLAGS := -Werror $(APP_CFLAGS) -frtti +LOCAL_LDFLAGS := $(APP_LDFLAGS) +LOCAL_LDLIBS := $(MY_MODULE) $(APP_LDLIBS) +LOCAL_SRC_FILES := $(MY_JNI_WRAP) pjsua_app_callback.cpp + +# Invoke SWIG +$(MY_JNI_DIR)/$(MY_JNI_WRAP): + @echo "Invoking SWIG..." + $(MY_SWIG) -c++ -o $(MY_JNI_DIR)/$(MY_JNI_WRAP) -package org.pjsip.pjsua -outdir src/org/pjsip/pjsua -java $(MY_JNI_DIR)/pjsua.i + +.PHONY: $(MY_JNI_DIR)/$(MY_JNI_WRAP) + +include $(BUILD_SHARED_LIBRARY) diff --git a/pjsip-apps/src/pjsua/android/jni/pjsua.i b/pjsip-apps/src/pjsua/android/jni/pjsua.i new file mode 100755 index 00000000..99443160 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/jni/pjsua.i @@ -0,0 +1,29 @@ +%module (directors="1") pjsua + +%{ +#include "pjsua_app_callback.h" +#include "../../pjsua_app.h" + +#ifdef __cplusplus +extern "C" { +#endif + int pjsuaStart(); + void pjsuaDestroy(); + int pjsuaRestart(); + void setCallbackObject(PjsuaAppCallback* callback); +#ifdef __cplusplus +} +#endif +%} + +int pjsuaStart(); +void pjsuaDestroy(); +int pjsuaRestart(); + +/* turn on director wrapping PjsuaAppCallback */ +%feature("director") PjsuaAppCallback; + +%include "pjsua_app_callback.h" + +void setCallbackObject(PjsuaAppCallback* callback); + diff --git a/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp b/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp new file mode 100644 index 00000000..6268b55e --- /dev/null +++ b/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.cpp @@ -0,0 +1,113 @@ +/* $Id: pjsua_app_callback.cpp $ */ +/* + * Copyright (C) 2012-2012 Teluu Inc. (http://www.teluu.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "pjsua_app_callback.h" +#include "../../pjsua_app.h" +#include "../../pjsua_app_config.h" + +#if defined(PJ_ANDROID) && PJ_ANDROID != 0 + +static PjsuaAppCallback* registeredCallbackObject = NULL; +static pjsua_app_cfg_t android_app_config; +static int restart_argc; +static char **restart_argv; + +extern const char *pjsua_app_def_argv[]; + +#define THIS_FILE "pjsua_app_callback.cpp" + +/** Callback wrapper **/ +void on_cli_started(pj_status_t status, const char *msg) +{ + char errmsg[PJ_ERR_MSG_SIZE]; + if (registeredCallbackObject) { + if ((status != PJ_SUCCESS) && (!msg || !*msg)) { + pj_strerror(status, errmsg, sizeof(errmsg)); + msg = errmsg; + } + registeredCallbackObject->onStarted(msg); + } +} + +void on_cli_stopped(pj_bool_t restart, int argc, char **argv) +{ + if (restart) { + restart_argc = argc; + restart_argv = argv; + } + + if (registeredCallbackObject) { + registeredCallbackObject->onStopped(restart); + } +} + +static int initMain(int argc, char **argv) +{ + pj_status_t status; + android_app_config.argc = argc; + android_app_config.argv = argv; + + status = pjsua_app_init(&android_app_config); + if (status == PJ_SUCCESS) { + status = pjsua_app_run(PJ_FALSE); + } else { + pjsua_app_destroy(); + } + + return status; +} + +int pjsuaStart() +{ + pj_status_t status; + + const char **argv = pjsua_app_def_argv; + int argc = pjsua_app_def_argc; + + pj_bzero(&android_app_config, sizeof(android_app_config)); + + android_app_config.on_started = &on_cli_started; + android_app_config.on_stopped = &on_cli_stopped; + + return initMain(argc, (char**)argv); +} + +void pjsuaDestroy() +{ + pjsua_app_destroy(); + + /** This is on purpose **/ + pjsua_app_destroy(); +} + +int pjsuaRestart() +{ + pj_status_t status; + + pjsuaDestroy(); + + return initMain(restart_argc, restart_argv); +} + +void setCallbackObject(PjsuaAppCallback* callback) +{ + registeredCallbackObject = callback; +} + +#endif diff --git a/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h b/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h new file mode 100644 index 00000000..561b5ce3 --- /dev/null +++ b/pjsip-apps/src/pjsua/android/jni/pjsua_app_callback.h @@ -0,0 +1,36 @@ +/* $Id: pjsua_app_callback.h $ */ +/* + * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef __PJSUA_APP_CALLBACK_H__ +#define __PJSUA_APP_CALLBACK_H__ + +class PjsuaAppCallback { +public: + virtual ~PjsuaAppCallback() {} + virtual void onStarted(const char *msg) {} + virtual void onStopped(int restart) {} +}; + +extern "C" { +int pjsuaStart(); +void pjsuaDestroy(); +int pjsuaRestart(); +void setCallbackObject(PjsuaAppCallback* callback); +} + +#endif /* __PJSUA_APP_CALLBACK_H__ */ -- cgit v1.2.3