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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 158 by william, Thu Jul 22 09:06:12 2010 UTC revision 165 by william, Thu Jul 22 12:37:13 2010 UTC
# Line 93  namespace gr2lib.core.coretypes.implemen Line 93  namespace gr2lib.core.coretypes.implemen
93      #region public class granny_log_callback_builder : igranny_log_callback_builder      #region public class granny_log_callback_builder : igranny_log_callback_builder
94      public class granny_log_callback_builder : igranny_log_callback_builder      public class granny_log_callback_builder : igranny_log_callback_builder
95      {      {
96            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
97            public delegate void granny_log_callback_method(granny_log_message_type Type, granny_log_message_origin Origin, [MarshalAs(UnmanagedType.LPStr)] string Message, IntPtr UserData);
98    
99          public delegate void OnMessageLogged(object sender, granny_log_eventargs e);          public delegate void OnMessageLogged(object sender, granny_log_eventargs e);
100          public event OnMessageLogged OnMessageLoggedEventHandler;          public static event OnMessageLogged OnMessageLoggedEventHandler;
101    
102          internal granny_log_callback _log_call_back;          internal granny_log_callback _log_call_back;
103          private coreapi.granny_log_callback_method _callback = null;          internal granny_log_callback_method _callback = null;
104    
105          private void LogCallback(granny_log_message_type Type, granny_log_message_origin Origin, [MarshalAs(UnmanagedType.LPStr)] string Message, IntPtr UserData)          [StructLayout(LayoutKind.Sequential, Pack = 4), Size(Size = 8)]
106            public struct granny_log_callback
107          {          {
108                [MarshalAs(UnmanagedType.FunctionPtr)]
109                public granny_log_callback_method Function;
110                public IntPtr UserData;
111            }
112    
113            #region Log Call Back
114            private void LogCallback(granny_log_message_type Type, granny_log_message_origin Origin, [MarshalAs(UnmanagedType.LPStr)] string Message, IntPtr UserData)
115            {          
116              string TypeString = coreapi.GrannyGetLogMessageTypeString(Type);              string TypeString = coreapi.GrannyGetLogMessageTypeString(Type);
117              string OriginString = coreapi.GrannyGetLogMessageOriginString(Origin);              string OriginString = coreapi.GrannyGetLogMessageOriginString(Origin);
118    
# Line 157  namespace gr2lib.core.coretypes.implemen Line 168  namespace gr2lib.core.coretypes.implemen
168              {                        {          
169                  OnMessageLoggedEventHandler(this, new granny_log_eventargs(Type, Origin, Message));                  OnMessageLoggedEventHandler(this, new granny_log_eventargs(Type, Origin, Message));
170              }              }
171                GC.KeepAlive(this);
172    
173          }          }
174            #endregion
175    
176          public granny_log_callback_builder() { _callback = new coreapi.granny_log_callback_method(this.LogCallback); }          public granny_log_callback_builder() { _callback = new granny_log_callback_method(this.LogCallback); }
177          //public granny_log_callback_builder(coreapi.granny_log_callback_method LogCallBack) { this._callback = LogCallBack; }          //public granny_log_callback_builder(coreapi.granny_log_callback_method LogCallBack) { this._callback = LogCallBack; }
178          public granny_log_callback_builder(OnMessageLogged OnMessageLoggedEventHandler) { this.OnMessageLoggedEventHandler = OnMessageLoggedEventHandler; }          public granny_log_callback_builder(OnMessageLogged OnMessageLoggedEvntHandler) { OnMessageLoggedEventHandler = OnMessageLoggedEvntHandler; _callback = new granny_log_callback_method(this.LogCallback); }
179    
180          #region Start Logger          #region Start Logger
181          public void StartLogging()          public void StartLogging()
# Line 169  namespace gr2lib.core.coretypes.implemen Line 183  namespace gr2lib.core.coretypes.implemen
183              try              try
184              {              {
185                  _log_call_back = new granny_log_callback();                  _log_call_back = new granny_log_callback();
186                  coreapi.granny_log_callback_method _granny_log_callback_method = new coreapi.granny_log_callback_method(this.LogCallback);                  _log_call_back.Function = _callback;
                 _log_call_back.Function = _granny_log_callback_method;  
187                  _log_call_back.UserData = IntPtr.Zero;                  _log_call_back.UserData = IntPtr.Zero;
188                    GC.KeepAlive(this);
189                  coreapi.GrannySetLogCallback(ref _log_call_back);                  coreapi.GrannySetLogCallback(ref _log_call_back);
190                    
191                  Console.WriteLine("Granny2 API Logger: {0}", "Activated");                  Console.WriteLine("Granny2 API Logger: {0}", "Activated");
192              }              }
193              catch              catch
# Line 190  namespace gr2lib.core.coretypes.implemen Line 205  namespace gr2lib.core.coretypes.implemen
205              {              {
206                  _log_call_back = new granny_log_callback();                  _log_call_back = new granny_log_callback();
207                  _log_call_back = new granny_log_callback();                  _log_call_back = new granny_log_callback();
208                  coreapi.granny_log_callback_method _granny_log_callback_method = null;                  granny_log_callback_method _granny_log_callback_method = null;
209                  _log_call_back.Function = _granny_log_callback_method;                  _log_call_back.Function = _granny_log_callback_method;
210                  _log_call_back.UserData = IntPtr.Zero;                  _log_call_back.UserData = IntPtr.Zero;
211                  coreapi.GrannySetLogCallback(ref _log_call_back);                  coreapi.GrannySetLogCallback(ref _log_call_back);
                 coreapi.GrannySetLogCallback(ref _log_call_back);  
212                  Console.WriteLine("Granny2 API Logger: {0}", "Deactivated");                  Console.WriteLine("Granny2 API Logger: {0}", "Deactivated");
213              }              }
214              catch              catch

Legend:
Removed from v.158  
changed lines
  Added in v.165

  ViewVC Help
Powered by ViewVC 1.1.22