#include "DBusServer.h"
#include "ContextManager.h"
#include "trigger/Trigger.h"
+#include "policy/PolicyManager.h"
#include "Server.h"
static GMainLoop *mainloop = NULL;
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 */
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");
if (__contextTrigger)
__contextTrigger->release();
- _I("Release Analyzer Manager");
+ _I("Release Policy Manager");
+ delete __policyMgr;
+
+ _I("Release Context Manager");
if (__contextMgr)
__contextMgr->release();
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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_ */
--- /dev/null
+/*
+ * 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;
+}
--- /dev/null
+/*
+ * 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_ */