[Local]: Lock Sequence from activateSurface to flushDraw
[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 <experimental/optional>
24 #include "windowmanager-client.hpp"
25
26 namespace wm {
27
28 /* using std::experimental::nullopt;
29 using std::experimental::optional; */
30
31 typedef enum Task{
32     TASK_ALLOCATE,
33     TASK_RELEASE
34 }ResourceTask;
35
36 struct WMRequest{
37     explicit WMRequest(std::string appid, std::string role,
38         std::string area, ResourceTask task);
39     virtual ~WMRequest();
40     WMRequest(const WMRequest &obj);
41
42     std::string appid;
43     std::string role;
44     std::string area;
45     Task task;
46     unsigned seq_num;
47     bool allocating;
48     bool end_draw_finished;
49 };
50
51 class  AppList {
52 public:
53     AppList();
54     virtual ~AppList();
55     AppList(const AppList &obj) = delete;
56
57     // Client Database Interface
58     void addClient(const std::string &appid, const std::string &role);
59     void removeClient(const std::string &appid);
60     bool contains(const std::string &appid);
61     std::shared_ptr<WMClient> lookUpClient(const std::string &appid);
62
63     // Request Interface
64     unsigned currentSequenceNumber();
65     unsigned getSequenceNumber(const std::string &appid);
66     unsigned addAllocateRequest(WMRequest req);
67     /* TODO: consider, which is better WMClient or std::string appid?
68     if appid is key to manage resources, it is better to select std::string
69     otherwise WMClient is better, IMO */
70     bool requestFinished();
71     unsigned lookUpAllocatingApp(const std::string &appid);
72     void setEndDrawFinished(unsigned request_seq, const std::string &role);
73     bool endDrawFullfilled(unsigned request_seq);
74     void removeRequest(unsigned request_seq);
75     void setCurrentSequence(unsigned request_seq);
76     bool haveRequest();
77     /* void revertRequestingState();
78     void removeAllRequesting(); */
79
80     //void revertRequestingState();//???
81
82     /* bool queue(int request_num);
83     bool pushTop(int request_num);
84     bool dequeue();
85     void deleteAllElement();
86     void removeElement(int request_num);
87     bool hasElement(int request_num); */
88
89 private:
90     std::vector<WMRequest> req_list;
91     std::unordered_map<std::string, std::shared_ptr<WMClient>> client_list;
92     unsigned current_seq;
93 };
94
95 }
96 #endif // ALLOCATE_LIST_HPP