sensor-framework : Initial commit
[platform/core/system/sensord.git] / src / shared / csensor_usage.cpp
1 /*
2  * libsensord-share
3  *
4  * Copyright (c) 2014 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.h>
21 #include <csensor_usage.h>
22 #include <common.h>
23
24 csensor_usage::csensor_usage()
25 : m_interval(POLL_MAX_HZ_MS)
26 , m_option(SENSOR_OPTION_DEFAULT)
27 , m_start(false)
28 {
29 }
30
31 csensor_usage::~csensor_usage()
32 {
33         m_reg_events.clear();
34 }
35
36 bool csensor_usage::register_event(const unsigned int event_type)
37 {
38         reg_event_vector::iterator it_event;
39         it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
40
41         if (it_event != m_reg_events.end()) {
42                 ERR("Event[0x%x] is already registered", event_type);
43                 return false;
44         }
45
46         m_reg_events.push_back(event_type);
47         return true;
48 }
49
50 bool csensor_usage::unregister_event(const unsigned int event_type)
51 {
52         reg_event_vector::iterator it_event;
53         it_event = find(m_reg_events.begin(), m_reg_events.end(), event_type);
54
55         if (it_event == m_reg_events.end()) {
56                 ERR("Event[0x%x] is not found", event_type);
57                 return false;
58         }
59
60         m_reg_events.erase(it_event);
61         return true;
62 }
63
64 bool csensor_usage::is_event_registered(const unsigned int event_type)
65 {
66         reg_event_vector::iterator it_event;
67         it_event = find (m_reg_events.begin(), m_reg_events.end(), event_type);
68
69         if (it_event == m_reg_events.end()) {
70                 DBG("Event[0x%x] is not registered", event_type);
71                 return false;
72         }
73
74         return true;
75 }