23d6b5adcf546bf2b509176d636b6fc79a7932e8
[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 "wm_client.hpp"
24 #include "request.hpp"
25 #include "wm_error.hpp"
26
27 namespace wm
28 {
29
30 /* using std::experimental::nullopt;
31 using std::experimental::optional; */
32
33 struct FloatingSurface
34 {
35     unsigned surface_id;
36     unsigned pid;
37 };
38
39 class AppList
40 {
41   public:
42     AppList();
43     virtual ~AppList() = default;
44     AppList(const AppList &obj);
45
46     // Client Database Interface
47     void addClient(const std::string &appid, const std::string &role);
48     void addClient(const std::string &appid, unsigned layer, unsigned surface, const std::string &role);
49     void removeClient(const std::string &appid);
50     bool contains(const std::string &appid) const;
51     int  countClient() const;
52     std::shared_ptr<WMClient> lookUpClient(const std::string &appid);
53     void removeSurface(unsigned surface);
54     WMError popFloatingSurface(unsigned pid, unsigned *surface);
55     WMError popFloatingSurface(const std::string &appid, unsigned *surface);
56     WMError appendRole(const std::string &appid, const std::string &role, unsigned surface);
57     void addFloatingClient(const std::string &appid, unsigned layer, const std::string &role);
58     void addFloatingSurface(unsigned surface, unsigned pid);
59
60     // Request Interface
61     unsigned
62     currentRequestNumber() const;
63     unsigned getRequestNumber(const std::string &appid) const;
64     unsigned addAllocateRequest(WMRequest req);
65     /* TODO: consider, which is better WMClient or std::string appid?
66     if appid is key to manage resources, it is better to select std::string
67     otherwise WMClient is better, IMO */
68     WMError setAction(unsigned req_num, const struct WMAction &action);
69     WMError setAction(unsigned req_num, const std::string &appid, const std::string &role, const std::string &area, bool visible = true);
70     bool setEndDrawFinished(unsigned req_num, const std::string &appid, const std::string &role);
71     bool endDrawFullfilled(unsigned req_num);
72     void removeRequest(unsigned req_num);
73     void next();
74     bool haveRequest() const;
75
76     struct WMTrigger getRequest(unsigned req_num);
77     const std::vector<struct WMAction> &getActions(unsigned req_num);
78
79     void clientDump();
80     void reqDump();
81
82   private:
83     std::vector<WMRequest> req_list;
84     std::unordered_map<std::string, std::shared_ptr<WMClient>> app2client;
85     unsigned current_req;
86
87     std::vector<struct FloatingSurface> floating_surfaces;
88     //std::vector<FloatingSurface> floating_clients;
89 };
90
91 } // namespace wm
92 #endif // ALLOCATE_LIST_HPP