Add an Alert callback. bigzid: 462
[deb_libcec.git] / src / LibCecSharp / CecSharpTypes.h
index 5d617941b0f4316c422cd257c249d5aba62281b8..a7316f8babdad2755d8216c5185832a17b8c144d 100644 (file)
@@ -326,13 +326,21 @@ 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
        };
 
   public enum class CecServerVersion
        {
                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
        };
 
        public ref class CecAdapter
@@ -547,6 +555,10 @@ 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;
                }
 
                void SetCallbacks(CecCallbackMethods ^callbacks)
@@ -586,6 +598,23 @@ namespace CecSharp
 
                        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;
+      }
                }
 
                property System::String ^     DeviceName;
@@ -606,6 +635,10 @@ 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 CecCallbackMethods ^ Callbacks;
        };
@@ -652,48 +685,30 @@ namespace CecSharp
                return 0;
        }
 
+       int CecAlertCB(void *cbParam, const CEC::libcec_alert alert, const libcec_parameter &data)
+       {
+               if (g_alertCB)
+                       return g_alertCB(alert, data);
+               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 &);
 
        // 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<LOGCB>(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<KEYCB>(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<COMMANDCB>(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<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer());
-                       g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB;
-
-                       delete context;
-               }
+    CecCallbackMethods(void)
+    {
+      m_bHasCallbacks = false;
+      m_bDelegatesCreated = false;
+    }
 
        ~CecCallbackMethods(void)
    {
@@ -709,13 +724,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;
@@ -790,16 +804,59 @@ namespace CecSharp
 
                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();
                        }
                }
 
+    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<LOGCB>(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<KEYCB>(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<COMMANDCB>(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<CONFIGCB>(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<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer());
+        g_cecCallbacks.CBCecAlert  = CecAlertCB;
+
+        delete context;
+        m_bDelegatesCreated = true;
+      }
+    }
+
                CecLogMessageManagedDelegate ^                    m_logMessageDelegate;
                static System::Runtime::InteropServices::GCHandle m_logMessageGCHandle;
                LOGCB                                             m_logMessageCallback;
@@ -816,7 +873,12 @@ 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;
+
                CecCallbackMethods ^ m_callbacks;
          bool                 m_bHasCallbacks;
+    bool                 m_bDelegatesCreated;
        };
 }