change hs_recoer
[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
23 HS_AppRecover* HS_AppRecover::me = nullptr;
24
25 /**
26  * screen_update event handler
27  *
28  * #### Parameters
29  * - api : the api
30  * - event : received event name
31  * - object : received json object
32  *
33  * #### Return
34  * 0 : event can transfer to others
35  * 1 : event not transfer to others
36  */
37 int on_screen_update_event(afb_api_t api, const char *event, struct json_object *object)
38 {
39
40     return 0;
41 }
42
43 /**
44  * get instance
45  *
46  * #### Parameters
47  *  - Nothing
48  *
49  * #### Return
50  * HS_AppRecover instance pointer
51  *
52  */
53 HS_AppRecover* HS_AppRecover::instance(void)
54 {
55     if(me == nullptr)
56         me = new HS_AppRecover();
57
58     return me;
59 }
60
61 /**
62  * HS_AppRecover initialize function
63  *
64  * #### Parameters
65  *  - api : the api serving the request
66  *
67  * #### Return
68  * 0 : init success
69  * 1 : init fail
70  *
71  */
72 int HS_AppRecover::init(afb_api_t api)
73 {
74     HS_WmProxy wm_proxy;
75     wm_proxy.subscribe(api, HS_WmProxy::Event_ScreenUpdated);
76     setEventHook("windowmanager/screenUpdated", on_screen_update_event);
77     return 0;
78 }
79
80 /**
81  * starting recover applications
82  *
83  * #### Parameters
84  *  - api : the api
85  *  - map : recover app map
86  *
87  * #### Return
88  * None
89  *
90  */
91 void HS_AppRecover::startRecovery(afb_api_t api, recover_map &map)
92 {
93     HS_AfmMainProxy afm_proxy;
94     for(auto &key : HS_Config::keys_recover_type) {
95         for(auto &m : map[key]){
96             struct app_recover_info recover_info;
97             recover_info.recover_type = key;
98             recover_info.visibility = m.visibility;
99             m_recover_apps_list[m.appid] = std::move(recover_info);
100
101             // recover application
102             m_recovering_set.insert(m.appid);
103             afm_proxy.start(api,  HS_AppInfo::instance()->getAppProperty(m.appid, _keyId));
104         }
105     }
106 }
107
108 /**
109  * register started applications
110  *
111  * #### Parameters
112  *  - appid : application id liked "dashboard"
113  *
114  * #### Return
115  * false : not all application recovered
116  * true : all applications recovered
117  */
118 bool HS_AppRecover::registerRecoveredApp(std::string &appid)
119 {
120     auto it = m_recovering_set.find(appid);
121     if(it != m_recovering_set.end()) {
122         m_recovering_set.erase(appid);
123         auto ip = m_recover_apps_list.find(appid);
124         if(ip != m_recover_apps_list.end()
125         && ip->second.visibility) {
126             HS_ClientManager::instance()->pushEvent("showWindow", nullptr, appid);
127         }
128     }
129
130     return m_recovering_set.empty() ? true : false;
131 }