29 #ifndef _TRM_MANAGER_H
30 #define _TRM_MANAGER_H
37 #include "trm/TunerReservation.h"
38 #include "trm/Timer.h"
41 #include "ReservationTimerTask.h"
42 #include "Executors.h"
46 class ReservationAttributes
49 ReservationAttributes(uint32_t clientId) : clientId(clientId) {}
52 uint32_t getClientId(
void) {
56 class PendingRequestProcessor
61 PendingReserveTunerConflicts,
62 PendingCancelRecording,
65 PendingRequestProcessor(
const std::string &uuid) : uuid(uuid) {};
66 virtual bool timeout() = 0;
67 virtual int getType() = 0;
68 std::string getUUID() {
71 virtual ~PendingRequestProcessor() {}
77 class PendingCancelLiveProcessor :
public PendingRequestProcessor
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) {}
84 return PendingCancelLive;
87 CancelLive cancelLiveRequest;
88 ReserveTuner reserveRequest;
92 class PendingReserveTunerConflictProcessor:
public PendingRequestProcessor
95 PendingReserveTunerConflictProcessor(
const std::string &uuid, uint32_t clientId,
const NotifyTunerReservationConflicts ¬ification,
const ReserveTuner &request,
const std::string &parentId)
96 : PendingRequestProcessor(uuid), clientId(clientId), notification(notification),request(request), parentId(parentId) {}
99 return PendingReserveTunerConflicts;
102 NotifyTunerReservationConflicts notification;
103 ReserveTuner request;
104 std::string parentId;
108 class PendingCancelRecordingProcessor:
public PendingRequestProcessor
111 PendingCancelRecordingProcessor(uint32_t clientId,
const CancelRecording & request)
112 : PendingRequestProcessor(request.getUUID()), clientId(clientId) , request(request){}
115 return PendingCancelRecording;
119 CancelRecording request;
123 class Manager :
public QObject
128 friend class PendingCancelLiveProcessor;
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;
138 typedef std::map<std::string, ReservationAttributes > ReservationAttributesCT;
140 static Manager &getInstance();
141 static const int kNumOfTuners = NUM_OF_TUNERS;
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);
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);
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);
166 std::string getLocalTuner();
167 void setLocalTuner(
const std::string &tunerId);
168 void adjustExpireTimer(
const std::string &reservationToken);
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);
179 ExpireTimerCT expireTimers;
180 StartTimerCT startTimers;
181 PreStartTimerCT preStartTimers;
182 PedingRequestTimerCT pendingRequestTimers;
184 ReservationAttributesCT attrs;
186 std::list<PendingRequestProcessor *> pendingRequests;
187 std::string localTuner;
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 *);
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 *);