/[gr2lib]/trunk/gr2lib/core/coretypes/implementation/granny_log_callback_builder.cs
ViewVC logotype

Annotation of /trunk/gr2lib/core/coretypes/implementation/granny_log_callback_builder.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (hide annotations) (download)
Tue Jul 20 10:26:54 2010 UTC (10 years, 2 months ago) by william
File size: 4266 byte(s)
add support for logging messages from the Granny2 API

1 william 153 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using gr2lib.core.typedefs;
6     using gr2lib.core.coretypes.native;
7    
8     namespace gr2lib.core.coretypes.implementation
9     {
10     public class granny_log_eventargs : EventArgs
11     {
12     private string message;
13     private granny_log_message_type type;
14     private granny_log_message_origin origin;
15     private string _type_string;
16     private string _origin_string;
17    
18     public granny_log_eventargs(granny_log_message_type type, granny_log_message_origin origin, string message)
19     {
20     this.type = type;
21     this.origin = origin;
22     this.message = message;
23     this._type_string = coreapi.GrannyGetLogMessageTypeString(type);
24     this._origin_string = coreapi.GrannyGetLogMessageOriginString(origin);
25     }
26     public granny_log_eventargs(granny_log_message_type type, granny_log_message_origin origin, string message, string type_string, string origin_string)
27     {
28     this.type = type;
29     this.origin = origin;
30     this.message = message;
31     this._type_string = type_string;
32     this._origin_string = origin_string;
33     }
34    
35     public granny_log_message_type Type { get { return type; } }
36     public granny_log_message_origin Origin { get { return origin; } }
37    
38     public string TypeString { get { return _type_string; } }
39     public string OriginString { get { return _origin_string; } }
40     public string Message { get { return message; } }
41     }
42    
43     public class granny_log_callback_builder
44     {
45    
46     public delegate void OnMessageLogged(object sender, granny_log_eventargs e);
47     public event OnMessageLogged OnMessageLoggedEventHandler;
48    
49     private void LogCallback(granny_log_message_type Type, granny_log_message_origin Origin, string Message, IntPtr UserData)
50     {
51     string TypeString = coreapi.GrannyGetLogMessageTypeString(Type);
52     string OriginString = coreapi.GrannyGetLogMessageOriginString(Origin);
53    
54     Console.WriteLine();
55     Console.WriteLine("Granny2 API Logger: Logging Message -> ");
56     Console.WriteLine();
57     Console.WriteLine("\tMessage Log Type: {0}\n\tMessage Log Origin: {1}\n\tMessage: {2}", TypeString, OriginString, Message);
58     Console.WriteLine();
59    
60     //if (OnMessageLoggedEventHandler != null)
61     //{
62     // OnMessageLoggedEventHandler(this, new granny_log_eventargs(Type, Origin, Message));
63     //}
64     }
65    
66     public granny_log_callback_builder() { }
67     public granny_log_callback_builder(OnMessageLogged OnMessageLoggedEventHandler) { this.OnMessageLoggedEventHandler = OnMessageLoggedEventHandler; }
68     public void StartLogging()
69     {
70     try
71     {
72     granny_log_callback _log_call_back = new granny_log_callback();
73     coreapi.granny_log_callback_method _granny_log_callback_method = new coreapi.granny_log_callback_method(this.LogCallback);
74     _log_call_back.Function = _granny_log_callback_method;
75     _log_call_back.UserData = IntPtr.Zero;
76     coreapi.GrannySetLogCallback(ref _log_call_back);
77     Console.WriteLine("Granny2 API Logger: {0}", "Activated");
78     }
79     catch
80     {
81     Console.WriteLine("Granny2 API Logger: {0}", "Not Activated");
82     }
83    
84     }
85     public void StopLogging()
86     {
87     try
88     {
89     granny_log_callback _log_call_back = new granny_log_callback();
90     coreapi.granny_log_callback_method _granny_log_callback_method = null;
91     _log_call_back.Function = _granny_log_callback_method;
92     _log_call_back.UserData = IntPtr.Zero;
93     coreapi.GrannySetLogCallback(ref _log_call_back);
94     Console.WriteLine("Granny2 API Logger: {0}", "Deactivated");
95     }
96     catch
97     {
98     Console.WriteLine("Granny2 API Logger: {0}", "Not Deactivated");
99     }
100     }
101    
102     }
103     }
104    

  ViewVC Help
Powered by ViewVC 1.1.22