Implement APIs for platform-managed stores 72/118072/3
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 8 Mar 2017 12:39:12 +0000 (21:39 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 10 Mar 2017 12:00:38 +0000 (21:00 +0900)
Change-Id: Ifa8e2f3fd0fab6f9f807e39696932aea73467d15
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
12 files changed:
include/ContextStore.h
include/ContextStoreManager.h
include/ContextStoreSearchQuery.h
src/client-dummy/ContextStore.cpp
src/client-dummy/ContextStoreManager.cpp
src/client-dummy/ContextStoreSearchQuery.cpp
src/client/ContextStore.cpp
src/client/ContextStoreManager.cpp
src/client/ContextStoreSearchQuery.cpp
src/client/PlatformManagedStore.cpp
src/client/PlatformManagedStore.h
src/shared/ContextStoreTypesPrivate.h

index bd1222d..214c988 100644 (file)
@@ -28,8 +28,8 @@ namespace ctx {
        public:
                virtual ~ContextStore();
 
-               virtual int insert(const std::vector<std::string>& columns, Tuple* record);
-               virtual int insert(const std::vector<std::string>& columns, std::vector<Tuple*>& records);
+               virtual int insert(const std::string& columns, Tuple* record);
+               virtual int insert(const std::string& columns, std::vector<Tuple*>& records);
                virtual int retrieve(const ContextStoreSearchQuery& query, std::vector<Tuple*>& result);
                virtual int remove(const std::string& selection);
 
index 4fbdcdc..60f2a3e 100644 (file)
@@ -29,7 +29,6 @@ namespace ctx {
                ~ContextStoreManager();
 
                int getStore(const std::string& uri, ContextStore** contextStore);
-               int removeStore(const std::string& uri);
        };
 
 }
index 2c0d187..c279676 100644 (file)
@@ -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;
index dd2b1d2..3ac2af0 100644 (file)
@@ -27,12 +27,12 @@ ContextStore::~ContextStore()
 {
 }
 
-int ContextStore::insert(const std::vector<std::string>& columns, Tuple* record)
+int ContextStore::insert(const std::string& columns, Tuple* record)
 {
        return E_SUPPORT;
 }
 
-int ContextStore::insert(const std::vector<std::string>& columns, std::vector<Tuple*>& records)
+int ContextStore::insert(const std::string& columns, std::vector<Tuple*>& records)
 {
        return E_SUPPORT;
 }
index f19a6dc..9178735 100644 (file)
@@ -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;
-}
index 25f60d4..bda66fe 100644 (file)
@@ -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;
 }
index dd2b1d2..3ac2af0 100644 (file)
@@ -27,12 +27,12 @@ ContextStore::~ContextStore()
 {
 }
 
-int ContextStore::insert(const std::vector<std::string>& columns, Tuple* record)
+int ContextStore::insert(const std::string& columns, Tuple* record)
 {
        return E_SUPPORT;
 }
 
-int ContextStore::insert(const std::vector<std::string>& columns, std::vector<Tuple*>& records)
+int ContextStore::insert(const std::string& columns, std::vector<Tuple*>& records)
 {
        return E_SUPPORT;
 }
index 69679f4..9dcca7c 100644 (file)
@@ -15,8 +15,6 @@
  */
 
 #include <ServiceProxy.h>
-#include <IServiceResultListener.h>
-#include <IServiceSignalListener.h>
 #include <ContextStoreTypesPrivate.h>
 #include <ContextStoreManager.h>
 #include "PlatformManagedStore.h"
@@ -29,10 +27,9 @@ static ServiceProxy* __getServiceProxy()
        return &proxy;
 }
 
-template<typename StoreType>
-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<PlatformManagedStore>(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;
-}
index 995f92d..d401725 100644 (file)
@@ -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;
index 575d29e..1c0c8f8 100644 (file)
@@ -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<std::string>& 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<std::string>& columns, std::vector<Tuple*>& records)
+int PlatformManagedStore::insert(const std::string& columns, std::vector<Tuple*>& 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<Tuple*>& 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<guint32>(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()));
 }
index fbc7bcd..c5d0786 100644 (file)
@@ -18,6 +18,8 @@
 #define __CONTEXT_STORE_PLATFORM_MANAGED_STORE_H__
 
 #include <ServiceProxy.h>
+#include <IServiceResultListener.h>
+#include <IServiceSignalListener.h>
 #include <ContextStore.h>
 #include <ContextStoreTypesPrivate.h>
 
@@ -30,15 +32,14 @@ namespace ctx {
 
                int init(const std::string& uri);
 
-               int insert(const std::vector<std::string>& columns, Tuple* record);
-               int insert(const std::vector<std::string>& columns, std::vector<Tuple*>& records);
+               int insert(const std::string& columns, Tuple* record);
+               int insert(const std::string& columns, std::vector<Tuple*>& records);
                int retrieve(const ContextStoreSearchQuery& query, std::vector<Tuple*>& result);
                int remove(const std::string& selection);
 
-               static int destroy(const std::string& uri, ServiceProxy* proxy);
-
        private:
                ServiceProxy* __proxy;
+               std::string __uri;
        };
 
 }
index 5322d5f..e482308 100644 (file)
 
 #define CTX_CONTEXT_STORE      "ContextStore"
 #define CTX_CONTEXT_STORE_SPEC \
-       "<method name='test'>" \
-       "       <arg type='i' name='attr' direction='in'/>" \
-       "       <arg type='i' name='return' direction='out'/>" \
+       "<method name='" METHOD_GET_ACCESS "'>" \
+       "       <arg type='s' name='uri' direction='in'/>" \
+       "       <arg type='s' name='path' direction='out'/>" \
+       "</method>" \
+       "<method name='" METHOD_INSERT "'>" \
+       "       <arg type='s' name='uri' direction='in'/>" \
+       "       <arg type='s' name='columns' direction='in'/>" \
+       "       <arg type='v' name='values' direction='in'/>" \
+       "</method>" \
+       "<method name='" METHOD_RETRIEVE "'>" \
+       "       <arg type='s' name='uri' direction='in'/>" \
+       "       <arg type='s' name='projection' direction='in'/>" \
+       "       <arg type='s' name='selection' direction='in'/>" \
+       "       <arg type='s' name='sortOrder' direction='in'/>" \
+       "       <arg type='u' name='limit' direction='in'/>" \
+       "       <arg type='v' name='values' direction='out'/>" \
+       "</method>" \
+       "<method name='" METHOD_REMOVE "'>" \
+       "       <arg type='s' name='uri' direction='in'/>" \
+       "       <arg type='s' name='selection' direction='in'/>" \
        "</method>"
 
+#define METHOD_GET_ACCESS      "GetAccess"
+#define METHOD_INSERT          "Insert"
+#define METHOD_RETRIEVE                "Retrieve"
+#define METHOD_REMOVE          "Remove"
+
+#define IDX_RETRIEVE_RESULT    0
+
 #endif