ensure that the tray app only initialises once. bugzid: 2082
[deb_libcec.git] / src / LibCecTray / controller / CECController.cs
index 13d75201cbdd644a7e63c9834ff87f7488da40fc..94fac2e4349e0bc4c76ecb83aab13f2ac6f8232e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the libCEC(R) library.
  *
- * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited.  All rights reserved.
+ * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited.  All rights reserved.
  * libCEC(R) is an original work, containing original code.
  *
  * libCEC(R) is a trademark of Pulse-Eight Limited.
@@ -203,6 +203,11 @@ namespace LibCECTray.controller
     /// </summary>
     public void Initialise()
     {
+      // only load once
+      if (_initialised)
+        return;
+      _initialised = true;
+
       CECActions.ConnectToDevice(Config);
       Applications.Initialise(this);
     }
@@ -215,6 +220,7 @@ namespace LibCECTray.controller
       Lib.DisableCallbacks();
       Lib.StandbyDevices(CecLogicalAddress.Broadcast);
       Lib.Close();
+      _initialised = false;
     }
 
     /// <summary>
@@ -438,7 +444,7 @@ namespace LibCECTray.controller
       {
         if (_config == null)
         {
-          _config = new LibCECConfiguration { DeviceName = "CEC Tray", ClientVersion = CecClientVersion.Version2_0_0 };
+          _config = new LibCECConfiguration { DeviceName = "CEC Tray", ClientVersion = CecClientVersion.Version2_1_0 };
           _config.DeviceTypes.Types[0] = CecDeviceType.RecordingDevice;
           _config.SetCallbacks(this);
 
@@ -491,19 +497,22 @@ namespace LibCECTray.controller
     }
 
     /// <summary>
-    /// Get the usb vid:prod descriptor
+    /// Get the usb vendor id
     /// </summary>
-    public string USBDescriptor
+    public ushort AdapterVendorId
     {
-      get
-      {
-        DateTime checkDate = new DateTime(1970, 1, 1, 0, 0, 0, 0);
-        checkDate = checkDate.AddSeconds(0x5045dbf5);
+      get { return Lib.GetAdapterVendorId(); }
+    }
 
-        return string.Format("2548:100{0}", ((DateTime)Config.FirmwareBuildDate >= checkDate ? "2" : "1"));
-      }
+    /// <summary>
+    /// Get the usb product id
+    /// </summary>
+    public ushort AdapterProductId
+    {
+      get { return Lib.GetAdapterProductId(); }
     }
 
+
     /// <summary>
     /// libCEC
     /// </summary>
@@ -516,6 +525,7 @@ namespace LibCECTray.controller
     private readonly CECTray _gui;
     public Actions CECActions;
     private bool _deviceChangeWarningDisplayed;
+    private bool _initialised;
 
     #endregion
   }