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