Browse Source

watchdog for the intel camera

Florian Mueller 7 years ago
parent
commit
0144c35e32

BIN
.vs/bbiwarg/v14/.suo


+ 30 - 5
bbiwarg/Input/InputProviding/InputProviderIntel.cs

@@ -1,6 +1,7 @@
 using System;
 using Emgu.CV;
 using Emgu.CV.Structure;
+using System.Timers;
 using System.Threading;
 
 namespace BBIWARG.Input.InputProviding
@@ -49,15 +50,26 @@ namespace BBIWARG.Input.InputProviding
 
         public UInt16 lowConfidenceValue;
         private AppDomain domain;
+        private System.Threading.Timer watchdogTimer;
 
         public void initialize()
         {
             CurrentFrameID = 0;
+
+            watchdogTimer = new System.Threading.Timer(Timer_Elapsed, null, 1000, 1000);
+        }
+
+        private void Timer_Elapsed(object state)
+        {
+            checkExitErrorstate();
+
+            if (wrapper != null)
+                wrapper.errorstate = true;
         }
 
         public void start()
         {
-            domain = System.AppDomain.CreateDomain("IntelSucks");
+            domain = System.AppDomain.CreateDomain(System.Guid.NewGuid().ToString());
 
             wrapper = (IntelCameraWrapper) domain.CreateInstanceAndUnwrap(typeof(IntelCameraWrapper).Assembly.GetName().ToString(), typeof(IntelCameraWrapper).FullName);
             wrapper.init(this);
@@ -72,17 +84,30 @@ namespace BBIWARG.Input.InputProviding
 
             wrapper.run();
 
-            if (wrapper.errorstate) {
+            checkExitErrorstate();
+        }
+
+        private void checkExitErrorstate()
+        {
+            if (wrapper.errorstate)
+            {
                 //we have crashed. Kill the app domain and try again.
                 Console.WriteLine("Killing AppDomain...");
-                System.AppDomain.Unload(domain);
-                Thread.Sleep(5000);
+                try
+                {
+                    System.AppDomain.Unload(domain);
+                    Thread.Sleep(5000);
+                }
+                catch (Exception)
+                {
+                    Console.WriteLine("Could not unload app domain... Still trying to start again...");
+                }
+                
                 Console.WriteLine("Starting again...");
                 start();
             }
         }
 
-
         public void stop()
         {
             IsActive = false;

+ 10 - 1
bbiwarg/Input/InputProviding/IntelCameraHandler.cs

@@ -4,6 +4,7 @@ using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Reflection;
+using System.Security.Permissions;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
@@ -28,6 +29,12 @@ namespace BBIWARG.Input.InputProviding
            
         }
 
+        [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.Infrastructure)]
+        public override object InitializeLifetimeService()
+        {
+            return null;
+        }
+
         public void init(InputProviderIntel intelInputProvider) {
             inputProviderIntel = intelInputProvider;
 
@@ -70,11 +77,13 @@ namespace BBIWARG.Input.InputProviding
         {
             while (inputProviderIntel.IsActive)
             {
+                errorstate = false;
+
                 var status = senseManager.AcquireFrame(true);
 
                 if (status != EverythingFine)
                 {
-                    Console.WriteLine("Stupid camera crashed with "+ status + ". Trying to recover...");
+                    Console.WriteLine("Found crash inside CameraHandler...");
                     errorstate = true;
                     break;
                 }