diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 13:36:50 +0100 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2013-12-12 15:25:03 +0100 |
commit | 41ac47d732eed8392d60d0f6773e5a279d49b999 (patch) | |
tree | cf19d099db9cfdb8d73aa21c31e7aa1cc86ff860 /plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java | |
download | eclipse-poky-juno-41ac47d732eed8392d60d0f6773e5a279d49b999.tar.gz |
Migrated from the internal git server on the dora-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java')
-rw-r--r-- | plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java new file mode 100644 index 0000000..79bef61 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java | |||
@@ -0,0 +1,109 @@ | |||
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 | *******************************************************************************/ | ||
11 | package org.yocto.sdk.remotetools.actions; | ||
12 | |||
13 | import java.io.File; | ||
14 | import java.lang.reflect.InvocationTargetException; | ||
15 | import java.text.SimpleDateFormat; | ||
16 | import java.util.Calendar; | ||
17 | |||
18 | import org.eclipse.core.runtime.IProgressMonitor; | ||
19 | import org.eclipse.core.runtime.SubProgressMonitor; | ||
20 | import org.eclipse.rse.core.model.IHost; | ||
21 | import org.eclipse.swt.widgets.Display; | ||
22 | import org.eclipse.ui.IWorkbenchPage; | ||
23 | import org.eclipse.ui.PartInitException; | ||
24 | import org.eclipse.ui.PlatformUI; | ||
25 | import org.yocto.sdk.remotetools.views.BaseFileView; | ||
26 | |||
27 | public class PowertopModel extends BaseModel { | ||
28 | |||
29 | private static final String REMOTE_EXEC = "/tmp/yocto_tool.sh"; | ||
30 | private static final String LOCAL_SCRIPT = "resources/yocto_tool.sh"; | ||
31 | |||
32 | private static final String REMOTE_FILE_PREFIX = "/tmp/yocto-powertop-"; | ||
33 | private static final String LOCAL_FILE_SUFFIX = ".local"; | ||
34 | |||
35 | private static final String TASK_NAME = "powertop command"; | ||
36 | |||
37 | private Float time; | ||
38 | private boolean showpid; | ||
39 | Display display; | ||
40 | |||
41 | public PowertopModel(IHost host, Float time,boolean showpid,Display display) { | ||
42 | super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); | ||
43 | this.time=time; | ||
44 | this.showpid=showpid; | ||
45 | this.display=display; | ||
46 | } | ||
47 | |||
48 | @Override | ||
49 | public void postProcess(IProgressMonitor monitor) | ||
50 | throws InvocationTargetException, InterruptedException { | ||
51 | try { | ||
52 | new File(localFile).delete(); | ||
53 | }catch (Exception e) { | ||
54 | |||
55 | } | ||
56 | } | ||
57 | |||
58 | private void generateData(IProgressMonitor monitor) throws Exception { | ||
59 | String currentDate = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); | ||
60 | remoteFile = new String(REMOTE_FILE_PREFIX + currentDate); | ||
61 | localFile = new String(remoteFile + LOCAL_FILE_SUFFIX); | ||
62 | |||
63 | String args = "start -l " + remoteFile + " powertop --debug --time " + time.toString(); | ||
64 | if(showpid) | ||
65 | args += " -p"; | ||
66 | runRemoteShellExec(monitor, args, true); | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | public void process(IProgressMonitor monitor) | ||
71 | throws InvocationTargetException, InterruptedException { | ||
72 | |||
73 | monitor.beginTask("Running powertop", 100); | ||
74 | try { | ||
75 | //running powertop | ||
76 | monitor.subTask("Generating powertop data file remotely"); | ||
77 | generateData(new SubProgressMonitor(monitor,30)); | ||
78 | //download datafile | ||
79 | monitor.subTask("Downloading powertop data file"); | ||
80 | getDataFile(new SubProgressMonitor(monitor,30)); | ||
81 | //show it in the powertop view | ||
82 | display.syncExec(new Runnable() { | ||
83 | public void run() { | ||
84 | BaseFileView view; | ||
85 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
86 | try { | ||
87 | view=(BaseFileView) page.showView("org.yocto.sdk.remotetools.views.PowerTopView"); | ||
88 | }catch (PartInitException e) { | ||
89 | e.printStackTrace(); | ||
90 | return; | ||
91 | } | ||
92 | view.setInput(localFile); | ||
93 | page.bringToTop(view); | ||
94 | } | ||
95 | }); | ||
96 | |||
97 | }catch (InterruptedException e){ | ||
98 | throw e; | ||
99 | }catch (InvocationTargetException e) { | ||
100 | throw e; | ||
101 | }catch (Exception e){ | ||
102 | throw new InvocationTargetException(e, e.getMessage()); | ||
103 | }finally { | ||
104 | monitor.done(); | ||
105 | } | ||
106 | |||
107 | } | ||
108 | |||
109 | } | ||