Merge "sensord: delete batch latency/attribute when client is terminated unexpectedly...
[platform/core/system/sensord.git] / src / server / sensor_usage.cpp
1 /*
2  * sensord
3  *
4  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <sensor_common.h>
21 #include <sensor_types.h>
22 #include <sensor_usage.h>
23 #include <sensor_log.h>
24
25 sensor_usage::sensor_usage()
26 : m_interval(POLL_1HZ_MS)
27 , m_latency(0)
28 , m_pause_policy(SENSORD_PAUSE_ALL)
29 , m_start(false)
30 {
31 }
32
33 sensor_usage::~sensor_usage()
34 {
35         m_reg_events.clear();
36 }
37
38 bool sensor_usage::register_event(unsigned int event_type)
39 {
40         auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
41
42         if (it_event != m_reg_events.end()) {
43                 _E("Event[%#x] is already registered", event_type);
44                 return false;
45         }
46
47         m_reg_events.push_back(event_type);
48         return true;
49 }
50
51 bool sensor_usage::unregister_event(unsigned int event_type)
52 {
53         auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
54
55         if (it_event == m_reg_events.end()) {
56                 _E("Event[%#x] is not found", event_type);
57                 return false;
58         }
59
60         m_reg_events.erase(it_event);
61
62         return true;
63 }
64
65 bool sensor_usage::is_event_registered(unsigned int event_type)
66 {
67         auto it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
68
69         if (it_event == m_reg_events.end()) {
70                 _D("Event[%#x] is not registered", event_type);
71                 return false;
72         }
73
74         return true;
75 }