* limitations under the License.
*/
+#include "lib/amd_app_lifecycle.h"
+
#include <aul.h>
#include <aul_app_lifecycle.h>
#include <aul_cmd.h>
#include <string>
#include "lib/amd_app_com.h"
-#include "lib/amd_app_lifecycle.h"
-#include "lib/app_status/app_status_manager.hh"
#include "lib/amd_launch.h"
#include "lib/amd_noti.h"
+#include "lib/app_status/app_status_manager.hh"
#include "lib/common/log_private.hh"
#include "lib/lifecycle/app_lifecycle_manager.hh"
#include "lib/request/request_manager.hh"
-static void __send_app_lifecycle_state_change(int pid) {
- if (!_app_com_endpoint_exists("app_lifecycle_state_change"))
- return;
+namespace {
+
+constexpr const char* kAppLifecycleStateString[] = {
+ "Initialized", "Created", "Resumed", "Paused", "Destroyed"};
+
+} // namespace
+
+static void SendAppLifecycleStateChange(int pid) {
+ if (!_app_com_endpoint_exists("app_lifecycle_state_change")) return;
auto& inst = amd::AppLifecycleManager::GetInst();
auto info = inst.Find(pid);
tizen_base::Bundle envelope;
envelope.Add(AUL_K_APPID, info->GetAppId());
- if (info->GetRealPid() != -1)
- pid = info->GetRealPid();
+ if (info->GetRealPid() != -1) pid = info->GetRealPid();
envelope.Add(AUL_K_PID, std::to_string(pid));
envelope.Add(AUL_K_STATE, std::to_string(info->GetState()));
envelope.Add(AUL_K_HAS_FOCUS, info->HasFocus() ? "true" : "false");
- _app_com_send("app_lifecycle_state_change", pid,
- envelope.GetHandle(), info->GetUid());
+ _app_com_send("app_lifecycle_state_change", pid, envelope.GetHandle(),
+ info->GetUid());
}
-static int __on_app_status_add(const char* msg, int arg1, int arg2,
- void* arg3, bundle* arg4) {
+static int OnAppStatusAdd(const char* msg, int arg1, int arg2, void* arg3,
+ bundle* arg4) {
auto* app_status = static_cast<amd::AppStatus*>(arg3);
std::string app_id = app_status->GetAppID();
int pid = app_status->GetPID();
return NOTI_CONTINUE;
}
-static int __on_app_status_destroy(const char* msg, int arg1, int arg2,
- void* arg3, bundle* arg4) {
+static int OnAppStatusDestroy(const char* msg, int arg1, int arg2, void* arg3,
+ bundle* arg4) {
auto* app_status = static_cast<amd::AppStatus*>(arg3);
int pid = app_status->GetPID();
int real_pid = app_status->GetRealPID();
auto& inst = amd::AppLifecycleManager::GetInst();
auto info = inst.Find(pid);
- if (info == nullptr)
- return NOTI_CONTINUE;
+ if (info == nullptr) return NOTI_CONTINUE;
if (info->GetState() != AUL_APP_LIFECYCLE_STATE_DESTROYED) {
info->SetState(AUL_APP_LIFECYCLE_STATE_DESTROYED);
else
info->SetFocus(false);
- __send_app_lifecycle_state_change(pid);
+ SendAppLifecycleStateChange(pid);
}
inst.Remove(pid);
return NOTI_CONTINUE;
}
-static int __on_launch_status_focus(const char* msg, int arg1, int arg2,
- void* arg3, bundle* arg4) {
+static int OnLaunchStatusFocus(const char* msg, int arg1, int arg2, void* arg3,
+ bundle* arg4) {
auto* app_status = static_cast<amd::AppStatus*>(arg3);
int pid = app_status->GetPID();
auto& inst = amd::AppLifecycleManager::GetInst();
auto info = inst.Find(pid);
- if (info == nullptr)
- return NOTI_CONTINUE;
+ if (info == nullptr) return NOTI_CONTINUE;
info->SetFocus(true);
if (info->GetState() == AUL_APP_LIFECYCLE_STATE_RESUMED)
- __send_app_lifecycle_state_change(pid);
+ SendAppLifecycleStateChange(pid);
return NOTI_CONTINUE;
}
-static int __dispatch_app_lifecycle_update_state(request_h request) {
+static int DispatchAppLifecycleUpdateState(request_h request) {
auto* req = static_cast<amd::Request*>(request);
auto& b = req->GetBundle();
if (b == nullptr) {
false, true);
}
- __send_app_lifecycle_state_change(pid);
+ SendAppLifecycleStateChange(pid);
}
- _W("pid(%d), state(%d)", pid, state);
+ _W("pid: %d, state: %s(%d)", pid, kAppLifecycleStateString[state], state);
return 0;
}
-static int __dispatch_app_lifecycle_get_state(request_h request) {
+static int DispatchAppLifecycleGetState(request_h request) {
auto* req = static_cast<amd::Request*>(request);
auto& b = req->GetBundle();
if (b == nullptr) {
b->Add(AUL_K_STATE, std::to_string(info->GetState()));
aul_sock_send_bundle_with_fd(req->DetachFD(), APP_GET_INFO_OK,
b->GetHandle(), AUL_SOCK_NOREPLY);
- _W("app_id(%s), pid(%d), state(%d)", app_id.c_str(), pid, info->GetState());
+ _W("app_id:%s, pid: %d, state: %s(%d)", app_id.c_str(), pid,
+ kAppLifecycleStateString[info->GetState()], info->GetState());
return 0;
}
-int _app_lifecycle_init(void) {
+int AppLifecycleInit(void) {
_W("APP_LIFECYCLE_INIT");
static request_cmd_dispatch dispatch_table[] = {
- {
- .cmd = APP_LIFECYCLE_UPDATE_STATE,
- .callback = __dispatch_app_lifecycle_update_state
- },
- {
- .cmd = APP_LIFECYCLE_GET_STATE,
- .callback = __dispatch_app_lifecycle_get_state
- },
+ {.cmd = APP_LIFECYCLE_UPDATE_STATE,
+ .callback = DispatchAppLifecycleUpdateState},
+ {.cmd = APP_LIFECYCLE_GET_STATE,
+ .callback = DispatchAppLifecycleGetState},
};
- amd::RequestManager::GetInst().RegisterCommands(
- dispatch_table, ARRAY_SIZE(dispatch_table));
+ amd::RequestManager::GetInst().RegisterCommands(dispatch_table,
+ ARRAY_SIZE(dispatch_table));
- _noti_listen(AMD_NOTI_MSG_APP_STATUS_ADD,
- __on_app_status_add);
- _noti_listen(AMD_NOTI_MSG_APP_STATUS_DESTROY,
- __on_app_status_destroy);
- _noti_listen(AMD_NOTI_MSG_LAUNCH_STATUS_FOCUS,
- __on_launch_status_focus);
+ _noti_listen(AMD_NOTI_MSG_APP_STATUS_ADD, OnAppStatusAdd);
+ _noti_listen(AMD_NOTI_MSG_APP_STATUS_DESTROY, OnAppStatusDestroy);
+ _noti_listen(AMD_NOTI_MSG_LAUNCH_STATUS_FOCUS, OnLaunchStatusFocus);
return 0;
}
-void _app_lifecycle_fini(void) {
+void AppLifecycleFini(void) {
_W("APP_LIFECYCLE_FINI");
amd::AppLifecycleManager::GetInst().Clear();
}