From: Rafal Walczyna Date: Tue, 5 Dec 2017 12:39:17 +0000 (+0100) Subject: [Application] Killing and launching moved to main thread X-Git-Tag: submit/tizen_3.0/20171206.135657~2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2ed280b87960093bb0ff88b85a75dd5be3012cf9;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Application] Killing and launching moved to main thread Because of the fact that appfw APIs are not thread safe some functions need to be called from main thread [Verification] 100% passrate on TM1: tct-appcontrol-tizen-tests tct-application-tizen-tests Change-Id: I092cc84e2ac244cfd6439566c3c65a5e2652813c Signed-off-by: Rafal Walczyna --- diff --git a/src/application/application_manager.cc b/src/application/application_manager.cc index 6557a505..8744c0cc 100644 --- a/src/application/application_manager.cc +++ b/src/application/application_manager.cc @@ -169,42 +169,7 @@ class TerminateHandler { response); } - void LaunchCheckTerminate() { - ScopeLogger(); - timeout_id_ = g_timeout_add(3000, CheckTerminate, this); - LoggerD("END"); - } - private: - static gboolean CheckTerminate(gpointer user_data) { - ScopeLogger(); - TerminateHandler* that = static_cast(user_data); - LoggerD("PID: %d", that->pid_); - - // we're canceling the callback by returning false, no need for Invoke() to do that again - that->timeout_id_ = 0; - - char* app_id = nullptr; - std::shared_ptr response{new picojson::value(picojson::object())}; - - LoggerD("checking if application is still alive"); - int ret = app_manager_get_app_id(that->pid_, &app_id); - if (APP_MANAGER_ERROR_NONE == ret) { - free(app_id); - // context is still alive, report error - LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to kill application."), - &response->get(), ("application is alive - failure")); - } else { - LoggerD("application is dead - success: %d (%s)", ret, get_error_message(ret)); - ReportSuccess(response->get()); - } - - that->Invoke(response); - delete that; - - return false; - } - int callback_handle_; pid_t pid_; guint timeout_id_; @@ -264,7 +229,7 @@ void ApplicationManager::Kill(const picojson::value& args) { } auto kill = [this, callback_id, context_id]() -> void { - ScopeLogger("Kill async"); + ScopeLogger("Kill"); std::shared_ptr response = std::shared_ptr(new picojson::value(picojson::object())); @@ -292,7 +257,7 @@ void ApplicationManager::Kill(const picojson::value& args) { CHECK_RESULT(result, response, handler) } - LoggerD("Kill async, pid: %d", pid); + LoggerD("Kill, pid: %d", pid); char* app_id = nullptr; int ret = app_manager_get_app_id(pid, &app_id); @@ -306,7 +271,7 @@ void ApplicationManager::Kill(const picojson::value& args) { CHECK_RESULT(result, response, handler) } - LoggerD("Kill async, app ID: %s", app_id); + LoggerD("Kill, app ID: %s", app_id); // acquire application context app_context_h app_context = nullptr; @@ -352,7 +317,7 @@ void ApplicationManager::Kill(const picojson::value& args) { } }; - LoggerD("Kill async, setting callback"); + LoggerD("Kill, setting callback"); handler->set_pid(pid); ret = app_manager_set_app_context_event_cb(terminate_callback, handler); @@ -363,12 +328,7 @@ void ApplicationManager::Kill(const picojson::value& args) { CHECK_RESULT(result, response, handler) } - // due to platform issue, sometimes termination event is not reported to callback - // registered with app_manager_set_app_context_event_cb() - // this is a workaround, it should be removed when issue is solved - // handler->LaunchCheckTerminate(); - - LoggerD("Kill async, KILL!!!!!!!!!"); + LoggerD("Kill, calling native function"); // terminate application ret = app_manager_terminate_app(app_context); @@ -380,10 +340,10 @@ void ApplicationManager::Kill(const picojson::value& args) { CHECK_RESULT(result, response, handler) } - LoggerD("Kill async, end, waiting for notification"); + LoggerD("Kill, end, waiting for notification"); }; - TaskQueue::GetInstance().Queue(kill); + kill(); } void ApplicationManager::Launch(const picojson::value& args) { @@ -409,7 +369,7 @@ void ApplicationManager::Launch(const picojson::value& args) { const std::string& id = app_id.get(); auto launch = [id](const std::shared_ptr& response) -> void { - ScopeLogger("Entered into asynchronous function, launch"); + ScopeLogger("launch"); PlatformResult result = PlatformResult(ErrorCode::NO_ERROR); const char* app_id = id.c_str(); const int retry_count = 3; @@ -458,11 +418,8 @@ void ApplicationManager::Launch(const picojson::value& args) { } }; - auto launch_response = [this](const std::shared_ptr& response) -> void { - Instance::PostMessage(&this->instance_, response->serialize().c_str()); - }; - - TaskQueue::GetInstance().Queue(launch, launch_response, response); + launch(response); + Instance::PostMessage(&this->instance_, response->serialize().c_str()); } void ApplicationManager::LaunchAppControl(const picojson::value& args) { @@ -651,13 +608,8 @@ void ApplicationManager::LaunchAppControl(const picojson::value& args) { ReportSuccess(response->get()); }; - auto launch_response = [this](const std::shared_ptr& response) -> void { - ScopeLogger("launch_response"); - - Instance::PostMessage(&this->instance_, response->serialize().c_str()); - }; - - TaskQueue::GetInstance().Queue(launch, launch_response, response); + launch(response); + Instance::PostMessage(&this->instance_, response->serialize().c_str()); } // internal impl of app_control_foreach_app_matched() for handling APP_CONTROL_ERROR_APP_NOT_FOUND