8e5545c45e44dc580a955a94206076802213ff62
[apps/agl-service-homescreen.git] / src / hs-apprecover.cpp
1 /*
2  * Copyright (c) 2019 TOYOTA MOTOR CORPORATION
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "hs-apprecover.h"
18 #include "hs-appinfo.h"
19 #include "hs-proxy.h"
20 #include "hs-clientmanager.h"
21
22 const char _keyArea[] = "area";
23
24 /**
25  * starting recover applications
26  *
27  * #### Parameters
28  *  - api : the api
29  *  - map : recover app map
30  *
31  * #### Return
32  * None
33  *
34  */
35 void HS_AppRecover::startRecovery(afb_api_t api, recover_map &map)
36 {
37     HS_AfmMainProxy afm_proxy;
38     for(auto &key : HS_Config::keys_recover_type) {
39         for(auto &m : map[key]){
40             struct app_recover_info recover_info;
41             recover_info.recover_type = key;
42             recover_info.area = m.area;
43             recover_info.visibility = m.visibility;
44             m_recover_apps_list[m.appid] = std::move(recover_info);
45
46             // recover application
47             m_recovering_set.insert(m.appid);
48             afm_proxy.start(api,  HS_AppInfo::instance()->getAppProperty(m.appid, _keyId));
49         }
50     }
51 }
52
53 /**
54  * register started applications
55  *
56  * #### Parameters
57  *  - appid : application id liked "dashboard"
58  *
59  * #### Return
60  * false : not all application recovered
61  * true : all applications recovered
62  */
63 bool HS_AppRecover::registerRecoveredApp(std::string &appid)
64 {
65     auto it = m_recovering_set.find(appid);
66     if(it != m_recovering_set.end()) {
67         m_recovering_set.erase(appid);
68         auto ip = m_recover_apps_list.find(appid);
69         if(ip != m_recover_apps_list.end()
70         && ip->second.visibility) {
71             // TBD, call setWindowResource
72             struct json_object *push_obj = json_object_new_object();
73             json_object_object_add(push_obj, _keyArea, json_object_new_string(ip->second.area.c_str()));
74             HS_ClientManager::instance()->pushEvent("showWindow", push_obj, appid);
75         }
76     }
77
78     return m_recovering_set.empty() ? true : false;
79 }