summaryrefslogtreecommitdiffstats
path: root/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java')
-rw-r--r--plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java107
1 files changed, 107 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java
new file mode 100644
index 0000000..60d7d76
--- /dev/null
+++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/SystemtapModel.java
@@ -0,0 +1,107 @@
1/*******************************************************************************
2 * Copyright (c) 2010 Intel Corporation.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Intel - initial API and implementation
10 *******************************************************************************/
11package org.yocto.sdk.remotetools.actions;
12
13import java.io.File;
14import java.lang.reflect.InvocationTargetException;
15
16import org.eclipse.core.runtime.IProgressMonitor;
17import org.eclipse.core.runtime.NullProgressMonitor;
18import org.eclipse.core.runtime.OperationCanceledException;
19import org.eclipse.jface.dialogs.ProgressMonitorDialog;
20import org.eclipse.jface.operation.IRunnableWithProgress;
21import org.eclipse.rse.subsystems.terminals.core.ITerminalServiceSubSystem;
22import org.eclipse.rse.ui.SystemBasePlugin;
23import org.eclipse.swt.widgets.Display;
24import org.eclipse.ui.console.ConsolePlugin;
25import org.eclipse.ui.console.IConsole;
26import org.eclipse.ui.console.IConsoleManager;
27import org.eclipse.ui.console.MessageConsole;
28import org.yocto.remote.utils.ShellSession;
29import org.yocto.remote.utils.RemoteHelper;
30import org.yocto.remote.utils.CommonHelper;
31
32public class SystemtapModel extends BaseModel {
33 protected static final String DEFAULT_INIT_SCRIPT = "oe-init-build-env";
34 protected static final String SYSTEMTAP_CONSOLE = "Systemtap Console";
35
36 private static final String TASK_NAME = "systemtap command";
37
38 protected MessageConsole sessionConsole;
39 private String metadata_location;
40 private String builddir_location;
41 private String remote_host;
42 private String user_id;
43 private String systemtap_script;
44 private String systemtap_args;
45
46 Display display;
47
48 public SystemtapModel(String metadata_location, String builddir_location, String remote_host, String user_id, String systemtap_script, String systemtap_args, Display display) {
49 super(null, TASK_NAME, "", "");
50 this.metadata_location = metadata_location;
51 this.builddir_location = builddir_location;
52 this.remote_host = remote_host;
53 this.user_id = user_id;
54 this.systemtap_script = systemtap_script;
55 this.systemtap_args = systemtap_args;
56 this.display = display;
57 }
58
59 @Override
60 public void preProcess(IProgressMonitor monitor)
61 throws InvocationTargetException, InterruptedException {
62 final ITerminalServiceSubSystem terminalSubSystem = RemoteHelper.getTerminalSubSystem(host);
63 if (!terminalSubSystem.isConnected()) {
64 try {
65 ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
66 dialog.run(true, true, new IRunnableWithProgress(){
67 @Override
68 public void run(IProgressMonitor monitor) {
69 monitor.beginTask("Connecting to remote target ...", 100);
70 try {
71 terminalSubSystem.connect(new NullProgressMonitor(), false);
72 monitor.done();
73 } catch (Exception e) {
74 CommonHelper.showErrorDialog("Connection failure", null, e.getMessage());
75 monitor.done();
76 }
77 }
78 });
79 } catch (OperationCanceledException e) {
80 // user canceled, return silently
81 } catch (Exception e) {
82 SystemBasePlugin.logError(e.getLocalizedMessage(), e);
83 }
84 }
85 }
86
87 protected String changeTerm = "export TERM=vt100;";
88
89 @Override
90 public void process(IProgressMonitor monitor)
91 throws InvocationTargetException, InterruptedException {
92 try {
93 ShellSession shell = new ShellSession(ShellSession.SHELL_TYPE_BASH,
94 new File(this.metadata_location),new File(this.builddir_location),
95 DEFAULT_INIT_SCRIPT, sessionConsole.newOutputStream());
96 boolean acceptedKey = shell.ensureKnownHostKey(user_id, remote_host);
97 if (acceptedKey) {
98 String crosstapCmd = "crosstap " + user_id + "@" + remote_host + " " + systemtap_script;
99 if (systemtap_args != null)
100 crosstapCmd = crosstapCmd + " " + systemtap_args;
101 shell.execute(crosstapCmd);
102 }
103 } catch (Exception e) {
104 throw new InvocationTargetException(e,e.getMessage());
105 }
106 }
107}