From ec7cc34ddb4cf5265761b4d1bdc66f4d1b7d628f Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Wed, 8 Mar 2017 21:39:12 +0900 Subject: [PATCH] Implement APIs for platform-managed stores Change-Id: Ifa8e2f3fd0fab6f9f807e39696932aea73467d15 Signed-off-by: Mu-Woong Lee --- include/ContextStore.h | 4 +-- include/ContextStoreManager.h | 1 - include/ContextStoreSearchQuery.h | 7 +++- src/client-dummy/ContextStore.cpp | 4 +-- src/client-dummy/ContextStoreManager.cpp | 5 --- src/client-dummy/ContextStoreSearchQuery.cpp | 22 +++++++++++- src/client/ContextStore.cpp | 4 +-- src/client/ContextStoreManager.cpp | 23 ++---------- src/client/ContextStoreSearchQuery.cpp | 22 +++++++++++- src/client/PlatformManagedStore.cpp | 53 ++++++++++++++++++---------- src/client/PlatformManagedStore.h | 9 ++--- src/shared/ContextStoreTypesPrivate.h | 30 ++++++++++++++-- 12 files changed, 124 insertions(+), 60 deletions(-) diff --git a/include/ContextStore.h b/include/ContextStore.h index bd1222d..214c988 100644 --- a/include/ContextStore.h +++ b/include/ContextStore.h @@ -28,8 +28,8 @@ namespace ctx { public: virtual ~ContextStore(); - virtual int insert(const std::vector& columns, Tuple* record); - virtual int insert(const std::vector& columns, std::vector& records); + virtual int insert(const std::string& columns, Tuple* record); + virtual int insert(const std::string& columns, std::vector& records); virtual int retrieve(const ContextStoreSearchQuery& query, std::vector& result); virtual int remove(const std::string& selection); diff --git a/include/ContextStoreManager.h b/include/ContextStoreManager.h index 4fbdcdc..60f2a3e 100644 --- a/include/ContextStoreManager.h +++ b/include/ContextStoreManager.h @@ -29,7 +29,6 @@ namespace ctx { ~ContextStoreManager(); int getStore(const std::string& uri, ContextStore** contextStore); - int removeStore(const std::string& uri); }; } diff --git a/include/ContextStoreSearchQuery.h b/include/ContextStoreSearchQuery.h index 2c0d187..c279676 100644 --- a/include/ContextStoreSearchQuery.h +++ b/include/ContextStoreSearchQuery.h @@ -38,7 +38,12 @@ namespace ctx { ContextStoreSearchQuery& setSortOrder(const std::string& sortOrder); ContextStoreSearchQuery& setLimit(unsigned int limit); - bool valid(); + 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; diff --git a/src/client-dummy/ContextStore.cpp b/src/client-dummy/ContextStore.cpp index dd2b1d2..3ac2af0 100644 --- a/src/client-dummy/ContextStore.cpp +++ b/src/client-dummy/ContextStore.cpp @@ -27,12 +27,12 @@ ContextStore::~ContextStore() { } -int ContextStore::insert(const std::vector& columns, Tuple* record) +int ContextStore::insert(const std::string& columns, Tuple* record) { return E_SUPPORT; } -int ContextStore::insert(const std::vector& columns, std::vector& records) +int ContextStore::insert(const std::string& columns, std::vector& records) { return E_SUPPORT; } diff --git a/src/client-dummy/ContextStoreManager.cpp b/src/client-dummy/ContextStoreManager.cpp index f19a6dc..9178735 100644 --- a/src/client-dummy/ContextStoreManager.cpp +++ b/src/client-dummy/ContextStoreManager.cpp @@ -31,8 +31,3 @@ int ContextStoreManager::getStore(const std::string& uri, ContextStore** store) { return E_SUPPORT; } - -int ContextStoreManager::removeStore(const std::string& uri) -{ - return E_SUPPORT; -} diff --git a/src/client-dummy/ContextStoreSearchQuery.cpp b/src/client-dummy/ContextStoreSearchQuery.cpp index 25f60d4..bda66fe 100644 --- a/src/client-dummy/ContextStoreSearchQuery.cpp +++ b/src/client-dummy/ContextStoreSearchQuery.cpp @@ -59,7 +59,27 @@ ContextStoreSearchQuery& ContextStoreSearchQuery::setLimit(unsigned int limit) return *this; } -bool ContextStoreSearchQuery::valid() +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/ContextStore.cpp b/src/client/ContextStore.cpp index dd2b1d2..3ac2af0 100644 --- a/src/client/ContextStore.cpp +++ b/src/client/ContextStore.cpp @@ -27,12 +27,12 @@ ContextStore::~ContextStore() { } -int ContextStore::insert(const std::vector& columns, Tuple* record) +int ContextStore::insert(const std::string& columns, Tuple* record) { return E_SUPPORT; } -int ContextStore::insert(const std::vector& columns, std::vector& records) +int ContextStore::insert(const std::string& columns, std::vector& records) { return E_SUPPORT; } diff --git a/src/client/ContextStoreManager.cpp b/src/client/ContextStoreManager.cpp index 69679f4..9dcca7c 100644 --- a/src/client/ContextStoreManager.cpp +++ b/src/client/ContextStoreManager.cpp @@ -15,8 +15,6 @@ */ #include -#include -#include #include #include #include "PlatformManagedStore.h" @@ -29,10 +27,9 @@ static ServiceProxy* __getServiceProxy() return &proxy; } -template -static ContextStore* __createStore(const std::string& uri, int* error) +static ContextStore* __createPlatformManagedStore(const std::string& uri, int* error) { - StoreType* store = new(std::nothrow) StoreType(__getServiceProxy()); + PlatformManagedStore* store = new(std::nothrow) PlatformManagedStore(__getServiceProxy()); if (!store) { *error = E_NO_MEM; @@ -67,23 +64,9 @@ int ContextStoreManager::getStore(const std::string& uri, ContextStore** store) int error = E_NONE; ContextStore* _store = NULL; - _store = __createStore(uri, &error); + _store = __createPlatformManagedStore(uri, &error); IF_FAIL_RETURN(_store, error); *store = _store; return E_NONE; } - -int ContextStoreManager::removeStore(const std::string& uri) -{ - _D("Dropping the store %s", uri.c_str()); - - int error = E_NONE; - - error = PlatformManagedStore::destroy(uri, __getServiceProxy()); - - if (error != E_NONE) - _E("%s", CTX_ERROR_STR(error)); - - return error; -} diff --git a/src/client/ContextStoreSearchQuery.cpp b/src/client/ContextStoreSearchQuery.cpp index 995f92d..d401725 100644 --- a/src/client/ContextStoreSearchQuery.cpp +++ b/src/client/ContextStoreSearchQuery.cpp @@ -59,7 +59,27 @@ ContextStoreSearchQuery& ContextStoreSearchQuery::setLimit(unsigned int limit) return *this; } -bool ContextStoreSearchQuery::valid() +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 { // TODO return true; diff --git a/src/client/PlatformManagedStore.cpp b/src/client/PlatformManagedStore.cpp index 575d29e..1c0c8f8 100644 --- a/src/client/PlatformManagedStore.cpp +++ b/src/client/PlatformManagedStore.cpp @@ -29,36 +29,53 @@ PlatformManagedStore::~PlatformManagedStore() int PlatformManagedStore::init(const std::string& uri) { - // TODO - return E_SUPPORT; + int error = __proxy->call(METHOD_GET_ACCESS, g_variant_new("(s)", uri.c_str())); + __uri = uri; + return error; } -int PlatformManagedStore::insert(const std::vector& columns, Tuple* record) +int PlatformManagedStore::insert(const std::string& columns, Tuple* record) { - // TODO - return E_SUPPORT; + if (columns.empty() || record == NULL) { + delete record; + return E_PARAM; + } + + GVariant* param = g_variant_new("(ssv)", __uri.c_str(), columns.c_str(), Tuple::toGVariant(record)); + return __proxy->call(METHOD_INSERT, param); } -int PlatformManagedStore::insert(const std::vector& columns, std::vector& records) +int PlatformManagedStore::insert(const std::string& columns, std::vector& records) { - // TODO - return E_SUPPORT; + if (columns.empty() || records.empty()) { + for (auto& tuple : records) { + delete tuple; + } + records.clear(); + return E_PARAM; + } + + GVariant* param = g_variant_new("(ssv)", __uri.c_str(), columns.c_str(), Tuple::toGVariant(records)); + return __proxy->call(METHOD_INSERT, param); } int PlatformManagedStore::retrieve(const ContextStoreSearchQuery& query, std::vector& result) { - // TODO - return E_SUPPORT; -} + IF_FAIL_RETURN(query.valid(), E_PARAM); -int PlatformManagedStore::remove(const std::string& selection) -{ - // TODO - return E_SUPPORT; + GVariant* param = g_variant_new("(ssssu)", __uri.c_str(), + query.getProjection().c_str(), query.getSelection().c_str(), + query.getSortOrder().c_str(), static_cast(query.getLimit())); + + GVariant* outParam = NULL; + int error = __proxy->call(METHOD_RETRIEVE, param, &outParam); + IF_FAIL_RETURN_TAG(error == E_NONE, error, _E, "%s", CTX_ERROR_STR(error)); + + result = Tuple::buildFrom(g_variant_get_child_value(outParam, IDX_RETRIEVE_RESULT)); + return E_NONE; } -int PlatformManagedStore::destroy(const std::string& uri, ServiceProxy* proxy) +int PlatformManagedStore::remove(const std::string& selection) { - // TODO - return E_NONE; + return __proxy->call(METHOD_REMOVE, g_variant_new("(ss)", __uri.c_str(), selection.c_str())); } diff --git a/src/client/PlatformManagedStore.h b/src/client/PlatformManagedStore.h index fbc7bcd..c5d0786 100644 --- a/src/client/PlatformManagedStore.h +++ b/src/client/PlatformManagedStore.h @@ -18,6 +18,8 @@ #define __CONTEXT_STORE_PLATFORM_MANAGED_STORE_H__ #include +#include +#include #include #include @@ -30,15 +32,14 @@ namespace ctx { int init(const std::string& uri); - int insert(const std::vector& columns, Tuple* record); - int insert(const std::vector& columns, std::vector& records); + int insert(const std::string& columns, Tuple* record); + int insert(const std::string& columns, std::vector& records); int retrieve(const ContextStoreSearchQuery& query, std::vector& result); int remove(const std::string& selection); - static int destroy(const std::string& uri, ServiceProxy* proxy); - private: ServiceProxy* __proxy; + std::string __uri; }; } diff --git a/src/shared/ContextStoreTypesPrivate.h b/src/shared/ContextStoreTypesPrivate.h index 5322d5f..e482308 100644 --- a/src/shared/ContextStoreTypesPrivate.h +++ b/src/shared/ContextStoreTypesPrivate.h @@ -23,9 +23,33 @@ #define CTX_CONTEXT_STORE "ContextStore" #define CTX_CONTEXT_STORE_SPEC \ - "" \ - " " \ - " " \ + "" \ + " " \ + " " \ + "" \ + "" \ + " " \ + " " \ + " " \ + "" \ + "" \ + " " \ + " " \ + " " \ + " " \ + " " \ + " " \ + "" \ + "" \ + " " \ + " " \ "" +#define METHOD_GET_ACCESS "GetAccess" +#define METHOD_INSERT "Insert" +#define METHOD_RETRIEVE "Retrieve" +#define METHOD_REMOVE "Remove" + +#define IDX_RETRIEVE_RESULT 0 + #endif -- 2.7.4