Package: DbgpOperation$1

DbgpOperation$1

nameinstructionbranchcomplexitylinemethod
run(IProgressMonitor)
M: 45 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
{...}
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * #%~
3: * org.overture.ide.debug
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.debug.core.model.internal.operations;
23:
24: import org.eclipse.core.runtime.IProgressMonitor;
25: import org.eclipse.core.runtime.IStatus;
26: import org.eclipse.core.runtime.Status;
27: import org.eclipse.core.runtime.jobs.Job;
28: import org.overture.ide.debug.core.VdmDebugPlugin;
29: import org.overture.ide.debug.core.dbgp.IDbgpStatus;
30: import org.overture.ide.debug.core.dbgp.commands.IDbgpCommands;
31: import org.overture.ide.debug.core.dbgp.commands.IDbgpCoreCommands;
32: import org.overture.ide.debug.core.dbgp.commands.IDbgpExtendedCommands;
33: import org.overture.ide.debug.core.dbgp.exceptions.DbgpException;
34: import org.overture.ide.debug.core.dbgp.exceptions.DbgpOpertionCanceledException;
35: import org.overture.ide.debug.core.dbgp.exceptions.DbgpTimeoutException;
36: import org.overture.ide.debug.core.model.IVdmThread;
37:
38: public abstract class DbgpOperation
39: {
40:         private static final boolean DEBUG = false;// VdmDebugPlugin.DEBUG;
41:
42:         public interface IResultHandler
43:         {
44:                 void finish(IDbgpStatus status, DbgpException e);
45:         }
46:
47:         private final Job job;
48:         private final IDbgpCommands commands;
49:
50:         protected IDbgpCoreCommands getCore()
51:         {
52:                 return commands.getCoreCommands();
53:         }
54:
55:         protected IDbgpExtendedCommands getExtended()
56:         {
57:                 return commands.getExtendedCommands();
58:         }
59:
60:         private final IResultHandler resultHandler;
61:
62:         protected void callFinish(IDbgpStatus status)
63:         {
64:                 if (DEBUG)
65:                 {
66:                         System.out.println("Status: " + status); //$NON-NLS-1$
67:                 }
68:
69:                 resultHandler.finish(status, null);
70:         }
71:
72:         protected DbgpOperation(IVdmThread thread, String name,
73:                         IResultHandler handler)
74:         {
75:                 this.resultHandler = handler;
76:
77:                 this.commands = thread.getDbgpSession();
78:
79:                 job = new Job(name)
80:                 {
81:                         protected IStatus run(IProgressMonitor monitor)
82:                         {
83:                                 // TODO: improve
84:                                 try
85:                                 {
86:                                         process();
87:                                 } catch (DbgpOpertionCanceledException e)
88:                                 {
89:                                         // Operation was canceled cause debugger is shutting down
90:                                 } catch (DbgpTimeoutException e)
91:                                 {
92:•                                        if (VdmDebugPlugin.DEBUG)
93:                                         {
94:                                                 e.printStackTrace();
95:                                         }
96:                                         resultHandler.finish(null, e);
97:                                 } catch (DbgpException e)
98:                                 {
99:•                                        if (VdmDebugPlugin.DEBUG)
100:                                         {
101:                                                 System.out.println("Exception: " + e.getMessage()); //$NON-NLS-1$
102:                                                 System.out.println(e.getClass());
103:                                                 e.printStackTrace();
104:                                         }
105:                                         resultHandler.finish(null, e);
106:                                 }
107:
108:                                 return Status.OK_STATUS;
109:                         }
110:                 };
111:                 job.setSystem(true);
112:                 job.setUser(false);
113:         }
114:
115:         public void schedule()
116:         {
117:                 if (DEBUG)
118:                 {
119:                         System.out.println("Starting operation: " + job.getName()); //$NON-NLS-1$
120:                 }
121:
122:                 job.schedule();
123:         }
124:
125:         protected abstract void process() throws DbgpException;
126: }