#include <message.h>
#include <channel.h>
+#include "sensor_manager_channel_handler.h"
+
#define SIZE_STR_SENSOR_ALL 27
using namespace sensor;
m_client = new(std::nothrow) ipc::ipc_client(SENSOR_CHANNEL_PATH);
retvm_if(!m_client, false, "Failed to allocate memory");
- m_handler = new(std::nothrow) sensor_manager_handler(this);
+ m_handler = new(std::nothrow) channel_handler(this);
if (!m_handler) {
delete m_client;
m_client = NULL;
#include "sensor_internal.h"
#include "sensor_provider.h"
-#include "sensor_manager_handler.h"
namespace sensor {
void remove_sensor_removed_cb(sensord_removed_cb cb);
private:
- typedef std::vector<sensor_info> sensor_list_t;
+ class channel_handler;
bool init(void);
void deinit(void);
ipc::channel *m_channel;
ipc::event_loop m_loop;
std::atomic<bool> m_connected;
- sensor_manager_handler *m_handler;
+ channel_handler *m_handler;
- sensor_list_t m_sensors;
+ std::vector<sensor_info> m_sensors;
};
}
--- /dev/null
+/*
+ * 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_channel_handler.h"
+
+#include <sensor_log.h>
+#include <command_types.h>
+#include "sensor_manager.h"
+
+using namespace sensor;
+
+sensor_manager::channel_handler::channel_handler(sensor_manager *manager)
+: m_manager(manager)
+{
+}
+
+void sensor_manager::channel_handler::connected(ipc::channel *ch)
+{
+}
+
+void sensor_manager::channel_handler::disconnected(ipc::channel *ch)
+{
+ /* If channel->disconnect() is not explicitly called, it will be restored */
+ m_manager->restore();
+}
+
+void sensor_manager::channel_handler::read(ipc::channel *ch, ipc::message &msg)
+{
+ switch (msg.header()->type) {
+ case CMD_MANAGER_SENSOR_ADDED:
+ on_sensor_added(ch, msg);
+ break;
+ case CMD_MANAGER_SENSOR_REMOVED:
+ on_sensor_removed(ch, msg);
+ break;
+ }
+}
+
+void sensor_manager::channel_handler::read_complete(ipc::channel *ch)
+{
+}
+
+void sensor_manager::channel_handler::error_caught(ipc::channel *ch, int error)
+{
+}
+
+void sensor_manager::channel_handler::on_sensor_added(ipc::channel *ch, ipc::message &msg)
+{
+ ret_if(msg.header()->err < OP_SUCCESS);
+
+ sensor_info info;
+ info.clear();
+ info.deserialize(msg.body(), msg.size());
+
+ m_manager->add_sensor(info);
+
+ auto it = m_sensor_added_callbacks.begin();
+ while (it != m_sensor_added_callbacks.end()) {
+ it->first(info.get_uri().c_str(), it->second);
+ ++it;
+ }
+}
+
+void sensor_manager::channel_handler::on_sensor_removed(ipc::channel *ch, ipc::message &msg)
+{
+ ret_if(msg.header()->err < 0);
+ char uri[NAME_MAX] = {0, };
+
+ msg.disclose(uri);
+ m_manager->remove_sensor(uri);
+
+ auto it = m_sensor_removed_callbacks.begin();
+ while (it != m_sensor_removed_callbacks.end()) {
+ it->first(uri, it->second);
+ ++it;
+ }
+}
+
+void sensor_manager::channel_handler::add_sensor_added_cb(sensord_added_cb cb, void *user_data)
+{
+ m_sensor_added_callbacks.emplace(cb, user_data);
+}
+
+void sensor_manager::channel_handler::remove_sensor_added_cb(sensord_added_cb cb)
+{
+ m_sensor_added_callbacks.erase(cb);
+}
+
+void sensor_manager::channel_handler::add_sensor_removed_cb(sensord_removed_cb cb, void *user_data)
+{
+ m_sensor_removed_callbacks.emplace(cb, user_data);
+}
+
+void sensor_manager::channel_handler::remove_sensor_removed_cb(sensord_removed_cb cb)
+{
+ m_sensor_removed_callbacks.erase(cb);
+}
--- /dev/null
+/*
+ * 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_CHANNEL_HANDLER__
+#define __SENSOR_MANAGER_CHANNEL_HANDLER__
+
+#include <sensor_internal.h>
+#include <sensor_manager.h>
+#include <channel_handler.h>
+#include <map>
+
+namespace sensor {
+
+class sensor_manager::channel_handler : public ipc::channel_handler
+{
+public:
+ channel_handler(sensor_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);
+
+ void on_sensor_added(ipc::channel *ch, ipc::message &msg);
+ void on_sensor_removed(ipc::channel *ch, ipc::message &msg);
+
+ void add_sensor_added_cb(sensord_added_cb cb, void *user_data);
+ void remove_sensor_added_cb(sensord_added_cb cb);
+
+ void add_sensor_removed_cb(sensord_removed_cb cb, void *user_data);
+ void remove_sensor_removed_cb(sensord_removed_cb cb);
+
+private:
+ typedef std::map<sensord_added_cb, void *> sensor_added_cb_list_t;
+ typedef std::map<sensord_removed_cb, void *> sensor_removed_cb_list_t;
+
+ sensor_manager *m_manager;
+ sensor_added_cb_list_t m_sensor_added_callbacks;
+ sensor_removed_cb_list_t m_sensor_removed_callbacks;
+};
+
+}
+
+#endif /* __SENSOR_MANAGER_CHANNEL_HANDLER__ */
+++ /dev/null
-/*
- * 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_handler.h"
-
-#include <sensor_log.h>
-#include <command_types.h>
-#include "sensor_manager.h"
-
-using namespace sensor;
-
-sensor_manager_handler::sensor_manager_handler(sensor_manager *manager)
-: m_manager(manager)
-{
-}
-
-void sensor_manager_handler::connected(ipc::channel *ch)
-{
-}
-
-void sensor_manager_handler::disconnected(ipc::channel *ch)
-{
- /* If channel->disconnect() is not explicitly called, it will be restored */
- m_manager->restore();
-}
-
-void sensor_manager_handler::read(ipc::channel *ch, ipc::message &msg)
-{
- switch (msg.header()->type) {
- case CMD_MANAGER_SENSOR_ADDED:
- on_sensor_added(ch, msg);
- break;
- case CMD_MANAGER_SENSOR_REMOVED:
- on_sensor_removed(ch, msg);
- break;
- }
-}
-
-void sensor_manager_handler::read_complete(ipc::channel *ch)
-{
-}
-
-void sensor_manager_handler::error_caught(ipc::channel *ch, int error)
-{
-}
-
-void sensor_manager_handler::on_sensor_added(ipc::channel *ch, ipc::message &msg)
-{
- ret_if(msg.header()->err < OP_SUCCESS);
-
- sensor_info info;
- info.clear();
- info.deserialize(msg.body(), msg.size());
-
- m_manager->add_sensor(info);
-
- auto it = m_sensor_added_callbacks.begin();
- while (it != m_sensor_added_callbacks.end()) {
- it->first(info.get_uri().c_str(), it->second);
- ++it;
- }
-}
-
-void sensor_manager_handler::on_sensor_removed(ipc::channel *ch, ipc::message &msg)
-{
- ret_if(msg.header()->err < 0);
- char uri[NAME_MAX] = {0, };
-
- msg.disclose(uri);
- m_manager->remove_sensor(uri);
-
- auto it = m_sensor_removed_callbacks.begin();
- while (it != m_sensor_removed_callbacks.end()) {
- it->first(uri, it->second);
- ++it;
- }
-}
-
-void sensor_manager_handler::add_sensor_added_cb(sensord_added_cb cb, void *user_data)
-{
- m_sensor_added_callbacks.emplace(cb, user_data);
-}
-
-void sensor_manager_handler::remove_sensor_added_cb(sensord_added_cb cb)
-{
- m_sensor_added_callbacks.erase(cb);
-}
-
-void sensor_manager_handler::add_sensor_removed_cb(sensord_removed_cb cb, void *user_data)
-{
- m_sensor_removed_callbacks.emplace(cb, user_data);
-}
-
-void sensor_manager_handler::remove_sensor_removed_cb(sensord_removed_cb cb)
-{
- m_sensor_removed_callbacks.erase(cb);
-}
+++ /dev/null
-/*
- * 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_HANDLER__
-#define __SENSOR_MANAGER_HANDLER__
-
-#include <sensor_internal.h>
-#include <channel_handler.h>
-#include <map>
-
-namespace sensor {
-
-class sensor_manager;
-
-class sensor_manager_handler : public ipc::channel_handler
-{
-public:
- sensor_manager_handler(sensor_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);
-
- void on_sensor_added(ipc::channel *ch, ipc::message &msg);
- void on_sensor_removed(ipc::channel *ch, ipc::message &msg);
-
- void add_sensor_added_cb(sensord_added_cb cb, void *user_data);
- void remove_sensor_added_cb(sensord_added_cb cb);
-
- void add_sensor_removed_cb(sensord_removed_cb cb, void *user_data);
- void remove_sensor_removed_cb(sensord_removed_cb cb);
-
-private:
- typedef std::map<sensord_added_cb, void *> sensor_added_cb_list_t;
- typedef std::map<sensord_removed_cb, void *> sensor_removed_cb_list_t;
-
- sensor_manager *m_manager;
- sensor_added_cb_list_t m_sensor_added_callbacks;
- sensor_removed_cb_list_t m_sensor_removed_callbacks;
-};
-
-}
-
-#endif /* __SENSOR_MANAGER_HANDLER__ */
#include <ipc_client.h>
#include <command_types.h>
-#include "sensor_provider_handler.h"
+#include "sensor_provider_channel_handler.h"
using namespace sensor;
m_client = new(std::nothrow) ipc::ipc_client(SENSOR_CHANNEL_PATH);
retvm_if(!m_client, false, "Failed to allocate memory");
- m_handler = new(std::nothrow) sensor_provider_handler(this);
+ m_handler = new(std::nothrow) channel_handler(this);
if (!m_handler) {
delete m_client;
return false;
#include <map>
#include <atomic>
-#include "sensor_provider_handler.h"
-
namespace sensor {
class sensor_provider {
int publish(sensor_data_t *data, int len);
private:
+ class channel_handler;
+
bool init(const char *uri);
void deinit(void);
ipc::ipc_client *m_client;
ipc::channel *m_channel;
ipc::event_loop m_loop;
- sensor_provider_handler *m_handler;
+ channel_handler *m_handler;
std::atomic<bool> m_connected;
};
--- /dev/null
+/*
+ * 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_provider_channel_handler.h"
+
+#include <command_types.h>
+#include <sensor_log.h>
+#include "sensor_provider.h"
+
+using namespace sensor;
+
+sensor_provider::channel_handler::channel_handler(sensor_provider *provider)
+: m_provider(provider)
+, m_start_cb(NULL)
+, m_stop_cb(NULL)
+, m_set_interval_cb(NULL)
+, m_start_user_data(NULL)
+, m_stop_user_data(NULL)
+, m_set_interval_user_data(NULL)
+{
+}
+
+void sensor_provider::channel_handler::connected(ipc::channel *ch)
+{
+ _I("Connected");
+}
+
+void sensor_provider::channel_handler::disconnected(ipc::channel *ch)
+{
+ /* TODO */
+ /* m_provider->restore(); */
+}
+
+void sensor_provider::channel_handler::read(ipc::channel *ch, ipc::message &msg)
+{
+ switch (msg.type()) {
+ case CMD_PROVIDER_START:
+ m_start_cb(m_provider, m_start_user_data);
+ break;
+ case CMD_PROVIDER_STOP:
+ m_stop_cb(m_provider, m_stop_user_data);
+ break;
+ case CMD_PROVIDER_ATTR_INT:
+ cmd_provider_attr_int_t buf;
+ msg.disclose((char *)&buf);
+
+ if (buf.attribute == SENSORD_ATTRIBUTE_INTERVAL)
+ m_set_interval_cb(m_provider, buf.value, m_set_interval_user_data);
+ break;
+ }
+}
+
+void sensor_provider::channel_handler::read_complete(ipc::channel *ch)
+{
+}
+
+void sensor_provider::channel_handler::error_caught(ipc::channel *ch, int error)
+{
+}
+
+void sensor_provider::channel_handler::set_start_cb(sensord_provider_start_cb cb, void *user_data)
+{
+ m_start_cb = cb;
+ m_start_user_data = user_data;
+}
+
+void sensor_provider::channel_handler::set_stop_cb(sensord_provider_stop_cb cb, void *user_data)
+{
+ m_stop_cb = cb;
+ m_stop_user_data = user_data;
+}
+
+void sensor_provider::channel_handler::set_interval_cb(sensord_provider_set_interval_cb cb, void *user_data)
+{
+ m_set_interval_cb = cb;
+ m_set_interval_user_data = user_data;
+}
--- /dev/null
+/*
+ * 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_PROVIDER_CHANNEL_HANDLER__
+#define __SENSOR_PROVIDER_CHANNEL_HANDLER__
+
+#include <channel_handler.h>
+#include <sensor_internal.h>
+#include "sensor_provider.h"
+
+namespace sensor {
+
+class sensor_provider::channel_handler : public ipc::channel_handler
+{
+public:
+ channel_handler(sensor_provider *provider);
+
+ 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);
+
+ void set_start_cb(sensord_provider_start_cb cb, void *user_data);
+ void set_stop_cb(sensord_provider_stop_cb cb, void *user_data);
+ void set_interval_cb(sensord_provider_set_interval_cb cb, void *user_data);
+
+private:
+ sensor_provider *m_provider;
+
+ sensord_provider_start_cb m_start_cb;
+ sensord_provider_stop_cb m_stop_cb;
+ sensord_provider_set_interval_cb m_set_interval_cb;
+
+ void *m_start_user_data;
+ void *m_stop_user_data;
+ void *m_set_interval_user_data;
+};
+
+}
+
+#endif /* __SENSOR_PROVIDER_CHANNEL_HANDLER__ */
+++ /dev/null
-/*
- * 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_provider_handler.h"
-
-#include <command_types.h>
-#include <sensor_log.h>
-#include "sensor_provider.h"
-
-using namespace sensor;
-
-sensor_provider_handler::sensor_provider_handler(sensor_provider *provider)
-: m_provider(provider)
-, m_start_cb(NULL)
-, m_stop_cb(NULL)
-, m_set_interval_cb(NULL)
-, m_start_user_data(NULL)
-, m_stop_user_data(NULL)
-, m_set_interval_user_data(NULL)
-{
-}
-
-void sensor_provider_handler::connected(ipc::channel *ch)
-{
- _I("Connected");
-}
-
-void sensor_provider_handler::disconnected(ipc::channel *ch)
-{
- /* TODO */
- /* m_provider->restore(); */
-}
-
-void sensor_provider_handler::read(ipc::channel *ch, ipc::message &msg)
-{
- switch (msg.type()) {
- case CMD_PROVIDER_START:
- m_start_cb(m_provider, m_start_user_data);
- break;
- case CMD_PROVIDER_STOP:
- m_stop_cb(m_provider, m_stop_user_data);
- break;
- case CMD_PROVIDER_ATTR_INT:
- cmd_provider_attr_int_t buf;
- msg.disclose((char *)&buf);
-
- if (buf.attribute == SENSORD_ATTRIBUTE_INTERVAL)
- m_set_interval_cb(m_provider, buf.value, m_set_interval_user_data);
- break;
- }
-}
-
-void sensor_provider_handler::read_complete(ipc::channel *ch)
-{
-}
-
-void sensor_provider_handler::error_caught(ipc::channel *ch, int error)
-{
-}
-
-void sensor_provider_handler::set_start_cb(sensord_provider_start_cb cb, void *user_data)
-{
- m_start_cb = cb;
- m_start_user_data = user_data;
-}
-
-void sensor_provider_handler::set_stop_cb(sensord_provider_stop_cb cb, void *user_data)
-{
- m_stop_cb = cb;
- m_stop_user_data = user_data;
-}
-
-void sensor_provider_handler::set_interval_cb(sensord_provider_set_interval_cb cb, void *user_data)
-{
- m_set_interval_cb = cb;
- m_set_interval_user_data = user_data;
-}
+++ /dev/null
-/*
- * 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_PROVIDER_HANDLER__
-#define __SENSOR_PROVIDER_HANDLER__
-
-#include <sensor_internal.h>
-#include <channel_handler.h>
-
-namespace sensor {
-
-class sensor_provider;
-
-class sensor_provider_handler : public ipc::channel_handler
-{
-public:
- sensor_provider_handler(sensor_provider *provider);
-
- 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);
-
- void set_start_cb(sensord_provider_start_cb cb, void *user_data);
- void set_stop_cb(sensord_provider_stop_cb cb, void *user_data);
- void set_interval_cb(sensord_provider_set_interval_cb cb, void *user_data);
-
-private:
- sensor_provider *m_provider;
-
- sensord_provider_start_cb m_start_cb;
- sensord_provider_stop_cb m_stop_cb;
- sensord_provider_set_interval_cb m_set_interval_cb;
-
- void *m_start_user_data;
- void *m_stop_user_data;
- void *m_set_interval_user_data;
-};
-
-}
-
-#endif /* __SENSOR_PROVIDER_HANDLER__ */