From: kibak.yoon Date: Tue, 4 Apr 2017 09:22:21 +0000 (+0900) Subject: sensord: clean up command-related types and log-related files X-Git-Tag: accepted/tizen/unified/20170414.164053^2~65 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=834df86f338de3ee2428f1b9aedd4703e194b233;p=platform%2Fcore%2Fsystem%2Fsensord.git sensord: clean up command-related types and log-related files - remove sensor_log.cpp - rename command_common.h to command_types.h Change-Id: I01635838c0a11f466b183b3766ee013a19dee6b8 Signed-off-by: kibak.yoon --- diff --git a/include/sensor_types.h b/include/sensor_types.h index c244943..5062062 100644 --- a/include/sensor_types.h +++ b/include/sensor_types.h @@ -225,6 +225,8 @@ enum poll_interval_t { POLL_MAX_HZ_MS = 255000, }; +#define DEFAULT_INTERVAL POLL_10HZ_MS + enum sensor_interval_t { SENSOR_INTERVAL_FASTEST = POLL_100HZ_MS, SENSOR_INTERVAL_NORMAL = POLL_5HZ_MS, diff --git a/src/sensorctl/tester.cpp b/src/sensorctl/tester.cpp index 1ea034a..4ac906f 100644 --- a/src/sensorctl/tester.cpp +++ b/src/sensorctl/tester.cpp @@ -33,9 +33,9 @@ #define TESTER_ARGC 3 /* e.g. {sensorctl, test, accelerometer} */ #define MAX_COUNT 999999 -#define DEFAULT_INTERVAL 100 -#define DEFAULT_LATENCY 0 -#define DEFAULT_POWERSAVE_OPTION SENSOR_OPTION_ALWAYS_ON +#define TEST_DEFAULT_INTERVAL 100 +#define TEST_DEFAULT_LATENCY 0 +#define TEST_DEFAULT_POWERSAVE_OPTION SENSOR_OPTION_ALWAYS_ON static sensor_type_t type; static int interval; @@ -94,9 +94,9 @@ bool tester_manager::setup_manual(int argc, char *argv[]) type = get_sensor_type(argv[2]); RETVM_IF(type == UNKNOWN_SENSOR, false, "Invalid argument\n"); - interval = DEFAULT_INTERVAL; - latency = DEFAULT_LATENCY; - powersave = DEFAULT_POWERSAVE_OPTION; + interval = TEST_DEFAULT_INTERVAL; + latency = TEST_DEFAULT_LATENCY; + powersave = TEST_DEFAULT_POWERSAVE_OPTION; event_count = 0; if (argc >= TESTER_ARGC + 1) diff --git a/src/shared/command_common.h b/src/shared/command_common.h deleted file mode 100644 index c3711ce..0000000 --- a/src/shared/command_common.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * 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 _COMMAND_COMMON_H_ -#define _COMMAND_COMMON_H_ - -#include -#include -#include - -#define SENSOR_CHANNEL_PATH "/run/.sensord.socket" - -#define MAX_HANDLE 256 -#define MAX_HANDLE_REACHED -2 - -enum packet_type_t { - CMD_DONE = -1, - CMD_NONE = 0, - CMD_GET_ID, - CMD_GET_SENSOR_LIST, - CMD_HELLO, - CMD_BYEBYE, - CMD_START, - CMD_STOP, - CMD_REG, - CMD_UNREG, - CMD_SET_PAUSE_POLICY, - CMD_SET_BATCH, - CMD_UNSET_BATCH, - CMD_GET_DATA, - CMD_SET_ATTRIBUTE_INT, - CMD_SET_ATTRIBUTE_STR, - CMD_FLUSH, - CMD_CNT, -}; - -enum ext_packet_type_t { - CMD_EXT_DONE = -1, - CMD_EXT_NONE = 0, - CMD_EXT_GET_ID, - CMD_EXT_CONNECT, - CMD_EXT_DISCONNECT, - CMD_EXT_POST, - CMD_EXT_CNT, -}; - -typedef struct { - char name[NAME_MAX]; -} cmd_get_id_t; - -typedef struct { -} cmd_get_sensor_list_t; - -typedef struct { - int client_id; - sensor_id_t sensor; -} cmd_hello_t; - -typedef struct { -} cmd_byebye_t; - -typedef struct { - unsigned int type; -} cmd_get_data_t; - -typedef struct { - long value; -} cmd_done_t; - -typedef struct { - int client_id; -} cmd_get_id_done_t; - -typedef struct { - int sensor_cnt; - char data[0]; -} cmd_get_sensor_list_done_t; - -typedef struct { - int state; - sensor_data_t base_data; -} cmd_get_data_done_t; - -typedef struct { -} cmd_start_t; - -typedef struct { -} cmd_stop_t; - -typedef struct { - unsigned int event_type; -} cmd_reg_t; - -typedef struct { - unsigned int event_type; -} cmd_unreg_t; - -typedef struct { - unsigned int interval; - unsigned int latency; -} cmd_set_batch_t; - -typedef struct { -} cmd_unset_batch_t; - -typedef struct { - int pause_policy; -} cmd_set_pause_policy_t; - -typedef struct { - int attribute; - int value; -} cmd_set_attribute_int_t; - -typedef struct { - int attribute; - int len; - char value[0]; -} cmd_set_attribute_str_t; - -typedef struct { -} cmd_flush_t; - -typedef struct { - char name[NAME_MAX]; -} cmd_ext_get_id_t; - -typedef struct { - int client_id; - char key[NAME_MAX]; -} cmd_ext_connect_t; - -typedef struct { -} cmd_ext_disconnect_t; - -typedef struct { - unsigned long long timestamp; - int data_cnt; - float data[0]; -} cmd_ext_post_t; - -typedef struct { - long value; -} cmd_ext_done_t; - -typedef struct { - int client_id; -} cmd_ext_get_id_done_t; - -typedef struct { - sensor_id_t sensor_id; -} cmd_ext_connect_done_t; - -#define CHANNEL_MAGIC_NUM 0xCAFECAFE - -typedef struct { - unsigned int magic; - int client_id; -} channel_ready_t; - -typedef struct external_command_header_t { - sensor_id_t sensor_id; - int command_len; -} external_command_header_t; - -typedef struct external_command_t { - external_command_header_t header; - std::vector command; -} external_command_t; - -typedef void *(*cmd_func_t)(void *data, void *cb_data); - -#define COMMAND_LEN_MAX (10*1024) -#define POST_DATA_LEN_MAX (10*1024) - -#endif /* _COMMAND_COMMON_H_ */ diff --git a/src/shared/command_types.h b/src/shared/command_types.h new file mode 100644 index 0000000..81d4a21 --- /dev/null +++ b/src/shared/command_types.h @@ -0,0 +1,116 @@ +/* + * 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 __COMMAND_TYPES_H__ +#define __COMMAND_TYPES_H__ + +#include +#include "sensor_info.h" + +#define SENSOR_CHANNEL_PATH "/run/.sensord.socket" +#define MAX_BUF_SIZE 4096 + +/* TODO: OOP - create serializer interface */ +enum cmd_type_e { + CMD_DONE = -1, + CMD_NONE = 0, + + /* Manager */ + CMD_MANAGER_SENSOR_LIST, + + /* Listener */ + CMD_LISTENER_EVENT, + CMD_LISTENER_ACC_EVENT, + CMD_LISTENER_CONNECT, + CMD_LISTENER_DISCONNECT, + CMD_LISTENER_START, + CMD_LISTENER_STOP, + CMD_LISTENER_ATTR_INT, + CMD_LISTENER_ATTR_STR, + CMD_LISTENER_GET_DATA, + + /* Provider(Dyanmic/External sensor) */ + CMD_PROVIDER_CMD_EVENT, + CMD_PROVIDER_CONNECT, + CMD_PROVIDER_DISCONNECT, + CMD_PROVIDER_POST, + + CMD_CNT, +}; + +typedef struct { + int sensor_cnt; + char data[0]; +} cmd_manager_sensor_list_t; + +typedef struct { + int listener_id; + char sensor[NAME_MAX]; +} cmd_listener_connect_t; + +typedef struct { + int listener_id; +} cmd_listener_disconnect_t; + +typedef struct { + int listener_id; +} cmd_listener_start_t; + +typedef struct { + int listener_id; +} cmd_listener_stop_t; + +typedef struct { + int listener_id; + int attribute; + int value; +} cmd_listener_attr_int_t; + +typedef struct { + int listener_id; + int attribute; + int len; + char value[0]; +} cmd_listener_attr_str_t; + +typedef struct { + int listener_id; + int len; + char data[0]; +} cmd_listener_get_data_t; + +typedef struct { + int provider_id; + int sensor_id; + char sensor[NAME_MAX]; + char s_info[0]; +} cmd_provider_connect_t; + +typedef struct { + int provider_id; + char sensor[NAME_MAX]; +} cmd_provider_disconnect_t; + +typedef struct { + int provider_id; + char sensor[NAME_MAX]; + sensorhub_data_t base_data; +} cmd_provider_post_t; + +#endif /* __COMMAND_TYPES_H__ */ diff --git a/src/shared/sensor_log.cpp b/src/shared/sensor_log.cpp deleted file mode 100644 index f657883..0000000 --- a/src/shared/sensor_log.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * sensord - * - * Copyright (c) 2013 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PATH_MAX 256 - -#if defined(_DEBUG) -bool get_proc_name(pid_t pid, char *process_name) -{ - FILE *fp; - char buf[NAME_MAX]; - char filename[PATH_MAX]; - - sprintf(filename, "/proc/%d/stat", pid); - fp = fopen(filename, "r"); - - if (fp == NULL) - return false; - - if (fscanf(fp, "%*s (%[^)]", buf) < 1) { - fclose(fp); - return false; - } - - strncpy(process_name, buf, NAME_MAX-1); - process_name[NAME_MAX-1] = '\0'; - fclose(fp); - - return true; -} -#else -bool get_proc_name(pid_t pid, char *process_name) -{ - char buf[NAME_MAX]; - - if (snprintf(buf, sizeof(buf), "%d process", pid) < 1) { - return false; - } - - strncpy(process_name, buf, NAME_MAX-1); - process_name[NAME_MAX-1] = '\0'; - - return true; -} -#endif - -const char* get_client_name(void) -{ - const int pid_string_size = 10; - static pid_t pid = -1; - static char client_name[NAME_MAX + pid_string_size]; - - char proc_name[NAME_MAX]; - - if (pid == -1) - { - pid = getpid(); - get_proc_name(pid, proc_name); - snprintf(client_name, sizeof(client_name), "%s(%d)", proc_name, pid); - } - - return client_name; -} diff --git a/src/shared/sensor_log.h b/src/shared/sensor_log.h index 22d1d7d..f2e0d49 100644 --- a/src/shared/sensor_log.h +++ b/src/shared/sensor_log.h @@ -17,36 +17,29 @@ * */ -#ifndef _SENSOR_LOG_H_ -#define _SENSOR_LOG_H_ +#ifndef __SENSOR_LOG_H__ +#define __SENSOR_LOG_H__ #include #include -#define MICROSECONDS(tv) ((tv.tv_sec * 1000000ll) + tv.tv_usec) - #ifdef LOG_TAG #undef LOG_TAG #endif #define LOG_TAG "SENSOR" -#define LOG_DUMP(fp, fmt, arg...) do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0) - -#ifdef _DEBUG -#define DBG SLOGD -#else -#define DBG(...) do {} while (0) -#endif - -#define ERR SLOGE -#define WARN SLOGW -#define INFO SLOGI -#define _E ERR -#define _W WARN -#define _I INFO -#define _D DBG +/* Logging and Error Handling */ +#define _I SLOGI +#define _D SLOGD +#define _W SLOGW +#define _E SLOGE +#define _SI SECURE_SLOGI +#define _SD SECURE_SLOGD +#define _SW SECURE_SLOGW +#define _SE SECURE_SLOGE -#define _ERRNO(errno, tag, fmt, arg...) do { \ +#define _ERRNO(errno, tag, fmt, arg...) \ + do { \ char buf[1024]; \ char *error = strerror_r(errno, buf, 1024); \ if (!error) { \ @@ -56,80 +49,22 @@ tag(fmt" (%s[%d])", ##arg, error, errno); \ } while (0) -#if defined(_DEBUG) -# define warn_if(expr, fmt, arg...) do { \ - if (expr) { \ - _D("(%s) -> " fmt, #expr, ##arg); \ - } \ - } while (0) -# define ret_if(expr) do { \ - if (expr) { \ - _D("(%s) -> %s() return", #expr, __FUNCTION__); \ - return; \ - } \ - } while (0) -# define retv_if(expr, val) do { \ - if (expr) { \ - _D("(%s) -> %s() return", #expr, __FUNCTION__); \ - return (val); \ - } \ - } while (0) -# define retm_if(expr, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - _D("(%s) -> %s() return", #expr, __FUNCTION__); \ - return; \ - } \ - } while (0) -# define retvm_if(expr, val, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - _D("(%s) -> %s() return", #expr, __FUNCTION__); \ - return (val); \ - } \ - } while (0) +#define warn_if(expr, fmt, arg...) \ + do { if (expr) { _E(fmt, ##arg); } } while (0) -#else -# define warn_if(expr, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - } \ - } while (0) -# define ret_if(expr) do { \ - if (expr) { \ - return; \ - } \ - } while (0) -# define retv_if(expr, val) do { \ - if (expr) { \ - return (val); \ - } \ - } while (0) -# define retm_if(expr, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - return; \ - } \ - } while (0) -# define retvm_if(expr, val, fmt, arg...) do { \ - if (expr) { \ - _E(fmt, ##arg); \ - return (val); \ - } \ - } while (0) +#define ret_if(expr) \ + do { if (expr) { return; } } while (0) -#endif +#define retv_if(expr, val) \ + do { if (expr) { return (val); } } while (0) -#ifdef __cplusplus -extern "C" -{ -#endif +#define retm_if(expr, fmt, arg...) \ + do { if (expr) { _E(fmt, ##arg); return; } } while (0) -const char* get_client_name(void); -bool get_proc_name(pid_t pid, char *process_name); +#define retvm_if(expr, val, fmt, arg...) \ + do { if (expr) { _E(fmt, ##arg); return (val); } } while (0) -#ifdef __cplusplus -} -#endif +#define LOG_DUMP(fp, fmt, arg...) \ + do { if (fp) fprintf(fp, fmt, ##arg); else _E(fmt, ##arg); } while (0) -#endif /* _SENSOR_LOG_H_ */ +#endif /* __SENSOR_LOG_H__ */