sensord: add physical_sensor/fusion_sensor/external_sensor interfaces 01/123601/4
authorkibak.yoon <kibak.yoon@samsung.com>
Thu, 6 Apr 2017 07:58:05 +0000 (16:58 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Thu, 6 Apr 2017 09:38:03 +0000 (18:38 +0900)
- add sensor information structure(sensor_info2_t)..

Change-Id: I9daca248bc3671b77c3f37c8547575a9ab2903f5
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
include/external_sensor.h [new file with mode: 0644]
include/fusion_sensor.h [new file with mode: 0644]
include/physical_sensor.h [new file with mode: 0644]
include/sensor_types.h
src/server/physical_sensor.cpp [deleted file]
src/server/physical_sensor.h [deleted file]
src/server/server.h
src/server/virtual_sensor.cpp [deleted file]
src/server/virtual_sensor.h [deleted file]
src/shared/sensor_info.cpp
src/shared/sensor_info.h

diff --git a/include/external_sensor.h b/include/external_sensor.h
new file mode 100644 (file)
index 0000000..d34cf96
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * 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 __EXTERNAL_SENSOR_H__
+#define __EXTERNAL_SENSOR_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <sensor_types.h>
+#include <string>
+
+#ifndef EXTERNAL_SENSOR_VERSION
+#define EXTERNAL_SENSOR_VERSION(maj, min) \
+               ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF))
+#endif
+
+#ifndef OP_SUCCESS
+#define OP_SUCCESS 0
+#endif
+#ifndef OP_ERROR
+#define OP_ERROR   -1
+#endif
+#ifndef OP_DEFAULT
+#define OP_DEFAULT 1
+#endif
+
+/*
+ * Create sensor
+ */
+typedef void *external_sensor_t;
+typedef int (*create_external_t)(external_sensor_t **sensors);
+
+typedef void *observer_h;
+
+/*
+ * Sensor event notifier
+ * External Sensor has to call notify() function if data is ready.
+ */
+class sensor_notifier {
+public:
+       virtual ~sensor_notifier() {}
+
+       virtual int notify(void) = 0;
+};
+
+/*
+ * Sensor interface
+ */
+class external_sensor {
+public:
+       virtual ~external_sensor() {}
+
+       inline uint32_t get_version(void) { return EXTERNAL_SENSOR_VERSION(1, 0); }
+
+       virtual int get_sensors(const sensor_info2_t **sensors) = 0;
+       virtual void set_notifier(sensor_notifier *notifier) = 0;
+       virtual int get_data(sensor_data_t **data, int *len) = 0;
+
+       virtual int start(observer_h ob)
+       {
+               return OP_DEFAULT;
+       }
+;
+       virtual int stop(observer_h ob)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_interval(observer_h ob, int32_t &interval)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_batch_latency(observer_h ob, int32_t &latency)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_attribute(observer_h ob, int32_t attr, int32_t value)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_attribute(observer_h ob, int32_t attr, const char *value, int len)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int flush(observer_h ob)
+       {
+               return OP_DEFAULT;
+       }
+};
+
+#endif /* __EXTERNAL_SENSOR_H__ */
diff --git a/include/fusion_sensor.h b/include/fusion_sensor.h
new file mode 100644 (file)
index 0000000..6fa6d09
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * 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 __FUSION_SENSOR_H__
+#define __FUSION_SENSOR_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <sensor_types.h>
+#include <vector>
+#include <string>
+
+#ifndef FUSION_SENSOR_VERSION
+#define FUSION_SENSOR_VERSION(maj, min) \
+               ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF))
+#endif
+
+#ifndef OP_SUCCESS
+#define OP_SUCCESS 0
+#endif
+#ifndef OP_ERROR
+#define OP_ERROR   -1
+#endif
+#ifndef OP_DEFAULT
+#define OP_DEFAULT 1
+#endif
+
+/*
+ * Create sensor
+ */
+typedef void *fusion_sensor_t;
+typedef int (*create_fusion_t)(fusion_sensor_t **sensors);
+
+typedef void *observer_h;
+
+/*
+ * Sensor interface
+ */
+class fusion_sensor {
+public:
+       virtual ~fusion_sensor() {}
+
+       inline uint32_t get_version(void) { return FUSION_SENSOR_VERSION(1, 0); }
+
+       virtual int get_sensors(const sensor_info2_t **sensors) = 0;
+       virtual void get_required_sensors(std::vector<std::string> &sensors) = 0;
+
+       /* if update() returns positive value, then get_data() is called */
+       virtual int update(const char *uri, sensor_data_t *data, int len) = 0;
+       virtual int get_data(sensor_data_t **data, int *len) = 0;
+
+       virtual int start(observer_h ob)
+       {
+               return OP_DEFAULT;
+       }
+;
+       virtual int stop(observer_h ob)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_interval(observer_h ob, int32_t &interval)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_batch_latency(observer_h ob, int32_t &latency)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_attribute(observer_h ob, int32_t attr, int32_t value)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_attribute(observer_h ob, int32_t attr, const char *value, int len)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int flush(observer_h ob)
+       {
+               return OP_DEFAULT;
+       }
+};
+
+#endif /* __FUSION_SENSOR_H__ */
diff --git a/include/physical_sensor.h b/include/physical_sensor.h
new file mode 100644 (file)
index 0000000..6009167
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * 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 __PHYSICAL_SENSOR_H__
+#define __PHYSICAL_SENSOR_H__
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <string>
+#include <sensor_types.h>
+
+#ifndef SENSOR_VERSION
+#define PHYSICAL_SENSOR_VERSION(maj, min) \
+               ((((maj) & 0xFFFF) << 24) | ((min) & 0xFFFF))
+#endif
+
+#ifndef OP_SUCCESS
+#define OP_SUCCESS 1
+#endif
+#ifndef OP_ERROR
+#define OP_ERROR   -1
+#endif
+#ifndef OP_DEFAULT
+#define OP_DEFAULT 1
+#endif
+
+/*
+ * Create sensor
+ */
+typedef void *physical_sensor_t;
+typedef int (*create_physical_t)(physical_sensor_t **sensors);
+
+typedef void *observer_h;
+
+/*
+ * Sensor interface
+ */
+class physical_sensor {
+public:
+       virtual ~physical_sensor() {}
+
+       inline uint32_t get_version(void) { return PHYSICAL_SENSOR_VERSION(1, 0); }
+
+       /* TODO */
+       virtual std::string get_privilege(void) { return ""; }
+
+       virtual int start(observer_h ob) = 0;
+       virtual int stop(observer_h ob) = 0;
+       virtual int set_interval(observer_h ob, uint32_t interval)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_batch_latency(observer_h ob, uint32_t latency)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_attribute(observer_h ob, int32_t attr, int32_t value)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int set_attribute(observer_h ob, int32_t attr, const char *value, int len)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int flush(observer_h ob)
+       {
+               return OP_DEFAULT;
+       }
+
+       virtual int on_event(sensor_data_t *data, int32_t len, int32_t remains)
+       {
+               return OP_DEFAULT;
+       }
+};
+
+#endif /* __PHYSICAL_SENSOR_H__ */
index 2253a29f4d0da5591f1af9ea8abc755344d67bdf..3da9cfc05de685886e9bdd598a4b21114473bce8 100644 (file)
@@ -164,6 +164,20 @@ typedef enum sensor_type_t {
        CUSTOM_SENSOR = 0X9000,
 } sensor_type_t;
 
