sensord: api: add skeleton code of internal apis 24/123224/3
authorkibak.yoon <kibak.yoon@samsung.com>
Wed, 5 Apr 2017 04:06:01 +0000 (13:06 +0900)
committerKibak Yoon <kibak.yoon@samsung.com>
Wed, 5 Apr 2017 05:08:28 +0000 (22:08 -0700)
- sensor_manager can stores and manages all of sensors.
- sensor_listener can listen sensor event and modify sensor configuation
  (interval, option, batch_latency, attributes and so on)

- rename client.cpp to sensor_internal.cpp

Change-Id: I15b74b777ba70d9c7b7d7a2c597fabf91f259b2c
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/client/sensor_internal.cpp [moved from src/client/client.cpp with 100% similarity]
src/client/sensor_listener.cpp [new file with mode: 0644]
src/client/sensor_listener.h [new file with mode: 0644]
src/client/sensor_manager.cpp [new file with mode: 0644]
src/client/sensor_manager.h [new file with mode: 0644]

diff --git a/src/client/sensor_listener.cpp b/src/client/sensor_listener.cpp
new file mode 100644 (file)
index 0000000..83145ef
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "sensor_listener.h"
+
+#include <channel_handler.h>
+#include <sensor_log.h>
+#include <sensor_types.h>
+#include <command_types.h>
+#include <ipc_client.h>
+
+using namespace sensor;
+
+class listener_handler : public ipc::channel_handler
+{
+public:
+       listener_handler(sensor_listener *listener)
+       : m_listener(listener)
+       {}
+       void connected(ipc::channel *ch) {}
+       void disconnected(ipc::channel *ch) {}
+       void read(ipc::channel *ch, ipc::message &msg) {}
+       void read_complete(ipc::channel *ch) {}
+       void error_caught(ipc::channel *ch, int error) {}
+
+private:
+       sensor_listener *m_listener;
+};
+
+sensor_listener::sensor_listener(sensor_t sensor)
+: m_id(0)
+, m_sensor(reinterpret_cast<sensor_info *>(sensor))
+, m_client(NULL)
+, m_channel(NULL)
+, m_handler(NULL)
+, m_evt_handler(NULL)
+, m_acc_handler(NULL)
+, m_connected(false)
+, m_started(false)
+{
+       init();
+}
+
+sensor_listener::~sensor_listener()
+{
+       deinit();
+}
+
+bool sensor_listener::init(void)
+{
+       return true;
+}
+
+void sensor_listener::deinit(void)
+{
+}
+
+int sensor_listener::get_id(void)
+{
+       return m_id;
+}
+
+sensor_t sensor_listener::get_sensor(void)
+{
+       return static_cast<sensor_t>(m_sensor);
+}
+
+void sensor_listener::restore(void)
+{
+       _D("Restored listener[%d]", get_id());
+}
+
+bool sensor_listener::connect(void)
+{
+       _I("Listener ID[%d]", get_id());
+
+       return true;
+}
+
+void sensor_listener::disconnect(void)
+{
+       _I("Disconnected[%d]", get_id());
+}
+
+bool sensor_listener::is_connected(void)
+{
+       return m_connected.load();
+}
+
+ipc::channel_handler *sensor_listener::get_event_handler(void)
+{
+       return m_evt_handler;
+}
+
+void sensor_listener::set_event_handler(ipc::channel_handler *handler)
+{
+       m_evt_handler = handler;
+}
+
+void sensor_listener::unset_event_handler(void)
+{
+       delete m_evt_handler;
+       m_evt_handler = NULL;
+}
+
+ipc::channel_handler *sensor_listener::get_accuracy_handler(void)
+{
+       return m_acc_handler;
+}
+
+void sensor_listener::set_accuracy_handler(ipc::channel_handler *handler)
+{
+       m_acc_handler = handler;
+}
+
+void sensor_listener::unset_accuracy_handler(void)
+{
+       m_acc_handler = NULL;
+}
+
+int sensor_listener::start(void)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::stop(void)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::get_interval(void)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::get_max_batch_latency(void)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::get_pause_policy(void)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::get_passive_mode(void)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::set_interval(unsigned int interval)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::set_max_batch_latency(unsigned int max_batch_latency)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::set_passive_mode(bool passive)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::flush(void)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::set_attribute(int attribute, int value)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::set_attribute(int attribute, const char *value, int len)
+{
+       return OP_ERROR;
+}
+
+int sensor_listener::get_sensor_data(sensor_data_t *data)
+{
+       return OP_ERROR;
+}
+
diff --git a/src/client/sensor_listener.h b/src/client/sensor_listener.h
new file mode 100644 (file)
index 0000000..ea30092
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SENSOR_LISTENER_H__
+#define __SENSOR_LISTENER_H__
+
+#include <ipc_client.h>
+#include <channel.h>
+#include <channel_handler.h>
+#include <event_loop.h>
+#include <sensor_info.h>
+#include <sensor_types.h>
+#include <map>
+#include <atomic>
+
+namespace sensor {
+
+class sensor_listener {
+public:
+       sensor_listener(sensor_t sensor);
+       virtual ~sensor_listener();
+
+       int get_id(void);
+       sensor_t get_sensor(void);
+
+       ipc::channel_handler *get_event_handler(void);
+       ipc::channel_handler *get_accuracy_handler(void);
+
+       /* TODO: modify the listener so that it can register multiple handlers(1:n) */
+       void set_event_handler(ipc::channel_handler *handler);
+       void set_accuracy_handler(ipc::channel_handler *handler);
+
+       void unset_event_handler(void);
+       void unset_accuracy_handler(void);
+
+       int start(void);
+       int stop(void);
+
+       int get_interval(void);
+       int get_max_batch_latency(void);
+       int get_pause_policy(void);
+       int get_passive_mode(void);
+
+       int set_interval(unsigned int interval);
+       int set_max_batch_latency(unsigned int max_batch_latency);
+       int set_passive_mode(bool passive);
+       int set_attribute(int attribute, int value);
+       int set_attribute(int attribute, const char *value, int len);
+
+       int get_sensor_data(sensor_data_t *data);
+       int flush(void);
+
+       void restore(void);
+
+private:
+       bool init(void);
+       void deinit(void);
+
+       bool connect(void);
+       void disconnect(void);
+       bool is_connected(void);
+
+       int m_id;
+       sensor_info *m_sensor;
+
+       ipc::ipc_client *m_client;
+       ipc::channel *m_channel;
+       ipc::channel_handler *m_handler;
+       ipc::channel_handler *m_evt_handler;
+       ipc::channel_handler *m_acc_handler;
+       ipc::event_loop m_loop;
+       std::atomic<bool> m_connected;
+       std::atomic<bool> m_started;
+       std::map<int, int> m_attributes;
+};
+
+}
+
+#endif /* __SENSOR_LISTENER_H__ */
diff --git a/src/client/sensor_manager.cpp b/src/client/sensor_manager.cpp
new file mode 100644 (file)
index 0000000..3a4742b
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "sensor_manager.h"
+
+#include <sensor_log.h>
+#include <sensor_info.h>
+#include <sensor_utils.h>
+#include <command_types.h>
+#include <ipc_client.h>
+#include <message.h>
+#include <channel.h>
+
+using namespace sensor;
+
+class manager_handler : public ipc::channel_handler
+{
+public:
+       manager_handler(sensor_manager *manager)
+       : m_manager(manager)
+       {}
+       void connected(ipc::channel *ch) {}
+       void disconnected(ipc::channel *ch) {}
+       void read(ipc::channel *ch, ipc::message &msg) {}
+       void read_complete(ipc::channel *ch) {}
+       void error_caught(ipc::channel *ch, int error) {}
+
+private:
+       sensor_manager *m_manager;
+};
+
+sensor_manager::sensor_manager()
+: m_client(NULL)
+, m_handler(NULL)
+, m_channel(NULL)
+, m_connected(false)
+{
+       init();
+}
+
+sensor_manager::~sensor_manager()
+{
+       deinit();
+}
+
+int sensor_manager::get_sensor(sensor_type_t type, sensor_t *sensor)
+{
+       return OP_ERROR;
+}
+
+int sensor_manager::get_sensors(sensor_type_t type, sensor_t **list, int *count)
+{
+       return OP_ERROR;
+}
+
+int sensor_manager::get_sensor(const char *uri, sensor_t *sensor)
+{
+       return OP_ERROR;
+}
+
+int sensor_manager::get_sensors(const char *uri, sensor_t **list, int *count)
+{
+       return OP_ERROR;
+}
+
+bool sensor_manager::is_supported(sensor_t sensor)
+{
+       return false;
+}
+
+bool sensor_manager::is_supported(const char *uri)
+{
+       return false;
+}
+
+bool sensor_manager::init(void)
+{
+       return true;
+}
+
+void sensor_manager::deinit(void)
+{
+}
+
+bool sensor_manager::connect_channel(void)
+{
+       _D("Connected");
+       return true;
+}
+
+bool sensor_manager::connect(void)
+{
+       return false;
+}
+
+void sensor_manager::disconnect(void)
+{
+       _D("Disconnected");
+}
+
+bool sensor_manager::is_connected(void)
+{
+       return m_connected.load();
+}
+
+void sensor_manager::restore(void)
+{
+       _D("Restored manager");
+}
+
+void sensor_manager::decode_sensors(const char *buf, std::vector<sensor_info> &infos)
+{
+       int count = 0;
+       _D("Sensor count : %d", count);
+}
+
+bool sensor_manager::get_sensors_internal(void)
+{
+       return true;
+}
+
+sensor_info *sensor_manager::get_info(const char *uri)
+{
+       return NULL;
+}
+
+std::vector<sensor_info *> sensor_manager::get_infos(const char *uri)
+{
+       std::vector<sensor_info *> infos;
+       return infos;
+}
+
diff --git a/src/client/sensor_manager.h b/src/client/sensor_manager.h
new file mode 100644 (file)
index 0000000..35ae863
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * sensord
+ *
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __SENSOR_MANAGER_H__
+#define __SENSOR_MANAGER_H__
+
+#include <channel.h>
+#include <sensor_info.h>
+#include <ipc_client.h>
+#include <event_loop.h>
+#include <vector>
+#include <atomic>
+
+#include "sensor_internal.h"
+
+namespace sensor {
+
+class sensor_manager {
+public:
+       sensor_manager();
+       virtual ~sensor_manager();
+
+       bool connect(void);
+       void disconnect(void);
+
+       int get_sensor(sensor_type_t type, sensor_t *sensor);
+       int get_sensors(sensor_type_t type, sensor_t **list, int *count);
+       int get_sensor(const char *uri, sensor_t *sensor);
+       int get_sensors(const char *uri, sensor_t **list, int *count);
+
+       bool is_supported(sensor_t sensor);
+       bool is_supported(const char *uri);
+
+       void restore(void);
+
+       /* TODO: register sensor_provider by using manager */
+       /* int register_sensor(sensor_provider *provider); */
+       /* int unregister_sensor(const char *uri) */
+
+private:
+       typedef std::vector<sensor_info> sensor_infos_t;
+
+       bool init(void);
+       void deinit(void);
+
+       bool connect_channel(void);
+       bool is_connected(void);
+
+       void decode_sensors(const char *buf, std::vector<sensor_info> &infos);
+       bool get_sensors_internal(void);
+
+       sensor_info *get_info(const char *uri);
+       std::vector<sensor_info *> get_infos(const char *uri);
+
+       ipc::ipc_client *m_client;
+       ipc::channel_handler *m_handler;
+       ipc::channel *m_channel;
+       ipc::event_loop m_loop;
+       std::atomic<bool> m_connected;
+
+       sensor_infos_t m_infos;
+};
+
+}
+
+#endif /* __SENSOR_MANAGER_H__ */