Add functions for requesting / getting results for log archive
authorBoyeon <boyeon.son@samsung.com>
Fri, 10 May 2019 11:57:11 +0000 (20:57 +0900)
committer손보연/Tizen Platform Lab(SR)/Engineer/삼성전자 <boyeon.son@samsung.com>
Thu, 16 May 2019 06:23:11 +0000 (15:23 +0900)
src/devicemanagerservice.c

index 0a76942..7ebab13 100644 (file)
@@ -30,7 +30,7 @@ typedef struct _app_data {
 
 static void __get_taskinfo(int duration, int period, unsigned long id, idm_result_cb result_cb_func, void *data);
 
-static char *__make_request(int duration, int period)
+static char *__make_taskinfo_request(int duration, int period)
 {
        char *request_json = NULL;
 
@@ -39,6 +39,21 @@ static char *__make_request(int duration, int period)
        return request_json;
 }
 
+static char *__make_log_archive_request(const char *log_path_arr[], const char *archive_file)
+{
+       char *request_json = NULL;
+       char *log_path_str = NULL;
+
+       log_path_str = g_strjoinv("\", \"", log_path_arr);
+
+       request_json = g_strdup_printf("{ \"logPath\" : [ \"%s\" ], \"archiveFile\" : \"%s\" }", log_path_str, archive_file);
+
+       return request_json;
+}
+
+// static void __make_temp_logs()
+// Make temporary log directories and files using app_get_data_path() API
+
 static void __reboot_result_callback(idm_command_h command, idm_result_e result, idm_reason_e reason, const char *detail, void *data)
 {
        app_data *ad = data;
@@ -81,9 +96,131 @@ static void __reboot(void *data)
        }
 }
 
+static void __get_log_archive_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;
+       }
+}
+
+static void __get_log_archive(const char *log_path_arr[], const char *archive_file, unsigned long id, idm_result_cb result_cb_func, void *data)
+{
+       app_data *ad = data;
+       idm_command_h command = NULL;
+       char *request = NULL;
+       int ret = -1;
+
+       idm_command_new(&command);
+       ret_if(!command);
+
+       idm_command_set_id(command, id);
+       ad->command = command;
+
+       request = __make_log_archive_request(log_path_arr, archive_file);
+       if (!request) {
+               _E("failed to make request");
+               idm_command_free(command);
+               ad->command = NULL;
+               return;
+       }
+
+       ret = idm_command_set_diagnosis_cmd(command, IDM_CMD_DIAGNOSIS_GET_LOG, request);
+
+       g_free(request);
+       request = NULL;
+
+       if (ret != 0) {
+               _E("failed to idm_command_set_info_cmd");
+               idm_command_stop(ad->command);
+               idm_command_free(command);
+               ad->command = NULL;
+               return;
+       }
+
+       ret = idm_command_run(command, result_cb_func, ad);
+       if (ret != 0) {
+               _E("failed to idm_command_run");
+               idm_command_stop(ad->command);
+               idm_command_free(command);
+               ad->command = NULL;
+               return;
+       }
+}
+
+static void __get_log_archive_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;
+       }
+}
+
+static void __get_log_archive(const char *log_path_arr[], const char *archive_file, unsigned long id, idm_result_cb result_cb_func, void *data)
+{
+       app_data *ad = data;
+       idm_command_h command = NULL;
+       char *request = NULL;
+       int ret = -1;
+
+       idm_command_new(&command);
+       ret_if(!command);
+
+       idm_command_set_id(command, id);
+       ad->command = command;
+
+       request = __make_log_archive_request(log_path_arr, archive_file);
+       if (!request) {
+               _E("failed to make request");
+               idm_command_free(command);
+               ad->command = NULL;
+               return;
+       }
+
+       ret = idm_command_set_diagnosis_cmd(command, IDM_CMD_DIAGNOSIS_GET_LOG, request);
+
+       g_free(request);
+       request = NULL;
+
+       if (ret != 0) {
+               _E("failed to idm_command_set_info_cmd");
+               idm_command_stop(ad->command);
+               idm_command_free(command);
+               ad->command = NULL;
+               return;
+       }
+
+       ret = idm_command_run(command, result_cb_func, ad);
+       if (ret != 0) {
+               _E("failed to idm_command_run");
+               idm_command_stop(ad->command);
+               idm_command_free(command);
+               ad->command = NULL;
+               return;
+       }
+}
+
 static Eina_Bool __command_stop(void *data)
 {
        app_data *ad = data;
+       char log_path_arr[][2] = {
+               "/TBD/",
+               "/TBD/",
+               NULL
+       }; // The last item of this array must be NULL
+       char *archive_file = "/TBD/log.zip"
 
        if (ad->command) {
                idm_command_stop(ad->command);
@@ -92,6 +229,9 @@ static Eina_Bool __command_stop(void *data)
        }
        ad->timer = NULL;
 
+       // Get log archive
+       __get_log_archive(log_path_arr, archive_file, 3, __get_log_archive_result_cb, ad);
+
        // 3. reboot cmd 실행
        __reboot(ad);
 
@@ -134,7 +274,7 @@ static void __get_taskinfo(int duration, int period, unsigned long id, idm_resul
        idm_command_set_id(command, id);
        ad->command = command;
 
-       request = __make_request(duration, period);
+       request = __make_taskinfo_request(duration, period);
        if (!request) {
                _E("failed to make request");
                idm_command_free(command);