cec: added the new menu state changed callback to LibCecSharp. free the alert GC...
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 24 Apr 2012 09:04:29 +0000 (11:04 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 24 Apr 2012 09:06:13 +0000 (11:06 +0200)
include/cectypes.h
src/LibCecSharp/CecSharpTypes.h

index c1cc1af89c2b9989af09e5878eb228d419a320da..ea2c73dc653935695f8968e7a61011656bbd5ddd 100644 (file)
@@ -1039,7 +1039,7 @@ typedef int (CEC_CDECL* CBCecKeyPressType)(void *param, const cec_keypress &);
 typedef int (CEC_CDECL* CBCecCommandType)(void *param, const cec_command &);
 typedef int (CEC_CDECL* CBCecConfigurationChangedType)(void *param, const libcec_configuration &);
 typedef int (CEC_CDECL* CBCecAlertType)(void *param, const libcec_alert, const libcec_parameter &);
-typedef int (CEC_CDECL* CBCecMenuStateChangedType)(void *param, const cec_menu_state newVal);
+typedef int (CEC_CDECL* CBCecMenuStateChangedType)(void *param, const cec_menu_state);
 
 typedef struct ICECCallbacks
 {
index b0992de26e0f3442faa80240d96d82f75422d309..1e808196a881de53bdc045d21a81be02a1f5dd10 100644 (file)
@@ -678,12 +678,14 @@ namespace CecSharp
        typedef int (__stdcall *COMMANDCB)(const CEC::cec_command &command);
        typedef int (__stdcall *CONFIGCB) (const CEC::libcec_configuration &config);
        typedef int (__stdcall *ALERTCB)  (const CEC::libcec_alert, const CEC::libcec_parameter &data);
+       typedef int (__stdcall *MENUCB)   (const CEC::cec_menu_state newVal);
 
        static LOGCB              g_logCB;
        static KEYCB              g_keyCB;
        static COMMANDCB          g_commandCB;
        static CONFIGCB           g_configCB;
        static ALERTCB            g_alertCB;
+       static MENUCB             g_menuCB;
        static CEC::ICECCallbacks g_cecCallbacks;
 
        int CecLogMessageCB(void *cbParam, const CEC::cec_log_message &message)
@@ -721,6 +723,13 @@ namespace CecSharp
                return 0;
        }
 
+       int CecMenuCB(void *cbParam, const CEC::cec_menu_state newVal)
+       {
+               if (g_menuCB)
+                       return g_menuCB(newVal);
+               return 0;
+       }
+
        #pragma managed
        // delegates for the unmanaged callback methods
        public delegate int CecLogMessageManagedDelegate(const CEC::cec_log_message &);
@@ -728,6 +737,7 @@ namespace CecSharp
        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 &);
+       public delegate int CecMenuManagedDelegate(const CEC::cec_menu_state newVal);
 
        // callback method interface
        public ref class CecCallbackMethods
@@ -794,6 +804,11 @@ namespace CecSharp
                        return 0;
                }
 
+               virtual int ReceiveMenuStateChange(CecMenuState newVal)
+               {
+                       return 0;
+               }
+
        protected:
                // managed callback methods
                int CecLogMessageManaged(const CEC::cec_log_message &message)
@@ -853,6 +868,16 @@ namespace CecSharp
                        return iReturn;
                }
 
+               int CecMenuManaged(const CEC::cec_menu_state newVal)
+               {
+                       int iReturn(0);
+                       if (m_bHasCallbacks)
+                       {
+                               iReturn = m_callbacks->ReceiveMenuStateChange((CecMenuState)newVal);
+                       }
+                       return iReturn;
+               }
+
                void DestroyDelegates()
                {
       m_bHasCallbacks = false;
@@ -862,6 +887,8 @@ namespace CecSharp
                                m_logMessageGCHandle.Free();
                                m_keypressGCHandle.Free();
                                m_commandGCHandle.Free();
+                               m_alertGCHandle.Free();
+                               m_menuGCHandle.Free();
                        }
                }
 
@@ -903,6 +930,12 @@ namespace CecSharp
         g_alertCB                  = static_cast<ALERTCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer());
         g_cecCallbacks.CBCecAlert  = CecAlertCB;
 
+        // create the delegate method for the menu callback
+        m_menuDelegate             = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged);
+        m_menuGCHandle             = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate);
+        g_menuCB                   = static_cast<MENUCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer());
+        g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB;
+
         delete context;
         m_bDelegatesCreated = true;
       }
@@ -928,6 +961,10 @@ namespace CecSharp
                static System::Runtime::InteropServices::GCHandle m_alertGCHandle;
                CONFIGCB                                          m_alertCallback;
 
+               CecMenuManagedDelegate ^                          m_menuDelegate;
+               static System::Runtime::InteropServices::GCHandle m_menuGCHandle;
+               MENUCB                                            m_menuCallback;
+
                CecCallbackMethods ^ m_callbacks;
          bool                 m_bHasCallbacks;
     bool                 m_bDelegatesCreated;