RDK Documentation (Open Sourced RDK Components)
JsonDecoder.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 * @defgroup trm
23 * @{
24 * @defgroup common
25 * @{
26 **/
27 
28 
29 #include "trm/Klass.h"
30 #include "trm/JsonDecoder.h"
31 #include "Util.h"
32 
33 TRM_BEGIN_NAMESPACE
34 
35 
36 void JsonDecoder::decode(std::vector<uint8_t> &in)
37 {
38  Log() << "Decoding " << in.size() << " bytes" << std::endl;
39  Enum<Klass> klass(Klass::kUnknown);
40 
41  //@TODO: JsonDecode(in, klass) may err for malformed json message.
42  int handle = JsonDecode(in, klass);
43 
44  if (handle == 0) return;
45 
46  if (klass == Klass::kReserveTuner) {
47  JsonDecode<ReserveTuner>(handle, processor);
48  }
49  else
50  if (klass == Klass::kReserveTunerResponse) {
51  JsonDecode<ReserveTunerResponse>(handle, processor);
52  }
53  else
54  if (klass == Klass::kReleaseTunerReservation) {
55  JsonDecode<ReleaseTunerReservation>(handle, processor);
56  }
57  else
58  if (klass == Klass::kReleaseTunerReservationResponse) {
59  JsonDecode<ReleaseTunerReservationResponse>(handle, processor);
60  }
61  else
62  if (klass == Klass::kValidateTunerReservation) {
63  JsonDecode<ValidateTunerReservation>(handle, processor);
64  }
65  else
66  if (klass == Klass::kValidateTunerReservationResponse) {
67  JsonDecode<ValidateTunerReservationResponse>(handle, processor);
68  }
69  else
70  if (klass == Klass::kCancelRecording) {
71  JsonDecode<CancelRecording>(handle, processor);
72  }
73  else
74  if (klass == Klass::kCancelRecordingResponse) {
75  JsonDecode<CancelRecordingResponse>(handle, processor);
76  }
77  else
78  if (klass == Klass::kCancelLive) {
79  JsonDecode<CancelLive>(handle, processor);
80  }
81  else
82  if (klass == Klass::kCancelLiveResponse) {
83  JsonDecode<CancelLiveResponse>(handle, processor);
84  }
85  else
86  if (klass == Klass::kGetAllTunerIds) {
87  JsonDecode<GetAllTunerIds>(handle, processor);
88  }
89  else
90  if (klass == Klass::kGetAllTunerIdsResponse) {
91  JsonDecode<GetAllTunerIdsResponse>(handle, processor);
92  }
93  else
94  if (klass == Klass::kGetAllTunerStates) {
95  JsonDecode<GetAllTunerStates>(handle, processor);
96  }
97  else
98  if (klass == Klass::kGetAllTunerStatesResponse) {
99  JsonDecode<GetAllTunerStatesResponse>(handle, processor);
100  }
101  else
102  if (klass == Klass::kGetAllReservations) {
103  JsonDecode<GetAllReservations>(handle, processor);
104  }
105  else
106  if (klass == Klass::kGetAllReservationsResponse) {
107  JsonDecode<GetAllReservationsResponse>(handle, processor);
108  }
109  else
110  if (klass == Klass::kGetAllConnectedDeviceIdsResponse) {
111  JsonDecode<GetAllConnectedDeviceIdsResponse>(handle, processor);
112  }
113  else
114  if (klass == Klass::kGetVersion) {
115  JsonDecode<GetVersion>(handle, processor);
116  }
117  else
118  if (klass == Klass::kGetVersionResponse) {
119  JsonDecode<GetVersionResponse>(handle, processor);
120  }
121  else
122  if (klass == Klass::kNotifyTunerReservationUpdate) {
123  JsonDecode<NotifyTunerReservationUpdate>(handle, processor);
124  }
125  else
126  if (klass == Klass::kNotifyTunerReservationRelease) {
127  JsonDecode<NotifyTunerReservationRelease>(handle, processor);
128  }
129  else
130  if (klass == Klass::kNotifyTunerReservationConflicts) {
131  JsonDecode<NotifyTunerReservationConflicts>(handle, processor);
132  }
133  else
134  if (klass == Klass::kNotifyTunerStatesUpdate) {
135  JsonDecode<NotifyTunerStatesUpdate>(handle, processor);
136  }
137  else
138  if (klass == Klass::kNotifyTunerPretune) {
139  JsonDecode<NotifyTunerPretune>(handle, processor);
140  }
141  else
142  if (klass == Klass::kNotifyClientConnectionEvent) {
143  JsonDecode<NotifyClientConnectionEvent>(handle, processor);
144  }
145  else if (klass == Klass::kGetTRMConnectionEvents) {
146  JsonDecode<GetTRMConnectionEvents>(handle, processor);
147  }
148  else if (klass == Klass::kUpdateTunerActivityStatus) {
149  JsonDecode<UpdateTunerActivityStatus>(handle, processor);
150  }
151 
152  else
153  {
154  SafeAssert(0);
155  }
156 
157 }
158 
159 TRM_END_NAMESPACE
160 
161 
162 /** @} */
163 /** @} */