Make inline function for logging 40/286240/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Mon, 2 Jan 2023 07:47:46 +0000 (16:47 +0900)
committerTizen AI <ai.tzn.sec@samsung.com>
Mon, 2 Jan 2023 10:31:20 +0000 (19:31 +0900)
- Issue:
For printing log, enum value is used as boolean.

- Solution:
This patch makes converting function for removing invalid usage of enum
value as boolean. Through this patch, the new function will safely
converts the enum value to string.

Change-Id: I0ee373dd86e044933225728e7e970119b5fb5cce
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
server/vcd_server.c

index f0b1b3c..ebdfaf8 100644 (file)
@@ -1479,6 +1479,20 @@ static void __read_proc()
        return;
 }
 
+static inline const char *__get_client_type(vcd_client_type_e type)
+{
+       switch (type) {
+       case VCD_CLIENT_TYPE_NORMAL:
+               return "Normal";
+       case VCD_CLIENT_TYPE_WIDGET:
+               return "Widget";
+       case VCD_CLIENT_TYPE_MANAGER:
+               return "Manager";
+       default:
+               return "Invalid";
+       }
+}
+
 static void __vcd_cleanup_client(vcd_client_type_e type)
 {
        int* client_list = NULL;
@@ -1504,7 +1518,7 @@ static void __vcd_cleanup_client(vcd_client_type_e type)
        }
 
        if (0 == ret || mgr_pid > 0) {
-               SLOG(LOG_INFO, TAG_VCD, "@@@ Clean up %s client ", type ? (type == VCD_CLIENT_TYPE_WIDGET) ? "Widget" : "Manager" : "Normal");
+               SLOG(LOG_INFO, TAG_VCD, "@@@ Clean up %s client ", __get_client_type(type));
                if (NULL != client_list && client_count > 0) {
                        for (i = 0; i < client_count; i++) {
                                exist = false;
@@ -1513,7 +1527,7 @@ static void __vcd_cleanup_client(vcd_client_type_e type)
                                        iter = g_list_nth(g_proc_list, j);
                                        if (NULL != iter) {
                                                if (*(client_list + i) == GPOINTER_TO_INT(iter->data)) {
-                                                       SLOG(LOG_INFO, TAG_VCD, "%s pid(%d) is running", type ? (type == VCD_CLIENT_TYPE_WIDGET) ? "Widget" : "Manager" : "Normal", *(client_list + i));
+                                                       SLOG(LOG_INFO, TAG_VCD, "%s pid(%d) is running", __get_client_type(type), *(client_list + i));
                                                        exist = true;
                                                        break;
                                                }
@@ -1521,7 +1535,7 @@ static void __vcd_cleanup_client(vcd_client_type_e type)
                                }
 
                                if (false == exist) {
-                                       SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", type ? (type == VCD_CLIENT_TYPE_WIDGET) ? "Widget" : "Manager" : "Normal", *(client_list + i));
+                                       SLOG(LOG_ERROR, TAG_VCD, "%s pid(%d) should be removed", __get_client_type(type), *(client_list + i));
                                        if (VCD_CLIENT_TYPE_NORMAL == type)
                                                vcd_server_finalize(*(client_list + i));
                                        else if (VCD_CLIENT_TYPE_WIDGET == type)