30 #include "trm/JsonEncoder.h"
35 #include "ReservationTimerTask.h"
36 #include "Connection.h"
38 extern void printThread(
const char *func);
43 ReservationExpirationTimerTask::ReservationExpirationTimerTask(
Timer &timer,
const std::string &reservationToken)
44 : timer(timer), reservationToken(reservationToken) {}
46 ReservationExpirationTimerTask::~ReservationExpirationTimerTask(
void) {}
48 void ReservationExpirationTimerTask::run(
void)
50 Log() <<
"Reservation " << reservationToken <<
" Timer "
52 <<
" Expired at " << time(0) << std::endl;
54 TunerReservation &expired = Manager::getInstance().getReservation(reservationToken);
57 Assert(expired.state == TunerReservation::ACTIVE);
58 const ReservationAttributes &attrs = Manager::getInstance().getReservationAttributes(reservationToken);
60 const Connection &connection = ::serverInstance->getConnection(attrs.clientId);
61 NotifyTunerReservationRelease notification(GenerateUUID(), reservationToken,
"expired");
63 std::vector<uint8_t> out;
64 SerializeMessage(notification, attrs.clientId, out);
73 Log() <<
"Reservation released failed: " << std::endl;
75 Log() <<
"Reservation Expired : " << std::endl;
77 expired.state = TunerReservation::EXPIRED;
78 Manager::getInstance().releaseReservation(reservationToken);
81 Timer & ReservationExpirationTimerTask::getTimer(
void)
87 ReservationStartTimerTask::ReservationStartTimerTask(
Timer &timer,
const std::string &reservationToken)
88 : timer(timer), reservationToken(reservationToken) {}
90 ReservationStartTimerTask::~ReservationStartTimerTask(
void) {}
92 void ReservationStartTimerTask::run(
void)
94 Log() <<
"Reservation " << reservationToken <<
" Start Timer "
96 <<
" Started at " << time(0) << std::endl;
98 TunerReservation &started = Manager::getInstance().getReservation(reservationToken);
101 Assert(started.state == TunerReservation::IDLE);
102 printf(
"Starting Reservation %p\r\n", &started);
105 Tuner & tuner = Manager::getInstance().getTuner(Manager::getInstance().getParent(reservationToken));
107 TunerState state = tuner.getState();
108 state = state + started.getActivity().getActivity();
109 tuner.setState(state);
114 started.state = TunerReservation::ACTIVE;
115 Log() <<
"New Tuner State is " << (
const char *) tuner.getState().getState() << std::endl;
118 if (tuner.getState().getState() == TunerState::kHybrid) {
119 Manager::getInstance().syncHybrid(tuner.getId(), reservationToken);
122 Manager::getInstance().startReservation(reservationToken);
123 Manager::getInstance().adjustExpireTimer(reservationToken);
126 Log() <<
"Reservation start failed : " << std::endl;
128 Log() <<
"Reservation started : " << std::endl;
132 Timer & ReservationStartTimerTask::getTimer(
void)
138 ReservationPreStartTimerTask::ReservationPreStartTimerTask(
Timer &timer,
const std::string &reservationToken)
139 : timer(timer), reservationToken(reservationToken) {}
141 ReservationPreStartTimerTask::~ReservationPreStartTimerTask(
void) {}
143 void ReservationPreStartTimerTask::run(
void)
145 Log() <<
"Reservation " << reservationToken <<
" PreStart Timer "
147 <<
" Started at " << time(0) << std::endl;
149 TunerReservation &started = Manager::getInstance().getReservation(reservationToken);
152 Assert(started.state == TunerReservation::IDLE);
153 printf(
"About to start Reservation %p\r\n", &started);
156 Tuner & tuner = Manager::getInstance().getTuner(Manager::getInstance().getParent(reservationToken));
157 Log() <<
"Current Tuner State is " << (
const char *) tuner.getState().getState() << std::endl;
160 if ( (started.getActivity().getActivity() == Activity::kRecord) && (tuner.getState().getState() == TunerState::kHybrid)) {
161 Manager::getInstance().prepareRecordHandover(tuner.getId(), reservationToken);
165 Log() <<
"Reservation start failed : " << std::endl;
167 Log() <<
"Reservation is about to start: " << std::endl;
171 Timer & ReservationPreStartTimerTask::getTimer(
void)
176 PendingRequestTimeoutTimerTask::PendingRequestTimeoutTimerTask(
Timer &timer,
const std::string &uuid)
177 : timer(timer), uuid(uuid) {}
179 PendingRequestTimeoutTimerTask::~PendingRequestTimeoutTimerTask(
void) {}
181 void PendingRequestTimeoutTimerTask::run(
void)
187 PendingRequestProcessor &pending = Manager::getInstance().getPendingRequest(timer.getToken());
189 Log() <<
"PendingRequest [type=" << pending.getType() <<
"] " <<
"uuid=" << pending.getUUID() <<
" "
190 <<
"Timer " << timer.getToken() <<
" timeout" << std::endl;
193 Manager::getInstance().removePendingRequest(pending.getUUID());
200 Timer & PendingRequestTimeoutTimerTask::getTimer(
void)