From 4d2ab4b110b483b15d950b897f05b89ee0ee8a45 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Tue, 2 Nov 2010 18:19:41 +0000 Subject: Refactor to abide by Eclipse naming standards. --- .../.project | 2 +- .../META-INF/MANIFEST.MF | 8 +- .../plugin.xml | 20 +- .../sequoyah/device/LinuxToolsPlugin.java | 84 ++++++ .../linuxtools/sequoyah/device/Messages.java | 33 ++ .../linuxtools/sequoyah/device/messages.properties | 21 ++ .../sequoyah/device/network/tcf/TCFProvider.java | 139 +++++++++ .../sequoyah/device/network/tcf/TCFWrapper.java | 98 ++++++ .../device/network/telnet/TelnetProvider.java | 193 ++++++++++++ .../device/network/telnet/TelnetWrapper.java | 235 +++++++++++++++ .../device/tools/cpuload/CpuLoadProcessor.java | 279 +++++++++++++++++ .../sequoyah/device/tools/cpuload/CpuLoadTool.java | 208 +++++++++++++ .../sequoyah/device/tools/cpuload/CpuLoadView.java | 332 +++++++++++++++++++++ .../tools/cpuload/CpuLoadViewContentProvider.java | 61 ++++ .../tools/cpuload/CpuLoadViewLabelProvider.java | 54 ++++ .../device/tools/cpuload/DialogOptions.java | 108 +++++++ .../sequoyah/device/tools/cpuload/Messages.java | 49 +++ .../device/tools/cpuload/ViewActionOptions.java | 59 ++++ .../device/tools/cpuload/messages.properties | 38 +++ .../device/tools/memorymap/MemoryMapProcessor.java | 138 +++++++++ .../device/tools/memorymap/MemoryMapTool.java | 184 ++++++++++++ .../memorymap/MemoryMapVViewLabelProvider.java | 59 ++++ .../device/tools/memorymap/MemoryMapView.java | 290 ++++++++++++++++++ .../memorymap/MemoryMapViewContentProvider.java | 60 ++++ .../sequoyah/device/tools/memorymap/Messages.java | 40 +++ .../device/tools/memorymap/messages.properties | 27 ++ .../device/linuxtools/LinuxToolsPlugin.java | 84 ------ .../sequoyah/device/linuxtools/Messages.java | 33 -- .../sequoyah/device/linuxtools/messages.properties | 21 -- .../device/linuxtools/network/tcf/TCFProvider.java | 139 --------- .../device/linuxtools/network/tcf/TCFWrapper.java | 98 ------ .../linuxtools/network/telnet/TelnetProvider.java | 193 ------------ .../linuxtools/network/telnet/TelnetWrapper.java | 235 --------------- .../linuxtools/tools/cpuload/CpuLoadProcessor.java | 279 ----------------- .../linuxtools/tools/cpuload/CpuLoadTool.java | 208 ------------- .../linuxtools/tools/cpuload/CpuLoadView.java | 332 --------------------- .../tools/cpuload/CpuLoadViewContentProvider.java | 61 ---- .../tools/cpuload/CpuLoadViewLabelProvider.java | 54 ---- .../linuxtools/tools/cpuload/DialogOptions.java | 108 ------- .../device/linuxtools/tools/cpuload/Messages.java | 49 --- .../tools/cpuload/ViewActionOptions.java | 59 ---- .../linuxtools/tools/cpuload/messages.properties | 38 --- .../tools/memorymap/MemoryMapProcessor.java | 138 --------- .../linuxtools/tools/memorymap/MemoryMapTool.java | 184 ------------ .../memorymap/MemoryMapVViewLabelProvider.java | 59 ---- .../linuxtools/tools/memorymap/MemoryMapView.java | 290 ------------------ .../memorymap/MemoryMapViewContentProvider.java | 60 ---- .../linuxtools/tools/memorymap/Messages.java | 40 --- .../linuxtools/tools/memorymap/messages.properties | 27 -- 49 files changed, 2804 insertions(+), 2804 deletions(-) create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/LinuxToolsPlugin.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/Messages.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/messages.properties create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/tcf/TCFProvider.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/tcf/TCFWrapper.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/telnet/TelnetProvider.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/telnet/TelnetWrapper.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadProcessor.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadTool.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadView.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadViewContentProvider.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadViewLabelProvider.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/DialogOptions.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/Messages.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/ViewActionOptions.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/messages.properties create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapProcessor.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapTool.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapVViewLabelProvider.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapView.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapViewContentProvider.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/Messages.java create mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/messages.properties delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/LinuxToolsPlugin.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/Messages.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/messages.properties delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/tcf/TCFProvider.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/tcf/TCFWrapper.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/telnet/TelnetProvider.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/telnet/TelnetWrapper.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadProcessor.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadTool.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadView.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadViewContentProvider.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadViewLabelProvider.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/DialogOptions.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/Messages.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/ViewActionOptions.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/messages.properties delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapProcessor.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapTool.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapVViewLabelProvider.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapView.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapViewContentProvider.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/Messages.java delete mode 100644 proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/messages.properties (limited to 'proctools') diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/.project b/proctools/org.eclipse.sequoyah.device.linuxtools/.project index 20cac40bbf..76d668bc9d 100644 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/.project +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/.project @@ -1,6 +1,6 @@ - org.eclipse.sequoyah.device.linuxtools + org.eclipse.linuxtools.sequoyah.device diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/META-INF/MANIFEST.MF b/proctools/org.eclipse.sequoyah.device.linuxtools/META-INF/MANIFEST.MF index 006ce30ef5..02961b59da 100644 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/META-INF/MANIFEST.MF +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/META-INF/MANIFEST.MF @@ -4,11 +4,11 @@ Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.sequoyah.device.linuxtools;singleton:=true Bundle-Version: 0.1.0.qualifier Bundle-Localization: plugin -Bundle-Activator: org.eclipse.sequoyah.device.linuxtools.LinuxToolsPlugin +Bundle-Activator: org.eclipse.linuxtools.sequoyah.device.LinuxToolsPlugin Bundle-Vendor: %providerName Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy -Require-Bundle: org.eclipse.sequoyah.device.linuxtools.base, +Require-Bundle: org.eclipse.linuxtools.sequoyah.device.base, org.eclipse.sequoyah.device.common.utilities, org.eclipse.ui, org.eclipse.core.runtime, @@ -17,5 +17,5 @@ Require-Bundle: org.eclipse.sequoyah.device.linuxtools.base, org.eclipse.rse.core, org.eclipse.rse.subsystems.files.core, org.eclipse.rse.services -Export-Package: org.eclipse.sequoyah.device.linuxtools.network.tcf, - org.eclipse.sequoyah.device.linuxtools.network.telnet +Export-Package: org.eclipse.linuxtools.sequoyah.device.network.tcf, + org.eclipse.linuxtools.sequoyah.device.network.telnet diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/plugin.xml b/proctools/org.eclipse.sequoyah.device.linuxtools/plugin.xml index abb8f68448..b87dd6fd90 100644 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/plugin.xml +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/plugin.xml @@ -6,27 +6,27 @@ point="org.eclipse.ui.views"> + id="org.eclipse.linuxtools.sequoyah.device.Category"> + category="org.eclipse.linuxtools.sequoyah.device.Category" + class="org.eclipse.linuxtools.sequoyah.device.tools.memorymap.MemoryMapView" + id="org.eclipse.linuxtools.sequoyah.device.tools.memorymap.View"> + point="org.eclipse.linuxtools.sequoyah.device.base.protocols"> @@ -35,7 +35,7 @@ diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/LinuxToolsPlugin.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/LinuxToolsPlugin.java new file mode 100644 index 0000000000..ab431365ad --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/LinuxToolsPlugin.java @@ -0,0 +1,84 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device; + +import org.eclipse.sequoyah.device.common.utilities.BasePlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class LinuxToolsPlugin extends BasePlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.linuxtools.sequoyah.device"; //$NON-NLS-1$ + + // Common icons + public static final String ICON_RUN = "run.gif"; //$NON-NLS-1$ + public static final String ICON_PAUSE = "pause.gif"; //$NON-NLS-1$ + public static final String ICON_OPTIONS = "options.gif"; //$NON-NLS-1$ + public static final String ICON_REFRESH = "refresh.gif"; //$NON-NLS-1$ + public static final String ICON_DISCONNECT = "disconnect.gif"; //$NON-NLS-1$ + public static final String ICON_CONNECT = "connect.gif"; //$NON-NLS-1$ + + // The shared instance + private static LinuxToolsPlugin plugin; + + private static final String[] allIcons = {ICON_RUN, + ICON_PAUSE, + ICON_OPTIONS, + ICON_REFRESH, + ICON_DISCONNECT, + ICON_CONNECT}; + + /** + * Returns the shared instance + * @return the shared instance + */ + public static LinuxToolsPlugin getDefault() { + return plugin; + } + + /** + * The constructor + */ + public LinuxToolsPlugin() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + @Override + protected void initializeImageRegistry() { + String path = getIconPath(); + for (String s: allIcons) { + putImageInRegistry(s, path + s); + } + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/Messages.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/Messages.java new file mode 100644 index 0000000000..bcc84418bd --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/Messages.java @@ -0,0 +1,33 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device; + +import org.eclipse.osgi.util.NLS; + +/** + * @author Otavio Ferranti + * + */ +public class Messages extends NLS { + + private static String BUNDLE_NAME = "org.eclipse.linuxtools.sequoyah.device.messages"; //$NON-NLS-1$ + public static String TML_Plugin_Name; + public static String TML_Error; + public static String TML_Resource_Not_Available; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/messages.properties b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/messages.properties new file mode 100644 index 0000000000..a657aabb37 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/messages.properties @@ -0,0 +1,21 @@ +################################################################################ +# Copyright (c) 2009 Motorola Inc. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Initial Contributors: +# Otavio Ferranti (Motorola) +# +# Contributors: +# {Name} (company) - description of contribution. +################################################################################ + +# NLS_MESSAGEFORMAT_VAR +# NLS_ENCODING=UTF-8 + +TML_Plugin_Name=Linux Tools Plugin (Incubation) +TML_Error=A unexpected exception was found +TML_Resource_Not_Available=Resource not available + diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/tcf/TCFProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/tcf/TCFProvider.java new file mode 100644 index 0000000000..75aee71bee --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/tcf/TCFProvider.java @@ -0,0 +1,139 @@ +/******************************************************************************** + * Copyright (c) 2009 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.network.tcf; + +import java.io.IOException; + +import org.eclipse.linuxtools.sequoyah.device.LinuxToolsPlugin; +import org.eclipse.linuxtools.sequoyah.device.network.IConnectionProvider; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.CommandCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.OperationCode; +import org.eclipse.linuxtools.sequoyah.device.tools.AbstractNotifier; +import org.eclipse.sequoyah.device.common.utilities.logger.ILogger; + +public class TCFProvider extends AbstractNotifier implements + IConnectionProvider { + + private TCFWrapper connectionWrapper = null; + private ILogger logger = null; + + private Thread connectThread = null; + private Thread sendCommandThread = null; + + /** + * The constructor. + */ + public TCFProvider() { + connectionWrapper = new TCFWrapper(); + logger = LinuxToolsPlugin.getLogger(); + } + + /** + * This method will be executed in a separated thread and will produce + * an event to be sent to the registered listeners. + */ + public void connect(String host, int port) throws IOException { + final String hostAux = host; + final int portAux = port; + final TCFWrapper connectionWrapperAux = connectionWrapper; + + /*TODO: Enhance this. It would be great if all these executed-in-other threads + were located under a synchronized block */ + + connectThread = new Thread() { + public void run() { + try { + connectionWrapperAux.connect(hostAux, portAux); + TCFProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_CONNECT_FINISHED, + OperationCode.SUCCESS); + } catch (IOException ie) { + TCFProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_CONNECT_ERROR, + OperationCode.UNEXPECTED_RESULT); + } + + } + }; + connectThread.start(); + } + + public void disconnect() throws IOException { + if (null != connectThread && + connectThread.isAlive()) { + connectThread.interrupt(); + } + + if (null != sendCommandThread && + sendCommandThread.isAlive()) { + sendCommandThread.interrupt(); + } + connectionWrapper.disconnect(); + notifyListeners( + EventCode.EVT_PROVIDER_DISCONNECT_FINISHED, OperationCode.SUCCESS); + } + + public StringBuffer getLastResponde() { + return connectionWrapper.getLastResponde(); + } + + public void login(String user, String password) throws IOException { + + } + + /** + * This method will be executed in a separated thread and will produce + * an event to be sent to the registered listeners. + */ + public void sendCommand(CommandCode cmd, String cmdStr) throws IOException { + + if (CommandCode.FETCH_FILE != cmd) { + return; + } + + final TCFWrapper connectionWrapperAux = connectionWrapper; + + final String path = cmdStr.substring(0, cmdStr.lastIndexOf("/")); + final String fileName = cmdStr.substring(cmdStr.lastIndexOf("/")); + + sendCommandThread = new Thread() { + public void run() { + try { + + if (null != connectionWrapperAux.fetchFile(path, fileName)) { + StringBuffer result = connectionWrapperAux.getLastResponde(); + TCFProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_SENDCOMMAND_FINISHED, result); + } else { + logger.info("##### NULL ######"); + } + } catch (IOException ie) { + TCFProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_SENDCOMMAND_ERROR, null); + } + + } + }; + sendCommandThread.start(); + } + + public void sendData(String out) { + connectionWrapper.sendData(out); + } + + public void setResponseLength(int maxLength) { + connectionWrapper.setResponseLength(maxLength); + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/tcf/TCFWrapper.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/tcf/TCFWrapper.java new file mode 100644 index 0000000000..42073a9a2b --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/tcf/TCFWrapper.java @@ -0,0 +1,98 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.network.tcf; + +import java.io.IOException; +import java.io.InputStream; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.OperationCode; +import org.eclipse.rse.core.IRSECoreRegistry; +import org.eclipse.rse.core.IRSESystemType; +import org.eclipse.rse.core.RSECorePlugin; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.ISystemRegistry; +import org.eclipse.rse.services.clientserver.messages.SystemMessageException; +import org.eclipse.rse.subsystems.files.core.model.RemoteFileUtility; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; + +public class TCFWrapper { + + private StringBuffer lastResponse = null; + private IHost rseHost = null; + + public void connect(String host, int port) throws IOException { + ISystemRegistry rseSystemRegistry = RSECorePlugin.getTheSystemRegistry(); + IRSECoreRegistry rseCoreRegistry = RSECorePlugin.getTheCoreRegistry(); + IRSESystemType tcfSystemType = rseCoreRegistry.getSystemTypeById("org.eclipse.tm.tcf.rse.systemType"); + try { + rseHost = rseSystemRegistry.createHost(tcfSystemType, host, host, host); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void disconnect() throws IOException { + // TODO Auto-generated method stub + + } + + public StringBuffer getLastResponde() { + return lastResponse; + } + + public OperationCode login(String user, String password) throws IOException { + // TODO Auto-generated method stub + return OperationCode.SUCCESS; + } + + public String fetchFile(String path, String fileName) throws IOException { + IRemoteFileSubSystem remoteFileSubSystem = + RemoteFileUtility.getFileSubSystem(rseHost); + InputStream inputStream = null; + + try { + remoteFileSubSystem.connect(new NullProgressMonitor(), false); + inputStream = remoteFileSubSystem.getInputStream(path, fileName, + false, new NullProgressMonitor()); + } catch (SystemMessageException sme) { + // TODO Auto-generated catch block + sme.printStackTrace(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + lastResponse = new StringBuffer(); + + byte[] b = new byte[16]; + char[] c = new char[16]; + while (inputStream.read(b) >= 0) { + for (int i = 0; i < b.length; i++) { + c[i] = (char) b[i]; + } + lastResponse.append(c); + } + return "OK"; + } + + public void sendData(String out) { + // TODO Auto-generated method stub + + } + + public void setResponseLength(int maxLength) { + // TODO Auto-generated method stub + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/telnet/TelnetProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/telnet/TelnetProvider.java new file mode 100644 index 0000000000..5bb41dc476 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/telnet/TelnetProvider.java @@ -0,0 +1,193 @@ +/******************************************************************************** + * Copyright (c) 2009 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.network.telnet; + +import java.io.IOException; + +import org.eclipse.linuxtools.sequoyah.device.LinuxToolsPlugin; +import org.eclipse.linuxtools.sequoyah.device.network.IConnectionProvider; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.CommandCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.OperationCode; +import org.eclipse.linuxtools.sequoyah.device.tools.AbstractNotifier; +import org.eclipse.sequoyah.device.common.utilities.logger.ILogger; + +/** + * @author Ot�vio Ferranti + */ +public class TelnetProvider extends AbstractNotifier implements IConnectionProvider { + + final private String CMD_FETCH_PREFIX = "cat "; //$NON-NLS-1$ + + private TelnetWrapper connectionWrapper = null; + private ILogger logger = null; + + private Thread connectThread = null; + private Thread loginThread = null; + private Thread sendCommandThread = null; + + /** + * The constructor. + */ + public TelnetProvider() { + connectionWrapper = new TelnetWrapper(); + logger = LinuxToolsPlugin.getLogger(); + } + + /** + * This method will be executed in a separated thread and will produce + * an event to be sent to the registered listeners. + */ + /* (non-Javadoc) + * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#connect(java.lang.String, int) + */ + public void connect(String host, int port) throws IOException { + final String hostAux = host; + final int portAux = port; + final TelnetWrapper connectionWrapperAux = connectionWrapper; + + /*TODO: Enhance this. It would be great if all these executed-in-other threads + were located under a synchronized block */ + + connectThread = new Thread() { + public void run() { + try { + OperationCode opCode; + opCode = connectionWrapperAux.connect(hostAux, portAux); + TelnetProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_CONNECT_FINISHED, opCode); + } catch (IOException ie) { + TelnetProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_CONNECT_ERROR, + OperationCode.UNEXPECTED_RESULT); + } + + } + }; + connectThread.start(); + } + + /* (non-Javadoc) + * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#disconnect() + */ + public void disconnect() throws IOException { + if (null != connectThread && + connectThread.isAlive()) { + connectThread.interrupt(); + } + if (null != loginThread && + loginThread.isAlive()) { + loginThread.interrupt(); + } + if (null != sendCommandThread && + sendCommandThread.isAlive()) { + sendCommandThread.interrupt(); + } + connectionWrapper.disconnect(); + notifyListeners( + EventCode.EVT_PROVIDER_DISCONNECT_FINISHED, OperationCode.SUCCESS); + } + + /** + * This method will be executed in a separated thread and will produce + * an event to be sent to the registered listeners. + */ + /* (non-Javadoc) + * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#login(java.lang.String, java.lang.String) + */ + public void login(String user, String password) throws IOException { + final String userAux = user; + final String passwordAux = password; + final TelnetWrapper connectionWrapperAux = connectionWrapper; + + /*TODO: Enhance this. It would be great if all these executed-in-other threads + were located under a synchronized block */ + loginThread = new Thread() { + public void run() { + try { + OperationCode opCode; + opCode = connectionWrapperAux.login(userAux, passwordAux); + TelnetProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_LOGIN_FINISHED, opCode); + } catch (IOException ie) { + TelnetProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_LOGIN_ERROR, + OperationCode.UNEXPECTED_RESULT); + } + } + }; + loginThread.start(); + } + + /* (non-Javadoc) + * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#getLastResponde() + */ + public StringBuffer getLastResponde() { + return connectionWrapper.getLastResponde(); + } + + /** + * This method will be executed in a separated thread and will produce + * an event to be sent to the registered listeners. + */ + /* (non-Javadoc) + * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#sendCommand(java.lang.String) + */ + public void sendCommand(CommandCode cmd, String cmdStr) throws IOException { + + if (CommandCode.FETCH_FILE != cmd) { + return; + } + + final String commandAux = CMD_FETCH_PREFIX + cmdStr + "\n"; //$NON-NLS-1$ + + final TelnetWrapper connectionWrapperAux = connectionWrapper; + + /*TODO: Enhance this. It would be great if all these executed-in-other threads + were located under a synchronized block */ + sendCommandThread = new Thread() { + public void run() { + try { + connectionWrapperAux.setResponseLength(2048); + if (null != connectionWrapperAux.sendCommand(commandAux)) { + StringBuffer result = connectionWrapperAux.getLastResponde(); + TelnetProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_SENDCOMMAND_FINISHED, result); + } else { + logger.info("##### NULL ######"); + } + } catch (IOException ie) { + TelnetProvider.this.notifyListeners( + EventCode.EVT_PROVIDER_SENDCOMMAND_ERROR, null); + } + + } + }; + sendCommandThread.start(); + } + + /* (non-Javadoc) + * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#sendData(java.lang.String) + */ + public void sendData(String out) { + connectionWrapper.sendData(out); + } + + /* (non-Javadoc) + * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#setResponseLength(int) + */ + public void setResponseLength(int maxLength) { + connectionWrapper.setResponseLength(maxLength); + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/telnet/TelnetWrapper.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/telnet/TelnetWrapper.java new file mode 100644 index 0000000000..62a84efd91 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/network/telnet/TelnetWrapper.java @@ -0,0 +1,235 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * Otavio Ferranti - Eldorado Research Institute - Bug 255255 [tml][proctools] Add extension points + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.network.telnet; + +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.util.HashMap; + +import org.apache.commons.net.telnet.EchoOptionHandler; +import org.apache.commons.net.telnet.InvalidTelnetOptionException; +import org.apache.commons.net.telnet.SuppressGAOptionHandler; +import org.apache.commons.net.telnet.TelnetClient; +import org.apache.commons.net.telnet.TerminalTypeOptionHandler; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.OperationCode; + +/** + * @author Ot�vio Ferranti + */ +public class TelnetWrapper { + + final public String PROMPT = "[###]:"; //$NON-NLS-1$ + final private String[] LOGIN_TOKENS = {"login:", //$NON-NLS-1$ + "Login:"}; //$NON-NLS-1$ + final private String[] PASSWORD_TOKENS = {"password:", //$NON-NLS-1$ + "Password:"}; //$NON-NLS-1$ + final private String[] LOGIN_FAILED_TOKENS = {"Login incorrect", //$NON-NLS-1$ + "Access denied"}; //$NON-NLS-1$ + final private String CHANGE_PROMPT = "export PS1='[\\043\\043\\043]:'\n"; //$NON-NLS-1$ + + // private ILogger logger = null; + private TelnetClient client = null; + private InputStream inStream = null; + private PrintStream outStream = null; + private StringBuffer lastResponse = null; + private int maxResponseDataLength = 1024; + + private int MAX_LENGTH_PASSWORD_TOKENS = 32; + private int MAX_LENGTH_LOGIN_FAILED = 32; + private int MAX_LENGTH_LOGIN_INITSCREEN = 2048; + private int MAX_LENGTH_CHANGE_PROMPT = 128; + + /** + * Constructor + */ + public TelnetWrapper() { + if (null == this.client) { + this.client = new TelnetClient(); + try { + this.client.addOptionHandler(new TerminalTypeOptionHandler( + "VT100", false, false, true, false)); //$NON-NLS-1$ + this.client.addOptionHandler(new SuppressGAOptionHandler( + true, true, true, true)); + this.client.addOptionHandler(new EchoOptionHandler( + false, false, false, false)); + } catch (InvalidTelnetOptionException itoe) { } + // logger = LinuxToolsPlugin.getLogger(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IConnectionWrapper#connect(java.lang.String, int) + */ + public OperationCode connect(String host, int port) throws IOException { + OperationCode retVal; + + this.client.connect(host, port); + + inStream = client.getInputStream(); + outStream = new PrintStream (client.getOutputStream()); + + // sendData(user+"\n"); + if(null == readUntilTokens(LOGIN_TOKENS)) { + retVal = OperationCode.SUCCESS; + } else { + retVal = OperationCode.LOGIN_REQUIRED; + } + return retVal; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IConnectionWrapper#disconnect() + */ + public void disconnect() throws IOException { + if (null != client) { + client.disconnect(); + // System.out.println("Connection closed ..."); + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IConnectionWrapper#login(java.lang.String, java.lang.String) + */ + public OperationCode login(String user, String password) throws IOException { + OperationCode retVal = OperationCode.UNEXPECTED_RESULT; + + sendData(user+"\n"); //$NON-NLS-1$ + setResponseLength(MAX_LENGTH_PASSWORD_TOKENS); + if (null != readUntilTokens(PASSWORD_TOKENS)) { + sendData(password+"\n"); //$NON-NLS-1$ + + setResponseLength(MAX_LENGTH_LOGIN_FAILED); + if (null != readUntilTokens(LOGIN_FAILED_TOKENS)) { + if(null != readUntilTokens(LOGIN_TOKENS)) { + retVal = OperationCode.LOGIN_FAILED; + } else { + retVal = OperationCode.UNEXPECTED_RESULT; + } + return retVal; + } else { + setResponseLength(MAX_LENGTH_LOGIN_INITSCREEN); + int toBeSkipped = inStream.available(); + inStream.skip(toBeSkipped); + } + } + try { + Thread.sleep (2000); + } catch (InterruptedException ite) { + + } + setResponseLength(MAX_LENGTH_CHANGE_PROMPT); + sendData(CHANGE_PROMPT); + if (null != readUntilTokens(PROMPT)) { + retVal = OperationCode.SUCCESS; + } + return retVal; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IConnectionWrapper#getLastResponde() + */ + public StringBuffer getLastResponde() { + return lastResponse; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IConnectionWrapper#sendCommand(java.lang.String) + */ + public String sendCommand(String command) throws IOException { + sendData (command); + return readUntilTokens (PROMPT); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IConnectionWrapper#sendData(java.lang.String) + */ + public void sendData(String out) { + if (null != outStream) { + outStream.print(out); + outStream.flush(); + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IConnectionWrapper#setResponseLength(int) + */ + public void setResponseLength(int maxLength) { + maxResponseDataLength = maxLength; + } + + /** + * @param token + * @return + * @throws IOException + */ + private String readUntilTokens(String token)throws IOException { + return readUntilTokens(new String[] {token}); + } + + /** + * @param tokenArray + * @return + * @throws IOException + */ + private String readUntilTokens(final String []tokenArray) throws IOException { + String matchedString = null; + boolean tokenFound = false; + StringBuffer readData = new StringBuffer(); + + HashMap hashMap = new HashMap(); + + for (int i = 0; i < tokenArray.length; i++) { + hashMap.put(tokenArray[i], new Integer(0)); + } + + for (int i = 0; i < this.maxResponseDataLength; i++) { + + int aux = inStream.read(); + + char ch = 0; + if (aux == 0 || aux == 1) { + continue; + } else { + ch = (char) aux; + } + readData.append(ch); + + // if (ch != 1 && ch != 0) + // logger.info(ch); + + for (int j = 0; j < tokenArray.length; j++) { + String token = tokenArray[j]; + Integer rank = hashMap.get(token); + if (ch == token.charAt(rank)) { + rank ++; + if (rank >= token.length()) { + // MATCHED + readData.setLength(readData.length() - token.length()); + matchedString = token; + tokenFound = true; + } + } else { + rank = 0; + } + hashMap.put(token, rank); + } + if (tokenFound) { + break; + } + } + this.lastResponse = readData; + return matchedString; + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadProcessor.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadProcessor.java new file mode 100644 index 0000000000..ce14720817 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadProcessor.java @@ -0,0 +1,279 @@ +/******************************************************************************** + * Copyright (c) 2009 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.cpuload; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.regex.MatchResult; + +import org.eclipse.linuxtools.sequoyah.device.LinuxToolsPlugin; +import org.eclipse.linuxtools.sequoyah.device.network.IConnectionProvider; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.CommandCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode; +import org.eclipse.linuxtools.sequoyah.device.tools.AbstractNotifier; +import org.eclipse.linuxtools.sequoyah.device.tools.IListener; +import org.eclipse.linuxtools.sequoyah.device.tools.INotifier; +import org.eclipse.sequoyah.device.common.utilities.logger.ILogger; + +/** + * @author Otavio Ferranti + */ +public class CpuLoadProcessor extends AbstractNotifier implements IListener { + + final private String CMD_FETCH_STAT = "/proc/stat"; //$NON-NLS-1$ + final private String PARSE_PATTERN_1 = "cpu(\\d*)(.*)"; //$NON-NLS-1$; + final private String PARSE_PATTERN_2 = "\\s+(\\d+)"; //$NON-NLS-1$; + final private String DATA_FORMAT = "%1$02.1f %%"; //$NON-NLS-1$; + + final private String MSG_EXECUTING_COMMAND = + Messages.CpuLoadProcessor_Msg_Executing_the_command; + + final private String MSG_GOT_RESULT = + Messages.CpuLoadProcessor_Msg_Got_The_Result; + + final private int MAX_COLUMNS = 100; + + private int[][] previousData = null; + private long[] previousTotal = null; + private IConnectionProvider connectionProvider = null; + + private ILogger logger = null; + + /** + * The constructor; + * @param connectionProvider + */ + public CpuLoadProcessor(IConnectionProvider connectionProvider) { + setConnectionProvider(connectionProvider); + logger = LinuxToolsPlugin.getLogger(); + } + + /** + * Requests data. + * @throws IOException + */ + public void gatherData() throws IOException { + this.connectionProvider.sendCommand(CommandCode.FETCH_FILE, this.CMD_FETCH_STAT); + logger.debug(MSG_EXECUTING_COMMAND + "\n" + this.CMD_FETCH_STAT); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IListener#notify(org.eclipse.linuxtools.sequoyah.device.network.INotifier, org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode, java.lang.Object) + */ + public void notify(INotifier notifier, + EventCode event, + Object result) { + if (notifier == this.connectionProvider && + event == EventCode.EVT_PROVIDER_SENDCOMMAND_FINISHED) { + Object[][] parsedResult = parseStat((StringBuffer) result); + this.notifyListeners(EventCode.EVT_PROCESSOR_GATHERDATA_FINISHED, + parsedResult); + } + } + + /** + * Set the connection provider. + * @param connectionProvider + */ + public void setConnectionProvider (IConnectionProvider connectionProvider) { + if (null != this.connectionProvider) { + this.connectionProvider.removeListener(this); + } + this.connectionProvider = connectionProvider; + if (null != this.connectionProvider) { + this.connectionProvider.addListener(this); + } + } + + /** + * @param currentDataStr + * @return + */ + private Object[][] calculateTimes(String[][] currentDataStr) { + String[][] resultStr = null; + + if (null == currentDataStr) { + currentDataStr = new String[][] {{"0"}}; + } + if (null == previousData) { + previousData = new int[][] {{0}}; + previousTotal = new long[] {1}; + } + if (previousData.length != currentDataStr.length || + previousData[0].length != currentDataStr[0].length) { + previousData = String2int(currentDataStr); + previousTotal = new long[previousData.length]; + + for (int j = 0; j < previousData.length; j++) { + long total = 0; + for (int i = 0; i < previousData[0].length; i++) { + total += previousData[j][i]; + } + previousTotal[j] = total; + } + } + final int[][] currentDataInt = String2int(currentDataStr); + float[][] resultFloat = new float[currentDataStr.length][currentDataStr[0].length]; + + for (int j = 0; j < currentDataInt.length; j++) { + long total = 0; + for (int i = 0; i < currentDataInt[0].length; i++) { + total += currentDataInt[j][i]; + } + float deltaTotal = total - previousTotal[j]; + previousTotal[j] = total; + for (int i = 0; i < currentDataInt[0].length; i++) { + float deltaData = currentDataInt[j][i] - previousData[j][i]; + if (0 == deltaTotal) { + resultFloat[j][i] = 0; + } else { + resultFloat[j][i] = 100* deltaData / deltaTotal; + } + } + } + previousData = currentDataInt; + resultStr = float2StringFormated(resultFloat, DATA_FORMAT); + return resultStr; + } + + /** + * @param target + * @param Source + */ + private void copyData(Object[][] target, Object[][] Source) { + for (int j = 0; j < target.length; j++) { + for (int i = 1; i < target[0].length; i++) { + target[j][i] = Source[j][i-1]; + } + } + } + + /** + * @param input + * @return + */ + private String[][] float2StringFormated (float[][] input, String format) { + String[][] output = null; + if (null != input) { + output = new String[input.length][input[0].length]; + for (int j = 0; j < output.length; j++) { + for (int i = 0; i < output[0].length; i++) { + output[j][i] = String.format(format, new Float(input[j][i])); + } + } + } + return output; + } + + /** + * @param data + * @return + */ + private Object[][] parseStat(StringBuffer data) { + logger.debug(MSG_GOT_RESULT + "\n" + data.toString()); + + int requiredColumns = 0; + + Scanner s1 = new Scanner(data.toString()); + ArrayList list = new ArrayList(); + + while (s1.hasNextLine()) { + String[] entry = new String[MAX_COLUMNS];; + + Scanner s2 = new Scanner(s1.nextLine()); + s2.findInLine(PARSE_PATTERN_1); + + try { + + MatchResult result = s2.match(); + entry[0] = result.group(1).trim(); + + String aux = result.group(2); + + Scanner s3 = new Scanner(aux); + entry[1] = s3.findInLine(PARSE_PATTERN_2).trim(); + + s3.match(); + int i = 2; + + while (s3.hasNext() && i < MAX_COLUMNS) { + entry[i] = s3.next().trim(); + + if (i > requiredColumns) { + requiredColumns = i; + } + i++; + } + s3.close(); + if (null != entry) { + list.add(entry); + } + } catch (IllegalStateException ise) { + } + s2.close(); + } + s1.close(); + + String[][] dataAux = new String[list.size()][requiredColumns + 1]; + for (int j = 0; j < dataAux.length; j++) { + for (int i = 0; i < dataAux[0].length; i++) { + dataAux[j][i] = list.get(j)[i]; + } + } + String[][] dataStrippedAux = stripFirstColumn(dataAux); + Object[][] result = calculateTimes(dataStrippedAux); + copyData(dataAux, result); + return dataAux; + } + + /** + * @param input + * @return + */ + private int[][] String2int (String[][] input) { + int[][] output = null; + if (null != input) { + output = new int[input.length][input[0].length]; + for (int j = 0; j < output.length; j++) { + for (int i = 0; i < output[0].length; i++) { + try { + output[j][i] = new Integer(input[j][i]).intValue(); + } + catch (NumberFormatException nfe) { + output[j][i] = -1; + } + } + } + } + return output; + } + + /** + * @param input + * @return + */ + private String[][] stripFirstColumn (String[][] input) { + String output[][] = null; + if (null != input) { + output = new String[input.length][input[0].length-1]; + for (int j = 0; j < output.length; j++) { + for (int i = 0; i < output[0].length; i++) { + output[j][i] = input[j][i+1]; + } + } + } + return output; + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadTool.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadTool.java new file mode 100644 index 0000000000..54375bf9d0 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadTool.java @@ -0,0 +1,208 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * Otavio Ferranti - Eldorado Research Institute - Bug 255255 [tml][proctools] Add extension points + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.cpuload; + +import java.io.IOException; +import java.util.List; + +import org.eclipse.linuxtools.sequoyah.device.network.IConnectionProvider; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.OperationCode; +import org.eclipse.linuxtools.sequoyah.device.tools.AbstractNotifier; +import org.eclipse.linuxtools.sequoyah.device.tools.IListener; +import org.eclipse.linuxtools.sequoyah.device.tools.INotifier; +import org.eclipse.linuxtools.sequoyah.device.tools.ITool; +import org.eclipse.linuxtools.sequoyah.device.utilities.Extensions; +import org.eclipse.linuxtools.sequoyah.device.utilities.ProtocolDescriptor; + +/** + * @author Otavio Ferranti + */ +public class CpuLoadTool extends AbstractNotifier implements IListener, ITool { + + public enum ToolStateEnum {RUNNING, STOPPED, STOP_SCHEDULED}; + + private IConnectionProvider connectionProvider = null; + private CpuLoadProcessor processor = null; + private int delay = 1000; + + private ToolStateEnum toolState = ToolStateEnum.STOPPED; + + private String[] requiredCapabilities = {"GET_FILE"}; //$NON-NLS-1$ + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.ITool#createConnection(java.lang.String, int, java.lang.String) + */ + public void connect (String host, + int port, + ProtocolDescriptor protocol) { + + Class connectionProviderClass = + protocol.getConnectionProviderClass(); + + try { + Object aux = connectionProviderClass.newInstance(); + connectionProvider = (IConnectionProvider) aux; + } catch (InstantiationException ie) { + } catch (IllegalAccessException iae) { + } catch (ClassCastException cce) { + } + + connectionProvider.addListener(this); + try { + connectionProvider.connect(host, port); + } catch (IOException ie) { } + processor = new CpuLoadProcessor(connectionProvider); + + processor.addListener(this); + toolState = ToolStateEnum.STOPPED; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.ITool#closeConnection() + */ + public void disconnect() { + if (null != connectionProvider) { + try { + connectionProvider.disconnect(); + } catch (IOException ie) { + } + connectionProvider = null; + toolState = ToolStateEnum.STOPPED; + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.ITool#login(java.lang.String, java.lang.String) + */ + public void login (String user, String password) { + try { + connectionProvider.login(user, password); + } catch (IOException ie) { + //TODO: Nothing ? + } + } + + public List getProtocolsDescriptors() { + List pdList = Extensions.findProcotols(requiredCapabilities); + return pdList; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.IListener#notify(org.eclipse.linuxtools.sequoyah.device.tools.INotifier, org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode, java.lang.Object) + */ + public void notify(INotifier notifier, EventCode event, Object result) { + try { + if (notifier == connectionProvider) { + switch (event) { + case EVT_PROVIDER_CONNECT_FINISHED: + if (OperationCode.SUCCESS == result) { + start(); + } + this.notifyListeners( + EventCode.EVT_TOOL_CONNECT_FINISHED, + result); + break; + case EVT_PROVIDER_CONNECT_ERROR: + + break; + case EVT_PROVIDER_LOGIN_FINISHED: + if (OperationCode.SUCCESS == result) { + start(); + } + this.notifyListeners( + EventCode.EVT_TOOL_LOGIN_FINISHED, + result); + break; + case EVT_PROVIDER_SENDCOMMAND_FINISHED: + break; + case EVT_PROVIDER_SENDCOMMAND_ERROR: + break; + case EVT_PROVIDER_SENDDATA_FINISHED: + break; + case EVT_PROVIDER_SENDDATA_ERROR: + break; + case EVT_PROVIDER_DISCONNECT_FINISHED: + this.notifyListeners( + EventCode.EVT_TOOL_DISCONNECT_FINISHED, + result); + break; + } + } + if (notifier == processor) { + switch (event) { + case EVT_PROCESSOR_GATHERDATA_FINISHED: + if (ToolStateEnum.RUNNING == toolState) { + try { + notifyListeners(EventCode.EVT_TOOL_REFRESH_VIEW, + result); + Thread.sleep(delay); + processor.gatherData(); + } catch (InterruptedException ie) { + } + } else if (ToolStateEnum.STOP_SCHEDULED == toolState) { + toolState = ToolStateEnum.STOPPED; + } + break; + case EVT_PROCESSOR_GATHERDATA_ERROR: + break; + } + } + } catch (IOException ie) { + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.ITool#getRefreshDelay() + */ + public int getRefreshDelay() { + return this.delay; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.ITool#setRefreshDelay(int) + */ + public void setRefreshDelay(int delay) { + this.delay = delay; + } + + /** + * + */ + public void start() { + try { + if (null != processor) { + if (ToolStateEnum.STOPPED == toolState) { + toolState = ToolStateEnum.RUNNING; + processor.gatherData(); + } else if (ToolStateEnum.STOP_SCHEDULED == toolState) { + toolState = ToolStateEnum.RUNNING; + } + } + } catch (IOException ie) { + //TODO: Nothing ? + } + } + + /** + * + */ + public void stop () { + toolState = ToolStateEnum.STOP_SCHEDULED; + } + + public void refresh() { + // TODO Auto-generated method stub + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadView.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadView.java new file mode 100644 index 0000000000..d6d4b71b1b --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadView.java @@ -0,0 +1,332 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.cpuload; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.linuxtools.sequoyah.device.LinuxToolsPlugin; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.OperationCode; +import org.eclipse.linuxtools.sequoyah.device.tools.IListener; +import org.eclipse.linuxtools.sequoyah.device.tools.INotifier; +import org.eclipse.linuxtools.sequoyah.device.tools.ITool; +import org.eclipse.linuxtools.sequoyah.device.ui.DialogLogin; +import org.eclipse.linuxtools.sequoyah.device.ui.IToolViewPart; +import org.eclipse.linuxtools.sequoyah.device.ui.ViewActionConnect; +import org.eclipse.linuxtools.sequoyah.device.ui.ViewActionDisconnect; +import org.eclipse.linuxtools.sequoyah.device.ui.ViewActionPause; +import org.eclipse.linuxtools.sequoyah.device.ui.ViewActionRun; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.ViewPart; + +/** + * @author Otavio Ferranti + */ +public class CpuLoadView extends ViewPart implements IToolViewPart, IListener { + + private class CpuSorter extends ViewerSorter { + + public int compare(Viewer viewer, Object e1, Object e2) { + int result = 0; + try { + int a = new Integer(((String[]) e1)[0]).intValue(); + int b = new Integer(((String[]) e2)[0]).intValue(); + if (a > b) { + result = 1; + } else if (a < b) { + result = -1; + }; + } + catch (NumberFormatException nfe) { + //TODO: Nothing ? + } + return result; + } + } + final private String COL_LABEL_CPU = Messages.CpuLoadView_Col_Label_Cpu; + final private String COL_LABEL_USER_MODE = Messages.CpuLoadView_Col_Label_User_Mode; + final private String COL_LABEL_NICE = Messages.CpuLoadView_Col_Label_Nice; + final private String COL_LABEL_SYSTEM = Messages.CpuLoadView_Col_Label_System; + final private String COL_LABEL_IDLE = Messages.CpuLoadView_Col_Label_Idle; + final private String COL_LABEL_WAIT = Messages.CpuLoadView_Col_Label_Wait; + final private String COL_LABEL_HIRQ = Messages.CpuLoadView_Col_label_HIrq; + + final private String COL_LABEL_SIRQ = Messages.CpuLoadView_Col_Label_SIrq; + + private ITool tool = null; + private TableViewer viewer; + + private Action runAction; + private Action pauseAction; + private Action optionsAction; + private Action disconnectAction; + private Action connectAction; + + private boolean receivedData = false; + + private IPartListener partActivationListener = new IPartListener() { + public void partActivated(IWorkbenchPart part) { + } + + public void partBroughtToTop(IWorkbenchPart part) { + } + + public void partClosed(IWorkbenchPart part) { + if (CpuLoadView.this.getSite().getPart() == part) { + ITool tool = CpuLoadView.this.getTool(); + if (null != tool) { + tool.disconnect(); + } + } + } + + public void partDeactivated(IWorkbenchPart part) { + } + + public void partOpened(IWorkbenchPart part) { + } + }; + + /** + * The constructor. + */ + public CpuLoadView() { + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + public void createPartControl(Composite parent) { + + viewer = new TableViewer(parent, SWT.FULL_SELECTION | + SWT.H_SCROLL | SWT.V_SCROLL); + viewer.setContentProvider(new CpuLoadViewContentProvider()); + viewer.setLabelProvider(new CpuLoadViewLabelProvider()); + viewer.setSorter(new CpuSorter()); + + Table table = viewer.getTable(); + table.setHeaderVisible(true); + + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_CPU); + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_USER_MODE); + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_NICE); + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_SYSTEM); + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_IDLE); + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_WAIT); + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_HIRQ); + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_SIRQ); + + refresh(); + resize(); + + makeActions(); + // hookDoubleClickAction(); + addToToolBar(); + + getViewSite() + .getWorkbenchWindow() + .getPartService() + .addPartListener(partActivationListener); + + setConnectEnabled(true); + setRunPauseEnabled(false, false); + } + + private void addToToolBar() { + IActionBars actionBars = getViewSite().getActionBars(); + IToolBarManager toolBarMmanager = actionBars.getToolBarManager(); + toolBarMmanager.add(runAction); + toolBarMmanager.add(pauseAction); + toolBarMmanager.add(optionsAction); + toolBarMmanager.add(disconnectAction); + toolBarMmanager.add(connectAction); + } + + private void makeActions() { + + runAction = new Action() { + public void run() { + IViewActionDelegate delegate = new ViewActionRun(); + delegate.init(CpuLoadView.this); + delegate.run(this); + setRunPauseEnabled(false, true); + } + }; + runAction.setToolTipText(Messages.CpuLoadView_Action_Run); + runAction.setImageDescriptor( + LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_RUN)); + + pauseAction = new Action() { + public void run() { + IViewActionDelegate delegate = new ViewActionPause(); + delegate.init(CpuLoadView.this); + delegate.run(this); + setRunPauseEnabled(true, false); + } + }; + pauseAction.setToolTipText(Messages.CpuLoadView_Action_Pause); + pauseAction.setImageDescriptor( + LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_PAUSE)); + + optionsAction = new Action() { + public void run() { + IViewActionDelegate delegate = new ViewActionOptions(); + delegate.init(CpuLoadView.this); + delegate.run(this); + } + }; + optionsAction.setToolTipText(Messages.CpuLoadView_Action_Options); + optionsAction.setImageDescriptor( + LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_OPTIONS)); + + disconnectAction = new Action() { + public void run() { + IViewActionDelegate delegate = new ViewActionDisconnect(); + delegate.init(CpuLoadView.this); + delegate.run(this); + } + }; + disconnectAction.setToolTipText(Messages.CpuLoadView_Action_Disconnect); + disconnectAction.setImageDescriptor( + LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_DISCONNECT)); + + connectAction = new Action() { + public void run() { + IViewActionDelegate delegate = new ViewActionConnect(); + delegate.init(CpuLoadView.this); + delegate.run(this); + } + }; + connectAction.setToolTipText(Messages.CpuLoadView_Action_Connect); + connectAction.setImageDescriptor( + LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_CONNECT)); + } + + private void setConnectEnabled(boolean bool) { + connectAction.setEnabled(bool); + disconnectAction.setEnabled(!bool); + } + + private void setRunPauseEnabled(boolean runBool, boolean pauseBool) { + runAction.setEnabled(runBool); + pauseAction.setEnabled(pauseBool); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.ui.IToolView#getTool() + */ + public ITool getTool() { + if(null == tool) { + tool = new CpuLoadTool(); + tool.addListener(this); + } + return tool; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IListener#notify(org.eclipse.linuxtools.sequoyah.device.network.INotifier, org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode, java.lang.Object) + */ + public void notify(INotifier notifier, EventCode event, Object result) { + if (notifier == this.tool) { + final Object finalResult = result; + final EventCode finalEvent = event; + final ViewPart finalView = this; + final ITool finalTool = this.tool; + + this.getViewSite().getShell().getDisplay().asyncExec(new Runnable() { + public void run() { + switch(finalEvent) { + case EVT_TOOL_REFRESH_VIEW: + viewer.setInput(finalResult); + refresh(); + if (!receivedData) { + resize(); + receivedData = true; + } + break; + case EVT_TOOL_CONNECT_FINISHED: + case EVT_TOOL_LOGIN_FINISHED: + switch ((OperationCode)finalResult) { + case SUCCESS: + setConnectEnabled(false); + setRunPauseEnabled(false, true); + break; + case LOGIN_REQUIRED: { + final DialogLogin dialog = new DialogLogin( + finalView.getViewSite().getShell(), + finalTool, false); + dialog.open(); + } + break; + case LOGIN_FAILED: { + final DialogLogin dialog = new DialogLogin( + finalView.getViewSite().getShell(), + finalTool, true); + dialog.open(); + } + break; + } + break; + case EVT_TOOL_DISCONNECT_FINISHED: + setConnectEnabled(true); + setRunPauseEnabled(false, false); + break; + } + } + }); + } + } + + /** + * + */ + public void refresh() { + viewer.refresh(); + } + + /** + * + */ + public void resize() { + Table table = viewer.getTable(); + for (int i = 0, n = table.getColumnCount(); i < n; i++) { + table.getColumn(i).pack(); + } + } + + /** + * @param data + */ + public void setData (Object data) { + viewer.setInput(data); + } + + /** + * Passing the focus request to the viewer's control. + */ + public void setFocus() { + viewer.getControl().setFocus(); + } +} \ No newline at end of file diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadViewContentProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadViewContentProvider.java new file mode 100644 index 0000000000..6aed1e4c86 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadViewContentProvider.java @@ -0,0 +1,61 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.cpuload; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/* + * The content provider class is responsible for + * providing objects to the view. It can wrap + * existing objects in adapters or simply return + * objects as-is. These objects may be sensitive + * to the current input of the view, or ignore + * it and always show the same content + * (like Task List, for example). + */ + +/** + * @author Otavio Ferranti + */ +public class CpuLoadViewContentProvider implements IStructuredContentProvider { + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object parent) { + if (parent instanceof String[][]) { + return (String[][]) parent; + } else { + String[][] aux = new String[1][]; + aux[0] = new String[] {"", "", //$NON-NLS-1$ //$NON-NLS-2$ + "", "", //$NON-NLS-1$ //$NON-NLS-2$ + "", "", //$NON-NLS-1$ //$NON-NLS-2$ + "", ""}; //$NON-NLS-1$ //$NON-NLS-2$ + return aux; + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadViewLabelProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadViewLabelProvider.java new file mode 100644 index 0000000000..3acfca3214 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/CpuLoadViewLabelProvider.java @@ -0,0 +1,54 @@ +/******************************************************************************** + * Copyright (c) 2009 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.cpuload; + +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +/** + * @author Otavio Ferranti + */ +public class CpuLoadViewLabelProvider extends LabelProvider implements + ITableLabelProvider { + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) + */ + public Image getColumnImage(Object obj, int index) { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) + */ + public String getColumnText(Object obj, int index) { + if (obj instanceof String[]) { + return getText(((Object[]) obj)[index]); + } else { + return new String(""); //$NON-NLS-1$ + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) + */ + public Image getImage(Object obj) { + return PlatformUI.getWorkbench(). + getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); + } +} + diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/DialogOptions.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/DialogOptions.java new file mode 100644 index 0000000000..f8b06c5cbf --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/DialogOptions.java @@ -0,0 +1,108 @@ +/******************************************************************************** + * Copyright (c) 2009 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.cpuload; + +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.linuxtools.sequoyah.device.tools.ITool; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Spinner; + +/** + * @author Otavio Ferranti + */ +public class DialogOptions extends TitleAreaDialog { + + final private String WINDOW_TITLE = Messages.OptionsDialog_Window_Title; + final private String WINDOW_MESSAGE = Messages.OptionsDialog_Window_Message; + final private String LABEL_REFRESH = Messages.OptionsDialog_Label_Refresh_Rate; + final private String LABEL_TIMEUNIT = "ms"; //$NON-NLS-1$ + + private Spinner spinner; + + private ITool tool = null; + + /** + * The constructor. + * @param parent + */ + public DialogOptions(Shell parent, ITool tool) { + super(parent); + this.tool = tool; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite) + */ + protected Control createDialogArea(Composite parent) { + setTitle(WINDOW_TITLE); + setMessage(WINDOW_MESSAGE); + + Composite dialogArea = new Composite(parent, SWT.NONE); + GridLayout gridLayout = new GridLayout(3, false); + + gridLayout.marginLeft = 7; + gridLayout.marginRight = 7; + + dialogArea.setLayout(gridLayout); + dialogArea.setLayoutData(new GridData(GridData.FILL_BOTH)); + dialogArea.setFont(parent.getFont()); + + Label refreshLabel = new Label(dialogArea, SWT.NULL); + refreshLabel.setText(LABEL_REFRESH); + + spinner = new Spinner(dialogArea, SWT.BORDER); + + Label timeUnit = new Label(dialogArea, SWT.NULL); + timeUnit.setText(LABEL_TIMEUNIT); + + spinner.setMinimum(0); + spinner.setMaximum(50000); + spinner.setSelection(tool.getRefreshDelay()); + spinner.setIncrement(100); + spinner.setPageIncrement(500); + spinner.pack(); + + return dialogArea; + } + + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.TitleAreaDialog#getInitialSize() + */ + protected Point getInitialSize() { + return super.getInitialSize(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#okPressed() + */ + protected void okPressed() { + tool.setRefreshDelay(spinner.getSelection()); + super.okPressed(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.Dialog#cancelPressed() + */ + protected void cancelPressed() { + super.cancelPressed(); + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/Messages.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/Messages.java new file mode 100644 index 0000000000..cb853297dc --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/Messages.java @@ -0,0 +1,49 @@ +/******************************************************************************** + * Copyright (c) 2009 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.cpuload; + +import org.eclipse.osgi.util.NLS; + +/** + * @author Otavio Ferranti + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = + "org.eclipse.linuxtools.sequoyah.device.tools.cpuload.messages"; //$NON-NLS-1$ + public static String CpuLoadProcessor_Msg_Executing_the_command; + public static String CpuLoadProcessor_Msg_Got_The_Result; + public static String CpuLoadView_Action_Connect; + public static String CpuLoadView_Action_Disconnect; + public static String CpuLoadView_Action_Options; + public static String CpuLoadView_Action_Pause; + public static String CpuLoadView_Action_Run; + public static String CpuLoadView_Col_Label_Cpu; + public static String CpuLoadView_Col_label_HIrq; + public static String CpuLoadView_Col_Label_Idle; + public static String CpuLoadView_Col_Label_Nice; + public static String CpuLoadView_Col_Label_SIrq; + public static String CpuLoadView_Col_Label_System; + public static String CpuLoadView_Col_Label_User_Mode; + public static String CpuLoadView_Col_Label_Wait; + public static String OptionsDialog_Label_Refresh_Rate; + public static String OptionsDialog_Window_Message; + public static String OptionsDialog_Window_Title; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/ViewActionOptions.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/ViewActionOptions.java new file mode 100644 index 0000000000..5986507130 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/ViewActionOptions.java @@ -0,0 +1,59 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.cpuload; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.linuxtools.sequoyah.device.ui.IToolViewPart; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.PlatformUI; + +/** + * @author Otavio Ferranti + */ +public class ViewActionOptions implements IViewActionDelegate { + + private IViewPart targetPart; + + /** + * The constructor. + */ + public ViewActionOptions() { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) + */ + public void init(IViewPart view) { + this.targetPart = view; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + final DialogOptions dialog = new DialogOptions( + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), + ((IToolViewPart) this.targetPart).getTool()); + dialog.open(); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) + */ + public void selectionChanged(IAction action, ISelection selection) { + + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/messages.properties b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/messages.properties new file mode 100644 index 0000000000..da06c3d3c9 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/cpuload/messages.properties @@ -0,0 +1,38 @@ +################################################################################ +# Copyright (c) 2009 Motorola Inc. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Initial Contributors: +# Otavio Ferranti (Motorola) +# +# Contributors: +# {Name} (company) - description of contribution. +################################################################################ + +# NLS_MESSAGEFORMAT_VAR +# NLS_ENCODING=UTF-8 + +CpuLoadView_Col_Label_Cpu=Cpu +CpuLoadView_Col_Label_User_Mode=User +CpuLoadView_Col_Label_Nice=Nice +CpuLoadView_Col_Label_System=System +CpuLoadView_Col_Label_Idle=Idle +CpuLoadView_Col_Label_Wait=Wait +CpuLoadView_Col_label_HIrq=HW Irq +CpuLoadView_Col_Label_SIrq=SW Irq + +CpuLoadView_Action_Run=Run +CpuLoadView_Action_Pause=Pause +CpuLoadView_Action_Options=Options +CpuLoadView_Action_Disconnect=Disconnect +CpuLoadView_Action_Connect=Connect + +CpuLoadProcessor_Msg_Executing_the_command=Executing the command: +CpuLoadProcessor_Msg_Got_The_Result=Got the result: + +OptionsDialog_Window_Title=Options +OptionsDialog_Window_Message=Some options may take effect only after reconnection +OptionsDialog_Label_Refresh_Rate=Refresh delay: diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapProcessor.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapProcessor.java new file mode 100644 index 0000000000..083cde3c79 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapProcessor.java @@ -0,0 +1,138 @@ +/******************************************************************************** + * Copyright (c) 2009 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.memorymap; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.regex.MatchResult; + +import org.eclipse.linuxtools.sequoyah.device.LinuxToolsPlugin; +import org.eclipse.linuxtools.sequoyah.device.network.IConnectionProvider; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.CommandCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode; +import org.eclipse.linuxtools.sequoyah.device.tools.AbstractNotifier; +import org.eclipse.linuxtools.sequoyah.device.tools.IListener; +import org.eclipse.linuxtools.sequoyah.device.tools.INotifier; +import org.eclipse.sequoyah.device.common.utilities.logger.ILogger; + +/** + * @author Otavio Ferranti + */ +public class MemoryMapProcessor extends AbstractNotifier implements IListener { + + final private String CMD_FETCH_IOMEM = "/proc/iomem"; //$NON-NLS-1$ + final private String PARSE_PATTERN = "\\s*(\\w{8})-(\\w{8})\\s*:\\s*(.*)"; //$NON-NLS-1$ + + final private String MSG_EXECUTING_COMMAND = + Messages.MemoryMapProcessor_Msg_Executing_The_Command; + + final private String MSG_GOT_RESULT = + Messages.MemoryMapProcessor_Msg_Got_The_Result; + + final private int MAX_COLUMNS = 4; + private IConnectionProvider connectionProvider = null; + + private ILogger logger = null; + + /** + * The constructor; + * @param connectionProvider + */ + public MemoryMapProcessor(IConnectionProvider connectionProvider) { + setConnectionProvider(connectionProvider); + logger = LinuxToolsPlugin.getLogger(); + } + + /** + * @throws IOException + */ + public void gatherData() throws IOException { + connectionProvider.setResponseLength(8192); + connectionProvider.sendCommand(CommandCode.FETCH_FILE, this.CMD_FETCH_IOMEM); + logger.debug(MSG_EXECUTING_COMMAND + "\n" + this.CMD_FETCH_IOMEM); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IListener#notify(org.eclipse.linuxtools.sequoyah.device.network.INotifier, org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode, java.lang.Object) + */ + public void notify(INotifier notifier, + EventCode event, + Object result) { + if (notifier == this.connectionProvider && + event == EventCode.EVT_PROVIDER_SENDCOMMAND_FINISHED) { + this.connectionProvider.setResponseLength(1024); + Object[][] parsedResult = parseIomem((StringBuffer) result); + this.notifyListeners(EventCode.EVT_PROCESSOR_GATHERDATA_FINISHED, + parsedResult); + } + } + + /** + * @param connectionProvider + */ + public void setConnectionProvider (IConnectionProvider connectionProvider) { + if (null != this.connectionProvider) { + this.connectionProvider.removeListener(this); + } + this.connectionProvider = connectionProvider; + if (null != this.connectionProvider) { + this.connectionProvider.addListener(this); + } + } + + /** + * @param data + * @return + */ + private Object[][] parseIomem(StringBuffer data) { + logger.debug(MSG_GOT_RESULT + "\n" + data.toString()); + + Scanner s1 = new Scanner(data.toString()); + + ArrayList list = new ArrayList(); + + int j = 0; + + while (s1.hasNextLine()) { + Scanner s2 = new Scanner(s1.nextLine()); + s2.findInLine(PARSE_PATTERN); + + String[] entry = null; + try { + MatchResult result = s2.match(); + entry = new String[MAX_COLUMNS]; + for (int i = 1; i <= result.groupCount() && i <= MAX_COLUMNS - 1; i++) { + entry[i-1] = result.group(i); + } + entry[MAX_COLUMNS - 1] = new Integer(j).toString(); + j++; + } catch (IllegalStateException ise) { + //TODO: Nothing ? + } + + s2.close(); + if (null != entry) { + list.add(entry); + } + } + s1.close(); + + String[][] retVal = new String[list.size()][MAX_COLUMNS]; + for (int i = 0; i < retVal.length; i++) { + retVal[i] = list.get(i); + } + return retVal; + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapTool.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapTool.java new file mode 100644 index 0000000000..d2a1386321 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapTool.java @@ -0,0 +1,184 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * Otavio Ferranti - Eldorado Research Institute - Bug 255255 [tml][proctools] Add extension points + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.memorymap; + +import java.io.IOException; +import java.util.List; + +import org.eclipse.linuxtools.sequoyah.device.network.IConnectionProvider; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.OperationCode; +import org.eclipse.linuxtools.sequoyah.device.tools.AbstractNotifier; +import org.eclipse.linuxtools.sequoyah.device.tools.IListener; +import org.eclipse.linuxtools.sequoyah.device.tools.INotifier; +import org.eclipse.linuxtools.sequoyah.device.tools.ITool; +import org.eclipse.linuxtools.sequoyah.device.utilities.Extensions; +import org.eclipse.linuxtools.sequoyah.device.utilities.ProtocolDescriptor; + +/** + * @author Otavio Ferranti + */ +public class MemoryMapTool extends AbstractNotifier implements IListener, ITool { + + private IConnectionProvider connectionProvider = null; + private MemoryMapProcessor processor = null; + + private String[] requiredCapabilities = {"GET_FILE"}; //$NON-NLS-1$ + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.memorymap.iTool#createInstance(java.lang.String, int, java.lang.String) + */ + public void connect (String host, + int port, + ProtocolDescriptor protocol) { + + Class connectionProviderClass = + protocol.getConnectionProviderClass(); + + try { + Object aux = connectionProviderClass.newInstance(); + connectionProvider = (IConnectionProvider) aux; + } catch (InstantiationException ie) { + } catch (IllegalAccessException iae) { + } catch (ClassCastException cce) { + } + + connectionProvider.addListener(this); + try { + connectionProvider.connect(host, port); + } catch (IOException ie) { } + processor = new MemoryMapProcessor(connectionProvider); + + processor.addListener(this); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.ITool#closeConnection() + */ + public void disconnect() { + if (null != connectionProvider) { + try { + connectionProvider.disconnect(); + } catch (IOException ie) { + } + connectionProvider = null; + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.memorymap.iTool#login(java.lang.String, java.lang.String) + */ + public void login (String user, String password) { + try { + connectionProvider.login(user, password); + } catch (IOException ie) { + //TODO: Nothing ? + } + } + + public List getProtocolsDescriptors() { + List pdList = Extensions.findProcotols(requiredCapabilities); + return pdList; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.IListener#notify(org.eclipse.linuxtools.sequoyah.device.tools.INotifier, org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode, java.lang.Object) + */ + public void notify(INotifier notifier, EventCode event, Object result) { + try { + if (notifier == connectionProvider) { + switch (event) { + case EVT_PROVIDER_CONNECT_FINISHED: + if (OperationCode.SUCCESS == result) { + processor.gatherData(); + } + this.notifyListeners( + EventCode.EVT_TOOL_CONNECT_FINISHED, + result); + break; + case EVT_PROVIDER_CONNECT_ERROR: + break; + case EVT_PROVIDER_LOGIN_FINISHED: + if (OperationCode.SUCCESS == result) { + processor.gatherData(); + } + this.notifyListeners( + EventCode.EVT_TOOL_LOGIN_FINISHED, + result); + break; + case EVT_PROVIDER_SENDCOMMAND_FINISHED: + break; + case EVT_PROVIDER_SENDCOMMAND_ERROR: + break; + case EVT_PROVIDER_SENDDATA_FINISHED: + break; + case EVT_PROVIDER_SENDDATA_ERROR: + break; + case EVT_PROVIDER_DISCONNECT_FINISHED: + this.notifyListeners( + EventCode.EVT_TOOL_DISCONNECT_FINISHED, + result); + break; + } + } + if (notifier == processor) { + switch (event) { + case EVT_PROCESSOR_GATHERDATA_FINISHED: + notifyListeners(EventCode.EVT_TOOL_REFRESH_VIEW, + result); + break; + case EVT_PROCESSOR_GATHERDATA_ERROR: + break; + } + } + } catch (IOException ie) { + } + } + + /** + * + */ + public void refresh() { + try { + if (null != processor) { + processor.gatherData(); + } + } catch (IOException ie) { + //TODO: Nothing ? + } + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.ITool#getRefreshDelay() + */ + public int getRefreshDelay() { + // TODO Auto-generated method stub + return 0; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.tools.ITool#setRefreshDelay(int) + */ + public void setRefreshDelay(int delay) { + // TODO Auto-generated method stub + } + + public void start() { + // TODO Auto-generated method stub + } + + public void stop() { + // TODO Auto-generated method stub + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapVViewLabelProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapVViewLabelProvider.java new file mode 100644 index 0000000000..55abd9853c --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapVViewLabelProvider.java @@ -0,0 +1,59 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.memorymap; + +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +/** + * @author Otavio Ferranti + */ +public class MemoryMapVViewLabelProvider extends LabelProvider implements + ITableLabelProvider { + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) + */ + public Image getColumnImage(Object obj, int index) { + //TODO: Enhance this. + if (index == 2) { + return getImage(((Object[]) obj)[index]); + } else { + return null; + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) + */ + public String getColumnText(Object obj, int index) { + if (obj instanceof String[]) { + return getText(((Object[]) obj)[index]); + } else { + return new String(""); //$NON-NLS-1$ + } + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) + */ + public Image getImage(Object obj) { + return PlatformUI.getWorkbench(). + getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); + } +} + diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapView.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapView.java new file mode 100644 index 0000000000..a6f58b0852 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapView.java @@ -0,0 +1,290 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.memorymap; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.linuxtools.sequoyah.device.LinuxToolsPlugin; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode; +import org.eclipse.linuxtools.sequoyah.device.network.IConstants.OperationCode; +import org.eclipse.linuxtools.sequoyah.device.tools.IListener; +import org.eclipse.linuxtools.sequoyah.device.tools.INotifier; +import org.eclipse.linuxtools.sequoyah.device.tools.ITool; +import org.eclipse.linuxtools.sequoyah.device.ui.DialogLogin; +import org.eclipse.linuxtools.sequoyah.device.ui.IToolViewPart; +import org.eclipse.linuxtools.sequoyah.device.ui.ViewActionConnect; +import org.eclipse.linuxtools.sequoyah.device.ui.ViewActionDisconnect; +import org.eclipse.linuxtools.sequoyah.device.ui.ViewActionRefresh; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IPartListener; +import org.eclipse.ui.IViewActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.part.ViewPart; + +/** + * @author Otavio Ferranti + */ +public class MemoryMapView extends ViewPart implements IToolViewPart, IListener { + + private class AddressSorter extends ViewerSorter { + + public int compare(Viewer viewer, Object e1, Object e2) { + int result = 0; + try { + int a = new Integer(((String[]) e1)[MAX_COLUMNS - 1]).intValue(); + int b = new Integer(((String[]) e2)[MAX_COLUMNS - 1]).intValue(); + if (a > b) { + result = 1; + } else if (a < b) { + result = -1; + }; + } + catch (NumberFormatException nfe) { + //TODO: Nothing ? + } + return result; + } + } + final private String COL_LABEL_ADDRESS_START = Messages.MemoryMapView_Col_Label_Address_Start; + final private String COL_LABEL_ADDRESS_END = Messages.MemoryMapView_Col_Label_Address_End; + final private String COL_LABEL_REGION = Messages.MemoryMapView_Col_label_Region; + + final private int MAX_COLUMNS = 4; + + private ITool tool = null; + private TableViewer viewer; + + private Action refreshAction; + private Action disconnectAction; + private Action connectAction; + + private IPartListener partActivationListener = new IPartListener() { + public void partActivated(IWorkbenchPart part) { + } + + public void partBroughtToTop(IWorkbenchPart part) { + } + + public void partClosed(IWorkbenchPart part) { + if (MemoryMapView.this.getSite().getPart() == part) { + ITool tool = MemoryMapView.this.getTool(); + if (null != tool) { + tool.disconnect(); + } + } + } + + public void partDeactivated(IWorkbenchPart part) { + } + + public void partOpened(IWorkbenchPart part) { + } + }; + + /** + * The constructor. + */ + public MemoryMapView() { + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + /* (non-Javadoc) + * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) + */ + public void createPartControl(Composite parent) { + + viewer = new TableViewer(parent, SWT.FULL_SELECTION | + SWT.H_SCROLL | SWT.V_SCROLL); + viewer.setContentProvider(new MemoryMapViewContentProvider()); + viewer.setLabelProvider(new MemoryMapVViewLabelProvider()); + viewer.setSorter(new AddressSorter()); + + Table table = viewer.getTable(); + table.setHeaderVisible(true); + + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_ADDRESS_START); + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_ADDRESS_END); + new TableColumn(table, SWT.LEFT).setText(COL_LABEL_REGION); + + refresh(); + resize(); + + makeActions(); + // hookDoubleClickAction(); + addToToolBar(); + + getViewSite() + .getWorkbenchWindow() + .getPartService() + .addPartListener(partActivationListener); + + setConnectEnabled(true); + refreshAction.setEnabled(false); + } + + private void addToToolBar() { + IActionBars actionBars = getViewSite().getActionBars(); + IToolBarManager toolBarMmanager = actionBars.getToolBarManager(); + toolBarMmanager.add(refreshAction); + toolBarMmanager.add(disconnectAction); + toolBarMmanager.add(connectAction); + } + + private void makeActions() { + + refreshAction = new Action() { + public void run() { + IViewActionDelegate delegate = new ViewActionRefresh(); + delegate.init(MemoryMapView.this); + delegate.run(this); + this.setEnabled(false); + } + }; + refreshAction.setToolTipText(Messages.MemoryMapView_Action_Refresh); + refreshAction.setImageDescriptor( + LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_REFRESH)); + + disconnectAction = new Action() { + public void run() { + IViewActionDelegate delegate = new ViewActionDisconnect(); + delegate.init(MemoryMapView.this); + delegate.run(this); + } + }; + disconnectAction.setToolTipText(Messages.MemoryMapView_Action_Disconnect); + disconnectAction.setImageDescriptor( + LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_DISCONNECT)); + + connectAction = new Action() { + public void run() { + IViewActionDelegate delegate = new ViewActionConnect(); + delegate.init(MemoryMapView.this); + delegate.run(this); + } + }; + connectAction.setToolTipText(Messages.MemoryMapView_Action_Connect); + connectAction.setImageDescriptor( + LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_CONNECT)); + + } + + private void setConnectEnabled(boolean bool) { + connectAction.setEnabled(bool); + disconnectAction.setEnabled(!bool); + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.ui.IToolView#getTool() + */ + public ITool getTool() { + if(null == tool) { + tool = new MemoryMapTool(); + tool.addListener(this); + } + return tool; + } + + /* (non-Javadoc) + * @see org.eclipse.linuxtools.sequoyah.device.network.IListener#notify(org.eclipse.linuxtools.sequoyah.device.network.INotifier, org.eclipse.linuxtools.sequoyah.device.network.IConstants.EventCode, java.lang.Object) + */ + public void notify(INotifier notifier, EventCode event, Object result) { + if (notifier == tool) { + final Object finalResult = result; + final EventCode finalEvent = event; + final ViewPart finalView = this; + final ITool finalTool = this.tool; + + this.getViewSite().getShell().getDisplay().asyncExec(new Runnable() { + public void run() { + switch(finalEvent) { + case EVT_TOOL_REFRESH_VIEW: + viewer.setInput(finalResult); + refreshAction.setEnabled(true); + refresh(); + resize(); + break; + case EVT_TOOL_CONNECT_FINISHED: + case EVT_TOOL_LOGIN_FINISHED: + switch ((OperationCode)finalResult) { + case SUCCESS: + setConnectEnabled(false); + refreshAction.setEnabled(true); + break; + case LOGIN_REQUIRED: { + final DialogLogin dialog = new DialogLogin( + finalView.getViewSite().getShell(), + finalTool, false); + dialog.open(); + } + break; + case LOGIN_FAILED: { + final DialogLogin dialog = new DialogLogin( + finalView.getViewSite().getShell(), + finalTool, true); + dialog.open(); + } + break; + } + break; + case EVT_TOOL_DISCONNECT_FINISHED: + setConnectEnabled(true); + refreshAction.setEnabled(false); + break; + } + } + }); + } + } + + /** + * + */ + public void refresh() { + viewer.refresh(); + } + + /** + * + */ + public void resize() { + Table table = viewer.getTable(); + for (int i = 0, n = table.getColumnCount(); i < n; i++) { + table.getColumn(i).pack(); + } + } + + /** + * @param data + */ + public void setData (Object data) { + viewer.setInput(data); + } + + /** + * Passing the focus request to the viewer's control. + */ + public void setFocus() { + viewer.getControl().setFocus(); + } +} \ No newline at end of file diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapViewContentProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapViewContentProvider.java new file mode 100644 index 0000000000..c251eabe92 --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/MemoryMapViewContentProvider.java @@ -0,0 +1,60 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.memorymap; + +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/* + * The content provider class is responsible for + * providing objects to the view. It can wrap + * existing objects in adapters or simply return + * objects as-is. These objects may be sensitive + * to the current input of the view, or ignore + * it and always show the same content + * (like Task List, for example). + */ + +/** + * @author Otavio Ferranti + */ +public class MemoryMapViewContentProvider implements IStructuredContentProvider { + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object parent) { + if (parent instanceof String[][]) { + return (String[][]) parent; + } else { + String[][] aux = new String[1][]; + aux[0] = new String[] {"", //$NON-NLS-1$ + "", //$NON-NLS-1$ + ""}; //$NON-NLS-1$ + return aux; + } + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/Messages.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/Messages.java new file mode 100644 index 0000000000..0f6fdcbede --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/Messages.java @@ -0,0 +1,40 @@ +/******************************************************************************** + * Copyright (c) 2008 Motorola Inc. All rights reserved. + * This program and the accompanying materials are made available under the terms + * of the Eclipse Public License v1.0 which accompanies this distribution, and is + * available at http://www.eclipse.org/legal/epl-v10.html + * + * Initial Contributor: + * Otavio Ferranti (Motorola) + * + * Contributors: + * {Name} (company) - description of contribution. + ********************************************************************************/ + +package org.eclipse.linuxtools.sequoyah.device.tools.memorymap; + +import org.eclipse.osgi.util.NLS; + +/** + * @author Otavio Ferranti + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = + "org.eclipse.linuxtools.sequoyah.device.tools.memorymap.messages"; //$NON-NLS-1$ + + public static String MemoryMapProcessor_Msg_Executing_The_Command; + public static String MemoryMapProcessor_Msg_Got_The_Result; + public static String MemoryMapView_Action_Refresh; + public static String MemoryMapView_Action_Disconnect; + public static String MemoryMapView_Action_Connect; + public static String MemoryMapView_Col_Label_Address_End; + public static String MemoryMapView_Col_Label_Address_Start; + public static String MemoryMapView_Col_label_Region; + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/messages.properties b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/messages.properties new file mode 100644 index 0000000000..b242a0463e --- /dev/null +++ b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/linuxtools/sequoyah/device/tools/memorymap/messages.properties @@ -0,0 +1,27 @@ +################################################################################ +# Copyright (c) 2009 Motorola Inc. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Initial Contributors: +# Otavio Ferranti (Motorola) +# +# Contributors: +# {Name} (company) - description of contribution. +################################################################################ + +# NLS_MESSAGEFORMAT_VAR +# NLS_ENCODING=UTF-8 + +MemoryMapView_Col_Label_Address_Start=Start +MemoryMapView_Col_Label_Address_End=End +MemoryMapView_Col_label_Region=Region name + +MemoryMapView_Action_Refresh=Refresh +MemoryMapView_Action_Disconnect=Disconnect +MemoryMapView_Action_Connect=Connect + +MemoryMapProcessor_Msg_Executing_The_Command=Executing the command: +MemoryMapProcessor_Msg_Got_The_Result=Got the result: diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/LinuxToolsPlugin.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/LinuxToolsPlugin.java deleted file mode 100644 index 9e600c684b..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/LinuxToolsPlugin.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools; - -import org.eclipse.sequoyah.device.common.utilities.BasePlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class LinuxToolsPlugin extends BasePlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.sequoyah.device.linuxtools"; //$NON-NLS-1$ - - // Common icons - public static final String ICON_RUN = "run.gif"; //$NON-NLS-1$ - public static final String ICON_PAUSE = "pause.gif"; //$NON-NLS-1$ - public static final String ICON_OPTIONS = "options.gif"; //$NON-NLS-1$ - public static final String ICON_REFRESH = "refresh.gif"; //$NON-NLS-1$ - public static final String ICON_DISCONNECT = "disconnect.gif"; //$NON-NLS-1$ - public static final String ICON_CONNECT = "connect.gif"; //$NON-NLS-1$ - - // The shared instance - private static LinuxToolsPlugin plugin; - - private static final String[] allIcons = {ICON_RUN, - ICON_PAUSE, - ICON_OPTIONS, - ICON_REFRESH, - ICON_DISCONNECT, - ICON_CONNECT}; - - /** - * Returns the shared instance - * @return the shared instance - */ - public static LinuxToolsPlugin getDefault() { - return plugin; - } - - /** - * The constructor - */ - public LinuxToolsPlugin() { - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - @Override - protected void initializeImageRegistry() { - String path = getIconPath(); - for (String s: allIcons) { - putImageInRegistry(s, path + s); - } - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/Messages.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/Messages.java deleted file mode 100644 index 1f7ab94606..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/Messages.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools; - -import org.eclipse.osgi.util.NLS; - -/** - * @author Otavio Ferranti - * - */ -public class Messages extends NLS { - - private static String BUNDLE_NAME = "org.eclipse.sequoyah.device.linuxtools.messages"; //$NON-NLS-1$ - public static String TML_Plugin_Name; - public static String TML_Error; - public static String TML_Resource_Not_Available; - - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/messages.properties b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/messages.properties deleted file mode 100644 index a657aabb37..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/messages.properties +++ /dev/null @@ -1,21 +0,0 @@ -################################################################################ -# Copyright (c) 2009 Motorola Inc. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Initial Contributors: -# Otavio Ferranti (Motorola) -# -# Contributors: -# {Name} (company) - description of contribution. -################################################################################ - -# NLS_MESSAGEFORMAT_VAR -# NLS_ENCODING=UTF-8 - -TML_Plugin_Name=Linux Tools Plugin (Incubation) -TML_Error=A unexpected exception was found -TML_Resource_Not_Available=Resource not available - diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/tcf/TCFProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/tcf/TCFProvider.java deleted file mode 100644 index 6717cf0bbf..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/tcf/TCFProvider.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2009 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.network.tcf; - -import java.io.IOException; - -import org.eclipse.sequoyah.device.common.utilities.logger.ILogger; -import org.eclipse.sequoyah.device.linuxtools.LinuxToolsPlugin; -import org.eclipse.sequoyah.device.linuxtools.network.IConnectionProvider; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.CommandCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.OperationCode; -import org.eclipse.sequoyah.device.linuxtools.tools.AbstractNotifier; - -public class TCFProvider extends AbstractNotifier implements - IConnectionProvider { - - private TCFWrapper connectionWrapper = null; - private ILogger logger = null; - - private Thread connectThread = null; - private Thread sendCommandThread = null; - - /** - * The constructor. - */ - public TCFProvider() { - connectionWrapper = new TCFWrapper(); - logger = LinuxToolsPlugin.getLogger(); - } - - /** - * This method will be executed in a separated thread and will produce - * an event to be sent to the registered listeners. - */ - public void connect(String host, int port) throws IOException { - final String hostAux = host; - final int portAux = port; - final TCFWrapper connectionWrapperAux = connectionWrapper; - - /*TODO: Enhance this. It would be great if all these executed-in-other threads - were located under a synchronized block */ - - connectThread = new Thread() { - public void run() { - try { - connectionWrapperAux.connect(hostAux, portAux); - TCFProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_CONNECT_FINISHED, - OperationCode.SUCCESS); - } catch (IOException ie) { - TCFProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_CONNECT_ERROR, - OperationCode.UNEXPECTED_RESULT); - } - - } - }; - connectThread.start(); - } - - public void disconnect() throws IOException { - if (null != connectThread && - connectThread.isAlive()) { - connectThread.interrupt(); - } - - if (null != sendCommandThread && - sendCommandThread.isAlive()) { - sendCommandThread.interrupt(); - } - connectionWrapper.disconnect(); - notifyListeners( - EventCode.EVT_PROVIDER_DISCONNECT_FINISHED, OperationCode.SUCCESS); - } - - public StringBuffer getLastResponde() { - return connectionWrapper.getLastResponde(); - } - - public void login(String user, String password) throws IOException { - - } - - /** - * This method will be executed in a separated thread and will produce - * an event to be sent to the registered listeners. - */ - public void sendCommand(CommandCode cmd, String cmdStr) throws IOException { - - if (CommandCode.FETCH_FILE != cmd) { - return; - } - - final TCFWrapper connectionWrapperAux = connectionWrapper; - - final String path = cmdStr.substring(0, cmdStr.lastIndexOf("/")); - final String fileName = cmdStr.substring(cmdStr.lastIndexOf("/")); - - sendCommandThread = new Thread() { - public void run() { - try { - - if (null != connectionWrapperAux.fetchFile(path, fileName)) { - StringBuffer result = connectionWrapperAux.getLastResponde(); - TCFProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_SENDCOMMAND_FINISHED, result); - } else { - logger.info("##### NULL ######"); - } - } catch (IOException ie) { - TCFProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_SENDCOMMAND_ERROR, null); - } - - } - }; - sendCommandThread.start(); - } - - public void sendData(String out) { - connectionWrapper.sendData(out); - } - - public void setResponseLength(int maxLength) { - connectionWrapper.setResponseLength(maxLength); - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/tcf/TCFWrapper.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/tcf/TCFWrapper.java deleted file mode 100644 index dab2d5d776..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/tcf/TCFWrapper.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.network.tcf; - -import java.io.IOException; -import java.io.InputStream; - -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.rse.core.IRSECoreRegistry; -import org.eclipse.rse.core.IRSESystemType; -import org.eclipse.rse.core.RSECorePlugin; -import org.eclipse.rse.core.model.IHost; -import org.eclipse.rse.core.model.ISystemRegistry; -import org.eclipse.rse.services.clientserver.messages.SystemMessageException; -import org.eclipse.rse.subsystems.files.core.model.RemoteFileUtility; -import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.OperationCode; - -public class TCFWrapper { - - private StringBuffer lastResponse = null; - private IHost rseHost = null; - - public void connect(String host, int port) throws IOException { - ISystemRegistry rseSystemRegistry = RSECorePlugin.getTheSystemRegistry(); - IRSECoreRegistry rseCoreRegistry = RSECorePlugin.getTheCoreRegistry(); - IRSESystemType tcfSystemType = rseCoreRegistry.getSystemTypeById("org.eclipse.tm.tcf.rse.systemType"); - try { - rseHost = rseSystemRegistry.createHost(tcfSystemType, host, host, host); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void disconnect() throws IOException { - // TODO Auto-generated method stub - - } - - public StringBuffer getLastResponde() { - return lastResponse; - } - - public OperationCode login(String user, String password) throws IOException { - // TODO Auto-generated method stub - return OperationCode.SUCCESS; - } - - public String fetchFile(String path, String fileName) throws IOException { - IRemoteFileSubSystem remoteFileSubSystem = - RemoteFileUtility.getFileSubSystem(rseHost); - InputStream inputStream = null; - - try { - remoteFileSubSystem.connect(new NullProgressMonitor(), false); - inputStream = remoteFileSubSystem.getInputStream(path, fileName, - false, new NullProgressMonitor()); - } catch (SystemMessageException sme) { - // TODO Auto-generated catch block - sme.printStackTrace(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - lastResponse = new StringBuffer(); - - byte[] b = new byte[16]; - char[] c = new char[16]; - while (inputStream.read(b) >= 0) { - for (int i = 0; i < b.length; i++) { - c[i] = (char) b[i]; - } - lastResponse.append(c); - } - return "OK"; - } - - public void sendData(String out) { - // TODO Auto-generated method stub - - } - - public void setResponseLength(int maxLength) { - // TODO Auto-generated method stub - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/telnet/TelnetProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/telnet/TelnetProvider.java deleted file mode 100644 index 4a34606e02..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/telnet/TelnetProvider.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2009 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.network.telnet; - -import java.io.IOException; - -import org.eclipse.sequoyah.device.common.utilities.logger.ILogger; -import org.eclipse.sequoyah.device.linuxtools.LinuxToolsPlugin; -import org.eclipse.sequoyah.device.linuxtools.network.IConnectionProvider; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.CommandCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.OperationCode; -import org.eclipse.sequoyah.device.linuxtools.tools.AbstractNotifier; - -/** - * @author Ot�vio Ferranti - */ -public class TelnetProvider extends AbstractNotifier implements IConnectionProvider { - - final private String CMD_FETCH_PREFIX = "cat "; //$NON-NLS-1$ - - private TelnetWrapper connectionWrapper = null; - private ILogger logger = null; - - private Thread connectThread = null; - private Thread loginThread = null; - private Thread sendCommandThread = null; - - /** - * The constructor. - */ - public TelnetProvider() { - connectionWrapper = new TelnetWrapper(); - logger = LinuxToolsPlugin.getLogger(); - } - - /** - * This method will be executed in a separated thread and will produce - * an event to be sent to the registered listeners. - */ - /* (non-Javadoc) - * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#connect(java.lang.String, int) - */ - public void connect(String host, int port) throws IOException { - final String hostAux = host; - final int portAux = port; - final TelnetWrapper connectionWrapperAux = connectionWrapper; - - /*TODO: Enhance this. It would be great if all these executed-in-other threads - were located under a synchronized block */ - - connectThread = new Thread() { - public void run() { - try { - OperationCode opCode; - opCode = connectionWrapperAux.connect(hostAux, portAux); - TelnetProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_CONNECT_FINISHED, opCode); - } catch (IOException ie) { - TelnetProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_CONNECT_ERROR, - OperationCode.UNEXPECTED_RESULT); - } - - } - }; - connectThread.start(); - } - - /* (non-Javadoc) - * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#disconnect() - */ - public void disconnect() throws IOException { - if (null != connectThread && - connectThread.isAlive()) { - connectThread.interrupt(); - } - if (null != loginThread && - loginThread.isAlive()) { - loginThread.interrupt(); - } - if (null != sendCommandThread && - sendCommandThread.isAlive()) { - sendCommandThread.interrupt(); - } - connectionWrapper.disconnect(); - notifyListeners( - EventCode.EVT_PROVIDER_DISCONNECT_FINISHED, OperationCode.SUCCESS); - } - - /** - * This method will be executed in a separated thread and will produce - * an event to be sent to the registered listeners. - */ - /* (non-Javadoc) - * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#login(java.lang.String, java.lang.String) - */ - public void login(String user, String password) throws IOException { - final String userAux = user; - final String passwordAux = password; - final TelnetWrapper connectionWrapperAux = connectionWrapper; - - /*TODO: Enhance this. It would be great if all these executed-in-other threads - were located under a synchronized block */ - loginThread = new Thread() { - public void run() { - try { - OperationCode opCode; - opCode = connectionWrapperAux.login(userAux, passwordAux); - TelnetProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_LOGIN_FINISHED, opCode); - } catch (IOException ie) { - TelnetProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_LOGIN_ERROR, - OperationCode.UNEXPECTED_RESULT); - } - } - }; - loginThread.start(); - } - - /* (non-Javadoc) - * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#getLastResponde() - */ - public StringBuffer getLastResponde() { - return connectionWrapper.getLastResponde(); - } - - /** - * This method will be executed in a separated thread and will produce - * an event to be sent to the registered listeners. - */ - /* (non-Javadoc) - * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#sendCommand(java.lang.String) - */ - public void sendCommand(CommandCode cmd, String cmdStr) throws IOException { - - if (CommandCode.FETCH_FILE != cmd) { - return; - } - - final String commandAux = CMD_FETCH_PREFIX + cmdStr + "\n"; //$NON-NLS-1$ - - final TelnetWrapper connectionWrapperAux = connectionWrapper; - - /*TODO: Enhance this. It would be great if all these executed-in-other threads - were located under a synchronized block */ - sendCommandThread = new Thread() { - public void run() { - try { - connectionWrapperAux.setResponseLength(2048); - if (null != connectionWrapperAux.sendCommand(commandAux)) { - StringBuffer result = connectionWrapperAux.getLastResponde(); - TelnetProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_SENDCOMMAND_FINISHED, result); - } else { - logger.info("##### NULL ######"); - } - } catch (IOException ie) { - TelnetProvider.this.notifyListeners( - EventCode.EVT_PROVIDER_SENDCOMMAND_ERROR, null); - } - - } - }; - sendCommandThread.start(); - } - - /* (non-Javadoc) - * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#sendData(java.lang.String) - */ - public void sendData(String out) { - connectionWrapper.sendData(out); - } - - /* (non-Javadoc) - * @see org.eclipse.tml.linuxmemorymapviewer.network.IConnectionProvider#setResponseLength(int) - */ - public void setResponseLength(int maxLength) { - connectionWrapper.setResponseLength(maxLength); - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/telnet/TelnetWrapper.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/telnet/TelnetWrapper.java deleted file mode 100644 index fbb3f2ff3d..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/network/telnet/TelnetWrapper.java +++ /dev/null @@ -1,235 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * Otavio Ferranti - Eldorado Research Institute - Bug 255255 [tml][proctools] Add extension points - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.network.telnet; - -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.util.HashMap; - -import org.apache.commons.net.telnet.EchoOptionHandler; -import org.apache.commons.net.telnet.InvalidTelnetOptionException; -import org.apache.commons.net.telnet.SuppressGAOptionHandler; -import org.apache.commons.net.telnet.TelnetClient; -import org.apache.commons.net.telnet.TerminalTypeOptionHandler; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.OperationCode; - -/** - * @author Ot�vio Ferranti - */ -public class TelnetWrapper { - - final public String PROMPT = "[###]:"; //$NON-NLS-1$ - final private String[] LOGIN_TOKENS = {"login:", //$NON-NLS-1$ - "Login:"}; //$NON-NLS-1$ - final private String[] PASSWORD_TOKENS = {"password:", //$NON-NLS-1$ - "Password:"}; //$NON-NLS-1$ - final private String[] LOGIN_FAILED_TOKENS = {"Login incorrect", //$NON-NLS-1$ - "Access denied"}; //$NON-NLS-1$ - final private String CHANGE_PROMPT = "export PS1='[\\043\\043\\043]:'\n"; //$NON-NLS-1$ - - // private ILogger logger = null; - private TelnetClient client = null; - private InputStream inStream = null; - private PrintStream outStream = null; - private StringBuffer lastResponse = null; - private int maxResponseDataLength = 1024; - - private int MAX_LENGTH_PASSWORD_TOKENS = 32; - private int MAX_LENGTH_LOGIN_FAILED = 32; - private int MAX_LENGTH_LOGIN_INITSCREEN = 2048; - private int MAX_LENGTH_CHANGE_PROMPT = 128; - - /** - * Constructor - */ - public TelnetWrapper() { - if (null == this.client) { - this.client = new TelnetClient(); - try { - this.client.addOptionHandler(new TerminalTypeOptionHandler( - "VT100", false, false, true, false)); //$NON-NLS-1$ - this.client.addOptionHandler(new SuppressGAOptionHandler( - true, true, true, true)); - this.client.addOptionHandler(new EchoOptionHandler( - false, false, false, false)); - } catch (InvalidTelnetOptionException itoe) { } - // logger = LinuxToolsPlugin.getLogger(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IConnectionWrapper#connect(java.lang.String, int) - */ - public OperationCode connect(String host, int port) throws IOException { - OperationCode retVal; - - this.client.connect(host, port); - - inStream = client.getInputStream(); - outStream = new PrintStream (client.getOutputStream()); - - // sendData(user+"\n"); - if(null == readUntilTokens(LOGIN_TOKENS)) { - retVal = OperationCode.SUCCESS; - } else { - retVal = OperationCode.LOGIN_REQUIRED; - } - return retVal; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IConnectionWrapper#disconnect() - */ - public void disconnect() throws IOException { - if (null != client) { - client.disconnect(); - // System.out.println("Connection closed ..."); - } - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IConnectionWrapper#login(java.lang.String, java.lang.String) - */ - public OperationCode login(String user, String password) throws IOException { - OperationCode retVal = OperationCode.UNEXPECTED_RESULT; - - sendData(user+"\n"); //$NON-NLS-1$ - setResponseLength(MAX_LENGTH_PASSWORD_TOKENS); - if (null != readUntilTokens(PASSWORD_TOKENS)) { - sendData(password+"\n"); //$NON-NLS-1$ - - setResponseLength(MAX_LENGTH_LOGIN_FAILED); - if (null != readUntilTokens(LOGIN_FAILED_TOKENS)) { - if(null != readUntilTokens(LOGIN_TOKENS)) { - retVal = OperationCode.LOGIN_FAILED; - } else { - retVal = OperationCode.UNEXPECTED_RESULT; - } - return retVal; - } else { - setResponseLength(MAX_LENGTH_LOGIN_INITSCREEN); - int toBeSkipped = inStream.available(); - inStream.skip(toBeSkipped); - } - } - try { - Thread.sleep (2000); - } catch (InterruptedException ite) { - - } - setResponseLength(MAX_LENGTH_CHANGE_PROMPT); - sendData(CHANGE_PROMPT); - if (null != readUntilTokens(PROMPT)) { - retVal = OperationCode.SUCCESS; - } - return retVal; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IConnectionWrapper#getLastResponde() - */ - public StringBuffer getLastResponde() { - return lastResponse; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IConnectionWrapper#sendCommand(java.lang.String) - */ - public String sendCommand(String command) throws IOException { - sendData (command); - return readUntilTokens (PROMPT); - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IConnectionWrapper#sendData(java.lang.String) - */ - public void sendData(String out) { - if (null != outStream) { - outStream.print(out); - outStream.flush(); - } - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IConnectionWrapper#setResponseLength(int) - */ - public void setResponseLength(int maxLength) { - maxResponseDataLength = maxLength; - } - - /** - * @param token - * @return - * @throws IOException - */ - private String readUntilTokens(String token)throws IOException { - return readUntilTokens(new String[] {token}); - } - - /** - * @param tokenArray - * @return - * @throws IOException - */ - private String readUntilTokens(final String []tokenArray) throws IOException { - String matchedString = null; - boolean tokenFound = false; - StringBuffer readData = new StringBuffer(); - - HashMap hashMap = new HashMap(); - - for (int i = 0; i < tokenArray.length; i++) { - hashMap.put(tokenArray[i], new Integer(0)); - } - - for (int i = 0; i < this.maxResponseDataLength; i++) { - - int aux = inStream.read(); - - char ch = 0; - if (aux == 0 || aux == 1) { - continue; - } else { - ch = (char) aux; - } - readData.append(ch); - - // if (ch != 1 && ch != 0) - // logger.info(ch); - - for (int j = 0; j < tokenArray.length; j++) { - String token = tokenArray[j]; - Integer rank = hashMap.get(token); - if (ch == token.charAt(rank)) { - rank ++; - if (rank >= token.length()) { - // MATCHED - readData.setLength(readData.length() - token.length()); - matchedString = token; - tokenFound = true; - } - } else { - rank = 0; - } - hashMap.put(token, rank); - } - if (tokenFound) { - break; - } - } - this.lastResponse = readData; - return matchedString; - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadProcessor.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadProcessor.java deleted file mode 100644 index e6edcbee95..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadProcessor.java +++ /dev/null @@ -1,279 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2009 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.cpuload; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Scanner; -import java.util.regex.MatchResult; - -import org.eclipse.sequoyah.device.common.utilities.logger.ILogger; -import org.eclipse.sequoyah.device.linuxtools.LinuxToolsPlugin; -import org.eclipse.sequoyah.device.linuxtools.network.IConnectionProvider; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.CommandCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode; -import org.eclipse.sequoyah.device.linuxtools.tools.AbstractNotifier; -import org.eclipse.sequoyah.device.linuxtools.tools.IListener; -import org.eclipse.sequoyah.device.linuxtools.tools.INotifier; - -/** - * @author Otavio Ferranti - */ -public class CpuLoadProcessor extends AbstractNotifier implements IListener { - - final private String CMD_FETCH_STAT = "/proc/stat"; //$NON-NLS-1$ - final private String PARSE_PATTERN_1 = "cpu(\\d*)(.*)"; //$NON-NLS-1$; - final private String PARSE_PATTERN_2 = "\\s+(\\d+)"; //$NON-NLS-1$; - final private String DATA_FORMAT = "%1$02.1f %%"; //$NON-NLS-1$; - - final private String MSG_EXECUTING_COMMAND = - Messages.CpuLoadProcessor_Msg_Executing_the_command; - - final private String MSG_GOT_RESULT = - Messages.CpuLoadProcessor_Msg_Got_The_Result; - - final private int MAX_COLUMNS = 100; - - private int[][] previousData = null; - private long[] previousTotal = null; - private IConnectionProvider connectionProvider = null; - - private ILogger logger = null; - - /** - * The constructor; - * @param connectionProvider - */ - public CpuLoadProcessor(IConnectionProvider connectionProvider) { - setConnectionProvider(connectionProvider); - logger = LinuxToolsPlugin.getLogger(); - } - - /** - * Requests data. - * @throws IOException - */ - public void gatherData() throws IOException { - this.connectionProvider.sendCommand(CommandCode.FETCH_FILE, this.CMD_FETCH_STAT); - logger.debug(MSG_EXECUTING_COMMAND + "\n" + this.CMD_FETCH_STAT); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IListener#notify(org.eclipse.sequoyah.device.linuxtools.network.INotifier, org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode, java.lang.Object) - */ - public void notify(INotifier notifier, - EventCode event, - Object result) { - if (notifier == this.connectionProvider && - event == EventCode.EVT_PROVIDER_SENDCOMMAND_FINISHED) { - Object[][] parsedResult = parseStat((StringBuffer) result); - this.notifyListeners(EventCode.EVT_PROCESSOR_GATHERDATA_FINISHED, - parsedResult); - } - } - - /** - * Set the connection provider. - * @param connectionProvider - */ - public void setConnectionProvider (IConnectionProvider connectionProvider) { - if (null != this.connectionProvider) { - this.connectionProvider.removeListener(this); - } - this.connectionProvider = connectionProvider; - if (null != this.connectionProvider) { - this.connectionProvider.addListener(this); - } - } - - /** - * @param currentDataStr - * @return - */ - private Object[][] calculateTimes(String[][] currentDataStr) { - String[][] resultStr = null; - - if (null == currentDataStr) { - currentDataStr = new String[][] {{"0"}}; - } - if (null == previousData) { - previousData = new int[][] {{0}}; - previousTotal = new long[] {1}; - } - if (previousData.length != currentDataStr.length || - previousData[0].length != currentDataStr[0].length) { - previousData = String2int(currentDataStr); - previousTotal = new long[previousData.length]; - - for (int j = 0; j < previousData.length; j++) { - long total = 0; - for (int i = 0; i < previousData[0].length; i++) { - total += previousData[j][i]; - } - previousTotal[j] = total; - } - } - final int[][] currentDataInt = String2int(currentDataStr); - float[][] resultFloat = new float[currentDataStr.length][currentDataStr[0].length]; - - for (int j = 0; j < currentDataInt.length; j++) { - long total = 0; - for (int i = 0; i < currentDataInt[0].length; i++) { - total += currentDataInt[j][i]; - } - float deltaTotal = total - previousTotal[j]; - previousTotal[j] = total; - for (int i = 0; i < currentDataInt[0].length; i++) { - float deltaData = currentDataInt[j][i] - previousData[j][i]; - if (0 == deltaTotal) { - resultFloat[j][i] = 0; - } else { - resultFloat[j][i] = 100* deltaData / deltaTotal; - } - } - } - previousData = currentDataInt; - resultStr = float2StringFormated(resultFloat, DATA_FORMAT); - return resultStr; - } - - /** - * @param target - * @param Source - */ - private void copyData(Object[][] target, Object[][] Source) { - for (int j = 0; j < target.length; j++) { - for (int i = 1; i < target[0].length; i++) { - target[j][i] = Source[j][i-1]; - } - } - } - - /** - * @param input - * @return - */ - private String[][] float2StringFormated (float[][] input, String format) { - String[][] output = null; - if (null != input) { - output = new String[input.length][input[0].length]; - for (int j = 0; j < output.length; j++) { - for (int i = 0; i < output[0].length; i++) { - output[j][i] = String.format(format, new Float(input[j][i])); - } - } - } - return output; - } - - /** - * @param data - * @return - */ - private Object[][] parseStat(StringBuffer data) { - logger.debug(MSG_GOT_RESULT + "\n" + data.toString()); - - int requiredColumns = 0; - - Scanner s1 = new Scanner(data.toString()); - ArrayList list = new ArrayList(); - - while (s1.hasNextLine()) { - String[] entry = new String[MAX_COLUMNS];; - - Scanner s2 = new Scanner(s1.nextLine()); - s2.findInLine(PARSE_PATTERN_1); - - try { - - MatchResult result = s2.match(); - entry[0] = result.group(1).trim(); - - String aux = result.group(2); - - Scanner s3 = new Scanner(aux); - entry[1] = s3.findInLine(PARSE_PATTERN_2).trim(); - - s3.match(); - int i = 2; - - while (s3.hasNext() && i < MAX_COLUMNS) { - entry[i] = s3.next().trim(); - - if (i > requiredColumns) { - requiredColumns = i; - } - i++; - } - s3.close(); - if (null != entry) { - list.add(entry); - } - } catch (IllegalStateException ise) { - } - s2.close(); - } - s1.close(); - - String[][] dataAux = new String[list.size()][requiredColumns + 1]; - for (int j = 0; j < dataAux.length; j++) { - for (int i = 0; i < dataAux[0].length; i++) { - dataAux[j][i] = list.get(j)[i]; - } - } - String[][] dataStrippedAux = stripFirstColumn(dataAux); - Object[][] result = calculateTimes(dataStrippedAux); - copyData(dataAux, result); - return dataAux; - } - - /** - * @param input - * @return - */ - private int[][] String2int (String[][] input) { - int[][] output = null; - if (null != input) { - output = new int[input.length][input[0].length]; - for (int j = 0; j < output.length; j++) { - for (int i = 0; i < output[0].length; i++) { - try { - output[j][i] = new Integer(input[j][i]).intValue(); - } - catch (NumberFormatException nfe) { - output[j][i] = -1; - } - } - } - } - return output; - } - - /** - * @param input - * @return - */ - private String[][] stripFirstColumn (String[][] input) { - String output[][] = null; - if (null != input) { - output = new String[input.length][input[0].length-1]; - for (int j = 0; j < output.length; j++) { - for (int i = 0; i < output[0].length; i++) { - output[j][i] = input[j][i+1]; - } - } - } - return output; - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadTool.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadTool.java deleted file mode 100644 index 0c8bb37687..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadTool.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * Otavio Ferranti - Eldorado Research Institute - Bug 255255 [tml][proctools] Add extension points - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.cpuload; - -import java.io.IOException; -import java.util.List; - -import org.eclipse.sequoyah.device.linuxtools.network.IConnectionProvider; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.OperationCode; -import org.eclipse.sequoyah.device.linuxtools.tools.AbstractNotifier; -import org.eclipse.sequoyah.device.linuxtools.tools.IListener; -import org.eclipse.sequoyah.device.linuxtools.tools.INotifier; -import org.eclipse.sequoyah.device.linuxtools.tools.ITool; -import org.eclipse.sequoyah.device.linuxtools.utilities.Extensions; -import org.eclipse.sequoyah.device.linuxtools.utilities.ProtocolDescriptor; - -/** - * @author Otavio Ferranti - */ -public class CpuLoadTool extends AbstractNotifier implements IListener, ITool { - - public enum ToolStateEnum {RUNNING, STOPPED, STOP_SCHEDULED}; - - private IConnectionProvider connectionProvider = null; - private CpuLoadProcessor processor = null; - private int delay = 1000; - - private ToolStateEnum toolState = ToolStateEnum.STOPPED; - - private String[] requiredCapabilities = {"GET_FILE"}; //$NON-NLS-1$ - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.ITool#createConnection(java.lang.String, int, java.lang.String) - */ - public void connect (String host, - int port, - ProtocolDescriptor protocol) { - - Class connectionProviderClass = - protocol.getConnectionProviderClass(); - - try { - Object aux = connectionProviderClass.newInstance(); - connectionProvider = (IConnectionProvider) aux; - } catch (InstantiationException ie) { - } catch (IllegalAccessException iae) { - } catch (ClassCastException cce) { - } - - connectionProvider.addListener(this); - try { - connectionProvider.connect(host, port); - } catch (IOException ie) { } - processor = new CpuLoadProcessor(connectionProvider); - - processor.addListener(this); - toolState = ToolStateEnum.STOPPED; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.ITool#closeConnection() - */ - public void disconnect() { - if (null != connectionProvider) { - try { - connectionProvider.disconnect(); - } catch (IOException ie) { - } - connectionProvider = null; - toolState = ToolStateEnum.STOPPED; - } - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.ITool#login(java.lang.String, java.lang.String) - */ - public void login (String user, String password) { - try { - connectionProvider.login(user, password); - } catch (IOException ie) { - //TODO: Nothing ? - } - } - - public List getProtocolsDescriptors() { - List pdList = Extensions.findProcotols(requiredCapabilities); - return pdList; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.IListener#notify(org.eclipse.sequoyah.device.linuxtools.tools.INotifier, org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode, java.lang.Object) - */ - public void notify(INotifier notifier, EventCode event, Object result) { - try { - if (notifier == connectionProvider) { - switch (event) { - case EVT_PROVIDER_CONNECT_FINISHED: - if (OperationCode.SUCCESS == result) { - start(); - } - this.notifyListeners( - EventCode.EVT_TOOL_CONNECT_FINISHED, - result); - break; - case EVT_PROVIDER_CONNECT_ERROR: - - break; - case EVT_PROVIDER_LOGIN_FINISHED: - if (OperationCode.SUCCESS == result) { - start(); - } - this.notifyListeners( - EventCode.EVT_TOOL_LOGIN_FINISHED, - result); - break; - case EVT_PROVIDER_SENDCOMMAND_FINISHED: - break; - case EVT_PROVIDER_SENDCOMMAND_ERROR: - break; - case EVT_PROVIDER_SENDDATA_FINISHED: - break; - case EVT_PROVIDER_SENDDATA_ERROR: - break; - case EVT_PROVIDER_DISCONNECT_FINISHED: - this.notifyListeners( - EventCode.EVT_TOOL_DISCONNECT_FINISHED, - result); - break; - } - } - if (notifier == processor) { - switch (event) { - case EVT_PROCESSOR_GATHERDATA_FINISHED: - if (ToolStateEnum.RUNNING == toolState) { - try { - notifyListeners(EventCode.EVT_TOOL_REFRESH_VIEW, - result); - Thread.sleep(delay); - processor.gatherData(); - } catch (InterruptedException ie) { - } - } else if (ToolStateEnum.STOP_SCHEDULED == toolState) { - toolState = ToolStateEnum.STOPPED; - } - break; - case EVT_PROCESSOR_GATHERDATA_ERROR: - break; - } - } - } catch (IOException ie) { - } - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.ITool#getRefreshDelay() - */ - public int getRefreshDelay() { - return this.delay; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.ITool#setRefreshDelay(int) - */ - public void setRefreshDelay(int delay) { - this.delay = delay; - } - - /** - * - */ - public void start() { - try { - if (null != processor) { - if (ToolStateEnum.STOPPED == toolState) { - toolState = ToolStateEnum.RUNNING; - processor.gatherData(); - } else if (ToolStateEnum.STOP_SCHEDULED == toolState) { - toolState = ToolStateEnum.RUNNING; - } - } - } catch (IOException ie) { - //TODO: Nothing ? - } - } - - /** - * - */ - public void stop () { - toolState = ToolStateEnum.STOP_SCHEDULED; - } - - public void refresh() { - // TODO Auto-generated method stub - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadView.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadView.java deleted file mode 100644 index 9942c6da40..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadView.java +++ /dev/null @@ -1,332 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.cpuload; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.sequoyah.device.linuxtools.LinuxToolsPlugin; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.OperationCode; -import org.eclipse.sequoyah.device.linuxtools.tools.IListener; -import org.eclipse.sequoyah.device.linuxtools.tools.INotifier; -import org.eclipse.sequoyah.device.linuxtools.tools.ITool; -import org.eclipse.sequoyah.device.linuxtools.ui.DialogLogin; -import org.eclipse.sequoyah.device.linuxtools.ui.IToolViewPart; -import org.eclipse.sequoyah.device.linuxtools.ui.ViewActionConnect; -import org.eclipse.sequoyah.device.linuxtools.ui.ViewActionDisconnect; -import org.eclipse.sequoyah.device.linuxtools.ui.ViewActionPause; -import org.eclipse.sequoyah.device.linuxtools.ui.ViewActionRun; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IPartListener; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.part.ViewPart; - -/** - * @author Otavio Ferranti - */ -public class CpuLoadView extends ViewPart implements IToolViewPart, IListener { - - private class CpuSorter extends ViewerSorter { - - public int compare(Viewer viewer, Object e1, Object e2) { - int result = 0; - try { - int a = new Integer(((String[]) e1)[0]).intValue(); - int b = new Integer(((String[]) e2)[0]).intValue(); - if (a > b) { - result = 1; - } else if (a < b) { - result = -1; - }; - } - catch (NumberFormatException nfe) { - //TODO: Nothing ? - } - return result; - } - } - final private String COL_LABEL_CPU = Messages.CpuLoadView_Col_Label_Cpu; - final private String COL_LABEL_USER_MODE = Messages.CpuLoadView_Col_Label_User_Mode; - final private String COL_LABEL_NICE = Messages.CpuLoadView_Col_Label_Nice; - final private String COL_LABEL_SYSTEM = Messages.CpuLoadView_Col_Label_System; - final private String COL_LABEL_IDLE = Messages.CpuLoadView_Col_Label_Idle; - final private String COL_LABEL_WAIT = Messages.CpuLoadView_Col_Label_Wait; - final private String COL_LABEL_HIRQ = Messages.CpuLoadView_Col_label_HIrq; - - final private String COL_LABEL_SIRQ = Messages.CpuLoadView_Col_Label_SIrq; - - private ITool tool = null; - private TableViewer viewer; - - private Action runAction; - private Action pauseAction; - private Action optionsAction; - private Action disconnectAction; - private Action connectAction; - - private boolean receivedData = false; - - private IPartListener partActivationListener = new IPartListener() { - public void partActivated(IWorkbenchPart part) { - } - - public void partBroughtToTop(IWorkbenchPart part) { - } - - public void partClosed(IWorkbenchPart part) { - if (CpuLoadView.this.getSite().getPart() == part) { - ITool tool = CpuLoadView.this.getTool(); - if (null != tool) { - tool.disconnect(); - } - } - } - - public void partDeactivated(IWorkbenchPart part) { - } - - public void partOpened(IWorkbenchPart part) { - } - }; - - /** - * The constructor. - */ - public CpuLoadView() { - } - - /** - * This is a callback that will allow us - * to create the viewer and initialize it. - */ - public void createPartControl(Composite parent) { - - viewer = new TableViewer(parent, SWT.FULL_SELECTION | - SWT.H_SCROLL | SWT.V_SCROLL); - viewer.setContentProvider(new CpuLoadViewContentProvider()); - viewer.setLabelProvider(new CpuLoadViewLabelProvider()); - viewer.setSorter(new CpuSorter()); - - Table table = viewer.getTable(); - table.setHeaderVisible(true); - - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_CPU); - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_USER_MODE); - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_NICE); - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_SYSTEM); - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_IDLE); - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_WAIT); - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_HIRQ); - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_SIRQ); - - refresh(); - resize(); - - makeActions(); - // hookDoubleClickAction(); - addToToolBar(); - - getViewSite() - .getWorkbenchWindow() - .getPartService() - .addPartListener(partActivationListener); - - setConnectEnabled(true); - setRunPauseEnabled(false, false); - } - - private void addToToolBar() { - IActionBars actionBars = getViewSite().getActionBars(); - IToolBarManager toolBarMmanager = actionBars.getToolBarManager(); - toolBarMmanager.add(runAction); - toolBarMmanager.add(pauseAction); - toolBarMmanager.add(optionsAction); - toolBarMmanager.add(disconnectAction); - toolBarMmanager.add(connectAction); - } - - private void makeActions() { - - runAction = new Action() { - public void run() { - IViewActionDelegate delegate = new ViewActionRun(); - delegate.init(CpuLoadView.this); - delegate.run(this); - setRunPauseEnabled(false, true); - } - }; - runAction.setToolTipText(Messages.CpuLoadView_Action_Run); - runAction.setImageDescriptor( - LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_RUN)); - - pauseAction = new Action() { - public void run() { - IViewActionDelegate delegate = new ViewActionPause(); - delegate.init(CpuLoadView.this); - delegate.run(this); - setRunPauseEnabled(true, false); - } - }; - pauseAction.setToolTipText(Messages.CpuLoadView_Action_Pause); - pauseAction.setImageDescriptor( - LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_PAUSE)); - - optionsAction = new Action() { - public void run() { - IViewActionDelegate delegate = new ViewActionOptions(); - delegate.init(CpuLoadView.this); - delegate.run(this); - } - }; - optionsAction.setToolTipText(Messages.CpuLoadView_Action_Options); - optionsAction.setImageDescriptor( - LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_OPTIONS)); - - disconnectAction = new Action() { - public void run() { - IViewActionDelegate delegate = new ViewActionDisconnect(); - delegate.init(CpuLoadView.this); - delegate.run(this); - } - }; - disconnectAction.setToolTipText(Messages.CpuLoadView_Action_Disconnect); - disconnectAction.setImageDescriptor( - LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_DISCONNECT)); - - connectAction = new Action() { - public void run() { - IViewActionDelegate delegate = new ViewActionConnect(); - delegate.init(CpuLoadView.this); - delegate.run(this); - } - }; - connectAction.setToolTipText(Messages.CpuLoadView_Action_Connect); - connectAction.setImageDescriptor( - LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_CONNECT)); - } - - private void setConnectEnabled(boolean bool) { - connectAction.setEnabled(bool); - disconnectAction.setEnabled(!bool); - } - - private void setRunPauseEnabled(boolean runBool, boolean pauseBool) { - runAction.setEnabled(runBool); - pauseAction.setEnabled(pauseBool); - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.ui.IToolView#getTool() - */ - public ITool getTool() { - if(null == tool) { - tool = new CpuLoadTool(); - tool.addListener(this); - } - return tool; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IListener#notify(org.eclipse.sequoyah.device.linuxtools.network.INotifier, org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode, java.lang.Object) - */ - public void notify(INotifier notifier, EventCode event, Object result) { - if (notifier == this.tool) { - final Object finalResult = result; - final EventCode finalEvent = event; - final ViewPart finalView = this; - final ITool finalTool = this.tool; - - this.getViewSite().getShell().getDisplay().asyncExec(new Runnable() { - public void run() { - switch(finalEvent) { - case EVT_TOOL_REFRESH_VIEW: - viewer.setInput(finalResult); - refresh(); - if (!receivedData) { - resize(); - receivedData = true; - } - break; - case EVT_TOOL_CONNECT_FINISHED: - case EVT_TOOL_LOGIN_FINISHED: - switch ((OperationCode)finalResult) { - case SUCCESS: - setConnectEnabled(false); - setRunPauseEnabled(false, true); - break; - case LOGIN_REQUIRED: { - final DialogLogin dialog = new DialogLogin( - finalView.getViewSite().getShell(), - finalTool, false); - dialog.open(); - } - break; - case LOGIN_FAILED: { - final DialogLogin dialog = new DialogLogin( - finalView.getViewSite().getShell(), - finalTool, true); - dialog.open(); - } - break; - } - break; - case EVT_TOOL_DISCONNECT_FINISHED: - setConnectEnabled(true); - setRunPauseEnabled(false, false); - break; - } - } - }); - } - } - - /** - * - */ - public void refresh() { - viewer.refresh(); - } - - /** - * - */ - public void resize() { - Table table = viewer.getTable(); - for (int i = 0, n = table.getColumnCount(); i < n; i++) { - table.getColumn(i).pack(); - } - } - - /** - * @param data - */ - public void setData (Object data) { - viewer.setInput(data); - } - - /** - * Passing the focus request to the viewer's control. - */ - public void setFocus() { - viewer.getControl().setFocus(); - } -} \ No newline at end of file diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadViewContentProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadViewContentProvider.java deleted file mode 100644 index 00a8f37e75..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadViewContentProvider.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.cpuload; - -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/* - * The content provider class is responsible for - * providing objects to the view. It can wrap - * existing objects in adapters or simply return - * objects as-is. These objects may be sensitive - * to the current input of the view, or ignore - * it and always show the same content - * (like Task List, for example). - */ - -/** - * @author Otavio Ferranti - */ -public class CpuLoadViewContentProvider implements IStructuredContentProvider { - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - */ - public void dispose() { - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) - */ - public Object[] getElements(Object parent) { - if (parent instanceof String[][]) { - return (String[][]) parent; - } else { - String[][] aux = new String[1][]; - aux[0] = new String[] {"", "", //$NON-NLS-1$ //$NON-NLS-2$ - "", "", //$NON-NLS-1$ //$NON-NLS-2$ - "", "", //$NON-NLS-1$ //$NON-NLS-2$ - "", ""}; //$NON-NLS-1$ //$NON-NLS-2$ - return aux; - } - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) - */ - public void inputChanged(Viewer v, Object oldInput, Object newInput) { - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadViewLabelProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadViewLabelProvider.java deleted file mode 100644 index 085d569d55..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/CpuLoadViewLabelProvider.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2009 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.cpuload; - -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; - -/** - * @author Otavio Ferranti - */ -public class CpuLoadViewLabelProvider extends LabelProvider implements - ITableLabelProvider { - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) - */ - public Image getColumnImage(Object obj, int index) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) - */ - public String getColumnText(Object obj, int index) { - if (obj instanceof String[]) { - return getText(((Object[]) obj)[index]); - } else { - return new String(""); //$NON-NLS-1$ - } - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) - */ - public Image getImage(Object obj) { - return PlatformUI.getWorkbench(). - getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); - } -} - diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/DialogOptions.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/DialogOptions.java deleted file mode 100644 index 846e7b96f5..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/DialogOptions.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2009 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.cpuload; - -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.sequoyah.device.linuxtools.tools.ITool; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Spinner; - -/** - * @author Otavio Ferranti - */ -public class DialogOptions extends TitleAreaDialog { - - final private String WINDOW_TITLE = Messages.OptionsDialog_Window_Title; - final private String WINDOW_MESSAGE = Messages.OptionsDialog_Window_Message; - final private String LABEL_REFRESH = Messages.OptionsDialog_Label_Refresh_Rate; - final private String LABEL_TIMEUNIT = "ms"; //$NON-NLS-1$ - - private Spinner spinner; - - private ITool tool = null; - - /** - * The constructor. - * @param parent - */ - public DialogOptions(Shell parent, ITool tool) { - super(parent); - this.tool = tool; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.TitleAreaDialog#createDialogArea(org.eclipse.swt.widgets.Composite) - */ - protected Control createDialogArea(Composite parent) { - setTitle(WINDOW_TITLE); - setMessage(WINDOW_MESSAGE); - - Composite dialogArea = new Composite(parent, SWT.NONE); - GridLayout gridLayout = new GridLayout(3, false); - - gridLayout.marginLeft = 7; - gridLayout.marginRight = 7; - - dialogArea.setLayout(gridLayout); - dialogArea.setLayoutData(new GridData(GridData.FILL_BOTH)); - dialogArea.setFont(parent.getFont()); - - Label refreshLabel = new Label(dialogArea, SWT.NULL); - refreshLabel.setText(LABEL_REFRESH); - - spinner = new Spinner(dialogArea, SWT.BORDER); - - Label timeUnit = new Label(dialogArea, SWT.NULL); - timeUnit.setText(LABEL_TIMEUNIT); - - spinner.setMinimum(0); - spinner.setMaximum(50000); - spinner.setSelection(tool.getRefreshDelay()); - spinner.setIncrement(100); - spinner.setPageIncrement(500); - spinner.pack(); - - return dialogArea; - } - - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.TitleAreaDialog#getInitialSize() - */ - protected Point getInitialSize() { - return super.getInitialSize(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.Dialog#okPressed() - */ - protected void okPressed() { - tool.setRefreshDelay(spinner.getSelection()); - super.okPressed(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.dialogs.Dialog#cancelPressed() - */ - protected void cancelPressed() { - super.cancelPressed(); - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/Messages.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/Messages.java deleted file mode 100644 index 736460acb4..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/Messages.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2009 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.cpuload; - -import org.eclipse.osgi.util.NLS; - -/** - * @author Otavio Ferranti - */ -public class Messages extends NLS { - private static final String BUNDLE_NAME = - "org.eclipse.sequoyah.device.linuxtools.tools.cpuload.messages"; //$NON-NLS-1$ - public static String CpuLoadProcessor_Msg_Executing_the_command; - public static String CpuLoadProcessor_Msg_Got_The_Result; - public static String CpuLoadView_Action_Connect; - public static String CpuLoadView_Action_Disconnect; - public static String CpuLoadView_Action_Options; - public static String CpuLoadView_Action_Pause; - public static String CpuLoadView_Action_Run; - public static String CpuLoadView_Col_Label_Cpu; - public static String CpuLoadView_Col_label_HIrq; - public static String CpuLoadView_Col_Label_Idle; - public static String CpuLoadView_Col_Label_Nice; - public static String CpuLoadView_Col_Label_SIrq; - public static String CpuLoadView_Col_Label_System; - public static String CpuLoadView_Col_Label_User_Mode; - public static String CpuLoadView_Col_Label_Wait; - public static String OptionsDialog_Label_Refresh_Rate; - public static String OptionsDialog_Window_Message; - public static String OptionsDialog_Window_Title; - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/ViewActionOptions.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/ViewActionOptions.java deleted file mode 100644 index d50864f861..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/ViewActionOptions.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.cpuload; - -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.sequoyah.device.linuxtools.ui.IToolViewPart; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.PlatformUI; - -/** - * @author Otavio Ferranti - */ -public class ViewActionOptions implements IViewActionDelegate { - - private IViewPart targetPart; - - /** - * The constructor. - */ - public ViewActionOptions() { - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) - */ - public void init(IViewPart view) { - this.targetPart = view; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - final DialogOptions dialog = new DialogOptions( - PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), - ((IToolViewPart) this.targetPart).getTool()); - dialog.open(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) - */ - public void selectionChanged(IAction action, ISelection selection) { - - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/messages.properties b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/messages.properties deleted file mode 100644 index da06c3d3c9..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/cpuload/messages.properties +++ /dev/null @@ -1,38 +0,0 @@ -################################################################################ -# Copyright (c) 2009 Motorola Inc. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Initial Contributors: -# Otavio Ferranti (Motorola) -# -# Contributors: -# {Name} (company) - description of contribution. -################################################################################ - -# NLS_MESSAGEFORMAT_VAR -# NLS_ENCODING=UTF-8 - -CpuLoadView_Col_Label_Cpu=Cpu -CpuLoadView_Col_Label_User_Mode=User -CpuLoadView_Col_Label_Nice=Nice -CpuLoadView_Col_Label_System=System -CpuLoadView_Col_Label_Idle=Idle -CpuLoadView_Col_Label_Wait=Wait -CpuLoadView_Col_label_HIrq=HW Irq -CpuLoadView_Col_Label_SIrq=SW Irq - -CpuLoadView_Action_Run=Run -CpuLoadView_Action_Pause=Pause -CpuLoadView_Action_Options=Options -CpuLoadView_Action_Disconnect=Disconnect -CpuLoadView_Action_Connect=Connect - -CpuLoadProcessor_Msg_Executing_the_command=Executing the command: -CpuLoadProcessor_Msg_Got_The_Result=Got the result: - -OptionsDialog_Window_Title=Options -OptionsDialog_Window_Message=Some options may take effect only after reconnection -OptionsDialog_Label_Refresh_Rate=Refresh delay: diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapProcessor.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapProcessor.java deleted file mode 100644 index 5244f3e06b..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapProcessor.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2009 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.memorymap; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Scanner; -import java.util.regex.MatchResult; - -import org.eclipse.sequoyah.device.common.utilities.logger.ILogger; -import org.eclipse.sequoyah.device.linuxtools.LinuxToolsPlugin; -import org.eclipse.sequoyah.device.linuxtools.network.IConnectionProvider; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.CommandCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode; -import org.eclipse.sequoyah.device.linuxtools.tools.AbstractNotifier; -import org.eclipse.sequoyah.device.linuxtools.tools.IListener; -import org.eclipse.sequoyah.device.linuxtools.tools.INotifier; - -/** - * @author Otavio Ferranti - */ -public class MemoryMapProcessor extends AbstractNotifier implements IListener { - - final private String CMD_FETCH_IOMEM = "/proc/iomem"; //$NON-NLS-1$ - final private String PARSE_PATTERN = "\\s*(\\w{8})-(\\w{8})\\s*:\\s*(.*)"; //$NON-NLS-1$ - - final private String MSG_EXECUTING_COMMAND = - Messages.MemoryMapProcessor_Msg_Executing_The_Command; - - final private String MSG_GOT_RESULT = - Messages.MemoryMapProcessor_Msg_Got_The_Result; - - final private int MAX_COLUMNS = 4; - private IConnectionProvider connectionProvider = null; - - private ILogger logger = null; - - /** - * The constructor; - * @param connectionProvider - */ - public MemoryMapProcessor(IConnectionProvider connectionProvider) { - setConnectionProvider(connectionProvider); - logger = LinuxToolsPlugin.getLogger(); - } - - /** - * @throws IOException - */ - public void gatherData() throws IOException { - connectionProvider.setResponseLength(8192); - connectionProvider.sendCommand(CommandCode.FETCH_FILE, this.CMD_FETCH_IOMEM); - logger.debug(MSG_EXECUTING_COMMAND + "\n" + this.CMD_FETCH_IOMEM); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IListener#notify(org.eclipse.sequoyah.device.linuxtools.network.INotifier, org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode, java.lang.Object) - */ - public void notify(INotifier notifier, - EventCode event, - Object result) { - if (notifier == this.connectionProvider && - event == EventCode.EVT_PROVIDER_SENDCOMMAND_FINISHED) { - this.connectionProvider.setResponseLength(1024); - Object[][] parsedResult = parseIomem((StringBuffer) result); - this.notifyListeners(EventCode.EVT_PROCESSOR_GATHERDATA_FINISHED, - parsedResult); - } - } - - /** - * @param connectionProvider - */ - public void setConnectionProvider (IConnectionProvider connectionProvider) { - if (null != this.connectionProvider) { - this.connectionProvider.removeListener(this); - } - this.connectionProvider = connectionProvider; - if (null != this.connectionProvider) { - this.connectionProvider.addListener(this); - } - } - - /** - * @param data - * @return - */ - private Object[][] parseIomem(StringBuffer data) { - logger.debug(MSG_GOT_RESULT + "\n" + data.toString()); - - Scanner s1 = new Scanner(data.toString()); - - ArrayList list = new ArrayList(); - - int j = 0; - - while (s1.hasNextLine()) { - Scanner s2 = new Scanner(s1.nextLine()); - s2.findInLine(PARSE_PATTERN); - - String[] entry = null; - try { - MatchResult result = s2.match(); - entry = new String[MAX_COLUMNS]; - for (int i = 1; i <= result.groupCount() && i <= MAX_COLUMNS - 1; i++) { - entry[i-1] = result.group(i); - } - entry[MAX_COLUMNS - 1] = new Integer(j).toString(); - j++; - } catch (IllegalStateException ise) { - //TODO: Nothing ? - } - - s2.close(); - if (null != entry) { - list.add(entry); - } - } - s1.close(); - - String[][] retVal = new String[list.size()][MAX_COLUMNS]; - for (int i = 0; i < retVal.length; i++) { - retVal[i] = list.get(i); - } - return retVal; - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapTool.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapTool.java deleted file mode 100644 index 23d58e1a58..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapTool.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * Otavio Ferranti - Eldorado Research Institute - Bug 255255 [tml][proctools] Add extension points - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.memorymap; - -import java.io.IOException; -import java.util.List; - -import org.eclipse.sequoyah.device.linuxtools.network.IConnectionProvider; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.OperationCode; -import org.eclipse.sequoyah.device.linuxtools.tools.AbstractNotifier; -import org.eclipse.sequoyah.device.linuxtools.tools.IListener; -import org.eclipse.sequoyah.device.linuxtools.tools.INotifier; -import org.eclipse.sequoyah.device.linuxtools.tools.ITool; -import org.eclipse.sequoyah.device.linuxtools.utilities.Extensions; -import org.eclipse.sequoyah.device.linuxtools.utilities.ProtocolDescriptor; - -/** - * @author Otavio Ferranti - */ -public class MemoryMapTool extends AbstractNotifier implements IListener, ITool { - - private IConnectionProvider connectionProvider = null; - private MemoryMapProcessor processor = null; - - private String[] requiredCapabilities = {"GET_FILE"}; //$NON-NLS-1$ - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.memorymap.iTool#createInstance(java.lang.String, int, java.lang.String) - */ - public void connect (String host, - int port, - ProtocolDescriptor protocol) { - - Class connectionProviderClass = - protocol.getConnectionProviderClass(); - - try { - Object aux = connectionProviderClass.newInstance(); - connectionProvider = (IConnectionProvider) aux; - } catch (InstantiationException ie) { - } catch (IllegalAccessException iae) { - } catch (ClassCastException cce) { - } - - connectionProvider.addListener(this); - try { - connectionProvider.connect(host, port); - } catch (IOException ie) { } - processor = new MemoryMapProcessor(connectionProvider); - - processor.addListener(this); - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.ITool#closeConnection() - */ - public void disconnect() { - if (null != connectionProvider) { - try { - connectionProvider.disconnect(); - } catch (IOException ie) { - } - connectionProvider = null; - } - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.memorymap.iTool#login(java.lang.String, java.lang.String) - */ - public void login (String user, String password) { - try { - connectionProvider.login(user, password); - } catch (IOException ie) { - //TODO: Nothing ? - } - } - - public List getProtocolsDescriptors() { - List pdList = Extensions.findProcotols(requiredCapabilities); - return pdList; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.IListener#notify(org.eclipse.sequoyah.device.linuxtools.tools.INotifier, org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode, java.lang.Object) - */ - public void notify(INotifier notifier, EventCode event, Object result) { - try { - if (notifier == connectionProvider) { - switch (event) { - case EVT_PROVIDER_CONNECT_FINISHED: - if (OperationCode.SUCCESS == result) { - processor.gatherData(); - } - this.notifyListeners( - EventCode.EVT_TOOL_CONNECT_FINISHED, - result); - break; - case EVT_PROVIDER_CONNECT_ERROR: - break; - case EVT_PROVIDER_LOGIN_FINISHED: - if (OperationCode.SUCCESS == result) { - processor.gatherData(); - } - this.notifyListeners( - EventCode.EVT_TOOL_LOGIN_FINISHED, - result); - break; - case EVT_PROVIDER_SENDCOMMAND_FINISHED: - break; - case EVT_PROVIDER_SENDCOMMAND_ERROR: - break; - case EVT_PROVIDER_SENDDATA_FINISHED: - break; - case EVT_PROVIDER_SENDDATA_ERROR: - break; - case EVT_PROVIDER_DISCONNECT_FINISHED: - this.notifyListeners( - EventCode.EVT_TOOL_DISCONNECT_FINISHED, - result); - break; - } - } - if (notifier == processor) { - switch (event) { - case EVT_PROCESSOR_GATHERDATA_FINISHED: - notifyListeners(EventCode.EVT_TOOL_REFRESH_VIEW, - result); - break; - case EVT_PROCESSOR_GATHERDATA_ERROR: - break; - } - } - } catch (IOException ie) { - } - } - - /** - * - */ - public void refresh() { - try { - if (null != processor) { - processor.gatherData(); - } - } catch (IOException ie) { - //TODO: Nothing ? - } - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.ITool#getRefreshDelay() - */ - public int getRefreshDelay() { - // TODO Auto-generated method stub - return 0; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.tools.ITool#setRefreshDelay(int) - */ - public void setRefreshDelay(int delay) { - // TODO Auto-generated method stub - } - - public void start() { - // TODO Auto-generated method stub - } - - public void stop() { - // TODO Auto-generated method stub - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapVViewLabelProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapVViewLabelProvider.java deleted file mode 100644 index 66c0a17496..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapVViewLabelProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.memorymap; - -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.PlatformUI; - -/** - * @author Otavio Ferranti - */ -public class MemoryMapVViewLabelProvider extends LabelProvider implements - ITableLabelProvider { - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) - */ - public Image getColumnImage(Object obj, int index) { - //TODO: Enhance this. - if (index == 2) { - return getImage(((Object[]) obj)[index]); - } else { - return null; - } - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) - */ - public String getColumnText(Object obj, int index) { - if (obj instanceof String[]) { - return getText(((Object[]) obj)[index]); - } else { - return new String(""); //$NON-NLS-1$ - } - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object) - */ - public Image getImage(Object obj) { - return PlatformUI.getWorkbench(). - getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); - } -} - diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapView.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapView.java deleted file mode 100644 index 6d234cef9d..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapView.java +++ /dev/null @@ -1,290 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.memorymap; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.sequoyah.device.linuxtools.LinuxToolsPlugin; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode; -import org.eclipse.sequoyah.device.linuxtools.network.IConstants.OperationCode; -import org.eclipse.sequoyah.device.linuxtools.tools.IListener; -import org.eclipse.sequoyah.device.linuxtools.tools.INotifier; -import org.eclipse.sequoyah.device.linuxtools.tools.ITool; -import org.eclipse.sequoyah.device.linuxtools.ui.DialogLogin; -import org.eclipse.sequoyah.device.linuxtools.ui.IToolViewPart; -import org.eclipse.sequoyah.device.linuxtools.ui.ViewActionConnect; -import org.eclipse.sequoyah.device.linuxtools.ui.ViewActionDisconnect; -import org.eclipse.sequoyah.device.linuxtools.ui.ViewActionRefresh; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IPartListener; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.part.ViewPart; - -/** - * @author Otavio Ferranti - */ -public class MemoryMapView extends ViewPart implements IToolViewPart, IListener { - - private class AddressSorter extends ViewerSorter { - - public int compare(Viewer viewer, Object e1, Object e2) { - int result = 0; - try { - int a = new Integer(((String[]) e1)[MAX_COLUMNS - 1]).intValue(); - int b = new Integer(((String[]) e2)[MAX_COLUMNS - 1]).intValue(); - if (a > b) { - result = 1; - } else if (a < b) { - result = -1; - }; - } - catch (NumberFormatException nfe) { - //TODO: Nothing ? - } - return result; - } - } - final private String COL_LABEL_ADDRESS_START = Messages.MemoryMapView_Col_Label_Address_Start; - final private String COL_LABEL_ADDRESS_END = Messages.MemoryMapView_Col_Label_Address_End; - final private String COL_LABEL_REGION = Messages.MemoryMapView_Col_label_Region; - - final private int MAX_COLUMNS = 4; - - private ITool tool = null; - private TableViewer viewer; - - private Action refreshAction; - private Action disconnectAction; - private Action connectAction; - - private IPartListener partActivationListener = new IPartListener() { - public void partActivated(IWorkbenchPart part) { - } - - public void partBroughtToTop(IWorkbenchPart part) { - } - - public void partClosed(IWorkbenchPart part) { - if (MemoryMapView.this.getSite().getPart() == part) { - ITool tool = MemoryMapView.this.getTool(); - if (null != tool) { - tool.disconnect(); - } - } - } - - public void partDeactivated(IWorkbenchPart part) { - } - - public void partOpened(IWorkbenchPart part) { - } - }; - - /** - * The constructor. - */ - public MemoryMapView() { - } - - /** - * This is a callback that will allow us - * to create the viewer and initialize it. - */ - /* (non-Javadoc) - * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) - */ - public void createPartControl(Composite parent) { - - viewer = new TableViewer(parent, SWT.FULL_SELECTION | - SWT.H_SCROLL | SWT.V_SCROLL); - viewer.setContentProvider(new MemoryMapViewContentProvider()); - viewer.setLabelProvider(new MemoryMapVViewLabelProvider()); - viewer.setSorter(new AddressSorter()); - - Table table = viewer.getTable(); - table.setHeaderVisible(true); - - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_ADDRESS_START); - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_ADDRESS_END); - new TableColumn(table, SWT.LEFT).setText(COL_LABEL_REGION); - - refresh(); - resize(); - - makeActions(); - // hookDoubleClickAction(); - addToToolBar(); - - getViewSite() - .getWorkbenchWindow() - .getPartService() - .addPartListener(partActivationListener); - - setConnectEnabled(true); - refreshAction.setEnabled(false); - } - - private void addToToolBar() { - IActionBars actionBars = getViewSite().getActionBars(); - IToolBarManager toolBarMmanager = actionBars.getToolBarManager(); - toolBarMmanager.add(refreshAction); - toolBarMmanager.add(disconnectAction); - toolBarMmanager.add(connectAction); - } - - private void makeActions() { - - refreshAction = new Action() { - public void run() { - IViewActionDelegate delegate = new ViewActionRefresh(); - delegate.init(MemoryMapView.this); - delegate.run(this); - this.setEnabled(false); - } - }; - refreshAction.setToolTipText(Messages.MemoryMapView_Action_Refresh); - refreshAction.setImageDescriptor( - LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_REFRESH)); - - disconnectAction = new Action() { - public void run() { - IViewActionDelegate delegate = new ViewActionDisconnect(); - delegate.init(MemoryMapView.this); - delegate.run(this); - } - }; - disconnectAction.setToolTipText(Messages.MemoryMapView_Action_Disconnect); - disconnectAction.setImageDescriptor( - LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_DISCONNECT)); - - connectAction = new Action() { - public void run() { - IViewActionDelegate delegate = new ViewActionConnect(); - delegate.init(MemoryMapView.this); - delegate.run(this); - } - }; - connectAction.setToolTipText(Messages.MemoryMapView_Action_Connect); - connectAction.setImageDescriptor( - LinuxToolsPlugin.getDefault().getImageDescriptor(LinuxToolsPlugin.ICON_CONNECT)); - - } - - private void setConnectEnabled(boolean bool) { - connectAction.setEnabled(bool); - disconnectAction.setEnabled(!bool); - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.ui.IToolView#getTool() - */ - public ITool getTool() { - if(null == tool) { - tool = new MemoryMapTool(); - tool.addListener(this); - } - return tool; - } - - /* (non-Javadoc) - * @see org.eclipse.sequoyah.device.linuxtools.network.IListener#notify(org.eclipse.sequoyah.device.linuxtools.network.INotifier, org.eclipse.sequoyah.device.linuxtools.network.IConstants.EventCode, java.lang.Object) - */ - public void notify(INotifier notifier, EventCode event, Object result) { - if (notifier == tool) { - final Object finalResult = result; - final EventCode finalEvent = event; - final ViewPart finalView = this; - final ITool finalTool = this.tool; - - this.getViewSite().getShell().getDisplay().asyncExec(new Runnable() { - public void run() { - switch(finalEvent) { - case EVT_TOOL_REFRESH_VIEW: - viewer.setInput(finalResult); - refreshAction.setEnabled(true); - refresh(); - resize(); - break; - case EVT_TOOL_CONNECT_FINISHED: - case EVT_TOOL_LOGIN_FINISHED: - switch ((OperationCode)finalResult) { - case SUCCESS: - setConnectEnabled(false); - refreshAction.setEnabled(true); - break; - case LOGIN_REQUIRED: { - final DialogLogin dialog = new DialogLogin( - finalView.getViewSite().getShell(), - finalTool, false); - dialog.open(); - } - break; - case LOGIN_FAILED: { - final DialogLogin dialog = new DialogLogin( - finalView.getViewSite().getShell(), - finalTool, true); - dialog.open(); - } - break; - } - break; - case EVT_TOOL_DISCONNECT_FINISHED: - setConnectEnabled(true); - refreshAction.setEnabled(false); - break; - } - } - }); - } - } - - /** - * - */ - public void refresh() { - viewer.refresh(); - } - - /** - * - */ - public void resize() { - Table table = viewer.getTable(); - for (int i = 0, n = table.getColumnCount(); i < n; i++) { - table.getColumn(i).pack(); - } - } - - /** - * @param data - */ - public void setData (Object data) { - viewer.setInput(data); - } - - /** - * Passing the focus request to the viewer's control. - */ - public void setFocus() { - viewer.getControl().setFocus(); - } -} \ No newline at end of file diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapViewContentProvider.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapViewContentProvider.java deleted file mode 100644 index 3e396fc40d..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/MemoryMapViewContentProvider.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.memorymap; - -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.Viewer; - -/* - * The content provider class is responsible for - * providing objects to the view. It can wrap - * existing objects in adapters or simply return - * objects as-is. These objects may be sensitive - * to the current input of the view, or ignore - * it and always show the same content - * (like Task List, for example). - */ - -/** - * @author Otavio Ferranti - */ -public class MemoryMapViewContentProvider implements IStructuredContentProvider { - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) - */ - public void inputChanged(Viewer v, Object oldInput, Object newInput) { - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IContentProvider#dispose() - */ - public void dispose() { - } - - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) - */ - public Object[] getElements(Object parent) { - if (parent instanceof String[][]) { - return (String[][]) parent; - } else { - String[][] aux = new String[1][]; - aux[0] = new String[] {"", //$NON-NLS-1$ - "", //$NON-NLS-1$ - ""}; //$NON-NLS-1$ - return aux; - } - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/Messages.java b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/Messages.java deleted file mode 100644 index c7155dd838..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/Messages.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2008 Motorola Inc. All rights reserved. - * This program and the accompanying materials are made available under the terms - * of the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Initial Contributor: - * Otavio Ferranti (Motorola) - * - * Contributors: - * {Name} (company) - description of contribution. - ********************************************************************************/ - -package org.eclipse.sequoyah.device.linuxtools.tools.memorymap; - -import org.eclipse.osgi.util.NLS; - -/** - * @author Otavio Ferranti - */ -public class Messages extends NLS { - private static final String BUNDLE_NAME = - "org.eclipse.sequoyah.device.linuxtools.tools.memorymap.messages"; //$NON-NLS-1$ - - public static String MemoryMapProcessor_Msg_Executing_The_Command; - public static String MemoryMapProcessor_Msg_Got_The_Result; - public static String MemoryMapView_Action_Refresh; - public static String MemoryMapView_Action_Disconnect; - public static String MemoryMapView_Action_Connect; - public static String MemoryMapView_Col_Label_Address_End; - public static String MemoryMapView_Col_Label_Address_Start; - public static String MemoryMapView_Col_label_Region; - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - private Messages() { - } -} diff --git a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/messages.properties b/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/messages.properties deleted file mode 100644 index b242a0463e..0000000000 --- a/proctools/org.eclipse.sequoyah.device.linuxtools/src/org/eclipse/sequoyah/device/linuxtools/tools/memorymap/messages.properties +++ /dev/null @@ -1,27 +0,0 @@ -################################################################################ -# Copyright (c) 2009 Motorola Inc. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Initial Contributors: -# Otavio Ferranti (Motorola) -# -# Contributors: -# {Name} (company) - description of contribution. -################################################################################ - -# NLS_MESSAGEFORMAT_VAR -# NLS_ENCODING=UTF-8 - -MemoryMapView_Col_Label_Address_Start=Start -MemoryMapView_Col_Label_Address_End=End -MemoryMapView_Col_label_Region=Region name - -MemoryMapView_Action_Refresh=Refresh -MemoryMapView_Action_Disconnect=Disconnect -MemoryMapView_Action_Connect=Connect - -MemoryMapProcessor_Msg_Executing_The_Command=Executing the command: -MemoryMapProcessor_Msg_Got_The_Result=Got the result: -- cgit v1.2.3