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
268 public enum class CecAudioStatus
270 MuteStatusMask
= 0x80,
271 VolumeStatusMask
= 0x7F,
274 VolumeStatusUnknown
= 0x7F
277 public enum class CecOpcode
282 InactiveSource
= 0x9D,
283 RequestActiveSource
= 0x85,
284 RoutingChange
= 0x80,
285 RoutingInformation
= 0x81,
286 SetStreamPath
= 0x86,
291 RecordTvScreen
= 0x0F,
292 ClearAnalogueTimer
= 0x33,
293 ClearDigitalTimer
= 0x99,
294 ClearExternalTimer
= 0xA1,
295 SetAnalogueTimer
= 0x34,
296 SetDigitalTimer
= 0x97,
297 SetExternalTimer
= 0xA2,
298 SetTimerProgramTitle
= 0x67,
299 TimerClearedStatus
= 0x43,
302 GetCecVersion
= 0x9F,
303 GivePhysicalAddress
= 0x83,
304 GetMenuLanguage
= 0x91,
305 ReportPhysicalAddress
= 0x84,
306 SetMenuLanguage
= 0x32,
309 GiveDeckStatus
= 0x1A,
311 GiveTunerDeviceStatus
= 0x08,
312 SelectAnalogueService
= 0x92,
313 SelectDigtalService
= 0x93,
314 TunerDeviceStatus
= 0x07,
315 TunerStepDecrement
= 0x06,
316 TunerStepIncrement
= 0x05,
317 DeviceVendorId
= 0x87,
318 GiveDeviceVendorId
= 0x8C,
319 VendorCommand
= 0x89,
320 VendorCommandWithId
= 0xA0,
321 VendorRemoteButtonDown
= 0x8A,
322 VendorRemoteButtonUp
= 0x8B,
328 UserControlPressed
= 0x44,
329 UserControlRelease
= 0x45,
330 GiveDevicePowerStatus
= 0x8F,
331 ReportPowerStatus
= 0x90,
334 GiveAudioStatus
= 0x71,
335 GiveSystemAudioMode
= 0x7D,
336 ReportAudioStatus
= 0x7A,
337 SetSystemAudioMode
= 0x72,
338 SystemAudioModeRequest
= 0x70,
339 SystemAudioModeStatus
= 0x7E,
341 /* when this opcode is set, no opcode will be sent to the device. this is one of the reserved numbers */
345 public enum class CecSystemAudioStatus
351 public enum class CecClientVersion
354 Version1_5_0
= 0x1500,
355 Version1_5_1
= 0x1501,
356 Version1_5_2
= 0x1502,
357 Version1_5_3
= 0x1503,
358 Version1_6_0
= 0x1600,
359 Version1_6_1
= 0x1601,
360 Version1_6_2
= 0x1602,
361 Version1_6_3
= 0x1603,
362 Version1_7_0
= 0x1700,
363 Version1_7_1
= 0x1701
366 public enum class CecServerVersion
369 Version1_5_0
= 0x1500,
370 Version1_5_1
= 0x1501,
371 Version1_5_2
= 0x1502,
372 Version1_5_3
= 0x1503,
373 Version1_6_0
= 0x1600,
374 Version1_6_1
= 0x1601,
375 Version1_6_2
= 0x1602,
376 Version1_6_3
= 0x1603,
377 Version1_7_0
= 0x1700,
378 Version1_7_1
= 0x1701
381 public ref
class CecAdapter
384 CecAdapter(System::String
^ strPath
, System::String
^ strComPort
)
387 ComPort
= strComPort
;
390 property
System::String
^ Path
;
391 property
System::String
^ ComPort
;
394 public ref
class CecDeviceTypeList
397 CecDeviceTypeList(void)
399 Types
= gcnew array
<CecDeviceType
>(5);
400 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
401 Types
[iPtr
] = CecDeviceType::Reserved
;
404 property array
<CecDeviceType
> ^ Types
;
407 public ref
class CecLogicalAddresses
410 CecLogicalAddresses(void)
412 Addresses
= gcnew array
<CecLogicalAddress
>(16);
418 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
419 Addresses
[iPtr
] = CecLogicalAddress::Unknown
;
422 bool IsSet(CecLogicalAddress iAddress
)
424 return Addresses
[(unsigned int)iAddress
] != CecLogicalAddress::Unknown
;
427 void Set(CecLogicalAddress iAddress
)
429 Addresses
[(unsigned int)iAddress
] = iAddress
;
432 property CecLogicalAddress Primary
;
433 property array
<CecLogicalAddress
> ^ Addresses
;
436 public ref
class CecDatapacket
441 Data
= gcnew array
<uint8_t>(100);
445 void PushBack(uint8_t data
)
454 property array
<uint8_t> ^ Data
;
455 property
uint8_t Size
;
458 public ref
class CecCommand
461 CecCommand(CecLogicalAddress iInitiator
, CecLogicalAddress iDestination
, bool bAck
, bool bEom
, CecOpcode iOpcode
, int32_t iTransmitTimeout
)
463 Initiator
= iInitiator
;
464 Destination
= iDestination
;
469 TransmitTimeout
= iTransmitTimeout
;
470 Parameters
= gcnew CecDatapacket
;
476 Initiator
= CecLogicalAddress::Unknown
;
477 Destination
= CecLogicalAddress::Unknown
;
480 Opcode
= CecOpcode::None
;
483 Parameters
= gcnew CecDatapacket
;
487 void PushBack(uint8_t data
)
489 if (Initiator
== CecLogicalAddress::Unknown
&& Destination
== CecLogicalAddress::Unknown
)
491 Initiator
= (CecLogicalAddress
) (data
>> 4);
492 Destination
= (CecLogicalAddress
) (data
& 0xF);
497 Opcode
= (CecOpcode
)data
;
501 Parameters
->PushBack(data
);
506 property CecLogicalAddress Initiator
;
507 property CecLogicalAddress Destination
;
510 property CecOpcode Opcode
;
511 property CecDatapacket
^ Parameters
;
512 property
bool OpcodeSet
;
513 property
int32_t TransmitTimeout
;
516 public ref
class CecKeypress
519 CecKeypress(CecUserControlCode iKeycode
, unsigned int iDuration
)
522 Duration
= iDuration
;
528 Keycode
= CecUserControlCode::Unknown
;
534 property CecUserControlCode Keycode
;
535 property
unsigned int Duration
;
538 public ref
class CecLogMessage
541 CecLogMessage(System::String
^ strMessage
, CecLogLevel iLevel
, int64_t iTime
)
543 Message
= strMessage
;
552 Level
= CecLogLevel::None
;
558 property
System::String
^Message
;
559 property CecLogLevel Level
;
560 property
int64_t Time
;
563 ref
class CecCallbackMethods
; //forward
564 public ref
class LibCECConfiguration
567 LibCECConfiguration(void)
570 DeviceTypes
= gcnew
CecDeviceTypeList();
571 AutodetectAddress
= true;
572 PhysicalAddress
= CEC_DEFAULT_PHYSICAL_ADDRESS
;
573 BaseDevice
= (CecLogicalAddress
)CEC_DEFAULT_BASE_DEVICE
;
574 HDMIPort
= CEC_DEFAULT_HDMI_PORT
;
575 ClientVersion
= CecClientVersion::VersionPre1_5
;
576 ServerVersion
= CecServerVersion::VersionPre1_5
;
577 TvVendor
= CecVendorId::Unknown
;
579 GetSettingsFromROM
= false;
580 UseTVMenuLanguage
= CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE
== 1;
581 ActivateSource
= CEC_DEFAULT_SETTING_ACTIVATE_SOURCE
== 1;
583 WakeDevices
= gcnew
CecLogicalAddresses();
584 if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE
== 1)
585 WakeDevices
->Set(CecLogicalAddress::Tv
);
587 PowerOffDevices
= gcnew
CecLogicalAddresses();
588 if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN
== 1)
589 PowerOffDevices
->Set(CecLogicalAddress::Broadcast
);
591 PowerOffScreensaver
= CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER
== 1;
592 PowerOffOnStandby
= CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY
== 1;
594 SendInactiveSource
= CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE
== 1;
595 LogicalAddresses
= gcnew
CecLogicalAddresses();
597 PowerOffDevicesOnStandby
= CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY
== 1;
598 ShutdownOnStandby
= CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY
== 1;
602 void SetCallbacks(CecCallbackMethods
^callbacks
)
604 Callbacks
= callbacks
;
607 void Update(const CEC::libcec_configuration
&config
)
609 DeviceName
= gcnew
System::String(config
.strDeviceName
);
611 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
612 DeviceTypes
->Types
[iPtr
] = (CecDeviceType
)config
.deviceTypes
.types
[iPtr
];
614 AutodetectAddress
= config
.bAutodetectAddress
== 1;
615 PhysicalAddress
= config
.iPhysicalAddress
;
616 BaseDevice
= (CecLogicalAddress
)config
.baseDevice
;
617 HDMIPort
= config
.iHDMIPort
;
618 ClientVersion
= (CecClientVersion
)config
.clientVersion
;
619 ServerVersion
= (CecServerVersion
)config
.serverVersion
;
620 TvVendor
= (CecVendorId
)config
.tvVendor
;
622 // player specific settings
623 GetSettingsFromROM
= config
.bGetSettingsFromROM
== 1;
624 UseTVMenuLanguage
= config
.bUseTVMenuLanguage
== 1;
625 ActivateSource
= config
.bActivateSource
== 1;
627 WakeDevices
->Clear();
628 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
629 if (config
.wakeDevices
[iPtr
])
630 WakeDevices
->Set((CecLogicalAddress
)iPtr
);
632 PowerOffDevices
->Clear();
633 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
634 if (config
.powerOffDevices
[iPtr
])
635 PowerOffDevices
->Set((CecLogicalAddress
)iPtr
);
637 PowerOffScreensaver
= config
.bPowerOffScreensaver
== 1;
638 PowerOffOnStandby
= config
.bPowerOffOnStandby
== 1;
640 if (ServerVersion
>= CecServerVersion::Version1_5_1
)
641 SendInactiveSource
= config
.bSendInactiveSource
== 1;
643 if (ServerVersion
>= CecServerVersion::Version1_5_3
)
645 LogicalAddresses
->Clear();
646 for (uint8_t iPtr
= 0; iPtr
<= 16; iPtr
++)
647 if (config
.logicalAddresses
[iPtr
])
648 LogicalAddresses
->Set((CecLogicalAddress
)iPtr
);
651 if (ServerVersion
>= CecServerVersion::Version1_6_0
)
653 FirmwareVersion
= config
.iFirmwareVersion
;
654 PowerOffDevicesOnStandby
= config
.bPowerOffDevicesOnStandby
== 1;
655 ShutdownOnStandby
= config
.bShutdownOnStandby
== 1;
658 if (ServerVersion
>= CecServerVersion::Version1_6_2
)
659 DeviceLanguage
= gcnew
System::String(config
.strDeviceLanguage
);
661 if (ServerVersion
>= CecServerVersion::Version1_6_3
)
662 MonitorOnlyClient
= config
.bMonitorOnly
== 1;
665 property
System::String
^ DeviceName
;
666 property CecDeviceTypeList
^ DeviceTypes
;
667 property
bool AutodetectAddress
;
668 property
uint16_t PhysicalAddress
;
669 property CecLogicalAddress BaseDevice
;
670 property
uint8_t HDMIPort
;
671 property CecClientVersion ClientVersion
;
672 property CecServerVersion ServerVersion
;
673 property CecVendorId TvVendor
;
675 // player specific settings
676 property
bool GetSettingsFromROM
;
677 property
bool UseTVMenuLanguage
;
678 property
bool ActivateSource
;
679 property CecLogicalAddresses
^WakeDevices
;
680 property CecLogicalAddresses
^PowerOffDevices
;
681 property
bool PowerOffScreensaver
;
682 property
bool PowerOffOnStandby
;
683 property
bool SendInactiveSource
;
684 property CecLogicalAddresses
^LogicalAddresses
;
685 property
uint16_t FirmwareVersion
;
686 property
bool PowerOffDevicesOnStandby
;
687 property
bool ShutdownOnStandby
;
688 property
bool MonitorOnlyClient
;
689 property
System::String
^ DeviceLanguage
;
690 property CecCallbackMethods
^ Callbacks
;
693 // the callback methods are called by unmanaged code, so we need some delegates for this
695 // unmanaged callback methods
696 typedef int (__stdcall
*LOGCB
) (const CEC::cec_log_message
&message
);
697 typedef int (__stdcall
*KEYCB
) (const CEC::cec_keypress
&key
);
698 typedef int (__stdcall
*COMMANDCB
)(const CEC::cec_command
&command
);
699 typedef int (__stdcall
*CONFIGCB
) (const CEC::libcec_configuration
&config
);
700 typedef int (__stdcall
*ALERTCB
) (const CEC::libcec_alert
, const CEC::libcec_parameter
&data
);
701 typedef int (__stdcall
*MENUCB
) (const CEC::cec_menu_state newVal
);
702 typedef void (__stdcall
*ACTICB
) (const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
);
712 ACTICB sourceActivatedCB
;
713 } UnmanagedCecCallbacks
;
715 static PLATFORM::CMutex g_callbackMutex
;
716 static std::vector
<UnmanagedCecCallbacks
> g_unmanagedCallbacks
;
717 static CEC::ICECCallbacks g_cecCallbacks
;
719 int CecLogMessageCB(void *cbParam
, const CEC::cec_log_message
&message
)
723 size_t iPtr
= (size_t)cbParam
;
724 PLATFORM::CLockObject
lock(g_callbackMutex
);
725 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
726 return g_unmanagedCallbacks
[iPtr
].logCB(message
);
731 int CecKeyPressCB(void *cbParam
, const CEC::cec_keypress
&key
)
735 size_t iPtr
= (size_t)cbParam
;
736 PLATFORM::CLockObject
lock(g_callbackMutex
);
737 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
738 return g_unmanagedCallbacks
[iPtr
].keyCB(key
);
743 int CecCommandCB(void *cbParam
, const CEC::cec_command
&command
)
747 size_t iPtr
= (size_t)cbParam
;
748 PLATFORM::CLockObject
lock(g_callbackMutex
);
749 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
750 return g_unmanagedCallbacks
[iPtr
].commandCB(command
);
755 int CecConfigCB(void *cbParam
, const CEC::libcec_configuration
&config
)
759 size_t iPtr
= (size_t)cbParam
;
760 PLATFORM::CLockObject
lock(g_callbackMutex
);
761 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
762 return g_unmanagedCallbacks
[iPtr
].configCB(config
);
767 int CecAlertCB(void *cbParam
, const CEC::libcec_alert alert
, const CEC::libcec_parameter
&data
)
771 size_t iPtr
= (size_t)cbParam
;
772 PLATFORM::CLockObject
lock(g_callbackMutex
);
773 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
774 return g_unmanagedCallbacks
[iPtr
].alertCB(alert
, data
);
779 int CecMenuCB(void *cbParam
, const CEC::cec_menu_state newVal
)
783 size_t iPtr
= (size_t)cbParam
;
784 PLATFORM::CLockObject
lock(g_callbackMutex
);
785 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
786 return g_unmanagedCallbacks
[iPtr
].menuCB(newVal
);
791 void CecSourceActivatedCB(void *cbParam
, const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
)
795 size_t iPtr
= (size_t)cbParam
;
796 PLATFORM::CLockObject
lock(g_callbackMutex
);
797 if (iPtr
>= 0 && iPtr
< g_unmanagedCallbacks
.size())
798 g_unmanagedCallbacks
[iPtr
].sourceActivatedCB(logicalAddress
, bActivated
);
803 // delegates for the unmanaged callback methods
804 public delegate
int CecLogMessageManagedDelegate(const CEC::cec_log_message
&);
805 public delegate
int CecKeyPressManagedDelegate(const CEC::cec_keypress
&);
806 public delegate
int CecCommandManagedDelegate(const CEC::cec_command
&);
807 public delegate
int CecConfigManagedDelegate(const CEC::libcec_configuration
&);
808 public delegate
int CecAlertManagedDelegate(const CEC::libcec_alert
, const CEC::libcec_parameter
&);
809 public delegate
int CecMenuManagedDelegate(const CEC::cec_menu_state newVal
);
810 public delegate
void CecSourceActivatedManagedDelegate(const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
);
812 void AssignCallbacks()
814 g_cecCallbacks
.CBCecLogMessage
= CecLogMessageCB
;
815 g_cecCallbacks
.CBCecKeyPress
= CecKeyPressCB
;
816 g_cecCallbacks
.CBCecCommand
= CecCommandCB
;
817 g_cecCallbacks
.CBCecConfigurationChanged
= CecConfigCB
;
818 g_cecCallbacks
.CBCecAlert
= CecAlertCB
;
819 g_cecCallbacks
.CBCecMenuStateChanged
= CecMenuCB
;
820 g_cecCallbacks
.CBCecSourceActivated
= CecSourceActivatedCB
;
823 // callback method interface
824 public ref
class CecCallbackMethods
827 CecCallbackMethods(void)
831 m_bHasCallbacks
= false;
832 m_bDelegatesCreated
= false;
835 ~CecCallbackMethods(void)
840 size_t GetCallbackPtr(void)
842 PLATFORM::CLockObject
lock(g_callbackMutex
);
843 return m_iCallbackPtr
;
847 !CecCallbackMethods(void)
853 virtual void DisableCallbacks(void)
858 virtual bool EnableCallbacks(CecCallbackMethods
^ callbacks
)
861 if (!m_bHasCallbacks
)
863 m_bHasCallbacks
= true;
864 m_callbacks
= callbacks
;
871 virtual int ReceiveLogMessage(CecLogMessage
^ message
)
876 virtual int ReceiveKeypress(CecKeypress
^ key
)
881 virtual int ReceiveCommand(CecCommand
^ command
)
886 virtual int ConfigurationChanged(LibCECConfiguration
^ config
)
891 virtual int ReceiveAlert(CecAlert alert
, CecParameter
^ data
)
896 virtual int ReceiveMenuStateChange(CecMenuState newVal
)
901 virtual void SourceActivated(CecLogicalAddress logicalAddress
, bool bActivated
)
906 // managed callback methods
907 int CecLogMessageManaged(const CEC::cec_log_message
&message
)
911 iReturn
= m_callbacks
->ReceiveLogMessage(gcnew
CecLogMessage(gcnew
System::String(message
.message
), (CecLogLevel
)message
.level
, message
.time
));
915 int CecKeyPressManaged(const CEC::cec_keypress
&key
)
919 iReturn
= m_callbacks
->ReceiveKeypress(gcnew
CecKeypress((CecUserControlCode
)key
.keycode
, key
.duration
));
923 int CecCommandManaged(const CEC::cec_command
&command
)
928 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
);
929 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
930 newCommand
->Parameters
->PushBack(command
.parameters
[iPtr
]);
931 iReturn
= m_callbacks
->ReceiveCommand(newCommand
);
936 int CecConfigManaged(const CEC::libcec_configuration
&config
)
941 LibCECConfiguration
^netConfig
= gcnew
LibCECConfiguration();
942 netConfig
->Update(config
);
943 iReturn
= m_callbacks
->ConfigurationChanged(netConfig
);
948 int CecAlertManaged(const CEC::libcec_alert alert
, const CEC::libcec_parameter
&data
)
953 CecParameterType newType
= (CecParameterType
)data
.paramType
;
954 if (newType
== CecParameterType::ParameterTypeString
)
956 System::String
^ newData
= gcnew
System::String((const char *)data
.paramData
, 0, 128);
957 CecParameter
^ newParam
= gcnew
CecParameter(newType
, newData
);
958 iReturn
= m_callbacks
->ReceiveAlert((CecAlert
)alert
, newParam
);
964 int CecMenuManaged(const CEC::cec_menu_state newVal
)
969 iReturn
= m_callbacks
->ReceiveMenuStateChange((CecMenuState
)newVal
);
974 void CecSourceActivatedManaged(const CEC::cec_logical_address logicalAddress
, const uint8_t bActivated
)
977 m_callbacks
->SourceActivated((CecLogicalAddress
)logicalAddress
, bActivated
== 1);
980 void DestroyDelegates()
982 m_bHasCallbacks
= false;
983 if (m_bDelegatesCreated
)
985 m_bDelegatesCreated
= false;
986 m_logMessageGCHandle
.Free();
987 m_keypressGCHandle
.Free();
988 m_commandGCHandle
.Free();
989 m_alertGCHandle
.Free();
990 m_menuGCHandle
.Free();
991 m_sourceActivatedGCHandle
.Free();
995 void CreateDelegates()
999 if (!m_bDelegatesCreated
)
1001 msclr::interop::marshal_context
^ context
= gcnew
msclr::interop::marshal_context();
1003 // create the delegate method for the log message callback
1004 m_logMessageDelegate
= gcnew
CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged
);
1005 m_logMessageGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate
);
1006 m_logMessageCallback
= static_cast<LOGCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate
).ToPointer());
1008 // create the delegate method for the keypress callback
1009 m_keypressDelegate
= gcnew
CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged
);
1010 m_keypressGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate
);
1011 m_keypressCallback
= static_cast<KEYCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate
).ToPointer());
1013 // create the delegate method for the command callback
1014 m_commandDelegate
= gcnew
CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged
);
1015 m_commandGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate
);
1016 m_commandCallback
= static_cast<COMMANDCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate
).ToPointer());
1018 // create the delegate method for the configuration change callback
1019 m_configDelegate
= gcnew
CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged
);
1020 m_configGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate
);
1021 m_configCallback
= static_cast<CONFIGCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate
).ToPointer());
1023 // create the delegate method for the alert callback
1024 m_alertDelegate
= gcnew
CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged
);
1025 m_alertGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate
);
1026 m_alertCallback
= static_cast<ALERTCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate
).ToPointer());
1028 // create the delegate method for the menu callback
1029 m_menuDelegate
= gcnew
CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged
);
1030 m_menuGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate
);
1031 m_menuCallback
= static_cast<MENUCB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate
).ToPointer());
1033 // create the delegate method for the source activated callback
1034 m_sourceActivatedDelegate
= gcnew
CecSourceActivatedManagedDelegate(this, &CecCallbackMethods::CecSourceActivatedManaged
);
1035 m_sourceActivatedGCHandle
= System::Runtime::InteropServices::GCHandle::Alloc(m_sourceActivatedDelegate
);
1036 m_sourceActivatedCallback
= static_cast<ACTICB
>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_sourceActivatedDelegate
).ToPointer());
1040 UnmanagedCecCallbacks unmanagedCallbacks
;
1041 unmanagedCallbacks
.logCB
= m_logMessageCallback
;
1042 unmanagedCallbacks
.keyCB
= m_keypressCallback
;
1043 unmanagedCallbacks
.commandCB
= m_commandCallback
;
1044 unmanagedCallbacks
.configCB
= m_configCallback
;
1045 unmanagedCallbacks
.alertCB
= m_alertCallback
;
1046 unmanagedCallbacks
.menuCB
= m_menuCallback
;
1047 unmanagedCallbacks
.sourceActivatedCB
= m_sourceActivatedCallback
;
1049 PLATFORM::CLockObject
lock(g_callbackMutex
);
1050 g_unmanagedCallbacks
.push_back(unmanagedCallbacks
);
1051 m_iCallbackPtr
= g_unmanagedCallbacks
.size() - 1;
1052 m_bDelegatesCreated
= true;
1056 CecLogMessageManagedDelegate
^ m_logMessageDelegate
;
1057 static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle
;
1058 LOGCB m_logMessageCallback
;
1060 CecKeyPressManagedDelegate
^ m_keypressDelegate
;
1061 static System::Runtime::InteropServices::GCHandle m_keypressGCHandle
;
1062 KEYCB m_keypressCallback
;
1064 CecCommandManagedDelegate
^ m_commandDelegate
;
1065 static System::Runtime::InteropServices::GCHandle m_commandGCHandle
;
1066 COMMANDCB m_commandCallback
;
1068 CecConfigManagedDelegate
^ m_configDelegate
;
1069 static System::Runtime::InteropServices::GCHandle m_configGCHandle
;
1070 CONFIGCB m_configCallback
;
1072 CecAlertManagedDelegate
^ m_alertDelegate
;
1073 static System::Runtime::InteropServices::GCHandle m_alertGCHandle
;
1074 ALERTCB m_alertCallback
;
1076 CecMenuManagedDelegate
^ m_menuDelegate
;
1077 static System::Runtime::InteropServices::GCHandle m_menuGCHandle
;
1078 MENUCB m_menuCallback
;
1080 CecSourceActivatedManagedDelegate
^ m_sourceActivatedDelegate
;
1081 static System::Runtime::InteropServices::GCHandle m_sourceActivatedGCHandle
;
1082 ACTICB m_sourceActivatedCallback
;
1084 CecCallbackMethods
^ m_callbacks
;
1085 bool m_bHasCallbacks
;
1086 bool m_bDelegatesCreated
;
1087 size_t m_iCallbackPtr
;