+/**
+ * handshake event function
+ *
+ * #### Parameters
+ * - api : the api
+ * - event : received event name
+ * - object : received json object
+ *
+ * #### Return
+ * 0 : event can transfer to others
+ * 1 : event not transfer to others
+ */
+int on_handshake_event(afb_api_t api, const char *event, struct json_object *object)
+{
+ AFB_NOTICE("received handshake event from windowmanager.");
+ hs_handshake::hs_sts = hs_handshake::Handshake_Over;
+ return 1;
+}
+
+/**
+ * start handshake function
+ *
+ * #### Parameters
+ * - api : the api
+ *
+ * #### Return
+ * 0 : handshake success
+ * other : handshake fail
+ *
+ */
+int hs_handshake::start(afb_api_t api)
+{
+ AFB_NOTICE("start handshake with windowmanager.");
+ setEventHook(sub_event.c_str(), on_handshake_event);
+
+ std::thread th(&hs_handshake::handshake_loop, this, api, m_times, m_sleep);
+ th.detach();
+ return 0;
+}
+
+/**
+ * handshake loop
+ *
+ * #### Parameters
+ * - api : the api
+ *
+ * #### Return
+ * None
+ *
+ */
+void hs_handshake::handshake_loop(afb_api_t api, int times, int sleeps)
+{
+ 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;
+ 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(sleeps*1000);
+ } while(count < times);
+ AFB_NOTICE("handshake over, m_times=%d, m_sleep=%d, count=%d.", times, sleeps, count);
+ HS_AppRecover::instance()->startRecovery(api);
+}
+
+struct hs_instance {
+ HS_ClientManager *client_manager; // the connection session manager
+ HS_AppInfo *app_info; // application info
+ HS_AppRecover *app_recover; // application recover
+ HS_VuiAdapter * vui_adapter; // vui function adapter
+
+ hs_instance() : client_manager(HS_ClientManager::instance()), app_info(HS_AppInfo::instance()), app_recover(HS_AppRecover::instance()), vui_adapter(HS_VuiAdapter::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);