Skip to content

Commit

Permalink
Merge pull request rdkcentral#99 from rdkcentral/METROL-103/DeviceIde…
Browse files Browse the repository at this point in the history
…ntification

This reverts commit 9d267b9.
  • Loading branch information
scthunderbolt committed Sep 17, 2020
1 parent 8194148 commit 4b9757c
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
12 changes: 11 additions & 1 deletion DeviceIdentification/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
set(PLUGIN_NAME DeviceIdentification)
set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME})

option(PLUGIN_DEVICEIDENTIFICATION_USE_MFR "Get device identification details using MFR library" OFF)

find_package(NEXUS QUIET)
find_package(BCM_HOST QUIET)
find_package(MFRFWLibs QUIET)

find_package(${NAMESPACE}Plugins REQUIRED)
find_package(CompileSettingsDebug CONFIG REQUIRED)
Expand All @@ -29,7 +32,14 @@ add_library(${MODULE_NAME} SHARED
DeviceIdentificationJsonRpc.cpp
Module.cpp)

if(NEXUS_FOUND)
if (PLUGIN_DEVICEIDENTIFICATION_USE_MFR AND MFRFWLIBS_FOUND)
target_sources(${MODULE_NAME}
PRIVATE
Implementation/MFR/MFR.cpp)
target_link_libraries(${MODULE_NAME}
PRIVATE
mfrfwlibs::mfrfwlibs)
elseif (NEXUS_FOUND)
find_package(NXCLIENT REQUIRED)
target_link_libraries(${MODULE_NAME}
PRIVATE
Expand Down
4 changes: 3 additions & 1 deletion DeviceIdentification/DeviceIdentification.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
set (autostart true)
set(PLUGIN_DEVICEIDENTIFICATION_AUTOSTART true CACHE STRING "Automatically start DeviceIdentification plugin")

set (autostart ${PLUGIN_DEVICEIDENTIFICATION_AUTOSTART})
set (preconditions Platform)

map()
Expand Down
125 changes: 125 additions & 0 deletions DeviceIdentification/Implementation/MFR/MFR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:
*
* Copyright 2020 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "../../Module.h"
#include <interfaces/IDeviceIdentification.h>

#include <fstream>

extern "C" {
#include <mfrApi.h>
}

namespace WPEFramework {
namespace Plugin {

class DeviceImplementation : public Exchange::IDeviceProperties, public PluginHost::ISubSystem::IIdentifier {

public:
DeviceImplementation()
{
UpdateChipset(_chipset);
UpdateFirmwareVersion(_firmwareVersion);
UpdateIdentifier();
}

DeviceImplementation(const DeviceImplementation&) = delete;
DeviceImplementation& operator= (const DeviceImplementation&) = delete;
virtual ~DeviceImplementation()
{
/* Nothing to do here. */
}

public:
// Device Propertirs interface
const string Chipset() const override
{
return _chipset;
}
const string FirmwareVersion() const override
{
return _firmwareVersion;
}

// Identifier interface
uint8_t Identifier(const uint8_t length, uint8_t buffer[]) const override
{
uint8_t result = 0;
if ((_identity.length()) && (_status == mfrERR_NONE)) {
result = (_identity.length() > length ? length : _identity.length());
::memcpy(buffer, _identity.c_str(), result);
} else {
SYSLOG(Logging::Notification, (_T("Cannot determine system identity; Error:[%d]!"),
static_cast<uint8_t>(_status)));
}
return result;
}

BEGIN_INTERFACE_MAP(DeviceImplementation)
INTERFACE_ENTRY(Exchange::IDeviceProperties)
INTERFACE_ENTRY(PluginHost::ISubSystem::IIdentifier)
END_INTERFACE_MAP

private:
inline void UpdateFirmwareVersion(string& firmwareVersion) const
{
int retVal = -1;
mfrSerializedData_t mfrSerializedData;
retVal = mfrGetSerializedData(mfrSERIALIZED_TYPE_SOFTWAREVERSION, &mfrSerializedData);
if ((mfrERR_NONE == retVal) && mfrSerializedData.bufLen) {
firmwareVersion = mfrSerializedData.buf;
if (mfrSerializedData.freeBuf) {
mfrSerializedData.freeBuf(mfrSerializedData.buf);
}
}
}
inline void UpdateChipset(string& chipset) const
{
int retVal = -1;
mfrSerializedData_t mfrSerializedData;
retVal = mfrGetSerializedData(mfrSERIALIZED_TYPE_CHIPSETINFO, &mfrSerializedData);
if ((mfrERR_NONE == retVal) && mfrSerializedData.bufLen) {
chipset = mfrSerializedData.buf;
if (mfrSerializedData.freeBuf) {
mfrSerializedData.freeBuf(mfrSerializedData.buf);
}
}
}
inline void UpdateIdentifier()
{
mfrSerializedData_t mfrSerializedData;
_status = mfrGetSerializedData(mfrSERIALIZED_TYPE_SERIALNUMBER, &mfrSerializedData);
if ((mfrERR_NONE == _status) && mfrSerializedData.bufLen) {
_identity = mfrSerializedData.buf;
if (mfrSerializedData.freeBuf) {
mfrSerializedData.freeBuf(mfrSerializedData.buf);
}
}
}

private:
string _chipset;
string _firmwareVersion;
string _identity;
mfrError_t _status;
};

SERVICE_REGISTRATION(DeviceImplementation, 1, 0);
}
}

0 comments on commit 4b9757c

Please sign in to comment.