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
374 public enum class CecServerVersion
377 Version1_5_0
= 0x1500,
378 Version1_5_1
= 0x1501,
379 Version1_5_2
= 0x1502,
380 Version1_5_3
= 0x1503,
381 Version1_6_0
= 0x1600,
382 Version1_6_1
= 0x1601,
383 Version1_6_2
= 0x1602,
384 Version1_6_3
= 0x1603,
385 Version1_7_0
= 0x1700,
386 Version1_7_1
= 0x1701
389 public ref
class CecAdapter
392 CecAdapter(System::String
^ strPath
, System::String
^ strComPort
)
395 ComPort
= strComPort
;
398 property
System::String
^ Path
;
399 property
System::String
^ ComPort
;
402 public ref
class CecDeviceTypeList
405 CecDeviceTypeList(void)
407 Types
= gcnew array
<CecDeviceType
>(5);
408 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
409 Types
[iPtr
] = CecDeviceType::Reserved
;
412 property array
<CecDeviceType
> ^ Types
;
415 public ref
class CecLogicalAddresses
418 CecLogicalAddresses(void)
420 Addresses
= gcnew array
<CecLogicalAddress
>(16);
426 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
427 Addresses
[iPtr
] = CecLogicalAddress::Unknown
;
430 bool IsSet(CecLogicalAddress iAddress
)
432 return Addresses
[(unsigned int)iAddress
] != CecLogicalAddress::Unknown
;
435 void Set(CecLogicalAddress iAddress
)
437 Addresses
[(unsigned int)iAddress
] = iAddress
;
440 property CecLogicalAddress Primary
;
441 property array
<CecLogicalAddress
> ^ Addresses
;
444 public ref
class CecDatapacket
449 Data
= gcnew array
<uint8_t>(100);
453 void PushBack(uint8_t data
)
462 property array
<uint8_t> ^ Data
;
463 property
uint8_t Size
;
466 public ref
class CecCommand
469 CecCommand(CecLogicalAddress iInitiator
, CecLogicalAddress iDestination
, bool bAck
, bool bEom
, CecOpcode iOpcode
, int32_t iTransmitTimeout
)
471 Initiator
= iInitiator
;
472 Destination
= iDestination
;
477 TransmitTimeout
= iTransmitTimeout
;
478 Parameters
= gcnew CecDatapacket
;
484 Initiator
= CecLogicalAddress::Unknown
;
485 Destination
= CecLogicalAddress::Unknown
;
488 Opcode
= CecOpcode::None
;
491 Parameters
= gcnew CecDatapacket
;
495 void PushBack(uint8_t data
)
497 if (Initiator
== CecLogicalAddress::Unknown
&& Destination
== CecLogicalAddress::Unknown
)
499 Initiator
= (CecLogicalAddress
) (data
>> 4);
500 Destination
= (CecLogicalAddress
) (data
& 0xF);
505 Opcode
= (CecOpcode
)data
;
509 Parameters
->PushBack(data
);
514 property CecLogicalAddress Initiator
;
515 property CecLogicalAddress Destination
;
518 property CecOpcode Opcode
;
519 property CecDatapacket
^ Parameters
;
520 property
bool OpcodeSet
;
521 property
int32_t TransmitTimeout
;
524 public ref
class CecKeypress
527 CecKeypress(CecUserControlCode iKeycode
, unsigned int iDuration
)
530 Duration
= iDuration
;
536 Keycode
= CecUserControlCode::Unknown
;
542 property CecUserControlCode Keycode
;
543 property
unsigned int Duration
;
546 public ref
class CecLogMessage
549 CecLogMessage(System::String
^ strMessage
, CecLogLevel iLevel
, int64_t iTime
)
551 Message
= strMessage
;
560 Level
= CecLogLevel::None
;
566 property
System::String
^Message
;
567 property CecLogLevel Level
;
568 property
int64_t Time
;
571 ref
class CecCallbackMethods
; //forward
572 public ref
class LibCECConfiguration
575 LibCECConfiguration(void)
578 DeviceTypes
= gcnew
CecDeviceTypeList();
579 AutodetectAddress
= true;
580 PhysicalAddress
= CEC_DEFAULT_PHYSICAL_ADDRESS
;
581 BaseDevice
= (CecLogicalAddress
)CEC_DEFAULT_BASE_DEVICE
;
582 HDMIPort
= CEC_DEFAULT_HDMI_PORT
;
583 ClientVersion
= CecClientVersion::VersionPre1_5
;
584 ServerVersion
= CecServerVersion::VersionPre1_5
;
585 TvVendor
= CecVendorId::Unknown
;
587 GetSettingsFromROM
= false;
588 UseTVMenuLanguage
= CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE
== 1;
589 ActivateSource
= CEC_DEFAULT_SETTING_ACTIVATE_SOURCE
== 1;
591 WakeDevices
= gcnew
CecLogicalAddresses();
592 if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE
== 1)
593 WakeDevices
->Set(CecLogicalAddress::Tv
);
595 PowerOffDevices
= gcnew
CecLogicalAddresses();
596 if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN
== 1)
597 PowerOffDevices
->Set(CecLogicalAddress::Broadcast
);
599 PowerOffScreensaver
= CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER
== 1;
600 PowerOffOnStandby
= CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY
== 1;
602 SendInactiveSource
= CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE
== 1;
603 LogicalAddresses
= gcnew
CecLogicalAddresses();
605 PowerOffDevicesOnStandby
= CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY
== 1;
606 ShutdownOnStandby
= CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY
== 1;
610 void SetCallbacks(CecCallbackMethods
^callbacks
)
612 Callbacks
= callbacks
;
615 void Update(const CEC::libcec_configuration
&config
)
617 DeviceName
= gcnew
System::String(config
.strDeviceName
);
619 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
620 DeviceTypes
->Types
[iPtr
] = (CecDeviceType
)config
.deviceTypes
.types
[iPtr
];
622 AutodetectAddress
= config
.bAutodetectAddress
== 1;
623 PhysicalAddress
= config
.iPhysicalAddress
;
624 BaseDevice
= (CecLogicalAddress
)config
.baseDevice
;
625 HDMIPort
= config
.iHDMIPort
;
626 ClientVersion
= (CecClientVersion
)config
.clientVersion
;
627 ServerVersion
= (CecServerVersion
)config
.serverVersion
;
628 TvVendor
= (CecVendorId
)config
.tvVendor
;
630 // player specific settings
631 GetSettingsFromROM
= config
.bGetSettingsFromROM
== 1;
632 UseTVMenuLanguage
= config
.bUseTVMenuLanguage
== 1;
633 ActivateSource
= config
.bActivateSource
== 1;
635 WakeDevices
->Clear();
636 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
637 if (config
.wakeDevices
[iPtr
])
638 WakeDevices
->Set((CecLogicalAddress
)iPtr
);
640 PowerOffDevices
->Clear();
641 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
642 if (config
.powerOffDevices
[iPtr
])
643 PowerOffDevices
->Set((CecLogicalAddress
)iPtr
);
645 PowerOffScreensaver
= config
.bPowerOffScreensaver
== 1;
646 PowerOffOnStandby
= config
.bPowerOffOnStandby
== 1;
648 if (ServerVersion
>= CecServerVersion::Version1_5_1
)
649 SendInactiveSource
= config
.bSendInactiveSource
== 1;
651 if (ServerVersion
>= CecServerVersion::Version1_5_3
)
653 LogicalAddresses
->Clear();
654 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
655 if (config
.logicalAddresses
[iPtr
])
656 LogicalAddresses
->Set((CecLogicalAddress
)iPtr
);
659 if (ServerVersion
>= CecServerVersion::Version1_6_0
)
661 FirmwareVersion
= config
.iFirmwareVersion
;
662 PowerOffDevicesOnStandby
= config
.bPowerOffDevicesOnStandby
== 1;
663 ShutdownOnStandby
= config
.bShutdownOnStandby
== 1;
666 if (ServerVersion
>= CecServerVersion::Version1_6_2
)
667 DeviceLanguage
= gcnew
System::String(config
.strDeviceLanguage
);
669 if (ServerVersion
>= CecServerVersion::Version1_6_3
)
670 MonitorOnlyClient
= config
.bMonitorOnly
== 1;
673 property
System::String
^ DeviceName
;
674 property CecDeviceTypeList
^ DeviceTypes
;
675 property
bool AutodetectAddress
;
676 property
uint16_t PhysicalAddress
;
677 property CecLogicalAddress BaseDevice
;
678 property
uint8_t HDMIPort
;
679 property CecClientVersion ClientVersion
;
680 property CecServerVersion ServerVersion
;
681 property CecVendorId TvVendor
;
683 // player specific settings
684 property
bool GetSettingsFromROM
;
685 property
bool UseTVMenuLanguage
;
686 property
bool ActivateSource
;
687 property CecLogicalAddresses
^WakeDevices
;
688 property CecLogicalAddresses
^PowerOffDevices
;
689 property
bool PowerOffScreensaver
;
690 property
bool PowerOffOnStandby
;
691 property
bool SendInactiveSource
;
692 property CecLogicalAddresses
^LogicalAddresses
;
693 property
uint16_t FirmwareVersion
;
694 property
bool PowerOffDevicesOnStandby
;
695 property
bool ShutdownOnStandby
;
696 property
bool MonitorOnlyClient
;
697 property
System::String
^ DeviceLanguage
;
698 property CecCallbackMethods
^ Callbacks
;
701 // the callback methods are called by unmanaged code, so we need some delegates for this
703 // unmanaged callback methods
704 typedef int (__stdcall
*LOGCB
) (const CEC::cec_log_message
&message
);
705 typedef int (__stdcall
*KEYCB
) (const CEC::cec_keypress
&key
);
706 typedef int (__stdcall
*COMMANDCB
)(const CEC::cec_command
&command
);
707 typedef int (__stdcall
*CONFIGCB
) (const CEC::libcec_configuration
&config
);
708 typedef int (__stdcall
*ALERTCB
) (const CEC::libcec_alert
, const CEC::libcec_parameter
&data
);
709 typedef int (__stdcall
*MENUCB
) (const CEC::cec_menu_state newVal
);
710 typedef void (__stdcall
*ACTICB
) (const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
);
720 ACTICB sourceActivatedCB
;
721 } UnmanagedCecCallbacks
;
723 static PLATFORM::CMutex g_callbackMutex
;
724 static std::vector
<UnmanagedCecCallbacks
> g_unmanagedCallbacks
;
725 static CEC::ICECCallbacks g_cecCallbacks
;
727 int CecLogMessageCB(void *cbParam
, const CEC::cec_log_message
&message
)
731 size_t iPtr
= (size_t)cbParam
;
732 PLATFORM::CLockObject
lock(g_callbackMutex
);
733 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
734 return g_unmanagedCallbacks
[iPtr
].logCB(message
);
739 int CecKeyPressCB(void *cbParam
, const CEC::cec_keypress
&key
)
743 size_t iPtr
= (size_t)cbParam
;
744 PLATFORM::CLockObject
lock(g_callbackMutex
);
745 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
746 return g_unmanagedCallbacks
[iPtr
].keyCB(key
);
751 int CecCommandCB(void *cbParam
, const CEC::cec_command
&command
)
755 size_t iPtr
= (size_t)cbParam
;
756 PLATFORM::CLockObject
lock(g_callbackMutex
);
757 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
758 return g_unmanagedCallbacks
[iPtr
].commandCB(command
);
763 int CecConfigCB(void *cbParam
, const CEC::libcec_configuration
&config
)
767 size_t iPtr
= (size_t)cbParam
;
768 PLATFORM::CLockObject
lock(g_callbackMutex
);
769 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
770 return g_unmanagedCallbacks
[iPtr
].configCB(config
);
775 int CecAlertCB(void *cbParam
, const CEC::libcec_alert alert
, const CEC::libcec_parameter
&data
)
779 size_t iPtr
= (size_t)cbParam
;
780 PLATFORM::CLockObject
lock(g_callbackMutex
);
781 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
782 return g_unmanagedCallbacks
[iPtr
].alertCB(alert
, data
);
787 int CecMenuCB(void *cbParam
, const CEC::cec_menu_state newVal
)
791 size_t iPtr
= (size_t)cbParam
;
792 PLATFORM::CLockObject
lock(g_callbackMutex
);
793 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
794 return g_unmanagedCallbacks
[iPtr
].menuCB(newVal
);
799 void CecSourceActivatedCB(void *cbParam
, const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
)
803 size_t iPtr
= (size_t)cbParam
;
804 PLATFORM::CLockObject
lock(g_callbackMutex
);
805 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
806 g_unmanagedCallbacks
[iPtr
].sourceActivatedCB(logicalAddress
, bActivated
);
811 // delegates for the unmanaged callback methods
812 public delegate
int CecLogMessageManagedDelegate(const CEC::cec_log_message
&);
813 public delegate
int CecKeyPressManagedDelegate(const CEC::cec_keypress
&);
814 public delegate
int CecCommandManagedDelegate(const CEC::cec_command
&);
815 public delegate
int CecConfigManagedDelegate(const CEC::libcec_configuration
&);
816 public delegate
int CecAlertManagedDelegate(const CEC::libcec_alert
, const CEC::libcec_parameter
&);
817 public delegate
int CecMenuManagedDelegate(const CEC::cec_menu_state newVal
);
818 public delegate
void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
);
820 void AssignCallbacks()
822 g_cecCallbacks
.CBCecLogMessage
= CecLogMessageCB
;
823 g_cecCallbacks
.CBCecKeyPress
= CecKeyPressCB
;
824 g_cecCallbacks
.CBCecCommand
= CecCommandCB
;
825 g_cecCallbacks
.CBCecConfigurationChanged
= CecConfigCB
;
826 g_cecCallbacks
.CBCecAlert
= CecAlertCB
;
827 g_cecCallbacks
.CBCecMenuStateChanged
= CecMenuCB
;
828 g_cecCallbacks
.CBCecSourceActivated
= CecSourceActivatedCB
;
831 // callback method interface
832 public ref
class CecCallbackMethods
835 CecCallbackMethods(void)
839 m_bHasCallbacks
= false;
840 m_bDelegatesCreated
= false;
843 ~CecCallbackMethods(void)
848 size_t GetCallbackPtr(void)
850 PLATFORM::CLockObject
lock(g_callbackMutex
);
851 return m_iCallbackPtr
;
855 !CecCallbackMethods(void)
861 virtual void DisableCallbacks(void)
866 virtual bool EnableCallbacks(CecCallbackMethods
^ callbacks
)
869 if (!m_bHasCallbacks
)
871 m_bHasCallbacks
= true;
872 m_callbacks
= callbacks
;
879 virtual int ReceiveLogMessage(CecLogMessage
^ message
)
884 virtual int ReceiveKeypress(CecKeypress
^ key
)
889 virtual int ReceiveCommand(CecCommand
^ command
)
894 virtual int ConfigurationChanged(LibCECConfiguration
^ config
)
899 virtual int ReceiveAlert(CecAlert alert
, CecParameter
^ data
)
904 virtual int ReceiveMenuStateChange(CecMenuState newVal
)
909 virtual void SourceActivated(CecLogicalAddress logicalAddress
, bool bActivated
)
914 // managed callback methods
915 int CecLogMessageManaged(const CEC::cec_log_message
&message
)
919 iReturn
= m_callbacks
->ReceiveLogMessage(gcnew
CecLogMessage(gcnew
System::String(message
.message
), (CecLogLevel
)message
.level
, message
.time
));
923 int CecKeyPressManaged(const CEC::cec_keypress
&key
)
927 iReturn
= m_callbacks
->ReceiveKeypress(gcnew
CecKeypress((CecUserControlCode
)key
.keycode
, key
.duration
));
931 int CecCommandManaged(const CEC::cec_command
&command
)
936 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
);
937 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
938 newCommand
->Parameters
->PushBack(command
.parameters
[iPtr
]);
939 iReturn
= m_callbacks
->ReceiveCommand(newCommand
);
944 int CecConfigManaged(const CEC::libcec_configuration
&config
)
949 LibCECConfiguration
^netConfig
= gcnew
LibCECConfiguration();
950 netConfig
->Update(config
);
951 iReturn
= m_callbacks
->ConfigurationChanged(netConfig
);
956 int CecAlertManaged(const CEC::libcec_alert alert
, const CEC::libcec_parameter
&data
)
961 CecParameterType newType
= (CecParameterType
)data
.paramType
;
962 if (newType
== CecParameterType::ParameterTypeString
)
964 System::String
^ newData
= gcnew
System::String((const char *)data
.paramData
, 0, 128);
965 CecParameter
^ newParam
= gcnew
CecParameter(newType
, newData
);
966 iReturn
= m_callbacks
->ReceiveAlert((CecAlert
)alert
, newParam
);
972 int CecMenuManaged(const CEC::cec_menu_state newVal
)
977 iReturn
= m_callbacks
->ReceiveMenuStateChange((CecMenuState
)newVal
);
982 void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
)
985 m_callbacks
->SourceActivated((CecLogicalAddress
)logicalAddress
, bActivated
== 1);
988 void DestroyDelegates()
990 m_bHasCallbacks
= false;
991 if (m_bDelegatesCreated
)
993 m_bDelegatesCreated
= false;
994 m_logMessageGCHandle
.Free();
995 m_keypressGCHandle
.Free();
996 m_commandGCHandle
.Free();
997 m_alertGCHandle
.Free();
998 m_menuGCHandle
.Free();
999 m_sourceActivatedGCHandle
.Free();
1003 void CreateDelegates()
1007 if (!m_bDelegatesCreated
)
1009 msclr::interop::marshal_context
^ context
= gcnew
msclr::interop::marshal_context();
1011 // create the delegate method for the log message callback
1012 m_logMessageDelegate
= gcnew
CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged
);
1013 m_logMessageGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate
);
1014 m_logMessageCallback
= static_cast<LOGCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate
).ToPointer());
1016 // create the delegate method for the keypress callback
1017 m_keypressDelegate
= gcnew
CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged
);
1018 m_keypressGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate
);
1019 m_keypressCallback
= static_cast<KEYCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate
).ToPointer());
1021 // create the delegate method for the command callback
1022 m_commandDelegate
= gcnew
CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged
);
1023 m_commandGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate
);
1024 m_commandCallback
= static_cast<COMMANDCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate
).ToPointer());
1026 // create the delegate method for the configuration change callback
1027 m_configDelegate
= gcnew
CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged
);
1028 m_configGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate
);
1029 m_configCallback
= static_cast<CONFIGCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate
).ToPointer());
1031 // create the delegate method for the alert callback
1032 m_alertDelegate
= gcnew
CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged
);
1033 m_alertGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate
);
1034 m_alertCallback
= static_cast<ALERTCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate
).ToPointer());
1036 // create the delegate method for the menu callback
1037 m_menuDelegate
= gcnew
CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged
);
1038 m_menuGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate
);
1039 m_menuCallback
= static_cast<MENUCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate
).ToPointer());
1041 // create the delegate method for the source activated callback
1042 m_sourceActivatedDelegate
= gcnew
CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged
);
1043 m_sourceActivatedGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate
);
1044 m_sourceActivatedCallback
= static_cast<ACTICB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate
).ToPointer());
1048 UnmanagedCecCallbacks unmanagedCallbacks
;
1049 unmanagedCallbacks
.logCB
= m_logMessageCallback
;
1050 unmanagedCallbacks
.keyCB
= m_keypressCallback
;
1051 unmanagedCallbacks
.commandCB
= m_commandCallback
;
1052 unmanagedCallbacks
.configCB
= m_configCallback
;
1053 unmanagedCallbacks
.alertCB
= m_alertCallback
;
1054 unmanagedCallbacks
.menuCB
= m_menuCallback
;
1055 unmanagedCallbacks
.sourceActivatedCB
= m_sourceActivatedCallback
;
1057 PLATFORM::CLockObject
lock(g_callbackMutex
);
1058 g_unmanagedCallbacks
.push_back(unmanagedCallbacks
);
1059 m_iCallbackPtr
= g_unmanagedCallbacks
.size() - 1;
1060 m_bDelegatesCreated
= true;
1064 CecLogMessageManagedDelegate
^ m_logMessageDelegate
;
1065 static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle
;
1066 LOGCB m_logMessageCallback
;
1068 CecKeyPressManagedDelegate
^ m_keypressDelegate
;
1069 static System::Runtime::InteropServices::GCHandle m_keypressGCHandle
;
1070 KEYCB m_keypressCallback
;
1072 CecCommandManagedDelegate
^ m_commandDelegate
;
1073 static System::Runtime::InteropServices::GCHandle m_commandGCHandle
;
1074 COMMANDCB m_commandCallback
;
1076 CecConfigManagedDelegate
^ m_configDelegate
;
1077 static System::Runtime::InteropServices::GCHandle m_configGCHandle
;
1078 CONFIGCB m_configCallback
;
1080 CecAlertManagedDelegate
^ m_alertDelegate
;
1081 static System::Runtime::InteropServices::GCHandle m_alertGCHandle
;
1082 ALERTCB m_alertCallback
;
1084 CecMenuManagedDelegate
^ m_menuDelegate
;
1085 static System::Runtime::InteropServices::GCHandle m_menuGCHandle
;
1086 MENUCB m_menuCallback
;
1088 CecSourceActivatedManagedDelegate
^ m_sourceActivatedDelegate
;
1089 static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle
;
1090 ACTICB m_sourceActivatedCallback
;
1092 CecCallbackMethods
^ m_callbacks
;
1093 bool m_bHasCallbacks
;
1094 bool m_bDelegatesCreated
;
1095 size_t m_iCallbackPtr
;