aboutsummaryrefslogtreecommitdiffstats
path: root/src/homescreen.cpp
diff options
context:
space:
mode:
authorwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-04-16 18:30:59 +0800
committerwang_zhiqiang <wang_zhiqiang@dl.cn.nexty-ele.com>2019-04-16 18:30:59 +0800
commit0fc1fc7db6ff7cb95ad6cd6f0ef8f2b88f3d08da (patch)
tree9fb4b9e07763b1fe4323cddce644d1480660ded5 /src/homescreen.cpp
parent54c9e53f5f9cfbc9f8cf1ea4af9b81447c3a9ffc (diff)
add handshake
Change-Id: Ie5bdd327f5e994730b0d1cbffad68fca93c80766
Diffstat (limited to 'src/homescreen.cpp')
-rw-r--r--src/homescreen.cpp83
1 files changed, 75 insertions, 8 deletions
diff --git a/src/homescreen.cpp b/src/homescreen.cpp
index 7b8e653..3e4ff8f 100644
--- a/src/homescreen.cpp
+++ b/src/homescreen.cpp
@@ -25,6 +25,7 @@
#include "hs-clientmanager.h"
#include "hs-appinfo.h"
#include "hs-config.h"
+#include <unistd.h>
const char _error[] = "error";
@@ -34,16 +35,77 @@ const char _reply_message[] = "reply_message";
const char _keyData[] = "data";
const char _keyId[] = "id";
+struct hs_handshake {
+ hs_handshake(int times, int sleep) : m_times(times), m_sleep(sleep) {}
+ void start(afb_api_t api) const;
+
+ enum HandshakeStatus {
+ Handshake_Idle = 0,
+ Handshake_Subscribing,
+ Handshake_Subscribe_Fail,
+ Handshake_WaitEvent,
+ Handshake_Over
+ };
+ static int hs_sts;
+
+private:
+ const std::string sub_event = "windowmanager/handshake";
+ const int m_times;
+ const int m_sleep;
+};
+
+int hs_handshake::hs_sts = hs_handshake::Handshake_Idle;
+
+void handshake_subscribe_callback(struct json_object *obj, const char *error, const char *info)
+{
+ if(error == nullptr) {
+ hs_handshake::hs_sts = hs_handshake::Handshake_WaitEvent;
+ }
+ else {
+ hs_handshake::hs_sts = hs_handshake::Handshake_Subscribe_Fail;
+ }
+}
+
+int on_handshake_event(afb_api_t api, const char *event, struct json_object *object)
+{
+ hs_handshake::hs_sts = hs_handshake::Handshake_Over;
+ return 1;
+}
+
+void hs_handshake::start(afb_api_t api) const
+{
+ setEventHook(sub_event.c_str(), on_handshake_event);
+ int count = 0;
+ do {
+ // try to subscribe handshake event
+ if(hs_handshake::hs_sts == hs_handshake::Handshake_Idle
+ || hs_handshake::hs_sts == hs_handshake::Handshake_Subscribe_Fail) {
+ hs_handshake::hs_sts = Handshake_Subscribing;
+ HS_WmProxy *wm_proxy = new HS_WmProxy();
+ wm_proxy->subscribe(api, HS_WmProxy::Event_Handshake, handshake_subscribe_callback);
+ }
+
+ // wait handshake event
+ if(hs_handshake::hs_sts == hs_handshake::Handshake_Over) {
+ break;
+ }
+
+ ++count;
+ usleep(m_sleep*1000);
+ } while(count < m_times);
+ AFB_WARNING("wait count is %d.", count);
+}
+
struct hs_instance {
- HS_ClientManager *client_manager; // the connection session manager
- HS_AppInfo *app_info; // application info
+ HS_ClientManager *client_manager; // the connection session manager
+ HS_AppInfo *app_info; // application info
- hs_instance() : client_manager(HS_ClientManager::instance()), app_info(HS_AppInfo::instance()) {}
- int init(afb_api_t api);
- void setEventHook(const char *event, const event_hook_func f);
- void onEvent(afb_api_t api, const char *event, struct json_object *object);
+ hs_instance() : client_manager(HS_ClientManager::instance()), app_info(HS_AppInfo::instance()) {}
+ int init(afb_api_t api);
+ void setEventHook(const char *event, const event_hook_func f);
+ void onEvent(afb_api_t api, const char *event, struct json_object *object);
private:
- std::unordered_map<std::string, std::list<event_hook_func>> event_hook_list;
+ std::unordered_map<std::string, std::list<event_hook_func>> event_hook_list;
};
/**
@@ -77,7 +139,12 @@ int hs_instance::init(afb_api_t api)
return -1;
}
- // handshake
+ // const struct handshake_info *h = hs_config.getHandshakeInfo();
+ // struct hs_handshake handshake(h->times, h->sleep);
+ // handshake.start(api);
+
+ // recover application
+
return 0;
}