X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FLibCecSharp%2FCecSharpTypes.h;h=9be7ab5b87b64285b63e5bde5290a3e51f86e4ba;hb=142d9730b03e137b8cf5b11c2435e5544ea235dc;hp=f385cdaa15264402487328daf2f608bfaffc7c2d;hpb=63851508ba8fac60c03c1899bf98595481a161c5;p=deb_libcec.git diff --git a/src/LibCecSharp/CecSharpTypes.h b/src/LibCecSharp/CecSharpTypes.h index f385cda..9be7ab5 100644 --- a/src/LibCecSharp/CecSharpTypes.h +++ b/src/LibCecSharp/CecSharpTypes.h @@ -83,6 +83,29 @@ namespace CecSharp Broadcast = 15 }; + public enum class CecAlert + { + ServiceDevice = 1 + }; + + public enum class CecParameterType + { + ParameterTypeString = 1 + }; + + public ref class CecParameter + { + public: + CecParameter(CecParameterType type, System::String ^ strData) + { + Type = type; + Data = strData; + } + + property CecParameterType Type; + property System::String ^ Data; + }; + public enum class CecPowerStatus { On = 0x00, @@ -224,6 +247,7 @@ namespace CecSharp F5 = 0x75, Data = 0x76, Max = 0x76, + SamsungReturn = 0x91, Unknown }; @@ -326,7 +350,29 @@ namespace CecSharp public enum class CecClientVersion { VersionPre1_5 = 0, - Version1_5_0 = 0x1500 + Version1_5_0 = 0x1500, + Version1_5_1 = 0x1501, + Version1_5_2 = 0x1502, + Version1_5_3 = 0x1503, + Version1_6_0 = 0x1600, + Version1_6_1 = 0x1601, + Version1_6_2 = 0x1602, + Version1_6_3 = 0x1603, + Version1_7_0 = 0x1700 + }; + + public enum class CecServerVersion + { + VersionPre1_5 = 0, + Version1_5_0 = 0x1500, + Version1_5_1 = 0x1501, + Version1_5_2 = 0x1502, + Version1_5_3 = 0x1503, + Version1_6_0 = 0x1600, + Version1_6_1 = 0x1601, + Version1_6_2 = 0x1602, + Version1_6_3 = 0x1603, + Version1_7_0 = 0x1700 }; public ref class CecAdapter @@ -467,7 +513,7 @@ namespace CecSharp public ref class CecKeypress { public: - CecKeypress(int iKeycode, unsigned int iDuration) + CecKeypress(CecUserControlCode iKeycode, unsigned int iDuration) { Keycode = iKeycode; Duration = iDuration; @@ -476,14 +522,14 @@ namespace CecSharp CecKeypress(void) { - Keycode = 0; + Keycode = CecUserControlCode::Unknown; Duration = 0; Empty = true; } - property bool Empty; - property int Keycode; - property unsigned int Duration; + property bool Empty; + property CecUserControlCode Keycode; + property unsigned int Duration; }; public ref class CecLogMessage @@ -519,10 +565,12 @@ namespace CecSharp { DeviceName = ""; DeviceTypes = gcnew CecDeviceTypeList(); + AutodetectAddress = true; PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS; BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE; HDMIPort = CEC_DEFAULT_HDMI_PORT; ClientVersion = CecClientVersion::VersionPre1_5; + ServerVersion = CecServerVersion::VersionPre1_5; TvVendor = CecVendorId::Unknown; GetSettingsFromROM = false; @@ -539,6 +587,13 @@ namespace CecSharp PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER == 1; PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY == 1; + + SendInactiveSource = CEC_DEFAULT_SETTING_SEND_INACTIVE_SOURCE == 1; + LogicalAddresses = gcnew CecLogicalAddresses(); + FirmwareVersion = 1; + PowerOffDevicesOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_DEVICES_STANDBY == 1; + ShutdownOnStandby = CEC_DEFAULT_SETTING_SHUTDOWN_ON_STANDBY == 1; + DeviceLanguage = ""; } void SetCallbacks(CecCallbackMethods ^callbacks) @@ -546,12 +601,72 @@ namespace CecSharp Callbacks = callbacks; } + void Update(const CEC::libcec_configuration &config) + { + DeviceName = gcnew System::String(config.strDeviceName); + + for (unsigned int iPtr = 0; iPtr < 5; iPtr++) + DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr]; + + AutodetectAddress = config.bAutodetectAddress == 1; + PhysicalAddress = config.iPhysicalAddress; + BaseDevice = (CecLogicalAddress)config.baseDevice; + HDMIPort = config.iHDMIPort; + ClientVersion = (CecClientVersion)config.clientVersion; + ServerVersion = (CecServerVersion)config.serverVersion; + TvVendor = (CecVendorId)config.tvVendor; + + // player specific settings + GetSettingsFromROM = config.bGetSettingsFromROM == 1; + UseTVMenuLanguage = config.bUseTVMenuLanguage == 1; + ActivateSource = config.bActivateSource == 1; + + WakeDevices->Clear(); + for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) + if (config.wakeDevices[iPtr]) + WakeDevices->Set((CecLogicalAddress)iPtr); + + PowerOffDevices->Clear(); + for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) + if (config.powerOffDevices[iPtr]) + PowerOffDevices->Set((CecLogicalAddress)iPtr); + + PowerOffScreensaver = config.bPowerOffScreensaver == 1; + PowerOffOnStandby = config.bPowerOffOnStandby == 1; + + if (ServerVersion >= CecServerVersion::Version1_5_1) + SendInactiveSource = config.bSendInactiveSource == 1; + + if (ServerVersion >= CecServerVersion::Version1_5_3) + { + LogicalAddresses->Clear(); + for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) + if (config.logicalAddresses[iPtr]) + LogicalAddresses->Set((CecLogicalAddress)iPtr); + } + + if (ServerVersion >= CecServerVersion::Version1_6_0) + { + FirmwareVersion = config.iFirmwareVersion; + PowerOffDevicesOnStandby = config.bPowerOffDevicesOnStandby == 1; + ShutdownOnStandby = config.bShutdownOnStandby == 1; + } + + if (ServerVersion >= CecServerVersion::Version1_6_2) + DeviceLanguage = gcnew System::String(config.strDeviceLanguage); + + if (ServerVersion >= CecServerVersion::Version1_6_3) + MonitorOnlyClient = config.bMonitorOnly == 1; + } + property System::String ^ DeviceName; property CecDeviceTypeList ^ DeviceTypes; + property bool AutodetectAddress; property uint16_t PhysicalAddress; property CecLogicalAddress BaseDevice; property uint8_t HDMIPort; property CecClientVersion ClientVersion; + property CecServerVersion ServerVersion; property CecVendorId TvVendor; // player specific settings @@ -562,7 +677,13 @@ namespace CecSharp property CecLogicalAddresses ^PowerOffDevices; property bool PowerOffScreensaver; property bool PowerOffOnStandby; - + property bool SendInactiveSource; + property CecLogicalAddresses ^LogicalAddresses; + property uint16_t FirmwareVersion; + property bool PowerOffDevicesOnStandby; + property bool ShutdownOnStandby; + property bool MonitorOnlyClient; + property System::String ^ DeviceLanguage; property CecCallbackMethods ^ Callbacks; }; @@ -573,11 +694,15 @@ namespace CecSharp typedef int (__stdcall *KEYCB) (const CEC::cec_keypress &key); typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command); typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config); + typedef int (__stdcall *ALERTCB) (const CEC::libcec_alert, const CEC::libcec_parameter &data); + typedef int (__stdcall *MENUCB) (const CEC::cec_menu_state newVal); static LOGCB g_logCB; static KEYCB g_keyCB; static COMMANDCB g_commandCB; static CONFIGCB g_configCB; + static ALERTCB g_alertCB; + static MENUCB g_menuCB; static CEC::ICECCallbacks g_cecCallbacks; int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message) @@ -608,48 +733,38 @@ namespace CecSharp return 0; } + int CecAlertCB(void *cbParam, const CEC::libcec_alert alert, const CEC::libcec_parameter &data) + { + if (g_alertCB) + return g_alertCB(alert, data); + return 0; + } + + int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal) + { + if (g_menuCB) + return g_menuCB(newVal); + return 0; + } + #pragma managed // delegates for the unmanaged callback methods public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &); public delegate int CecKeyPressManagedDelegate(const CEC::cec_keypress &); public delegate int CecCommandManagedDelegate(const CEC::cec_command &); public delegate int CecConfigManagedDelegate(const CEC::libcec_configuration &); + public delegate int CecAlertManagedDelegate(const CEC::libcec_alert, const CEC::libcec_parameter &); + public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state newVal); // callback method interface public ref class CecCallbackMethods { public: - CecCallbackMethods(void) - { - m_bHasCallbacks = false; - msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context(); - - // create the delegate method for the log message callback - m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged); - m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate); - g_logCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer()); - g_cecCallbacks.CBCecLogMessage = CecLogMessageCB; - - // create the delegate method for the keypress callback - m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged); - m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate); - g_keyCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer()); - g_cecCallbacks.CBCecKeyPress = CecKeyPressCB; - - // create the delegate method for the command callback - m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged); - m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate); - g_commandCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer()); - g_cecCallbacks.CBCecCommand = CecCommandCB; - - // create the delegate method for the configuration change callback - m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged); - m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate); - g_configCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer()); - g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB; - - delete context; - } + CecCallbackMethods(void) + { + m_bHasCallbacks = false; + m_bDelegatesCreated = false; + } ~CecCallbackMethods(void) { @@ -665,13 +780,12 @@ namespace CecSharp public: virtual void DisableCallbacks(void) { - if (m_bHasCallbacks) - delete m_callbacks; - m_bHasCallbacks = false; + DestroyDelegates(); } + virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) { - DisableCallbacks(); + CreateDelegates(); if (!m_bHasCallbacks) { m_bHasCallbacks = true; @@ -701,6 +815,17 @@ namespace CecSharp { return 0; } + + virtual int ReceiveAlert(CecAlert alert, CecParameter ^ data) + { + return 0; + } + + virtual int ReceiveMenuStateChange(CecMenuState newVal) + { + return 0; + } + protected: // managed callback methods int CecLogMessageManaged(const CEC::cec_log_message &message) @@ -715,7 +840,7 @@ namespace CecSharp { int iReturn(0); if (m_bHasCallbacks) - iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress(key.keycode, key.duration)); + iReturn = m_callbacks->ReceiveKeypress(gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration)); return iReturn; } @@ -738,47 +863,101 @@ namespace CecSharp if (m_bHasCallbacks) { LibCECConfiguration ^netConfig = gcnew LibCECConfiguration(); - netConfig->DeviceName = gcnew System::String(config.strDeviceName); - for (unsigned int iPtr = 0; iPtr < 5; iPtr++) - netConfig->DeviceTypes->Types[iPtr] = (CecDeviceType)config.deviceTypes.types[iPtr]; - - netConfig->PhysicalAddress = config.iPhysicalAddress; - netConfig->BaseDevice = (CecLogicalAddress)config.baseDevice; - netConfig->HDMIPort = config.iHDMIPort; - netConfig->ClientVersion = (CecClientVersion)config.clientVersion; - netConfig->GetSettingsFromROM = config.bGetSettingsFromROM == 1; - netConfig->ActivateSource = config.bActivateSource == 1; - - netConfig->WakeDevices->Clear(); - for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) - if (config.wakeDevices[iPtr]) - netConfig->WakeDevices->Set((CecLogicalAddress)iPtr); - - netConfig->PowerOffDevices->Clear(); - for (uint8_t iPtr = 0; iPtr <= 16; iPtr++) - if (config.powerOffDevices[iPtr]) - netConfig->PowerOffDevices->Set((CecLogicalAddress)iPtr); + netConfig->Update(config); + iReturn = m_callbacks->ConfigurationChanged(netConfig); + } + return iReturn; + } - netConfig->PowerOffScreensaver = config.bPowerOffScreensaver == 1; - netConfig->PowerOffOnStandby = config.bPowerOffOnStandby == 1; + int CecAlertManaged(const CEC::libcec_alert alert, const CEC::libcec_parameter &data) + { + int iReturn(0); + if (m_bHasCallbacks) + { + CecParameterType newType = (CecParameterType)data.paramType; + if (newType == CecParameterType::ParameterTypeString) + { + System::String ^ newData = gcnew System::String((const char *)data.paramData, 0, 128); + CecParameter ^ newParam = gcnew CecParameter(newType, newData); + iReturn = m_callbacks->ReceiveAlert((CecAlert)alert, newParam); + } + } + return iReturn; + } - iReturn = m_callbacks->ConfigurationChanged(netConfig); + int CecMenuManaged(const CEC::cec_menu_state newVal) + { + int iReturn(0); + if (m_bHasCallbacks) + { + iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal); } return iReturn; } void DestroyDelegates() { - if (m_bHasCallbacks) + m_bHasCallbacks = false; + if (m_bDelegatesCreated) { - m_bHasCallbacks = false; - delete m_callbacks; + m_bDelegatesCreated = false; m_logMessageGCHandle.Free(); m_keypressGCHandle.Free(); m_commandGCHandle.Free(); + m_alertGCHandle.Free(); + m_menuGCHandle.Free(); } } + void CreateDelegates() + { + DestroyDelegates(); + + if (!m_bDelegatesCreated) + { + msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context(); + + // create the delegate method for the log message callback + m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged); + m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate); + g_logCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer()); + g_cecCallbacks.CBCecLogMessage = CecLogMessageCB; + + // create the delegate method for the keypress callback + m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged); + m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate); + g_keyCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer()); + g_cecCallbacks.CBCecKeyPress = CecKeyPressCB; + + // create the delegate method for the command callback + m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged); + m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate); + g_commandCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer()); + g_cecCallbacks.CBCecCommand = CecCommandCB; + + // create the delegate method for the configuration change callback + m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged); + m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate); + g_configCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer()); + g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB; + + // create the delegate method for the alert callback + m_alertDelegate = gcnew CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged); + m_alertGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate); + g_alertCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer()); + g_cecCallbacks.CBCecAlert = CecAlertCB; + + // create the delegate method for the menu callback + m_menuDelegate = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged); + m_menuGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate); + g_menuCB = static_cast(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer()); + g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB; + + delete context; + m_bDelegatesCreated = true; + } + } + CecLogMessageManagedDelegate ^ m_logMessageDelegate; static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle; LOGCB m_logMessageCallback; @@ -795,7 +974,16 @@ namespace CecSharp static System::Runtime::InteropServices::GCHandle m_configGCHandle; CONFIGCB m_configCallback; + CecAlertManagedDelegate ^ m_alertDelegate; + static System::Runtime::InteropServices::GCHandle m_alertGCHandle; + CONFIGCB m_alertCallback; + + CecMenuManagedDelegate ^ m_menuDelegate; + static System::Runtime::InteropServices::GCHandle m_menuGCHandle; + MENUCB m_menuCallback; + CecCallbackMethods ^ m_callbacks; bool m_bHasCallbacks; + bool m_bDelegatesCreated; }; }