LibCecSharp: better handling of callbacks
[deb_libcec.git] / src / LibCecSharp / LibCecSharp.cpp
index 2338671d577dfa53448185aacfd58abafc89a753..cd0f6d05d3ae239afc2e8286b9e1ae7694c2e2c8 100644 (file)
@@ -82,6 +82,7 @@ namespace CecSharp
                        ConvertConfiguration(context, config, libCecConfig);
 
                        m_libCec = (ICECAdapter *) CECInitialise(&libCecConfig);
+                       config->Update(libCecConfig);
 
                        delete context;
                        return m_libCec != NULL;
@@ -91,7 +92,8 @@ namespace CecSharp
                {
                        config.Clear();
 
-                       _snprintf_s(config.strDeviceName, 13, context->marshal_as<const char*>(netConfig->DeviceName));
+                       const char *strDeviceName = context->marshal_as<const char*>(netConfig->DeviceName);
+                       memcpy_s(config.strDeviceName, 13, strDeviceName, 13);
                        for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
                                config.deviceTypes.types[iPtr] = (cec_device_type)netConfig->DeviceTypes->Types[iPtr];
 
@@ -118,13 +120,25 @@ namespace CecSharp
                        config.bPowerOffScreensaver = netConfig->PowerOffScreensaver ? 1 : 0;
                        config.bPowerOffOnStandby   = netConfig->PowerOffOnStandby ? 1 : 0;
 
-      if (netConfig->ServerVersion >= CecServerVersion::Version1_5_1)
-        config.bSendInactiveSource  = netConfig->SendInactiveSource ? 1 : 0;
+                       if (netConfig->ServerVersion >= CecServerVersion::Version1_5_1)
+                               config.bSendInactiveSource  = netConfig->SendInactiveSource ? 1 : 0;
 
-      if (netConfig->ServerVersion >= CecServerVersion::Version1_6_0)
-        config.bPowerOffDevicesOnStandby  = netConfig->PowerOffDevicesOnStandby ? 1 : 0;
+                       if (netConfig->ServerVersion >= CecServerVersion::Version1_6_0)
+                       {
+                               config.bPowerOffDevicesOnStandby  = netConfig->PowerOffDevicesOnStandby ? 1 : 0;
+                               config.bShutdownOnStandby         = netConfig->ShutdownOnStandby ? 1 : 0;
+                       }
+
+                       if (netConfig->ServerVersion >= CecServerVersion::Version1_6_2)
+                       {
+                               const char *strDeviceLanguage = context->marshal_as<const char*>(netConfig->DeviceLanguage);
+                               memcpy_s(config.strDeviceLanguage, 3, strDeviceLanguage, 3);
+                       }
+
+                       if (netConfig->ServerVersion >= CecServerVersion::Version1_6_3)
+                         config.bMonitorOnly = netConfig->MonitorOnlyClient ? 1 : 0;
 
-                       config.callbacks            = &g_cecCallbacks;
+                       config.callbacks = &g_cecCallbacks;
                }
 
        public:
@@ -174,7 +188,7 @@ namespace CecSharp
                virtual bool EnableCallbacks(CecCallbackMethods ^ callbacks) override
                {
                        if (m_libCec && CecCallbackMethods::EnableCallbacks(callbacks))
-                               return m_libCec->EnableCallbacks(NULL, &g_cecCallbacks);
+                               return m_libCec->EnableCallbacks((void*)GetCallbackPtr(), &g_cecCallbacks);
 
                        return false;
                }
@@ -220,7 +234,7 @@ namespace CecSharp
                        cec_keypress key;
                        if (m_libCec->GetNextKeypress(&key))
                        {
-                               return gcnew CecKeypress(key.keycode, key.duration);
+                               return gcnew CecKeypress((CecUserControlCode)key.keycode, key.duration);
                        }
 
                        return gcnew CecKeypress();