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>
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <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;
-}
+++ /dev/null
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __CONTEXT_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__ */
* 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;
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();
}
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);
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;
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;
}
* 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);
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__ */
#include <ServiceProxy.h>
#include <ContextStoreTypesPrivate.h>
-#include "PlatformManagedStore.h"
-#include "ContextStoreManager.h"
+#include "StoreProxy.h"
+#include "StoreProxyManager.h"
using namespace ctx;
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;
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);
}
* 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();
}
-#endif /* __CONTEXT_STORE_MANAGER_H__ */
+#endif /* __CONTEXT_STORE_PROXY_MANAGER_H__ */
#include <map>
#include <ContextStoreTypesPrivate.h>
#include <context_store_internal.h>
-#include "ContextStore.h"
-#include "ContextStoreManager.h"
+#include "StoreProxy.h"
+#include "StoreProxyManager.h"
#define COMMA ","
typedef struct _ctx_store_handle_s {
std::string uri;
- ContextStore* proxy;
+ StoreProxy* proxy;
} ctx_store_handle_s;
union DataValue {
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;