4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <sf_common.h>
22 #include <geo_sensor.h>
23 #include <sensor_plugin_loader.h>
25 #define SENSOR_NAME "GEOMAGNETIC_SENSOR"
27 geo_sensor::geo_sensor()
30 m_name = string(SENSOR_NAME);
32 register_supported_event(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME);
33 register_supported_event(GEOMAGNETIC_EVENT_CALIBRATION_NEEDED);
35 physical_sensor::set_poller(geo_sensor::working, this);
38 geo_sensor::~geo_sensor()
40 INFO("geo_sensor is destroyed!");
43 bool geo_sensor::init()
45 m_sensor_hal = sensor_plugin_loader::get_instance().get_sensor_hal(GEOMAGNETIC_SENSOR);
48 ERR("cannot load sensor_hal[%s]", sensor_base::get_name());
52 INFO("%s is created!", sensor_base::get_name());
56 sensor_type_t geo_sensor::get_type(void)
58 return GEOMAGNETIC_SENSOR;
61 bool geo_sensor::working(void *inst)
63 geo_sensor *sensor = (geo_sensor *)inst;
64 return sensor->process_event();
67 bool geo_sensor::process_event(void)
71 if (!m_sensor_hal->is_data_ready(true))
74 m_sensor_hal->get_sensor_data(event.data);
76 AUTOLOCK(m_client_info_mutex);
79 if (get_client_cnt(GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME)) {
80 event.event_type = GEOMAGNETIC_EVENT_RAW_DATA_REPORT_ON_TIME;
88 bool geo_sensor::on_start(void)
92 if (!m_sensor_hal->enable()) {
93 ERR("m_sensor_hal start fail");
100 bool geo_sensor::on_stop(void)
104 if (!m_sensor_hal->disable()) {
105 ERR("m_sensor_hal stop fail");
112 long geo_sensor::set_command(const unsigned int cmd, long value)
114 if (m_sensor_hal->set_command(cmd, value) < 0) {
115 ERR("m_sensor_hal set_cmd fail");
122 bool geo_sensor::get_properties(const unsigned int type, sensor_properties_t &properties)
124 return m_sensor_hal->get_properties(properties);
127 int geo_sensor::get_sensor_data(const unsigned int type, sensor_data_t &data)
131 if (type != GEOMAGNETIC_BASE_DATA_SET)
134 state = m_sensor_hal->get_sensor_data(data);
137 ERR("m_sensor_hal get struct_data fail");
144 bool geo_sensor::set_interval(unsigned long interval)
148 INFO("Polling interval is set to %dms", interval);
149 return m_sensor_hal->set_interval(interval);
152 extern "C" void *create(void)
157 inst = new geo_sensor();
159 ERR("Failed to create geo_sensor class, errno : %d, errstr : %s", err, strerror(err));
166 extern "C" void destroy(void *inst)
168 delete (geo_sensor *)inst;