8c82e7ae13a944b3e52eb32a38e38cd02a62c682
[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     unsigned surface_id;
37     unsigned pid;
38 };
39
40 class AppList
41 {
42   public:
43     AppList();
44     virtual ~AppList();
45     AppList(const AppList &obj) = delete;
46
47     // Client Database Interface
48     /* TODO: consider, which is better WMClient as parameter or not
49        If the WMClient should be more flexible, I think this param should be WMClient class
50     */
51     void addClient(const std::string &appid, unsigned layer,
52                     unsigned surface,const std::string &role);
53     void removeClient(const std::string &appid);
54     bool contains(const std::string &appid) const;
55     int  countClient() const;
56     std::shared_ptr<WMClient> lookUpClient(const std::string &appid);
57     void removeSurface(unsigned surface);
58     std::string getAppID(unsigned surface, const std::string &role, bool *found) const;
59     WMError appendRole(const std::string &appid, const std::string &role, unsigned surface);
60
61     // Floating surface
62     void addFloatingClient(const std::string &appid, unsigned layer, const std::string &role);
63     void addFloatingSurface(unsigned surface, unsigned pid);
64     WMError popFloatingSurface(unsigned pid, unsigned *surface);
65     WMError popFloatingSurface(const std::string &appid, unsigned *surface);
66     void removeFloatingSurface(unsigned surface);
67
68     // Request Interface
69     unsigned currentRequestNumber() const;
70     unsigned getRequestNumber(const std::string &appid) const;
71     unsigned addRequest(WMRequest req);
72     WMError setAction(unsigned req_num, const struct WMAction &action);
73     WMError setAction(unsigned req_num, const std::string &appid,
74                     const std::string &role, const std::string &area, TaskVisible visible);
75     bool setEndDrawFinished(unsigned req_num, const std::string &appid, const std::string &role);
76     bool endDrawFullfilled(unsigned req_num);
77     void removeRequest(unsigned req_num);
78     void next();
79     bool haveRequest() const;
80
81     struct WMTrigger getRequest(unsigned req_num, bool* found);
82     const std::vector<struct WMAction> &getActions(unsigned req_num, bool* found);
83
84     void clientDump();
85     void reqDump();
86     void dumpFloatingSurfaces();
87
88   private:
89     std::vector<WMRequest> req_list;
90     std::unordered_map<std::string, std::shared_ptr<WMClient>> app2client;
91     unsigned current_req;
92     std::mutex mtx;
93     std::vector<struct FloatingSurface> floating_surfaces;
94     //std::vector<FloatingSurface> floating_clients;
95 };
96
97 } // namespace wm
98 #endif // ALLOCATE_LIST_HPP