Skip to content

Commit 55a74e8

Browse files
committed
AVInput COM-RPC Support: Moved getInputDevices out of IAVInput
1 parent fd9eb04 commit 55a74e8

File tree

6 files changed

+111
-21
lines changed

6 files changed

+111
-21
lines changed

AVInput/AVInput.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,25 @@
1818
**/
1919

2020
#include "AVInput.h"
21+
#include "dsMgr.h"
22+
#include "hdmiIn.hpp"
23+
#include "compositeIn.hpp"
24+
25+
#include "UtilsJsonRpc.h"
2126

2227
#define API_VERSION_NUMBER_MAJOR 1
2328
#define API_VERSION_NUMBER_MINOR 7
2429
#define API_VERSION_NUMBER_PATCH 1
2530

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+
2640
namespace WPEFramework {
2741
namespace {
2842

@@ -47,11 +61,13 @@ namespace Plugin {
4761
, _avInput(nullptr)
4862
, _avInputNotification(this)
4963
{
64+
Register<JsonObject, JsonObject>(_T(AVINPUT_METHOD_GET_INPUT_DEVICES), &AVInput::getInputDevicesWrapper, this);
5065
SYSLOG(Logging::Startup, (_T("AVInput Constructor")));
5166
}
5267

5368
AVInput::~AVInput()
5469
{
70+
Unregister(_T(AVINPUT_METHOD_GET_INPUT_DEVICES));
5571
SYSLOG(Logging::Shutdown, (string(_T("AVInput Destructor"))));
5672
}
5773

@@ -147,6 +163,87 @@ namespace Plugin {
147163
SYSLOG(Logging::Shutdown, (string(_T("AVInput de-initialised"))));
148164
}
149165

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+
150247
string AVInput::Information() const
151248
{
152249
return (string());

AVInput/AVInput.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#pragma once
2121

2222
#include "Module.h"
23+
2324
#include <core/JSON.h>
2425
#include <interfaces/IAVInput.h>
2526
#include <interfaces/json/JAVInput.h>
@@ -157,6 +158,11 @@ namespace Plugin {
157158

158159
void Deactivated(RPC::IRemoteConnection* connection);
159160

161+
// <pca>
162+
JsonArray getInputDevices(int iType);
163+
uint32_t getInputDevicesWrapper(const JsonObject& parameters, JsonObject& response);
164+
// </pca>
165+
160166
}; // AVInput
161167
} // namespace Plugin
162168
} // namespace WPEFramework

AVInput/AVInputImplementation.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ static int planeType = 0;
3838

3939
using namespace std;
4040

41-
int getTypeOfInput(string sType)
42-
{
43-
int iType = -1;
44-
if (strcmp(sType.c_str(), "HDMI") == 0)
45-
iType = HDMI;
46-
else if (strcmp(sType.c_str(), "COMPOSITE") == 0)
47-
iType = COMPOSITE;
48-
else
49-
throw "Invalide type of INPUT, please specify HDMI/COMPOSITE";
50-
return iType;
51-
}
52-
5341
namespace WPEFramework {
5442
namespace Plugin {
5543
SERVICE_REGISTRATION(AVInputImplementation, 1, 0);

AVInput/AVInputImplementation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ namespace Plugin {
150150
virtual Core::hresult Unregister(Exchange::IAVInput::IHdmiContentTypeUpdateNotification* notification) override;
151151

152152
Core::hresult NumberOfInputs(uint32_t& numberOfInputs, bool& success) override;
153-
Core::hresult GetInputDevices(const int typeOfInput, Exchange::IAVInput::IInputDeviceIterator*& devices, bool& success) override;
153+
Core::hresult GetInputDevices(const int typeOfInput, Exchange::IAVInput::IInputDeviceIterator*& devices, bool& success);
154154
Core::hresult WriteEDID(const int portId, const string& message, SuccessResult& successResult) override;
155155
Core::hresult ReadEDID(const int portId, string& EDID, bool& success) override;
156156
Core::hresult GetRawSPD(const int portId, string& HDMISPD, bool& success) override;

AVInput/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ set_target_properties(${MODULE_NAME} PROPERTIES
4141

4242
target_compile_definitions(${MODULE_NAME} PRIVATE MODULE_NAME=Plugin_${PLUGIN_NAME})
4343

44+
find_package(DS)
45+
find_package(IARMBus)
46+
4447
target_include_directories(${MODULE_NAME} PRIVATE ../helpers)
4548
target_include_directories(${MODULE_NAME} PRIVATE ${DS_INCLUDE_DIRS})
4649
target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS})
@@ -78,15 +81,14 @@ if (RDK_SERVICE_L2_TEST)
7881
endif (TESTMOCKLIB_LIBRARIES)
7982
endif (RDK_SERVICES_L2_TEST)
8083

81-
find_package(DS)
82-
find_package(IARMBus)
83-
8484
target_include_directories(${PLUGIN_IMPLEMENTATION} PRIVATE ${DS_INCLUDE_DIRS})
8585
target_include_directories(${PLUGIN_IMPLEMENTATION} PRIVATE ${IARMBUS_INCLUDE_DIRS})
8686
target_include_directories(${PLUGIN_IMPLEMENTATION} PRIVATE ../helpers)
8787

8888
target_link_libraries(${PLUGIN_IMPLEMENTATION} PUBLIC ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES} ${DS_LIBRARIES} )
8989

90+
target_link_libraries(${MODULE_NAME} PUBLIC ${IARMBUS_LIBRARIES} ${DS_LIBRARIES} )
91+
9092
install(TARGETS ${PLUGIN_IMPLEMENTATION}
9193
DESTINATION lib/${STORAGE_DIRECTORY}/plugins)
9294

Tests/L1Tests/tests/test_AVInput.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,14 @@ TEST_F(AVInputInit, getInputDevices)
363363
TEST_LOG("*** _DEBUG: TEST_F(AVInputInit, getInputDevices): entry");
364364
EXPECT_CALL(*p_hdmiInputImplMock, getNumberOfInputs())
365365
.WillOnce(::testing::Return(1));
366-
TEST_LOG("*** _DEBUG: TEST_F(AVInputInit, getInputDevices): Mark 1");
367366
EXPECT_CALL(*p_compositeInputImplMock, getNumberOfInputs())
368367
.WillOnce(::testing::Return(1));
369-
TEST_LOG("*** _DEBUG: TEST_F(AVInputInit, getInputDevices): Mark 2");
370368
EXPECT_EQ(Core::ERROR_NONE, handler.Invoke(connection, _T("getInputDevices"), _T("{}"), response));
371369
TEST_LOG("*** _DEBUG: TEST_F(AVInputInit, getInputDevices): response=%s", response.c_str());
372370
// <pca>
373-
//EXPECT_EQ(response, string("{\"devices\":[{\"id\":0,\"connected\":false,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\"},{\"id\":0,\"connected\":false,\"locator\":\"cvbsin:\\/\\/localhost\\/deviceid\\/0\"}],\"success\":true}"));
374-
EXPECT_EQ(response, string("{\"devices\":[{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"connected\":false}],\"success\":true}"));
371+
EXPECT_EQ(response, string("{\"devices\":[{\"id\":0,\"connected\":false,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\"},{\"id\":0,\"connected\":false,\"locator\":\"cvbsin:\\/\\/localhost\\/deviceid\\/0\"}],\"success\":true}"));
372+
//EXPECT_EQ(response, string("{\"devices\":[{\"id\":0,\"locator\":\"hdmiin:\\/\\/localhost\\/deviceid\\/0\",\"connected\":false}],\"success\":true}"));
375373
// </pca>
376-
TEST_LOG("*** _DEBUG: TEST_F(AVInputInit, getInputDevices): exit");
377374
}
378375

379376
TEST_F(AVInputInit, getInputDevices_HDMI)

0 commit comments

Comments
 (0)