client: merge PlatformManagedStore into ContextStore and rename it to StoreProxy 04/126904/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 25 Apr 2017 08:32:09 +0000 (17:32 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 25 Apr 2017 08:32:09 +0000 (17:32 +0900)
ContextStore does not support other types of stores except the platform-managed one.
Thus the class hierarchy of ContextStore & PlatformManagedStore classes are not necessary.

Change-Id: Ifd7b69624df98bd96be1b641b51f5dce87f65672
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/client/ContextStore.cpp [deleted file]
src/client/ContextStore.h [deleted file]
src/client/StoreProxy.cpp [moved from src/client/PlatformManagedStore.cpp with 50% similarity]
src/client/StoreProxy.h [moved from src/client/PlatformManagedStore.h with 66% similarity]
src/client/StoreProxyManager.cpp [moved from src/client/ContextStoreManager.cpp with 70% similarity]
src/client/StoreProxyManager.h [moved from src/client/ContextStoreManager.h with 72% similarity]
src/client/context_store.cpp

diff --git a/src/client/ContextStore.cpp b/src/client/ContextStore.cpp
deleted file mode 100644 (file)
index 9539b27..0000000
+++ /dev/null
@@ -1,80 +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 <Database.h>
-#include <ContextStoreTypesPrivate.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()
-{
-}
-
-ContextStore::~ContextStore()
-{
-}
-
-int ContextStore::insert(const std::string& columns, std::shared_ptr<Tuple> record)
-{
-       return E_SUPPORT;
-}
-
-int ContextStore::insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& records)
-{
-       return E_SUPPORT;
-}
-
-int ContextStore::retrieve(const ContextStoreSearchQuery& query, std::vector<std::shared_ptr<Tuple>>* records)
-{
-       return E_SUPPORT;
-}
-
-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 (const std::exception& e) {
-               _E("%s", e.what());
-       }
-
-       return type;
-}
diff --git a/src/client/ContextStore.h b/src/client/ContextStore.h
deleted file mode 100644 (file)
index a713392..0000000
+++ /dev/null
@@ -1,53 +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_H__
-#define __CONTEXT_STORE_H__
-
-#include <vector>
-#include <Tuple.h>
-#include <ContextStoreTypesPrivate.h>
-
-namespace ctx {
-
-       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();
-
-               virtual int insert(const std::string& columns, std::shared_ptr<Tuple> record);
-               virtual int insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& records);
-               virtual int retrieve(const ContextStoreSearchQuery& query, std::vector<std::shared_ptr<Tuple>>* records);
-               virtual int remove(const std::string& selection);
-
-               DataType getColumnType(const std::string& columnName);
-
-       protected:
-               ContextStore();
-
-               std::string __columns;
-       };
-
-}
-
-#endif /* __CONTEXT_STORE_H__ */
similarity index 50%
rename from src/client/PlatformManagedStore.cpp
rename to src/client/StoreProxy.cpp
index f0ae6be..4324244 100644 (file)
  * limitations under the License.
  */
 
-#include "PlatformManagedStore.h"
+#include <Database.h>
+#include <ContextStoreTypesPrivate.h>
+#include "StoreProxy.h"
 
 using namespace ctx;
 
-PlatformManagedStore::PlatformManagedStore(ServiceProxy* proxy) :
-       __proxy(proxy)
+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)
 {
 }
 
-PlatformManagedStore::~PlatformManagedStore()
+StoreProxy::StoreProxy(ServiceProxy* serviceProxy) :
+       __serviceProxy(serviceProxy)
 {
 }
 
-int PlatformManagedStore::init(const std::string& uri)
+StoreProxy::~StoreProxy()
+{
+}
+
+int StoreProxy::init(const std::string& uri)
 {
        __uri = uri;
        GVariant* outParam = NULL;
-       int error = __proxy->call(METHOD_GET_ACCESS, g_variant_new("(s)", uri.c_str()), &outParam);
+       int error = __serviceProxy->call(METHOD_GET_ACCESS, g_variant_new("(s)", uri.c_str()), &outParam);
        IF_FAIL_RETURN(error == E_NONE, error);
 
        const char* columns = NULL;
@@ -44,17 +54,17 @@ int PlatformManagedStore::init(const std::string& uri)
        return E_NONE;
 }
 
