From: Lars Op den Kamp Date: Thu, 10 May 2012 22:30:16 +0000 (+0200) Subject: cec: fixed - ensure that the correct libCEC version is set after initialising the... X-Git-Tag: upstream/2.2.0~1^2~28^2~26 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=99aeafb929fa132a096c236c4ae1eb78c2a595ec;p=deb_libcec.git cec: fixed - ensure that the correct libCEC version is set after initialising the adapter. ensure that we don't crash out when trying to stop a thread that hasn't been started yet --- diff --git a/src/lib/CECClient.cpp b/src/lib/CECClient.cpp index 4cccb60..30723fe 100644 --- a/src/lib/CECClient.cpp +++ b/src/lib/CECClient.cpp @@ -733,8 +733,7 @@ bool CCECClient::SetConfiguration(const libcec_configuration *configuration) CCECBusDevice *primary = bIsRunning ? GetPrimaryDevice() : NULL; cec_device_type oldPrimaryType = primary ? primary->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE; - m_configuration.serverVersion = LIBCEC_VERSION_CURRENT; - m_configuration.clientVersion = configuration->clientVersion; + m_configuration.clientVersion = configuration->clientVersion; LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using client version '%s'", __FUNCTION__, ToString((cec_client_version)configuration->clientVersion)); // client version 1.5.0 diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 435177b..0add41b 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -104,6 +104,13 @@ void CCECProcessor::Close(void) delete m_communication; m_communication = NULL; } + + m_bMonitor = false; + m_iPreviousAckMask = 0; + m_iStandardLineTimeout = 3; + m_iRetryLineTimeout = 3; + m_iLastTransmission = 0; + m_busDevices->ResetDeviceStatus(); } bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening /* = true */) @@ -617,7 +624,8 @@ bool CCECProcessor::RegisterClient(CCECClient *client) client->Initialise(); // set the firmware version and build date - configuration.iFirmwareVersion = m_communication->GetFirmwareVersion(); + configuration.serverVersion = LIBCEC_VERSION_CURRENT; + configuration.iFirmwareVersion = m_communication->GetFirmwareVersion(); configuration.iFirmwareBuildDate = m_communication->GetFirmwareBuildDate(); CStdString strLog; @@ -670,9 +678,8 @@ bool CCECProcessor::RegisterClient(CCECClient *client) void CCECProcessor::UnregisterClient(CCECClient *client) { CLockObject lock(m_mutex); - libcec_configuration &configuration = *client->GetConfiguration(); CECDEVICEVEC devices; - m_busDevices->GetByLogicalAddresses(devices, configuration.logicalAddresses); + m_busDevices->GetByLogicalAddresses(devices, client->GetConfiguration()->logicalAddresses); for (CECDEVICEVEC::const_iterator it = devices.begin(); it != devices.end(); it++) { map::iterator entry = m_clients.find((*it)->GetLogicalAddress()); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index f860700..daa0b55 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -65,6 +65,9 @@ CLibCEC::~CLibCEC(void) bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */) { + if (!m_cec) + return false; + if (m_cec->IsRunning()) { AddLog(CEC_LOG_ERROR, "connection already open"); @@ -91,17 +94,13 @@ bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = CEC_DEFAULT_CON void CLibCEC::Close(void) { - m_clients.clear(); - - if (m_client) - { - delete m_client; - m_client = NULL; - } if (m_cec) + m_cec->Close(); + + for (vector::iterator it = m_clients.begin(); it != m_clients.end(); it++) { - delete m_cec; - m_cec = NULL; + (*it)->SetRegistered(false); + (*it)->SetInitialised(false); } } @@ -923,7 +922,7 @@ CCECClient *CLibCEC::RegisterClient(libcec_configuration *configuration) if (m_cec->IsRunning()) m_cec->RegisterClient(newClient); - return m_client; + return newClient; } void CLibCEC::UnregisterClients(void) @@ -939,8 +938,15 @@ void * CECInitialise(libcec_configuration *configuration) return NULL; CLibCEC *lib = new CLibCEC; + CCECClient *client(NULL); if (lib) - lib->RegisterClient(configuration); + client = lib->RegisterClient(configuration); + + if (client) + client->GetCurrentConfiguration(configuration); + + // ensure that the correct server version is set + configuration->serverVersion = LIBCEC_VERSION_CURRENT; return static_cast< void* > (lib); } @@ -948,7 +954,6 @@ void * CECInitialise(libcec_configuration *configuration) void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types, uint16_t iPhysicalAddress /* = 0 */) { libcec_configuration configuration; - configuration.serverVersion = LIBCEC_VERSION_CURRENT; // client version < 1.5.0 snprintf(configuration.strDeviceName, 13, "%s", strDeviceName); diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index ca66a46..a0d20a8 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -998,6 +998,9 @@ void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* m_iStreamPath = iNewAddress; } + if (!LIB_CEC->IsValidPhysicalAddress(iNewAddress)) + return; + CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress); if (device) { diff --git a/src/lib/platform/threads/threads.h b/src/lib/platform/threads/threads.h index e29578c..ead0ebd 100644 --- a/src/lib/platform/threads/threads.h +++ b/src/lib/platform/threads/threads.h @@ -41,13 +41,15 @@ namespace PLATFORM CThread(void) : m_bStop(false), m_bRunning(false), - m_bStopped(false) {} + m_bStopped(false), + m_thread(NULL) {} virtual ~CThread(void) { StopThread(0); void *retVal; - ThreadsWait(m_thread, &retVal); + if (m_thread) + ThreadsWait(m_thread, &retVal); #if defined(__WINDOWS__) (void *)retVal; //"unreferenced local variable" warning #endif