-.project
-.cproject
+/build
+/.cproject
+/.project
+*.dll
+*.exe
+*.exp
+*.ilk
+*.lib
*.manifest
+*.metagen
+*.ncb
+*.opensdf
+*.pdb
+*.suo
+*.user
aclocal.m4
autom4te.cache
Makefile.in
missing
-libcec.dll
-libcec.exp
-libcec.ilk
-libcec.lib
-libcec.pdb
-cec-client.exe
-cec-client.ilk
-cec-client.pdb
-CecSharpClient.exe
-CecSharpClient.pdb
-CecSharpClient.vshost.exe
-CecSharpClient.vshost.exe.manifest
-
-LibCecSharp.dll
-LibCecSharp.ilk
-LibCecSharp.pdb
-
-build
-
include/boost
project/bin
project/Debug/
+project/*.exe
project/Release/
project/ipch/
project/libcec.sdf
-project/libcec.suo
project/obj
project/Properties
-project/*.user
+
+project/x64
src/lib/.deps
src/lib/.libs
src/testclient/cec-client
src/testclient/*.o
+src/CecSharpTester/bin
src/CecSharpTester/obj
+src/libcec-wmc/bin
+src/libcec-wmc/obj
+
/dpinst-x86.exe
/dpinst-amd64.exe
+libcec (1.4-2) unstable; urgency=low
+
+ * changed/added:
+ * added a firmware flash script for linux.
+ usage: ./support/cec-flash-device.sh /path/to/firware.hex
+ * refactored threading/locking - added windows native instead of
+ pthread-win32, so we can compile native x64 too
+ * check whether the adapter responds when connecting to it and report the
+ firmware version of the adapter after connecting
+ * moved create-installer.cmd to support/
+ * completely removed AM_SILENT_RULES
+ * interface changes:
+ * compile LibCecSharp against .NET framework 2.0 and sign the assembly
+ * fixed:
+ * only the key release events were sent, not keypresses, which appeared in
+ clients as laggy keypresses
+ * fixed reconnect after standby
+ * wait for active tranmission to finish when opening a connection to the
+ adapter. fixes initialisation errors
+ * set the default transmit timeout properly instead of using 0
+ * fixed possible deadlock because of a negative timeout in
+ CAdapterCommunication::WaitForTransmitSucceeded()
+ * fixed error message in cec-client (unable to open the device on port ...)
+ * exit cec-client after entering bootloader mode
+ * MSGCODE_START_BOOTLOADER doesn't respond with MSGCODE_COMMAND_ACCEPTED
+
+ -- Pulse-Eight Packaging <packaging@pulse-eight.com> Thu, 25 Jan 2012 23:28:00 +0100
+
libcec (1.4-1) unstable; urgency=low
* changed/added:
AC_INIT([libcec], 1:4:0)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
-AM_SILENT_RULES([yes])
-
AC_PROG_CXX
AC_PROG_LIBTOOL
+libcec (1.4-2) unstable; urgency=low
+
+ * changed/added:
+ * added a firmware flash script for linux.
+ usage: ./support/cec-flash-device.sh /path/to/firware.hex
+ * refactored threading/locking - added windows native instead of
+ pthread-win32, so we can compile native x64 too
+ * check whether the adapter responds when connecting to it and report the
+ firmware version of the adapter after connecting
+ * moved create-installer.cmd to support/
+ * completely removed AM_SILENT_RULES
+ * interface changes:
+ * compile LibCecSharp against .NET framework 2.0 and sign the assembly
+ * fixed:
+ * only the key release events were sent, not keypresses, which appeared in
+ clients as laggy keypresses
+ * fixed reconnect after standby
+ * wait for active tranmission to finish when opening a connection to the
+ adapter. fixes initialisation errors
+ * set the default transmit timeout properly instead of using 0
+ * fixed possible deadlock because of a negative timeout in
+ CAdapterCommunication::WaitForTransmitSucceeded()
+ * fixed error message in cec-client (unable to open the device on port ...)
+ * exit cec-client after entering bootloader mode
+ * MSGCODE_START_BOOTLOADER doesn't respond with MSGCODE_COMMAND_ACCEPTED
+
+ -- Pulse-Eight Packaging <packaging@pulse-eight.com> Thu, 25 Jan 2012 23:28:00 +0100
+
libcec (1.4-1) unstable; urgency=low
* changed/added:
+#pragma once
/*
* This file is part of the libCEC(R) library.
*
CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS, const char *strLib = NULL)
{
if (!g_libCEC)
+#if defined(_WIN64)
+ g_libCEC = LoadLibrary(strLib ? strLib : "libcec.x64.dll");
+#else
g_libCEC = LoadLibrary(strLib ? strLib : "libcec.dll");
+#endif
if (!g_libCEC)
return NULL;
CEC::ICECAdapter *LibCecInit(const char *strDeviceName, CEC::cec_device_type_list types, const char *strLib = NULL)
{
if (!g_libCEC)
+#if defined(_WIN64)
+ g_libCEC = LoadLibrary(strLib ? strLib : "libcec.x64.dll");
+#else
g_libCEC = LoadLibrary(strLib ? strLib : "libcec.dll");
+#endif
if (!g_libCEC)
return NULL;
#define ESCOFFSET 3
#define CEC_BUTTON_TIMEOUT 500
#define CEC_POWER_STATE_REFRESH_TIME 30000
+#define CEC_FW_VERSION_UNKNOWN 0xFFFF
#define CEC_DEFAULT_TRANSMIT_TIMEOUT 1000
#define CEC_DEFAULT_TRANSMIT_WAIT 2000
#define CEC_DEFAULT_TRANSMIT_RETRIES 1
+#define CEC_PING_ADAPTER_TRIES 5
+#define CEC_FW_VERSION_TRIES 5
#define CEC_MIN_LIB_VERSION 1
#define CEC_LIB_VERSION_MAJOR 1
+++ /dev/null
-
-Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual Studio 2010
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CecSharpClient", "..\src\CecSharpTester\CecSharpClient.csproj", "{47EF8EFE-5758-4E82-B9BA-F9B002F9C0D4}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|x86 = Debug|x86
- Release|x86 = Release|x86
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {47EF8EFE-5758-4E82-B9BA-F9B002F9C0D4}.Debug|x86.ActiveCfg = Debug|x86
- {47EF8EFE-5758-4E82-B9BA-F9B002F9C0D4}.Debug|x86.Build.0 = Debug|x86
- {47EF8EFE-5758-4E82-B9BA-F9B002F9C0D4}.Release|x86.ActiveCfg = Release|x86
- {47EF8EFE-5758-4E82-B9BA-F9B002F9C0D4}.Release|x86.Build.0 = Release|x86
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
--- /dev/null
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CecSharpTester", "..\src\CecSharpTester\CecSharpTester.csproj", "{B6A7F3A9-F47C-41E5-9754-0BFF233B1172}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibCecSharp", "LibCecSharp.vcproj", "{E54D4581-CD59-4687-BB10-694B8192EABA}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B6A7F3A9-F47C-41E5-9754-0BFF233B1172}.Debug|x64.ActiveCfg = Debug|x64
+ {B6A7F3A9-F47C-41E5-9754-0BFF233B1172}.Debug|x64.Build.0 = Debug|x64
+ {B6A7F3A9-F47C-41E5-9754-0BFF233B1172}.Debug|x86.ActiveCfg = Debug|x86
+ {B6A7F3A9-F47C-41E5-9754-0BFF233B1172}.Debug|x86.Build.0 = Debug|x86
+ {B6A7F3A9-F47C-41E5-9754-0BFF233B1172}.Release|x64.ActiveCfg = Release|x64
+ {B6A7F3A9-F47C-41E5-9754-0BFF233B1172}.Release|x64.Build.0 = Release|x64
+ {B6A7F3A9-F47C-41E5-9754-0BFF233B1172}.Release|x86.ActiveCfg = Release|x86
+ {B6A7F3A9-F47C-41E5-9754-0BFF233B1172}.Release|x86.Build.0 = Release|x86
+ {E54D4581-CD59-4687-BB10-694B8192EABA}.Debug|x64.ActiveCfg = Debug|x64
+ {E54D4581-CD59-4687-BB10-694B8192EABA}.Debug|x64.Build.0 = Debug|x64
+ {E54D4581-CD59-4687-BB10-694B8192EABA}.Debug|x86.ActiveCfg = Debug|Win32
+ {E54D4581-CD59-4687-BB10-694B8192EABA}.Debug|x86.Build.0 = Debug|Win32
+ {E54D4581-CD59-4687-BB10-694B8192EABA}.Release|x64.ActiveCfg = Release|x64
+ {E54D4581-CD59-4687-BB10-694B8192EABA}.Release|x64.Build.0 = Release|x64
+ {E54D4581-CD59-4687-BB10-694B8192EABA}.Release|x86.ActiveCfg = Release|Win32
+ {E54D4581-CD59-4687-BB10-694B8192EABA}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
--- /dev/null
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9,00"
+ Name="LibCecSharp"
+ ProjectGUID="{E54D4581-CD59-4687-BB10-694B8192EABA}"
+ RootNamespace="LibCecSharp"
+ Keyword="ManagedCProj"
+ AssemblyReferenceSearchPaths=""$(SolutionDir)..""
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ <Platform
+ Name="x64"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)..\build\"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ ManagedExtensions="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=""$(SolutionDir)..\include";"$(SolutionDir)..\src\lib\platform\windows""
+ PreprocessorDefinitions="_DEBUG"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ WarnAsError="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="$(OutDir)libcec.lib"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ AssemblyDebug="1"
+ TargetMachine="1"
+ KeyFile="$(SolutionDir)LibCecSharp-dev.snk"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|x64"
+ OutputDirectory="$(SolutionDir)..\build\"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ ManagedExtensions="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=""$(SolutionDir)..\include";"$(SolutionDir)..\src\lib\platform\windows""
+ PreprocessorDefinitions="_DEBUG"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ WarnAsError="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="$(OutDir)libcec.x64.lib"
+ OutputFile="$(OutDir)\$(ProjectName).x64.dll"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ AssemblyDebug="1"
+ TargetMachine="17"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)..\build\"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ ManagedExtensions="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""$(SolutionDir)..\include";"$(SolutionDir)..\src\lib\platform\windows""
+ PreprocessorDefinitions="NDEBUG"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ WarnAsError="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="$(OutDir)libcec.lib"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ TargetMachine="1"
+ KeyFile="$(SolutionDir)LibCecSharp-dev.snk"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|x64"
+ OutputDirectory="$(SolutionDir)..\build\"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ ManagedExtensions="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ AdditionalIncludeDirectories=""$(SolutionDir)..\include";"$(SolutionDir)..\src\lib\platform\windows""
+ PreprocessorDefinitions="NDEBUG"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ WarnAsError="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="$(OutDir)libcec.x64.lib"
+ KeyFile="$(SolutionDir)LibCecSharp-dev.snk"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ <AssemblyReference
+ RelativePath="System.dll"
+ AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
+ MinFrameworkVersion="131072"
+ />
+ <AssemblyReference
+ RelativePath="System.Data.dll"
+ AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86"
+ MinFrameworkVersion="131072"
+ />
+ <AssemblyReference
+ RelativePath="System.XML.dll"
+ AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
+ MinFrameworkVersion="131072"
+ />
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="..\src\LibCecSharp\AssemblyInfo.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\src\LibCecSharp\LibCecSharp.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath="..\include\cec.h"
+ >
+ </File>
+ <File
+ RelativePath="..\include\cectypes.h"
+ >
+ </File>
+ <File
+ RelativePath="..\src\LibCecSharp\resource.h"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug|Win32">
- <Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <ProjectGuid>{1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}</ProjectGuid>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <Keyword>ManagedCProj</Keyword>
- <RootNamespace>LibCecSharp</RootNamespace>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseDebugLibraries>true</UseDebugLibraries>
- <CLRSupport>true</CLRSupport>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseDebugLibraries>false</UseDebugLibraries>
- <CLRSupport>true</CLRSupport>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
- <ImportGroup Label="ExtensionSettings">
- </ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <LinkIncremental>true</LinkIncremental>
- <IncludePath>$(SolutionDir)\..\include;$(IncludePath)</IncludePath>
- <TargetName>$(ProjectName)</TargetName>
- <OutDir>$(SolutionDir)..\</OutDir>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <LinkIncremental>false</LinkIncremental>
- <IncludePath>$(SolutionDir)\..\include;$(IncludePath)</IncludePath>
- </PropertyGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </ClCompile>
- <Link>
- <GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalDependencies>
- </AdditionalDependencies>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <PrecompiledHeader>NotUsing</PrecompiledHeader>
- </ClCompile>
- <Link>
- <GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalDependencies>
- </AdditionalDependencies>
- </Link>
- </ItemDefinitionGroup>
- <ItemGroup>
- <Reference Include="System" />
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="..\include\cec.h" />
- <ClInclude Include="..\include\cectypes.h" />
- <ClInclude Include="..\src\LibCecSharp\resource.h" />
- <ClInclude Include="..\src\LibCecSharp\Stdafx.h" />
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="..\src\LibCecSharp\AssemblyInfo.cpp" />
- <ClCompile Include="..\src\LibCecSharp\LibCecSharp.cpp" />
- <ClCompile Include="..\src\LibCecSharp\Stdafx.cpp" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="libcec.vcxproj">
- <Project>{c04b0fb1-667d-4f1c-bdae-a07cdffaaaa0}</Project>
- </ProjectReference>
- </ItemGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
- <ImportGroup Label="ExtensionTargets">
- </ImportGroup>
-</Project>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <ItemGroup>
- <Filter Include="Source Files">
- <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
- <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
- </Filter>
- <Filter Include="Header Files">
- <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
- <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
- </Filter>
- <Filter Include="Resource Files">
- <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
- <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
- </Filter>
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="..\src\LibCecSharp\resource.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="..\src\LibCecSharp\Stdafx.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="..\include\cec.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="..\include\cectypes.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- </ItemGroup>
- <ItemGroup>
- <ClCompile Include="..\src\LibCecSharp\AssemblyInfo.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\src\LibCecSharp\LibCecSharp.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\src\LibCecSharp\Stdafx.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- </ItemGroup>
-</Project>
\ No newline at end of file
+++ /dev/null
-@echo off
-
-set NSIS="C:\Program Files (x86)\NSIS\makensis.exe"
-set DDK=C:\WinDDK\7600.16385.1
-
-IF "%VS100COMNTOOLS%"=="" (
- set COMPILER="%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\VCExpress.exe"
-) ELSE IF EXIST "%VS100COMNTOOLS%\..\IDE\VCExpress.exe" (
- set COMPILER="%VS100COMNTOOLS%\..\IDE\VCExpress.exe"
-) ELSE IF EXIST "%VS100COMNTOOLS%\..\IDE\devenv.exe" (
- set COMPILER="%VS100COMNTOOLS%\..\IDE\devenv.exe"
-)
-
-rem Compile libCEC
-echo Cleaning libCEC
-%COMPILER% libcec.sln /clean Release
-
-echo Compiling libCEC
-%COMPILER% libcec.sln /build Release /project libcec
-echo Compiling cec-client
-%COMPILER% libcec.sln /build Release /project testclient
-echo Compiling LibCecSharp
-%COMPILER% libcec.sln /build Release /project LibCecSharp
-
-rem Copy driver installer
-echo Copying driver installer
-copy "%DDK%\redist\DIFx\dpinst\MultiLin\amd64\dpinst.exe" ..\dpinst-amd64.exe
-copy "%DDK%\redist\DIFx\dpinst\MultiLin\x86\dpinst.exe" ..\dpinst-x86.exe
-
-rem Run the NSIS installer
-echo Creating the installer
-%NSIS% /V1 /X"SetCompressor /FINAL lzma" "libCEC.nsi"
-
-echo The installer can be found here: libCEC-installer.exe
\ No newline at end of file
!include "x64.nsh"
Name "libCEC"
-OutFile "libCEC-installer.exe"
+OutFile "..\build\libCEC-installer.exe"
XPStyle on
InstallDir "$PROGRAMFILES\libCEC"
SetShellVarContext current
SectionIn RO
SectionIn 1 #section is in installtype Full
+
+ ; Copy to the installation directory
SetOutPath "$INSTDIR"
File "..\AUTHORS"
- File "..\cec-client.exe"
+ File /x dpinst*.exe "..\build\*.exe"
File "..\ChangeLog"
File "..\COPYING"
- File "..\libcec.dll"
- File "..\libcec.lib"
- File "Release\LibCecSharp.dll"
- File "..\pthreadVC2.dll"
File "..\README"
+ File "..\build\*.dll"
+ SetOutPath "$INSTDIR\x64"
+ File /nonfatal "..\build\x64\*"
; Copy to XBMC\system
ReadRegStr $1 HKCU "Software\XBMC" ""
${If} $1 != ""
SetOutPath "$1\system"
- File "..\libcec.dll"
+ File "..\build\libcec.dll"
${EndIf}
+ ; Copy the driver installer and .inf file
SetOutPath "$INSTDIR\driver"
- File "..\dpinst-amd64.exe"
- File "..\dpinst-x86.exe"
+ File "..\build\dpinst-amd64.exe"
+ File "..\build\dpinst-x86.exe"
File "..\OEM001.inf"
+
+ ; Copy the headers
SetOutPath "$INSTDIR\include"
File /r /x *.so "..\include\cec*.*"
+ ; Copy libcec.dll and libcec.x64.dll to the system directory
+ SetOutPath "$SYSDIR"
+ File "..\build\libcec.dll"
+ ${If} ${RunningX64}
+ File /nonfatal "..\build\x64\libcec.x64.dll"
+ ${EndIf}
+
;Store installation folder
WriteRegStr HKCU "Software\libCEC" "" $INSTDIR
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\CEC Test client.lnk" "$INSTDIR\cec-client.exe" \
"" "$INSTDIR\cec-client.exe" 0 SW_SHOWNORMAL \
"" "Start the CEC Test client."
+ ${If} ${RunningX64}
+ CreateShortCut "$SMPROGRAMS\$StartMenuFolder\CEC Test client (x64).lnk" "$INSTDIR\x64\cec-client.x64.exe" \
+ "" "$INSTDIR\cec-client.x64.exe" 0 SW_SHOWNORMAL \
+ "" "Start the CEC Test client (x64)."
+ ${EndIf}
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\Uninstall libCEC.lnk" "$INSTDIR\Uninstall.exe" \
"" "$INSTDIR\Uninstall.exe" 0 SW_SHOWNORMAL \
"" "Uninstall libCEC."
ExecWait '"$INSTDIR\driver\dpinst-x64.exe" /u "$INSTDIR\driver\OEM001.inf"'
${EndIf}
Delete "$INSTDIR\AUTHORS"
- Delete "$INSTDIR\cec-client.exe"
+ Delete "$INSTDIR\cec*.exe"
Delete "$INSTDIR\ChangeLog"
Delete "$INSTDIR\COPYING"
- Delete "$INSTDIR\libcec.dll"
- Delete "$INSTDIR\libcec.lib"
- Delete "$INSTDIR\libcec.pdb"
- Delete "$INSTDIR\LibCecSharp.dll"
- Delete "$INSTDIR\pthreadVC2.dll"
+ Delete "$INSTDIR\*.dll"
+ Delete "$INSTDIR\*.lib"
+ Delete "$INSTDIR\x64\*.dll"
+ Delete "$INSTDIR\x64\*.lib"
Delete "$INSTDIR\README"
Delete "$INSTDIR\driver\OEM001.inf"
Delete "$INSTDIR\driver\dpinst-amd64.exe"
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
Delete "$SMPROGRAMS\$StartMenuFolder\CEC Test client.lnk"
+ ${If} ${RunningX64}
+ Delete "$SMPROGRAMS\$StartMenuFolder\CEC Test client (x64).lnk"
+ ${EndIf}
Delete "$SMPROGRAMS\$StartMenuFolder\Uninstall libCEC.lnk"
Delete "$SMPROGRAMS\$StartMenuFolder\Visit Pulse-Eight.url"
RMDir "$SMPROGRAMS\$StartMenuFolder"
{C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0} = {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibCecSharp", "LibCecSharp.vcxproj", "{1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}"
- ProjectSection(ProjectDependencies) = postProject
- {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0} = {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}
- EndProjectSection
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
- Debug|x86 = Debug|x86
- Release|Any CPU = Release|Any CPU
- Release|Mixed Platforms = Release|Mixed Platforms
+ Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
- Release|x86 = Release|x86
+ Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|Any CPU.ActiveCfg = Debug|Win32
- {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
- {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|Win32.ActiveCfg = Debug|Win32
{C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|Win32.Build.0 = Debug|Win32
- {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|x86.ActiveCfg = Debug|Win32
- {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|Any CPU.ActiveCfg = Release|Win32
- {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|Mixed Platforms.ActiveCfg = Release|Win32
- {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|Mixed Platforms.Build.0 = Release|Win32
+ {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|x64.ActiveCfg = Debug|x64
+ {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Debug|x64.Build.0 = Debug|x64
{C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|Win32.ActiveCfg = Release|Win32
{C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|Win32.Build.0 = Release|Win32
- {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|x86.ActiveCfg = Release|Win32
- {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|Any CPU.ActiveCfg = Debug|Win32
- {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
- {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|Mixed Platforms.Build.0 = Debug|Win32
+ {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|x64.ActiveCfg = Release|x64
+ {C04B0FB1-667D-4F1C-BDAE-A07CDFFAAAA0}.Release|x64.Build.0 = Release|x64
{F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|Win32.ActiveCfg = Debug|Win32
{F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|Win32.Build.0 = Debug|Win32
- {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|x86.ActiveCfg = Debug|Win32
- {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|Any CPU.ActiveCfg = Release|Win32
- {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|Mixed Platforms.ActiveCfg = Release|Win32
- {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|Mixed Platforms.Build.0 = Release|Win32
+ {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|x64.ActiveCfg = Debug|x64
+ {F01222BF-6B3D-43BD-B254-434031CB9887}.Debug|x64.Build.0 = Debug|x64
{F01222BF-6B3D-43BD-B254-434031CB9887}.Release|Win32.ActiveCfg = Release|Win32
{F01222BF-6B3D-43BD-B254-434031CB9887}.Release|Win32.Build.0 = Release|Win32
- {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|x86.ActiveCfg = Release|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|Any CPU.ActiveCfg = Debug|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|Mixed Platforms.Build.0 = Debug|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|Win32.ActiveCfg = Debug|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|Win32.Build.0 = Debug|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Debug|x86.ActiveCfg = Debug|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|Any CPU.ActiveCfg = Release|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|Mixed Platforms.ActiveCfg = Release|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|Mixed Platforms.Build.0 = Release|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|Win32.ActiveCfg = Release|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|Win32.Build.0 = Release|Win32
- {1AC27FBD-653A-4F5F-ADBC-2A8FD074EEB7}.Release|x86.ActiveCfg = Release|Win32
+ {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|x64.ActiveCfg = Release|x64
+ {F01222BF-6B3D-43BD-B254-434031CB9887}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\include\cec.h" />
<ClInclude Include="..\include\cecc.h" />
<ClInclude Include="..\include\cecloader.h" />
<ClInclude Include="..\include\cectypes.h" />
- <ClInclude Include="..\src\lib\AdapterCommunication.h" />
- <ClInclude Include="..\src\lib\AdapterDetection.h" />
+ <ClInclude Include="..\src\lib\adapter\AdapterCommunication.h" />
+ <ClInclude Include="..\src\lib\adapter\AdapterDetection.h" />
+ <ClInclude Include="..\src\lib\adapter\AdapterMessage.h" />
<ClInclude Include="..\src\lib\CECProcessor.h" />
<ClInclude Include="..\src\lib\devices\CECAudioSystem.h" />
<ClInclude Include="..\src\lib\devices\CECBusDevice.h" />
<ClInclude Include="..\src\lib\implementations\SLCommandHandler.h" />
<ClInclude Include="..\src\lib\implementations\VLCommandHandler.h" />
<ClInclude Include="..\src\lib\LibCEC.h" />
- <ClInclude Include="..\src\lib\platform\baudrate.h" />
- <ClInclude Include="..\src\lib\platform\os-dependent.h" />
- <ClInclude Include="..\src\lib\platform\pthread_win32\pthread.h" />
- <ClInclude Include="..\src\lib\platform\pthread_win32\sched.h" />
- <ClInclude Include="..\src\lib\platform\pthread_win32\semaphore.h" />
- <ClInclude Include="..\src\lib\platform\serialport.h" />
- <ClInclude Include="..\src\lib\platform\threads.h" />
+ <ClInclude Include="..\src\lib\platform\buffer.h" />
+ <ClInclude Include="..\src\lib\platform\os.h" />
+ <ClInclude Include="..\src\lib\platform\serialport\baudrate.h" />
+ <ClInclude Include="..\src\lib\platform\serialport\serialport.h" />
+ <ClInclude Include="..\src\lib\platform\StdString.h" />
+ <ClInclude Include="..\src\lib\platform\threads\mutex.h" />
+ <ClInclude Include="..\src\lib\platform\threads\threads.h" />
<ClInclude Include="..\src\lib\platform\timeutils.h" />
- <ClInclude Include="..\src\lib\platform\windows\dlfcn-win32.h" />
- <ClInclude Include="..\src\lib\platform\windows\os_windows.h" />
- <ClInclude Include="..\src\lib\util\buffer.h" />
- <ClInclude Include="..\src\lib\util\StdString.h" />
- <ClInclude Include="resource.h" />
+ <ClInclude Include="..\src\lib\platform\windows\os-threads.h" />
+ <ClInclude Include="..\src\lib\platform\windows\os-types.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\src\lib\AdapterCommunication.cpp" />
- <ClCompile Include="..\src\lib\AdapterDetection.cpp" />
+ <ClCompile Include="..\src\lib\adapter\AdapterCommunication.cpp" />
+ <ClCompile Include="..\src\lib\adapter\AdapterDetection.cpp" />
<ClCompile Include="..\src\lib\CECProcessor.cpp" />
<ClCompile Include="..\src\lib\devices\CECAudioSystem.cpp" />
<ClCompile Include="..\src\lib\devices\CECBusDevice.cpp" />
<ClCompile Include="..\src\lib\LibCEC.cpp" />
<ClCompile Include="..\src\lib\LibCECC.cpp" />
<ClCompile Include="..\src\lib\LibCECDll.cpp" />
- <ClCompile Include="..\src\lib\platform\threads.cpp" />
- <ClCompile Include="..\src\lib\platform\windows\dlfcn-win32.cpp" />
- <ClCompile Include="..\src\lib\platform\windows\os_windows.cpp" />
<ClCompile Include="..\src\lib\platform\windows\serialport.cpp" />
</ItemGroup>
<ItemGroup>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <OutDir>$(SolutionDir)..\</OutDir>
+ <OutDir>$(SolutionDir)..\build\</OutDir>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <OutDir>$(SolutionDir)..\build\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<TargetName>libcec</TargetName>
- <TargetExt>.dll</TargetExt>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <TargetName>$(ProjectName).x64</TargetName>
</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>
- <IgnoreImportLibrary>false</IgnoreImportLibrary>
- <LinkIncremental>true</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <IncludePath>$(SolutionDir)..\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <OutDir>$(SolutionDir)..\</OutDir>
+ <OutDir>$(SolutionDir)..\build\</OutDir>
<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>
- <LinkIncremental>true</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <OutDir>$(SolutionDir)..\build\</OutDir>
+ <TargetName>$(ProjectName).x64</TargetName>
+ <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;$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <DisableSpecificWarnings>4996;4100;4309;4505</DisableSpecificWarnings>
+ <PreprocessorDefinitions>_USE_32BIT_TIME_T;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;DLL_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <DisableSpecificWarnings>
+ </DisableSpecificWarnings>
<TreatWarningAsError>true</TreatWarningAsError>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <OutputFile>$(SolutionDir)..\libcec.dll</OutputFile>
- <AdditionalDependencies>%(AdditionalDependencies);setupapi.lib;$(SolutionDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib</AdditionalDependencies>
- <IgnoreSpecificDefaultLibraries>libcmtd</IgnoreSpecificDefaultLibraries>
<Version>
</Version>
</Link>
</ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <WarningLevel>Level4</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>_WIN64;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;DLL_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <DisableSpecificWarnings>
+ </DisableSpecificWarnings>
+ <TreatWarningAsError>true</TreatWarningAsError>
+ </ClCompile>
+ <Link>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ <IgnoreSpecificDefaultLibraries>
+ </IgnoreSpecificDefaultLibraries>
+ <Version>
+ </Version>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(SolutionDir)..\src\lib\platform\pthread_win32;$(SolutionDir)..\include;%(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>
+ <PreprocessorDefinitions>_USE_32BIT_TIME_T;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;DLL_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <DisableSpecificWarnings>
+ </DisableSpecificWarnings>
+ <TreatWarningAsError>true</TreatWarningAsError>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <Version>
+ </Version>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level4</WarningLevel>
+ <Optimization>Full</Optimization>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>_WIN64;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;DLL_EXPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <DisableSpecificWarnings>
+ </DisableSpecificWarnings>
<TreatWarningAsError>true</TreatWarningAsError>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
- <OutputFile>$(SolutionDir)..\libcec.dll</OutputFile>
- <AdditionalDependencies>%(AdditionalDependencies);setupapi.lib;$(SolutionDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib</AdditionalDependencies>
- <IgnoreSpecificDefaultLibraries>libcmt</IgnoreSpecificDefaultLibraries>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
+ <IgnoreSpecificDefaultLibraries>
+ </IgnoreSpecificDefaultLibraries>
<Version>
</Version>
</Link>
+ <ProjectReference />
+ <Lib>
+ <TargetMachine>MachineX64</TargetMachine>
+ <TreatLibWarningAsErrors>true</TreatLibWarningAsErrors>
+ <SubSystem>Windows</SubSystem>
+ </Lib>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
- <Filter Include="util">
- <UniqueIdentifier>{4171e8da-4c9d-40dd-97a3-755ba5535ca6}</UniqueIdentifier>
- </Filter>
<Filter Include="platform">
<UniqueIdentifier>{cc48ddc0-be11-43ec-a805-3a9434f443ed}</UniqueIdentifier>
</Filter>
<Filter Include="devices">
<UniqueIdentifier>{bfc43a58-636d-4c1a-b191-486cb8509c7c}</UniqueIdentifier>
</Filter>
+ <Filter Include="platform\windows">
+ <UniqueIdentifier>{fa3d5953-d288-45e9-93f4-8419e6b701c7}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="platform\serialport">
+ <UniqueIdentifier>{e3945145-efa2-4393-b201-f50e1e775008}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="platform\threads">
+ <UniqueIdentifier>{38a27e9e-86ad-46f6-a4fb-e1e524267b74}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="adapter">
+ <UniqueIdentifier>{51614b77-8a0e-47a8-8500-5beb0fd12d49}</UniqueIdentifier>
+ </Filter>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="..\src\lib\util\buffer.h">
- <Filter>util</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\util\StdString.h">
- <Filter>util</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\AdapterCommunication.h" />
- <ClInclude Include="..\src\lib\AdapterDetection.h" />
<ClInclude Include="..\src\lib\CECProcessor.h" />
<ClInclude Include="..\src\lib\LibCEC.h" />
- <ClInclude Include="..\src\lib\platform\baudrate.h">
- <Filter>platform</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\platform\os-dependent.h">
- <Filter>platform</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\platform\serialport.h">
- <Filter>platform</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\platform\threads.h">
- <Filter>platform</Filter>
- </ClInclude>
<ClInclude Include="..\src\lib\platform\timeutils.h">
<Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\platform\windows\dlfcn-win32.h">
- <Filter>platform</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\platform\windows\os_windows.h">
- <Filter>platform</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\platform\pthread_win32\pthread.h">
- <Filter>platform</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\platform\pthread_win32\sched.h">
- <Filter>platform</Filter>
- </ClInclude>
- <ClInclude Include="..\src\lib\platform\pthread_win32\semaphore.h">
- <Filter>platform</Filter>
- </ClInclude>
<ClInclude Include="..\include\cec.h">
<Filter>exports</Filter>
</ClInclude>
<ClInclude Include="..\src\lib\devices\CECBusDevice.h">
<Filter>devices</Filter>
</ClInclude>
- <ClInclude Include="resource.h" />
<ClInclude Include="..\src\lib\implementations\VLCommandHandler.h">
<Filter>implementations</Filter>
</ClInclude>
<ClInclude Include="..\src\lib\devices\CECTV.h">
<Filter>devices</Filter>
</ClInclude>
+ <ClInclude Include="..\src\lib\platform\os.h">
+ <Filter>platform</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\windows\os-threads.h">
+ <Filter>platform\windows</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\windows\os-types.h">
+ <Filter>platform\windows</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\serialport\baudrate.h">
+ <Filter>platform\serialport</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\serialport\serialport.h">
+ <Filter>platform\serialport</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\threads\mutex.h">
+ <Filter>platform\threads</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\threads\threads.h">
+ <Filter>platform\threads</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\buffer.h">
+ <Filter>platform</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\StdString.h">
+ <Filter>platform</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\adapter\AdapterCommunication.h">
+ <Filter>adapter</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\adapter\AdapterDetection.h">
+ <Filter>adapter</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\adapter\AdapterMessage.h">
+ <Filter>adapter</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\src\lib\AdapterCommunication.cpp" />
- <ClCompile Include="..\src\lib\AdapterDetection.cpp" />
<ClCompile Include="..\src\lib\CECProcessor.cpp" />
<ClCompile Include="..\src\lib\LibCEC.cpp" />
<ClCompile Include="..\src\lib\LibCECC.cpp" />
<ClCompile Include="..\src\lib\LibCECDll.cpp" />
- <ClCompile Include="..\src\lib\platform\threads.cpp">
- <Filter>platform</Filter>
- </ClCompile>
- <ClCompile Include="..\src\lib\platform\windows\dlfcn-win32.cpp">
- <Filter>platform</Filter>
- </ClCompile>
- <ClCompile Include="..\src\lib\platform\windows\os_windows.cpp">
- <Filter>platform</Filter>
- </ClCompile>
- <ClCompile Include="..\src\lib\platform\windows\serialport.cpp">
- <Filter>platform</Filter>
- </ClCompile>
<ClCompile Include="..\src\lib\implementations\ANCommandHandler.cpp">
<Filter>implementations</Filter>
</ClCompile>
<ClCompile Include="..\src\lib\devices\CECTV.cpp">
<Filter>devices</Filter>
</ClCompile>
+ <ClCompile Include="..\src\lib\platform\windows\serialport.cpp">
+ <Filter>platform\serialport</Filter>
+ </ClCompile>
+ <ClCompile Include="..\src\lib\adapter\AdapterCommunication.cpp">
+ <Filter>adapter</Filter>
+ </ClCompile>
+ <ClCompile Include="..\src\lib\adapter\AdapterDetection.cpp">
+ <Filter>adapter</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="libcec.rc" />
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{F01222BF-6B3D-43BD-B254-434031CB9887}</ProjectGuid>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Application</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <LinkIncremental>true</LinkIncremental>
- <OutDir>$(SolutionDir)..\</OutDir>
+ <OutDir>$(SolutionDir)..\build\</OutDir>
<TargetName>cec-client</TargetName>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <OutDir>$(SolutionDir)..\build\</OutDir>
+ <TargetName>cec-client.x64</TargetName>
+ </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <LinkIncremental>true</LinkIncremental>
- <OutDir>$(SolutionDir)..\</OutDir>
+ <OutDir>$(SolutionDir)..\build\</OutDir>
<TargetName>cec-client</TargetName>
</PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <OutDir>$(SolutionDir)..\build\</OutDir>
+ <TargetName>cec-client.x64</TargetName>
+ </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>WIN32;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>_USE_32BIT_TIME_T;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatWarningAsError>true</TreatWarningAsError>
- <DisableSpecificWarnings>4100;4309;4505</DisableSpecificWarnings>
+ <DisableSpecificWarnings>
+ </DisableSpecificWarnings>
<AdditionalIncludeDirectories>$(SolutiontDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalDependencies>$(ProjectDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <OutputFile>$(SolutionDir)..\cec-client.exe</OutputFile>
+ <Version>
+ </Version>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <WarningLevel>Level4</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <PreprocessorDefinitions>_WIN64;_DEBUG;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <TreatWarningAsError>true</TreatWarningAsError>
+ <DisableSpecificWarnings>
+ </DisableSpecificWarnings>
+ <AdditionalIncludeDirectories>$(SolutiontDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
<Version>
</Version>
</Link>
<Optimization>Full</Optimization>
<FunctionLevelLinking>false</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
- <PreprocessorDefinitions>_WIN32;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_USE_32BIT_TIME_T;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;__WINDOWS__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>_USE_32BIT_TIME_T;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <TreatWarningAsError>true</TreatWarningAsError>
+ <DisableSpecificWarnings>
+ </DisableSpecificWarnings>
+ <AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <Version>
+ </Version>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <WarningLevel>Level4</WarningLevel>
+ <PrecompiledHeader>
+ </PrecompiledHeader>
+ <Optimization>Full</Optimization>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>_WIN64;_CRT_SECURE_NO_WARNINGS;_WINSOCKAPI_;__STDC_CONSTANT_MACROS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<TreatWarningAsError>true</TreatWarningAsError>
- <DisableSpecificWarnings>4100;4309</DisableSpecificWarnings>
+ <DisableSpecificWarnings>
+ </DisableSpecificWarnings>
<AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
- <AdditionalDependencies>$(ProjectDir)..\src\lib\platform\pthread_win32\pthreadVC2.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>
+ </AdditionalDependencies>
<Version>
</Version>
</Link>
<ItemGroup>
<ClInclude Include="..\include\cec.h" />
<ClInclude Include="..\include\cecloader.h" />
- <ClInclude Include="..\src\lib\platform\os-dependent.h" />
- <ClInclude Include="..\src\lib\platform\threads.h" />
- <ClInclude Include="..\src\lib\platform\windows\os_windows.h" />
- <ClInclude Include="..\src\lib\util\StdString.h" />
- <ClInclude Include="resource1.h" />
+ <ClInclude Include="..\src\lib\platform\os.h" />
+ <ClInclude Include="..\src\lib\platform\threads\mutex.h" />
+ <ClInclude Include="..\src\lib\platform\threads\threads.h" />
+ <ClInclude Include="..\src\lib\platform\timeutils.h" />
+ <ClInclude Include="..\src\lib\platform\windows\dlfcn-win32.h" />
+ <ClInclude Include="..\src\lib\platform\windows\os-threads.h" />
+ <ClInclude Include="..\src\lib\platform\windows\os-types.h" />
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\src\lib\platform\threads.cpp" />
- <ClCompile Include="..\src\lib\platform\windows\os_windows.cpp" />
+ <ClCompile Include="..\src\lib\platform\windows\dlfcn-win32.cpp" />
<ClCompile Include="..\src\testclient\main.cpp" />
</ItemGroup>
<ItemGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
- <Filter Include="Source Files">
- <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
- <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ <Filter Include="exports">
+ <UniqueIdentifier>{cc0a01c1-e1e7-4af8-9656-fa9463140613}</UniqueIdentifier>
</Filter>
- <Filter Include="Header Files">
- <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
- <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ <Filter Include="platform">
+ <UniqueIdentifier>{f08c0a80-22d9-4bdd-90de-b9cf5fa88f99}</UniqueIdentifier>
</Filter>
- <Filter Include="Resource Files">
- <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
- <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
+ <Filter Include="platform\threads">
+ <UniqueIdentifier>{fb28e188-b2a5-48d3-9010-b56024b19850}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="platform\windows">
+ <UniqueIdentifier>{a8b22b54-3252-44fb-a499-e42f9bac0e15}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
- <ClInclude Include="..\src\lib\util\StdString.h">
- <Filter>Header Files</Filter>
+ <ClInclude Include="..\include\cec.h">
+ <Filter>exports</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\platform\threads.h">
- <Filter>Header Files</Filter>
+ <ClInclude Include="..\include\cecloader.h">
+ <Filter>exports</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\platform\os-dependent.h">
- <Filter>Header Files</Filter>
+ <ClInclude Include="..\src\lib\platform\os.h">
+ <Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\src\lib\platform\windows\os_windows.h">
- <Filter>Header Files</Filter>
+ <ClInclude Include="..\src\lib\platform\timeutils.h">
+ <Filter>platform</Filter>
</ClInclude>
- <ClInclude Include="..\include\cec.h">
- <Filter>Header Files</Filter>
+ <ClInclude Include="..\src\lib\platform\windows\dlfcn-win32.h">
+ <Filter>platform\windows</Filter>
</ClInclude>
- <ClInclude Include="..\include\cecloader.h">
- <Filter>Header Files</Filter>
+ <ClInclude Include="..\src\lib\platform\windows\os-threads.h">
+ <Filter>platform\windows</Filter>
</ClInclude>
- <ClInclude Include="resource1.h">
- <Filter>Header Files</Filter>
+ <ClInclude Include="..\src\lib\platform\windows\os-types.h">
+ <Filter>platform\windows</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\threads\mutex.h">
+ <Filter>platform\threads</Filter>
+ </ClInclude>
+ <ClInclude Include="..\src\lib\platform\threads\threads.h">
+ <Filter>platform\threads</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
- <ClCompile Include="..\src\testclient\main.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\src\lib\platform\threads.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\src\lib\platform\windows\os_windows.cpp">
- <Filter>Source Files</Filter>
+ <ClCompile Include="..\src\testclient\main.cpp" />
+ <ClCompile Include="..\src\lib\platform\windows\dlfcn-win32.cpp">
+ <Filter>platform\windows</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
- <ResourceCompile Include="testclient.rc">
- <Filter>Resource Files</Filter>
- </ResourceCompile>
+ <ResourceCompile Include="testclient.rc" />
</ItemGroup>
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Text;
namespace CecSharpClient
Console.WriteLine("CEC bus information");
Console.WriteLine("===================");
CecLogicalAddresses addresses = Lib.GetActiveDevices();
- for (int iPtr = 0; iPtr < addresses.Addresses.Count(); iPtr++)
+ for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++)
{
CecLogicalAddress address = (CecLogicalAddress)iPtr;
if (!addresses.IsSet(address))
<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
- <ProductVersion>8.0.30703</ProductVersion>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{47EF8EFE-5758-4E82-B9BA-F9B002F9C0D4}</ProjectGuid>
+ <ProjectGuid>{B6A7F3A9-F47C-41E5-9754-0BFF233B1172}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>CecSharpClient</RootNamespace>
- <AssemblyName>CecSharpClient</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
- <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <RootNamespace>CecSharpTester</RootNamespace>
+ <AssemblyName>CecSharpTester</AssemblyName>
+ <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
- <PlatformTarget>x86</PlatformTarget>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<DebugSymbols>true</DebugSymbols>
+ <OutputPath>..\..\build\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>..\..\</OutputPath>
+ <PlatformTarget>x64</PlatformTarget>
+ <ErrorReport>prompt</ErrorReport>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
+ <OutputPath>..\..\build\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>x64</PlatformTarget>
+ <ErrorReport>prompt</ErrorReport>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <DebugSymbols>true</DebugSymbols>
+ <OutputPath>..\..\build\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DebugType>full</DebugType>
+ <PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
- <PlatformTarget>x86</PlatformTarget>
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
+ <OutputPath>..\..\build\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="LibCecSharp, Version=1.3.2.0, Culture=neutral, processorArchitecture=x86">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\LibCecSharp.dll</HintPath>
- </Reference>
<Reference Include="System" />
- <Reference Include="System.Core" />
- <Reference Include="System.Xml.Linq" />
- <Reference Include="System.Data.DataSetExtensions" />
- <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
- <Compile Include="AssemblyInfo.cs" />
<Compile Include="CecSharpClient.cs" />
</ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\project\LibCecSharp.vcproj">
+ <Project>{E54D4581-CD59-4687-BB10-694B8192EABA}</Project>
+ <Name>LibCecSharp</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="Properties\" />
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Pulse-Eight Ltd.")]
[assembly: AssemblyProduct("CecSharpClient")]
-[assembly: AssemblyCopyright("Copyright (c) Pulse-Eight Ltd. 2012)")]
+[assembly: AssemblyCopyright("Copyright (c) Pulse-Eight Ltd. 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.4.0.0")]
-[assembly: AssemblyFileVersion("1.4.0.0")]
+[assembly: AssemblyVersion("1.4.1.0")]
+[assembly: AssemblyFileVersion("1.4.1.0")]
--- /dev/null
+<?xml version="1.0"?>
+<configuration>
+<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>
-#include "stdafx.h"
-
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
-//
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-//
[assembly:AssemblyTitleAttribute("LibCecSharp")];
[assembly:AssemblyDescriptionAttribute("")];
[assembly:AssemblyConfigurationAttribute("")];
[assembly:AssemblyTrademarkAttribute("")];
[assembly:AssemblyCultureAttribute("")];
-//
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the value or you can default the Revision and Build Numbers
-// by using the '*' as shown below:
-
-[assembly:AssemblyVersionAttribute("1.4.0.0")];
+[assembly:AssemblyVersionAttribute("1.4.1.0")];
[assembly:ComVisible(false)];
-
[assembly:CLSCompliantAttribute(true)];
-
[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
+[assembly:AssemblyKeyFile("LibCecSharp-dev.snk")];
* http://www.pulse-eight.net/
*/
-#include "stdafx.h"
#include <windows.h>
#include <vcclr.h>
#include <msclr/marshal.h>
+++ /dev/null
-// stdafx.cpp : source file that includes just the standard includes
-// LibCecSharp.pch will be the pre-compiled header
-// stdafx.obj will contain the pre-compiled type information
-
-#include "stdafx.h"
+++ /dev/null
-// stdafx.h : include file for standard system include files,
-// or project specific include files that are used frequently,
-// but are changed infrequently
-
-#pragma once
-
-
+++ /dev/null
-/*
- * This file is part of the libCEC(R) library.
- *
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
- * libCEC(R) is an original work, containing original code.
- *
- * libCEC(R) is a trademark of Pulse-Eight Limited.
- *
- * This program is dual-licensed; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- *
- * Alternatively, you can license this library under a commercial license,
- * please contact Pulse-Eight Licensing for more information.
- *
- * For more information contact:
- * Pulse-Eight Licensing <license@pulse-eight.com>
- * http://www.pulse-eight.com/
- * http://www.pulse-eight.net/
- */
-
-#include "AdapterCommunication.h"
-
-#include "CECProcessor.h"
-#include "platform/serialport.h"
-#include "util/StdString.h"
-#include "platform/timeutils.h"
-
-using namespace std;
-using namespace CEC;
-
-CCECAdapterMessage::CCECAdapterMessage(const cec_command &command)
-{
- clear();
-
- //set ack polarity to high when transmitting to the broadcast address
- //set ack polarity low when transmitting to any other address
- push_back(MSGSTART);
- push_escaped(MSGCODE_TRANSMIT_ACK_POLARITY);
- if (command.destination == CECDEVICE_BROADCAST)
- push_escaped(CEC_TRUE);
- else
- push_escaped(CEC_FALSE);
- push_back(MSGEND);
-
- // add source and destination
- push_back(MSGSTART);
- push_escaped(command.opcode_set == 0 ? (uint8_t)MSGCODE_TRANSMIT_EOM : (uint8_t)MSGCODE_TRANSMIT);
- push_back(((uint8_t)command.initiator << 4) + (uint8_t)command.destination);
- push_back(MSGEND);
-
- // add opcode
- if (command.opcode_set == 1)
- {
- push_back(MSGSTART);
- push_escaped(command.parameters.IsEmpty() ? (uint8_t)MSGCODE_TRANSMIT_EOM : (uint8_t)MSGCODE_TRANSMIT);
- push_back((uint8_t) command.opcode);
- push_back(MSGEND);
-
- // add parameters
- for (int8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
- {
- push_back(MSGSTART);
-
- if (iPtr == command.parameters.size - 1)
- push_escaped( MSGCODE_TRANSMIT_EOM);
- else
- push_escaped(MSGCODE_TRANSMIT);
-
- push_escaped(command.parameters[iPtr]);
-
- push_back(MSGEND);
- }
- }
-
- // set timeout
- transmit_timeout = command.transmit_timeout;
-}
-
-CCECAdapterMessage &CCECAdapterMessage::operator =(const CCECAdapterMessage &msg)
-{
- packet = msg.packet;
- state = msg.state;
- return *this;
-}
-
-CStdString CCECAdapterMessage::MessageCodeAsString(void) const
-{
- CStdString strMsg;
- switch (message())
- {
- case MSGCODE_NOTHING:
- strMsg = "NOTHING";
- break;
- case MSGCODE_PING:
- strMsg = "PING";
- break;
- case MSGCODE_TIMEOUT_ERROR:
- strMsg = "TIMEOUT";
- break;
- case MSGCODE_HIGH_ERROR:
- strMsg = "HIGH_ERROR";
- break;
- case MSGCODE_LOW_ERROR:
- strMsg = "LOW_ERROR";
- break;
- case MSGCODE_FRAME_START:
- strMsg = "FRAME_START";
- break;
- case MSGCODE_FRAME_DATA:
- strMsg = "FRAME_DATA";
- break;
- case MSGCODE_RECEIVE_FAILED:
- strMsg = "RECEIVE_FAILED";
- break;
- case MSGCODE_COMMAND_ACCEPTED:
- strMsg = "COMMAND_ACCEPTED";
- break;
- case MSGCODE_COMMAND_REJECTED:
- strMsg = "COMMAND_REJECTED";
- break;
- case MSGCODE_SET_ACK_MASK:
- strMsg = "SET_ACK_MASK";
- break;
- case MSGCODE_TRANSMIT:
- strMsg = "TRANSMIT";
- break;
- case MSGCODE_TRANSMIT_EOM:
- strMsg = "TRANSMIT_EOM";
- break;
- case MSGCODE_TRANSMIT_IDLETIME:
- strMsg = "TRANSMIT_IDLETIME";
- break;
- case MSGCODE_TRANSMIT_ACK_POLARITY:
- strMsg = "TRANSMIT_ACK_POLARITY";
- break;
- case MSGCODE_TRANSMIT_LINE_TIMEOUT:
- strMsg = "TRANSMIT_LINE_TIMEOUT";
- break;
- case MSGCODE_TRANSMIT_SUCCEEDED:
- strMsg = "TRANSMIT_SUCCEEDED";
- break;
- case MSGCODE_TRANSMIT_FAILED_LINE:
- strMsg = "TRANSMIT_FAILED_LINE";
- break;
- case MSGCODE_TRANSMIT_FAILED_ACK:
- strMsg = "TRANSMIT_FAILED_ACK";
- break;
- case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA:
- strMsg = "TRANSMIT_FAILED_TIMEOUT_DATA";
- break;
- case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE:
- strMsg = "TRANSMIT_FAILED_TIMEOUT_LINE";
- break;
- case MSGCODE_FIRMWARE_VERSION:
- strMsg = "FIRMWARE_VERSION";
- break;
- case MSGCODE_START_BOOTLOADER:
- strMsg = "START_BOOTLOADER";
- break;
- case MSGCODE_FRAME_EOM:
- strMsg = "FRAME_EOM";
- break;
- case MSGCODE_FRAME_ACK:
- strMsg = "FRAME_ACK";
- break;
- }
-
- return strMsg;
-}
-
-CStdString CCECAdapterMessage::ToString(void) const
-{
- CStdString strMsg;
- if (size() == 0)
- {
- strMsg = "empty message";
- }
- else
- {
- strMsg = MessageCodeAsString();
-
- switch (message())
- {
- case MSGCODE_TIMEOUT_ERROR:
- case MSGCODE_HIGH_ERROR:
- case MSGCODE_LOW_ERROR:
- {
- int iLine = (size() >= 3) ? (at(1) << 8) | at(2) : 0;
- uint32_t iTime = (size() >= 7) ? (at(3) << 24) | (at(4) << 16) | (at(5) << 8) | at(6) : 0;
- strMsg.AppendFormat(" line:%i", iLine);
- strMsg.AppendFormat(" time:%u", iTime);
- }
- break;
- case MSGCODE_FRAME_START:
- if (size() >= 2)
- strMsg.AppendFormat(" initiator:%1x destination:%1x ack:%s %s", initiator(), destination(), ack() ? "high" : "low", eom() ? "eom" : "");
- break;
- case MSGCODE_FRAME_DATA:
- if (size() >= 2)
- strMsg.AppendFormat(" %02x %s", at(1), eom() ? "eom" : "");
- break;
- default:
- break;
- }
- }
-
- return strMsg;
-}
-
-bool CCECAdapterMessage::is_error(void) const
-{
- cec_adapter_messagecode code = message();
- return (code == MSGCODE_HIGH_ERROR ||
- code == MSGCODE_LOW_ERROR ||
- code == MSGCODE_RECEIVE_FAILED ||
- code == MSGCODE_COMMAND_REJECTED ||
- code == MSGCODE_TRANSMIT_LINE_TIMEOUT ||
- code == MSGCODE_TRANSMIT_FAILED_LINE ||
- code == MSGCODE_TRANSMIT_FAILED_ACK ||
- code == MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA ||
- code == MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE);
-}
-
-void CCECAdapterMessage::push_escaped(uint8_t byte)
-{
- if (byte >= MSGESC)
- {
- push_back(MSGESC);
- push_back(byte - ESCOFFSET);
- }
- else
- push_back(byte);
-}
-
-CAdapterCommunication::CAdapterCommunication(CCECProcessor *processor) :
- m_port(NULL),
- m_processor(processor),
- m_iLineTimeout(0)
-{
- m_port = new CSerialPort;
-}
-
-CAdapterCommunication::~CAdapterCommunication(void)
-{
- Close();
-
- if (m_port)
- {
- delete m_port;
- m_port = NULL;
- }
-}
-
-bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
-{
- uint64_t iNow = GetTimeMs();
- uint64_t iTimeout = iNow + iTimeoutMs;
-
- CLockObject lock(&m_mutex);
-
- if (!m_port)
- {
- m_processor->AddLog(CEC_LOG_ERROR, "port is NULL");
- return false;
- }
-
- if (IsOpen())
- {
- m_processor->AddLog(CEC_LOG_ERROR, "port is already open");
- return true;
- }
-
- CStdString strError;
- bool bConnected(false);
- while (!bConnected && iNow < iTimeout)
- {
- if ((bConnected = m_port->Open(strPort, iBaudRate)) == false)
- {
- strError.Format("error opening serial port '%s': %s", strPort, m_port->GetError().c_str());
- Sleep(250);
- iNow = GetTimeMs();
- }
- }
-
- if (!bConnected)
- {
- m_processor->AddLog(CEC_LOG_ERROR, strError);
- return false;
- }
-
- m_processor->AddLog(CEC_LOG_DEBUG, "connection opened");
-
- //clear any input bytes
- uint8_t buff[1];
- while (m_port->Read(buff, 1, 5) == 1) {}
-
- if (CreateThread())
- {
- m_startCondition.Wait(&m_mutex);
- m_processor->AddLog(CEC_LOG_DEBUG, "communication thread started");
- return true;
- }
- else
- {
- m_processor->AddLog(CEC_LOG_DEBUG, "could not create a communication thread");
- }
-
- return false;
-}
-
-void CAdapterCommunication::Close(void)
-{
- CLockObject lock(&m_mutex);
- m_startCondition.Broadcast();
- m_rcvCondition.Broadcast();
- StopThread();
-}
-
-void *CAdapterCommunication::Process(void)
-{
- {
- CLockObject lock(&m_mutex);
- m_startCondition.Signal();
- }
-
- while (!IsStopped())
- {
- ReadFromDevice(50);
- Sleep(5);
- WriteNextCommand();
- }
-
- CCECAdapterMessage *msg;
- if (m_outBuffer.Pop(msg))
- msg->condition.Broadcast();
-
- return NULL;
-}
-
-bool CAdapterCommunication::ReadFromDevice(uint32_t iTimeout)
-{
- int32_t iBytesRead;
- uint8_t buff[1024];
- if (!m_port)
- return false;
-
- iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout);
- if (iBytesRead < 0 || iBytesRead > 256)
- {
- CStdString strError;
- strError.Format("error reading from serial port: %s", m_port->GetError().c_str());
- m_processor->AddLog(CEC_LOG_ERROR, strError);
- return false;
- }
- else if (iBytesRead > 0)
- AddData(buff, (uint8_t) iBytesRead);
-
- return iBytesRead > 0;
-}
-
-void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen)
-{
- CLockObject lock(&m_mutex);
- for (unsigned int iPtr = 0; iPtr < iLen; iPtr++)
- m_inBuffer.Push(data[iPtr]);
-
- m_rcvCondition.Signal();
-}
-
-void CAdapterCommunication::WriteNextCommand(void)
-{
- CCECAdapterMessage *msg;
- if (m_outBuffer.Pop(msg))
- SendMessageToAdapter(msg);
-}
-
-void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg)
-{
- CLockObject lock(&msg->mutex);
- if (m_port->Write(msg) != (int32_t) msg->size())
- {
- CStdString strError;
- strError.Format("error writing to serial port: %s", m_port->GetError().c_str());
- m_processor->AddLog(CEC_LOG_ERROR, strError);
- msg->state = ADAPTER_MESSAGE_STATE_ERROR;
- }
- else
- {
- m_processor->AddLog(CEC_LOG_DEBUG, "command sent");
- msg->state = ADAPTER_MESSAGE_STATE_SENT;
- }
- msg->condition.Signal();
-}
-
-bool CAdapterCommunication::Write(CCECAdapterMessage *data)
-{
- data->state = ADAPTER_MESSAGE_STATE_WAITING;
- m_outBuffer.Push(data);
- return true;
-}
-
-bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout)
-{
- CLockObject lock(&m_mutex);
-
- msg.clear();
- uint64_t iNow = GetTimeMs();
- uint64_t iTarget = iNow + iTimeout;
- bool bGotFullMessage(false);
- bool bNextIsEscaped(false);
- bool bGotStart(false);
-
- while(!bGotFullMessage && iNow < iTarget)
- {
- uint8_t buf = 0;
- if (!m_inBuffer.Pop(buf))
- {
- if (!m_rcvCondition.Wait(&m_mutex, (uint32_t) (iTarget - iNow)))
- return false;
- }
-
- if (!bGotStart)
- {
- if (buf == MSGSTART)
- bGotStart = true;
- continue;
- }
- 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");
- msg.clear();
- bGotStart = true;
- }
-
- if (buf == MSGEND)
- {
- bGotFullMessage = true;
- }
- else if (bNextIsEscaped)
- {
- msg.push_back(buf + (uint8_t)ESCOFFSET);
- bNextIsEscaped = false;
- }
- else if (buf == MSGESC)
- bNextIsEscaped = true;
- else
- msg.push_back(buf);
- }
-
- if (bGotFullMessage)
- msg.state = ADAPTER_MESSAGE_STATE_RECEIVED;
-
- return bGotFullMessage;
-}
-
-std::string CAdapterCommunication::GetError(void) const
-{
- return m_port->GetError();
-}
-
-bool CAdapterCommunication::StartBootloader(void)
-{
- bool bReturn(false);
- if (!IsRunning())
- return bReturn;
-
- m_processor->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
- CCECAdapterMessage *output = new CCECAdapterMessage;
-
- output->push_back(MSGSTART);
- output->push_escaped(MSGCODE_START_BOOTLOADER);
- output->push_back(MSGEND);
-
- CLockObject lock(&output->mutex);
- if (Write(output))
- output->condition.Wait(&output->mutex);
- bReturn = output->state == ADAPTER_MESSAGE_STATE_SENT;
- delete output;
-
- return bReturn;
-}
-
-bool CAdapterCommunication::PingAdapter(void)
-{
- bool bReturn(false);
- if (!IsRunning())
- return bReturn;
-
- m_processor->AddLog(CEC_LOG_DEBUG, "sending ping");
- CCECAdapterMessage *output = new CCECAdapterMessage;
-
- output->push_back(MSGSTART);
- output->push_escaped(MSGCODE_PING);
- output->push_back(MSGEND);
-
- CLockObject lock(&output->mutex);
- if (Write(output))
- output->condition.Wait(&output->mutex);
- bReturn = output->state == ADAPTER_MESSAGE_STATE_SENT;
- delete output;
-
- return bReturn;
-}
-
-bool CAdapterCommunication::SetLineTimeout(uint8_t iTimeout)
-{
- bool bReturn(m_iLineTimeout != iTimeout);
-
- if (!bReturn)
- {
- CCECAdapterMessage *output = new CCECAdapterMessage;
-
- output->push_back(MSGSTART);
- output->push_escaped(MSGCODE_TRANSMIT_IDLETIME);
- output->push_escaped(iTimeout);
- output->push_back(MSGEND);
-
- if ((bReturn = Write(output)) == false)
- m_processor->AddLog(CEC_LOG_ERROR, "could not set the idletime");
- delete output;
- }
-
- return bReturn;
-}
-
-bool CAdapterCommunication::IsOpen(void) const
-{
- return !IsStopped() && m_port->IsOpen() && IsRunning();
-}
+++ /dev/null
-#pragma once
-/*
- * This file is part of the libCEC(R) library.
- *
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
- * libCEC(R) is an original work, containing original code.
- *
- * libCEC(R) is a trademark of Pulse-Eight Limited.
- *
- * This program is dual-licensed; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- *
- * Alternatively, you can license this library under a commercial license,
- * please contact Pulse-Eight Licensing for more information.
- *
- * For more information contact:
- * Pulse-Eight Licensing <license@pulse-eight.com>
- * http://www.pulse-eight.com/
- * http://www.pulse-eight.net/
- */
-
-#include <cectypes.h>
-#include "platform/threads.h"
-#include "util/buffer.h"
-#include "util/StdString.h"
-#include <string>
-
-namespace CEC
-{
- typedef enum cec_adapter_message_state
- {
- ADAPTER_MESSAGE_STATE_UNKNOWN = 0,
- ADAPTER_MESSAGE_STATE_WAITING,
- ADAPTER_MESSAGE_STATE_SENT,
- ADAPTER_MESSAGE_STATE_RECEIVED,
- ADAPTER_MESSAGE_STATE_ERROR
- } cec_adapter_message_state;
-
-
- class CCECAdapterMessage
- {
- public:
- CCECAdapterMessage(void) { clear(); }
- CCECAdapterMessage(const cec_command &command);
- CCECAdapterMessage &operator =(const CCECAdapterMessage &msg);
- CStdString ToString(void) const;
- CStdString MessageCodeAsString(void) const;
-
- bool empty(void) const { return packet.IsEmpty(); }
- uint8_t operator[](uint8_t pos) const { return packet[pos]; }
- uint8_t at(uint8_t pos) const { return packet[pos]; }
- uint8_t size(void) const { return packet.size; }
- void clear(void) { state = ADAPTER_MESSAGE_STATE_UNKNOWN; transmit_timeout = 0; packet.Clear(); maxTries = CEC_DEFAULT_TRANSMIT_RETRIES + 1; tries = 0; reply = MSGCODE_NOTHING; }
- void shift(uint8_t iShiftBy) { packet.Shift(iShiftBy); }
- void push_back(uint8_t add) { packet.PushBack(add); }
- cec_adapter_messagecode message(void) const { return packet.size >= 1 ? (cec_adapter_messagecode) (packet.At(0) & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK)) : MSGCODE_NOTHING; }
- bool eom(void) const { return packet.size >= 1 ? (packet.At(0) & MSGCODE_FRAME_EOM) != 0 : false; }
- bool ack(void) const { return packet.size >= 1 ? (packet.At(0) & MSGCODE_FRAME_ACK) != 0 : false; }
- cec_logical_address initiator(void) const { return packet.size >= 2 ? (cec_logical_address) (packet.At(1) >> 4) : CECDEVICE_UNKNOWN; };
- cec_logical_address destination(void) const { return packet.size >= 2 ? (cec_logical_address) (packet.At(1) & 0xF) : CECDEVICE_UNKNOWN; };
- bool is_error(void) const;
- void push_escaped(uint8_t byte);
- bool needs_retry(void) const { return reply == MSGCODE_NOTHING ||
- reply == MSGCODE_RECEIVE_FAILED ||
- reply == MSGCODE_TIMEOUT_ERROR ||
- reply == MSGCODE_TRANSMIT_FAILED_LINE ||
- reply == MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA ||
- reply == MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE ||
- reply == MSGCODE_TRANSMIT_LINE_TIMEOUT; }
-
- uint8_t maxTries;
- uint8_t tries;
- cec_adapter_messagecode reply;
- cec_datapacket packet;
- cec_adapter_message_state state;
- int32_t transmit_timeout;
- CMutex mutex;
- CCondition condition;
- };
-
- class CSerialPort;
- class CCECProcessor;
-
- class CAdapterCommunication : private CThread
- {
- public:
- CAdapterCommunication(CCECProcessor *processor);
- virtual ~CAdapterCommunication();
-
- bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
- bool Read(CCECAdapterMessage &msg, uint32_t iTimeout = 1000);
- bool Write(CCECAdapterMessage *data);
- bool PingAdapter(void);
- void Close(void);
- bool IsOpen(void) const;
- std::string GetError(void) const;
-
- void *Process(void);
-
- bool SetLineTimeout(uint8_t iTimeout);
- bool StartBootloader(void);
-
- private:
- void SendMessageToAdapter(CCECAdapterMessage *msg);
- void WriteNextCommand(void);
- void AddData(uint8_t *data, uint8_t iLen);
- bool ReadFromDevice(uint32_t iTimeout);
-
- CSerialPort * m_port;
- CCECProcessor * m_processor;
- CecBuffer<uint8_t> m_inBuffer;
- CecBuffer<CCECAdapterMessage *> m_outBuffer;
- CMutex m_mutex;
- CCondition m_rcvCondition;
- CCondition m_startCondition;
- uint8_t m_iLineTimeout;
- };
-};
#include "CECProcessor.h"
-#include "AdapterCommunication.h"
+#include "adapter/AdapterMessage.h"
#include "devices/CECBusDevice.h"
#include "devices/CECAudioSystem.h"
#include "devices/CECPlaybackDevice.h"
#include "devices/CECTV.h"
#include "implementations/CECCommandHandler.h"
#include "LibCEC.h"
-#include "util/StdString.h"
-#include "platform/timeutils.h"
using namespace CEC;
using namespace std;
+using namespace PLATFORM;
CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
m_bStarted(false),
delete m_busDevices[iPtr];
}
-bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
+bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs)
{
bool bReturn(false);
+ CLockObject lock(m_mutex);
+ if (!m_communication)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "no connection handler found");
+ return bReturn;
+ }
+ /* check for an already opened connection */
+ if (m_communication->IsOpen())
{
- CLockObject lock(&m_mutex);
+ CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened");
+ return bReturn;
+ }
- /* check for an already opened connection */
- if (!m_communication || m_communication->IsOpen())
+ /* open a new connection */
+ if ((bReturn = m_communication->Open(strPort, iBaudRate, iTimeoutMs)) == false)
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection");
+
+ /* try to ping the adapter */
+ int iPingTry(0);
+ bool bPingOk(false);
+ while (!bPingOk && iPingTry++ < CEC_PING_ADAPTER_TRIES)
+ {
+ if ((bPingOk = m_communication->PingAdapter()) == false)
{
- m_controller->AddLog(CEC_LOG_ERROR, "connection already opened");
- return bReturn;
+ CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond correctly to a ping (try %d of %d)", iPingTry, CEC_PING_ADAPTER_TRIES);
+ Sleep(500);
}
+ }
- /* open a new connection */
- if (!m_communication->Open(strPort, iBaudRate, iTimeoutMs))
+ if (bPingOk)
+ {
+ uint16_t iFirmwareVersion(CEC_FW_VERSION_UNKNOWN);
+ int iFwVersionTry(0);
+ bool bFwVersionOk(false);
+ while (!bFwVersionOk && iFwVersionTry++ < CEC_FW_VERSION_TRIES)
{
- m_controller->AddLog(CEC_LOG_ERROR, "could not open a connection");
- return bReturn;
+ if ((iFirmwareVersion = m_communication->GetFirmwareVersion()) == CEC_FW_VERSION_UNKNOWN)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond with a correct firmware version (try %d of %d)", iFwVersionTry, CEC_FW_VERSION_TRIES);
+ Sleep(500);
+ }
}
- /* create the processor thread */
- if (!CreateThread() || !m_startCondition.Wait(&m_mutex) || !m_bStarted)
+ if (iFirmwareVersion == CEC_FW_VERSION_UNKNOWN)
{
- m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
- return bReturn;
+ bReturn = false;
+ }
+ else
+ {
+ bReturn = true;
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "CEC Adapter firmware version: %d", iFirmwareVersion);
}
}
- /* find the logical address for the adapter */
- bReturn = m_logicalAddresses.IsEmpty() ? FindLogicalAddresses() : true;
- if (!bReturn)
- m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses");
+ return bReturn;
+}
- /* set the physical address for the adapter */
- if (bReturn)
+void CCECProcessor::SetInitialised(bool bSetTo /* = true */)
+{
+ CLockObject lock(m_mutex);
+ m_bInitialised = bSetTo;
+}
+
+bool CCECProcessor::Initialise(void)
+{
+ bool bReturn(false);
{
+ CLockObject lock(m_mutex);
+ if (!m_logicalAddresses.IsEmpty())
+ m_logicalAddresses.Clear();
+
+ if (!FindLogicalAddresses())
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not detect our logical addresses");
+ return bReturn;
+ }
+
/* only set our OSD name for the primary device */
m_busDevices[m_logicalAddresses.primary]->m_strDeviceName = m_strDeviceName;
+ }
- /* get the vendor id from the TV, so we are using the correct handler */
- m_busDevices[CECDEVICE_TV]->RequestVendorId();
- ReplaceHandlers();
+ /* get the vendor id from the TV, so we are using the correct handler */
+ m_busDevices[CECDEVICE_TV]->RequestVendorId();
+ ReplaceHandlers();
+
+ if ((bReturn = SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true)) == false)
+ 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);
+
+ return bReturn;
+}
+
+bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
+{
+ bool bReturn(false);
+
+ {
+ CLockObject lock(m_mutex);
+ if (!OpenConnection(strPort, iBaudRate, iTimeoutMs))
+ return bReturn;
- bReturn = SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true);
+ /* create the processor thread */
+ if (!CreateThread() || !m_startCondition.Wait(m_mutex) || !m_bStarted)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread");
+ return bReturn;
+ }
}
- if (bReturn)
+ if ((bReturn = Initialise()) == false)
{
- m_bInitialised = true;
- m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread");
+ StopThread(true);
}
else
{
- m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
- StopThread(true);
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
}
return bReturn;
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);
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) ||
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);
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);
}
{
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);
+ CLockObject lock(m_mutex);
CCECBusDevice *previousDevice = GetDeviceByType(from);
m_logicalAddresses.primary = CECDEVICE_UNKNOWN;
{
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();
CCECAdapterMessage msg;
{
- CLockObject lock(&m_mutex);
+ 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();
}
{
ReplaceHandlers();
command.Clear();
- msg.clear();
+ msg.Clear();
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (m_commandBuffer.Pop(command))
{
bParseFrame = true;
void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
m_iStandardLineTimeout = iTimeout;
}
void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
m_iRetryLineTimeout = iTimeout;
}
bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */)
{
bool bReturn(false);
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
m_iBaseDevice = iBaseDevice;
m_iHDMIPort = 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)
{
- lock.Leave();
+ lock.Unlock();
iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
lock.Lock();
}
}
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.Leave();
+ lock.Unlock();
SetPhysicalAddress(iPhysicalAddress);
}
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)
{
- CLockObject lock(&m_mutex);
+ 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());
cec_logical_addresses sendUpdatesTo;
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (!m_logicalAddresses.IsEmpty())
{
bool bWasActiveSource(false);
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);
+ CLockObject lock(m_mutex);
m_bMonitor = bEnable;
}
bReturn = Transmit(output);
/* set to "not present" on failed ack */
- if (output->is_error() && output->reply == MSGCODE_TRANSMIT_FAILED_ACK &&
- output->destination() != CECDEVICE_BROADCAST)
- m_busDevices[output->destination()]->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT);
+ if (output->state == ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED &&
+ output->Destination() != CECDEVICE_BROADCAST)
+ m_busDevices[output->Destination()]->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT);
delete output;
return bReturn;
bool CCECProcessor::Transmit(CCECAdapterMessage *output)
{
bool bReturn(false);
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
{
+ if (!m_communication)
+ return bReturn;
+
m_iLastTransmission = GetTimeMs();
m_communication->SetLineTimeout(m_iStandardLineTimeout);
- output->tries = 1;
+ output->tries = 0;
do
{
if (output->tries > 0)
m_communication->SetLineTimeout(m_iRetryLineTimeout);
-
- CLockObject msgLock(&output->mutex);
- if (!m_communication || !m_communication->Write(output))
- return bReturn;
- else
- {
- output->condition.Wait(&output->mutex);
- if (output->state != ADAPTER_MESSAGE_STATE_SENT)
- {
- m_controller->AddLog(CEC_LOG_ERROR, "command was not sent");
- return bReturn;
- }
- }
-
- if (output->transmit_timeout > 0)
- {
- if ((bReturn = WaitForTransmitSucceeded(output)) == false)
- m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ack");
- }
- else
- bReturn = true;
- }while (output->transmit_timeout > 0 && output->needs_retry() && ++output->tries < output->maxTries);
+ bReturn = m_communication->Write(output);
+ }while (!bReturn && output->transmit_timeout > 0 && output->NeedsRetry() && ++output->tries < output->maxTries);
}
m_communication->SetLineTimeout(m_iStandardLineTimeout);
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
Transmit(command);
}
-bool CCECProcessor::WaitForTransmitSucceeded(CCECAdapterMessage *message)
-{
- bool bError(false);
- bool bTransmitSucceeded(false);
- uint8_t iPacketsLeft(message->size() / 4);
-
- int64_t iNow = GetTimeMs();
- int64_t iTargetTime = iNow + message->transmit_timeout;
-
- while (!bTransmitSucceeded && !bError && (message->transmit_timeout == 0 || iNow < iTargetTime))
- {
- CCECAdapterMessage msg;
-
- if (!m_communication->Read(msg, message->transmit_timeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
- {
- iNow = GetTimeMs();
- continue;
- }
-
- if (msg.message() == MSGCODE_FRAME_START && msg.ack())
- {
- m_busDevices[msg.initiator()]->GetHandler()->HandlePoll(msg.initiator(), msg.destination());
- m_lastInitiator = msg.initiator();
- iNow = GetTimeMs();
- continue;
- }
-
- bError = msg.is_error();
- if (msg.message() == MSGCODE_RECEIVE_FAILED &&
- m_lastInitiator != CECDEVICE_UNKNOWN &&
- !m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed())
- {
- iNow = GetTimeMs();
- continue;
- }
-
- if (bError)
- {
- message->reply = msg.message();
- m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
- }
- else
- {
- switch(msg.message())
- {
- case MSGCODE_COMMAND_ACCEPTED:
- m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
- if (iPacketsLeft > 0)
- iPacketsLeft--;
- break;
- case MSGCODE_TRANSMIT_SUCCEEDED:
- m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
- bTransmitSucceeded = (iPacketsLeft == 0);
- bError = !bTransmitSucceeded;
- message->reply = MSGCODE_TRANSMIT_SUCCEEDED;
- break;
- default:
- // ignore other data while waiting
- break;
- }
-
- iNow = GetTimeMs();
- }
- }
-
- return bTransmitSucceeded && !bError;
-}
-
bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
{
bool bEom(false);
- bool bIsError(msg.is_error());
+ bool bIsError(msg.IsError());
- if (msg.empty())
+ if (msg.IsEmpty())
return bEom;
- switch(msg.message())
+ switch(msg.Message())
{
case MSGCODE_FRAME_START:
{
m_currentframe.Clear();
- if (msg.size() >= 2)
+ if (msg.Size() >= 2)
{
- m_currentframe.initiator = msg.initiator();
- m_currentframe.destination = msg.destination();
- m_currentframe.ack = msg.ack();
- m_currentframe.eom = msg.eom();
+ m_currentframe.initiator = msg.Initiator();
+ m_currentframe.destination = msg.Destination();
+ m_currentframe.ack = msg.IsACK();
+ m_currentframe.eom = msg.IsEOM();
}
if (m_currentframe.ack == 0x1)
{
break;
case MSGCODE_FRAME_DATA:
{
- if (msg.size() >= 2)
+ if (msg.Size() >= 2)
{
m_currentframe.PushBack(msg[1]);
- m_currentframe.eom = msg.eom();
+ m_currentframe.eom = msg.IsEOM();
}
- bEom = msg.eom();
+ bEom = msg.IsEOM();
}
break;
default:
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;
}
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);
return false;
}
-void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
-{
- m_controller->SetCurrentButton(iButtonCode);
-}
-
-void CCECProcessor::AddCommand(const cec_command &command)
-{
- m_controller->AddCommand(command);
-}
-
-void CCECProcessor::AddKey(cec_keypress &key)
-{
- m_controller->AddKey(key);
-}
-
-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)
{
- bool bReturn(false);
- CStdString strLog;
- strLog.Format("setting ackmask to %2x", iMask);
- m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
-
- CCECAdapterMessage *output = new CCECAdapterMessage;
-
- output->push_back(MSGSTART);
- output->push_escaped(MSGCODE_SET_ACK_MASK);
- output->push_escaped(iMask >> 8);
- output->push_escaped((uint8_t)iMask);
- output->push_back(MSGEND);
-
- if ((bReturn = Transmit(output)) == false)
- m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask");
-
- delete output;
-
- return bReturn;
+ return m_communication->SetAckMask(iMask);
}
bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
{
return m_communication->PingAdapter();
}
+
+void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination)
+{
+ m_busDevices[initiator]->GetHandler()->HandlePoll(initiator, destination);
+ m_lastInitiator = initiator;
+}
+
+bool CCECProcessor::HandleReceiveFailed(void)
+{
+ return m_lastInitiator != CECDEVICE_UNKNOWN &&
+ !m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed();
+}
#include <string>
#include <cectypes.h>
-#include "AdapterCommunication.h"
-#include "platform/threads.h"
-#include "util/buffer.h"
-#include "util/StdString.h"
+#include "adapter/AdapterCommunication.h"
+#include "platform/os.h"
class CSerialPort;
class CAdapterCommunication;
class CCECBusDevice;
- class CCECProcessor : public CThread
+ class CCECProcessor : public PLATFORM::CThread
{
public:
CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint16_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS);
virtual bool Transmit(CCECAdapterMessage *output);
virtual void TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
- virtual void SetCurrentButton(cec_user_control_code iButtonCode);
- 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);
virtual bool SetAckMask(uint16_t iMask);
virtual bool StartBootloader(void);
virtual bool PingAdapter(void);
+ virtual void HandlePoll(cec_logical_address initiator, cec_logical_address destination);
+ virtual bool HandleReceiveFailed(void);
- CCECBusDevice *m_busDevices[16];
- CMutex m_transmitMutex;
+ CCECBusDevice * m_busDevices[16];
+ PLATFORM::CMutex m_transmitMutex;
private:
+ bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs);
+ bool Initialise(void);
+ void SetInitialised(bool bSetTo = true);
+
void ReplaceHandlers(void);
void ScanCECBus(void);
bool PhysicalAddressInUse(uint16_t iPhysicalAddress);
bool FindLogicalAddressAudioSystem(void);
void LogOutput(const cec_command &data);
- bool WaitForTransmitSucceeded(CCECAdapterMessage *message);
bool ParseMessage(const CCECAdapterMessage &msg);
void ParseCommand(cec_command &command);
- bool m_bStarted;
- bool m_bInitialised;
- uint8_t m_iHDMIPort;
- cec_logical_address m_iBaseDevice;
- cec_command m_currentframe;
- cec_logical_addresses m_logicalAddresses;
- cec_logical_address m_lastInitiator;
- std::string m_strDeviceName;
- cec_device_type_list m_types;
- CMutex m_mutex;
- CCondition m_startCondition;
- CAdapterCommunication* m_communication;
- CLibCEC* m_controller;
- bool m_bMonitor;
- CecBuffer<cec_command> m_commandBuffer;
- cec_keypress m_previousKey;
- CThread * m_busScan;
- uint8_t m_iLineTimeout;
- uint8_t m_iStandardLineTimeout;
- uint8_t m_iRetryLineTimeout;
- uint64_t m_iLastTransmission;
+ bool m_bStarted;
+ bool m_bInitialised;
+ uint8_t m_iHDMIPort;
+ cec_logical_address m_iBaseDevice;
+ cec_command m_currentframe;
+ cec_logical_addresses m_logicalAddresses;
+ cec_logical_address m_lastInitiator;
+ std::string m_strDeviceName;
+ cec_device_type_list m_types;
+ PLATFORM::CMutex m_mutex;
+ PLATFORM::CCondition m_startCondition;
+ CAdapterCommunication* m_communication;
+ CLibCEC* m_controller;
+ bool m_bMonitor;
+ PLATFORM::SyncedBuffer<cec_command> m_commandBuffer;
+ cec_keypress m_previousKey;
+ PLATFORM::CThread * m_busScan;
+ uint8_t m_iLineTimeout;
+ uint8_t m_iStandardLineTimeout;
+ uint8_t m_iRetryLineTimeout;
+ uint64_t m_iLastTransmission;
};
- class CCECBusScan : public CThread
+ class CCECBusScan : public PLATFORM::CThread
{
public:
CCECBusScan(CCECProcessor *processor) { m_processor = processor; }
#include "LibCEC.h"
-#include "AdapterCommunication.h"
-#include "AdapterDetection.h"
+#include "adapter/AdapterCommunication.h"
+#include "adapter/AdapterDetection.h"
#include "CECProcessor.h"
#include "devices/CECBusDevice.h"
-#include "util/StdString.h"
#include "platform/timeutils.h"
using namespace std;
using namespace CEC;
+using namespace PLATFORM;
CLibCEC::CLibCEC(const char *strDeviceName, cec_device_type_list types) :
m_iStartTime(GetTimeMs()),
bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (m_cec)
{
m_cbParam = cbParam;
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)
{
- CLockObject lock(&m_mutex);
- if (m_callbacks)
- m_callbacks->CBCecKeyPress(m_cbParam, key);
+ CLibCEC *instance = CLibCEC::GetInstance();
+ CLockObject lock(instance->m_mutex);
+
+ AddLog(CEC_LOG_DEBUG, "key pressed: %1x", key.keycode);
+
+ if (instance->m_callbacks)
+ instance->m_callbacks->CBCecKeyPress(instance->m_cbParam, key);
else
- m_keyBuffer.Push(key);
- m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
- m_buttontime = 0;
+ instance->m_keyBuffer.Push(key);
+
+ instance->m_iCurrentButton = key.duration > 0 ? CEC_USER_CONTROL_CODE_UNKNOWN : key.keycode;
+ instance->m_buttontime = key.duration > 0 ? 0 : GetTimeMs();
+}
+
+void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode)
+{
+ /* push keypress to the keybuffer with 0 duration.
+ push another press to the keybuffer with the duration set when the button is released */
+ cec_keypress key;
+ key.duration = 0;
+ key.keycode = iButtonCode;
+
+ AddKey(key);
}
void CLibCEC::AddKey(void)
{
- CLockObject lock(&m_mutex);
- if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN)
+ CLibCEC *instance = CLibCEC::GetInstance();
+ CLockObject lock(instance->m_mutex);
+
+ if (instance->m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN)
{
cec_keypress key;
- key.duration = (unsigned int) (GetTimeMs() - m_buttontime);
- key.keycode = m_iCurrentButton;
+ key.duration = (unsigned int) (GetTimeMs() - instance->m_buttontime);
+ key.keycode = instance->m_iCurrentButton;
+ AddLog(CEC_LOG_DEBUG, "key released: %1x", key.keycode);
- if (m_callbacks)
- m_callbacks->CBCecKeyPress(m_cbParam, key);
+ if (instance->m_callbacks)
+ instance->m_callbacks->CBCecKeyPress(instance->m_cbParam, key);
else
- m_keyBuffer.Push(key);
- m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
+ instance->m_keyBuffer.Push(key);
+ instance->m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
}
- m_buttontime = 0;
+ instance->m_buttontime = 0;
}
void CLibCEC::AddCommand(const cec_command &command)
{
- CLockObject lock(&m_mutex);
- if (m_callbacks)
- {
- m_callbacks->CBCecCommand(m_cbParam, command);
- }
- else if (m_commandBuffer.Push(command))
- {
- CStdString strDebug;
- strDebug.Format("stored command '%2x' in the command buffer. buffer size = %d", command.opcode, m_commandBuffer.Size());
- AddLog(CEC_LOG_DEBUG, strDebug);
- }
- else
- {
+ CLibCEC *instance = CLibCEC::GetInstance();
+ CLockObject lock(instance->m_mutex);
+
+ AddLog(CEC_LOG_NOTICE, ">> %s (%X) -> %s (%X): %s (%2X)", instance->m_cec->ToString(command.initiator), command.initiator, instance->m_cec->ToString(command.destination), command.destination, instance->m_cec->ToString(command.opcode), command.opcode);
+
+ if (instance->m_callbacks)
+ instance->m_callbacks->CBCecCommand(instance->m_cbParam, command);
+ else if (!instance->m_commandBuffer.Push(command))
AddLog(CEC_LOG_WARNING, "command buffer is full");
- }
}
void CLibCEC::CheckKeypressTimeout(void)
}
}
-void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode)
+static CLibCEC *g_libCEC_instance(NULL);
+CLibCEC *CLibCEC::GetInstance(void)
{
- m_iCurrentButton = iButtonCode;
- m_buttontime = GetTimeMs();
+ return g_libCEC_instance;
+}
- /* push keypress to the keybuffer with 0 duration.
- push another press to the keybuffer with the duration set when the button is released */
- cec_keypress key;
- key.duration = 0;
- key.keycode = m_iCurrentButton;
- m_keyBuffer.Push(key);
+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)
#include <string>
#include <cec.h>
-#include "util/buffer.h"
+#include "platform/os.h"
namespace CEC
{
const char *ToString(const cec_vendor_id vendor);
//@}
- virtual void AddLog(cec_log_level level, const std::string &strMessage);
- virtual void AddKey(void);
- virtual void AddKey(cec_keypress &key);
- virtual void AddCommand(const cec_command &command);
+ static void AddLog(cec_log_level level, const char *strFormat, ...);
+ static void AddKey(void);
+ static void AddKey(cec_keypress &key);
+ static void AddCommand(const cec_command &command);
+ static void SetCurrentButton(cec_user_control_code iButtonCode);
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;
- int64_t m_buttontime;
- CCECProcessor *m_cec;
- CecBuffer<cec_log_message> m_logBuffer;
- CecBuffer<cec_keypress> m_keyBuffer;
- CecBuffer<cec_command> m_commandBuffer;
- ICECCallbacks *m_callbacks;
- void *m_cbParam;
- CMutex m_mutex;
+ int64_t m_iStartTime;
+ cec_user_control_code m_iCurrentButton;
+ int64_t m_buttontime;
+ CCECProcessor * m_cec;
+ PLATFORM::SyncedBuffer<cec_log_message> m_logBuffer;
+ PLATFORM::SyncedBuffer<cec_keypress> m_keyBuffer;
+ PLATFORM::SyncedBuffer<cec_command> m_commandBuffer;
+ ICECCallbacks * m_callbacks;
+ void * m_cbParam;
+ PLATFORM::CMutex m_mutex;
};
};
* http://www.pulse-eight.net/
*/
-#include <windows.h>
+#include "platform/os.h"
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libcec.pc
-libcec_la_SOURCES = AdapterCommunication.cpp \
- AdapterCommunication.h \
- AdapterDetection.cpp \
- AdapterDetection.h \
- CECProcessor.cpp \
- CECProcessor.h \
+libcec_la_SOURCES = CECProcessor.cpp \
LibCEC.cpp \
- LibCEC.h \
LibCECC.cpp \
- util/StdString.h \
- devices/CECAudioSystem.h \
- devices/CECAudioSystem.cpp \
+ adapter/AdapterCommunication.cpp \
+ adapter/AdapterDetection.cpp \
+ devices/CECAudioSystem.cpp \
devices/CECBusDevice.cpp \
- devices/CECBusDevice.h \
- devices/CECPlaybackDevice.h \
devices/CECPlaybackDevice.cpp \
- devices/CECRecordingDevice.h \
- devices/CECRecordingDevice.cpp \
- devices/CECTuner.h \
+ devices/CECRecordingDevice.cpp \
devices/CECTuner.cpp \
- devices/CECTV.h \
devices/CECTV.cpp \
implementations/ANCommandHandler.cpp \
- implementations/ANCommandHandler.h \
implementations/CECCommandHandler.cpp \
- implementations/CECCommandHandler.h \
implementations/SLCommandHandler.cpp \
- implementations/SLCommandHandler.h \
implementations/VLCommandHandler.cpp \
- implementations/VLCommandHandler.h \
- platform/timeutils.h \
- platform/baudrate.h \
- platform/os-dependent.h \
- platform/linux/os_posix.h \
- platform/linux/serialport.cpp \
- platform/serialport.h \
- platform/threads.cpp \
- platform/threads.h
+ platform/posix/serialport.cpp
libcec_la_LDFLAGS = @LIBS@ -version-info @VERSION@
libcec_la_CPPFLAGS = -I@abs_top_srcdir@/include
--- /dev/null
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+#include "AdapterCommunication.h"
+
+#include "AdapterMessage.h"
+#include "../CECProcessor.h"
+#include "../platform/serialport/serialport.h"
+#include "../LibCEC.h"
+
+using namespace std;
+using namespace CEC;
+using namespace PLATFORM;
+
+CAdapterCommunication::CAdapterCommunication(CCECProcessor *processor) :
+ m_port(NULL),
+ m_processor(processor),
+ m_iLineTimeout(0),
+ m_iFirmwareVersion(CEC_FW_VERSION_UNKNOWN)
+{
+ m_port = new PLATFORM::CSerialPort;
+}
+
+CAdapterCommunication::~CAdapterCommunication(void)
+{
+ Close();
+
+ if (m_port)
+ {
+ delete m_port;
+ m_port = NULL;
+ }
+}
+
+bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
+{
+ uint64_t iNow = GetTimeMs();
+ uint64_t iTimeout = iNow + iTimeoutMs;
+
+ CLockObject lock(m_mutex);
+
+ if (!m_port)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "port is NULL");
+ return false;
+ }
+
+ if (IsOpen())
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "port is already open");
+ return true;
+ }
+
+ CStdString strError;
+ bool bConnected(false);
+ while (!bConnected && iNow < iTimeout)
+ {
+ if ((bConnected = m_port->Open(strPort, iBaudRate)) == false)
+ {
+ strError.Format("error opening serial port '%s': %s", strPort, m_port->GetError().c_str());
+ Sleep(250);
+ iNow = GetTimeMs();
+ }
+ }
+
+ if (!bConnected)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, strError);
+ return false;
+ }
+
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "connection opened, clearing any previous input and waiting for active transmissions to end before starting");
+
+ //clear any input bytes
+ uint8_t buff[1024];
+ while (m_port->Read(buff, 1024, 100) > 0)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "data received, clearing it");
+ Sleep(250);
+ }
+
+ if (CreateThread())
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "communication thread started");
+ return true;
+ }
+ else
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a communication thread");
+ }
+
+ return false;
+}
+
+void CAdapterCommunication::Close(void)
+{
+ CLockObject lock(m_mutex);
+ m_rcvCondition.Broadcast();
+ StopThread();
+}
+
+void *CAdapterCommunication::Process(void)
+{
+ while (!IsStopped())
+ {
+ ReadFromDevice(50);
+ Sleep(5);
+ WriteNextCommand();
+ }
+
+ CCECAdapterMessage *msg(NULL);
+ if (m_outBuffer.Pop(msg))
+ msg->condition.Broadcast();
+
+ return NULL;
+}
+
+bool CAdapterCommunication::Write(CCECAdapterMessage *data)
+{
+ bool bReturn(false);
+
+ CLockObject lock(data->mutex);
+ data->state = ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT;
+ m_outBuffer.Push(data);
+ data->condition.Wait(data->mutex);
+
+ if (data->state != ADAPTER_MESSAGE_STATE_SENT)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "command was not sent");
+ }
+ else if (data->expectControllerAck)
+ {
+ bReturn = WaitForAck(*data);
+ if (bReturn)
+ {
+ if (data->isTransmission)
+ data->state = ADAPTER_MESSAGE_STATE_SENT_ACKED;
+ }
+ else
+ {
+ data->state = ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED;
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "did not receive ack");
+ }
+ }
+ else
+ {
+ bReturn = true;
+ }
+
+ return bReturn;
+}
+
+bool CAdapterCommunication::Read(CCECAdapterMessage &msg, uint32_t iTimeout)
+{
+ CLockObject lock(m_mutex);
+
+ msg.Clear();
+ uint64_t iNow = GetTimeMs();
+ uint64_t iTarget = iNow + iTimeout;
+ bool bGotFullMessage(false);
+ bool bNextIsEscaped(false);
+ bool bGotStart(false);
+
+ while(!bGotFullMessage && iNow < iTarget)
+ {
+ uint8_t buf = 0;
+ if (!m_inBuffer.Pop(buf))
+ {
+ if (!m_rcvCondition.Wait(m_mutex, (uint32_t) (iTarget - iNow)))
+ return false;
+ }
+
+ if (!bGotStart)
+ {
+ if (buf == MSGSTART)
+ bGotStart = true;
+ continue;
+ }
+ else if (buf == MSGSTART) //we found a msgstart before msgend, this is not right, remove
+ {
+ if (msg.Size() > 0)
+ CLibCEC::AddLog(CEC_LOG_WARNING, "received MSGSTART before MSGEND, removing previous buffer contents");
+ msg.Clear();
+ bGotStart = true;
+ }
+
+ if (buf == MSGEND)
+ {
+ bGotFullMessage = true;
+ }
+ else if (bNextIsEscaped)
+ {
+ msg.PushBack(buf + (uint8_t)ESCOFFSET);
+ bNextIsEscaped = false;
+ }
+ else if (buf == MSGESC)
+ bNextIsEscaped = true;
+ else
+ msg.PushBack(buf);
+ }
+
+ if (bGotFullMessage)
+ msg.state = ADAPTER_MESSAGE_STATE_INCOMING;
+
+ return bGotFullMessage;
+}
+
+std::string CAdapterCommunication::GetError(void) const
+{
+ return m_port->GetError();
+}
+
+bool CAdapterCommunication::StartBootloader(void)
+{
+ bool bReturn(false);
+ if (!IsRunning())
+ return bReturn;
+
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "starting the bootloader");
+ CCECAdapterMessage *output = new CCECAdapterMessage;
+
+ output->PushBack(MSGSTART);
+ output->PushEscaped(MSGCODE_START_BOOTLOADER);
+ output->PushBack(MSGEND);
+ output->isTransmission = false;
+ output->expectControllerAck = false;
+
+ if ((bReturn = Write(output)) == false)
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not start the bootloader");
+ delete output;
+
+ return bReturn;
+}
+
+bool CAdapterCommunication::PingAdapter(void)
+{
+ bool bReturn(false);
+ if (!IsRunning())
+ return bReturn;
+
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "sending ping");
+ CCECAdapterMessage *output = new CCECAdapterMessage;
+
+ output->PushBack(MSGSTART);
+ output->PushEscaped(MSGCODE_PING);
+ output->PushBack(MSGEND);
+ output->isTransmission = false;
+
+ if ((bReturn = Write(output)) == false)
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not ping the adapter");
+ delete output;
+
+ return bReturn;
+}
+
+uint16_t CAdapterCommunication::GetFirmwareVersion(void)
+{
+ uint16_t iReturn(m_iFirmwareVersion);
+ if (!IsRunning())
+ return iReturn;
+
+ if (iReturn == CEC_FW_VERSION_UNKNOWN)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "requesting the firmware version");
+ CCECAdapterMessage *output = new CCECAdapterMessage;
+
+ output->PushBack(MSGSTART);
+ output->PushEscaped(MSGCODE_FIRMWARE_VERSION);
+ output->PushBack(MSGEND);
+ output->isTransmission = false;
+ output->expectControllerAck = false;
+
+ SendMessageToAdapter(output);
+ delete output;
+
+ CCECAdapterMessage input;
+ if (!Read(input, CEC_DEFAULT_TRANSMIT_WAIT) || input.Message() != MSGCODE_FIRMWARE_VERSION || input.Size() != 3)
+ CLibCEC::AddLog(CEC_LOG_ERROR, "no or invalid firmware version (size = %d, message = %d)", input.Size(), input.Message());
+ else
+ {
+ m_iFirmwareVersion = (input[1] << 8 | input[2]);
+ iReturn = m_iFirmwareVersion;
+ }
+ }
+
+ return iReturn;
+}
+
+bool CAdapterCommunication::SetLineTimeout(uint8_t iTimeout)
+{
+ bool bReturn(m_iLineTimeout != iTimeout);
+
+ if (!bReturn)
+ {
+ CCECAdapterMessage *output = new CCECAdapterMessage;
+
+ output->PushBack(MSGSTART);
+ output->PushEscaped(MSGCODE_TRANSMIT_IDLETIME);
+ output->PushEscaped(iTimeout);
+ output->PushBack(MSGEND);
+ output->isTransmission = false;
+
+ if ((bReturn = Write(output)) == false)
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not set the idletime");
+ delete output;
+ }
+
+ return bReturn;
+}
+
+bool CAdapterCommunication::SetAckMask(uint16_t iMask)
+{
+ bool bReturn(false);
+ CStdString strLog;
+ strLog.Format("setting ackmask to %2x", iMask);
+ CLibCEC::AddLog(CEC_LOG_DEBUG, strLog.c_str());
+
+ CCECAdapterMessage *output = new CCECAdapterMessage;
+
+ output->PushBack(MSGSTART);
+ output->PushEscaped(MSGCODE_SET_ACK_MASK);
+ output->PushEscaped(iMask >> 8);
+ output->PushEscaped((uint8_t)iMask);
+ output->PushBack(MSGEND);
+ output->isTransmission = false;
+
+ if ((bReturn = Write(output)) == false)
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not set the ackmask");
+ delete output;
+
+ return bReturn;
+}
+
+bool CAdapterCommunication::IsOpen(void)
+{
+ return !IsStopped() && m_port->IsOpen() && IsRunning();
+}
+
+bool CAdapterCommunication::WaitForAck(CCECAdapterMessage &message)
+{
+ bool bError(false);
+ bool bTransmitSucceeded(false);
+ uint8_t iPacketsLeft(message.Size() / 4);
+
+ int64_t iNow = GetTimeMs();
+ int64_t iTargetTime = iNow + message.transmit_timeout;
+
+ while (!bTransmitSucceeded && !bError && (message.transmit_timeout == 0 || iNow < iTargetTime))
+ {
+ CCECAdapterMessage msg;
+ int32_t iWait = (int32_t)(iTargetTime - iNow);
+ if (iWait <= 5 || message.transmit_timeout <= 5)
+ iWait = CEC_DEFAULT_TRANSMIT_WAIT;
+
+ if (!Read(msg, iWait))
+ {
+ iNow = GetTimeMs();
+ continue;
+ }
+
+ if (msg.Message() == MSGCODE_FRAME_START && msg.IsACK())
+ {
+ m_processor->HandlePoll(msg.Initiator(), msg.Destination());
+ iNow = GetTimeMs();
+ continue;
+ }
+
+ if (msg.Message() == MSGCODE_RECEIVE_FAILED &&
+ m_processor->HandleReceiveFailed())
+ {
+ iNow = GetTimeMs();
+ continue;
+ }
+
+ bError = msg.IsError();
+ if (bError)
+ {
+ message.reply = msg.Message();
+ CLibCEC::AddLog(CEC_LOG_DEBUG, msg.ToString());
+ }
+ else
+ {
+ switch(msg.Message())
+ {
+ case MSGCODE_COMMAND_ACCEPTED:
+ CLibCEC::AddLog(CEC_LOG_DEBUG, msg.ToString());
+ if (iPacketsLeft > 0)
+ iPacketsLeft--;
+ if (!message.isTransmission && iPacketsLeft == 0)
+ bTransmitSucceeded = true;
+ break;
+ case MSGCODE_TRANSMIT_SUCCEEDED:
+ CLibCEC::AddLog(CEC_LOG_DEBUG, msg.ToString());
+ bTransmitSucceeded = (iPacketsLeft == 0);
+ bError = !bTransmitSucceeded;
+ message.reply = MSGCODE_TRANSMIT_SUCCEEDED;
+ break;
+ default:
+ // ignore other data while waiting
+ break;
+ }
+
+ iNow = GetTimeMs();
+ }
+ }
+
+ return bTransmitSucceeded && !bError;
+}
+
+void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen)
+{
+ CLockObject lock(m_mutex);
+ for (uint8_t iPtr = 0; iPtr < iLen; iPtr++)
+ m_inBuffer.Push(data[iPtr]);
+
+ m_rcvCondition.Signal();
+}
+
+bool CAdapterCommunication::ReadFromDevice(uint32_t iTimeout)
+{
+ int32_t iBytesRead;
+ uint8_t buff[1024];
+ if (!m_port)
+ return false;
+
+ CLockObject lock(m_mutex);
+ iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout);
+ if (iBytesRead < 0 || iBytesRead > 256)
+ {
+ CStdString strError;
+ strError.Format("error reading from serial port: %s", m_port->GetError().c_str());
+ CLibCEC::AddLog(CEC_LOG_ERROR, strError);
+ return false;
+ }
+ else if (iBytesRead > 0)
+ AddData(buff, (uint8_t) iBytesRead);
+
+ return iBytesRead > 0;
+}
+
+void CAdapterCommunication::SendMessageToAdapter(CCECAdapterMessage *msg)
+{
+ CLockObject adapterLock(m_mutex);
+ CLockObject lock(msg->mutex);
+ if (m_port->Write(msg->packet.data, msg->Size()) != (int32_t) msg->Size())
+ {
+ CStdString strError;
+ strError.Format("error writing to serial port: %s", m_port->GetError().c_str());
+ CLibCEC::AddLog(CEC_LOG_ERROR, strError);
+ msg->state = ADAPTER_MESSAGE_STATE_ERROR;
+ }
+ else
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "command sent");
+ msg->state = ADAPTER_MESSAGE_STATE_SENT;
+ }
+ msg->condition.Signal();
+}
+
+void CAdapterCommunication::WriteNextCommand(void)
+{
+ CCECAdapterMessage *msg(NULL);
+ if (m_outBuffer.Pop(msg))
+ SendMessageToAdapter(msg);
+}
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+#include <cectypes.h>
+#include "../platform/os.h"
+
+namespace PLATFORM
+{
+ class CSerialPort;
+}
+
+namespace CEC
+{
+ class CCECProcessor;
+ class CCECAdapterMessage;
+
+ class CAdapterCommunication : private PLATFORM::CThread
+ {
+ public:
+ CAdapterCommunication(CCECProcessor *processor);
+ virtual ~CAdapterCommunication();
+
+ bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
+ bool Read(CCECAdapterMessage &msg, uint32_t iTimeout = 1000);
+ bool Write(CCECAdapterMessage *data);
+ void Close(void);
+ bool IsOpen(void);
+ std::string GetError(void) const;
+
+ void *Process(void);
+
+ bool SetLineTimeout(uint8_t iTimeout);
+ bool StartBootloader(void);
+ bool SetAckMask(uint16_t iMask);
+ bool PingAdapter(void);
+ uint16_t GetFirmwareVersion(void);
+
+ bool WaitForAck(CCECAdapterMessage &message);
+
+ private:
+ void SendMessageToAdapter(CCECAdapterMessage *msg);
+ void WriteNextCommand(void);
+ void AddData(uint8_t *data, uint8_t iLen);
+ bool ReadFromDevice(uint32_t iTimeout);
+
+ PLATFORM::CSerialPort * m_port;
+ CCECProcessor * m_processor;
+ PLATFORM::SyncedBuffer<uint8_t> m_inBuffer;
+ PLATFORM::SyncedBuffer<CCECAdapterMessage *> m_outBuffer;
+ PLATFORM::CMutex m_mutex;
+ PLATFORM::CCondition m_rcvCondition;
+ uint8_t m_iLineTimeout;
+ uint16_t m_iFirmwareVersion;
+ };
+};
*/
#include "AdapterDetection.h"
-#include "platform/os-dependent.h"
-#include "util/StdString.h"
+#include "../platform/os.h"
#if defined(__APPLE__)
#include <dirent.h>
#include <IOKit/serial/IOSerialKeys.h>
#include <CoreFoundation/CoreFoundation.h>
#elif defined(__WINDOWS__)
+#pragma comment(lib, "advapi32.lib")
+#pragma comment(lib, "setupapi.lib")
#include <setupapi.h>
// the virtual COM port only shows up when requesting devices with the raw device guid!
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+namespace CEC
+{
+ typedef enum cec_adapter_message_state
+ {
+ ADAPTER_MESSAGE_STATE_UNKNOWN = 0,
+ ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT,
+ ADAPTER_MESSAGE_STATE_SENT,
+ ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED,
+ ADAPTER_MESSAGE_STATE_SENT_ACKED,
+ ADAPTER_MESSAGE_STATE_INCOMING,
+ ADAPTER_MESSAGE_STATE_ERROR
+ } cec_adapter_message_state;
+
+
+ class CCECAdapterMessage
+ {
+ public:
+ CCECAdapterMessage(void)
+ {
+ Clear();
+ }
+
+ CCECAdapterMessage(const cec_command &command)
+ {
+ Clear();
+
+ //set ack polarity to high when transmitting to the broadcast address
+ //set ack polarity low when transmitting to any other address
+ PushBack(MSGSTART);
+ PushEscaped(MSGCODE_TRANSMIT_ACK_POLARITY);
+ if (command.destination == CECDEVICE_BROADCAST)
+ PushEscaped(CEC_TRUE);
+ else
+ PushEscaped(CEC_FALSE);
+ PushBack(MSGEND);
+
+ // add source and destination
+ PushBack(MSGSTART);
+ PushEscaped(command.opcode_set == 0 ? (uint8_t)MSGCODE_TRANSMIT_EOM : (uint8_t)MSGCODE_TRANSMIT);
+ PushBack(((uint8_t)command.initiator << 4) + (uint8_t)command.destination);
+ PushBack(MSGEND);
+
+ // add opcode
+ if (command.opcode_set == 1)
+ {
+ PushBack(MSGSTART);
+ PushEscaped(command.parameters.IsEmpty() ? (uint8_t)MSGCODE_TRANSMIT_EOM : (uint8_t)MSGCODE_TRANSMIT);
+ PushBack((uint8_t) command.opcode);
+ PushBack(MSGEND);
+
+ // add parameters
+ for (int8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
+ {
+ PushBack(MSGSTART);
+
+ if (iPtr == command.parameters.size - 1)
+ PushEscaped( MSGCODE_TRANSMIT_EOM);
+ else
+ PushEscaped(MSGCODE_TRANSMIT);
+
+ PushEscaped(command.parameters[iPtr]);
+
+ PushBack(MSGEND);
+ }
+ }
+
+ // set timeout
+ transmit_timeout = command.transmit_timeout;
+ //TODO
+ }
+
+ CCECAdapterMessage &operator=(const CCECAdapterMessage &msg)
+ {
+ packet = msg.packet;
+ state = msg.state;
+ return *this;
+ }
+
+ CStdString ToString(void) const
+ {
+ CStdString strMsg;
+ if (Size() == 0)
+ {
+ strMsg = "empty message";
+ }
+ else
+ {
+ strMsg = MessageCodeAsString();
+
+ switch (Message())
+ {
+ case MSGCODE_TIMEOUT_ERROR:
+ case MSGCODE_HIGH_ERROR:
+ case MSGCODE_LOW_ERROR:
+ {
+ uint32_t iLine = (Size() >= 3) ? (At(1) << 8) | At(2) : 0;
+ uint32_t iTime = (Size() >= 7) ? (At(3) << 24) | (At(4) << 16) | (At(5) << 8) | At(6) : 0;
+ strMsg.AppendFormat(" line:%u", iLine);
+ strMsg.AppendFormat(" time:%u", iTime);
+ }
+ break;
+ case MSGCODE_FRAME_START:
+ if (Size() >= 2)
+ strMsg.AppendFormat(" initiator:%1x destination:%1x ack:%s %s", Initiator(), Destination(), IsACK() ? "high" : "low", IsEOM() ? "eom" : "");
+ break;
+ case MSGCODE_FRAME_DATA:
+ if (Size() >= 2)
+ strMsg.AppendFormat(" %02x %s", At(1), IsEOM() ? "eom" : "");
+ break;
+ default:
+ break;
+ }
+ }
+
+ return strMsg;
+ }
+
+ CStdString MessageCodeAsString(void) const
+ {
+ CStdString strMsg;
+ switch (Message())
+ {
+ case MSGCODE_NOTHING:
+ strMsg = "NOTHING";
+ break;
+ case MSGCODE_PING:
+ strMsg = "PING";
+ break;
+ case MSGCODE_TIMEOUT_ERROR:
+ strMsg = "TIMEOUT";
+ break;
+ case MSGCODE_HIGH_ERROR:
+ strMsg = "HIGH_ERROR";
+ break;
+ case MSGCODE_LOW_ERROR:
+ strMsg = "LOW_ERROR";
+ break;
+ case MSGCODE_FRAME_START:
+ strMsg = "FRAME_START";
+ break;
+ case MSGCODE_FRAME_DATA:
+ strMsg = "FRAME_DATA";
+ break;
+ case MSGCODE_RECEIVE_FAILED:
+ strMsg = "RECEIVE_FAILED";
+ break;
+ case MSGCODE_COMMAND_ACCEPTED:
+ strMsg = "COMMAND_ACCEPTED";
+ break;
+ case MSGCODE_COMMAND_REJECTED:
+ strMsg = "COMMAND_REJECTED";
+ break;
+ case MSGCODE_SET_ACK_MASK:
+ strMsg = "SET_ACK_MASK";
+ break;
+ case MSGCODE_TRANSMIT:
+ strMsg = "TRANSMIT";
+ break;
+ case MSGCODE_TRANSMIT_EOM:
+ strMsg = "TRANSMIT_EOM";
+ break;
+ case MSGCODE_TRANSMIT_IDLETIME:
+ strMsg = "TRANSMIT_IDLETIME";
+ break;
+ case MSGCODE_TRANSMIT_ACK_POLARITY:
+ strMsg = "TRANSMIT_ACK_POLARITY";
+ break;
+ case MSGCODE_TRANSMIT_LINE_TIMEOUT:
+ strMsg = "TRANSMIT_LINE_TIMEOUT";
+ break;
+ case MSGCODE_TRANSMIT_SUCCEEDED:
+ strMsg = "TRANSMIT_SUCCEEDED";
+ break;
+ case MSGCODE_TRANSMIT_FAILED_LINE:
+ strMsg = "TRANSMIT_FAILED_LINE";
+ break;
+ case MSGCODE_TRANSMIT_FAILED_ACK:
+ strMsg = "TRANSMIT_FAILED_ACK";
+ break;
+ case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA:
+ strMsg = "TRANSMIT_FAILED_TIMEOUT_DATA";
+ break;
+ case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE:
+ strMsg = "TRANSMIT_FAILED_TIMEOUT_LINE";
+ break;
+ case MSGCODE_FIRMWARE_VERSION:
+ strMsg = "FIRMWARE_VERSION";
+ break;
+ case MSGCODE_START_BOOTLOADER:
+ strMsg = "START_BOOTLOADER";
+ break;
+ case MSGCODE_FRAME_EOM:
+ strMsg = "FRAME_EOM";
+ break;
+ case MSGCODE_FRAME_ACK:
+ strMsg = "FRAME_ACK";
+ break;
+ }
+
+ return strMsg;
+ }
+
+ uint8_t operator[](uint8_t pos) const
+ {
+ return packet[pos];
+ }
+
+ uint8_t At(uint8_t pos) const
+ {
+ return packet[pos];
+ }
+
+ uint8_t Size(void) const
+ {
+ return packet.size;
+ }
+
+ bool IsEmpty(void) const
+ {
+ return packet.IsEmpty();
+ }
+
+ void Clear(void)
+ {
+ state = ADAPTER_MESSAGE_STATE_UNKNOWN;
+ transmit_timeout = CEC_DEFAULT_TRANSMIT_TIMEOUT;
+ packet.Clear();
+ maxTries = CEC_DEFAULT_TRANSMIT_RETRIES + 1;
+ tries = 0;
+ reply = MSGCODE_NOTHING;
+ isTransmission = true;
+ expectControllerAck = true;
+ }
+
+ void Shift(uint8_t iShiftBy)
+ {
+ packet.Shift(iShiftBy);
+ }
+
+ void PushBack(uint8_t add)
+ {
+ packet.PushBack(add);
+ }
+
+ void PushEscaped(uint8_t byte)
+ {
+ if (byte >= MSGESC)
+ {
+ PushBack(MSGESC);
+ PushBack(byte - ESCOFFSET);
+ }
+ else
+ {
+ PushBack(byte);
+ }
+ }
+
+ cec_adapter_messagecode Message(void) const
+ {
+ return packet.size >= 1 ?
+ (cec_adapter_messagecode) (packet.At(0) & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK)) :
+ MSGCODE_NOTHING;
+ }
+
+ bool IsEOM(void) const
+ {
+ return packet.size >= 1 ?
+ (packet.At(0) & MSGCODE_FRAME_EOM) != 0 :
+ false;
+ }
+
+ bool IsACK(void) const
+ {
+ return packet.size >= 1 ?
+ (packet.At(0) & MSGCODE_FRAME_ACK) != 0 :
+ false;
+ }
+
+ bool IsError(void) const
+ {
+ cec_adapter_messagecode code = Message();
+ return (code == MSGCODE_HIGH_ERROR ||
+ code == MSGCODE_LOW_ERROR ||
+ code == MSGCODE_RECEIVE_FAILED ||
+ code == MSGCODE_COMMAND_REJECTED ||
+ code == MSGCODE_TRANSMIT_LINE_TIMEOUT ||
+ code == MSGCODE_TRANSMIT_FAILED_LINE ||
+ code == MSGCODE_TRANSMIT_FAILED_ACK ||
+ code == MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA ||
+ code == MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE);
+ }
+
+ bool NeedsRetry(void) const
+ {
+ return reply == MSGCODE_NOTHING ||
+ reply == MSGCODE_RECEIVE_FAILED ||
+ reply == MSGCODE_TIMEOUT_ERROR ||
+ reply == MSGCODE_TRANSMIT_FAILED_LINE ||
+ reply == MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA ||
+ reply == MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE ||
+ reply == MSGCODE_TRANSMIT_LINE_TIMEOUT;
+ }
+
+ cec_logical_address Initiator(void) const
+ {
+ return packet.size >= 2 ?
+ (cec_logical_address) (packet.At(1) >> 4) :
+ CECDEVICE_UNKNOWN;
+ }
+
+ cec_logical_address Destination(void) const
+ {
+ return packet.size >= 2 ?
+ (cec_logical_address) (packet.At(1) & 0xF) :
+ CECDEVICE_UNKNOWN;
+ }
+
+ uint8_t maxTries;
+ uint8_t tries;
+ cec_adapter_messagecode reply;
+ cec_datapacket packet;
+ cec_adapter_message_state state;
+ int32_t transmit_timeout;
+ bool isTransmission;
+ bool expectControllerAck;
+ PLATFORM::CMutex mutex;
+ PLATFORM::CCondition condition;
+ };
+}
#include "CECAudioSystem.h"
#include "../CECProcessor.h"
#include "../implementations/CECCommandHandler.h"
+#include "../LibCEC.h"
using namespace CEC;
+using namespace PLATFORM;
#define ToString(p) m_processor->ToString(p)
bool CCECAudioSystem::SetAudioStatus(uint8_t status)
{
- CLockObject lock(&m_mutex);
+ 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;
}
bool CCECAudioSystem::SetSystemAudioModeStatus(const cec_system_audio_status mode)
{
- CLockObject lock(&m_mutex);
+ 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;
}
{
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);
+ CLockObject lock(m_mutex);
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %x -> %x: audio status '%2x'", m_iLogicalAddress, dest, m_audioStatus);
state = m_audioStatus;
}
{
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);
+ CLockObject lock(m_mutex);
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %x -> %x: set system audio mode '%2x'", m_iLogicalAddress, dest, m_audioStatus);
state = m_systemAudioStatus;
}
{
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);
+ CLockObject lock(m_mutex);
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %x -> %x: system audio mode '%s'", m_iLogicalAddress, dest, ToString(m_systemAudioStatus));
state = m_systemAudioStatus;
}
if (TransmitKeypress(CEC_USER_CONTROL_CODE_VOLUME_UP) && bSendRelease)
TransmitKeyRelease();
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_audioStatus;
}
if (TransmitKeypress(CEC_USER_CONTROL_CODE_VOLUME_DOWN) && bSendRelease)
TransmitKeyRelease();
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_audioStatus;
}
if (TransmitKeypress(CEC_USER_CONTROL_CODE_MUTE) && bSendRelease)
TransmitKeyRelease();
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_audioStatus;
}
#include "../implementations/CECCommandHandler.h"
#include "../implementations/SLCommandHandler.h"
#include "../implementations/VLCommandHandler.h"
-#include "../platform/timeutils.h"
+#include "../LibCEC.h"
using namespace CEC;
+using namespace PLATFORM;
#define ToString(p) m_processor->ToString(p)
m_iLastActive(0),
m_iLastPowerStateUpdate(0),
m_cecVersion(CEC_VERSION_UNKNOWN),
- m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN),
- m_handlerMutex(false)
+ m_deviceStatus(CEC_DEVICE_STATUS_UNKNOWN)
{
m_handler = new CCECCommandHandler(this);
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);
/* update "last active" */
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
m_iLastActive = GetTimeMs();
if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC)
/* change status to present */
if (bHandled)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
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;
}
}
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))
{
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
// m_powerStatus = CEC_POWER_STATUS_UNKNOWN;
m_powerStatus = CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON;
}
// /* 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();
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);
}
{
bool bRequestUpdate(false);
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
(bUpdate || m_cecVersion == CEC_VERSION_UNKNOWN));
}
if (bRequestUpdate)
RequestCecVersion();
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_cecVersion;
}
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();
{
bool bRequestUpdate(false);
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
(bUpdate || !strcmp(m_menuLanguage.language, "???")));
}
if (bRequestUpdate)
RequestMenuLanguage();
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_menuLanguage;
}
!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();
}
cec_menu_state CCECBusDevice::GetMenuState(void)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_menuState;
}
{
bool bRequestUpdate(false);
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
(bUpdate || m_strDeviceName.Equals(ToString(m_iLogicalAddress))) &&
m_type != CEC_DEVICE_TYPE_TV);
if (bRequestUpdate)
RequestOSDName();
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_strDeviceName;
}
!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();
}
{
bool bRequestUpdate(false);
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
(m_iPhysicalAddress == 0xFFFF || bUpdate));
}
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);
+ CLockObject lock(m_mutex);
return m_iPhysicalAddress;
}
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();
}
{
bool bRequestUpdate(false);
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
(bUpdate || m_powerStatus == CEC_POWER_STATUS_UNKNOWN ||
m_powerStatus == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON ||
if (bRequestUpdate)
RequestPowerStatus();
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_powerStatus;
}
!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();
}
{
bool bRequestUpdate(false);
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
bRequestUpdate = (GetStatus() == CEC_DEVICE_STATUS_PRESENT &&
(bUpdate || m_vendor == CEC_VENDOR_UNKNOWN));
}
if (bRequestUpdate)
RequestVendorId();
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_vendor;
}
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();
cec_bus_device_status CCECBusDevice::GetStatus(bool bForcePoll /* = false */)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (m_deviceStatus != CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC &&
(m_deviceStatus == CEC_DEVICE_STATUS_UNKNOWN || bForcePoll))
{
- lock.Leave();
+ lock.Unlock();
bool bPollAcked(false);
if (bForcePoll || NeedsPoll())
bPollAcked = m_processor->PollDevice(m_iLogicalAddress);
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)
{
- CLockObject lock(&m_mutex);
+ 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;
}
}
void CCECBusDevice::SetOSDName(CStdString strName)
{
- CLockObject lock(&m_mutex);
+ 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;
}
}
void CCECBusDevice::SetMenuState(const cec_menu_state state)
{
- CLockObject lock(&m_mutex);
+ 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;
}
}
void CCECBusDevice::SetInactiveSource(void)
{
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
m_bActiveSource = false;
}
void CCECBusDevice::SetActiveSource(void)
{
- CLockObject lock(&m_mutex);
+ 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)
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;
}
void CCECBusDevice::SetDeviceStatus(const cec_bus_device_status newStatus)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
switch (newStatus)
{
case CEC_DEVICE_STATUS_UNKNOWN:
void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
{
- CLockObject lock(&m_mutex);
+ 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;
}
}
void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /* = 0 */)
{
- CLockObject lock(&m_mutex);
+ 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)
{
- lock.Leave();
+ lock.Unlock();
SetPowerStatus(CEC_POWER_STATUS_ON);
}
}
void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
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;
}
}
bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */)
{
- CLockObject lock(&m_mutex);
- CLockObject handlerLock(&m_handlerMutex);
+ CLockObject lock(m_mutex);
+ CLockObject handlerLock(m_handlerMutex);
if (m_vendor != m_handler->GetVendorId())
{
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)
bool bVendorChanged(false);
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
bVendorChanged = (m_vendor != (cec_vendor_id)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;
}
bool bSendActiveSource(false);
{
- CLockObject lock(&m_mutex);
+ 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)
{
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);
+ CLockObject lock(m_mutex);
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): cec version %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_cecVersion));
version = m_cecVersion;
}
{
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);
+ CLockObject lock(m_mutex);
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> broadcast (F): inactive source", GetLogicalAddressName(), m_iLogicalAddress);
iPhysicalAddress = m_iPhysicalAddress;
}
{
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);
+ CLockObject lock(m_mutex);
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): menu state '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_menuState));
menuState = m_menuState;
}
{
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());
+ CLockObject lock(m_mutex);
+ 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;
}
{
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;
uint16_t iPhysicalAddress;
cec_device_type type;
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
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;
}
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);
+ CLockObject lock(m_mutex);
if (bReturn)
{
m_iLastActive = GetTimeMs();
{
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());
+ CLockObject lock(m_mutex);
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_powerStatus));
state = m_powerStatus;
}
{
uint64_t iVendorId;
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
iVendorId = (uint64_t)m_vendor;
}
{
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);
}
}
bool CCECBusDevice::ActivateSource(void)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_handler->ActivateSource();
}
#include <cectypes.h>
#include <set>
-#include "../platform/threads.h"
-#include "../util/StdString.h"
+#include "../platform/os.h"
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);
cec_version m_cecVersion;
cec_bus_device_status m_deviceStatus;
std::set<cec_opcode> m_unsupportedFeatures;
- CMutex m_mutex;
- CMutex m_handlerMutex;
+ PLATFORM::CMutex m_mutex;
+ PLATFORM::CMutex m_handlerMutex;
};
};
#include "CECPlaybackDevice.h"
#include "../implementations/CECCommandHandler.h"
#include "../CECProcessor.h"
+#include "../LibCEC.h"
using namespace CEC;
+using namespace PLATFORM;
#define ToString(p) m_processor->ToString(p)
cec_deck_info CCECPlaybackDevice::GetDeckStatus(void)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_deckStatus;
}
void CCECPlaybackDevice::SetDeckStatus(cec_deck_info deckStatus)
{
- CLockObject lock(&m_mutex);
+ 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;
}
}
cec_deck_control_mode CCECPlaybackDevice::GetDeckControlMode(void)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_deckControlMode;
}
void CCECPlaybackDevice::SetDeckControlMode(cec_deck_control_mode mode)
{
- CLockObject lock(&m_mutex);
+ 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;
}
}
{
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);
+ CLockObject lock(m_mutex);
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< %s (%X) -> %s (%X): deck status '%s'", GetLogicalAddressName(), m_iLogicalAddress, ToString(dest), dest, ToString(m_deckStatus));
state = m_deckStatus;
}
#include "ANCommandHandler.h"
#include "../devices/CECBusDevice.h"
#include "../CECProcessor.h"
-#include "../util/StdString.h"
+#include "../LibCEC.h"
using namespace CEC;
}
if (key.keycode != CEC_USER_CONTROL_CODE_UNKNOWN)
- {
- CStdString strLog;
- strLog.Format("key pressed: %1x", key.keycode);
- m_busDevice->AddLog(CEC_LOG_DEBUG, strLog);
-
- m_busDevice->GetProcessor()->AddKey(key);
- }
+ CLibCEC::AddKey(key);
}
return true;
#include "../devices/CECAudioSystem.h"
#include "../devices/CECPlaybackDevice.h"
#include "../CECProcessor.h"
+#include "../LibCEC.h"
using namespace CEC;
using namespace std;
+using namespace PLATFORM;
CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) :
m_busDevice(busDevice),
CCECCommandHandler::~CCECCommandHandler(void)
{
- CLockObject lock(&m_processor->m_transmitMutex);
- CLockObject receiveLock(&m_receiveMutex);
+ CLockObject lock(m_processor->m_transmitMutex);
+ CLockObject receiveLock(m_receiveMutex);
m_condition.Broadcast();
}
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);
-
- m_processor->AddCommand(command);
+ CLibCEC::AddCommand(command);
switch(command.opcode)
{
if (bHandled)
{
- CLockObject lock(&m_receiveMutex);
+ CLockObject lock(m_receiveMutex);
if (m_expectedResponse == CEC_OPCODE_NONE ||
m_expectedResponse == command.opcode)
m_condition.Signal();
{
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<CCECBusDevice *> devices;
- for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
+ for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++)
devices[iDevicePtr]->TransmitActiveSource();
return true;
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);
{
if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
{
- m_processor->AddKey();
+ CLibCEC::AddKey();
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());
-
if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER ||
command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION)
{
}
else
{
- m_processor->SetCurrentButton((cec_user_control_code) command.parameters[0]);
+ CLibCEC::SetCurrentButton((cec_user_control_code) command.parameters[0]);
}
return true;
}
bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
{
if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
- m_processor->AddKey();
+ CLibCEC::AddKey();
return true;
}
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);
}
-unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
+size_t CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
{
- unsigned int iReturn(0);
+ size_t iReturn(0);
cec_logical_addresses addresses = m_processor->GetLogicalAddresses();
for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
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;
}
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)
{
cec_command command;
cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_NAME);
- for (unsigned int iPtr = 0; iPtr < strDeviceName.length(); iPtr++)
+ for (size_t iPtr = 0; iPtr < strDeviceName.length(); iPtr++)
command.parameters.PushBack(strDeviceName.at(iPtr));
return Transmit(command, false);
cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_STRING);
command.parameters.PushBack((uint8_t)duration);
- unsigned int iLen = strlen(strMessage);
+ size_t iLen = strlen(strMessage);
if (iLen > 13) iLen = 13;
- for (unsigned int iPtr = 0; iPtr < iLen; iPtr++)
+ for (size_t iPtr = 0; iPtr < iLen; iPtr++)
command.parameters.PushBack(strMessage[iPtr]);
return Transmit(command, false);
{
uint8_t iTries(0), iMaxTries(command.opcode == CEC_OPCODE_NONE ? 1 : m_iTransmitRetries + 1);
- CLockObject writeLock(&m_processor->m_transmitMutex);
- CLockObject receiveLock(&m_receiveMutex);
+ CLockObject writeLock(m_processor->m_transmitMutex);
+ CLockObject receiveLock(m_receiveMutex);
++m_iUseCounter;
while (!bReturn && ++iTries <= iMaxTries)
{
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) :
+ m_condition.Wait(m_receiveMutex, m_iTransmitWait) :
true;
}
}
void CCECCommandHandler::MarkBusy(void)
{
- CLockObject receiveLock(&m_receiveMutex);
+ CLockObject receiveLock(m_receiveMutex);
++m_iUseCounter;
}
bool CCECCommandHandler::MarkReady(void)
{
- CLockObject receiveLock(&m_receiveMutex);
+ CLockObject receiveLock(m_receiveMutex);
return m_iUseCounter > 0 ? (--m_iUseCounter == 0) : true;
}
bool CCECCommandHandler::InUse(void)
{
- CLockObject receiveLock(&m_receiveMutex);
+ CLockObject receiveLock(m_receiveMutex);
return m_iUseCounter > 0;
}
#include <cectypes.h>
#include <vector>
-#include "../util/StdString.h"
-#include "../platform/threads.h"
+#include "../platform/os.h"
namespace CEC
{
virtual bool HandleVendorCommand(const cec_command &command);
virtual void UnhandledCommand(const cec_command &command);
- virtual unsigned int GetMyDevices(std::vector<CCECBusDevice *> &devices) const;
+ virtual size_t GetMyDevices(std::vector<CCECBusDevice *> &devices) const;
virtual CCECBusDevice *GetDevice(cec_logical_address iLogicalAddress) const;
virtual CCECBusDevice *GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const;
virtual CCECBusDevice *GetDeviceByType(cec_device_type type) const;
virtual bool Transmit(cec_command &command, bool bExpectResponse = true, cec_opcode expectedResponse = CEC_OPCODE_NONE);
- CCECBusDevice *m_busDevice;
- CCECProcessor *m_processor;
- int32_t m_iTransmitTimeout;
- int32_t m_iTransmitWait;
- int8_t m_iTransmitRetries;
- bool m_bHandlerInited;
- uint8_t m_iUseCounter;
- cec_opcode m_expectedResponse;
- bool m_bOPTSendDeckStatusUpdateOnActiveSource;
- cec_vendor_id m_vendorId;
- CMutex m_receiveMutex;
- CCondition m_condition;
+ CCECBusDevice * m_busDevice;
+ CCECProcessor * m_processor;
+ int32_t m_iTransmitTimeout;
+ int32_t m_iTransmitWait;
+ int8_t m_iTransmitRetries;
+ bool m_bHandlerInited;
+ uint8_t m_iUseCounter;
+ cec_opcode m_expectedResponse;
+ bool m_bOPTSendDeckStatusUpdateOnActiveSource;
+ cec_vendor_id m_vendorId;
+ PLATFORM::CMutex m_receiveMutex;
+ PLATFORM::CCondition m_condition;
};
};
#include "../devices/CECBusDevice.h"
#include "../devices/CECPlaybackDevice.h"
#include "../CECProcessor.h"
-#include "../platform/timeutils.h"
-#include "../platform/threads.h"
using namespace CEC;
* http://www.pulse-eight.net/
*/
-#include "../platform/threads.h"
+#include "os.h"
#include <queue>
-namespace CEC
+namespace PLATFORM
{
template<typename _BType>
- struct CecBuffer
+ struct SyncedBuffer
{
public:
- CecBuffer(unsigned int iMaxSize = 100)
+ SyncedBuffer(size_t iMaxSize = 100)
{
m_maxSize = iMaxSize;
}
- virtual ~CecBuffer(void)
+ virtual ~SyncedBuffer(void)
{
+ CLockObject lock(m_mutex, true);
Clear();
}
m_buffer.pop();
}
- int Size(void) const { return m_buffer.size(); }
+ size_t Size(void) const { return m_buffer.size(); }
bool Push(_BType entry)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (m_buffer.size() == m_maxSize)
return false;
bool Pop(_BType &entry)
{
bool bReturn(false);
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (!m_buffer.empty())
{
entry = m_buffer.front();
}
private:
- unsigned int m_maxSize;
+ size_t m_maxSize;
std::queue<_BType> m_buffer;
CMutex m_mutex;
};
+++ /dev/null
-#pragma once
-/*
- * Copyright (C) 2005-2011 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#if defined(_WIN32) || defined(_WIN64)
-#ifndef __WINDOWS__
-#define __WINDOWS__
-#endif
-#endif
-
-#if defined(__WINDOWS__)
-#include "windows/os_windows.h"
-#else
-#include "linux/os_posix.h"
-#endif
-
-#if !defined(TRUE)
-#define TRUE 1
-#endif
-
-#if !defined(FALSE)
-#define FALSE 0
-#endif
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+#if defined(_WIN32) || defined(_WIN64)
+#ifndef __WINDOWS__
+#define __WINDOWS__
+#endif
+#include "windows/os-types.h"
+#include "windows/os-threads.h"
+#else
+#include "posix/os-types.h"
+#include "posix/os-threads.h"
+#endif
+
+#include "timeutils.h"
+#include "threads/threads.h"
+#include "buffer.h"
+#include "StdString.h"
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+namespace PLATFORM
+{
+ inline pthread_mutexattr_t *GetRecursiveMutexAttribute(void)
+ {
+ static pthread_mutexattr_t g_mutexAttr;
+ static bool bAttributeInitialised = false;
+ if (!bAttributeInitialised)
+ {
+ pthread_mutexattr_init(&g_mutexAttr);
+ pthread_mutexattr_settype(&g_mutexAttr, PTHREAD_MUTEX_RECURSIVE);
+ bAttributeInitialised = true;
+ }
+ return &g_mutexAttr;
+ }
+
+ inline struct timespec GetAbsTime(uint64_t iIncreaseBy = 0)
+ {
+ struct timespec abstime;
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ iIncreaseBy += now.tv_usec / 1000;
+ abstime.tv_sec = now.tv_sec + (time_t)(iIncreaseBy / 1000);
+ abstime.tv_nsec = (int32_t)((iIncreaseBy % (uint32_t)1000) * (uint32_t)1000000);
+ return abstime;
+ }
+
+ typedef pthread_t thread_t;
+
+ #define ThreadsCreate(thread, func, arg) (pthread_create(&thread, NULL, (void *(*) (void *))func, (void *)arg) == 0)
+ #define ThreadsWait(thread, retval) (pthread_join(thread, retval) == 0)
+
+ typedef pthread_mutex_t mutex_t;
+ #define MutexCreate(mutex) pthread_mutex_init(&mutex, GetRecursiveMutexAttribute());
+ #define MutexDelete(mutex) pthread_mutex_destroy(&mutex);
+ #define MutexLock(mutex) (pthread_mutex_lock(&mutex) == 0)
+ #define MutexTryLock(mutex) (pthread_mutex_trylock(&mutex) == 0)
+ #define MutexUnlock(mutex) pthread_mutex_unlock(&mutex)
+
+ typedef pthread_cond_t condition_t;
+ #define ConditionCreate(cond) pthread_cond_init(&cond, NULL)
+ #define ConditionDelete(cond) pthread_cond_destroy(&cond)
+ #define ConditionSignal(cond) pthread_cond_signal(&cond)
+ #define ConditionBroadcast(cond) pthread_cond_broadcast(&cond)
+ inline bool ConditionWait(condition_t &cond, mutex_t &mutex, uint32_t iTimeout)
+ {
+ sched_yield();
+ if (iTimeout > 0)
+ {
+ struct timespec timeout = GetAbsTime(iTimeout);
+ return (pthread_cond_timedwait(&cond, &mutex, &timeout) == 0);
+ }
+ return (pthread_cond_wait(&cond, &mutex) == 0);
+ }
+}
#include <errno.h>
#include <sys/time.h>
#ifndef __APPLE__
-#include <sys/prctl.h>
+#include <sys/prctl.h>
#endif
#include <pthread.h>
#include <poll.h>
#include <semaphore.h>
+#include <stdint.h>
#define LIBTYPE
#define DECLSPEC
+
#include <stdio.h>
#include <fcntl.h>
-#include "../serialport.h"
-#include "../baudrate.h"
+#include "../serialport/serialport.h"
+#include "../serialport/baudrate.h"
#include "../timeutils.h"
#if defined(__APPLE__)
#endif
#endif
using namespace std;
-using namespace CEC;
+using namespace PLATFORM;
CSerialPort::CSerialPort()
{
Close();
}
-int8_t CSerialPort::Write(CCECAdapterMessage *data)
+int64_t CSerialPort::Write(uint8_t* data, uint32_t len)
{
fd_set port;
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (m_fd == -1)
{
m_error = "port closed";
return -1;
}
- int32_t byteswritten = 0;
-
- struct timeval timeout, *tv;
- if (data->transmit_timeout <= 0)
- {
+ int64_t byteswritten = 0;
+ struct timeval *tv;
+//TODO
+// struct timeval timeout, *tv;
+// if (data->transmit_timeout <= 0)
+// {
tv = NULL;
- }
- else
- {
- timeout.tv_sec = (long int)data->transmit_timeout / (long int)1000.;
- timeout.tv_usec = (long int)data->transmit_timeout % (long int)1000.;
- tv = &timeout;
- }
-
- while (byteswritten < (int32_t) data->size())
+// }
+// else
+// {
+// timeout.tv_sec = (long int)data->transmit_timeout / (long int)1000.;
+// timeout.tv_usec = (long int)data->transmit_timeout % (long int)1000.;
+// tv = &timeout;
+// }
+
+ while (byteswritten < len)
{
FD_ZERO(&port);
FD_SET(m_fd, &port);
return -1;
}
- returnv = write(m_fd, data->packet.data + byteswritten, data->size() - byteswritten);
+ returnv = write(m_fd, data + byteswritten, len - byteswritten);
if (returnv == -1)
{
m_error = strerror(errno);
{
printf("%s write:", m_name.c_str());
for (int i = 0; i < byteswritten; i++)
- printf(" %02x", data->at(i));
+ printf(" %02x", data[i]);
printf("\n");
}
int64_t now(0), target(0);
int32_t bytesread = 0;
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (m_fd == -1)
{
m_error = "port closed";
{
m_name = name;
m_error = strerror(errno);
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (databits < 5 || databits > 8)
{
void CSerialPort::Close()
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (m_fd != -1)
{
close(m_fd);
bool CSerialPort::IsOpen()
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_fd != -1;
}
+++ /dev/null
-/* This is an implementation of the threads API of POSIX 1003.1-2001.
- *
- * --------------------------------------------------------------------------
- *
- * Pthreads-win32 - POSIX Threads Library for Win32
- * Copyright(C) 1998 John E. Bossom
- * Copyright(C) 1999,2005 Pthreads-win32 contributors
- *
- * Contact Email: rpj@callisto.canberra.edu.au
- *
- * The current list of contributors is contained
- * in the file CONTRIBUTORS included with the source
- * code distribution. The list can also be seen at the
- * following World Wide Web location:
- * http://sources.redhat.com/pthreads-win32/contributors.html
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#if !defined( PTHREAD_H )
-#define PTHREAD_H
-
-/*
- * See the README file for an explanation of the pthreads-win32 version
- * numbering scheme and how the DLL is named etc.
- */
-#define PTW32_VERSION 2,8,0,0
-#define PTW32_VERSION_STRING "2, 8, 0, 0\0"
-
-/* There are three implementations of cancel cleanup.
- * Note that pthread.h is included in both application
- * compilation units and also internally for the library.
- * The code here and within the library aims to work
- * for all reasonable combinations of environments.
- *
- * The three implementations are:
- *
- * WIN32 SEH
- * C
- * C++
- *
- * Please note that exiting a push/pop block via
- * "return", "exit", "break", or "continue" will
- * lead to different behaviour amongst applications
- * depending upon whether the library was built
- * using SEH, C++, or C. For example, a library built
- * with SEH will call the cleanup routine, while both
- * C++ and C built versions will not.
- */
-
-/*
- * Define defaults for cleanup code.
- * Note: Unless the build explicitly defines one of the following, then
- * we default to standard C style cleanup. This style uses setjmp/longjmp
- * in the cancelation and thread exit implementations and therefore won't
- * do stack unwinding if linked to applications that have it (e.g.
- * C++ apps). This is currently consistent with most/all commercial Unix
- * POSIX threads implementations.
- */
-#if !defined( __CLEANUP_SEH ) && !defined( __CLEANUP_CXX ) && !defined( __CLEANUP_C )
-# define __CLEANUP_C
-#endif
-
-#if defined( __CLEANUP_SEH ) && ( !defined( _MSC_VER ) && !defined(PTW32_RC_MSC))
-#error ERROR [__FILE__, line __LINE__]: SEH is not supported for this compiler.
-#endif
-
-/*
- * Stop here if we are being included by the resource compiler.
- */
-#ifndef RC_INVOKED
-
-#undef PTW32_LEVEL
-
-#if defined(_POSIX_SOURCE)
-#define PTW32_LEVEL 0
-/* Early POSIX */
-#endif
-
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
-#undef PTW32_LEVEL
-#define PTW32_LEVEL 1
-/* Include 1b, 1c and 1d */
-#endif
-
-#if defined(INCLUDE_NP)
-#undef PTW32_LEVEL
-#define PTW32_LEVEL 2
-/* Include Non-Portable extensions */
-#endif
-
-#define PTW32_LEVEL_MAX 3
-
-#if !defined(PTW32_LEVEL)
-#define PTW32_LEVEL PTW32_LEVEL_MAX
-/* Include everything */
-#endif
-
-#ifdef _UWIN
-# define HAVE_STRUCT_TIMESPEC 1
-# define HAVE_SIGNAL_H 1
-# undef HAVE_CONFIG_H
-# pragma comment(lib, "pthread")
-#endif
-
-/*
- * -------------------------------------------------------------
- *
- *
- * Module: pthread.h
- *
- * Purpose:
- * Provides an implementation of PThreads based upon the
- * standard:
- *
- * POSIX 1003.1-2001
- * and
- * The Single Unix Specification version 3
- *
- * (these two are equivalent)
- *
- * in order to enhance code portability between Windows,
- * various commercial Unix implementations, and Linux.
- *
- * See the ANNOUNCE file for a full list of conforming
- * routines and defined constants, and a list of missing
- * routines and constants not defined in this implementation.
- *
- * Authors:
- * There have been many contributors to this library.
- * The initial implementation was contributed by
- * John Bossom, and several others have provided major
- * sections or revisions of parts of the implementation.
- * Often significant effort has been contributed to
- * find and fix important bugs and other problems to
- * improve the reliability of the library, which sometimes
- * is not reflected in the amount of code which changed as
- * result.
- * As much as possible, the contributors are acknowledged
- * in the ChangeLog file in the source code distribution
- * where their changes are noted in detail.
- *
- * Contributors are listed in the CONTRIBUTORS file.
- *
- * As usual, all bouquets go to the contributors, and all
- * brickbats go to the project maintainer.
- *
- * Maintainer:
- * The code base for this project is coordinated and
- * eventually pre-tested, packaged, and made available by
- *
- * Ross Johnson <rpj@callisto.canberra.edu.au>
- *
- * QA Testers:
- * Ultimately, the library is tested in the real world by
- * a host of competent and demanding scientists and
- * engineers who report bugs and/or provide solutions
- * which are then fixed or incorporated into subsequent
- * versions of the library. Each time a bug is fixed, a
- * test case is written to prove the fix and ensure
- * that later changes to the code don't reintroduce the
- * same error. The number of test cases is slowly growing
- * and therefore so is the code reliability.
- *
- * Compliance:
- * See the file ANNOUNCE for the list of implemented
- * and not-implemented routines and defined options.
- * Of course, these are all defined is this file as well.
- *
- * Web site:
- * The source code and other information about this library
- * are available from
- *
- * http://sources.redhat.com/pthreads-win32/
- *
- * -------------------------------------------------------------
- */
-
-/* Try to avoid including windows.h */
-#if defined(__MINGW32__) && defined(__cplusplus)
-#define PTW32_INCLUDE_WINDOWS_H
-#endif
-
-#ifdef PTW32_INCLUDE_WINDOWS_H
-#include <windows.h>
-#endif
-
-#if defined(_MSC_VER) && _MSC_VER < 1300 || defined(__DMC__)
-/*
- * VC++6.0 or early compiler's header has no DWORD_PTR type.
- */
-typedef unsigned long DWORD_PTR;
-#endif
-/*
- * -----------------
- * autoconf switches
- * -----------------
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#ifndef NEED_FTIME
-#include <time.h>
-#else /* NEED_FTIME */
-/* use native WIN32 time API */
-#endif /* NEED_FTIME */
-
-#if HAVE_SIGNAL_H
-#include <signal.h>
-#endif /* HAVE_SIGNAL_H */
-
-#include <setjmp.h>
-#include <limits.h>
-
-/*
- * Boolean values to make us independent of system includes.
- */
-enum {
- PTW32_FALSE = 0,
- PTW32_TRUE = (! PTW32_FALSE)
-};
-
-/*
- * This is a duplicate of what is in the autoconf config.h,
- * which is only used when building the pthread-win32 libraries.
- */
-
-#ifndef PTW32_CONFIG_H
-# if defined(WINCE)
-# define NEED_ERRNO
-# define NEED_SEM
-# endif
-# if defined(_UWIN) || defined(__MINGW32__)
-# define HAVE_MODE_T
-# endif
-#endif
-
-/*
- *
- */
-
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
-#ifdef NEED_ERRNO
-#include "need_errno.h"
-#else
-#include <errno.h>
-#endif
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
-
-/*
- * Several systems don't define some error numbers.
- */
-#ifndef ENOTSUP
-# define ENOTSUP 48 /* This is the value in Solaris. */
-#endif
-
-#ifndef ETIMEDOUT
-# define ETIMEDOUT 10060 /* This is the value in winsock.h. */
-#endif
-
-#ifndef ENOSYS
-# define ENOSYS 140 /* Semi-arbitrary value */
-#endif
-
-#ifndef EDEADLK
-# ifdef EDEADLOCK
-# define EDEADLK EDEADLOCK
-# else
-# define EDEADLK 36 /* This is the value in MSVC. */
-# endif
-#endif
-
-#include "sched.h"
-
-/*
- * To avoid including windows.h we define only those things that we
- * actually need from it.
- */
-#ifndef PTW32_INCLUDE_WINDOWS_H
-#ifndef HANDLE
-# define PTW32__HANDLE_DEF
-# define HANDLE void *
-#endif
-#ifndef DWORD
-# define PTW32__DWORD_DEF
-# define DWORD unsigned long
-#endif
-#endif
-
-#ifndef HAVE_STRUCT_TIMESPEC
-#define HAVE_STRUCT_TIMESPEC 1
-struct timespec {
- long tv_sec;
- long tv_nsec;
-};
-#endif /* HAVE_STRUCT_TIMESPEC */
-
-#ifndef SIG_BLOCK
-#define SIG_BLOCK 0
-#endif /* SIG_BLOCK */
-
-#ifndef SIG_UNBLOCK
-#define SIG_UNBLOCK 1
-#endif /* SIG_UNBLOCK */
-
-#ifndef SIG_SETMASK
-#define SIG_SETMASK 2
-#endif /* SIG_SETMASK */
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-/*
- * -------------------------------------------------------------
- *
- * POSIX 1003.1-2001 Options
- * =========================
- *
- * Options are normally set in <unistd.h>, which is not provided
- * with pthreads-win32.
- *
- * For conformance with the Single Unix Specification (version 3), all of the
- * options below are defined, and have a value of either -1 (not supported)
- * or 200112L (supported).
- *
- * These options can neither be left undefined nor have a value of 0, because
- * either indicates that sysconf(), which is not implemented, may be used at
- * runtime to check the status of the option.
- *
- * _POSIX_THREADS (== 200112L)
- * If == 200112L, you can use threads
- *
- * _POSIX_THREAD_ATTR_STACKSIZE (== 200112L)
- * If == 200112L, you can control the size of a thread's
- * stack
- * pthread_attr_getstacksize
- * pthread_attr_setstacksize
- *
- * _POSIX_THREAD_ATTR_STACKADDR (== -1)
- * If == 200112L, you can allocate and control a thread's
- * stack. If not supported, the following functions
- * will return ENOSYS, indicating they are not
- * supported:
- * pthread_attr_getstackaddr
- * pthread_attr_setstackaddr
- *
- * _POSIX_THREAD_PRIORITY_SCHEDULING (== -1)
- * If == 200112L, you can use realtime scheduling.
- * This option indicates that the behaviour of some
- * implemented functions conforms to the additional TPS
- * requirements in the standard. E.g. rwlocks favour
- * writers over readers when threads have equal priority.
- *
- * _POSIX_THREAD_PRIO_INHERIT (== -1)
- * If == 200112L, you can create priority inheritance
- * mutexes.
- * pthread_mutexattr_getprotocol +
- * pthread_mutexattr_setprotocol +
- *
- * _POSIX_THREAD_PRIO_PROTECT (== -1)
- * If == 200112L, you can create priority ceiling mutexes
- * Indicates the availability of:
- * pthread_mutex_getprioceiling
- * pthread_mutex_setprioceiling
- * pthread_mutexattr_getprioceiling
- * pthread_mutexattr_getprotocol +
- * pthread_mutexattr_setprioceiling
- * pthread_mutexattr_setprotocol +
- *
- * _POSIX_THREAD_PROCESS_SHARED (== -1)
- * If set, you can create mutexes and condition
- * variables that can be shared with another
- * process.If set, indicates the availability
- * of:
- * pthread_mutexattr_getpshared
- * pthread_mutexattr_setpshared
- * pthread_condattr_getpshared
- * pthread_condattr_setpshared
- *
- * _POSIX_THREAD_SAFE_FUNCTIONS (== 200112L)
- * If == 200112L you can use the special *_r library
- * functions that provide thread-safe behaviour
- *
- * _POSIX_READER_WRITER_LOCKS (== 200112L)
- * If == 200112L, you can use read/write locks
- *
- * _POSIX_SPIN_LOCKS (== 200112L)
- * If == 200112L, you can use spin locks
- *
- * _POSIX_BARRIERS (== 200112L)
- * If == 200112L, you can use barriers
- *
- * + These functions provide both 'inherit' and/or
- * 'protect' protocol, based upon these macro
- * settings.
- *
- * -------------------------------------------------------------
- */
-
-/*
- * POSIX Options
- */
-#undef _POSIX_THREADS
-#define _POSIX_THREADS 200112L
-
-#undef _POSIX_READER_WRITER_LOCKS
-#define _POSIX_READER_WRITER_LOCKS 200112L
-
-#undef _POSIX_SPIN_LOCKS
-#define _POSIX_SPIN_LOCKS 200112L
-
-#undef _POSIX_BARRIERS
-#define _POSIX_BARRIERS 200112L
-
-#undef _POSIX_THREAD_SAFE_FUNCTIONS
-#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
-
-#undef _POSIX_THREAD_ATTR_STACKSIZE
-#define _POSIX_THREAD_ATTR_STACKSIZE 200112L
-
-/*
- * The following options are not supported
- */
-#undef _POSIX_THREAD_ATTR_STACKADDR
-#define _POSIX_THREAD_ATTR_STACKADDR -1
-
-#undef _POSIX_THREAD_PRIO_INHERIT
-#define _POSIX_THREAD_PRIO_INHERIT -1
-
-#undef _POSIX_THREAD_PRIO_PROTECT
-#define _POSIX_THREAD_PRIO_PROTECT -1
-
-/* TPS is not fully supported. */
-#undef _POSIX_THREAD_PRIORITY_SCHEDULING
-#define _POSIX_THREAD_PRIORITY_SCHEDULING -1
-
-#undef _POSIX_THREAD_PROCESS_SHARED
-#define _POSIX_THREAD_PROCESS_SHARED -1
-
-
-/*
- * POSIX 1003.1-2001 Limits
- * ===========================
- *
- * These limits are normally set in <limits.h>, which is not provided with
- * pthreads-win32.
- *
- * PTHREAD_DESTRUCTOR_ITERATIONS
- * Maximum number of attempts to destroy
- * a thread's thread-specific data on
- * termination (must be at least 4)
- *
- * PTHREAD_KEYS_MAX
- * Maximum number of thread-specific data keys
- * available per process (must be at least 128)
- *
- * PTHREAD_STACK_MIN
- * Minimum supported stack size for a thread
- *
- * PTHREAD_THREADS_MAX
- * Maximum number of threads supported per
- * process (must be at least 64).
- *
- * SEM_NSEMS_MAX
- * The maximum number of semaphores a process can have.
- * (must be at least 256)
- *
- * SEM_VALUE_MAX
- * The maximum value a semaphore can have.
- * (must be at least 32767)
- *
- */
-#undef _POSIX_THREAD_DESTRUCTOR_ITERATIONS
-#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
-
-#undef PTHREAD_DESTRUCTOR_ITERATIONS
-#define PTHREAD_DESTRUCTOR_ITERATIONS _POSIX_THREAD_DESTRUCTOR_ITERATIONS
-
-#undef _POSIX_THREAD_KEYS_MAX
-#define _POSIX_THREAD_KEYS_MAX 128
-
-#undef PTHREAD_KEYS_MAX
-#define PTHREAD_KEYS_MAX _POSIX_THREAD_KEYS_MAX
-
-#undef PTHREAD_STACK_MIN
-#define PTHREAD_STACK_MIN 0
-
-#undef _POSIX_THREAD_THREADS_MAX
-#define _POSIX_THREAD_THREADS_MAX 64
-
- /* Arbitrary value */
-#undef PTHREAD_THREADS_MAX
-#define PTHREAD_THREADS_MAX 2019
-
-#undef _POSIX_SEM_NSEMS_MAX
-#define _POSIX_SEM_NSEMS_MAX 256
-
- /* Arbitrary value */
-#undef SEM_NSEMS_MAX
-#define SEM_NSEMS_MAX 1024
-
-#undef _POSIX_SEM_VALUE_MAX
-#define _POSIX_SEM_VALUE_MAX 32767
-
-#undef SEM_VALUE_MAX
-#define SEM_VALUE_MAX INT_MAX
-
-
-#if __GNUC__ && ! defined (__declspec)
-# error Please upgrade your GNU compiler to one that supports __declspec.
-#endif
-
-/*
- * When building the DLL code, you should define PTW32_BUILD so that
- * the variables/functions are exported correctly. When using the DLL,
- * do NOT define PTW32_BUILD, and then the variables/functions will
- * be imported correctly.
- */
-#ifndef PTW32_STATIC_LIB
-# ifdef PTW32_BUILD
-# define PTW32_DLLPORT __declspec (dllexport)
-# else
-# define PTW32_DLLPORT __declspec (dllimport)
-# endif
-#else
-# define PTW32_DLLPORT
-#endif
-
-/*
- * The Open Watcom C/C++ compiler uses a non-standard calling convention
- * that passes function args in registers unless __cdecl is explicitly specified
- * in exposed function prototypes.
- *
- * We force all calls to cdecl even though this could slow Watcom code down
- * slightly. If you know that the Watcom compiler will be used to build both
- * the DLL and application, then you can probably define this as a null string.
- * Remember that pthread.h (this file) is used for both the DLL and application builds.
- */
-#define PTW32_CDECL __cdecl
-
-#if defined(_UWIN) && PTW32_LEVEL >= PTW32_LEVEL_MAX
-# include <sys/types.h>
-#else
-/*
- * Generic handle type - intended to extend uniqueness beyond
- * that available with a simple pointer. It should scale for either
- * IA-32 or IA-64.
- */
-typedef struct {
- void * p; /* Pointer to actual object */
- unsigned int x; /* Extra information - reuse count etc */
-} ptw32_handle_t;
-
-typedef ptw32_handle_t pthread_t;
-typedef struct pthread_attr_t_ * pthread_attr_t;
-typedef struct pthread_once_t_ pthread_once_t;
-typedef struct pthread_key_t_ * pthread_key_t;
-typedef struct pthread_mutex_t_ * pthread_mutex_t;
-typedef struct pthread_mutexattr_t_ * pthread_mutexattr_t;
-typedef struct pthread_cond_t_ * pthread_cond_t;
-typedef struct pthread_condattr_t_ * pthread_condattr_t;
-#endif
-typedef struct pthread_rwlock_t_ * pthread_rwlock_t;
-typedef struct pthread_rwlockattr_t_ * pthread_rwlockattr_t;
-typedef struct pthread_spinlock_t_ * pthread_spinlock_t;
-typedef struct pthread_barrier_t_ * pthread_barrier_t;
-typedef struct pthread_barrierattr_t_ * pthread_barrierattr_t;
-
-/*
- * ====================
- * ====================
- * POSIX Threads
- * ====================
- * ====================
- */
-
-enum {
-/*
- * pthread_attr_{get,set}detachstate
- */
- PTHREAD_CREATE_JOINABLE = 0, /* Default */
- PTHREAD_CREATE_DETACHED = 1,
-
-/*
- * pthread_attr_{get,set}inheritsched
- */
- PTHREAD_INHERIT_SCHED = 0,
- PTHREAD_EXPLICIT_SCHED = 1, /* Default */
-
-/*
- * pthread_{get,set}scope
- */
- PTHREAD_SCOPE_PROCESS = 0,
- PTHREAD_SCOPE_SYSTEM = 1, /* Default */
-
-/*
- * pthread_setcancelstate paramters
- */
- PTHREAD_CANCEL_ENABLE = 0, /* Default */
- PTHREAD_CANCEL_DISABLE = 1,
-
-/*
- * pthread_setcanceltype parameters
- */
- PTHREAD_CANCEL_ASYNCHRONOUS = 0,
- PTHREAD_CANCEL_DEFERRED = 1, /* Default */
-
-/*
- * pthread_mutexattr_{get,set}pshared
- * pthread_condattr_{get,set}pshared
- */
- PTHREAD_PROCESS_PRIVATE = 0,
- PTHREAD_PROCESS_SHARED = 1,
-
-/*
- * pthread_barrier_wait
- */
- PTHREAD_BARRIER_SERIAL_THREAD = -1
-};
-
-/*
- * ====================
- * ====================
- * Cancelation
- * ====================
- * ====================
- */
-#define PTHREAD_CANCELED ((void *) -1)
-
-
-/*
- * ====================
- * ====================
- * Once Key
- * ====================
- * ====================
- */
-#define PTHREAD_ONCE_INIT { PTW32_FALSE, 0, 0, 0}
-
-struct pthread_once_t_
-{
- int done; /* indicates if user function has been executed */
- void * lock;
- int reserved1;
- int reserved2;
-};
-
-
-/*
- * ====================
- * ====================
- * Object initialisers
- * ====================
- * ====================
- */
-#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
-#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2)
-#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3)
-
-/*
- * Compatibility with LinuxThreads
- */
-#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
-#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP PTHREAD_ERRORCHECK_MUTEX_INITIALIZER
-
-#define PTHREAD_COND_INITIALIZER ((pthread_cond_t) -1)
-
-#define PTHREAD_RWLOCK_INITIALIZER ((pthread_rwlock_t) -1)
-
-#define PTHREAD_SPINLOCK_INITIALIZER ((pthread_spinlock_t) -1)
-
-
-/*
- * Mutex types.
- */
-enum
-{
- /* Compatibility with LinuxThreads */
- PTHREAD_MUTEX_FAST_NP,
- PTHREAD_MUTEX_RECURSIVE_NP,
- PTHREAD_MUTEX_ERRORCHECK_NP,
- PTHREAD_MUTEX_TIMED_NP = PTHREAD_MUTEX_FAST_NP,
- PTHREAD_MUTEX_ADAPTIVE_NP = PTHREAD_MUTEX_FAST_NP,
- /* For compatibility with POSIX */
- PTHREAD_MUTEX_NORMAL = PTHREAD_MUTEX_FAST_NP,
- PTHREAD_MUTEX_RECURSIVE = PTHREAD_MUTEX_RECURSIVE_NP,
- PTHREAD_MUTEX_ERRORCHECK = PTHREAD_MUTEX_ERRORCHECK_NP,
- PTHREAD_MUTEX_DEFAULT = PTHREAD_MUTEX_NORMAL
-};
-
-
-typedef struct ptw32_cleanup_t ptw32_cleanup_t;
-
-#if defined(_MSC_VER)
-/* Disable MSVC 'anachronism used' warning */
-#pragma warning( disable : 4229 )
-#endif
-
-typedef void (* PTW32_CDECL ptw32_cleanup_callback_t)(void *);
-
-#if defined(_MSC_VER)
-#pragma warning( default : 4229 )
-#endif
-
-struct ptw32_cleanup_t
-{
- ptw32_cleanup_callback_t routine;
- void *arg;
- struct ptw32_cleanup_t *prev;
-};
-
-#ifdef __CLEANUP_SEH
- /*
- * WIN32 SEH version of cancel cleanup.
- */
-
-#define pthread_cleanup_push( _rout, _arg ) \
- { \
- ptw32_cleanup_t _cleanup; \
- \
- _cleanup.routine = (ptw32_cleanup_callback_t)(_rout); \
- _cleanup.arg = (_arg); \
- __try \
- { \
-
-#define pthread_cleanup_pop( _execute ) \
- } \
- __finally \
- { \
- if( _execute || AbnormalTermination()) \
- { \
- (*(_cleanup.routine))( _cleanup.arg ); \
- } \
- } \
- }
-
-#else /* __CLEANUP_SEH */
-
-#ifdef __CLEANUP_C
-
- /*
- * C implementation of PThreads cancel cleanup
- */
-
-#define pthread_cleanup_push( _rout, _arg ) \
- { \
- ptw32_cleanup_t _cleanup; \
- \
- ptw32_push_cleanup( &_cleanup, (ptw32_cleanup_callback_t) (_rout), (_arg) ); \
-
-#define pthread_cleanup_pop( _execute ) \
- (void) ptw32_pop_cleanup( _execute ); \
- }
-
-#else /* __CLEANUP_C */
-
-#ifdef __CLEANUP_CXX
-
- /*
- * C++ version of cancel cleanup.
- * - John E. Bossom.
- */
-
- class PThreadCleanup {
- /*
- * PThreadCleanup
- *
- * Purpose
- * This class is a C++ helper class that is
- * used to implement pthread_cleanup_push/
- * pthread_cleanup_pop.
- * The destructor of this class automatically
- * pops the pushed cleanup routine regardless
- * of how the code exits the scope
- * (i.e. such as by an exception)
- */
- ptw32_cleanup_callback_t cleanUpRout;
- void * obj;
- int executeIt;
-
- public:
- PThreadCleanup() :
- cleanUpRout( 0 ),
- obj( 0 ),
- executeIt( 0 )
- /*
- * No cleanup performed
- */
- {
- }
-
- PThreadCleanup(
- ptw32_cleanup_callback_t routine,
- void * arg ) :
- cleanUpRout( routine ),
- obj( arg ),
- executeIt( 1 )
- /*
- * Registers a cleanup routine for 'arg'
- */
- {
- }
-
- ~PThreadCleanup()
- {
- if ( executeIt && ((void *) cleanUpRout != (void *) 0) )
- {
- (void) (*cleanUpRout)( obj );
- }
- }
-
- void execute( int exec )
- {
- executeIt = exec;
- }
- };
-
- /*
- * C++ implementation of PThreads cancel cleanup;
- * This implementation takes advantage of a helper
- * class who's destructor automatically calls the
- * cleanup routine if we exit our scope weirdly
- */
-#define pthread_cleanup_push( _rout, _arg ) \
- { \
- PThreadCleanup cleanup((ptw32_cleanup_callback_t)(_rout), \
- (void *) (_arg) );
-
-#define pthread_cleanup_pop( _execute ) \
- cleanup.execute( _execute ); \
- }
-
-#else
-
-#error ERROR [__FILE__, line __LINE__]: Cleanup type undefined.
-
-#endif /* __CLEANUP_CXX */
-
-#endif /* __CLEANUP_C */
-
-#endif /* __CLEANUP_SEH */
-
-/*
- * ===============
- * ===============
- * Methods
- * ===============
- * ===============
- */
-
-/*
- * PThread Attribute Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_init (pthread_attr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_destroy (pthread_attr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_getdetachstate (const pthread_attr_t * attr,
- int *detachstate);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstackaddr (const pthread_attr_t * attr,
- void **stackaddr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_getstacksize (const pthread_attr_t * attr,
- size_t * stacksize);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_setdetachstate (pthread_attr_t * attr,
- int detachstate);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstackaddr (pthread_attr_t * attr,
- void *stackaddr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_setstacksize (pthread_attr_t * attr,
- size_t stacksize);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedparam (const pthread_attr_t *attr,
- struct sched_param *param);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedparam (pthread_attr_t *attr,
- const struct sched_param *param);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_setschedpolicy (pthread_attr_t *,
- int);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_getschedpolicy (pthread_attr_t *,
- int *);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_setinheritsched(pthread_attr_t * attr,
- int inheritsched);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_getinheritsched(pthread_attr_t * attr,
- int * inheritsched);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_setscope (pthread_attr_t *,
- int);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_attr_getscope (const pthread_attr_t *,
- int *);
-
-/*
- * PThread Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_create (pthread_t * tid,
- const pthread_attr_t * attr,
- void *(*start) (void *),
- void *arg);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_detach (pthread_t tid);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_equal (pthread_t t1,
- pthread_t t2);
-
-PTW32_DLLPORT void PTW32_CDECL pthread_exit (void *value_ptr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_join (pthread_t thread,
- void **value_ptr);
-
-PTW32_DLLPORT pthread_t PTW32_CDECL pthread_self (void);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_cancel (pthread_t thread);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_setcancelstate (int state,
- int *oldstate);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_setcanceltype (int type,
- int *oldtype);
-
-PTW32_DLLPORT void PTW32_CDECL pthread_testcancel (void);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_once (pthread_once_t * once_control,
- void (*init_routine) (void));
-
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
-PTW32_DLLPORT ptw32_cleanup_t * PTW32_CDECL ptw32_pop_cleanup (int execute);
-
-PTW32_DLLPORT void PTW32_CDECL ptw32_push_cleanup (ptw32_cleanup_t * cleanup,
- void (*routine) (void *),
- void *arg);
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
-
-/*
- * Thread Specific Data Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_key_create (pthread_key_t * key,
- void (*destructor) (void *));
-
-PTW32_DLLPORT int PTW32_CDECL pthread_key_delete (pthread_key_t key);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_setspecific (pthread_key_t key,
- const void *value);
-
-PTW32_DLLPORT void * PTW32_CDECL pthread_getspecific (pthread_key_t key);
-
-
-/*
- * Mutex Attribute Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_init (pthread_mutexattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_destroy (pthread_mutexattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getpshared (const pthread_mutexattr_t
- * attr,
- int *pshared);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setpshared (pthread_mutexattr_t * attr,
- int pshared);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind);
-PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_gettype (pthread_mutexattr_t * attr, int *kind);
-
-/*
- * Barrier Attribute Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_init (pthread_barrierattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_destroy (pthread_barrierattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_getpshared (const pthread_barrierattr_t
- * attr,
- int *pshared);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_barrierattr_setpshared (pthread_barrierattr_t * attr,
- int pshared);
-
-/*
- * Mutex Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_mutex_init (pthread_mutex_t * mutex,
- const pthread_mutexattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_mutex_destroy (pthread_mutex_t * mutex);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_mutex_lock (pthread_mutex_t * mutex);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_mutex_timedlock(pthread_mutex_t *mutex,
- const struct timespec *abstime);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_mutex_trylock (pthread_mutex_t * mutex);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_mutex_unlock (pthread_mutex_t * mutex);
-
-/*
- * Spinlock Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_spin_init (pthread_spinlock_t * lock, int pshared);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_spin_destroy (pthread_spinlock_t * lock);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_spin_lock (pthread_spinlock_t * lock);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_spin_trylock (pthread_spinlock_t * lock);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_spin_unlock (pthread_spinlock_t * lock);
-
-/*
- * Barrier Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_barrier_init (pthread_barrier_t * barrier,
- const pthread_barrierattr_t * attr,
- unsigned int count);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_barrier_destroy (pthread_barrier_t * barrier);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_barrier_wait (pthread_barrier_t * barrier);
-
-/*
- * Condition Variable Attribute Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_condattr_init (pthread_condattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_condattr_destroy (pthread_condattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_condattr_getpshared (const pthread_condattr_t * attr,
- int *pshared);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_condattr_setpshared (pthread_condattr_t * attr,
- int pshared);
-
-/*
- * Condition Variable Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_cond_init (pthread_cond_t * cond,
- const pthread_condattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_cond_destroy (pthread_cond_t * cond);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_cond_wait (pthread_cond_t * cond,
- pthread_mutex_t * mutex);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_cond_timedwait (pthread_cond_t * cond,
- pthread_mutex_t * mutex,
- const struct timespec *abstime);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_cond_signal (pthread_cond_t * cond);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_cond_broadcast (pthread_cond_t * cond);
-
-/*
- * Scheduling
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_setschedparam (pthread_t thread,
- int policy,
- const struct sched_param *param);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_getschedparam (pthread_t thread,
- int *policy,
- struct sched_param *param);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_setconcurrency (int);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_getconcurrency (void);
-
-/*
- * Read-Write Lock Functions
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_init(pthread_rwlock_t *lock,
- const pthread_rwlockattr_t *attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_destroy(pthread_rwlock_t *lock);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_tryrdlock(pthread_rwlock_t *);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_trywrlock(pthread_rwlock_t *);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_rdlock(pthread_rwlock_t *lock);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedrdlock(pthread_rwlock_t *lock,
- const struct timespec *abstime);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_wrlock(pthread_rwlock_t *lock);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_timedwrlock(pthread_rwlock_t *lock,
- const struct timespec *abstime);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlock_unlock(pthread_rwlock_t *lock);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_init (pthread_rwlockattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_destroy (pthread_rwlockattr_t * attr);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_getpshared (const pthread_rwlockattr_t * attr,
- int *pshared);
-
-PTW32_DLLPORT int PTW32_CDECL pthread_rwlockattr_setpshared (pthread_rwlockattr_t * attr,
- int pshared);
-
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX - 1
-
-/*
- * Signal Functions. Should be defined in <signal.h> but MSVC and MinGW32
- * already have signal.h that don't define these.
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_kill(pthread_t thread, int sig);
-
-/*
- * Non-portable functions
- */
-
-/*
- * Compatibility with Linux.
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_setkind_np(pthread_mutexattr_t * attr,
- int kind);
-PTW32_DLLPORT int PTW32_CDECL pthread_mutexattr_getkind_np(pthread_mutexattr_t * attr,
- int *kind);
-
-/*
- * Possibly supported by other POSIX threads implementations
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_delay_np (struct timespec * interval);
-PTW32_DLLPORT int PTW32_CDECL pthread_num_processors_np(void);
-
-/*
- * Useful if an application wants to statically link
- * the lib rather than load the DLL at run-time.
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_attach_np(void);
-PTW32_DLLPORT int PTW32_CDECL pthread_win32_process_detach_np(void);
-PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_attach_np(void);
-PTW32_DLLPORT int PTW32_CDECL pthread_win32_thread_detach_np(void);
-
-/*
- * Features that are auto-detected at load/run time.
- */
-PTW32_DLLPORT int PTW32_CDECL pthread_win32_test_features_np(int);
-enum ptw32_features {
- PTW32_SYSTEM_INTERLOCKED_COMPARE_EXCHANGE = 0x0001, /* System provides it. */
- PTW32_ALERTABLE_ASYNC_CANCEL = 0x0002 /* Can cancel blocked threads. */
-};
-
-/*
- * Register a system time change with the library.
- * Causes the library to perform various functions
- * in response to the change. Should be called whenever
- * the application's top level window receives a
- * WM_TIMECHANGE message. It can be passed directly to
- * pthread_create() as a new thread if desired.
- */
-PTW32_DLLPORT void * PTW32_CDECL pthread_timechange_handler_np(void *);
-
-#endif /*PTW32_LEVEL >= PTW32_LEVEL_MAX - 1 */
-
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
-
-/*
- * Returns the Win32 HANDLE for the POSIX thread.
- */
-PTW32_DLLPORT HANDLE PTW32_CDECL pthread_getw32threadhandle_np(pthread_t thread);
-
-
-/*
- * Protected Methods
- *
- * This function blocks until the given WIN32 handle
- * is signaled or pthread_cancel had been called.
- * This function allows the caller to hook into the
- * PThreads cancel mechanism. It is implemented using
- *
- * WaitForMultipleObjects
- *
- * on 'waitHandle' and a manually reset WIN32 Event
- * used to implement pthread_cancel. The 'timeout'
- * argument to TimedWait is simply passed to
- * WaitForMultipleObjects.
- */
-PTW32_DLLPORT int PTW32_CDECL pthreadCancelableWait (HANDLE waitHandle);
-PTW32_DLLPORT int PTW32_CDECL pthreadCancelableTimedWait (HANDLE waitHandle,
- DWORD timeout);
-
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
-
-/*
- * Thread-Safe C Runtime Library Mappings.
- */
-#ifndef _UWIN
-# if defined(NEED_ERRNO)
- PTW32_DLLPORT int * PTW32_CDECL _errno( void );
-# else
-# ifndef errno
-# if (defined(_MT) || defined(_DLL))
- __declspec(dllimport) extern int * __cdecl _errno(void);
-# define errno (*_errno())
-# endif
-# endif
-# endif
-#endif
-
-/*
- * WIN32 C runtime library had been made thread-safe
- * without affecting the user interface. Provide
- * mappings from the UNIX thread-safe versions to
- * the standard C runtime library calls.
- * Only provide function mappings for functions that
- * actually exist on WIN32.
- */
-
-#if !defined(__MINGW32__)
-#define strtok_r( _s, _sep, _lasts ) \
- ( *(_lasts) = strtok( (_s), (_sep) ) )
-#endif /* !__MINGW32__ */
-
-#define asctime_r( _tm, _buf ) \
- ( strcpy( (_buf), asctime( (_tm) ) ), \
- (_buf) )
-
-#define ctime_r( _clock, _buf ) \
- ( strcpy( (_buf), ctime( (_clock) ) ), \
- (_buf) )
-
-#define gmtime_r( _clock, _result ) \
- ( *(_result) = *gmtime( (_clock) ), \
- (_result) )
-
-#define localtime_r( _clock, _result ) \
- ( *(_result) = *localtime( (_clock) ), \
- (_result) )
-
-#define rand_r( _seed ) \
- ( _seed == _seed? rand() : rand() )
-
-
-/*
- * Some compiler environments don't define some things.
- */
-#if defined(__BORLANDC__)
-# define _ftime ftime
-# define _timeb timeb
-#endif
-
-#ifdef __cplusplus
-
-/*
- * Internal exceptions
- */
-class ptw32_exception {};
-class ptw32_exception_cancel : public ptw32_exception {};
-class ptw32_exception_exit : public ptw32_exception {};
-
-#endif
-
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
-
-/* FIXME: This is only required if the library was built using SEH */
-/*
- * Get internal SEH tag
- */
-PTW32_DLLPORT DWORD PTW32_CDECL ptw32_get_exception_services_code(void);
-
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
-
-#ifndef PTW32_BUILD
-
-#ifdef __CLEANUP_SEH
-
-/*
- * Redefine the SEH __except keyword to ensure that applications
- * propagate our internal exceptions up to the library's internal handlers.
- */
-#define __except( E ) \
- __except( ( GetExceptionCode() == ptw32_get_exception_services_code() ) \
- ? EXCEPTION_CONTINUE_SEARCH : ( E ) )
-
-#endif /* __CLEANUP_SEH */
-
-#ifdef __CLEANUP_CXX
-
-/*
- * Redefine the C++ catch keyword to ensure that applications
- * propagate our internal exceptions up to the library's internal handlers.
- */
-#ifdef _MSC_VER
- /*
- * WARNING: Replace any 'catch( ... )' with 'PtW32CatchAll'
- * if you want Pthread-Win32 cancelation and pthread_exit to work.
- */
-
-#ifndef PtW32NoCatchWarn
-
-#pragma message("Specify \"/DPtW32NoCatchWarn\" compiler flag to skip this message.")
-#pragma message("------------------------------------------------------------------")
-#pragma message("When compiling applications with MSVC++ and C++ exception handling:")
-#pragma message(" Replace any 'catch( ... )' in routines called from POSIX threads")
-#pragma message(" with 'PtW32CatchAll' or 'CATCHALL' if you want POSIX thread")
-#pragma message(" cancelation and pthread_exit to work. For example:")
-#pragma message("")
-#pragma message(" #ifdef PtW32CatchAll")
-#pragma message(" PtW32CatchAll")
-#pragma message(" #else")
-#pragma message(" catch(...)")
-#pragma message(" #endif")
-#pragma message(" {")
-#pragma message(" /* Catchall block processing */")
-#pragma message(" }")
-#pragma message("------------------------------------------------------------------")
-
-#endif
-
-#define PtW32CatchAll \
- catch( ptw32_exception & ) { throw; } \
- catch( ... )
-
-#else /* _MSC_VER */
-
-#define catch( E ) \
- catch( ptw32_exception & ) { throw; } \
- catch( E )
-
-#endif /* _MSC_VER */
-
-#endif /* __CLEANUP_CXX */
-
-#endif /* ! PTW32_BUILD */
-
-#ifdef __cplusplus
-} /* End of extern "C" */
-#endif /* __cplusplus */
-
-#ifdef PTW32__HANDLE_DEF
-# undef HANDLE
-#endif
-#ifdef PTW32__DWORD_DEF
-# undef DWORD
-#endif
-
-#undef PTW32_LEVEL
-#undef PTW32_LEVEL_MAX
-
-#endif /* ! RC_INVOKED */
-
-#endif /* PTHREAD_H */
+++ /dev/null
-/*
- * Module: sched.h
- *
- * Purpose:
- * Provides an implementation of POSIX realtime extensions
- * as defined in
- *
- * POSIX 1003.1b-1993 (POSIX.1b)
- *
- * --------------------------------------------------------------------------
- *
- * Pthreads-win32 - POSIX Threads Library for Win32
- * Copyright(C) 1998 John E. Bossom
- * Copyright(C) 1999,2005 Pthreads-win32 contributors
- *
- * Contact Email: rpj@callisto.canberra.edu.au
- *
- * The current list of contributors is contained
- * in the file CONTRIBUTORS included with the source
- * code distribution. The list can also be seen at the
- * following World Wide Web location:
- * http://sources.redhat.com/pthreads-win32/contributors.html
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-#ifndef _SCHED_H
-#define _SCHED_H
-
-#undef PTW32_LEVEL
-
-#if defined(_POSIX_SOURCE)
-#define PTW32_LEVEL 0
-/* Early POSIX */
-#endif
-
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
-#undef PTW32_LEVEL
-#define PTW32_LEVEL 1
-/* Include 1b, 1c and 1d */
-#endif
-
-#if defined(INCLUDE_NP)
-#undef PTW32_LEVEL
-#define PTW32_LEVEL 2
-/* Include Non-Portable extensions */
-#endif
-
-#define PTW32_LEVEL_MAX 3
-
-#if !defined(PTW32_LEVEL)
-#define PTW32_LEVEL PTW32_LEVEL_MAX
-/* Include everything */
-#endif
-
-
-#if __GNUC__ && ! defined (__declspec)
-# error Please upgrade your GNU compiler to one that supports __declspec.
-#endif
-
-/*
- * When building the DLL code, you should define PTW32_BUILD so that
- * the variables/functions are exported correctly. When using the DLL,
- * do NOT define PTW32_BUILD, and then the variables/functions will
- * be imported correctly.
- */
-#ifndef PTW32_STATIC_LIB
-# ifdef PTW32_BUILD
-# define PTW32_DLLPORT __declspec (dllexport)
-# else
-# define PTW32_DLLPORT __declspec (dllimport)
-# endif
-#else
-# define PTW32_DLLPORT
-#endif
-
-/*
- * This is a duplicate of what is in the autoconf config.h,
- * which is only used when building the pthread-win32 libraries.
- */
-
-#ifndef PTW32_CONFIG_H
-# if defined(WINCE)
-# define NEED_ERRNO
-# define NEED_SEM
-# endif
-# if defined(_UWIN) || defined(__MINGW32__)
-# define HAVE_MODE_T
-# endif
-#endif
-
-/*
- *
- */
-
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
-#ifdef NEED_ERRNO
-#include "need_errno.h"
-#else
-#include <errno.h>
-#endif
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
-
-#if defined(__MINGW32__) || defined(_UWIN)
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
-/* For pid_t */
-# include <sys/types.h>
-/* Required by Unix 98 */
-# include <time.h>
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
-#else
-typedef int pid_t;
-#endif
-
-/* Thread scheduling policies */
-
-enum {
- SCHED_OTHER = 0,
- SCHED_FIFO,
- SCHED_RR,
- SCHED_MIN = SCHED_OTHER,
- SCHED_MAX = SCHED_RR
-};
-
-struct sched_param {
- int sched_priority;
-};
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-PTW32_DLLPORT int __cdecl sched_yield (void);
-
-PTW32_DLLPORT int __cdecl sched_get_priority_min (int policy);
-
-PTW32_DLLPORT int __cdecl sched_get_priority_max (int policy);
-
-PTW32_DLLPORT int __cdecl sched_setscheduler (pid_t pid, int policy);
-
-PTW32_DLLPORT int __cdecl sched_getscheduler (pid_t pid);
-
-/*
- * Note that this macro returns ENOTSUP rather than
- * ENOSYS as might be expected. However, returning ENOSYS
- * should mean that sched_get_priority_{min,max} are
- * not implemented as well as sched_rr_get_interval.
- * This is not the case, since we just don't support
- * round-robin scheduling. Therefore I have chosen to
- * return the same value as sched_setscheduler when
- * SCHED_RR is passed to it.
- */
-#define sched_rr_get_interval(_pid, _interval) \
- ( errno = ENOTSUP, (int) -1 )
-
-
-#ifdef __cplusplus
-} /* End of extern "C" */
-#endif /* __cplusplus */
-
-#undef PTW32_LEVEL
-#undef PTW32_LEVEL_MAX
-
-#endif /* !_SCHED_H */
-
+++ /dev/null
-/*
- * Module: semaphore.h
- *
- * Purpose:
- * Semaphores aren't actually part of the PThreads standard.
- * They are defined by the POSIX Standard:
- *
- * POSIX 1003.1b-1993 (POSIX.1b)
- *
- * --------------------------------------------------------------------------
- *
- * Pthreads-win32 - POSIX Threads Library for Win32
- * Copyright(C) 1998 John E. Bossom
- * Copyright(C) 1999,2005 Pthreads-win32 contributors
- *
- * Contact Email: rpj@callisto.canberra.edu.au
- *
- * The current list of contributors is contained
- * in the file CONTRIBUTORS included with the source
- * code distribution. The list can also be seen at the
- * following World Wide Web location:
- * http://sources.redhat.com/pthreads-win32/contributors.html
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-#if !defined( SEMAPHORE_H )
-#define SEMAPHORE_H
-
-#undef PTW32_LEVEL
-
-#if defined(_POSIX_SOURCE)
-#define PTW32_LEVEL 0
-/* Early POSIX */
-#endif
-
-#if defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309
-#undef PTW32_LEVEL
-#define PTW32_LEVEL 1
-/* Include 1b, 1c and 1d */
-#endif
-
-#if defined(INCLUDE_NP)
-#undef PTW32_LEVEL
-#define PTW32_LEVEL 2
-/* Include Non-Portable extensions */
-#endif
-
-#define PTW32_LEVEL_MAX 3
-
-#if !defined(PTW32_LEVEL)
-#define PTW32_LEVEL PTW32_LEVEL_MAX
-/* Include everything */
-#endif
-
-#if __GNUC__ && ! defined (__declspec)
-# error Please upgrade your GNU compiler to one that supports __declspec.
-#endif
-
-/*
- * When building the DLL code, you should define PTW32_BUILD so that
- * the variables/functions are exported correctly. When using the DLL,
- * do NOT define PTW32_BUILD, and then the variables/functions will
- * be imported correctly.
- */
-#ifndef PTW32_STATIC_LIB
-# ifdef PTW32_BUILD
-# define PTW32_DLLPORT __declspec (dllexport)
-# else
-# define PTW32_DLLPORT __declspec (dllimport)
-# endif
-#else
-# define PTW32_DLLPORT
-#endif
-
-/*
- * This is a duplicate of what is in the autoconf config.h,
- * which is only used when building the pthread-win32 libraries.
- */
-
-#ifndef PTW32_CONFIG_H
-# if defined(WINCE)
-# define NEED_ERRNO
-# define NEED_SEM
-# endif
-# if defined(_UWIN) || defined(__MINGW32__)
-# define HAVE_MODE_T
-# endif
-#endif
-
-/*
- *
- */
-
-#if PTW32_LEVEL >= PTW32_LEVEL_MAX
-#ifdef NEED_ERRNO
-#include "need_errno.h"
-#else
-#include <errno.h>
-#endif
-#endif /* PTW32_LEVEL >= PTW32_LEVEL_MAX */
-
-#define _POSIX_SEMAPHORES
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-#ifndef HAVE_MODE_T
-typedef unsigned int mode_t;
-#endif
-
-
-typedef struct sem_t_ * sem_t;
-
-PTW32_DLLPORT int __cdecl sem_init (sem_t * sem,
- int pshared,
- unsigned int value);
-
-PTW32_DLLPORT int __cdecl sem_destroy (sem_t * sem);
-
-PTW32_DLLPORT int __cdecl sem_trywait (sem_t * sem);
-
-PTW32_DLLPORT int __cdecl sem_wait (sem_t * sem);
-
-PTW32_DLLPORT int __cdecl sem_timedwait (sem_t * sem,
- const struct timespec * abstime);
-
-PTW32_DLLPORT int __cdecl sem_post (sem_t * sem);
-
-PTW32_DLLPORT int __cdecl sem_post_multiple (sem_t * sem,
- int count);
-
-PTW32_DLLPORT int __cdecl sem_open (const char * name,
- int oflag,
- mode_t mode,
- unsigned int value);
-
-PTW32_DLLPORT int __cdecl sem_close (sem_t * sem);
-
-PTW32_DLLPORT int __cdecl sem_unlink (const char * name);
-
-PTW32_DLLPORT int __cdecl sem_getvalue (sem_t * sem,
- int * sval);
-
-#ifdef __cplusplus
-} /* End of extern "C" */
-#endif /* __cplusplus */
-
-#undef PTW32_LEVEL
-#undef PTW32_LEVEL_MAX
-
-#endif /* !SEMAPHORE_H */
//every baudrate I could find is in here in an #ifdef block
//so it should compile on everything
-#include "os-dependent.h"
-
#ifndef __WINDOWS__
#include <termios.h>
#endif
-namespace CEC
+namespace PLATFORM
{
static struct sbaudrate
{
int32_t rate;
int32_t symbol;
}
+
baudrates[] =
{
#ifdef B50
{ -1, -1}
};
- static int32_t IntToBaudrate(uint32_t baudrate)
+ inline int32_t IntToBaudrate(uint32_t baudrate)
{
- for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(CEC::sbaudrate) - 1; i++)
+ for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(PLATFORM::sbaudrate) - 1; i++)
{
if (baudrates[i].rate == (int32_t) baudrate)
return baudrates[i].symbol;
* http://www.pulse-eight.net/
*/
-#include "os-dependent.h"
-#include <cectypes.h>
+#include "../os.h"
#include <string>
#include <stdint.h>
-#include "../AdapterCommunication.h"
-#include "../platform/threads.h"
#ifndef __WINDOWS__
#include <termios.h>
-#else
-#include "../util/buffer.h"
#endif
-namespace CEC
+namespace PLATFORM
{
#define PAR_NONE 0
#define PAR_EVEN 1
bool IsOpen();
void Close();
- int8_t Write(CCECAdapterMessage *data);
+ int64_t Write(uint8_t* data, uint32_t len);
int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0);
std::string GetError() { return m_error; }
private:
bool SetBaudRate(uint32_t baudrate);
- std::string m_error;
- std::string m_name;
- CMutex m_mutex;
- bool m_tostdout;
+ std::string m_error;
+ std::string m_name;
+ CMutex m_mutex;
+ bool m_tostdout;
#ifdef __WINDOWS__
bool SetTimeouts(bool bBlocking);
- HANDLE m_handle;
- bool m_bIsOpen;
- uint32_t m_iBaudrate;
- uint8_t m_iDatabits;
- uint8_t m_iStopbits;
- uint8_t m_iParity;
- int64_t m_iTimeout;
- CecBuffer<uint8_t> m_buffer;
- HANDLE m_ovHandle;
+ HANDLE m_handle;
+ bool m_bIsOpen;
+ uint32_t m_iBaudrate;
+ uint8_t m_iDatabits;
+ uint8_t m_iStopbits;
+ uint8_t m_iParity;
+ int64_t m_iTimeout;
+ SyncedBuffer<uint8_t> m_buffer;
+ HANDLE m_ovHandle;
#else
struct termios m_options;
int m_fd;
+++ /dev/null
-/*
- * This file is part of the libCEC(R) library.
- *
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
- * libCEC(R) is an original work, containing original code.
- *
- * libCEC(R) is a trademark of Pulse-Eight Limited.
- *
- * This program is dual-licensed; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- *
- * Alternatively, you can license this library under a commercial license,
- * please contact Pulse-Eight Licensing for more information.
- *
- * For more information contact:
- * Pulse-Eight Licensing <license@pulse-eight.com>
- * http://www.pulse-eight.com/
- * http://www.pulse-eight.net/
- */
-
-#include "threads.h"
-#include "timeutils.h"
-
-using namespace CEC;
-
-CMutex::CMutex(bool bRecursive /* = true */)
-{
- pthread_mutex_init(&m_mutex, bRecursive ? GetMutexAttribute() : NULL);
-}
-
-CMutex::~CMutex(void)
-{
- pthread_mutex_destroy(&m_mutex);
-}
-
-bool CMutex::TryLock(void)
-{
- return (pthread_mutex_trylock(&m_mutex) == 0);
-}
-
-bool CMutex::Lock(void)
-{
- return (pthread_mutex_lock(&m_mutex) == 0);
-}
-
-void CMutex::Unlock(void)
-{
- pthread_mutex_unlock(&m_mutex);
-}
-
-static pthread_mutexattr_t g_mutexAttr;
-pthread_mutexattr_t *CMutex::GetMutexAttribute()
-{
- static bool bAttributeInitialised = false;
- if (!bAttributeInitialised)
- {
- pthread_mutexattr_init(&g_mutexAttr);
- pthread_mutexattr_settype(&g_mutexAttr, PTHREAD_MUTEX_RECURSIVE);
- bAttributeInitialised = true;
- }
- return &g_mutexAttr;
-}
-
-CLockObject::CLockObject(CMutex *mutex, bool bTryLock /* = false */) :
- m_mutex(mutex)
-{
- if (m_mutex)
- m_bLocked = bTryLock ? m_mutex->TryLock() : m_mutex->Lock();
-}
-
-CLockObject::~CLockObject(void)
-{
- Leave();
- m_mutex = NULL;
-}
-
-void CLockObject::Leave(void)
-{
- if (m_mutex && m_bLocked)
- {
- m_bLocked = false;
- m_mutex->Unlock();
- }
-}
-
-void CLockObject::Lock(void)
-{
- if (m_mutex)
- m_bLocked = m_mutex->Lock();
-}
-
-CCondition::CCondition(void)
-{
- pthread_cond_init(&m_cond, NULL);
-}
-
-CCondition::~CCondition(void)
-{
- pthread_cond_broadcast(&m_cond);
- pthread_cond_destroy(&m_cond);
-}
-
-void CCondition::Broadcast(void)
-{
- pthread_cond_broadcast(&m_cond);
-}
-
-void CCondition::Signal(void)
-{
- pthread_cond_signal(&m_cond);
-}
-
-bool CCondition::Wait(CMutex *mutex, uint32_t iTimeout /* = 0 */)
-{
- bool bReturn(false);
- sched_yield();
- if (mutex)
- {
- if (iTimeout > 0)
- {
- struct timespec abstime;
- struct timeval now;
- gettimeofday(&now, NULL);
- iTimeout += now.tv_usec / 1000;
- abstime.tv_sec = now.tv_sec + (time_t)(iTimeout / 1000);
- abstime.tv_nsec = (int32_t)((iTimeout % (uint32_t)1000) * (uint32_t)1000000);
- bReturn = (pthread_cond_timedwait(&m_cond, &mutex->m_mutex, &abstime) == 0);
- }
- else
- {
- bReturn = (pthread_cond_wait(&m_cond, &mutex->m_mutex) == 0);
- }
- }
-
- return bReturn;
-}
-
-void CCondition::Sleep(uint32_t iTimeout)
-{
- CCondition w;
- CMutex m;
- CLockObject lock(&m);
- w.Wait(&m, iTimeout);
-}
-
-CThread::CThread(void) :
- m_bStop(false),
- m_bRunning(false)
-{
-}
-
-CThread::~CThread(void)
-{
- StopThread();
-}
-
-bool CThread::CreateThread(bool bWait /* = true */)
-{
- 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)
- {
- if (bWait)
- m_threadCondition.Wait(&m_threadMutex);
- bReturn = true;
- }
-
- return bReturn;
-}
-
-void *CThread::ThreadHandler(CThread *thread)
-{
- void *retVal = NULL;
-
- if (thread)
- {
- CLockObject lock(&thread->m_threadMutex);
- thread->m_bRunning = true;
- lock.Leave();
- thread->m_threadCondition.Broadcast();
-
- retVal = thread->Process();
-
- lock.Lock();
- thread->m_bRunning = false;
- lock.Leave();
- thread->m_threadCondition.Broadcast();
- }
-
- return retVal;
-}
-
-bool CThread::StopThread(bool bWaitForExit /* = true */)
-{
- bool bReturn(true);
- m_bStop = true;
-
- m_threadCondition.Broadcast();
-
- void *retVal;
- if (bWaitForExit && m_bRunning)
- bReturn = (pthread_join(m_thread, &retVal) == 0);
-
- return bReturn;
-}
-
-bool CThread::Sleep(uint32_t iTimeout)
-{
- CLockObject lock(&m_threadMutex);
- return m_bStop ? false : m_threadCondition.Wait(&m_threadMutex, iTimeout);
-}
+++ /dev/null
-#pragma once
-/*
- * This file is part of the libCEC(R) library.
- *
- * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
- * libCEC(R) is an original work, containing original code.
- *
- * libCEC(R) is a trademark of Pulse-Eight Limited.
- *
- * This program is dual-licensed; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- *
- * Alternatively, you can license this library under a commercial license,
- * please contact Pulse-Eight Licensing for more information.
- *
- * For more information contact:
- * Pulse-Eight Licensing <license@pulse-eight.com>
- * http://www.pulse-eight.com/
- * http://www.pulse-eight.net/
- */
-
-#include "os-dependent.h"
-#include <stdint.h>
-
-namespace CEC
-{
- class CMutex;
-
- class CCondition
- {
- public:
- CCondition(void);
- virtual ~CCondition(void);
-
- void Broadcast(void);
- void Signal(void);
- bool Wait(CMutex *mutex, uint32_t iTimeout = 0);
- static void Sleep(uint32_t iTimeout);
-
- private:
- pthread_cond_t m_cond;
- };
-
- class CMutex
- {
- public:
- CMutex(bool bRecursive = true);
- virtual ~CMutex(void);
-
- bool TryLock(void);
- bool Lock(void);
- void Unlock(void);
-
- pthread_mutex_t m_mutex;
-
- private:
- static pthread_mutexattr_t *GetMutexAttribute();
- };
-
- class CLockObject
- {
- public:
- CLockObject(CMutex *mutex, bool bTryLock = false);
- ~CLockObject(void);
-
- bool IsLocked(void) const { return m_bLocked; }
- void Leave(void);
- void Lock(void);
-
- private:
- CMutex *m_mutex;
- bool m_bLocked;
- };
-
- class CThread
- {
- public:
- CThread(void);
- virtual ~CThread(void);
-
- virtual bool IsRunning(void) const { return m_bRunning; }
- virtual bool CreateThread(bool bWait = true);
- virtual bool StopThread(bool bWaitForExit = true);
- virtual bool IsStopped(void) const { return m_bStop; };
- virtual bool Sleep(uint32_t iTimeout);
-
- static void *ThreadHandler(CThread *thread);
- virtual void *Process(void) = 0;
-
- protected:
- CCondition m_threadCondition;
-
- private:
- pthread_t m_thread;
- CMutex m_threadMutex;
- bool m_bStop;
- bool m_bRunning;
- };
-};
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+namespace PLATFORM
+{
+ class PreventCopy
+ {
+ public:
+ inline PreventCopy(void) {}
+ inline ~PreventCopy(void) {}
+
+ private:
+ inline PreventCopy(const PreventCopy &c) { *this = c; }
+ inline PreventCopy &operator=(const PreventCopy &c){ *this = c; return *this; }
+ };
+
+ class CCondition;
+
+ class CMutex : public PreventCopy
+ {
+ friend class CCondition;
+ public:
+ inline CMutex(void) :
+ m_iLockCount(0)
+ {
+ MutexCreate(m_mutex);
+ }
+
+ inline ~CMutex(void)
+ {
+ Clear();
+ MutexDelete(m_mutex);
+ }
+
+ inline bool TryLock(void)
+ {
+ if (MutexTryLock(m_mutex))
+ {
+ ++m_iLockCount;
+ return true;
+ }
+ return false;
+ }
+
+ inline bool Lock(void)
+ {
+ MutexLock(m_mutex);
+ ++m_iLockCount;
+ return true;
+ }
+
+ inline void Unlock(void)
+ {
+ if (Lock())
+ {
+ if (m_iLockCount >= 2)
+ {
+ --m_iLockCount;
+ MutexUnlock(m_mutex);
+ }
+
+ --m_iLockCount;
+ MutexUnlock(m_mutex);
+ }
+ }
+
+ inline bool Clear(void)
+ {
+ bool bReturn(false);
+ if (TryLock())
+ {
+ unsigned int iLockCount = m_iLockCount;
+ for (unsigned int iPtr = 0; iPtr < iLockCount; iPtr++)
+ Unlock();
+ bReturn = true;
+ }
+ return bReturn;
+ }
+
+ private:
+ mutex_t m_mutex;
+ volatile unsigned int m_iLockCount;
+ };
+
+ class CLockObject : public PreventCopy
+ {
+ public:
+ inline CLockObject(CMutex &mutex, bool bClearOnExit = false) :
+ m_mutex(mutex),
+ m_bClearOnExit(bClearOnExit)
+ {
+ m_mutex.Lock();
+ }
+
+ inline ~CLockObject(void)
+ {
+ if (m_bClearOnExit)
+ Clear();
+ else
+ Unlock();
+ }
+
+ inline bool TryLock(void)
+ {
+ return m_mutex.TryLock();
+ }
+
+ inline void Unlock(void)
+ {
+ m_mutex.Unlock();
+ }
+
+ inline bool Clear(void)
+ {
+ return m_mutex.Clear();
+ }
+
+ inline bool Lock(void)
+ {
+ return m_mutex.Lock();
+ }
+
+ private:
+ CMutex &m_mutex;
+ bool m_bClearOnExit;
+ };
+
+ class CCondition : public PreventCopy
+ {
+ public:
+ inline CCondition(void)
+ {
+ ConditionCreate(m_condition);
+ }
+
+ inline ~CCondition(void)
+ {
+ Broadcast();
+ ConditionDelete(m_condition);
+ }
+
+ inline void Broadcast(void)
+ {
+ ConditionBroadcast(m_condition);
+ }
+
+ inline void Signal(void)
+ {
+ ConditionSignal(m_condition);
+ }
+
+ inline bool Wait(CMutex &mutex, uint32_t iTimeout = 0)
+ {
+ return ConditionWait(m_condition, mutex.m_mutex, iTimeout);
+ }
+
+ static void Sleep(uint32_t iTimeout)
+ {
+ CCondition w;
+ CMutex m;
+ CLockObject lock(m);
+ w.Wait(m, iTimeout);
+ }
+
+ condition_t m_condition;
+ };
+}
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+#include "mutex.h"
+
+namespace PLATFORM
+{
+ class CThread
+ {
+ public:
+ CThread(void) :
+ m_bStop(false),
+ m_bRunning(false) {}
+
+ virtual ~CThread(void)
+ {
+ StopThread();
+ }
+
+ static void *ThreadHandler(CThread *thread)
+ {
+ void *retVal = NULL;
+
+ if (thread)
+ {
+ CLockObject lock(thread->m_threadMutex);
+ thread->m_bRunning = true;
+ lock.Unlock();
+ thread->m_threadCondition.Broadcast();
+
+ retVal = thread->Process();
+
+ lock.Lock();
+ thread->m_bRunning = false;
+ lock.Unlock();
+ thread->m_threadCondition.Broadcast();
+ }
+
+ return retVal;
+ }
+
+ inline bool IsRunning(void)
+ {
+ CLockObject lock(m_threadMutex);
+ return m_bRunning;
+ }
+
+ inline bool IsStopped(void)
+ {
+ CLockObject lock(m_threadMutex);
+ return m_bStop;
+ }
+
+ inline bool CreateThread(bool bWait = true)
+ {
+ bool bReturn(false);
+ CLockObject lock(m_threadMutex);
+ if (!IsRunning())
+ {
+ m_bStop = false;
+ if (ThreadsCreate(m_thread, CThread::ThreadHandler, ((void*)static_cast<CThread *>(this))))
+ {
+ if (bWait)
+ m_threadCondition.Wait(m_threadMutex);
+ bReturn = true;
+ }
+ }
+ return bReturn;
+ }
+
+ inline bool StopThread(bool bWaitForExit = true)
+ {
+ bool bReturn(true);
+ bool bRunning(false);
+ {
+ CLockObject lock(m_threadMutex);
+ bRunning = IsRunning();
+ m_bStop = true;
+ m_threadCondition.Broadcast();
+ }
+
+ if (bRunning && bWaitForExit)
+ {
+ void *retVal = NULL;
+ bReturn = ThreadsWait(m_thread, &retVal);
+ }
+ return true;
+ }
+
+ inline bool Sleep(uint32_t iTimeout)
+ {
+ CLockObject lock(m_threadMutex);
+ return m_bStop ? false : m_threadCondition.Wait(m_threadMutex, iTimeout);
+ }
+
+ virtual void *Process(void) = 0;
+
+ protected:
+ void SetRunning(bool bSetTo);
+
+ private:
+ bool m_bStop;
+ bool m_bRunning;
+ CCondition m_threadCondition;
+ CMutex m_threadMutex;
+ thread_t m_thread;
+ };
+};
#include <sys/time.h>
#endif
-namespace CEC
+#include "os.h"
+
+namespace PLATFORM
{
+ #if defined(__WINDOWS__)
+ struct timezone
+ {
+ int tz_minuteswest;
+ int tz_dsttime;
+ };
+
+ #define usleep(t) Sleep((DWORD)(t)/1000)
+
+ inline int gettimeofday(struct timeval *pcur_time, struct timezone *tz)
+ {
+ if (pcur_time == NULL)
+ {
+ SetLastError(EFAULT);
+ return -1;
+ }
+ struct _timeb current;
+
+ _ftime(¤t);
+
+ pcur_time->tv_sec = (long) current.time;
+ pcur_time->tv_usec = current.millitm * 1000L;
+ if (tz)
+ {
+ tz->tz_minuteswest = current.timezone; /* minutes west of Greenwich */
+ tz->tz_dsttime = current.dstflag; /* type of dst correction */
+ }
+ return 0;
+ }
+ #endif
+
inline int64_t GetTimeMs()
{
#if defined(__APPLE__)
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+namespace PLATFORM
+{
+ #define thread_t HANDLE
+ #define ThreadsWait(thread, retVal) (::WaitForSingleObject(thread, INFINITE) < 0)
+ #define ThreadsCreate(thread, func, arg) ((thread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, arg, 0, NULL)) == NULL ? false : true)
+
+ typedef CRITICAL_SECTION* mutex_t;
+ #define MutexCreate(mutex) ::InitializeCriticalSection(mutex = new CRITICAL_SECTION)
+ #define MutexDelete(mutex) ::DeleteCriticalSection(mutex); delete mutex
+ #define MutexLock(mutex) ::EnterCriticalSection(mutex)
+ #define MutexTryLock(mutex) (::TryEnterCriticalSection(mutex) != 0)
+ #define MutexUnlock(mutex) ::LeaveCriticalSection(mutex)
+
+ #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
+ typedef CONDITION_VARIABLE* condition_t;
+ #define ConditionCreate(cond) ::InitializeConditionVariable(cond = new CONDITION_VARIABLE)
+ #define ConditionDelete(cond) delete cond
+ #define ConditionSignal(cond) ::WakeConditionVariable(cond)
+ #define ConditionBroadcast(cond) ::WakeAllConditionVariable(cond)
+ #define ConditionWait(cond, mutex, timeout) (::SleepConditionVariableCS(cond, mutex, timeout <= 0 ? INFINITE : timeout) ? true : false)
+ #else
+ typedef HANDLE condition_t;
+ #define ConditionCreate(cond) (cond = ::CreateEvent(NULL, TRUE, FALSE, NULL))
+ #define ConditionDelete(cond) ::CloseHandle(cond)
+ #define ConditionSignal(cond) ::SetEvent(cond)
+ #define ConditionBroadcast(cond) ::SetEvent(cond)
+ #define ConditionWait(cond, mutex, timeout) ::ResetEvent(cond); \
+ MutexUnlock(mutex); \
+ ::WaitForSingleObject(cond, timeout <= 0 ? 1000 : timeout); \
+ MutexLock(mutex)
+ #endif
+}
--- /dev/null
+#pragma once
+/*
+ * This file is part of the libCEC(R) library.
+ *
+ * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
+ * libCEC(R) is an original work, containing original code.
+ *
+ * libCEC(R) is a trademark of Pulse-Eight Limited.
+ *
+ * This program is dual-licensed; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *
+ * Alternatively, you can license this library under a commercial license,
+ * please contact Pulse-Eight Licensing for more information.
+ *
+ * For more information contact:
+ * Pulse-Eight Licensing <license@pulse-eight.com>
+ * http://www.pulse-eight.com/
+ * http://www.pulse-eight.net/
+ */
+
+#pragma warning(disable:4005) // Disable "warning C4005: '_WINSOCKAPI_' : macro redefinition"
+#include <winsock2.h>
+#pragma warning(default:4005)
+
+#include <sys/timeb.h>
+#include <io.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stddef.h>
+#include <process.h>
+
+typedef signed __int8 int8_t;
+typedef signed __int16 int16_t;
+typedef signed __int32 int32_t;
+typedef signed __int64 int64_t;
+typedef unsigned __int8 uint8_t;
+typedef unsigned __int16 uint16_t;
+typedef unsigned __int32 uint32_t;
+typedef unsigned __int64 uint64_t;
+
+#define snprintf _snprintf
+
+#if defined(_MSC_VER)
+#pragma warning (push)
+#endif
+
+#define NOGDI
+#if defined(_MSC_VER) /* prevent inclusion of wingdi.h */
+#pragma warning (pop)
+#endif
+
+#pragma warning(disable:4189) /* disable 'defined but not used' */
+#pragma warning(disable:4100) /* disable 'unreferenced formal parameter' */
+++ /dev/null
-/*
- * Copyright (C) 2005-2011 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include "os_windows.h"
-#include <sys/timeb.h>
-
-int gettimeofday(struct timeval *pcur_time, struct timezone *tz)
-{
- if (pcur_time == NULL)
- {
- SetLastError(EFAULT);
- return -1;
- }
- struct _timeb current;
-
- _ftime(¤t);
-
- pcur_time->tv_sec = (long) current.time;
- pcur_time->tv_usec = current.millitm * 1000L;
- if (tz)
- {
- tz->tz_minuteswest = current.timezone; /* minutes west of Greenwich */
- tz->tz_dsttime = current.dstflag; /* type of dst correction */
- }
- return 0;
-}
+++ /dev/null
-#pragma once
-/*
- * Copyright (C) 2011 Team XBMC
- * http://www.xbmc.org
- *
- * This Program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This Program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with XBMC; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#pragma warning(disable:4005) // Disable "warning C4005: '_WINSOCKAPI_' : macro redefinition"
-#include <winsock2.h>
-#pragma warning(default:4005)
-
-#include "../pthread_win32/pthread.h"
-
-#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64
-# define __USE_FILE_OFFSET64 1
-#endif
-
-typedef signed __int32 int32_t;
-typedef signed __int64 int64_t;
-typedef unsigned __int8 uint8_t;
-typedef unsigned __int16 uint16_t;
-typedef unsigned __int32 uint32_t;
-typedef unsigned __int64 uint64_t;
-
-#if defined __USE_FILE_OFFSET64
-typedef int64_t off_t;
-typedef uint64_t ino_t;
-#endif
-
-#define usleep(t) Sleep((t)/1000)
-#define snprintf _snprintf
-
-#include <stddef.h>
-#include <process.h>
-#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
-#pragma warning (push)
-#endif
-/* prevent inclusion of wingdi.h */
-#define NOGDI
-#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
-#pragma warning (pop)
-#endif
-#include <io.h>
-#include <stdlib.h>
-#include <errno.h>
-
-struct timezone
-{
- int tz_minuteswest; /* minutes west of Greenwich */
- int tz_dsttime; /* type of dst correction */
-};
-
-/*!
- \brief implements similar unix call under windows
- \return 0 on success, -1 on failure (if pcur_time was NULL)
- \param pcur_time points to a timeval structure, should not be NULL
- \param tz points to a timezone structure, may be NULL
- */
-extern int gettimeofday(struct timeval *pcur_time, struct timezone *tz);
* http://www.pulse-eight.net/
*/
-#include "../serialport.h"
-#include "../baudrate.h"
+#include "../serialport/serialport.h"
+#include "../serialport/baudrate.h"
#include "../timeutils.h"
using namespace std;
-using namespace CEC;
+using namespace PLATFORM;
void FormatWindowsError(int iErrorCode, string &strMessage)
{
bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity)
{
CStdString strComPath = "\\\\.\\" + name;
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
m_handle = CreateFile(strComPath.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (m_handle == INVALID_HANDLE_VALUE)
{
void CSerialPort::Close(void)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
if (m_bIsOpen)
{
CloseHandle(m_handle);
}
}
-int8_t CSerialPort::Write(CCECAdapterMessage *data)
+int64_t CSerialPort::Write(uint8_t* data, uint32_t len)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
DWORD iBytesWritten = 0;
if (!m_bIsOpen)
return -1;
- if (!WriteFile(m_handle, data->packet.data, data->size(), &iBytesWritten, NULL))
+ if (!WriteFile(m_handle, data, len, &iBytesWritten, NULL))
{
m_error = "Error while writing to COM port";
FormatWindowsError(GetLastError(), m_error);
return -1;
}
- return (int8_t)iBytesWritten;
+ return (int64_t)iBytesWritten;
}
int32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /* = 0 */)
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
int32_t iReturn(-1);
DWORD iBytesRead = 0;
if (m_handle == 0)
bool CSerialPort::IsOpen()
{
- CLockObject lock(&m_mutex);
+ CLockObject lock(m_mutex);
return m_bIsOpen;
}
--- /dev/null
+// ISO C9x compliant stdint.h for Microsoft Visual Studio
+// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
+//
+// Copyright (c) 2006-2008 Alexander Chemeris
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+// 3. The name of the author may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _MSC_VER // [
+#error "Use this header only with Microsoft Visual C++ compilers!"
+#endif // _MSC_VER ]
+
+#ifndef _MSC_STDINT_H_ // [
+#define _MSC_STDINT_H_
+
+#if _MSC_VER > 1000
+#pragma once
+#endif
+
+#include <limits.h>
+
+// For Visual Studio 6 in C++ mode and for many Visual Studio versions when
+// compiling for ARM we should wrap <wchar.h> include with 'extern "C++" {}'
+// or compiler give many errors like this:
+// error C2733: second C linkage of overloaded function 'wmemchr' not allowed
+#ifdef __cplusplus
+extern "C" {
+#endif
+# include <wchar.h>
+#ifdef __cplusplus
+}
+#endif
+
+// Define _W64 macros to mark types changing their size, like intptr_t.
+#ifndef _W64
+# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
+# define _W64 __w64
+# else
+# define _W64
+# endif
+#endif
+
+
+// 7.18.1 Integer types
+
+// 7.18.1.1 Exact-width integer types
+
+// Visual Studio 6 and Embedded Visual C++ 4 doesn't
+// realize that, e.g. char has the same size as __int8
+// so we give up on __intX for them.
+#if (_MSC_VER < 1300)
+ typedef signed char int8_t;
+ typedef signed short int16_t;
+ typedef signed int int32_t;
+ typedef unsigned char uint8_t;
+ typedef unsigned short uint16_t;
+ typedef unsigned int uint32_t;
+#else
+ typedef signed __int8 int8_t;
+ typedef signed __int16 int16_t;
+ typedef signed __int32 int32_t;
+ typedef unsigned __int8 uint8_t;
+ typedef unsigned __int16 uint16_t;
+ typedef unsigned __int32 uint32_t;
+#endif
+typedef signed __int64 int64_t;
+typedef unsigned __int64 uint64_t;
+
+
+// 7.18.1.2 Minimum-width integer types
+typedef int8_t int_least8_t;
+typedef int16_t int_least16_t;
+typedef int32_t int_least32_t;
+typedef int64_t int_least64_t;
+typedef uint8_t uint_least8_t;
+typedef uint16_t uint_least16_t;
+typedef uint32_t uint_least32_t;
+typedef uint64_t uint_least64_t;
+
+// 7.18.1.3 Fastest minimum-width integer types
+typedef int8_t int_fast8_t;
+typedef int16_t int_fast16_t;
+typedef int32_t int_fast32_t;
+typedef int64_t int_fast64_t;
+typedef uint8_t uint_fast8_t;
+typedef uint16_t uint_fast16_t;
+typedef uint32_t uint_fast32_t;
+typedef uint64_t uint_fast64_t;
+
+// 7.18.1.4 Integer types capable of holding object pointers
+#ifdef _WIN64 // [
+ typedef signed __int64 intptr_t;
+ typedef unsigned __int64 uintptr_t;
+#else // _WIN64 ][
+ typedef _W64 signed int intptr_t;
+ typedef _W64 unsigned int uintptr_t;
+#endif // _WIN64 ]
+
+// 7.18.1.5 Greatest-width integer types
+typedef int64_t intmax_t;
+typedef uint64_t uintmax_t;
+
+
+// 7.18.2 Limits of specified-width integer types
+
+#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
+
+// 7.18.2.1 Limits of exact-width integer types
+#define INT8_MIN ((int8_t)_I8_MIN)
+#define INT8_MAX _I8_MAX
+#define INT16_MIN ((int16_t)_I16_MIN)
+#define INT16_MAX _I16_MAX
+#define INT32_MIN ((int32_t)_I32_MIN)
+#define INT32_MAX _I32_MAX
+#define INT64_MIN ((int64_t)_I64_MIN)
+#define INT64_MAX _I64_MAX
+#define UINT8_MAX _UI8_MAX
+#define UINT16_MAX _UI16_MAX
+#define UINT32_MAX _UI32_MAX
+#define UINT64_MAX _UI64_MAX
+
+// 7.18.2.2 Limits of minimum-width integer types
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST8_MAX INT8_MAX
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MIN INT64_MIN
+#define INT_LEAST64_MAX INT64_MAX
+#define UINT_LEAST8_MAX UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+// 7.18.2.3 Limits of fastest minimum-width integer types
+#define INT_FAST8_MIN INT8_MIN
+#define INT_FAST8_MAX INT8_MAX
+#define INT_FAST16_MIN INT16_MIN
+#define INT_FAST16_MAX INT16_MAX
+#define INT_FAST32_MIN INT32_MIN
+#define INT_FAST32_MAX INT32_MAX
+#define INT_FAST64_MIN INT64_MIN
+#define INT_FAST64_MAX INT64_MAX
+#define UINT_FAST8_MAX UINT8_MAX
+#define UINT_FAST16_MAX UINT16_MAX
+#define UINT_FAST32_MAX UINT32_MAX
+#define UINT_FAST64_MAX UINT64_MAX
+
+// 7.18.2.4 Limits of integer types capable of holding object pointers
+#ifdef _WIN64 // [
+# define INTPTR_MIN INT64_MIN
+# define INTPTR_MAX INT64_MAX
+# define UINTPTR_MAX UINT64_MAX
+#else // _WIN64 ][
+# define INTPTR_MIN INT32_MIN
+# define INTPTR_MAX INT32_MAX
+# define UINTPTR_MAX UINT32_MAX
+#endif // _WIN64 ]
+
+// 7.18.2.5 Limits of greatest-width integer types
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+// 7.18.3 Limits of other integer types
+
+#ifdef _WIN64 // [
+# define PTRDIFF_MIN _I64_MIN
+# define PTRDIFF_MAX _I64_MAX
+#else // _WIN64 ][
+# define PTRDIFF_MIN _I32_MIN
+# define PTRDIFF_MAX _I32_MAX
+#endif // _WIN64 ]
+
+#define SIG_ATOMIC_MIN INT_MIN
+#define SIG_ATOMIC_MAX INT_MAX
+
+#ifndef SIZE_MAX // [
+# ifdef _WIN64 // [
+# define SIZE_MAX _UI64_MAX
+# else // _WIN64 ][
+# define SIZE_MAX _UI32_MAX
+# endif // _WIN64 ]
+#endif // SIZE_MAX ]
+
+// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
+#ifndef WCHAR_MIN // [
+# define WCHAR_MIN 0
+#endif // WCHAR_MIN ]
+#ifndef WCHAR_MAX // [
+# define WCHAR_MAX _UI16_MAX
+#endif // WCHAR_MAX ]
+
+#define WINT_MIN 0
+#define WINT_MAX _UI16_MAX
+
+#endif // __STDC_LIMIT_MACROS ]
+
+
+// 7.18.4 Limits of other integer types
+
+#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
+
+// 7.18.4.1 Macros for minimum-width integer constants
+
+#define INT8_C(val) val##i8
+#define INT16_C(val) val##i16
+#define INT32_C(val) val##i32
+#define INT64_C(val) val##i64
+
+#define UINT8_C(val) val##ui8
+#define UINT16_C(val) val##ui16
+#define UINT32_C(val) val##ui32
+#define UINT64_C(val) val##ui64
+
+// 7.18.4.2 Macros for greatest-width integer constants
+#define INTMAX_C INT64_C
+#define UINTMAX_C UINT64_C
+
+#endif // __STDC_CONSTANT_MACROS ]
+
+
+#endif // _MSC_STDINT_H_ ]
bin_PROGRAMS = cec-client
-cec_client_SOURCES = main.cpp \
- ../lib/platform/threads.cpp
+cec_client_SOURCES = main.cpp
cec_client_CPPFLAGS = -I@abs_top_srcdir@/include
cec_client_LDFLAGS = @LIBS_DL@
\ No newline at end of file
#include <fstream>
#include <string>
#include <sstream>
-#include "../lib/platform/threads.h"
-#include "../lib/util/StdString.h"
+#include "../lib/platform/os.h"
#include "../lib/implementations/CECCommandHandler.h"
using namespace CEC;
using namespace std;
+using namespace PLATFORM;
#define CEC_TEST_CLIENT_VERSION 1
cec_logical_address g_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE);
cec_device_type_list g_typeList;
bool g_bSingleCommand(false);
+bool g_bExit(false);
+bool g_bHardExit(false);
CMutex g_outputMutex;
ICECCallbacks g_callbacks;
inline void PrintToStdOut(const char *strOut)
{
- CLockObject lock(&g_outputMutex);
+ CLockObject lock(g_outputMutex);
cout << strOut << endl;
}
void ShowHelpCommandLine(const char* strExec)
{
- CLockObject lock(&g_outputMutex);
+ CLockObject lock(g_outputMutex);
cout << endl <<
strExec << " {-h|--help|-l|--list-devices|[COM PORT]}" << endl <<
endl <<
void ShowHelpConsole(void)
{
- CLockObject lock(&g_outputMutex);
+ CLockObject lock(g_outputMutex);
cout << endl <<
"================================================================================" << endl <<
"Available commands:" << endl <<
{
if (command == "bl")
{
- parser->StartBootloader();
+ if (parser->StartBootloader())
+ {
+ PrintToStdOut("entered bootloader mode. exiting cec-client");
+ g_bExit = true;
+ g_bHardExit = true;
+ }
return true;
}
if (!parser->Open(g_strPort.c_str()))
{
CStdString strLog;
- strLog.Format("unable to open the device on port %s");
+ strLog.Format("unable to open the device on port %s", g_strPort.c_str());
PrintToStdOut(strLog);
UnloadLibCec(parser);
return 1;
PrintToStdOut("waiting for input");
}
- bool bContinue(true);
- while (bContinue)
+ while (!g_bExit && !g_bHardExit)
{
string input;
getline(cin, input);
cin.clear();
- if (ProcessConsoleCommand(parser, input) && !g_bSingleCommand)
+ if (ProcessConsoleCommand(parser, input) && !g_bSingleCommand && !g_bExit && !g_bHardExit)
{
if (!input.empty())
PrintToStdOut("waiting for input");
}
else
- bContinue = false;
+ g_bExit = true;
- if (bContinue)
+ if (!g_bExit && !g_bHardExit)
CCondition::Sleep(50);
}
- if (!g_bSingleCommand)
+ if (!g_bSingleCommand && !g_bHardExit)
parser->StandbyDevices(CECDEVICE_BROADCAST);
parser->Close();
--- /dev/null
+#!/bin/bash
+
+_usage()
+{
+ echo "Usage: $0 /path/to/firmware.hex"
+}
+
+_check_bootloader_device()
+{
+ cec_adapter=`lsusb | grep "03eb:2ffa" | wc -l`
+ if [ $cec_adapter -eq 0 ]; then
+ _enter_bootloader
+ cec_adapter=`lsusb | grep "03eb:2ffa" | wc -l`
+ fi
+
+ if [ $cec_adapter -eq 0 ]; then
+ echo "ERROR: failed to find any CEC adapter in bootloader mode"
+ return 1
+ fi
+
+ return 0
+}
+
+_enter_bootloader()
+{
+ echo "Instructing the CEC adapter to enter bootloader mode"
+ cec_adapter=`lsusb | grep "2548:1001" | wc -l`
+ if [ $cec_adapter -gt 0 ]; then
+ echo "bl" | cec-client -s -d 2
+ echo "Waiting for the device to reinitialise"
+ sleep 5
+ fi
+}
+
+_flash()
+{
+ file=$1
+
+ if [ ! -f "$file" ]; then
+ echo "ERROR: firmware file '$file' does not exist"
+ exit 1
+ fi
+
+ cat << EOB
+Flash '$file' onto the CEC adapter
+
+DISCONNECT THE HDMI CABLES BEFORE STARTING AND
+DO NOT POWER OFF OR DISCONNECT THE DEVICE WHILE THIS OPERATION IS IN PROGRESS!
+
+
+Are you sure you want to flash '$file' onto the CEC adapter?
+Type 'do it!' if you're sure. Anything else will cancel the operation.
+
+EOB
+ read confirmation
+ if [ ! "$confirmation" == "do it!" ]; then
+ echo "Exiting"
+ exit 0
+ fi
+
+ _prereq
+ if [ $? -eq 1 ]; then
+ exit 1
+ fi
+
+ _check_bootloader_device
+ if [ $? -eq 1 ]; then
+ exit 1
+ fi
+
+
+ echo "Erasing the previous firmware"
+ sudo dfu-programmer at90usb162 erase
+
+ echo "Flashing the new firmware"
+ sudo dfu-programmer at90usb162 flash "$file"
+
+ cat << EOB
+
+===============================================================================
+
+Done!
+
+Remove the USB cable from the device and reconnect it to use the new firmware.
+
+EOB
+ exit 0
+}
+
+_prereq()
+{
+ programmer=`which dfu-programmer`
+ if [ -z "$programmer" ]; then
+ echo "dfu-programmer was not found in your path, installing"
+ sudo apt-get install -y dfu-programmer
+ fi
+
+ programmer=`which dfu-programmer`
+ if [ -z "$programmer" ]; then
+ echo "ERROR: failed to find dfu-programmer"
+ return 1
+ fi
+ return 0
+}
+
+
+cat << EOB
+===============================================================================
+ Pulse-Eight CEC Adapter firmware flash tool
+===============================================================================
+
+EOB
+
+if [ -z "$1" ]; then
+ _usage
+else
+ _flash $1
+fi
+
+exit 0
--- /dev/null
+@echo off
+
+rem Check for NSIS
+IF EXIST "%ProgramFiles%\NSIS\makensis.exe" (
+ set NSIS="%ProgramFiles%\NSIS\makensis.exe"
+) ELSE IF EXIST "%ProgramFiles(x86)%\NSIS\makensis.exe" (
+ set NSIS="%ProgramFiles(x86)%\NSIS\makensis.exe"
+) ELSE GOTO NONSIS
+
+rem Check for the Windows DDK
+IF NOT EXIST "C:\WinDDK\7600.16385.1" GOTO NODDK
+set DDK="C:\WinDDK\7600.16385.1"
+
+rem Check for VC10
+IF "%VS100COMNTOOLS%"=="" (
+ set COMPILER10="%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\VCExpress.exe"
+) ELSE IF EXIST "%VS100COMNTOOLS%\..\IDE\VCExpress.exe" (
+ set COMPILER10="%VS100COMNTOOLS%\..\IDE\VCExpress.exe"
+) ELSE IF EXIST "%VS100COMNTOOLS%\..\IDE\devenv.exe" (
+ set COMPILER10="%VS100COMNTOOLS%\..\IDE\devenv.exe"
+) ELSE GOTO NOSDK10
+
+cd ..\project
+
+del /s /f /q ..\build
+mkdir ..\build
+mkdir ..\build\x64
+
+rem Skip to libCEC/x86 when we're running on win32
+if "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="" goto libcecx86
+
+rem Compile libCEC and cec-client x64
+echo. Cleaning libCEC (x64)
+%COMPILER10% libcec.sln /clean "Release|x64"
+echo. Compiling libCEC (x64)
+%COMPILER10% libcec.sln /build "Release|x64" /project libcec
+echo. Compiling cec-client (x64)
+%COMPILER10% libcec.sln /build "Release|x64" /project testclient
+
+:libcecx86
+rem Compile libCEC and cec-client Win32
+echo. Cleaning libCEC (x86)
+%COMPILER10% libcec.sln /clean "Release|Win32"
+echo. Compiling libCEC (x86)
+%COMPILER10% libcec.sln /build "Release|Win32" /project libcec
+echo. Compiling cec-client (x86)
+%COMPILER10% libcec.sln /build "Release|Win32" /project testclient
+
+rem Check for VC9
+IF "%VS90COMNTOOLS%"=="" (
+ set COMPILER9="%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\VCExpress.exe"
+) ELSE IF EXIST "%VS90COMNTOOLS%\..\IDE\VCExpress.exe" (
+ set COMPILER9="%VS90COMNTOOLS%\..\IDE\VCExpress.exe"
+) ELSE IF EXIST "%VS90COMNTOOLS%\..\IDE\devenv.exe" (
+ set COMPILER9="%VS90COMNTOOLS%\..\IDE\devenv.exe"
+) ELSE GOTO NOSDK9
+
+rem Skip to libCEC/x86 when we're running on win32
+if "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="" goto libcecsharpx86
+
+rem Compile LibCecSharp (x64)
+echo. Cleaning LibCecSharp (x64)
+%COMPILER9% LibCecSharp.Net2.sln /clean "Release|x64"
+echo. Compiling LibCecSharp (x64)
+%COMPILER9% LibCecSharp.sln /build "Release|x64" /project LibCecSharp
+%COMPILER9% LibCecSharp.sln /build "Release|x64" /project CecSharpTester
+
+copy ..\build\LibCecSharp.dll ..\build\x64\LibCecSharp.dll
+copy ..\build\CecSharpTester.exe ..\build\x64\CecSharpTester.exe
+
+:libcecsharpx86
+rem Compile LibCecSharp (x86)
+echo. Cleaning LibCecSharp (x86)
+%COMPILER9% LibCecSharp.sln /clean "Release|x86"
+echo. Compiling LibCecSharp (x86)
+%COMPILER9% LibCecSharp.sln /build "Release|x86" /project LibCecSharp
+%COMPILER9% LibCecSharp.sln /build "Release|x86" /project CecSharpTester
+
+:NOSDK9
+:CREATEINSTALLER
+echo. Copying driver installer
+copy "%DDK%\redist\DIFx\dpinst\MultiLin\amd64\dpinst.exe" ..\build\dpinst-amd64.exe
+copy "%DDK%\redist\DIFx\dpinst\MultiLin\x86\dpinst.exe" ..\build\dpinst-x86.exe
+
+rem Clean things up before creating the installer
+del ..\build\LibCecSharp.pdb
+del ..\build\CecSharpTester.pdb
+copy ..\build\cec-client.x64.exe ..\build\x64\cec-client.x64.exe
+del ..\build\cec-client.x64.exe
+copy ..\build\libcec.x64.dll ..\build\x64\libcec.x64.dll
+del ..\build\libcec.x64.dll
+copy ..\build\libcec.x64.lib ..\build\x64\libcec.x64.lib
+del ..\build\libcec.x64.lib
+
+echo. Creating the installer
+%NSIS% /V1 /X"SetCompressor /FINAL lzma" "libCEC.nsi"
+
+echo. The installer can be found here: ..\build\libCEC-installer.exe
+
+GOTO EXIT
+
+:NOSDK10
+echo. Both Visual Studio 2010 and Visual C++ Express 2010 were not found on your system.
+GOTO EXIT
+
+:NOSIS
+echo. NSIS could not be found on your system.
+GOTO EXIT
+
+:NODDK
+echo. Windows DDK could not be found on your system
+
+:EXIT