Skip to content
Open
10 changes: 4 additions & 6 deletions ccec/src/Bus.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:

Check failure on line 3 in ccec/src/Bus.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'ccec/src/Bus.cpp' (Match: rdk/components/generic/hdmicec/rdk/components/generic/hdmicec/903ab78, 390 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/hdmicec/+archive/903ab7800e37e8f4895b48adf077127670f25710.tar.gz, file: ccec/src/Bus.cpp)

Check failure on line 3 in ccec/src/Bus.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'ccec/src/Bus.cpp' (Match: rdk/components/generic/hdmicec/rdk/components/generic/hdmicec/2010, 461 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/hdmicec/+archive/rdk-dev-2010.tar.gz, file: ccec/src/Bus.cpp)
*
* Copyright 2016 RDK Management
*
Expand Down Expand Up @@ -70,8 +70,8 @@
Bus::Bus(void) : reader(*this), writer(*this), started(false)
{
CCEC_LOG( LOG_DEBUG, "Bus Instance Created\r\n");
Thread(this->reader).start();
Thread(this->writer).start();
/* Reader and Writer threads start via Bus::start() to prevent 100% CPU on HALs without CEC;
launched from LibCCEC::init() after driver validation. */
CCEC_LOG( LOG_DEBUG, "Bus Instance DONE\r\n");
}

Expand All @@ -93,7 +93,6 @@
Thread(writer).start();
}

Driver::getInstance().open();
started = true;
}

Expand All @@ -116,7 +115,6 @@
writer.stop(true);
}

Driver::getInstance().close();
CCEC_LOG( LOG_INFO, "Bus::stop is called reader isstop :%d writer isstop :%d \r\n",reader.isStopped(),writer.isStopped());
}

Expand Down Expand Up @@ -404,7 +402,7 @@
}

