diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:23:09 +0200 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:24:09 +0200 |
commit | c7da892cb23d50d4d85746c9a0b6b14bf570989d (patch) | |
tree | e7136073f386d6156f51766c498c52c30c8df85f /plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java | |
download | eclipse-poky-kepler-c7da892cb23d50d4d85746c9a0b6b14bf570989d.tar.gz |
initial commit for Enea Linux 4.0daisy
Migrated from the internal git server on the daisy-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 | 106 |
1 files changed, 106 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..932f1c2 --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/actions/PowertopModel.java | |||
@@ -0,0 +1,106 @@ | |||
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 | Display display; | ||
39 | |||
40 | public PowertopModel(IHost host, Float time, Display display) { | ||
41 | super(host, TASK_NAME, LOCAL_SCRIPT, REMOTE_EXEC); | ||
42 | this.time=time; | ||
43 | this.display=display; | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public void postProcess(IProgressMonitor monitor) | ||
48 | throws InvocationTargetException, InterruptedException { | ||
49 | try { | ||
50 | new File(localFile).delete(); | ||
51 | }catch (Exception e) { | ||
52 | |||
53 | } | ||
54 | } | ||
55 | |||
56 | private void generateData(IProgressMonitor monitor) throws Exception { | ||
57 | String currentDate = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime()).toString(); | ||
58 | remoteFile = new String(REMOTE_FILE_PREFIX + currentDate); | ||
59 | localFile = new String(remoteFile + LOCAL_FILE_SUFFIX); | ||
60 | |||
61 | String args = "start -l " + remoteFile + " powertop --debug --time " + time.toString(); | ||
62 | |||
63 | runRemoteShellExec(monitor, args, true); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public void process(IProgressMonitor monitor) | ||
68 | throws InvocationTargetException, InterruptedException { | ||
69 | |||
70 | monitor.beginTask("Running powertop", 100); | ||
71 | try { | ||
72 | //running powertop | ||
73 | monitor.subTask("Generating powertop data file remotely"); | ||
74 | generateData(new SubProgressMonitor(monitor,30)); | ||
75 | //download datafile | ||
76 | monitor.subTask("Downloading powertop data file"); | ||
77 | getDataFile(new SubProgressMonitor(monitor,30)); | ||
78 | //show it in the powertop view | ||
79 | display.syncExec(new Runnable() { | ||
80 | public void run() { | ||
81 | BaseFileView view; | ||
82 | IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | ||
83 | try { | ||
84 | view=(BaseFileView) page.showView("org.yocto.sdk.remotetools.views.PowerTopView"); | ||
85 | }catch (PartInitException e) { | ||
86 | e.printStackTrace(); | ||
87 | return; | ||
88 | } | ||
89 | view.setInput(localFile); | ||
90 | page.bringToTop(view); | ||
91 | } | ||
92 | }); | ||
93 | |||
94 | }catch (InterruptedException e){ | ||
95 | throw e; | ||
96 | }catch (InvocationTargetException e) { | ||
97 | throw e; | ||
98 | }catch (Exception e){ | ||
99 | throw new InvocationTargetException(e, e.getMessage()); | ||
100 | }finally { | ||
101 | monitor.done(); | ||
102 | } | ||
103 | |||
104 | } | ||
105 | |||
106 | } | ||