~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
1
//
2
// DebugExecutionHandlerFactory.cs
3
//
4
// Author:
5
//   Lluis Sanchez Gual
6
//
7
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8
//
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
16
// 
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
19
// 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
//
28
29
using System;
30
using System.Collections.Generic;
31
using System.Threading;
32
using MonoDevelop.Core;
33
using MonoDevelop.Core.Execution;
34
using Mono.Debugging.Client;
35
using MonoDevelop.Ide.Gui;
36
using Mono.Debugging;
37
38
namespace MonoDevelop.Debugger
39
{
10.1.2 by Mirco Bauer
Import upstream version 1.9.3+dfsg
40
	internal class DebugExecutionHandlerFactory: IExecutionHandler
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
41
	{
10.2.2 by Mirco Bauer
Import upstream version 2.1.1+dfsg
42
		public bool CanExecute (ExecutionCommand command)
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
43
		{
10.1.2 by Mirco Bauer
Import upstream version 1.9.3+dfsg
44
			return DebuggingService.CanDebugCommand (command);
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
45
		}
46
10.2.2 by Mirco Bauer
Import upstream version 2.1.1+dfsg
47
		public IProcessAsyncOperation Execute (ExecutionCommand command, IConsole console)
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
48
		{
10.1.2 by Mirco Bauer
Import upstream version 1.9.3+dfsg
49
			if (!CanExecute (command))
50
			    return null;
10.2.2 by Mirco Bauer
Import upstream version 2.1.1+dfsg
51
			DebugExecutionHandler h = new DebugExecutionHandler (null);
52
			return h.Execute (command, console);
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
53
		}
54
	}
55
	
10.2.2 by Mirco Bauer
Import upstream version 2.1.1+dfsg
56
	class DebugExecutionHandler: IProcessAsyncOperation
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
57
	{
58
		bool done;
59
		ManualResetEvent stopEvent;
10.2.6 by Jo Shields
Import upstream version 2.4+dfsg
60
		DebuggerEngine factory;
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
61
		
10.2.6 by Jo Shields
Import upstream version 2.4+dfsg
62
		public DebugExecutionHandler (DebuggerEngine factory)
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
63
		{
10.2.2 by Mirco Bauer
Import upstream version 2.1.1+dfsg
64
			this.factory = factory;
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
65
			DebuggingService.StoppedEvent += new EventHandler (OnStopDebug);
66
		}
67
		
10.2.2 by Mirco Bauer
Import upstream version 2.1.1+dfsg
68
		public IProcessAsyncOperation Execute (ExecutionCommand command, IConsole console)
69
		{
70
			DebuggingService.InternalRun (command, factory, console);
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
71
			return this;
72
		}
73
		
74
		public void Cancel ()
75
		{
76
			DebuggingService.Stop ();
77
		}
78
		
79
		public void WaitForCompleted ()
80
		{
81
			lock (this) {
82
				if (done) return;
83
				if (stopEvent == null)
84
					stopEvent = new ManualResetEvent (false);
85
			}
86
			stopEvent.WaitOne ();
87
		}
88
		
89
		public int ExitCode {
90
			get { return 0; }
91
		}
92
		
93
		public bool IsCompleted {
94
			get { return done; }
95
		}
96
		
97
		public bool Success {
98
			get { return true; }
99
		}
100
101
		public bool SuccessWithWarnings {
102
			get { return true; }
103
		}
104
105
		void OnStopDebug (object sender, EventArgs args)
106
		{
107
			lock (this) {
108
				done = true;
109
				if (stopEvent != null)
110
					stopEvent.Set ();
111
				if (completedEvent != null)
112
					completedEvent (this);
113
			}
114
115
			DebuggingService.StoppedEvent -= new EventHandler (OnStopDebug);
116
		}
117
		
118
		event OperationHandler IAsyncOperation.Completed {
119
			add {
120
				bool raiseNow = false;
121
				lock (this) {
122
					if (done)
123
						raiseNow = true;
124
					else
125
						completedEvent += value;
126
				}
127
				if (raiseNow)
128
					value (this);
129
			}
130
			remove {
131
				lock (this) {
132
					completedEvent -= value;
133
				}
134
			}
135
		}
136
		
137
		//FIXME:
138
		public int ProcessId {
139
			get { return -1; }
140
		}
141
		
142
		event OperationHandler completedEvent;
10.2.6 by Jo Shields
Import upstream version 2.4+dfsg
143
		
144
		void IDisposable.Dispose () {}
10.1.1 by Jo Shields
Import upstream version 1.9.2+dfsg
145
	}
146
}