- add sensor information structure(sensor_info2_t)..
Change-Id: I9daca248bc3671b77c3f37c8547575a9ab2903f5
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
--- /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 __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__ */
--- /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 __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__ */
--- /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 __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__ */
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,
+++ /dev/null
-/*
- * 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()
-{
-}
-
+++ /dev/null
-/*
- * 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_ */
#include <ipc_server.h>
#include <sensor_manager.h>
#include <server_channel_handler.h>
-#include <physical_sensor.h>
#include <atomic>
namespace sensor {
+++ /dev/null
-/*
- * 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()
-{
-}
+++ /dev/null
-/*
- * 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_ */
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;
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);
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);