summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp6
-rw-r--r--src/window_manager.cpp141
-rw-r--r--src/window_manager.hpp14
-rw-r--r--src/wm_client.cpp172
-rw-r--r--src/wm_client.hpp18
5 files changed, 195 insertions, 156 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 333df70..cc4386c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -431,10 +431,10 @@ void windowmanager_wm_subscribe(afb_req_t req) noexcept
afb_req_fail(req, "failed", "Need char const* argument event");
return;
}
- int event_id = json_object_get_int(j);
- int ret = g_afb_instance->wmgr.api_subscribe(req, event_id);
+ wm::WindowManager::EventType event_id = (wm::WindowManager::EventType)json_object_get_int(j);
+ bool ret = g_afb_instance->wmgr.api_subscribe(req, event_id);
- if (ret)
+ if (!ret)
{
afb_req_fail(req, "failed", "Error: afb_req_subscribe()");
return;
diff --git a/src/window_manager.cpp b/src/window_manager.cpp
index 77d41b7..9537be7 100644
--- a/src/window_manager.cpp
+++ b/src/window_manager.cpp
@@ -133,8 +133,8 @@ int WindowManager::init()
// Register callback to PolicyManager
this->pmw.registerCallback(onStateTransitioned, onError);
- // Make afb event
- for (int i = Event_Val_Min; i <= Event_Val_Max; i++)
+ // Make afb event for subscriber
+ for (int i = Event_ScreenUpdated; i < Event_Error; i++)
{
map_afb_event[kListEventName[i]] = afb_api_make_event(afbBindingV3root, kListEventName[i].c_str());
}
@@ -380,10 +380,37 @@ void WindowManager::api_enddraw(char const *appid, char const *drawing_name)
}
}
-int WindowManager::api_subscribe(afb_req_t req, int event_id)
+bool WindowManager::api_subscribe(afb_req_t req, EventType event_id)
{
- afb_event_t event = this->map_afb_event[kListEventName[event_id]];
- return afb_req_subscribe(req, event);
+ bool ret = false;
+ char* appid = afb_req_get_application_id(req);
+ if(event_id < Event_Val_Min || event_id > Event_Val_Max)
+ {
+ HMI_ERROR("not defined in Window Manager", event_id);
+ return ret;
+ }
+ HMI_INFO("%s subscribe %s : %d", appid, kListEventName[event_id], event_id);
+ if(event_id == Event_ScreenUpdated)
+ {
+ // Event_ScreenUpdated should be emitted to subscriber
+ afb_event_t event = this->map_afb_event[kListEventName[event_id]];
+ int rc = afb_req_subscribe(req, event);
+ if(rc == 0)
+ {
+ ret = true;
+ }
+ }
+ else if(appid)
+ {
+ string id = appid;
+ free(appid);
+ auto client = g_app_list.lookUpClient(id);
+ if(client != nullptr)
+ {
+ ret = client->subscribe(req, kListEventName[event_id]);
+ }
+ }
+ return ret;
}
result<json_object *> WindowManager::api_get_display_info()
@@ -425,39 +452,6 @@ result<json_object *> WindowManager::api_get_area_info(char const *drawing_name)
return Ok<json_object *>(object);
}
-void WindowManager::send_event(const string& evname, const string& role)
-{
- json_object *j = json_object_new_object();
- json_object_object_add(j, kKeyDrawingName, json_object_new_string(role.c_str()));
-
- int ret = afb_event_push(this->map_afb_event[evname], j);
- if (ret != 0)
- {
- HMI_DEBUG("afb_event_push failed: %m");
- }
-}
-
-void WindowManager::send_event(const string& evname, const string& role, const string& area,
- int x, int y, int w, int h)
-{
- json_object *j_rect = json_object_new_object();
- json_object_object_add(j_rect, kKeyX, json_object_new_int(x));
- json_object_object_add(j_rect, kKeyY, json_object_new_int(y));
- json_object_object_add(j_rect, kKeyWidth, json_object_new_int(w));
- json_object_object_add(j_rect, kKeyHeight, json_object_new_int(h));
-
- json_object *j = json_object_new_object();
- json_object_object_add(j, kKeyDrawingName, json_object_new_string(role.c_str()));
- json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area.c_str()));
- json_object_object_add(j, kKeyDrawingRect, j_rect);
-
- int ret = afb_event_push(this->map_afb_event[evname], j);
- if (ret != 0)
- {
- HMI_DEBUG("afb_event_push failed: %m");
- }
-}
-
/**
* proxied events
*/
@@ -608,49 +602,6 @@ void WindowManager::processError(WMError error)
this->processNextRequest();
}
-/*
- ******* Private Functions *******
- */
-
-void WindowManager::emit_activated(const string& role)
-{
- this->send_event(kListEventName[Event_Active], role);
-}
-
-void WindowManager::emit_deactivated(const string& role)
-{
- this->send_event(kListEventName[Event_Inactive], role);
-}
-
-void WindowManager::emit_syncdraw(const string& role, char const *area, int x, int y, int w, int h)
-{
- this->send_event(kListEventName[Event_SyncDraw], role, area, x, y, w, h);
-}
-
-void WindowManager::emit_syncdraw(const string &role, const string &area)
-{
- struct rect rect = this->lc->getAreaSize(area);
- this->send_event(kListEventName[Event_SyncDraw],
- role, area, rect.x, rect.y, rect.w, rect.h);
-}
-
-void WindowManager::emit_flushdraw(const string& role)
-{
- this->send_event(kListEventName[Event_FlushDraw], role);
-}
-
-void WindowManager::emit_visible(const string& role, bool is_visible)
-{
- this->send_event(is_visible ? kListEventName[Event_Visible] : kListEventName[Event_Invisible], role);
-}
-
-void WindowManager::emit_invisible(const string& role)
-{
- return emit_visible(role, false);
-}
-
-void WindowManager::emit_visible(const string& role) { return emit_visible(role, true); }
-
WMError WindowManager::setRequest(const string& appid, const string &role, const string &area,
Task task, unsigned* req_num)
{
@@ -740,10 +691,8 @@ WMError WindowManager::startTransition(unsigned req_num)
if (action.visible == TaskVisible::VISIBLE)
{
sync_draw_happen = true;
- this->emit_syncdraw(action.role, action.area);
- /* TODO: emit event for app not subscriber
- if(g_app_list.contains(y.appid))
- g_app_list.lookUpClient(y.appid)->emit_syncdraw(y.role, y.area); */
+ struct rect r = this->lc->getAreaSize(action.area);
+ action.client->emitSyncDraw(action.area, r);
}
}
@@ -758,12 +707,8 @@ WMError WindowManager::startTransition(unsigned req_num)
for (const auto &x : actions)
{
this->lc->visibilityChange(x);
- emit_deactivated(x.role);
- /* if (g_app_list.contains(x.client->appID()))
- {
- auto client = g_app_list.lookUpClient(x.client->appID());
- this->deactivate(client->surfaceID(x.role));
- } */
+ x.client->emitActive(false);
+ x.client->emitVisible(false);
}
this->lc->renderLayers();
ret = WMError::NO_LAYOUT_CHANGE;
@@ -800,16 +745,8 @@ WMError WindowManager::doEndDraw(unsigned req_num)
}
ret = this->lc->visibilityChange(act);
- if(act.visible == VISIBLE)
- {
- emit_visible(act.role);
- emit_activated(act.role);
- }
- else
- {
- emit_invisible(act.role);
- emit_deactivated(act.role);
- }
+ act.client->emitActive((act.visible == VISIBLE));
+ act.client->emitVisible((act.visible == VISIBLE));
if (ret != WMError::SUCCESS)
{
@@ -828,7 +765,7 @@ WMError WindowManager::doEndDraw(unsigned req_num)
{
if(act_flush.visible == TaskVisible::VISIBLE)
{
- this->emit_flushdraw(act_flush.role);
+ act_flush.client->emitFlushDraw();
}
}
diff --git a/src/window_manager.hpp b/src/window_manager.hpp
index 30deb4b..e9caf7e 100644
--- a/src/window_manager.hpp
+++ b/src/window_manager.hpp
@@ -176,11 +176,9 @@ class WindowManager
void api_activate_window(char const *appid, char const *role, char const *drawing_area, const reply_func &reply);
void api_deactivate_window(char const *appid, char const *role, const reply_func &reply);
void api_enddraw(char const *appid, char const *role);
- int api_subscribe(afb_req_t req, int event_id);
+ bool api_subscribe(afb_req_t req, EventType event_id);
result<json_object *> api_get_display_info();
result<json_object *> api_get_area_info(char const *role);
- void send_event(const std::string& evname, const std::string& role);
- void send_event(const std::string& evname, const std::string& role, const std::string& area, int x, int y, int w, int h);
// Events from the compositor we are interested in
void surface_created(unsigned surface_id);
@@ -195,16 +193,6 @@ class WindowManager
void processError(WMError error);
private:
- // WM Events to clients
- void emit_activated(const std::string& role);
- void emit_deactivated(const std::string& role);
- void emit_syncdraw(const std::string& role, char const *area, int x, int y, int w, int h);
- void emit_syncdraw(const std::string &role, const std::string &area);
- void emit_flushdraw(const std::string& role);
- void emit_visible(const std::string& role, bool is_visible);
- void emit_invisible(const std::string& role);
- void emit_visible(const std::string& role);
-
WMError setRequest(const std::string &appid, const std::string &role, const std::string &area,
Task task, unsigned *req_num);
WMError checkPolicy(unsigned req_num);
diff --git a/src/wm_client.cpp b/src/wm_client.cpp
index 3edf850..fdf7919 100644
--- a/src/wm_client.cpp
+++ b/src/wm_client.cpp
@@ -16,7 +16,6 @@
#include <json-c/json.h>
#include "wm_client.hpp"
-#include "util.hpp"
#include <ilm/ilm_control.h>
#define INVALID_SURFACE_ID 0
@@ -27,16 +26,31 @@ using std::vector;
namespace wm
{
-static const vector<string> kWMEvents = {
- // Private event for applications
- "syncDraw", "flushDraw", "visible", "invisible", "active", "inactive", "error"};
-static const vector<string> kErrorDescription = {
- "unknown-error"};
-
+static const char kActive[] = "active";
+static const char kInactive[] = "inactive";
+static const char kVisible[] = "visible";
+static const char kInvisible[] = "invisible";
+static const char kSyncDraw[] = "syncDraw";
+static const char kFlushDraw[] = "flushDraw";
static const char kKeyDrawingName[] = "drawing_name";
+static const char kKeyDrawingArea[] = "drawing_area";
+static const char kKeyRole[] = "role";
+static const char kKeyArea[] = "area";
static const char kKeyrole[] = "role";
static const char kKeyError[] = "error";
-static const char kKeyErrorDesc[] = "kErrorDescription";
+static const char kKeyErrorDesc[] = "errorDescription";
+static const char kKeyX[] = "x";
+static const char kKeyY[] = "y";
+static const char kKeyWidth[] = "width";
+static const char kKeyHeight[] = "height";
+static const char kKeyDrawingRect[] = "drawing-rect";
+
+static const vector<string> kWMEvents = {
+ // Private event for applications
+ kActive, kInactive,
+ kVisible, kInvisible,
+ kSyncDraw, kFlushDraw,
+ kKeyError};
WMClient::WMClient(const string &appid, unsigned layer, unsigned surface, const string &role)
: id(appid), layer(layer), is_source_set(false),
@@ -50,7 +64,7 @@ WMClient::WMClient(const string &appid, unsigned layer, unsigned surface, const
#else
afb_event_t ev = afb_api_make_event(afbBindingV3root, x.c_str());
#endif
- evname2list[x] = ev;
+ evname2afb_event[x] = ev;
}
}
@@ -59,7 +73,7 @@ WMClient::WMClient(const string &appid, const string &role)
layer(0),
is_source_set(false),
role2surface(0),
- evname2list(0)
+ evname2afb_event(0)
{
role2surface[role] = INVALID_SURFACE_ID;
for (auto x : kWMEvents)
@@ -69,7 +83,7 @@ WMClient::WMClient(const string &appid, const string &role)
#else
afb_event_t ev = afb_api_make_event(afbBindingV3root, x.c_str());
#endif
- evname2list[x] = ev;
+ evname2afb_event[x] = ev;
}
}
@@ -78,7 +92,7 @@ WMClient::WMClient(const string &appid, unsigned layer, const string &role)
layer(layer),
main_role(role),
role2surface(0),
- evname2list(0)
+ evname2afb_event(0)
{
role2surface[role] = INVALID_SURFACE_ID;
for (auto x : kWMEvents)
@@ -88,7 +102,7 @@ WMClient::WMClient(const string &appid, unsigned layer, const string &role)
#else
afb_event_t ev = afb_api_make_event(afbBindingV3root, x.c_str());
#endif
- evname2list[x] = ev;
+ evname2afb_event[x] = ev;
}
}
@@ -158,15 +172,9 @@ bool WMClient::removeSurfaceIfExist(unsigned surface)
return ret;
}
-
-#if GTEST_ENABLED
bool WMClient::subscribe(afb_req_t req, const string &evname)
{
- if(evname != kKeyError){
- HMI_DEBUG("error is only enabeled for now");
- return false;
- }
- int ret = afb_req_subscribe(req, this->evname2list[evname]);
+ int ret = afb_req_subscribe(req, this->evname2afb_event[evname]);
if (ret)
{
HMI_DEBUG("Failed to subscribe %s", evname.c_str());
@@ -175,24 +183,132 @@ bool WMClient::subscribe(afb_req_t req, const string &evname)
return true;
}
-void WMClient::emitError(WM_CLIENT_ERROR_EVENT ev)
+void WMClient::emitVisible(bool visible)
+{
+ // error check
+ bool allow_send = false;
+ if(visible)
+ {
+ allow_send = afb_event_is_valid(this->evname2afb_event[kVisible]);
+ }
+ else
+ {
+ allow_send = afb_event_is_valid(this->evname2afb_event[kInvisible]);
+ }
+ if(allow_send)
+ {
+ this->area = area;
+ json_object* j = json_object_new_object();
+ json_object_object_add(j, kKeyRole, json_object_new_string(this->role().c_str()));
+ json_object_object_add(j, kKeyDrawingName, json_object_new_string(this->role().c_str()));
+
+ if(visible)
+ {
+ afb_event_push(this->evname2afb_event[kVisible], j);
+ }
+ else
+ {
+ afb_event_push(this->evname2afb_event[kInvisible], j);
+ }
+ }
+ else
+ {
+ HMI_ERROR("Failed to send %s", __func__);
+ }
+}
+
+void WMClient::emitActive(bool active)
+{
+ // error check
+ bool allow_send = false;
+ if(active)
+ {
+ allow_send = afb_event_is_valid(this->evname2afb_event[kActive]);
+ }
+ else
+ {
+ allow_send = afb_event_is_valid(this->evname2afb_event[kInactive]);
+ }
+ if(allow_send)
+ {
+ this->area = area;
+ json_object* j = json_object_new_object();
+ json_object_object_add(j, kKeyRole, json_object_new_string(this->role().c_str()));
+ json_object_object_add(j, kKeyDrawingName, json_object_new_string(this->role().c_str()));
+
+ if(active)
+ {
+ afb_event_push(this->evname2afb_event[kActive], j);
+ }
+ else
+ {
+ afb_event_push(this->evname2afb_event[kInactive], j);
+ }
+ }
+ else
+ {
+ HMI_ERROR("Failed to send %s", __func__);
+ }
+}
+
+void WMClient::emitSyncDraw(const string& area, struct rect& r)
+{
+ HMI_NOTICE("trace");
+ if(afb_event_is_valid(this->evname2afb_event[kSyncDraw]))
+ {
+ this->area = area;
+ json_object *j_rect = json_object_new_object();
+ json_object_object_add(j_rect, kKeyX, json_object_new_int(r.x));
+ json_object_object_add(j_rect, kKeyY, json_object_new_int(r.y));
+ json_object_object_add(j_rect, kKeyWidth, json_object_new_int(r.w));
+ json_object_object_add(j_rect, kKeyHeight, json_object_new_int(r.h));
+
+ json_object* j = json_object_new_object();
+ json_object_object_add(j, kKeyRole, json_object_new_string(this->role().c_str()));
+ json_object_object_add(j, kKeyDrawingName, json_object_new_string(this->role().c_str()));
+ json_object_object_add(j, kKeyDrawingArea, json_object_new_string(area.c_str()));
+ json_object_object_add(j, kKeyArea, json_object_new_string(this->role().c_str()));
+
+ json_object_object_add(j, kKeyDrawingRect, j_rect);
+ afb_event_push(this->evname2afb_event[kSyncDraw], j);
+ }
+ else
+ {
+ HMI_ERROR("Failed to send %s", __func__);
+ }
+}
+
+void WMClient::emitFlushDraw()
{
- if (!afb_event_is_valid(this->evname2list[kKeyError])){
+ if(afb_event_is_valid(this->evname2afb_event[kFlushDraw]))
+ {
+ json_object* j = json_object_new_object();
+ json_object_object_add(j, kKeyRole, json_object_new_string(this->role().c_str()));
+ json_object_object_add(j, kKeyDrawingName, json_object_new_string(this->role().c_str()));
+ afb_event_push(this->evname2afb_event[kFlushDraw], nullptr);
+ }
+ else
+ {
+ HMI_ERROR("Failed to send %s", __func__);
+ }
+}
+
+void WMClient::emitError(WMError error)
+{
+ if (!afb_event_is_valid(this->evname2afb_event[kKeyError])){
HMI_ERROR("event err is not valid");
return;
}
json_object *j = json_object_new_object();
- json_object_object_add(j, kKeyError, json_object_new_int(ev));
- json_object_object_add(j, kKeyErrorDesc, json_object_new_string(kErrorDescription[ev].c_str()));
- HMI_DEBUG("error: %d, description:%s", ev, kErrorDescription[ev].c_str());
-
- int ret = afb_event_push(this->evname2list[kKeyError], j);
+ json_object_object_add(j, kKeyError, json_object_new_int(error));
+ json_object_object_add(j, kKeyErrorDesc, json_object_new_string(errorDescription(error)));
+ HMI_DEBUG("error: %d, description:%s", error, errorDescription(error));
+ int ret = afb_event_push(this->evname2afb_event[kKeyError], j);
if (ret != 0)
{
HMI_DEBUG("afb_event_push failed: %m");
}
}
-#endif
void WMClient::dumpInfo()
{
diff --git a/src/wm_client.hpp b/src/wm_client.hpp
index 53383fb..99ae499 100644
--- a/src/wm_client.hpp
+++ b/src/wm_client.hpp
@@ -20,6 +20,7 @@
#include <vector>
#include <string>
#include <unordered_map>
+#include "util.hpp"
#include "wm_error.hpp"
extern "C"
@@ -30,11 +31,6 @@ extern "C"
namespace wm
{
-enum WM_CLIENT_ERROR_EVENT
-{
- UNKNOWN_ERROR
-};
-
class WMClient
{
public:
@@ -57,10 +53,12 @@ class WMClient
void setSurfaceSizeCorrectly();
bool removeSurfaceIfExist(unsigned surface);
-#if GTEST_ENABLED
bool subscribe(afb_req_t req, const std::string &event_name);
- void emitError(WM_CLIENT_ERROR_EVENT ev);
-#endif
+ void emitActive(bool active);
+ void emitVisible(bool visible);
+ void emitSyncDraw(const std::string& area, struct rect& r);
+ void emitFlushDraw();
+ void emitError(WMError error);
void dumpInfo();
@@ -75,9 +73,9 @@ class WMClient
std::unordered_map<std::string, unsigned> role2surface;
#if GTEST_ENABLED
// This is for unit test. afb_make_event occurs sig11 if call not in afb-binding
- std::unordered_map<std::string, std::string> event2list;
+ std::unordered_map<std::string, std::string> evname2afb_event;
#else
- std::unordered_map<std::string, afb_event_t> evname2list;
+ std::unordered_map<std::string, afb_event_t> evname2afb_event;
#endif
};
} // namespace wm