From 5f39c4d854ec7441761bc6db870b6bbc73016309 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Mon, 3 Oct 2011 13:09:25 +0200 Subject: [PATCH] timeout parameter removed from Close()/cec_close(). return type changed to void. added cec_destroy() method --- include/CECExportsC.h | 9 ++++++--- include/CECExportsCpp.h | 2 +- src/lib/CECParser.cpp | 18 +++--------------- src/lib/CECParser.h | 2 +- src/lib/CECParserC.cpp | 16 +++++++++------- src/testclient/main.cpp | 3 ++- 6 files changed, 22 insertions(+), 28 deletions(-) diff --git a/include/CECExportsC.h b/include/CECExportsC.h index 19706f4..d03bfe0 100644 --- a/include/CECExportsC.h +++ b/include/CECExportsC.h @@ -45,13 +45,17 @@ extern "C" { * @param iPhysicalAddress The physical address of this device. 0x1000 by default. * @return True when initialised, false otherwise. */ - #ifdef __cplusplus extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); #else extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); #endif +/*! + * @brief Unload the CEC adapter library. + */ +extern DECLSPEC void cec_destroy(void); + /*! * @brief Open a connection to the CEC adapter. * @param strPort The path to the port. @@ -62,9 +66,8 @@ 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); +extern DECLSPEC void cec_close(void); /*! * @brief Ping the CEC adapter. diff --git a/include/CECExportsCpp.h b/include/CECExportsCpp.h index a87c2d0..635d505 100644 --- a/include/CECExportsCpp.h +++ b/include/CECExportsCpp.h @@ -44,7 +44,7 @@ namespace CEC /*! * @see cec_close */ - virtual bool Close(int iTimeoutMs = 2000) = 0; + virtual void Close(void) = 0; /*! * @see cec_find_devices diff --git a/src/lib/CECParser.cpp b/src/lib/CECParser.cpp index 1eaa1f5..7a6d871 100644 --- a/src/lib/CECParser.cpp +++ b/src/lib/CECParser.cpp @@ -66,7 +66,7 @@ CCECParser::CCECParser(const char *strDeviceName, cec_logical_address iLogicalAd CCECParser::~CCECParser(void) { - Close(0); + Close(); m_communication->Close(); delete m_communication; } @@ -110,22 +110,10 @@ bool CCECParser::Open(const char *strPort, int iTimeoutMs /* = 10000 */) return false; } -bool CCECParser::Close(int iTimeoutMs /* = 2000 */) +void CCECParser::Close(void) { 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; + pthread_join(m_thread, NULL); } void *CCECParser::ThreadHandler(CCECParser *parser) diff --git a/src/lib/CECParser.h b/src/lib/CECParser.h index 1c72c1e..7b369df 100644 --- a/src/lib/CECParser.h +++ b/src/lib/CECParser.h @@ -54,7 +54,7 @@ namespace CEC virtual ~CCECParser(void); virtual bool Open(const char *strPort, int iTimeout = 10000); - virtual bool Close(int iTimeoutMs = 2000); + virtual void Close(void); virtual int FindDevices(std::vector &deviceList, const char *strDevicePath = NULL); virtual bool Ping(void); virtual bool StartBootloader(void); diff --git a/src/lib/CECParserC.cpp b/src/lib/CECParserC.cpp index 7deb982..5d7bf61 100644 --- a/src/lib/CECParserC.cpp +++ b/src/lib/CECParserC.cpp @@ -47,6 +47,13 @@ bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* return (cec_parser != NULL); } +void cec_destroy(void) +{ + cec_close(); + delete cec_parser; + cec_parser = NULL; +} + bool cec_open(const char *strPort, int iTimeout) { if (cec_parser) @@ -54,15 +61,10 @@ bool cec_open(const char *strPort, int iTimeout) return false; } -bool cec_close(int iTimeout) +void cec_close(void) { - bool bReturn = false; if (cec_parser) - bReturn = cec_parser->Close(iTimeout); - - delete cec_parser; - cec_parser = NULL; - return bReturn; + cec_parser->Close(); } bool cec_ping(void) diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 37df94d..458c734 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -263,7 +263,8 @@ int main (int argc, char *argv[]) CCondition::Sleep(50); } - parser->PowerOffDevices(CECDEVICE_TV); + parser->PowerOffDevices(CECDEVICE_BROADCAST); + parser->Close(); flush_log(parser); UnloadLibCec(parser); return 0; -- 2.34.1