From: Lars Op den Kamp Date: Wed, 25 Jan 2012 14:14:27 +0000 (+0100) Subject: cec: simplified AddLog() method X-Git-Tag: upstream/2.2.0~1^2~39^2~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5477a250b595adb296ed42a88abab002981f4761;p=deb_libcec.git cec: simplified AddLog() method --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 0c409eb..7a4e019 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -134,32 +134,30 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint CLockObject lock(m_mutex); if (!m_communication) { - m_controller->AddLog(CEC_LOG_ERROR, "no connection handler found"); + CLibCEC::AddLog(CEC_LOG_ERROR, "no connection handler found"); return bReturn; } /* check for an already opened connection */ if (m_communication->IsOpen()) { - m_controller->AddLog(CEC_LOG_ERROR, "connection already opened"); + CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened"); return bReturn; } /* open a new connection */ if ((bReturn = m_communication->Open(strPort, iBaudRate, iTimeoutMs)) == false) - m_controller->AddLog(CEC_LOG_ERROR, "could not open a connection"); + CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection"); /* try to ping the adapter */ if ((bReturn = m_communication->PingAdapter()) == false) - m_controller->AddLog(CEC_LOG_ERROR, "the adapter does not respond correctly"); + CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter does not respond correctly"); uint16_t iFirmwareVersion = m_communication->GetFirmwareVersion(); if ((bReturn = (iFirmwareVersion != CEC_FW_VERSION_UNKNOWN)) == false) m_controller->AddLog(CEC_LOG_ERROR, "the adapter is running an unknown firmware version"); - CStdString strLog; - strLog.Format("CEC Adapter firmware version: %d", iFirmwareVersion); - m_controller->AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "CEC Adapter firmware version: %d", iFirmwareVersion); return bReturn; } @@ -180,7 +178,7 @@ bool CCECProcessor::Initialise(void) if (!FindLogicalAddresses()) { - m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses"); + CLibCEC::AddLog(CEC_LOG_ERROR, "could not detect our logical addresses"); return bReturn; } @@ -193,11 +191,7 @@ bool CCECProcessor::Initialise(void) ReplaceHandlers(); if ((bReturn = SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true)) == false) - { - CStdString strLog; - strLog.Format("unable to set HDMI port %d on %s (%x)", m_iHDMIPort, ToString(m_iBaseDevice), (uint8_t)m_iBaseDevice); - m_controller->AddLog(CEC_LOG_ERROR, strLog); - } + CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_iHDMIPort, ToString(m_iBaseDevice), (uint8_t)m_iBaseDevice); SetInitialised(bReturn); @@ -216,19 +210,19 @@ bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, /* create the processor thread */ if (!CreateThread() || !m_startCondition.Wait(m_mutex) || !m_bStarted) { - m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); + CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread"); return bReturn; } } if ((bReturn = Initialise()) == false) { - m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); + CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread"); StopThread(true); } else { - m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started"); } return bReturn; @@ -247,7 +241,7 @@ bool CCECProcessor::TryLogicalAddress(cec_logical_address address) bool CCECProcessor::FindLogicalAddressRecordingDevice(void) { - AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'"); return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) || TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) || TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3); @@ -255,7 +249,7 @@ bool CCECProcessor::FindLogicalAddressRecordingDevice(void) bool CCECProcessor::FindLogicalAddressTuner(void) { - AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'"); return TryLogicalAddress(CECDEVICE_TUNER1) || TryLogicalAddress(CECDEVICE_TUNER2) || TryLogicalAddress(CECDEVICE_TUNER3) || @@ -264,7 +258,7 @@ bool CCECProcessor::FindLogicalAddressTuner(void) bool CCECProcessor::FindLogicalAddressPlaybackDevice(void) { - AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'"); return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) || TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) || TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3); @@ -272,7 +266,7 @@ bool CCECProcessor::FindLogicalAddressPlaybackDevice(void) bool CCECProcessor::FindLogicalAddressAudioSystem(void) { - AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'"); return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM); } @@ -280,9 +274,7 @@ bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to) { bool bChanged(false); - CStdString strLog; - strLog.Format("changing device type '%s' into '%s'", ToString(from), ToString(to)); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "changing device type '%s' into '%s'", ToString(from), ToString(to)); CLockObject lock(m_mutex); CCECBusDevice *previousDevice = GetDeviceByType(from); @@ -359,15 +351,13 @@ bool CCECProcessor::FindLogicalAddresses(void) { bool bReturn(true); m_logicalAddresses.Clear(); - CStdString strLog; for (unsigned int iPtr = 0; iPtr < 5; iPtr++) { if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RESERVED) continue; - strLog.Format("%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]); - AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]); if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE) bReturn &= FindLogicalAddressRecordingDevice(); @@ -400,7 +390,7 @@ void *CCECProcessor::Process(void) { CLockObject lock(m_mutex); m_bStarted = true; - m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started"); m_startCondition.Signal(); } @@ -548,9 +538,7 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, if (!m_bStarted && !bForce) return true; - CStdString strLog; - strLog.Format("setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice); - AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, "setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice); uint16_t iPhysicalAddress(0); if (iBaseDevice > CECDEVICE_TV) @@ -575,7 +563,7 @@ bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, } if (!bReturn) - m_controller->AddLog(CEC_LOG_ERROR, "failed to set the physical address"); + CLibCEC::AddLog(CEC_LOG_ERROR, "failed to set the physical address"); else { lock.Unlock(); @@ -614,7 +602,7 @@ void CCECProcessor::LogOutput(const cec_command &data) for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++) strTx.AppendFormat(":%02x", data.parameters[iPtr]); - m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str()); + CLibCEC::AddLog(CEC_LOG_TRAFFIC, strTx.c_str()); } bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) @@ -622,9 +610,7 @@ bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) CLockObject lock(m_mutex); if (m_logicalAddresses.primary != iLogicalAddress) { - CStdString strLog; - strLog.Format("<< setting primary logical address to %1x", iLogicalAddress); - m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< setting primary logical address to %1x", iLogicalAddress); m_logicalAddresses.primary = iLogicalAddress; m_logicalAddresses.Set(iLogicalAddress); return SetAckMask(m_logicalAddresses.AckMask()); @@ -685,9 +671,7 @@ bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpda bool CCECProcessor::SwitchMonitoring(bool bEnable) { - CStdString strLog; - strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling"); - m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling"); { CLockObject lock(m_mutex); @@ -895,7 +879,7 @@ bool CCECProcessor::Transmit(CCECAdapterMessage *output) void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) { - m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "<< transmitting abort message"); cec_command command; // TODO @@ -953,7 +937,7 @@ bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg) break; } - m_controller->AddLog(bIsError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString()); + CLibCEC::AddLog(bIsError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString()); return bEom; } @@ -963,7 +947,7 @@ void CCECProcessor::ParseCommand(cec_command &command) dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode); for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]); - m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str()); + CLibCEC::AddLog(CEC_LOG_TRAFFIC, dataStr.c_str()); if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST) m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); @@ -1024,11 +1008,6 @@ void CCECProcessor::AddKey(void) m_controller->AddKey(); } -void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage) -{ - m_controller->AddLog(level, strMessage); -} - bool CCECProcessor::SetAckMask(uint16_t iMask) { return m_communication->SetAckMask(iMask); diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 82ea16f..39c3671 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -121,7 +121,6 @@ namespace CEC virtual void AddCommand(const cec_command &command); virtual void AddKey(cec_keypress &key); virtual void AddKey(void); - virtual void AddLog(cec_log_level level, const CStdString &strMessage); virtual bool ChangeDeviceType(cec_device_type from, cec_device_type to); virtual bool FindLogicalAddresses(void); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index db141f3..69830fd 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -341,21 +341,27 @@ cec_osd_name CLibCEC::GetDeviceOSDName(cec_logical_address iAddress) return retVal; } -void CLibCEC::AddLog(cec_log_level level, const string &strMessage) +void CLibCEC::AddLog(cec_log_level level, const char *strFormat, ...) { - CLockObject lock(m_mutex); - if (m_cec) - { - cec_log_message message; - message.level = level; - message.time = GetTimeMs() - m_iStartTime; - snprintf(message.message, sizeof(message.message), "%s", strMessage.c_str()); + CStdString strLog; - if (m_callbacks) - m_callbacks->CBCecLogMessage(m_cbParam, message); - else - m_logBuffer.Push(message); - } + va_list argList; + va_start(argList, strFormat); + strLog.FormatV(strFormat, argList); + va_end(argList); + + CLibCEC *instance = CLibCEC::GetInstance(); + CLockObject lock(instance->m_mutex); + + cec_log_message message; + message.level = level; + message.time = GetTimeMs() - instance->m_iStartTime; + snprintf(message.message, sizeof(message.message), "%s", strLog.c_str()); + + if (instance->m_callbacks) + instance->m_callbacks->CBCecLogMessage(instance->m_cbParam, message); + else + instance->m_logBuffer.Push(message); } void CLibCEC::AddKey(cec_keypress &key) @@ -429,21 +435,36 @@ void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode) m_keyBuffer.Push(key); } +static CLibCEC *g_libCEC_instance(NULL); +CLibCEC *CLibCEC::GetInstance(void) +{ + return g_libCEC_instance; +} + +void CLibCEC::SetInstance(CLibCEC *instance) +{ + if (g_libCEC_instance) + delete g_libCEC_instance; + g_libCEC_instance = instance; +} + void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /*= CEC::CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) { - return static_cast< void* > (new CLibCEC(strDeviceName, iLogicalAddress, iPhysicalAddress)); + CLibCEC *lib = new CLibCEC(strDeviceName, iLogicalAddress, iPhysicalAddress); + CLibCEC::SetInstance(lib); + return static_cast< void* > (lib); } void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types) { - return static_cast< void* > (new CLibCEC(strDeviceName, types)); + CLibCEC *lib = new CLibCEC(strDeviceName, types); + CLibCEC::SetInstance(lib); + return static_cast< void* > (lib); } -void CECDestroy(CEC::ICECAdapter *instance) +void CECDestroy(CEC::ICECAdapter *UNUSED(instance)) { - CLibCEC *lib = static_cast< CLibCEC* > (instance); - if (lib) - delete lib; + CLibCEC::SetInstance(NULL); } const char *CLibCEC::ToString(const cec_menu_state state) diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 20b6ccd..9ca006e 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -112,13 +112,16 @@ namespace CEC const char *ToString(const cec_vendor_id vendor); //@} - virtual void AddLog(cec_log_level level, const std::string &strMessage); + static void AddLog(cec_log_level level, const char *strFormat, ...); virtual void AddKey(void); virtual void AddKey(cec_keypress &key); virtual void AddCommand(const cec_command &command); virtual void CheckKeypressTimeout(void); virtual void SetCurrentButton(cec_user_control_code iButtonCode); + static CLibCEC *GetInstance(void); + static void SetInstance(CLibCEC *instance); + protected: int64_t m_iStartTime; cec_user_control_code m_iCurrentButton; diff --git a/src/lib/adapter/AdapterCommunication.cpp b/src/lib/adapter/AdapterCommunication.cpp index 15b6851..fd481d5 100644 --- a/src/lib/adapter/AdapterCommunication.cpp +++ b/src/lib/adapter/AdapterCommunication.cpp @@ -35,6 +35,7 @@ #include "AdapterMessage.h" #include "CECProcessor.h" #include "platform/serialport/serialport.h" +#include "../LibCEC.h" using namespace std; using namespace CEC; @@ -69,13 +70,13 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38 if (!m_port) { - m_processor->AddLog(CEC_LOG_ERROR, "port is NULL"); + CLibCEC::AddLog(CEC_LOG_ERROR, "port is NULL"); return false; } if (IsOpen()) { - m_processor->AddLog(CEC_LOG_ERROR, "port is already open"); + CLibCEC::AddLog(CEC_LOG_ERROR, "port is already open"); return true; } @@ -93,11 +94,11 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38 if (!bConnected) { - m_processor->AddLog(CEC_LOG_ERROR, strError); + CLibCEC::AddLog(CEC_LOG_ERROR, strError); return false; } - m_processor->AddLog(CEC_LOG_DEBUG, "connection opened"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "connection opened"); //clear any input bytes uint8_t buff[1]; @@ -105,12 +106,12 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38 if (CreateThread()) { - m_processor->AddLog(CEC_LOG_DEBUG, "communication thread started"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "communication thread started"); return true; } else { - m_processor->AddLog(CEC_LOG_ERROR, "could not create a communication thread"); + CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a communication thread"); } return false; @@ -150,7 +151,7 @@ bool CAdapterCommunication::Write(CCECAdapterMessage *data) if (data->state != ADAPTER_MESSAGE_STATE_SENT) { - m_processor->AddLog(CEC_LOG_ERROR, "command was not sent"); + CLibCEC::AddLog(CEC_LOG_ERROR, "command was not sent"); } if (data->expectControllerAck) @@ -164,7 +165,7 @@ bool CAdapterCommunication::Write(CCECAdapterMessage *data) else { data->state = ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED; - m_processor->AddLog(CEC_LOG_DEBUG, "did not receive ack"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "did not receive ack"); } } else @@ -204,7 +205,7 @@ bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout) else if (buf == MSGSTART) //we found a msgstart before msgend, this is not right, remove { if (msg.Size() > 0) - m_processor->AddLog(CEC_LOG_WARNING, "received MSGSTART before MSGEND, removing previous buffer contents"); + CLibCEC::AddLog(CEC_LOG_WARNING, "received MSGSTART before MSGEND, removing previous buffer contents"); msg.Clear(); bGotStart = true; } @@ -241,7 +242,7 @@ bool CAdapterCommunication::StartBootloader(void) if (!IsRunning()) return bReturn; - m_processor->AddLog(CEC_LOG_DEBUG, "starting the bootloader"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "starting the bootloader"); CCECAdapterMessage *output = new CCECAdapterMessage; output->PushBack(MSGSTART); @@ -251,7 +252,7 @@ bool CAdapterCommunication::StartBootloader(void) output->expectControllerAck = false; if ((bReturn = Write(output)) == false) - m_processor->AddLog(CEC_LOG_ERROR, "could not start the bootloader"); + CLibCEC::AddLog(CEC_LOG_ERROR, "could not start the bootloader"); delete output; return bReturn; @@ -263,7 +264,7 @@ bool CAdapterCommunication::PingAdapter(void) if (!IsRunning()) return bReturn; - m_processor->AddLog(CEC_LOG_DEBUG, "sending ping"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "sending ping"); CCECAdapterMessage *output = new CCECAdapterMessage; output->PushBack(MSGSTART); @@ -272,7 +273,7 @@ bool CAdapterCommunication::PingAdapter(void) output->isTransmission = false; if ((bReturn = Write(output)) == false) - m_processor->AddLog(CEC_LOG_ERROR, "could not ping the adapter"); + CLibCEC::AddLog(CEC_LOG_ERROR, "could not ping the adapter"); delete output; return bReturn; @@ -286,7 +287,7 @@ uint16_t CAdapterCommunication::GetFirmwareVersion(void) if (iReturn == CEC_FW_VERSION_UNKNOWN) { - m_processor->AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting the firmware version"); CCECAdapterMessage *output = new CCECAdapterMessage; output->PushBack(MSGSTART); @@ -300,7 +301,7 @@ uint16_t CAdapterCommunication::GetFirmwareVersion(void) CCECAdapterMessage input; if (!Read(input, CEC_DEFAULT_TRANSMIT_WAIT) || input.Message() != MSGCODE_FIRMWARE_VERSION || input.Size() != 3) - m_processor->AddLog(CEC_LOG_ERROR, "no or invalid firmware version"); + CLibCEC::AddLog(CEC_LOG_ERROR, "no or invalid firmware version"); else { m_iFirmwareVersion = (input[1] << 8 | input[2]); @@ -326,7 +327,7 @@ bool CAdapterCommunication::SetLineTimeout(uint8_t iTimeout) output->isTransmission = false; if ((bReturn = Write(output)) == false) - m_processor->AddLog(CEC_LOG_ERROR, "could not set the idletime"); + CLibCEC::AddLog(CEC_LOG_ERROR, "could not set the idletime"); delete output; } @@ -338,7 +339,7 @@ bool CAdapterCommunication::SetAckMask(uint16_t iMask) bool bReturn(false); CStdString strLog; strLog.Format("setting ackmask to %2x", iMask); - m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_DEBUG, strLog.c_str()); CCECAdapterMessage *output = new CCECAdapterMessage; @@ -350,7 +351,7 @@ bool CAdapterCommunication::SetAckMask(uint16_t iMask) output->isTransmission = false; if ((bReturn = Write(output)) == false) - m_processor->AddLog(CEC_LOG_ERROR, "could not set the ackmask"); + CLibCEC::AddLog(CEC_LOG_ERROR, "could not set the ackmask"); delete output; return bReturn; @@ -398,21 +399,21 @@ bool CAdapterCommunication::WaitForTransmitSucceeded(CCECAdapterMessage *message if (bError) { message->reply = msg.Message(); - m_processor->AddLog(CEC_LOG_DEBUG, msg.ToString()); + CLibCEC::AddLog(CEC_LOG_DEBUG, msg.ToString()); } else { switch(msg.Message()) { case MSGCODE_COMMAND_ACCEPTED: - m_processor->AddLog(CEC_LOG_DEBUG, msg.ToString()); + CLibCEC::AddLog(CEC_LOG_DEBUG, msg.ToString()); if (iPacketsLeft > 0) iPacketsLeft--; if (!message->isTransmission && iPacketsLeft == 0) bTransmitSucceeded = true; break; case MSGCODE_TRANSMIT_SUCCEEDED: - m_processor->AddLog(CEC_LOG_DEBUG, msg.ToString()); + CLibCEC::AddLog(CEC_LOG_DEBUG, msg.ToString()); bTransmitSucceeded = (iPacketsLeft == 0); bError = !bTransmitSucceeded; message->reply = MSGCODE_TRANSMIT_SUCCEEDED; @@ -451,7 +452,7 @@ bool CAdapterCommunication::ReadFromDevice(uint32_t iTimeout) { CStdString strError; strError.Format("error reading from serial port: %s", m_port->GetError().c_str()); - m_processor->AddLog(CEC_LOG_ERROR, strError); + CLibCEC::AddLog(CEC_LOG_ERROR, strError); return false; } else if (iBytesRead > 0) @@ -468,12 +469,12 @@ void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg) { CStdString strError; strError.Format("error writing to serial port: %s", m_port->GetError().c_str()); - m_processor->AddLog(CEC_LOG_ERROR, strError); + CLibCEC::AddLog(CEC_LOG_ERROR, strError); msg->state = ADAPTER_MESSAGE_STATE_ERROR; } else { - m_processor->AddLog(CEC_LOG_DEBUG, "command sent"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "command sent"); msg->state = ADAPTER_MESSAGE_STATE_SENT; } msg->condition.Signal(); diff --git a/src/lib/devices/CECAudioSystem.cpp b/src/lib/devices/CECAudioSystem.cpp index 7bdb091..e8fbf8c 100644 --- a/src/lib/devices/CECAudioSystem.cpp +++ b/src/lib/devices/CECAudioSystem.cpp @@ -33,6 +33,7 @@ #include "CECAudioSystem.h" #include "../CECProcessor.h" #include "../implementations/CECCommandHandler.h" +#include "../LibCEC.h" using namespace CEC; using namespace PLATFORM; @@ -52,10 +53,7 @@ bool CCECAudioSystem::SetAudioStatus(uint8_t status) CLockObject lock(m_mutex); if (m_audioStatus != status) { - CStdString strLog; - strLog.Format(">> %s (%X): audio status changed from %2x to %2x", GetLogicalAddressName(), m_iLogicalAddress, m_audioStatus, status); - AddLog(CEC_LOG_DEBUG, strLog.c_str()); - + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): audio status changed from %2x to %2x", GetLogicalAddressName(), m_iLogicalAddress, m_audioStatus, status); m_audioStatus = status; return true; } @@ -68,10 +66,7 @@ bool CCECAudioSystem::SetSystemAudioModeStatus(const cec_system_audio_status mod CLockObject lock(m_mutex); if (m_systemAudioStatus != mode) { - CStdString strLog; - strLog.Format(">> %s (%X): system audio mode status changed from %s to %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_systemAudioStatus), ToString(mode)); - AddLog(CEC_LOG_DEBUG, strLog.c_str()); - + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): system audio mode status changed from %s to %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_systemAudioStatus), ToString(mode)); m_systemAudioStatus = mode; return true; } @@ -84,9 +79,7 @@ bool CCECAudioSystem::TransmitAudioStatus(cec_logical_address dest) uint8_t state; { CLockObject lock(m_mutex); - CStdString strLog; - strLog.Format("<< %x -> %x: audio status '%2x'", m_iLogicalAddress, dest, m_audioStatus); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %x -> %x: audio status '%2x'", m_iLogicalAddress, dest, m_audioStatus); state = m_audioStatus; } @@ -98,9 +91,7 @@ bool CCECAudioSystem::TransmitSetSystemAudioMode(cec_logical_address dest) cec_system_audio_status state; { CLockObject lock(m_mutex); - CStdString strLog; - strLog.Format("<< %x -> %x: set system audio mode '%2x'", m_iLogicalAddress, dest, m_audioStatus); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %x -> %x: set system audio mode '%2x'", m_iLogicalAddress, dest, m_audioStatus); state = m_systemAudioStatus; } @@ -112,9 +103,7 @@ bool CCECAudioSystem::TransmitSystemAudioModeStatus(cec_logical_address dest) cec_system_audio_status state; { CLockObject lock(m_mutex); - CStdString strLog; - strLog.Format("<< %x -> %x: system audio mode '%s'", m_iLogicalAddress, dest, ToString(m_systemAudioStatus)); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %x -> %x: system audio mode '%s'", m_iLogicalAddress, dest, ToString(m_systemAudioStatus)); state = m_systemAudioStatus; } diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index a907fc8..46e618c 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -36,6 +36,7 @@ #include "../implementations/CECCommandHandler.h" #include "../implementations/SLCommandHandler.h" #include "../implementations/VLCommandHandler.h" +#include "../LibCEC.h" using namespace CEC; using namespace PLATFORM; @@ -73,11 +74,6 @@ CCECBusDevice::~CCECBusDevice(void) delete m_handler; } -void CCECBusDevice::AddLog(cec_log_level level, const CStdString &strMessage) -{ - m_processor->AddLog(level, strMessage); -} - bool CCECBusDevice::HandleCommand(const cec_command &command) { bool bHandled(false); @@ -101,11 +97,7 @@ bool CCECBusDevice::HandleCommand(const cec_command &command) if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) { if (m_deviceStatus != CEC_DEVICE_STATUS_PRESENT) - { - CStdString strLog; - strLog.Format("device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command.opcode)); - AddLog(CEC_LOG_DEBUG, strLog); - } + CLibCEC::AddLog(CEC_LOG_DEBUG, "device %s (%x) status changed to present after command %s", GetLogicalAddressName(), (uint8_t)GetLogicalAddress(), ToString(command.opcode)); m_deviceStatus = CEC_DEVICE_STATUS_PRESENT; } } @@ -115,9 +107,7 @@ bool CCECBusDevice::HandleCommand(const cec_command &command) bool CCECBusDevice::PowerOn(void) { - CStdString strLog; - strLog.Format("<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_DEBUG, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_DEBUG, "<< powering on '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); if (m_handler->TransmitImageViewOn(GetMyLogicalAddress(), m_iLogicalAddress)) { @@ -132,7 +122,7 @@ bool CCECBusDevice::PowerOn(void) // /* sending the normal power on command appears to have failed */ // CStdString strLog; // strLog.Format("<< sending power on keypress to '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); -// AddLog(CEC_LOG_DEBUG, strLog.c_str()); +// CLibCEC::AddLog(CEC_LOG_DEBUG, strLog.c_str()); // // TransmitKeypress(CEC_USER_CONTROL_CODE_POWER); // return TransmitKeyRelease(); @@ -145,10 +135,7 @@ bool CCECBusDevice::PowerOn(void) bool CCECBusDevice::Standby(void) { - CStdString strLog; - strLog.Format("<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_DEBUG, strLog.c_str()); - + CLibCEC::AddLog(CEC_LOG_DEBUG, "<< putting '%s' (%X) in standby mode", GetLogicalAddressName(), m_iLogicalAddress); return m_handler->TransmitStandby(GetMyLogicalAddress(), m_iLogicalAddress); } @@ -177,9 +164,7 @@ bool CCECBusDevice::RequestCecVersion(void) if (!MyLogicalAddressContains(m_iLogicalAddress)) { m_handler->MarkBusy(); - CStdString strLog; - strLog.Format("<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting CEC version of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); bReturn = m_handler->TransmitRequestCecVersion(GetMyLogicalAddress(), m_iLogicalAddress); m_handler->MarkReady(); @@ -216,9 +201,7 @@ bool CCECBusDevice::RequestMenuLanguage(void) !IsUnsupportedFeature(CEC_OPCODE_GET_MENU_LANGUAGE)) { m_handler->MarkBusy(); - CStdString strLog; - strLog.Format("<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting menu language of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); bReturn = m_handler->TransmitRequestMenuLanguage(GetMyLogicalAddress(), m_iLogicalAddress); m_handler->MarkReady(); } @@ -266,9 +249,7 @@ bool CCECBusDevice::RequestOSDName(void) !IsUnsupportedFeature(CEC_OPCODE_GIVE_OSD_NAME)) { m_handler->MarkBusy(); - CStdString strLog; - strLog.Format("<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting OSD name of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); bReturn = m_handler->TransmitRequestOSDName(GetMyLogicalAddress(), m_iLogicalAddress); m_handler->MarkReady(); } @@ -285,7 +266,7 @@ uint16_t CCECBusDevice::GetPhysicalAddress(bool bUpdate /* = false */) } if (bRequestUpdate && !RequestPhysicalAddress()) - AddLog(CEC_LOG_ERROR, "failed to request the physical address (1)"); + CLibCEC::AddLog(CEC_LOG_ERROR, "failed to request the physical address"); CLockObject lock(m_mutex); return m_iPhysicalAddress; @@ -298,9 +279,7 @@ bool CCECBusDevice::RequestPhysicalAddress(void) if (!MyLogicalAddressContains(m_iLogicalAddress)) { m_handler->MarkBusy(); - CStdString strLog; - strLog.Format("<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting physical address of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); bReturn = m_handler->TransmitRequestPhysicalAddress(GetMyLogicalAddress(), m_iLogicalAddress); m_handler->MarkReady(); } @@ -334,9 +313,7 @@ bool CCECBusDevice::RequestPowerStatus(void) !IsUnsupportedFeature(CEC_OPCODE_GIVE_DEVICE_POWER_STATUS)) { m_handler->MarkBusy(); - CStdString strLog; - strLog.Format("<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting power status of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); bReturn = m_handler->TransmitRequestPowerStatus(GetMyLogicalAddress(), m_iLogicalAddress); m_handler->MarkReady(); } @@ -366,9 +343,7 @@ bool CCECBusDevice::RequestVendorId(void) if (!MyLogicalAddressContains(m_iLogicalAddress)) { m_handler->MarkBusy(); - CStdString strLog; - strLog.Format("<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< requesting vendor ID of '%s' (%X)", GetLogicalAddressName(), m_iLogicalAddress); bReturn = m_handler->TransmitRequestVendorId(GetMyLogicalAddress(), m_iLogicalAddress); m_handler->MarkReady(); @@ -459,10 +434,7 @@ cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */) void CCECBusDevice::SetCecVersion(const cec_version newVersion) { m_cecVersion = newVersion; - - CStdString strLog; - strLog.Format("%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion)); - AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): CEC version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(newVersion)); } void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) @@ -470,9 +442,7 @@ void CCECBusDevice::SetMenuLanguage(const cec_menu_language &language) CLockObject lock(m_mutex); if (language.device == m_iLogicalAddress) { - CStdString strLog; - strLog.Format(">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language); - m_processor->AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu language set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, language.language); m_menuLanguage = language; } } @@ -482,9 +452,7 @@ void CCECBusDevice::SetOSDName(CStdString strName) CLockObject lock(m_mutex); if (m_strDeviceName != strName) { - CStdString strLog; - strLog.Format(">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName); - m_processor->AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): osd name set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, strName.c_str()); m_strDeviceName = strName; } } @@ -494,9 +462,7 @@ void CCECBusDevice::SetMenuState(const cec_menu_state state) CLockObject lock(m_mutex); if (m_menuState != state) { - CStdString strLog; - strLog.Format(">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState)); - m_processor->AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): menu state set to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_menuState)); m_menuState = state; } } @@ -516,11 +482,7 @@ void CCECBusDevice::SetActiveSource(void) { CLockObject lock(m_mutex); if (!m_bActiveSource) - { - CStdString strLog; - strLog.Format("making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_DEBUG, strLog); - } + CLibCEC::AddLog(CEC_LOG_DEBUG, "making %s (%x) the active source", GetLogicalAddressName(), m_iLogicalAddress); for (int iPtr = 0; iPtr < 16; iPtr++) if (iPtr != m_iLogicalAddress) @@ -532,22 +494,18 @@ void CCECBusDevice::SetActiveSource(void) bool CCECBusDevice::TryLogicalAddress(void) { - CStdString strLog; - strLog.Format("trying logical address '%s'", GetLogicalAddressName()); - AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, "trying logical address '%s'", GetLogicalAddressName()); m_processor->SetAckMask(0x1 << m_iLogicalAddress); if (!TransmitPoll(m_iLogicalAddress)) { - strLog.Format("using logical address '%s'", GetLogicalAddressName()); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "using logical address '%s'", GetLogicalAddressName()); SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC); return true; } - strLog.Format("logical address '%s' already taken", GetLogicalAddressName()); - AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, "logical address '%s' already taken", GetLogicalAddressName()); SetDeviceStatus(CEC_DEVICE_STATUS_PRESENT); return false; } @@ -589,10 +547,7 @@ void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress) CLockObject lock(m_mutex); if (iNewAddress > 0 && m_iPhysicalAddress != iNewAddress) { - CStdString strLog; - strLog.Format(">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress); - AddLog(CEC_LOG_DEBUG, strLog.c_str()); - + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress); m_iPhysicalAddress = iNewAddress; } } @@ -602,10 +557,7 @@ void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* CLockObject lock(m_mutex); if (iNewAddress > 0) { - CStdString strLog; - strLog.Format(">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress); - AddLog(CEC_LOG_DEBUG, strLog.c_str()); - + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): stream path changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, iOldAddress == 0 ? m_iStreamPath : iOldAddress, iNewAddress); m_iStreamPath = iNewAddress; if (iNewAddress > 0) @@ -622,9 +574,7 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) if (m_powerStatus != powerStatus) { m_iLastPowerStateUpdate = GetTimeMs(); - CStdString strLog; - strLog.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus)); - m_processor->AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_powerStatus), ToString(powerStatus)); m_powerStatus = powerStatus; } } @@ -641,13 +591,11 @@ bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) CStdString strLog; if (m_handler->InUse()) { - strLog.Format("handler for device '%s' (%x) is being used. not replacing the command handler", GetLogicalAddressName(), GetLogicalAddress()); - m_processor->AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, "handler for device '%s' (%x) is being used. not replacing the command handler", GetLogicalAddressName(), GetLogicalAddress()); return false; } - strLog.Format("replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress()); - m_processor->AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, "replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress()); delete m_handler; switch (m_vendor) @@ -687,9 +635,7 @@ bool CCECBusDevice::SetVendorId(uint64_t iVendorId) m_vendor = (cec_vendor_id)iVendorId; } - CStdString strLog; - strLog.Format("%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_vendor), m_vendor); - m_processor->AddLog(CEC_LOG_DEBUG, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_DEBUG, "%s (%X): vendor = %s (%06x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_vendor), m_vendor); return bVendorChanged; } @@ -704,24 +650,14 @@ bool CCECBusDevice::TransmitActiveSource(void) { CLockObject lock(m_mutex); if (m_powerStatus != CEC_POWER_STATUS_ON) - { - CStdString strLog; - strLog.Format("<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_DEBUG, strLog); - } + CLibCEC::AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not powered on", GetLogicalAddressName(), m_iLogicalAddress); else if (m_bActiveSource) { - CStdString strLog; - strLog.Format("<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): active source (%4x)", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); bSendActiveSource = true; } else - { - CStdString strLog; - strLog.Format("<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_DEBUG, strLog); - } + CLibCEC::AddLog(CEC_LOG_DEBUG, "<< %s (%X) is not the active source", GetLogicalAddressName(), m_iLogicalAddress); } if (bSendActiveSource) @@ -739,9 +675,7 @@ bool CCECBusDevice::TransmitCECVersion(cec_logical_address dest) cec_version version; { CLockObject lock(m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion)); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion)); version = m_cecVersion; } @@ -753,9 +687,7 @@ bool CCECBusDevice::TransmitInactiveSource(void) uint16_t iPhysicalAddress; { CLockObject lock(m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress); iPhysicalAddress = m_iPhysicalAddress; } @@ -767,9 +699,7 @@ bool CCECBusDevice::TransmitMenuState(cec_logical_address dest) cec_menu_state menuState; { CLockObject lock(m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState)); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState)); menuState = m_menuState; } @@ -781,9 +711,7 @@ bool CCECBusDevice::TransmitOSDName(cec_logical_address dest) CStdString strDeviceName; { CLockObject lock(m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str()); - AddLog(CEC_LOG_NOTICE, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): OSD name '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, m_strDeviceName.c_str()); strDeviceName = m_strDeviceName; } @@ -794,10 +722,7 @@ bool CCECBusDevice::TransmitOSDString(cec_logical_address dest, cec_display_cont { if (!IsUnsupportedFeature(CEC_OPCODE_SET_OSD_STRING)) { - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage); - AddLog(CEC_LOG_NOTICE, strLog.c_str()); - + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): display OSD message '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, strMessage); return m_handler->TransmitOSDString(m_iLogicalAddress, dest, duration, strMessage); } return false; @@ -812,10 +737,7 @@ bool CCECBusDevice::TransmitPhysicalAddress(void) if (m_iPhysicalAddress == 0xffff) return false; - CStdString strLog; - strLog.Format("<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); - AddLog(CEC_LOG_NOTICE, strLog.c_str()); - + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): physical adddress %4x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress); iPhysicalAddress = m_iPhysicalAddress; type = m_type; } @@ -833,11 +755,9 @@ bool CCECBusDevice::TransmitPoll(cec_logical_address dest) if (destDevice->m_deviceStatus == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC) return bReturn; - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); - AddLog(CEC_LOG_NOTICE, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): POLL", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); bReturn = m_handler->TransmitPoll(m_iLogicalAddress, dest); - AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent"); + CLibCEC::AddLog(CEC_LOG_DEBUG, bReturn ? ">> POLL sent" : ">> POLL not sent"); CLockObject lock(m_mutex); if (bReturn) @@ -856,9 +776,7 @@ bool CCECBusDevice::TransmitPowerState(cec_logical_address dest) cec_power_status state; { CLockObject lock(m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus)); - AddLog(CEC_LOG_NOTICE, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus)); state = m_powerStatus; } @@ -877,20 +795,14 @@ bool CCECBusDevice::TransmitVendorID(cec_logical_address dest, bool bSendAbort / { if (bSendAbort) { - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); - AddLog(CEC_LOG_NOTICE, strLog); - + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): vendor id feature abort", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest); m_processor->TransmitAbort(dest, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); } return false; } else { - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString((cec_vendor_id)iVendorId), iVendorId); - AddLog(CEC_LOG_NOTICE, strLog); - + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): vendor id %s (%x)", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString((cec_vendor_id)iVendorId), iVendorId); return m_handler->TransmitVendorID(m_iLogicalAddress, iVendorId); } } diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 412504e..ba68632 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -50,7 +50,6 @@ namespace CEC CCECBusDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = 0); virtual ~CCECBusDevice(void); - virtual void AddLog(cec_log_level level, const CStdString &strMessage); virtual bool HandleCommand(const cec_command &command); virtual bool PowerOn(void); virtual bool Standby(void); diff --git a/src/lib/devices/CECPlaybackDevice.cpp b/src/lib/devices/CECPlaybackDevice.cpp index f9689cb..86c1679 100644 --- a/src/lib/devices/CECPlaybackDevice.cpp +++ b/src/lib/devices/CECPlaybackDevice.cpp @@ -33,6 +33,7 @@ #include "CECPlaybackDevice.h" #include "../implementations/CECCommandHandler.h" #include "../CECProcessor.h" +#include "../LibCEC.h" using namespace CEC; using namespace PLATFORM; @@ -58,10 +59,7 @@ void CCECPlaybackDevice::SetDeckStatus(cec_deck_info deckStatus) CLockObject lock(m_mutex); if (m_deckStatus != deckStatus && m_deckStatus != CEC_DECK_INFO_OTHER_STATUS_LG) { - CStdString strLog; - strLog.Format(">> %s (%X): deck status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_deckStatus), ToString(deckStatus)); - AddLog(CEC_LOG_DEBUG, strLog.c_str()); - + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): deck status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_deckStatus), ToString(deckStatus)); m_deckStatus = deckStatus; } } @@ -77,10 +75,7 @@ void CCECPlaybackDevice::SetDeckControlMode(cec_deck_control_mode mode) CLockObject lock(m_mutex); if (m_deckControlMode != mode) { - CStdString strLog; - strLog.Format(">> %s (%X): deck control mode changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_deckControlMode), ToString(mode)); - AddLog(CEC_LOG_DEBUG, strLog.c_str()); - + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %s (%X): deck control mode changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_deckControlMode), ToString(mode)); m_deckControlMode = mode; } } @@ -90,9 +85,7 @@ bool CCECPlaybackDevice::TransmitDeckStatus(cec_logical_address dest) cec_deck_info state; { CLockObject lock(m_mutex); - CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): deck status '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_deckStatus)); - AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): deck status '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_deckStatus)); state = m_deckStatus; } diff --git a/src/lib/implementations/ANCommandHandler.cpp b/src/lib/implementations/ANCommandHandler.cpp index bf9dea5..1df94fa 100644 --- a/src/lib/implementations/ANCommandHandler.cpp +++ b/src/lib/implementations/ANCommandHandler.cpp @@ -33,6 +33,7 @@ #include "ANCommandHandler.h" #include "../devices/CECBusDevice.h" #include "../CECProcessor.h" +#include "../LibCEC.h" using namespace CEC; @@ -62,10 +63,7 @@ bool CANCommandHandler::HandleVendorRemoteButtonDown(const cec_command &command) if (key.keycode != CEC_USER_CONTROL_CODE_UNKNOWN) { - CStdString strLog; - strLog.Format("key pressed: %1x", key.keycode); - m_busDevice->AddLog(CEC_LOG_DEBUG, strLog); - + CLibCEC::AddLog(CEC_LOG_DEBUG, "key pressed: %1x", key.keycode); m_busDevice->GetProcessor()->AddKey(key); } } diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index d407e40..0178ae0 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -35,6 +35,7 @@ #include "../devices/CECAudioSystem.h" #include "../devices/CECPlaybackDevice.h" #include "../CECProcessor.h" +#include "../LibCEC.h" using namespace CEC; using namespace std; @@ -66,9 +67,7 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) bool bHandled(true); MarkBusy(); - CStdString strLog; - strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", m_processor->ToString(command.initiator), command.initiator, m_processor->ToString(command.destination), command.destination, m_processor->ToString(command.opcode), command.opcode); - m_busDevice->AddLog(CEC_LOG_NOTICE, strLog); + CLibCEC::AddLog(CEC_LOG_NOTICE, ">> %s (%X) -> %s (%X): %s (%2X)", m_processor->ToString(command.initiator), command.initiator, m_processor->ToString(command.destination), command.destination, m_processor->ToString(command.opcode), command.opcode); m_processor->AddCommand(command); @@ -422,9 +421,7 @@ bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) { if (m_processor->IsStarted()) { - CStdString strLog; - strLog.Format(">> %i requests active source", (uint8_t) command.initiator); - m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i requests active source", (uint8_t) command.initiator); vector devices; for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++) @@ -505,9 +502,7 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) if (m_processor->IsStarted() && command.parameters.size >= 2) { uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); - CStdString strLog; - strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); - m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); /* one of the device handled by libCEC has been made active */ CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); @@ -600,9 +595,7 @@ bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) { - CStdString strLog; - strLog.Format("key pressed: %x", command.parameters[0]); - m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); + CLibCEC::AddLog(CEC_LOG_DEBUG, "key pressed: %x", command.parameters[0]); if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) @@ -647,9 +640,7 @@ bool CCECCommandHandler::HandleVendorCommand(const cec_command & UNUSED(command) void CCECCommandHandler::UnhandledCommand(const cec_command &command) { - CStdString strLog; - strLog.Format("unhandled command with opcode %02x from address %d", command.opcode, command.initiator); - m_busDevice->AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, "unhandled command with opcode %02x from address %d", command.opcode, command.initiator); } size_t CCECCommandHandler::GetMyDevices(vector &devices) const @@ -694,7 +685,7 @@ bool CCECCommandHandler::SetVendorId(const cec_command &command) bool bChanged(false); if (command.parameters.size < 3) { - m_busDevice->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); + CLibCEC::AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); return bChanged; } @@ -726,9 +717,7 @@ void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16 void CCECCommandHandler::HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) { - CStdString strLog; - strLog.Format("<< POLL: %s (%x) -> %s (%x)", m_processor->ToString(iInitiator), iInitiator, m_processor->ToString(iDestination), iDestination); - m_processor->AddLog(CEC_LOG_DEBUG, strLog); + CLibCEC::AddLog(CEC_LOG_DEBUG, "<< POLL: %s (%x) -> %s (%x)", m_processor->ToString(iInitiator), iInitiator, m_processor->ToString(iDestination), iDestination); } bool CCECCommandHandler::HandleReceiveFailed(void) @@ -973,7 +962,7 @@ bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /* m_expectedResponse = expectedResponse; if (m_processor->Transmit(command)) { - m_processor->AddLog(CEC_LOG_DEBUG, "command transmitted"); + CLibCEC::AddLog(CEC_LOG_DEBUG, "command transmitted"); bReturn = bExpectResponse ? m_condition.Wait(m_receiveMutex, m_iTransmitWait) : true;