Add PolicyManager for enabling usage loggers at launch time 60/67560/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 27 Apr 2016 08:20:37 +0000 (17:20 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Wed, 27 Apr 2016 08:20:37 +0000 (17:20 +0900)
Change-Id: I754e7962f88b65f61a41d5c644d2a4b19d2ded38
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/Server.cpp
src/policy/PolicyManager.cpp [new file with mode: 0644]
src/policy/PolicyManager.h [new file with mode: 0644]
src/policy/PolicyRequest.cpp [new file with mode: 0644]
src/policy/PolicyRequest.h [new file with mode: 0644]

index 2617a4f..04a043c 100644 (file)
@@ -23,6 +23,7 @@
 #include "DBusServer.h"
 #include "ContextManager.h"
 #include "trigger/Trigger.h"
+#include "policy/PolicyManager.h"
 #include "Server.h"
 
 static GMainLoop *mainloop = NULL;
@@ -30,6 +31,7 @@ static bool started = false;
 
 static ctx::ContextManager *__contextMgr = NULL;
 static ctx::DBusServer *__dbusHandle = NULL;
+static ctx::PolicyManager *__policyMgr = NULL;
 static ctx::trigger::Trigger *__contextTrigger = NULL;
 
 /* TODO: re-organize activation & deactivation processes */
@@ -60,6 +62,10 @@ void ctx::Server::activate()
        result = __contextMgr->init();
        IF_FAIL_CATCH_TAG(result, _E, "Initialization Failed");
 
+       _I("Init Policy Manager");
+       __policyMgr = new(std::nothrow) ctx::PolicyManager(__contextMgr);
+       IF_FAIL_CATCH_TAG(__policyMgr, _E, "Memory allocation failed");
+
        _I("Init Context Trigger");
        __contextTrigger = new(std::nothrow) ctx::trigger::Trigger();
        IF_FAIL_CATCH_TAG(__contextTrigger, _E, "Memory allocation failed");
@@ -84,7 +90,10 @@ void ctx::Server::release()
        if (__contextTrigger)
                __contextTrigger->release();
 
-       _I("Release Analyzer Manager");
+       _I("Release Policy Manager");
+       delete __policyMgr;
+
+       _I("Release Context Manager");
        if (__contextMgr)
                __contextMgr->release();
 
diff --git a/src/policy/PolicyManager.cpp b/src/policy/PolicyManager.cpp
new file mode 100644 (file)
index 0000000..c742254
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2016 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 <Types.h>
+#include <DBusTypes.h>
+#include <ProviderTypes.h>
+#include "../ContextManager.h"
+#include "PolicyRequest.h"
+#include "PolicyManager.h"
+
+using namespace ctx;
+
+PolicyManager::PolicyManager(ContextManager *contextMgr) :
+       __contextMgr(contextMgr)
+{
+       __init();
+}
+
+PolicyManager::~PolicyManager()
+{
+       __release();
+}
+
+void PolicyManager::__init()
+{
+       __subscribe(SUBJ_APP_LOGGER, __ridAppLogging);
+       __subscribe(SUBJ_MEDIA_LOGGER, __ridMediaLogging);
+       __subscribe(SUBJ_SOCIAL_LOGGER, __ridSocialLogging);
+
+       __subscribe(SUBJ_PLACE_DETECTION, __ridPlaceDetection);
+}
+
+void PolicyManager::__release()
+{
+       __unsubscribe(SUBJ_APP_LOGGER, __ridAppLogging);
+       __unsubscribe(SUBJ_MEDIA_LOGGER, __ridMediaLogging);
+       __unsubscribe(SUBJ_SOCIAL_LOGGER, __ridSocialLogging);
+
+       __unsubscribe(SUBJ_PLACE_DETECTION, __ridPlaceDetection);
+}
+
+void PolicyManager::__subscribe(const char *subject, int &reqId)
+{
+       static int rid = 0;
+       ++rid;
+
+       reqId = rid;
+
+       PolicyRequest *req = new(std::nothrow) PolicyRequest(REQ_SUBSCRIBE, reqId, subject, NULL);
+       IF_FAIL_VOID_TAG(req, _E, "Memory allocation failed");
+
+       __contextMgr->assignRequest(req);
+}
+
+void PolicyManager::__unsubscribe(const char *subject, int reqId)
+{
+       PolicyRequest *req = new(std::nothrow) PolicyRequest(REQ_UNSUBSCRIBE, reqId, subject, NULL);
+       IF_FAIL_VOID_TAG(req, _E, "Memory allocation failed");
+
+       __contextMgr->assignRequest(req);
+}
diff --git a/src/policy/PolicyManager.h b/src/policy/PolicyManager.h
new file mode 100644 (file)
index 0000000..e9d2d09
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016 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_POLICY_MANAGER_H_
+#define _CONTEXT_POLICY_MANAGER_H_
+
+namespace ctx {
+
+       class ContextManger;
+
+       class PolicyManager {
+       public:
+               ~PolicyManager();
+
+       private:
+               PolicyManager(ContextManager *contextMgr);
+
+               void __init();
+               void __release();
+
+               void __subscribe(const char *subject, int &reqId);
+               void __unsubscribe(const char *subject, int reqId);
+
+               ContextManager *__contextMgr;
+               int __ridAppLogging;
+               int __ridMediaLogging;
+               int __ridSocialLogging;
+               int __ridPlaceDetection;
+
+               friend class Server;
+       };
+
+}      /* namespace ctx */
+
+#endif /* End of _CONTEXT_POLICY_MANAGER_H_ */
diff --git a/src/policy/PolicyRequest.cpp b/src/policy/PolicyRequest.cpp
new file mode 100644 (file)
index 0000000..466dc2e
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2016 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 "PolicyRequest.h"
+
+using namespace ctx;
+
+PolicyRequest::PolicyRequest(int type, int reqId, const char *subj, const char *desc) :
+       RequestInfo(type, reqId, subj, desc)
+{
+}
+
+PolicyRequest::~PolicyRequest()
+{
+}
+
+bool PolicyRequest::reply(int error)
+{
+       return true;
+}
+
+bool PolicyRequest::reply(int error, ctx::Json &requestResult)
+{
+       return true;
+}
+
+bool PolicyRequest::reply(int error, ctx::Json &requestResult, ctx::Json &dataRead)
+{
+       return true;
+}
+
+bool PolicyRequest::publish(int error, ctx::Json &data)
+{
+       return true;
+}
diff --git a/src/policy/PolicyRequest.h b/src/policy/PolicyRequest.h
new file mode 100644 (file)
index 0000000..940b203
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2016 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_POLICY_REQUEST_H_
+#define _CONTEXT_POLICY_REQUEST_H_
+
+#include "../Request.h"
+
+namespace ctx {
+
+       class PolicyRequest : public RequestInfo {
+       public:
+               PolicyRequest(int type, int reqId, const char *subj, const char *desc);
+               ~PolicyRequest();
+
+               bool reply(int error);
+               bool reply(int error, ctx::Json &requestResult);
+               bool reply(int error, ctx::Json &requestResult, ctx::Json &dataRead);
+               bool publish(int error, ctx::Json &data);
+       };
+
+}      /* namespace ctx */
+
+#endif /* End of _CONTEXT_POLICY_REQUEST_H_ */