From: kibak.yoon Date: Tue, 12 Apr 2016 15:30:35 +0000 (+0900) Subject: sensord: declare sensor types by using macro for converting type to X-Git-Tag: accepted/tizen/common/20160427.053748^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0484ca3600234e0cf9a4e1a0bb38aeec00264fdf;p=platform%2Fcore%2Fsystem%2Fsensord.git sensord: declare sensor types by using macro for converting type to string - added macros in enum_factory.h - DECLARE_ENUM - DECLARE_ENUM_UTIL - GENERATE_ENUM_UTIL - although it is hard to understand, it can reduce so many duplicated codes. Change-Id: Ice4436e5d232612e09e67aa9fdab4c2ac30a4ba4 Signed-off-by: kibak.yoon --- diff --git a/src/shared/enum_factory.h b/src/shared/enum_factory.h new file mode 100644 index 0000000..e67d71b --- /dev/null +++ b/src/shared/enum_factory.h @@ -0,0 +1,47 @@ +/* + * sensord + * + * Copyright (c) 2016 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 _ENUM_FACTORY_H_ +#define _ENUM_FACTORY_H_ + +#define ENUM_SENSOR(name) name, +#define ENUM_SENSOR_VALUE(name, assign) name = (assign), + +#define ENUM_CASE(name) case (name): return #name; +#define ENUM_CASE_VALUE(name, assign) ENUM_CASE(name) + +#define DECLARE_SENSOR_ENUM(ENUM_TYPE, ENUM_DEF) \ + typedef enum ENUM_TYPE { \ + ENUM_DEF(ENUM_SENSOR, ENUM_SENSOR_VALUE) \ + } ENUM_TYPE; + +#define DECLARE_SENSOR_ENUM_UTIL_NS(ENUM_TYPE) \ + namespace util_##ENUM_TYPE { \ + const char *get_string(ENUM_TYPE type); \ + }; + +#define DECLARE_SENSOR_ENUM_UTIL(ENUM_TYPE, ENUM_DEF) \ + const char *util_##ENUM_TYPE::get_string(ENUM_TYPE type) { \ + switch (type) { \ + ENUM_DEF(ENUM_CASE, ENUM_CASE_VALUE) \ + } \ + return "UNKNOWN"; \ + } + +#endif /* _ENUM_FACTORY_H_ */ diff --git a/src/shared/sensor_types.cpp b/src/shared/sensor_types.cpp new file mode 100644 index 0000000..084e6b8 --- /dev/null +++ b/src/shared/sensor_types.cpp @@ -0,0 +1,22 @@ +/* + * sensord + * + * Copyright (c) 2016 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_types.h" + +DECLARE_SENSOR_ENUM_UTIL(sensor_type_t, SENSOR_TYPE) diff --git a/src/shared/sensor_types.h b/src/shared/sensor_types.h index 1bf3b67..6667684 100644 --- a/src/shared/sensor_types.h +++ b/src/shared/sensor_types.h @@ -20,72 +20,76 @@ #ifndef _SENSOR_TYPES_H_ #define _SENSOR_TYPES_H_ +#include "enum_factory.h" + #ifdef __cplusplus extern "C" { #endif -typedef enum { - UNKNOWN_SENSOR = -2, - ALL_SENSOR = -1, - ACCELEROMETER_SENSOR, - GRAVITY_SENSOR, - LINEAR_ACCEL_SENSOR, - GEOMAGNETIC_SENSOR, - ROTATION_VECTOR_SENSOR, - ORIENTATION_SENSOR, - GYROSCOPE_SENSOR, - LIGHT_SENSOR, - PROXIMITY_SENSOR, - PRESSURE_SENSOR, - ULTRAVIOLET_SENSOR, - TEMPERATURE_SENSOR, - HUMIDITY_SENSOR, - HRM_SENSOR, - BIO_HRM_SENSOR = HRM_SENSOR, - HRM_LED_GREEN_SENSOR, - BIO_LED_GREEN_SENSOR = HRM_LED_GREEN_SENSOR, - HRM_LED_IR_SENSOR, - BIO_LED_IR_SENSOR = HRM_LED_IR_SENSOR, - HRM_LED_RED_SENSOR, - BIO_LED_RED_SENSOR = HRM_LED_RED_SENSOR, - GYROSCOPE_UNCAL_SENSOR, - GEOMAGNETIC_UNCAL_SENSOR, - GYROSCOPE_RV_SENSOR, - GEOMAGNETIC_RV_SENSOR, - - HUMAN_PEDOMETER_SENSOR = 0x300, - HUMAN_SLEEP_MONITOR_SENSOR, - - FUSION_SENSOR = 0x900, - AUTO_ROTATION_SENSOR, - - CONTEXT_SENSOR = 0x1000, - MOTION_SENSOR, - PIR_SENSOR, - PIR_LONG_SENSOR, - DUST_SENSOR, - THERMOMETER_SENSOR, - PEDOMETER_SENSOR, - FLAT_SENSOR, - HRM_RAW_SENSOR, - BIO_SENSOR = HRM_RAW_SENSOR, - TILT_SENSOR, - RV_RAW_SENSOR, - EXERCISE_SENSOR, - - GESTURE_MOVEMENT_SENSOR = 0x1200, - GESTURE_WRIST_UP_SENSOR, - GESTURE_WRIST_DOWN_SENSOR, - GESTURE_MOVEMENT_STATE_SENSOR, - - WEAR_STATUS_SENSOR = 0x1A00, - WEAR_ON_MONITOR_SENSOR, - GPS_BATCH_SENSOR, - ACTIVITY_TRACKER_SENSOR, - SLEEP_DETECTOR_SENSOR, - -} sensor_type_t; +#define SENSOR_TYPE(DEF_SENSOR, DEF_SENSOR_VALUE) \ + DEF_SENSOR_VALUE(UNKNOWN_SENSOR, -2) \ + DEF_SENSOR_VALUE(ALL_SENSOR, -1) \ + DEF_SENSOR_VALUE(ACCELEROMETER_SENSOR, 0) \ + DEF_SENSOR(GRAVITY_SENSOR) \ + DEF_SENSOR(LINEAR_ACCEL_SENSOR) \ + DEF_SENSOR(GEOMAGNETIC_SENSOR) \ + DEF_SENSOR(ROTATION_VECTOR_SENSOR) \ + DEF_SENSOR(ORIENTATION_SENSOR) \ + DEF_SENSOR(GYROSCOPE_SENSOR) \ + DEF_SENSOR(LIGHT_SENSOR) \ + DEF_SENSOR(PROXIMITY_SENSOR) \ + DEF_SENSOR(PRESSURE_SENSOR) \ + DEF_SENSOR(ULTRAVIOLET_SENSOR) \ + DEF_SENSOR(TEMPERATURE_SENSOR) \ + DEF_SENSOR(HUMIDITY_SENSOR) \ + DEF_SENSOR(HRM_SENSOR) \ + DEF_SENSOR(HRM_LED_GREEN_SENSOR) \ + DEF_SENSOR(HRM_LED_IR_SENSOR) \ + DEF_SENSOR(HRM_LED_RED_SENSOR) \ + DEF_SENSOR(GYROSCOPE_UNCAL_SENSOR) \ + DEF_SENSOR(GEOMAGNETIC_UNCAL_SENSOR) \ + DEF_SENSOR(GYROSCOPE_RV_SENSOR) \ + DEF_SENSOR(GEOMAGNETIC_RV_SENSOR) \ + \ + DEF_SENSOR_VALUE(HUMAN_PEDOMETER_SENSOR, 0x300) \ + DEF_SENSOR(HUMAN_SLEEP_MONITOR_SENSOR) \ + \ + DEF_SENSOR_VALUE(FUSION_SENSOR, 0x900) \ + DEF_SENSOR(AUTO_ROTATION_SENSOR) \ + DEF_SENSOR(AUTO_BRIGHTNESS_SENSOR) \ + \ + DEF_SENSOR_VALUE(CONTEXT_SENSOR, 0x1000) \ + DEF_SENSOR(MOTION_SENSOR) \ + DEF_SENSOR(PIR_SENSOR) \ + DEF_SENSOR(PIR_LONG_SENSOR) \ + DEF_SENSOR(DUST_SENSOR) \ + DEF_SENSOR(THERMOMETER_SENSOR) \ + DEF_SENSOR(PEDOMETER_SENSOR) \ + DEF_SENSOR(FLAT_SENSOR) \ + DEF_SENSOR(HRM_RAW_SENSOR) \ + DEF_SENSOR(TILT_SENSOR) \ + DEF_SENSOR(RV_RAW_SENSOR) \ + DEF_SENSOR(EXERCISE_SENSOR) \ + \ + DEF_SENSOR_VALUE(GESTURE_MOVEMENT_SENSOR, 0x1200) \ + DEF_SENSOR(GESTURE_WRIST_UP_SENSOR) \ + DEF_SENSOR(GESTURE_WRIST_DOWN_SENSOR) \ + DEF_SENSOR(GESTURE_MOVEMENT_STATE_SENSOR) \ + \ + DEF_SENSOR_VALUE(WEAR_STATUS_SENSOR, 0x1A00) \ + DEF_SENSOR(WEAR_ON_MONITOR_SENSOR) \ + DEF_SENSOR(GPS_BATCH_SENSOR) \ + DEF_SENSOR(ACTIVITY_TRACKER_SENSOR) \ + DEF_SENSOR(SLEEP_DETECTOR_SENSOR) \ + +#define BIO_HRM_SENSOR HRM_SENSOR +#define BIO_LED_GREEN_SENSOR HRM_LED_GREEN_SENSOR +#define BIO_LED_IR_SENSOR HRM_LED_IR_SENSOR +#define BIO_LED_RED_SENSOR HRM_LED_RED_SENSOR +#define BIO_SENSOR HRM_RAW_SENSOR + +DECLARE_SENSOR_ENUM(sensor_type_t, SENSOR_TYPE) // Sensor Event Types enum event_types_t { @@ -270,6 +274,10 @@ enum motion_property_id { } #endif +#ifdef __cplusplus +DECLARE_SENSOR_ENUM_UTIL_NS(sensor_type_t) +#endif + #include #endif /* _SENSOR_TYPES_H_ */