summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-08-03 18:10:41 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-08-03 21:03:52 +0900
commit1652c7b5702e6ea4016537af36474829cf6903ef (patch)
tree20a8baf2d878e44c93a449436f737315c4dc0701
parent16cad1a12557954f64e6d10249655060921cfe3a (diff)
Simple API[2/2]
Change-Id: I3e56ee8ddcf396ea6d4c4e9d942de3b38c7f9914 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r--src/libwindowmanager.cpp244
-rw-r--r--src/libwindowmanager.h62
2 files changed, 305 insertions, 1 deletions
diff --git a/src/libwindowmanager.cpp b/src/libwindowmanager.cpp
index e4614ac..f5e6100 100644
--- a/src/libwindowmanager.cpp
+++ b/src/libwindowmanager.cpp
@@ -29,6 +29,7 @@
#include <mutex>
#include <set>
#include <queue>
+#include <memory>
#include <unistd.h>
@@ -79,6 +80,14 @@ class LibWindowmanager::Impl {
void set_event_handler(enum EventType et, handler_fun func);
+ void setVisibleHandler(visible_handler f);
+ void setInvisibleHandler(invisible_handler f);
+ void setActiveHandler(active_handler f);
+ void setInactiveHandler(inactive_handler f);
+ void setSyncDrawHandler(sync_draw_handler f);
+ void setFlushDrawHandler(flush_draw_handler f);
+ void setScreenUpdatedHandler(screen_update_handler f);
+
Impl();
~Impl();
@@ -96,11 +105,17 @@ public:
void event(char const *et, json_object *object);
private:
int runEventLoop();
+ visible_handler _on_visible = nullptr;
+ invisible_handler _on_invisible = nullptr;
+ active_handler _on_active = nullptr;
+ inactive_handler _on_inactive = nullptr;
+ sync_draw_handler _on_sync_draw = nullptr;
+ flush_draw_handler _on_flush_draw = nullptr;
+ screen_update_handler _on_screen_updated = nullptr;
};
namespace {
-constexpr const int token_maxlen = 20;
constexpr const char *const wmAPI = "windowmanager";
#define CONCAT_(X, Y) X##Y
@@ -584,6 +599,89 @@ void LibWindowmanager::Impl::set_event_handler(enum EventType et, handler_fun fu
}
}
+void LibWindowmanager::Impl::setActiveHandler(active_handler f) {
+ struct json_object* j = json_object_new_object();
+ json_object_object_add(j, "event", json_object_new_int(Event_Active));
+
+ int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this);
+ if (0 > ret) {
+ HMI_ERROR("libwm", "Failed to subscribe event");
+ return;
+ }
+ this->_on_active = f;
+}
+
+void LibWindowmanager::Impl::setInactiveHandler(inactive_handler f) {
+ struct json_object* j = json_object_new_object();
+ json_object_object_add(j, "event", json_object_new_int(Event_Inactive));
+
+ int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this);
+ if (0 > ret) {
+ HMI_ERROR("libwm", "Failed to subscribe event");
+ return;
+ }
+ this->_on_inactive = f;
+}
+
+void LibWindowmanager::Impl::setVisibleHandler(visible_handler f) {
+ struct json_object* j = json_object_new_object();
+ json_object_object_add(j, "event", json_object_new_int(Event_Visible));
+
+ int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this);
+ if (0 > ret) {
+ HMI_ERROR("libwm", "Failed to subscribe event");
+ return;
+ }
+ this->_on_visible = f;
+}
+
+void LibWindowmanager::Impl::setInvisibleHandler(invisible_handler f) {
+ struct json_object* j = json_object_new_object();
+ json_object_object_add(j, "event", json_object_new_int(Event_Invisible));
+
+ int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this);
+ if (0 > ret) {
+ HMI_ERROR("libwm", "Failed to subscribe event");
+ return;
+ }
+ this->_on_invisible = f;
+}
+
+void LibWindowmanager::Impl::setSyncDrawHandler(sync_draw_handler f) {
+ struct json_object* j = json_object_new_object();
+ json_object_object_add(j, "event", json_object_new_int(Event_SyncDraw));
+
+ int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this);
+ if (0 > ret) {
+ HMI_ERROR("libwm", "Failed to subscribe event");
+ return;
+ }
+ this->_on_sync_draw = f;
+}
+
+void LibWindowmanager::Impl::setFlushDrawHandler(flush_draw_handler f) {
+ struct json_object* j = json_object_new_object();
+ json_object_object_add(j, "event", json_object_new_int(Event_FlushDraw));
+
+ int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this);
+ if (0 > ret) {
+ HMI_ERROR("libwm", "Failed to subscribe event");
+ return;
+ }
+ this->_on_flush_draw = f;
+}
+void LibWindowmanager::Impl::setScreenUpdatedHandler(screen_update_handler f) {
+ struct json_object* j = json_object_new_object();
+ json_object_object_add(j, "event", json_object_new_int(Event_ScreenUpdated));
+
+ int ret = afb_wsj1_call_j(this->wsj1, wmAPI, "wm_subscribe", j, _on_reply_static, this);
+ if (0 > ret) {
+ HMI_ERROR("libwm", "Failed to subscribe event");
+ return;
+ }
+ this->_on_screen_updated = f;
+}
+
namespace {
std::pair<bool, LibWindowmanager::EventType> make_event_type(char const *et) {
// Event have the form "$API/$EVENT", just try to find the first / and
@@ -690,6 +788,74 @@ void LibWindowmanager::Impl::event(char const *et, json_object *object) {
return;
}
+ json_object *j_val;
+ const char* role;
+ bool emit = false;
+ if(json_object_object_get_ex(object, kKeyDrawingName, &j_val)) {
+ role = json_object_get_string(j_val);
+ }
+ if (this->labels.find(role) != this->labels.end()){
+ emit = true;
+ }
+
+ switch(oet.second) {
+ case Event_Active :
+ if(_on_active && emit) {
+ return _on_active(role);
+ }
+ break;
+ case Event_Inactive :
+ if(_on_inactive && emit) {
+ return _on_inactive(role);
+ }
+ break;
+ case Event_Visible :
+ if(_on_visible && emit) {
+ return _on_visible(role);
+ }
+ break;
+ case Event_Invisible :
+ if(_on_invisible && emit) {
+ return _on_invisible(role);
+ }
+ break;
+ case Event_SyncDraw :
+ if(_on_sync_draw && emit) {
+ json_object_object_get_ex(object, kKeyDrawingArea, &j_val);
+ const char* area = json_object_get_string(j_val);
+ json_object_object_get_ex(object, "x", &j_val);
+ unsigned x = json_object_get_int(j_val);
+ json_object_object_get_ex(object, "y", &j_val);
+ unsigned y = json_object_get_int(j_val);
+ json_object_object_get_ex(object, "width", &j_val);
+ unsigned w = json_object_get_int(j_val);
+ json_object_object_get_ex(object, "height", &j_val);
+ unsigned h = json_object_get_int(j_val);
+ Rect rect(x, y, w, h);
+ return _on_sync_draw(role, area, rect);
+ }
+ break;
+ case Event_FlushDraw :
+ if(_on_flush_draw && emit) {
+ return _on_flush_draw(role);
+ }
+ break;
+ case Event_ScreenUpdated :
+ if(_on_screen_updated) {
+ // emit this case
+ json_object_object_get_ex(object, "ids", &j_val);
+ int len = json_object_array_length(j_val);
+ std::vector<std::string> id_list;
+ for(int i = 0; i < len; i++)
+ {
+ id_list.emplace_back(
+ json_object_get_string(json_object_array_get_idx(j_val, i)));
+ }
+ return _on_screen_updated(id_list);
+ }
+ break;
+ }
+
auto i = this->handlers.find(oet.second);
if (i != this->handlers.end()) {
json_object *val;
@@ -807,10 +973,58 @@ int LibWindowmanager::getDisplayInfo(json_object *object) {
return this->d->getDisplayInfo(object);
}
+int LibWindowmanager::getDisplayInfo(AGLScreenInfo *out_info) {
+ json_object* object = json_object_new_object();
+ int ret = this->d->getDisplayInfo(object);
+ if (!ret) {
+ json_object *j_val;
+ if (json_object_object_get_ex(object, "width_pixel", &j_val)) {
+ out_info->set_width_dp(json_object_get_double(j_val));
+ }
+ if (json_object_object_get_ex(object, "height_pixel", &j_val)) {
+ out_info->set_height_dp(json_object_get_double(j_val));
+ }
+ if (json_object_object_get_ex(object, "width_mm", &j_val)) {
+ out_info->set_width_mm(json_object_get_double(j_val));
+ }
+ if (json_object_object_get_ex(object, "height_mm", &j_val)) {
+ out_info->set_height_mm(json_object_get_double(j_val));
+ }
+ if (json_object_object_get_ex(object, "scale", &j_val)) {
+ out_info->set_scale_factor(json_object_get_double(j_val));
+ }
+ }
+ json_object_put(object);
+ return ret;
+}
+
int LibWindowmanager::getAreaInfo(json_object *in_obj, json_object *out_obj) {
return this->d->getAreaInfo(in_obj, out_obj);
}
+int LibWindowmanager::getAreaInfo(const char *role, Rect *out_rect) {
+ json_object *object = json_object_new_object();
+ json_object *out = json_object_new_object();
+ json_object_object_add(object, this->kKeyDrawingName, json_object_new_string(role));
+ int ret = this->d->getAreaInfo(object, out);
+ if(!ret) {
+ json_object *j_val;
+ if (json_object_object_get_ex(object, "x", &j_val)) {
+ out_rect->set_left(json_object_get_int(j_val));
+ }
+ if (json_object_object_get_ex(object, "y", &j_val)) {
+ out_rect->set_top(json_object_get_int(j_val));
+ }
+ if (json_object_object_get_ex(object, "width", &j_val)) {
+ out_rect->set_width(json_object_get_int(j_val));
+ }
+ if (json_object_object_get_ex(object, "height", &j_val)) {
+ out_rect->set_height(json_object_get_int(j_val));
+ }
+ }
+ return ret;
+}
+
int LibWindowmanager::getAreaInfo(const char *label, json_object *out_obj) {
json_object *object = json_object_new_object();
json_object_object_add(object, this->kKeyDrawingName, json_object_new_string(label));
@@ -821,6 +1035,34 @@ void LibWindowmanager::set_event_handler(enum EventType et, handler_fun f) {
return this->d->set_event_handler(et, std::move(f));
}
+void LibWindowmanager::setVisibleHandler(invisible_handler f) {
+ return this->d->setVisibleHandler(f);
+}
+
+void LibWindowmanager::setInvisibleHandler(visible_handler f) {
+ return this->d->setInvisibleHandler(f);
+}
+
+void LibWindowmanager::setActiveHandler(active_handler f) {
+ return this->d->setActiveHandler(f);
+}
+
+void LibWindowmanager::setInactiveHandler(inactive_handler f) {
+ return this->d->setInactiveHandler(f);
+}
+
+void LibWindowmanager::setSyncDrawHandler(sync_draw_handler f) {
+ return this->d->setSyncDrawHandler(f);
+}
+
+void LibWindowmanager::setFlushDrawHandler(flush_draw_handler f) {
+ return this->d->setFlushDrawHandler(f);
+}
+
+void LibWindowmanager::setScreenUpdatedHandler(screen_update_handler f) {
+ return this->d->setScreenUpdatedHandler(f);
+}
+
LibWindowmanager::LibWindowmanager() : d(new Impl) {}
LibWindowmanager::~LibWindowmanager() { delete d; }
diff --git a/src/libwindowmanager.h b/src/libwindowmanager.h
index 697191c..a241131 100644
--- a/src/libwindowmanager.h
+++ b/src/libwindowmanager.h
@@ -18,8 +18,53 @@
#define LIBWINDOWMANAGER_H
#include <functional>
+#include <vector>
#include <json-c/json.h>
+class Rect {
+ public:
+ Rect() : _x(0), _y(0),_w(0), _h(0) {}
+ Rect(unsigned x, unsigned y, unsigned w, unsigned h)
+ : _x(x), _y(y),_w(w), _h(h) {}
+ ~Rect() = default;
+ unsigned left() const {return _x;}
+ unsigned top() const {return _y;}
+ unsigned width() const {return _w;}
+ unsigned height() const {return _h;}
+ void set_left(unsigned int x){_x = x;}
+ void set_top(unsigned int y){_y = y;}
+ void set_width(unsigned int w){_w = w;}
+ void set_height(unsigned int h){_h = h;}
+ private:
+ unsigned _x;
+ unsigned _y;
+ unsigned _w;
+ unsigned _h;
+};
+
+class AGLScreenInfo
+{
+ public:
+ unsigned long width_dp(void) const { return _width_dp; };
+ unsigned long height_dp(void) const { return _height_dp; };
+ unsigned long width_mm(void) const { return _width_mm; };
+ unsigned long height_mm(void) const { return _height_mm; };
+ double scale_factor(void) const { return _scale; };
+
+ void set_width_dp(unsigned long w) { _width_dp = w; };
+ void set_height_dp(unsigned long h) { _height_dp = h; };
+ void set_width_mm(unsigned long w) { _width_mm = w; };
+ void set_height_mm(unsigned long h) { _height_mm = h; };
+ void set_scale_factor(double scale) { _scale = scale; };
+
+ private:
+ unsigned long _width_dp;
+ unsigned long _height_dp;
+ unsigned long _width_mm;
+ unsigned long _height_mm;
+ double _scale = 1.0;
+};
+
class LibWindowmanager {
public:
LibWindowmanager();
@@ -29,6 +74,13 @@ public:
LibWindowmanager &operator=(const LibWindowmanager &) = delete;
using handler_fun = std::function<void(json_object *)>;
+ using visible_handler = std::function<void(const char*)>;
+ using invisible_handler = std::function<void(const char*)>;
+ using active_handler = std::function<void(const char*)>;
+ using inactive_handler = std::function<void(const char*)>;
+ using sync_draw_handler = std::function<void(const char*, const char*, const Rect&)>;
+ using flush_draw_handler= std::function<void(const char*)>;
+ using screen_update_handler = std::function<void(const std::vector<std::string>&)>;
/* DrawingArea name (usage: {layout}.{area}) */
const std::string kStrLayoutNormal = "normal";
@@ -68,6 +120,16 @@ public:
int activateWindow(const char* role, const char* area);
int deactivateWindow(const char* role);
int endDraw(const char* role);
+ int getDisplayInfo(AGLScreenInfo *out_info);
+ int getAreaInfo(const char* role, Rect *out_rect);
+
+ void setVisibleHandler(visible_handler f);
+ void setInvisibleHandler(invisible_handler f);
+ void setActiveHandler(active_handler f);
+ void setInactiveHandler(inactive_handler f);
+ void setSyncDrawHandler(sync_draw_handler f);
+ void setFlushDrawHandler(flush_draw_handler f);
+ void setScreenUpdatedHandler(screen_update_handler f);
// Backward Compatible API
int requestSurface(json_object *object);