public ref class LibCECConfiguration
{
public:
- LibCECConfiguration(CecCallbackMethods ^callbacks)
+ LibCECConfiguration(void)
{
DeviceName = "";
PhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS;
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;
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)
private:
ICECAdapter * m_libCec;
+ LibCECConfiguration ^m_configuration;
};
}