Start app and get runnables list by homescreen
[apps/agl-service-homescreen.git] / src / hs-appinfo.h
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 #ifndef HOMESCREEN_APPINFO_H
18 #define HOMESCREEN_APPINFO_H
19
20 #include <string>
21 #include <mutex>
22 #include <memory>
23 #include <vector>
24 #include <functional>
25 #include <unordered_map>
26 #include "hs-helper.h"
27 #include "hs-proxy.h"
28
29
30 struct AppDetail {
31     std::string name;
32     std::string id;
33     std::string detail; // detail json_object string
34     bool periphery;
35
36     std::string getProperty(std::string key) const;
37 };
38
39 class HS_AppInfo {
40 public:
41     HS_AppInfo() = default;
42     ~HS_AppInfo();
43     HS_AppInfo(HS_AppInfo const &) = delete;
44     HS_AppInfo &operator=(HS_AppInfo const &) = delete;
45     HS_AppInfo(HS_AppInfo &&) = delete;
46     HS_AppInfo &operator=(HS_AppInfo &&) = delete;
47
48     static HS_AppInfo* instance(void);
49     int init(afb_api_t api);
50     void onEvent(afb_api_t api, const char *event, struct json_object *object);
51
52     void getRunnables(struct json_object **object);
53     std::string getAppProperty(const std::string appid, std::string key) const;
54     std::string checkAppId(const std::string &appid);
55
56 private:
57     void updateAppDetailList(afb_api_t api, struct json_object *object);
58     void createAppDetailList(struct json_object *object);
59     std::string parseAppDetail(struct json_object *object, AppDetail &info) const;
60     void addAppDetail(struct json_object *object);
61     void removeAppDetail(std::string appid);
62     struct json_object* retrieveRunnables(struct json_object *obj_runnables, std::string id);
63     void pushAppListChangedEvent(const char *oper, struct json_object *object);
64     std::string id2appid(const std::string &id) const;
65     bool isPeripheryApp(const char *appid) const;
66
67     // applications can't display on launcher
68     const std::vector<const char*> periphery_app_list {
69         "launcher",
70         "homescreen",
71         "onscreenapp",
72         "restriction"
73     };
74
75     typedef void (HS_AppInfo::*func_handler)(afb_api_t, struct json_object*);
76     const std::unordered_map<std::string, func_handler> concerned_event_list {
77         {"afm-main/application-list-changed",    &HS_AppInfo::updateAppDetailList}
78     };
79
80 private:
81     static HS_AppInfo* me;
82     HS_AfmMainProxy* afmmain = nullptr;
83     std::unordered_map<std::string, std::string> appid2name;
84     std::unordered_map<std::string, std::string> name2appid;
85     std::unordered_map<std::string, AppDetail> app_detail_list;
86     std::mutex mtx;
87 };
88
89 #endif // HOMESCREEN_APPINFO_H