aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-04-10 17:36:11 +0800
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-04-10 17:36:21 +0800
commit134be0531d2aa3926bb6ed441c7839174a8bba17 (patch)
treecf476ae4eb18d15de73dcb4df7fbce07a5eb8453 /src
parenta7e49d93b4dd03f8ce3b77f831f9293ba5a3de01 (diff)
modify
add wm proxy add read/write json file add getRunnables to ApplicationGuide.md Change-Id: I65e9e6620ecb207c999e590410782590edd7005d
Diffstat (limited to 'src')
-rw-r--r--src/hs-helper.cpp49
-rw-r--r--src/hs-helper.h4
-rw-r--r--src/hs-proxy.cpp29
-rw-r--r--src/hs-proxy.h28
4 files changed, 106 insertions, 4 deletions
diff --git a/src/hs-helper.cpp b/src/hs-helper.cpp
index 50a3ae1..159668e 100644
--- a/src/hs-helper.cpp
+++ b/src/hs-helper.cpp
@@ -17,6 +17,7 @@
#include <string.h>
#include <cstdarg>
#include "hs-helper.h"
+#include <unistd.h>
const char* evlist[] = {
@@ -272,3 +273,51 @@ std::string get_application_id(const afb_req_t request)
return appid;
}
+
+/**
+ * read json file
+ *
+ * #### Parameters
+ * - file : file name
+ * - obj : json_object
+ *
+ * #### Return
+ * 0 : read success
+ * 1 : read fail
+ *
+ */
+int readJsonFile(const char* file, struct json_object **obj)
+{
+ *obj = nullptr;
+ int ret = -1;
+ FILE *fp = fopen(file, "rb");
+ if(fp == nullptr) {
+ AFB_ERROR("open %s failed", file);
+ return ret;
+ }
+
+ const int buf_size = 128;
+ char buf[buf_size];
+ struct json_tokener *tokener = json_tokener_new();
+ enum json_tokener_error json_error;
+ while(1) {
+ size_t len = fread(buf, sizeof(char), buf_size, fp);
+ *obj = json_tokener_parse_ex(tokener, buf, len);
+ if(nullptr != *obj) {
+ AFB_NOTICE("read %s success", file);
+ ret = 0;
+ break;
+ }
+
+ json_error = json_tokener_get_error(tokener);
+ if ((json_tokener_continue != json_error) || (buf_size > len)) {
+ AFB_ERROR("parse %s error", file);
+ *obj = nullptr;
+ break;
+ }
+ }
+
+ fclose(fp);
+ json_tokener_free(tokener);
+ return ret;
+}
diff --git a/src/hs-helper.h b/src/hs-helper.h
index f57799d..55f9386 100644
--- a/src/hs-helper.h
+++ b/src/hs-helper.h
@@ -17,7 +17,7 @@
#ifndef HOMESCREEN_HELPER_H
#define HOMESCREEN_HELPER_H
#define AFB_BINDING_VERSION 3
-#include <afb/afb-binding.h>
+#include <afb/afb-binding>
#include <json-c/json.h>
#include <string>
@@ -53,6 +53,8 @@ void hs_add_object_to_json_object_str(struct json_object* j_obj, int count, ...)
void hs_add_object_to_json_object_func(struct json_object* j_obj, const char* verb_name, int count, ...);
int hs_search_event_name_index(const char* value);
std::string get_application_id(const afb_req_t request);
+int readJsonFile(const char* file, struct json_object **obj);
+int writeJsonFile(const char* file, struct json_object *obj);
typedef int (*event_hook_func)(afb_api_t api, const char *event, struct json_object *object);
void setEventHook(const char *event, const event_hook_func f);
diff --git a/src/hs-proxy.cpp b/src/hs-proxy.cpp
index f0ee5f0..967c1b1 100644
--- a/src/hs-proxy.cpp
+++ b/src/hs-proxy.cpp
@@ -16,8 +16,9 @@
#include "hs-proxy.h"
-const char _afm_main[] = "afm-main";
-
+static const char _afm_main[] = "afm-main";
+static const char _windowmanager[] = "windowmanager";
+static const char _event[] = "event";
/**
* the callback function
@@ -80,6 +81,8 @@ static int api_call_sync(afb_api_t api, const char *service, const char *verb, s
return ret;
}
+/* -------------------------------------HS_AfmMainProxy------------------------------------------ */
+
/**
* get runnables application list
*
@@ -131,4 +134,24 @@ void HS_AfmMainProxy::start(afb_req_t request, const std::string &id)
{
struct json_object *args = json_object_new_string(id.c_str());
api_call(request->api, _afm_main, __FUNCTION__, args);
-} \ No newline at end of file
+}
+
+/* -------------------------------------HS_WmProxy------------------------------------------ */
+
+/**
+ * subscribe windowmanager event
+ *
+ * #### Parameters
+ * - api : the api serving the request
+ * - event : windowmanager event
+ *
+ * #### Return
+ * None
+ *
+ */
+void HS_WmProxy::subscribe(afb_api_t api, EventType event)
+{
+ struct json_object* push_obj = json_object_new_object();
+ json_object_object_add(push_obj, _event, json_object_new_int(event));
+ api_call(api, _windowmanager, "wm_subscribe", push_obj);
+}
diff --git a/src/hs-proxy.h b/src/hs-proxy.h
index 8741e49..b6283d6 100644
--- a/src/hs-proxy.h
+++ b/src/hs-proxy.h
@@ -31,4 +31,32 @@ struct HS_AfmMainProxy {
void start(afb_req_t request, const std::string &id);
};
+class HS_WmProxy {
+public:
+ HS_WmProxy() = default;
+ ~HS_WmProxy() = default;
+
+ enum EventType
+ {
+ Event_Val_Min = 0,
+
+ Event_Active = Event_Val_Min,
+ Event_Inactive,
+
+ Event_Visible,
+ Event_Invisible,
+
+ Event_SyncDraw,
+ Event_FlushDraw,
+
+ Event_ScreenUpdated,
+
+ Event_Error,
+
+ Event_Val_Max = Event_Error,
+ };
+
+ // asynchronous call, reply in callback function
+ void subscribe(afb_api_t api, EventType event);
+};
#endif // HOMESCREEN_PROXY_H \ No newline at end of file