Commit 4e3c5d95 authored by Ronan's avatar Ronan

fix(PlatformHelpers): clean code, fix coding style, use cpp logger...

parent 2941e64e
......@@ -221,47 +221,47 @@ if (APPLE)
list(APPEND LINPHONE_OBJC_SOURCE_FILES core/paths/paths-apple.mm)
list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES core/paths/paths-apple.h)
elseif(ANDROID)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES core/paths/paths-android.cpp core/platform-helpers/android-helpers.cpp)
elseif (ANDROID)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES core/paths/paths-android.cpp core/platform-helpers/android-platform-helpers.cpp)
list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES core/paths/paths-android.h)
elseif(WIN32)
elseif (WIN32)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES core/paths/paths-windows.cpp)
list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES core/paths/paths-windows.h)
elseif(UNIX)
elseif (UNIX)
list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES core/paths/paths-linux.cpp)
list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES core/paths/paths-linux.h)
endif()
endif ()
set(LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${BELR_INCLUDE_DIRS} ${LIBXSD_INCLUDE_DIRS})
set(LINPHONE_CXX_OBJECTS_DEFINITIONS "-DLIBLINPHONE_EXPORTS")
set(LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${BELR_INCLUDE_DIRS})
if(SOCI_FOUND)
if (SOCI_FOUND)
list(APPEND LINPHONE_CXX_OBJECTS_INCLUDE_DIRS ${SOCI_INCLUDE_DIRS} ${SOCI_MYSQL_INCLUDES})
add_definitions(-DSOCI_ENABLED)
endif()
endif ()
set(LINPHONE_PRIVATE_HEADER_FILES)
foreach(header ${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES})
foreach (header ${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES})
list(APPEND LINPHONE_PRIVATE_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/${header}")
endforeach()
endforeach ()
set(LINPHONE_PRIVATE_HEADER_FILES ${LINPHONE_PRIVATE_HEADER_FILES} PARENT_SCOPE)
bc_apply_compile_flags(LINPHONE_CXX_OBJECTS_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX)
bc_apply_compile_flags(LINPHONE_OBJC_SOURCE_FILES STRICT_OPTIONS_CPP STRICT_OPTIONS_CXX STRICT_OPTIONS_OBJC)
if(ENABLE_STATIC)
if (ENABLE_STATIC)
add_library(
linphone-cxx-objects-static OBJECT
${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES} ${LINPHONE_CXX_OBJECTS_SOURCE_FILES} ${LINPHONE_OBJC_SOURCE_FILES}
)
target_compile_definitions(linphone-cxx-objects-static PRIVATE ${LINPHONE_CXX_OBJECTS_DEFINITIONS})
target_include_directories(linphone-cxx-objects-static SYSTEM PRIVATE ${LINPHONE_CXX_OBJECTS_INCLUDE_DIRS} ${LINPHONE_INCLUDE_DIRS})
endif()
endif ()
if(ENABLE_SHARED)
if (ENABLE_SHARED)
add_library(
linphone-cxx-objects OBJECT
${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES} ${LINPHONE_CXX_OBJECTS_SOURCE_FILES} ${LINPHONE_OBJC_SOURCE_FILES}
......@@ -269,4 +269,4 @@ if(ENABLE_SHARED)
target_compile_definitions(linphone-cxx-objects PRIVATE ${LINPHONE_CXX_OBJECTS_DEFINITIONS})
target_include_directories(linphone-cxx-objects SYSTEM PRIVATE ${LINPHONE_CXX_OBJECTS_INCLUDE_DIRS} ${LINPHONE_INCLUDE_DIRS})
target_compile_options(linphone-cxx-objects PRIVATE "-fPIC")
endif()
endif ()
......@@ -19,14 +19,13 @@
#include <algorithm>
#include "address/address.h"
#include "chat/chat-room/basic-chat-room.h"
#include "core-p.h"
#include "db/main-db.h"
#include "linphone/core.h"
#include "object/object-p.h"
#include "paths/paths.h"
// TODO: Remove me later.
#include "private.h"
// =============================================================================
......
......@@ -22,10 +22,12 @@
#include <list>
#include "chat/chat-room/chat-room.h"
#include "object/object.h"
// =============================================================================
L_DECL_C_STRUCT(LinphoneCore);
LINPHONE_BEGIN_NAMESPACE
class ChatRoom;
......
/*
linphone
Copyright (C) 2017 Belledonne Communications SARL
* android-platform-helpers.h
* Copyright (C) 2010-2017 Belledonne Communications SARL
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <jni.h>
#include "linphone/utils/utils.h"
#include "platform-helpers.h"
#include "logger/logger.h"
// TODO: Remove me later.
#include "private.h"
#ifdef __ANDROID__
// =============================================================================
#include <jni.h>
using namespace std;
LINPHONE_BEGIN_NAMESPACE
class AndroidPlatformHelpers : public PlatformHelpers {
public:
AndroidPlatformHelpers (LinphoneCore *lc, void *system_context);
AndroidPlatformHelpers (LinphoneCore *lc, void *systemContext);
~AndroidPlatformHelpers ();
void setDnsServers () override;
void acquireWifiLock () override;
void releaseWifiLock () override;
......@@ -37,9 +43,9 @@ public:
void releaseMcastLock () override;
void acquireCpuLock () override;
void releaseCpuLock () override;
std::string getDataPath () override;
std::string getConfigPath () override;
~AndroidPlatformHelpers ();
string getDataPath () override;
string getConfigPath () override;
private:
int callVoidMethod (jmethodID id);
static jmethodID getMethodId (JNIEnv *env, jclass klass, const char *method, const char *signature);
......@@ -54,40 +60,37 @@ private:
jmethodID mGetPowerManagerId;
jmethodID mGetDataPathId;
jmethodID mGetConfigPathId;
};
static const char* GetStringUTFChars (JNIEnv* env, jstring string) {
const char *cstring = string ? env->GetStringUTFChars(string, NULL) : NULL;
return cstring;
static const char *GetStringUTFChars (JNIEnv *env, jstring string) {
const char *cstring = string ? env->GetStringUTFChars(string, nullptr) : nullptr;
return cstring;
}
static void ReleaseStringUTFChars (JNIEnv* env, jstring string, const char *cstring) {
if (string) env->ReleaseStringUTFChars(string, cstring);
static void ReleaseStringUTFChars (JNIEnv *env, jstring string, const char *cstring) {
if (string) env->ReleaseStringUTFChars(string, cstring);
}
jmethodID AndroidPlatformHelpers::getMethodId (JNIEnv *env, jclass klass, const char *method, const char *signature) {
jmethodID id = env->GetMethodID(klass, method, signature);
if (id == 0) {
ms_fatal("Could not find java method '%s %s'", method, signature);
}
if (id == 0)
lFatal() << "Could not find java method: `" << method << ", " << signature << "`.";
return id;
}
AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *system_context) : PlatformHelpers(lc) {
JNIEnv *env=ms_get_jni_env();
AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemContext) : PlatformHelpers(lc) {
JNIEnv *env = ms_get_jni_env();
jclass klass = env->FindClass("org/linphone/core/tools/AndroidPlatformHelper");
if (!klass) {
ms_fatal("Could not find java AndroidPlatformHelper class");
return;
}
jmethodID ctor = env->GetMethodID(klass,"<init>", "(Ljava/lang/Object;)V");
mJavaHelper = env->NewObject(klass, ctor, (jobject)system_context);
if (!klass)
lFatal() << "Could not find java AndroidPlatformHelper class.";
jmethodID ctor = env->GetMethodID(klass, "<init>", "(Ljava/lang/Object;)V");
mJavaHelper = env->NewObject(klass, ctor, (jobject)systemContext);
if (!mJavaHelper) {
ms_error("Could not instanciate AndroidPlatformHelper object.");
lError() << "Could not instanciate AndroidPlatformHelper object.";
return;
}
mJavaHelper = (jobject) env->NewGlobalRef(mJavaHelper);
mJavaHelper = (jobject)env->NewGlobalRef(mJavaHelper);
mWifiLockAcquireId = getMethodId(env, klass, "acquireWifiLock", "()V");
mWifiLockReleaseId = getMethodId(env, klass, "releaseWifiLock", "()V");
......@@ -100,10 +103,10 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *system_c
mGetDataPathId = getMethodId(env, klass, "getDataPath", "()Ljava/lang/String;");
mGetConfigPathId = getMethodId(env, klass, "getConfigPath", "()Ljava/lang/String;");
jobject pm = env->CallObjectMethod(mJavaHelper,mGetPowerManagerId);
jobject pm = env->CallObjectMethod(mJavaHelper, mGetPowerManagerId);
belle_sip_wake_lock_init(env, pm);
ms_message("AndroidPlatformHelpers is fully initialised");
lInfo() << "AndroidPlatformHelpers is fully initialised.";
}
AndroidPlatformHelpers::~AndroidPlatformHelpers () {
......@@ -111,28 +114,27 @@ AndroidPlatformHelpers::~AndroidPlatformHelpers () {
JNIEnv *env = ms_get_jni_env();
belle_sip_wake_lock_uninit(env);
env->DeleteGlobalRef(mJavaHelper);
mJavaHelper = NULL;
mJavaHelper = nullptr;
}
}
void AndroidPlatformHelpers::setDnsServers () {
if (!mJavaHelper) return;
JNIEnv *env=ms_get_jni_env();
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
jobjectArray jservers = (jobjectArray)env->CallObjectMethod(mJavaHelper,mGetDnsServersId);
bctbx_list_t *l = NULL;
jobjectArray jservers = (jobjectArray)env->CallObjectMethod(mJavaHelper, mGetDnsServersId);
bctbx_list_t *l = nullptr;
if (env->ExceptionCheck()) {
env->ExceptionClear();
ms_error("AndroidPlatformHelpers::setDnsServers() exception");
lError() << "AndroidPlatformHelpers::setDnsServers() exception.";
return;
}
if (jservers != NULL) {
if (jservers != nullptr) {
int count = env->GetArrayLength(jservers);
for (int i=0; i < count; i++) {
jstring jserver = (jstring) env->GetObjectArrayElement(jservers, i);
const char *str = env->GetStringUTFChars(jserver, NULL);
for (int i = 0; i < count; i++) {
jstring jserver = (jstring)env->GetObjectArrayElement(jservers, i);
const char *str = env->GetStringUTFChars(jserver, nullptr);
if (str) {
l = bctbx_list_append(l, ms_strdup(str));
env->ReleaseStringUTFChars(jserver, str);
......@@ -168,28 +170,28 @@ void AndroidPlatformHelpers::releaseCpuLock () {
callVoidMethod(mCpuLockReleaseId);
}
std::string AndroidPlatformHelpers::getDataPath () {
string AndroidPlatformHelpers::getDataPath () {
JNIEnv *env = ms_get_jni_env();
jstring jdata_path = (jstring)env->CallObjectMethod(mJavaHelper,mGetDataPathId);
jstring jdata_path = (jstring)env->CallObjectMethod(mJavaHelper, mGetDataPathId);
const char *data_path = GetStringUTFChars(env, jdata_path);
std::string dataPath = data_path;
string dataPath = data_path;
ReleaseStringUTFChars(env, jdata_path, data_path);
return dataPath;
}
std::string AndroidPlatformHelpers::getConfigPath () {
string AndroidPlatformHelpers::getConfigPath () {
JNIEnv *env = ms_get_jni_env();
jstring jconfig_path = (jstring)env->CallObjectMethod(mJavaHelper,mGetConfigPathId);
jstring jconfig_path = (jstring)env->CallObjectMethod(mJavaHelper, mGetConfigPathId);
const char *config_path = GetStringUTFChars(env, jconfig_path);
std::string configPath = config_path;
string configPath = config_path;
ReleaseStringUTFChars(env, jconfig_path, config_path);
return configPath;
}
int AndroidPlatformHelpers::callVoidMethod (jmethodID id) {
JNIEnv *env=ms_get_jni_env();
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
env->CallVoidMethod(mJavaHelper,id);
env->CallVoidMethod(mJavaHelper, id);
if (env->ExceptionCheck()) {
env->ExceptionClear();
return -1;
......@@ -199,10 +201,8 @@ int AndroidPlatformHelpers::callVoidMethod (jmethodID id) {
return -1;
}
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *system_context) {
return new AndroidPlatformHelpers(lc, system_context);
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext) {
return new AndroidPlatformHelpers(lc, systemContext);
}
LINPHONE_END_NAMESPACE
#endif
/*
linphone
Copyright (C) 2017 Belledonne Communications SARL
* platform-helpers.cpp
* Copyright (C) 2010-2017 Belledonne Communications SARL
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "platform-helpers.h"
// =============================================================================
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.
LINPHONE_BEGIN_NAMESPACE
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.
StubbedPlatformHelpers::StubbedPlatformHelpers (LinphoneCore *lc) : PlatformHelpers(lc) {}
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
void StubbedPlatformHelpers::setDnsServers () {}
#include "linphone/utils/utils.h"
void StubbedPlatformHelpers::acquireWifiLock () {}
#include "private.h"
void StubbedPlatformHelpers::releaseWifiLock () {}
LINPHONE_BEGIN_NAMESPACE
void StubbedPlatformHelpers::acquireMcastLock () {}
PlatformHelpers::~PlatformHelpers () {}
void StubbedPlatformHelpers::releaseMcastLock () {}
StubbedPlatformHelpers::StubbedPlatformHelpers (LinphoneCore *lc) : PlatformHelpers(lc) {}
void StubbedPlatformHelpers::acquireCpuLock () {}
void StubbedPlatformHelpers::releaseCpuLock () {}
void StubbedPlatformHelpers::setDnsServers () {
}
void StubbedPlatformHelpers::acquireWifiLock () {
}
void StubbedPlatformHelpers::releaseWifiLock () {
}
void StubbedPlatformHelpers::acquireMcastLock () {
}
void StubbedPlatformHelpers::releaseMcastLock () {
}
void StubbedPlatformHelpers::acquireCpuLock () {
}
void StubbedPlatformHelpers::releaseCpuLock () {
}
std::string StubbedPlatformHelpers::getDataPath () {
return Utils::getEmptyConstRefObject<std::string>();
return "";
}
std::string StubbedPlatformHelpers::getConfigPath () {
return Utils::getEmptyConstRefObject<std::string>();
}
StubbedPlatformHelpers::~StubbedPlatformHelpers () {
return "";
}
LINPHONE_END_NAMESPACE
/*
linphone
Copyright (C) 2017 Belledonne Communications SARL
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
* platform-helpers.h
* Copyright (C) 2010-2017 Belledonne Communications SARL
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _PLATFORM_HELPERS_H_
#define _PLATFORM_HELPERS_H_
#include <string>
#include "linphone/core.h"
#include "linphone/utils/general.h"
// =============================================================================
L_DECL_C_STRUCT(LinphoneCore);
LINPHONE_BEGIN_NAMESPACE
/**
* This interface aims at abstracting some features offered by the platform, most often mobile platforms.
* A per platform implementation is to be made to implement these features, if available on the platform
* A per platform implementation is to be made to implement these features, if available on the platform.
*/
class PlatformHelpers {
public:
//This method shall retrieve DNS server list from the platform and assign it to the core.
virtual ~PlatformHelpers () = default;
// This method shall retrieve DNS server list from the platform and assign it to the core.
virtual void setDnsServers () = 0;
virtual void acquireWifiLock () = 0;
virtual void releaseWifiLock () = 0;
......@@ -43,16 +48,18 @@ public:
virtual void releaseCpuLock () = 0;
virtual std::string getDataPath () = 0;
virtual std::string getConfigPath () = 0;
virtual ~PlatformHelpers ();
protected:
inline PlatformHelpers (LinphoneCore *lc) : mCore(lc) {}
LinphoneCore *mCore;
};
class StubbedPlatformHelpers : public PlatformHelpers {
public:
StubbedPlatformHelpers (LinphoneCore *lc);
virtual ~StubbedPlatformHelpers () = default;
void setDnsServers () override;
void acquireWifiLock () override;
void releaseWifiLock () override;
......@@ -62,10 +69,9 @@ public:
void releaseCpuLock () override;
std::string getDataPath () override;
std::string getConfigPath () override;
virtual ~StubbedPlatformHelpers ();
};
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *system_context);
PlatformHelpers *createAndroidPlatformHelpers (LinphoneCore *lc, void *systemContext);
LINPHONE_END_NAMESPACE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment