RDK Documentation (Open Sourced RDK Components)
TRMMonitor.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_TRM_MONITOR_H
30 #define _TRM_TRM_MONITOR_H
31 
32 #include <QMutex>
33 #include <QWaitCondition>
34 #include <QMap>
35 #include <QQueue>
36 
37 #include "Client.h"
38 #include "trm/TunerReservation.h"
39 #include "trm/JsonEncoder.h"
40 #include "trm/Header.h"
41 #include "trm/MessageProcessor.h"
42 #include "safec_lib.h"
43 
44 namespace TRM {
45 
46 class TRMMonitor : public Client, public MessageProcessor
47 {
48  Q_OBJECT
49 public:
50  TRMMonitor(const QHostAddress &address, quint16 port, uint32_t clientId);
51  virtual ~TRMMonitor();
52  void sendTunerReserve(const QString &device, qint64 startTime, qint64 duration, const QString &locator, const QString &activity, const QString &token);
53  void sendGetAllTunerIds(void);
54  void sendGetAllTunerStates(void);
55  void sendGetAllReservations(void);
56  void sendReleaseTunerReservation(const QString &reservationToken);
57  void sendValidateTunerReservation(const QString &device, const QString &reservationToken);
58  void sendCancelRecording(const QString &device, const QString &reservationToken);
59  void sendCancelRecordingResponse(const QString &uuid, const QString &device, const QString &reservationToken, uint32_t outClientId);
60 
61  template<class MsgT>
62  void send(const MsgT &msg, std::vector<uint8_t> &out, uint32_t outClientId = Connection::kInvalidClientId) {
63  if (connection == 0) {
64  return;
65  }
66  out.clear();
67  out.resize(Header::kHeaderLength, 0);
68  JsonEncoder().encode(msg, out);
69  out.push_back('\0'); //append '\0' so we could print the msg as string
70  std::cout << (const char *)(&out[Header::kHeaderLength]) << "\r\n";
71  out.pop_back(); // Some json parser had issue with extra '\0' byte;
72  //Now send response bytes out to connection.
73  std::vector<uint8_t> headerBytes;
74  if (outClientId == Connection::kInvalidClientId) {
75  outClientId = clientId;
76  }
77  Header header(Request, outClientId, out.size() - Header::kHeaderLength);
78  header.serialize(headerBytes);
79  errno_t safec_rc = memcpy_s(&out[0], out.size(), &headerBytes[0], Header::kHeaderLength);
80  ERR_CHK(safec_rc);
81  }
82 
83  MessageProcessor & getMessageProcessor(uint32_t inClientId) {
84  this->inClientId = inClientId;
85  return *this;
86  }
87 
88  bool hasResponse(void) const { return false; }
89  const std::vector<uint8_t> & getResponse(void) const { throw IllegalArgumentException(); }
90  template<class MsgT>
91  void process(const MsgT &msg) {
92  msg.print();
93  }
94  void operator() (const ReserveTunerResponse &msg);
95  void operator() (const ReleaseTunerReservationResponse &msg);
96  void operator() (const ValidateTunerReservationResponse &msg);
97  void operator() (const CancelRecording &msg);
98  void operator() (const CancelRecordingResponse &msg);
99  void operator() (const GetAllTunerIdsResponse &msg);
100  void operator() (const GetAllTunerStatesResponse &msg);
101  void operator() (const GetAllReservationsResponse &msg);
102  void operator() (const NotifyTunerReservationConflicts &msg);
103  void operator() (const NotifyTunerReservationUpdate &msg);
104  void operator() (const NotifyTunerReservationRelease &msg);
105  void operator() (const NotifyTunerStatesUpdate &msg);
106  void operator() (const NotifyTunerPretune &msg);
107 
108  const std::list<std::string> & getTunerIds(void) const;
109 
110 Q_SIGNALS:
111  void tunerIdsUpdated(std::list<std::string>);
112  void tunerStatesUpdated(std::map<std::string, std::string>);
113  void tunerReservationsUpdated(std::map<std::string, std::list<TunerReservation> >);
114  void statusMessageReceived(std::string);
115  void conflictsReceived(ReserveTunerResponse::ConflictCT);
116 
117 private:
118  QHostAddress hostAddress;
119  quint16 portNumber;
120  uint32_t clientId;
121  uint32_t inClientId;
122  QQueue<QString> pendingRequestIds;
123  std::list<std::string> tunerIds;
124 
125 };
126 
127 }
128 
129 #endif
130 
131 
132 /** @} */
133 /** @} */
TRM::ValidateTunerReservationResponse
Implements the response message payload for Tuner reservation validation requests.
Definition: Messages.h:1118
TRM::CancelRecording
Implements a message to cancel the recording.
Definition: Messages.h:1241
TRM::MessageProcessor
Definition: MessageProcessor.h:39
Header.h
TRM::JsonEncoder
Definition: JsonEncoder.h:72
TRM::TRMMonitor
Definition: TRMMonitor.h:46
TRM::Client
Definition: Client.h:42
TRM::CancelRecordingResponse
Implements payload for a response message against cancel recording request.
Definition: Messages.h:1194
TRM::NotifyTunerPretune
Implements a Notification message when a pre tune has performed.
Definition: Messages.h:2076
TRM::ReleaseTunerReservationResponse
Class implementing the response message payload for releasing Tuner reservation.
Definition: Messages.h:1046
TRM::NotifyTunerReservationConflicts
Class for implementing asynchronous notification from TRM to the owner of a token that a tuner reserv...
Definition: Messages.h:1945
TRM::Header
Definition: Header.h:94
TRM::ReserveTunerResponse
Class implementing the response message to a ReserveTuner request.
Definition: Messages.h:858
TRM::GetAllTunerIdsResponse
Implements the response message payload against a Tuner Id request.
Definition: Messages.h:1378
TRM::GetAllTunerStatesResponse
Implements the response payload against a Get tuner state request.
Definition: Messages.h:1563
TRM::GetAllReservationsResponse
Implements the response message for the request to get All tuner reservation details.
Definition: Messages.h:1692
TRM::NotifyTunerStatesUpdate
Class for implementing an asynchronous Notification from TRM whenever a tuner has changed it state.
Definition: Messages.h:2037
TRM::NotifyTunerReservationUpdate
Implements the asynchronous Notification from TRM whenever a reservation has changed its usage by its...
Definition: Messages.h:1892
TRM::NotifyTunerReservationRelease
Class to implement asynchronous Notification from TRM to the owner of a token that its tuner reservat...
Definition: Messages.h:1845
TRM::IllegalArgumentException
Definition: TRM.h:50