Remove the lazy creation routine for context providers 66/66266/5
authorMu-Woong Lee <muwoong.lee@samsung.com>
Mon, 18 Apr 2016 06:25:28 +0000 (15:25 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Tue, 19 Apr 2016 05:51:45 +0000 (14:51 +0900)
Change-Id: Ie8bc5c7ddb1832a86e2db4c9eec1eb3f1fda6fa1
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
13 files changed:
CMakeLists.txt
packaging/context-service.spec
src/ContextManager.cpp [moved from src/ContextManagerImpl.cpp with 70% similarity]
src/ContextManager.h [moved from src/ContextManagerImpl.h with 82% similarity]
src/ProviderHandler.cpp
src/ProviderHandler.h
src/Server.cpp
src/trigger/ContextMonitor.cpp
src/trigger/ContextMonitor.h
src/trigger/TemplateManager.cpp
src/trigger/TemplateManager.h
src/trigger/Trigger.cpp
src/trigger/Trigger.h

index 032be8b..1513748 100644 (file)
@@ -13,7 +13,10 @@ MESSAGE("Sources: ${SRCS}")
 SET(DEPS
        vconf
        capi-system-info
+       capi-system-device
+       capi-system-runtime-info
        capi-appfw-app-manager
+       capi-appfw-package-manager
        appsvc
        notification
        capi-system-system-settings
index e314866..a8af397 100644 (file)
@@ -12,7 +12,10 @@ BuildRequires: cmake
 BuildRequires: sed
 BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-system-device)
+BuildRequires: pkgconfig(capi-system-runtime-info)
 BuildRequires: pkgconfig(capi-appfw-app-manager)
+BuildRequires: pkgconfig(capi-appfw-package-manager)
 BuildRequires: pkgconfig(appsvc)
 BuildRequires: pkgconfig(notification)
 BuildRequires: pkgconfig(capi-system-system-settings)
similarity index 70%
rename from src/ContextManagerImpl.cpp
rename to src/ContextManager.cpp
index 00f27d3..119fcff 100644 (file)
 #include <DBusTypes.h>
 #include <context_trigger_types_internal.h>
 #include <Json.h>
+#include <ContextProvider.h>
 #include "Server.h"
 #include "access_control/Privilege.h"
 #include "Request.h"
 #include "ProviderHandler.h"
-#include "ContextManagerImpl.h"
+#include "ContextManager.h"
 #include "trigger/TemplateManager.h"
 
 /* Context Providers */
 #include <internal/PlaceContextProvider.h>
 #include <internal/CustomContextProvider.h>
 
+using namespace ctx;
+
 struct TriggerItemFormat {
        std::string subject;
        int operation;
-       ctx::Json attributes;
-       ctx::Json options;
+       Json attributes;
+       Json options;
        std::string owner;
        bool unregister;
-       TriggerItemFormat(std::string subj, int ops, ctx::Json attr, ctx::Json opt, std::string own) :
+       TriggerItemFormat(std::string subj, int ops, Json attr, Json opt, std::string own) :
                subject(subj),
                operation(ops),
                attributes(attr),
@@ -59,18 +62,19 @@ struct TriggerItemFormat {
 };
 
 static std::list<TriggerItemFormat> __triggerItemList;
-bool ctx::ContextManagerImpl::__initialized = false;
 
-ctx::ContextManagerImpl::ContextManagerImpl()
+ContextManager::ContextManager() :
+       __initialized(false)
 {
+       ContextProvider::__setContextManager(this);
 }
 
-ctx::ContextManagerImpl::~ContextManagerImpl()
+ContextManager::~ContextManager()
 {
        release();
 }
 
-bool ctx::ContextManagerImpl::init()
+bool ContextManager::init()
 {
        bool ret;
 
@@ -83,46 +87,38 @@ bool ctx::ContextManagerImpl::init()
        ret = initPlaceContextProvider();
        IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: PlaceContextProvider");
 
-       ret = initCustomContextProvider();
-       IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: CustomContextProvider");
+//     ret = initCustomContextProvider();
+//     IF_FAIL_RETURN_TAG(ret, false, _E, "Initialization failed: CustomContextProvider");
 
        __initialized = true;
-
        return true;
 }
 
-void ctx::ContextManagerImpl::release()
+void ContextManager::release()
 {
-       for (auto it = __providerHandleMap.begin(); it != __providerHandleMap.end(); ++it) {
-               delete it->second;
+       for (auto& it : __providerHandleMap) {
+               delete it.second;
        }
        __providerHandleMap.clear();
 }
 
-bool ctx::ContextManagerImpl::registerProvider(const char *subject, ctx::ContextProviderInfo &providerInfo)
+bool ContextManager::registerProvider(const char *subject, const char *privilege, ContextProvider *provider)
 {
        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);
+       _SI("Subj: %s, Priv: %s", subject, privilege);
 
-       if (!handle) {
-               _E("Memory allocation failed");
-               __providerHandleMap.erase(it);
-               return false;
-       }
+       ProviderHandler *handle = new(std::nothrow) ProviderHandler(subject, privilege, provider);
+       IF_FAIL_RETURN_TAG(handle, false, _E, "Memory allocation failed");
 
-       it->second = handle;
+       __providerHandleMap[subject] = handle;
        return true;
 }
 
-bool ctx::ContextManagerImpl::unregisterProvider(const char *subject)
+bool ContextManager::unregisterProvider(const char *subject)
 {
        auto it = __providerHandleMap.find(subject);
        if (it == __providerHandleMap.end()) {
@@ -136,14 +132,14 @@ bool ctx::ContextManagerImpl::unregisterProvider(const char *subject)
        return true;
 }
 
-bool ctx::ContextManagerImpl::registerTriggerItem(const char *subject, int operation, ctx::Json attributes, ctx::Json options, const char* owner)
+bool ContextManager::registerTriggerItem(const char *subject, int operation, Json attributes, 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();
+               trigger::TemplateManager* tmplMgr = trigger::TemplateManager::getInstance();
                IF_FAIL_RETURN_TAG(tmplMgr, false, _E, "Memory allocation failed");
                tmplMgr->registerTemplate(subject, operation, attributes, options, owner);
        }
@@ -151,14 +147,14 @@ bool ctx::ContextManagerImpl::registerTriggerItem(const char *subject, int opera
        return true;
 }
 
-bool ctx::ContextManagerImpl::unregisterTriggerItem(const char *subject)
+bool ContextManager::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();
+               trigger::TemplateManager* tmplMgr = trigger::TemplateManager::getInstance();
                IF_FAIL_RETURN_TAG(tmplMgr, false, _E, "Memory allocation failed");
                tmplMgr->unregisterTemplate(subject);
        }
@@ -166,7 +162,7 @@ bool ctx::ContextManagerImpl::unregisterTriggerItem(const char *subject)
        return true;
 }
 
-bool ctx::ContextManagerImpl::popTriggerItem(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string& owner, bool& unregister)
+bool ContextManager::popTriggerItem(std::string &subject, int &operation, Json &attributes, Json &options, std::string& owner, bool& unregister)
 {
        IF_FAIL_RETURN(!__triggerItemList.empty(), false);
 
@@ -183,7 +179,7 @@ bool ctx::ContextManagerImpl::popTriggerItem(std::string &subject, int &operatio
        return true;
 }
 
-void ctx::ContextManagerImpl::assignRequest(ctx::RequestInfo* request)
+void ContextManager::assignRequest(RequestInfo* request)
 {
        if (__handleCustomRequest(request)) {
                delete request;
@@ -229,13 +225,13 @@ void ctx::ContextManagerImpl::assignRequest(ctx::RequestInfo* request)
        }
 }
 
-bool ctx::ContextManagerImpl::isSupported(const char *subject)
+bool ContextManager::isSupported(const char *subject)
 {
        auto it = __providerHandleMap.find(subject);
        return (it != __providerHandleMap.end());
 }
 
-bool ctx::ContextManagerImpl::isAllowed(const ctx::Credentials *creds, const char *subject)
+bool ContextManager::isAllowed(const Credentials *creds, const char *subject)
 {
        IF_FAIL_RETURN(creds, true);    /* In case internal requests */
        auto it = __providerHandleMap.find(subject);
@@ -243,7 +239,7 @@ bool ctx::ContextManagerImpl::isAllowed(const ctx::Credentials *creds, const cha
        return it->second->isAllowed(creds);
 }
 
-void ctx::ContextManagerImpl::__publish(const char* subject, ctx::Json &option, int error, ctx::Json &dataUpdated)
+void ContextManager::__publish(const char* subject, Json &option, int error, Json &dataUpdated)
 {
        _I("Publishing '%s'", subject);
        _J("Option", option);
@@ -254,7 +250,7 @@ void ctx::ContextManagerImpl::__publish(const char* subject, ctx::Json &option,
        it->second->publish(option, error, dataUpdated);
 }
 
-void ctx::ContextManagerImpl::__replyToRead(const char* subject, ctx::Json &option, int error, ctx::Json &dataRead)
+void ContextManager::__replyToRead(const char* subject, Json &option, int error, Json &dataRead)
 {
        _I("Sending data of '%s'", subject);
        _J("Option", option);
@@ -268,12 +264,12 @@ void ctx::ContextManagerImpl::__replyToRead(const char* subject, ctx::Json &opti
 
 struct PublishedData {
        int type;
-       ctx::ContextManagerImpl *mgr;
+       ContextManager *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)
+       Json option;
+       Json data;
+       PublishedData(int t, ContextManager *m, const char* s, Json& o, int e, Json& d)
                : type(t), mgr(m), subject(s), error(e)
        {
                option = o.str();
@@ -281,7 +277,7 @@ struct PublishedData {
        }
 };
 
-gboolean ctx::ContextManagerImpl::__threadSwitcher(gpointer data)
+gboolean ContextManager::__threadSwitcher(gpointer data)
 {
        PublishedData *tuple = static_cast<PublishedData*>(data);
 
@@ -300,7 +296,7 @@ gboolean ctx::ContextManagerImpl::__threadSwitcher(gpointer data)
        return FALSE;
 }
 
-bool ctx::ContextManagerImpl::publish(const char* subject, ctx::Json& option, int error, ctx::Json& dataUpdated)
+bool ContextManager::publish(const char* subject, Json& option, int error, Json& dataUpdated)
 {
        IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
 
@@ -312,7 +308,7 @@ bool ctx::ContextManagerImpl::publish(const char* subject, ctx::Json& option, in
        return true;
 }
 
-bool ctx::ContextManagerImpl::replyToRead(const char* subject, ctx::Json& option, int error, ctx::Json& dataRead)
+bool ContextManager::replyToRead(const char* subject, Json& option, int error, Json& dataRead)
 {
        IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
 
@@ -324,44 +320,46 @@ bool ctx::ContextManagerImpl::replyToRead(const char* subject, ctx::Json& option
        return true;
 }
 
-bool ctx::ContextManagerImpl::__handleCustomRequest(ctx::RequestInfo* request)
+bool ContextManager::__handleCustomRequest(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);
 
+#if 0
        const char* pkg_id = request->getPackageId();
        if (pkg_id == NULL) {
                request->reply(ERR_OPERATION_FAILED);
                return true;
        }
 
-       ctx::Json desc = request->getDescription();
+       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;
+               Json tmpl;
                desc.get(NULL, CT_CUSTOM_ATTRIBUTES, &tmpl);
 
-               error = ctx::custom_context_provider::addItem(subj, name, tmpl, pkg_id);
+               error = custom_context_provider::addItem(subj, name, tmpl, pkg_id);
        } else if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE) {
-               error = ctx::custom_context_provider::removeItem(subj);
+               error = custom_context_provider::removeItem(subj);
                if (error == ERR_NONE) {
-                       ctx::Json data;
+                       Json data;
                        data.set(NULL, CT_CUSTOM_SUBJECT, subj);
                        request->reply(error, data);
                }
        } else if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_PUBLISH) {
-               ctx::Json fact;
+               Json fact;
                desc.get(NULL, CT_CUSTOM_FACT, &fact);
 
-               error = ctx::custom_context_provider::publishData(subj, fact);
+               error = custom_context_provider::publishData(subj, fact);
        }
 
        request->reply(error);
+#endif
        return true;
 }
similarity index 82%
rename from src/ContextManagerImpl.h
rename to src/ContextManager.h
index ab4b377..e2518bc 100644 (file)
  * limitations under the License.
  */
 
-#ifndef _CONTEXT_MANAGER_IMPL_H_
-#define _CONTEXT_MANAGER_IMPL_H_
+#ifndef _CONTEXT_CONTEXT_MANAGER_H_
+#define _CONTEXT_CONTEXT_MANAGER_H_
 
-#include <string>
 #include <map>
-#include <glib.h>
-#include <ContextManager.h>
 #include <IContextManager.h>
 
 namespace ctx {
@@ -30,10 +27,9 @@ namespace ctx {
        class RequestInfo;
        class ProviderHandler;
 
-       class ContextManagerImpl : public IContextManager {
+       class ContextManager : public IContextManager {
        public:
-               ContextManagerImpl();
-               ~ContextManagerImpl();
+               ~ContextManager();
 
                bool init();
                void release();
@@ -44,7 +40,7 @@ namespace ctx {
                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 registerProvider(const char *subject, const char *privilege, ContextProvider *provider);
                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);
@@ -52,17 +48,23 @@ namespace ctx {
                bool replyToRead(const char *subject, ctx::Json &option, int error, ctx::Json &dataRead);
 
        private:
-               std::map<std::string, ProviderHandler*> __providerHandleMap;
-               static bool __initialized;
+               ContextManager();
 
                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 */
+
+               bool __initialized;
+               std::map<std::string, ProviderHandler*> __providerHandleMap;
+
+               friend class Server;
+
+       };      /* class ContextManager */
 
 }      /* namespace ctx */
 
-#endif /* End of __CONTEXT_MANAGER_IMPL_H__ */
+#endif /* _CONTEXT_CONTEXT_MANAGER_H_ */
index fd92e62..8742495 100644 (file)
 
 #include <glib.h>
 #include <Types.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)
+using namespace ctx;
+
+ProviderHandler::ProviderHandler(const char *subject, const char *privilege, ContextProvider *provider) :
+       __subject(subject),
+       __privilege(privilege),
+       __provider(provider)
 {
 }
 
-ctx::ProviderHandler::~ProviderHandler()
+ProviderHandler::~ProviderHandler()
 {
-       for (auto it = __subscribeRequests.begin(); it != __subscribeRequests.end(); ++it) {
-               delete *it;
+       for (RequestInfo*& info : __subscribeRequests) {
+               delete info;
        }
        __subscribeRequests.clear();
 
-       for (auto it = __readRequests.begin(); it != __readRequests.end(); ++it) {
-               delete *it;
+       for (RequestInfo*& info : __readRequests) {
+               delete info;
        }
        __readRequests.clear();
 
-       __providerInfo.destroy(__providerInfo.data);
+       delete __provider;
 }
 
-bool ctx::ProviderHandler::isAllowed(const ctx::Credentials *creds)
+bool ProviderHandler::isAllowed(const Credentials *creds)
 {
        IF_FAIL_RETURN(creds, true);    /* In case of internal requests */
-       return privilege_manager::isAllowed(creds, __providerInfo.privilege);
+       return privilege_manager::isAllowed(creds, __privilege);
 }
 
-ctx::ContextProviderBase* ctx::ProviderHandler::__getProvider(ctx::RequestInfo *request)
+ContextProvider* ProviderHandler::__getProvider(RequestInfo *request)
 {
-       ContextProviderBase *provider = __providerInfo.create(__providerInfo.data);
-       if (!provider) {
-               _E("Memory allocation failed");
-               delete request;
-               return NULL;
-       }
-
-       return provider;
+       /* TODO: When implementing dynamic so loading... */
+       return __provider;
 }
 
-void ctx::ProviderHandler::subscribe(ctx::RequestInfo *request)
+void ProviderHandler::subscribe(RequestInfo *request)
 {
        _I(CYAN("'%s' subscribes '%s' (RID-%d)"), request->getClient(), __subject, request->getId());
 
-       ContextProviderBase *provider = __getProvider(request);
+       ContextProvider *provider = __getProvider(request);
        IF_FAIL_VOID(provider);
 
-       ctx::Json requestResult;
-       int error = provider->subscribe(__subject, request->getDescription().str(), &requestResult);
+       Json requestResult;
+       int error = provider->subscribe(request->getDescription().str(), &requestResult);
 
        if (!request->reply(error, requestResult) || error != ERR_NONE) {
                delete request;
@@ -79,11 +74,11 @@ void ctx::ProviderHandler::subscribe(ctx::RequestInfo *request)
        __subscribeRequests.push_back(request);
 }
 
-void ctx::ProviderHandler::unsubscribe(ctx::RequestInfo *request)
+void ProviderHandler::unsubscribe(RequestInfo *request)
 {
        _I(CYAN("'%s' unsubscribes '%s' (RID-%d)"), request->getClient(), __subject, request->getId());
 
-       // Search the subscribe request to be removed
+       /* Search the subscribe request to be removed */
        auto target = __findRequest(__subscribeRequests, request->getClient(), request->getId());
        if (target == __subscribeRequests.end()) {
                _W("Unknown request");
@@ -91,42 +86,42 @@ void ctx::ProviderHandler::unsubscribe(ctx::RequestInfo *request)
                return;
        }
 
-       // Keep the pointer to the request found
-       RequestInfo *req_found = *target;
+       /* Keep the pointer to the request found */
+       RequestInfo *reqFound = *target;
 
-       // Remove the request from the list
+       /* 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());
+       /* Check if there exist the same requests */
+       if (__findRequest(__subscribeRequests, reqFound->getDescription()) != __subscribeRequests.end()) {
+               /* Do not stop detecting the subject */
+               _D("A same request from '%s' exists", reqFound->getClient());
                request->reply(ERR_NONE);
                delete request;
-               delete req_found;
+               delete reqFound;
                return;
        }
 
-       // Get the provider
-       ContextProviderBase *provider = __getProvider(request);
+       /* Get the provider */
+       ContextProvider *provider = __getProvider(request);
        IF_FAIL_VOID(provider);
 
-       // Stop detecting the subject
-       int error = provider->unsubscribe(__subject, req_found->getDescription());
+       /* Stop detecting the subject */
+       int error = provider->unsubscribe(reqFound->getDescription());
        request->reply(error);
        delete request;
-       delete req_found;
+       delete reqFound;
 }
 
-void ctx::ProviderHandler::read(ctx::RequestInfo *request)
+void ProviderHandler::read(RequestInfo *request)
 {
        _I(CYAN("'%s' reads '%s' (RID-%d)"), request->getClient(), __subject, request->getId());
 
-       ContextProviderBase *provider = __getProvider(request);
+       ContextProvider *provider = __getProvider(request);
        IF_FAIL_VOID(provider);
 
-       ctx::Json requestResult;
-       int error = provider->read(__subject, request->getDescription().str(), &requestResult);
+       Json requestResult;
+       int error = provider->read(request->getDescription().str(), &requestResult);
 
        if (!request->reply(error, requestResult) || error != ERR_NONE) {
                delete request;
@@ -136,21 +131,21 @@ void ctx::ProviderHandler::read(ctx::RequestInfo *request)
        __readRequests.push_back(request);
 }
 
-void ctx::ProviderHandler::write(ctx::RequestInfo *request)
+void ProviderHandler::write(RequestInfo *request)
 {
        _I(CYAN("'%s' writes '%s' (RID-%d)"), request->getClient(), __subject, request->getId());
 
-       ContextProviderBase *provider = __getProvider(request);
+       ContextProvider *provider = __getProvider(request);
        IF_FAIL_VOID(provider);
 
-       ctx::Json requestResult;
-       int error = provider->write(__subject, request->getDescription(), &requestResult);
+       Json requestResult;
+       int error = provider->write(request->getDescription(), &requestResult);
 
        request->reply(error, requestResult);
        delete request;
 }
 
-bool ctx::ProviderHandler::publish(ctx::Json &option, int error, ctx::Json &dataUpdated)
+bool ProviderHandler::publish(Json &option, int error, Json &dataUpdated)
 {
        auto end = __subscribeRequests.end();
        auto target = __findRequest(__subscribeRequests.begin(), end, option);
@@ -165,13 +160,13 @@ bool ctx::ProviderHandler::publish(ctx::Json &option, int error, ctx::Json &data
        return true;
 }
 
-bool ctx::ProviderHandler::replyToRead(ctx::Json &option, int error, ctx::Json &dataRead)
+bool ProviderHandler::replyToRead(Json &option, int error, Json &dataRead)
 {
        auto end = __readRequests.end();
        auto target = __findRequest(__readRequests.begin(), end, option);
        auto prev = target;
 
-       ctx::Json dummy;
+       Json dummy;
 
        while (target != end) {
                (*target)->reply(error, dummy, dataRead);
@@ -185,14 +180,14 @@ bool ctx::ProviderHandler::replyToRead(ctx::Json &option, int error, ctx::Json &
        return true;
 }
 
-ctx::ProviderHandler::RequestList::iterator
-ctx::ProviderHandler::__findRequest(RequestList &reqList, Json &option)
+ProviderHandler::RequestList::iterator
+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)
+ProviderHandler::RequestList::iterator
+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()) {
@@ -202,8 +197,8 @@ ctx::ProviderHandler::__findRequest(RequestList &reqList, std::string client, in
        return reqList.end();
 }
 
-ctx::ProviderHandler::RequestList::iterator
-ctx::ProviderHandler::__findRequest(RequestList::iterator begin, RequestList::iterator end, Json &option)
+ProviderHandler::RequestList::iterator
+ProviderHandler::__findRequest(RequestList::iterator begin, RequestList::iterator end, Json &option)
 {
        for (auto it = begin; it != end; ++it) {
                if (option == (*it)->getDescription()) {
index d2524bc..d8cea26 100644 (file)
 
 #include <string>
 #include <list>
-#include <ContextProviderBase.h>
+#include <ContextProvider.h>
 
 namespace ctx {
 
-       class Json;
        class Credentials;
        class RequestInfo;
 
@@ -31,7 +30,7 @@ namespace ctx {
        public:
                typedef std::list<RequestInfo*> RequestList;
 
-               ProviderHandler(const char *subj, ContextProviderInfo &prvd);
+               ProviderHandler(const char *subject, const char *privilege, ContextProvider *provider);
                ~ProviderHandler();
 
                bool isAllowed(const Credentials *creds);
@@ -46,11 +45,12 @@ namespace ctx {
 
        private:
                const char *__subject;
-               ContextProviderInfo __providerInfo;
+               const char *__privilege;
+               ContextProvider *__provider;
                RequestList __subscribeRequests;
                RequestList __readRequests;
 
-               ContextProviderBase* __getProvider(RequestInfo *request);
+               ContextProvider* __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);
index 879d294..2617a4f 100644 (file)
 
 #include <Types.h>
 #include "DBusServer.h"
-#include "ContextManagerImpl.h"
+#include "ContextManager.h"
 #include "trigger/Trigger.h"
 #include "Server.h"
 
 static GMainLoop *mainloop = NULL;
 static bool started = false;
 
-static ctx::ContextManagerImpl *__contextMgr = NULL;
+static ctx::ContextManager *__contextMgr = NULL;
 static ctx::DBusServer *__dbusHandle = NULL;
 static ctx::trigger::Trigger *__contextTrigger = NULL;
 
@@ -55,9 +55,8 @@ void ctx::Server::activate()
        bool result = false;
 
        _I("Init Context Manager");
-       __contextMgr = new(std::nothrow) ctx::ContextManagerImpl();
+       __contextMgr = new(std::nothrow) ctx::ContextManager();
        IF_FAIL_CATCH_TAG(__contextMgr, _E, "Memory allocation failed");
-       context_manager::setInstance(__contextMgr);
        result = __contextMgr->init();
        IF_FAIL_CATCH_TAG(result, _E, "Initialization Failed");
 
index 386eaa4..56f5eed 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <Types.h>
 #include "../access_control/Privilege.h"
-#include "../ContextManagerImpl.h"
+#include "../ContextManager.h"
 #include "ContextMonitor.h"
 #include "IContextListener.h"
 #include "FactRequest.h"
@@ -28,7 +28,7 @@ static int __lastRid;
 static int __lastErr;
 
 ContextMonitor *ContextMonitor::__instance = NULL;
-ContextManagerImpl *ContextMonitor::__contextMgr = NULL;
+ContextManager *ContextMonitor::__contextMgr = NULL;
 
 static int __generateReqId()
 {
@@ -50,7 +50,7 @@ ContextMonitor::~ContextMonitor()
 {
 }
 
-void ContextMonitor::setContextManager(ContextManagerImpl* ctx_mgr)
+void ContextMonitor::setContextManager(ContextManager* ctx_mgr)
 {
        __contextMgr = ctx_mgr;
 }
index a681d69..d3c6966 100644 (file)
@@ -24,7 +24,7 @@
 
 namespace ctx {
 
-       class ContextManagerImpl;
+       class ContextManager;
 
 namespace trigger {
 
@@ -34,7 +34,7 @@ namespace trigger {
        class ContextMonitor {
        public:
                static ContextMonitor* getInstance();
-               static void setContextManager(ContextManagerImpl* ctx_mgr);
+               static void setContextManager(ContextManager* ctx_mgr);
                static void destroy();
 
                int subscribe(int ruleId, std::string subject, Json option, IContextListener* listener);
@@ -53,7 +53,7 @@ namespace trigger {
                ~ContextMonitor();
 
                static ContextMonitor *__instance;
-               static ContextManagerImpl *__contextMgr;
+               static ContextManager *__contextMgr;
 
                int __subscribe(const char* subject, Json* option, IContextListener* listener);
                void __unsubscribe(const char *subject, int subscriptionId);
index 1761650..51dcb6c 100644 (file)
@@ -17,7 +17,7 @@
 #include <sstream>
 #include <Types.h>
 #include <context_trigger_types_internal.h>
-#include "../ContextManagerImpl.h"
+#include "../ContextManager.h"
 #include "RuleManager.h"
 #include "TemplateManager.h"
 
@@ -25,7 +25,7 @@ using namespace ctx;
 using namespace ctx::trigger;
 
 TemplateManager *TemplateManager::__instance = NULL;
-ContextManagerImpl *TemplateManager::__contextMgr = NULL;
+ContextManager *TemplateManager::__contextMgr = NULL;
 RuleManager *TemplateManager::__ruleMgr = NULL;
 
 static std::string __intToString(int i)
@@ -44,7 +44,7 @@ TemplateManager::~TemplateManager()
 {
 }
 
-void TemplateManager::setManager(ContextManagerImpl* ctxMgr, RuleManager* ruleMgr)
+void TemplateManager::setManager(ContextManager* ctxMgr, RuleManager* ruleMgr)
 {
        __contextMgr = ctxMgr;
        __ruleMgr = ruleMgr;
index 22d1b32..c91ef15 100644 (file)
@@ -22,7 +22,7 @@
 
 namespace ctx {
 
-       class ContextManagerImpl;
+       class ContextManager;
 
 namespace trigger {
 
@@ -31,7 +31,7 @@ namespace trigger {
        class TemplateManager {
        public:
                static TemplateManager* getInstance();
-               static void setManager(ContextManagerImpl* ctxMgr, RuleManager* ruleMgr);
+               static void setManager(ContextManager* ctxMgr, RuleManager* ruleMgr);
                static void destroy();
 
                bool init();
@@ -46,7 +46,7 @@ namespace trigger {
                ~TemplateManager();
 
                static TemplateManager *__instance;
-               static ContextManagerImpl *__contextMgr;
+               static ContextManager *__contextMgr;
                static RuleManager *__ruleMgr;
 
                DatabaseManager __dbManager;
index 7cfdbe2..ac56d3c 100644 (file)
@@ -33,7 +33,7 @@ Trigger::~Trigger()
 {
 }
 
-bool Trigger::init(ContextManagerImpl* ctxMgr)
+bool Trigger::init(ContextManager* ctxMgr)
 {
        // Do the necessary initialization process.
        // This function is called from the main thread during the service launching process.
@@ -99,7 +99,7 @@ void Trigger::__processRequest(RequestInfo* request)
        }
 }
 
-void Trigger::__processInitialize(ContextManagerImpl* mgr)
+void Trigger::__processInitialize(ContextManager* mgr)
 {
        // Context Monitor
        ContextMonitor::setContextManager(mgr);
index 984c9bd..161c99e 100644 (file)
@@ -22,7 +22,7 @@
 namespace ctx {
 
        class client_request;
-       class ContextManagerImpl;
+       class ContextManager;
 
 namespace trigger {
 
@@ -33,14 +33,14 @@ namespace trigger {
                        Trigger();
                        ~Trigger();
 
-                       bool init(ContextManagerImpl* ctxMgr);
+                       bool init(ContextManager* ctxMgr);
                        void release();
 
                        bool assignRequest(RequestInfo* request);
 
                private:
                        void __processRequest(RequestInfo* request);
-                       void __processInitialize(ContextManagerImpl* mgr);
+                       void __processInitialize(ContextManager* mgr);
 
                        void __addRule(RequestInfo* request);
                        void __removeRule(RequestInfo* request);