|
Lines 10-49
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.cdt.dsf.gdb.launching; |
11 |
package org.eclipse.cdt.dsf.gdb.launching; |
| 12 |
|
12 |
|
|
|
13 |
import java.util.ArrayList; |
| 14 |
import java.util.Collections; |
| 15 |
import java.util.Comparator; |
| 16 |
import java.util.List; |
| 17 |
|
| 13 |
import org.eclipse.cdt.dsf.concurrent.DsfExecutor; |
18 |
import org.eclipse.cdt.dsf.concurrent.DsfExecutor; |
| 14 |
import org.eclipse.cdt.dsf.concurrent.RequestMonitor; |
19 |
import org.eclipse.cdt.dsf.concurrent.RequestMonitor; |
| 15 |
import org.eclipse.cdt.dsf.concurrent.Sequence; |
20 |
import org.eclipse.cdt.dsf.concurrent.Sequence; |
| 16 |
import org.eclipse.cdt.dsf.debug.service.IBreakpoints; |
|
|
| 17 |
import org.eclipse.cdt.dsf.debug.service.IDisassembly; |
| 18 |
import org.eclipse.cdt.dsf.debug.service.IExpressions; |
| 19 |
import org.eclipse.cdt.dsf.debug.service.IMemory; |
| 20 |
import org.eclipse.cdt.dsf.debug.service.IModules; |
| 21 |
import org.eclipse.cdt.dsf.debug.service.IProcesses; |
| 22 |
import org.eclipse.cdt.dsf.debug.service.IRegisters; |
| 23 |
import org.eclipse.cdt.dsf.debug.service.IRunControl; |
| 24 |
import org.eclipse.cdt.dsf.debug.service.ISourceLookup; |
| 25 |
import org.eclipse.cdt.dsf.debug.service.IStack; |
| 26 |
import org.eclipse.cdt.dsf.debug.service.command.ICommandControl; |
| 27 |
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; |
21 |
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; |
| 28 |
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl; |
|
|
| 29 |
import org.eclipse.cdt.dsf.mi.service.IMIBackend; |
| 30 |
import org.eclipse.cdt.dsf.mi.service.MIBreakpointsManager; |
| 31 |
import org.eclipse.cdt.dsf.service.DsfServicesTracker; |
| 32 |
import org.eclipse.cdt.dsf.service.IDsfService; |
22 |
import org.eclipse.cdt.dsf.service.IDsfService; |
|
|
23 |
import org.osgi.framework.InvalidSyntaxException; |
| 24 |
import org.osgi.framework.ServiceReference; |
| 33 |
|
25 |
|
| 34 |
public class ShutdownSequence extends Sequence { |
26 |
public class ShutdownSequence extends Sequence { |
| 35 |
|
27 |
|
| 36 |
String fSessionId; |
28 |
class ServiceShutdownStep extends Step { |
| 37 |
|
29 |
|
| 38 |
String fApplicationName; |
30 |
IDsfService fService; |
| 39 |
|
31 |
|
| 40 |
String fDebugModelId; |
32 |
ServiceShutdownStep( IDsfService service ) { |
| 41 |
|
33 |
super(); |
| 42 |
DsfServicesTracker fTracker; |
34 |
fService = service; |
|
|
35 |
} |
| 36 |
|
| 37 |
/* (non-Javadoc) |
| 38 |
* @see org.eclipse.cdt.dsf.concurrent.Sequence.Step#execute(org.eclipse.cdt.dsf.concurrent.RequestMonitor) |
| 39 |
*/ |
| 40 |
@Override |
| 41 |
public void execute( final RequestMonitor rm ) { |
| 42 |
fService.shutdown( new RequestMonitor( getExecutor(), rm ) { |
| 43 |
|
| 44 |
/* (non-Javadoc) |
| 45 |
* @see org.eclipse.cdt.dsf.concurrent.RequestMonitor#handleCompleted() |
| 46 |
*/ |
| 47 |
@Override |
| 48 |
protected void handleCompleted() { |
| 49 |
if ( !isSuccess() ) { |
| 50 |
GdbPlugin.getDefault().getLog().log( getStatus() ); |
| 51 |
} |
| 52 |
rm.done(); |
| 53 |
} |
| 54 |
} ); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
private String fSessionId; |
| 59 |
|
| 60 |
private Step[] fSteps; |
| 43 |
|
61 |
|
| 44 |
public ShutdownSequence(DsfExecutor executor, String sessionId, RequestMonitor requestMonitor) { |
62 |
public ShutdownSequence(DsfExecutor executor, String sessionId, RequestMonitor requestMonitor) { |
| 45 |
super(executor, requestMonitor); |
63 |
super(executor, requestMonitor); |
| 46 |
fSessionId = sessionId; |
64 |
fSessionId = sessionId; |
|
|
65 |
fSteps = createSteps(); |
| 47 |
} |
66 |
} |
| 48 |
|
67 |
|
| 49 |
@Override |
68 |
@Override |
|
Lines 51-166
Link Here
|
| 51 |
return fSteps; |
70 |
return fSteps; |
| 52 |
} |
71 |
} |
| 53 |
|
72 |
|
| 54 |
private final Step[] fSteps = new Step[] { new Step() { |
73 |
private Step[] createSteps() { |
| 55 |
@Override |
74 |
IDsfService[] services = getServices(); |
| 56 |
public void execute(RequestMonitor requestMonitor) { |
75 |
ServiceShutdownStep[] steps = new ServiceShutdownStep[services.length]; |
| 57 |
assert GdbPlugin.getBundleContext() != null; |
76 |
for ( int i = 0; i < steps.length; ++i ) |
| 58 |
fTracker = new DsfServicesTracker(GdbPlugin.getBundleContext(), fSessionId); |
77 |
steps[i] = new ServiceShutdownStep( services[i] ); |
| 59 |
requestMonitor.done(); |
78 |
return steps; |
| 60 |
} |
79 |
} |
| 61 |
|
80 |
|
| 62 |
@Override |
81 |
private IDsfService[] getServices() { |
| 63 |
public void rollBack(RequestMonitor requestMonitor) { |
82 |
IDsfService[] result = new IDsfService[0]; |
| 64 |
fTracker.dispose(); |
83 |
try { |
| 65 |
fTracker = null; |
84 |
ServiceReference<?>[] serviceRefs = GdbPlugin.getBundleContext().getServiceReferences( |
| 66 |
requestMonitor.done(); |
85 |
IDsfService.class.getName(), |
| 67 |
} |
86 |
String.format( "(%s=%s)", IDsfService.PROP_SESSION_ID, fSessionId ).intern() ); //$NON-NLS-1$ |
| 68 |
}, new Step() { |
87 |
List<IDsfService> services = new ArrayList<IDsfService>( serviceRefs.length ); |
| 69 |
@Override |
88 |
for ( ServiceReference<?> ref : serviceRefs ) { |
| 70 |
public void execute(RequestMonitor requestMonitor) { |
89 |
Object serviceObj = GdbPlugin.getBundleContext().getService( ref ); |
| 71 |
shutdownService(IGDBTraceControl.class, requestMonitor); |
90 |
if ( serviceObj instanceof IDsfService ) { |
| 72 |
} |
91 |
services.add( (IDsfService)serviceObj ); |
| 73 |
}, new Step() { |
92 |
} |
| 74 |
@Override |
93 |
} |
| 75 |
public void execute(RequestMonitor requestMonitor) { |
94 |
Collections.sort( services, new Comparator<IDsfService>() { |
| 76 |
shutdownService(IDisassembly.class, requestMonitor); |
95 |
|
| 77 |
} |
96 |
public int compare( IDsfService o1, IDsfService o2 ) { |
| 78 |
}, new Step() { |
97 |
return o2.getStartupNumber() - o1.getStartupNumber(); |
| 79 |
@Override |
98 |
} |
| 80 |
public void execute(RequestMonitor requestMonitor) { |
99 |
} ); |
| 81 |
shutdownService(IRegisters.class, requestMonitor); |
100 |
result = services.toArray( new IDsfService[services.size()] ); |
| 82 |
} |
101 |
} |
| 83 |
}, new Step() { |
102 |
catch( InvalidSyntaxException e ) { |
| 84 |
@Override |
103 |
// Shouldn't happen |
| 85 |
public void execute(RequestMonitor requestMonitor) { |
104 |
} |
| 86 |
shutdownService(MIBreakpointsManager.class, requestMonitor); |
105 |
return result; |
| 87 |
} |
106 |
} |
| 88 |
}, new Step() { |
|
|
| 89 |
@Override |
| 90 |
public void execute(RequestMonitor requestMonitor) { |
| 91 |
shutdownService(IBreakpoints.class, requestMonitor); |
| 92 |
} |
| 93 |
}, new Step() { |
| 94 |
@Override |
| 95 |
public void execute(RequestMonitor requestMonitor) { |
| 96 |
shutdownService(ISourceLookup.class, requestMonitor); |
| 97 |
} |
| 98 |
}, new Step() { |
| 99 |
@Override |
| 100 |
public void execute(RequestMonitor requestMonitor) { |
| 101 |
shutdownService(IExpressions.class, requestMonitor); |
| 102 |
} |
| 103 |
}, new Step() { |
| 104 |
@Override |
| 105 |
public void execute(RequestMonitor requestMonitor) { |
| 106 |
shutdownService(IStack.class, requestMonitor); |
| 107 |
} |
| 108 |
}, new Step() { |
| 109 |
@Override |
| 110 |
public void execute(RequestMonitor requestMonitor) { |
| 111 |
shutdownService(IModules.class, requestMonitor); |
| 112 |
} |
| 113 |
}, new Step() { |
| 114 |
@Override |
| 115 |
public void execute(RequestMonitor requestMonitor) { |
| 116 |
shutdownService(IMemory.class, requestMonitor); |
| 117 |
} |
| 118 |
}, new Step() { |
| 119 |
@Override |
| 120 |
public void execute(RequestMonitor requestMonitor) { |
| 121 |
shutdownService(IRunControl.class, requestMonitor); |
| 122 |
} |
| 123 |
}, new Step() { |
| 124 |
@Override |
| 125 |
public void execute(RequestMonitor requestMonitor) { |
| 126 |
shutdownService(IProcesses.class, requestMonitor); |
| 127 |
} |
| 128 |
}, new Step() { |
| 129 |
@Override |
| 130 |
public void execute(RequestMonitor requestMonitor) { |
| 131 |
shutdownService(ICommandControl.class, requestMonitor); |
| 132 |
} |
| 133 |
}, new Step() { |
| 134 |
@Override |
| 135 |
public void execute(RequestMonitor requestMonitor) { |
| 136 |
shutdownService(IMIBackend.class, requestMonitor); |
| 137 |
} |
| 138 |
}, new Step() { |
| 139 |
@Override |
| 140 |
public void execute(RequestMonitor requestMonitor) { |
| 141 |
fTracker.dispose(); |
| 142 |
fTracker = null; |
| 143 |
requestMonitor.done(); |
| 144 |
} |
| 145 |
} }; |
| 146 |
|
| 147 |
@SuppressWarnings("unchecked") |
| 148 |
private void shutdownService(Class clazz, final RequestMonitor requestMonitor) { |
| 149 |
IDsfService service = (IDsfService)fTracker.getService(clazz); |
| 150 |
if (service != null) { |
| 151 |
service.shutdown(new RequestMonitor(getExecutor(), requestMonitor) { |
| 152 |
@Override |
| 153 |
protected void handleCompleted() { |
| 154 |
if (!isSuccess()) { |
| 155 |
GdbPlugin.getDefault().getLog().log(getStatus()); |
| 156 |
} |
| 157 |
requestMonitor.done(); |
| 158 |
} |
| 159 |
}); |
| 160 |
} else { |
| 161 |
// It is possible that a particular service was not instantiated at all |
| 162 |
// depending on our backend |
| 163 |
requestMonitor.done(); |
| 164 |
} |
| 165 |
} |
| 166 |
} |
107 |
} |