extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
#endif
-/*!
- * @brief Close the CEC adapter connection.
- * @return True when the device was closed, false otherwise.
- */
-extern DECLSPEC bool cec_close(void);
-
/*!
* @brief Open a connection to the CEC adapter.
* @param strPort The path to the port.
*/
extern DECLSPEC bool cec_open(const char *strPort, int iTimeout);
+/*!
+ * @brief Close the connection to the CEC adapter.
+ * @param iTimeout Timeout in ms
+ */
+extern DECLSPEC bool cec_close(int iTimeout);
+
/*!
* @brief Ping the CEC adapter.
* @return True when the ping was succesful, false otherwise.
CCECParser::~CCECParser(void)
{
- m_bRunning = false;
- pthread_join(m_thread, NULL);
+ Close(0);
m_serialport->Close();
delete m_serialport;
}
return bReturn;
}
+bool CCECParser::Close(int iTimeoutMs /* = 2000 */)
+{
+ m_bRunning = false;
+ bool bExit(false);
+ if (iTimeoutMs > 0)
+ {
+ bExit = m_exitCondition.Wait(&m_mutex, iTimeoutMs);
+ m_mutex.Unlock();
+ }
+ else
+ {
+ pthread_join(m_thread, NULL);
+ bExit = true;
+ }
+
+ return bExit;
+}
+
void *CCECParser::ThreadHandler(CCECParser *parser)
{
if (parser)
AddLog(CEC_LOG_DEBUG, "reader thread terminated");
m_bRunning = false;
+ m_exitCondition.Signal();
return true;
}
bool CCECParser::Ping(void)
{
+ if (!m_bRunning)
+ return false;
+
AddLog(CEC_LOG_DEBUG, "sending ping");
cec_frame output;
output.push_back(MSGSTART);
bool CCECParser::StartBootloader(void)
{
+ if (!m_bRunning)
+ return false;
+
AddLog(CEC_LOG_DEBUG, "starting the bootloader");
cec_frame output;
output.push_back(MSGSTART);
bool CCECParser::PowerOffDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
{
+ if (!m_bRunning)
+ return false;
+
CStdString strLog;
strLog.Format("powering off devices with logical address %d", (int8_t)address);
AddLog(CEC_LOG_DEBUG, strLog.c_str());
bool CCECParser::PowerOnDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
{
+ if (!m_bRunning)
+ return false;
+
CStdString strLog;
strLog.Format("powering on devices with logical address %d", (int8_t)address);
AddLog(CEC_LOG_DEBUG, strLog.c_str());
bool CCECParser::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
{
+ if (!m_bRunning)
+ return false;
+
CStdString strLog;
strLog.Format("putting all devices with logical address %d in standby mode", (int8_t)address);
AddLog(CEC_LOG_DEBUG, strLog.c_str());
bool CCECParser::SetActiveView(void)
{
+ if (!m_bRunning)
+ return false;
+
AddLog(CEC_LOG_DEBUG, "setting active view");
cec_frame frame;
frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
bool CCECParser::SetInactiveView(void)
{
+ if (!m_bRunning)
+ return false;
+
AddLog(CEC_LOG_DEBUG, "setting inactive view");
cec_frame frame;
frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
bool CCECParser::GetNextLogMessage(cec_log_message *message)
{
- return m_logBuffer.Pop(*message);
+ return m_bRunning ? m_logBuffer.Pop(*message) : false;
}
bool CCECParser::GetNextKeypress(cec_keypress *key)
{
- return m_keyBuffer.Pop(*key);
+ return m_bRunning ? m_keyBuffer.Pop(*key) : false;
}
bool CCECParser::GetNextCommand(cec_command *command)
{
- return m_commandBuffer.Pop(*command);
+ return m_bRunning ? m_commandBuffer.Pop(*command) : false;
}
//@}
void CCECParser::ProcessMessages(void)
{
cec_frame msg;
- while (GetMessage(msg))
+ while (m_bRunning && GetMessage(msg))
ParseMessage(msg);
}