159d5ab1d07ff9b51d868f6d8cbdf7a1081334f7
[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 class AppList
34 {
35   public:
36     AppList();
37     virtual ~AppList();
38     AppList(const AppList &obj) = delete;
39
40     // Client Database Interface
41     void addClient(const std::string &appid, const std::string &role);
42     void addClient(const std::string &appid, unsigned layer, unsigned surface, const std::string &role);
43     void removeClient(const std::string &appid);
44     bool contains(const std::string &appid) const;
45     int  countClient() const;
46     std::shared_ptr<WMClient> lookUpClient(const std::string &appid);
47     void removeSurface(unsigned surface);
48
49     // Request Interface
50     unsigned currentRequestNumber() const;
51     unsigned getRequestNumber(const std::string &appid) const;
52     unsigned addAllocateRequest(WMRequest req);
53     /* TODO: consider, which is better WMClient or std::string appid?
54     if appid is key to manage resources, it is better to select std::string
55     otherwise WMClient is better, IMO */
56     WMError setAction(unsigned req_num, const struct WMAction &action);
57     WMError setAction(unsigned req_num, const std::string &appid, const std::string &role, const std::string &area, bool visible = true);
58     bool setEndDrawFinished(unsigned req_num, const std::string &appid, const std::string &role);
59     bool endDrawFullfilled(unsigned req_num);
60     void removeRequest(unsigned req_num);
61     void next();
62     bool haveRequest() const;
63
64     struct WMTrigger getRequest(unsigned req_num);
65     const std::vector<struct WMAction> &getActions(unsigned req_num);
66
67     void clientDump();
68     void reqDump();
69
70   private:
71     std::vector<WMRequest> req_list;
72     std::unordered_map<std::string, std::shared_ptr<WMClient>> app2client;
73     unsigned current_req;
74 };
75
76 } // namespace wm
77 #endif // ALLOCATE_LIST_HPP