RDK Documentation (Open Sourced RDK Components)
Header.h
Go to the documentation of this file.
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  * @file Header.h
22  *
23  * @defgroup TRM_MAIN Tuner Reservation Manager (TRM)
24  * Tuner Reservation Manager (TRM) coordinates the usage of tuners on the device for the connected clients on Gateway device and
25  * it is specific to Gateway devices only.
26  * TRM uses messages for communicating between Gateway and Client device to reserve, cancel, status retrieval, etc.
27  *
28  * @image html trm_main.png
29  *
30  * - The Gateway box contains multiple tuners (example, Xg1v3 broadcom box having 6 tuner connected to it)
31  * - The Gateway box connected with the incoming RF signal and it is also connected to client boxes
32  * through the MOCA/Router devices.
33  * - TRM application runs on a gateway device and coordinates the usage of tuners on the device for
34  * its connecting clients based on the types of the request.
35  * - Reserve a tuner for specified usage (Live playback, Record, Hybrid, or EAS), start time, end time and content (locator).
36  * - Detect conflicts with existing tuner reservations and resolve.
37  *
38  * @par How TRM works
39  * Client requests a tuner through URL(http, dvr, live), TRM server receives the request and checks for the valid
40  * reservation and reserves the tuner so that the client is provided with the service requested.
41  * Client also can extend or delete the reservation. It is also possible for a client to request
42  * a list of the active reservations.
43  *
44  * Usually Xg1 boxes have multiple tuners (in Xg1v3 box has 6 tuners (configurable)) & each tuners can have following states:
45  * State | Meaning
46  * ------------| -----------
47  * Free | The Tuner is available for allocation.
48  * Live | Currently tuned to a service and in use for viewing the live TV channel.
49  * Record | Currently tuned to a service and recording a program.
50  * Hybrid | Live view of recording in progress.
51  * EAS | Emergency Alert Service.
52  *
53  * @par TRM Consumer
54  * This diagram depicts the different element interact with TRM.
55  * @image html trm_consumer.png
56  * - The Guide server represent the primary user interface for end user.
57  * - The user agent and the browser agents represents the local application acts as a client to the guide server.
58  * - In case of html 5 application, the Browser/Agent would be web browser.
59  * - The Recorder is an RDK component, it maintain a list of Active, Completed and Schedule of recording.
60  * - The Scheduler is responsible for communicating with TRM for scheduling the recording (start, stop, pause).
61  *
62  * @par TRM Communication and WebSockets
63  * TRM uses WebSockets to communicate with other components. This diagram represent the running state of
64  * the Tuner Reservation Manager(TRM)
65  * @image html trm_websocket1.png
66  * The above diagram depicts that how IP client device sends the request to gateway device for TRM service.
67  * - TRM Server is a process, which starts and listen on a perticular port.
68  * - TRM Server receives the Tuner reservation request from client device through websocket.
69  *
70  * @par TRM Sequence Diagram
71  * @image html trm_sequence.png
72  */
73 
74 /**
75 * @defgroup trm
76 * @{
77 * @defgroup common
78 * @{
79 **/
80 
81 
82 #ifndef TRM_TRANSPORT_HEADER_H_
83 #define TRM_TRANSPORT_HEADER_H_
84 
85 #include <stdint.h>
86 #include <vector>
87 
88 #include "TRM.h"
89 #include "Klass.h"
90 #include "Messages.h"
91 
92 TRM_BEGIN_NAMESPACE
93 
94 class Header
95 {
96 public:
97  static const size_t kHeaderLength = 16;
98 
99  Header(void) {}
100  Header(MessageType type, int connectionId, size_t payloadLength);
101  void serialize(std::vector<uint8_t> &out) const;
102  void deserialize(const std::vector<uint8_t> &in);
103  void setPayloadLength(size_t payloadLength);
104  size_t getPayloadLength(void) const;
105  void setClientId(uint32_t connectionId);
106  uint32_t getClientId(void) const;
107 
108  void print(void) const {
109  printf("payloadLength =0x%0X\r\n", payloadLength);
110  }
111 private:
112  static uint32_t messageIndex;
113  /* Header Fields:
114  * |'T'R'M'S|'t'y'p'e|-'i'd'-|'p'l'e'n|
115  */
116  static const char kProtocol[4];
117  MessageType type;
118  uint32_t clientId;
119  uint32_t payloadLength;
120 
121 public:
122 };
123 
124 TRM_END_NAMESPACE
125 #endif
126 
127 
128 /** @} */
129 /** @} */
TRM::Header
Definition: Header.h:94
Messages.h