Add an Alert callback. bigzid: 462
authorMark Kendall <mkendall@mythtv.org>
Thu, 5 Apr 2012 13:39:27 +0000 (14:39 +0100)
committerMark Kendall <mkendall@mythtv.org>
Thu, 5 Apr 2012 13:39:27 +0000 (14:39 +0100)
This will be used to signal the client application to signal the user
about critical issues.

Also adds new libcec_parameter and libcec_parameter_types types for
future expansion.

include/cectypes.h
src/LibCecSharp/CecSharpTypes.h
src/cec-config/cec-config.cpp
src/testclient/main.cpp

index 3beef1cc391a779871d9347f9ecd4fa91d6b2932..29a2e3806fcb840fa1d64f333793b9abf37099bc 100644 (file)
@@ -922,12 +922,29 @@ typedef struct cec_logical_addresses
 #endif
 } cec_logical_addresses;
 
+typedef enum libcec_alert
+{
+  CEC_ALERT_SERVICE_DEVICE
+} libcec_alert;
+
+typedef enum libcec_parameter_type
+{
+  CEC_PARAMETER_TYPE_STRING
+} libcec_parameter_type;
+
+struct libcec_parameter
+{
+  libcec_parameter_type paramType;
+  void*                 paramData;
+};
+
 struct libcec_configuration;
 
 typedef int (CEC_CDECL* CBCecLogMessageType)(void *param, const cec_log_message &);
 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 struct ICECCallbacks
 {
@@ -958,6 +975,14 @@ typedef struct ICECCallbacks
    * @return 1 when ok, 0 otherwise
    */
   CBCecConfigurationChangedType CBCecConfigurationChanged;
+
+  /*!
+   * @Brief Transfer a libcec alert message from libCEC to the client
+   * @Param alert The alert type transfer.
+   * @Param data  Misc. additional information.
+   * @return 1 when ok, 0 otherwise
+   */
+  CBCecAlertType CBCecAlert;
 } ICECCallbacks;
 
 typedef enum cec_client_version
index d9fcc9d2a0fcc7cde1c312b685a2c6f071596ce7..a7316f8babdad2755d8216c5185832a17b8c144d 100644 (file)
@@ -685,12 +685,20 @@ 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
@@ -838,6 +846,12 @@ namespace CecSharp
         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;
       }
@@ -859,6 +873,10 @@ 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;
index a7335c74a94ccd14bb8f6b75c5233ed9b344d6e3..1e6c96fd9272e6763b7fd265294019710f433202 100644 (file)
@@ -145,6 +145,7 @@ void EnableCallbacks(ICECAdapter *adapter)
   g_callbacks.CBCecKeyPress   = &CecKeyPress;
   g_callbacks.CBCecCommand    = &CecCommand;
   g_callbacks.CBCecConfigurationChanged = NULL;
+  g_callbacks.CBCecAlert      = NULL;
   adapter->EnableCallbacks(NULL, &g_callbacks);
 }
 
index 1621ad34b1d80b437409bc805765c2bc460d5b2f..c1106d5cdcf88dfc3c4f84b95d5aef1873e79269 100644 (file)
@@ -181,6 +181,7 @@ void EnableCallbacks(ICECAdapter *adapter)
   g_callbacks.CBCecKeyPress   = &CecKeyPress;
   g_callbacks.CBCecCommand    = &CecCommand;
   g_callbacks.CBCecConfigurationChanged = NULL;
+  g_callbacks.CBCecAlert      = NULL;
   adapter->EnableCallbacks(NULL, &g_callbacks);
 }