RDK Documentation (Open Sourced RDK Components)
TunerReservation.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  * @defgroup TRM_RESERVATION Tuner Reservation
22  * @ingroup TRM_MAIN
23  * @par Tuner Reservation
24  * The TunerReservation object represents a requested or granted tuner reservation.
25  * The reservation has a validity window that is indicated by startTime and duration.
26  * The requesting device is required to renew a reservation before its validity window disappears.
27  * If it is not renewed, the token will be released by TRM and all messages that follow bearing the
28  * token will be considered as MalformedRequest . For Record reservations, the requested startTime
29  * should be N seconds ahead of the actual recording start time
30  * (or should be left out so that the granted reservation starts at the time when it is granted by TRM),
31  * to give room in case a conflict needs to be resolved.
32  * @n @n
33  * A same reservationToken can be reused if and only if values of {device, activity} are the same.
34  * In the case, the {serviceLocator, startTime, duration} of the reused token can be updated.
35  * This is useful during a channel change, where the TRM client can reuse a same Live tuner reservation by
36  * just updating the serviceLocator of it.
37  * @n @n
38  * A reservation is renewed by requesting tunerRreservation with a same reservationToken.
39  * @n
40  * @code
41  * TunerReservation :=
42  * {
43  * "reservationToken" (optional) : [String] reservationToken,
44  * "device" : [String] device,
45  * "serviceLocator" : [String] sourceLocator,
46  * "startTime" (optional) : [long] startTime,
47  * "duration" (optional) : [long] duration
48  * "activity" : <Activity>
49  * "customAttributes" (optional) : <CustomAttributes>
50  * }
51  * @endcode
52  * @n
53  * - @b token: a unique token generated when a reservation is created.
54  * After a reservation is created, this token is used in all messages to uniquely identify an existing reservation within TRM.
55  * - @b device: the remote device requesting the reservation. For a hot recording, this
56  * should be the receiverId of the originating device.
57  * - @b serviceLocator: locator of the service that the tuner will tune to.
58  * - @b startTime:start time of the reservation in milliseconds from the epoch. If not present in a request message,
59  * this is set to when the reservation is granted or renewed. startTime is always included in a response message.
60  * - @b duration: the reservation period measured from the start in milliseconds.
61  * If not present in a request message, the token is valid for a default duration. duration is always included in a response message.
62  * - @b activity: the granted activity. Granted activity may or may not be the same as the requested.
63  * In the latter case the owner of the reservation will need to comply with the returned activity,
64  * or initiate conflict resolution.
65  * @n
66  * For example, when a client requests Live activity when EAS is in progress,
67  * the returned reservation will have the EAS activity.
68  * - @b customAttributes: a set of attributes assigned by the application.
69  * These attributes are associated with the reservation token for the lifetime of the reservation.
70  *
71  * @par Response Status
72  * All response messages from TRM will provide information regarding the status of the response.
73  * Responses to recognized requests may contain additional information, as described in later sections of this document.
74  * Responses to unrecognized requests will contain only this status data, consisting of a status code
75  * and message signifying the request was unrecognized.
76  * @n @n
77  * @code
78  * ResponseStatus := {
79  * "status" : [String] status,
80  * "statusMessage" [optional] : [String] statusMessage
81  * }
82  * @endcode
83  * @n
84  * Where the fields are defined as follows:
85  * @n @b status: is an enumeration of strings indicating the status of the request.
86  * - @b Ok Request was successful.
87  * - @b GeneralError Request was unsuccessful.
88  * - @b MalFormedRequest Unexpected/Invalid request data.
89  * - @b UnRecognizedRequest Unrecognized request.
90  * - @b InsufficientResource: there is no tuner available.
91  * - @b UserCancellation: Token is released as result of user cancellation.
92  * - @b InvalidToken: Token included in the message is invalid.
93  * - @b InvalidState: Token is in invalid state.
94  * - @b statusMessage: is a string containing additional information about the status.
95  *
96  * @defgroup TRM_RESERVATION_CLASSES Tuner Reservation Classes
97  * @ingroup TRM_RESERVATION
98  * Described the details about Tuner Reservation Specifications.
99  */
100 
101 /**
102 * @defgroup trm
103 * @{
104 * @defgroup common
105 * @{
106 **/
107 
108 
109 #ifndef TRM_TUNER_RESERVATION_H_
110 #define TRM_TUNER_RESERVATION_H_
111 
112 #include <stdint.h>
113 
114 #include <string>
115 #include <iostream>
116 #include <list>
117 
118 #include "TRM.h"
119 #include "Activity.h"
120 #include "Klass.h"
121 
122 namespace TRM {
123 
125 /**
126  * @brief The TunerReservation class is used to set the requested or granted tuner reservation from client.
127  * The reservation has a validity window that is indicated by startTime and duration.
128  * The requesting device is required to renew a reservation before its validity window disappears.
129  * If it is not renewed, the token will be released by TRM and all messages that follow bearing the
130  * token will be considered as MalformedRequest. For Record reservations, the requested startTime should
131  * be N seconds ahead of the actual recording start time (or should be left out so that the granted reservation
132  * starts at the time when it is granted by TRM), to give room in case a conflict needs to be resolved.
133  * @n @n A same reservationToken can be reused if and only if values of {device, activity} are the same.
134  * In the case, the {serviceLocator, startTime, duration} of the reused token can be updated.
135  * This is useful during a channel change, where the TRM client can reuse a same @b Live tuner reservation
136  * by just updating the serviceLocator of it.
137  * @ingroup TRM_RESERVATION_CLASSES
138  */
140 {
141 public:
142  typedef std::list<std::string> TokenList;
143  enum {
144  IDLE = 0,
145  ACTIVE,
146  EXPIRED,
147  };
148 
149  static const char *klassName(void) { return Klass::kTunerReservation; }
150 
151  const std::string & getReservationToken(void) const;
152  const std::string & getDevice(void) const;
153  const std::string & getServiceLocator(void) const;
154  uint64_t getStartTime(void) const;
155  uint64_t getDuration(void) const;
156  const Activity & getActivity(void) const;
157 
158  void setReservationToken(const std::string &token);
159  void setServiceLocator(const std::string &_serviceLocator);
160  void setStartTime(const uint64_t &_startTime);
161  void setDuration(const uint64_t &_duratioin);
162  uint64_t getExpirationTime(void) const;
163  void setActivity(const Activity &activity);
164  void addDetail(const std::string &key, const std::string &value);
167  virtual void print(void) const;
168 
169 
170 public:
172  : reservationToken(""), device(""), serviceLocator(""),
173  startTime(0), duration(0),
174  activity(Activity::kNone),
175  customAttributes(0),state(0) {}; //CID:18524-Initialize state
176 
177  TunerReservationBase(const std::string &device,
178  const std::string &serviceLocator,
179  const uint64_t startTime,
180  const uint64_t duration,
181  const Activity &activity,
182  const std::string &reservationToken = "",
183  ReservationCustomAttributes *customAttributes = 0);
184 
185  virtual ~TunerReservationBase(void);
186 
187 private:
188  std::string reservationToken;
189  std::string device;
190  std::string serviceLocator;
191  //@TODO: should startTime defaults to "Now" and duration to "Infinity"?
192  uint64_t startTime;
193  uint64_t duration;
194  Activity activity;
195  //@TODO: safe copy constructor
196  ReservationCustomAttributes* customAttributes;
197 public:
198  int state;
199 };
200 
202 
203 }
204 #endif
205 
206 
207 /** @} */
208 /** @} */
TRM::TunerReservationBase::setServiceLocator
void setServiceLocator(const std::string &_serviceLocator)
This function is used to set the locator of the service that the tuner will tune to....
Definition: TunerReservation.cpp:155
TRM::TunerReservationBase::getStartTime
uint64_t getStartTime(void) const
This function is used to get the start time of the reservation in milliseconds from the epoch.
Definition: TunerReservation.cpp:105
TRM::TunerReservationBase::print
virtual void print(void) const
This function is used to print the following attributes of tunerReservation token.
Definition: TunerReservation.cpp:270
ReservationCustomAttributes
Definition: ReservationCustomAttributes.h:38
TRM::Activity
The Activity class represents the request or granted usage of a tuner. The activity field in the clas...
Definition: Activity.h:92
TRM::TunerReservationBase::setStartTime
void setStartTime(const uint64_t &_startTime)
This function is used to set the start time of the reservation in milliseconds from the epoch....
Definition: TunerReservation.cpp:169
TRM::TunerReservationBase::setReservationToken
void setReservationToken(const std::string &token)
This function is used to set a unique token generated when a reservation is created....
Definition: TunerReservation.cpp:71
TRM::TunerReservationBase::getDevice
const std::string & getDevice(void) const
This function is used to get the remote device id requesting for tuner reservation.
Definition: TunerReservation.cpp:127
TRM::TunerReservationBase::getCustomAttributes
const ReservationCustomAttributes * getCustomAttributes(void) const
This function is used to return the custom attributes assigned by the application....
Definition: TunerReservation.cpp:234
TRM::TunerReservationBase::setCustomAttributes
void setCustomAttributes(ReservationCustomAttributes *)
This function is used to set the attributes assigned by the application. These attributes are associa...
Definition: TunerReservation.cpp:255
TRM::TunerReservationBase::getExpirationTime
uint64_t getExpirationTime(void) const
This function is used to return remaining tuner reservation time.
Definition: TunerReservation.cpp:195
TRM::TunerReservationBase::getActivity
const Activity & getActivity(void) const
This function is used to return the granted activity. Granted activity may or may not be the same as ...
Definition: TunerReservation.cpp:142
TRM::TunerReservationBase::getServiceLocator
const std::string & getServiceLocator(void) const
This function is used to return the locator of the service that the tuner is tuned to.
Definition: TunerReservation.cpp:94
TRM::TunerReservationBase::getDuration
uint64_t getDuration(void) const
This function is used to get the reservation period measured from the start in milliseconds.
Definition: TunerReservation.cpp:116
TRM::TunerReservationBase::setDuration
void setDuration(const uint64_t &_duratioin)
This function is used to set the reservation duration measured from the start in milliseconds....
Definition: TunerReservation.cpp:183
TRM::TunerReservationBase
The TunerReservation class is used to set the requested or granted tuner reservation from client....
Definition: TunerReservation.h:139
TRM::TunerReservationBase::getReservationToken
const std::string & getReservationToken(void) const
This function is used to return the unique token generated when a reservation is created.
Definition: TunerReservation.cpp:83
TRM::TunerReservationBase::addDetail
void addDetail(const std::string &key, const std::string &value)
This function is used to add the details describing the tuner reservation activity in to the activity...
Definition: TunerReservation.cpp:222