35 #include <sys/select.h>
37 #include <sys/types.h>
39 #include <sys/types.h>
40 #include <sys/socket.h>
44 #include "osal/Exception.hpp"
45 #include "ccec/Util.hpp"
46 #include "ccec/Exception.hpp"
47 #include "DriverImpl.hpp"
48 #include "ccec/OpCode.hpp"
54 #include "ccec/driver/hdmi_cec_driver.h"
56 size_t write(
const unsigned char *buf,
size_t len);
58 void DriverImpl::DriverReceiveCallback(
int handle,
void *callbackData,
unsigned char *buf,
int len)
61 frame->append((
unsigned char *)buf, (
size_t)len);
63 CCEC_LOG( LOG_DEBUG,
">>>>>>> >>>>> >>>> >> >> >\r\n");
67 CCEC_LOG(LOG_DEBUG,
"==========================\r\n");
70 static_cast<DriverImpl &
>(Driver::getInstance()).getIncomingQueue(handle).
offer(frame);
73 CCEC_LOG( LOG_EXP,
"Exception during frame offer...discarding\r\n");
75 CCEC_LOG( LOG_DEBUG,
"frame offered\r\n");
78 void DriverImpl::DriverTransmitCallback(
int handle,
void *callbackData,
int result)
80 if (HDMI_CEC_IO_SUCCESS != result) {
81 CCEC_LOG( LOG_DEBUG,
"======== HdmiCecSetTxCallback received. Result: %d\r\n", result);
85 DriverImpl::DriverImpl() : status(CLOSED), nativeHandle(0)
87 CCEC_LOG( LOG_DEBUG,
"Creating DriverImpl done\r\n");
90 DriverImpl::~DriverImpl()
93 if (status != CLOSED) {
102 if (status != CLOSED) {
111 if (err != HDMI_CEC_IO_SUCCESS) {
125 if (status != OPENED) {
138 if (err != HDMI_CEC_IO_SUCCESS) {
149 if (status != OPENED) {
154 CCEC_LOG( LOG_DEBUG,
"DriverImpl::Read()\r\n");
156 bool backToPoll =
false;
168 if (status != OPENED) {
170 while (rQueue.size() > 0) {
171 inFrame = rQueue.poll();
190 const uint8_t *buf = NULL;
193 frame.getBuffer(&buf, &length);
195 if (status != OPENED) {
198 CCEC_LOG( LOG_DEBUG,
"DriverImpl::write to call HdmiCecTxAsync\r\n");
202 CCEC_LOG( LOG_DEBUG,
">>>>>>> >>>>> >>>> >> >> >\r\n");
206 CCEC_LOG(LOG_DEBUG,
"==========================\r\n");
208 CCEC_LOG( LOG_DEBUG,
"DriverImpl:: call HdmiCecTxAsync %x\r\n", err);
210 if (err != HDMI_CEC_IO_SUCCESS) {
216 CCEC_LOG( LOG_DEBUG,
"Send Async Completed\r\n");
226 const uint8_t *buf = NULL;
229 frame.getBuffer(&buf, &length);
232 if (status != OPENED) {
235 int sendResult = HDMI_CEC_IO_SUCCESS;
236 CCEC_LOG( LOG_DEBUG,
"DriverImpl::write to call HdmiCecTx\r\n");
238 int err =
HdmiCecTx(nativeHandle, buf, length, &sendResult);
240 CCEC_LOG( LOG_DEBUG,
">>>>>>> >>>>> >>>> >> >> >\r\n");
244 CCEC_LOG(LOG_DEBUG,
"==========================\r\n");
246 CCEC_LOG( LOG_DEBUG,
"DriverImpl:: call HdmiCecTx DONE %x, result %x\r\n", err, sendResult);
248 if (err != HDMI_CEC_IO_SUCCESS) {
252 if (sendResult != HDMI_CEC_IO_SUCCESS) {
253 if ((sendResult == HDMI_CEC_IO_INVALID_STATE) ||
254 (sendResult == HDMI_CEC_IO_INVALID_ARGUMENT) ||
255 (sendResult == HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE) ||
256 (sendResult == HDMI_CEC_IO_SENT_FAILED) ||
257 (sendResult == HDMI_CEC_IO_GENERAL_ERROR) )
263 if (((frame.at(0) & 0x0F) != 0x0F) && sendResult == HDMI_CEC_IO_SENT_BUT_NOT_ACKD) {
267 else if (((frame.at(0) & 0x0F) == 0x0F) && (length > 1) && ((frame.at(1) & 0xFF) == REPORT_PHYSICAL_ADDRESS ) && (sendResult == HDMI_CEC_IO_SENT_BUT_NOT_ACKD))
274 CCEC_LOG( LOG_DEBUG,
"Send Completed\r\n");
277 int DriverImpl::getLogicalAddress(
int devType)
280 int logicalAddress = 0;
281 CCEC_LOG( LOG_DEBUG,
"DriverImpl::getLogicalAddress called for devType : %d \r\n", devType);
285 CCEC_LOG( LOG_DEBUG,
"DriverImpl::getLogicalAddress got logical Address : %d \r\n", logicalAddress);
286 return logicalAddress;
290 void DriverImpl::getPhysicalAddress(
unsigned int *physicalAddress)
293 CCEC_LOG( LOG_DEBUG,
"DriverImpl::getPhysicalAddress called \r\n");
297 CCEC_LOG( LOG_DEBUG,
"DriverImpl::getPhysicalAddress got physical Address : %x \r\n", *physicalAddress);
303 void DriverImpl::removeLogicalAddress(
const LogicalAddress &source)
307 if (status != OPENED) {
311 logicalAddresses.remove(source);
320 if (status != OPENED) {
326 if (retErr == HDMI_CEC_IO_LOGICALADDRESS_UNAVAILABLE) {
329 else if (retErr == HDMI_CEC_IO_GENERAL_ERROR) {
333 logicalAddresses.push_back(source);
340 bool DriverImpl::isValidLogicalAddress(
const LogicalAddress & source)
const
343 std::list<LogicalAddress>::const_iterator it;
344 for (it = logicalAddresses.begin(); it != logicalAddresses.end(); it++) {
357 uint8_t firstByte = (((from.toInt() & 0x0F) << 4) | (to.toInt() & 0x0F));
358 CCEC_LOG( LOG_DEBUG,
"$$$$$$$$$$$$$$$$$$$$ POST POLL [%s] [%s]$$$$$$$$$$$$$$$$$$$$$\r\n", from.toString().c_str(), to.toString().c_str());
362 frame.append(firstByte);
370 frame->append(firstByte);
378 if (status != OPENED) {