OLD | NEW |
| (Empty) |
1 // Copyright 2009 The Native Client Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can | |
3 // be found in the LICENSE file. | |
4 using System; | |
5 using System.Collections.Generic; | |
6 using System.Diagnostics; | |
7 using System.Linq; | |
8 using Microsoft.VisualStudio; | |
9 using Microsoft.VisualStudio.Debugger.Interop; | |
10 using Microsoft.VisualStudio.OLE.Interop; | |
11 using Microsoft.VisualStudio.Shell; | |
12 | |
13 namespace Google.MsAd7.BaseImpl { | |
14 public abstract class Port | |
15 : IDebugPort2, | |
16 IDebugPortNotify2, | |
17 IConnectionPointContainer, | |
18 IConnectionPoint { | |
19 public Port(IDebugPortSupplier2 supplier, | |
20 IDebugPortRequest2 request, | |
21 Guid guid) { | |
22 request_ = request; | |
23 supplier_ = supplier; | |
24 guid_ = guid; | |
25 } | |
26 | |
27 public Guid Guid { | |
28 get { return guid_; } | |
29 } | |
30 | |
31 public IDebugPortRequest2 Request { | |
32 get { return request_; } | |
33 } | |
34 | |
35 public IDebugPortSupplier2 Supplier { | |
36 get { return supplier_; } | |
37 } | |
38 | |
39 public DebugProcess CreateProcess(ProcessStartInfo psi) | |
40 { | |
41 DebugProcess proc = CreateProcessInternal(psi); | |
42 return proc; | |
43 } | |
44 | |
45 #region Implementation of IDebugPort2 | |
46 | |
47 public int GetPortName(out string pbstrName) { | |
48 Debug.WriteLine("Port.GetPortName"); | |
49 return request_.GetPortName(out pbstrName); | |
50 } | |
51 | |
52 public int GetPortId(out Guid pguidPort) { | |
53 Debug.WriteLine("Port.GetPortId"); | |
54 pguidPort = guid_; | |
55 return VSConstants.S_OK; | |
56 } | |
57 | |
58 public int GetPortRequest(out IDebugPortRequest2 ppRequest) { | |
59 Debug.WriteLine("Port.GetPortRequest"); | |
60 ppRequest = request_; | |
61 return VSConstants.S_OK; | |
62 } | |
63 | |
64 public int GetPortSupplier(out IDebugPortSupplier2 ppSupplier) { | |
65 Debug.WriteLine("Port.GetPortSupplier"); | |
66 ppSupplier = supplier_; | |
67 return VSConstants.S_OK; | |
68 } | |
69 | |
70 public int GetProcess(AD_PROCESS_ID ProcessId, out IDebugProcess2 ppProcess)
{ | |
71 Debug.WriteLine("Port.GetProcess"); | |
72 Debug.Assert( | |
73 ProcessId.ProcessIdType == | |
74 (int) enum_AD_PROCESS_ID.AD_PROCESS_ID_SYSTEM); | |
75 | |
76 IEnumerable<DebugProcess> procList = GetProcesses(); | |
77 var proc = from p in procList | |
78 where p.Pid == ProcessId.dwProcessId | |
79 select p; | |
80 ppProcess = proc.FirstOrDefault(); | |
81 return ppProcess != null ? VSConstants.S_OK : VSConstants.S_FALSE; | |
82 } | |
83 | |
84 public int EnumProcesses(out IEnumDebugProcesses2 ppEnum) { | |
85 Debug.WriteLine("Port.EnumProcesses"); | |
86 IEnumerable<DebugProcess> procList = GetProcesses(); | |
87 var processes = new List<IDebugProcess2>(); | |
88 foreach (var debugProcess in procList) { | |
89 processes.Add(debugProcess); | |
90 } | |
91 ppEnum = new Ad7Enumerators.ProcessEnumerator(processes); | |
92 return VSConstants.S_OK; | |
93 } | |
94 | |
95 #endregion | |
96 | |
97 #region IConnectionPoint Members | |
98 | |
99 public void GetConnectionInterface(out Guid pIID) { | |
100 pIID = typeof (IDebugPortEvents2).GUID; | |
101 } | |
102 | |
103 public void GetConnectionPointContainer(out IConnectionPointContainer ppCPC)
{ | |
104 ppCPC = this; | |
105 } | |
106 | |
107 public void Advise(object pUnkSink, out uint pdwCookie) { | |
108 pdwCookie = eventSinks_.Add(pUnkSink); | |
109 } | |
110 | |
111 public void Unadvise(uint dwCookie) { | |
112 eventSinks_.RemoveAt(dwCookie); | |
113 } | |
114 | |
115 public void EnumConnections(out IEnumConnections ppEnum) { | |
116 throw new NotImplementedException(); | |
117 } | |
118 | |
119 #endregion | |
120 | |
121 #region IConnectionPointContainer Members | |
122 | |
123 public void EnumConnectionPoints(out IEnumConnectionPoints ppEnum) { | |
124 // This doesn't need to be implemented; all we care about | |
125 // is FindConnectionPoint(). | |
126 throw new NotImplementedException(); | |
127 } | |
128 | |
129 public void FindConnectionPoint(ref Guid riid, out IConnectionPoint ppCP) { | |
130 ppCP = null; | |
131 if (riid == typeof (IDebugPortEvents2).GUID) { | |
132 ppCP = this; | |
133 } | |
134 } | |
135 | |
136 #endregion | |
137 | |
138 #region IDebugPortNotify2 Members | |
139 | |
140 public int AddProgramNode(IDebugProgramNode2 pProgramNode) { | |
141 IDebugProcess2 proc; | |
142 AD_PROCESS_ID[] pid = new AD_PROCESS_ID[1]; | |
143 ComUtils.RequireOk(pProgramNode.GetHostPid(pid)); | |
144 ComUtils.RequireOk(GetProcess(pid[0], out proc)); | |
145 | |
146 // Our implementation conflates ProgramNode and Program, | |
147 // perhaps erroneously. | |
148 IDebugProgram2 program = (IDebugProgram2) pProgramNode; | |
149 | |
150 SendEvent(null, this, proc, program, new Ad7Events.DebugProgramCreateEvent
(enum_EVENTATTRIBUTES.EVENT_IMMEDIATE)); | |
151 return VSConstants.S_OK; | |
152 } | |
153 | |
154 public int RemoveProgramNode(IDebugProgramNode2 pProgramNode) { | |
155 throw new NotImplementedException(); | |
156 } | |
157 | |
158 #endregion | |
159 | |
160 #region Private Implementation | |
161 | |
162 private void SendEvent(IDebugCoreServer2 server, IDebugPort2 port, IDebugPro
cess2 process, IDebugProgram2 program, IDebugEvent2 ev) { | |
163 Guid iid = ComUtils.GuidOf(ev); | |
164 foreach (var eventSink in eventSinks_) { | |
165 IDebugPortEvents2 events = eventSink as IDebugPortEvents2; | |
166 if (events != null) { | |
167 events.Event(server, port, process, program, ev, ref iid); | |
168 } | |
169 } | |
170 } | |
171 | |
172 private readonly Guid guid_; | |
173 | |
174 private readonly IDebugPortRequest2 request_; | |
175 private readonly IDebugPortSupplier2 supplier_; | |
176 | |
177 private EventSinkCollection eventSinks_ = new EventSinkCollection(); | |
178 | |
179 #endregion | |
180 | |
181 protected abstract IEnumerable<DebugProcess> GetProcesses(); | |
182 | |
183 protected abstract DebugProcess CreateProcessInternal(ProcessStartInfo psi); | |
184 } | |
185 } | |
OLD | NEW |