Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions ccec/src/DriverImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <sys/time.h>
#include <sys/types.h>
#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>

Expand All @@ -46,6 +45,7 @@
#include "ccec/Exception.hpp"
#include "DriverImpl.hpp"
#include "ccec/OpCode.hpp"
#include "factoryImpl/HDMICecHalFactory.h"

using CCEC_OSAL::AutoLock;

Expand All @@ -71,7 +71,6 @@ void DriverImpl::DriverReceiveCallback(int handle, void *callbackData, unsigned
}
catch(...) {
CCEC_LOG( LOG_EXP, "Exception during frame offer...discarding\r\n");
// Copilot fix: Delete frame to prevent memory leak when offer() throws exception
delete frame;
}
CCEC_LOG( LOG_DEBUG, "frame offered\r\n");
Expand All @@ -86,6 +85,7 @@ void DriverImpl::DriverTransmitCallback(int handle, void *callbackData, int resu

DriverImpl::DriverImpl() : status(CLOSED), nativeHandle(0)
{
mHal = HDMICecHalFactory::Create();
CCEC_LOG( LOG_DEBUG, "Creating DriverImpl done\r\n");
Comment on lines 86 to 89
Comment on lines 86 to 89
Comment on lines 86 to 89
}
Comment thread
IshvarKR marked this conversation as resolved.

Expand All @@ -108,6 +108,7 @@ DriverImpl::~DriverImpl()
void DriverImpl::open(void) noexcept(false)
{
{AutoLock lock_(mutex);
CCEC_LOG( LOG_INFO, "DriverImpl::open invoked\r\n");
if (status != CLOSED) {
#if 0
throw InvalidStateException();
Expand All @@ -116,14 +117,17 @@ void DriverImpl::open(void) noexcept(false)
#endif
}

int err = HdmiCecOpen(&nativeHandle);
int err = mHal->open(&nativeHandle);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add NULL check for mHal wherever it is used

CCEC_LOG( LOG_INFO, "DriverImpl::open mHal->open returned %d, handle=%d\r\n", err, nativeHandle);
if (err != HDMI_CEC_IO_SUCCESS) {
throw IOException();
}

HdmiCecSetRxCallback(nativeHandle, DriverReceiveCallback, 0);
HdmiCecSetTxCallback(nativeHandle, DriverTransmitCallback, 0);
mHal->setRxCallback(nativeHandle, DriverReceiveCallback, 0);
mHal->setTxCallback(nativeHandle, DriverTransmitCallback, 0);

status = OPENED;
CCEC_LOG( LOG_INFO, "DriverImpl::open completed successfully\r\n");
}
}

Expand All @@ -143,7 +147,7 @@ void DriverImpl::close(void) noexcept(false)
/* Use NULL as sentinel */
rQueue.offer(0);

int err = HdmiCecClose(nativeHandle);
int err = mHal->close(nativeHandle);
if (err != HDMI_CEC_IO_SUCCESS) {
status = CLOSED;
throw IOException();
Expand Down Expand Up @@ -204,12 +208,13 @@ void DriverImpl::writeAsync(const CECFrame &frame) noexcept(false)
printFrameDetails(frame);

{AutoLock lock_(mutex);
if (status != OPENED) {
if (status != OPENED) {
throw InvalidStateException();
}

CCEC_LOG( LOG_DEBUG, "DriverImpl::write to call HdmiCecTxAsync\r\n");

int err = HdmiCecTxAsync(nativeHandle, buf, length);
int err = mHal->txAsync(nativeHandle, buf, length);

CCEC_LOG( LOG_DEBUG, ">>>>>>> >>>>> >>>> >> >> >\r\n");

Expand All @@ -222,8 +227,7 @@ void DriverImpl::writeAsync(const CECFrame &frame) noexcept(false)
if (err != HDMI_CEC_IO_SUCCESS) {
throw IOException();
}

}
}

CCEC_LOG( LOG_DEBUG, "Send Async Completed\r\n");
}
Comment on lines +230 to 233
Expand All @@ -248,7 +252,7 @@ void DriverImpl::write(const CECFrame &frame) noexcept(false)
int sendResult = HDMI_CEC_IO_SUCCESS;
CCEC_LOG( LOG_DEBUG, "DriverImpl::write to call HdmiCecTx\r\n");

int err = HdmiCecTx(nativeHandle, buf, length, &sendResult);
int err = mHal->tx(nativeHandle, buf, length, &sendResult);

CCEC_LOG( LOG_DEBUG, ">>>>>>> >>>>> >>>> >> >> >\r\n");

Expand All @@ -264,10 +268,10 @@ void DriverImpl::write(const CECFrame &frame) noexcept(false)

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_GENERAL_ERROR) )
(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 @@ -293,7 +297,7 @@ int DriverImpl::getLogicalAddress(int devType)
int logicalAddress = 0;
CCEC_LOG( LOG_DEBUG, "DriverImpl::getLogicalAddress called for devType : %d \r\n", devType);

HdmiCecGetLogicalAddress(nativeHandle, &logicalAddress);
mHal->getLogicalAddress(nativeHandle, devType, &logicalAddress);

CCEC_LOG( LOG_DEBUG, "DriverImpl::getLogicalAddress got logical Address : %d \r\n", logicalAddress);
return logicalAddress;
Expand All @@ -305,7 +309,7 @@ void DriverImpl::getPhysicalAddress(unsigned int *physicalAddress)
{AutoLock lock_(mutex);
CCEC_LOG( LOG_DEBUG, "DriverImpl::getPhysicalAddress called \r\n");

HdmiCecGetPhysicalAddress(nativeHandle,physicalAddress);
mHal->getPhysicalAddress(nativeHandle, physicalAddress);

CCEC_LOG( LOG_DEBUG, "DriverImpl::getPhysicalAddress got physical Address : %x \r\n", *physicalAddress);
return ;
Expand All @@ -315,14 +319,13 @@ void DriverImpl::getPhysicalAddress(unsigned int *physicalAddress)

void DriverImpl::removeLogicalAddress(const LogicalAddress &source)
{
// int LA[15] = {0};
{AutoLock lock_(mutex);
if (status != OPENED) {
throw InvalidStateException();
}

logicalAddresses.remove(source);
HdmiCecRemoveLogicalAddress(nativeHandle, source.toInt());
mHal->removeLogicalAddress(nativeHandle, source.toInt());
}
}

Expand All @@ -334,7 +337,7 @@ bool DriverImpl::addLogicalAddress(const LogicalAddress &source)
throw InvalidStateException();
}

int retErr = HdmiCecAddLogicalAddress(nativeHandle, source.toInt());
int retErr = mHal->addLogicalAddress(nativeHandle, source.toInt());

if (retErr == HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE) {
throw AddressNotAvailableException();
Expand Down
5 changes: 4 additions & 1 deletion ccec/src/DriverImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
#define HDMI_CCEC_DRIVER_IMPL_HPP_

#include <list>

#include <memory>
#include "osal/Mutex.hpp"
#include "osal/EventQueue.hpp"

#include "osal/ConditionVariable.hpp"
#include "ccec/Driver.hpp"
#include "ccec/Header.hpp"
#include "factoryImpl/IHDMICecHal.h"

using CCEC_OSAL::EventQueue;
using CCEC_OSAL::Mutex;
Expand Down Expand Up @@ -87,6 +88,8 @@ class DriverImpl : public Driver
mutable Mutex mutex;
std::list<LogicalAddress> logicalAddresses;

std::unique_ptr<IHDMICecHal> mHal;

DriverImpl(const DriverImpl &); /* Not allowed */
DriverImpl & operator = (const DriverImpl &); /* Not allowed */

Expand Down
44 changes: 41 additions & 3 deletions ccec/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,65 @@ OBJS:= CECFrame.o \
LibCCEC.o \
OpCode.o \
Util.o \
factoryImpl/HDMICecHalFactory.o \
factoryImpl/HDMICecRdkVHAL.o \
factoryImpl/HDMICecAidlHAL.o \
factoryImpl/ServiceManagerCheck.o \

# Calculate AIDL include path relative to workspace
AIDL_GEN_DIR := $(shell cd ../../.. && pwd)/aidl/rdk-halif-aidl/gen/hdmicec/current
AIDL_H_DIR := $(AIDL_GEN_DIR)/h
BINDER_IDL_DIR := $(shell cd ../../.. && pwd)/aidl/rdk-halif-aidl/build-tools/linux_binder_idl
Comment thread
IshvarKR marked this conversation as resolved.
BINDER_INCLUDE := $(BINDER_IDL_DIR)/android/native/libs/binder/include
Comment on lines +38 to +42
BINDER_NDK_INCLUDE := $(BINDER_IDL_DIR)/android/native/libs/binder/ndk/include_cpp
BINDER_UTILS_INCLUDE := $(BINDER_IDL_DIR)/android/core/libutils/include
BINDER_CUTILS_INCLUDE := $(BINDER_IDL_DIR)/android/core/libcutils/include
BINDER_LOG_INCLUDE := $(BINDER_IDL_DIR)/android/logging/liblog/include
BINDER_BASE_INCLUDE := $(BINDER_IDL_DIR)/android/libbase/include
BINDER_BUILD_DIR := $(BINDER_IDL_DIR)/aidl-generator/out
Comment on lines +38 to +48

Comment thread
IshvarKR marked this conversation as resolved.
# Calculate include directory path explicitly
CCEC_INCLUDE_DIR := $(shell cd .. && pwd)/include

Comment on lines +38 to 52
INCLUDE = -I.\
-I../include \
-I$(CCEC_INCLUDE_DIR) \
-I../../osal/include \
Comment thread
IshvarKR marked this conversation as resolved.
-I../drivers/include \
-IfactoryImpl \
-I$(AIDL_H_DIR) \
-I$(BINDER_INCLUDE) \
-I$(BINDER_NDK_INCLUDE) \
-I$(BINDER_UTILS_INCLUDE) \
-I$(BINDER_CUTILS_INCLUDE) \
-I$(BINDER_LOG_INCLUDE) \
-I$(BINDER_BASE_INCLUDE) \
-I$(BINDER_IDL_DIR)/android/native/include \
Comment thread
IshvarKR marked this conversation as resolved.


CFLAGS+= $(INCLUDE)

LDFLAGS+= -L$(OPENSOURCE_BASE)/lib
LDFLAGS+=-L$(GLIB_LIBRARY_PATH)/
LDFLAGS+=$(GLIBS)
LDFLAGS += -L. -lpthread
LDFLAGS += -L. -lpthread -L../../osal/src/install/lib -lRCECOSHal
# Binder libraries - link if they exist
ifneq ($(wildcard $(BINDER_BUILD_DIR)/libbinder.a),)
LDFLAGS += -L$(BINDER_BUILD_DIR) -lbinder
endif
ifneq ($(wildcard $(BINDER_BUILD_DIR)/libutils.a),)
LDFLAGS += -L$(BINDER_BUILD_DIR) -lutils
endif
ifneq ($(wildcard $(BINDER_BUILD_DIR)/liblog.a),)
LDFLAGS += -L$(BINDER_BUILD_DIR) -llog
endif
Comment thread
IshvarKR marked this conversation as resolved.
Comment thread
IshvarKR marked this conversation as resolved.
Comment on lines +74 to +83
Comment on lines +74 to +83

all: clean library
@echo "Build Finished...."

library: $(OBJS)
@echo "Building $(LIBNAMEFULL) ...."
mkdir -p install/lib
$(CXX) $(OBJS) $(CFLAGS) -shared -o install/lib/$(LIBNAMEFULL)
$(CXX) $(OBJS) $(CFLAGS) $(LDFLAGS) -shared -o install/lib/$(LIBNAMEFULL)

%.o: %.cpp
@echo "Building $@ ...."
Expand Down
9 changes: 7 additions & 2 deletions ccec/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lib_LTLIBRARIES = libRCEC.la

AM_LDFLAGS = -ltelemetry_msgsender

# Main RCEC library
libRCEC_la_SOURCES = CECFrame.cpp \
Util.cpp \
DriverImpl.cpp \
Expand All @@ -31,7 +32,11 @@ libRCEC_la_SOURCES = CECFrame.cpp \
OpCode.cpp \
Connection.cpp \
Driver.cpp \
MessageDecoder.cpp
MessageDecoder.cpp \
factoryImpl/HDMICecHalFactory.cpp \
factoryImpl/HDMICecRdkVHAL.cpp \
factoryImpl/HDMICecAidlHAL.cpp \
factoryImpl/ServiceManagerCheck.cpp
Comment thread
vinodtel marked this conversation as resolved.
Comment on lines +35 to +39
Comment on lines +35 to +39
Comment on lines 27 to +39
Comment on lines +36 to +39
Comment on lines +36 to +39

Comment thread
vinodtel marked this conversation as resolved.
libRCEC_la_LDFLAGS = -lpthread
Comment on lines +36 to 41
libRCEC_la_LIBADD = -lRCECOSHal -L${top_builddir}/osal/src/.libs
libRCEC_la_LIBADD = ${top_builddir}/osal/src/libRCECOSHal.la
Comment thread
vinodtel marked this conversation as resolved.
Loading
Loading