summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-11-30 10:39:33 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2018-11-30 16:56:35 +0900
commit2a4be1018eab8af5fe2c2da733f4aba227b034ec (patch)
treefc662515df8b20b70d5a164dde82a204f90ccb1a
parentd8ff66046bfffc084e6965233237eb43b13dc316 (diff)
Add new features
* changeAreaSize * getAreaList Change-Id: I02cc6a5db1888c4900f525f2b3b6c2fb7b9c19b1 Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r--src/libwindowmanager.cpp103
-rw-r--r--src/libwindowmanager.h22
2 files changed, 123 insertions, 2 deletions
diff --git a/src/libwindowmanager.cpp b/src/libwindowmanager.cpp
index dfc0886..915500b 100644
--- a/src/libwindowmanager.cpp
+++ b/src/libwindowmanager.cpp
@@ -33,6 +33,10 @@ extern "C" {
#define UNUSED(x) (void)(x)
+using std::string;
+using std::vector;
+using std::unordered_map;
+
namespace {
/* Key for json obejct */
static const char g_kKeyDrawingName[] = "drawing_name";
@@ -59,6 +63,8 @@ class LibWindowmanager::Impl {
int activateWindow(json_object *object);
int deactivateWindow(json_object *object);
int endDraw(json_object *object);
+ int getAreaList(ChangeAreaReq* req);
+ int changeAreaSize(json_object* object);
int getDisplayInfo(json_object *object);
int getAreaInfo(json_object *in_obj, json_object *out_obj);
@@ -385,6 +391,76 @@ int LibWindowmanager::Impl::endDraw(json_object *object) {
});
}
+int LibWindowmanager::Impl::getAreaList(ChangeAreaReq* req) {
+ TRACE();
+ json_object* obj = json_object_new_object();
+ int rc = -1;
+ /* send the request */
+ int rc2 =
+ this->api_call("getAreaList", nullptr,
+ [req, &rc](bool ok, json_object *j) {
+ if (ok) {
+ json_object *val, *jarea;
+ if (json_object_object_get_ex(j, g_kKeyResponse, &val)) {
+ HMI_DEBUG("libwm", "responce:%s", json_object_get_string(val));
+ if (json_object_object_get_ex(val, "areas", &jarea)) {
+ int size = json_object_array_length(val);
+ for(int i = 0; i < size; i++)
+ {
+ json_object* elem = json_object_array_get_idx(jarea, i);
+ Rect rect;
+ json_object *_val, *jrect;
+ std::string name;
+ json_object_object_get_ex(elem, "name", &_val);
+ name = json_object_get_string(_val);
+ if(json_object_object_get_ex(elem, "rect", &jrect)) {
+ if(json_object_object_get_ex(jrect, "x", &_val))
+ rect.set_left(json_object_get_int(_val));
+ if(json_object_object_get_ex(jrect, "y", &_val))
+ rect.set_top(json_object_get_int(_val));
+ if(json_object_object_get_ex(jrect, "w", &_val))
+ rect.set_width(json_object_get_int(_val));
+ if(json_object_object_get_ex(jrect, "h", &_val))
+ rect.set_height(json_object_get_int(_val));
+ }
+ req->addAreaList(name, rect);
+ }
+ rc = 0;
+ }
+ }
+ else {
+ HMI_ERROR("libwm", "Not found key \"response\"");
+ rc = -EINVAL;
+ return;
+ }
+ } else {
+ HMI_ERROR("libwm", "Windowmanager-service is not initialized: %s",
+ j != nullptr ? json_object_to_json_string_ext(
+ j, JSON_C_TO_STRING_PRETTY)
+ : "no-info");
+ rc = -EPERM;
+ }
+ });
+
+ if (0 > rc2) {
+ HMI_ERROR("libwm", "api_call() failed");
+ rc = rc2;
+ }
+
+ return rc;
+}
+
+int LibWindowmanager::Impl::changeAreaSize(json_object* object) {
+ TRACE();
+ return this->api_call(__func__, object, [](bool ok, json_object *j) {
+ if (!ok) {
+ HMI_ERROR("libwm", "API Call changeAreaSize() failed: %s",
+ j != nullptr ? json_object_to_json_string_ext(j, JSON_C_TO_STRING_PRETTY)
+ : "no-info");
+ }
+ });
+}
+
int LibWindowmanager::Impl::getDisplayInfo(json_object *object) {
TRACE();
HMI_DEBUG("libwm", "called");
@@ -647,6 +723,7 @@ int LibWindowmanager::Impl::api_call(
int rc = 0;
if ((0 == strcmp("RequestSurface", verb)) ||
(0 == strcmp("GetDisplayInfo", verb)) ||
+ (0 == strcmp("getAreaList", verb)) ||
(0 == strcmp("GetAreaInfo", verb))) {
// We need to wrap the actual onReply call once in order to
// *look* like a normal functions pointer (std::functions<>
@@ -1184,6 +1261,32 @@ int LibWindowmanager::getAreaInfo(const char *label, json_object *out_obj) {
return this->d->getAreaInfo(object, out_obj);
}
+int LibWindowmanager::getAreaList(ChangeAreaReq* req)
+{
+ return this->d->getAreaList(req);
+}
+
+int LibWindowmanager::changeAreaSize(const ChangeAreaReq &req) {
+ json_object* object = json_object_new_object();
+ json_object_object_add(object, "save", json_object_new_boolean(req.getSave()));
+ json_object *array = json_object_new_array();
+ unordered_map<string, Rect> _req_area_size = req.getReq();
+
+ for(const auto& i: _req_area_size) {
+ json_object *elem = json_object_new_object();
+ json_object_object_add(elem, "name", json_object_new_string(i.first.c_str()));
+ json_object *rect = json_object_new_object();
+ json_object_object_add(rect, "x", json_object_new_int(i.second.left()));
+ json_object_object_add(rect, "y", json_object_new_int(i.second.top()));
+ json_object_object_add(rect, "w", json_object_new_int(i.second.width()));
+ json_object_object_add(rect, "h", json_object_new_int(i.second.height()));
+ json_object_object_add(elem, "rect", rect);
+ json_object_array_add(array, elem);
+ }
+ json_object_object_add(object, "areas", array);
+ return this->d->changeAreaSize(object);
+}
+
void LibWindowmanager::set_event_handler(enum EventType et, handler_fun f) {
return this->d->set_event_handler(et, std::move(f));
}
diff --git a/src/libwindowmanager.h b/src/libwindowmanager.h
index e963798..1b2bfae 100644
--- a/src/libwindowmanager.h
+++ b/src/libwindowmanager.h
@@ -20,6 +20,7 @@
#include <functional>
#include <vector>
#include <string>
+#include <unordered_map>
#include <json-c/json.h>
class Rect {
@@ -43,8 +44,7 @@ class Rect {
unsigned _h;
};
-struct Screen
-{
+struct Screen {
unsigned long width_dp;
unsigned long height_dp;
unsigned long width_mm;
@@ -79,6 +79,22 @@ class WMHandler {
car_event_handler on_car_run;
};
+class ChangeAreaReq {
+ public:
+ ChangeAreaReq() : _save(false) {}
+ ~ChangeAreaReq() = default;
+ void setAreaReq(const std::unordered_map<std::string, Rect> &area_req) { this->_area_req = area_req; }
+ void addAreaReq(const std::string& area_name, const Rect& area_size) { this->_area_req[area_name] = area_size; }
+ void setSaveReq(bool save) { this->_save = save; }
+ bool getSave() const { return this->_save; }
+ void addAreaList(const std::string& area_name, const Rect& area_size){ this->_area_list[area_name] = area_size; }
+ const std::unordered_map<std::string, Rect>& getReq() const { return this->_area_req; }
+ private:
+ std::unordered_map<std::string, Rect> _area_req;
+ std::unordered_map<std::string, Rect> _area_list;
+ bool _save;
+};
+
class LibWindowmanager {
public:
LibWindowmanager();
@@ -143,6 +159,8 @@ public:
int deactivateWindow(const char* role);
int endDraw(const char* role);
struct Screen getScreenInfo();
+ int getAreaList(ChangeAreaReq* req);
+ int changeAreaSize(const ChangeAreaReq& req);
int getAreaInfo(const char* role, Rect *out_rect);
void setEventHandler(const WMHandler& wmh);