-int PlatformManagedStore::insert(const std::string& columns, std::shared_ptr<Tuple> record)
+int StoreProxy::insert(const std::string& columns, std::shared_ptr<Tuple> record)
 {
        if (columns.empty() || record == NULL) {
                return E_PARAM;
        }
 
        GVariant* param = g_variant_new("(ssv)", __uri.c_str(), columns.c_str(), Tuple::toGVariant(record));
-       return __proxy->call(METHOD_INSERT, param);
+       return __serviceProxy->call(METHOD_INSERT, param);
 }
 
-int PlatformManagedStore::insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& records)
+int StoreProxy::insert(const std::string& columns, std::vector<std::shared_ptr<Tuple>>& records)
 {
        if (columns.empty() || records.empty()) {
                records.clear();
@@ -62,10 +72,10 @@ int PlatformManagedStore::insert(const std::string& columns, std::vector<std::sh
        }
 
        GVariant* param = g_variant_new("(ssv)", __uri.c_str(), columns.c_str(), Tuple::toGVariant(records));
-       return __proxy->call(METHOD_INSERT, param);
+       return __serviceProxy->call(METHOD_INSERT, param);
 }
 
-int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::vector<std::shared_ptr<Tuple>>* records)
+int StoreProxy::retrieve(const ContextStoreSearchQuery& query, std::vector<std::shared_ptr<Tuple>>* records)
 {
        IF_FAIL_RETURN(!query.projection.empty() && records, E_PARAM);
 
@@ -74,7 +84,7 @@ int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::ve
                        query.sortOrder.c_str(), static_cast<guint32>(query.limit));
 
        GVariant* outParam = NULL;
-       int error = __proxy->call(METHOD_RETRIEVE, param, &outParam);
+       int error = __serviceProxy->call(METHOD_RETRIEVE, param, &outParam);
        IF_FAIL_RETURN_TAG(error == E_NONE, error, _E, "%s", CTX_ERROR_STR(error));
 
        GVariant* vals = NULL;
@@ -87,7 +97,30 @@ int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::ve
        return error;
 }
 
-int PlatformManagedStore::remove(const std::string& selection)
+int StoreProxy::remove(const std::string& selection)
+{
+       return __serviceProxy->call(METHOD_REMOVE, g_variant_new("(ss)", __uri.c_str(), selection.c_str()));
+}
+
+DataType StoreProxy::getColumnType(const std::string& columnName)
 {
-       return __proxy->call(METHOD_REMOVE, g_variant_new("(ss)", __uri.c_str(), selection.c_str()));
+       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 (const std::exception& e) {
+               _E("%s", e.what());
+       }
+
+       return type;
 }
similarity index 66%
rename from src/client/PlatformManagedStore.h
rename to src/client/StoreProxy.h
index a47943d..5bec474 100644 (file)
  * limitations under the License.
  */
 
-#ifndef __CONTEXT_PLATFORM_MANAGED_STORE_H__
-#define __CONTEXT_PLATFORM_MANAGED_STORE_H__
+#ifndef __CONTEXT_STORE_PROXY_H__
+#define __CONTEXT_STORE_PROXY_H__
 
+#include <vector>
+#include <Tuple.h>
 #include <ServiceProxy.h>
 #include <IServiceResultListener.h>
 #include <IServiceSignalListener.h>
 #include <ContextStoreTypesPrivate.h>
