2 * emulator-plugin-geo-filter
4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * SooYoung Ha <yoosah.ha@samsnung.com>
8 * Sungmin Ha <sungmin82.ha@samsung.com>
9 * DongKyun Yun <dk77.yun@samsung.com>
11 * This library is free software; you can redistribute it and/or modify it under
12 * the terms of the GNU Lesser General Public License as published by the
13 * Free Software Foundation; either version 2.1 of the License, or (at your option)
16 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
17 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 * License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this library; if not, write to the Free Software Foundation, Inc., 51
23 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
38 #include <netinet/in.h>
43 #include <cobject_type.h>
52 #include <sf_common.h>
54 #include <csensor_module.h>
55 #include <cfilter_module.h>
56 #include <geo_sim_filter.h>
60 geo_sim_filter::geo_sim_filter()
68 , m_polling_interval(500000)
70 m_name = strdup("geo_sim_filter");
76 if (check_hw_node() != 1 ) {
86 geo_sim_filter::~geo_sim_filter()
93 const char *geo_sim_filter::name(void)
100 int geo_sim_filter::version(void)
107 int geo_sim_filter::id(void)
114 bool geo_sim_filter::is_data_ready(bool wait)
116 unsigned long long cur_time;
117 unsigned long elapsed_time;
121 gettimeofday(&sv, NULL);
122 cur_time = MICROSECONDS(sv);
124 elapsed_time = (unsigned long)(cur_time - m_fired_time);
125 if (elapsed_time < m_polling_interval) {
128 usleep(m_polling_interval - elapsed_time);
129 m_fired_time = cur_time + (m_polling_interval-elapsed_time);
133 DBG("Re-firing %llu %llu\n", cur_time, m_fired_time);
134 DBG("elapsed_time %lu polling_interval %ld\n", elapsed_time, m_polling_interval);
135 m_fired_time = cur_time;
138 return m_sensor ? m_sensor->is_data_ready(wait) : false;
143 long geo_sim_filter::value(const char *port)
145 return m_sensor ? m_sensor->value(port) : -1;
150 long geo_sim_filter::value(int id)
152 return m_sensor ? m_sensor->value(id) : -1;
157 bool geo_sim_filter::update_name(char *name)
161 new_name = strdup(name);
174 bool geo_sim_filter::update_version(int ver)
182 bool geo_sim_filter::update_id(int id)
190 void geo_sim_filter::reset(void)
196 bool geo_sim_filter::add_input(csensor_module *module)
204 cfilter_module *geo_sim_filter::create_new(void)
206 #ifdef USE_ONLY_ONE_MODULE
207 return (cfilter_module*)this;
209 geo_sim_filter *inst;
213 inst = new geo_sim_filter;
219 bstate = cmodule::add_to_list((cmodule *)inst);
221 ERR("Creat and add_to_list fail");
225 return (cfilter_module*)inst;
231 void geo_sim_filter::destroy(cfilter_module *module)
235 bstate = cmodule::del_from_list((cmodule *)module);
238 ERR("Destory and del_from_list fail");
239 delete (geo_sim_filter *)module;
247 bool geo_sim_filter::start(void)
249 return m_sensor ? m_sensor->start() : false;
254 bool geo_sim_filter::stop(void)
256 return m_sensor ? m_sensor->stop() : false;
259 int geo_sim_filter::get_sensor_type(void)
262 return m_sensor->get_sensor_type();
269 int geo_sim_filter::check_hw_node(void)
275 const char* orig_name = "geo_sim";
281 snprintf(name_node,sizeof(name_node),"/opt/sensor/geo/name");
283 fp = fopen(name_node, "r");
285 DBG("Failed to open a sys_node or there is no node : %s\n",name_node);
289 if ( fscanf(fp, "%s", hw_name) < 0) {
291 ERR("Failed to collect data\n");
296 if (!strcasecmp(hw_name, orig_name )) {
305 long geo_sim_filter::polling_interval(void)
307 return (unsigned long long)m_polling_interval /1000llu ;
310 bool geo_sim_filter::update_polling_interval(unsigned long val)
312 DBG("Update polling interval %lu\n", val);
313 cfilter_module::lock();
314 m_polling_interval = (unsigned long long)val * 1000llu;
315 cfilter_module::unlock();
319 int geo_sim_filter::get_property(unsigned int property_level , void *property_data)
322 return m_sensor->get_property(property_level , property_data);
329 int geo_sim_filter::get_struct_value(unsigned int struct_type , void *struct_values)
333 return m_sensor->get_struct_value(struct_type , struct_values);
336 ERR("no m_sensor , cannot get_struct_value from sensor\n");
342 extern "C" cmodule *module_init(void *win, void *egl)
344 geo_sim_filter *sample;
347 sample = new geo_sim_filter;
348 } catch (int ErrNo) {
349 ERR("geo_sim_filter class create fail , errno : %d , errstr : %s\n",ErrNo, strerror(ErrNo));
353 return (cmodule*)sample;
358 extern "C" void module_exit(cmodule *inst)
360 geo_sim_filter *sample = (geo_sim_filter*)inst;