--- /dev/null
+/*
+ * Copyright (c) 2015 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 <glib.h>
+#include <list>
+
+#include <types_internal.h>
+#include <context_trigger_types_internal.h>
+#include <Json.h>
+#include "server.h"
+#include "access_control/Privilege.h"
+#include "Request.h"
+#include "ProviderHandler.h"
+#include "ContextManagerImpl.h"
+#include "trigger/TemplateManager.h"
+
+/* Context Providers */
+#include <internal/device_context_provider.h>
+#include <internal/statistics_context_provider.h>
+#include <internal/place_context_provider.h>
+#include <internal/custom_context_provider.h>
+
+struct TriggerItemFormat {
+ std::string subject;
+ int operation;
+ ctx::Json attributes;
+ ctx::Json options;
+ std::string owner;
+ bool unregister;
+ TriggerItemFormat(std::string subj, int ops, ctx::Json attr, ctx::Json opt, std::string own) :
+ subject(subj),
+ operation(ops),
+ attributes(attr),
+ options(opt),
+ owner(own)
+ {
+ unregister = false;
+ }
+
+ TriggerItemFormat(std::string subj) :
+ subject(subj)
+ {
+ unregister = true;
+ }
+};
+
+static std::list<TriggerItemFormat> __triggerItemList;
+bool ctx::ContextManagerImpl::__initialized = false;
+
+ctx::ContextManagerImpl::ContextManagerImpl()
+{
+}
+
+ctx::ContextManagerImpl::~ContextManagerImpl()
+{
+ release();
+}
+
+bool ctx::ContextManagerImpl::init()
+{
+ bool ret;
+
+ ret = init_device_context_provider();
+ IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: device-context-provider");
+
+ ret = init_statistics_context_provider();
+ IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: statistics-context-provider");
+
+ ret = init_place_context_provider();
+ IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: place-context-provider");
+
+ ret = init_custom_context_provider();
+ IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: custom-context-provider");
+
+ __initialized = true;
+
+ return true;
+}
+
+void ctx::ContextManagerImpl::release()
+{
+ for (auto it = __providerHandleMap.begin(); it != __providerHandleMap.end(); ++it) {
+ delete it->second;
+ }
+ __providerHandleMap.clear();
+}
+
+bool ctx::ContextManagerImpl::registerProvider(const char *subject, ctx::ContextProviderInfo &providerInfo)
+{
+ if (__providerHandleMap.find(subject) != __providerHandleMap.end()) {
+ _E("The provider for the subject '%s' is already registered.", subject);
+ return false;
+ }
+
+ _SI("Subj: %s, Priv: %s", subject, providerInfo.privilege);
+ __providerHandleMap[subject] = NULL;
+
+ auto it = __providerHandleMap.find(subject);
+ ProviderHandler *handle = new(std::nothrow) ProviderHandler(it->first.c_str(), providerInfo);
+
+ if (!handle) {
+ _E("Memory allocation failed");
+ __providerHandleMap.erase(it);
+ return false;
+ }
+
+ it->second = handle;
+ return true;
+}
+
+bool ctx::ContextManagerImpl::unregisterProvider(const char *subject)
+{
+ auto it = __providerHandleMap.find(subject);
+ if (it == __providerHandleMap.end()) {
+ _E("The provider for the subject '%s' is not found.", subject);
+ return false;
+ }
+
+ delete it->second;
+ __providerHandleMap.erase(it);
+
+ return true;
+}
+
+bool ctx::ContextManagerImpl::registerTriggerItem(const char *subject, int operation, ctx::Json attributes, ctx::Json options, const char* owner)
+{
+ IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
+
+ if (!__initialized) {
+ __triggerItemList.push_back(TriggerItemFormat(subject, operation, attributes, options, (owner)? owner : ""));
+ } else {
+ ctx::trigger::TemplateManager* tmplMgr = ctx::trigger::TemplateManager::getInstance();
+ IF_FAIL_RETURN_TAG(tmplMgr, false, _E, "Memory allocation failed");
+ tmplMgr->registerTemplate(subject, operation, attributes, options, owner);
+ }
+
+ return true;
+}
+
+bool ctx::ContextManagerImpl::unregisterTriggerItem(const char *subject)
+{
+ IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
+
+ if (!__initialized) {
+ __triggerItemList.push_back(TriggerItemFormat(subject));
+ } else {
+ ctx::trigger::TemplateManager* tmplMgr = ctx::trigger::TemplateManager::getInstance();
+ IF_FAIL_RETURN_TAG(tmplMgr, false, _E, "Memory allocation failed");
+ tmplMgr->unregisterTemplate(subject);
+ }
+
+ return true;
+}
+
+bool ctx::ContextManagerImpl::popTriggerItem(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string& owner, bool& unregister)
+{
+ IF_FAIL_RETURN(!__triggerItemList.empty(), false);
+
+ TriggerItemFormat format = __triggerItemList.front();
+ __triggerItemList.pop_front();
+
+ subject = format.subject;
+ operation = format.operation;
+ attributes = format.attributes;
+ options = format.options;
+ owner = format.owner;
+ unregister = format.unregister;
+
+ return true;
+}
+
+void ctx::ContextManagerImpl::assignRequest(ctx::RequestInfo* request)
+{
+ if (__handleCustomRequest(request)) {
+ delete request;
+ return;
+ }
+
+ auto it = __providerHandleMap.find(request->getSubject());
+ if (it == __providerHandleMap.end()) {
+ _W("Unsupported subject");
+ request->reply(ERR_NOT_SUPPORTED);
+ delete request;
+ return;
+ }
+
+ if (!it->second->isAllowed(request->getCredentials())) {
+ _W("Permission denied");
+ request->reply(ERR_PERMISSION_DENIED);
+ delete request;
+ return;
+ }
+
+ switch (request->getType()) {
+ case REQ_SUBSCRIBE:
+ it->second->subscribe(request);
+ break;
+ case REQ_UNSUBSCRIBE:
+ it->second->unsubscribe(request);
+ break;
+ case REQ_READ:
+ case REQ_READ_SYNC:
+ it->second->read(request);
+ break;
+ case REQ_WRITE:
+ it->second->write(request);
+ break;
+ case REQ_SUPPORT:
+ request->reply(ERR_NONE);
+ delete request;
+ break;
+ default:
+ _E("Invalid type of request");
+ delete request;
+ }
+}
+
+bool ctx::ContextManagerImpl::isSupported(const char *subject)
+{
+ auto it = __providerHandleMap.find(subject);
+ return (it != __providerHandleMap.end());
+}
+
+bool ctx::ContextManagerImpl::isAllowed(const ctx::Credentials *creds, const char *subject)
+{
+ IF_FAIL_RETURN(creds, true); /* In case internal requests */
+ auto it = __providerHandleMap.find(subject);
+ IF_FAIL_RETURN(it != __providerHandleMap.end(), false);
+ return it->second->isAllowed(creds);
+}
+
+void ctx::ContextManagerImpl::__publish(const char* subject, ctx::Json &option, int error, ctx::Json &dataUpdated)
+{
+ _I("Publishing '%s'", subject);
+ _J("Option", option);
+
+ auto it = __providerHandleMap.find(subject);
+ IF_FAIL_VOID(it != __providerHandleMap.end());
+
+ it->second->publish(option, error, dataUpdated);
+}
+
+void ctx::ContextManagerImpl::__replyToRead(const char* subject, ctx::Json &option, int error, ctx::Json &dataRead)
+{
+ _I("Sending data of '%s'", subject);
+ _J("Option", option);
+ _J("Data", dataRead);
+
+ auto it = __providerHandleMap.find(subject);
+ IF_FAIL_VOID(it != __providerHandleMap.end());
+
+ it->second->replyToRead(option, error, dataRead);
+}
+
+struct PublishedData {
+ int type;
+ ctx::ContextManagerImpl *mgr;
+ std::string subject;
+ int error;
+ ctx::Json option;
+ ctx::Json data;
+ PublishedData(int t, ctx::ContextManagerImpl *m, const char* s, ctx::Json& o, int e, ctx::Json& d)
+ : type(t), mgr(m), subject(s), error(e)
+ {
+ option = o.str();
+ data = d.str();
+ }
+};
+
+gboolean ctx::ContextManagerImpl::__threadSwitcher(gpointer data)
+{
+ PublishedData *tuple = static_cast<PublishedData*>(data);
+
+ switch (tuple->type) {
+ case REQ_SUBSCRIBE:
+ tuple->mgr->__publish(tuple->subject.c_str(), tuple->option, tuple->error, tuple->data);
+ break;
+ case REQ_READ:
+ tuple->mgr->__replyToRead(tuple->subject.c_str(), tuple->option, tuple->error, tuple->data);
+ break;
+ default:
+ _W("Invalid type");
+ }
+
+ delete tuple;
+ return FALSE;
+}
+
+bool ctx::ContextManagerImpl::publish(const char* subject, ctx::Json& option, int error, ctx::Json& dataUpdated)
+{
+ IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
+
+ PublishedData *tuple = new(std::nothrow) PublishedData(REQ_SUBSCRIBE, this, subject, option, error, dataUpdated);
+ IF_FAIL_RETURN_TAG(tuple, false, _E, "Memory allocation failed");
+
+ g_idle_add(__threadSwitcher, tuple);
+
+ return true;
+}
+
+bool ctx::ContextManagerImpl::replyToRead(const char* subject, ctx::Json& option, int error, ctx::Json& dataRead)
+{
+ IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
+
+ PublishedData *tuple = new(std::nothrow) PublishedData(REQ_READ, this, subject, option, error, dataRead);
+ IF_FAIL_RETURN_TAG(tuple, false, _E, "Memory allocation failed");
+
+ g_idle_add(__threadSwitcher, tuple);
+
+ return true;
+}
+
+bool ctx::ContextManagerImpl::__handleCustomRequest(ctx::RequestInfo* request)
+{
+ std::string subject = request->getSubject();
+ IF_FAIL_RETURN( subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_ADD ||
+ subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE ||
+ subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_PUBLISH, false);
+
+ const char* pkg_id = request->getPackageId();
+ if (pkg_id == NULL) {
+ request->reply(ERR_OPERATION_FAILED);
+ return true;
+ }
+
+ ctx::Json desc = request->getDescription();
+ std::string name;
+ desc.get(NULL, CT_CUSTOM_NAME, &name);
+ std::string subj = pkg_id + std::string("::") + name;
+
+ int error = ERR_NONE;
+ if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_ADD) {
+ ctx::Json tmpl;
+ desc.get(NULL, CT_CUSTOM_ATTRIBUTES, &tmpl);
+
+ error = ctx::custom_context_provider::addItem(subj, name, tmpl, pkg_id);
+ } else if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE) {
+ error = ctx::custom_context_provider::removeItem(subj);
+ if (error == ERR_NONE) {
+ ctx::Json data;
+ data.set(NULL, CT_CUSTOM_SUBJECT, subj);
+ request->reply(error, data);
+ }
+ } else if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_PUBLISH) {
+ ctx::Json fact;
+ desc.get(NULL, CT_CUSTOM_FACT, &fact);
+
+ error = ctx::custom_context_provider::publishData(subj, fact);
+ }
+
+ request->reply(error);
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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_MANAGER_IMPL_H_
+#define _CONTEXT_MANAGER_IMPL_H_
+
+#include <string>
+#include <map>
+#include <glib.h>
+#include <ContextManager.h>
+#include <IContextManager.h>
+
+namespace ctx {
+
+ /* Forward declaration */
+ class Credentials;
+ class RequestInfo;
+ class ProviderHandler;
+
+ class ContextManagerImpl : public IContextManager {
+ public:
+ ContextManagerImpl();
+ ~ContextManagerImpl();
+
+ bool init();
+ void release();
+
+ void assignRequest(ctx::RequestInfo *request);
+ bool isSupported(const char *subject);
+ bool isAllowed(const Credentials *creds, const char *subject);
+ bool popTriggerItem(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string &owner, bool& unregister);
+
+ /* From the interface class */
+ bool registerProvider(const char *subject, ContextProviderInfo &providerInfo);
+ bool unregisterProvider(const char *subject);
+ bool registerTriggerItem(const char *subject, int operation, ctx::Json attributes, ctx::Json options, const char *owner = NULL);
+ bool unregisterTriggerItem(const char *subject);
+ bool publish(const char *subject, ctx::Json &option, int error, ctx::Json &dataUpdated);
+ bool replyToRead(const char *subject, ctx::Json &option, int error, ctx::Json &dataRead);
+
+ private:
+ std::map<std::string, ProviderHandler*> __providerHandleMap;
+ static bool __initialized;
+
+ static gboolean __threadSwitcher(gpointer data);
+ void __publish(const char *subject, ctx::Json &option, int error, ctx::Json &dataUpdated);
+ void __replyToRead(const char *subject, ctx::Json &option, int error, ctx::Json &dataRead);
+
+ /* For custom request */
+ bool __handleCustomRequest(ctx::RequestInfo* request);
+ }; /* class ContextManagerImpl */
+
+} /* namespace ctx */
+
+#endif /* End of __CONTEXT_MANAGER_IMPL_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2015 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 <glib.h>
+#include <types_internal.h>
+#include <Json.h>
+#include "access_control/Privilege.h"
+#include "server.h"
+#include "Request.h"
+#include "ProviderHandler.h"
+
+ctx::ProviderHandler::ProviderHandler(const char *subj, ctx::ContextProviderInfo &prvd) :
+ __subject(subj),
+ __providerInfo(prvd)
+{
+}
+
+ctx::ProviderHandler::~ProviderHandler()
+{
+ for (auto it = __subscribeRequests.begin(); it != __subscribeRequests.end(); ++it) {
+ delete *it;
+ }
+ __subscribeRequests.clear();
+
+ for (auto it = __readRequests.begin(); it != __readRequests.end(); ++it) {
+ delete *it;
+ }
+ __readRequests.clear();
+
+ __providerInfo.destroy(__providerInfo.data);
+}
+
+bool ctx::ProviderHandler::isAllowed(const ctx::Credentials *creds)
+{
+ IF_FAIL_RETURN(creds, true); /* In case of internal requests */
+ return privilege_manager::isAllowed(creds, __providerInfo.privilege);
+}
+
+ctx::ContextProviderBase* ctx::ProviderHandler::__getProvider(ctx::RequestInfo *request)
+{
+ ContextProviderBase *provider = __providerInfo.create(__providerInfo.data);
+ if (!provider) {
+ _E("Memory allocation failed");
+ delete request;
+ return NULL;
+ }
+
+ return provider;
+}
+
+void ctx::ProviderHandler::subscribe(ctx::RequestInfo *request)
+{
+ _I(CYAN("'%s' subscribes '%s' (RID-%d)"), request->getClient(), __subject, request->getId());
+
+ ContextProviderBase *provider = __getProvider(request);
+ IF_FAIL_VOID(provider);
+
+ ctx::Json requestResult;
+ int error = provider->subscribe(__subject, request->getDescription().str(), &requestResult);
+
+ if (!request->reply(error, requestResult) || error != ERR_NONE) {
+ delete request;
+ return;
+ }
+
+ __subscribeRequests.push_back(request);
+}
+
+void ctx::ProviderHandler::unsubscribe(ctx::RequestInfo *request)
+{
+ _I(CYAN("'%s' unsubscribes '%s' (RID-%d)"), request->getClient(), __subject, request->getId());
+
+ // Search the subscribe request to be removed
+ auto target = __findRequest(__subscribeRequests, request->getClient(), request->getId());
+ if (target == __subscribeRequests.end()) {
+ _W("Unknown request");
+ delete request;
+ return;
+ }
+
+ // Keep the pointer to the request found
+ RequestInfo *req_found = *target;
+
+ // Remove the request from the list
+ __subscribeRequests.erase(target);
+
+ // Check if there exist the same requests
+ if (__findRequest(__subscribeRequests, req_found->getDescription()) != __subscribeRequests.end()) {
+ // Do not stop detecting the subject
+ _D("A same request from '%s' exists", req_found->getClient());
+ request->reply(ERR_NONE);
+ delete request;
+ delete req_found;
+ return;
+ }
+
+ // Get the provider
+ ContextProviderBase *provider = __getProvider(request);
+ IF_FAIL_VOID(provider);
+
+ // Stop detecting the subject
+ int error = provider->unsubscribe(__subject, req_found->getDescription());
+ request->reply(error);
+ delete request;
+ delete req_found;
+}
+
+void ctx::ProviderHandler::read(ctx::RequestInfo *request)
+{
+ _I(CYAN("'%s' reads '%s' (RID-%d)"), request->getClient(), __subject, request->getId());
+
+ ContextProviderBase *provider = __getProvider(request);
+ IF_FAIL_VOID(provider);
+
+ ctx::Json requestResult;
+ int error = provider->read(__subject, request->getDescription().str(), &requestResult);
+
+ if (!request->reply(error, requestResult) || error != ERR_NONE) {
+ delete request;
+ return;
+ }
+
+ __readRequests.push_back(request);
+}
+
+void ctx::ProviderHandler::write(ctx::RequestInfo *request)
+{
+ _I(CYAN("'%s' writes '%s' (RID-%d)"), request->getClient(), __subject, request->getId());
+
+ ContextProviderBase *provider = __getProvider(request);
+ IF_FAIL_VOID(provider);
+
+ ctx::Json requestResult;
+ int error = provider->write(__subject, request->getDescription(), &requestResult);
+
+ request->reply(error, requestResult);
+ delete request;
+}
+
+bool ctx::ProviderHandler::publish(ctx::Json &option, int error, ctx::Json &dataUpdated)
+{
+ auto end = __subscribeRequests.end();
+ auto target = __findRequest(__subscribeRequests.begin(), end, option);
+
+ while (target != end) {
+ if (!(*target)->publish(error, dataUpdated)) {
+ return false;
+ }
+ target = __findRequest(++target, end, option);
+ }
+
+ return true;
+}
+
+bool ctx::ProviderHandler::replyToRead(ctx::Json &option, int error, ctx::Json &dataRead)
+{
+ auto end = __readRequests.end();
+ auto target = __findRequest(__readRequests.begin(), end, option);
+ auto prev = target;
+
+ ctx::Json dummy;
+
+ while (target != end) {
+ (*target)->reply(error, dummy, dataRead);
+ prev = target;
+ target = __findRequest(++target, end, option);
+
+ delete *prev;
+ __readRequests.erase(prev);
+ }
+
+ return true;
+}
+
+ctx::ProviderHandler::RequestList::iterator
+ctx::ProviderHandler::__findRequest(RequestList &reqList, Json &option)
+{
+ return __findRequest(reqList.begin(), reqList.end(), option);
+}
+
+ctx::ProviderHandler::RequestList::iterator
+ctx::ProviderHandler::__findRequest(RequestList &reqList, std::string client, int reqId)
+{
+ for (auto it = reqList.begin(); it != reqList.end(); ++it) {
+ if (client == (*it)->getClient() && reqId == (*it)->getId()) {
+ return it;
+ }
+ }
+ return reqList.end();
+}
+
+ctx::ProviderHandler::RequestList::iterator
+ctx::ProviderHandler::__findRequest(RequestList::iterator begin, RequestList::iterator end, Json &option)
+{
+ for (auto it = begin; it != end; ++it) {
+ if (option == (*it)->getDescription()) {
+ return it;
+ }
+ }
+ return end;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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_PROVIDER_HANDLER_H_
+#define _CONTEXT_PROVIDER_HANDLER_H_
+
+#include <string>
+#include <list>
+#include <ContextProviderBase.h>
+
+namespace ctx {
+
+ class Json;
+ class Credentials;
+ class RequestInfo;
+
+ class ProviderHandler {
+ public:
+ typedef std::list<RequestInfo*> RequestList;
+
+ ProviderHandler(const char *subj, ContextProviderInfo &prvd);
+ ~ProviderHandler();
+
+ bool isAllowed(const Credentials *creds);
+
+ void subscribe(RequestInfo *request);
+ void unsubscribe(RequestInfo *request);
+ void read(RequestInfo *request);
+ void write(RequestInfo *request);
+
+ bool publish(ctx::Json &option, int error, ctx::Json &dataUpdated);
+ bool replyToRead(ctx::Json &option, int error, ctx::Json &dataRead);
+
+ private:
+ const char *__subject;
+ ContextProviderInfo __providerInfo;
+ RequestList __subscribeRequests;
+ RequestList __readRequests;
+
+ ContextProviderBase* __getProvider(RequestInfo *request);
+ RequestList::iterator __findRequest(RequestList &reqList, Json &option);
+ RequestList::iterator __findRequest(RequestList &reqList, std::string client, int reqId);
+ RequestList::iterator __findRequest(RequestList::iterator begin, RequestList::iterator end, Json &option);
+
+ }; /* class ProviderHandler */
+
+} /* namespace ctx */
+
+#endif /* _CONTEXT_PROVIDER_HANDLER_H_ */
+++ /dev/null
-/*
- * Copyright (c) 2015 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 <glib.h>
-#include <list>
-
-#include <types_internal.h>
-#include <context_trigger_types_internal.h>
-#include <Json.h>
-#include <provider_iface.h>
-#include "server.h"
-#include "access_control/Privilege.h"
-#include "Request.h"
-#include "provider.h"
-#include "context_mgr_impl.h"
-#include "trigger/TemplateManager.h"
-
-/* Context Providers */
-#include <internal/device_context_provider.h>
-#include <internal/statistics_context_provider.h>
-#include <internal/place_context_provider.h>
-#include <internal/custom_context_provider.h>
-
-struct trigger_item_format_s {
- std::string subject;
- int operation;
- ctx::Json attributes;
- ctx::Json options;
- std::string owner;
- bool unregister;
- trigger_item_format_s(std::string subj, int ops, ctx::Json attr, ctx::Json opt, std::string own)
- : subject(subj), operation(ops), attributes(attr), options(opt), owner(own)
- {
- unregister = false;
- }
-
- trigger_item_format_s(std::string subj)
- : subject(subj) {
- unregister = true;
- }
-};
-
-static std::list<trigger_item_format_s> __trigger_item_list;
-bool ctx::context_manager_impl::initialized = false;
-
-ctx::context_manager_impl::context_manager_impl()
-{
-}
-
-ctx::context_manager_impl::~context_manager_impl()
-{
- release();
-}
-
-bool ctx::context_manager_impl::init()
-{
- bool ret;
-
- ret = init_device_context_provider();
- IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: device-context-provider");
-
- ret = init_statistics_context_provider();
- IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: statistics-context-provider");
-
- ret = init_place_context_provider();
- IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: place-context-provider");
-
- ret = init_custom_context_provider();
- IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: custom-context-provider");
-
- initialized = true;
-
- return true;
-}
-
-void ctx::context_manager_impl::release()
-{
- for (auto it = provider_handle_map.begin(); it != provider_handle_map.end(); ++it) {
- delete it->second;
- }
- provider_handle_map.clear();
-}
-
-bool ctx::context_manager_impl::register_provider(const char *subject, ctx::context_provider_info &provider_info)
-{
- if (provider_handle_map.find(subject) != provider_handle_map.end()) {
- _E("The provider for the subject '%s' is already registered.", subject);
- return false;
- }
-
- _SI("Subj: %s, Priv: %s", subject, provider_info.privilege);
- provider_handle_map[subject] = NULL;
-
- auto it = provider_handle_map.find(subject);
- context_provider_handler *handle = new(std::nothrow) context_provider_handler(it->first.c_str(), provider_info);
-
- if (!handle) {
- _E("Memory allocation failed");
- provider_handle_map.erase(it);
- return false;
- }
-
- it->second = handle;
- return true;
-}
-
-bool ctx::context_manager_impl::unregister_provider(const char *subject)
-{
- auto it = provider_handle_map.find(subject);
- if (it == provider_handle_map.end()) {
- _E("The provider for the subject '%s' is not found.", subject);
- return false;
- }
-
- delete it->second;
- provider_handle_map.erase(it);
-
- return true;
-}
-
-bool ctx::context_manager_impl::register_trigger_item(const char *subject, int operation, ctx::Json attributes, ctx::Json options, const char* owner)
-{
- IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
-
- if (!initialized) {
- __trigger_item_list.push_back(trigger_item_format_s(subject, operation, attributes, options, (owner)? owner : ""));
- } else {
- ctx::trigger::TemplateManager* tmplMgr = ctx::trigger::TemplateManager::getInstance();
- IF_FAIL_RETURN_TAG(tmplMgr, false, _E, "Memory allocation failed");
- tmplMgr->registerTemplate(subject, operation, attributes, options, owner);
- }
-
- return true;
-}
-
-bool ctx::context_manager_impl::unregister_trigger_item(const char *subject)
-{
- IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
-
- if (!initialized) {
- __trigger_item_list.push_back(trigger_item_format_s(subject));
- } else {
- ctx::trigger::TemplateManager* tmplMgr = ctx::trigger::TemplateManager::getInstance();
- IF_FAIL_RETURN_TAG(tmplMgr, false, _E, "Memory allocation failed");
- tmplMgr->unregisterTemplate(subject);
- }
-
- return true;
-}
-
-bool ctx::context_manager_impl::pop_trigger_item(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string& owner, bool& unregister)
-{
- IF_FAIL_RETURN(!__trigger_item_list.empty(), false);
-
- trigger_item_format_s format = __trigger_item_list.front();
- __trigger_item_list.pop_front();
-
- subject = format.subject;
- operation = format.operation;
- attributes = format.attributes;
- options = format.options;
- owner = format.owner;
- unregister = format.unregister;
-
- return true;
-}
-
-void ctx::context_manager_impl::assign_request(ctx::RequestInfo* request)
-{
- if (handle_custom_request(request)) {
- delete request;
- return;
- }
-
- auto it = provider_handle_map.find(request->getSubject());
- if (it == provider_handle_map.end()) {
- _W("Unsupported subject");
- request->reply(ERR_NOT_SUPPORTED);
- delete request;
- return;
- }
-
- if (!it->second->is_allowed(request->getCredentials())) {
- _W("Permission denied");
- request->reply(ERR_PERMISSION_DENIED);
- delete request;
- return;
- }
-
- switch (request->getType()) {
- case REQ_SUBSCRIBE:
- it->second->subscribe(request);
- break;
- case REQ_UNSUBSCRIBE:
- it->second->unsubscribe(request);
- break;
- case REQ_READ:
- case REQ_READ_SYNC:
- it->second->read(request);
- break;
- case REQ_WRITE:
- it->second->write(request);
- break;
- case REQ_SUPPORT:
- request->reply(ERR_NONE);
- delete request;
- break;
- default:
- _E("Invalid type of request");
- delete request;
- }
-}
-
-bool ctx::context_manager_impl::is_supported(const char *subject)
-{
- auto it = provider_handle_map.find(subject);
- return (it != provider_handle_map.end());
-}
-
-bool ctx::context_manager_impl::is_allowed(const ctx::Credentials *creds, const char *subject)
-{
- IF_FAIL_RETURN(creds, true); /* In case internal requests */
- auto it = provider_handle_map.find(subject);
- IF_FAIL_RETURN(it != provider_handle_map.end(), false);
- return it->second->is_allowed(creds);
-}
-
-void ctx::context_manager_impl::_publish(const char* subject, ctx::Json &option, int error, ctx::Json &data_updated)
-{
- _I("Publishing '%s'", subject);
- _J("Option", option);
-
- auto it = provider_handle_map.find(subject);
- IF_FAIL_VOID(it != provider_handle_map.end());
-
- it->second->publish(option, error, data_updated);
-}
-
-void ctx::context_manager_impl::_reply_to_read(const char* subject, ctx::Json &option, int error, ctx::Json &data_read)
-{
- _I("Sending data of '%s'", subject);
- _J("Option", option);
- _J("Data", data_read);
-
- auto it = provider_handle_map.find(subject);
- IF_FAIL_VOID(it != provider_handle_map.end());
-
- it->second->reply_to_read(option, error, data_read);
-}
-
-struct published_data_s {
- int type;
- ctx::context_manager_impl *mgr;
- std::string subject;
- int error;
- ctx::Json option;
- ctx::Json data;
- published_data_s(int t, ctx::context_manager_impl *m, const char* s, ctx::Json& o, int e, ctx::Json& d)
- : type(t), mgr(m), subject(s), error(e)
- {
- option = o.str();
- data = d.str();
- }
-};
-
-gboolean ctx::context_manager_impl::thread_switcher(gpointer data)
-{
- published_data_s *tuple = static_cast<published_data_s*>(data);
-
- switch (tuple->type) {
- case REQ_SUBSCRIBE:
- tuple->mgr->_publish(tuple->subject.c_str(), tuple->option, tuple->error, tuple->data);
- break;
- case REQ_READ:
- tuple->mgr->_reply_to_read(tuple->subject.c_str(), tuple->option, tuple->error, tuple->data);
- break;
- default:
- _W("Invalid type");
- }
-
- delete tuple;
- return FALSE;
-}
-
-bool ctx::context_manager_impl::publish(const char* subject, ctx::Json& option, int error, ctx::Json& data_updated)
-{
- IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
-
- published_data_s *tuple = new(std::nothrow) published_data_s(REQ_SUBSCRIBE, this, subject, option, error, data_updated);
- IF_FAIL_RETURN_TAG(tuple, false, _E, "Memory allocation failed");
-
- g_idle_add(thread_switcher, tuple);
-
- return true;
-}
-
-bool ctx::context_manager_impl::reply_to_read(const char* subject, ctx::Json& option, int error, ctx::Json& data_read)
-{
- IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
-
- published_data_s *tuple = new(std::nothrow) published_data_s(REQ_READ, this, subject, option, error, data_read);
- IF_FAIL_RETURN_TAG(tuple, false, _E, "Memory allocation failed");
-
- g_idle_add(thread_switcher, tuple);
-
- return true;
-}
-
-bool ctx::context_manager_impl::handle_custom_request(ctx::RequestInfo* request)
-{
- std::string subject = request->getSubject();
- IF_FAIL_RETURN( subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_ADD ||
- subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE ||
- subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_PUBLISH, false);
-
- const char* pkg_id = request->getPackageId();
- if (pkg_id == NULL) {
- request->reply(ERR_OPERATION_FAILED);
- return true;
- }
-
- ctx::Json desc = request->getDescription();
- std::string name;
- desc.get(NULL, CT_CUSTOM_NAME, &name);
- std::string subj = pkg_id + std::string("::") + name;
-
- int error = ERR_NONE;
- if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_ADD) {
- ctx::Json tmpl;
- desc.get(NULL, CT_CUSTOM_ATTRIBUTES, &tmpl);
-
- error = ctx::custom_context_provider::add_item(subj, name, tmpl, pkg_id);
- } else if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE) {
- error = ctx::custom_context_provider::remove_item(subj);
- if (error == ERR_NONE) {
- ctx::Json data;
- data.set(NULL, CT_CUSTOM_SUBJECT, subj);
- request->reply(error, data);
- }
- } else if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_PUBLISH) {
- ctx::Json fact;
- desc.get(NULL, CT_CUSTOM_FACT, &fact);
-
- error = ctx::custom_context_provider::publish_data(subj, fact);
- }
-
- request->reply(error);
- return true;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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_MANAGER_IMPL_H__
-#define __CONTEXT_MANAGER_IMPL_H__
-
-#include <string>
-#include <map>
-#include <glib.h>
-#include <context_mgr.h>
-#include <context_mgr_iface.h>
-
-namespace ctx {
-
- /* Forward declaration */
- class Credentials;
- class RequestInfo;
- class context_provider_handler;
-
- class context_manager_impl : public context_manager_iface {
- public:
- context_manager_impl();
- ~context_manager_impl();
-
- bool init();
- void release();
-
- void assign_request(ctx::RequestInfo *request);
- bool is_supported(const char *subject);
- bool is_allowed(const Credentials *creds, const char *subject);
- bool pop_trigger_item(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string &owner, bool& unregister);
-
- /* From the interface class */
- bool register_provider(const char *subject, context_provider_info &provider_info);
- bool unregister_provider(const char *subject);
- bool register_trigger_item(const char *subject, int operation, ctx::Json attributes, ctx::Json options, const char *owner = NULL);
- bool unregister_trigger_item(const char *subject);
- bool publish(const char *subject, ctx::Json &option, int error, ctx::Json &data_updated);
- bool reply_to_read(const char *subject, ctx::Json &option, int error, ctx::Json &data_read);
-
- private:
- std::map<std::string, context_provider_handler*> provider_handle_map;
- static bool initialized;
-
- static gboolean thread_switcher(gpointer data);
- void _publish(const char *subject, ctx::Json &option, int error, ctx::Json &data_updated);
- void _reply_to_read(const char *subject, ctx::Json &option, int error, ctx::Json &data_read);
-
- /* For custom request */
- bool handle_custom_request(ctx::RequestInfo* request);
- }; /* class context_manager_impl */
-
-} /* namespace ctx */
-
-#endif /* End of __CONTEXT_MANAGER_IMPL_H__ */
+++ /dev/null
-/*
- * Copyright (c) 2015 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 <glib.h>
-#include <types_internal.h>
-#include <Json.h>
-#include "access_control/Privilege.h"
-#include "server.h"
-#include "Request.h"
-#include "provider.h"
-
-ctx::context_provider_handler::context_provider_handler(const char *subj, ctx::context_provider_info &prvd) :
- subject(subj),
- provider_info(prvd)
-{
-}
-
-ctx::context_provider_handler::~context_provider_handler()
-{
- for (auto it = subscribe_requests.begin(); it != subscribe_requests.end(); ++it) {
- delete *it;
- }
- subscribe_requests.clear();
-
- for (auto it = read_requests.begin(); it != read_requests.end(); ++it) {
- delete *it;
- }
- read_requests.clear();
-
- provider_info.destroy(provider_info.data);
-}
-
-bool ctx::context_provider_handler::is_allowed(const ctx::Credentials *creds)
-{
- IF_FAIL_RETURN(creds, true); /* In case of internal requests */
- return privilege_manager::isAllowed(creds, provider_info.privilege);
-}
-
-ctx::context_provider_iface* ctx::context_provider_handler::get_provider(ctx::RequestInfo *request)
-{
- context_provider_iface *provider = provider_info.create(provider_info.data);
- if (!provider) {
- _E("Memory allocation failed");
- delete request;
- return NULL;
- }
-
- return provider;
-}
-
-void ctx::context_provider_handler::subscribe(ctx::RequestInfo *request)
-{
- _I(CYAN("'%s' subscribes '%s' (RID-%d)"), request->getClient(), subject, request->getId());
-
- context_provider_iface *provider = get_provider(request);
- IF_FAIL_VOID(provider);
-
- ctx::Json request_result;
- int error = provider->subscribe(subject, request->getDescription().str(), &request_result);
-
- if (!request->reply(error, request_result) || error != ERR_NONE) {
- delete request;
- return;
- }
-
- subscribe_requests.push_back(request);
-}
-
-void ctx::context_provider_handler::unsubscribe(ctx::RequestInfo *request)
-{
- _I(CYAN("'%s' unsubscribes '%s' (RID-%d)"), request->getClient(), subject, request->getId());
-
- // Search the subscribe request to be removed
- auto target = find_request(subscribe_requests, request->getClient(), request->getId());
- if (target == subscribe_requests.end()) {
- _W("Unknown request");
- delete request;
- return;
- }
-
- // Keep the pointer to the request found
- RequestInfo *req_found = *target;
-
- // Remove the request from the list
- subscribe_requests.erase(target);
-
- // Check if there exist the same requests
- if (find_request(subscribe_requests, req_found->getDescription()) != subscribe_requests.end()) {
- // Do not stop detecting the subject
- _D("A same request from '%s' exists", req_found->getClient());
- request->reply(ERR_NONE);
- delete request;
- delete req_found;
- return;
- }
-
- // Get the provider
- context_provider_iface *provider = get_provider(request);
- IF_FAIL_VOID(provider);
-
- // Stop detecting the subject
- int error = provider->unsubscribe(subject, req_found->getDescription());
- request->reply(error);
- delete request;
- delete req_found;
-}
-
-void ctx::context_provider_handler::read(ctx::RequestInfo *request)
-{
- _I(CYAN("'%s' reads '%s' (RID-%d)"), request->getClient(), subject, request->getId());
-
- context_provider_iface *provider = get_provider(request);
- IF_FAIL_VOID(provider);
-
- ctx::Json request_result;
- int error = provider->read(subject, request->getDescription().str(), &request_result);
-
- if (!request->reply(error, request_result) || error != ERR_NONE) {
- delete request;
- return;
- }
-
- read_requests.push_back(request);
-}
-
-void ctx::context_provider_handler::write(ctx::RequestInfo *request)
-{
- _I(CYAN("'%s' writes '%s' (RID-%d)"), request->getClient(), subject, request->getId());
-
- context_provider_iface *provider = get_provider(request);
- IF_FAIL_VOID(provider);
-
- ctx::Json request_result;
- int error = provider->write(subject, request->getDescription(), &request_result);
-
- request->reply(error, request_result);
- delete request;
-}
-
-bool ctx::context_provider_handler::publish(ctx::Json &option, int error, ctx::Json &data_updated)
-{
- auto end = subscribe_requests.end();
- auto target = find_request(subscribe_requests.begin(), end, option);
-
- while (target != end) {
- if (!(*target)->publish(error, data_updated)) {
- return false;
- }
- target = find_request(++target, end, option);
- }
-
- return true;
-}
-
-bool ctx::context_provider_handler::reply_to_read(ctx::Json &option, int error, ctx::Json &data_read)
-{
- auto end = read_requests.end();
- auto target = find_request(read_requests.begin(), end, option);
- auto prev = target;
-
- ctx::Json dummy;
-
- while (target != end) {
- (*target)->reply(error, dummy, data_read);
- prev = target;
- target = find_request(++target, end, option);
-
- delete *prev;
- read_requests.erase(prev);
- }
-
- return true;
-}
-
-ctx::context_provider_handler::request_list_t::iterator
-ctx::context_provider_handler::find_request(request_list_t &r_list, Json &option)
-{
- return find_request(r_list.begin(), r_list.end(), option);
-}
-
-ctx::context_provider_handler::request_list_t::iterator
-ctx::context_provider_handler::find_request(request_list_t &r_list, std::string client, int req_id)
-{
- for (auto it = r_list.begin(); it != r_list.end(); ++it) {
- if (client == (*it)->getClient() && req_id == (*it)->getId()) {
- return it;
- }
- }
- return r_list.end();
-}
-
-ctx::context_provider_handler::request_list_t::iterator
-ctx::context_provider_handler::find_request(request_list_t::iterator begin, request_list_t::iterator end, Json &option)
-{
- for (auto it = begin; it != end; ++it) {
- if (option == (*it)->getDescription()) {
- return it;
- }
- }
- return end;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 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_PROVIDER_HANDLER_H__
-#define __CONTEXT_PROVIDER_HANDLER_H__
-
-#include <string>
-#include <list>
-#include <provider_iface.h>
-
-namespace ctx {
-
- class Json;
- class Credentials;
- class RequestInfo;
-
- class context_provider_handler {
- public:
- typedef std::list<RequestInfo*> request_list_t;
-
- context_provider_handler(const char *subj, context_provider_info &prvd);
- ~context_provider_handler();
-
- bool is_allowed(const Credentials *creds);
-
- void subscribe(RequestInfo *request);
- void unsubscribe(RequestInfo *request);
- void read(RequestInfo *request);
- void write(RequestInfo *request);
-
- bool publish(ctx::Json &option, int error, ctx::Json &data_updated);
- bool reply_to_read(ctx::Json &option, int error, ctx::Json &data_read);
-
- private:
- const char *subject;
- context_provider_info provider_info;
- request_list_t subscribe_requests;
- request_list_t read_requests;
-
- context_provider_iface* get_provider(RequestInfo *request);
- request_list_t::iterator find_request(request_list_t &r_list, Json &option);
- request_list_t::iterator find_request(request_list_t &r_list, std::string client, int req_id);
- request_list_t::iterator find_request(request_list_t::iterator begin, request_list_t::iterator end, Json &option);
-
- }; /* class context_provider_handler */
-
-} /* namespace ctx */
-
-#endif /* __CONTEXT_PROVIDER_HANDLER_H__ */
#include <types_internal.h>
#include "DBusServer.h"
#include "db_mgr_impl.h"
-#include "context_mgr_impl.h"
+#include "ContextManagerImpl.h"
#include "trigger/Trigger.h"
#include "server.h"
static GMainLoop *mainloop = NULL;
static bool started = false;
-static ctx::context_manager_impl *context_mgr = NULL;
+static ctx::ContextManagerImpl *context_mgr = NULL;
static ctx::db_manager_impl *database_mgr = NULL;
static ctx::DBusServer *dbus_handle = NULL;
static ctx::trigger::Trigger *context_trigger = NULL;
IF_FAIL_CATCH_TAG(result, _E, "Initialization Failed");
_I("Init Context Manager");
- context_mgr = new(std::nothrow) ctx::context_manager_impl();
+ context_mgr = new(std::nothrow) ctx::ContextManagerImpl();
IF_FAIL_CATCH_TAG(context_mgr, _E, "Memory allocation failed");
- context_manager::set_instance(context_mgr);
+ context_manager::setInstance(context_mgr);
result = context_mgr->init();
IF_FAIL_CATCH_TAG(result, _E, "Initialization Failed");
}
if (!context_trigger->assignRequest(request)) {
- context_mgr->assign_request(request);
+ context_mgr->assignRequest(request);
}
}
#include <types_internal.h>
#include "../access_control/Privilege.h"
-#include "../context_mgr_impl.h"
+#include "../ContextManagerImpl.h"
#include "ContextMonitor.h"
#include "IContextListener.h"
#include "FactRequest.h"
static int __lastErr;
ContextMonitor *ContextMonitor::__instance = NULL;
-context_manager_impl *ContextMonitor::__contextMgr = NULL;
+ContextManagerImpl *ContextMonitor::__contextMgr = NULL;
static int __generateReqId()
{
{
}
-void ContextMonitor::setContextManager(context_manager_impl* ctx_mgr)
+void ContextMonitor::setContextManager(ContextManagerImpl* ctx_mgr)
{
__contextMgr = ctx_mgr;
}
rid, subject, option ? option->str().c_str() : NULL, this);
IF_FAIL_RETURN_TAG(req, ERR_OUT_OF_MEMORY, _E, "Memory allocation failed");
- __contextMgr->assign_request(req);
+ __contextMgr->assignRequest(req);
__addSub(REQ_SUBSCRIBE, rid, subject, option, listener);
if (__lastErr != ERR_NONE) {
FactRequest *req = new(std::nothrow) FactRequest(REQ_UNSUBSCRIBE, subscriptionId, subject, NULL, NULL);
IF_FAIL_VOID_TAG(req, _E, "Memory allocation failed");
- __contextMgr->assign_request(req);
+ __contextMgr->assignRequest(req);
__removeSub(REQ_SUBSCRIBE, subscriptionId);
}
rid, subject, option ? option->str().c_str() : NULL, this);
IF_FAIL_RETURN_TAG(req, -1, _E, "Memory allocation failed");
- __contextMgr->assign_request(req);
+ __contextMgr->assignRequest(req);
__addSub(REQ_READ, rid, subject, option, listener);
if (__lastErr != ERR_NONE) {
bool ContextMonitor::isSupported(std::string subject)
{
- return __contextMgr->is_supported(subject.c_str());
+ return __contextMgr->isSupported(subject.c_str());
}
bool ContextMonitor::isAllowed(const char *client, const char *subject)
namespace ctx {
- class context_manager_impl;
+ class ContextManagerImpl;
namespace trigger {
class ContextMonitor {
public:
static ContextMonitor* getInstance();
- static void setContextManager(context_manager_impl* ctx_mgr);
+ static void setContextManager(ContextManagerImpl* ctx_mgr);
static void destroy();
int subscribe(int ruleId, std::string subject, Json option, IContextListener* listener);
~ContextMonitor();
static ContextMonitor *__instance;
- static context_manager_impl *__contextMgr;
+ static ContextManagerImpl *__contextMgr;
int __subscribe(const char* subject, Json* option, IContextListener* listener);
void __unsubscribe(const char *subject, int subscriptionId);
#include <types_internal.h>
#include <context_trigger_types_internal.h>
#include <db_mgr.h>
-#include "../context_mgr_impl.h"
+#include "../ContextManagerImpl.h"
#include "RuleManager.h"
#include "TemplateManager.h"
using namespace ctx::trigger;
TemplateManager *TemplateManager::__instance = NULL;
-context_manager_impl *TemplateManager::__contextMgr = NULL;
+ContextManagerImpl *TemplateManager::__contextMgr = NULL;
RuleManager *TemplateManager::__ruleMgr = NULL;
static std::string __intToString(int i)
{
}
-void TemplateManager::setManager(context_manager_impl* ctxMgr, RuleManager* ruleMgr)
+void TemplateManager::setManager(ContextManagerImpl* ctxMgr, RuleManager* ruleMgr)
{
__contextMgr = ctxMgr;
__ruleMgr = ruleMgr;
std::string query;
query.clear();
- while(__contextMgr->pop_trigger_item(subject, operation, attributes, options, owner, unregister)) {
+ while(__contextMgr->popTriggerItem(subject, operation, attributes, options, owner, unregister)) {
if (unregister) {
unregisterTemplate(subject);
} else {
namespace ctx {
- class context_manager_impl;
+ class ContextManagerImpl;
namespace trigger {
class TemplateManager {
public:
static TemplateManager* getInstance();
- static void setManager(context_manager_impl* ctxMgr, RuleManager* ruleMgr);
+ static void setManager(ContextManagerImpl* ctxMgr, RuleManager* ruleMgr);
static void destroy();
bool init();
~TemplateManager();
static TemplateManager *__instance;
- static context_manager_impl *__contextMgr;
+ static ContextManagerImpl *__contextMgr;
static RuleManager *__ruleMgr;
std::string __addTemplate(std::string &subject, int &operation, Json &attributes, Json &options, std::string &owner);
{
}
-bool Trigger::init(context_manager_impl* ctxMgr)
+bool Trigger::init(ContextManagerImpl* ctxMgr)
{
// Do the necessary initialization process.
// This function is called from the main thread during the service launching process.
}
}
-void Trigger::__processInitialize(context_manager_impl* mgr)
+void Trigger::__processInitialize(ContextManagerImpl* mgr)
{
// Context Monitor
ContextMonitor::setContextManager(mgr);
namespace ctx {
class client_request;
- class context_manager_impl;
+ class ContextManagerImpl;
namespace trigger {
Trigger();
~Trigger();
- bool init(context_manager_impl* ctxMgr);
+ bool init(ContextManagerImpl* ctxMgr);
void release();
bool assignRequest(RequestInfo* request);
private:
void __processRequest(RequestInfo* request);
- void __processInitialize(context_manager_impl* mgr);
+ void __processInitialize(ContextManagerImpl* mgr);
void __addRule(RequestInfo* request);
void __removeRule(RequestInfo* request);