Kaynağa Gözat

Added Logger.

Daniel Kauth 10 yıl önce
ebeveyn
işleme
9053d89fa8

+ 4 - 2
bbiwarg/Constants.cs

@@ -5,13 +5,15 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
+using bbiwarg.Utility;
+
 namespace bbiwarg
 {
     class Constants
     {
         // BBIWARG
-        public static readonly bool OutputTimerEnabled = false;
-        public static readonly bool sendingSystemTimeEnabled = false;
+        public static readonly Logger.LogSubject LogLevel =
+            Logger.LogSubject.TUIOServer;
         public static readonly int OutputNumImages = 5;
         public static readonly int OutputNumImagesPerRow = 3;
         public static readonly float OutputScaleFactor = 1f; // output window size is scaled by this factor (from necessary size for images)

+ 1 - 2
bbiwarg/Graphics/OutputWindow.cs

@@ -165,8 +165,7 @@ namespace bbiwarg.Graphics
 
             Timer.stop("onRenderFrame");
             
-            if(Constants.OutputTimerEnabled)
-                Timer.outputAll();
+            Timer.outputAll();
         }
 
     }

+ 0 - 1
bbiwarg/InputProvider/IisuInputProvider.cs

@@ -121,7 +121,6 @@ namespace bbiwarg.InputProviders
             return active;
         }
 
-
         // Data-methodes
         public InputFrame getInputFrame() {
             //depthData

+ 3 - 2
bbiwarg/Server/TUIO/TuioServer.cs

@@ -7,6 +7,8 @@ using System.Threading.Tasks;
 using OSC.NET;
 //using System.Runtime.InteropServices;
 
+using bbiwarg.Utility;
+
 namespace TUIO
 {
     class TuioServer
@@ -132,8 +134,7 @@ namespace TUIO
                 }*/
                 packet.Append(currentMessage);
 
-                if(bbiwarg.Constants.sendingSystemTimeEnabled)
-                    Console.WriteLine("Send Cursor "+cursor.getSessionID()+" at time "+TuioTime.getSystemTime().ToString());
+                Logger.log("Send Cursor "+cursor.getSessionID()+" at time "+TuioTime.getSystemTime().ToString(), Logger.LogSubject.TUIOServer);
             }
             currentMessage = new OSCMessage("/tuio/2Dcur");
             currentMessage.Append("fseq");

+ 29 - 0
bbiwarg/Utility/Logger.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace bbiwarg.Utility
+{
+    static class Logger
+    {
+        public enum LogSubject
+        {
+            FingerDetector = 1,
+            FingerTracker = 2,
+            HandDetector = 4,
+            PalmDetector = 8,
+            TouchDetector = 16,
+            TouchTracker = 32,
+            TUIOServer = 64,
+            Timer = 128
+        }
+
+        public static void log(string message, LogSubject subject)
+        {
+            if (Constants.LogLevel.HasFlag(subject))
+                Console.WriteLine(message);
+        }
+    }
+}

+ 5 - 4
bbiwarg/Utility/Timer.cs

@@ -37,15 +37,16 @@ namespace bbiwarg.Utility
         }
 
         public static void output(String name) {
-            Console.WriteLine("name:{0}\tavg:{1:00.00}\tmin:{2:00.00}\tmax:{3:00.00}", name, sumTimes[name] / Math.Max(numTimes[name], 1), minTimes[name], maxTimes[name]);
-       }
+            Logger.log(String.Format("name:{0}\tavg:{1:00.00}\tmin:{2:00.00}\tmax:{3:00.00}",
+                name, sumTimes[name] / Math.Max(numTimes[name], 1), minTimes[name], maxTimes[name]), Logger.LogSubject.Timer);
+        }
 
         public static void outputAll() {
-            Console.WriteLine("---TIMERS-START---");
+            Logger.log("---TIMERS-START---", Logger.LogSubject.Timer);
             foreach (String name in stopwatches.Keys) {
                 output(name);
             }
-            Console.WriteLine("---TIMERS-END---");
+            Logger.log("---TIMERS-END---", Logger.LogSubject.Timer);
         }
 
     }

+ 1 - 0
bbiwarg/bbiwarg.csproj

@@ -103,6 +103,7 @@
     <Compile Include="Utility\Kalman2DPositionFilter.cs" />
     <Compile Include="Utility\Line2D.cs" />
     <Compile Include="Utility\LineSegment2D.cs" />
+    <Compile Include="Utility\Logger.cs" />
     <Compile Include="Utility\Quadrangle.cs" />
     <Compile Include="Utility\Timer.cs" />
     <Compile Include="Utility\Vector2D.cs" />