[sample] modified details regarding sys info
authorEunyoung Lee <ey928.lee@samsung.com>
Thu, 23 May 2019 10:32:19 +0000 (19:32 +0900)
committer이은영/Tizen Platform Lab(SR)/Engineer/삼성전자 <ey928.lee@samsung.com>
Mon, 27 May 2019 04:26:20 +0000 (13:26 +0900)
src/devicemanagerservice.c

index ac9ceaa..c084aec 100644 (file)
@@ -34,21 +34,27 @@ typedef struct _app_data {
 } app_data;
 
 static void __get_taskinfo(int duration, int period, unsigned long id, idm_result_cb result_cb_func, void *data);
 } app_data;
 
 static void __get_taskinfo(int duration, int period, unsigned long id, idm_result_cb result_cb_func, void *data);
+static Eina_Bool __command_stop(void *data);
 
 static char *__make_sysinfo_request(void)
 {
 
 static char *__make_sysinfo_request(void)
 {
+       char path[1024];
        char *buff = NULL;
        int size = 0;
 
        char *buff = NULL;
        int size = 0;
 
-       FILE *fp = fopen("/home/owner/apps_rw/org.example.devicemanagerservice/res/sysinfoRequestTest.txt", "r");
+       snprintf(path, sizeof(path), "%s%s", app_get_resource_path(), "/sysinfoRequestTest.txt");
+       _D("path : %s", path);
+
+       FILE *fp = fopen(path, "r");
        if (fp == NULL) {
                _E("fp is NULL");
                return NULL;
        }
        if (fp == NULL) {
                _E("fp is NULL");
                return NULL;
        }
+
        fseek(fp, 0, SEEK_END);
        size = ftell(fp);
        fseek(fp, 0, SEEK_END);
        size = ftell(fp);
-       buff = malloc(size + 1);
-       memset(buff, 0, size + 1);
+       buff = g_malloc(size + 1);
+       buff[size] = '\0';
        fseek(fp, 0, SEEK_SET);
        fread(buff, size, 1, fp);
 
        fseek(fp, 0, SEEK_SET);
        fread(buff, size, 1, fp);
 
@@ -107,6 +113,29 @@ static char *__make_temp_logs(const char *file_name)
        return file_path;
 }
 
        return file_path;
 }
 
+static void __get_tinfo_result_cb(idm_command_h command, idm_result_e result, idm_reason_e reason, const char *detail, void *data)
+{
+       unsigned long id;
+       idm_command_get_id(command, &id);
+
+       _D("[%d] result : %d, reason : %d, detail : %s", id, result, reason, detail ? detail : "None");
+
+       if (result != IDM_RESULT_RUNNING) {
+               app_data *ad = data;
+               idm_command_free(command);
+               ad->command = NULL;
+
+               if (id == 1) {
+                       // 3. 2초 간격으로 20초간 task info 받도록 cmd 실행하고, 10초 뒤에 cmd stop 호출
+                       __get_taskinfo(20, 2, 2, __get_tinfo_result_cb, ad);
+
+                       if (ad->timer)
+                               ecore_timer_del(ad->timer);
+                       ad->timer = ecore_timer_add(10.0, __command_stop, ad);
+               }
+       }
+}
+
 static void __sysinfo_result_cb(idm_command_h command, idm_result_e result, idm_reason_e reason, const char *detail, void *data)
 {
        app_data *ad = data;
 static void __sysinfo_result_cb(idm_command_h command, idm_result_e result, idm_reason_e reason, const char *detail, void *data)
 {
        app_data *ad = data;
@@ -116,6 +145,9 @@ static void __sysinfo_result_cb(idm_command_h command, idm_result_e result, idm_
        if (result != IDM_RESULT_RUNNING) {
                idm_command_free(command);
                ad->command = NULL;
        if (result != IDM_RESULT_RUNNING) {
                idm_command_free(command);
                ad->command = NULL;
+
+               // 2. 1초 간격으로 10초간 task info 받도록 cmd 실행
+               __get_taskinfo(10, 1, 1, __get_tinfo_result_cb, ad);
        }
 }
 
        }
 }
 
@@ -173,10 +205,10 @@ static void __get_log_archive_result_cb(idm_command_h command, idm_result_e resu
        if (result != IDM_RESULT_RUNNING) {
                idm_command_free(command);
                ad->command = NULL;
        if (result != IDM_RESULT_RUNNING) {
                idm_command_free(command);
                ad->command = NULL;
-       }
 
 
-       // 4. reboot cmd 실행
-       __reboot(ad);
+               // 4. reboot cmd 실행
+               __reboot(ad);
+       }
 }
 
 static void __get_log_archive(char *log_path_arr[], const char *archive_file, unsigned long id, idm_result_cb result_cb_func, void *data)
 }
 
 static void __get_log_archive(char *log_path_arr[], const char *archive_file, unsigned long id, idm_result_cb result_cb_func, void *data)
@@ -252,29 +284,6 @@ static Eina_Bool __command_stop(void *data)
        return ECORE_CALLBACK_CANCEL;
 }
 
        return ECORE_CALLBACK_CANCEL;
 }
 
-static void __get_tinfo_result_cb(idm_command_h command, idm_result_e result, idm_reason_e reason, const char *detail, void *data)
-{
-       unsigned long id;
-       idm_command_get_id(command, &id);
-
-       _D("[%d] result : %d, reason : %d, detail : %s", id, result, reason, detail ? detail : "None");
-
-       if (result != IDM_RESULT_RUNNING) {
-               app_data *ad = data;
-               idm_command_free(command);
-               ad->command = NULL;
-
-               if (id == 1) {
-                       // 3. 2초 간격으로 20초간 task info 받도록 cmd 실행하고, 10초 뒤에 cmd stop 호출
-                       __get_taskinfo(20, 2, 2, __get_tinfo_result_cb, ad);
-
-                       if (ad->timer)
-                               ecore_timer_del(ad->timer);
-                       ad->timer = ecore_timer_add(10.0, __command_stop, ad);
-               }
-       }
-}
-
 static void __get_taskinfo(int duration, int period, unsigned long id, idm_result_cb result_cb_func, void *data)
 {
        app_data *ad = data;
 static void __get_taskinfo(int duration, int period, unsigned long id, idm_result_cb result_cb_func, void *data)
 {
        app_data *ad = data;
@@ -401,9 +410,6 @@ static void service_app_control(app_control_h app_control, void *data)
        // 1. request로 요청된 system info를 result_cb으로 받기
        __get_sysinfo(__sysinfo_result_cb, ad);
 
        // 1. request로 요청된 system info를 result_cb으로 받기
        __get_sysinfo(__sysinfo_result_cb, ad);
 
-       // 2. 1초 간격으로 10초간 task info 받도록 cmd 실행
-       __get_taskinfo(10, 1, 1, __get_tinfo_result_cb, ad);
-
        return;
 }
 
        return;
 }