diff options
-rw-r--r-- | src/homescreen.cpp | 6 | ||||
-rw-r--r-- | src/hs-apprecover.cpp | 58 | ||||
-rw-r--r-- | src/hs-apprecover.h | 4 | ||||
-rw-r--r-- | src/hs-clientmanager.cpp | 7 | ||||
-rw-r--r-- | src/hs-clientmanager.h | 3 |
5 files changed, 65 insertions, 13 deletions
diff --git a/src/homescreen.cpp b/src/homescreen.cpp index cb8a633..2a0ee77 100644 --- a/src/homescreen.cpp +++ b/src/homescreen.cpp @@ -140,8 +140,9 @@ int hs_handshake::start(afb_api_t api) const struct hs_instance { HS_ClientManager *client_manager; // the connection session manager HS_AppInfo *app_info; // application info + HS_AppRecover *app_recover; - hs_instance() : client_manager(HS_ClientManager::instance()), app_info(HS_AppInfo::instance()) {} + hs_instance() : client_manager(HS_ClientManager::instance()), app_info(HS_AppInfo::instance()), app_recover(HS_AppRecover::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); @@ -189,13 +190,12 @@ int hs_instance::init(afb_api_t api) return -1; } - HS_AppRecover *app_recover = new HS_AppRecover(); if(app_recover == nullptr) { AFB_ERROR("app_recover is nullptr."); return -1; } + app_recover->init(api); app_recover->startRecovery(api, hs_config.getRecoverMap()); - client_manager->setAppRecover(app_recover); return 0; } diff --git a/src/hs-apprecover.cpp b/src/hs-apprecover.cpp index 9bd0cf2..ded070e 100644 --- a/src/hs-apprecover.cpp +++ b/src/hs-apprecover.cpp @@ -19,7 +19,63 @@ #include "hs-proxy.h" #include "hs-clientmanager.h" -const char _keyArea[] = "area"; + +HS_AppRecover* HS_AppRecover::me = nullptr; + +/** + * screen_update event handler + * + * #### 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_screen_update_event(afb_api_t api, const char *event, struct json_object *object) +{ + + return 0; +} + +/** + * get instance + * + * #### Parameters + * - Nothing + * + * #### Return + * HS_AppRecover instance pointer + * + */ +HS_AppRecover* HS_AppRecover::instance(void) +{ + if(me == nullptr) + me = new HS_AppRecover(); + + return me; +} + +/** + * HS_AppRecover initialize function + * + * #### Parameters + * - api : the api serving the request + * + * #### Return + * 0 : init success + * 1 : init fail + * + */ +int HS_AppRecover::init(afb_api_t api) +{ + HS_WmProxy wm_proxy; + wm_proxy.subscribe(api, HS_WmProxy::Event_ScreenUpdated); + setEventHook("windowmanager/screenUpdated", on_screen_update_event); + return 0; +} /** * starting recover applications diff --git a/src/hs-apprecover.h b/src/hs-apprecover.h index f46846d..abaf20b 100644 --- a/src/hs-apprecover.h +++ b/src/hs-apprecover.h @@ -35,11 +35,13 @@ public: HS_AppRecover(HS_AppRecover &&) = delete; HS_AppRecover &operator=(HS_AppRecover &&) = delete; + static HS_AppRecover* instance(void); + int init(afb_api_t api); void startRecovery(afb_api_t api, recover_map &map); bool registerRecoveredApp(std::string &appid); private: - + static HS_AppRecover* me; std::map<std::string, struct app_recover_info> m_recover_apps_list; std::set<std::string> m_recovering_set; }; diff --git a/src/hs-clientmanager.cpp b/src/hs-clientmanager.cpp index 4a17b72..83d6bb3 100644 --- a/src/hs-clientmanager.cpp +++ b/src/hs-clientmanager.cpp @@ -37,7 +37,7 @@ static void cbRemoveClientCtxt(void *data) * None * */ -HS_ClientManager::HS_ClientManager() : app_recover(nullptr) +HS_ClientManager::HS_ClientManager() { } @@ -246,8 +246,5 @@ int HS_ClientManager::pushEvent(const char *event, struct json_object *param, st */ void HS_ClientManager::registerApplication(std::string appid) { - if(app_recover != nullptr && app_recover->registerRecoveredApp(appid)) { - delete app_recover; - app_recover = nullptr; - } + }
\ No newline at end of file diff --git a/src/hs-clientmanager.h b/src/hs-clientmanager.h index af5b4c8..cbddaba 100644 --- a/src/hs-clientmanager.h +++ b/src/hs-clientmanager.h @@ -23,7 +23,6 @@ #include <unordered_map> #include "hs-helper.h" #include "hs-client.h" -#include "hs-apprecover.h" typedef struct HS_ClientCtxt { @@ -49,7 +48,6 @@ public: int handleRequest(afb_req_t request, const char *verb, const char *appid = nullptr); int pushEvent(const char *event, struct json_object *param, std::string appid = ""); void removeClientCtxt(void *data); // don't use, internal only - void setAppRecover(HS_AppRecover *recover) {app_recover = recover;} private: HS_ClientCtxt* createClientCtxt(afb_req_t req, std::string appid); @@ -62,7 +60,6 @@ private: std::unordered_map<std::string, HS_Client*> client_list; std::unordered_map<std::string, HS_ClientCtxt*> appid2ctxt; std::mutex mtx; - HS_AppRecover *app_recover; }; #endif // HOMESCREEN_CLIENTMANAGER_H
\ No newline at end of file |