With this separation, API-sides are capable to use the database.
Change-Id: Ia2ad68184f305cee292fd69ff3d3bfd0dca40ad7
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
FILES_MATCHING PATTERN "*.h"
)
+SET(target_prefix "context")
+SET(target_shared "${target_prefix}-shared")
+SET(target_database "${target_prefix}-database")
+
+ADD_SUBDIRECTORY(src/shared)
+ADD_SUBDIRECTORY(src/database)
ADD_SUBDIRECTORY(src/client)
ADD_SUBDIRECTORY(src/server)
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CONTEXT_ERROR_UTIL_H__
+#define __CONTEXT_ERROR_UTIL_H__
+
+#include <ContextTypes.h>
+
+#define CTX_ERROR_DOMAIN (ctx::dbusErrorQuark())
+#define CTX_ERROR_STR(X) (ctx::getErrorString(X))
+
+namespace ctx {
+ const char* getErrorString(int error);
+ GQuark dbusErrorQuark(void);
+}
+
+#endif
#define E_DATA_EXIST (TIZEN_ERROR_CONTEXT | 0X09) /* Data exists */
#define E_INV_DATA (TIZEN_ERROR_CONTEXT | 0X0A) /* Invalid data */
-#define CTX_ERROR_DOMAIN (ctx::dbusErrorQuark())
-#define CTX_ERROR_STR(X) (ctx::getErrorString(X))
-
/* Logging and Error Handling */
#define _I SLOGI
#define _D SLOGD
#define HANDLE_GERROR(Err) \
do { if ((Err)) { _E("GError: %s", Err->message); g_error_free(Err); Err = NULL; } } while (0)
-namespace ctx {
- const char* getErrorString(int error);
- GQuark dbusErrorQuark(void);
-}
-
#endif /* __CONTEXT_TYPES_H__ */
namespace ctx {
- class Credential;
class Tuple;
class EXPORT_API Database {
public:
- Database(const std::string& dbName, uid_t uid);
- Database(const std::string& dbName, const Credential& credential);
- Database(const std::string& dbName, const Credential* credential);
- Database(const std::string& dbName);
+ Database(const std::string& dbPath);
- ~Database();
+ virtual ~Database();
bool open();
void close();
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CONTEXT_PLATFORM_DATABASE_H__
+#define __CONTEXT_PLATFORM_DATABASE_H__
+
+#include <ContextTypes.h>
+#include <Database.h>
+
+namespace ctx {
+
+ class Credential;
+
+ class EXPORT_API PlatformDatabase : public Database {
+ public:
+ PlatformDatabase(const std::string& dbName, uid_t uid);
+ PlatformDatabase(const std::string& dbName, const Credential& credential);
+ PlatformDatabase(const std::string& dbName, const Credential* credential);
+ PlatformDatabase(const std::string& dbName);
+ };
+
+}
+
+#endif /* __CONTEXT_PLATFORM_DATABASE_H__ */
-SET(target "${PROJECT_NAME}-client")
+SET(target "${target_prefix}-client")
-FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
+SET(DEPS "${DEPS} sqlite3")
+
+FILE(GLOB_RECURSE SRCS *.cpp)
MESSAGE("Sources: ${SRCS}")
INCLUDE(FindPkgConfig)
ENDFOREACH(flag)
ADD_LIBRARY(${target} SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${target} ${PKG_CLIENT_LDFLAGS})
+TARGET_LINK_LIBRARIES(${target} ${PKG_CLIENT_LDFLAGS} ${target_shared})
SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER})
SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
-SET(PC_NAME ${target})
+SET(PC_NAME "${PROJECT_NAME}-client")
SET(PC_DESCRIPTION "Tizen Context-Service Internal Shared Library for Clients")
SET(PC_REQUIRED ${DEPS})
-SET(PC_LDFLAGS -l${target})
+SET(PC_LDFLAGS "-l${target} -l${target_shared} -l${target_database}")
CONFIGURE_FILE(
${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.pc.in
* limitations under the License.
*/
+#include <ContextErrorUtil.h>
#include <IServiceResultListener.h>
#include <IServiceSignalListener.h>
#include <ServiceProxy.h>
--- /dev/null
+SET(target ${target_database})
+
+SET(DEPS "${DEPS} sqlite3")
+
+FILE(GLOB_RECURSE SRCS *.cpp)
+MESSAGE("Sources: ${SRCS}")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(PKG_DATABASE REQUIRED ${DEPS})
+
+FOREACH(flag ${PKG_DATABASE_CFLAGS})
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${target} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${target} ${PKG_DATABASE_LDFLAGS} ${target_shared})
+SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
+
+INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
*/
#include <sqlite3.h>
-#include <tzplatform_config.h>
-#include <ScopeMutex.h>
-#include <Credential.h>
#include <Tuple.h>
#include <Database.h>
-#define ROOT_UID ((uid_t)0)
-
using namespace ctx;
-static GMutex __pathMutex;
-
-static std::string __getSystemPath(const std::string& dbName)
-{
- std::string path = "." + dbName + ".db";
-
- {
- ScopeMutex sm(&__pathMutex);
- path = tzplatform_mkpath(TZ_SYS_DB, path.c_str());
- }
-
- return path;
-}
-
-static std::string __getUserPath(const std::string& dbName, uid_t uid)
-{
- std::string path = "." + dbName + ".db";
-
- tzplatform_context* context = NULL;
- tzplatform_context_create(&context);
- IF_FAIL_RETURN_TAG(context, "", _E, "tzplatform_context_create() failed");
-
- if (tzplatform_context_set_user(context, uid) != E_NONE) {
- _E("tzplatform_context_set_user() failed");
- tzplatform_context_destroy(context);
- return "";
- }
-
- {
- ScopeMutex sm(&__pathMutex);
- path = tzplatform_context_mkpath(context, TZ_USER_DB, path.c_str());
- }
-
- tzplatform_context_destroy(context);
-
- return path;
-}
-
-Database::Database(const std::string& dbName, uid_t uid) :
+Database::Database(const std::string& dbPath) :
__dbHandle(NULL),
+ __dbPath(dbPath),
__transactionOn(false)
{
- if (Credential::isSystemUid(uid)) {
- __dbPath = __getSystemPath(dbName);
- } else {
- __dbPath = __getUserPath(dbName, uid);
- }
-
- _I("Path: %s", __dbPath.c_str());
-}
-
-Database::Database(const std::string& dbName, const Credential& credential) :
- Database(dbName, credential.getUid())
-{
-}
-
-Database::Database(const std::string& dbName, const Credential* credential) :
- Database(dbName, credential->getUid())
-{
-}
-
-Database::Database(const std::string& dbName) :
- Database(dbName, ROOT_UID)
-{
+ _D("%s", __dbPath.c_str());
}
Database::~Database()
-SET(target "${PROJECT_NAME}-server")
+SET(target "${target_prefix}-server")
SET(DEPS "${DEPS} sqlite3 libsystemd-login libtzplatform-config alarm-service cynara-creds-gdbus cynara-client cynara-session")
-FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
+FILE(GLOB_RECURSE SRCS *.cpp)
MESSAGE("Sources: ${SRCS}")
INCLUDE(FindPkgConfig)
ENDFOREACH(flag)
ADD_LIBRARY(${target} SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${target} ${LIB_PKG_LDFLAGS})
+TARGET_LINK_LIBRARIES(${target} ${LIB_PKG_LDFLAGS} ${target_shared} ${target_database})
SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER})
SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
-SET(PC_NAME ${target})
+SET(PC_NAME "${PROJECT_NAME}-server")
SET(PC_DESCRIPTION "Tizen Context-Service Internal Shared Library for Servers")
SET(PC_REQUIRED ${DEPS})
-SET(PC_LDFLAGS -l${target})
+SET(PC_LDFLAGS "-l${target} -l${target_shared} -l${target_database}")
CONFIGURE_FILE(
${CMAKE_SOURCE_DIR}/${PROJECT_NAME}.pc.in
* limitations under the License.
*/
+#include <ContextErrorUtil.h>
#include <ClientBase.h>
#include <MethodCall.h>
--- /dev/null
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sqlite3.h>
+#include <tzplatform_config.h>
+#include <ScopeMutex.h>
+#include <Credential.h>
+#include <Tuple.h>
+#include <PlatformDatabase.h>
+
+#define ROOT_UID ((uid_t)0)
+
+using namespace ctx;
+
+static GMutex __pathMutex;
+
+static std::string __getSystemPath(const std::string& dbName)
+{
+ std::string path = "." + dbName + ".db";
+
+ {
+ ScopeMutex sm(&__pathMutex);
+ path = tzplatform_mkpath(TZ_SYS_DB, path.c_str());
+ }
+
+ return path;
+}
+
+static std::string __getUserPath(const std::string& dbName, uid_t uid)
+{
+ std::string path = "." + dbName + ".db";
+
+ tzplatform_context* context = NULL;
+ tzplatform_context_create(&context);
+ IF_FAIL_RETURN_TAG(context, "", _E, "tzplatform_context_create() failed");
+
+ if (tzplatform_context_set_user(context, uid) != E_NONE) {
+ _E("tzplatform_context_set_user() failed");
+ tzplatform_context_destroy(context);
+ return "";
+ }
+
+ {
+ ScopeMutex sm(&__pathMutex);
+ path = tzplatform_context_mkpath(context, TZ_USER_DB, path.c_str());
+ }
+
+ tzplatform_context_destroy(context);
+
+ return path;
+}
+
+static std::string __getPath(const std::string& dbName, uid_t uid)
+{
+ if (Credential::isSystemUid(uid)) {
+ return __getSystemPath(dbName);
+ } else {
+ return __getUserPath(dbName, uid);
+ }
+}
+
+PlatformDatabase::PlatformDatabase(const std::string& dbName, uid_t uid) :
+ Database(__getPath(dbName, uid))
+{
+}
+
+PlatformDatabase::PlatformDatabase(const std::string& dbName, const Credential& credential) :
+ PlatformDatabase(dbName, credential.getUid())
+{
+}
+
+PlatformDatabase::PlatformDatabase(const std::string& dbName, const Credential* credential) :
+ PlatformDatabase(dbName, credential->getUid())
+{
+}
+
+PlatformDatabase::PlatformDatabase(const std::string& dbName) :
+ PlatformDatabase(dbName, ROOT_UID)
+{
+}
--- /dev/null
+SET(target "${target_prefix}-shared")
+
+FILE(GLOB_RECURSE SRCS *.cpp)
+MESSAGE("Sources: ${SRCS}")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(PKG_SHARED REQUIRED ${DEPS})
+
+FOREACH(flag ${PKG_SHARED_CFLAGS})
+ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
+ENDFOREACH(flag)
+
+ADD_LIBRARY(${target} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${target} ${PKG_SHARED_LDFLAGS})
+SET_TARGET_PROPERTIES(${target} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${target} PROPERTIES VERSION ${FULLVER})
+
+INSTALL(TARGETS ${target} DESTINATION ${CMAKE_INSTALL_LIBDIR})
* limitations under the License.
*/
-#include <ContextTypes.h>
+#include <ContextErrorUtil.h>
#define ERROR_PREFIX CTX_DBUS_IFACE "Error."
return "Unknown";
}
-GQuark ctx::dbusErrorQuark(void)
+EXPORT_API GQuark ctx::dbusErrorQuark(void)
{
static volatile gsize quarkVolatile = 0;
g_dbus_error_register_error_domain("tizen-ctx-error-quark",