Permalink
Browse files

2007-07-02 Atsushi Enomoto <atsushi@ximian.com>

	* XsltDebugger.cs XsltDebuggerSession.cs :
	  some renaming. Added thread manager and got break commands working.

	* xslt-debugger.cs : added couple of commands.


svn path=/trunk/olive/; revision=81155
  • Loading branch information...
1 parent 947a6ae commit ac86bb7673216065ba6b794d250da187cedb92e3 @atsushieno atsushieno committed Jul 2, 2007
@@ -1,3 +1,8 @@
+2007-07-02 Atsushi Enomoto <atsushi@ximian.com>
+
+ * XsltDebugger.cs XsltDebuggerSession.cs :
+ some renaming. Added thread manager and got break commands working.
+
2007-06-29 Atsushi Enomoto <atsushi@ximian.com>
* XsltExecuteEventArgs.cs XsltExecuteEventHandler.cs
@@ -2,13 +2,14 @@
using System.Collections;
using System.IO;
using System.Security.Policy;
+using System.Threading;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
namespace Mono.XsltDebugger
{
- public class XsltDebugger
+ public class XsltDebuggerService
{
XPathDocument style;
XPathDocument input;
@@ -17,11 +18,16 @@ public class XsltDebugger
ArrayList breakpoints = new ArrayList ();
XsltDebuggerSession current_run;
XmlNamespaceManager nsmgr = new XmlNamespaceManager (new NameTable ());
+ ThreadManager thread_manager;
- public XsltDebugger ()
+ public XsltDebuggerService ()
{
}
+ public event EventHandler BreakpointMatched;
+
+ public event EventHandler TransformCompleted;
+
public XmlNamespaceManager NamespaceManager {
get { return nsmgr; }
}
@@ -90,21 +96,26 @@ public void Run ()
Abort ();
}
current_run = new XsltDebuggerSession (this);
+ thread_manager = new ThreadManager (current_run);
// set breakpoints
current_run.Executed += OnExecute;
- current_run.Run ();
+ thread_manager.StartTransform ();
}
public virtual void Interrupt ()
{
- throw new NotImplementedException ();
+ if (thread_manager == null)
+ throw new XsltDebuggerException ("No active transformation to interrupt");
+ thread_manager.InterruptTransform ();
}
public virtual void Resume ()
{
- throw new NotImplementedException ();
+ if (thread_manager == null)
+ throw new XsltDebuggerException ("No active transformation to interrupt");
+ thread_manager.ResumeTransform ();
}
public virtual void Abort ()
@@ -140,13 +151,30 @@ protected internal virtual void Transform (XslTransform transform, XmlWriter wri
if (input == null)
throw new XsltDebuggerException ("Input document is not specified");
transform.Transform (input, null, writer, xml_resolver);
+
+ OnTransformCompleted ();
}
+ // invoked inside transformation thread.
void OnExecute (object o, XsltExecuteEventArgs args)
{
if (!Break (args.Context))
return;
-Console.WriteLine ("Match");
+ thread_manager.DispatchBreakpointMatch (o, args);
+ }
+
+ // invoked from ThreadManager notification thread
+ void OnBreakpointMatch (object o, XsltExecuteEventArgs args)
+ {
+ if (BreakpointMatched != null)
+ BreakpointMatched (o, args);
+ }
+
+ void OnTransformCompleted ()
+ {
+ if (TransformCompleted != null)
+ TransformCompleted (null, null);
+ thread_manager.Dispose ();
}
bool Break (XsltDebuggerContext ctx)
@@ -158,5 +186,80 @@ bool Break (XsltDebuggerContext ctx)
return true;
return false;
}
+
+ class ThreadManager : IDisposable
+ {
+ XsltDebuggerSession session;
+ Thread run_thread, notify_thread;
+ ManualResetEvent notify_handle, trans_handle;
+
+ // used between notification thread and transformation thread
+ object event_sender;
+ XsltExecuteEventArgs event_args;
+
+ public ThreadManager (XsltDebuggerSession session)
+ {
+ this.session = session;
+ }
+
+ public void Dispose ()
+ {
+ if (notify_thread != null) {
+ notify_thread.Abort ();
+ notify_thread = null;
+ }
+ if (run_thread != null) {
+ run_thread.Abort ();
+ run_thread = null;
+ }
+ }
+
+ // It kicks the transform thread and returns.
+ public void StartTransform ()
+ {
+ notify_handle = new ManualResetEvent (false);
+ trans_handle = new ManualResetEvent (false);
+
+ run_thread = new Thread (delegate () {
+ try {
+ session.Run ();
+ } catch (ThreadAbortException) {
+ Thread.ResetAbort ();
+ }
+ });
+ notify_thread = new Thread (delegate () {
+ try {
+ while (true) {
+ notify_handle.Reset ();
+ notify_handle.WaitOne ();
+ session.Debugger.OnBreakpointMatch (event_sender, event_args);
+ }
+ } catch (ThreadAbortException) {
+ Thread.ResetAbort ();
+ }
+ });
+
+ notify_thread.Start ();
+ run_thread.Start ();
+ }
+
+ public void InterruptTransform ()
+ {
+ trans_handle.WaitOne ();
+ }
+
+ public void ResumeTransform ()
+ {
+ trans_handle.Set ();
+ }
+
+ public void DispatchBreakpointMatch (object o, XsltExecuteEventArgs args)
+ {
+ this.event_sender = o;
+ this.event_args = args;
+ notify_handle.Set ();
+ trans_handle.WaitOne ();
+ }
+ }
}
}
@@ -11,19 +11,19 @@ namespace Mono.XsltDebugger
{
public class XsltDebuggerSession : IDisposable
{
- XsltDebugger debugger;
+ XsltDebuggerService debugger;
XsltInjector injector;
XslTransform transform;
XmlNodeWriter output;
Hashtable custom_cache;
- public XsltDebuggerSession (XsltDebugger debugger)
+ public XsltDebuggerSession (XsltDebuggerService debugger)
{
this.debugger = debugger;
Init ();
}
- public XsltDebugger Debugger {
+ public XsltDebuggerService Debugger {
get { return debugger; }
}
@@ -46,6 +46,7 @@ public void Dispose ()
output = null;
}
+ // It is indicated by ThreadManager.StartDebug().
internal void Run ()
{
custom_cache = new Hashtable ();
@@ -1,3 +1,7 @@
+2007-07-02 Atsushi Enomoto <atsushi@ximian.com>
+
+ * xslt-debugger.cs : added couple of commands.
+
2007-06-29 Atsushi Enomoto <atsushi@ximian.com>
* Makefile
Oops, something went wrong.

0 comments on commit ac86bb7

Please sign in to comment.