3 * This file is part of the libCEC(R) library.
5 * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
10 * This program is dual-licensed; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
28 * For more information contact:
29 * Pulse-Eight Licensing <license@pulse-eight.com>
30 * http://www.pulse-eight.com/
31 * http://www.pulse-eight.net/
34 #include "../lib/platform/threads/mutex.h"
36 #include <msclr/marshal.h>
37 #include "../../include/cec.h"
43 /// LibCecSharp namespace
45 /// <see cref="LibCecSharp" />
49 /// The device type. For client applications, libCEC only supports RecordingDevice, PlaybackDevice or Tuner.
50 /// libCEC uses RecordingDevice by default.
52 public enum class CecDeviceType
63 /// Reserved / do not use
75 /// Audio system / AVR
81 /// Log level that can be used by the logging callback method to filter messages from libCEC.
83 public enum class CecLogLevel
90 /// libCEC encountered a serious problem, and couldn't complete an action.
94 /// libCEC warns that it encountered a problem, but recovered.
98 /// libCEC informs the client about a CEC state change.
102 /// Raw CEC data traffic
106 /// Debugging messages
110 /// Display all messages
116 /// A logical address on the CEC bus
118 public enum class CecLogicalAddress
121 /// Not a valid logical address
129 /// Recording device 1
131 RecordingDevice1
= 1,
133 /// Recording device 2
135 RecordingDevice2
= 2,
141 /// Playback device 1
145 /// Audio system / AVR
157 /// Playback device 2
161 /// Recording device 3
163 RecordingDevice3
= 9,
169 /// Playback device 3
171 PlaybackDevice3
= 11,
173 /// Reserved address 1
177 /// Reserved address 2
185 /// Unregistered / new device
189 /// Broadcast address
195 /// The type of alert when libCEC calls the CecAlert callback
197 public enum class CecAlert
200 /// The device needs servicing. This is set when the firmware can be upgraded, or when a problem with the firmware is detected.
201 /// The latest firmware flash tool can be downloaded from http://packages.pulse-eight.net/
205 /// The connection to the adapter was lost, probably because the device got unplugged.
209 /// No permission from the OS to access the adapter.
213 /// The device is being used by another program.
217 /// The physical address that is assigned to the adapter is already being used.
219 PhysicalAddressError
,
221 /// The TV does not respond to polls.
227 /// The type of parameter that is sent with the CecAlert callback
229 public enum class CecParameterType
232 /// The parameter is a string
234 ParameterTypeString
= 1
238 /// A parameter for the CecAlert callback
240 public ref
class CecParameter
244 /// Create a new parameter
246 /// <param name="type">The type of this parameter.</param>
247 /// <param name="data">The value of this parameter.</param>
248 CecParameter(CecParameterType type
, System::String
^ data
)
255 /// The type of this parameter
257 property CecParameterType Type
;
259 /// The value of this parameter
261 property
System::String
^ Data
;
265 /// The power status of a CEC device
267 public enum class CecPowerStatus
278 /// In transition from standby to on
280 InTransitionStandbyToOn
= 0x02,
282 /// In transition from on to standby
284 InTransitionOnToStandby
= 0x03,
292 /// The CEC version of a CEC device
294 public enum class CecVersion
323 /// Parameter for OSD string display, that controls how to display the string
325 public enum class CecDisplayControl
328 /// Display for the default time
330 DisplayForDefaultTime
= 0x00,
332 /// Display until it is cleared by ClearPreviousMessage
334 DisplayUntilCleared
= 0x40,
336 /// Clear message displayed by DisplayUntilCleared
338 ClearPreviousMessage
= 0x80,
340 /// Reserved / do not use
342 ReservedForFutureUse
= 0xC0
346 /// The menu state of a CEC device
348 public enum class CecMenuState
361 /// Deck control mode for playback and recording devices
363 public enum class CecDeckControlMode
366 /// Skip forward / wind
370 /// Skip reverse / rewind
372 SkipReverseRewind
= 2,
384 /// Deck status for playback and recording devices
386 public enum class CecDeckInfo
401 /// Showing still frame
409 /// Playing slow reverse
421 /// No media detected
425 /// Stop / not playing
429 /// Skip forward / wind
431 SkipForwardWind
= 0x1B,
433 /// Skip reverse / rewind
435 SkipReverseRewind
= 0x1C,
437 /// Index search forward
439 IndexSearchForward
= 0x1D,
441 /// Index search reverse
443 IndexSearchReverse
= 0x1E,
445 /// Other / unknown status
451 /// User control code, the key code when the user presses or releases a button on the remote.
452 /// Used by SendKeypress() and the CecKey callback.
454 public enum class CecUserControlCode
477 /// Direction right + up
481 /// Direction right + down
485 /// Direction left + up
489 /// Direction left + down
579 PreviousChannel
= 0x32,
581 /// Select sound track
589 /// Display information
591 DisplayInformation
= 0x35,
605 /// Toggle powered on / standby
669 /// Toggle sub picture
673 /// Toggle video on demand
675 VideoOnDemand
= 0x52,
677 /// Toggle electronic program guide (EPG)
679 ElectronicProgramGuide
= 0x53,
681 /// Toggle timer programming
683 TimerProgramming
= 0x54,
685 /// Set initial configuration
687 InitialConfiguration
= 0x55,
689 /// Start playback function
693 /// Pause playback function
695 PausePlayFunction
= 0x61,
697 /// Toggle recording function
699 RecordFunction
= 0x62,
701 /// Pause recording function
703 PauseRecordFunction
= 0x63,
705 /// Stop playback function
709 /// Mute audio function
713 /// Restore volume function
715 RestoreVolumeFunction
= 0x66,
721 /// Select media function
723 SelectMediaFunction
= 0x68,
725 /// Select AV input function
727 SelectAVInputFunction
= 0x69,
729 /// Select audio input function
731 SelectAudioInputFunction
= 0x6A,
733 /// Toggle powered on / standby function
735 PowerToggleFunction
= 0x6B,
737 /// Power off function
739 PowerOffFunction
= 0x6C,
741 /// Power on function
743 PowerOnFunction
= 0x6D,
753 /// F3 / green button
757 /// F4 / yellow button
769 /// Max. valid key code for standard buttons
773 /// Extra return button on Samsung remotes
775 SamsungReturn
= 0x91,
777 /// Unknown / invalid key code
783 /// Vendor IDs for CEC devices
785 public enum class CecVendorId
795 PulseEight
= 0x001582,
796 HarmanKardon2
= 0x001950,
799 Panasonic
= 0x008045,
811 HarmanKardon
= 0x9C645E,
816 /// Audio status of audio system / AVR devices
818 public enum class CecAudioStatus
823 MuteStatusMask
= 0x80,
825 /// Not muted, volume status mask
827 VolumeStatusMask
= 0x7F,
839 VolumeStatusUnknown
= 0x7F
843 /// CEC opcodes, as described in the HDMI CEC specification
845 public enum class CecOpcode
852 /// Image view on: power on display for image display
856 /// Text view on: power on display for text display
860 /// Device no longer is the active source
862 InactiveSource
= 0x9D,
864 /// Request which device has the active source status
866 RequestActiveSource
= 0x85,
868 /// Routing change for HDMI switches
870 RoutingChange
= 0x80,
872 /// Routing information for HDMI switches
874 RoutingInformation
= 0x81,
876 /// Change the stream path to the given physical address
878 SetStreamPath
= 0x86,
880 /// Inform that a device went into standby mode
892 /// Recording status information
896 /// Record current display
898 RecordTvScreen
= 0x0F,
900 /// Clear analogue timer
902 ClearAnalogueTimer
= 0x33,
904 /// Clear digital timer
906 ClearDigitalTimer
= 0x99,
908 /// Clear external timer
910 ClearExternalTimer
= 0xA1,
912 /// Set analogue timer
914 SetAnalogueTimer
= 0x34,
916 /// Set digital timer
918 SetDigitalTimer
= 0x97,
920 /// Set external timer
922 SetExternalTimer
= 0xA2,
924 /// Set program title of a timer
926 SetTimerProgramTitle
= 0x67,
928 /// Timer status cleared
930 TimerClearedStatus
= 0x43,
932 /// Timer status information
936 /// CEC version used by a device
940 /// Request CEC version of a device
942 GetCecVersion
= 0x9F,
944 /// Request physical address of a device
946 GivePhysicalAddress
= 0x83,
948 /// Request language code of the menu language of a device
949 /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/
951 GetMenuLanguage
= 0x91,
953 /// Report the physical address
955 ReportPhysicalAddress
= 0x84,
957 /// Report the language code of the menu language
958 /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/
960 SetMenuLanguage
= 0x32,
962 /// Deck control for playback and recording devices
966 /// Deck status for playback and recording devices
970 /// Request deck status from playback and recording devices
972 GiveDeckStatus
= 0x1A,
974 /// Start playback on playback and recording devices
978 /// Request tuner status
980 GiveTunerDeviceStatus
= 0x08,
982 /// Select analogue service on a tuner
984 SelectAnalogueService
= 0x92,
986 /// Select digital service on a tuner
988 SelectDigtalService
= 0x93,
990 /// Report tuner device status
992 TunerDeviceStatus
= 0x07,
994 /// Tuner step decrement
996 TunerStepDecrement
= 0x06,
998 /// Tuner step increment
1000 TunerStepIncrement
= 0x05,
1002 /// Report device vendor ID
1004 DeviceVendorId
= 0x87,
1006 /// Request device vendor ID
1008 GiveDeviceVendorId
= 0x8C,
1010 /// Vendor specific command
1012 VendorCommand
= 0x89,
1014 /// Vendor specific command with vendor ID
1016 VendorCommandWithId
= 0xA0,
1018 /// Vendor specific remote button pressed
1020 VendorRemoteButtonDown
= 0x8A,
1022 /// Vendor specific remote button released
1024 VendorRemoteButtonUp
= 0x8B,
1026 /// Display / clear OSD string
1028 SetOsdString
= 0x64,
1030 /// Request device OSD name
1034 /// Report device OSD name
1038 /// Request device menu status
1042 /// Report device menu status
1046 /// Remote button pressed
1048 UserControlPressed
= 0x44,
1050 /// Remote button released
1052 UserControlRelease
= 0x45,
1054 /// Request device power status
1056 GiveDevicePowerStatus
= 0x8F,
1058 /// Report device power status
1060 ReportPowerStatus
= 0x90,
1062 /// Feature abort / unsupported command
1064 FeatureAbort
= 0x00,
1070 /// Give audio status
1072 GiveAudioStatus
= 0x71,
1074 /// Give audiosystem mode
1076 GiveSystemAudioMode
= 0x7D,
1078 /// Report device audio status
1080 ReportAudioStatus
= 0x7A,
1082 /// Set audiosystem mode
1084 SetSystemAudioMode
= 0x72,
1086 /// Request audiosystem mode
1088 SystemAudioModeRequest
= 0x70,
1090 /// Report audiosystem mode
1092 SystemAudioModeStatus
= 0x7E,
1094 /// Set audio bitrate
1096 SetAudioRate
= 0x9A,
1098 /// When this opcode is set, no opcode will be sent to the device / poll message
1099 /// This is one of the reserved numbers
1105 /// Audiosystem status
1107 public enum class CecSystemAudioStatus
1120 /// libCEC client application version
1122 public enum class CecClientVersion
1131 Version1_5_0
= 0x1500,
1135 Version1_5_1
= 0x1501,
1139 Version1_5_2
= 0x1502,
1143 Version1_5_3
= 0x1503,
1147 Version1_6_0
= 0x1600,
1151 Version1_6_1
= 0x1601,
1155 Version1_6_2
= 0x1602,
1159 Version1_6_3
= 0x1603,
1163 Version1_7_0
= 0x1700,
1167 Version1_7_1
= 0x1701,
1171 Version1_7_2
= 0x1702,
1175 Version1_8_0
= 0x1800,
1179 Version1_8_1
= 0x1801,
1183 Version1_8_2
= 0x1802,
1187 Version1_9_0
= 0x1900,
1191 Version1_99_0
= 0x1990,
1195 Version2_0_0
= 0x2000,
1199 Version2_0_1
= 0x2001,
1203 Version2_0_2
= 0x2002,
1207 Version2_0_3
= 0x2003,
1211 Version2_0_4
= 0x2004,
1215 Version2_0_5
= 0x2005,
1219 Version2_1_0
= 0x2100,
1223 Version2_1_1
= 0x2101,
1227 Version2_1_2
= 0x2102,
1231 Version2_1_3
= 0x2103,
1235 Version2_1_4
= 0x2104,
1239 Version2_2_0
= 0x2200,
1241 /// The current version
1243 CurrentVersion
= 0x2200
1249 public enum class CecServerVersion
1258 Version1_5_0
= 0x1500,
1262 Version1_5_1
= 0x1501,
1266 Version1_5_2
= 0x1502,
1270 Version1_5_3
= 0x1503,
1274 Version1_6_0
= 0x1600,
1278 Version1_6_1
= 0x1601,
1282 Version1_6_2
= 0x1602,
1286 Version1_6_3
= 0x1603,
1290 Version1_7_0
= 0x1700,
1294 Version1_7_1
= 0x1701,
1298 Version1_7_2
= 0x1702,
1302 Version1_8_0
= 0x1800,
1306 Version1_8_1
= 0x1801,
1310 Version1_8_2
= 0x1802,
1314 Version1_9_0
= 0x1900,
1318 Version1_99_0
= 0x1990,
1322 Version2_0_0
= 0x2000,
1326 Version2_0_1
= 0x2001,
1330 Version2_0_2
= 0x2002,
1334 Version2_0_3
= 0x2003,
1338 Version2_0_4
= 0x2004,
1342 Version2_0_5
= 0x2005,
1346 Version2_1_0
= 0x2100,
1350 Version2_1_1
= 0x2101,
1354 Version2_1_2
= 0x2102,
1358 Version2_1_3
= 0x2103,
1362 Version2_1_4
= 0x2104,
1366 Version2_2_0
= 0x2200,
1368 /// The current version
1370 CurrentVersion
= 0x2200
1374 /// Type of adapter to which libCEC is connected
1376 public enum class CecAdapterType
1379 /// Unknown adapter type
1383 /// Pulse-Eight USB-CEC adapter
1385 PulseEightExternal
= 0x1,
1387 /// Pulse-Eight CEC daughterboard
1389 PulseEightDaughterboard
= 0x2,
1393 RaspberryPi
= 0x100,
1401 /// Descriptor of a CEC adapter, returned when scanning for adapters that are connected to the system
1403 public ref
class CecAdapter
1407 /// Create a new CEC adapter descriptor
1409 /// <param name="path"> The path descriptor for this CEC adapter</param>
1410 /// <param name="comPort">The COM port of this CEC adapter</param>
1411 CecAdapter(System::String
^ path
, System::String
^ comPort
)
1418 /// The path descriptor for this CEC adapter
1420 property
System::String
^ Path
;
1423 /// The COM port of this CEC adapter
1425 property
System::String
^ ComPort
;
1429 /// A list of CEC device types
1431 public ref
class CecDeviceTypeList
1435 /// Create a new empty list of CEC device types
1437 CecDeviceTypeList(void)
1439 Types
= gcnew array
<CecDeviceType
>(5);
1440 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
1441 Types
[iPtr
] = CecDeviceType::Reserved
;
1445 /// The array with CecDeviceType instances in this list.
1447 property array
<CecDeviceType
> ^ Types
;
1451 /// A list of logical addresses
1453 public ref
class CecLogicalAddresses
1457 /// Create a new empty list of logical addresses
1459 CecLogicalAddresses(void)
1461 Addresses
= gcnew array
<CecLogicalAddress
>(16);
1466 /// Clears this list
1470 Primary
= CecLogicalAddress::Unknown
;
1471 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
1472 Addresses
[iPtr
] = CecLogicalAddress::Unknown
;
1476 /// Checks whether a logical address is set in this list.
1478 /// <param name="address">The address to check.</param>
1479 /// <returns>True when set, false otherwise</returns>
1480 bool IsSet(CecLogicalAddress address
)
1482 return Addresses
[(unsigned int)address
] != CecLogicalAddress::Unknown
;
1486 /// Add a logical address to this list (if it's not set already)
1488 /// <param name="address">The address to add.</param>
1489 void Set(CecLogicalAddress address
)
1491 Addresses
[(unsigned int)address
] = address
;
1492 if (Primary
== CecLogicalAddress::Unknown
)
1497 /// The primary (first) address in this list
1499 property CecLogicalAddress Primary
;
1502 /// The list of addresses
1504 property array
<CecLogicalAddress
> ^ Addresses
;
1509 /// Byte array used for CEC command parameters
1511 public ref
class CecDatapacket
1515 /// Create a new byte array with maximum size 100
1519 Data
= gcnew array
<uint8_t>(100);
1524 /// Adds a byte to this byte array
1526 /// <param name="data">The byte to add.</param>
1527 void PushBack(uint8_t data
)
1539 property array
<uint8_t> ^ Data
;
1542 /// Current data size
1544 property
uint8_t Size
;
1548 /// A CEC command that is received or transmitted over the CEC bus
1550 public ref
class CecCommand
1554 /// Create a new CEC command instance
1556 /// <param name="initiator">The initiator of the command</param>
1557 /// <param name="destination">The receiver of the command</param>
1558 /// <param name="ack">True when the ack bit is set, false otherwise</param>
1559 /// <param name="eom">True when the eom bit is set, false otherwise</param>
1560 /// <param name="opcode">The CEC opcode of this command</param>
1561 /// <param name="transmitTimeout">The timeout to use when transmitting a command</param>
1562 CecCommand(CecLogicalAddress initiator
, CecLogicalAddress destination
, bool ack
, bool eom
, CecOpcode opcode
, int32_t transmitTimeout
)
1564 Initiator
= initiator
;
1565 Destination
= destination
;
1570 TransmitTimeout
= transmitTimeout
;
1571 Parameters
= gcnew CecDatapacket
;
1576 /// Create a new empty CEC command instance
1580 Initiator
= CecLogicalAddress::Unknown
;
1581 Destination
= CecLogicalAddress::Unknown
;
1584 Opcode
= CecOpcode::None
;
1586 TransmitTimeout
= 0;
1587 Parameters
= gcnew CecDatapacket
;
1592 /// Pushes a byte of data to this CEC command
1594 /// <param name="data">The byte to add</param>
1595 void PushBack(uint8_t data
)
1597 if (Initiator
== CecLogicalAddress::Unknown
&& Destination
== CecLogicalAddress::Unknown
)
1599 Initiator
= (CecLogicalAddress
) (data
>> 4);
1600 Destination
= (CecLogicalAddress
) (data
& 0xF);
1602 else if (!OpcodeSet
)
1605 Opcode
= (CecOpcode
)data
;
1609 Parameters
->PushBack(data
);
1614 /// True when this command is empty, false otherwise.
1616 property
bool Empty
;
1618 /// The initiator of the command
1620 property CecLogicalAddress Initiator
;
1622 /// The destination of the command
1624 property CecLogicalAddress Destination
;
1626 /// True when the ack bit is set, false otherwise
1630 /// True when the eom bit is set, false otherwise
1634 /// The CEC opcode of the command
1636 property CecOpcode Opcode
;
1638 /// The parameters of this command
1640 property CecDatapacket
^ Parameters
;
1642 /// True when an opcode is set, false otherwise (poll message)
1644 property
bool OpcodeSet
;
1646 /// The timeout to use when transmitting a command
1648 property
int32_t TransmitTimeout
;
1652 /// A key press that was received
1654 public ref
class CecKeypress
1658 /// Create a new key press instance
1660 /// <param name="keycode">The key code of this key press</param>
1661 /// <param name="duration">The duration of this key press in milliseconds</param>
1662 CecKeypress(CecUserControlCode keycode
, unsigned int duration
)
1665 Duration
= duration
;
1670 /// Create a new empty key press instance
1674 Keycode
= CecUserControlCode::Unknown
;
1680 /// True when empty, false otherwise
1682 property
bool Empty
;
1684 /// The key code of this key press
1686 property CecUserControlCode Keycode
;
1688 /// The duration of this key press in milliseconds
1690 property
unsigned int Duration
;
1694 /// A log message that libCEC generated
1696 public ref
class CecLogMessage
1700 /// Create a new log message
1702 /// <param name="message">The actual message</param>
1703 /// <param name="level">The log level, so the application can choose what type information to display</param>
1704 /// <param name="time">The timestamp of this message, in milliseconds after connecting</param>
1705 CecLogMessage(System::String
^ message
, CecLogLevel level
, int64_t time
)
1714 /// Create a new empty log message
1719 Level
= CecLogLevel::None
;
1725 /// True when empty, false otherwise.
1727 property
bool Empty
;
1729 /// The actual message
1731 property
System::String
^Message
;
1733 /// The log level, so the application can choose what type information to display
1735 property CecLogLevel Level
;
1737 /// The timestamp of this message, in milliseconds after connecting
1739 property
int64_t Time
;
1742 ref
class CecCallbackMethods
; //forward declaration
1745 /// The configuration that libCEC uses.
1747 public ref
class LibCECConfiguration
1751 /// Create a new configuration instance with default settings.
1753 LibCECConfiguration(void)
1756 DeviceTypes
= gcnew
CecDeviceTypeList();
1757 AutodetectAddress
= true;
1758 PhysicalAddress
= CEC_DEFAULT_PHYSICAL_ADDRESS
;
1759 BaseDevice
= (CecLogicalAddress
)CEC_DEFAULT_BASE_DEVICE
;
1760 HDMIPort
= CEC_DEFAULT_HDMI_PORT
;
1761 ClientVersion
= CecClientVersion::CurrentVersion
;
1762 ServerVersion
= CecServerVersion::CurrentVersion
;
1763 TvVendor
= CecVendorId::Unknown
;
1765 GetSettingsFromROM
= false;
1766 UseTVMenuLanguage
= CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE
== 1;
1767 ActivateSource
= CEC_DEFAULT_SETTING_ACTIVATE_SOURCE
== 1;
1769 WakeDevices
= gcnew
CecLogicalAddresses();
1770 if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE
== 1)
1771 WakeDevices
->Set(CecLogicalAddress::Tv
);
1773 PowerOffDevices
= gcnew
CecLogicalAddresses();
1774 if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN
== 1)
1775 PowerOffDevices
->Set(CecLogicalAddress::Broadcast
);
1777 PowerOffScreensaver
= CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER
== 1;
1778 PowerOffOnStandby
= CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY
== 1;
1780 SendInactiveSource
= CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE
== 1;
1781 LogicalAddresses
= gcnew
CecLogicalAddresses();
1782 FirmwareVersion
= 1;
1783 PowerOffDevicesOnStandby
= CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY
== 1;
1784 ShutdownOnStandby
= CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY
== 1;
1785 DeviceLanguage
= "";
1786 FirmwareBuildDate
= gcnew
System::DateTime(1970,1,1,0,0,0,0);
1787 CECVersion
= (CecVersion
)CEC_DEFAULT_SETTING_CEC_VERSION
;
1788 AdapterType
= CecAdapterType::Unknown
;
1792 /// Change the callback method pointers in this configuration instance.
1794 /// <param name="callbacks">The new callbacks</param>
1795 void SetCallbacks(CecCallbackMethods
^callbacks
)
1797 Callbacks
= callbacks
;
1801 /// Update this configuration with data received from libCEC
1803 /// <param name="config">The configuration that was received from libCEC</param>
1804 void Update(const CEC::libcec_configuration
&config
)
1806 DeviceName
= gcnew
System::String(config
.strDeviceName
);
1808 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
1809 DeviceTypes
->Types
[iPtr
] = (CecDeviceType
)config
.deviceTypes
.types
[iPtr
];
1811 AutodetectAddress
= config
.bAutodetectAddress
== 1;
1812 PhysicalAddress
= config
.iPhysicalAddress
;
1813 BaseDevice
= (CecLogicalAddress
)config
.baseDevice
;
1814 HDMIPort
= config
.iHDMIPort
;
1815 ClientVersion
= (CecClientVersion
)config
.clientVersion
;
1816 ServerVersion
= (CecServerVersion
)config
.serverVersion
;
1817 TvVendor
= (CecVendorId
)config
.tvVendor
;
1819 // player specific settings
1820 GetSettingsFromROM
= config
.bGetSettingsFromROM
== 1;
1821 UseTVMenuLanguage
= config
.bUseTVMenuLanguage
== 1;
1822 ActivateSource
= config
.bActivateSource
== 1;
1824 WakeDevices
->Clear();
1825 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
1826 if (config
.wakeDevices
[iPtr
])
1827 WakeDevices
->Set((CecLogicalAddress
)iPtr
);
1829 PowerOffDevices
->Clear();
1830 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
1831 if (config
.powerOffDevices
[iPtr
])
1832 PowerOffDevices
->Set((CecLogicalAddress
)iPtr
);
1834 PowerOffScreensaver
= config
.bPowerOffScreensaver
== 1;
1835 PowerOffOnStandby
= config
.bPowerOffOnStandby
== 1;
1837 if (ServerVersion
>= CecServerVersion::Version1_5_1
)
1838 SendInactiveSource
= config
.bSendInactiveSource
== 1;
1840 if (ServerVersion
>= CecServerVersion::Version1_5_3
)
1842 LogicalAddresses
->Clear();
1843 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
1844 if (config
.logicalAddresses
[iPtr
])
1845 LogicalAddresses
->Set((CecLogicalAddress
)iPtr
);
1848 if (ServerVersion
>= CecServerVersion::Version1_6_0
)
1850 FirmwareVersion
= config
.iFirmwareVersion
;
1851 PowerOffDevicesOnStandby
= config
.bPowerOffDevicesOnStandby
== 1;
1852 ShutdownOnStandby
= config
.bShutdownOnStandby
== 1;
1855 if (ServerVersion
>= CecServerVersion::Version1_6_2
)
1857 DeviceLanguage
= gcnew
System::String(config
.strDeviceLanguage
);
1858 FirmwareBuildDate
= gcnew
System::DateTime(1970,1,1,0,0,0,0);
1859 FirmwareBuildDate
= FirmwareBuildDate
->AddSeconds(config
.iFirmwareBuildDate
);
1862 if (ServerVersion
>= CecServerVersion::Version1_6_3
)
1863 MonitorOnlyClient
= config
.bMonitorOnly
== 1;
1865 if (ServerVersion
>= CecServerVersion::Version1_8_0
)
1866 CECVersion
= (CecVersion
)config
.cecVersion
;
1868 if (ServerVersion
>= CecServerVersion::Version1_8_2
)
1869 AdapterType
= (CecAdapterType
)config
.adapterType
;
1871 if (ServerVersion
>= CecServerVersion::Version2_1_0
)
1872 PowerOnScreensaver
= config
.bPowerOnScreensaver
== 1;
1876 /// The device name to use on the CEC bus
1878 property
System::String
^ DeviceName
;
1881 /// The device type(s) to use on the CEC bus for libCEC
1883 property CecDeviceTypeList
^ DeviceTypes
;
1886 /// (read only) set to true by libCEC when the physical address was autodetected
1888 property
bool AutodetectAddress
;
1891 /// The physical address of the CEC adapter
1893 property
uint16_t PhysicalAddress
;
1896 /// 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
1898 property CecLogicalAddress BaseDevice
;
1901 /// The HDMI port to which the adapter is connected. Only used when iPhysicalAddress = 0 or when the adapter doesn't support autodetection
1903 property
uint8_t HDMIPort
;
1906 /// The client API version to use
1908 property CecClientVersion ClientVersion
;
1911 /// The version of libCEC
1913 property CecServerVersion ServerVersion
;
1916 /// Override the vendor ID of the TV. Leave this untouched to autodetect
1918 property CecVendorId TvVendor
;
1921 /// True to read the settings from the EEPROM, which possibly override the settings passed here
1923 property
bool GetSettingsFromROM
;
1926 /// Use the language setting of the TV in the client application. Must be implemented by the client application.
1927 /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/
1929 property
bool UseTVMenuLanguage
;
1932 /// Make libCEC the active source when starting the client application
1934 property
bool ActivateSource
;
1937 /// List of devices to wake when initialising libCEC or when calling PowerOnDevices() without any parameter.
1939 property CecLogicalAddresses
^WakeDevices
;
1942 /// List of devices to power off when calling StandbyDevices() without any parameter.
1944 property CecLogicalAddresses
^PowerOffDevices
;
1947 /// Send standby commands when the client application activates the screensaver. Must be implemented by the client application.
1949 property
bool PowerOffScreensaver
;
1952 /// Power off the PC when the TV powers off. Must be implemented by the client application.
1954 property
bool PowerOffOnStandby
;
1957 /// Send an inactive source message when exiting the client application.
1959 property
bool SendInactiveSource
;
1962 /// The list of logical addresses that libCEC is using
1964 property CecLogicalAddresses
^LogicalAddresses
;
1967 /// The firmware version of the adapter to which libCEC is connected
1969 property
uint16_t FirmwareVersion
;
1972 /// Send standby commands when the client application activates standby mode (S3). Must be implemented by the client application.
1974 property
bool PowerOffDevicesOnStandby
;
1977 /// Shutdown this PC when the TV is switched off. only used when PowerOffOnStandby = false
1979 property
bool ShutdownOnStandby
;
1982 /// True to start a monitor-only client, false to start a standard client.
1984 property
bool MonitorOnlyClient
;
1987 /// The language code of the menu language that libCEC reports to other devices.
1988 /// 3 character ISO 639-2 country code. see http://http://www.loc.gov/standards/iso639-2/
1990 property
System::String
^ DeviceLanguage
;
1993 /// The callback methods to use.
1995 property CecCallbackMethods
^ Callbacks
;
1998 /// The build date of the firmware.
2000 property
System::DateTime
^ FirmwareBuildDate
;
2003 /// The CEC version that libCEC uses.
2005 property CecVersion CECVersion
;
2008 /// The type of adapter that libCEC is connected to.
2010 property CecAdapterType AdapterType
;
2013 /// True to power on when quitting the screensaver.
2015 property
bool PowerOnScreensaver
;
2018 // the callback methods are called by unmanaged code, so we need some delegates for this
2020 // unmanaged callback methods
2021 typedef int (__stdcall
*LOGCB
) (const CEC::cec_log_message
&message
);
2022 typedef int (__stdcall
*KEYCB
) (const CEC::cec_keypress
&key
);
2023 typedef int (__stdcall
*COMMANDCB
)(const CEC::cec_command
&command
);
2024 typedef int (__stdcall
*CONFIGCB
) (const CEC::libcec_configuration
&config
);
2025 typedef int (__stdcall
*ALERTCB
) (const CEC::libcec_alert
, const CEC::libcec_parameter
&data
);
2026 typedef int (__stdcall
*MENUCB
) (const CEC::cec_menu_state newVal
);
2027 typedef void (__stdcall
*ACTICB
) (const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
);
2030 /// libCEC callback methods. Unmanaged code.
2035 /// Log message callback
2039 /// Key press/release callback
2043 /// Raw CEC data callback
2045 COMMANDCB commandCB
;
2047 /// Updated configuration callback
2051 /// Alert message callback
2055 /// Menu status change callback
2059 /// Source (de)activated callback
2061 ACTICB sourceActivatedCB
;
2062 } UnmanagedCecCallbacks
;
2064 static PLATFORM::CMutex g_callbackMutex
;
2065 static std::vector
<UnmanagedCecCallbacks
> g_unmanagedCallbacks
;
2066 static CEC::ICECCallbacks g_cecCallbacks
;
2069 /// Called by libCEC to send back a log message to the application
2071 /// <param name="cbParam">Pointer to the callback struct</param>
2072 /// <param name="message">The log message</param>
2073 /// <return>1 when handled, 0 otherwise</return>
2074 int CecLogMessageCB(void *cbParam
, const CEC::cec_log_message message
)
2078 size_t iPtr
= (size_t)cbParam
;
2079 PLATFORM::CLockObject
lock(g_callbackMutex
);
2080 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
2081 return g_unmanagedCallbacks
[iPtr
].logCB(message
);
2087 /// Called by libCEC to send back a key press or release to the application
2089 /// <param name="cbParam">Pointer to the callback struct</param>
2090 /// <param name="key">The key press command that libCEC received</param>
2091 /// <return>1 when handled, 0 otherwise</return>
2092 int CecKeyPressCB(void *cbParam
, const CEC::cec_keypress key
)
2096 size_t iPtr
= (size_t)cbParam
;
2097 PLATFORM::CLockObject
lock(g_callbackMutex
);
2098 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
2099 return g_unmanagedCallbacks
[iPtr
].keyCB(key
);
2105 /// Called by libCEC to send back raw CEC data to the application
2107 /// <param name="cbParam">Pointer to the callback struct</param>
2108 /// <param name="command">The raw CEC data</param>
2109 /// <return>1 when handled, 0 otherwise</return>
2110 int CecCommandCB(void *cbParam
, const CEC::cec_command command
)
2114 size_t iPtr
= (size_t)cbParam
;
2115 PLATFORM::CLockObject
lock(g_callbackMutex
);
2116 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
2117 return g_unmanagedCallbacks
[iPtr
].commandCB(command
);
2123 /// Called by libCEC to send back an updated configuration to the application
2125 /// <param name="cbParam">Pointer to the callback struct</param>
2126 /// <param name="config">The new configuration</param>
2127 /// <return>1 when handled, 0 otherwise</return>
2128 int CecConfigCB(void *cbParam
, const CEC::libcec_configuration config
)
2132 size_t iPtr
= (size_t)cbParam
;
2133 PLATFORM::CLockObject
lock(g_callbackMutex
);
2134 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
2135 return g_unmanagedCallbacks
[iPtr
].configCB(config
);
2141 /// Called by libCEC to send back an alert message to the application
2143 /// <param name="cbParam">Pointer to the callback struct</param>
2144 /// <param name="data">The alert message</param>
2145 /// <return>1 when handled, 0 otherwise</return>
2146 int CecAlertCB(void *cbParam
, const CEC::libcec_alert alert
, const CEC::libcec_parameter data
)
2150 size_t iPtr
= (size_t)cbParam
;
2151 PLATFORM::CLockObject
lock(g_callbackMutex
);
2152 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
2153 return g_unmanagedCallbacks
[iPtr
].alertCB(alert
, data
);
2159 /// Called by libCEC to send back a menu state change to the application
2161 /// <param name="cbParam">Pointer to the callback struct</param>
2162 /// <param name="newVal">The new menu state</param>
2163 /// <return>1 when handled, 0 otherwise</return>
2164 int CecMenuCB(void *cbParam
, const CEC::cec_menu_state newVal
)
2168 size_t iPtr
= (size_t)cbParam
;
2169 PLATFORM::CLockObject
lock(g_callbackMutex
);
2170 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
2171 return g_unmanagedCallbacks
[iPtr
].menuCB(newVal
);
2177 /// Called by libCEC to notify the application that the source that is handled by libCEC was (de)activated
2179 /// <param name="cbParam">Pointer to the callback struct</param>
2180 /// <param name="logicalAddress">The logical address that was (de)activated</param>
2181 /// <param name="activated">True when activated, false when deactivated</param>
2182 void CecSourceActivatedCB(void *cbParam
, const CEC::cec_logical_address logicalAddress
, const uint8_t activated
)
2186 size_t iPtr
= (size_t)cbParam
;
2187 PLATFORM::CLockObject
lock(g_callbackMutex
);
2188 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
2189 g_unmanagedCallbacks
[iPtr
].sourceActivatedCB(logicalAddress
, activated
);
2195 /// Delegate method for the CecLogMessageCB callback in CecCallbackMethods
2197 public delegate
int CecLogMessageManagedDelegate(const CEC::cec_log_message
&);
2199 /// Delegate method for the CecKeyPressCB callback in CecCallbackMethods
2201 public delegate
int CecKeyPressManagedDelegate(const CEC::cec_keypress
&);
2203 /// Delegate method for the CecCommandCB callback in CecCallbackMethods
2205 public delegate
int CecCommandManagedDelegate(const CEC::cec_command
&);
2207 /// Delegate method for the CecConfigCB callback in CecCallbackMethods
2209 public delegate
int CecConfigManagedDelegate(const CEC::libcec_configuration
&);
2211 /// Delegate method for the CecAlertCB callback in CecCallbackMethods
2213 public delegate
int CecAlertManagedDelegate(const CEC::libcec_alert
, const CEC::libcec_parameter
&);
2215 /// Delegate method for the CecMenuCB callback in CecCallbackMethods
2217 public delegate
int CecMenuManagedDelegate(const CEC::cec_menu_state
);
2219 /// Delegate method for the CecSourceActivatedCB callback in CecCallbackMethods
2221 public delegate
void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address
, const uint8_t);
2224 /// Assign the callback methods in the g_cecCallbacks struct
2226 void AssignCallbacks()
2228 g_cecCallbacks
.CBCecLogMessage
= CecLogMessageCB
;
2229 g_cecCallbacks
.CBCecKeyPress
= CecKeyPressCB
;
2230 g_cecCallbacks
.CBCecCommand
= CecCommandCB
;
2231 g_cecCallbacks
.CBCecConfigurationChanged
= CecConfigCB
;
2232 g_cecCallbacks
.CBCecAlert
= CecAlertCB
;
2233 g_cecCallbacks
.CBCecMenuStateChanged
= CecMenuCB
;
2234 g_cecCallbacks
.CBCecSourceActivated
= CecSourceActivatedCB
;
2238 /// The callback methods that libCEC uses
2240 public ref
class CecCallbackMethods
2243 CecCallbackMethods(void)
2245 m_iCallbackPtr
= -1;
2247 m_bHasCallbacks
= false;
2248 m_bDelegatesCreated
= false;
2251 ~CecCallbackMethods(void)
2257 /// Pointer to the callbacks struct entry
2259 size_t GetCallbackPtr(void)
2261 PLATFORM::CLockObject
lock(g_callbackMutex
);
2262 return m_iCallbackPtr
;
2266 !CecCallbackMethods(void)
2273 /// Disable callback methods
2275 virtual void DisableCallbacks(void)
2281 /// Enable callback methods
2283 /// <param name="callbacks">Callback methods to activate</param>
2284 /// <return>true when handled, false otherwise</return>
2285 virtual bool EnableCallbacks(CecCallbackMethods
^ callbacks
)
2288 if (!m_bHasCallbacks
)
2290 m_bHasCallbacks
= true;
2291 m_callbacks
= callbacks
;
2299 /// Called by libCEC to send back a log message to the application.
2300 /// Override in the application to handle this callback.
2302 /// <param name="message">The log message</param>
2303 /// <return>1 when handled, 0 otherwise</return>
2304 virtual int ReceiveLogMessage(CecLogMessage
^ message
)
2310 /// Called by libCEC to send back a key press or release to the application.
2311 /// Override in the application to handle this callback.
2313 /// <param name="key">The key press command that libCEC received</param>
2314 /// <return>1 when handled, 0 otherwise</return>
2315 virtual int ReceiveKeypress(CecKeypress
^ key
)
2321 /// Called by libCEC to send back raw CEC data to the application.
2322 /// Override in the application to handle this callback.
2324 /// <param name="command">The raw CEC data</param>
2325 /// <return>1 when handled, 0 otherwise</return>
2326 virtual int ReceiveCommand(CecCommand
^ command
)
2332 /// Called by libCEC to send back an updated configuration to the application.
2333 /// Override in the application to handle this callback.
2335 /// <param name="config">The new configuration</param>
2336 /// <return>1 when handled, 0 otherwise</return>
2337 virtual int ConfigurationChanged(LibCECConfiguration
^ config
)
2343 /// Called by libCEC to send back an alert message to the application.
2344 /// Override in the application to handle this callback.
2346 /// <param name="data">The alert message</param>
2347 /// <return>1 when handled, 0 otherwise</return>
2348 virtual int ReceiveAlert(CecAlert alert
, CecParameter
^ data
)
2354 /// Called by libCEC to send back a menu state change to the application.
2355 /// Override in the application to handle this callback.
2357 /// <param name="newVal">The new menu state</param>
2358 /// <return>1 when handled, 0 otherwise</return>
2359 virtual int ReceiveMenuStateChange(CecMenuState newVal
)
2365 /// Called by libCEC to notify the application that the source that is handled by libCEC was (de)activated.
2366 /// Override in the application to handle this callback.
2368 /// <param name="logicalAddress">The logical address that was (de)activated</param>
2369 /// <param name="activated">True when activated, false when deactivated</param>
2370 virtual void SourceActivated(CecLogicalAddress logicalAddress
, bool activated
)
2375 // managed callback methods
2376 int CecLogMessageManaged(const CEC::cec_log_message
&message
)
2379 if (m_bHasCallbacks
)
2380 iReturn
= m_callbacks
->ReceiveLogMessage(gcnew
CecLogMessage(gcnew
System::String(message
.message
), (CecLogLevel
)message
.level
, message
.time
));
2384 int CecKeyPressManaged(const CEC::cec_keypress
&key
)
2387 if (m_bHasCallbacks
)
2388 iReturn
= m_callbacks
->ReceiveKeypress(gcnew
CecKeypress((CecUserControlCode
)key
.keycode
, key
.duration
));
2392 int CecCommandManaged(const CEC::cec_command
&command
)
2395 if (m_bHasCallbacks
)
2397 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
);
2398 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
2399 newCommand
->Parameters
->PushBack(command
.parameters
[iPtr
]);
2400 iReturn
= m_callbacks
->ReceiveCommand(newCommand
);
2405 int CecConfigManaged(const CEC::libcec_configuration
&config
)
2408 if (m_bHasCallbacks
)
2410 LibCECConfiguration
^netConfig
= gcnew
LibCECConfiguration();
2411 netConfig
->Update(config
);
2412 iReturn
= m_callbacks
->ConfigurationChanged(netConfig
);
2417 int CecAlertManaged(const CEC::libcec_alert alert
, const CEC::libcec_parameter
&data
)
2420 if (m_bHasCallbacks
)
2422 CecParameterType newType
= (CecParameterType
)data
.paramType
;
2423 if (newType
== CecParameterType::ParameterTypeString
)
2425 System::String
^ newData
= gcnew
System::String(data
.paramData
? (const char *)data
.paramData
: "", 0, 128);
2426 CecParameter
^ newParam
= gcnew
CecParameter(newType
, newData
);
2427 iReturn
= m_callbacks
->ReceiveAlert((CecAlert
)alert
, newParam
);
2433 int CecMenuManaged(const CEC::cec_menu_state newVal
)
2436 if (m_bHasCallbacks
)
2438 iReturn
= m_callbacks
->ReceiveMenuStateChange((CecMenuState
)newVal
);
2443 void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
)
2445 if (m_bHasCallbacks
)
2446 m_callbacks
->SourceActivated((CecLogicalAddress
)logicalAddress
, bActivated
== 1);
2449 void DestroyDelegates()
2451 m_bHasCallbacks
= false;
2452 if (m_bDelegatesCreated
)
2454 m_bDelegatesCreated
= false;
2455 m_logMessageGCHandle
.Free();
2456 m_keypressGCHandle
.Free();
2457 m_commandGCHandle
.Free();
2458 m_alertGCHandle
.Free();
2459 m_menuGCHandle
.Free();
2460 m_sourceActivatedGCHandle
.Free();
2464 void CreateDelegates()
2468 if (!m_bDelegatesCreated
)
2470 msclr::interop::marshal_context
^ context
= gcnew
msclr::interop::marshal_context();
2472 // create the delegate method for the log message callback
2473 m_logMessageDelegate
= gcnew
CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged
);
2474 m_logMessageGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate
);
2475 m_logMessageCallback
= static_cast<LOGCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate
).ToPointer());
2477 // create the delegate method for the keypress callback
2478 m_keypressDelegate
= gcnew
CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged
);
2479 m_keypressGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate
);
2480 m_keypressCallback
= static_cast<KEYCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate
).ToPointer());
2482 // create the delegate method for the command callback
2483 m_commandDelegate
= gcnew
CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged
);
2484 m_commandGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate
);
2485 m_commandCallback
= static_cast<COMMANDCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate
).ToPointer());
2487 // create the delegate method for the configuration change callback
2488 m_configDelegate
= gcnew
CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged
);
2489 m_configGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate
);
2490 m_configCallback
= static_cast<CONFIGCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate
).ToPointer());
2492 // create the delegate method for the alert callback
2493 m_alertDelegate
= gcnew
CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged
);
2494 m_alertGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate
);
2495 m_alertCallback
= static_cast<ALERTCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate
).ToPointer());
2497 // create the delegate method for the menu callback
2498 m_menuDelegate
= gcnew
CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged
);
2499 m_menuGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate
);
2500 m_menuCallback
= static_cast<MENUCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate
).ToPointer());
2502 // create the delegate method for the source activated callback
2503 m_sourceActivatedDelegate
= gcnew
CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged
);
2504 m_sourceActivatedGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate
);
2505 m_sourceActivatedCallback
= static_cast<ACTICB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate
).ToPointer());
2509 UnmanagedCecCallbacks unmanagedCallbacks
;
2510 unmanagedCallbacks
.logCB
= m_logMessageCallback
;
2511 unmanagedCallbacks
.keyCB
= m_keypressCallback
;
2512 unmanagedCallbacks
.commandCB
= m_commandCallback
;
2513 unmanagedCallbacks
.configCB
= m_configCallback
;
2514 unmanagedCallbacks
.alertCB
= m_alertCallback
;
2515 unmanagedCallbacks
.menuCB
= m_menuCallback
;
2516 unmanagedCallbacks
.sourceActivatedCB
= m_sourceActivatedCallback
;
2518 PLATFORM::CLockObject
lock(g_callbackMutex
);
2519 g_unmanagedCallbacks
.push_back(unmanagedCallbacks
);
2520 m_iCallbackPtr
= g_unmanagedCallbacks
.size() - 1;
2521 m_bDelegatesCreated
= true;
2525 CecLogMessageManagedDelegate
^ m_logMessageDelegate
;
2526 static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle
;
2527 LOGCB m_logMessageCallback
;
2529 CecKeyPressManagedDelegate
^ m_keypressDelegate
;
2530 static System::Runtime::InteropServices::GCHandle m_keypressGCHandle
;
2531 KEYCB m_keypressCallback
;
2533 CecCommandManagedDelegate
^ m_commandDelegate
;
2534 static System::Runtime::InteropServices::GCHandle m_commandGCHandle
;
2535 COMMANDCB m_commandCallback
;
2537 CecConfigManagedDelegate
^ m_configDelegate
;
2538 static System::Runtime::InteropServices::GCHandle m_configGCHandle
;
2539 CONFIGCB m_configCallback
;
2541 CecAlertManagedDelegate
^ m_alertDelegate
;
2542 static System::Runtime::InteropServices::GCHandle m_alertGCHandle
;
2543 ALERTCB m_alertCallback
;
2545 CecMenuManagedDelegate
^ m_menuDelegate
;
2546 static System::Runtime::InteropServices::GCHandle m_menuGCHandle
;
2547 MENUCB m_menuCallback
;
2549 CecSourceActivatedManagedDelegate
^ m_sourceActivatedDelegate
;
2550 static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle
;
2551 ACTICB m_sourceActivatedCallback
;
2553 CecCallbackMethods
^ m_callbacks
;
2554 bool m_bHasCallbacks
;
2555 bool m_bDelegatesCreated
;
2556 size_t m_iCallbackPtr
;