X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FLibCecSharp%2FCecSharpTypes.h;h=2de94bf015800c2b3680b65d605ba2e025d560c4;hb=7cb1f563b6f5568953064b8e9bd7e63f0ad874ab;hp=52c0b2020797bfd702ddbc4aa293395f49947f27;hpb=217b236882e3f4e5303a135aae39f6207bfbd279;p=deb_libcec.git diff --git a/src/LibCecSharp/CecSharpTypes.h b/src/LibCecSharp/CecSharpTypes.h index 52c0b20..2de94bf 100644 --- a/src/LibCecSharp/CecSharpTypes.h +++ b/src/LibCecSharp/CecSharpTypes.h @@ -1,35 +1,35 @@ #pragma once /* - * This file is part of the libCEC(R) library. - * - * libCEC(R) is Copyright (C) 2011-2012 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 - * http://www.pulse-eight.com/ - * http://www.pulse-eight.net/ - */ +* This file is part of the libCEC(R) library. +* +* libCEC(R) is Copyright (C) 2011-2013 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 +* http://www.pulse-eight.com/ +* http://www.pulse-eight.net/ +*/ #include "../lib/platform/threads/mutex.h" #include @@ -39,979 +39,2418 @@ #using +/// +/// LibCecSharp namespace +/// +/// namespace CecSharp { - public enum class CecDeviceType - { - Tv = 0, - RecordingDevice = 1, - Reserved = 2, - Tuner = 3, - PlaybackDevice = 4, - AudioSystem = 5 - }; - - public enum class CecLogLevel - { - None = 0, - Error = 1, - Warning = 2, - Notice = 4, - Traffic = 8, - Debug = 16, - All = 31 - }; - - public enum class CecLogicalAddress - { - Unknown = -1, //not a valid logical address - Tv = 0, - RecordingDevice1 = 1, - RecordingDevice2 = 2, - Tuner1 = 3, - PlaybackDevice1 = 4, - AudioSystem = 5, - Tuner2 = 6, - Tuner3 = 7, - PlaybackDevice2 = 8, - RecordingDevice3 = 9, - Tuner4 = 10, - PlaybackDevice3 = 11, - Reserved1 = 12, - Reserved2 = 13, - FreeUse = 14, - Unregistered = 15, - Broadcast = 15 - }; - - public enum class CecAlert - { - ServiceDevice = 1 - }; - - public enum class CecParameterType - { - ParameterTypeString = 1 - }; - - public ref class CecParameter - { - public: - CecParameter(CecParameterType type, System::String ^ strData) - { - Type = type; - Data = strData; - } - - property CecParameterType Type; - property System::String ^ Data; - }; - - public enum class CecPowerStatus - { - On = 0x00, - Standby = 0x01, - InTransitionStandbyToOn = 0x02, - InTransitionOnToStandby = 0x03, - Unknown = 0x99 - }; - - public enum class CecVersion - { - Unknown = 0x00, - V1_2 = 0x01, - V1_2A = 0x02, - V1_3 = 0x03, - V1_3A = 0x04, - V1_4 = 0x05 - }; - - public enum class CecDisplayControl - { - DisplayForDefaultTime = 0x00, - DisplayUntilCleared = 0x40, - ClearPreviousMessage = 0x80, - ReservedForFutureUse = 0xC0 - }; - - public enum class CecMenuState - { - Activated = 0, - Deactivated = 1 - }; - - public enum class CecDeckControlMode - { - SkipForwardWind = 1, - SkipReverseRewind = 2, - Stop = 3, - Eject = 4 - }; - - public enum class CecDeckInfo - { - Play = 0x11, - Record = 0x12, - Reverse = 0x13, - Still = 0x14, - Slow = 0x15, - SlowReverse = 0x16, - FastForward = 0x17, - FastReverse = 0x18, - NoMedia = 0x19, - Stop = 0x1A, - SkipForwardWind = 0x1B, - SkipReverseRewind = 0x1C, - IndexSearchForward = 0x1D, - IndexSearchReverse = 0x1E, - OtherStatus = 0x1F - }; - - public enum class CecUserControlCode - { - Select = 0x00, - Up = 0x01, - Down = 0x02, - Left = 0x03, - Right = 0x04, - RightUp = 0x05, - RightDown = 0x06, - LeftUp = 0x07, - LeftDown = 0x08, - RootMenu = 0x09, - SetupMenu = 0x0A, - ContentsMenu = 0x0B, - FavoriteMenu = 0x0C, - Exit = 0x0D, - Number0 = 0x20, - Number1 = 0x21, - Number2 = 0x22, - Number3 = 0x23, - Number4 = 0x24, - Number5 = 0x25, - Number6 = 0x26, - Number7 = 0x27, - Number8 = 0x28, - Number9 = 0x29, - Dot = 0x2A, - Enter = 0x2B, - Clear = 0x2C, - NextFavorite = 0x2F, - ChannelUp = 0x30, - ChannelDown = 0x31, - PreviousChannel = 0x32, - SoundSelect = 0x33, - InputSelect = 0x34, - DisplayInformation = 0x35, - Help = 0x36, - PageUp = 0x37, - PageDown = 0x38, - Power = 0x40, - VolumeUp = 0x41, - VolumeDown = 0x42, - Mute = 0x43, - Play = 0x44, - Stop = 0x45, - Pause = 0x46, - Record = 0x47, - Rewind = 0x48, - FastForward = 0x49, - Eject = 0x4A, - Forward = 0x4B, - Backward = 0x4C, - StopRecord = 0x4D, - PauseRecord = 0x4E, - Angle = 0x50, - SubPicture = 0x51, - VideoOnDemand = 0x52, - ElectronicProgramGuide = 0x53, - TimerProgramming = 0x54, - InitialConfiguration = 0x55, - PlayFunction = 0x60, - PausePlayFunction = 0x61, - RecordFunction = 0x62, - PauseRecordFunction = 0x63, - StopFunction = 0x64, - MuteFunction = 0x65, - RestoreVolumeFunction = 0x66, - TuneFunction = 0x67, - SelectMediaFunction = 0x68, - SelectAVInputFunction = 0x69, - SelectAudioInputFunction = 0x6A, - PowerToggleFunction = 0x6B, - PowerOffFunction = 0x6C, - PowerOnFunction = 0x6D, - F1Blue = 0x71, - F2Red = 0X72, - F3Green = 0x73, - F4Yellow = 0x74, - F5 = 0x75, - Data = 0x76, - Max = 0x76, - SamsungReturn = 0x91, - Unknown - }; - - public enum class CecVendorId - { - Samsung = 0x0000F0, - LG = 0x00E091, - Panasonic = 0x008045, - Pioneer = 0x00E036, - Onkyo = 0x0009B0, - Yamaha = 0x00A0DE, - Philips = 0x00903E, - Sony = 0x080046, - Toshiba = 0x000039, - Akai = 0x0020C7, - Benq = 0x8065E9, - Daewoo = 0x009053, - Grundig = 0x00D0D5, - Medion = 0x000CB8, - Sharp = 0x08001F, - Vizio = 0x6B746D, - Unknown = 0 - }; - - public enum class CecAudioStatus - { - MuteStatusMask = 0x80, - VolumeStatusMask = 0x7F, - VolumeMin = 0x00, - VolumeMax = 0x64, - VolumeStatusUnknown = 0x7F - }; - - public enum class CecOpcode - { - ActiveSource = 0x82, - ImageViewOn = 0x04, - TextViewOn = 0x0D, - InactiveSource = 0x9D, - RequestActiveSource = 0x85, - RoutingChange = 0x80, - RoutingInformation = 0x81, - SetStreamPath = 0x86, - Standby = 0x36, - RecordOff = 0x0B, - RecordOn = 0x09, - RecordStatus = 0x0A, - RecordTvScreen = 0x0F, - ClearAnalogueTimer = 0x33, - ClearDigitalTimer = 0x99, - ClearExternalTimer = 0xA1, - SetAnalogueTimer = 0x34, - SetDigitalTimer = 0x97, - SetExternalTimer = 0xA2, - SetTimerProgramTitle = 0x67, - TimerClearedStatus = 0x43, - TimerStatus = 0x35, - CecVersion = 0x9E, - GetCecVersion = 0x9F, - GivePhysicalAddress = 0x83, - GetMenuLanguage = 0x91, - ReportPhysicalAddress = 0x84, - SetMenuLanguage = 0x32, - DeckControl = 0x42, - DeckStatus = 0x1B, - GiveDeckStatus = 0x1A, - Play = 0x41, - GiveTunerDeviceStatus = 0x08, - SelectAnalogueService = 0x92, - SelectDigtalService = 0x93, - TunerDeviceStatus = 0x07, - TunerStepDecrement = 0x06, - TunerStepIncrement = 0x05, - DeviceVendorId = 0x87, - GiveDeviceVendorId = 0x8C, - VendorCommand = 0x89, - VendorCommandWithId = 0xA0, - VendorRemoteButtonDown = 0x8A, - VendorRemoteButtonUp = 0x8B, - SetOsdString = 0x64, - GiveOsdName = 0x46, - SetOsdName = 0x47, - MenuRequest = 0x8D, - MenuStatus = 0x8E, - UserControlPressed = 0x44, - UserControlRelease = 0x45, - GiveDevicePowerStatus = 0x8F, - ReportPowerStatus = 0x90, - FeatureAbort = 0x00, - Abort = 0xFF, - GiveAudioStatus = 0x71, - GiveSystemAudioMode = 0x7D, - ReportAudioStatus = 0x7A, - SetSystemAudioMode = 0x72, - SystemAudioModeRequest = 0x70, - SystemAudioModeStatus = 0x7E, - SetAudioRate = 0x9A, - /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */ - None = 0xFD - }; - - public enum class CecSystemAudioStatus - { - Off = 0, - On = 1 - }; - - public enum class CecClientVersion - { - VersionPre1_5 = 0, - Version1_5_0 = 0x1500, - Version1_5_1 = 0x1501, - Version1_5_2 = 0x1502, - Version1_5_3 = 0x1503, - Version1_6_0 = 0x1600, - Version1_6_1 = 0x1601, - Version1_6_2 = 0x1602, - Version1_6_3 = 0x1603, - Version1_7_0 = 0x1700, - Version1_7_1 = 0x1701, - Version1_7_2 = 0x1702, - Version1_8_0 = 0x1800, - Version1_8_1 = 0x1801, - Version1_8_2 = 0x1802, - Version1_9_0 = 0x1900 - }; - - public enum class CecServerVersion - { - VersionPre1_5 = 0, - Version1_5_0 = 0x1500, - Version1_5_1 = 0x1501, - Version1_5_2 = 0x1502, - Version1_5_3 = 0x1503, - Version1_6_0 = 0x1600, - Version1_6_1 = 0x1601, - Version1_6_2 = 0x1602, - Version1_6_3 = 0x1603, - Version1_7_0 = 0x1700, - Version1_7_1 = 0x1701, - Version1_7_2 = 0x1702, - Version1_8_0 = 0x1800, - Version1_8_1 = 0x1801, - Version1_8_2 = 0x1802, - Version1_9_0 = 0x1900 - }; - - public ref class CecAdapter - { - public: - CecAdapter(System::String ^ strPath, System::String ^ strComPort) - { - Path = strPath; - ComPort = strComPort; - } - - property System::String ^ Path; - property System::String ^ ComPort; - }; - - public ref class CecDeviceTypeList - { - public: - CecDeviceTypeList(void) - { - Types = gcnew array(5); - for (unsigned int iPtr = 0; iPtr < 5; iPtr++) - Types[iPtr] = CecDeviceType::Reserved; - } - - property array ^ Types; - }; - - public ref class CecLogicalAddresses - { - public: - CecLogicalAddresses(void) - { - Addresses = gcnew array(16); - Clear(); - } - - void Clear(void) - { - Primary = CecLogicalAddress::Unknown; - for (unsigned int iPtr = 0; iPtr < 16; iPtr++) - Addresses[iPtr] = CecLogicalAddress::Unknown; - } - - bool IsSet(CecLogicalAddress iAddress) - { - return Addresses[(unsigned int)iAddress] != CecLogicalAddress::Unknown; - } - - void Set(CecLogicalAddress iAddress) - { - Addresses[(unsigned int)iAddress] = iAddress; - if (Primary == CecLogicalAddress::Unknown) - Primary = iAddress; - } - - property CecLogicalAddress Primary; - property array ^ Addresses; - }; - - public ref class CecDatapacket - { - public: - CecDatapacket(void) - { - Data = gcnew array(100); - Size = 0; - } - - void PushBack(uint8_t data) - { - if (Size < 100) - { - Data[Size] = data; - Size++; - } - } - - property array ^ Data; - property uint8_t Size; - }; - - public ref class CecCommand - { - public: - CecCommand(CecLogicalAddress iInitiator, CecLogicalAddress iDestination, bool bAck, bool bEom, CecOpcode iOpcode, int32_t iTransmitTimeout) - { - Initiator = iInitiator; - Destination = iDestination; - Ack = bAck; - Eom = bEom; - Opcode = iOpcode; - OpcodeSet = true; - TransmitTimeout = iTransmitTimeout; - Parameters = gcnew CecDatapacket; - Empty = false; - } - - CecCommand(void) - { - Initiator = CecLogicalAddress::Unknown; - Destination = CecLogicalAddress::Unknown; - Ack = false; - Eom = false; - Opcode = CecOpcode::None; - OpcodeSet = false; - TransmitTimeout = 0; - Parameters = gcnew CecDatapacket; - Empty = true; - } - - void PushBack(uint8_t data) - { - if (Initiator == CecLogicalAddress::Unknown && Destination == CecLogicalAddress::Unknown) - { - Initiator = (CecLogicalAddress) (data >> 4); - Destination = (CecLogicalAddress) (data & 0xF); - } - else if (!OpcodeSet) - { - OpcodeSet = true; - Opcode = (CecOpcode)data; - } - else - { - Parameters->PushBack(data); - } - } - - property bool Empty; - property CecLogicalAddress Initiator; - property CecLogicalAddress Destination; - property bool Ack; - property bool Eom; - property CecOpcode Opcode; - property CecDatapacket ^ Parameters; - property bool OpcodeSet; - property int32_t TransmitTimeout; - }; - - public ref class CecKeypress - { - public: - CecKeypress(CecUserControlCode iKeycode, unsigned int iDuration) - { - Keycode = iKeycode; - Duration = iDuration; - Empty = false; - } - - CecKeypress(void) - { - Keycode = CecUserControlCode::Unknown; - Duration = 0; - Empty = true; - } - - property bool Empty; - property CecUserControlCode Keycode; - property unsigned int Duration; - }; - - public ref class CecLogMessage - { - public: - CecLogMessage(System::String ^ strMessage, CecLogLevel iLevel, int64_t iTime) - { - Message = strMessage; - Level = iLevel; - Time = iTime; - Empty = false; - } - - CecLogMessage(void) - { - Message = ""; - Level = CecLogLevel::None; - Time = 0; - Empty = true; - } - - property bool Empty; - property System::String ^Message; - property CecLogLevel Level; - property int64_t Time; - }; - - ref class CecCallbackMethods; //forward - public ref class LibCECConfiguration - { - public: - LibCECConfiguration(void) - { - DeviceName = ""; - DeviceTypes = gcnew CecDeviceTypeList(); - AutodetectAddress = true; - PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS; - BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE; - HDMIPort = CEC_DEFAULT_HDMI_PORT; - ClientVersion = CecClientVersion::VersionPre1_5; - ServerVersion = CecServerVersion::VersionPre1_5; - TvVendor = CecVendorId::Unknown; - - GetSettingsFromROM = false; - UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1; - ActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1; - - WakeDevices = gcnew CecLogicalAddresses(); - if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1) - WakeDevices->Set(CecLogicalAddress::Tv); - - PowerOffDevices = gcnew CecLogicalAddresses(); - if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1) - PowerOffDevices->Set(CecLogicalAddress::Broadcast); - - PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1; - PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1; - - SendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1; - LogicalAddresses = gcnew CecLogicalAddresses(); - FirmwareVersion = 1; - PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1; - ShutdownOnStandby = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY == 1; - DeviceLanguage = ""; - } - - void SetCallbacks(CecCallbackMethods ^callbacks) - { - Callbacks = callbacks; - } - - void Update(const CEC::libcec_configuration &config) - { - DeviceName = gcnew System::String(config.strDeviceName); - - for (unsigned int iPtr = 0; iPtr < 5; iPtr++) - DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr]; - - AutodetectAddress = config.bAutodetectAddress == 1; - PhysicalAddress = config.iPhysicalAddress; - BaseDevice = (CecLogicalAddress)config.baseDevice; - HDMIPort = config.iHDMIPort; - ClientVersion = (CecClientVersion)config.clientVersion; - ServerVersion = (CecServerVersion)config.serverVersion; - TvVendor = (CecVendorId)config.tvVendor; - - // player specific settings - GetSettingsFromROM = config.bGetSettingsFromROM == 1; - UseTVMenuLanguage = config.bUseTVMenuLanguage == 1; - ActivateSource = config.bActivateSource == 1; - - WakeDevices->Clear(); - for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) - if (config.wakeDevices[iPtr]) - WakeDevices->Set((CecLogicalAddress)iPtr); - - PowerOffDevices->Clear(); - for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) - if (config.powerOffDevices[iPtr]) - PowerOffDevices->Set((CecLogicalAddress)iPtr); - - PowerOffScreensaver = config.bPowerOffScreensaver == 1; - PowerOffOnStandby = config.bPowerOffOnStandby == 1; - - if (ServerVersion >= CecServerVersion::Version1_5_1) - SendInactiveSource = config.bSendInactiveSource == 1; - - if (ServerVersion >= CecServerVersion::Version1_5_3) - { - LogicalAddresses->Clear(); - for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) - if (config.logicalAddresses[iPtr]) - LogicalAddresses->Set((CecLogicalAddress)iPtr); - } - - if (ServerVersion >= CecServerVersion::Version1_6_0) - { - FirmwareVersion = config.iFirmwareVersion; - PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1; - ShutdownOnStandby = config.bShutdownOnStandby == 1; - } - - if (ServerVersion >= CecServerVersion::Version1_6_2) - DeviceLanguage = gcnew System::String(config.strDeviceLanguage); - - if (ServerVersion >= CecServerVersion::Version1_6_3) - MonitorOnlyClient = config.bMonitorOnly == 1; - } - - property System::String ^ DeviceName; - property CecDeviceTypeList ^ DeviceTypes; - property bool AutodetectAddress; - property uint16_t PhysicalAddress; - property CecLogicalAddress BaseDevice; - property uint8_t HDMIPort; - property CecClientVersion ClientVersion; - property CecServerVersion ServerVersion; - property CecVendorId TvVendor; - - // player specific settings - property bool GetSettingsFromROM; - property bool UseTVMenuLanguage; - property bool ActivateSource; - property CecLogicalAddresses ^WakeDevices; - property CecLogicalAddresses ^PowerOffDevices; - property bool PowerOffScreensaver; - property bool PowerOffOnStandby; - property bool SendInactiveSource; - property CecLogicalAddresses ^LogicalAddresses; - property uint16_t FirmwareVersion; - property bool PowerOffDevicesOnStandby; - property bool ShutdownOnStandby; - property bool MonitorOnlyClient; - property System::String ^ DeviceLanguage; - property CecCallbackMethods ^ Callbacks; - }; - - // the callback methods are called by unmanaged code, so we need some delegates for this - #pragma unmanaged - // unmanaged callback methods - typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message); - typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key); - typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command); - typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config); - typedef int (__stdcall *ALERTCB) (const CEC::libcec_alert, const CEC::libcec_parameter &data); - typedef int (__stdcall *MENUCB) (const CEC::cec_menu_state newVal); - typedef void (__stdcall *ACTICB) (const CEC::cec_logical_address logicalAddress, const uint8_t bActivated); - - typedef struct - { - LOGCB logCB; - KEYCB keyCB; - COMMANDCB commandCB; - CONFIGCB configCB; - ALERTCB alertCB; - MENUCB menuCB; - ACTICB sourceActivatedCB; - } UnmanagedCecCallbacks; - - static PLATFORM::CMutex g_callbackMutex; - static std::vector g_unmanagedCallbacks; + /// + /// The device type. For client applications, libCEC only supports RecordingDevice, PlaybackDevice or Tuner. + /// libCEC uses RecordingDevice by default. + /// + public enum class CecDeviceType + { + /// + /// Television + /// + Tv = 0, + /// + /// Recording device + /// + RecordingDevice = 1, + /// + /// Reserved / do not use + /// + Reserved = 2, + /// + /// Tuner + /// + Tuner = 3, + /// + /// Playback device + /// + PlaybackDevice = 4, + /// + /// Audio system / AVR + /// + AudioSystem = 5 + }; + + /// + /// Log level that can be used by the logging callback method to filter messages from libCEC. + /// + public enum class CecLogLevel + { + /// + /// No logging + /// + None = 0, + /// + /// libCEC encountered a serious problem, and couldn't complete an action. + /// + Error = 1, + /// + /// libCEC warns that it encountered a problem, but recovered. + /// + Warning = 2, + /// + /// libCEC informs the client about a CEC state change. + /// + Notice = 4, + /// + /// Raw CEC data traffic + /// + Traffic = 8, + /// + /// Debugging messages + /// + Debug = 16, + /// + /// Display all messages + /// + All = 31 + }; + + /// + /// A logical address on the CEC bus + /// + public enum class CecLogicalAddress + { + /// + /// Not a valid logical address + /// + Unknown = -1, + /// + /// Television + /// + Tv = 0, + /// + /// Recording device 1 + /// + RecordingDevice1 = 1, + /// + /// Recording device 2 + /// + RecordingDevice2 = 2, + /// + /// Tuner 1 + /// + Tuner1 = 3, + /// + /// Playback device 1 + /// + PlaybackDevice1 = 4, + /// + /// Audio system / AVR + /// + AudioSystem = 5, + /// + /// Tuner 2 + /// + Tuner2 = 6, + /// + /// Tuner 3 + /// + Tuner3 = 7, + /// + /// Playback device 2 + /// + PlaybackDevice2 = 8, + /// + /// Recording device 3 + /// + RecordingDevice3 = 9, + /// + /// Tuner 4 + /// + Tuner4 = 10, + /// + /// Playback device 3 + /// + PlaybackDevice3 = 11, + /// + /// Reserved address 1 + /// + Reserved1 = 12, + /// + /// Reserved address 2 + /// + Reserved2 = 13, + /// + /// Free to use + /// + FreeUse = 14, + /// + /// Unregistered / new device + /// + Unregistered = 15, + /// + /// Broadcast address + /// + Broadcast = 15 + }; + + /// + /// The type of alert when libCEC calls the CecAlert callback + /// + public enum class CecAlert + { + /// + /// The device needs servicing. This is set when the firmware can be upgraded, or when a problem with the firmware is detected. + /// The latest firmware flash tool can be downloaded from http://packages.pulse-eight.net/ + /// + ServiceDevice = 0, + /// + /// The connection to the adapter was lost, probably because the device got unplugged. + /// + ConnectionLost, + /// + /// No permission from the OS to access the adapter. + /// + PermissionError, + /// + /// The device is being used by another program. + /// + PortBusy, + /// + /// The physical address that is assigned to the adapter is already being used. + /// + PhysicalAddressError, + /// + /// The TV does not respond to polls. + /// + TVPollFailed + }; + + /// + /// The type of parameter that is sent with the CecAlert callback + /// + public enum class CecParameterType + { + /// + /// The parameter is a string + /// + ParameterTypeString = 1 + }; + + /// + /// A parameter for the CecAlert callback + /// + public ref class CecParameter + { + public: + /// + /// Create a new parameter + /// + /// The type of this parameter. + /// The value of this parameter. + CecParameter(CecParameterType type, System::String ^ data) + { + Type = type; + Data = data; + } + + /// + /// The type of this parameter + /// + property CecParameterType Type; + /// + /// The value of this parameter + /// + property System::String ^ Data; + }; + + /// + /// The power status of a CEC device + /// + public enum class CecPowerStatus + { + /// + /// Powered on + /// + On = 0x00, + /// + /// In standby mode + /// + Standby = 0x01, + /// + /// In transition from standby to on + /// + InTransitionStandbyToOn = 0x02, + /// + /// In transition from on to standby + /// + InTransitionOnToStandby = 0x03, + /// + /// Unknown status + /// + Unknown = 0x99 + }; + + /// + /// The CEC version of a CEC device + /// + public enum class CecVersion + { + /// + /// Unknown version + /// + Unknown = 0x00, + /// + /// Version 1.2 + /// + V1_2 = 0x01, + /// + /// Version 1.2a + /// + V1_2A = 0x02, + /// + /// Version 1.3 + /// + V1_3 = 0x03, + /// + /// Version 1.3a + /// + V1_3A = 0x04, + /// + /// Version 1.4 + /// + V1_4 = 0x05 + }; + + /// + /// Parameter for OSD string display, that controls how to display the string + /// + public enum class CecDisplayControl + { + /// + /// Display for the default time + /// + DisplayForDefaultTime = 0x00, + /// + /// Display until it is cleared by ClearPreviousMessage + /// + DisplayUntilCleared = 0x40, + /// + /// Clear message displayed by DisplayUntilCleared + /// + ClearPreviousMessage = 0x80, + /// + /// Reserved / do not use + /// + ReservedForFutureUse = 0xC0 + }; + + /// + /// The menu state of a CEC device + /// + public enum class CecMenuState + { + /// + /// Menu active + /// + Activated = 0, + /// + /// Menu not active + /// + Deactivated = 1 + }; + + /// + /// Deck control mode for playback and recording devices + /// + public enum class CecDeckControlMode + { + /// + /// Skip forward / wind + /// + SkipForwardWind = 1, + /// + /// Skip reverse / rewind + /// + SkipReverseRewind = 2, + /// + /// Stop + /// + Stop = 3, + /// + /// Eject + /// + Eject = 4 + }; + + /// + /// Deck status for playback and recording devices + /// + public enum class CecDeckInfo + { + /// + /// Playing + /// + Play = 0x11, + /// + /// Recording + /// + Record = 0x12, + /// + /// Reverse + /// + Reverse = 0x13, + /// + /// Showing still frame + /// + Still = 0x14, + /// + /// Playing slow + /// + Slow = 0x15, + /// + /// Playing slow reverse + /// + SlowReverse = 0x16, + /// + /// Fast forward + /// + FastForward = 0x17, + /// + /// Fast reverse + /// + FastReverse = 0x18, + /// + /// No media detected + /// + NoMedia = 0x19, + /// + /// Stop / not playing + /// + Stop = 0x1A, + /// + /// Skip forward / wind + /// + SkipForwardWind = 0x1B, + /// + /// Skip reverse / rewind + /// + SkipReverseRewind = 0x1C, + /// + /// Index search forward + /// + IndexSearchForward = 0x1D, + /// + /// Index search reverse + /// + IndexSearchReverse = 0x1E, + /// + /// Other / unknown status + /// + OtherStatus = 0x1F + }; + + /// + /// User control code, the key code when the user presses or releases a button on the remote. + /// Used by SendKeypress() and the CecKey callback. + /// + public enum class CecUserControlCode + { + /// + /// Select / OK + /// + Select = 0x00, + /// + /// Direction up + /// + Up = 0x01, + /// + /// Direction down + /// + Down = 0x02, + /// + /// Direction left + /// + Left = 0x03, + /// + /// Direction right + /// + Right = 0x04, + /// + /// Direction right + up + /// + RightUp = 0x05, + /// + /// Direction right + down + /// + RightDown = 0x06, + /// + /// Direction left + up + /// + LeftUp = 0x07, + /// + /// Direction left + down + /// + LeftDown = 0x08, + /// + /// Root menu + /// + RootMenu = 0x09, + /// + /// Setup menu + /// + SetupMenu = 0x0A, + /// + /// Contents menu + /// + ContentsMenu = 0x0B, + /// + /// Favourite menu + /// + FavoriteMenu = 0x0C, + /// + /// Exit / back + /// + Exit = 0x0D, + /// + /// Number 0 + /// + Number0 = 0x20, + /// + /// Number 1 + /// + Number1 = 0x21, + /// + /// Number 2 + /// + Number2 = 0x22, + /// + /// Number 3 + /// + Number3 = 0x23, + /// + /// Number 4 + /// + Number4 = 0x24, + /// + /// Number 5 + /// + Number5 = 0x25, + /// + /// Number 6 + /// + Number6 = 0x26, + /// + /// Number 7 + /// + Number7 = 0x27, + /// + /// Number 8 + /// + Number8 = 0x28, + /// + /// Number 9 + /// + Number9 = 0x29, + /// + /// . + /// + Dot = 0x2A, + /// + /// Enter input + /// + Enter = 0x2B, + /// + /// Clear input + /// + Clear = 0x2C, + /// + /// Next favourite + /// + NextFavorite = 0x2F, + /// + /// Channel up + /// + ChannelUp = 0x30, + /// + /// Channel down + /// + ChannelDown = 0x31, + /// + /// Previous channel + /// + PreviousChannel = 0x32, + /// + /// Select sound track + /// + SoundSelect = 0x33, + /// + /// Select input + /// + InputSelect = 0x34, + /// + /// Display information + /// + DisplayInformation = 0x35, + /// + /// Show help + /// + Help = 0x36, + /// + /// Page up + /// + PageUp = 0x37, + /// + /// Page down + /// + PageDown = 0x38, + /// + /// Toggle powered on / standby + /// + Power = 0x40, + /// + /// Volume up + /// + VolumeUp = 0x41, + /// + /// Volume down + /// + VolumeDown = 0x42, + /// + /// Mute audio + /// + Mute = 0x43, + /// + /// Start playback + /// + Play = 0x44, + /// + /// Stop playback + /// + Stop = 0x45, + /// + /// Pause playback + /// + Pause = 0x46, + /// + /// Toggle recording + /// + Record = 0x47, + /// + /// Rewind + /// + Rewind = 0x48, + /// + /// Fast forward + /// + FastForward = 0x49, + /// + /// Eject media + /// + Eject = 0x4A, + /// + /// Forward + /// + Forward = 0x4B, + /// + /// Backward + /// + Backward = 0x4C, + /// + /// Stop recording + /// + StopRecord = 0x4D, + /// + /// Pause recording + /// + PauseRecord = 0x4E, + /// + /// Change angle + /// + Angle = 0x50, + /// + /// Toggle sub picture + /// + SubPicture = 0x51, + /// + /// Toggle video on demand + /// + VideoOnDemand = 0x52, + /// + /// Toggle electronic program guide (EPG) + /// + ElectronicProgramGuide = 0x53, + /// + /// Toggle timer programming + /// + TimerProgramming = 0x54, + /// + /// Set initial configuration + /// + InitialConfiguration = 0x55, + /// + /// Start playback function + /// + PlayFunction = 0x60, + /// + /// Pause playback function + /// + PausePlayFunction = 0x61, + /// + /// Toggle recording function + /// + RecordFunction = 0x62, + /// + /// Pause recording function + /// + PauseRecordFunction = 0x63, + /// + /// Stop playback function + /// + StopFunction = 0x64, + /// + /// Mute audio function + /// + MuteFunction = 0x65, + /// + /// Restore volume function + /// + RestoreVolumeFunction = 0x66, + /// + /// Tune function + /// + TuneFunction = 0x67, + /// + /// Select media function + /// + SelectMediaFunction = 0x68, + /// + /// Select AV input function + /// + SelectAVInputFunction = 0x69, + /// + /// Select audio input function + /// + SelectAudioInputFunction = 0x6A, + /// + /// Toggle powered on / standby function + /// + PowerToggleFunction = 0x6B, + /// + /// Power off function + /// + PowerOffFunction = 0x6C, + /// + /// Power on function + /// + PowerOnFunction = 0x6D, + /// + /// F1 / blue button + /// + F1Blue = 0x71, + /// + /// F2 / red button + /// + F2Red = 0X72, + /// + /// F3 / green button + /// + F3Green = 0x73, + /// + /// F4 / yellow button + /// + F4Yellow = 0x74, + /// + /// F5 + /// + F5 = 0x75, + /// + /// Data / teletext + /// + Data = 0x76, + /// + /// Max. valid key code for standard buttons + /// + Max = 0x76, + /// + /// Extra return button on Samsung remotes + /// + SamsungReturn = 0x91, + /// + /// Unknown / invalid key code + /// + Unknown + }; + + /// + /// Vendor IDs for CEC devices + /// + public enum class CecVendorId + { + Toshiba = 0x000039, + Samsung = 0x0000F0, + Denon = 0x0005CD, + Marantz = 0x000678, + Loewe = 0x000982, + Onkyo = 0x0009B0, + Medion = 0x000CB8, + Toshiba2 = 0x000CE7, + PulseEight = 0x001582, + Akai = 0x0020C7, + AOC = 0x002467, + Panasonic = 0x008045, + Philips = 0x00903E, + Daewoo = 0x009053, + Yamaha = 0x00A0DE, + Grundig = 0x00D0D5, + Pioneer = 0x00E036, + LG = 0x00E091, + Sharp = 0x08001F, + Sony = 0x080046, + Broadcom = 0x18C086, + Vizio = 0x6B746D, + Benq = 0x8065E9, + HarmanKardon = 0x9C645E, + Unknown = 0 + }; + + /// + /// Audio status of audio system / AVR devices + /// + public enum class CecAudioStatus + { + /// + /// Muted + /// + MuteStatusMask = 0x80, + /// + /// Not muted, volume status mask + /// + VolumeStatusMask = 0x7F, + /// + /// Minumum volume + /// + VolumeMin = 0x00, + /// + /// Maximum volume + /// + VolumeMax = 0x64, + /// + /// Unknown status + /// + VolumeStatusUnknown = 0x7F + }; + + /// + /// CEC opcodes, as described in the HDMI CEC specification + /// + public enum class CecOpcode + { + /// + /// Active source + /// + ActiveSource = 0x82, + /// + /// Image view on: power on display for image display + /// + ImageViewOn = 0x04, + /// + /// Text view on: power on display for text display + /// + TextViewOn = 0x0D, + /// + /// Device no longer is the active source + /// + InactiveSource = 0x9D, + /// + /// Request which device has the active source status + /// + RequestActiveSource = 0x85, + /// + /// Routing change for HDMI switches + /// + RoutingChange = 0x80, + /// + /// Routing information for HDMI switches + /// + RoutingInformation = 0x81, + /// + /// Change the stream path to the given physical address + /// + SetStreamPath = 0x86, + /// + /// Inform that a device went into standby mode + /// + Standby = 0x36, + /// + /// Stop recording + /// + RecordOff = 0x0B, + /// + /// Start recording + /// + RecordOn = 0x09, + /// + /// Recording status information + /// + RecordStatus = 0x0A, + /// + /// Record current display + /// + RecordTvScreen = 0x0F, + /// + /// Clear analogue timer + /// + ClearAnalogueTimer = 0x33, + /// + /// Clear digital timer + /// + ClearDigitalTimer = 0x99, + /// + /// Clear external timer + /// + ClearExternalTimer = 0xA1, + /// + /// Set analogue timer + /// + SetAnalogueTimer = 0x34, + /// + /// Set digital timer + /// + SetDigitalTimer = 0x97, + /// + /// Set external timer + /// + SetExternalTimer = 0xA2, + /// + /// Set program title of a timer + /// + SetTimerProgramTitle = 0x67, + /// + /// Timer status cleared + /// + TimerClearedStatus = 0x43, + /// + /// Timer status information + /// + TimerStatus = 0x35, + /// + /// CEC version used by a device + /// + CecVersion = 0x9E, + /// + /// Request CEC version of a device + /// + GetCecVersion = 0x9F, + /// + /// Request physical address of a device + /// + GivePhysicalAddress = 0x83, + /// + /// Request language code of the menu language of a device + /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/ + /// + GetMenuLanguage = 0x91, + /// + /// Report the physical address + /// + ReportPhysicalAddress = 0x84, + /// + /// Report the language code of the menu language + /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/ + /// + SetMenuLanguage = 0x32, + /// + /// Deck control for playback and recording devices + /// + DeckControl = 0x42, + /// + /// Deck status for playback and recording devices + /// + DeckStatus = 0x1B, + /// + /// Request deck status from playback and recording devices + /// + GiveDeckStatus = 0x1A, + /// + /// Start playback on playback and recording devices + /// + Play = 0x41, + /// + /// Request tuner status + /// + GiveTunerDeviceStatus = 0x08, + /// + /// Select analogue service on a tuner + /// + SelectAnalogueService = 0x92, + /// + /// Select digital service on a tuner + /// + SelectDigtalService = 0x93, + /// + /// Report tuner device status + /// + TunerDeviceStatus = 0x07, + /// + /// Tuner step decrement + /// + TunerStepDecrement = 0x06, + /// + /// Tuner step increment + /// + TunerStepIncrement = 0x05, + /// + /// Report device vendor ID + /// + DeviceVendorId = 0x87, + /// + /// Request device vendor ID + /// + GiveDeviceVendorId = 0x8C, + /// + /// Vendor specific command + /// + VendorCommand = 0x89, + /// + /// Vendor specific command with vendor ID + /// + VendorCommandWithId = 0xA0, + /// + /// Vendor specific remote button pressed + /// + VendorRemoteButtonDown = 0x8A, + /// + /// Vendor specific remote button released + /// + VendorRemoteButtonUp = 0x8B, + /// + /// Display / clear OSD string + /// + SetOsdString = 0x64, + /// + /// Request device OSD name + /// + GiveOsdName = 0x46, + /// + /// Report device OSD name + /// + SetOsdName = 0x47, + /// + /// Request device menu status + /// + MenuRequest = 0x8D, + /// + /// Report device menu status + /// + MenuStatus = 0x8E, + /// + /// Remote button pressed + /// + UserControlPressed = 0x44, + /// + /// Remote button released + /// + UserControlRelease = 0x45, + /// + /// Request device power status + /// + GiveDevicePowerStatus = 0x8F, + /// + /// Report device power status + /// + ReportPowerStatus = 0x90, + /// + /// Feature abort / unsupported command + /// + FeatureAbort = 0x00, + /// + /// Abort command + /// + Abort = 0xFF, + /// + /// Give audio status + /// + GiveAudioStatus = 0x71, + /// + /// Give audiosystem mode + /// + GiveSystemAudioMode = 0x7D, + /// + /// Report device audio status + /// + ReportAudioStatus = 0x7A, + /// + /// Set audiosystem mode + /// + SetSystemAudioMode = 0x72, + /// + /// Request audiosystem mode + /// + SystemAudioModeRequest = 0x70, + /// + /// Report audiosystem mode + /// + SystemAudioModeStatus = 0x7E, + /// + /// Set audio bitrate + /// + SetAudioRate = 0x9A, + /// + /// When this opcode is set, no opcode will be sent to the device / poll message + /// This is one of the reserved numbers + /// + None = 0xFD + }; + + /// + /// Audiosystem status + /// + public enum class CecSystemAudioStatus + { + /// + /// Turned off + /// + Off = 0, + /// + /// Turned on + /// + On = 1 + }; + + /// + /// libCEC client application version + /// + public enum class CecClientVersion + { + /// + /// before v1.5.0 + /// + VersionPre1_5 = 0, + /// + /// v1.5.0 + /// + Version1_5_0 = 0x1500, + /// + /// v1.5.1 + /// + Version1_5_1 = 0x1501, + /// + /// v1.5.2 + /// + Version1_5_2 = 0x1502, + /// + /// v1.5.3 + /// + Version1_5_3 = 0x1503, + /// + /// v1.6.0 + /// + Version1_6_0 = 0x1600, + /// + /// v1.6.1 + /// + Version1_6_1 = 0x1601, + /// + /// v1.6.2 + /// + Version1_6_2 = 0x1602, + /// + /// v1.6.3 + /// + Version1_6_3 = 0x1603, + /// + /// v1.7.0 + /// + Version1_7_0 = 0x1700, + /// + /// v1.7.1 + /// + Version1_7_1 = 0x1701, + /// + /// v1.7.2 + /// + Version1_7_2 = 0x1702, + /// + /// v1.8.0 + /// + Version1_8_0 = 0x1800, + /// + /// v1.8.1 + /// + Version1_8_1 = 0x1801, + /// + /// v1.8.2 + /// + Version1_8_2 = 0x1802, + /// + /// v1.9.0 + /// + Version1_9_0 = 0x1900, + /// + /// v2.0.0-pre + /// + Version1_99_0 = 0x1990, + /// + /// v2.0.0 + /// + Version2_0_0 = 0x2000, + /// + /// v2.0.1 + /// + Version2_0_1 = 0x2001, + /// + /// v2.0.2 + /// + Version2_0_2 = 0x2002, + /// + /// v2.0.3 + /// + Version2_0_3 = 0x2003, + /// + /// v2.0.4 + /// + Version2_0_4 = 0x2004, + /// + /// v2.0.5 + /// + Version2_0_5 = 0x2005, + /// + /// v2.1.0 + /// + Version2_1_0 = 0x2100, + /// + /// v2.1.1 + /// + Version2_1_1 = 0x2101, + /// + /// v2.1.2 + /// + Version2_1_2 = 0x2102, + /// + /// v2.1.3 + /// + Version2_1_3 = 0x2103, + /// + /// v2.1.4 + /// + Version2_1_4 = 0x2104, + /// + /// The current version + /// + CurrentVersion = 0x2104 + }; + + /// + /// libCEC version + /// + public enum class CecServerVersion + { + /// + /// before v1.5.0 + /// + VersionPre1_5 = 0, + /// + /// v1.5.0 + /// + Version1_5_0 = 0x1500, + /// + /// v1.5.1 + /// + Version1_5_1 = 0x1501, + /// + /// v1.5.2 + /// + Version1_5_2 = 0x1502, + /// + /// v1.5.3 + /// + Version1_5_3 = 0x1503, + /// + /// v1.6.0 + /// + Version1_6_0 = 0x1600, + /// + /// v1.6.1 + /// + Version1_6_1 = 0x1601, + /// + /// v1.6.2 + /// + Version1_6_2 = 0x1602, + /// + /// v1.6.3 + /// + Version1_6_3 = 0x1603, + /// + /// v1.7.0 + /// + Version1_7_0 = 0x1700, + /// + /// v1.7.1 + /// + Version1_7_1 = 0x1701, + /// + /// v1.7.2 + /// + Version1_7_2 = 0x1702, + /// + /// v1.8.0 + /// + Version1_8_0 = 0x1800, + /// + /// v1.8.1 + /// + Version1_8_1 = 0x1801, + /// + /// v1.8.2 + /// + Version1_8_2 = 0x1802, + /// + /// v1.9.0 + /// + Version1_9_0 = 0x1900, + /// + /// v2.0.0-pre + /// + Version1_99_0 = 0x1990, + /// + /// v2.0.0 + /// + Version2_0_0 = 0x2000, + /// + /// v2.0.1 + /// + Version2_0_1 = 0x2001, + /// + /// v2.0.2 + /// + Version2_0_2 = 0x2002, + /// + /// v2.0.3 + /// + Version2_0_3 = 0x2003, + /// + /// v2.0.4 + /// + Version2_0_4 = 0x2004, + /// + /// v2.0.5 + /// + Version2_0_5 = 0x2005, + /// + /// v2.1.0 + /// + Version2_1_0 = 0x2100, + /// + /// v2.1.1 + /// + Version2_1_1 = 0x2101, + /// + /// v2.1.2 + /// + Version2_1_2 = 0x2102, + /// + /// v2.1.3 + /// + Version2_1_3 = 0x2103, + /// + /// v2.1.4 + /// + Version2_1_4 = 0x2104, + /// + /// The current version + /// + CurrentVersion = 0x2104 + }; + + /// + /// Type of adapter to which libCEC is connected + /// + public enum class CecAdapterType + { + /// + /// Unknown adapter type + /// + Unknown = 0, + /// + /// Pulse-Eight USB-CEC adapter + /// + PulseEightExternal = 0x1, + /// + /// Pulse-Eight CEC daughterboard + /// + PulseEightDaughterboard = 0x2, + /// + /// Raspberry Pi + /// + RaspberryPi = 0x100, + /// + /// TDA995x + /// + TDA995x = 0x200 + }; + + /// + /// Descriptor of a CEC adapter, returned when scanning for adapters that are connected to the system + /// + public ref class CecAdapter + { + public: + /// + /// Create a new CEC adapter descriptor + /// + /// The path descriptor for this CEC adapter + /// The COM port of this CEC adapter + CecAdapter(System::String ^ path, System::String ^ comPort) + { + Path = path; + ComPort = comPort; + } + + /// + /// The path descriptor for this CEC adapter + /// + property System::String ^ Path; + + /// + /// The COM port of this CEC adapter + /// + property System::String ^ ComPort; + }; + + /// + /// A list of CEC device types + /// + public ref class CecDeviceTypeList + { + public: + /// + /// Create a new empty list of CEC device types + /// + CecDeviceTypeList(void) + { + Types = gcnew array(5); + for (unsigned int iPtr = 0; iPtr < 5; iPtr++) + Types[iPtr] = CecDeviceType::Reserved; + } + + /// + /// The array with CecDeviceType instances in this list. + /// + property array ^ Types; + }; + + /// + /// A list of logical addresses + /// + public ref class CecLogicalAddresses + { + public: + /// + /// Create a new empty list of logical addresses + /// + CecLogicalAddresses(void) + { + Addresses = gcnew array(16); + Clear(); + } + + /// + /// Clears this list + /// + void Clear(void) + { + Primary = CecLogicalAddress::Unknown; + for (unsigned int iPtr = 0; iPtr < 16; iPtr++) + Addresses[iPtr] = CecLogicalAddress::Unknown; + } + + /// + /// Checks whether a logical address is set in this list. + /// + /// The address to check. + /// True when set, false otherwise + bool IsSet(CecLogicalAddress address) + { + return Addresses[(unsigned int)address] != CecLogicalAddress::Unknown; + } + + /// + /// Add a logical address to this list (if it's not set already) + /// + /// The address to add. + void Set(CecLogicalAddress address) + { + Addresses[(unsigned int)address] = address; + if (Primary == CecLogicalAddress::Unknown) + Primary = address; + } + + /// + /// The primary (first) address in this list + /// + property CecLogicalAddress Primary; + + /// + /// The list of addresses + /// + property array ^ Addresses; + }; + + + /// + /// Byte array used for CEC command parameters + /// + public ref class CecDatapacket + { + public: + /// + /// Create a new byte array with maximum size 100 + /// + CecDatapacket(void) + { + Data = gcnew array(100); + Size = 0; + } + + /// + /// Adds a byte to this byte array + /// + /// The byte to add. + void PushBack(uint8_t data) + { + if (Size < 100) + { + Data[Size] = data; + Size++; + } + } + + /// + /// Array data + /// + property array ^ Data; + + /// + /// Current data size + /// + property uint8_t Size; + }; + + /// + /// A CEC command that is received or transmitted over the CEC bus + /// + public ref class CecCommand + { + public: + /// + /// Create a new CEC command instance + /// + /// The initiator of the command + /// The receiver of the command + /// True when the ack bit is set, false otherwise + /// True when the eom bit is set, false otherwise + /// The CEC opcode of this command + /// The timeout to use when transmitting a command + CecCommand(CecLogicalAddress initiator, CecLogicalAddress destination, bool ack, bool eom, CecOpcode opcode, int32_t transmitTimeout) + { + Initiator = initiator; + Destination = destination; + Ack = ack; + Eom = eom; + Opcode = opcode; + OpcodeSet = true; + TransmitTimeout = transmitTimeout; + Parameters = gcnew CecDatapacket; + Empty = false; + } + + /// + /// Create a new empty CEC command instance + /// + CecCommand(void) + { + Initiator = CecLogicalAddress::Unknown; + Destination = CecLogicalAddress::Unknown; + Ack = false; + Eom = false; + Opcode = CecOpcode::None; + OpcodeSet = false; + TransmitTimeout = 0; + Parameters = gcnew CecDatapacket; + Empty = true; + } + + /// + /// Pushes a byte of data to this CEC command + /// + /// The byte to add + void PushBack(uint8_t data) + { + if (Initiator == CecLogicalAddress::Unknown && Destination == CecLogicalAddress::Unknown) + { + Initiator = (CecLogicalAddress) (data >> 4); + Destination = (CecLogicalAddress) (data & 0xF); + } + else if (!OpcodeSet) + { + OpcodeSet = true; + Opcode = (CecOpcode)data; + } + else + { + Parameters->PushBack(data); + } + } + + /// + /// True when this command is empty, false otherwise. + /// + property bool Empty; + /// + /// The initiator of the command + /// + property CecLogicalAddress Initiator; + /// + /// The destination of the command + /// + property CecLogicalAddress Destination; + /// + /// True when the ack bit is set, false otherwise + /// + property bool Ack; + /// + /// True when the eom bit is set, false otherwise + /// + property bool Eom; + /// + /// The CEC opcode of the command + /// + property CecOpcode Opcode; + /// + /// The parameters of this command + /// + property CecDatapacket ^ Parameters; + /// + /// True when an opcode is set, false otherwise (poll message) + /// + property bool OpcodeSet; + /// + /// The timeout to use when transmitting a command + /// + property int32_t TransmitTimeout; + }; + + /// + /// A key press that was received + /// + public ref class CecKeypress + { + public: + /// + /// Create a new key press instance + /// + /// The key code of this key press + /// The duration of this key press in milliseconds + CecKeypress(CecUserControlCode keycode, unsigned int duration) + { + Keycode = keycode; + Duration = duration; + Empty = false; + } + + /// + /// Create a new empty key press instance + /// + CecKeypress(void) + { + Keycode = CecUserControlCode::Unknown; + Duration = 0; + Empty = true; + } + + /// + /// True when empty, false otherwise + /// + property bool Empty; + /// + /// The key code of this key press + /// + property CecUserControlCode Keycode; + /// + /// The duration of this key press in milliseconds + /// + property unsigned int Duration; + }; + + /// + /// A log message that libCEC generated + /// + public ref class CecLogMessage + { + public: + /// + /// Create a new log message + /// + /// The actual message + /// The log level, so the application can choose what type information to display + /// The timestamp of this message, in milliseconds after connecting + CecLogMessage(System::String ^ message, CecLogLevel level, int64_t time) + { + Message = message; + Level = level; + Time = time; + Empty = false; + } + + /// + /// Create a new empty log message + /// + CecLogMessage(void) + { + Message = ""; + Level = CecLogLevel::None; + Time = 0; + Empty = true; + } + + /// + /// True when empty, false otherwise. + /// + property bool Empty; + /// + /// The actual message + /// + property System::String ^Message; + /// + /// The log level, so the application can choose what type information to display + /// + property CecLogLevel Level; + /// + /// The timestamp of this message, in milliseconds after connecting + /// + property int64_t Time; + }; + + ref class CecCallbackMethods; //forward declaration + + /// + /// The configuration that libCEC uses. + /// + public ref class LibCECConfiguration + { + public: + /// + /// Create a new configuration instance with default settings. + /// + LibCECConfiguration(void) + { + DeviceName = ""; + DeviceTypes = gcnew CecDeviceTypeList(); + AutodetectAddress = true; + PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS; + BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE; + HDMIPort = CEC_DEFAULT_HDMI_PORT; + ClientVersion = CecClientVersion::CurrentVersion; + ServerVersion = CecServerVersion::CurrentVersion; + TvVendor = CecVendorId::Unknown; + + GetSettingsFromROM = false; + UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1; + ActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1; + + WakeDevices = gcnew CecLogicalAddresses(); + if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1) + WakeDevices->Set(CecLogicalAddress::Tv); + + PowerOffDevices = gcnew CecLogicalAddresses(); + if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1) + PowerOffDevices->Set(CecLogicalAddress::Broadcast); + + PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1; + PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1; + + SendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1; + LogicalAddresses = gcnew CecLogicalAddresses(); + FirmwareVersion = 1; + PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1; + ShutdownOnStandby = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY == 1; + DeviceLanguage = ""; + FirmwareBuildDate = gcnew System::DateTime(1970,1,1,0,0,0,0); + CECVersion = (CecVersion)CEC_DEFAULT_SETTING_CEC_VERSION; + AdapterType = CecAdapterType::Unknown; + } + + /// + /// Change the callback method pointers in this configuration instance. + /// + /// The new callbacks + void SetCallbacks(CecCallbackMethods ^callbacks) + { + Callbacks = callbacks; + } + + /// + /// Update this configuration with data received from libCEC + /// + /// The configuration that was received from libCEC + void Update(const CEC::libcec_configuration &config) + { + DeviceName = gcnew System::String(config.strDeviceName); + + for (unsigned int iPtr = 0; iPtr < 5; iPtr++) + DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr]; + + AutodetectAddress = config.bAutodetectAddress == 1; + PhysicalAddress = config.iPhysicalAddress; + BaseDevice = (CecLogicalAddress)config.baseDevice; + HDMIPort = config.iHDMIPort; + ClientVersion = (CecClientVersion)config.clientVersion; + ServerVersion = (CecServerVersion)config.serverVersion; + TvVendor = (CecVendorId)config.tvVendor; + + // player specific settings + GetSettingsFromROM = config.bGetSettingsFromROM == 1; + UseTVMenuLanguage = config.bUseTVMenuLanguage == 1; + ActivateSource = config.bActivateSource == 1; + + WakeDevices->Clear(); + for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) + if (config.wakeDevices[iPtr]) + WakeDevices->Set((CecLogicalAddress)iPtr); + + PowerOffDevices->Clear(); + for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) + if (config.powerOffDevices[iPtr]) + PowerOffDevices->Set((CecLogicalAddress)iPtr); + + PowerOffScreensaver = config.bPowerOffScreensaver == 1; + PowerOffOnStandby = config.bPowerOffOnStandby == 1; + + if (ServerVersion >= CecServerVersion::Version1_5_1) + SendInactiveSource = config.bSendInactiveSource == 1; + + if (ServerVersion >= CecServerVersion::Version1_5_3) + { + LogicalAddresses->Clear(); + for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) + if (config.logicalAddresses[iPtr]) + LogicalAddresses->Set((CecLogicalAddress)iPtr); + } + + if (ServerVersion >= CecServerVersion::Version1_6_0) + { + FirmwareVersion = config.iFirmwareVersion; + PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1; + ShutdownOnStandby = config.bShutdownOnStandby == 1; + } + + if (ServerVersion >= CecServerVersion::Version1_6_2) + { + DeviceLanguage = gcnew System::String(config.strDeviceLanguage); + FirmwareBuildDate = gcnew System::DateTime(1970,1,1,0,0,0,0); + FirmwareBuildDate = FirmwareBuildDate->AddSeconds(config.iFirmwareBuildDate); + } + + if (ServerVersion >= CecServerVersion::Version1_6_3) + MonitorOnlyClient = config.bMonitorOnly == 1; + + if (ServerVersion >= CecServerVersion::Version1_8_0) + CECVersion = (CecVersion)config.cecVersion; + + if (ServerVersion >= CecServerVersion::Version1_8_2) + AdapterType = (CecAdapterType)config.adapterType; + + if (ServerVersion >= CecServerVersion::Version2_1_0) + PowerOnScreensaver = config.bPowerOnScreensaver == 1; + } + + /// + /// The device name to use on the CEC bus + /// + property System::String ^ DeviceName; + + /// + /// The device type(s) to use on the CEC bus for libCEC + /// + property CecDeviceTypeList ^ DeviceTypes; + + /// + /// (read only) set to true by libCEC when the physical address was autodetected + /// + property bool AutodetectAddress; + + /// + /// The physical address of the CEC adapter + /// + property uint16_t PhysicalAddress; + + /// + /// The logical address of the device to which the adapter is connected. Only used when PhysicalAddress = 0 or when the adapter doesn't support autodetection + /// + property CecLogicalAddress BaseDevice; + + /// + /// The HDMI port to which the adapter is connected. Only used when iPhysicalAddress = 0 or when the adapter doesn't support autodetection + /// + property uint8_t HDMIPort; + + /// + /// The client API version to use + /// + property CecClientVersion ClientVersion; + + /// + /// The version of libCEC + /// + property CecServerVersion ServerVersion; + + /// + /// Override the vendor ID of the TV. Leave this untouched to autodetect + /// + property CecVendorId TvVendor; + + /// + /// True to read the settings from the EEPROM, which possibly override the settings passed here + /// + property bool GetSettingsFromROM; + + /// + /// Use the language setting of the TV in the client application. Must be implemented by the client application. + /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/ + /// + property bool UseTVMenuLanguage; + + /// + /// Make libCEC the active source when starting the client application + /// + property bool ActivateSource; + + /// + /// List of devices to wake when initialising libCEC or when calling PowerOnDevices() without any parameter. + /// + property CecLogicalAddresses ^WakeDevices; + + /// + /// List of devices to power off when calling StandbyDevices() without any parameter. + /// + property CecLogicalAddresses ^PowerOffDevices; + + /// + /// Send standby commands when the client application activates the screensaver. Must be implemented by the client application. + /// + property bool PowerOffScreensaver; + + /// + /// Power off the PC when the TV powers off. Must be implemented by the client application. + /// + property bool PowerOffOnStandby; + + /// + /// Send an inactive source message when exiting the client application. + /// + property bool SendInactiveSource; + + /// + /// The list of logical addresses that libCEC is using + /// + property CecLogicalAddresses ^LogicalAddresses; + + /// + /// The firmware version of the adapter to which libCEC is connected + /// + property uint16_t FirmwareVersion; + + /// + /// Send standby commands when the client application activates standby mode (S3). Must be implemented by the client application. + /// + property bool PowerOffDevicesOnStandby; + + /// + /// Shutdown this PC when the TV is switched off. only used when PowerOffOnStandby = false + /// + property bool ShutdownOnStandby; + + /// + /// True to start a monitor-only client, false to start a standard client. + /// + property bool MonitorOnlyClient; + + /// + /// The language code of the menu language that libCEC reports to other devices. + /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/ + /// + property System::String ^ DeviceLanguage; + + /// + /// The callback methods to use. + /// + property CecCallbackMethods ^ Callbacks; + + /// + /// The build date of the firmware. + /// + property System::DateTime ^ FirmwareBuildDate; + + /// + /// The CEC version that libCEC uses. + /// + property CecVersion CECVersion; + + /// + /// The type of adapter that libCEC is connected to. + /// + property CecAdapterType AdapterType; + + /// + /// True to power on when quitting the screensaver. + /// + property bool PowerOnScreensaver; + }; + + // the callback methods are called by unmanaged code, so we need some delegates for this +#pragma unmanaged + // unmanaged callback methods + typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message); + typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key); + typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command); + typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config); + typedef int (__stdcall *ALERTCB) (const CEC::libcec_alert, const CEC::libcec_parameter &data); + typedef int (__stdcall *MENUCB) (const CEC::cec_menu_state newVal); + typedef void (__stdcall *ACTICB) (const CEC::cec_logical_address logicalAddress, const uint8_t bActivated); + + /// + /// libCEC callback methods. Unmanaged code. + /// + typedef struct + { + /// + /// Log message callback + /// + LOGCB logCB; + /// + /// Key press/release callback + /// + KEYCB keyCB; + /// + /// Raw CEC data callback + /// + COMMANDCB commandCB; + /// + /// Updated configuration callback + /// + CONFIGCB configCB; + /// + /// Alert message callback + /// + ALERTCB alertCB; + /// + /// Menu status change callback + /// + MENUCB menuCB; + /// + /// Source (de)activated callback + /// + ACTICB sourceActivatedCB; + } UnmanagedCecCallbacks; + + static PLATFORM::CMutex g_callbackMutex; + static std::vector g_unmanagedCallbacks; static CEC::ICECCallbacks g_cecCallbacks; - int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message) - { - if (cbParam) - { - size_t iPtr = (size_t)cbParam; - PLATFORM::CLockObject lock(g_callbackMutex); - if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) - return g_unmanagedCallbacks[iPtr].logCB(message); - } - return 0; - } - - int CecKeyPressCB(void *cbParam, const CEC::cec_keypress &key) - { - if (cbParam) - { - size_t iPtr = (size_t)cbParam; - PLATFORM::CLockObject lock(g_callbackMutex); - if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) - return g_unmanagedCallbacks[iPtr].keyCB(key); - } - return 0; - } - - int CecCommandCB(void *cbParam, const CEC::cec_command &command) - { - if (cbParam) - { - size_t iPtr = (size_t)cbParam; - PLATFORM::CLockObject lock(g_callbackMutex); - if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) - return g_unmanagedCallbacks[iPtr].commandCB(command); - } - return 0; - } - - int CecConfigCB(void *cbParam, const CEC::libcec_configuration &config) - { - if (cbParam) - { - size_t iPtr = (size_t)cbParam; - PLATFORM::CLockObject lock(g_callbackMutex); - if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) - return g_unmanagedCallbacks[iPtr].configCB(config); - } - return 0; - } - - int CecAlertCB(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter &data) - { - if (cbParam) - { - size_t iPtr = (size_t)cbParam; - PLATFORM::CLockObject lock(g_callbackMutex); - if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) - return g_unmanagedCallbacks[iPtr].alertCB(alert, data); - } - return 0; - } - - int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal) - { - if (cbParam) - { - size_t iPtr = (size_t)cbParam; - PLATFORM::CLockObject lock(g_callbackMutex); - if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) - return g_unmanagedCallbacks[iPtr].menuCB(newVal); - } - return 0; - } - - void CecSourceActivatedCB(void *cbParam, const CEC::cec_logical_address logicalAddress, const uint8_t bActivated) - { - if (cbParam) - { - size_t iPtr = (size_t)cbParam; - PLATFORM::CLockObject lock(g_callbackMutex); - if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) - g_unmanagedCallbacks[iPtr].sourceActivatedCB(logicalAddress, bActivated); - } - } - - #pragma managed - // delegates for the unmanaged callback methods - public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &); - public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &); - public delegate int CecCommandManagedDelegate(const CEC::cec_command &); - public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &); - public delegate int CecAlertManagedDelegate(const CEC::libcec_alert, const CEC::libcec_parameter &); - public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state newVal); - public delegate void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated); - - void AssignCallbacks() - { - g_cecCallbacks.CBCecLogMessage = CecLogMessageCB; - g_cecCallbacks.CBCecKeyPress = CecKeyPressCB; - g_cecCallbacks.CBCecCommand = CecCommandCB; - g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB; - g_cecCallbacks.CBCecAlert = CecAlertCB; - g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB; + /// + /// Called by libCEC to send back a log message to the application + /// + /// Pointer to the callback struct + /// The log message + /// 1 when handled, 0 otherwise + int CecLogMessageCB(void *cbParam, const CEC::cec_log_message message) + { + if (cbParam) + { + size_t iPtr = (size_t)cbParam; + PLATFORM::CLockObject lock(g_callbackMutex); + if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) + return g_unmanagedCallbacks[iPtr].logCB(message); + } + return 0; + } + + /// + /// Called by libCEC to send back a key press or release to the application + /// + /// Pointer to the callback struct + /// The key press command that libCEC received + /// 1 when handled, 0 otherwise + int CecKeyPressCB(void *cbParam, const CEC::cec_keypress key) + { + if (cbParam) + { + size_t iPtr = (size_t)cbParam; + PLATFORM::CLockObject lock(g_callbackMutex); + if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) + return g_unmanagedCallbacks[iPtr].keyCB(key); + } + return 0; + } + + /// + /// Called by libCEC to send back raw CEC data to the application + /// + /// Pointer to the callback struct + /// The raw CEC data + /// 1 when handled, 0 otherwise + int CecCommandCB(void *cbParam, const CEC::cec_command command) + { + if (cbParam) + { + size_t iPtr = (size_t)cbParam; + PLATFORM::CLockObject lock(g_callbackMutex); + if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) + return g_unmanagedCallbacks[iPtr].commandCB(command); + } + return 0; + } + + /// + /// Called by libCEC to send back an updated configuration to the application + /// + /// Pointer to the callback struct + /// The new configuration + /// 1 when handled, 0 otherwise + int CecConfigCB(void *cbParam, const CEC::libcec_configuration config) + { + if (cbParam) + { + size_t iPtr = (size_t)cbParam; + PLATFORM::CLockObject lock(g_callbackMutex); + if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) + return g_unmanagedCallbacks[iPtr].configCB(config); + } + return 0; + } + + /// + /// Called by libCEC to send back an alert message to the application + /// + /// Pointer to the callback struct + /// The alert message + /// 1 when handled, 0 otherwise + int CecAlertCB(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter data) + { + if (cbParam) + { + size_t iPtr = (size_t)cbParam; + PLATFORM::CLockObject lock(g_callbackMutex); + if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) + return g_unmanagedCallbacks[iPtr].alertCB(alert, data); + } + return 0; + } + + /// + /// Called by libCEC to send back a menu state change to the application + /// + /// Pointer to the callback struct + /// The new menu state + /// 1 when handled, 0 otherwise + int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal) + { + if (cbParam) + { + size_t iPtr = (size_t)cbParam; + PLATFORM::CLockObject lock(g_callbackMutex); + if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) + return g_unmanagedCallbacks[iPtr].menuCB(newVal); + } + return 0; + } + + /// + /// Called by libCEC to notify the application that the source that is handled by libCEC was (de)activated + /// + /// Pointer to the callback struct + /// The logical address that was (de)activated + /// True when activated, false when deactivated + void CecSourceActivatedCB(void *cbParam, const CEC::cec_logical_address logicalAddress, const uint8_t activated) + { + if (cbParam) + { + size_t iPtr = (size_t)cbParam; + PLATFORM::CLockObject lock(g_callbackMutex); + if (iPtr >= 0 && iPtr < g_unmanagedCallbacks.size()) + g_unmanagedCallbacks[iPtr].sourceActivatedCB(logicalAddress, activated); + } + } + +#pragma managed + /// + /// Delegate method for the CecLogMessageCB callback in CecCallbackMethods + /// + public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &); + /// + /// Delegate method for the CecKeyPressCB callback in CecCallbackMethods + /// + public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &); + /// + /// Delegate method for the CecCommandCB callback in CecCallbackMethods + /// + public delegate int CecCommandManagedDelegate(const CEC::cec_command &); + /// + /// Delegate method for the CecConfigCB callback in CecCallbackMethods + /// + public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &); + /// + /// Delegate method for the CecAlertCB callback in CecCallbackMethods + /// + public delegate int CecAlertManagedDelegate(const CEC::libcec_alert, const CEC::libcec_parameter &); + /// + /// Delegate method for the CecMenuCB callback in CecCallbackMethods + /// + public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state); + /// + /// Delegate method for the CecSourceActivatedCB callback in CecCallbackMethods + /// + public delegate void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address, const uint8_t); + + /// + /// Assign the callback methods in the g_cecCallbacks struct + /// + void AssignCallbacks() + { + g_cecCallbacks.CBCecLogMessage = CecLogMessageCB; + g_cecCallbacks.CBCecKeyPress = CecKeyPressCB; + g_cecCallbacks.CBCecCommand = CecCommandCB; + g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB; + g_cecCallbacks.CBCecAlert = CecAlertCB; + g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB; g_cecCallbacks.CBCecSourceActivated = CecSourceActivatedCB; - } - - // callback method interface - public ref class CecCallbackMethods - { - public: + } + + /// + /// The callback methods that libCEC uses + /// + public ref class CecCallbackMethods + { + public: CecCallbackMethods(void) { - m_iCallbackPtr = -1; - AssignCallbacks(); + m_iCallbackPtr = -1; + AssignCallbacks(); m_bHasCallbacks = false; m_bDelegatesCreated = false; } - ~CecCallbackMethods(void) + ~CecCallbackMethods(void) { DestroyDelegates(); } - size_t GetCallbackPtr(void) - { - PLATFORM::CLockObject lock(g_callbackMutex); - return m_iCallbackPtr; - } - - protected: - !CecCallbackMethods(void) - { - DestroyDelegates(); - } - - public: - virtual void DisableCallbacks(void) - { - DestroyDelegates(); - } - - virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) - { + /// + /// Pointer to the callbacks struct entry + /// + size_t GetCallbackPtr(void) + { + PLATFORM::CLockObject lock(g_callbackMutex); + return m_iCallbackPtr; + } + + protected: + !CecCallbackMethods(void) + { + DestroyDelegates(); + } + + public: + /// + /// Disable callback methods + /// + virtual void DisableCallbacks(void) + { + DestroyDelegates(); + } + + /// + /// Enable callback methods + /// + /// Callback methods to activate + /// true when handled, false otherwise + virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) + { CreateDelegates(); - if (!m_bHasCallbacks) - { - m_bHasCallbacks = true; - m_callbacks = callbacks; - return true; - } - - return false; - } - - virtual int ReceiveLogMessage(CecLogMessage ^ message) - { - return 0; - } - - virtual int ReceiveKeypress(CecKeypress ^ key) - { - return 0; - } - - virtual int ReceiveCommand(CecCommand ^ command) - { - return 0; - } - - virtual int ConfigurationChanged(LibCECConfiguration ^ config) - { - return 0; - } - - virtual int ReceiveAlert(CecAlert alert, CecParameter ^ data) - { - return 0; - } - - virtual int ReceiveMenuStateChange(CecMenuState newVal) - { - return 0; - } - - virtual void SourceActivated(CecLogicalAddress logicalAddress, bool bActivated) - { - } - - protected: - // managed callback methods - int CecLogMessageManaged(const CEC::cec_log_message &message) - { - int iReturn(0); - if (m_bHasCallbacks) - iReturn = m_callbacks->ReceiveLogMessage(gcnew CecLogMessage(gcnew System::String(message.message), (CecLogLevel)message.level, message.time)); - return iReturn; - } - - int CecKeyPressManaged(const CEC::cec_keypress &key) - { - int iReturn(0); - if (m_bHasCallbacks) - iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration)); - return iReturn; - } - - int CecCommandManaged(const CEC::cec_command &command) - { - int iReturn(0); - if (m_bHasCallbacks) - { - CecCommand ^ newCommand = gcnew CecCommand((CecLogicalAddress)command.initiator, (CecLogicalAddress)command.destination, command.ack == 1 ? true : false, command.eom == 1 ? true : false, (CecOpcode)command.opcode, command.transmit_timeout); - for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) - newCommand->Parameters->PushBack(command.parameters[iPtr]); - iReturn = m_callbacks->ReceiveCommand(newCommand); - } - return iReturn; - } - - int CecConfigManaged(const CEC::libcec_configuration &config) - { - int iReturn(0); - if (m_bHasCallbacks) - { - LibCECConfiguration ^netConfig = gcnew LibCECConfiguration(); - netConfig->Update(config); - iReturn = m_callbacks->ConfigurationChanged(netConfig); - } - return iReturn; - } - - int CecAlertManaged(const CEC::libcec_alert alert, const CEC::libcec_parameter &data) - { - int iReturn(0); - if (m_bHasCallbacks) - { - CecParameterType newType = (CecParameterType)data.paramType; - if (newType == CecParameterType::ParameterTypeString) - { - System::String ^ newData = gcnew System::String((const char *)data.paramData, 0, 128); - CecParameter ^ newParam = gcnew CecParameter(newType, newData); - iReturn = m_callbacks->ReceiveAlert((CecAlert)alert, newParam); - } - } - return iReturn; - } - - int CecMenuManaged(const CEC::cec_menu_state newVal) - { - int iReturn(0); - if (m_bHasCallbacks) - { - iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal); - } - return iReturn; - } - - void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated) - { - if (m_bHasCallbacks) - m_callbacks->SourceActivated((CecLogicalAddress)logicalAddress, bActivated == 1); - } - - void DestroyDelegates() - { + if (!m_bHasCallbacks) + { + m_bHasCallbacks = true; + m_callbacks = callbacks; + return true; + } + + return false; + } + + /// + /// Called by libCEC to send back a log message to the application. + /// Override in the application to handle this callback. + /// + /// The log message + /// 1 when handled, 0 otherwise + virtual int ReceiveLogMessage(CecLogMessage ^ message) + { + return 0; + } + + /// + /// Called by libCEC to send back a key press or release to the application. + /// Override in the application to handle this callback. + /// + /// The key press command that libCEC received + /// 1 when handled, 0 otherwise + virtual int ReceiveKeypress(CecKeypress ^ key) + { + return 0; + } + + /// + /// Called by libCEC to send back raw CEC data to the application. + /// Override in the application to handle this callback. + /// + /// The raw CEC data + /// 1 when handled, 0 otherwise + virtual int ReceiveCommand(CecCommand ^ command) + { + return 0; + } + + /// + /// Called by libCEC to send back an updated configuration to the application. + /// Override in the application to handle this callback. + /// + /// The new configuration + /// 1 when handled, 0 otherwise + virtual int ConfigurationChanged(LibCECConfiguration ^ config) + { + return 0; + } + + /// + /// Called by libCEC to send back an alert message to the application. + /// Override in the application to handle this callback. + /// + /// The alert message + /// 1 when handled, 0 otherwise + virtual int ReceiveAlert(CecAlert alert, CecParameter ^ data) + { + return 0; + } + + /// + /// Called by libCEC to send back a menu state change to the application. + /// Override in the application to handle this callback. + /// + /// The new menu state + /// 1 when handled, 0 otherwise + virtual int ReceiveMenuStateChange(CecMenuState newVal) + { + return 0; + } + + /// + /// Called by libCEC to notify the application that the source that is handled by libCEC was (de)activated. + /// Override in the application to handle this callback. + /// + /// The logical address that was (de)activated + /// True when activated, false when deactivated + virtual void SourceActivated(CecLogicalAddress logicalAddress, bool activated) + { + } + + protected: + // managed callback methods + int CecLogMessageManaged(const CEC::cec_log_message &message) + { + int iReturn(0); + if (m_bHasCallbacks) + iReturn = m_callbacks->ReceiveLogMessage(gcnew CecLogMessage(gcnew System::String(message.message), (CecLogLevel)message.level, message.time)); + return iReturn; + } + + int CecKeyPressManaged(const CEC::cec_keypress &key) + { + int iReturn(0); + if (m_bHasCallbacks) + iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration)); + return iReturn; + } + + int CecCommandManaged(const CEC::cec_command &command) + { + int iReturn(0); + if (m_bHasCallbacks) + { + CecCommand ^ newCommand = gcnew CecCommand((CecLogicalAddress)command.initiator, (CecLogicalAddress)command.destination, command.ack == 1 ? true : false, command.eom == 1 ? true : false, (CecOpcode)command.opcode, command.transmit_timeout); + for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) + newCommand->Parameters->PushBack(command.parameters[iPtr]); + iReturn = m_callbacks->ReceiveCommand(newCommand); + } + return iReturn; + } + + int CecConfigManaged(const CEC::libcec_configuration &config) + { + int iReturn(0); + if (m_bHasCallbacks) + { + LibCECConfiguration ^netConfig = gcnew LibCECConfiguration(); + netConfig->Update(config); + iReturn = m_callbacks->ConfigurationChanged(netConfig); + } + return iReturn; + } + + int CecAlertManaged(const CEC::libcec_alert alert, const CEC::libcec_parameter &data) + { + int iReturn(0); + if (m_bHasCallbacks) + { + CecParameterType newType = (CecParameterType)data.paramType; + if (newType == CecParameterType::ParameterTypeString) + { + System::String ^ newData = gcnew System::String(data.paramData ? (const char *)data.paramData : "", 0, 128); + CecParameter ^ newParam = gcnew CecParameter(newType, newData); + iReturn = m_callbacks->ReceiveAlert((CecAlert)alert, newParam); + } + } + return iReturn; + } + + int CecMenuManaged(const CEC::cec_menu_state newVal) + { + int iReturn(0); + if (m_bHasCallbacks) + { + iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal); + } + return iReturn; + } + + void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress, const uint8_t bActivated) + { + if (m_bHasCallbacks) + m_callbacks->SourceActivated((CecLogicalAddress)logicalAddress, bActivated == 1); + } + + void DestroyDelegates() + { m_bHasCallbacks = false; - if (m_bDelegatesCreated) - { + if (m_bDelegatesCreated) + { m_bDelegatesCreated = false; - m_logMessageGCHandle.Free(); - m_keypressGCHandle.Free(); - m_commandGCHandle.Free(); - m_alertGCHandle.Free(); - m_menuGCHandle.Free(); - m_sourceActivatedGCHandle.Free(); - } - } + m_logMessageGCHandle.Free(); + m_keypressGCHandle.Free(); + m_commandGCHandle.Free(); + m_alertGCHandle.Free(); + m_menuGCHandle.Free(); + m_sourceActivatedGCHandle.Free(); + } + } void CreateDelegates() { @@ -1024,87 +2463,87 @@ namespace CecSharp // create the delegate method for the log message callback m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged); m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate); - m_logMessageCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer()); + m_logMessageCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer()); // create the delegate method for the keypress callback m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged); m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate); - m_keypressCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer()); + m_keypressCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer()); // create the delegate method for the command callback m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged); m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate); - m_commandCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer()); + m_commandCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer()); // create the delegate method for the configuration change callback m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged); m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate); - m_configCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer()); + m_configCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer()); // create the delegate method for the alert callback m_alertDelegate = gcnew CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged); m_alertGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate); - m_alertCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer()); + m_alertCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer()); // create the delegate method for the menu callback m_menuDelegate = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged); m_menuGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate); - m_menuCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer()); + m_menuCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer()); - // create the delegate method for the source activated callback + // create the delegate method for the source activated callback m_sourceActivatedDelegate = gcnew CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged); m_sourceActivatedGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate); - m_sourceActivatedCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate).ToPointer()); + m_sourceActivatedCallback = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate).ToPointer()); delete context; - UnmanagedCecCallbacks unmanagedCallbacks; - unmanagedCallbacks.logCB = m_logMessageCallback; - unmanagedCallbacks.keyCB = m_keypressCallback; - unmanagedCallbacks.commandCB = m_commandCallback; - unmanagedCallbacks.configCB = m_configCallback; - unmanagedCallbacks.alertCB = m_alertCallback; - unmanagedCallbacks.menuCB = m_menuCallback; - unmanagedCallbacks.sourceActivatedCB = m_sourceActivatedCallback; - - PLATFORM::CLockObject lock(g_callbackMutex); - g_unmanagedCallbacks.push_back(unmanagedCallbacks); - m_iCallbackPtr = g_unmanagedCallbacks.size() - 1; - m_bDelegatesCreated = true; + UnmanagedCecCallbacks unmanagedCallbacks; + unmanagedCallbacks.logCB = m_logMessageCallback; + unmanagedCallbacks.keyCB = m_keypressCallback; + unmanagedCallbacks.commandCB = m_commandCallback; + unmanagedCallbacks.configCB = m_configCallback; + unmanagedCallbacks.alertCB = m_alertCallback; + unmanagedCallbacks.menuCB = m_menuCallback; + unmanagedCallbacks.sourceActivatedCB = m_sourceActivatedCallback; + + PLATFORM::CLockObject lock(g_callbackMutex); + g_unmanagedCallbacks.push_back(unmanagedCallbacks); + m_iCallbackPtr = g_unmanagedCallbacks.size() - 1; + m_bDelegatesCreated = true; } } - CecLogMessageManagedDelegate ^ m_logMessageDelegate; - static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle; - LOGCB m_logMessageCallback; + CecLogMessageManagedDelegate ^ m_logMessageDelegate; + static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle; + LOGCB m_logMessageCallback; - CecKeyPressManagedDelegate ^ m_keypressDelegate; - static System::Runtime::InteropServices::GCHandle m_keypressGCHandle; - KEYCB m_keypressCallback; + CecKeyPressManagedDelegate ^ m_keypressDelegate; + static System::Runtime::InteropServices::GCHandle m_keypressGCHandle; + KEYCB m_keypressCallback; - CecCommandManagedDelegate ^ m_commandDelegate; - static System::Runtime::InteropServices::GCHandle m_commandGCHandle; - COMMANDCB m_commandCallback; + CecCommandManagedDelegate ^ m_commandDelegate; + static System::Runtime::InteropServices::GCHandle m_commandGCHandle; + COMMANDCB m_commandCallback; - CecConfigManagedDelegate ^ m_configDelegate; - static System::Runtime::InteropServices::GCHandle m_configGCHandle; - CONFIGCB m_configCallback; + CecConfigManagedDelegate ^ m_configDelegate; + static System::Runtime::InteropServices::GCHandle m_configGCHandle; + CONFIGCB m_configCallback; - CecAlertManagedDelegate ^ m_alertDelegate; - static System::Runtime::InteropServices::GCHandle m_alertGCHandle; - ALERTCB m_alertCallback; + CecAlertManagedDelegate ^ m_alertDelegate; + static System::Runtime::InteropServices::GCHandle m_alertGCHandle; + ALERTCB m_alertCallback; - CecMenuManagedDelegate ^ m_menuDelegate; - static System::Runtime::InteropServices::GCHandle m_menuGCHandle; - MENUCB m_menuCallback; + CecMenuManagedDelegate ^ m_menuDelegate; + static System::Runtime::InteropServices::GCHandle m_menuGCHandle; + MENUCB m_menuCallback; - CecSourceActivatedManagedDelegate ^ m_sourceActivatedDelegate; - static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle; - ACTICB m_sourceActivatedCallback; + CecSourceActivatedManagedDelegate ^ m_sourceActivatedDelegate; + static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle; + ACTICB m_sourceActivatedCallback; - CecCallbackMethods ^ m_callbacks; - bool m_bHasCallbacks; + CecCallbackMethods ^ m_callbacks; + bool m_bHasCallbacks; bool m_bDelegatesCreated; - size_t m_iCallbackPtr; - }; + size_t m_iCallbackPtr; + }; }