2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <DBusTypes.h>
19 #include <ProviderTypes.h>
20 #include <SensorRecorderTypes.h>
21 #include "../ContextManager.h"
22 #include "PolicyRequest.h"
23 #include "PolicyManager.h"
27 PolicyManager::PolicyManager(ContextManager *contextMgr) :
28 __contextMgr(contextMgr)
30 __subscribe(SUBJ_CUSTOM);
32 __subscribe(SUBJ_APP_LOGGER);
33 __subscribe(SUBJ_BATTERY_LOGGER);
34 __subscribe(SUBJ_MEDIA_LOGGER);
35 __subscribe(SUBJ_PLACE_DETECTION);
36 __subscribe(SUBJ_STATE_WIFI);
38 __subscribe(SUBJ_SENSOR_PEDOMETER);
39 __subscribe(SUBJ_SENSOR_PRESSURE);
40 __subscribe(SUBJ_SENSOR_SLEEP_MONITOR);
41 __subscribe(SUBJ_SENSOR_HEART_RATE);
44 PolicyManager::~PolicyManager()
46 for (auto &it : __subscriptionMap) {
47 PolicyRequest *req = new(std::nothrow) PolicyRequest(REQ_UNSUBSCRIBE, it.first, it.second, NULL);
49 _E("Memory allocation failed");
52 __contextMgr->assignRequest(req);
55 __subscriptionMap.clear();
58 void PolicyManager::__subscribe(const char *subject)
63 PolicyRequest *req = new(std::nothrow) PolicyRequest(REQ_SUBSCRIBE, rid, subject, NULL);
64 IF_FAIL_VOID_TAG(req, _E, "Memory allocation failed");
66 __contextMgr->assignRequest(req);
68 __subscriptionMap[rid] = subject;