From 227cb9a687c69198a727c09bcaeecf94208b9fa6 Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Thu, 28 Feb 2019 13:38:37 +0900 Subject: [PATCH 01/16] Deleted unnecessary log. Signed-off-by: saerome.kim --- ua-daemon/src/ua-manager-request-handler.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 7d813a3..252248c 100644 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -789,9 +789,6 @@ static void __uam_manager_name_owner_changed_cb(GDBusConnection *connection, g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner); - UAM_ERR("old_owner[%s] new_owner[%s] size[%d]", - old_owner, new_owner, g_slist_length(uam_dbus_clients)); - if ('\0' == *new_owner) { g_mutex_lock(&uam_dbus_clients_mutex); count = g_slist_length(uam_dbus_clients); -- 2.7.4 From fd1b7c5db25116b022c8be2882f6446b2bc9b038 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Wed, 6 Mar 2019 11:23:47 +0530 Subject: [PATCH 02/16] Invoke UAM_REQUEST_ADD_DEVICE as ASYNC API Signed-off-by: Atul Rai --- ua-api/src/ua-api.c | 4 ++-- ua-api/src/ua-request-sender.c | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c index 64f62f3..ea21c06 100644 --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -341,8 +341,8 @@ UAM_EXPORT_API int _uam_request_add_device(char* account, uam_device_info_t* dev g_strlcpy(str, account, UAM_USER_ACCOUNT_MAX_STRING_LEN); g_array_append_vals(in_param1, str, sizeof(str)); g_array_append_vals(in_param2, device, sizeof(uam_device_info_t)); - ret = _uam_sync_request(UAM_REQUEST_ADD_DEVICE, - in_param1, in_param2, in_param3, in_param4, &out_param); + ret = _uam_async_request(UAM_REQUEST_ADD_DEVICE, in_param1, in_param2, + in_param3, in_param4, cb_info.callback, cb_info.user_data); UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); diff --git a/ua-api/src/ua-request-sender.c b/ua-api/src/ua-request-sender.c index cc4246a..940c1a8 100644 --- a/ua-api/src/ua-request-sender.c +++ b/ua-api/src/ua-request-sender.c @@ -88,6 +88,12 @@ static void __uam_get_event_info(int req_func, GArray *output, _uam_request_to_str(req_func), req_func); switch (req_func) { + case UAM_REQUEST_ADD_DEVICE: + *event = UAM_EVENT_DEVICE_ADDED; + ret_if(output == NULL); + *param_data = &g_array_index(output, + uam_device_info_t, 0); + break; default: UAM_ERR("Unknown request function"); return; -- 2.7.4 From 5c2a92c81027c3914b4d796363bee6bb9d1c011b Mon Sep 17 00:00:00 2001 From: Semun Lee Date: Fri, 8 Mar 2019 16:21:03 +0900 Subject: [PATCH 03/16] Fix circleci configuration It will use specific version of gbs. Change-Id: I54d747dc92910b9717a1a0d7571b2800e452bc41 Signed-off-by: Semun Lee --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d627e1e..059c76a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,7 +8,7 @@ jobs: - run: name: Install gbs command: | - echo "deb [trusted=yes] http://download.tizen.org/tools/latest-release/Ubuntu_16.04/ /" | sudo tee /etc/apt/sources.list.d/tizen.list + echo "deb [trusted=yes] http://download.tizen.org/tools/archive/19.03/Ubuntu_16.04/ /" | sudo tee /etc/apt/sources.list.d/tizen.list sudo apt-get update sudo apt-get install -y gbs find /proc/sys/fs/binfmt_misc/ -not -name status -not -name register -type f -exec sh -c "echo -1 | sudo tee {}" \; -- 2.7.4 From 755bc207b99b78509d0cd64a61d7f8f7e593fda6 Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Mon, 11 Mar 2019 17:28:34 +0900 Subject: [PATCH 04/16] Fixed build error due to dbus-policy checker - how to test : dbus-policychecker /etc/dbus-1/system.d/net.uamd.conf Signed-off-by: saerome.kim --- packaging/ua-manager.conf | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packaging/ua-manager.conf b/packaging/ua-manager.conf index 5dea756..0cde71b 100644 --- a/packaging/ua-manager.conf +++ b/packaging/ua-manager.conf @@ -3,23 +3,23 @@ - - - - - + + + + - - - - - + + + + + + + + + + + - - - - - -- 2.7.4 From 0c44678aa6759b2ddcccff1456488b8c4f8d2762 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Mon, 11 Mar 2019 16:21:21 +0530 Subject: [PATCH 05/16] Fixed ua-client cleanup on app termination Signed-off-by: Atul Rai --- ua-api/src/ua-api.c | 1 + ua-daemon/src/ua-manager-request-handler.c | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c index ea21c06..d24fa07 100644 --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -35,6 +35,7 @@ UAM_EXPORT_API int _uam_init(uam_event_callback cb, void *user_data) ret = _uam_sync_enable(TRUE); if (UAM_ERROR_NONE != ret) { + UAM_ERR("_uam_sync_enable(TRUE) failed"); return ret; } diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index 252248c..f7e1860 100644 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -751,7 +751,6 @@ static int __uam_manager_unregister_object(GDBusConnection *conn) static void __uam_manager_cleanup_requests_from_sender(const char *name) { -// FUNC_ENTRY; GSList *l; ret_if(NULL == name); @@ -771,7 +770,6 @@ static void __uam_manager_cleanup_requests_from_sender(const char *name) /* App terminated, cleanup monitor list */ _uam_core_cleanup_monitor((char *)name); -// FUNC_EXIT; } static void __uam_manager_name_owner_changed_cb(GDBusConnection *connection, @@ -782,26 +780,34 @@ static void __uam_manager_name_owner_changed_cb(GDBusConnection *connection, GVariant *parameters, gpointer user_data) { - int count = 0; + int count = 1; const char *name = NULL; const char *old_owner = NULL; const char *new_owner = NULL; + GSList *list; g_variant_get(parameters, "(&s&s&s)", &name, &old_owner, &new_owner); if ('\0' == *new_owner) { + /* Cleanup all pending request from this sender */ + __uam_manager_cleanup_requests_from_sender(name); + g_mutex_lock(&uam_dbus_clients_mutex); - count = g_slist_length(uam_dbus_clients); + list = __uam_list_find_client(name); + if (list) { + /* found bus name in our bus list */ + __uamd_dbus_client_cleanup((gpointer)list->data); + uam_dbus_clients = g_slist_remove_link(uam_dbus_clients, list); + count = g_slist_length(uam_dbus_clients); + } g_mutex_unlock(&uam_dbus_clients_mutex); - if (0 == count) { - /* Cleanup all pending request from this sender */ - __uam_manager_cleanup_requests_from_sender(name); + if (0 == count) { UAM_ERR("Quit ua-manager"); g_main_loop_quit(main_loop); } - - }} + } +} static void __uam_manager_name_acquired_cb( GDBusConnection *connection, const gchar *name, gpointer user_data) -- 2.7.4 From 40a9f7b56862b53ff3abcedf2e0f917d4110cc00 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Tue, 12 Mar 2019 17:10:40 +0530 Subject: [PATCH 06/16] Add app to monitor list if detection is already started Signed-off-by: Atul Rai --- ua-daemon/src/ua-manager-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 71f8ff4..b11d14f 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -1250,9 +1250,8 @@ static int __uam_core_start_detection(int detection_type, char *sender, unsigned return ret; } - monitors = g_slist_append(monitors, monitor); - done: + monitors = g_slist_append(monitors, monitor); monitor->sensors |= sensors; FUNC_EXIT; -- 2.7.4 From 973944da740a91ca2b6642c1ec9b6df36f7d186c Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Thu, 14 Mar 2019 10:33:07 +0530 Subject: [PATCH 07/16] Added Cloud plugin handler in ua-manager Signed-off-by: Atul Rai --- ua-daemon/CMakeLists.txt | 1 + ua-daemon/include/ua-cloud-plugin-handler.h | 33 ++++ ua-daemon/include/ua-manager-common.h | 9 + ua-daemon/include/ua-plugin-manager.h | 8 - ua-daemon/src/pm/ua-cloud-plugin-handler.c | 263 ++++++++++++++++++++++++++++ ua-daemon/src/ua-manager-core.c | 40 ++++- ua-plugins/include/ua-cloud-plugin.h | 172 ++++++++++++++++++ 7 files changed, 515 insertions(+), 11 deletions(-) create mode 100644 ua-daemon/include/ua-cloud-plugin-handler.h create mode 100644 ua-daemon/src/pm/ua-cloud-plugin-handler.c create mode 100644 ua-plugins/include/ua-cloud-plugin.h diff --git a/ua-daemon/CMakeLists.txt b/ua-daemon/CMakeLists.txt index b9f2128..7142fcf 100644 --- a/ua-daemon/CMakeLists.txt +++ b/ua-daemon/CMakeLists.txt @@ -24,6 +24,7 @@ SET(SRCS IF("$ENV{CFLAGS}" MATCHES "-DVD_REQ") LIST(APPEND SRCS src/pm/ua-power-plugin-manager.c) LIST(APPEND SRCS src/pm/ua-power-plugin-handler.c) + LIST(APPEND SRCS src/pm/ua-cloud-plugin-handler.c) ENDIF() IF("${CMAKE_BUILD_TYPE}" STREQUAL "") diff --git a/ua-daemon/include/ua-cloud-plugin-handler.h b/ua-daemon/include/ua-cloud-plugin-handler.h new file mode 100644 index 0000000..76e5ffd --- /dev/null +++ b/ua-daemon/include/ua-cloud-plugin-handler.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 __UAM_CLOUD_PLUGIN_HANDLER_H__ +#define __UAM_CLOUD_PLUGIN_HANDLER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void _uam_cloud_set_registered_devices(GSList *devices); + +void _uam_cloud_send_device_added(int status, int user_id, + const uam_device_info_t *dev_info); + +#ifdef __cplusplus +} +#endif +#endif /* __UAM_CLOUD_PLUGIN_HANDLER_H__ */ diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h index 0fb6922..faf9394 100644 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -53,6 +54,14 @@ extern "C" { #define FUNC_ENTRY UAM_DBG("+") #define FUNC_EXIT UAM_DBG("-") +#define PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib") +#ifdef VD_REQ +#define POWER_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/power") +#define CLOUD_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/cloud") +#endif + +#define UAM_VERSION "0.1" + #define ret_if(expr) \ do { \ if (expr) { \ diff --git a/ua-daemon/include/ua-plugin-manager.h b/ua-daemon/include/ua-plugin-manager.h index 7401dbd..e66eeb0 100644 --- a/ua-daemon/include/ua-plugin-manager.h +++ b/ua-daemon/include/ua-plugin-manager.h @@ -27,14 +27,6 @@ extern "C" { #endif -#define PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib") -#define POWER_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/power") - -#define UAM_VERSION "0.1" - -//#define PATH_MAX 4096 + 1 /**< Max. linux path length */ -//#define NAME_MAX 255 + 1 /**< Max. linux file name length */ - typedef enum { UAM_DETECT_PRESENCE = 0x01, UAM_DETECT_ABSENCE = 0x02, diff --git a/ua-daemon/src/pm/ua-cloud-plugin-handler.c b/ua-daemon/src/pm/ua-cloud-plugin-handler.c new file mode 100644 index 0000000..9042236 --- /dev/null +++ b/ua-daemon/src/pm/ua-cloud-plugin-handler.c @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 + +typedef struct { + void *handle; + void *module; + void *api; +} uam_plugin_info_t; + +uam_plugin_info_t *cloud_plugin; + +static int add_user(const char *account, const char *name) +{ + FUNC_ENTRY; + + FUNC_EXIT; + return UAC_STATUS_SUCCESS; +} + +static int remove_user(const char *account) +{ + FUNC_ENTRY; + + FUNC_EXIT; + return UAC_STATUS_SUCCESS; +} + +static int add_device(const char *account, uac_device_info_t *dev_info) +{ + FUNC_ENTRY; + + FUNC_EXIT; + return UAC_STATUS_SUCCESS; +} + +static int remove_device(const char *account, char* device_id) +{ + FUNC_ENTRY; + + FUNC_EXIT; + return UAC_STATUS_SUCCESS; +} + +static void reset_ua_db(void) +{ + FUNC_ENTRY; + + FUNC_EXIT; +} + +uac_callbacks_t cloud_cb = { + .add_user_cb = add_user, + .remove_user_cb = remove_user, + .add_device_cb = add_device, + .remove_device_cb = remove_device, + .reset_cb = reset_ua_db +}; + +void _uam_cloud_set_registered_devices(GSList *devices) +{ + FUNC_ENTRY; + + FUNC_EXIT; +} + +void _uam_cloud_send_device_added(int status, int user_id, + const uam_device_info_t *dev_info) +{ + FUNC_ENTRY; + + FUNC_EXIT; +} + +static gboolean __add_cloud_plugin(void *handle, uac_module_t *module) +{ + FUNC_ENTRY; + uac_api_t *api = NULL; + uam_plugin_info_t *plugin; + + UAM_DBG("Plugin [id: %d, name: %s, version: %s]", + module->id, module->name, module->version); + + if (PLUGIN_ID_CLOUD != module->id) { + UAM_ERR("Unknown Id %d for %s", module->id, module->name); + return FALSE; + } + + if (NULL != cloud_plugin) { + UAM_ERR("Plugin %s already added", + ((uac_module_t *)cloud_plugin->module)->name); + return FALSE; + } + + if (g_str_equal(module->version, UAM_VERSION) == FALSE) { + UAM_ERR("Version (%s) mismatch for %s", + module->version, module->name); + return FALSE; + } + + plugin = g_try_new0(uam_plugin_info_t, 1); + if (NULL == plugin) { + UAM_ERR("Memory allocation failed"); + return FALSE; + } + + retv_if(NULL == module->init, FALSE); + + module->init(&api); + if (NULL == api) { + UAM_ERR("API returned is NULL"); + return FALSE; + } + + plugin->handle = handle; + plugin->module = module; + plugin->api = api; + + cloud_plugin = plugin; + + FUNC_EXIT; + return TRUE; +} + +static int __load_cloud_plugin(void) +{ + FUNC_ENTRY; + GDir *dir; + const char *name; + int ret = UAM_ERROR_INTERNAL; + + retv_if(0 == strlen(CLOUD_PLUGIN_DIR), UAM_ERROR_INTERNAL); + UAM_DBG("Loading plugins from %s", CLOUD_PLUGIN_DIR); + + dir = g_dir_open(CLOUD_PLUGIN_DIR, 0, NULL); + if (!dir) { + UAM_ERR("Unable to open directory %s", CLOUD_PLUGIN_DIR); + return UAM_ERROR_INTERNAL; + } + + while ((name = g_dir_read_name(dir)) != NULL) { + char *filename; + void *handle; + uac_module_t *module; + + if (g_str_has_suffix(name, ".so") == FALSE) + continue; + + filename = g_build_filename(CLOUD_PLUGIN_DIR, name, NULL); + UAM_DBG("Loading [%s]", filename); + + handle = dlopen(filename, RTLD_NOW); + g_free(filename); + if (handle == NULL) { + UAM_ERR("Can't load plugin %s", dlerror()); + continue; + } + + module = (uac_module_t *)dlsym(handle, "uac_module"); + if (module == NULL) { + UAM_ERR("Can't load plugin module: %s", dlerror()); + dlclose(handle); + continue; + } + + if (FALSE == __add_cloud_plugin(handle, module)) { + UAM_WARN("__add_cloud_plugin failed"); + continue; + } + + ret = UAM_ERROR_NONE; + break; + } + + g_dir_close(dir); + FUNC_EXIT; + return ret; +} + +static void __deinit_cloud_plugin(void) +{ + FUNC_ENTRY; + uac_api_t *api = (uac_api_t *)cloud_plugin->api; + uac_module_t *module = (uac_module_t *)cloud_plugin->module; + + /* Deinitialize and unload cloud plugins */ + ret_if(NULL == cloud_plugin); + + if (api && api->deinit) + api->deinit(); + + if (module && module->deinit) + module->deinit(); + + if (cloud_plugin->handle) + dlclose(cloud_plugin->handle); + + g_free(cloud_plugin); + cloud_plugin = NULL; + FUNC_EXIT; +} + +static int __init_cloud_plugin(void) +{ + FUNC_ENTRY; + int status; + + /* Initialize loaded power plugins */ + retv_if(UAM_ERROR_NONE != __load_cloud_plugin(), UAM_ERROR_INTERNAL); + + if (!cloud_plugin || !cloud_plugin->api) { + UAM_WARN("Cloud plugin is NULL"); + return UAM_ERROR_NOT_IN_OPERATION; + } + + status = ((uac_api_t *)cloud_plugin->api)->init(&cloud_cb); + if (UAC_STATUS_SUCCESS != status) { + /* Deinit plugin */ + __deinit_cloud_plugin(); + return UAM_ERROR_INTERNAL; + } + + FUNC_EXIT; + return UAM_ERROR_NONE; +} + +static void __attribute__((constructor)) _uam_cloud_init(void) +{ + FUNC_ENTRY; + int ret; + + ret = __init_cloud_plugin(); + ret_if(UAM_ERROR_NONE != ret); + UAM_INFO_C("__init_cloud_plugin done"); + + FUNC_EXIT; +} + +static void __attribute__((destructor)) _uam_cloud_deinit(void) +{ + FUNC_ENTRY; + __deinit_cloud_plugin(); + FUNC_EXIT; +} diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index b11d14f..64c8783 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -27,6 +27,7 @@ #ifdef VD_REQ #include "ua-power-plugin-manager.h" +#include "ua-cloud-plugin-handler.h" #endif #define UAM_MAX_USERS 255 @@ -239,6 +240,10 @@ static void __free_uam_db_user_info(gpointer data) if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); +#ifdef VD_REQ + /* Set/update registered device list to cloud plugin */ + _uam_cloud_set_registered_devices(devices); +#endif __uam_core_release_user_id(user->user_id); g_free(user->name); g_free(user->account); @@ -810,6 +815,10 @@ int _uam_core_remove_device(const char *account, const uam_device_info_t *dev_in if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); +#ifdef VD_REQ + /* Set/update registered device list to cloud plugin */ + _uam_cloud_set_registered_devices(devices); +#endif FUNC_EXIT; return UAM_ERROR_NONE; } @@ -878,6 +887,10 @@ int _uam_core_remove_device_by_device_id(const char *device_id, int tech_type) if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); +#ifdef VD_REQ + /* Set/update registered device list to cloud plugin */ + _uam_cloud_set_registered_devices(devices); +#endif FUNC_EXIT; return UAM_ERROR_NONE; } @@ -936,6 +949,10 @@ int _uam_core_remove_device_by_mac(const char *mac) if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); +#ifdef VD_REQ + /* Set/update registered device list to cloud plugin */ + _uam_cloud_set_registered_devices(devices); +#endif FUNC_EXIT; return UAM_ERROR_NONE; } @@ -1467,6 +1484,10 @@ int _uam_core_init(void) if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); +#ifdef VD_REQ + /* Set/update registered device list to cloud plugin */ + _uam_cloud_set_registered_devices(devices); +#endif FUNC_EXIT; return UAM_ERROR_NONE; } @@ -1576,12 +1597,13 @@ void _uam_core_handle_device_added(int status, } } l = g_slist_find_custom(users, USER_ACCOUNT_DEFAULT, __compare_user_account); - if (l) - user = l->data; - else { + if (!l) { UAM_ERR("_uam_core_add_user failed because user is null"); return; } + + user = l->data; + user_id = user->user_id; } else { l = g_slist_find_custom(users, &user_id, __compare_user_id); if (NULL == l) { @@ -1608,6 +1630,14 @@ void _uam_core_handle_device_added(int status, UAM_ERR("_uam_pm_set_registered_devices failed"); } +#ifdef VD_REQ + _uam_cloud_send_device_added(status, user_id, dev_info); + + /* Set/update registered device list to cloud plugin */ + if (UAM_ERROR_NONE == status) + _uam_cloud_set_registered_devices(devices); +#endif + FUNC_EXIT; } @@ -1877,5 +1907,9 @@ void _uam_core_reset_database(void) UAM_ERR("_uam_pm_set_registered_devices failed with %s", _uam_manager_error_to_str(ret)); +#ifdef VD_REQ + /* Set/update registered device list to cloud plugin */ + _uam_cloud_set_registered_devices(devices); +#endif FUNC_EXIT; } diff --git a/ua-plugins/include/ua-cloud-plugin.h b/ua-plugins/include/ua-cloud-plugin.h new file mode 100644 index 0000000..c905229 --- /dev/null +++ b/ua-plugins/include/ua-cloud-plugin.h @@ -0,0 +1,172 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved. + * + * 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 __UAM_CLOUD_PLUGIN_H__ +#define __UAM_CLOUD_PLUGIN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define PLUGIN_ID_CLOUD 0x21 + +/* UA power plugin return status */ +typedef enum { + UAC_STATUS_SUCCESS = 0x00, + UAC_STATUS_FAIL = 0x01, + UAC_STATUS_NOT_READY = 0x02, + UAC_STATUS_NOMEM = 0x03, + UAC_STATUS_BUSY = 0x04, + UAC_STATUS_ALREADY_DONE = 0x05, + UAC_STATUS_UNSUPPORTED = 0x06, + UAC_STATUS_TIMEOUT = 0x07, + UAC_STATUS_INVALID_PARAMS = 0x08, +} uac_status_e; + +/* Device Address types */ +typedef enum { + UAC_ADDR_TYPE_BT = 0x01, + UAC_ADDR_TYPE_BLE, + UAC_ADDR_TYPE_WIFI, + UAC_ADDR_TYPE_P2P, + UAC_ADDR_TYPE_IPv4, + UAC_ADDR_TYPE_IPv6, + UAC_ADDR_TYPE_INVALID +} uac_address_type_e; + +/* Device address information structure */ +typedef struct { + uac_address_type_e type; + char *address; +} uac_address_info_t; + +/* Device information structure */ +typedef struct { + int user_id; + unsigned int supported_techs; + char *device_id; + int os; + int num_addr; + uac_address_info_t *addr_list; +} uac_device_info_t; + +/* + * DIRECTION: Cloud-plugin ---> ua-manager + * This callback will be invoked to request user addition in ua database. + * [Param] account - User account id + * [Param] name - User name + */ +typedef int (*add_user_callback)(const char *account, const char *name); + +/* + * DIRECTION: Cloud-plugin ---> ua-manager + * This callback will be invoked to request user deletion from ua database. + * [Param] account - User account id + */ +typedef int (*remove_user_callback)(const char *account); + +/* + * DIRECTION: Cloud-plugin ---> ua-manager + * This callback will be invoked to request device addition in ua database. + * [Param] account - Device's user account id + * [Param] dev_info - Device information + */ +typedef int (*add_device_callback)(const char *account, uac_device_info_t *dev_info); + +/* + * DIRECTION: Cloud-plugin ---> ua-manager + * This callback will be invoked to request device deletion from ua database. + * [Param] account - Device's user account id + * [Param] device_id - Unique device Id + */ +typedef int (*remove_device_callback)(const char *account, char* device_id); + +/* + * DIRECTION: Cloud-plugin ---> ua-manager + * This callback will be invoked to request ua database reset. + */ +typedef void (*reset_ua_db_callback)(void); + +/* Cloud plug-in callback structure */ +typedef struct { + add_user_callback add_user_cb; + remove_user_callback remove_user_cb; + add_device_callback add_device_cb; + remove_device_callback remove_device_cb; + reset_ua_db_callback reset_cb; +} uac_callbacks_t; + +typedef struct { + /* + * DIRECTION: ua-manager ---> Cloud-plugin + * [Sync API] To initialize cloud plug-in + * [Param] callbacks - Callback structre + */ + int (*init)(uac_callbacks_t *callbacks); + + /* + * DIRECTION: ua-manager ---> Cloud-plugin + * [Sync API] To de-initialize cloud plug-in + */ + int (*deinit)(void); + + /* + * DIRECTION: ua-manager ---> Cloud-plugin + * [Sync API] To send registered device list from ua db to plug-in. + * This api will be invoked whenever device list changes (On device addition/removal). + * [Param] num_devices - Number of registered devices. + * [Param] devices - List of registered devices. + */ + int (*set_registered_devices)(int num_devices, uac_device_info_t *devices); + + /* + * DIRECTION: ua-manager ---> Cloud-plugin + * This API is invoked whenever a device is added in ua db. + * It is also used to send response for add_device_callback(). + * [Param] status - status for device add request + * [Param] dev_info - Device info for added device + */ + int (*device_added)(int status, uac_device_info_t *dev_info); +} uac_api_t; + +typedef struct { + /** Identifier of module */ + int id; + + /** Name of this module */ + const char *name; + + /** Author/owner/implementor of the module */ + const char *author; + + /** Version of the module-specific plugin API */ + const char *version; + + /** Modules init */ + int (*init)(uac_api_t **api); + + /** Modules de-init */ + int (*deinit)(void); +} uac_module_t; + +#define UAC_MODULE_ADD(name, author, version, init, deinit) \ + uac_module_t uac_module = { PLUGIN_ID_CLOUD, name, author, version, init, deinit }; + +#ifdef __cplusplus +} +#endif +#endif /* __UAM_CLOUD_PLUGIN_H__ */ -- 2.7.4 From deab27bdc8de74013a8dc27c07da077978955285 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Thu, 14 Mar 2019 10:39:24 +0530 Subject: [PATCH 08/16] Fixed Tizen coding rule errors Signed-off-by: Atul Rai --- include/ua-api.h | 2 +- ua-api/src/ua-api.c | 3 +-- ua-daemon/include/ua-cloud-plugin-handler.h | 2 +- ua-plugins/include/ua-cloud-plugin.h | 12 ++++++------ 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index a7ae32d..9621b8e 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -68,7 +68,7 @@ typedef enum { #define FOREACH_ERROR(ERROR) \ ERROR(UAM_ERROR_NONE, TIZEN_ERROR_NONE) \ ERROR(UAM_ERROR_INVALID_PARAM, TIZEN_ERROR_INVALID_PARAMETER) \ - ERROR(UAM_ERROR_PERMISSION_DENIED,TIZEN_ERROR_PERMISSION_DENIED) \ + ERROR(UAM_ERROR_PERMISSION_DENIED, TIZEN_ERROR_PERMISSION_DENIED) \ ERROR(UAM_ERROR_TIMEOUT, TIZEN_ERROR_TIMED_OUT) \ ERROR(UAM_ERROR_NOW_IN_PROGRESS, TIZEN_ERROR_NOW_IN_PROGRESS) \ ERROR(UAM_ERROR_NOT_SUPPORTED, TIZEN_ERROR_NOT_SUPPORTED) \ diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c index d24fa07..1f71b25 100644 --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -55,9 +55,8 @@ UAM_EXPORT_API int _uam_deinit(void) int ret; ret = _uam_sync_enable(FALSE); - if (UAM_ERROR_NONE != ret) { + if (UAM_ERROR_NONE != ret) return ret; - } ret = _uam_unregister_event_handler(); diff --git a/ua-daemon/include/ua-cloud-plugin-handler.h b/ua-daemon/include/ua-cloud-plugin-handler.h index 76e5ffd..0577963 100644 --- a/ua-daemon/include/ua-cloud-plugin-handler.h +++ b/ua-daemon/include/ua-cloud-plugin-handler.h @@ -25,7 +25,7 @@ extern "C" { void _uam_cloud_set_registered_devices(GSList *devices); void _uam_cloud_send_device_added(int status, int user_id, - const uam_device_info_t *dev_info); + const uam_device_info_t *dev_info); #ifdef __cplusplus } diff --git a/ua-plugins/include/ua-cloud-plugin.h b/ua-plugins/include/ua-cloud-plugin.h index c905229..df1281e 100644 --- a/ua-plugins/include/ua-cloud-plugin.h +++ b/ua-plugins/include/ua-cloud-plugin.h @@ -124,13 +124,13 @@ typedef struct { */ int (*deinit)(void); - /* + /* * DIRECTION: ua-manager ---> Cloud-plugin - * [Sync API] To send registered device list from ua db to plug-in. - * This api will be invoked whenever device list changes (On device addition/removal). - * [Param] num_devices - Number of registered devices. - * [Param] devices - List of registered devices. - */ + * [Sync API] To send registered device list from ua db to plug-in. + * This api will be invoked whenever device list changes (On device addition/removal). + * [Param] num_devices - Number of registered devices. + * [Param] devices - List of registered devices. + */ int (*set_registered_devices)(int num_devices, uac_device_info_t *devices); /* -- 2.7.4 From e057f4c8855f6b01004f2385f26ff7a2892675eb Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Thu, 14 Mar 2019 11:31:45 +0530 Subject: [PATCH 09/16] [Fix review comments] Modify plugin directory path Signed-off-by: Atul Rai --- ua-daemon/include/ua-manager-common.h | 2 +- ua-daemon/src/pm/ua-plugin-manager.c | 8 ++++---- ua-daemon/src/ua-manager-core.c | 22 +++++++--------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h index faf9394..b838e96 100644 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -54,7 +54,7 @@ extern "C" { #define FUNC_ENTRY UAM_DBG("+") #define FUNC_EXIT UAM_DBG("-") -#define PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib") +#define SENSOR_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/sensor") #ifdef VD_REQ #define POWER_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/power") #define CLOUD_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/cloud") diff --git a/ua-daemon/src/pm/ua-plugin-manager.c b/ua-daemon/src/pm/ua-plugin-manager.c index 42e371d..3a13745 100644 --- a/ua-daemon/src/pm/ua-plugin-manager.c +++ b/ua-daemon/src/pm/ua-plugin-manager.c @@ -136,11 +136,11 @@ static int __load_sensor_plugins(void) const char *filename; int ret = UAM_ERROR_INTERNAL; - retv_if(0 == strlen(PLUGIN_DIR), UAM_ERROR_INVALID_PARAM); + retv_if(0 == strlen(SENSOR_PLUGIN_DIR), UAM_ERROR_INVALID_PARAM); - UAM_DBG("Loading plugins from %s", PLUGIN_DIR); + UAM_DBG("Loading plugins from %s", SENSOR_PLUGIN_DIR); - dir = g_dir_open(PLUGIN_DIR, 0, NULL); + dir = g_dir_open(SENSOR_PLUGIN_DIR, 0, NULL); if (!dir) { UAM_ERR("Unable to open directory"); return UAM_ERROR_INTERNAL; @@ -153,7 +153,7 @@ static int __load_sensor_plugins(void) /* If atleast one plugin is loaded, return value is UAM_ERROR_NONE */ if (UAM_ERROR_NONE == __load_plugin( - PLUGIN_DIR, filename, "uas_module")) + SENSOR_PLUGIN_DIR, filename, "uas_module")) ret = UAM_ERROR_NONE; } diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 64c8783..ae5d0fe 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -24,10 +24,10 @@ #include "ua-manager-database.h" #include "ua-manager-config-parser.h" +#include "ua-cloud-plugin-handler.h" #ifdef VD_REQ #include "ua-power-plugin-manager.h" -#include "ua-cloud-plugin-handler.h" #endif #define UAM_MAX_USERS 255 @@ -240,10 +240,9 @@ static void __free_uam_db_user_info(gpointer data) if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); -#ifdef VD_REQ /* Set/update registered device list to cloud plugin */ _uam_cloud_set_registered_devices(devices); -#endif + __uam_core_release_user_id(user->user_id); g_free(user->name); g_free(user->account); @@ -815,10 +814,9 @@ int _uam_core_remove_device(const char *account, const uam_device_info_t *dev_in if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); -#ifdef VD_REQ /* Set/update registered device list to cloud plugin */ _uam_cloud_set_registered_devices(devices); -#endif + FUNC_EXIT; return UAM_ERROR_NONE; } @@ -887,10 +885,9 @@ int _uam_core_remove_device_by_device_id(const char *device_id, int tech_type) if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); -#ifdef VD_REQ /* Set/update registered device list to cloud plugin */ _uam_cloud_set_registered_devices(devices); -#endif + FUNC_EXIT; return UAM_ERROR_NONE; } @@ -949,10 +946,9 @@ int _uam_core_remove_device_by_mac(const char *mac) if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); -#ifdef VD_REQ /* Set/update registered device list to cloud plugin */ _uam_cloud_set_registered_devices(devices); -#endif + FUNC_EXIT; return UAM_ERROR_NONE; } @@ -1484,10 +1480,9 @@ int _uam_core_init(void) if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices)) UAM_ERR("_uam_pm_set_registered_devices failed"); -#ifdef VD_REQ /* Set/update registered device list to cloud plugin */ _uam_cloud_set_registered_devices(devices); -#endif + FUNC_EXIT; return UAM_ERROR_NONE; } @@ -1630,13 +1625,11 @@ void _uam_core_handle_device_added(int status, UAM_ERR("_uam_pm_set_registered_devices failed"); } -#ifdef VD_REQ _uam_cloud_send_device_added(status, user_id, dev_info); /* Set/update registered device list to cloud plugin */ if (UAM_ERROR_NONE == status) _uam_cloud_set_registered_devices(devices); -#endif FUNC_EXIT; } @@ -1907,9 +1900,8 @@ void _uam_core_reset_database(void) UAM_ERR("_uam_pm_set_registered_devices failed with %s", _uam_manager_error_to_str(ret)); -#ifdef VD_REQ /* Set/update registered device list to cloud plugin */ _uam_cloud_set_registered_devices(devices); -#endif + FUNC_EXIT; } -- 2.7.4 From c025869b5b12b98f8c33f02851f9d4941372df3f Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Thu, 14 Mar 2019 15:54:41 +0530 Subject: [PATCH 10/16] Modified cloud plugin interface and plugin include dir Signed-off-by: Atul Rai --- packaging/ua-manager.spec | 6 ++- ua-daemon/CMakeLists.txt | 2 +- ua-daemon/include/ua-cloud-plugin-handler.h | 4 +- ua-daemon/include/ua-manager-common.h | 2 +- ua-daemon/src/pm/ua-cloud-plugin-handler.c | 20 +++++---- ua-daemon/src/ua-manager-core.c | 18 ++++---- ua-plugins/CMakeLists.txt | 4 +- ua-plugins/include/ua-cloud-plugin.h | 61 +++++-------------------- ua-plugins/include/ua-plugin-type.h | 70 +++++++++++++++++++++++++++++ ua-plugins/ua-plugins.pc.in | 2 +- 10 files changed, 113 insertions(+), 76 deletions(-) create mode 100644 ua-plugins/include/ua-plugin-type.h diff --git a/packaging/ua-manager.spec b/packaging/ua-manager.spec index 29dd4a5..804937a 100644 --- a/packaging/ua-manager.spec +++ b/packaging/ua-manager.spec @@ -105,7 +105,9 @@ cp ua-manager.service %{buildroot}%{_unitdir}/ua-manager.service %files plugins %defattr(-, root, root) -%{_includedir}/ua-manager/ua-plugin.h -%{_includedir}/ua-manager/ua-power-plugin.h +%{_includedir}/ua-manager/plugins/ua-plugin-type.h +%{_includedir}/ua-manager/plugins/ua-plugin.h +%{_includedir}/ua-manager/plugins/ua-power-plugin.h +%{_includedir}/ua-manager/plugins/ua-cloud-plugin.h %{_libdir}/pkgconfig/ua-plugins.pc diff --git a/ua-daemon/CMakeLists.txt b/ua-daemon/CMakeLists.txt index 7142fcf..cc833a8 100644 --- a/ua-daemon/CMakeLists.txt +++ b/ua-daemon/CMakeLists.txt @@ -19,12 +19,12 @@ SET(SRCS src/pm/ua-wifi-plugin-handler.c src/pm/ua-light-plugin-handler.c src/pm/ua-motion-plugin-handler.c + src/pm/ua-cloud-plugin-handler.c ) IF("$ENV{CFLAGS}" MATCHES "-DVD_REQ") LIST(APPEND SRCS src/pm/ua-power-plugin-manager.c) LIST(APPEND SRCS src/pm/ua-power-plugin-handler.c) - LIST(APPEND SRCS src/pm/ua-cloud-plugin-handler.c) ENDIF() IF("${CMAKE_BUILD_TYPE}" STREQUAL "") diff --git a/ua-daemon/include/ua-cloud-plugin-handler.h b/ua-daemon/include/ua-cloud-plugin-handler.h index 0577963..b21e51f 100644 --- a/ua-daemon/include/ua-cloud-plugin-handler.h +++ b/ua-daemon/include/ua-cloud-plugin-handler.h @@ -22,9 +22,9 @@ extern "C" { #endif -void _uam_cloud_set_registered_devices(GSList *devices); +void _uam_cloud_update_registered_devices(void); -void _uam_cloud_send_device_added(int status, int user_id, +void _uam_cloud_send_device_added(int status, const char *account, const uam_device_info_t *dev_info); #ifdef __cplusplus diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h index b838e96..2e30d4b 100644 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -57,8 +57,8 @@ extern "C" { #define SENSOR_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/sensor") #ifdef VD_REQ #define POWER_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/power") -#define CLOUD_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/cloud") #endif +#define CLOUD_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/cloud") #define UAM_VERSION "0.1" diff --git a/ua-daemon/src/pm/ua-cloud-plugin-handler.c b/ua-daemon/src/pm/ua-cloud-plugin-handler.c index 9042236..3aec5e1 100644 --- a/ua-daemon/src/pm/ua-cloud-plugin-handler.c +++ b/ua-daemon/src/pm/ua-cloud-plugin-handler.c @@ -19,6 +19,7 @@ #include #include #include +#include #include typedef struct { @@ -34,7 +35,7 @@ static int add_user(const char *account, const char *name) FUNC_ENTRY; FUNC_EXIT; - return UAC_STATUS_SUCCESS; + return UAP_STATUS_SUCCESS; } static int remove_user(const char *account) @@ -42,23 +43,23 @@ static int remove_user(const char *account) FUNC_ENTRY; FUNC_EXIT; - return UAC_STATUS_SUCCESS; + return UAP_STATUS_SUCCESS; } -static int add_device(const char *account, uac_device_info_t *dev_info) +static int add_device(const char *account, uap_device_info_t *dev_info) { FUNC_ENTRY; FUNC_EXIT; - return UAC_STATUS_SUCCESS; + return UAP_STATUS_SUCCESS; } -static int remove_device(const char *account, char* device_id) +static int remove_device(const char* device_id, int type) { FUNC_ENTRY; FUNC_EXIT; - return UAC_STATUS_SUCCESS; + return UAP_STATUS_SUCCESS; } static void reset_ua_db(void) @@ -76,14 +77,14 @@ uac_callbacks_t cloud_cb = { .reset_cb = reset_ua_db }; -void _uam_cloud_set_registered_devices(GSList *devices) +void _uam_cloud_update_registered_devices(void) { FUNC_ENTRY; FUNC_EXIT; } -void _uam_cloud_send_device_added(int status, int user_id, +void _uam_cloud_send_device_added(int status, const char *account, const uam_device_info_t *dev_info) { FUNC_ENTRY; @@ -199,6 +200,7 @@ static int __load_cloud_plugin(void) static void __deinit_cloud_plugin(void) { FUNC_ENTRY; + ret_if(NULL == cloud_plugin); uac_api_t *api = (uac_api_t *)cloud_plugin->api; uac_module_t *module = (uac_module_t *)cloud_plugin->module; @@ -233,7 +235,7 @@ static int __init_cloud_plugin(void) } status = ((uac_api_t *)cloud_plugin->api)->init(&cloud_cb); - if (UAC_STATUS_SUCCESS != status) { + if (UAP_STATUS_SUCCESS != status) { /* Deinit plugin */ __deinit_cloud_plugin(); return UAM_ERROR_INTERNAL; diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index ae5d0fe..8e25ace 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -241,7 +241,7 @@ static void __free_uam_db_user_info(gpointer data) UAM_ERR("_uam_pm_set_registered_devices failed"); /* Set/update registered device list to cloud plugin */ - _uam_cloud_set_registered_devices(devices); + _uam_cloud_update_registered_devices(); __uam_core_release_user_id(user->user_id); g_free(user->name); @@ -815,7 +815,7 @@ int _uam_core_remove_device(const char *account, const uam_device_info_t *dev_in UAM_ERR("_uam_pm_set_registered_devices failed"); /* Set/update registered device list to cloud plugin */ - _uam_cloud_set_registered_devices(devices); + _uam_cloud_update_registered_devices(); FUNC_EXIT; return UAM_ERROR_NONE; @@ -886,7 +886,7 @@ int _uam_core_remove_device_by_device_id(const char *device_id, int tech_type) UAM_ERR("_uam_pm_set_registered_devices failed"); /* Set/update registered device list to cloud plugin */ - _uam_cloud_set_registered_devices(devices); + _uam_cloud_update_registered_devices(); FUNC_EXIT; return UAM_ERROR_NONE; @@ -947,7 +947,7 @@ int _uam_core_remove_device_by_mac(const char *mac) UAM_ERR("_uam_pm_set_registered_devices failed"); /* Set/update registered device list to cloud plugin */ - _uam_cloud_set_registered_devices(devices); + _uam_cloud_update_registered_devices(); FUNC_EXIT; return UAM_ERROR_NONE; @@ -1481,7 +1481,7 @@ int _uam_core_init(void) UAM_ERR("_uam_pm_set_registered_devices failed"); /* Set/update registered device list to cloud plugin */ - _uam_cloud_set_registered_devices(devices); + _uam_cloud_update_registered_devices(); FUNC_EXIT; return UAM_ERROR_NONE; @@ -1538,6 +1538,7 @@ void _uam_core_handle_device_added(int status, { FUNC_ENTRY; GSList *l; + uam_db_user_info_t *user = NULL; /* Send reply over dbus for add device API */ l = _uam_manager_get_request_list(); @@ -1574,7 +1575,6 @@ void _uam_core_handle_device_added(int status, } if (UAM_ERROR_NONE == status) { - uam_db_user_info_t *user; long long timestamp; if (0 > user_id) { @@ -1625,11 +1625,11 @@ void _uam_core_handle_device_added(int status, UAM_ERR("_uam_pm_set_registered_devices failed"); } - _uam_cloud_send_device_added(status, user_id, dev_info); + _uam_cloud_send_device_added(status, (user ? user->account : NULL), dev_info); /* Set/update registered device list to cloud plugin */ if (UAM_ERROR_NONE == status) - _uam_cloud_set_registered_devices(devices); + _uam_cloud_update_registered_devices(); FUNC_EXIT; } @@ -1901,7 +1901,7 @@ void _uam_core_reset_database(void) _uam_manager_error_to_str(ret)); /* Set/update registered device list to cloud plugin */ - _uam_cloud_set_registered_devices(devices); + _uam_cloud_update_registered_devices(); FUNC_EXIT; } diff --git a/ua-plugins/CMakeLists.txt b/ua-plugins/CMakeLists.txt index 5474290..5b08666 100644 --- a/ua-plugins/CMakeLists.txt +++ b/ua-plugins/CMakeLists.txt @@ -4,12 +4,14 @@ PROJECT(ua-plugins C) SET(LIB_PKGCONFIG_DIR "${LIB_PATH}/pkgconfig") SET(HEADERS + ua-plugin-type.h ua-plugin.h ua-power-plugin.h + ua-cloud-plugin.h ) FOREACH(hfile ${HEADERS}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/${hfile} DESTINATION include/ua-manager) + INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/${hfile} DESTINATION include/ua-manager/plugins/) ENDFOREACH(hfile) SET(PC_NAME ${PROJECT_NAME}) diff --git a/ua-plugins/include/ua-cloud-plugin.h b/ua-plugins/include/ua-cloud-plugin.h index df1281e..63bb802 100644 --- a/ua-plugins/include/ua-cloud-plugin.h +++ b/ua-plugins/include/ua-cloud-plugin.h @@ -18,56 +18,16 @@ #ifndef __UAM_CLOUD_PLUGIN_H__ #define __UAM_CLOUD_PLUGIN_H__ +#include + #ifdef __cplusplus extern "C" { #endif -#define PLUGIN_ID_CLOUD 0x21 - -/* UA power plugin return status */ -typedef enum { - UAC_STATUS_SUCCESS = 0x00, - UAC_STATUS_FAIL = 0x01, - UAC_STATUS_NOT_READY = 0x02, - UAC_STATUS_NOMEM = 0x03, - UAC_STATUS_BUSY = 0x04, - UAC_STATUS_ALREADY_DONE = 0x05, - UAC_STATUS_UNSUPPORTED = 0x06, - UAC_STATUS_TIMEOUT = 0x07, - UAC_STATUS_INVALID_PARAMS = 0x08, -} uac_status_e; - -/* Device Address types */ -typedef enum { - UAC_ADDR_TYPE_BT = 0x01, - UAC_ADDR_TYPE_BLE, - UAC_ADDR_TYPE_WIFI, - UAC_ADDR_TYPE_P2P, - UAC_ADDR_TYPE_IPv4, - UAC_ADDR_TYPE_IPv6, - UAC_ADDR_TYPE_INVALID -} uac_address_type_e; - -/* Device address information structure */ -typedef struct { - uac_address_type_e type; - char *address; -} uac_address_info_t; - -/* Device information structure */ -typedef struct { - int user_id; - unsigned int supported_techs; - char *device_id; - int os; - int num_addr; - uac_address_info_t *addr_list; -} uac_device_info_t; - /* * DIRECTION: Cloud-plugin ---> ua-manager * This callback will be invoked to request user addition in ua database. - * [Param] account - User account id + * [Param] account - User account * [Param] name - User name */ typedef int (*add_user_callback)(const char *account, const char *name); @@ -75,25 +35,25 @@ typedef int (*add_user_callback)(const char *account, const char *name); /* * DIRECTION: Cloud-plugin ---> ua-manager * This callback will be invoked to request user deletion from ua database. - * [Param] account - User account id + * [Param] account - User account */ typedef int (*remove_user_callback)(const char *account); /* * DIRECTION: Cloud-plugin ---> ua-manager * This callback will be invoked to request device addition in ua database. - * [Param] account - Device's user account id + * [Param] account - Device's user account * [Param] dev_info - Device information */ -typedef int (*add_device_callback)(const char *account, uac_device_info_t *dev_info); +typedef int (*add_device_callback)(const char *account, uap_device_info_t *dev_info); /* * DIRECTION: Cloud-plugin ---> ua-manager * This callback will be invoked to request device deletion from ua database. - * [Param] account - Device's user account id * [Param] device_id - Unique device Id + * [Param] type - Device's technology type (BLE/WIFI/...) */ -typedef int (*remove_device_callback)(const char *account, char* device_id); +typedef int (*remove_device_callback)(const char* device_id, int type); /* * DIRECTION: Cloud-plugin ---> ua-manager @@ -131,16 +91,17 @@ typedef struct { * [Param] num_devices - Number of registered devices. * [Param] devices - List of registered devices. */ - int (*set_registered_devices)(int num_devices, uac_device_info_t *devices); + int (*set_registered_devices)(int num_devices, uap_device_info_t *devices); /* * DIRECTION: ua-manager ---> Cloud-plugin * This API is invoked whenever a device is added in ua db. * It is also used to send response for add_device_callback(). * [Param] status - status for device add request + * [Param] account - Device's User account * [Param] dev_info - Device info for added device */ - int (*device_added)(int status, uac_device_info_t *dev_info); + int (*device_added)(int status, const char *account, uap_device_info_t *dev_info); } uac_api_t; typedef struct { diff --git a/ua-plugins/include/ua-plugin-type.h b/ua-plugins/include/ua-plugin-type.h new file mode 100644 index 0000000..d2c9d75 --- /dev/null +++ b/ua-plugins/include/ua-plugin-type.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 __UAP_TYPE_H__ +#define __UAP_TYPE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define PLUGIN_ID_CLOUD 0x21 + +#define UAP_MAC_ADDRESS_STRING_LEN 18 +#define UAP_DEVICE_ID_MAX_STRING_LEN 50 +#define UAP_IP_ADDRESS_MAX_STRING_LEN 50 + +typedef enum { + UAP_OS_TYPE_ANDROID = 0x00, + UAP_OS_TYPE_IOS, + UAP_OS_TYPE_TIZEN, + UAP_OS_TYPE_INVALID +} uap_os_type_e; + +typedef enum { + UAP_TECH_TYPE_NONE = 0x00, + UAP_TECH_TYPE_BT = 0x01, + UAP_TECH_TYPE_BLE = 0x02, + UAP_TECH_TYPE_WIFI = 0x04, + UAP_TECH_TYPE_P2P = 0x08, +} uap_tech_type_e; + +typedef struct { + uap_os_type_e os; /* Device's OS */ + uap_tech_type_e type; /* Device's mac address type (BT/BLE/WIFI/P2p/...) */ + char mac[UAP_MAC_ADDRESS_STRING_LEN]; /* Device's MAC ADDRESS */ + char ipv4_addr[UAP_IP_ADDRESS_MAX_STRING_LEN];/* Device's IPv4 address optional */ + char device_id[UAP_DEVICE_ID_MAX_STRING_LEN]; /* Device's uniquie ID */ +} uap_device_info_t; + +/* UA plugin return status */ +typedef enum { + UAP_STATUS_SUCCESS = 0x00, + UAP_STATUS_FAIL = 0x01, + UAP_STATUS_NOT_READY = 0x02, + UAP_STATUS_NOMEM = 0x03, + UAP_STATUS_BUSY = 0x04, + UAP_STATUS_ALREADY_DONE = 0x05, + UAP_STATUS_UNSUPPORTED = 0x06, + UAP_STATUS_TIMEOUT = 0x07, + UAP_STATUS_INVALID_PARAMS = 0x08, +} uap_status_e; + +#ifdef __cplusplus +} +#endif +#endif /* __UAP_TYPE_H__ */ diff --git a/ua-plugins/ua-plugins.pc.in b/ua-plugins/ua-plugins.pc.in index cc97f97..a779c1a 100644 --- a/ua-plugins/ua-plugins.pc.in +++ b/ua-plugins/ua-plugins.pc.in @@ -6,4 +6,4 @@ Name: @PC_NAME@ Description: Samsung Tizen platform User awareness sensor plugin interface Version: @VERSION@ Requires: @PC_REQUIRED@ -Cflags: -I${includedir} -I${includedir}/ua-manager +Cflags: -I${includedir} -I${includedir}/ua-manager/plugins -- 2.7.4 From 595fbe0ad95dc547a1e21cb4691bce8203c45846 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Thu, 14 Mar 2019 15:56:33 +0530 Subject: [PATCH 11/16] Added cloud plugin API and callback implementation Signed-off-by: Atul Rai --- ua-daemon/src/pm/ua-cloud-plugin-handler.c | 112 +++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/ua-daemon/src/pm/ua-cloud-plugin-handler.c b/ua-daemon/src/pm/ua-cloud-plugin-handler.c index 3aec5e1..2d45b6e 100644 --- a/ua-daemon/src/pm/ua-cloud-plugin-handler.c +++ b/ua-daemon/src/pm/ua-cloud-plugin-handler.c @@ -30,9 +30,50 @@ typedef struct { uam_plugin_info_t *cloud_plugin; +static void __uap_to_uam_device_info(uam_device_info_t *dest, + const uap_device_info_t *src) +{ + FUNC_ENTRY; + + ret_if(NULL == src); + ret_if(NULL == dest); + + dest->operating_system = src->os; + dest->type = src->type; + g_strlcpy(dest->device_id, src->device_id, UAM_DEVICE_ID_MAX_STRING_LEN); + g_strlcpy(dest->mac, src->mac, UAM_MAC_ADDRESS_STRING_LEN); + g_strlcpy(dest->ipv4_addr, src->ipv4_addr, UAM_IP_ADDRESS_MAX_STRING_LEN); + + FUNC_EXIT; +} + +static void __uam_to_uap_device_info(uap_device_info_t *dest, + const uam_device_info_t *src) +{ + FUNC_ENTRY; + + ret_if(NULL == src); + ret_if(NULL == dest); + + dest->os = src->operating_system; + dest->type = src->type; + g_strlcpy(dest->device_id, src->device_id, UAP_DEVICE_ID_MAX_STRING_LEN); + g_strlcpy(dest->mac, src->mac, UAP_MAC_ADDRESS_STRING_LEN); + g_strlcpy(dest->ipv4_addr, src->ipv4_addr, UAP_IP_ADDRESS_MAX_STRING_LEN); + + FUNC_EXIT; +} + static int add_user(const char *account, const char *name) { FUNC_ENTRY; + retv_if(NULL == account, UAP_STATUS_INVALID_PARAMS); + retv_if(NULL == name, UAP_STATUS_INVALID_PARAMS); + + if (UAM_ERROR_NONE != _uam_core_add_user(account, name)) { + UAM_ERR("_uam_core_add_user() failed"); + return UAP_STATUS_FAIL; + } FUNC_EXIT; return UAP_STATUS_SUCCESS; @@ -41,6 +82,12 @@ static int add_user(const char *account, const char *name) static int remove_user(const char *account) { FUNC_ENTRY; + retv_if(NULL == account, UAP_STATUS_INVALID_PARAMS); + + if (UAM_ERROR_NONE != _uam_core_remove_user(account)) { + UAM_ERR("_uam_core_remove_user() failed"); + return UAP_STATUS_FAIL; + } FUNC_EXIT; return UAP_STATUS_SUCCESS; @@ -49,6 +96,18 @@ static int remove_user(const char *account) static int add_device(const char *account, uap_device_info_t *dev_info) { FUNC_ENTRY; + uam_device_info_t device; + + retv_if(NULL == account, UAP_STATUS_INVALID_PARAMS); + retv_if(NULL == dev_info, UAP_STATUS_INVALID_PARAMS); + + memset(&device, 0x00, sizeof(uam_device_info_t)); + __uap_to_uam_device_info(&device, dev_info); + + if (UAM_ERROR_NONE != _uam_core_add_device(account, &device)) { + UAM_ERR("_uam_core_remove_user() failed"); + return UAP_STATUS_FAIL; + } FUNC_EXIT; return UAP_STATUS_SUCCESS; @@ -58,6 +117,15 @@ static int remove_device(const char* device_id, int type) { FUNC_ENTRY; + retv_if(NULL == device_id, UAP_STATUS_INVALID_PARAMS); + retv_if(UAP_TECH_TYPE_NONE >= type, UAM_ERROR_INVALID_PARAM); + retv_if(UAP_TECH_TYPE_P2P < type, UAM_ERROR_INVALID_PARAM); + + if (UAM_ERROR_NONE != _uam_core_remove_device_by_device_id(device_id, type)) { + UAM_ERR("_uam_core_remove_user() failed"); + return UAP_STATUS_FAIL; + } + FUNC_EXIT; return UAP_STATUS_SUCCESS; } @@ -80,7 +148,34 @@ uac_callbacks_t cloud_cb = { void _uam_cloud_update_registered_devices(void) { FUNC_ENTRY; + int indx; + uam_device_info_t *devices = NULL; + uap_device_info_t *dev_list = NULL; + int num_devices = 0; + uac_api_t *api; + + ret_if(NULL == cloud_plugin); + + api = (uac_api_t *)cloud_plugin->api; + ret_if(NULL == api); + ret_if(NULL == api->set_registered_devices); + if (UAM_ERROR_NONE != _uam_core_get_devices(&num_devices, &devices)) { + UAM_ERR("_uam_core_get_devices() failed"); + } else { + dev_list = g_new0(uap_device_info_t, num_devices); + for (indx = 0; indx < num_devices; indx++) + __uam_to_uap_device_info(&(dev_list[indx]), &(devices[indx])); + } + + if (!dev_list) + UAM_INFO("No devices in the list"); + + if (UAP_STATUS_SUCCESS != api->set_registered_devices(num_devices, dev_list)) + UAM_ERR("api->set_registered_devices() failed"); + + g_free(devices); + g_free(dev_list); FUNC_EXIT; } @@ -88,6 +183,23 @@ void _uam_cloud_send_device_added(int status, const char *account, const uam_device_info_t *dev_info) { FUNC_ENTRY; + ret_if(NULL == cloud_plugin); + uac_api_t *api = (uac_api_t *)cloud_plugin->api; + uap_device_info_t dev; + + ret_if(NULL == api); + ret_if(NULL == api->device_added); + ret_if(NULL == dev_info); + + if (UAM_ERROR_NONE != status) + status = UAP_STATUS_FAIL; + else + status = UAP_STATUS_SUCCESS; + + memset(&dev, 0x00, sizeof(uap_device_info_t)); + __uam_to_uap_device_info(&dev, dev_info); + if (UAP_STATUS_SUCCESS != api->device_added(status, account, &dev)) + UAM_ERR("api->device_added() failed"); FUNC_EXIT; } -- 2.7.4 From 6540dd872d2f89cf11e6aeeabfd685c7ffe9692e Mon Sep 17 00:00:00 2001 From: Mayank Haarit Date: Thu, 14 Mar 2019 20:59:33 +0530 Subject: [PATCH 12/16] Remove VD_REQ for power plugin related part Change-Id: I22c77430f9c3b01aee1eb92c82a28c74d2ec5664 Signed-off-by: Mayank Haarit --- packaging/ua-manager.spec | 3 --- ua-daemon/CMakeLists.txt | 7 ++----- ua-daemon/include/ua-manager-common.h | 2 -- ua-daemon/src/ua-manager-core.c | 4 ---- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/packaging/ua-manager.spec b/packaging/ua-manager.spec index 804937a..2ec5190 100644 --- a/packaging/ua-manager.spec +++ b/packaging/ua-manager.spec @@ -49,9 +49,6 @@ cp -a %{SOURCE3} . cp %{SOURCE1001} . %build -%if 0%{?vd_req:1} -export CFLAGS="$CFLAGS -DVD_REQ" -%endif MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \ diff --git a/ua-daemon/CMakeLists.txt b/ua-daemon/CMakeLists.txt index cc833a8..f957f4f 100644 --- a/ua-daemon/CMakeLists.txt +++ b/ua-daemon/CMakeLists.txt @@ -20,13 +20,10 @@ SET(SRCS src/pm/ua-light-plugin-handler.c src/pm/ua-motion-plugin-handler.c src/pm/ua-cloud-plugin-handler.c + src/pm/ua-power-plugin-manager.c + src/pm/ua-power-plugin-handler.c ) -IF("$ENV{CFLAGS}" MATCHES "-DVD_REQ") - LIST(APPEND SRCS src/pm/ua-power-plugin-manager.c) - LIST(APPEND SRCS src/pm/ua-power-plugin-handler.c) -ENDIF() - IF("${CMAKE_BUILD_TYPE}" STREQUAL "") SET(CMAKE_BUILD_TYPE "Release") ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") diff --git a/ua-daemon/include/ua-manager-common.h b/ua-daemon/include/ua-manager-common.h index 2e30d4b..0f32d21 100644 --- a/ua-daemon/include/ua-manager-common.h +++ b/ua-daemon/include/ua-manager-common.h @@ -55,9 +55,7 @@ extern "C" { #define FUNC_EXIT UAM_DBG("-") #define SENSOR_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/sensor") -#ifdef VD_REQ #define POWER_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/power") -#endif #define CLOUD_PLUGIN_DIR tzplatform_mkpath(TZ_SYS_GLOBALUSER_DATA, "network/ua/lib/cloud") #define UAM_VERSION "0.1" diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 8e25ace..5b1a096 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -26,9 +26,7 @@ #include "ua-manager-config-parser.h" #include "ua-cloud-plugin-handler.h" -#ifdef VD_REQ #include "ua-power-plugin-manager.h" -#endif #define UAM_MAX_USERS 255 #define USER_ACCOUNT_DEFAULT "default@default.com" @@ -1645,9 +1643,7 @@ void _uam_core_handle_presence_detected(unsigned int sensor, UAM_INFO("sensor: 0x%8.8X, user_id: %d", sensor, user_id); -#ifdef VD_REQ _uam_ppm_send_presence_detection_event(sensor); -#endif if (NULL == dev_info) { _uam_manager_send_event(NULL, UAM_EVENT_PRESENCE_DETECTED, -- 2.7.4 From da289ee0615fe743443ff1c40b51b381f2578460 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Wed, 20 Mar 2019 16:39:11 +0530 Subject: [PATCH 13/16] Aligned OS type across all interface headers Change-Id: I2d6d44358f350e42d4846709c25a3441454adc04 Signed-off-by: Atul Rai --- include/ua-api.h | 5 +++-- ua-plugins/include/ua-plugin-type.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index 9621b8e..12c0127 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -117,9 +117,10 @@ typedef enum { } uam_presence_state_e; typedef enum { - UAM_OS_TYPE_ANDROID = 0x00, - UAM_OS_TYPE_IOS, + UAM_OS_TYPE_UNDEFINED = 0x00, UAM_OS_TYPE_TIZEN, + UAM_OS_TYPE_ANDROID, + UAM_OS_TYPE_IOS, UAM_OS_TYPE_INVALID } uam_os_type_e; diff --git a/ua-plugins/include/ua-plugin-type.h b/ua-plugins/include/ua-plugin-type.h index d2c9d75..e91972b 100644 --- a/ua-plugins/include/ua-plugin-type.h +++ b/ua-plugins/include/ua-plugin-type.h @@ -29,9 +29,10 @@ extern "C" { #define UAP_IP_ADDRESS_MAX_STRING_LEN 50 typedef enum { - UAP_OS_TYPE_ANDROID = 0x00, - UAP_OS_TYPE_IOS, + UAP_OS_TYPE_UNDEFINED = 0x00, UAP_OS_TYPE_TIZEN, + UAP_OS_TYPE_ANDROID, + UAP_OS_TYPE_IOS, UAP_OS_TYPE_INVALID } uap_os_type_e; -- 2.7.4 From c7f8a7deb22fd212d97810bb492384daf7d88d42 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Wed, 20 Mar 2019 16:42:40 +0530 Subject: [PATCH 14/16] Handle NULL account in add_device_cb from cloud plugin Change-Id: Iebf37b1d4029d23f795f02d27d60ffe349bbcd92 Signed-off-by: Atul Rai --- ua-daemon/src/pm/ua-cloud-plugin-handler.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ua-daemon/src/pm/ua-cloud-plugin-handler.c b/ua-daemon/src/pm/ua-cloud-plugin-handler.c index 2d45b6e..1a98b54 100644 --- a/ua-daemon/src/pm/ua-cloud-plugin-handler.c +++ b/ua-daemon/src/pm/ua-cloud-plugin-handler.c @@ -97,8 +97,17 @@ static int add_device(const char *account, uap_device_info_t *dev_info) { FUNC_ENTRY; uam_device_info_t device; + uam_user_info_t user; + + if (NULL == account) { + if (UAM_ERROR_NONE != _uam_core_get_default_user(&user)) { + UAM_ERR("_uam_core_get_default_user failed"); + return UAP_STATUS_FAIL; + } + + account = user.account; + } - retv_if(NULL == account, UAP_STATUS_INVALID_PARAMS); retv_if(NULL == dev_info, UAP_STATUS_INVALID_PARAMS); memset(&device, 0x00, sizeof(uam_device_info_t)); -- 2.7.4 From ee816d515075aeee20bb72b69ca3023507b7bc82 Mon Sep 17 00:00:00 2001 From: Atul Rai Date: Tue, 26 Mar 2019 10:23:04 +0530 Subject: [PATCH 15/16] Added support for GET/SET detection parameters Change-Id: I7c8d3448fc31fbc7bed714240585a1bb043b04b6 Signed-off-by: Atul Rai --- include/ua-api.h | 10 +++++ include/ua-internal.h | 2 + packaging/ua-manager.spec | 4 +- ua-api/src/ua-api.c | 54 ++++++++++++++++++++++++ ua-daemon/include/ua-manager-config-parser.h | 2 + ua-daemon/include/ua-manager-core.h | 5 ++- ua-daemon/src/ua-manager-config-parser.c | 59 ++++++++++++++++++++++++++ ua-daemon/src/ua-manager-core.c | 62 ++++++++++++++++++++++++---- ua-daemon/src/ua-manager-request-handler.c | 22 ++++++++++ 9 files changed, 209 insertions(+), 11 deletions(-) diff --git a/include/ua-api.h b/include/ua-api.h index 12c0127..7b1245b 100644 --- a/include/ua-api.h +++ b/include/ua-api.h @@ -155,6 +155,12 @@ typedef struct { char name[UAM_USER_NAME_MAX_STRING_LEN]; } uam_user_event_data_t; +typedef struct { + int cycle; + int period; + int retries; +} uam_detection_params_t; + int _uam_get_registered_users(GPtrArray **user_list); int _uam_is_device_registered( @@ -202,6 +208,10 @@ int _uam_enable_low_power_mode(void); int _uam_disable_low_power_mode(void); +int _uam_get_detection_params(int *cycle, int *period, int *retries); + +int _uam_set_detection_params(int cycle, int period, int retries); + #ifdef __cplusplus } #endif diff --git a/include/ua-internal.h b/include/ua-internal.h index dfb3966..fd6c8d9 100644 --- a/include/ua-internal.h +++ b/include/ua-internal.h @@ -57,6 +57,8 @@ extern "C" { REQUEST(UAM_REQUEST_START_ABSENCE_DETECTION) \ REQUEST(UAM_REQUEST_STOP_ABSENCE_DETECTION) \ REQUEST(UAM_REQUEST_SET_LOW_POWER_MODE) \ + REQUEST(UAM_REQUEST_GET_DETECTION_PARAMS) \ + REQUEST(UAM_REQUEST_SET_DETECTION_PARAMS) \ REQUEST(UAM_REQUEST_MAX) #define GENERATE_REQUEST_ENUM(ENUM) ENUM, diff --git a/packaging/ua-manager.spec b/packaging/ua-manager.spec index 2ec5190..38c9cbc 100644 --- a/packaging/ua-manager.spec +++ b/packaging/ua-manager.spec @@ -68,7 +68,7 @@ sqlite3 %{buildroot}%{database_full_path} < %{buildroot}/usr/share/ua_db.sql rm %{buildroot}/usr/share/ua_db.sql mkdir -p %{buildroot}/opt/usr/data/ua -install -m 0644 config/uam-config.json %{buildroot}%{config_file_path}/uam-config.json +cp config/uam-config.json %{buildroot}%{config_file_path}/uam-config.json mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d cp ua-manager.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/ua-manager.conf @@ -90,7 +90,7 @@ cp ua-manager.service %{buildroot}%{_unitdir}/ua-manager.service %config %{_sysconfdir}/dbus-1/system.d/ua-manager.conf %attr(644,root,root) %{_datadir}/dbus-1/system-services/* %attr(644,root,root) %{_unitdir}/ua-manager.service -%{config_file_path}/uam-config.json +%config %attr(660, network_fw, network_fw) %{config_file_path}/uam-config.json %config %attr(660, network_fw, network_fw) %{database_full_path} %config %attr(660, network_fw, network_fw) %{database_full_path}-journal diff --git a/ua-api/src/ua-api.c b/ua-api/src/ua-api.c index 1f71b25..d9b2621 100644 --- a/ua-api/src/ua-api.c +++ b/ua-api/src/ua-api.c @@ -718,3 +718,57 @@ UAM_EXPORT_API int _uam_disable_low_power_mode(void) FUNC_EXIT; return ret; } + +UAM_EXPORT_API int _uam_get_detection_params(int *cycle, int *period, int *retries) +{ + FUNC_ENTRY; + int ret; + + UAM_VALIDATE_INPUT_PARAMETER(cycle); + UAM_VALIDATE_INPUT_PARAMETER(period); + UAM_VALIDATE_INPUT_PARAMETER(retries); + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + ret = _uam_sync_request(UAM_REQUEST_GET_DETECTION_PARAMS, + in_param1, in_param2, in_param3, in_param4, &out_param); + if (UAM_ERROR_NONE == ret) { + uam_detection_params_t *detection_param; + + detection_param = &g_array_index(out_param, uam_detection_params_t, 0); + *cycle = detection_param->cycle; + *period = detection_param->period; + *retries = detection_param->retries; + UAM_INFO("Detection Params: cycle = %d, period = %d, retries = %d", + *cycle, *period, *retries); + } + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} + +UAM_EXPORT_API int _uam_set_detection_params(int cycle, int period, int retries) +{ + FUNC_ENTRY; + int ret; + uam_detection_params_t detection_param; + + detection_param.cycle = cycle; + detection_param.period = period; + detection_param.retries = retries; + + UAM_INIT_PARAMS(); + UAM_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &detection_param, sizeof(uam_detection_params_t)); + ret = _uam_sync_request(UAM_REQUEST_SET_DETECTION_PARAMS, + in_param1, in_param2, in_param3, in_param4, &out_param); + + UAM_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + FUNC_EXIT; + return ret; +} diff --git a/ua-daemon/include/ua-manager-config-parser.h b/ua-daemon/include/ua-manager-config-parser.h index 231c096..5be98ab 100644 --- a/ua-daemon/include/ua-manager-config-parser.h +++ b/ua-daemon/include/ua-manager-config-parser.h @@ -24,6 +24,8 @@ extern "C" { int _uam_read_detection_params(int *cycle, int *period, int *retries); +int _uam_write_detection_params(int cycle, int period, int retries); + #ifdef __cplusplus } #endif diff --git a/ua-daemon/include/ua-manager-core.h b/ua-daemon/include/ua-manager-core.h index b1e168e..1ee5e31 100644 --- a/ua-daemon/include/ua-manager-core.h +++ b/ua-daemon/include/ua-manager-core.h @@ -120,8 +120,9 @@ int _uam_core_stop_absence_detection(char *sender, unsigned int sensors); int _uam_core_set_low_power_mode(gboolean mode); -int _uam_core_set_detection_parameters(unsigned int sensor, - int cycle, int period, int retries); +int _uam_core_get_detection_parameters(int *cycle, int *period, int *retries); + +int _uam_core_set_detection_parameters(int cycle, int period, int retries); int _uam_core_init(void); diff --git a/ua-daemon/src/ua-manager-config-parser.c b/ua-daemon/src/ua-manager-config-parser.c index 63fbc7b..77e8010 100644 --- a/ua-daemon/src/ua-manager-config-parser.c +++ b/ua-daemon/src/ua-manager-config-parser.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "ua-internal.h" @@ -98,3 +99,61 @@ done: FUNC_EXIT; return ret; } + +int _uam_write_detection_params(int cycle, int period, int retries) +{ + FUNC_ENTRY; + int ret = UAM_ERROR_INTERNAL; + FILE *conf_file; + char *contents; + const char *out_content; + json_object *jmain; + json_object *jdparams; + json_object *jint; + + contents = __uam_get_file_content(UAM_CONFIG_FILE); + retv_if(NULL == contents, UAM_ERROR_INTERNAL); + + jmain = json_tokener_parse(contents); + if (!jmain) + goto done; + + /* Detection Parameters */ + json_object_object_get_ex(jmain, "DetectionParams", &jdparams); + if (!jdparams) + goto done; + + json_object_object_del(jdparams, "Cycle"); + jint = json_object_new_int(cycle); + json_object_object_add(jdparams, "Cycle", jint); + + json_object_object_del(jdparams, "Period"); + jint = json_object_new_int(period); + json_object_object_add(jdparams, "Period", jint); + + json_object_object_del(jdparams, "Retries"); + jint = json_object_new_int(retries); + json_object_object_add(jdparams, "Retries", jint); + + conf_file = fopen(UAM_CONFIG_FILE, "wr"); + if (!conf_file) { + char err_str[100]; + + strerror_r(errno, err_str, 100); + UAM_ERR("Failed to open file %s with error %s(%d)", + UAM_CONFIG_FILE, err_str, errno); + goto done; + } + + out_content = json_object_to_json_string_ext(jmain, JSON_C_TO_STRING_PRETTY); + fwrite(out_content, sizeof(char), strlen(out_content), conf_file); + fclose(conf_file); + ret = UAM_ERROR_NONE; +done: + g_free(contents); + if (jmain) + json_object_put(jmain); + + FUNC_EXIT; + return ret; +} diff --git a/ua-daemon/src/ua-manager-core.c b/ua-daemon/src/ua-manager-core.c index 5b1a096..b343b6d 100644 --- a/ua-daemon/src/ua-manager-core.c +++ b/ua-daemon/src/ua-manager-core.c @@ -1222,8 +1222,8 @@ static int __uam_core_start_detection(int detection_type, char *sender, unsigned { FUNC_ENTRY; int ret; - int active_sensors; - int inactive_sensors; + unsigned int active_sensors; + unsigned int inactive_sensors; uam_monitor_info_t *monitor; retv_if(NULL == sender, UAM_ERROR_INVALID_PARAM); @@ -1379,21 +1379,70 @@ int _uam_core_set_low_power_mode(gboolean mode) return UAM_ERROR_NONE; } -int _uam_core_set_detection_parameters(unsigned int sensor, - int cycle, int period, int retries) +int _uam_core_get_detection_parameters(int *cycle, int *period, int *retries) { FUNC_ENTRY; int ret; + retv_if(NULL == cycle, UAM_ERROR_INVALID_PARAM); + retv_if(NULL == period, UAM_ERROR_INVALID_PARAM); + retv_if(NULL == retries, UAM_ERROR_INVALID_PARAM); + + /* Read configuration */ + ret = _uam_read_detection_params(cycle, period, retries); + if (UAM_ERROR_NONE == ret) + UAM_INFO_C("Detection Params: [cycle = %d], [period = %d], " + "[retries = %d]", *cycle, *period, *retries); + + FUNC_EXIT; + return ret; +} + +int _uam_core_set_detection_parameters(int cycle, int period, int retries) +{ + FUNC_ENTRY; + int ret; + unsigned int presence_sensors; + unsigned int absence_sensors; + retv_if(cycle <= period, UAM_ERROR_INVALID_PARAM); - ret = _uam_pm_set_detection_params(sensor, cycle, period, retries); + /* Find sensors which are already monitoring and stop monitoring */ + presence_sensors = _uam_core_get_active_sensors(UAM_DETECT_PRESENCE); + UAM_DBG("UAM_DETECT_PRESENCE active_sensors: 0x%8.8X", presence_sensors); + if (0 != presence_sensors) + if (UAM_ERROR_NONE != _uam_pm_stop_detection( + UAM_DETECT_PRESENCE, presence_sensors)) + UAM_WARN("_uam_pm_stop_detection failed"); + + absence_sensors = _uam_core_get_active_sensors(UAM_DETECT_ABSENCE); + UAM_DBG("UAM_DETECT_ABSENCE active_sensors: 0x%8.8X", absence_sensors); + if (0 != absence_sensors) + if (UAM_ERROR_NONE != _uam_pm_stop_detection( + UAM_DETECT_ABSENCE, absence_sensors)) + UAM_WARN("_uam_pm_stop_detection failed"); + + ret = _uam_pm_set_detection_params(UAM_SENSOR_ALL, cycle, period, retries); if (UAM_ERROR_NONE != ret) { UAM_ERR("_uam_pm_set_detection_params failed with %s", _uam_manager_error_to_str(ret)); return ret; } + if (0 != presence_sensors) + if (UAM_ERROR_NONE != _uam_pm_start_detection( + UAM_DETECT_PRESENCE, presence_sensors)) + UAM_WARN("_uam_pm_start_detection failed"); + + if (0 != absence_sensors) + if (UAM_ERROR_NONE != _uam_pm_start_detection( + UAM_DETECT_ABSENCE, absence_sensors)) + UAM_WARN("_uam_pm_start_detection failed"); + + /* Update conf file */ + if (UAM_ERROR_NONE != _uam_write_detection_params(cycle, period, retries)) + UAM_WARN("_uam_write_detection_params failed"); + FUNC_EXIT; return UAM_ERROR_NONE; } @@ -1413,8 +1462,7 @@ int _uam_core_init(void) &cycle, &period, &retries)) { UAM_INFO_C("Detection Params: [cycle = %d], [period = %d], " "[retries = %d]", cycle, period, retries); - _uam_core_set_detection_parameters( - UAM_SENSOR_ALL, cycle, period, retries); + _uam_core_set_detection_parameters(cycle, period, retries); } /* Init database */ diff --git a/ua-daemon/src/ua-manager-request-handler.c b/ua-daemon/src/ua-manager-request-handler.c index f7e1860..5e775b1 100644 --- a/ua-daemon/src/ua-manager-request-handler.c +++ b/ua-daemon/src/ua-manager-request-handler.c @@ -370,6 +370,26 @@ static int __uam_manager_sync_request_handler( result = _uam_core_set_low_power_mode(mode); break; } + case UAM_REQUEST_GET_DETECTION_PARAMS: { + uam_detection_params_t detection_param; + + result = _uam_core_get_detection_parameters(&detection_param.cycle, + &detection_param.period, &detection_param.retries); + if (UAM_ERROR_NONE == result) + g_array_append_vals(*out_param1, + &detection_param, sizeof(uam_detection_params_t)); + break; + } + case UAM_REQUEST_SET_DETECTION_PARAMS: { + uam_detection_params_t detection_param; + + __uam_manager_copy_params(in_param1, + &detection_param, sizeof(uam_detection_params_t)); + + result = _uam_core_set_detection_parameters(detection_param.cycle, + detection_param.period, detection_param.retries); + break; + } default: UAM_WARN("UnSupported function [%s(0x%4.4X)]", _uam_manager_request_to_str(function), function); @@ -499,6 +519,8 @@ static gboolean __uam_manager_is_sync_function(int function) case UAM_REQUEST_START_ABSENCE_DETECTION: case UAM_REQUEST_STOP_ABSENCE_DETECTION: case UAM_REQUEST_SET_LOW_POWER_MODE: + case UAM_REQUEST_GET_DETECTION_PARAMS: + case UAM_REQUEST_SET_DETECTION_PARAMS: return TRUE; default: return FALSE; -- 2.7.4 From a81ffba108946c662074d37c732ef125561090f0 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Wed, 3 Apr 2019 13:32:55 +0900 Subject: [PATCH 16/16] Fix Svace issue : access memory after free Change-Id: I7cd057b2b6956161a34d2033878c52e05e1267e3 Signed-off-by: Jihoon Jung --- ua-daemon/src/pm/ua-power-plugin-manager.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ua-daemon/src/pm/ua-power-plugin-manager.c b/ua-daemon/src/pm/ua-power-plugin-manager.c index d1fd091..7b33e96 100644 --- a/ua-daemon/src/pm/ua-power-plugin-manager.c +++ b/ua-daemon/src/pm/ua-power-plugin-manager.c @@ -112,12 +112,14 @@ static int __load_power_plugin(const char *path, const char *name, const char *s UAM_DBG("Loading [%s]", filename); handle = dlopen(filename, RTLD_NOW); - g_free(filename); if (handle == NULL) { UAM_ERR("Can't load plugin %s: %s", filename, dlerror()); + g_free(filename); return UAM_ERROR_INTERNAL; } + g_free(filename); + module = (uap_module_t *)dlsym(handle, symbol); if (module == NULL) { UAM_ERR("Can't load power plugin module: %s", dlerror()); -- 2.7.4