-#include "ContextStore.h"
 
 namespace ctx {
 
-       class PlatformManagedStore : public ContextStore {
+       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 StoreProxy {
        public:
-               PlatformManagedStore(ServiceProxy* proxy);
-               ~PlatformManagedStore();
+               StoreProxy(ServiceProxy* serviceProxy);
+               ~StoreProxy();
 
                int init(const std::string& uri);
 
@@ -37,11 +46,14 @@ namespace ctx {
                int retrieve(const ContextStoreSearchQuery& query, std::vector<std::shared_ptr<Tuple>>* records);
                int remove(const std::string& selection);
 
+               DataType getColumnType(const std::string& columnName);
+
        private:
-               ServiceProxy* __proxy;
+               ServiceProxy* __serviceProxy;
                std::string __uri;
+               std::string __columns;
        };
 
 }
 
-#endif /* __CONTEXT_STORE_PLATFORM_MANAGED_STORE_H__ */
+#endif /* __CONTEXT_STORE_PROXY_H__ */
similarity index 70%
rename from src/client/ContextStoreManager.cpp
rename to src/client/StoreProxyManager.cpp
index 9f135a1..cf8e02a 100644 (file)
@@ -16,8 +16,8 @@
 
 #include <ServiceProxy.h>
 #include <ContextStoreTypesPrivate.h>
-#include "PlatformManagedStore.h"
-#include "ContextStoreManager.h"
+#include "StoreProxy.h"
+#include "StoreProxyManager.h"
 
 using namespace ctx;
 
@@ -27,9 +27,9 @@ static ServiceProxy* __getServiceProxy()
        return &proxy;
 }
 
-static ContextStore* __createPlatformManagedStore(const std::string& uri, int* error)
+static StoreProxy* __createStoreProxy(const std::string& uri, int* error)
 {
-       PlatformManagedStore* store = new(std::nothrow) PlatformManagedStore(__getServiceProxy());
+       StoreProxy* store = new(std::nothrow) StoreProxy(__getServiceProxy());
 
        if (!store) {
                *error = E_NO_MEM;
@@ -48,35 +48,35 @@ static ContextStore* __createPlatformManagedStore(const std::string& uri, int* e
        return store;
 }
 
-ContextStoreManager::ContextStoreManager()
+StoreProxyManager::StoreProxyManager()
 {
 }
 
-ContextStoreManager::~ContextStoreManager()
+StoreProxyManager::~StoreProxyManager()
 {
 }
 
-int ContextStoreManager::getStore(const std::string& uri, ContextStore** store)
+int StoreProxyManager::getStore(const std::string& uri, StoreProxy** store)
 {
        IF_FAIL_RETURN(store, E_PARAM);
        _D("Getting the store %s", uri.c_str());
 
        int error = E_NONE;
-       ContextStore* _store = NULL;
+       StoreProxy* _store = NULL;
 
-       _store = __createPlatformManagedStore(uri, &error);
+       _store = __createStoreProxy(uri, &error);
        IF_FAIL_RETURN(_store, error);
 
        *store = _store;
        return E_NONE;
 }
 
-int ContextStoreManager::reloadUser()
+int StoreProxyManager::reloadUser()
 {
        return __getServiceProxy()->call(METHOD_RELOAD_USER, NULL);
 }
 
-int ContextStoreManager::reloadSystem()
+int StoreProxyManager::reloadSystem()
 {
        return __getServiceProxy()->call(METHOD_RELOAD_SYSTEM, NULL);
 }
similarity index 72%
rename from src/client/ContextStoreManager.h
rename to src/client/StoreProxyManager.h
index 1c978d2..ceed080 100644 (file)
  * limitations under the License.
  */
 
-#ifndef __CONTEXT_STORE_MANAGER_H__
-#define __CONTEXT_STORE_MANAGER_H__
+#ifndef __CONTEXT_STORE_PROXY_MANAGER_H__
+#define __CONTEXT_STORE_PROXY_MANAGER_H__
 
 #include <string>
 #include <ContextStoreTypesPrivate.h>
 
 namespace ctx {
 
-       class ContextStore;
+       class StoreProxy;
 
-       class ContextStoreManager {
+       class StoreProxyManager {
        public:
-               ContextStoreManager();
-               ~ContextStoreManager();
+               StoreProxyManager();
+               ~StoreProxyManager();
 
-               int getStore(const std::string& uri, ContextStore** contextStore);
+               int getStore(const std::string& uri, StoreProxy** contextStore);
 
                int reloadUser();
 
@@ -38,4 +38,4 @@ namespace ctx {
 
 }
 
-#endif /* __CONTEXT_STORE_MANAGER_H__ */
+#endif /* __CONTEXT_STORE_PROXY_MANAGER_H__ */
index 9aeffe5..2a8c635 100644 (file)
@@ -19,8 +19,8 @@
 #include <map>
 #include <ContextStoreTypesPrivate.h>
 #include <context_store_internal.h>
-#include "ContextStore.h"
-#include "ContextStoreManager.h"
+#include "StoreProxy.h"
+#include "StoreProxyManager.h"
 
 #define COMMA ","
 
@@ -28,7 +28,7 @@ using namespace ctx;
 
 typedef struct _ctx_store_handle_s {
        std::string uri;
-       ContextStore* proxy;
+       StoreProxy* proxy;
 } ctx_store_handle_s;
 
 union DataValue {
@@ -47,14 +47,14 @@ typedef struct _ctx_store_cursor_s {
        std::vector<std::shared_ptr<Tuple>> tuples;
 } ctx_store_cursor_s;
 
-static ContextStoreManager __storeManager;
+static StoreProxyManager __storeProxyManager;
 
 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);
+       StoreProxy* proxy;
+       int error = __storeProxyManager.getStore(uri, &proxy);
        IF_FAIL_RETURN(error == E_NONE, error);
 
        ctx_store_h handle = new(std::nothrow) ctx_store_handle_s;