18
18
**/
19
19
20
20
#include " AVInput.h"
21
+ #include " dsMgr.h"
22
+ #include " hdmiIn.hpp"
23
+ #include " compositeIn.hpp"
24
+
25
+ #include " UtilsJsonRpc.h"
21
26
22
27
#define API_VERSION_NUMBER_MAJOR 1
23
28
#define API_VERSION_NUMBER_MINOR 7
24
29
#define API_VERSION_NUMBER_PATCH 1
25
30
31
+ // <pca>
32
+ // Explicitly implementing getInputDevices method instead of autogenerating via IAVInput.h
33
+ // because it requires optional parameters which are not supported in Thunder 4.x. This can
34
+ // be refactored after migrating to 5.x.
35
+ #define AVINPUT_METHOD_GET_INPUT_DEVICES " getInputDevices"
36
+ #define HDMI 0
37
+ #define COMPOSITE 1
38
+ // </pca>
39
+
26
40
namespace WPEFramework {
27
41
namespace {
28
42
@@ -47,11 +61,13 @@ namespace Plugin {
47
61
, _avInput(nullptr )
48
62
, _avInputNotification(this )
49
63
{
64
+ Register<JsonObject, JsonObject>(_T (AVINPUT_METHOD_GET_INPUT_DEVICES), &AVInput::getInputDevicesWrapper, this );
50
65
SYSLOG (Logging::Startup, (_T (" AVInput Constructor" )));
51
66
}
52
67
53
68
AVInput::~AVInput ()
54
69
{
70
+ Unregister (_T (AVINPUT_METHOD_GET_INPUT_DEVICES));
55
71
SYSLOG (Logging::Shutdown, (string (_T (" AVInput Destructor" ))));
56
72
}
57
73
@@ -147,6 +163,87 @@ namespace Plugin {
147
163
SYSLOG (Logging::Shutdown, (string (_T (" AVInput de-initialised" ))));
148
164
}
149
165
166
+ // <pca>
167
+ JsonArray AVInput::getInputDevices (int iType)
168
+ {
169
+ JsonArray list;
170
+ try
171
+ {
172
+ int num = 0 ;
173
+ if (iType == HDMI) {
174
+ num = device::HdmiInput::getInstance ().getNumberOfInputs ();
175
+ }
176
+ else if (iType == COMPOSITE) {
177
+ num = device::CompositeInput::getInstance ().getNumberOfInputs ();
178
+ }
179
+ if (num > 0 ) {
180
+ int i = 0 ;
181
+ for (i = 0 ; i < num; i++) {
182
+ // Input ID is aleays 0-indexed, continuous number starting 0
183
+ JsonObject hash;
184
+ hash[" id" ] = i;
185
+ std::stringstream locator;
186
+ if (iType == HDMI) {
187
+ locator << " hdmiin://localhost/deviceid/" << i;
188
+ hash[" connected" ] = device::HdmiInput::getInstance ().isPortConnected (i);
189
+ }
190
+ else if (iType == COMPOSITE) {
191
+ locator << " cvbsin://localhost/deviceid/" << i;
192
+ hash[" connected" ] = device::CompositeInput::getInstance ().isPortConnected (i);
193
+ }
194
+ hash[" locator" ] = locator.str ();
195
+ LOGWARN (" AVInputService::getInputDevices id %d, locator=[%s], connected=[%d]" , i, hash[" locator" ].String ().c_str (), hash[" connected" ].Boolean ());
196
+ list.Add (hash);
197
+ }
198
+ }
199
+ }
200
+ catch (const std::exception &e) {
201
+ LOGWARN (" AVInputService::getInputDevices Failed" );
202
+ }
203
+ return list;
204
+ }
205
+
206
+ // <pca>
207
+ int getTypeOfInput (string sType )
208
+ {
209
+ int iType = -1 ;
210
+ if (strcmp (sType .c_str (), " HDMI" ) == 0 )
211
+ iType = HDMI;
212
+ else if (strcmp (sType .c_str (), " COMPOSITE" ) == 0 )
213
+ iType = COMPOSITE;
214
+ else
215
+ throw " Invalide type of INPUT, please specify HDMI/COMPOSITE" ;
216
+ return iType;
217
+ }
218
+ // </pca>
219
+
220
+ uint32_t AVInput::getInputDevicesWrapper (const JsonObject& parameters, JsonObject& response)
221
+ {
222
+ LOGINFOMETHOD ();
223
+
224
+ if (parameters.HasLabel (" typeOfInput" )) {
225
+ string sType = parameters[" typeOfInput" ].String ();
226
+ int iType = 0 ;
227
+ try {
228
+ iType = getTypeOfInput (sType );
229
+ }catch (...) {
230
+ LOGWARN (" Invalid Arguments" );
231
+ returnResponse (false );
232
+ }
233
+ response[" devices" ] = getInputDevices (iType);
234
+ }
235
+ else {
236
+ JsonArray listHdmi = getInputDevices (HDMI);
237
+ JsonArray listComposite = getInputDevices (COMPOSITE);
238
+ for (int i = 0 ; i < listComposite.Length (); i++) {
239
+ listHdmi.Add (listComposite.Get (i));
240
+ }
241
+ response[" devices" ] = listHdmi;
242
+ }
243
+ returnResponse (true );
244
+ }
245
+ // </pca>
246
+
150
247
string AVInput::Information () const
151
248
{
152
249
return (string ());
0 commit comments