apply command id to sample application 29/207829/4 master
authorJeonghoon Park <jh1979.park@samsung.com>
Thu, 13 Jun 2019 06:38:57 +0000 (15:38 +0900)
committerJeonghoon Park <jh1979.park@samsung.com>
Mon, 17 Jun 2019 07:55:02 +0000 (16:55 +0900)
Change-Id: I4b7056b2febf74939c02975d0b6d5dd951dafb2f

src/devicemanagerservice.c
tizen-manifest.xml

index bacc98f..f0289ac 100644 (file)
@@ -29,8 +29,12 @@ typedef struct _app_data {
        idm_command_h command;
 } 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_id_request(void)
+{
+       char *request_json = NULL;
+       request_json = g_strdup_printf("{ \"idSeed\" : \"%s\" }", "testSeed");
+       return request_json;
+}
 
 static char *__make_sysinfo_request(void)
 {
@@ -109,59 +113,8 @@ static char *__make_temp_logs(const char *file_name)
        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)
+static void __reboot(app_data *ad, idm_result_cb result_cb_func)
 {
-       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;
-
-       _D("result : %d, reason : %d, detail : %s", result, reason, detail ? detail : "None");
-
-       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);
-       }
-}
-
-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;
-
-       _D("result : %d, reason : %d, detail : %s", result, reason, detail ? detail : "None");
-
-       if (result != IDM_RESULT_RUNNING) {
-               idm_command_free(command);
-               ad->command = NULL;
-       }
-}
-
-static void __reboot(void *data)
-{
-       app_data *ad = data;
        idm_command_h command = NULL;
        int ret = -1;
 
@@ -180,7 +133,7 @@ static void __reboot(void *data)
                return;
        }
 
