RDK Documentation (Open Sourced RDK Components)
Manager.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22 * @defgroup trm
23 * @{
24 * @defgroup qtapp
25 * @{
26 **/
27 
28 
29 #ifndef _TRM_MANAGER_H
30 #define _TRM_MANAGER_H
31 
32 #include <limits>
33 
34 #include <QObject>
35 
36 #include "trm/TRM.h"
37 #include "trm/TunerReservation.h"
38 #include "trm/Timer.h"
39 
40 #include "Tuner.h"
41 #include "ReservationTimerTask.h"
42 #include "Executors.h"
43 
44 namespace TRM {
45 
46 class ReservationAttributes
47 {
48 public:
49  ReservationAttributes(uint32_t clientId) : clientId(clientId) {}
50  uint32_t clientId;
51 
52  uint32_t getClientId(void) {
53  return clientId;
54  }
55 };
56 class PendingRequestProcessor
57 {
58 public:
59  enum {
60  PendingCancelLive,
61  PendingReserveTunerConflicts,
62  PendingCancelRecording,
63  };
64 
65  PendingRequestProcessor(const std::string &uuid) : uuid(uuid) {};
66  virtual bool timeout() = 0;
67  virtual int getType() = 0;
68  std::string getUUID() {
69  return uuid;
70  }
71  virtual ~PendingRequestProcessor() {}
72 
73 private:
74  std::string uuid;
75 };
76 
77 class PendingCancelLiveProcessor : public PendingRequestProcessor
78 {
79 public:
80  PendingCancelLiveProcessor(uint32_t clientId, const CancelLive &cancelLiveRequest, const ReserveTuner &reserveRequest, const std::string &parentId) :
81  PendingRequestProcessor(cancelLiveRequest.getUUID()), clientId(clientId), cancelLiveRequest(cancelLiveRequest), reserveRequest(reserveRequest), parentId(parentId) {}
82  bool timeout();
83  int getType() {
84  return PendingCancelLive;
85  }
86  uint32_t clientId;
87  CancelLive cancelLiveRequest;
88  ReserveTuner reserveRequest;
89  std::string parentId;
90 };
91 
92 class PendingReserveTunerConflictProcessor: public PendingRequestProcessor
93 {
94 public:
95  PendingReserveTunerConflictProcessor(const std::string &uuid, uint32_t clientId, const NotifyTunerReservationConflicts &notification, const ReserveTuner &request, const std::string &parentId)
96  : PendingRequestProcessor(uuid), clientId(clientId), notification(notification),request(request), parentId(parentId) {}
97  bool timeout();
98  int getType() {
99  return PendingReserveTunerConflicts;
100  }
101  uint32_t clientId;
102  NotifyTunerReservationConflicts notification;
103  ReserveTuner request;
104  std::string parentId;
105 
106 };
107 
108 class PendingCancelRecordingProcessor: public PendingRequestProcessor
109 {
110 public:
111  PendingCancelRecordingProcessor(uint32_t clientId, const CancelRecording & request)
112  : PendingRequestProcessor(request.getUUID()), clientId(clientId) , request(request){}
113  bool timeout();
114  int getType() {
115  return PendingCancelRecording;
116  }
117 
118  uint32_t clientId;
119  CancelRecording request;
120 };
121 
122 
123 class Manager : public QObject
124 {
125  Q_OBJECT
126 public:
127  friend class ReservationExpirationTimerTask;
128  friend class PendingCancelLiveProcessor;
129  friend void Execute(Executor<CancelLiveResponse> &exec);
130 ;
131 
132  typedef std::map<std::string, Tuner > TunerCT;
133  typedef std::map<std::string, ReservationExpirationTimerTask > ExpireTimerCT;
134  typedef std::map<std::string, ReservationStartTimerTask > StartTimerCT;
135  typedef std::map<std::string, ReservationPreStartTimerTask > PreStartTimerCT;
136  typedef std::map<std::string, PendingRequestTimeoutTimerTask > PedingRequestTimerCT;
137 
138  typedef std::map<std::string, ReservationAttributes > ReservationAttributesCT;
139 
140  static Manager &getInstance();
141  static const int kNumOfTuners = NUM_OF_TUNERS;
142 
143  Tuner::IdList & getTunerIds(Tuner::IdList & tunerIds);
144  Tuner & getTuner(const std::string &tunerId);
145  const std::string & getParent(const std::string &reservationToken);
146  void prepareRecordHandover(const std::string &tunerId, const std::string &reservationToken);
147  void syncHybrid(const std::string &tunerId, const std::string &reservationToken);
148 
149  void addReservation(const TunerReservation & reservation, const std::string &tunerId);
150  void setReservationAttributes(const std::string &token, const ReservationAttributes &attr);
151  ReservationAttributes & getReservationAttributes(const std::string &token);
152  void releaseReservation(const std::string &reservationToken, bool notifyClient = true);
153  TunerReservation::TokenList & getReservationTokens(TunerReservation::TokenList &tokens, uint32_t clientId);
154  TunerReservation::TokenList & getReservationTokens(TunerReservation::TokenList &tokens, const std::string tunerId);
155  TunerReservation::TokenList & getReservationTokens(TunerReservation::TokenList &tokens, const Tuner::IdList & tunerIds);
156  TunerReservation & getReservation(const std::string &reservationToken);
157 
158  void addPendingRequest(PendingRequestProcessor *, int timeout);
159  bool isPendingConflict(const std::string &reservationToken);
160  bool isPendingRequest (const std::string &reservationToken);
161  PendingRequestProcessor & getPendingRequest (const std::string &reservationToken);
162  void removePendingRequest(const std::string &reservationToken);
163  NotifyTunerStatesUpdate getTunerStatesUpdate(void);
164  void startReservation(const std::string &reservationToken);
165 
166  std::string getLocalTuner();
167  void setLocalTuner(const std::string &tunerId);
168  void adjustExpireTimer(const std::string &reservationToken);
169 
170 private:
171  Manager(void);
172  void setTimer(const TunerReservation & reservation);
173  void cancelPreStartTimer(const std::string &reservationToken);
174  void cancelStartTimer(const std::string &reservationToken);
175  void cancelExpireTimer(const std::string &reservationToken);
176  void cancelPendingTimer(const std::string &reservationToken);
177 
178  TunerCT tuners;
179  ExpireTimerCT expireTimers;
180  StartTimerCT startTimers;
181  PreStartTimerCT preStartTimers;
182  PedingRequestTimerCT pendingRequestTimers;
183 
184  ReservationAttributesCT attrs;
185  //Single listener is enough for current usage.
186  std::list<PendingRequestProcessor *> pendingRequests;
187  std::string localTuner;
188 
189 signals:
190  void reservationStarted(uint32_t);
191  void reservationReleased(uint32_t, Activity, std::string, std::string);
192  void reservationUpdated(void);
193  void notifyTunerStatesUpdate(NotifyTunerStatesUpdate);
194  void cancelLiveResponse(CancelLiveResponse, ReserveTuner, const std::string);
195  void timerDeleted(void *);
196 
197 public slots:
198  void onReservationReleased(uint32_t, Activity, std::string, std::string);
199  void onCancelLiveResponse(CancelLiveResponse, ReserveTuner, const std::string);
200  void onNotifyTunerStatesUpdate(NotifyTunerStatesUpdate);
201  void onReservationUpdated(void);
202  void onTimerDeleted(void *);
203 
204 };
205 
206 TRM_END_NAMESPACE
207 
208 #endif
209 
210 
211 /** @} */
212 /** @} */
ReservationExpirationTimerTask
Definition: ReservationTimerTask.h:37
Executor
Definition: Executors.h:44
Tuner
Definition: Tuner.h:43