3 * This file is part of the libCEC(R) library.
5 * libCEC(R) is Copyright (C) 2011-2012 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"
44 public enum class CecDeviceType
54 public enum class CecLogLevel
65 public enum class CecLogicalAddress
67 Unknown
= -1, //not a valid logical address
87 public enum class CecAlert
92 public enum class CecParameterType
94 ParameterTypeString
= 1
97 public ref
class CecParameter
100 CecParameter(CecParameterType type
, System::String
^ strData
)
106 property CecParameterType Type
;
107 property
System::String
^ Data
;
110 public enum class CecPowerStatus
114 InTransitionStandbyToOn
= 0x02,
115 InTransitionOnToStandby
= 0x03,
119 public enum class CecVersion
129 public enum class CecDisplayControl
131 DisplayForDefaultTime
= 0x00,
132 DisplayUntilCleared
= 0x40,
133 ClearPreviousMessage
= 0x80,
134 ReservedForFutureUse
= 0xC0
137 public enum class CecMenuState
143 public enum class CecDeckControlMode
146 SkipReverseRewind
= 2,
151 public enum class CecDeckInfo
163 SkipForwardWind
= 0x1B,
164 SkipReverseRewind
= 0x1C,
165 IndexSearchForward
= 0x1D,
166 IndexSearchReverse
= 0x1E,
170 public enum class CecUserControlCode
202 PreviousChannel
= 0x32,
205 DisplayInformation
= 0x35,
226 VideoOnDemand
= 0x52,
227 ElectronicProgramGuide
= 0x53,
228 TimerProgramming
= 0x54,
229 InitialConfiguration
= 0x55,
231 PausePlayFunction
= 0x61,
232 RecordFunction
= 0x62,
233 PauseRecordFunction
= 0x63,
236 RestoreVolumeFunction
= 0x66,
238 SelectMediaFunction
= 0x68,
239 SelectAVInputFunction
= 0x69,
240 SelectAudioInputFunction
= 0x6A,
241 PowerToggleFunction
= 0x6B,
242 PowerOffFunction
= 0x6C,
243 PowerOnFunction
= 0x6D,
251 SamsungReturn
= 0x91,
255 public enum class CecVendorId
259 Panasonic
= 0x008045,
276 public enum class CecAudioStatus
278 MuteStatusMask
= 0x80,
279 VolumeStatusMask
= 0x7F,
282 VolumeStatusUnknown
= 0x7F
285 public enum class CecOpcode
290 InactiveSource
= 0x9D,
291 RequestActiveSource
= 0x85,
292 RoutingChange
= 0x80,
293 RoutingInformation
= 0x81,
294 SetStreamPath
= 0x86,
299 RecordTvScreen
= 0x0F,
300 ClearAnalogueTimer
= 0x33,
301 ClearDigitalTimer
= 0x99,
302 ClearExternalTimer
= 0xA1,
303 SetAnalogueTimer
= 0x34,
304 SetDigitalTimer
= 0x97,
305 SetExternalTimer
= 0xA2,
306 SetTimerProgramTitle
= 0x67,
307 TimerClearedStatus
= 0x43,
310 GetCecVersion
= 0x9F,
311 GivePhysicalAddress
= 0x83,
312 GetMenuLanguage
= 0x91,
313 ReportPhysicalAddress
= 0x84,
314 SetMenuLanguage
= 0x32,
317 GiveDeckStatus
= 0x1A,
319 GiveTunerDeviceStatus
= 0x08,
320 SelectAnalogueService
= 0x92,
321 SelectDigtalService
= 0x93,
322 TunerDeviceStatus
= 0x07,
323 TunerStepDecrement
= 0x06,
324 TunerStepIncrement
= 0x05,
325 DeviceVendorId
= 0x87,
326 GiveDeviceVendorId
= 0x8C,
327 VendorCommand
= 0x89,
328 VendorCommandWithId
= 0xA0,
329 VendorRemoteButtonDown
= 0x8A,
330 VendorRemoteButtonUp
= 0x8B,
336 UserControlPressed
= 0x44,
337 UserControlRelease
= 0x45,
338 GiveDevicePowerStatus
= 0x8F,
339 ReportPowerStatus
= 0x90,
342 GiveAudioStatus
= 0x71,
343 GiveSystemAudioMode
= 0x7D,
344 ReportAudioStatus
= 0x7A,
345 SetSystemAudioMode
= 0x72,
346 SystemAudioModeRequest
= 0x70,
347 SystemAudioModeStatus
= 0x7E,
349 /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */
353 public enum class CecSystemAudioStatus
359 public enum class CecClientVersion
362 Version1_5_0
= 0x1500,
363 Version1_5_1
= 0x1501,
364 Version1_5_2
= 0x1502,
365 Version1_5_3
= 0x1503,
366 Version1_6_0
= 0x1600,
367 Version1_6_1
= 0x1601,
368 Version1_6_2
= 0x1602,
369 Version1_6_3
= 0x1603,
370 Version1_7_0
= 0x1700,
371 Version1_7_1
= 0x1701,
372 Version1_7_2
= 0x1702,
373 Version1_8_0
= 0x1800,
374 Version1_8_1
= 0x1801,
375 Version1_8_2
= 0x1802,
376 Version1_9_0
= 0x1900
379 public enum class CecServerVersion
382 Version1_5_0
= 0x1500,
383 Version1_5_1
= 0x1501,
384 Version1_5_2
= 0x1502,
385 Version1_5_3
= 0x1503,
386 Version1_6_0
= 0x1600,
387 Version1_6_1
= 0x1601,
388 Version1_6_2
= 0x1602,
389 Version1_6_3
= 0x1603,
390 Version1_7_0
= 0x1700,
391 Version1_7_1
= 0x1701,
392 Version1_7_2
= 0x1702,
393 Version1_8_0
= 0x1800,
394 Version1_8_1
= 0x1801,
395 Version1_8_2
= 0x1802,
396 Version1_9_0
= 0x1900
399 public ref
class CecAdapter
402 CecAdapter(System::String
^ strPath
, System::String
^ strComPort
)
405 ComPort
= strComPort
;
408 property
System::String
^ Path
;
409 property
System::String
^ ComPort
;
412 public ref
class CecDeviceTypeList
415 CecDeviceTypeList(void)
417 Types
= gcnew array
<CecDeviceType
>(5);
418 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
419 Types
[iPtr
] = CecDeviceType::Reserved
;
422 property array
<CecDeviceType
> ^ Types
;
425 public ref
class CecLogicalAddresses
428 CecLogicalAddresses(void)
430 Addresses
= gcnew array
<CecLogicalAddress
>(16);
436 Primary
= CecLogicalAddress::Unknown
;
437 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
438 Addresses
[iPtr
] = CecLogicalAddress::Unknown
;
441 bool IsSet(CecLogicalAddress iAddress
)
443 return Addresses
[(unsigned int)iAddress
] != CecLogicalAddress::Unknown
;
446 void Set(CecLogicalAddress iAddress
)
448 Addresses
[(unsigned int)iAddress
] = iAddress
;
449 if (Primary
== CecLogicalAddress::Unknown
)
453 property CecLogicalAddress Primary
;
454 property array
<CecLogicalAddress
> ^ Addresses
;
457 public ref
class CecDatapacket
462 Data
= gcnew array
<uint8_t>(100);
466 void PushBack(uint8_t data
)
475 property array
<uint8_t> ^ Data
;
476 property
uint8_t Size
;
479 public ref
class CecCommand
482 CecCommand(CecLogicalAddress iInitiator
, CecLogicalAddress iDestination
, bool bAck
, bool bEom
, CecOpcode iOpcode
, int32_t iTransmitTimeout
)
484 Initiator
= iInitiator
;
485 Destination
= iDestination
;
490 TransmitTimeout
= iTransmitTimeout
;
491 Parameters
= gcnew CecDatapacket
;
497 Initiator
= CecLogicalAddress::Unknown
;
498 Destination
= CecLogicalAddress::Unknown
;
501 Opcode
= CecOpcode::None
;
504 Parameters
= gcnew CecDatapacket
;
508 void PushBack(uint8_t data
)
510 if (Initiator
== CecLogicalAddress::Unknown
&& Destination
== CecLogicalAddress::Unknown
)
512 Initiator
= (CecLogicalAddress
) (data
>> 4);
513 Destination
= (CecLogicalAddress
) (data
& 0xF);
518 Opcode
= (CecOpcode
)data
;
522 Parameters
->PushBack(data
);
527 property CecLogicalAddress Initiator
;
528 property CecLogicalAddress Destination
;
531 property CecOpcode Opcode
;
532 property CecDatapacket
^ Parameters
;
533 property
bool OpcodeSet
;
534 property
int32_t TransmitTimeout
;
537 public ref
class CecKeypress
540 CecKeypress(CecUserControlCode iKeycode
, unsigned int iDuration
)
543 Duration
= iDuration
;
549 Keycode
= CecUserControlCode::Unknown
;
555 property CecUserControlCode Keycode
;
556 property
unsigned int Duration
;
559 public ref
class CecLogMessage
562 CecLogMessage(System::String
^ strMessage
, CecLogLevel iLevel
, int64_t iTime
)
564 Message
= strMessage
;
573 Level
= CecLogLevel::None
;
579 property
System::String
^Message
;
580 property CecLogLevel Level
;
581 property
int64_t Time
;
584 ref
class CecCallbackMethods
; //forward
585 public ref
class LibCECConfiguration
588 LibCECConfiguration(void)
591 DeviceTypes
= gcnew
CecDeviceTypeList();
592 AutodetectAddress
= true;
593 PhysicalAddress
= CEC_DEFAULT_PHYSICAL_ADDRESS
;
594 BaseDevice
= (CecLogicalAddress
)CEC_DEFAULT_BASE_DEVICE
;
595 HDMIPort
= CEC_DEFAULT_HDMI_PORT
;
596 ClientVersion
= CecClientVersion::VersionPre1_5
;
597 ServerVersion
= CecServerVersion::VersionPre1_5
;
598 TvVendor
= CecVendorId::Unknown
;
600 GetSettingsFromROM
= false;
601 UseTVMenuLanguage
= CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE
== 1;
602 ActivateSource
= CEC_DEFAULT_SETTING_ACTIVATE_SOURCE
== 1;
604 WakeDevices
= gcnew
CecLogicalAddresses();
605 if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE
== 1)
606 WakeDevices
->Set(CecLogicalAddress::Tv
);
608 PowerOffDevices
= gcnew
CecLogicalAddresses();
609 if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN
== 1)
610 PowerOffDevices
->Set(CecLogicalAddress::Broadcast
);
612 PowerOffScreensaver
= CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER
== 1;
613 PowerOffOnStandby
= CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY
== 1;
615 SendInactiveSource
= CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE
== 1;
616 LogicalAddresses
= gcnew
CecLogicalAddresses();
618 PowerOffDevicesOnStandby
= CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY
== 1;
619 ShutdownOnStandby
= CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY
== 1;
623 void SetCallbacks(CecCallbackMethods
^callbacks
)
625 Callbacks
= callbacks
;
628 void Update(const CEC::libcec_configuration
&config
)
630 DeviceName
= gcnew
System::String(config
.strDeviceName
);
632 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
633 DeviceTypes
->Types
[iPtr
] = (CecDeviceType
)config
.deviceTypes
.types
[iPtr
];
635 AutodetectAddress
= config
.bAutodetectAddress
== 1;
636 PhysicalAddress
= config
.iPhysicalAddress
;
637 BaseDevice
= (CecLogicalAddress
)config
.baseDevice
;
638 HDMIPort
= config
.iHDMIPort
;
639 ClientVersion
= (CecClientVersion
)config
.clientVersion
;
640 ServerVersion
= (CecServerVersion
)config
.serverVersion
;
641 TvVendor
= (CecVendorId
)config
.tvVendor
;
643 // player specific settings
644 GetSettingsFromROM
= config
.bGetSettingsFromROM
== 1;
645 UseTVMenuLanguage
= config
.bUseTVMenuLanguage
== 1;
646 ActivateSource
= config
.bActivateSource
== 1;
648 WakeDevices
->Clear();
649 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
650 if (config
.wakeDevices
[iPtr
])
651 WakeDevices
->Set((CecLogicalAddress
)iPtr
);
653 PowerOffDevices
->Clear();
654 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
655 if (config
.powerOffDevices
[iPtr
])
656 PowerOffDevices
->Set((CecLogicalAddress
)iPtr
);
658 PowerOffScreensaver
= config
.bPowerOffScreensaver
== 1;
659 PowerOffOnStandby
= config
.bPowerOffOnStandby
== 1;
661 if (ServerVersion
>= CecServerVersion::Version1_5_1
)
662 SendInactiveSource
= config
.bSendInactiveSource
== 1;
664 if (ServerVersion
>= CecServerVersion::Version1_5_3
)
666 LogicalAddresses
->Clear();
667 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
668 if (config
.logicalAddresses
[iPtr
])
669 LogicalAddresses
->Set((CecLogicalAddress
)iPtr
);
672 if (ServerVersion
>= CecServerVersion::Version1_6_0
)
674 FirmwareVersion
= config
.iFirmwareVersion
;
675 PowerOffDevicesOnStandby
= config
.bPowerOffDevicesOnStandby
== 1;
676 ShutdownOnStandby
= config
.bShutdownOnStandby
== 1;
679 if (ServerVersion
>= CecServerVersion::Version1_6_2
)
680 DeviceLanguage
= gcnew
System::String(config
.strDeviceLanguage
);
682 if (ServerVersion
>= CecServerVersion::Version1_6_3
)
683 MonitorOnlyClient
= config
.bMonitorOnly
== 1;
686 property
System::String
^ DeviceName
;
687 property CecDeviceTypeList
^ DeviceTypes
;
688 property
bool AutodetectAddress
;
689 property
uint16_t PhysicalAddress
;
690 property CecLogicalAddress BaseDevice
;
691 property
uint8_t HDMIPort
;
692 property CecClientVersion ClientVersion
;
693 property CecServerVersion ServerVersion
;
694 property CecVendorId TvVendor
;
696 // player specific settings
697 property
bool GetSettingsFromROM
;
698 property
bool UseTVMenuLanguage
;
699 property
bool ActivateSource
;
700 property CecLogicalAddresses
^WakeDevices
;
701 property CecLogicalAddresses
^PowerOffDevices
;
702 property
bool PowerOffScreensaver
;
703 property
bool PowerOffOnStandby
;
704 property
bool SendInactiveSource
;
705 property CecLogicalAddresses
^LogicalAddresses
;
706 property
uint16_t FirmwareVersion
;
707 property
bool PowerOffDevicesOnStandby
;
708 property
bool ShutdownOnStandby
;
709 property
bool MonitorOnlyClient
;
710 property
System::String
^ DeviceLanguage
;
711 property CecCallbackMethods
^ Callbacks
;
714 // the callback methods are called by unmanaged code, so we need some delegates for this
716 // unmanaged callback methods
717 typedef int (__stdcall
*LOGCB
) (const CEC::cec_log_message
&message
);
718 typedef int (__stdcall
*KEYCB
) (const CEC::cec_keypress
&key
);
719 typedef int (__stdcall
*COMMANDCB
)(const CEC::cec_command
&command
);
720 typedef int (__stdcall
*CONFIGCB
) (const CEC::libcec_configuration
&config
);
721 typedef int (__stdcall
*ALERTCB
) (const CEC::libcec_alert
, const CEC::libcec_parameter
&data
);
722 typedef int (__stdcall
*MENUCB
) (const CEC::cec_menu_state newVal
);
723 typedef void (__stdcall
*ACTICB
) (const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
);
733 ACTICB sourceActivatedCB
;
734 } UnmanagedCecCallbacks
;
736 static PLATFORM::CMutex g_callbackMutex
;
737 static std::vector
<UnmanagedCecCallbacks
> g_unmanagedCallbacks
;
738 static CEC::ICECCallbacks g_cecCallbacks
;
740 int CecLogMessageCB(void *cbParam
, const CEC::cec_log_message
&message
)
744 size_t iPtr
= (size_t)cbParam
;
745 PLATFORM::CLockObject
lock(g_callbackMutex
);
746 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
747 return g_unmanagedCallbacks
[iPtr
].logCB(message
);
752 int CecKeyPressCB(void *cbParam
, const CEC::cec_keypress
&key
)
756 size_t iPtr
= (size_t)cbParam
;
757 PLATFORM::CLockObject
lock(g_callbackMutex
);
758 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
759 return g_unmanagedCallbacks
[iPtr
].keyCB(key
);
764 int CecCommandCB(void *cbParam
, const CEC::cec_command
&command
)
768 size_t iPtr
= (size_t)cbParam
;
769 PLATFORM::CLockObject
lock(g_callbackMutex
);
770 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
771 return g_unmanagedCallbacks
[iPtr
].commandCB(command
);
776 int CecConfigCB(void *cbParam
, const CEC::libcec_configuration
&config
)
780 size_t iPtr
= (size_t)cbParam
;
781 PLATFORM::CLockObject
lock(g_callbackMutex
);
782 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
783 return g_unmanagedCallbacks
[iPtr
].configCB(config
);
788 int CecAlertCB(void *cbParam
, const CEC::libcec_alert alert
, const CEC::libcec_parameter
&data
)
792 size_t iPtr
= (size_t)cbParam
;
793 PLATFORM::CLockObject
lock(g_callbackMutex
);
794 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
795 return g_unmanagedCallbacks
[iPtr
].alertCB(alert
, data
);
800 int CecMenuCB(void *cbParam
, const CEC::cec_menu_state newVal
)
804 size_t iPtr
= (size_t)cbParam
;
805 PLATFORM::CLockObject
lock(g_callbackMutex
);
806 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
807 return g_unmanagedCallbacks
[iPtr
].menuCB(newVal
);
812 void CecSourceActivatedCB(void *cbParam
, const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
)
816 size_t iPtr
= (size_t)cbParam
;
817 PLATFORM::CLockObject
lock(g_callbackMutex
);
818 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
819 g_unmanagedCallbacks
[iPtr
].sourceActivatedCB(logicalAddress
, bActivated
);
824 // delegates for the unmanaged callback methods
825 public delegate
int CecLogMessageManagedDelegate(const CEC::cec_log_message
&);
826 public delegate
int CecKeyPressManagedDelegate(const CEC::cec_keypress
&);
827 public delegate
int CecCommandManagedDelegate(const CEC::cec_command
&);
828 public delegate
int CecConfigManagedDelegate(const CEC::libcec_configuration
&);
829 public delegate
int CecAlertManagedDelegate(const CEC::libcec_alert
, const CEC::libcec_parameter
&);
830 public delegate
int CecMenuManagedDelegate(const CEC::cec_menu_state newVal
);
831 public delegate
void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
);
833 void AssignCallbacks()
835 g_cecCallbacks
.CBCecLogMessage
= CecLogMessageCB
;
836 g_cecCallbacks
.CBCecKeyPress
= CecKeyPressCB
;
837 g_cecCallbacks
.CBCecCommand
= CecCommandCB
;
838 g_cecCallbacks
.CBCecConfigurationChanged
= CecConfigCB
;
839 g_cecCallbacks
.CBCecAlert
= CecAlertCB
;
840 g_cecCallbacks
.CBCecMenuStateChanged
= CecMenuCB
;
841 g_cecCallbacks
.CBCecSourceActivated
= CecSourceActivatedCB
;
844 // callback method interface
845 public ref
class CecCallbackMethods
848 CecCallbackMethods(void)
852 m_bHasCallbacks
= false;
853 m_bDelegatesCreated
= false;
856 ~CecCallbackMethods(void)
861 size_t GetCallbackPtr(void)
863 PLATFORM::CLockObject
lock(g_callbackMutex
);
864 return m_iCallbackPtr
;
868 !CecCallbackMethods(void)
874 virtual void DisableCallbacks(void)
879 virtual bool EnableCallbacks(CecCallbackMethods
^ callbacks
)
882 if (!m_bHasCallbacks
)
884 m_bHasCallbacks
= true;
885 m_callbacks
= callbacks
;
892 virtual int ReceiveLogMessage(CecLogMessage
^ message
)
897 virtual int ReceiveKeypress(CecKeypress
^ key
)
902 virtual int ReceiveCommand(CecCommand
^ command
)
907 virtual int ConfigurationChanged(LibCECConfiguration
^ config
)
912 virtual int ReceiveAlert(CecAlert alert
, CecParameter
^ data
)
917 virtual int ReceiveMenuStateChange(CecMenuState newVal
)
922 virtual void SourceActivated(CecLogicalAddress logicalAddress
, bool bActivated
)
927 // managed callback methods
928 int CecLogMessageManaged(const CEC::cec_log_message
&message
)
932 iReturn
= m_callbacks
->ReceiveLogMessage(gcnew
CecLogMessage(gcnew
System::String(message
.message
), (CecLogLevel
)message
.level
, message
.time
));
936 int CecKeyPressManaged(const CEC::cec_keypress
&key
)
940 iReturn
= m_callbacks
->ReceiveKeypress(gcnew
CecKeypress((CecUserControlCode
)key
.keycode
, key
.duration
));
944 int CecCommandManaged(const CEC::cec_command
&command
)
949 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
);
950 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
951 newCommand
->Parameters
->PushBack(command
.parameters
[iPtr
]);
952 iReturn
= m_callbacks
->ReceiveCommand(newCommand
);
957 int CecConfigManaged(const CEC::libcec_configuration
&config
)
962 LibCECConfiguration
^netConfig
= gcnew
LibCECConfiguration();
963 netConfig
->Update(config
);
964 iReturn
= m_callbacks
->ConfigurationChanged(netConfig
);
969 int CecAlertManaged(const CEC::libcec_alert alert
, const CEC::libcec_parameter
&data
)
974 CecParameterType newType
= (CecParameterType
)data
.paramType
;
975 if (newType
== CecParameterType::ParameterTypeString
)
977 System::String
^ newData
= gcnew
System::String((const char *)data
.paramData
, 0, 128);
978 CecParameter
^ newParam
= gcnew
CecParameter(newType
, newData
);
979 iReturn
= m_callbacks
->ReceiveAlert((CecAlert
)alert
, newParam
);
985 int CecMenuManaged(const CEC::cec_menu_state newVal
)
990 iReturn
= m_callbacks
->ReceiveMenuStateChange((CecMenuState
)newVal
);
995 void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
)
998 m_callbacks
->SourceActivated((CecLogicalAddress
)logicalAddress
, bActivated
== 1);
1001 void DestroyDelegates()
1003 m_bHasCallbacks
= false;
1004 if (m_bDelegatesCreated
)
1006 m_bDelegatesCreated
= false;
1007 m_logMessageGCHandle
.Free();
1008 m_keypressGCHandle
.Free();
1009 m_commandGCHandle
.Free();
1010 m_alertGCHandle
.Free();
1011 m_menuGCHandle
.Free();
1012 m_sourceActivatedGCHandle
.Free();
1016 void CreateDelegates()
1020 if (!m_bDelegatesCreated
)
1022 msclr::interop::marshal_context
^ context
= gcnew
msclr::interop::marshal_context();
1024 // create the delegate method for the log message callback
1025 m_logMessageDelegate
= gcnew
CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged
);
1026 m_logMessageGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate
);
1027 m_logMessageCallback
= static_cast<LOGCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate
).ToPointer());
1029 // create the delegate method for the keypress callback
1030 m_keypressDelegate
= gcnew
CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged
);
1031 m_keypressGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate
);
1032 m_keypressCallback
= static_cast<KEYCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate
).ToPointer());
1034 // create the delegate method for the command callback
1035 m_commandDelegate
= gcnew
CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged
);
1036 m_commandGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate
);
1037 m_commandCallback
= static_cast<COMMANDCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate
).ToPointer());
1039 // create the delegate method for the configuration change callback
1040 m_configDelegate
= gcnew
CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged
);
1041 m_configGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate
);
1042 m_configCallback
= static_cast<CONFIGCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate
).ToPointer());
1044 // create the delegate method for the alert callback
1045 m_alertDelegate
= gcnew
CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged
);
1046 m_alertGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate
);
1047 m_alertCallback
= static_cast<ALERTCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate
).ToPointer());
1049 // create the delegate method for the menu callback
1050 m_menuDelegate
= gcnew
CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged
);
1051 m_menuGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate
);
1052 m_menuCallback
= static_cast<MENUCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate
).ToPointer());
1054 // create the delegate method for the source activated callback
1055 m_sourceActivatedDelegate
= gcnew
CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged
);
1056 m_sourceActivatedGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate
);
1057 m_sourceActivatedCallback
= static_cast<ACTICB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate
).ToPointer());
1061 UnmanagedCecCallbacks unmanagedCallbacks
;
1062 unmanagedCallbacks
.logCB
= m_logMessageCallback
;
1063 unmanagedCallbacks
.keyCB
= m_keypressCallback
;
1064 unmanagedCallbacks
.commandCB
= m_commandCallback
;
1065 unmanagedCallbacks
.configCB
= m_configCallback
;
1066 unmanagedCallbacks
.alertCB
= m_alertCallback
;
1067 unmanagedCallbacks
.menuCB
= m_menuCallback
;
1068 unmanagedCallbacks
.sourceActivatedCB
= m_sourceActivatedCallback
;
1070 PLATFORM::CLockObject
lock(g_callbackMutex
);
1071 g_unmanagedCallbacks
.push_back(unmanagedCallbacks
);
1072 m_iCallbackPtr
= g_unmanagedCallbacks
.size() - 1;
1073 m_bDelegatesCreated
= true;
1077 CecLogMessageManagedDelegate
^ m_logMessageDelegate
;
1078 static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle
;
1079 LOGCB m_logMessageCallback
;
1081 CecKeyPressManagedDelegate
^ m_keypressDelegate
;
1082 static System::Runtime::InteropServices::GCHandle m_keypressGCHandle
;
1083 KEYCB m_keypressCallback
;
1085 CecCommandManagedDelegate
^ m_commandDelegate
;
1086 static System::Runtime::InteropServices::GCHandle m_commandGCHandle
;
1087 COMMANDCB m_commandCallback
;
1089 CecConfigManagedDelegate
^ m_configDelegate
;
1090 static System::Runtime::InteropServices::GCHandle m_configGCHandle
;
1091 CONFIGCB m_configCallback
;
1093 CecAlertManagedDelegate
^ m_alertDelegate
;
1094 static System::Runtime::InteropServices::GCHandle m_alertGCHandle
;
1095 ALERTCB m_alertCallback
;
1097 CecMenuManagedDelegate
^ m_menuDelegate
;
1098 static System::Runtime::InteropServices::GCHandle m_menuGCHandle
;
1099 MENUCB m_menuCallback
;
1101 CecSourceActivatedManagedDelegate
^ m_sourceActivatedDelegate
;
1102 static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle
;
1103 ACTICB m_sourceActivatedCallback
;
1105 CecCallbackMethods
^ m_callbacks
;
1106 bool m_bHasCallbacks
;
1107 bool m_bDelegatesCreated
;
1108 size_t m_iCallbackPtr
;