From 868898485c76ad5b0140e6528ba04c08878ea3ce Mon Sep 17 00:00:00 2001 From: wang_zhiqiang Date: Sun, 28 Apr 2019 10:57:30 +0800 Subject: [PATCH] fix bug Change-Id: I0e8b6f58bb2051a17723d19d93e07820650a03a2 --- src/hs-apprecover.cpp | 10 +++++++--- src/hs-clientmanager.cpp | 11 +++++++++-- src/hs-helper.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/hs-apprecover.cpp b/src/hs-apprecover.cpp index 5ccd039..c2464b1 100644 --- a/src/hs-apprecover.cpp +++ b/src/hs-apprecover.cpp @@ -71,9 +71,9 @@ HS_AppRecover* HS_AppRecover::instance(void) */ int HS_AppRecover::init(afb_api_t api) { + setEventHook("windowmanager/screenUpdated", on_screen_update_event); HS_WmProxy wm_proxy; wm_proxy.subscribe(api, HS_WmProxy::Event_ScreenUpdated); - setEventHook("windowmanager/screenUpdated", on_screen_update_event); return 0; } @@ -102,8 +102,11 @@ void HS_AppRecover::startRecovery(afb_api_t api, recover_map &map) } // recover application - m_recovering_set.insert(m.appid); - afm_proxy.start(api, HS_AppInfo::instance()->getAppProperty(m.appid, _keyId)); + auto it = m_recovering_set.find(m.appid); + if(it == m_recovering_set.end()) { + m_recovering_set.insert(m.appid); + afm_proxy.start(api, HS_AppInfo::instance()->getAppProperty(m.appid, _keyId)); + } } } } @@ -126,6 +129,7 @@ bool HS_AppRecover::registerRecoveredApp(const std::string &appid) return ret; } + AFB_INFO("recover appid=[%s].", appid.c_str()); auto it = m_recovering_set.find(appid); if(it != m_recovering_set.end()) { m_recovering_set.erase(appid); diff --git a/src/hs-clientmanager.cpp b/src/hs-clientmanager.cpp index 89b0ae2..832c64f 100644 --- a/src/hs-clientmanager.cpp +++ b/src/hs-clientmanager.cpp @@ -172,13 +172,15 @@ int HS_ClientManager::handleRequest(afb_req_t request, const char *verb, const c { AFB_INFO("verb=[%s],appid=[%s].", verb, appid); int ret = 0; - std::lock_guard lock(this->mtx); + bool isRegisterApp = false; if(appid == nullptr) { + std::lock_guard lock(this->mtx); for(auto m : client_list) { m.second->handleRequest(request, verb); } } else { + std::lock_guard lock(this->mtx); auto ip = client_list.find(std::string(appid)); if(ip != client_list.end()) { ret = ip->second->handleRequest(request, verb); @@ -188,7 +190,7 @@ int HS_ClientManager::handleRequest(afb_req_t request, const char *verb, const c appid2ctxt[appid] = createClientCtxt(request, appid); HS_Client* client = addClient(request, appid); ret = client->handleRequest(request, "subscribe"); - checkRegisterApp(std::string(appid)); + isRegisterApp = true; } else { AFB_NOTICE("not exist session"); @@ -196,6 +198,9 @@ int HS_ClientManager::handleRequest(afb_req_t request, const char *verb, const c } } } + if(isRegisterApp) { + checkRegisterApp(std::string(appid)); + } return ret; } @@ -214,6 +219,7 @@ int HS_ClientManager::handleRequest(afb_req_t request, const char *verb, const c */ int HS_ClientManager::pushEvent(const char *event, struct json_object *param, std::string appid) { + AFB_INFO("event=[%s], appid=[%s].", event, appid.c_str()); if(event == nullptr) { AFB_WARNING("event name is null."); return -1; @@ -247,6 +253,7 @@ int HS_ClientManager::pushEvent(const char *event, struct json_object *param, st */ void HS_ClientManager::checkRegisterApp(const std::string &appid) { + AFB_INFO("appid=[%s].", appid.c_str()); if(HS_AppRecover::instance()->registerRecoveredApp(appid)) { AFB_NOTICE("register recover application."); return; diff --git a/src/hs-helper.cpp b/src/hs-helper.cpp index 30b53b2..ef7e687 100644 --- a/src/hs-helper.cpp +++ b/src/hs-helper.cpp @@ -337,22 +337,22 @@ int readJsonFile(const char* file, struct json_object **obj) int writeJsonFile(const char* file, struct json_object *obj) { int ret = -1; - FILE *fp = fopen(file, "wb"); + FILE *fp = fopen(file, "w+"); if(fp == nullptr) { AFB_ERROR("open %s failed", file); return ret; } const char *str = json_object_to_json_string(obj); - size_t len = sizeof(str); + size_t len = strlen(str); size_t cnt = fwrite(str, len, 1, fp); - if(cnt == len) { + if(cnt == 1) { ret = 0; fflush(fp); fsync(fileno(fp)); } else { - AFB_WARNING("write to %s failed.", file); + AFB_WARNING("write to %s failed.cnt=%d,len=%d,str=%s", file, cnt, len, str); } fclose(fp); -- 2.16.6