RDK Documentation (Open Sourced RDK Components)
testTRMDiag.cpp
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 
23 /*C++ include*/
24 #include <errno.h>
25 #include <stdlib.h>
26 #include <map>
27 #include <string>
28 #include <string.h>
29 #include <uuid/uuid.h>
30 #include <list>
31 #include <vector>
32 #include <time.h>
33 #include <sys/time.h>
34 #include <stddef.h>
35 #include <sys/syscall.h>
36 #include <unistd.h>
37 #include <stdint.h>
38 #include <vector>
39 #include <memory>
40 #include <limits>
41 #include <iostream>
42 #include <map>
43 #include <string>
44 
45 /*IARM include*/
46 #include "libIBus.h"
47 
48 
49 /*TRM Manager include*/
50 #include "TRMMgr.h"
51 
52 
53 
54 /* TRM Include*/
55 #include "trm/Messages.h"
56 #include "trm/MessageProcessor.h"
57 #include "trm/Activity.h"
58 #include "trm/JsonEncoder.h"
59 #include "trm/JsonDecoder.h"
60 #include "trm/TRM.h"
61 #include "trm/Klass.h"
62 #include "trm/TunerReservation.h"
63 #include "trm/TunerReservation.h"
64 
65 using namespace TRM;
66 
67 static void getDiagParameter(int type);
68 static void processBuffer( const char* buf, int len);
69 
70 /* Time stamp information */
71 #define __TIMESTAMP() do { /*YYMMDD-HH:MM:SS:usec*/ \
72  struct tm __tm; \
73  struct timeval __tv; \
74  gettimeofday(&__tv, NULL); \
75  localtime_r(&__tv.tv_sec, &__tm); \
76  printf("\r\n[tid=%ld]:TestDiag %02d%02d%02d-%02d:%02d:%02d:%06d ", \
77  syscall(SYS_gettid), \
78  __tm.tm_year+1900-2000, \
79  __tm.tm_mon+1, \
80  __tm.tm_mday, \
81  __tm.tm_hour, \
82  __tm.tm_min, \
83  __tm.tm_sec, \
84  (int)__tv.tv_usec); \
85 } while(0);
86 
87 
88 int main(int argc, char *argv[])
89 {
90 
91  if (argc != 2) {
92  printf("%s : <Type - 0 - TRM Version | 1 - IN BAND TUNER | 2 - Device ID | 3 TUNER_RESERVATION | \r\n 4-CONNECTION_ERRORS | 5-TUNER_CONFLICTS \r\n", argv[0]);
93  return 0;
94  }
95 
96  int type = atoi((const char *)argv[1]);
97 
98  if (type >= TRMMgr_MSG_TYPE_MAX)
99  {
100  printf("%s : <Type - 0 - TRM Version | 1 - IN BAND TUNER | 2 - Device ID | 3 TUNER_RESERVATION | \r\n 4-CONNECTION_ERRORS | 5-TUNER_CONFLICTS \r\n", argv[0]);
101 
102  return 0;
103  }
104 
105  printf("Enter %s():%d \n" , __FUNCTION__, __LINE__);
106 
107  /* Initialization with IARM and Register RPC for the clients */
108  IARM_Bus_Init("getTRMDiagInfo");
110 
111  getDiagParameter(type);
112 
114  IARM_Bus_Term();
115 
116  return 0;
117 }
118 
119 
120 
121 static void getDiagParameter(int type)
122 {
123  TRMDiagInfo_t infoParam;
124 
125  __TIMESTAMP();printf("Enter %s():%d \n" , __FUNCTION__, __LINE__);
126 
127  memset(&infoParam, 0, sizeof(infoParam));
128 
129  switch (type)
130  {
131 
132  case TRMMgr_MSG_TYPE_GET_TRM_VERSION:
133  {
134  __TIMESTAMP();printf("%s : Get Diag Info for GET_TRM_VERSION \r\n",__FUNCTION__);
135 
136  infoParam.retCode = TRMMgr_ERR_UNKNOWN;
137  infoParam.bufLen = 0;
138  infoParam.msgType = TRMMgr_MSG_TYPE_GET_TRM_VERSION;
139 
140  IARM_Bus_Call(IARM_BUS_TRMMGR_NAME,
141  (char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
142  (void *)&infoParam,
143  sizeof(infoParam));
144 
145  if (infoParam.retCode == TRMMgr_ERR_NONE)
146  {
147  __TIMESTAMP();printf("%s() Get Diag Info Return Sucess for GET_TRM_VERSION \r\n",__FUNCTION__);
148  processBuffer(&(infoParam.buf[0]),infoParam.bufLen);
149  }
150 
151  }
152  break;
153 
154 
155  case TRMMgr_MSG_TYPE_GET_NUM_IN_BAND_TUNERS:
156  {
157  __TIMESTAMP();printf("%s : Get Diag Info for GET_NUM_IN_BAND_TUNERS \r\n",__FUNCTION__);
158 
159  infoParam.retCode = TRMMgr_ERR_UNKNOWN;
160  infoParam.bufLen = 0;
161  infoParam.numOfTuner = 0;
162  infoParam.msgType = TRMMgr_MSG_TYPE_GET_NUM_IN_BAND_TUNERS;
163 
164  IARM_Bus_Call(IARM_BUS_TRMMGR_NAME,
165  (char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
166  (void *)&infoParam,
167  sizeof(infoParam));
168 
169  if (infoParam.retCode == TRMMgr_ERR_NONE)
170  {
171  __TIMESTAMP();printf("%s() Get Diag Info Return Sucess for GET_NUM_IN_BAND_TUNERS \r\n",__FUNCTION__);
172  }
173  __TIMESTAMP();printf("%s : Num of Tuner Supported = %d \r\n",__FUNCTION__,infoParam.numOfTuner);
174 
175  }
176  break;
177 
178 
179  case TRMMgr_MSG_TYPE_GET_CONN_DEVICE_IDS:
180  {
181  __TIMESTAMP();printf("%s() Get Diag Info for GET_CONN_DEVICE_IDS \r\n",__FUNCTION__);
182 
183  infoParam.retCode = TRMMgr_ERR_UNKNOWN;
184  infoParam.bufLen = 0;
185  infoParam.msgType = TRMMgr_MSG_TYPE_GET_CONN_DEVICE_IDS;
186 
187  IARM_Bus_Call(IARM_BUS_TRMMGR_NAME,
188  (char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
189  (void *)&infoParam,
190  sizeof(infoParam));
191 
192  if (infoParam.retCode == TRMMgr_ERR_NONE)
193  {
194  __TIMESTAMP();printf("%s() Get Diag Info Return Sucess for GET_CONN_DEVICE_IDS \r\n",__FUNCTION__);
195  processBuffer(&(infoParam.buf[0]),infoParam.bufLen);
196  }
197  }
198  break;
199 
200  case TRMMgr_MSG_TYPE_GET_TUNER_RESERVATION:
201  {
202  __TIMESTAMP();printf("%s : Get Diag Info for GET_TUNER_RESERVATION \r\n",__FUNCTION__);
203 
204  infoParam.retCode = TRMMgr_ERR_UNKNOWN;
205  infoParam.bufLen = 0;
206  infoParam.msgType = TRMMgr_MSG_TYPE_GET_TUNER_RESERVATION;
207 
208  IARM_Bus_Call(IARM_BUS_TRMMGR_NAME,
209  (char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
210  (void *)&infoParam,
211  sizeof(infoParam));
212 
213  if (infoParam.retCode == TRMMgr_ERR_NONE)
214  {
215  __TIMESTAMP();printf("%s() Get Diag Info Return Sucess for GET_TUNER_RESERVATION \r\n",__FUNCTION__);
216  processBuffer(&(infoParam.buf[0]),infoParam.bufLen);
217  }
218 
219 
220  }
221  break;
222 
223  case TRMMgr_MSG_TYPE_GET_NUM_TRM_ERRORS:
224  {
225  __TIMESTAMP();printf("%s : Get Diag Info for GET_NUM_TRM_ERRORS \r\n",__FUNCTION__);
226 
227  infoParam.retCode = TRMMgr_ERR_UNKNOWN;
228  infoParam.bufLen = 0;
229  infoParam.numOfTRMError = 0;
230  infoParam.msgType = TRMMgr_MSG_TYPE_GET_NUM_TRM_ERRORS;
231 
232  IARM_Bus_Call(IARM_BUS_TRMMGR_NAME,
233  (char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
234  (void *)&infoParam,
235  sizeof(infoParam));
236 
237  if (infoParam.retCode == TRMMgr_ERR_NONE)
238  {
239  __TIMESTAMP();printf("%s() Get Diag Info Return Sucess for GET_NUM_TRM_ERRORS \r\n",__FUNCTION__);
240  __TIMESTAMP();printf("%s : Num of TRM Errors = %d \r\n",__FUNCTION__,infoParam.numOfTRMError);
241  }
242 
243  }
244  break;
245 
246 
247  case TRMMgr_MSG_TYPE_GET_CONNECTION_ERRORS:
248  {
249  __TIMESTAMP();printf("%s : Get Diag Info for GET_CONNECTION_ERRORS \r\n",__FUNCTION__);
250 
251  infoParam.retCode = TRMMgr_ERR_UNKNOWN;
252  infoParam.bufLen = 0;
253  infoParam.msgType = TRMMgr_MSG_TYPE_GET_CONNECTION_ERRORS;
254 
255  IARM_Bus_Call(IARM_BUS_TRMMGR_NAME,
256  (char *)IARM_BUS_TRMMGR_API_GetTRMDiagInfo,
257  (void *)&infoParam,
258  sizeof(infoParam));
259 
260  if (infoParam.retCode == TRMMgr_ERR_NONE)
261  {
262  __TIMESTAMP();printf("%s() Get Diag Info Return Sucess for GET_CONNECTION_ERRORS \r\n",__FUNCTION__);
263  processBuffer(&(infoParam.buf[0]),infoParam.bufLen);
264  }
265 
266  }
267  break;
268 
269  case TRMMgr_MSG_TYPE_GET_TUNER_CONFLICTS:
270  {
271  __TIMESTAMP();printf("%s : Get Diag Info for GET_TUNER_CONFLICTS \r\n",__FUNCTION__);
272 
273  }
274  break;
275 
276  default:
277  {
278  __TIMESTAMP();printf("%s Error: Diag Info not supported \r\n",__FUNCTION__);
279  }
280  break;
281  }
282 
283  __TIMESTAMP();printf("Exit %s():%d \n" ,__FUNCTION__,__LINE__);
284 }
285 
286 
287 /**
288  * @brief This function is used to Deocode the parse messafe from TRM Srv
289  */
290 class MsgProcessor : public TRM::MessageProcessor
291 {
292 
293 public :
294  void operator() (const TRM::GetVersionResponse &msg);
295  void operator() (const TRM::GetAllReservationsResponse &msg);
296  void operator() (const TRM::GetAllConnectedDeviceIdsResponse &msg);
297  void operator() (const TRM::GetTRMConnectionEvents &msg);
298 };
299 
300 
301 
302 
303 /**
304  * @brief Version Response Message
305  */
307 {
308 
309  int statusCode = msg.getStatus().getStatusCode();
310  if (TRM::ResponseStatus::kOk == statusCode)
311  {
312  __TIMESTAMP();printf("(GetAllConnectedDeviceIdsResponse) Sucess = %d\r\n",statusCode);
313 
314  const std::list<std::string> & DeviceIds = msg.getDeviceIds();
315  std::list<std::string>::const_iterator it;
316 
317  for (it = DeviceIds.begin(); it != DeviceIds.end(); it++) {
318  __TIMESTAMP();printf("conDeviceIDs = %s \r\n",(*it).c_str());
319  }
320  }
321  else
322  {
323  __TIMESTAMP();printf("(GetAllConnectedDeviceIdsResponse) StatusCode = %d \r\n",statusCode);
324  }
325 
326 }
327 
328 
329 /**
330  * @brief Version Response Message
331  */
333 {
334  int statusCode = msg.getStatus().getStatusCode();
335  if (TRM::ResponseStatus::kOk == statusCode)
336  {
337  __TIMESTAMP();printf("(GetVersionResponse) Sucess = %d \r\n",statusCode);
338  __TIMESTAMP();printf("(TRM Version is ) = %s\r\n",msg.getVersion().c_str());
339  }
340  else
341  {
342  __TIMESTAMP();printf("(GetVersionResponse) StatusCode = %d \r\n",statusCode);
343  }
344 }
345 
346 
347 
348 
349 /**
350  * @brief TRM GetAllReservationsResponse Message
351  */
353 {
354 
355  int statusCode = msg.getStatus().getStatusCode();
356 
357  if (TRM::ResponseStatus::kOk == statusCode)
358  {
359  __TIMESTAMP();printf("(GetAllReservationsResponse) Sucess = %d\r\n",statusCode);
360 
361  const std::map<std::string, std::list<TunerReservation> > & allReservations = msg.getAllReservations();
362  std::map<std::string, std::list<TunerReservation> >::const_iterator it;
363  int tuner = 0;
364  for (it = allReservations.begin(); it != allReservations.end(); it++)
365  {
366  const std::list<TunerReservation> & tunerReservations = it->second;
367  std::list<TunerReservation>::const_iterator it1;
368 
369  __TIMESTAMP();printf("Information for Tuner Reservation %d \r\n",tuner);
370  for (it1 = tunerReservations.begin(); it1 != tunerReservations.end(); it1++)
371  {
372 
373  __TIMESTAMP();printf("Info for Tuner %d \r\n",tuner);
374  __TIMESTAMP();printf("----------------------------------------------------------- \r\n");
375  __TIMESTAMP();printf("reservationToken - %s \r\n",(*it1).getReservationToken().c_str());
376  __TIMESTAMP();printf("device - %s \r\n",(*it1).getDevice().c_str());
377  __TIMESTAMP();printf("serviceLocator - %s \r\n",(*it1).getServiceLocator().c_str());
378  __TIMESTAMP();printf("startTime - %llu \r\n",(*it1).getStartTime());
379  __TIMESTAMP();printf("duration - %llu \r\n",(*it1).getDuration());
380 
381  if ((*it1).getActivity() == Activity::kLive) {
382  __TIMESTAMP();printf("Tuner is reserved for Live \r\n");
383  }
384  else if ((*it1).getActivity() == Activity::kRecord){
385  __TIMESTAMP();printf("Tuner is reserved for Record \r\n");
386 
387  }
388  else if ((*it1).getActivity() == Activity::kEAS){
389  __TIMESTAMP();printf("Tuner is reserved for EAS \r\n");
390 
391  }
392  else if ((*it1).getActivity() == Activity::kNone){
393 
394  __TIMESTAMP();printf("Tuner is reserved for None and Free \r\n");
395  }
396  __TIMESTAMP();printf("----------------------------------------------------------- \r\n");
397  tuner++;
398  }
399  }
400  }
401  else
402  {
403  __TIMESTAMP();printf("(GetAllReservationsResponse) StatusCode = %d \r\n",statusCode);
404  }
405 
406 }
407 
408 
409 
410 /**
411  * @brief Version Response Message
412  */
414 {
415 
416  int statusCode = msg.getStatus().getStatusCode();
417  if (TRM::ResponseStatus::kOk == statusCode)
418  {
419  __TIMESTAMP();printf("(GetTRMConnectionEvents) Sucess = %d\r\n",statusCode);
420 
421  }
422  else
423  {
424  __TIMESTAMP();printf("(GetTRMConnectionEvents) StatusCode = %d \r\n",statusCode);
425  }
426 }
427 
428 
429 /**
430  * @brief This function is used to Deocode the parse messafe from TRM Srv
431  */
432 static void processBuffer( const char* buf, int len)
433 {
434  if (buf != NULL)
435  {
436  __TIMESTAMP();printf("Response %s \r\n", buf);
437  __TIMESTAMP();printf("Response Length %d - %d\r\n", strlen(buf),len);
438 
439  std::vector<uint8_t> response;
440  response.insert( response.begin(), buf, buf+len);
441 
442  MsgProcessor msgProc;
443  TRM::JsonDecoder jdecoder( msgProc);
444  jdecoder.decode( response);
445  }
446 }
447 
_TRMDiagInfo_t
Definition: TRMMgr.h:65
IARM_Bus_Term
IARM_Result_t IARM_Bus_Term(void)
This API is used to terminate the IARM-Bus library.
TRM::MessageProcessor
Definition: MessageProcessor.h:39
IARM_Bus_Call
IARM_Result_t IARM_Bus_Call(const char *ownerName, const char *methodName, void *arg, size_t argLen)
This API is used to Invoke RPC method by its application name and method name.
Definition: iarm_bus.c:57
MsgProcessor
This function is used to Deocode the parse messafe from TRM Srv.
Definition: Helper.cpp:110
TRM::GetAllConnectedDeviceIdsResponse
Definition: Messages.h:2178
IARM_Bus_Disconnect
IARM_Result_t IARM_Bus_Disconnect(void)
This API disconnect Application from IARM Bus so the application will not receive any IARM event or R...
libIBus.h
RDK IARM-Bus API Declarations.
MsgProcessor::operator()
void operator()(const TRM::GetVersionResponse &msg)
Version Response Message.
Definition: Helper.cpp:482
Messages.h
TRM::GetTRMConnectionEvents
Definition: Messages.h:2139
TRM::JsonDecoder
Definition: JsonDecoder.h:73
TRM::GetAllReservationsResponse
Implements the response message for the request to get All tuner reservation details.
Definition: Messages.h:1692
IARM_Bus_Connect
IARM_Result_t IARM_Bus_Connect(void)
This API is used to connect application to the IARM bus daemon. After connected, the application can ...
Definition: iarmMgrMocks.cpp:33
IARM_Bus_Init
IARM_Result_t IARM_Bus_Init(const char *name)
This API is used to initialize the IARM-Bus library.
Definition: iarmMgrMocks.cpp:38
TRM::GetVersionResponse
Implements the response message for the queries that request TRM server version.
Definition: Messages.h:1783