diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 11ad32dbc..ad1331b12 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2234,7 +2234,7 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig lc->sal->set_user_pointer(lc); lc->sal->set_callbacks(&linphone_sal_callbacks); - new(&lc->cppCore) Core(); + new(&lc->cppCore) Core(lc); #ifdef TUNNEL_ENABLED lc->tunnel=linphone_core_tunnel_new(lc); diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 31f1c52d6..18579565f 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -100,6 +100,7 @@ set(UTILS_HEADER_FILES enum-generator.h general.h magic-macros.h + paths.h utils.h ) diff --git a/include/linphone/utils/paths.h b/include/linphone/utils/paths.h new file mode 100644 index 000000000..da968f719 --- /dev/null +++ b/include/linphone/utils/paths.h @@ -0,0 +1,42 @@ +/* + * paths.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 _PATHS_H_ +#define _PATHS_H_ + +#include + +#include "linphone/utils/general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +namespace Paths { + enum Type { + Data, + Config + }; + + LINPHONE_PUBLIC const std::string &getPath(Type type, void *context); +} + +LINPHONE_END_NAMESPACE + +#endif // ifndef _PATHS_H_ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2e6c4a00b..840e59621 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -199,6 +199,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES sal/register-op.cpp sal/sal.cpp utils/general.cpp + utils/paths/paths.cpp utils/payload-type-handler.cpp utils/utils.cpp variant/variant.cpp @@ -207,6 +208,27 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES xml/xml.cpp ) +set(LINPHONE_OBJC_SOURCE_FILES) +if (APPLE) + list(APPEND LINPHONE_OBJC_SOURCE_FILES utils/paths/paths-apple.mm) + list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES utils/paths/paths-apple.h) +endif() + +if (ANDROID) + list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES utils/paths/paths-android.cpp) + list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES utils/paths/paths-android.h) +endif() + +if (WIN32) + list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES utils/paths/paths-windows.cpp) + list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES utils/paths/paths-windows.h) +endif() + +if (UNIX AND NOT APPLE) + list(APPEND LINPHONE_CXX_OBJECTS_SOURCE_FILES utils/paths/paths-linux.cpp) + list(APPEND LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES utils/paths/paths-linux.h) +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}) @@ -223,11 +245,12 @@ 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) add_library( linphone-cxx-objects-static OBJECT - ${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES} ${LINPHONE_CXX_OBJECTS_SOURCE_FILES} + ${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}) @@ -236,7 +259,7 @@ endif() if(ENABLE_SHARED) add_library( linphone-cxx-objects OBJECT - ${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES} ${LINPHONE_CXX_OBJECTS_SOURCE_FILES} + ${LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES} ${LINPHONE_CXX_OBJECTS_SOURCE_FILES} ${LINPHONE_OBJC_SOURCE_FILES} ) 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}) diff --git a/src/core/core-p.h b/src/core/core-p.h index 5ebe4443f..c402c6ccd 100644 --- a/src/core/core-p.h +++ b/src/core/core-p.h @@ -31,6 +31,7 @@ LINPHONE_BEGIN_NAMESPACE class CorePrivate : public ObjectPrivate { public: MainDb mainDb; + LinphoneCore *cCore; private: std::list> chatRooms; diff --git a/src/core/core.cpp b/src/core/core.cpp index fe3e79218..96bc6a01c 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -23,6 +23,7 @@ #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 "core.h" @@ -35,7 +36,21 @@ LINPHONE_BEGIN_NAMESPACE // ----------------------------------------------------------------------------- -Core::Core () : Object(*new CorePrivate) {} +Core::Core (LinphoneCore *cCore) : Object(*new CorePrivate) { + L_D(); + d->cCore = cCore; + const char *uri = lp_config_get_string(linphone_core_get_config(d->cCore), "server", "db_uri", NULL); + if (uri) { + AbstractDb::Backend backend = + strcmp(lp_config_get_string(linphone_core_get_config(d->cCore), "server", "db_backend", NULL), "mysql") == 0 + ? MainDb::Mysql + : MainDb::Sqlite3; + d->mainDb.connect(backend, uri); + } else { + // TODO + // d->mainDb.connect(MainDb::Sqlite3, linphone_factory_get_writable_dir()/linphone.db); + } +} // ----------------------------------------------------------------------------- diff --git a/src/core/core.h b/src/core/core.h index 715abbaf9..a23b79f52 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -34,7 +34,7 @@ class CorePrivate; class LINPHONE_PUBLIC Core : public Object { friend class ClientGroupChatRoom; public: - Core (); + Core (LinphoneCore *cCore); std::shared_ptr createClientGroupChatRoom (const std::string &subject); std::shared_ptr getOrCreateChatRoom (const std::string &peerAddress, bool isRtt = false) const; diff --git a/src/utils/paths/paths-android.cpp b/src/utils/paths/paths-android.cpp new file mode 100644 index 000000000..d0f427689 --- /dev/null +++ b/src/utils/paths/paths-android.cpp @@ -0,0 +1,38 @@ +/* + * paths-android.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 "linphone/utils/utils.h" + +#include "paths-android.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +const std::string &SysPaths::getDataPath (void *context) { + //TODO. + return Utils::getEmptyConstRefObject(); +} + +const std::string &SysPaths::getConfigPath (void *context) { + //TODO. + return Utils::getEmptyConstRefObject(); +} + +LINPHONE_END_NAMESPACE diff --git a/src/utils/paths/paths-android.h b/src/utils/paths/paths-android.h new file mode 100644 index 000000000..7cd7efd91 --- /dev/null +++ b/src/utils/paths/paths-android.h @@ -0,0 +1,38 @@ +/* + * paths-android.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 _PATHS_ANDROID_H_ +#define _PATHS_ANDROID_H_ + +#include + +#include "linphone/utils/general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +namespace SysPaths { + LINPHONE_PUBLIC const std::string &getDataPath (void *context); + LINPHONE_PUBLIC const std::string &getConfigPath (void *context); +} + +LINPHONE_END_NAMESPACE + +#endif // ifndef _PATHS_ANDROID_H_ diff --git a/src/utils/paths/paths-apple.h b/src/utils/paths/paths-apple.h new file mode 100644 index 000000000..db0cd35ff --- /dev/null +++ b/src/utils/paths/paths-apple.h @@ -0,0 +1,38 @@ +/* + * paths-apple.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 _PATHS_APPLE_H_ +#define _PATHS_APPLE_H_ + +#include + +#include "linphone/utils/general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +namespace SysPaths { + LINPHONE_PUBLIC const std::string &getDataPath (void *context); + LINPHONE_PUBLIC const std::string &getConfigPath (void *context); +} + +LINPHONE_END_NAMESPACE + +#endif // ifndef _PATHS_APPLE_H_ diff --git a/src/utils/paths/paths-apple.mm b/src/utils/paths/paths-apple.mm new file mode 100644 index 000000000..a9f65b248 --- /dev/null +++ b/src/utils/paths/paths-apple.mm @@ -0,0 +1,54 @@ +/* + * paths-apple.m + * 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. + */ + +#import "linphone/utils/utils.h" + +#import "paths-apple.h" + +#ifdef __OBJC__ +#import +#endif + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +const std::string &SysPaths::getDataPath (void *context) { +#ifdef __OBJC__ + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); + NSString *writablePath = [paths objectAtIndex:0]; + NSString *fullPath = [writablePath stringByAppendingString:@"/linphone/"]; + const char *ret = fullPath.UTF8String; + return ret; +#endif + return Utils::getEmptyConstRefObject(); +} + +const std::string &SysPaths::getConfigPath (void *context) { +#ifdef __OBJC__ + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); + NSString *configPath = [paths objectAtIndex:0]; + NSString *fullPath = [configPath stringByAppendingString:@"/Preferences/linphone/"]; + const char *ret = fullPath.UTF8String; + return ret; +#endif + return Utils::getEmptyConstRefObject(); +} + +LINPHONE_END_NAMESPACE diff --git a/src/utils/paths/paths-linux.cpp b/src/utils/paths/paths-linux.cpp new file mode 100644 index 000000000..11f47d29c --- /dev/null +++ b/src/utils/paths/paths-linux.cpp @@ -0,0 +1,38 @@ +/* + * paths-linux.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 "linphone/utils/utils.h" + +#include "paths-linux.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +const std::string &SysPaths::getDataPath (void *context) { + //TODO. + return Utils::getEmptyConstRefObject(); +} + +const std::string &SysPaths::getConfigPath (void *context) { + //TODO. + return Utils::getEmptyConstRefObject(); +} + +LINPHONE_END_NAMESPACE diff --git a/src/utils/paths/paths-linux.h b/src/utils/paths/paths-linux.h new file mode 100644 index 000000000..85a1f284e --- /dev/null +++ b/src/utils/paths/paths-linux.h @@ -0,0 +1,38 @@ +/* + * paths-linux.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 _PATHS_LINUX_H_ +#define _PATHS_LINUX_H_ + +#include + +#include "linphone/utils/general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +namespace SysPaths { + LINPHONE_PUBLIC const std::string &getDataPath (void *context); + LINPHONE_PUBLIC const std::string &getConfigPath (void *context); +} + +LINPHONE_END_NAMESPACE + +#endif // ifndef _PATHS_LINUX_H_ diff --git a/src/utils/paths/paths-windows.cpp b/src/utils/paths/paths-windows.cpp new file mode 100644 index 000000000..fc6ec22f3 --- /dev/null +++ b/src/utils/paths/paths-windows.cpp @@ -0,0 +1,38 @@ +/* + * paths-windows.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 "linphone/utils/utils.h" + +#include "paths-windows.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +const std::string &SysPaths::getDataPath (void *context) { + //TODO. + return Utils::getEmptyConstRefObject(); +} + +const std::string &SysPaths::getConfigPath (void *context) { + //TODO. + return Utils::getEmptyConstRefObject(); +} + +LINPHONE_END_NAMESPACE diff --git a/src/utils/paths/paths-windows.h b/src/utils/paths/paths-windows.h new file mode 100644 index 000000000..b67b65e7a --- /dev/null +++ b/src/utils/paths/paths-windows.h @@ -0,0 +1,38 @@ +/* + * paths-windws.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 _PATHS_WINDOWS_H_ +#define _PATHS_WINDOWS_H_ + +#include + +#include "linphone/utils/general.h" + +// ============================================================================= + +LINPHONE_BEGIN_NAMESPACE + +namespace SysPaths { + LINPHONE_PUBLIC const std::string &getDataPath (void *context); + LINPHONE_PUBLIC const std::string &getConfigPath (void *context); +} + +LINPHONE_END_NAMESPACE + +#endif // ifndef _PATHS_WINDOWS_H_ diff --git a/src/utils/paths/paths.cpp b/src/utils/paths/paths.cpp new file mode 100644 index 000000000..63f6e959b --- /dev/null +++ b/src/utils/paths/paths.cpp @@ -0,0 +1,48 @@ +/* + * utils.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 "linphone/utils/paths.h" + +#ifdef __APPLE__ +#include "paths-apple.h" +#elif defined(__ANDROID__) +#include "paths-android.h" +#elif defined(_WIN32) +#include "paths-windows.h" +#elif defined(__linux) +#include "paths-linux.h" +#else +#error "Unsupported system" +#endif +// ============================================================================= + +using namespace std; + +LINPHONE_BEGIN_NAMESPACE + +const string &Paths::getPath (Paths::Type type, void *context) { + switch (type) { + case Data: + return SysPaths::getDataPath(context); + case Config: + return SysPaths::getConfigPath(context); + } +} + +LINPHONE_END_NAMESPACE