-       ret = idm_command_run(command, __reboot_result_callback, ad);
+       ret = idm_command_run(command, result_cb_func, ad);
        if (ret != 0) {
                _E("failed to idm_command_run");
                idm_command_free(command);
@@ -189,27 +142,20 @@ 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)
+static void __reboot_result_cb(idm_command_h command, idm_result_e result, idm_reason_e reason, const char *detail, void *data)
 {
        app_data *ad = data;
-       unsigned long id;
 
-       idm_command_get_id(command, &id);
-
-       _D("[%d] result : %d, reason : %d, detail : %s", id, result, reason, detail ? detail : "None");
+       _D("result : %d, reason : %d, detail : %s", result, reason, detail ? detail : "None");
 
        if (result != IDM_RESULT_RUNNING) {
                idm_command_free(command);
                ad->command = NULL;
-
-               // 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, app_data *ad)
 {
-       app_data *ad = data;
        idm_command_h command = NULL;
        char *request = NULL;
        int ret = -1;
@@ -250,6 +196,23 @@ static void __get_log_archive(char *log_path_arr[], const char *archive_file, un
        }
 }
 
+static void __get_log_archive_result_cb(idm_command_h command, idm_result_e result, idm_reason_e reason, const char *detail, void *data)
+{
+       app_data *ad = 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) {
+               idm_command_free(command);
+               ad->command = NULL;
+
+               __reboot(ad, __reboot_result_cb);
+       }
+}
+
 static Eina_Bool __command_stop(void *data)
 {
        app_data *ad = data;
@@ -280,9 +243,8 @@ static Eina_Bool __command_stop(void *data)
        return ECORE_CALLBACK_CANCEL;
 }
 
-static void __get_taskinfo(int duration, int period, unsigned long id, idm_result_cb result_cb_func, void *data)
+static void __get_taskinfo(int duration, int period, unsigned long id, idm_result_cb result_cb_func, app_data *ad)
 {
-       app_data *ad = data;
        idm_command_h command = NULL;
        char *request = NULL;
        int ret = -1;
@@ -322,34 +284,83 @@ static void __get_taskinfo(int duration, int period, unsigned long id, idm_resul
        }
 }
 
-static bool service_app_create(void *data)
+static void __get_tinfo_result_cb(idm_command_h command, idm_result_e result, idm_reason_e reason, const char *detail, void *data)
 {
-       _D("app create");
-       return true;
+       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) {
+                       __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 service_app_terminate(void *data)
+static void __get_sysinfo(idm_result_cb result_cb_func, app_data *ad)
 {
-       _D("app terminate");
-       app_data *ad = data;
+       idm_command_h command = NULL;
+       char *request = NULL;
+       int ret = -1;
 
-       if (ad->command) {
-               idm_command_stop(ad->command);
-               idm_command_free(ad->command);
+       idm_command_new(&command);
+       ret_if(!command);
+       ad->command = command;
+
+       request = __make_sysinfo_request();
+       if (!request) {
+               _E("failed to make request");
+               idm_command_free(command);
                ad->command = NULL;
+               return;
        }
 
-       if (ad->timer) {
-               ecore_timer_del(ad->timer);
-               ad->timer = NULL;
+       ret = idm_command_set_cmd_detail(command, IDM_CMD_GET_SYSINFO, request);
+
+       g_free(request);
+       request = NULL;
+
+       if (ret != 0) {
+               _E("failed to idm_command_set_info_cmd");
+               idm_command_free(command);
+               ad->command = NULL;
+               return;
        }
 
-       return;
+       ret = idm_command_run(command, result_cb_func, ad);
+       if (ret != 0) {
+               _E("failed to idm_command_run");
+               idm_command_free(command);
+               ad->command = NULL;
+               return;
+       }
 }
 
-static void __get_sysinfo(idm_result_cb result_cb_func, void *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;
+
+       _D("result : %d, reason : %d, detail : %s", result, reason, detail ? detail : "None");
+
+       if (result != IDM_RESULT_RUNNING) {
+               idm_command_free(command);
+               ad->command = NULL;
+
+               __get_taskinfo(10, 1, 1, __get_tinfo_result_cb, ad);
+       }
+}
+
+static void __get_id(idm_result_cb result_cb_func, app_data *ad)
+{
        idm_command_h command = NULL;
        char *request = NULL;
        int ret = -1;
@@ -358,7 +369,7 @@ static void __get_sysinfo(idm_result_cb result_cb_func, void *data)
        ret_if(!command);
        ad->command = command;
 
-       request = __make_sysinfo_request();
+       request = __make_id_request();
        if (!request) {
                _E("failed to make request");
                idm_command_free(command);
@@ -366,13 +377,13 @@ static void __get_sysinfo(idm_result_cb result_cb_func, void *data)
                return;
        }
 
-       ret = idm_command_set_cmd_detail(command, IDM_CMD_GET_SYSINFO, request);
+       ret = idm_command_set_cmd_detail(command, IDM_CMD_GET_ID, request);
 
        g_free(request);
        request = NULL;
 
        if (ret != 0) {
-               _E("failed to idm_command_set_info_cmd");
+               _E("failed to idm_command_set_cmd_detail");
                idm_command_free(command);
                ad->command = NULL;
                return;
@@ -387,6 +398,47 @@ static void __get_sysinfo(idm_result_cb result_cb_func, void *data)
        }
 }
 
+static void __get_id_result_cb(idm_command_h command, idm_result_e result, idm_reason_e reason, const char *detail, void *data)
+{
+       app_data *ad = 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)
+               return;
+
+       idm_command_free(command);
+       ad->command = NULL;
+       __get_sysinfo(__sysinfo_result_cb, ad);
+}
+
+static bool service_app_create(void *data)
+{
+       _D("app create");
+       return true;
+}
+
+static void service_app_terminate(void *data)
+{
+       _D("app terminate");
+       app_data *ad = data;
+
+       if (ad->command) {
+               idm_command_stop(ad->command);
+               idm_command_free(ad->command);
+               ad->command = NULL;
+       }
+
+       if (ad->timer) {
+               ecore_timer_del(ad->timer);
+               ad->timer = NULL;
+       }
+
+       return;
+}
+
 static void service_app_control(app_control_h app_control, void *data)
 {
        _D("app control");
@@ -403,8 +455,7 @@ static void service_app_control(app_control_h app_control, void *data)
                ad->timer = NULL;
        }
 
-       // 1. request로 요청된 system info를 result_cb으로 받기
-       __get_sysinfo(__sysinfo_result_cb, ad);
+       __get_id(__get_id_result_cb, ad);
 
        return;
 }
index 1f91d09..538541a 100644 (file)
@@ -7,6 +7,7 @@
     </service-application>
     <privileges>
         <privilege>http://tizen.org/privilege/systemmonitor</privilege>
+        <privilege>http://tizen.org/privilege/network.get</privilege>
         <privilege>http://tizen.org/privilege/reboot</privilege>
     </privileges>
 </manifest>