X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FLibCecSharp%2FCecSharpTypes.h;h=8cdaa89a0e9e797f2931fedb936534c3009a2bd2;hb=2e82cff0a171a476e5d323ca95749d214e90df59;hp=2c158a5d64dbdb7b78c919c58c55a28cf37e4419;hpb=d93fd39688099e9ff782896ce6cfa2520daa593a;p=deb_libcec.git diff --git a/src/LibCecSharp/CecSharpTypes.h b/src/LibCecSharp/CecSharpTypes.h index 2c158a5..8cdaa89 100644 --- a/src/LibCecSharp/CecSharpTypes.h +++ b/src/LibCecSharp/CecSharpTypes.h @@ -236,6 +236,7 @@ namespace CecSharp Onkyo = 0x09B0, Yamaha = 0xA0DE, Philips = 0x903E, + Sony = 0x080046, Unknown = 0 }; @@ -325,7 +326,17 @@ namespace CecSharp public enum class CecClientVersion { VersionPre1_5 = 0, - Version1_5_0 = 1 + Version1_5_0 = 0x1500, + Version1_5_1 = 0x1501, + Version1_5_2 = 0x1502 + }; + + public enum class CecServerVersion + { + VersionPre1_5 = 0, + Version1_5_0 = 0x1500, + Version1_5_1 = 0x1501, + Version1_5_2 = 0x1502 }; public ref class CecAdapter @@ -360,15 +371,26 @@ namespace CecSharp CecLogicalAddresses(void) { Addresses = gcnew array(16); + Clear(); + } + + void Clear(void) + { for (unsigned int iPtr = 0; iPtr < 16; iPtr++) - Addresses[iPtr] = CecLogicalAddress::Unregistered; + Addresses[iPtr] = CecLogicalAddress::Unknown; } bool IsSet(CecLogicalAddress iAddress) { - return Addresses[(unsigned int)iAddress] != CecLogicalAddress::Unregistered; + return Addresses[(unsigned int)iAddress] != CecLogicalAddress::Unknown; + } + + void Set(CecLogicalAddress iAddress) + { + Addresses[(unsigned int)iAddress] = iAddress; } + property CecLogicalAddress Primary; property array ^ Addresses; }; @@ -499,16 +521,114 @@ namespace CecSharp property int64_t Time; }; + ref class CecCallbackMethods; //forward + public ref class LibCECConfiguration + { + public: + LibCECConfiguration(void) + { + 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; + UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE == 1; + ActivateSource = CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1; + + WakeDevices = gcnew CecLogicalAddresses(); + if (CEC_DEFAULT_SETTING_ACTIVATE_SOURCE == 1) + WakeDevices->Set(CecLogicalAddress::Tv); + + PowerOffDevices = gcnew CecLogicalAddresses(); + if (CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN == 1) + PowerOffDevices->Set(CecLogicalAddress::Broadcast); + + 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; + } + + void SetCallbacks(CecCallbackMethods ^callbacks) + { + 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; + SendInactiveSource = config.bSendInactiveSource == 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 + property bool GetSettingsFromROM; + property bool UseTVMenuLanguage; + property bool ActivateSource; + property CecLogicalAddresses ^WakeDevices; + property CecLogicalAddresses ^PowerOffDevices; + property bool PowerOffScreensaver; + property bool PowerOffOnStandby; + property bool SendInactiveSource; + + property CecCallbackMethods ^ Callbacks; + }; + // the callback methods are called by unmanaged code, so we need some delegates for this #pragma unmanaged // unmanaged callback methods typedef int (__stdcall *LOGCB) (const CEC::cec_log_message &message); 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); static LOGCB g_logCB; static KEYCB g_keyCB; static COMMANDCB g_commandCB; + static CONFIGCB g_configCB; static CEC::ICECCallbacks g_cecCallbacks; int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message) @@ -532,41 +652,29 @@ namespace CecSharp return 0; } + int CecConfigCB(void *cbParam, const CEC::libcec_configuration &config) + { + if (g_configCB) + return g_configCB(config); + 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 &); // 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; - - delete context; - } + CecCallbackMethods(void) + { + m_bHasCallbacks = false; + m_bDelegatesCreated = false; + } ~CecCallbackMethods(void) { @@ -580,8 +688,14 @@ namespace CecSharp } public: + virtual void DisableCallbacks(void) + { + DestroyDelegates(); + } + virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) { + CreateDelegates(); if (!m_bHasCallbacks) { m_bHasCallbacks = true; @@ -607,6 +721,10 @@ namespace CecSharp return 0; } + virtual int ConfigurationChanged(LibCECConfiguration ^ config) + { + return 0; + } protected: // managed callback methods int CecLogMessageManaged(const CEC::cec_log_message &message) @@ -638,15 +756,67 @@ namespace CecSharp return iReturn; } + int CecConfigManaged(const CEC::libcec_configuration &config) + { + int iReturn(0); + if (m_bHasCallbacks) + { + LibCECConfiguration ^netConfig = gcnew LibCECConfiguration(); + netConfig->Update(config); + iReturn = m_callbacks->ConfigurationChanged(netConfig); + } + return iReturn; + } + void DestroyDelegates() { - m_bHasCallbacks = false; - delete m_callbacks; - m_logMessageGCHandle.Free(); - m_keypressGCHandle.Free(); - m_commandGCHandle.Free(); + m_bHasCallbacks = false; + if (m_bDelegatesCreated) + { + m_bDelegatesCreated = false; + m_logMessageGCHandle.Free(); + m_keypressGCHandle.Free(); + m_commandGCHandle.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; + + delete context; + m_bDelegatesCreated = true; + } + } + CecLogMessageManagedDelegate ^ m_logMessageDelegate; static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle; LOGCB m_logMessageCallback; @@ -659,50 +829,12 @@ namespace CecSharp static System::Runtime::InteropServices::GCHandle m_commandGCHandle; COMMANDCB m_commandCallback; + CecConfigManagedDelegate ^ m_configDelegate; + static System::Runtime::InteropServices::GCHandle m_configGCHandle; + CONFIGCB m_configCallback; + CecCallbackMethods ^ m_callbacks; bool m_bHasCallbacks; - }; - - public ref class LibCECConfiguration - { - public: - LibCECConfiguration(void) - { - DeviceName = ""; - DeviceTypes = gcnew CecDeviceTypeList(); - PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS; - BaseDevice = (CecLogicalAddress)CEC_DEFAULT_BASE_DEVICE; - HDMIPort = CEC_DEFAULT_HDMI_PORT; - ClientVersion = CecClientVersion::VersionPre1_5; - - GetSettingsFromROM = false; - UseTVMenuLanguage = CEC_DEFAULT_SETTING_USE_TV_MENU_LANGUAGE ? true : false; - PowerOnStartup = CEC_DEFAULT_SETTING_POWER_ON_STARTUP ? true : false; - PowerOffShutdown = CEC_DEFAULT_SETTING_POWER_OFF_SHUTDOWN ? true : false; - PowerOffScreensaver = CEC_DEFAULT_SETTING_POWER_OFF_SCREENSAVER ? true : false; - PowerOffOnStandby = CEC_DEFAULT_SETTING_POWER_OFF_ON_STANDBY ? true : false; - } - - void SetCallbacks(CecCallbackMethods ^callbacks) - { - Callbacks = callbacks; - } - - property System::String ^ DeviceName; - property CecDeviceTypeList ^ DeviceTypes; - property uint16_t PhysicalAddress; - property CecLogicalAddress BaseDevice; - property uint8_t HDMIPort; - property CecClientVersion ClientVersion; - - // player specific settings - property bool GetSettingsFromROM; - property bool UseTVMenuLanguage; - property bool PowerOnStartup; - property bool PowerOffShutdown; - property bool PowerOffScreensaver; - property bool PowerOffOnStandby; - - property CecCallbackMethods ^Callbacks; + bool m_bDelegatesCreated; }; }