+typedef struct sensor_info2_t {
+       uint32_t id;
+       sensor_type_t type;
+       const char *uri;
+       const char *vendor;
+       float min_range;
+       float max_range;
+       float resolution;
+       int min_interval;
+       int max_batch_count;
+       bool wakeup_supported;
+       const char *privilege;
+       void *reserved[8];
+} sensor_info2_t;
 
 typedef enum sensor_permission_t {
        SENSOR_PERMISSION_NONE = 0,
diff --git a/src/server/physical_sensor.cpp b/src/server/physical_sensor.cpp
deleted file mode 100644 (file)
index f1943f6..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 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 <physical_sensor.h>
-
-physical_sensor::physical_sensor()
-{
-}
-
-physical_sensor::~physical_sensor()
-{
-}
-
diff --git a/src/server/physical_sensor.h b/src/server/physical_sensor.h
deleted file mode 100644 (file)
index 669bbeb..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 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 _PHYSICAL_SENSOR_H_
-#define _PHYSICAL_SENSOR_H_
-
-class physical_sensor {
-public:
-       physical_sensor();
-       virtual ~physical_sensor();
-};
-
-#endif /* _PHYSICAL_SENSOR_H_ */
index b8bb2f64f595c9fe9bbe73bc692ed7e0f3bd205d..98d99c1473d18a60531f7f185f812badac55e1d8 100644 (file)
@@ -24,7 +24,6 @@
 #include <ipc_server.h>
 #include <sensor_manager.h>
 #include <server_channel_handler.h>
-#include <physical_sensor.h>
 #include <atomic>
 
 namespace sensor {
diff --git a/src/server/virtual_sensor.cpp b/src/server/virtual_sensor.cpp
deleted file mode 100644 (file)
index 59546b6..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 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 "virtual_sensor.h"
-
-virtual_sensor::virtual_sensor()
-{
-}
-
-virtual_sensor::~virtual_sensor()
-{
-}
diff --git a/src/server/virtual_sensor.h b/src/server/virtual_sensor.h
deleted file mode 100644 (file)
index 745a0b4..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * sensord
- *
- * Copyright (c) 2014 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 _VIRTUAL_SENSOR_H_
-#define _VIRTUAL_SENSOR_H_
-
-class virtual_sensor {
-public:
-       virtual_sensor();
-       virtual ~virtual_sensor();
-};
-
-#endif /* _VIRTUAL_SENSOR_H_ */
index f634c501460abd2105f3dcb93ac7435fa3c10698..808c07f93cf976a64d0768a816726690f20166f6 100644 (file)
@@ -81,6 +81,31 @@ sensor_info::sensor_info(const sensor_info_t &info)
        set_permission(SENSOR_PERMISSION_STANDARD);
 }
 
+sensor_info::sensor_info(const sensor_info2_t &info)
+{
+       std::string uri(info.uri);
+       std::size_t found = uri.find_last_of("/\\");
+
+       set_type(info.type);
+       set_type_uri(uri.substr(0, found).c_str());
+       set_uri(uri.c_str());
+       set_model(uri.substr(found + 1, uri.length()).c_str());
+       set_vendor(info.vendor);
+       set_min_range(info.min_range);
+       set_max_range(info.max_range);
+       set_resolution(info.resolution);
+       set_min_interval(info.min_interval);
+       set_max_batch_count(info.max_batch_count);
+       set_wakeup_supported(info.wakeup_supported);
+
+       /* TODO : store string just itself */
+       std::string privilege = info.privilege;
+       if (privilege == "http://tizen.org/privilege/healthinfo")
+               set_permission(SENSOR_PERMISSION_HEALTH_INFO);
+       else
+               set_permission(SENSOR_PERMISSION_STANDARD);
+}
+
 sensor_type_t sensor_info::get_type(void)
 {
        return m_type;
@@ -245,7 +270,7 @@ void sensor_info::deserialize(const char *data, int data_len)
 void sensor_info::show(void)
 {
        _I("Type = %s", m_type_uri.c_str());
-       _I("Name = %s", m_uri.c_str());
+       _I("URI = %s", m_uri.c_str());
        _I("Model = %s", m_model.c_str());
        _I("Vendor = %s", m_vendor.c_str());
        _I("Min_range = %f", m_min_range);
index 4fbabe82d4fc386b46d7021f1d79d551c7d2e844..93ae3aa8121a767a94b750cde7cfadb2bb7e9394 100644 (file)
@@ -37,6 +37,7 @@ public:
        sensor_info();
        sensor_info(const sensor_info &info);
        sensor_info(const sensor_info_t &info);
+       sensor_info(const sensor_info2_t &info);
 
        /* TODO: it would be better to get_type() returns type(URI) */
        sensor_type_t get_type(void);