/**
* @brief This function is used to poll the logical address
* @brief This function is used to poll the logical address
* and returns the ACK or NACK received from other devices.
* If NACK then the device can use this logical address.
*
Expand All @@ -431,7 +429,7 @@
}

/**
* @brief This function is used to ping devices, to know whether it present
* @brief This function is used to ping devices, to know whether it present
* and returns the ACK or NACK received from other devices.
* If ACK is received, then the device is present.
*
Expand Down
139 changes: 116 additions & 23 deletions ccec/src/DriverImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:

Check failure on line 3 in ccec/src/DriverImpl.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'ccec/src/DriverImpl.cpp' (Match: rdk/components/generic/hdmicec/rdk/components/generic/hdmicec/2010, 488 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/hdmicec/+archive/rdk-dev-2010.tar.gz, file: ccec/src/DriverImpl.cpp)
*
* Copyright 2016 RDK Management
*
Expand Down Expand Up @@ -117,8 +117,23 @@
}

int err = HdmiCecOpen(&nativeHandle);
if (err != HDMI_CEC_IO_SUCCESS) {
throw IOException();
if (HDMI_CEC_IO_SUCCESS != err) {
CCEC_LOG( LOG_EXP, "DriverImpl::open HdmiCecOpen failed with error %d\r\n", err);
switch (err) {
case HDMI_CEC_IO_INVALID_ARGUMENT:
case HDMI_CEC_IO_INVALID_HANDLE:
throw InvalidParamException();
break;
case HDMI_CEC_IO_ALREADY_OPEN:
throw InvalidStateException();
break;
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
break;
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment on lines +126 to +132
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The break statement after throw InvalidParamException() is unreachable code since the exception will transfer control out of the function. This pattern is repeated throughout all the switch-case error handling blocks in this file. Remove all break statements that appear after throw statements.

Suggested change
break;
case HDMI_CEC_IO_ALREADY_OPEN:
throw InvalidStateException();
break;
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
break;
case HDMI_CEC_IO_ALREADY_OPEN:
throw InvalidStateException();
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();

Copilot uses AI. Check for mistakes.
Comment on lines +126 to +132
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The break statement after throw OperationNotSupportedException() is unreachable. Remove it.

Suggested change
break;
case HDMI_CEC_IO_ALREADY_OPEN:
throw InvalidStateException();
break;
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
break;
case HDMI_CEC_IO_ALREADY_OPEN:
throw InvalidStateException();
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();

Copilot uses AI. Check for mistakes.
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
}
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}

HdmiCecSetRxCallback(nativeHandle, DriverReceiveCallback, 0);
Expand All @@ -145,7 +160,19 @@

int err = HdmiCecClose(nativeHandle);
if (err != HDMI_CEC_IO_SUCCESS) {
throw IOException();
CCEC_LOG( LOG_EXP, "DriverImpl::close HdmiCecClose failed with error %d\r\n", err);
switch (err) {
case HDMI_CEC_IO_INVALID_HANDLE:
throw InvalidParamException();
break;
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The break statement after throw InvalidParamException() is unreachable. Remove it.

Suggested change
break;

Copilot uses AI. Check for mistakes.
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
break;
Comment on lines +169 to +170
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The break statement after throw OperationNotSupportedException() is unreachable. Remove it.

Copilot uses AI. Check for mistakes.
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
break;
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}
}

status = CLOSED;
Expand Down Expand Up @@ -195,7 +222,6 @@
*/
void DriverImpl::writeAsync(const CECFrame &frame) noexcept(false)
{

const uint8_t *buf = NULL;
size_t length = 0;

Expand All @@ -219,7 +245,20 @@
CCEC_LOG( LOG_DEBUG, "DriverImpl:: call HdmiCecTxAsync %x\r\n", err);

if (err != HDMI_CEC_IO_SUCCESS) {
throw IOException();
CCEC_LOG(LOG_EXP, "DriverImpl::write HdmiCecTxAsync failed with error %d\r\n", err);
Comment thread
arun-madhavan-013 marked this conversation as resolved.
switch (err) {
case HDMI_CEC_IO_INVALID_ARGUMENT:
case HDMI_CEC_IO_INVALID_HANDLE:
throw InvalidParamException();
break;
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
break;
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
break;
Comment on lines +253 to +260
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The break statement after throw OperationNotSupportedException() is unreachable. Remove it.

Suggested change
break;
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
break;
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
break;
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();

Copilot uses AI. Check for mistakes.
Comment on lines +253 to +260
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The break statement after throw InvalidParamException() is unreachable. Remove it.

Suggested change
break;
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
break;
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
break;
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();

Copilot uses AI. Check for mistakes.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}
}

}
Expand All @@ -233,7 +272,6 @@
*/
void DriverImpl::write(const CECFrame &frame) noexcept(false)
{

const uint8_t *buf = NULL;
size_t length = 0;

Expand All @@ -258,14 +296,24 @@
CCEC_LOG( LOG_DEBUG, "DriverImpl:: call HdmiCecTx DONE %x, result %x\r\n", err, sendResult);

if (err != HDMI_CEC_IO_SUCCESS) {
throw IOException();
CCEC_LOG(LOG_EXP, "DriverImpl::write HdmiCecTx failed with error %d\r\n", err);
switch (err) {
case HDMI_CEC_IO_INVALID_ARGUMENT:
case HDMI_CEC_IO_INVALID_HANDLE:
throw InvalidParamException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}

if (sendResult != HDMI_CEC_IO_SUCCESS) {
if ((sendResult == HDMI_CEC_IO_INVALID_HANDLE) ||
(sendResult == HDMI_CEC_IO_INVALID_ARGUMENT) ||
(sendResult == HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE) ||
(sendResult == HDMI_CEC_IO_SENT_FAILED) ||
(sendResult == HDMI_CEC_IO_INVALID_ARGUMENT) ||
(sendResult == HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE) ||
(sendResult == HDMI_CEC_IO_SENT_FAILED) ||
(sendResult == HDMI_CEC_IO_GENERAL_ERROR) )
{
throw IOException();
Expand All @@ -278,7 +326,6 @@
/* CEC CTS 9-3-3 -Ensure that the DUT will accept a negatively for broadcat report physical address msg and retry atleast once */
else if (((frame.at(0) & 0x0F) == 0x0F) && (length > 1) && ((frame.at(1) & 0xFF) == REPORT_PHYSICAL_ADDRESS ) && (sendResult == HDMI_CEC_IO_SENT_BUT_NOT_ACKD))
{

throw CECNoAckException();
}
}
Expand All @@ -292,7 +339,20 @@
int logicalAddress = 0;
CCEC_LOG( LOG_DEBUG, "DriverImpl::getLogicalAddress called for devType : %d \r\n", devType);

HdmiCecGetLogicalAddress(nativeHandle, &logicalAddress);
int err = HdmiCecGetLogicalAddress(nativeHandle, &logicalAddress);
if (err != HDMI_CEC_IO_SUCCESS) {
CCEC_LOG(LOG_EXP, "DriverImpl::getLogicalAddress HdmiCecGetLogicalAddress failed with error %d\r\n", err);
switch (err) {
case HDMI_CEC_IO_INVALID_ARGUMENT:
case HDMI_CEC_IO_INVALID_HANDLE:
throw InvalidParamException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}
}

CCEC_LOG( LOG_DEBUG, "DriverImpl::getLogicalAddress got logical Address : %d \r\n", logicalAddress);
return logicalAddress;
Expand All @@ -304,7 +364,20 @@
{AutoLock lock_(mutex);
CCEC_LOG( LOG_DEBUG, "DriverImpl::getPhysicalAddress called \r\n");

HdmiCecGetPhysicalAddress(nativeHandle,physicalAddress);
int err = HdmiCecGetPhysicalAddress(nativeHandle,physicalAddress);
if (err != HDMI_CEC_IO_SUCCESS) {
CCEC_LOG(LOG_EXP, "DriverImpl::getPhysicalAddress HdmiCecGetPhysicalAddress failed with error %d\r\n", err);
switch (err) {
case HDMI_CEC_IO_INVALID_ARGUMENT:
case HDMI_CEC_IO_INVALID_HANDLE:
throw InvalidParamException();
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}
}
Comment thread
arun-madhavan-013 marked this conversation as resolved.

CCEC_LOG( LOG_DEBUG, "DriverImpl::getPhysicalAddress got physical Address : %x \r\n", *physicalAddress);
return ;
Expand All @@ -321,7 +394,20 @@
}

logicalAddresses.remove(source);
HdmiCecRemoveLogicalAddress(nativeHandle, source.toInt());
int err = HdmiCecRemoveLogicalAddress(nativeHandle, source.toInt());
if (err != HDMI_CEC_IO_SUCCESS) {
CCEC_LOG(LOG_EXP, "DriverImpl::removeLogicalAddress HdmiCecRemoveLogicalAddress failed with error %d\r\n", err);
switch (err) {
case HDMI_CEC_IO_INVALID_ARGUMENT:
case HDMI_CEC_IO_INVALID_HANDLE:
throw InvalidParamException();
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}
}
}

Expand All @@ -334,14 +420,21 @@
}

int retErr = HdmiCecAddLogicalAddress(nativeHandle, source.toInt());

if (retErr == HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE) {
throw AddressNotAvailableException();
}
else if (retErr == HDMI_CEC_IO_GENERAL_ERROR) {
throw IOException();
}
else {
if (retErr != HDMI_CEC_IO_SUCCESS) {
CCEC_LOG(LOG_EXP, "DriverImpl::addLogicalAddress HdmiCecAddLogicalAddress failed with error %d\r\n", retErr);
switch (retErr) {
case HDMI_CEC_IO_INVALID_ARGUMENT:
case HDMI_CEC_IO_INVALID_HANDLE:
throw InvalidParamException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
case HDMI_CEC_IO_OPERATION_NOT_SUPPORTED:
throw OperationNotSupportedException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
case HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE:
throw AddressNotAvailableException();
case HDMI_CEC_IO_GENERAL_ERROR:
default:
throw IOException();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
Comment thread
arun-madhavan-013 marked this conversation as resolved.
}
} else {
logicalAddresses.push_back(source);
}
}
Expand Down Expand Up @@ -374,7 +467,7 @@
frame.append(firstByte);
write(frame);
}

