sensord: change an input value name of set_attribute function
[platform/core/system/sensord.git] / src / client / client.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_internal_deprecated.h>
22 #include <sensor_internal.h>
23 #include <sensor_event_listener.h>
24 #include <sensor_client_info.h>
25 #include <client_common.h>
26 #include <vconf.h>
27 #include <cmutex.h>
28 #include <sensor_log.h>
29 #include <sensor_info.h>
30 #include <sensor_info_manager.h>
31 #include <vector>
32 #include <algorithm>
33 #include "dbus_listener.h"
34
35 using std::vector;
36
37 #ifndef API
38 #define API __attribute__((visibility("default")))
39 #endif
40
41 #ifndef VCONFKEY_SETAPPL_PSMODE
42 #define VCONFKEY_SETAPPL_PSMODE "db/setting/psmode"
43 #endif
44
45 #define DEFAULT_INTERVAL POLL_10HZ_MS
46
47 #define CONVERT_OPTION_PAUSE_POLICY(option) ((option) ^ 0b11)
48
49 static cmutex lock;
50
51 static int g_power_save_state = SENSORD_PAUSE_NONE;
52
53 static int get_power_save_state(void);
54 static void power_save_state_cb(keynode_t *node, void *data);
55 static void clean_up(void);
56 static bool change_sensor_rep(sensor_id_t sensor_id, sensor_rep &prev_rep, sensor_rep &cur_rep);
57 static void restore_session(void);
58 static bool register_event(int handle, unsigned int event_type, unsigned int interval, int max_batch_latency, void* cb, void *user_data);
59
60 class initiator {
61 public:
62         initiator()
63         {
64                 sensor_event_listener::get_instance().set_hup_observer(restore_session);
65         }
66 };
67
68 void good_bye(void)
69 {
70         _I("Good bye! %s\n", get_client_name());
71         clean_up();
72 }
73
74 static initiator g_initiator;
75
76 static int g_power_save_state_cb_cnt = 0;
77
78 static void set_power_save_state_cb(void)
79 {
80         if (g_power_save_state_cb_cnt < 0)
81                 _E("g_power_save_state_cb_cnt(%d) is wrong", g_power_save_state_cb_cnt);
82
83         ++g_power_save_state_cb_cnt;
84
85         if (g_power_save_state_cb_cnt == 1) {
86                 _D("Power save callback is registered");
87                 g_power_save_state = get_power_save_state();
88                 _D("power_save_state = [%d]", g_power_save_state);
89                 vconf_notify_key_changed(VCONFKEY_PM_STATE, power_save_state_cb, NULL);
90                 vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb, NULL);
91         }
92 }
93
94 static void unset_power_save_state_cb(void)
95 {
96         --g_power_save_state_cb_cnt;
97
98         if (g_power_save_state_cb_cnt < 0)
99                 _E("g_power_save_state_cb_cnt(%d) is wrong", g_power_save_state_cb_cnt);
100
101         if (g_power_save_state_cb_cnt == 0) {
102                 _D("Power save callback is unregistered");
103                 vconf_ignore_key_changed(VCONFKEY_PM_STATE, power_save_state_cb);
104                 vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE, power_save_state_cb);
105         }
106 }
107
108 void clean_up(void)
109 {
110         handle_vector handles;
111
112         sensor_client_info::get_instance().get_all_handles(handles);
113
114         auto it_handle = handles.begin();
115
116         while (it_handle != handles.end()) {
117                 sensord_disconnect(*it_handle);
118                 ++it_handle;
119         }
120
121         sensor_event_listener::get_instance().clear();
122 }
123
124 static int get_power_save_state(void)
125 {
126         int ret;
127         int state = 0;
128         int pm_state, ps_state;
129
130         ret = vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
131
132         if (!ret && pm_state == VCONFKEY_PM_STATE_LCDOFF)
133                 state |= SENSORD_PAUSE_ON_DISPLAY_OFF;
134
135         ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &ps_state);
136
137         if (!ret && ps_state != SETTING_PSMODE_NORMAL)
138                 state |= SENSORD_PAUSE_ON_POWERSAVE_MODE;
139
140         return state;
141 }
142
143 static void power_save_state_cb(keynode_t *node, void *data)
144 {
145         int cur_power_save_state;
146         sensor_id_vector sensors;
147         sensor_rep prev_rep, cur_rep;
148
149         AUTOLOCK(lock);
150
151         cur_power_save_state = get_power_save_state();
152
153         if (cur_power_save_state == g_power_save_state) {
154                 _D("g_power_save_state NOT changed : [%d]", cur_power_save_state);
155                 return;
156         }
157
158         g_power_save_state = cur_power_save_state;
159         _D("power_save_state: %d noti to %s", g_power_save_state, get_client_name());
160
161         sensor_client_info::get_instance().get_listening_sensors(sensors);
162
163         auto it_sensor = sensors.begin();
164
165         while (it_sensor != sensors.end()) {
166                 sensor_client_info::get_instance().get_sensor_rep(*it_sensor, prev_rep);
167                 sensor_client_info::get_instance().set_pause_policy(*it_sensor, cur_power_save_state);
168                 sensor_client_info::get_instance().get_sensor_rep(*it_sensor, cur_rep);
169                 change_sensor_rep(*it_sensor, prev_rep, cur_rep);
170
171                 ++it_sensor;
172         }
173 }
174
175 bool restore_attributes(int client_id, sensor_id_t sensor, command_channel *cmd_channel)
176 {
177         sensor_handle_info_map handle_infos;
178
179         sensor_client_info::get_instance().get_sensor_handle_info(sensor, handle_infos);
180
181         for (auto it_handles = handle_infos.begin(); it_handles != handle_infos.end(); ++it_handles) {
182                 sensor_handle_info info = it_handles->second;
183
184                 for (auto it = info.attributes_int.begin(); it != info.attributes_int.end(); ++it) {
185                         int attribute = it->first;
186                         int value = it->second;
187                         if (!cmd_channel->cmd_set_attribute_int(attribute, value)) {
188                                 _E("Failed to send cmd_set_attribute_int(%d, %d) for %s",
189                                     client_id, value, get_client_name());
190                                 return false;
191                         }
192                 }
193
194                 for (auto it = info.attributes_str.begin(); it != info.attributes_str.end(); ++it) {
195                         int attribute = it->first;
196                         const char *value = it->second->get();
197                         int len = it->second->size();
198                         if (!cmd_channel->cmd_set_attribute_str(attribute, value, len)) {
199                                 _E("Failed to send cmd_set_attribute_str(%d, %d, %s) for %s",
200                                     client_id, len, value, get_client_name());
201                                 return false;
202                         }
203                 }
204         }
205
206         return true;
207 }
208
209 void restore_session(void)
210 {
211         AUTOLOCK(lock);
212
213         _I("Trying to restore sensor client session for %s", get_client_name());
214
215         command_channel *cmd_channel;
216         int client_id;
217
218         sensor_client_info::get_instance().close_command_channel();
219         sensor_client_info::get_instance().set_client_id(CLIENT_ID_INVALID);
220
221         sensor_id_vector sensors;
222
223         sensor_client_info::get_instance().get_listening_sensors(sensors);
224
225         bool first_connection = true;
226
227         auto it_sensor = sensors.begin();
228
229         while (it_sensor != sensors.end()) {
230                 cmd_channel = new(std::nothrow) command_channel();
231                 retm_if(!cmd_channel, "Failed to allocate memory");
232
233                 if (!cmd_channel->create_channel()) {
234                         _E("%s failed to create command channel for %s", get_client_name(), get_sensor_name(*it_sensor));
235                         delete cmd_channel;
236                         goto FAILED;
237                 }
238
239                 sensor_client_info::get_instance().add_command_channel(*it_sensor, cmd_channel);
240
241                 if (first_connection) {
242                         first_connection = false;
243                         if (!cmd_channel->cmd_get_id(client_id)) {
244                                 _E("Failed to get client id");
245                                 goto FAILED;
246                         }
247
248                         sensor_client_info::get_instance().set_client_id(client_id);
249                         sensor_event_listener::get_instance().start_event_listener();
250                 }
251
252                 cmd_channel->set_client_id(client_id);
253
254                 if (!cmd_channel->cmd_hello(*it_sensor)) {
255                         _E("Sending cmd_hello(%s, %d) failed for %s", get_sensor_name(*it_sensor), client_id, get_client_name());
256                         goto FAILED;
257                 }
258
259                 sensor_rep prev_rep, cur_rep;
260                 prev_rep.active = false;
261                 prev_rep.pause_policy = SENSORD_PAUSE_ALL;
262                 prev_rep.interval = 0;
263
264                 sensor_client_info::get_instance().get_sensor_rep(*it_sensor, cur_rep);
265                 if (!change_sensor_rep(*it_sensor, prev_rep, cur_rep)) {
266                         _E("Failed to change rep(%s) for %s", get_sensor_name(*it_sensor), get_client_name());
267                         goto FAILED;
268                 }
269
270                 if (!restore_attributes(client_id, *it_sensor, cmd_channel)) {
271                         _E("Failed to restore attributes(%s) for %s", get_sensor_name(*it_sensor), get_client_name());
272                         goto FAILED;
273                 }
274                 ++it_sensor;
275         }
276
277         _I("Succeeded to restore sensor client session for %s", get_client_name());
278
279         return;
280
281 FAILED:
282         sensor_event_listener::get_instance().clear();
283         _E("Failed to restore session for %s", get_client_name());
284 }
285
286 static bool get_events_diff(event_type_vector &a_vec, event_type_vector &b_vec, event_type_vector &add_vec, event_type_vector &del_vec)
287 {
288         sort(a_vec.begin(), a_vec.end());
289         sort(b_vec.begin(), b_vec.end());
290
291         set_difference(a_vec.begin(), a_vec.end(), b_vec.begin(), b_vec.end(), back_inserter(del_vec));
292         set_difference(b_vec.begin(), b_vec.end(), a_vec.begin(), a_vec.end(), back_inserter(add_vec));
293
294         return !(add_vec.empty() && del_vec.empty());
295 }
296
297 static bool change_sensor_rep(sensor_id_t sensor_id, sensor_rep &prev_rep, sensor_rep &cur_rep)
298 {
299         int client_id;
300         command_channel *cmd_channel;
301         event_type_vector add_event_types, del_event_types;
302
303         if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
304                 _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
305                 return false;
306         }
307
308         client_id = sensor_client_info::get_instance().get_client_id();
309         retvm_if((client_id < 0), false, "Invalid client id : %d, %s, %s", client_id, get_sensor_name(sensor_id), get_client_name());
310
311         get_events_diff(prev_rep.event_types, cur_rep.event_types, add_event_types, del_event_types);
312
313         if (cur_rep.active) {
314                 if (prev_rep.pause_policy != cur_rep.pause_policy) {
315                         if (!cmd_channel->cmd_set_pause_policy(cur_rep.pause_policy)) {
316                                 _E("Sending cmd_set_pause_policy(%d, %s, %d) failed for %s", client_id, get_sensor_name(sensor_id), cur_rep.pause_policy, get_client_name());
317                                 return false;
318                         }
319                 }
320
321                 if ( (prev_rep.interval != cur_rep.interval) || (prev_rep.latency != cur_rep.latency)) {
322                         if (!cmd_channel->cmd_set_batch(cur_rep.interval, cur_rep.latency)) {
323                                 _E("Sending cmd_set_batch(%d, %s, %d, %d) failed for %s", client_id, get_sensor_name(sensor_id), cur_rep.interval, cur_rep.latency, get_client_name());
324                                 return false;
325                         }
326                 }
327
328                 if (!add_event_types.empty()) {
329                         if (!cmd_channel->cmd_register_events(add_event_types)) {
330                                 _E("Sending cmd_register_events(%d, add_event_types) failed for %s", client_id, get_client_name());
331                                 return false;
332                         }
333                 }
334         }
335
336         if (prev_rep.active && !del_event_types.empty()) {
337                 if (!cmd_channel->cmd_unregister_events(del_event_types)) {
338                         _E("Sending cmd_unregister_events(%d, del_event_types) failed for %s", client_id, get_client_name());
339                         return false;
340                 }
341         }
342
343         if (prev_rep.active != cur_rep.active) {
344                 if (cur_rep.active) {
345                         if (!cmd_channel->cmd_start()) {
346                                 _E("Sending cmd_start(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
347                                 return false;
348                         }
349                 } else {
350                         if (!cmd_channel->cmd_unset_batch()) {
351                                 _E("Sending cmd_unset_interval(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
352                                 return false;
353                         }
354
355                         if (!cmd_channel->cmd_stop()) {
356                                 _E("Sending cmd_stop(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
357                                 return false;
358                         }
359                 }
360         }
361
362         return true;
363 }
364
365 static bool get_sensor_list(void)
366 {
367         static cmutex l;
368         static bool init = false;
369
370         AUTOLOCK(l);
371
372         if (!init) {
373                 command_channel cmd_channel;
374
375                 if (!cmd_channel.create_channel()) {
376                         _E("%s failed to create command channel", get_client_name());
377                         return false;
378                 }
379
380                 if (!cmd_channel.cmd_get_sensor_list())
381                         return false;
382
383                 init = true;
384         }
385
386         return true;
387 }
388
389 API int sensord_get_sensors(sensor_type_t type, sensor_t **list, int *sensor_count)
390 {
391         retvm_if(!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
392
393         vector<sensor_info *> sensor_infos = sensor_info_manager::get_instance().get_infos(type);
394
395         if (sensor_infos.empty()) {
396                 *sensor_count = 0;
397                 return -ENODATA;
398         }
399
400         if (type != ALL_SENSOR) {
401                 if (sensor_infos[0]->get_id() == (sensor_id_t)(-EACCES))
402                         return -EACCES;
403         }
404
405         *list = (sensor_t *) malloc(sizeof(sensor_info *) * sensor_infos.size());
406         retvm_if(!*list, false, "Failed to allocate memory");
407
408         for (unsigned int i = 0; i < sensor_infos.size(); ++i)
409                 *(*list + i) = sensor_info_to_sensor(sensor_infos[i]);
410
411         *sensor_count = sensor_infos.size();
412
413         return OP_SUCCESS;
414 }
415
416 API int sensord_get_default_sensor(sensor_type_t type, sensor_t *sensor)
417 {
418         retvm_if(!get_sensor_list(), -EPERM, "Fail to get sensor list from server");
419
420         const sensor_info *info;
421
422         info = sensor_info_manager::get_instance().get_info(type);
423         if (info == NULL) {
424                 *sensor = NULL;
425                 return -ENODATA;
426         }
427
428         if ((const_cast<sensor_info *>(info))->get_id() == (sensor_id_t)(-EACCES))
429                 return -EACCES;
430
431         *sensor = sensor_info_to_sensor(info);
432
433         return OP_SUCCESS;
434 }
435
436 API bool sensord_get_sensor_list(sensor_type_t type, sensor_t **list, int *sensor_count)
437 {
438         return (sensord_get_sensors(type, list, sensor_count) == OP_SUCCESS);
439 }
440
441 API sensor_t sensord_get_sensor(sensor_type_t type)
442 {
443         sensor_t sensor;
444         sensord_get_default_sensor(type, &sensor);
445
446         return sensor;
447 }
448
449 API bool sensord_get_type(sensor_t sensor, sensor_type_t *type)
450 {
451         sensor_info* info = sensor_to_sensor_info(sensor);
452
453         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !type,
454                 NULL, "Invalid param: sensor (%p), type(%p)", sensor, type);
455
456         *type = info->get_type();
457
458         return true;
459 }
460
461 API const char* sensord_get_name(sensor_t sensor)
462 {
463         sensor_info* info = sensor_to_sensor_info(sensor);
464
465         retvm_if(!sensor_info_manager::get_instance().is_valid(info),
466                 NULL, "Invalid param: sensor (%p)", sensor);
467
468         return info->get_name();
469 }
470
471 API const char* sensord_get_vendor(sensor_t sensor)
472 {
473         sensor_info* info = sensor_to_sensor_info(sensor);
474
475         retvm_if(!sensor_info_manager::get_instance().is_valid(info),
476                 NULL, "Invalid param: sensor (%p)", sensor);
477
478         return info->get_vendor();
479 }
480
481 API bool sensord_get_privilege(sensor_t sensor, sensor_privilege_t *privilege)
482 {
483         sensor_info* info = sensor_to_sensor_info(sensor);
484
485         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !privilege,
486                 false, "Invalid param: sensor (%p), privilege(%p)", sensor, privilege);
487
488         *privilege = info->get_privilege();
489
490         return true;
491 }
492
493 API bool sensord_get_min_range(sensor_t sensor, float *min_range)
494 {
495         sensor_info* info = sensor_to_sensor_info(sensor);
496
497         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !min_range,
498                 false, "Invalid param: sensor (%p), min_range(%p)", sensor, min_range);
499
500         *min_range = info->get_min_range();
501
502         return true;
503 }
504
505 API bool sensord_get_max_range(sensor_t sensor, float *max_range)
506 {
507         sensor_info* info = sensor_to_sensor_info(sensor);
508
509         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !max_range,
510                 false, "Invalid param: sensor (%p), max_range(%p)", sensor, max_range);
511
512         *max_range = info->get_max_range();
513
514         return true;
515 }
516
517 API bool sensord_get_resolution(sensor_t sensor, float *resolution)
518 {
519         sensor_info* info = sensor_to_sensor_info(sensor);
520
521         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !resolution,
522                 false, "Invalid param: sensor (%p), resolution(%p)", sensor, resolution);
523
524         *resolution = info->get_resolution();
525
526         return true;
527 }
528
529 API bool sensord_get_min_interval(sensor_t sensor, int *min_interval)
530 {
531         sensor_info* info = sensor_to_sensor_info(sensor);
532
533         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !min_interval,
534                 false, "Invalid param: sensor (%p), min_interval(%p)", sensor, min_interval);
535
536         *min_interval = info->get_min_interval();
537
538         return true;
539 }
540
541 API bool sensord_get_fifo_count(sensor_t sensor, int *fifo_count)
542 {
543         sensor_info* info = sensor_to_sensor_info(sensor);
544
545         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !fifo_count,
546                 false, "Invalid param: sensor (%p), fifo_count(%p)", sensor, fifo_count);
547
548         *fifo_count = info->get_fifo_count();
549
550         return true;
551 }
552
553 API bool sensord_get_max_batch_count(sensor_t sensor, int *max_batch_count)
554 {
555         sensor_info* info = sensor_to_sensor_info(sensor);
556
557         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !max_batch_count,
558                 false, "Invalid param: sensor (%p), max_batch_count(%p)", sensor, max_batch_count);
559
560         *max_batch_count = info->get_max_batch_count();
561
562         return true;
563 }
564
565 API bool sensord_get_supported_event_types(sensor_t sensor, unsigned int **event_types, int *count)
566 {
567         sensor_info* info = sensor_to_sensor_info(sensor);
568
569         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !event_types || !count,
570                 false, "Invalid param: sensor (%p), event_types(%p), count(%p)", sensor, event_types, count);
571
572         unsigned int event_type;
573         event_type = info->get_supported_event();
574         *event_types = (unsigned int *)malloc(sizeof(unsigned int));
575
576         retvm_if(!*event_types, false, "Failed to allocate memory");
577
578         (*event_types)[0] = event_type;
579         *count = 1;
580
581         return true;
582 }
583
584 API bool sensord_is_supported_event_type(sensor_t sensor, unsigned int event_type, bool *supported)
585 {
586         sensor_info* info = sensor_to_sensor_info(sensor);
587
588         retvm_if(!sensor_info_manager::get_instance().is_valid(info) || !event_type || !supported,
589                 false, "Invalid param: sensor (%p), event_type(%p), supported(%p)", sensor, event_type, supported);
590
591         *supported = info->is_supported_event(event_type);
592
593         return true;
594 }
595
596 API bool sensord_is_wakeup_supported(sensor_t sensor)
597 {
598         sensor_info* info = sensor_to_sensor_info(sensor);
599
600         retvm_if(!sensor_info_manager::get_instance().is_valid(info),
601                 false, "Invalid param: sensor (%p)", sensor);
602
603         return info->is_wakeup_supported();
604 }
605
606 API int sensord_connect(sensor_t sensor)
607 {
608         command_channel *cmd_channel = NULL;
609         int handle;
610         int client_id;
611         bool sensor_registered;
612         bool first_connection = false;
613
614         sensor_info* info = sensor_to_sensor_info(sensor);
615
616         retvm_if(!sensor_info_manager::get_instance().is_valid(info),
617                 OP_ERROR, "Invalid param: sensor (%p)", sensor);
618
619         sensor_id_t sensor_id = info->get_id();
620
621         AUTOLOCK(lock);
622
623         sensor_registered = sensor_client_info::get_instance().is_sensor_registered(sensor_id);
624
625         // lazy loading after creating static variables
626         atexit(good_bye);
627
628         handle = sensor_client_info::get_instance().create_handle(sensor_id);
629         if (handle == MAX_HANDLE) {
630                 _E("Maximum number of handles reached, sensor: %s in client %s", get_sensor_name(sensor_id), get_client_name());
631                 return OP_ERROR;
632         }
633
634         if (!sensor_registered) {
635                 cmd_channel = new(std::nothrow) command_channel();
636                 if (!cmd_channel) {
637                         _E("Failed to allocated memory");
638                         sensor_client_info::get_instance().delete_handle(handle);
639                         return OP_ERROR;
640                 }
641
642                 if (!cmd_channel->create_channel()) {
643                         _E("%s failed to create command channel for %s", get_client_name(), get_sensor_name(sensor_id));
644                         sensor_client_info::get_instance().delete_handle(handle);
645                         delete cmd_channel;
646                         return OP_ERROR;
647                 }
648
649                 sensor_client_info::get_instance().add_command_channel(sensor_id, cmd_channel);
650         }
651
652         if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
653                 _E("%s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
654                 sensor_client_info::get_instance().delete_handle(handle);
655                 return OP_ERROR;
656         }
657
658         if (!sensor_client_info::get_instance().has_client_id()) {
659                 first_connection = true;
660                 if (!cmd_channel->cmd_get_id(client_id)) {
661                         _E("Sending cmd_get_id() failed for %s", get_sensor_name(sensor_id));
662                         sensor_client_info::get_instance().close_command_channel(sensor_id);
663                         sensor_client_info::get_instance().delete_handle(handle);
664                         return OP_ERROR;
665                 }
666
667                 sensor_client_info::get_instance().set_client_id(client_id);
668                 _I("%s gets client_id [%d]", get_client_name(), client_id);
669                 sensor_event_listener::get_instance().start_event_listener();
670                 _I("%s starts listening events with client_id [%d]", get_client_name(), client_id);
671         }
672
673         client_id = sensor_client_info::get_instance().get_client_id();
674         cmd_channel->set_client_id(client_id);
675
676         _I("%s[%d] connects with %s[%d]", get_client_name(), client_id, get_sensor_name(sensor_id), handle);
677
678         sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_STOPPED, SENSORD_PAUSE_ALL);
679
680         if (!sensor_registered) {
681                 if (!cmd_channel->cmd_hello(sensor_id)) {
682                         _E("Sending cmd_hello(%s, %d) failed for %s", get_sensor_name(sensor_id), client_id, get_client_name());
683                         sensor_client_info::get_instance().close_command_channel(sensor_id);
684                         sensor_client_info::get_instance().delete_handle(handle);
685                         if (first_connection) {
686                                 sensor_client_info::get_instance().set_client_id(CLIENT_ID_INVALID);
687                                 sensor_event_listener::get_instance().stop_event_listener();
688                         }
689                         return OP_ERROR;
690                 }
691         }
692
693         set_power_save_state_cb();
694         dbus_listener::init();
695         return handle;
696 }
697
698 API bool sensord_disconnect(int handle)
699 {
700         command_channel *cmd_channel;
701         sensor_id_t sensor_id;
702         int client_id;
703         int sensor_state;
704
705         AUTOLOCK(lock);
706
707         if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state)||
708                 !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
709                 _E("client %s failed to get handle information", get_client_name());
710                 return false;
711         }
712
713         if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
714                 _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
715                 return false;
716         }
717
718         client_id = sensor_client_info::get_instance().get_client_id();
719         retvm_if((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
720
721         _I("%s disconnects with %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle);
722
723         if (sensor_client_info::get_instance().get_passive_mode(handle)) {
724                 _W("%s[%d] for %s is on passive mode while disconnecting.",
725                         get_sensor_name(sensor_id), handle, get_client_name());
726
727                 command_channel *cmd_channel;
728                 event_type_vector event_types;
729                 sensor_client_info::get_instance().get_active_event_types(sensor_id, event_types);
730
731                 for (auto it = event_types.begin(); it != event_types.end(); ++it)
732                         sensord_unregister_event(handle, *it);
733
734                 if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
735                         _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
736                         return false;
737                 }
738
739                 if (!cmd_channel->cmd_unset_batch()) {
740                         _E("Sending cmd_unset_interval(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
741                         return false;
742                 }
743         }
744
745         if (sensor_state != SENSOR_STATE_STOPPED) {
746                 _W("%s[%d] for %s is not stopped before disconnecting.",
747                         get_sensor_name(sensor_id), handle, get_client_name());
748                 sensord_stop(handle);
749         }
750
751         if (!sensor_client_info::get_instance().delete_handle(handle))
752                 return false;
753
754         if (!sensor_client_info::get_instance().is_active())
755                 sensor_client_info::get_instance().set_client_id(CLIENT_ID_INVALID);
756
757         if (!sensor_client_info::get_instance().is_sensor_registered(sensor_id)) {
758                 if (!cmd_channel->cmd_byebye()) {
759                         _E("Sending cmd_byebye(%d, %s) failed for %s", client_id, get_sensor_name(sensor_id), get_client_name());
760                         return false;
761                 }
762                 sensor_client_info::get_instance().close_command_channel(sensor_id);
763         }
764
765         if (!sensor_client_info::get_instance().is_active()) {
766                 _I("Stop listening events for client %s with client id [%d]", get_client_name(), sensor_client_info::get_instance().get_client_id());
767                 sensor_event_listener::get_instance().stop_event_listener();
768         }
769
770         unset_power_save_state_cb();
771
772         return true;
773 }
774
775 static bool register_event(int handle, unsigned int event_type, unsigned int interval, int max_batch_latency, void* cb, void *user_data)
776 {
777         sensor_id_t sensor_id;
778         sensor_rep prev_rep, cur_rep;
779         bool ret;
780
781         retvm_if(!cb, false, "callback is NULL");
782
783         AUTOLOCK(lock);
784
785         if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
786                 _E("client %s failed to get handle information", get_client_name());
787                 return false;
788         }
789
790         if (interval == 0)
791                 interval = DEFAULT_INTERVAL;
792
793         _I("%s registers event %s[%#x] for sensor %s[%d] with interval: %d, latency: %d,  cb: %#x, user_data: %#x",
794                 get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id),
795                 handle, interval, max_batch_latency, cb, user_data);
796
797         sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
798         sensor_client_info::get_instance().register_event(handle, event_type, interval, max_batch_latency, cb, user_data);
799         sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
800         ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
801
802         if (!ret)
803                 sensor_client_info::get_instance().unregister_event(handle, event_type);
804
805         return ret;
806 }
807
808 API bool sensord_register_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensor_cb_t cb, void *user_data)
809 {
810         return register_event(handle, event_type, interval, max_batch_latency, (void *)cb, user_data);
811 }
812
813 API bool sensord_unregister_event(int handle, unsigned int event_type)
814 {
815         sensor_id_t sensor_id;
816         sensor_rep prev_rep, cur_rep;
817         bool ret;
818         unsigned int prev_interval, prev_latency;
819         void *prev_cb;
820         void *prev_user_data;
821
822         AUTOLOCK(lock);
823
824         if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
825                 _E("client %s failed to get handle information", get_client_name());
826                 return false;
827         }
828
829         _I("%s unregisters event %s[%#x] for sensor %s[%d]", get_client_name(), get_event_name(event_type),
830                 event_type, get_sensor_name(sensor_id), handle);
831
832         sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
833         sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data);
834
835         if (!sensor_client_info::get_instance().unregister_event(handle, event_type)) {
836                 _E("%s try to unregister non registered event %s[%#x] for sensor %s[%d]",
837                         get_client_name(), get_event_name(event_type), event_type, get_sensor_name(sensor_id), handle);
838                 return false;
839         }
840
841         sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
842         ret =  change_sensor_rep(sensor_id, prev_rep, cur_rep);
843
844         if (sensor_client_info::get_instance().get_passive_mode(handle))
845                 sensor_client_info::get_instance().set_passive_mode(handle, false);
846
847         if (!ret)
848                 sensor_client_info::get_instance().register_event(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data);
849
850         return ret;
851 }
852
853 API bool sensord_register_accuracy_cb(int handle, sensor_accuracy_changed_cb_t cb, void *user_data)
854 {
855         sensor_id_t sensor_id;
856
857         retvm_if(!cb, false, "callback is NULL");
858
859         AUTOLOCK(lock);
860
861         if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
862                 _E("client %s failed to get handle information", get_client_name());
863                 return false;
864         }
865
866         _I("%s registers accuracy_changed_cb for sensor %s[%d] with cb: %#x, user_data: %#x",
867                 get_client_name(), get_sensor_name(sensor_id), handle, cb, user_data);
868
869         sensor_client_info::get_instance().register_accuracy_cb(handle, cb , user_data);
870
871         return true;
872 }
873
874 API bool sensord_unregister_accuracy_cb(int handle)
875 {
876         sensor_id_t sensor_id;
877
878         AUTOLOCK(lock);
879
880         if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
881                 _E("client %s failed to get handle information", get_client_name());
882                 return false;
883         }
884
885         _I("%s unregisters accuracy_changed_cb for sensor %s[%d]",
886                 get_client_name(), get_sensor_name(sensor_id), handle);
887
888         sensor_client_info::get_instance().unregister_accuracy_cb(handle);
889
890         return true;
891 }
892
893 API bool sensord_start(int handle, int option)
894 {
895         sensor_id_t sensor_id;
896         sensor_rep prev_rep, cur_rep;
897         bool ret;
898         int prev_state, prev_pause;
899         int pause;
900
901         AUTOLOCK(lock);
902
903         if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
904                 _E("client %s failed to get handle information", get_client_name());
905                 return false;
906         }
907
908         retvm_if((option < 0) || (option >= SENSOR_OPTION_END), false, "Invalid option value : %d, handle: %d, %s, %s",
909                 option, handle, get_sensor_name(sensor_id), get_client_name());
910
911         _I("%s starts %s[%d], with option: %d, power save state: %d", get_client_name(), get_sensor_name(sensor_id),
912                 handle, option, g_power_save_state);
913
914         pause = CONVERT_OPTION_PAUSE_POLICY(option);
915
916         if (g_power_save_state && (g_power_save_state & pause)) {
917                 sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_PAUSED, pause);
918                 return true;
919         }
920
921         sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
922         sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_pause);
923         sensor_client_info::get_instance().set_sensor_params(handle, SENSOR_STATE_STARTED, pause);
924         sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
925
926         ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
927
928         if (!ret)
929                 sensor_client_info::get_instance().set_sensor_params(handle, prev_state, prev_pause);
930
931         return ret;
932 }
933
934 API bool sensord_stop(int handle)
935 {
936         sensor_id_t sensor_id;
937         int sensor_state;
938         bool ret;
939         int prev_state, prev_pause;
940
941         sensor_rep prev_rep, cur_rep;
942
943         AUTOLOCK(lock);
944
945         if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state)||
946                 !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
947                 _E("client %s failed to get handle information", get_client_name());
948                 return false;
949         }
950
951         retvm_if((sensor_state == SENSOR_STATE_STOPPED), true, "%s already stopped with %s[%d]",
952                 get_client_name(), get_sensor_name(sensor_id), handle);
953
954         _I("%s stops sensor %s[%d]", get_client_name(), get_sensor_name(sensor_id), handle);
955
956         sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
957         sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_pause);
958         sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_STOPPED);
959         sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
960
961         ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
962
963         if (!ret)
964                 sensor_client_info::get_instance().set_sensor_params(handle, prev_state, prev_pause);
965
966         return ret;
967 }
968
969 static bool change_event_batch(int handle, unsigned int event_type, unsigned int interval, unsigned int latency)
970 {
971         sensor_id_t sensor_id;
972         sensor_rep prev_rep, cur_rep;
973         bool ret;
974         unsigned int prev_interval, prev_latency;
975         void *prev_cb;
976         void *prev_user_data;
977
978         AUTOLOCK(lock);
979
980         if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
981                 _E("client %s failed to get handle information", get_client_name());
982                 return false;
983         }
984
985         if (interval == 0)
986                 interval = DEFAULT_INTERVAL;
987
988         _I("%s changes batch of event %s[%#x] for %s[%d] to (%d, %d)", get_client_name(), get_event_name(event_type),
989                         event_type, get_sensor_name(sensor_id), handle, interval, latency);
990
991         sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
992
993         sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data);
994
995         if (!sensor_client_info::get_instance().set_event_batch(handle, event_type, interval, latency))
996                 return false;
997
998         sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
999
1000         ret = change_sensor_rep(sensor_id, prev_rep, cur_rep);
1001
1002         if (!ret)
1003                 sensor_client_info::get_instance().set_event_batch(handle, event_type, prev_interval, prev_latency);
1004
1005         return ret;
1006 }
1007
1008 API bool sensord_change_event_interval(int handle, unsigned int event_type, unsigned int interval)
1009 {
1010         unsigned int prev_interval, prev_latency;
1011         void *prev_cb;
1012         void *prev_user_data;
1013
1014         AUTOLOCK(lock);
1015
1016         if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data)) {
1017                 _E("Failed to get event info with handle = %d, event_type = %#x", handle, event_type);
1018                 return false;
1019         }
1020
1021         _I("handle = %d, event_type = %#x, interval = %d, prev_latency = %d", handle, event_type, interval, prev_latency);
1022         return change_event_batch(handle, event_type, interval, prev_latency);
1023 }
1024
1025 API bool sensord_change_event_max_batch_latency(int handle, unsigned int event_type, unsigned int max_batch_latency)
1026 {
1027         unsigned int prev_interval, prev_latency;
1028         void *prev_cb;
1029         void *prev_user_data;
1030
1031         AUTOLOCK(lock);
1032
1033         if (!sensor_client_info::get_instance().get_event_info(handle, event_type, prev_interval, prev_latency, prev_cb, prev_user_data)) {
1034                 _E("Failed to get event info with handle = %d, event_type = %#x", handle, event_type);
1035                 return false;
1036         }
1037
1038         return change_event_batch(handle, event_type, prev_interval, max_batch_latency);
1039 }
1040
1041 static int change_pause_policy(int handle, int pause)
1042 {
1043         sensor_id_t sensor_id;
1044         sensor_rep prev_rep, cur_rep;
1045         int sensor_state;
1046         bool ret;
1047         int prev_state, prev_pause;
1048
1049         AUTOLOCK(lock);
1050
1051         retvm_if((pause < 0) || (pause >= SENSORD_PAUSE_END), -EINVAL,
1052                 "Invalid pause value : %d, handle: %d, %s, %s",
1053                 pause, handle, get_sensor_name(sensor_id), get_client_name());
1054
1055         if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state)||
1056                 !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
1057                 _E("client %s failed to get handle information", get_client_name());
1058                 return -EPERM;
1059         }
1060
1061         sensor_client_info::get_instance().get_sensor_rep(sensor_id, prev_rep);
1062         sensor_client_info::get_instance().get_sensor_params(handle, prev_state, prev_pause);
1063
1064         if (g_power_save_state) {
1065                 if ((pause & g_power_save_state) && (sensor_state == SENSOR_STATE_STARTED))
1066                         sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_PAUSED);
1067                 else if (!(pause & g_power_save_state) && (sensor_state == SENSOR_STATE_PAUSED))
1068                         sensor_client_info::get_instance().set_sensor_state(handle, SENSOR_STATE_STARTED);
1069         }
1070         sensor_client_info::get_instance().set_sensor_pause_policy(handle, pause);
1071
1072         sensor_client_info::get_instance().get_sensor_rep(sensor_id, cur_rep);
1073         ret =  change_sensor_rep(sensor_id, prev_rep, cur_rep);
1074
1075         if (!ret)
1076                 sensor_client_info::get_instance().set_sensor_pause_policy(handle, prev_pause);
1077
1078         return (ret ? OP_SUCCESS : OP_ERROR);
1079 }
1080
1081 static int change_axis_orientation(int handle, int axis_orientation)
1082 {
1083         sensor_event_listener::get_instance().set_sensor_axis(axis_orientation);
1084         return OP_SUCCESS;
1085 }
1086
1087 static int change_attribute_int(int handle, int attribute, int value)
1088 {
1089         sensor_id_t sensor_id;
1090         command_channel *cmd_channel;
1091         int client_id;
1092
1093         AUTOLOCK(lock);
1094
1095         if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
1096                 _E("client %s failed to get handle information", get_client_name());
1097                 return -EINVAL;
1098         }
1099
1100         if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
1101                 _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
1102                 return -EPERM;
1103         }
1104
1105         client_id = sensor_client_info::get_instance().get_client_id();
1106         retvm_if((client_id < 0), -EPERM,
1107                         "Invalid client id : %d, handle: %d, %s, %s",
1108                         client_id, handle, get_sensor_name(sensor_id), get_client_name());
1109
1110         if (!cmd_channel->cmd_set_attribute_int(attribute, value)) {
1111                 _E("Sending cmd_set_attribute_int(%d, %d) failed for %s",
1112                         client_id, value, get_client_name());
1113                 return -EPERM;
1114         }
1115
1116         sensor_client_info::get_instance().set_attribute(handle, attribute, value);
1117
1118         return OP_SUCCESS;
1119 }
1120
1121 API bool sensord_set_option(int handle, int option)
1122 {
1123         return (change_pause_policy(handle, CONVERT_OPTION_PAUSE_POLICY(option)) == OP_SUCCESS);
1124 }
1125
1126 API int sensord_set_attribute_int(int handle, int attribute, int value)
1127 {
1128         switch (attribute) {
1129         case SENSORD_ATTRIBUTE_PAUSE_POLICY:
1130                 return change_pause_policy(handle, value);
1131         case SENSORD_ATTRIBUTE_AXIS_ORIENTATION:
1132                 return change_axis_orientation(handle, value);
1133         default:
1134                 break;
1135         }
1136
1137         return change_attribute_int(handle, attribute, value);
1138 }
1139
1140 API int sensord_set_attribute_str(int handle, int attribute, const char *value, int value_len)
1141 {
1142         sensor_id_t sensor_id;
1143         command_channel *cmd_channel;
1144         int client_id;
1145
1146         AUTOLOCK(lock);
1147
1148         if (!sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
1149                 _E("Client %s failed to get handle information", get_client_name());
1150                 return -EINVAL;
1151         }
1152
1153         if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
1154                 _E("Client %s failed to get command channel for %s",
1155                         get_client_name(), get_sensor_name(sensor_id));
1156                 return -EPERM;
1157         }
1158
1159         retvm_if((value_len < 0) || (value == NULL), -EINVAL,
1160                         "Invalid value_len: %d, value: %#x, handle: %d, %s, %s",
1161                         value_len, value, handle, get_sensor_name(sensor_id), get_client_name());
1162
1163         client_id = sensor_client_info::get_instance().get_client_id();
1164         retvm_if((client_id < 0), -EPERM,
1165                         "Invalid client id : %d, handle: %d, %s, %s",
1166                         client_id, handle, get_sensor_name(sensor_id), get_client_name());
1167
1168         if (!cmd_channel->cmd_set_attribute_str(attribute, value, value_len)) {
1169                 _E("Sending cmd_set_attribute_str(%d, %d, %#x) failed for %s",
1170                         client_id, value_len, value, get_client_name());
1171                 return -EPERM;
1172         }
1173
1174         sensor_client_info::get_instance().set_attribute(handle, attribute, value, value_len);
1175
1176         return OP_SUCCESS;
1177 }
1178
1179 API bool sensord_send_sensorhub_data(int handle, const char *data, int data_len)
1180 {
1181         return (sensord_set_attribute_str(handle, 0, data, data_len) == OP_SUCCESS);
1182 }
1183
1184 API bool sensord_send_command(int handle, const char *command, int command_len)
1185 {
1186         return (sensord_set_attribute_str(handle, 0, command, command_len) == OP_SUCCESS);
1187 }
1188
1189 API bool sensord_get_data(int handle, unsigned int data_id, sensor_data_t* sensor_data)
1190 {
1191         sensor_id_t sensor_id;
1192         command_channel *cmd_channel;
1193         int sensor_state;
1194         int client_id;
1195
1196         retvm_if((!sensor_data), false, "sensor_data is NULL");
1197
1198         AUTOLOCK(lock);
1199
1200         if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state)||
1201                 !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
1202                 _E("client %s failed to get handle information", get_client_name());
1203                 return false;
1204         }
1205
1206         if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
1207                 _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
1208                 return false;
1209         }
1210
1211         client_id = sensor_client_info::get_instance().get_client_id();
1212         retvm_if((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
1213
1214         if (sensor_state != SENSOR_STATE_STARTED) {
1215                 _E("Sensor %s is not started for client %s with handle: %d, sensor_state: %d", get_sensor_name(sensor_id), get_client_name(), handle, sensor_state);
1216                 return false;
1217         }
1218
1219         if (!cmd_channel->cmd_get_data(data_id, sensor_data)) {
1220                 _E("cmd_get_data(%d, %d, %#x) failed for %s", client_id, data_id, sensor_data, get_client_name());
1221                 return false;
1222         }
1223
1224         return true;
1225 }
1226
1227 API bool sensord_flush(int handle)
1228 {
1229         sensor_id_t sensor_id;
1230         command_channel *cmd_channel;
1231         int sensor_state;
1232         int client_id;
1233
1234         AUTOLOCK(lock);
1235
1236         if (!sensor_client_info::get_instance().get_sensor_state(handle, sensor_state) ||
1237                 !sensor_client_info::get_instance().get_sensor_id(handle, sensor_id)) {
1238                 _E("client %s failed to get handle information", get_client_name());
1239                 return false;
1240         }
1241
1242         if (!sensor_client_info::get_instance().get_command_channel(sensor_id, &cmd_channel)) {
1243                 _E("client %s failed to get command channel for %s", get_client_name(), get_sensor_name(sensor_id));
1244                 return false;
1245         }
1246
1247         client_id = sensor_client_info::get_instance().get_client_id();
1248         retvm_if((client_id < 0), false, "Invalid client id : %d, handle: %d, %s, %s", client_id, handle, get_sensor_name(sensor_id), get_client_name());
1249
1250         if (sensor_state != SENSOR_STATE_STARTED) {
1251                 _E("Sensor %s is not started for client %s with handle: %d, sensor_state: %d", get_sensor_name(sensor_id), get_client_name(), handle, sensor_state);
1252                 return false;
1253         }
1254
1255         if (!cmd_channel->cmd_flush()) {
1256                 _E("cmd_flush() failed for %s", get_client_name());
1257                 return false;
1258         }
1259
1260         return true;
1261 }
1262
1263 API bool sensord_register_hub_event(int handle, unsigned int event_type, unsigned int interval, unsigned int max_batch_latency, sensorhub_cb_t cb, void *user_data)
1264 {
1265         return false;
1266 }
1267
1268 API bool sensord_set_passive_mode(int handle, bool passive)
1269 {
1270         if (!sensor_client_info::get_instance().set_passive_mode(handle, passive)) {
1271                 _E("Failed to set passive mode %d", passive);
1272                 return false;
1273         }
1274
1275         return true;
1276 }