Package: VdmDebugLogManager$1

VdmDebugLogManager$1

nameinstructionbranchcomplexitylinemethod
run()
M: 25 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 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.ui.log;
23:
24: import org.eclipse.core.runtime.CoreException;
25: import org.eclipse.debug.core.DebugEvent;
26: import org.eclipse.debug.core.DebugPlugin;
27: import org.eclipse.debug.core.IDebugEventSetListener;
28: import org.eclipse.debug.core.ILaunch;
29: import org.eclipse.debug.core.ILaunchListener;
30: import org.eclipse.debug.core.model.IDebugTarget;
31: import org.eclipse.swt.widgets.Display;
32: import org.eclipse.ui.IWorkbench;
33: import org.eclipse.ui.IWorkbenchPage;
34: import org.eclipse.ui.PartInitException;
35: import org.eclipse.ui.PlatformUI;
36: import org.overture.ide.debug.core.ExtendedDebugEventDetails;
37: import org.overture.ide.debug.core.IDebugConstants;
38: import org.overture.ide.debug.core.VdmDebugPlugin;
39: import org.overture.ide.debug.core.dbgp.IDbgpRawListener;
40: import org.overture.ide.debug.core.dbgp.IDbgpRawPacket;
41: import org.overture.ide.debug.core.dbgp.internal.IDbgpDebugingEngine;
42: import org.overture.ide.debug.core.model.IVdmDebugTarget;
43: import org.overture.ide.debug.core.model.IVdmThread;
44:
45: public class VdmDebugLogManager implements ILaunchListener,
46:                 IDebugEventSetListener, IDbgpRawListener
47: {
48:
49:         private static VdmDebugLogManager instance;
50:
51:         private VdmDebugLogView view;
52:
53:         private VdmDebugLogManager()
54:         {
55:                 // empty constructor
56:         }
57:
58:         public static synchronized VdmDebugLogManager getInstance()
59:         {
60:                 if (instance == null)
61:                 {
62:                         instance = new VdmDebugLogManager();
63:                 }
64:
65:                 return instance;
66:         }
67:
68:         /*
69:          * @see org.eclipse.dltk.dbgp.IDbgpRawListener#dbgpPacketReceived(java.lang.String )
70:          */
71:         public void dbgpPacketReceived(int sessionId, IDbgpRawPacket content)
72:         {
73:                 append(new VdmDebugLogItem(Messages.ItemType_Input, sessionId, content));
74:         }
75:
76:         /*
77:          * @see org.eclipse.dltk.dbgp.IDbgpRawListener#dbgpPacketSent(java.lang.String)
78:          */
79:         public void dbgpPacketSent(int sessionId, IDbgpRawPacket content)
80:         {
81:                 append(new VdmDebugLogItem(Messages.ItemType_Output, sessionId, content));
82:         }
83:
84:         /*
85:          * @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse .debug.core.DebugEvent[])
86:          */
87:         public void handleDebugEvents(DebugEvent[] events)
88:         {
89:                 if (view == null)
90:                 {
91:                         return;
92:                 }
93:
94:                 for (int i = 0; i < events.length; ++i)
95:                 {
96:                         DebugEvent event = events[i];
97:
98:                         append(new VdmDebugLogItem(Messages.ItemType_Event, getDebugEventKind(event)
99:                                         + " from " + event.getSource().getClass().getName()));//$NON-NLS-1$
100:
101:                         if (event.getKind() == DebugEvent.CREATE)
102:                         {
103:                                 handleCreateEvent(event);
104:                         } else if (event.getKind() == DebugEvent.MODEL_SPECIFIC
105:                                         && event.getDetail() == ExtendedDebugEventDetails.DGBP_NEW_CONNECTION)
106:                         {
107:                                 if (event.getSource() instanceof IDbgpDebugingEngine)
108:                                 {
109:                                         ((IDbgpDebugingEngine) event.getSource()).addRawListener(this);
110:                                 }
111:                         } else if (event.getKind() == DebugEvent.TERMINATE)
112:                         {
113:                                 handleTerminateEvent(event);
114:                         }
115:                 }
116:         }
117:
118:         /*
119:          * @see org.eclipse.debug.core.ILaunchListener#launchAdded(org.eclipse.debug. core.ILaunch)
120:          */
121:         public void launchAdded(ILaunch launch)
122:         {
123:                 // empty implementation
124:         }
125:
126:         /*
127:          * @see org.eclipse.debug.core.ILaunchListener#launchChanged(org.eclipse.debug .core.ILaunch)
128:          */
129:         public void launchChanged(ILaunch launch)
130:         {
131:                 IDebugTarget target = launch.getDebugTarget();
132:                 boolean loggingEnabled = false;
133:                 try
134:                 {
135:                         if (launch.getLaunchConfiguration() != null)
136:                         {
137:                                 loggingEnabled = launch.getLaunchConfiguration().getAttribute(IDebugConstants.VDM_LAUNCH_CONFIG_ENABLE_LOGGING, false);
138:                         }
139:
140:                 } catch (CoreException e1)
141:                 {
142:
143:                 }
144:
145:                 // bail if we're not a VdmDebugTarget or logging isn't enabled
146:                 if (!(target instanceof IVdmDebugTarget && loggingEnabled))
147:                 {
148:                         return;
149:                 }
150:
151:                 final IWorkbench wb = PlatformUI.getWorkbench();
152:                 if (wb.getWorkbenchWindowCount() > 0)
153:                 {
154:                         Display.getDefault().asyncExec(new Runnable()
155:                         {
156:                                 public void run()
157:                                 {
158:
159:                                         IWorkbenchPage page = wb.getWorkbenchWindows()[0].getActivePage();// VdmDebugPlugin.getActivePage();
160:
161:•                                        if (page != null)
162:                                         {
163:                                                 try
164:                                                 {
165:                                                         view = (VdmDebugLogView) page.showView(VdmDebugLogView.VIEW_ID);
166:
167:                                                         DebugPlugin.getDefault().addDebugEventListener(VdmDebugLogManager.this);
168:                                                 } catch (PartInitException e)
169:                                                 {
170:                                                         VdmDebugPlugin.log(e);
171:                                                 }
172:                                         }
173:                                 }
174:                         });
175:                 }
176:         }
177:
178:         /*
179:          * @see org.eclipse.debug.core.ILaunchListener#launchRemoved(org.eclipse.debug .core.ILaunch)
180:          */
181:         public void launchRemoved(ILaunch launch)
182:         {
183:                 // empty implementation
184:         }
185:
186:         protected void append(final VdmDebugLogItem item)
187:         {
188:                 view.append(item);
189:         }
190:
191:         private static String getDebugEventKind(DebugEvent event)
192:         {
193:                 switch (event.getKind())
194:                 {
195:                         case DebugEvent.CREATE:
196:                                 return Messages.EventKind_Create;
197:                         case DebugEvent.TERMINATE:
198:                                 return Messages.EventKind_Terminate;
199:                         case DebugEvent.CHANGE:
200:                                 return Messages.EventKind_Change;
201:                         case DebugEvent.SUSPEND:
202:                                 return Messages.EventKind_Suspend;
203:                         case DebugEvent.RESUME:
204:                                 return Messages.EventKind_Resume;
205:                         case DebugEvent.MODEL_SPECIFIC:
206:                                 return Messages.EventKind_ModelSpecific + '/'
207:                                                 + event.getDetail();
208:                 }
209:                 return Messages.EventKind_Unknown + '(' + event.getKind() + ')';
210:         }
211:
212:         private void handleCreateEvent(DebugEvent event)
213:         {
214:                 if (event.getSource() instanceof IVdmThread)
215:                 {
216:                         ((IVdmThread) event.getSource()).getDbgpSession().addRawListener(this);
217:                 }
218:         }
219:
220:         private void handleTerminateEvent(DebugEvent event)
221:         {
222:                 if (event.getSource() instanceof IVdmThread)
223:                 {
224:                         ((IVdmThread) event.getSource()).getDbgpSession().removeRawListenr(this);
225:                         DebugPlugin.getDefault().removeDebugEventListener(this);
226:                 }
227:         }
228:
229: }