cec: added the new initialise method to LibCecSharp (as a new constructor)
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 10 Feb 2012 11:24:43 +0000 (12:24 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 10 Feb 2012 11:24:43 +0000 (12:24 +0100)
src/LibCecSharp/CecSharpTypes.h
src/LibCecSharp/LibCecSharp.cpp

index 55c756ef874e05cf88f3011b99f69c4e9d8cc3e8..975c71d312b8376c80e8fa303642456c6353d51a 100644 (file)
@@ -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;
index 92a4eee84e18116a847b11bae513b238013941a1..61465e70e75c9bcc298d8fcb568ed215427771cb 100644 (file)
@@ -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<const char*>(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<const char*>(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<CecAdapter ^> ^ FindAdapters(String ^ path)
@@ -414,5 +450,6 @@ namespace CecSharp
 
        private:
                ICECAdapter *        m_libCec;
+               LibCECConfiguration ^m_configuration;
        };
 }