Add APIs for client application & daemons, and the other services in contextd 93/120893/7
authorMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 24 Mar 2017 13:00:00 +0000 (22:00 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 27 Mar 2017 10:07:15 +0000 (19:07 +0900)
Change-Id: I0176c6eb838508dd3cccc277902a7b0aeacaab8f
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
31 files changed:
CMakeLists.txt
include/ContextStoreSearchQuery.h [deleted file]
include/context_store_internal.h [new file with mode: 0644]
include/private/ContextStoreService.h [moved from include/ContextStoreService.h with 97% similarity]
include/private/ContextStoreSideGate.h [new file with mode: 0644]
script/init.sql
src/client-dummy/CMakeLists.txt
src/client-dummy/ContextStoreSearchQuery.cpp [deleted file]
src/client-dummy/context_store.cpp [new file with mode: 0644]
src/client/CMakeLists.txt
src/client/ContextStore.cpp
src/client/ContextStore.h [moved from include/ContextStore.h with 71% similarity]
src/client/ContextStoreManager.cpp
src/client/ContextStoreManager.h [moved from include/ContextStoreManager.h with 87% similarity]
src/client/ContextStoreSearchQuery.cpp [deleted file]
src/client/PlatformManagedStore.cpp
src/client/PlatformManagedStore.h
src/client/context_store.cpp [new file with mode: 0644]
src/server-dummy/CMakeLists.txt
src/server-dummy/ContextStoreSideGate.cpp [moved from src/client-dummy/ContextStore.cpp with 50% similarity]
src/server/CMakeLists.txt
src/server/ContextStoreClient.cpp
src/server/ContextStoreService.cpp
src/server/ContextStoreSideGate.cpp [new file with mode: 0644]
src/server/SchemaLoader.cpp
src/server/Store.cpp
src/server/Store.h
src/server/StoreManager.cpp
src/shared/ContextStoreTypesPrivate.h
src/shared/ContextStoreUtil.cpp [moved from src/client-dummy/ContextStoreManager.cpp with 61% similarity]
src/shared/ContextStoreUtil.h [moved from include/ContextStoreTypes.h with 74% similarity]

index 1905668..8dbfdf0 100644 (file)
@@ -7,7 +7,6 @@ SET(INCDIR "${CMAKE_INSTALL_INCLUDEDIR}/context-service")
 
 INCLUDE_DIRECTORIES(
        ${CMAKE_INSTALL_PREFIX}/${INCDIR}/private
-       ${CMAKE_SOURCE_DIR}/include
        ${CMAKE_SOURCE_DIR}/src/shared
 )
 
@@ -21,15 +20,8 @@ SET(PC_INCLUDE "${CMAKE_INSTALL_PREFIX}/${INCDIR}")
 SET(PC_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
 
 INSTALL(
-       FILES ${CMAKE_SOURCE_DIR}/include/ContextStoreService.h
-       DESTINATION ${INCDIR}/private
-)
-INSTALL(
        DIRECTORY ${CMAKE_SOURCE_DIR}/include/
        DESTINATION ${INCDIR}
-       FILES_MATCHING
-       PATTERN "*.h"
-       PATTERN "ContextStoreService.h" EXCLUDE
 )
 
 ADD_SUBDIRECTORY(src/client-dummy)
diff --git a/include/ContextStoreSearchQuery.h b/include/ContextStoreSearchQuery.h
deleted file mode 100644 (file)
index c279676..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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_STORE_SEARCH_QUERY_H__
-#define __CONTEXT_STORE_SEARCH_QUERY_H__
-
-#include <string>
-#include <ContextStoreTypes.h>
-
-namespace ctx {
-
-       class EXPORT_API ContextStoreSearchQuery {
-       public:
-               ContextStoreSearchQuery();
-               ContextStoreSearchQuery(
-                               const std::string& projection,
-                               const std::string& selection,
-                               const std::string& sortOrder,
-                               unsigned int limit);
-
-               ~ContextStoreSearchQuery();
-
-               ContextStoreSearchQuery& setProjection(const std::string& projection);
-               ContextStoreSearchQuery& setSelection(const std::string& selection);
-               ContextStoreSearchQuery& setSortOrder(const std::string& sortOrder);
-               ContextStoreSearchQuery& setLimit(unsigned int limit);
-
-               const std::string& getProjection() const;
-               const std::string& getSelection() const;
-               const std::string& getSortOrder() const;
-               unsigned int getLimit() const;
-
-               bool valid() const;
-
-       private:
-               std::string __projection;
-               std::string __selection;
-               std::string __sortOrder;
-               unsigned int __limit;
-       };
-
-}
-
-#endif /* __CONTEXT_STORE_SEARCH_QUERY_H__ */
diff --git a/include/context_store_internal.h b/include/context_store_internal.h
new file mode 100644 (file)
index 0000000..8e8c972
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * 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 __CAPI_CONTEXT_STORE_INTERNAL_H__
+#define __CAPI_CONTEXT_STORE_INTERNAL_H__
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+
+/* Handles */
+typedef struct _ctx_store_handle_s* ctx_store_h;
+
+typedef struct _ctx_store_record_s* ctx_store_record_h;
+
+typedef struct _ctx_store_cursor_s* ctx_store_cursor_h;
+
+
+/* Store object creation */
+int ctx_store_create(const char* uri, ctx_store_h* store);
+
+int ctx_store_destroy(ctx_store_h store);
+
+
+/* Data CRUD */
+int ctx_store_insert(ctx_store_h store, ctx_store_record_h record);
+
+int ctx_store_lazy_insert(ctx_store_h store, ctx_store_record_h record);
+
+int ctx_store_lazy_insert_flush(ctx_store_h store);
+
+int ctx_store_lazy_insert_reset(ctx_store_h store);
+
+int ctx_store_retrieve(ctx_store_h store,
+               const char* projection, const char* selection,
+               const char* sort_order, unsigned int limit,
+               ctx_store_cursor_h* cursor);
+
+int ctx_store_remove(ctx_store_h store, const char* selection);
+
+
+/* Tuple */
+int ctx_store_record_create(ctx_store_record_h* record);
+
+int ctx_store_record_destroy(ctx_store_record_h record);
+
+int ctx_store_record_set_int64(ctx_store_record_h record, const char* key, int64_t value);
+
+int ctx_store_record_set_double(ctx_store_record_h record, const char* key, double value);
+
+int ctx_store_record_set_string(ctx_store_record_h, const char* key, const char* value);
+
+
+/* Cursor */
+int ctx_store_cursor_destroy(ctx_store_cursor_h cursor);
+
+/* Cursor: Navigation */
+int ctx_store_cursor_get_count(ctx_store_cursor_h cursor, unsigned int* count);
+
+int ctx_store_cursor_get_position(ctx_store_cursor_h cursor, unsigned int* position);
+
+int ctx_store_cursor_set_position(ctx_store_cursor_h cursor, unsigned int position);
+
+int ctx_store_cursor_first(ctx_store_cursor_h cursor);
+
+int ctx_store_cursor_last(ctx_store_cursor_h cursor);
+
+int ctx_store_cursor_next(ctx_store_cursor_h cursor);
+
+int ctx_store_cursor_prev(ctx_store_cursor_h cursor);
+
+/* Cursor: Extraction */
+int ctx_store_cursor_get_int64(ctx_store_cursor_h cursor, const char* key, int64_t* value);
+
+int ctx_store_cursor_get_double(ctx_store_cursor_h cursor, const char* key, double* value);
+
+int ctx_store_cursor_get_string(ctx_store_cursor_h cursor, const char* key, char** value);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif
similarity index 97%
rename from include/ContextStoreService.h
rename to include/private/ContextStoreService.h
index 828424e..b056583 100644 (file)
@@ -20,7 +20,6 @@
 /* This header SHOULD NOT be included by other headers in this directory. */
 
 #include <ServiceBase.h>
-#include <ContextStoreTypes.h>
 
 namespace ctx {
 
diff --git a/include/private/ContextStoreSideGate.h b/include/private/ContextStoreSideGate.h
new file mode 100644 (file)
index 0000000..7e870d7
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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_STORE_SIDE_GATE_H__
+#define __CONTEXT_STORE_SIDE_GATE_H__
+
+#include <Tuple.h>
+
+namespace ctx {
+
+       class ContextStoreService;
+
+       class EXPORT_API ContextStoreSideGate {
+       public:
+               ~ContextStoreSideGate();
+
+               int insert(const std::string& columns, std::vector<Tuple*>& tuples);
+
+               static ContextStoreSideGate getUserStore(const std::string& uri);
+               static ContextStoreSideGate getSystemStore(const std::string& uri);
+
+       private:
+               ContextStoreSideGate(const std::string& uri, bool isSystem);
+
+               std::string __uri;
+               bool __isSystem;
+
+               static ContextStoreService* __hostService;
+
+               friend class ContextStoreService;
+       };
+
+}
+
+#endif
index d0ec0c9..80dd7bf 100644 (file)
@@ -1,5 +1,6 @@
 CREATE TABLE IF NOT EXISTS ContextStoreSchema (
        "uri" TEXT PRIMARY KEY,
+       "columns" TEXT NOT NULL,
        "retention" INTEGER NOT NULL DEFAULT 0,
        "limit" INTEGER NOT NULL DEFAULT 0,
        "readPrivileges" TEXT NOT NULL,
index 1e5e9f4..c5865b0 100644 (file)
@@ -2,6 +2,8 @@ SET(target "${PROJECT_NAME}-client")
 
 SET(DEPS "${DEPS} context-common-client")
 
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
 FILE(GLOB_RECURSE SRCS *.cpp)
 MESSAGE("Sources: ${SRCS}")
 
diff --git a/src/client-dummy/ContextStoreSearchQuery.cpp b/src/client-dummy/ContextStoreSearchQuery.cpp
deleted file mode 100644 (file)
index bda66fe..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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 <ContextStoreTypesPrivate.h>
-#include <ContextStoreSearchQuery.h>
-
-using namespace ctx;
-
-ContextStoreSearchQuery::ContextStoreSearchQuery() :
-       __limit(0)
-{
-}
-
-ContextStoreSearchQuery::ContextStoreSearchQuery(const std::string& projection,
-               const std::string& selection, const std::string& sortOrder,
-               unsigned int limit) :
-       __limit(0)
-{
-}
-
-ContextStoreSearchQuery::~ContextStoreSearchQuery()
-{
-}
-
-ContextStoreSearchQuery& ContextStoreSearchQuery::setProjection(const std::string& projection)
-{
-       __projection = projection;
-       return *this;
-}
-
-ContextStoreSearchQuery& ContextStoreSearchQuery::setSelection(const std::string& selection)
-{
-       __selection = selection;
-       return *this;
-}
-
-ContextStoreSearchQuery& ContextStoreSearchQuery::setSortOrder(const std::string& sortOrder)
-{
-       __sortOrder = sortOrder;
-       return *this;
-}
-
-ContextStoreSearchQuery& ContextStoreSearchQuery::setLimit(unsigned int limit)
-{
-       __limit = limit;
-       return *this;
-}
-
-const std::string& ContextStoreSearchQuery::getProjection() const
-{
-       return __projection;
-}
-
-const std::string& ContextStoreSearchQuery::getSelection() const
-{
-       return __selection;
-}
-
-const std::string& ContextStoreSearchQuery::getSortOrder() const
-{
-       return __sortOrder;
-}
-
-unsigned int ContextStoreSearchQuery::getLimit() const
-{
-       return __limit;
-}
-
-bool ContextStoreSearchQuery::valid() const
-{
-       return false;
-}
diff --git a/src/client-dummy/context_store.cpp b/src/client-dummy/context_store.cpp
new file mode 100644 (file)
index 0000000..7669bd6
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * 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 <ContextStoreTypesPrivate.h>
+#include <context_store_internal.h>
+
+typedef struct _ctx_store_handle_s {
+       int dummy;
+} ctx_store_handle_s;
+
+typedef struct _ctx_store_record_s {
+       int dummy;
+} ctx_store_record_s;
+
+typedef struct _ctx_store_cursor_s {
+       int dummy;
+} ctx_store_cursor_s;
+
+EXPORT_API int ctx_store_create(const char* uri, ctx_store_h* store)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_destroy(ctx_store_h store)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_insert(ctx_store_h store, ctx_store_record_h record)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_lazy_insert(ctx_store_h store, ctx_store_record_h record)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_lazy_insert_flush(ctx_store_h store)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_lazy_insert_reset(ctx_store_h store)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_retrieve(ctx_store_h store, const char* projection,
+               const char* selection, const char* sort_order, unsigned int limit,
+               ctx_store_cursor_h* cursor)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_remove(ctx_store_h store, const char* selection)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_record_create(ctx_store_record_h* record)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_record_destroy(ctx_store_record_h record)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_record_set_int64(ctx_store_record_h record, const char* key, int64_t value)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_record_set_double(ctx_store_record_h record, const char* key, double value)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_record_set_string(ctx_store_record_h record, const char* key, const char* value)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_destroy(ctx_store_cursor_h cursor)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_get_count(ctx_store_cursor_h cursor, unsigned int* count)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_get_position(ctx_store_cursor_h cursor, unsigned int* position)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_set_position(ctx_store_cursor_h cursor, unsigned int position)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_first(ctx_store_cursor_h cursor)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_last(ctx_store_cursor_h cursor)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_next(ctx_store_cursor_h cursor)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_prev(ctx_store_cursor_h cursor)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_get_int64(ctx_store_cursor_h cursor, const char* key, int64_t* value)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_get_double(ctx_store_cursor_h cursor, const char* key, double* value)
+{
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_cursor_get_string(ctx_store_cursor_h cursor, const char* key, char** value)
+{
+       return E_SUPPORT;
+}
index 8f551d7..cce6a58 100644 (file)
@@ -2,6 +2,8 @@ SET(target "${PROJECT_NAME}-client-genuine")
 
 SET(DEPS "${DEPS} context-common-client")
 
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
 FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
 MESSAGE("Sources: ${SRCS}")
 
index 3f14d37..8f906f9 100644 (file)
  * limitations under the License.
  */
 
+#include <Database.h>
 #include <ContextStoreTypesPrivate.h>
-#include <ContextStore.h>
+#include "ContextStore.h"
 
 using namespace ctx;
 
+ContextStoreSearchQuery::ContextStoreSearchQuery(const char* proj, const char* sel, const char* srt, unsigned int lim) :
+       projection(proj ? proj : EMPTY_STR),
+       selection(sel ? sel : EMPTY_STR),
+       sortOrder(srt ? srt : EMPTY_STR),
+       limit(lim)
+{
+}
+
 ContextStore::ContextStore()
 {
 }
@@ -46,3 +55,26 @@ int ContextStore::remove(const std::string& selection)
 {
        return E_SUPPORT;
 }
+
+DataType ContextStore::getColumnType(const std::string& columnName)
+{
+       size_t pos = __columns.find(columnName);
+       IF_FAIL_RETURN(pos != std::string::npos, DataType::UNKNOWN);
+
+       DataType type = DataType::UNKNOWN;
+
+       try {
+               char typeChar = __columns.at(pos + columnName.size() + 1);
+               if (typeChar == *COL_INT64) {
+                       type = DataType::INT64;
+               } else if (typeChar == *COL_DOUBLE) {
+                       type = DataType::DOUBLE;
+               } else if (typeChar == *COL_STRING) {
+                       type = DataType::STRING;
+               }
+       } catch (std::exception& e) {
+               _E("%s", e.what());
+       }
+
+       return type;
+}
similarity index 71%
rename from include/ContextStore.h
rename to src/client/ContextStore.h
index cf6c098..ccef9ea 100644 (file)
 
 #include <vector>
 #include <Tuple.h>
-#include <ContextStoreTypes.h>
-#include <ContextStoreSearchQuery.h>
+#include <ContextStoreTypesPrivate.h>
 
 namespace ctx {
 
-       class EXPORT_API ContextStore {
+       enum class DataType {
+               UNKNOWN = 0,
+               INT64 = 1,
+               DOUBLE,
+               STRING
+       };
+
+       struct ContextStoreSearchQuery {
+               std::string projection;
+               std::string selection;
+               std::string sortOrder;
+               unsigned int limit;
+               ContextStoreSearchQuery(const char* proj, const char* sel, const char* srt, unsigned int lim);
+       };
+
+       class ContextStore {
        public:
                virtual ~ContextStore();
 
@@ -33,8 +47,12 @@ namespace ctx {
                virtual int retrieve(const ContextStoreSearchQuery& query, std::vector<Tuple*>& records);
                virtual int remove(const std::string& selection);
 
+               DataType getColumnType(const std::string& columnName);
+
        protected:
                ContextStore();
+
+               std::string __columns;
        };
 
 }
index 9dcca7c..9f135a1 100644 (file)
@@ -16,8 +16,8 @@
 
 #include <ServiceProxy.h>
 #include <ContextStoreTypesPrivate.h>
-#include <ContextStoreManager.h>
 #include "PlatformManagedStore.h"
+#include "ContextStoreManager.h"
 
 using namespace ctx;
 
@@ -70,3 +70,13 @@ int ContextStoreManager::getStore(const std::string& uri, ContextStore** store)
        *store = _store;
        return E_NONE;
 }
+
+int ContextStoreManager::reloadUser()
+{
+       return __getServiceProxy()->call(METHOD_RELOAD_USER, NULL);
+}
+
+int ContextStoreManager::reloadSystem()
+{
+       return __getServiceProxy()->call(METHOD_RELOAD_SYSTEM, NULL);
+}
similarity index 87%
rename from include/ContextStoreManager.h
rename to src/client/ContextStoreManager.h
index 60f2a3e..1c978d2 100644 (file)
 #define __CONTEXT_STORE_MANAGER_H__
 
 #include <string>
-#include <ContextStoreTypes.h>
-#include <ContextStore.h>
+#include <ContextStoreTypesPrivate.h>
 
 namespace ctx {
 
-       class EXPORT_API ContextStoreManager {
+       class ContextStore;
+
+       class ContextStoreManager {
        public:
                ContextStoreManager();
                ~ContextStoreManager();
 
                int getStore(const std::string& uri, ContextStore** contextStore);
+
+               int reloadUser();
+
+               int reloadSystem();
        };
 
 }
diff --git a/src/client/ContextStoreSearchQuery.cpp b/src/client/ContextStoreSearchQuery.cpp
deleted file mode 100644 (file)
index cc606c8..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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 <ContextStoreTypesPrivate.h>
-#include <ContextStoreSearchQuery.h>
-
-using namespace ctx;
-
-ContextStoreSearchQuery::ContextStoreSearchQuery() :
-       __limit(DEFAULT_QUERY_LIMIT)
-{
-}
-
-ContextStoreSearchQuery::ContextStoreSearchQuery(const std::string& projection,
-               const std::string& selection, const std::string& sortOrder,
-               unsigned int limit) :
-       __projection(projection),
-       __selection(selection),
-       __sortOrder(sortOrder),
-       __limit(limit)
-{
-}
-
-ContextStoreSearchQuery::~ContextStoreSearchQuery()
-{
-}
-
-ContextStoreSearchQuery& ContextStoreSearchQuery::setProjection(const std::string& projection)
-{
-       __projection = projection;
-       return *this;
-}
-
-ContextStoreSearchQuery& ContextStoreSearchQuery::setSelection(const std::string& selection)
-{
-       __selection = selection;
-       return *this;
-}
-
-ContextStoreSearchQuery& ContextStoreSearchQuery::setSortOrder(const std::string& sortOrder)
-{
-       __sortOrder = sortOrder;
-       return *this;
-}
-
-ContextStoreSearchQuery& ContextStoreSearchQuery::setLimit(unsigned int limit)
-{
-       __limit = limit;
-       return *this;
-}
-
-const std::string& ContextStoreSearchQuery::getProjection() const
-{
-       return __projection;
-}
-
-const std::string& ContextStoreSearchQuery::getSelection() const
-{
-       return __selection;
-}
-
-const std::string& ContextStoreSearchQuery::getSortOrder() const
-{
-       return __sortOrder;
-}
-
-unsigned int ContextStoreSearchQuery::getLimit() const
-{
-       return __limit;
-}
-
-bool ContextStoreSearchQuery::valid() const
-{
-       if (__projection.empty())
-               return false;
-
-       return true;
-}
index 57f41c4..295c878 100644 (file)
@@ -29,9 +29,19 @@ PlatformManagedStore::~PlatformManagedStore()
 
 int PlatformManagedStore::init(const std::string& uri)
 {
-       int error = __proxy->call(METHOD_GET_ACCESS, g_variant_new("(s)", uri.c_str()));
        __uri = uri;
-       return error;
+       GVariant* outParam = NULL;
+       int error = __proxy->call(METHOD_GET_ACCESS, g_variant_new("(s)", uri.c_str()), &outParam);
+       IF_FAIL_RETURN(error == E_NONE, error);
+
+       const char* columns = NULL;
+       g_variant_get(outParam, "(&s)", &columns);
+
+       __columns = (columns ? columns : EMPTY_STR);
+
+       g_variant_unref(outParam);
+
+       return E_NONE;
 }
 
 int PlatformManagedStore::insert(const std::string& columns, Tuple* record)
@@ -61,11 +71,11 @@ int PlatformManagedStore::insert(const std::string& columns, std::vector<Tuple*>
 
 int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::vector<Tuple*>& records)
 {
-       IF_FAIL_RETURN(query.valid(), E_PARAM);
+       IF_FAIL_RETURN(!query.projection.empty(), E_PARAM);
 
        GVariant* param = g_variant_new("(ssssu)", __uri.c_str(),
-                       query.getProjection().c_str(), query.getSelection().c_str(),
-                       query.getSortOrder().c_str(), static_cast<guint32>(query.getLimit()));
+                       query.projection.c_str(), query.selection.c_str(),
+                       query.sortOrder.c_str(), static_cast<guint32>(query.limit));
 
        GVariant* outParam = NULL;
        int error = __proxy->call(METHOD_RETRIEVE, param, &outParam);
@@ -75,6 +85,9 @@ int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::ve
        g_variant_get(outParam, "(v)", &vals);
 
        records = Tuple::buildFrom(vals);
+
+       g_variant_unref(outParam);
+
        return E_NONE;
 }
 
index 77c3d38..4ba7d89 100644 (file)
  * limitations under the License.
  */
 
-#ifndef __CONTEXT_STORE_PLATFORM_MANAGED_STORE_H__
-#define __CONTEXT_STORE_PLATFORM_MANAGED_STORE_H__
+#ifndef __CONTEXT_PLATFORM_MANAGED_STORE_H__
+#define __CONTEXT_PLATFORM_MANAGED_STORE_H__
 
 #include <ServiceProxy.h>
 #include <IServiceResultListener.h>
 #include <IServiceSignalListener.h>
-#include <ContextStore.h>
 #include <ContextStoreTypesPrivate.h>
+#include "ContextStore.h"
 
 namespace ctx {
 
diff --git a/src/client/context_store.cpp b/src/client/context_store.cpp
new file mode 100644 (file)
index 0000000..2907759
--- /dev/null
@@ -0,0 +1,382 @@
+/*
+ * 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 <utility>
+#include <string>
+#include <map>
+#include <ContextStoreTypesPrivate.h>
+#include <ContextStoreUtil.h>
+#include <context_store_internal.h>
+#include "ContextStore.h"
+#include "ContextStoreManager.h"
+
+#define COMMA ","
+
+using namespace ctx;
+
+typedef struct _ctx_store_handle_s {
+       std::string uri;
+       ContextStore* proxy;
+} ctx_store_handle_s;
+
+union DataValue {
+       int64_t i64;
+       double dbl;
+       char* str;
+};
+
+typedef struct _ctx_store_record_s {
+       std::map<std::string, std::pair<DataType, DataValue>> attributes;
+} ctx_store_record_s;
+
+typedef struct _ctx_store_cursor_s {
+       size_t index;
+       std::vector<std::string> keys;
+       std::vector<Tuple*> tuples;
+} ctx_store_cursor_s;
+
+static ContextStoreManager __storeManager;
+
+EXPORT_API int ctx_store_create(const char* uri, ctx_store_h* store)
+{
+       IF_FAIL_RETURN(uri && store, E_PARAM);
+
+       ContextStore* proxy;
+       int error = __storeManager.getStore(uri, &proxy);
+       IF_FAIL_RETURN(error == E_NONE, error);
+
+       ctx_store_h handle = new(std::nothrow) ctx_store_handle_s;
+       if (!handle) {
+               delete proxy;
+               return E_NO_MEM;
+       }
+
+       handle->uri = uri;
+       handle->proxy = proxy;
+       *store = handle;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_destroy(ctx_store_h store)
+{
+       IF_FAIL_RETURN(store, E_NONE);
+
+       delete store->proxy;
+       delete store;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_insert(ctx_store_h store, ctx_store_record_h record)
+{
+       IF_FAIL_RETURN(store && record, E_PARAM);
+
+       std::string columns;
+       Tuple::Builder builder;
+
+       for (auto& iter : record->attributes) {
+               if (store->proxy->getColumnType(iter.first) != iter.second.first) {
+                       return E_PARAM;
+               }
+               columns.append(iter.first).append(COMMA);
+               if (iter.second.first == DataType::INT64) {
+                       builder.add(iter.second.second.i64);
+               } else if (iter.second.first == DataType::DOUBLE) {
+                       builder.add(iter.second.second.dbl);
+               } else {
+                       builder.add(iter.second.second.str);
+               }
+       }
+
+       IF_FAIL_RETURN(!columns.empty(), E_PARAM);
+       columns.pop_back();
+
+       Tuple* tuple = builder.build();
+       IF_FAIL_RETURN(tuple, E_FAILED);
+
+       return store->proxy->insert(columns, tuple);
+}
+
+EXPORT_API int ctx_store_lazy_insert(ctx_store_h store, ctx_store_record_h record)
+{
+       // TODO
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_lazy_insert_flush(ctx_store_h store)
+{
+       // TODO
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_lazy_insert_reset(ctx_store_h store)
+{
+       // TODO
+       return E_SUPPORT;
+}
+
+EXPORT_API int ctx_store_retrieve(ctx_store_h store, const char* projection,
+               const char* selection, const char* sort_order, unsigned int limit,
+               ctx_store_cursor_h* cursor)
+{
+       IF_FAIL_RETURN(store && projection && cursor, E_PARAM);
+
+       ctx_store_cursor_s* csr = new(std::nothrow) ctx_store_cursor_s;
+       IF_FAIL_RETURN(csr, E_NO_MEM);
+
+       std::vector<Tuple*> tuples;
+       ContextStoreSearchQuery query(projection, selection, sort_order, limit);
+
+       int error = store->proxy->retrieve(query, tuples);
+       if (error != E_NONE) {
+               delete csr;
+               return error;
+       }
+
+       csr->index = 0;
+       csr->keys = util::tokenizeString(query.projection, ", ");
+       csr->tuples = tuples;
+
+       *cursor = csr;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_remove(ctx_store_h store, const char* selection)
+{
+       IF_FAIL_RETURN(store && selection, E_PARAM);
+
+       return store->proxy->remove(selection);
+}
+
+EXPORT_API int ctx_store_record_create(ctx_store_record_h* record)
+{
+       IF_FAIL_RETURN(record, E_PARAM);
+
+       ctx_store_record_h handle = new(std::nothrow) ctx_store_record_s;
+       IF_FAIL_RETURN(handle, E_NO_MEM);
+
+       *record = handle;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_record_destroy(ctx_store_record_h record)
+{
+       IF_FAIL_RETURN(record, E_NONE);
+
+       for (auto& iter : record->attributes) {
+               if (iter.second.first == DataType::STRING)
+                       g_free(iter.second.second.str);
+       }
+
+       delete record;
+
+       return E_NONE;
+}
+
+static void __removeFromRecord(ctx_store_record_h record, const char* key)
+{
+       auto iter = record->attributes.find(key);
+       if (iter == record->attributes.end())
+               return;
+
+       if (iter->second.first == DataType::STRING)
+               g_free(iter->second.second.str);
+
+       record->attributes.erase(iter);
+}
+
+EXPORT_API int ctx_store_record_set_int64(ctx_store_record_h record, const char* key, int64_t value)
+{
+       IF_FAIL_RETURN(record && key, E_PARAM);
+
+       __removeFromRecord(record, key);
+
+       DataValue v;
+       v.i64 = value;
+       record->attributes[key] = std::make_pair(DataType::INT64, v);
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_record_set_double(ctx_store_record_h record, const char* key, double value)
+{
+       IF_FAIL_RETURN(record && key, E_PARAM);
+
+       __removeFromRecord(record, key);
+
+       DataValue v;
+       v.dbl = value;
+       record->attributes[key] = std::make_pair(DataType::DOUBLE, v);
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_record_set_string(ctx_store_record_h record, const char* key, const char* value)
+{
+       IF_FAIL_RETURN(record && key && value, E_PARAM);
+
+       __removeFromRecord(record, key);
+
+       DataValue v;
+       v.str = g_strdup(value);
+       IF_FAIL_RETURN(v.str, E_NO_MEM);
+
+       record->attributes[key] = std::make_pair(DataType::STRING, v);
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_destroy(ctx_store_cursor_h cursor)
+{
+       IF_FAIL_RETURN(cursor, E_NONE);
+
+       for (auto& tuple : cursor->tuples) {
+               delete tuple;
+       }
+
+       delete cursor;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_get_count(ctx_store_cursor_h cursor, unsigned int* count)
+{
+       IF_FAIL_RETURN(cursor && count, E_PARAM);
+
+       *count = cursor->tuples.size();
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_get_position(ctx_store_cursor_h cursor, unsigned int* position)
+{
+       IF_FAIL_RETURN(cursor && position, E_PARAM);
+
+       *position = cursor->index;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_set_position(ctx_store_cursor_h cursor, unsigned int position)
+{
+       IF_FAIL_RETURN(cursor && position < cursor->tuples.size(), E_PARAM);
+
+       cursor->index = position;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_first(ctx_store_cursor_h cursor)
+{
+       IF_FAIL_RETURN(cursor, E_PARAM);
+
+       cursor->index = 0;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_last(ctx_store_cursor_h cursor)
+{
+       IF_FAIL_RETURN(cursor, E_PARAM);
+
+       cursor->index = cursor->tuples.size() - 1;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_next(ctx_store_cursor_h cursor)
+{
+       IF_FAIL_RETURN(cursor, E_PARAM);
+       IF_FAIL_RETURN(cursor->index + 1 < cursor->tuples.size(), E_NO_DATA);
+
+       cursor->index += 1;
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_prev(ctx_store_cursor_h cursor)
+{
+       IF_FAIL_RETURN(cursor, E_PARAM);
+       IF_FAIL_RETURN(cursor->index != 0, E_NO_DATA);
+
+       cursor->index -= 1;
+
+       return E_NONE;
+}
+
+static unsigned int __getIndexOf(ctx_store_cursor_h cursor, const std::string& key)
+{
+       unsigned int i;
+       for (i = 0; i < cursor->keys.size(); ++i) {
+               if (cursor->keys[i] == key)
+                       return i;
+       }
+       return i;
+}
+
+EXPORT_API int ctx_store_cursor_get_int64(ctx_store_cursor_h cursor, const char* key, int64_t* value)
+{
+       IF_FAIL_RETURN(cursor && key && value, E_PARAM);
+
+       unsigned int idx = __getIndexOf(cursor, key);
+       const char* valueStr = NULL;
+
+       if (!cursor->tuples[cursor->index]->getAt(idx, &valueStr))
+               return E_PARAM;
+
+       //TODO: Type checking & locale-invariant?
+       *value = std::atoll(valueStr);
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_get_double(ctx_store_cursor_h cursor, const char* key, double* value)
+{
+       //TODO: check whether a number with many digits can be handled.
+       IF_FAIL_RETURN(cursor && key && value, E_PARAM);
+
+       unsigned int idx = __getIndexOf(cursor, key);
+       const char* valueStr = NULL;
+
+       if (!cursor->tuples[cursor->index]->getAt(idx, &valueStr))
+               return E_PARAM;
+
+       //TODO: Type checking & locale-invariant?
+       *value = std::atof(valueStr);
+
+       return E_NONE;
+}
+
+EXPORT_API int ctx_store_cursor_get_string(ctx_store_cursor_h cursor, const char* key, char** value)
+{
+       IF_FAIL_RETURN(cursor && key && value, E_PARAM);
+
+       unsigned int idx = __getIndexOf(cursor, key);
+       const char* valueStr = NULL;
+
+       if (!cursor->tuples[cursor->index]->getAt(idx, &valueStr))
+               return E_PARAM;
+
+       char* buf = g_strdup(valueStr);
+       IF_FAIL_RETURN(buf, E_NO_MEM);
+
+       *value = buf;
+
+       return E_NONE;
+}
index 1f0fdc0..efc6f22 100644 (file)
@@ -2,6 +2,8 @@ SET(target "${PROJECT_NAME}-server")
 
 SET(DEPS "${DEPS} context-common-server")
 
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/private)
+
 FILE(GLOB_RECURSE SRCS *.cpp)
 MESSAGE("Sources: ${SRCS}")
 
similarity index 50%
rename from src/client-dummy/ContextStore.cpp
rename to src/server-dummy/ContextStoreSideGate.cpp
index 3f14d37..c965543 100644 (file)
  * limitations under the License.
  */
 
-#include <ContextStoreTypesPrivate.h>
-#include <ContextStore.h>
+#include <ContextStoreService.h>
+#include <ContextStoreSideGate.h>
 
 using namespace ctx;
 
-ContextStore::ContextStore()
-{
-}
+ContextStoreService* ContextStoreSideGate::__hostService = NULL;
 
-ContextStore::~ContextStore()
+ContextStoreSideGate::ContextStoreSideGate(const std::string& uri, bool isSystem) :
+       __uri(uri),
+       __isSystem(isSystem)
 {
 }
 
-int ContextStore::insert(const std::string& columns, Tuple* record)
+ContextStoreSideGate::~ContextStoreSideGate()
 {
-       return E_SUPPORT;
 }
 
-int ContextStore::insert(const std::string& columns, std::vector<Tuple*>& records)
+int ContextStoreSideGate::insert(const std::string& columns, std::vector<Tuple*>& tuples)
 {
        return E_SUPPORT;
 }
 
-int ContextStore::retrieve(const ContextStoreSearchQuery& query, std::vector<Tuple*>& records)
+ContextStoreSideGate ContextStoreSideGate::getUserStore(const std::string& uri)
 {
-       return E_SUPPORT;
+       ContextStoreSideGate sideGate(uri, false);
+       return sideGate;
 }
 
-int ContextStore::remove(const std::string& selection)
+ContextStoreSideGate ContextStoreSideGate::getSystemStore(const std::string& uri)
 {
-       return E_SUPPORT;
+       ContextStoreSideGate sideGate(uri, true);
+       return sideGate;
 }
index 64a741f..bd50a93 100644 (file)
@@ -2,6 +2,8 @@ SET(target "${PROJECT_NAME}-server-genuine")
 
 SET(DEPS "${DEPS} context-common-server")
 
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include/private)
+
 FILE(GLOB_RECURSE SRCS *.cpp ../shared/*.cpp)
 MESSAGE("Sources: ${SRCS}")
 
index 096f35e..a89af10 100644 (file)
@@ -52,6 +52,7 @@ void ContextStoreClient::onMethodCalled(MethodCall* methodCall)
                        __remove(*store, *methodCall);
                }
        } catch (int error) {
+               _W("Catch: %s", CTX_ERROR_STR(error));
                methodCall->reply(error);
        } catch (std::exception& e) {
                _E("Exception: %s", e.what());
@@ -115,7 +116,7 @@ void ContextStoreClient::__getAccess(Store& store, MethodCall& methodCall)
        if (!store.permitted(*this))
                throw static_cast<int>(E_ACCESS);
 
-       methodCall.reply(g_variant_new("(s)", store.getPath().c_str()));
+       methodCall.reply(g_variant_new("(s)", store.getColumns().c_str()));
 }
 
 void ContextStoreClient::__insert(Store& store, MethodCall& methodCall)
@@ -166,6 +167,8 @@ void ContextStoreClient::__retrieve(Store& store, MethodCall& methodCall)
        int error = store.retrieve(*this, projection, selection, sortOrder, limit, &tuples);
        if (error != E_NONE)
                throw error;
+       if (tuples.empty())
+               throw static_cast<int>(E_NO_DATA);
 
        methodCall.reply(g_variant_new("(v)", Tuple::toGVariant(tuples)));
 }
index e4162e1..00993fd 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <ContextStoreTypesPrivate.h>
+#include <ContextStoreSideGate.h>
 #include <ContextStoreService.h>
 #include "ContextStoreClient.h"
 #include "StoreManager.h"
@@ -27,6 +28,7 @@ ContextStoreService::ContextStoreService(GDBusConnection* conn) :
        ServiceBase(conn, CTX_CONTEXT_STORE, CTX_CONTEXT_STORE_SPEC),
        __storeManager(NULL)
 {
+       ContextStoreSideGate::__hostService = this;
 }
 
 ContextStoreService::~ContextStoreService()
@@ -74,6 +76,8 @@ void ContextStoreService::onUserActivated()
 void ContextStoreService::onUserDeactivated()
 {
        DatabaseManager::closeUser();
+       if (__storeManager)
+               __storeManager->flushUserCache();
 }
 
 StoreManager& ContextStoreService::getStoreManager()
diff --git a/src/server/ContextStoreSideGate.cpp b/src/server/ContextStoreSideGate.cpp
new file mode 100644 (file)
index 0000000..a3f4e36
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * 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 <ContextStoreService.h>
+#include <ContextStoreSideGate.h>
+
+using namespace ctx;
+
+ContextStoreService* ContextStoreSideGate::__hostService = NULL;
+
+ContextStoreSideGate::ContextStoreSideGate(const std::string& uri, bool isSystem) :
+       __uri(uri),
+       __isSystem(isSystem)
+{
+}
+
+ContextStoreSideGate::~ContextStoreSideGate()
+{
+}
+
+int ContextStoreSideGate::insert(const std::string& columns, std::vector<Tuple*>& tuples)
+{
+       //TODO: Switch to the thread-default mainloop, get the Store object, and insert.
+       return E_SUPPORT;
+}
+
+ContextStoreSideGate ContextStoreSideGate::getUserStore(const std::string& uri)
+{
+       ContextStoreSideGate sideGate(uri, false);
+       return sideGate;
+}
+
+ContextStoreSideGate ContextStoreSideGate::getSystemStore(const std::string& uri)
+{
+       ContextStoreSideGate sideGate(uri, true);
+       return sideGate;
+}
index 4343456..146ed54 100644 (file)
@@ -254,9 +254,26 @@ void SchemaLoader::__insertMetadata(Schema& schema)
        char* insertSql = NULL;
        int length = 0;
 
+       std::string columns;
        std::string readPrivil;
        std::string writePrivil;
 
+       for (auto& attr : schema.attributes) {
+               columns.append(attr.first);
+               switch (attr.second) {
+               case Schema::AttributeType::INTEGER:
+                       columns.append(" " COL_INT64 COLUMN_DELIM);
+                       break;
+               case Schema::AttributeType::REAL:
+                       columns.append(" " COL_DOUBLE COLUMN_DELIM);
+                       break;
+               case Schema::AttributeType::TEXT:
+               default:
+                       columns.append(" " COL_STRING COLUMN_DELIM);
+                       break;
+               }
+       }
+
        for (auto& item : schema.readPrivileges) {
                readPrivil.append(item);
                readPrivil.append(PRIVILEGE_DELIM);
@@ -269,10 +286,10 @@ void SchemaLoader::__insertMetadata(Schema& schema)
 
        length = asprintf(&updateSql,
                        "UPDATE ContextStoreSchema"
-                       " SET uri='%s', retention=%u, \"limit\"=%u, readPrivileges='%s', writePrivileges='%s'"
+                       " SET uri='%s', columns='%s', retention=%u, \"limit\"=%u, readPrivileges='%s', writePrivileges='%s'"
                        " WHERE uri='%s'",
-                       schema.uri.c_str(), schema.retention, schema.limit, readPrivil.c_str(), writePrivil.c_str(),
-                       schema.uri.c_str());
+                       schema.uri.c_str(), columns.c_str(), schema.retention, schema.limit,
+                       readPrivil.c_str(), writePrivil.c_str(), schema.uri.c_str());
        if (length <= 0) {
                _E("Memory allocation failed");
                return;
@@ -280,9 +297,10 @@ void SchemaLoader::__insertMetadata(Schema& schema)
 
        length = asprintf(&insertSql,
                        "INSERT OR IGNORE INTO ContextStoreSchema"
-                       " (uri, retention, \"limit\", readPrivileges, writePrivileges)"
-                       " VALUES ('%s', %u, %u, '%s', '%s')",
-                       schema.uri.c_str(), schema.retention, schema.limit, readPrivil.c_str(), writePrivil.c_str());
+                       " (uri, columns, retention, \"limit\", readPrivileges, writePrivileges)"
+                       " VALUES ('%s', '%s', %u, %u, '%s', '%s')",
+                       schema.uri.c_str(), columns.c_str(), schema.retention, schema.limit,
+                       readPrivil.c_str(), writePrivil.c_str());
        if (length <= 0) {
                g_free(updateSql);
                _E("Memory allocation failed");
@@ -303,16 +321,17 @@ void SchemaLoader::__createStoreTable(Schema& schema)
                COL_OWNER_ID " TEXT NOT NULL DEFAULT ''";
 
        for (auto& item : schema.attributes) {
-               attr = attr + "," + item.first;
+               attr.append(",").append(item.first);
                switch (item.second) {
                case Schema::AttributeType::INTEGER:
-                       attr = attr + " INTEGER NOT NULL DEFAULT 0";
+                       attr.append(" INTEGER NOT NULL DEFAULT 0");
                        break;
                case Schema::AttributeType::REAL:
-                       attr = attr + " REAL NOT NULL DEFAULT 0";
+                       attr.append(" REAL NOT NULL DEFAULT 0");
                        break;
+               case Schema::AttributeType::TEXT:
                default:
-                       attr = attr + " TEXT NOT NULL DEFAULT ''";
+                       attr.append(" TEXT NOT NULL DEFAULT ''");
                        break;
                }
        }
index 1bd089b..ef765be 100644 (file)
@@ -37,9 +37,9 @@ bool Store::permitted(ContextStoreClient& client)
        return __readable(client) || __writable(client);
 }
 
-const std::string& Store::getPath()
+const std::string& Store::getColumns()
 {
-       return metadata.path;
+       return metadata.columns;
 }
 
 int Store::insert(ContextStoreClient& client, const std::string& columns, std::vector<Tuple*>& tuples)
@@ -52,6 +52,10 @@ int Store::insert(ContextStoreClient& client, const std::string& columns, std::v
        _D("Inserting %u tuples of (%s) to %s", tuples.size(), columns.c_str(), metadata.uri.c_str());
 
        int error = __getDatabase().insert(metadata.uri, columns, tuples) ? E_NONE : E_PARAM;
+       for (auto& tuple : tuples) {
+               delete tuple;
+       }
+       tuples.clear();
        return error;
 }
 
index c51778a..0000146 100644 (file)
@@ -33,8 +33,8 @@ namespace ctx {
                public:
                        Metadata();
 
-                       std::string path;
                        std::string uri;
+                       std::string columns;
                        unsigned int retention;
                        unsigned int limit;
                        std::vector<std::string> readPrivileges;
@@ -45,7 +45,7 @@ namespace ctx {
 
                bool permitted(ContextStoreClient& client);
 
-               const std::string& getPath();
+               const std::string& getColumns();
 
                int insert(ContextStoreClient& client, const std::string& columns, std::vector<Tuple*>& tuples);
 
index 9c36f95..5a6cee0 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <ContextStoreUtil.h>
 #include "DatabaseManager.h"
 #include "UserStore.h"
 #include "SystemStore.h"
@@ -29,6 +30,8 @@ StoreManager::StoreManager()
 
 StoreManager::~StoreManager()
 {
+       flushUserCache();
+       flushSystemCache();
 }
 
 Store* StoreManager::__findStore(std::list<Store*>& stores, const std::string& uri)
@@ -44,31 +47,16 @@ Store* StoreManager::__findStore(std::list<Store*>& stores, const std::string& u
        return NULL;
 }
 
-std::vector<std::string> __tokenize(std::string& in, const char* delim)
-{
-       std::vector<std::string> tokens;
-       std::size_t begin = 0;
-       std::size_t end = in.find(delim, 0);
-
-       while (end != std::string::npos) {
-               tokens.push_back(in.substr(begin, end - begin));
-               begin = end + 1;
-               end = in.find(delim, begin);
-       }
-
-       return tokens;
-}
-
 template<typename StoreType>
 Store* StoreManager::__createStore(Database& database, std::list<Store*>& stores, const std::string& uri)
 {
        std::string query =
-               "SELECT retention, \"limit\", readPrivileges, writePrivileges"
+               "SELECT columns, retention, \"limit\", readPrivileges, writePrivileges"
                " FROM ContextStoreSchema"
                " WHERE uri='" + uri + "'";
 
        std::vector<Tuple*> tuples;
-       if (!database.execute(query, COL_INT64 COL_INT64 COL_STRING COL_STRING, NULL, &tuples)) {
+       if (!database.execute(query, COL_STRING COL_INT64 COL_INT64 COL_STRING COL_STRING, NULL, &tuples)) {
                _E("DB search failed");
                return NULL;
        }
@@ -77,19 +65,22 @@ Store* StoreManager::__createStore(Database& database, std::list<Store*>& stores
                return NULL;
        }
 
+       std::string columns;
        int64_t retention = 0;
        int64_t limit = 0;
        std::string readPrivil;
        std::string writePrivil;
 
-       tuples[0]->getAt(0, &retention);
-       tuples[0]->getAt(1, &limit);
-       tuples[0]->getAt(2, &readPrivil);
-       tuples[0]->getAt(3, &writePrivil);
+       tuples[0]->getAt(0, &columns);
+       tuples[0]->getAt(1, &retention);
+       tuples[0]->getAt(2, &limit);
+       tuples[0]->getAt(3, &readPrivil);
+       tuples[0]->getAt(4, &writePrivil);
 
        delete tuples[0];
 
        _D("URI: %s, Retention: %u, Limit: %u", uri.c_str(), static_cast<unsigned int>(retention), static_cast<unsigned int>(limit));
+       _D("Columns: %s", columns.c_str());
        _D("Read: %s", readPrivil.c_str());
        _D("Write: %s", writePrivil.c_str());
 
@@ -97,10 +88,11 @@ Store* StoreManager::__createStore(Database& database, std::list<Store*>& stores
        IF_FAIL_RETURN_TAG(store, NULL, _E, "Memory allocation failed");
 
        store->metadata.uri = uri;
+       store->metadata.columns = columns;
        store->metadata.retention= static_cast<unsigned int>(retention);
        store->metadata.limit = static_cast<unsigned int>(limit);
-       store->metadata.readPrivileges = __tokenize(readPrivil, PRIVILEGE_DELIM);
-       store->metadata.writePrivileges = __tokenize(writePrivil, PRIVILEGE_DELIM);
+       store->metadata.readPrivileges = util::tokenizeString(readPrivil, PRIVILEGE_DELIM);
+       store->metadata.writePrivileges = util::tokenizeString(writePrivil, PRIVILEGE_DELIM);
 
        stores.push_front(store);
        if (stores.size() > CACHE_SIZE) {
index 7daa99f..9dbd2d0 100644 (file)
 
 #include <ContextTypes.h>
 #include <ContextErrorUtil.h>
-#include <ContextStoreTypes.h>
 
 #define CTX_CONTEXT_STORE      "ContextStore"
 #define CTX_CONTEXT_STORE_SPEC \
+       "<method name='" METHOD_RELOAD_USER "'>" \
+       "</method>" \
+       "<method name='" METHOD_RELOAD_SYSTEM "'>" \
+       "</method>" \
        "<method name='" METHOD_GET_ACCESS "'>" \
        "       <arg type='s' name='uri' direction='in'/>" \
-       "       <arg type='s' name='path' direction='out'/>" \
+       "       <arg type='s' name='columns' direction='out'/>" \
        "</method>" \
        "<method name='" METHOD_INSERT "'>" \
        "       <arg type='s' name='uri' direction='in'/>" \
@@ -45,6 +48,8 @@
        "       <arg type='s' name='selection' direction='in'/>" \
        "</method>"
 
+#define METHOD_RELOAD_USER             "ReloadUser"
+#define METHOD_RELOAD_SYSTEM   "ReloadSystem"
 #define METHOD_GET_ACCESS      "GetAccess"
 #define METHOD_INSERT          "Insert"
 #define METHOD_RETRIEVE                "Retrieve"
@@ -56,6 +61,7 @@
 #define MAX_RETENTION          8760            // one year
 #define MAX_LIMIT                      100000
 #define PRIVILEGE_DELIM                ";"
+#define COLUMN_DELIM           ";"
 
 #define BASE_PATH                      "context-store"
 
similarity index 61%
rename from src/client-dummy/ContextStoreManager.cpp
rename to src/shared/ContextStoreUtil.cpp
index 9178735..5d6d5f2 100644 (file)
  * limitations under the License.
  */
 
-#include <ContextStoreTypesPrivate.h>
-#include <ContextStoreManager.h>
+#include "ContextStoreTypesPrivate.h"
+#include "ContextStoreUtil.h"
 
 using namespace ctx;
 
-ContextStoreManager::ContextStoreManager()
+std::vector<std::string> util::tokenizeString(std::string& in, const char* delim)
 {
-}
+       std::vector<std::string> tokens;
+       std::size_t begin = 0;
+       std::size_t end = in.find(delim, 0);
 
-ContextStoreManager::~ContextStoreManager()
-{
-}
+       while (end != std::string::npos) {
+               tokens.push_back(in.substr(begin, end - begin));
+               begin = end + 1;
+               end = in.find(delim, begin);
+       }
 
-int ContextStoreManager::getStore(const std::string& uri, ContextStore** store)
-{
-       return E_SUPPORT;
+       return tokens;
 }
similarity index 74%
rename from include/ContextStoreTypes.h
rename to src/shared/ContextStoreUtil.h
index 03bd8b5..52348e8 100644 (file)
  * limitations under the License.
  */
 
-#ifndef __CONTEXT_STORE_TYPES_H__
-#define __CONTEXT_STORE_TYPES_H__
+#ifndef __CONTEXT_STORE_UTIL_H__
+#define __CONTEXT_STORE_UTIL_H__
 
-#include <tizen.h>
+#include <vector>
+#include <string>
 
+namespace ctx { namespace util {
+
+       std::vector<std::string> tokenizeString(std::string& in, const char* delim);
+
+} }
 
 #endif