From 765ed2eeb435450c5b05b3cdd6941ab00a6ed358 Mon Sep 17 00:00:00 2001 From: "nshero.lee" Date: Tue, 19 Dec 2017 12:29:20 +0900 Subject: [PATCH] Change file name Signed-off-by: nshero.lee --- include/sa_types.h | 27 +++++ src/CMakeLists.txt | 7 +- src/{sa_manager.c => adaptor.c} | 142 ++++++++++++++---------- src/input_file.c | 0 src/{sa_network.c => setup_network.c} | 0 src/{sa_systemdata.c => setup_system.c} | 0 6 files changed, 113 insertions(+), 63 deletions(-) rename src/{sa_manager.c => adaptor.c} (79%) create mode 100644 src/input_file.c rename src/{sa_network.c => setup_network.c} (100%) rename src/{sa_systemdata.c => setup_system.c} (100%) diff --git a/include/sa_types.h b/include/sa_types.h index be348b5..939e4b7 100644 --- a/include/sa_types.h +++ b/include/sa_types.h @@ -37,6 +37,33 @@ #define SA_CONFIG_NETWORKDATA_HTTPPROXYHOST "httpProxyHost" #define SA_CONFIG_NETWORKDATA_HTTPPROXYPORT "httpProxyPort" +#define SA_MESSAGE_QID 0x00000001 + +/** + * @brief This enum contains docker interface command type + * + * The sa_msgq_cmd_type_e indicates what command is set + * + */ +typedef enum { + SA_FILE_CHANGE = 0x10, + SA_WIFI_CALLBACK = 0x11, +} sa_msgq_cmd_type_e; + +/** + * @struct sa_msgq_buf_s + * @brief This struct contains message queue information + * + * The sa_msgq_buf_s encapsulate the mtype, *event_data, cmd in the one data + * + */ +typedef struct { + long mtype; + char *event_data; + sa_msgq_cmd_type_e cmd; +} sa_msgq_buf_s; + + /** * @brief This enum contains setup-adaptor error information * diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 471640f..e8dc39c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,9 +11,10 @@ INCLUDE_DIRECTORIES(${pbus_pkgs_INCLUDE_DIRS}) LINK_DIRECTORIES(${pbus_pkgs_LIBRARY_DIRS}) FILE(GLOB SRCS *.c - sa_manager.c - sa_network.c - sa_systemdata.c) + adaptor.c + setup_network.c + setup_system.c + input_file.c) ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) diff --git a/src/sa_manager.c b/src/adaptor.c similarity index 79% rename from src/sa_manager.c rename to src/adaptor.c index cda1c17..b41a5b5 100644 --- a/src/sa_manager.c +++ b/src/adaptor.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "sa_common.h" #include "sa_types.h" #include "sa_systemdata.h" @@ -28,6 +29,31 @@ #define NETWORK_CHECK_RETRY_MAX 10 #define EVENT_SIZE (sizeof(struct inotify_event)) #define BUF_LEN (1024 * (EVENT_SIZE + 16)) +static int sa_message_queue_id; + +static int __get_sa_msg_queue_id(void) +{ + return sa_message_queue_id; +} + +static int __send_message(sa_msgq_buf_s *msg_buf) +{ + int msgqid; + int msg_size; + + msg_buf->mtype = SA_MESSAGE_QID; + + msg_size = sizeof(sa_msgq_buf_s) - sizeof(msg_buf->mtype); + + msgqid = __get_sa_msg_queue_id(); + + if (msgsnd(msgqid, msg_buf, msg_size, 0) == -1) { + _E("msgsnd error(%d)", errno); + return -1; + } + + return 0; +} static int __check_config_file(char *filename) { @@ -133,43 +159,12 @@ static void __print_config_info(sa_config_s *config) static void __release_network_resource(sa_network_s * network) { if (network != NULL) { - if (network->wifi != NULL) { - if (network->wifi->ssid != NULL) - free(network->wifi->ssid); - if (network->wifi->password != NULL) - free(network->wifi->password); - - if (network->wifi->staticInfo != NULL) { - if (network->wifi->staticInfo->ipAddress != NULL) - free(network->wifi->staticInfo->ipAddress); - if (network->wifi->staticInfo->netmask != NULL) - free(network->wifi->staticInfo->netmask); - if (network->wifi->staticInfo->defaultGateway != NULL) - free(network->wifi->staticInfo->defaultGateway); - if (network->wifi->staticInfo->primaryDnsServer != NULL) - free(network->wifi->staticInfo->primaryDnsServer); - if (network->wifi->staticInfo->secondaryDnsServer != NULL) - free(network->wifi->staticInfo->secondaryDnsServer); - - free(network->wifi->staticInfo); - } - } + if (network->wifi != NULL) + free(network->wifi->staticInfo); if (network->eth != NULL) { - if (network->eth->staticInfo != NULL) { - if (network->eth->staticInfo->ipAddress != NULL) - free(network->eth->staticInfo->ipAddress); - if (network->eth->staticInfo->netmask != NULL) - free(network->eth->staticInfo->netmask); - if (network->eth->staticInfo->defaultGateway != NULL) - free(network->eth->staticInfo->defaultGateway); - if (network->eth->staticInfo->primaryDnsServer != NULL) - free(network->eth->staticInfo->primaryDnsServer); - if (network->eth->staticInfo->secondaryDnsServer != NULL) - free(network->eth->staticInfo->secondaryDnsServer); - + if (network->eth->staticInfo != NULL) free(network->eth->staticInfo); - } } if (network->httpProxyHost != NULL) @@ -179,28 +174,18 @@ static void __release_network_resource(sa_network_s * network) } } -static void __release_config_resource(sa_config_s *config, sa_network_activate_pararms_s *activateParams) +static void __release_config_resource(sa_config_s *config) { if (config != NULL) { - if (config->version != NULL) - free(config->version); - if (config->networkData != NULL) __release_network_resource(config->networkData); - if (config->systemData != NULL) { - if (config->systemData->deviceName != NULL) - free(config->systemData->deviceName); - + if (config->systemData != NULL) free(config->systemData); - } free(config); } - - if (activateParams != NULL) - __release_network_resource(activateParams->network); } static void *__config_event_loop(void *arg) @@ -274,13 +259,51 @@ static void *__config_event_loop(void *arg) return NULL; } +static void *__event_loop(void *pv) +{ + int msgqid = 0; + int msg_size = 0; + sa_msgq_buf_s msg_buf; + + msgqid = __get_sa_msg_queue_id(); + if (0 == msgqid) { + _D("msgqid is NULL"); + return; + } + + msg_size = sizeof(sa_msgq_buf_s) - sizeof(msg_buf.mtype); + + while (1) { + if (msgrcv(msgqid, &msg_buf, msg_size, 0, 0) == -1) + _E("msgrcv error(%d)", errno); + + switch (msg_buf.cmd) { + case SA_FILE_CHANGE: + _D("SA_FILE_CHANGE"); + + break; + case SA_WIFI_CALLBACK: + _D("SA_WIFI_CALLBACK"); + + break; + + default: + break; + } + } + + pthread_exit((void *)0); + return NULL; +} + + static sa_error_e __init_event_listener(void) { pthread_t p_thread; - // register file change event - // Start thread to create in order to receive event + sa_message_queue_id = msgget((key_t) SA_MESSAGE_QID, IPC_CREAT | 0666); + // Start thread to create in order to receive event if (pthread_create(&p_thread, NULL, &__config_event_loop, CONFIG_FILE) < 0) { _E("__init_event_listener create error"); return SA_ERROR_UNKNOWN; @@ -303,6 +326,13 @@ int main(int argc, char *argv[]) if (__check_config_file(CONFIG_FILE)) { + // 0.Initializing thread to receive file change event and network callback + if (ret == SA_ERROR_NONE) { + __init_event_listener(); + } else { + _E("__init_event_listener error [%d]", ret); + } + // 1.Get config info from interface // memory will be allocated from interface layer ret = sa_systemdata_get_config_info(CONFIG_FILE, config); @@ -345,21 +375,13 @@ int main(int argc, char *argv[]) } } - // 4.Register file change event - if (ret == SA_ERROR_NONE) { - // register file change event - // Start thread to create in order to receive event - __init_event_listener(); - } else { - _E("sa_network_activate return error [%d]", ret); - } - - /* 5.Save System Data(device name) + + /* 4.Save System Data(device name) - TBD */ - // 6.free resource - __release_config_resource(config, activateParams); + // 5.free resource + __release_config_resource(config); } else { /* If the file is not existed, it would be enabled softAP - TBD diff --git a/src/input_file.c b/src/input_file.c new file mode 100644 index 0000000..e69de29 diff --git a/src/sa_network.c b/src/setup_network.c similarity index 100% rename from src/sa_network.c rename to src/setup_network.c diff --git a/src/sa_systemdata.c b/src/setup_system.c similarity index 100% rename from src/sa_systemdata.c rename to src/setup_system.c -- 2.34.1