1bc27c6c4abe200bffa3af121c1929155264b4e5
[apps/agl-service-windowmanager.git] / src / applist.hpp
1 /*
2  * Copyright (c) 2017 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 ALLOCATE_LIST_HPP
18 #define ALLOCATE_LIST_HPP
19 #include <vector>
20 #include <string>
21 #include <map>
22 #include <memory>
23 #include <mutex>
24 #include "wm_client.hpp"
25 #include "request.hpp"
26 #include "wm_error.hpp"
27
28 namespace wm
29 {
30
31 /* using std::experimental::nullopt;
32 using std::experimental::optional; */
33
34 struct FloatingSurface
35 {
36     std::string appid;
37     unsigned surface_id;
38     unsigned pid;
39 };
40
41 class AppList
42 {
43   public:
44     AppList();
45     virtual ~AppList();
46     AppList(const AppList &obj) = delete;
47
48     // Client Database Interface
49     /* TODO: consider, which is better WMClient as parameter or not
50        If the WMClient should be more flexible, I think this param should be WMClient class
51     */
52     void addClient(const std::string &appid, unsigned layer,
53                     unsigned surface, const std::string &role);
54     void addClient(const std::string &appid, unsigned layer,
55         const std::string& layer_name, unsigned surface, const std::string &role);
56     void removeClient(const std::string &appid);
57     bool contains(const std::string &appid) const;
58     int  countClient() const;
59     std::shared_ptr<WMClient> lookUpClient(const std::string &appid);
60     void removeSurface(unsigned surface);
61     std::string getAppID(unsigned surface, const std::string &role, bool *found) const;
62     WMError appendRole(const std::string &appid, const std::string &role);
63
64     // Floating surface
65     void addFloatingClient(const std::string &appid, unsigned layer, const std::string &role);
66     void addFloatingSurface(const std::string &appid, unsigned surface, unsigned pid);
67     WMError popFloatingSurface(unsigned pid, unsigned *surface);
68     WMError popFloatingSurface(const std::string &appid, unsigned *surface);
69     void removeFloatingSurface(unsigned surface);
70
71     // Request Interface
72     unsigned currentRequestNumber() const;
73     unsigned getRequestNumber(const std::string &appid) const;
74     unsigned addRequest(WMRequest req);
75     WMError setAction(unsigned req_num, const struct WMAction &action);
76     WMError setAction(unsigned req_num, std::shared_ptr<WMClient> client,
77                     const std::string &role, const std::string &area, TaskVisible visible);
78     bool setEndDrawFinished(unsigned req_num, const std::string &appid, const std::string &role);
79     bool endDrawFullfilled(unsigned req_num);
80     void removeRequest(unsigned req_num);
81     void next();
82     bool haveRequest() const;
83
84     struct WMTrigger getRequest(unsigned req_num, bool* found);
85     const std::vector<struct WMAction> &getActions(unsigned req_num, bool* found);
86
87     void clientDump();
88     void reqDump();
89     void dumpFloatingSurfaces();
90
91   private:
92     std::vector<WMRequest> req_list;
93     std::unordered_map<std::string, std::shared_ptr<WMClient>> app2client;
94     unsigned current_req;
95     std::mutex mtx;
96     std::vector<struct FloatingSurface> floating_surfaces;
97 };
98
99 } // namespace wm
100 #endif // ALLOCATE_LIST_HPP