Increased SAM score 61/212461/1
authorsaerome.kim <saerome.kim@samsung.com>
Wed, 21 Aug 2019 12:33:58 +0000 (21:33 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 22 Aug 2019 00:47:29 +0000 (09:47 +0900)
- Increase Duplicated Code ratio.
- Removed all Global Variable violations.
- Removed all Predefined Preprocessor violations.

Change-Id: I059dfc8d902ef9a6bf9be282380d0e6ba1aad3bd
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
13 files changed:
packaging/ua-manager.spec [changed mode: 0644->0755]
ua-api/include/ua-common.h
ua-api/src/ua-common.c
ua-daemon/CMakeLists.txt
ua-daemon/include/ua-manager-database.h
ua-daemon/src/pm/ua-cloud-plugin-handler.c
ua-daemon/src/pm/ua-pm-util.c
ua-daemon/src/pm/ua-power-plugin-manager.c [changed mode: 0755->0644]
ua-daemon/src/ua-manager-common.c
ua-daemon/src/ua-manager-core.c
ua-daemon/src/ua-manager-event-sender.c
ua-daemon/src/ua-manager-request-handler.c
ua-daemon/src/ua-manager-user-db.c

old mode 100644 (file)
new mode 100755 (executable)
index b0028aa..0a696e8
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.6.7
+Version:    0.6.8
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
@@ -59,6 +59,7 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
        -DLIB_PATH=%{_lib} \
        -DFULLVER=%{version} \
        -DMAJORVER=${MAJORVER} \
+       -DDATABASE_FULL_PATH=%{database_full_path}
 
 %install
 %make_install
index 146fcf6..7f96ff5 100644 (file)
@@ -26,9 +26,7 @@
 extern "C" {
 #endif
 
-#ifndef UAM_EXPORT_API
 #define UAM_EXPORT_API __attribute__((visibility("default")))
-#endif
 
 #ifdef LOG_TAG
 #undef LOG_TAG
index a5ecb81..7e2117c 100644 (file)
@@ -20,7 +20,7 @@
 
 #include "ua-common.h"
 
-const char *request_string[] = {
+static const char *request_string[] = {
        FOREACH_REQUEST(GENERATE_REQUEST_STRING)
 };
 
index 59e51f7..976da4a 100644 (file)
@@ -52,6 +52,11 @@ FOREACH(flag ${PKGS_MGR_CFLAGS})
         SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag} -Wall")
 ENDFOREACH(flag)
 
+MESSAGE(DATABASE_FULL_PATH)
+IF(DATABASE_FULL_PATH)
+    ADD_DEFINITIONS("-DDATABASE_FULL_PATH=\"${DATABAES_FULL_PATH}\"")
+ENDIF(DATABASE_FULL_PATH)
+
 SET(RELO_FLAGS "-D_FORTIFY_SOURCE=2 -Wl,-z,relro")
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${RELO_FLAGS} -fPIE -fPIC -Wall -Werror")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
index c9dd226..a1a527d 100644 (file)
@@ -28,10 +28,6 @@ extern "C" {
 
 #define SQLITE_BUSY_TIMEOUT 500000
 
-#ifndef DATABASE_FULL_PATH
-#define DATABASE_FULL_PATH "/opt/usr/dbspace/.ua-manager-data.db"
-#endif
-
 /* Helper macros */
 #define EXEC(error_code, command, handle_error) do { \
        if (error_code != command) { \
index 28f64f5..de14463 100644 (file)
@@ -28,7 +28,7 @@ typedef struct {
        void *api;
 } uam_plugin_info_t;
 
-uam_plugin_info_t *cloud_plugin;
+static uam_plugin_info_t *cloud_plugin;
 
 static void __uap_to_uam_device_info(uam_device_info_s *dest,
                const uap_device_info_t *src)
@@ -147,7 +147,7 @@ static void reset_ua_db(void)
        FUNC_EXIT;
 }
 
-uac_callbacks_t cloud_cb = {
+static uac_callbacks_t cloud_cb = {
        .add_user_cb = add_user,
        .remove_user_cb = remove_user,
        .add_device_cb = add_device,
index 085e2d9..4bf7b99 100644 (file)
@@ -22,7 +22,7 @@
 #include "ua-plugin.h"
 #include <ua-plugin-manager.h>
 
-const char *status_string[] = {
+static const char *status_string[] = {
        FOREACH_STATUS(GENERATE_STATUS_STRING)
 };
 
old mode 100755 (executable)
new mode 100644 (file)
index c1a7aff..3490061
@@ -29,7 +29,7 @@ typedef struct {
        uap_api_t *api;
 } uam_power_plugin_info_t;
 
-uam_power_plugin_info_t* pwr_plugin = NULL;
+static uam_power_plugin_info_t* pwr_plugin = NULL;
 
 static void __deinit_power_plugin(void)
 {
index 998e504..15b2736 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "ua-manager-common.h"
 
-const char *request_string[] = {
+static const char *request_string[] = {
        FOREACH_REQUEST(GENERATE_REQUEST_STRING)
 };
 
index f3c6497..466850f 100644 (file)
@@ -44,12 +44,12 @@ typedef struct {
        guint timer;
 } uam_scanner_info_t;
 
-GSList *users; /* List of users - uam_db_user_info_t */
-GSList *devices; /* List of devices - uam_db_device_info_t */
-GSList *services; /* List of services -  uam_db_service_info_t */
+static GSList *users; /* List of users - uam_db_user_info_t */
+static GSList *devices; /* List of devices - uam_db_device_info_t */
+static GSList *services; /* List of services -  uam_db_service_info_t */
 
-GSList *monitors; /* List of monitoring apps - uam_monitor_info_t */
-GSList *scanners; /* List of scanning apps -  uam_scanner_info_t */
+static GSList *monitors; /* List of monitoring apps - uam_monitor_info_t */
+static GSList *scanners; /* List of scanning apps -  uam_scanner_info_t */
 
 static guint detection_timer = 0;
 static unsigned int detection_window;
@@ -484,21 +484,9 @@ static void __get_uam_db_dev_list_to_uam_dev_list(
        FUNC_EXIT;
 }
 
-static int __copy_tech_info_to_device_info(uam_db_tech_info_t *tech, uam_device_info_s *device)
+static void __uam_core_copy_addr(uam_device_info_s *device, uam_db_address_info_t *addr)
 {
-       FUNC_ENTRY;
-       GSList *l;
-
-       retv_if(NULL == tech, UAM_ERROR_INVALID_PARAMETER);
-
-       memset(device, 0x00, sizeof(uam_device_info_s));
-       for (l = tech->addresses; NULL != l; l = g_slist_next(l)) {
-               uam_db_address_info_t *addr = l->data;
-
-               if (!addr)
-                       continue;
-
-               switch (addr->addr_type) {
+       switch (addr->addr_type) {
                case UAM_ADDR_TYPE_BLE:
                case UAM_ADDR_TYPE_BT:
                case UAM_ADDR_TYPE_P2P:
@@ -513,7 +501,24 @@ static int __copy_tech_info_to_device_info(uam_db_tech_info_t *tech, uam_device_
                        break;
                default:
                        UAM_WARN("Unknown address type %d", addr->addr_type);
-               }
+       }
+}
+
+static int __copy_tech_info_to_device_info(uam_db_tech_info_t *tech, uam_device_info_s *device)
+{
+       FUNC_ENTRY;
+       GSList *l;
+
+       retv_if(NULL == tech, UAM_ERROR_INVALID_PARAMETER);
+
+       memset(device, 0x00, sizeof(uam_device_info_s));
+       for (l = tech->addresses; NULL != l; l = g_slist_next(l)) {
+               uam_db_address_info_t *addr = l->data;
+
+               if (!addr)
+                       continue;
+
+               __uam_core_copy_addr(device, addr);
        }
 
        device->operating_system = tech->device->os;
@@ -902,37 +907,13 @@ done:
        return UAM_ERROR_NONE;
 }
 
-int _uam_core_remove_device(const char *account, const uam_device_info_s *dev_info)
+static int __uam_remove_device(int user_id, uam_db_device_info_t *device,
+       const uam_device_info_s *dev_info, uam_db_tech_info_t *tech)
 {
-       FUNC_ENTRY;
        int ret;
        GSList *l;
-       uam_db_tech_info_t *tech;
-       uam_db_device_info_t *device;
-       uam_db_user_info_t *user;
 
-       retv_if(NULL == account, UAM_ERROR_INVALID_PARAMETER);
-       retv_if(NULL == dev_info, UAM_ERROR_INVALID_PARAMETER);
-
-       /* Retrieve user from list */
-       l = g_slist_find_custom(users, account, __compare_user_account);
-       retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
-       user = l->data;
-
-       /* Retrieve device from list */
-       l = g_slist_find_custom(devices, dev_info->device_id, __compare_device_id);
-       retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
-       device = l->data;
-       retv_if(user != device->user, UAM_ERROR_INVALID_PARAMETER);
-       retv_if(!(device->supported_techs & dev_info->type), UAM_ERROR_INVALID_PARAMETER);
-
-       /* Retrieve tech info from list */
-       l = g_slist_find_custom(device->tech_list,
-                       &(dev_info->type), __compare_tech_type);
-       retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
-       tech = l->data;
-
-       ret = _uam_pm_unregister_device(user->user_id, dev_info);
+       ret = _uam_pm_unregister_device(user_id, dev_info);
        if (UAM_ERROR_NONE != ret) {
                UAM_ERR("_uam_pm_unregister_device failed with %s",
                                _uam_manager_error_to_str(ret));
@@ -967,7 +948,7 @@ int _uam_core_remove_device(const char *account, const uam_device_info_s *dev_in
                devices = g_slist_remove(devices, device);
 
                /* Remove device  from user's device list */
-               user->devices = g_slist_remove(user->devices, device);
+               device->user->devices = g_slist_remove(device->user->devices, device);
 
                __free_user_device(device);
        }
@@ -983,7 +964,45 @@ int _uam_core_remove_device(const char *account, const uam_device_info_s *dev_in
        return UAM_ERROR_NONE;
 }
 
-int _uam_core_remove_device_by_device_id(const char *device_id, int tech_type)
+int _uam_core_remove_device(const char *account,
+       const uam_device_info_s *dev_info)
+{
+       FUNC_ENTRY;
+       int ret;
+       GSList *l;
+       uam_db_tech_info_t *tech;
+       uam_db_device_info_t *device;
+       uam_db_user_info_t *user;
+
+       retv_if(NULL == account, UAM_ERROR_INVALID_PARAMETER);
+       retv_if(NULL == dev_info, UAM_ERROR_INVALID_PARAMETER);
+
+       /* Retrieve user from list */
+       l = g_slist_find_custom(users, account, __compare_user_account);
+       retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
+       user = l->data;
+
+       /* Retrieve device from list */
+       l = g_slist_find_custom(devices, dev_info->device_id, __compare_device_id);
+       retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
+       device = l->data;
+       retv_if(user != device->user, UAM_ERROR_INVALID_PARAMETER);
+       retv_if(!(device->supported_techs & dev_info->type), UAM_ERROR_INVALID_PARAMETER);
+
+       /* Retrieve tech info from list */
+       l = g_slist_find_custom(device->tech_list,
+                       &(dev_info->type), __compare_tech_type);
+       retv_if(NULL == l, UAM_ERROR_INVALID_PARAMETER);
+       tech = l->data;
+
+       ret = __uam_remove_device(user->user_id, device, dev_info, tech);
+
+       FUNC_EXIT;
+       return ret ;
+}
+
+int _uam_core_remove_device_by_device_id(const char *device_id,
+       int tech_type)
 {
        FUNC_ENTRY;
        int ret;
@@ -1012,54 +1031,10 @@ int _uam_core_remove_device_by_device_id(const char *device_id, int tech_type)
        ret = _uam_core_get_devcie_by_device_id(device_id, tech_type, &dev_info);
        retv_if(UAM_ERROR_NONE != ret, UAM_ERROR_NOT_REGISTERED);
 
-       ret = _uam_pm_unregister_device(device->user->user_id, &dev_info);
-       if (UAM_ERROR_NONE != ret) {
-               UAM_WARN("_uam_pm_unregister_device failed with %s",
-                               _uam_manager_error_to_str(ret));
-       }
-
-       /* Send device removed event to application */
-       __send_device_event(UAM_EVENT_DEVICE_REMOVED, &dev_info);
-
-       /* remove from database */
-       if (UAM_ERROR_NONE != _ua_device_db_delete_device_info(
-                               dev_info.device_id, dev_info.type, dev_info.mac))
-               UAM_ERR("_ua_device_db_delete_device_info failed");
-
-       /* Remove device from service */
-       for (l = tech->svc_list; l; l = g_slist_next(l)) {
-               uam_db_service_info_t *svc = l->data;
-
-               if (!svc || !svc->name)
-                       continue;
-               _uam_core_service_remove_device(svc->name, dev_info.device_id, dev_info.type);
-       }
-
-       /* Remove tech info from device's tech list */
-       device->tech_list = g_slist_remove(device->tech_list, tech);
-       device->supported_techs &= ~(tech->tech_type);
-       UAM_INFO("device->supported_techs: %8.8X", device->supported_techs);
-       __free_dev_tech_info(tech);
-
-       if (UAM_TECH_TYPE_NONE == device->supported_techs) {
-               /* Remove device from global device list */
-               devices = g_slist_remove(devices, device);
-
-               /* Remove device  from user's device list */
-               device->user->devices = g_slist_remove(device->user->devices, device);
-
-               __free_user_device(device);
-       }
-
-       /* Set/update registered device list to plugins */
-       if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices))
-               UAM_ERR("_uam_pm_set_registered_devices failed");
-
-       /* Set/update registered device list to cloud plugin */
-       _uam_cloud_update_registered_devices();
+       ret = __uam_remove_device(device->user->user_id, device, &dev_info, tech);
 
        FUNC_EXIT;
-       return UAM_ERROR_NONE;
+       return ret;
 }
 
 int _uam_core_remove_device_by_mac(const char *mac)
@@ -1068,7 +1043,6 @@ int _uam_core_remove_device_by_mac(const char *mac)
        uam_db_tech_info_t *tech;
        uam_db_device_info_t *device;
        uam_device_info_s dev_info;
-       GSList *l;
        int ret;
 
        retv_if(NULL == mac, UAM_ERROR_INVALID_PARAMETER);
@@ -1083,53 +1057,10 @@ int _uam_core_remove_device_by_mac(const char *mac)
                return UAM_ERROR_INTERNAL;
        }
 
-       ret = _uam_pm_unregister_device(device->user->user_id, &dev_info);
-       if (UAM_ERROR_NONE != ret) {
-               UAM_WARN("_uam_pm_unregister_device failed with %s",
-                       _uam_manager_error_to_str(ret));
-       }
-
-       /* Send device removed event to application */
-       __send_device_event(UAM_EVENT_DEVICE_REMOVED, &dev_info);
-
-       /* Remove device from database */
-       if (UAM_ERROR_NONE != _ua_device_db_delete_device_info(
-                               dev_info.device_id, dev_info.type, dev_info.mac))
-               UAM_ERR("_ua_device_db_delete_device_info failed");
-
-       /* Remove device from service */
-       for (l = tech->svc_list; l; l = g_slist_next(l)) {
-               uam_db_service_info_t *svc = l->data;
-
-               if (!svc || !svc->name)
-                       continue;
-               _uam_core_service_remove_device(svc->name, dev_info.device_id, dev_info.type);
-       }
-
-       /* Remove tech info from device's tech list */
-       device->tech_list = g_slist_remove(device->tech_list, tech);
-       device->supported_techs &= ~(tech->tech_type);
-       UAM_INFO("device->supported_techs: %8.8X", tech->device->supported_techs);
-       __free_dev_tech_info(tech);
-
-       if (UAM_TECH_TYPE_NONE == device->supported_techs) {
-               /* Remove device from global device list */
-               devices = g_slist_remove(devices, device);
-
-               /* Remove device  from user's device list */
-               device->user->devices = g_slist_remove(device->user->devices, device);
-               __free_user_device(device);
-       }
-
-       /* Set/update registered device list to plugins */
-       if (UAM_ERROR_NONE != _uam_pm_set_registered_devices(devices))
-               UAM_ERR("_uam_pm_set_registered_devices failed");
-
-       /* Set/update registered device list to cloud plugin */
-       _uam_cloud_update_registered_devices();
+       ret = __uam_remove_device(device->user->user_id, device, &dev_info, tech);
 
        FUNC_EXIT;
-       return UAM_ERROR_NONE;
+       return ret;
 }
 
 int _uam_core_update_device(const uam_device_info_s *a_device)
@@ -1323,22 +1254,7 @@ int _uam_core_get_devcie_by_device_id(
                        if (!addr)
                                continue;
 
-                       switch (addr->addr_type) {
-                       case UAM_ADDR_TYPE_BLE:
-                       case UAM_ADDR_TYPE_BT:
-                       case UAM_ADDR_TYPE_P2P:
-                       case UAM_ADDR_TYPE_WIFI:
-                               g_strlcpy(device->mac, addr->address,
-                                               UAM_MAC_ADDRESS_STRING_LEN);
-                               break;
-                       case UAM_ADDR_TYPE_IPv4:
-                               g_strlcpy(device->ipv4_addr,
-                                               addr->address,
-                                               UAM_IP_ADDRESS_MAX_STRING_LEN);
-                               break;
-                       default:
-                               UAM_WARN("Unknown address type %d", addr->addr_type);
-                       }
+                       __uam_core_copy_addr(device, addr);
                }
 
                device->operating_system = db_info->os;
index a29f72d..b55ac47 100644 (file)
@@ -23,7 +23,7 @@
 #include <aul_svc.h>
 #include <bundle_internal.h>
 
-GSList *apps; /* List of apps to launch - uam_app_info_s*/
+static GSList *apps; /* List of apps to launch - uam_app_info_s*/
 
 #define UA_EVENT "UA_EVENT"
 
index c611d31..1d6083d 100644 (file)
@@ -30,7 +30,7 @@ typedef struct _uam_dbus_client_s {
 } uam_dbus_client_s;
 
 /* For maintaining Application Sync API call requests */
-GSList *request_list = NULL;
+static GSList *request_list = NULL;
 
 static GDBusConnection *uam_manager_conn;
 static guint g_dbus_object_id = 0;
index 2bb5ae0..e81e8eb 100644 (file)
@@ -90,17 +90,6 @@ static void __ua_finalize_insert(void)
        FUNC_EXIT;
 }
 
-#if 0
-/* TODO */
-static void _ua_finalize_update(void)
-{
-       FUNC_ENTRY;
-
-
-       FUNC_EXIT;
-}
-#endif
-
 static int __ua_prepare_delete(sqlite3 *db)
 {
        FUNC_ENTRY;