From: Lars Op den Kamp Date: Fri, 10 Feb 2012 11:24:43 +0000 (+0100) Subject: cec: added the new initialise method to LibCecSharp (as a new constructor) X-Git-Tag: upstream/2.2.0~1^2~35^2~116 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=41297a4573ccada540d0d2c3a6b63034866deab9;p=deb_libcec.git cec: added the new initialise method to LibCecSharp (as a new constructor) --- diff --git a/src/LibCecSharp/CecSharpTypes.h b/src/LibCecSharp/CecSharpTypes.h index 55c756e..975c71d 100644 --- a/src/LibCecSharp/CecSharpTypes.h +++ b/src/LibCecSharp/CecSharpTypes.h @@ -666,7 +666,7 @@ namespace CecSharp public ref class LibCECConfiguration { public: - LibCECConfiguration(CecCallbackMethods ^callbacks) + LibCECConfiguration(void) { DeviceName = ""; PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS; @@ -680,8 +680,11 @@ namespace CecSharp 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; + } - Callbacks = callbacks; + void SetCallbacks(CecCallbackMethods ^callbacks) + { + Callbacks = callbacks; } property System::String ^ DeviceName; diff --git a/src/LibCecSharp/LibCecSharp.cpp b/src/LibCecSharp/LibCecSharp.cpp index 92a4eee..61465e7 100644 --- a/src/LibCecSharp/LibCecSharp.cpp +++ b/src/LibCecSharp/LibCecSharp.cpp @@ -43,32 +43,68 @@ namespace CecSharp public ref class LibCecSharp : public CecCallbackMethods { public: + LibCecSharp(LibCECConfiguration ^config) + { + m_configuration = config; + m_configuration->SetCallbacks(this); + if (!InitialiseLibCec()) + throw gcnew Exception("Could not initialise LibCecSharp"); + } + LibCecSharp(String ^ strDeviceName, CecDeviceTypeList ^ deviceTypes) + { + m_configuration = gcnew LibCECConfiguration(); + m_configuration->SetCallbacks(this); + m_configuration->DeviceName = strDeviceName; + m_configuration->DeviceTypes = deviceTypes; + if (!InitialiseLibCec()) + throw gcnew Exception("Could not initialise LibCecSharp"); + } + + ~LibCecSharp(void) + { + Close(); + m_libCec = NULL; + } + + private: + !LibCecSharp(void) + { + Close(); + m_libCec = NULL; + } + + bool InitialiseLibCec(void) { marshal_context ^ context = gcnew marshal_context(); - m_bHasCallbacks = false; - const char* strDeviceNameC = context->marshal_as(strDeviceName); + libcec_configuration config; + GetConfiguration(context, config); - cec_device_type_list types; - for (unsigned int iPtr = 0; iPtr < 5; iPtr++) - types.types[iPtr] = (cec_device_type)deviceTypes->Types[iPtr]; - m_libCec = (ICECAdapter *) CECInit(strDeviceNameC, types); + m_libCec = (ICECAdapter *) CECInitialise(&config); delete context; + return m_libCec != NULL; + } + + void GetConfiguration(marshal_context ^context, libcec_configuration &config) + { + config.Clear(); + + _snprintf_s(config.strDeviceName, 13, context->marshal_as(m_configuration->DeviceName)); + for (unsigned int iPtr = 0; iPtr < 5; iPtr++) + config.deviceTypes.types[iPtr] = (cec_device_type)m_configuration->DeviceTypes->Types[iPtr]; + + config.iPhysicalAddress = m_configuration->PhysicalAddress; + config.baseDevice = (cec_logical_address)m_configuration->BaseDevice; + config.iHDMIPort = m_configuration->HDMIPort; + config.clientVersion = (cec_client_version)m_configuration->ClientVersion; + config.bGetSettingsFromROM = m_configuration->GetSettingsFromROM; + config.bPowerOnStartup = m_configuration->PowerOnStartup; + config.bPowerOffShutdown = m_configuration->PowerOffShutdown; + config.bPowerOffScreensaver = m_configuration->PowerOffScreensaver; + config.bPowerOffOnStandby = m_configuration->PowerOffOnStandby; + config.callbacks = &g_cecCallbacks; } - - ~LibCecSharp(void) - { - Close(); - m_libCec = NULL; - } - - protected: - !LibCecSharp(void) - { - Close(); - m_libCec = NULL; - } public: array ^ FindAdapters(String ^ path) @@ -414,5 +450,6 @@ namespace CecSharp private: ICECAdapter * m_libCec; + LibCECConfiguration ^m_configuration; }; }