Merge branch 'master' into release
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 5 Oct 2011 22:20:34 +0000 (00:20 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 5 Oct 2011 22:20:34 +0000 (00:20 +0200)
14 files changed:
ChangeLog
debian/changelog
include/CECExportsC.h
include/CECExportsCpp.h
project/libcec.vcxproj
project/testclient.vcxproj
src/lib/AdapterCommunication.cpp
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/platform/threads.cpp
src/lib/platform/threads.h
src/testclient/main.cpp

index 793462578b1a4f641913b3613386dd165b1914e3..c96e49ade06d505d3b2a52ff8254bc49cbcf4b78 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+libcec (0.4-3) unstable; urgency=low
+
+  * fixed reconnect
+  * fixed some threading related bugs
+  * fixed deadlock on exit
+  * fixed wrongly reported physical address
+
+ -- Pulse-Eight Packaging <packaging@pulse-eight.com>  Thu, 06 Oct 2011 00:19:00 +0200
+
 libcec (0.4-2) unstable; urgency=low
 
   * fixed int parameter sizes and some signed/unsigned warnings
index 793462578b1a4f641913b3613386dd165b1914e3..c96e49ade06d505d3b2a52ff8254bc49cbcf4b78 100644 (file)
@@ -1,3 +1,12 @@
+libcec (0.4-3) unstable; urgency=low
+
+  * fixed reconnect
+  * fixed some threading related bugs
+  * fixed deadlock on exit
+  * fixed wrongly reported physical address
+
+ -- Pulse-Eight Packaging <packaging@pulse-eight.com>  Thu, 06 Oct 2011 00:19:00 +0200
+
 libcec (0.4-2) unstable; urgency=low
 
   * fixed int parameter sizes and some signed/unsigned warnings
index b96beba585ff7eacfbb39d340b2ac52da96a60d5..2a6b6146c9c94d25162d7d6c40396d3d0ca3499e 100644 (file)
@@ -46,9 +46,9 @@ extern "C" {
  * @return True when initialised, false otherwise.
  */
 #ifdef __cplusplus
-extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
 #else
-extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
 #endif
 
 /*!
index f0a0ac9306040bb171d39160442b4d13b8a14cfe..d5903515b4d9603c54927f336c15015b08fe0be8 100644 (file)
@@ -122,7 +122,7 @@ namespace CEC
   };
 };
 
-extern DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+extern DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
 
 #if !defined(DLL_EXPORT)
 #if defined(_WIN32) || defined(_WIN64)
@@ -135,9 +135,9 @@ static int g_iLibCECInstanceCount = 0;
 /*!
  * @see cec_init
  */
-inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
+inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
 {
-  typedef void* (__cdecl*_CreateLibCec)(const char *, uint8_t, uint8_t);
+  typedef void* (__cdecl*_CreateLibCec)(const char *, uint8_t, uint16_t);
   _CreateLibCec CreateLibCec;
 
   if (!g_libCEC)
@@ -172,7 +172,7 @@ inline void UnloadLibCec(CEC::ICECAdapter *device)
 /*!
  * @see cec_init
  */
-inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
+inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS)
 {
   return (CEC::ICECAdapter*) CECCreate(strName, iLogicalAddress, iPhysicalAddress);
 };
index 65200d3fdc1604cbc064ff681cf11565f21ba94b..59ec3a3c1ace5c9b717c98c01d9848b8d0401e2e 100644 (file)
@@ -72,7 +72,7 @@
   </ImportGroup>
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <OutDir>$(SolutionDir)\..\</OutDir>
+    <OutDir>$(SolutionDir)..\</OutDir>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <TargetName>libcec</TargetName>
@@ -80,7 +80,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ExtensionsToDeleteOnClean>*.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.dll</ExtensionsToDeleteOnClean>
-    <IncludePath>$(SolutionDir)\..\include;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)..\include;$(IncludePath)</IncludePath>
     <IgnoreImportLibrary>true</IgnoreImportLibrary>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <TargetName>libcec</TargetName>
     <TargetExt>.dll</TargetExt>
     <ExtensionsToDeleteOnClean>*.cdf;*.cache;*.obj;*.ilk;*.resources;*.tlb;*.tli;*.tlh;*.tmp;*.rsp;*.pgc;*.pgd;*.meta;*.tlog;*.manifest;*.res;*.pch;*.exp;*.idb;*.rep;*.xdc;*.pdb;*_manifest.rc;*.bsc;*.sbr;*.xml;*.dll</ExtensionsToDeleteOnClean>
-    <IncludePath>$(SolutionDir)\..\include;$(IncludePath)</IncludePath>
+    <IncludePath>$(SolutionDir)..\include;$(IncludePath)</IncludePath>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <WarningLevel>Level4</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;DLL_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>$(SolutionDir)\..\src\lib\platform\pthread_win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(SolutionDir)..\src\lib\platform\pthread_win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <DisableSpecificWarnings>4996;4100;4309</DisableSpecificWarnings>
       <TreatWarningAsError>true</TreatWarningAsError>
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <OutputFile>$(SolutionDir)\..\$(TargetName)$(TargetExt)</OutputFile>
-      <AdditionalDependencies>%(AdditionalDependencies);setupapi.lib;..\src\lib\platform\pthread_win32\pthreadVC2d.lib</AdditionalDependencies>
+      <OutputFile>$(SolutionDir)..\libcec.dll</OutputFile>
+      <AdditionalDependencies>%(AdditionalDependencies);setupapi.lib;$(SolutionDir)..\src\lib\platform\pthread_win32\pthreadVC2d.lib</AdditionalDependencies>
       <IgnoreSpecificDefaultLibraries>libcmtd</IgnoreSpecificDefaultLibraries>
       <Version>2</Version>
     </Link>
       <Optimization>Full</Optimization>
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
-      <AdditionalIncludeDirectories>$(SolutionDir)\..\src\lib\platform\pthread_win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>_WIN32;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;DLL_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalIncludeDirectories>$(SolutionDir)..\src\lib\platform\pthread_win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;DLL_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <DisableSpecificWarnings>4100;4309</DisableSpecificWarnings>
       <TreatWarningAsError>true</TreatWarningAsError>
       <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
       <GenerateDebugInformation>false</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <OutputFile>$(SolutionDir)\..\libcec.dll</OutputFile>
-      <AdditionalDependencies>%(AdditionalDependencies);setupapi.lib;..\src\lib\platform\pthread_win32\pthreadVC2.lib</AdditionalDependencies>
+      <OutputFile>$(SolutionDir)..\libcec.dll</OutputFile>
+      <AdditionalDependencies>%(AdditionalDependencies);setupapi.lib;$(SolutionDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib</AdditionalDependencies>
       <IgnoreSpecificDefaultLibraries>libcmt</IgnoreSpecificDefaultLibraries>
     </Link>
   </ItemDefinitionGroup>
index 94c7f24c445f0fd7dd2d7a79ef451f5d2e67e3bb..42cc447cfa0e4c63cce815cb81e7f5e9b197cf75 100644 (file)
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <LinkIncremental>true</LinkIncremental>
-    <OutDir>$(SolutionDir)\..\</OutDir>
+    <OutDir>$(SolutionDir)..\</OutDir>
     <TargetName>cec-client</TargetName>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <LinkIncremental>false</LinkIncremental>
     <OutDir>$(SolutionDir)..\</OutDir>
+    <TargetName>cec-client</TargetName>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
@@ -59,8 +60,8 @@
     <Link>
       <SubSystem>Console</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>..\src\lib\platform\pthread_win32\pthreadVC2d.lib;%(AdditionalDependencies)</AdditionalDependencies>
-      <OutputFile>$(SolutionDir)\..\$(TargetName)$(TargetExt)</OutputFile>
+      <AdditionalDependencies>$(ProjectDir)..\src\lib\platform\pthread_win32\pthreadVC2d.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <OutputFile>$(SolutionDir)..\cec-client.exe</OutputFile>
     </Link>
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -80,7 +81,7 @@
       <GenerateDebugInformation>false</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
-      <AdditionalDependencies>$(SolutionDir)\..\src\lib\platform\pthread_win32\pthreadVC2.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>$(ProjectDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
index 4b0bcdd1b238ac26aa7882a8b4ebae1c62de90da..ae1a4e451c288fd4820cc3527efaf4084d67f20b 100644 (file)
@@ -40,6 +40,7 @@ using namespace std;
 using namespace CEC;
 
 CAdapterCommunication::CAdapterCommunication(CLibCEC *controller) :
+    m_port(NULL),
     m_controller(controller),
     m_inbuf(NULL),
     m_iInbufSize(0),
@@ -52,16 +53,19 @@ CAdapterCommunication::CAdapterCommunication(CLibCEC *controller) :
 
 CAdapterCommunication::~CAdapterCommunication(void)
 {
-  StopThread();
-  m_port->Close();
-  delete m_port;
-  m_port = NULL;
+  Close();
+
+  if (m_port)
+  {
+    delete m_port;
+    m_port = NULL;
+  }
 }
 
 bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint64_t iTimeoutMs /* = 10000 */)
 {
   CLockObject lock(&m_commMutex);
-  if (m_bStarted)
+  if (m_bStarted || !m_port)
     return false;
 
   if (!m_port->Open(strPort, iBaudRate))
@@ -78,14 +82,12 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38
   uint8_t buff[1024];
   m_port->Read(buff, sizeof(buff), 50);
 
-  CCondition::Sleep(CEC_SETTLE_DOWN_TIME);
-
-  m_bStop = false;
-  m_bStarted = true;
+  Sleep(CEC_SETTLE_DOWN_TIME);
 
   if (CreateThread())
   {
     m_controller->AddLog(CEC_LOG_DEBUG, "reader thread created");
+    m_bStarted = true;
     return true;
   }
   else
@@ -98,14 +100,20 @@ bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38
 
 void CAdapterCommunication::Close(void)
 {
+  CLockObject lock(&m_commMutex);
+  if (m_port)
+    m_port->Close();
+
   StopThread();
-  m_port->Close();
 }
 
 void *CAdapterCommunication::Process(void)
 {
+  m_controller->AddLog(CEC_LOG_DEBUG, "communication thread started");
+
   while (!m_bStop)
   {
+    CLockObject lock(&m_commMutex);
     if (!ReadFromDevice(250))
     {
       m_bStarted = false;
@@ -113,10 +121,12 @@ void *CAdapterCommunication::Process(void)
     }
 
     if (!m_bStop)
-      CCondition::Sleep(50);
+    {
+      lock.Leave();
+      Sleep(50);
+    }
   }
 
-  CLockObject lock(&m_commMutex);
   m_bStarted = false;
   return NULL;
 }
@@ -124,12 +134,10 @@ void *CAdapterCommunication::Process(void)
 bool CAdapterCommunication::ReadFromDevice(uint64_t iTimeout)
 {
   uint8_t buff[1024];
-  CLockObject lock(&m_commMutex);
   if (!m_port)
     return false;
 
   int32_t iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout);
-  lock.Leave();
   if (iBytesRead < 0 || iBytesRead > 256)
   {
     CStdString strError;
@@ -172,7 +180,7 @@ bool CAdapterCommunication::Write(const cec_frame &data)
 
   m_controller->AddLog(CEC_LOG_DEBUG, "command sent");
 
-  CCondition::Sleep((int) data.size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/ + 50 /* to be on the safe side */);
+  Sleep((int) data.size() * 24 /*data*/ + 5 /*start bit (4.5 ms)*/ + 50 /* to be on the safe side */);
 
   return true;
 }
index 258e16419f9b79dd3b7cb3e413e651085329748c..6750c87dba52a1a2c9dd8111755a51cb11c9bec4 100644 (file)
@@ -40,7 +40,7 @@
 using namespace CEC;
 using namespace std;
 
-CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
+CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
     m_physicaladdress(iPhysicalAddress),
     m_iLogicalAddress(iLogicalAddress),
     m_strDeviceName(strDeviceName),
@@ -95,7 +95,7 @@ void *CCECProcessor::Process(void)
     if (!m_bStop)
     {
       m_controller->CheckKeypressTimeout();
-      CCondition::Sleep(50);
+      Sleep(50);
     }
   }
 
index aea17c88d7853af010456dabf65aec7be96598ad..90db3bc28038e57141dc129942f5b4e5b3a70975 100644 (file)
@@ -46,7 +46,7 @@ namespace CEC
   class CCECProcessor : public CThread
   {
     public:
-      CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+      CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
       virtual ~CCECProcessor(void);
 
       virtual bool Start(void);
@@ -76,7 +76,7 @@ namespace CEC
       void ParseCurrentFrame(void);
 
       cec_frame                  m_currentframe;
-      int                        m_physicaladdress;
+      uint16_t                   m_physicaladdress;
       cec_logical_address        m_iLogicalAddress;
       CecBuffer<cec_frame>       m_frameBuffer;
       std::string                m_strDeviceName;
index 3437e451ee132f1a62e8da013825957d61fadd85..abc800c19cc528af2ff0029f43b6787a9f9a5625 100644 (file)
@@ -41,7 +41,7 @@
 using namespace std;
 using namespace CEC;
 
-CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) :
+CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) :
     m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN),
     m_buttontime(0)
 {
@@ -51,6 +51,7 @@ CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress
 
 CLibCEC::~CLibCEC(void)
 {
+  Close();
   delete m_cec;
   m_cec = NULL;
 
@@ -61,7 +62,10 @@ CLibCEC::~CLibCEC(void)
 bool CLibCEC::Open(const char *strPort, uint64_t iTimeoutMs /* = 10000 */)
 {
   if (!m_comm)
+  {
+    AddLog(CEC_LOG_ERROR, "no comm port");
     return false;
+  }
 
   if (m_comm->IsOpen())
   {
@@ -87,17 +91,9 @@ bool CLibCEC::Open(const char *strPort, uint64_t iTimeoutMs /* = 10000 */)
 void CLibCEC::Close(void)
 {
   if (m_cec)
-  {
     m_cec->StopThread();
-    delete m_cec;
-    m_cec = NULL;
-  }
   if (m_comm)
-  {
     m_comm->Close();
-    delete m_comm;
-    m_comm = NULL;
-  }
 }
 
 int CLibCEC::FindAdapters(std::vector<cec_adapter> &deviceList, const char *strDevicePath /* = NULL */)
@@ -233,7 +229,7 @@ void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode)
   m_buttontime = GetTimeMs();
 }
 
-DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /*= CEC::CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
+DECLSPEC 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));
 }
index cb9eb8c6e6e538691a098bf3581d076cbfff7174..29110717536445c8c86de320908ae156b6f1453f 100644 (file)
@@ -47,7 +47,7 @@ namespace CEC
      * ICECAdapter implementation
      */
     //@{
-      CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
+      CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
       virtual ~CLibCEC(void);
 
       virtual bool Open(const char *strPort, uint64_t iTimeout = 10000);
index 7c5b6ce4ed716de8cda00689de685482fca57eda..08a4c3b8884c39e9ce775212e8d5665a78175316 100644 (file)
@@ -63,7 +63,8 @@ void CMutex::Unlock(void)
 CLockObject::CLockObject(CMutex *mutex) :
   m_mutex(mutex)
 {
-  m_mutex->Lock();
+  if (m_mutex)
+    m_mutex->Lock();
 }
 
 CLockObject::~CLockObject(void)
@@ -74,12 +75,14 @@ CLockObject::~CLockObject(void)
 
 void CLockObject::Leave(void)
 {
-  m_mutex->Unlock();
+  if (m_mutex)
+    m_mutex->Unlock();
 }
 
 void CLockObject::Lock(void)
 {
-  m_mutex->Lock();
+  if (m_mutex)
+    m_mutex->Lock();
 }
 
 CCondition::CCondition(void)
@@ -93,34 +96,42 @@ CCondition::~CCondition(void)
   pthread_cond_destroy(&m_cond);
 }
 
-void CCondition::Signal(void)
+void CCondition::Broadcast(void)
 {
   pthread_cond_broadcast(&m_cond);
 }
 
+void CCondition::Signal(void)
+{
+  pthread_cond_signal(&m_cond);
+}
+
 bool CCondition::Wait(CMutex *mutex, int64_t iTimeout)
 {
   bool bReturn(false);
-  struct timespec abstime;
-  struct timeval now;
-  if (gettimeofday(&now, NULL) == 0)
+  sched_yield();
+  if (mutex)
   {
-    iTimeout       += now.tv_usec / 1000;
-    abstime.tv_sec  = now.tv_sec + (time_t)(iTimeout / 1000);
-    abstime.tv_nsec = (long)((iTimeout % (unsigned long)1000) * (unsigned long)1000000);
-    bReturn         = (pthread_cond_timedwait(&m_cond, &mutex->m_mutex, &abstime) == 0);
+    struct timespec abstime;
+    struct timeval now;
+    if (gettimeofday(&now, NULL) == 0)
+    {
+      iTimeout       += now.tv_usec / 1000;
+      abstime.tv_sec  = now.tv_sec + (time_t)(iTimeout / 1000);
+      abstime.tv_nsec = (long)((iTimeout % (unsigned long)1000) * (unsigned long)1000000);
+      bReturn         = (pthread_cond_timedwait(&m_cond, &mutex->m_mutex, &abstime) == 0);
+    }
   }
 
   return bReturn;
 }
 
-void CCondition::Sleep(int iTimeout)
+void CCondition::Sleep(int64_t iTimeout)
 {
-  sched_yield();
   CCondition w;
   CMutex m;
   CLockObject lock(&m);
-  w.Wait(&m, int64_t(iTimeout));
+  w.Wait(&m, iTimeout);
 }
 
 CThread::CThread(void) :
@@ -132,6 +143,7 @@ CThread::CThread(void) :
 CThread::~CThread(void)
 {
   m_bStop = true;
+  m_threadCondition.Broadcast();
   pthread_join(m_thread, NULL);
 }
 
@@ -139,10 +151,11 @@ bool CThread::CreateThread(void)
 {
   bool bReturn(false);
 
+  CLockObject lock(&m_threadMutex);
+  m_bStop = false;
   if (!m_bRunning && pthread_create(&m_thread, NULL, (void *(*) (void *))&CThread::ThreadHandler, (void *)this) == 0)
   {
     m_bRunning = true;
-    pthread_detach(m_thread);
     bReturn = true;
   }
 
@@ -151,14 +164,30 @@ bool CThread::CreateThread(void)
 
 void *CThread::ThreadHandler(CThread *thread)
 {
+  void *retVal = NULL;
+
   if (thread)
-    return thread->Process();
-  return NULL;
+    retVal = thread->Process();
+  thread->m_bRunning = false;
+
+  return retVal;
 }
 
-void CThread::StopThread(bool bWaitForExit /* = true */)
+bool CThread::StopThread(bool bWaitForExit /* = true */)
 {
+  bool bReturn(false);
   m_bStop = true;
+
+  m_threadCondition.Broadcast();
+  void *retVal;
   if (bWaitForExit)
-    pthread_join(m_thread, NULL);
+    bReturn = (pthread_join(m_thread, &retVal) == 0);
+
+  return bReturn;
+}
+
+bool CThread::Sleep(uint64_t iTimeout)
+{
+  CLockObject lock(&m_threadMutex);
+  return m_bStop ? false :m_threadCondition.Wait(&m_threadMutex, iTimeout);
 }
index 4ae5ac72557433464e96236e9821aee8ba414561..8b0729db4cf045dccbf3f1bf6777b5d33f6e0df2 100644 (file)
@@ -32,6 +32,7 @@
  */
 
 #include "os-dependent.h"
+#include <stdint.h>
 
 namespace CEC
 {
@@ -43,9 +44,10 @@ namespace CEC
     CCondition(void);
     virtual ~CCondition(void);
 
+    void Broadcast(void);
     void Signal(void);
     bool Wait(CMutex *mutex, int64_t iTimeout);
-    static void Sleep(int iTimeout);
+    static void Sleep(int64_t iTimeout);
 
   private:
     pthread_cond_t  m_cond;
@@ -87,14 +89,17 @@ namespace CEC
 
     virtual bool IsRunning(void) const { return m_bRunning; }
     virtual bool CreateThread(void);
-    virtual void StopThread(bool bWaitForExit = true);
+    virtual bool StopThread(bool bWaitForExit = true);
+    virtual bool Sleep(uint64_t iTimeout);
 
     static void *ThreadHandler(CThread *thread);
     virtual void *Process(void) = 0;
 
   protected:
-    pthread_t m_thread;
-    bool      m_bRunning;
-    bool      m_bStop;
+    pthread_t  m_thread;
+    CMutex     m_threadMutex;
+    CCondition m_threadCondition;
+    bool       m_bRunning;
+    bool       m_bStop;
   };
 };
index 983ba13736fff90d6b3b16c9fce8985206ead71c..813e22b4cd193501dd0f7447d26041e1f690c7e7 100644 (file)
@@ -240,7 +240,6 @@ int main (int argc, char *argv[])
   }
 
   cout << "cec device opened" << endl;
-  usleep(CEC_SETTLE_DOWN_TIME);
 
   parser->PowerOnDevices(CECDEVICE_TV);
   flush_log(parser);
@@ -289,6 +288,12 @@ int main (int argc, char *argv[])
         {
           parser->StartBootloader();
         }
+        else if (command == "r")
+        {
+          parser->Close();
+          parser->Open(strPort.c_str());
+          parser->SetActiveView();
+        }
         else if (command == "h" || command == "help")
         {
           show_console_help();