aboutsummaryrefslogtreecommitdiffstats
path: root/src/window_manager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/window_manager.cpp')
-rw-r--r--src/window_manager.cpp172
1 files changed, 170 insertions, 2 deletions
diff --git a/src/window_manager.cpp b/src/window_manager.cpp
index cd7d2e5..06f7793 100644
--- a/src/window_manager.cpp
+++ b/src/window_manager.cpp
@@ -187,6 +187,11 @@ result<int> WindowManager::api_request_surface(char const *appid, char const *dr
auto id = int(this->id_alloc.generate_id(role));
this->tmp_surface2app[id] = {str_id, lid};
+ // POI: AGL LifeCycle Management
+ this->amgr.states[str_id] = lcm::CREATED;
+ this->amgr.emit_activity_status_changed(str_id.c_str(),
+ this->amgr.states_s[lcm::CREATED]);
+
return Ok<int>(id);
}
@@ -246,6 +251,11 @@ char const *WindowManager::api_request_surface(char const *appid, char const *dr
auto client = g_app_list.lookUpClient(str_id);
client->addSurface(sid);
+ // POI: AGL LifeCycle Management
+ this->amgr.states[str_id] = lcm::CREATED;
+ this->amgr.emit_activity_status_changed(str_id.c_str(),
+ this->amgr.states_s[lcm::CREATED]);
+
return nullptr;
}
@@ -285,7 +295,7 @@ void WindowManager::api_activate_window(char const *appid, char const *drawing_n
}
// Do allocate tasks
-
+
ret = this->checkPolicy(req_num);
if (ret != WMError::SUCCESS)
@@ -294,6 +304,13 @@ void WindowManager::api_activate_window(char const *appid, char const *drawing_n
HMI_SEQ_ERROR(req_num, errorDescription(ret));
g_app_list.removeRequest(req_num);
this->processNextRequest();
+ } else {
+ // POI: AGL LifeCycle Management
+ if (this->amgr.states[id] == lcm::CREATED) {
+ this->amgr.states[id] = lcm::STARTED;
+ this->amgr.emit_activity_status_changed(id.c_str(),
+ this->amgr.states_s[lcm::STARTED]);
+ }
}
}
@@ -334,6 +351,14 @@ void WindowManager::api_deactivate_window(char const *appid, char const *drawing
HMI_SEQ_ERROR(req_num, errorDescription(ret));
g_app_list.removeRequest(req_num);
this->processNextRequest();
+ } else {
+ // POI: AGL LifeCycle Management
+ int state = this->amgr.states[id];
+ if (state == lcm::STARTED || state == lcm::BACKGROUND) {
+ this->amgr.states[id] = lcm::STOPPED;
+ this->amgr.emit_activity_status_changed(id.c_str(),
+ this->amgr.states_s[lcm::STOPPED]);
+ }
}
}
@@ -492,6 +517,12 @@ void WindowManager::removeClient(const string &appid)
auto client = g_app_list.lookUpClient(appid);
this->lc->appTerminated(client);
g_app_list.removeClient(appid);
+ // POI: AGL LifeCycle Management
+ if (this->amgr.states[appid] != lcm::DESTROYED) {
+ this->amgr.states[appid] = lcm::DESTROYED;
+ this->amgr.emit_activity_status_changed(appid.c_str(),
+ this->amgr.states_s[lcm::DESTROYED]);
+ }
}
void WindowManager::exceptionProcessForTransition()
@@ -853,9 +884,22 @@ void WindowManager::emitScreenUpdated(unsigned req_num)
for(const auto& action: actions)
{
+ std::string appid = action.client->appID();
+
if(action.visible != TaskVisible::INVISIBLE)
{
- json_object_array_add(jarray, json_object_new_string(action.client->appID().c_str()));
+ json_object_array_add(jarray, json_object_new_string(appid.c_str()));
+ // POI: AGL LifeCycle Management
+ if (this->amgr.states[appid] != lcm::FOREGROUND) {
+ this->amgr.states[appid] = lcm::FOREGROUND;
+ this->amgr.emit_activity_status_changed(appid.c_str(), this->amgr.states_s[lcm::FOREGROUND]);
+ }
+ } else {
+ // POI: AGL LifeCycle Management
+ if (this->amgr.states[appid] != lcm::BACKGROUND) {
+ this->amgr.states[appid] = lcm::BACKGROUND;
+ this->amgr.emit_activity_status_changed(appid.c_str(), this->amgr.states_s[lcm::BACKGROUND]);
+ }
}
}
json_object_object_add(j, kKeyIds, jarray);
@@ -928,3 +972,127 @@ void WindowManager::processNextRequest()
}
} // namespace wm
+
+namespace lcm
+{
+
+ActivityManager::ActivityManager (void)
+ : states_s { "NOTEXISTS",
+ "CREATED",
+ "DESTROYED",
+ "STARTED",
+ "STOPPED",
+ "FOREGROUND",
+ "BACKGROUND" }
+{
+ ;
+}
+
+void ActivityManager::api_register_activity_observer (afb_req_t req)
+{
+ std::string observer = afb_req_get_application_id(req);
+
+ json_object *j_data = afb_req_json(req);
+ json_object *j_target;
+ if (!json_object_object_get_ex(j_data, LCM_TARGET, &j_target)) {
+ afb_req_fail(req, "failed", "Need char const* argument target");
+ return;
+ }
+ std::string target(json_object_get_string(j_target));
+
+ for (auto itr = this->map_observers.begin(); itr != this->map_observers.end(); ++itr) {
+ observers mp = itr->second;
+ if (mp.count(observer)) {
+ // Already exist
+ HMI_DEBUG("observer(%s) is already exist", observer.c_str());
+ if (this->map_observers[target].count(observer)) {
+ // Aready registered
+ HMI_DEBUG("observer(%s->%s) is already registered", observer.c_str(), target.c_str());
+ } else {
+ HMI_DEBUG("observer(%s->%s) is registered", observer.c_str(), target.c_str());
+
+ (this->map_observers[target])[observer] = mp[observer];
+ }
+ return;
+ }
+ }
+
+ // New observer
+ afb_event_t event = afb_daemon_make_event(LCM_EVENT_STATUS_CHANGED);
+ //afb_event_t event = afb_daemon_make_event(LCM_EVENT_STATUS_CHANGED);
+ (this->map_observers[target])[observer] = {
+ event,
+ std::bitset<NUM_STATUS>(ACTIVITY_FILTER_ALL_SET)
+ };
+
+ if (afb_req_subscribe(req, event) != 0) {
+ HMI_ERROR("cannot subscribe event");
+ }
+}
+
+void ActivityManager::api_unregister_activity_observer (afb_req_t req)
+{
+ std::string observer = afb_req_get_application_id(req);
+
+ json_object *j_data = afb_req_json(req);
+ json_object *j_target;
+
+ if (!json_object_object_get_ex(j_data, LCM_TARGET, &j_target)) {
+ afb_req_fail(req, "failed", "Need char const* argument target");
+ return;
+ }
+ std::string target(json_object_get_string(j_target));
+
+ HMI_DEBUG("observer(%s->%s) is unregistered.", observer.c_str(), target.c_str());
+}
+
+wm::result<json_object *> ActivityManager::api_get_activity_status (const char *appid)
+{
+ std::string id = appid;
+ int st = NOTEXISTS;
+
+ if (this->states.count(id)) {
+ st = this->states[id];
+
+ if (st < 0 || st >= NUM_STATUS) {
+ HMI_ERROR("Illegal lifecycle state (%d) of [%s]", st, appid);
+ return wm::Err<json_object *>("Illegal lifecycle state");
+ }
+ }
+
+ const char * state = this->states_s[st];
+
+ json_object *object = json_object_new_object();
+ json_object_object_add(object, LCM_API, json_object_new_string(LCM_API_GET_ACTIVITY_STATUS));
+ json_object_object_add(object, LCM_TARGET, json_object_new_string(appid));
+ json_object_object_add(object, LCM_STATE, json_object_new_string(state));
+
+ return wm::Ok<json_object *>(object);
+}
+
+void ActivityManager::emit_activity_status_changed (const char* appid, const char* state)
+{
+ // POI: AGL LifeCycle Management
+ // E.g. statusChanged(CREATED->STARTED)
+ std::string id = appid;
+
+ if (this->map_observers.count(id)) {
+ observers mp = this->map_observers[id];
+ for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
+ afb_event_t event = itr->second.event;
+ if (afb_event_is_valid(event)) {
+ HMI_DEBUG("emit_activity_status_changed(%s, %s)", appid, state);
+ json_object *data = json_object_new_object();
+ json_object_object_add(data, LCM_STATE, json_object_new_string(state));
+ json_object_object_add(data, LCM_TARGET, json_object_new_string(appid));
+
+ afb_event_push(event, json_object_get(data));
+ json_object_put(data);
+ } else {
+ HMI_ERROR("afb_event is not valid");
+ }
+ }
+ }
+}
+
+} // namespace lcm