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