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);
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;
}
#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
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;
};
* None
*
*/
-HS_ClientManager::HS_ClientManager() : app_recover(nullptr)
+HS_ClientManager::HS_ClientManager()
{
}
*/
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
#include <unordered_map>
#include "hs-helper.h"
#include "hs-client.h"
-#include "hs-apprecover.h"
typedef struct HS_ClientCtxt
{
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);
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