#if 0
{
/* Send a Poll so indicate there is a device present */
Expand Down
19 changes: 16 additions & 3 deletions ccec/src/LibCCEC.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:

Check failure on line 3 in ccec/src/LibCCEC.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'ccec/src/LibCCEC.cpp' (Match: rdk/components/generic/hdmicec/rdk/components/generic/hdmicec/903ab78, 182 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/hdmicec/+archive/903ab7800e37e8f4895b48adf077127670f25710.tar.gz, file: ccec/src/LibCCEC.cpp)

Check failure on line 3 in ccec/src/LibCCEC.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'ccec/src/LibCCEC.cpp' (Match: rdk/components/generic/hdmicec/rdk/components/generic/hdmicec/2010, 203 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/hdmicec/+archive/rdk-dev-2010.tar.gz, file: ccec/src/LibCCEC.cpp)
*
* Copyright 2016 RDK Management
*
Expand Down Expand Up @@ -99,10 +99,23 @@

check_cec_log_status();

/* Add Host-specific Initialization*/
Driver::getInstance().open();
/* Add Host-specific Initialization */
// Do not start the threads in Bus constructor if HAL does not support CEC to prevent 100% CPU usage issue.
// throw exceptions and prevent starting the worker threads if driver open fails.
try {
Driver::getInstance().open();
} catch (OperationNotSupportedException &e) {
Comment thread
arun-madhavan-013 marked this conversation as resolved.
CCEC_LOG( LOG_EXP, "LibCCEC::init Caught OperationNotSupportedException during host-specific initialization: %s\r\n", e.what());
throw;
} catch (Exception &e) {
CCEC_LOG( LOG_EXP, "LibCCEC::init Caught Exception during host-specific initialization: %s\r\n", e.what());
throw;
} catch (...) {
CCEC_LOG( LOG_EXP, "LibCCEC::init Caught Unknown Exception during host-specific initialization\r\n");
throw;
}
Bus::getInstance().start();
Comment thread
arun-madhavan-013 marked this conversation as resolved.
t2_init(const_cast<char*>("hdmicec"));
t2_init(const_cast<char*>("hdmicec"));
initialized = true;
}

Expand Down
4 changes: 2 additions & 2 deletions ccec/src/Util.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* If not stated otherwise in this file or this component's LICENSE file the
* following copyright and licenses apply:

Check failure on line 3 in ccec/src/Util.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'ccec/src/Util.cpp' (Match: rdk/components/generic/hdmicec/rdk/components/generic/hdmicec/903ab78, 145 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/hdmicec/+archive/903ab7800e37e8f4895b48adf077127670f25710.tar.gz, file: ccec/src/Util.cpp)
*
* Copyright 2016 RDK Management
*
Expand Down Expand Up @@ -81,7 +81,7 @@
memset(&st,0,sizeof(st));
if((fp = fopen("/tmp/cec_log_enabled","r")) == NULL)
{
printf("Error in opening cec_log_enabled filee \n");
printf("Error in opening cec_log_enabled file.\n");
return;
}
if ((fgets(cecBuffer,buffer_length,fp)) != NULL)
Expand All @@ -96,7 +96,7 @@
}
}
fclose(fp);

return;
}

Expand Down
Loading