| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012 Ericsson |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | * |
| 9 | * Contributors: |
| 10 | * Bernd Hufmann - Initial API and implementation |
| 11 | **********************************************************************/ |
| 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote; |
| 13 | |
| 14 | import java.util.Arrays; |
| 15 | |
| 16 | /** |
| 17 | * <p> |
| 18 | * Class containing command result of remote command execution. |
| 19 | * </p> |
| 20 | * |
| 21 | * @author Bernd Hufmann |
| 22 | */ |
| 23 | public class CommandResult implements ICommandResult { |
| 24 | |
| 25 | // ------------------------------------------------------------------------ |
| 26 | // Attributes |
| 27 | // ------------------------------------------------------------------------ |
| 28 | /** |
| 29 | * The result of the command. 0 if successful else > 0 |
| 30 | */ |
| 31 | private int fResult; |
| 32 | |
| 33 | /** |
| 34 | * The output as String array. |
| 35 | */ |
| 36 | private String[] fOutput = new String[0]; |
| 37 | |
| 38 | // ------------------------------------------------------------------------ |
| 39 | // Constructor |
| 40 | // ------------------------------------------------------------------------ |
| 41 | public CommandResult(int result, String[] output) { |
| 42 | fResult = result; |
| 43 | if (output != null) { |
| 44 | fOutput = Arrays.copyOf(output, output.length); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // ------------------------------------------------------------------------ |
| 49 | // Accessor |
| 50 | // ------------------------------------------------------------------------ |
| 51 | /* |
| 52 | * (non-Javadoc) |
| 53 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ICommandResult#getResult() |
| 54 | */ |
| 55 | @Override |
| 56 | public int getResult() { |
| 57 | return fResult; |
| 58 | } |
| 59 | |
| 60 | /* |
| 61 | * (non-Javadoc) |
| 62 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ICommandResult#setResult(int) |
| 63 | */ |
| 64 | @Override |
| 65 | public void setResult(int result) { |
| 66 | fResult = result; |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * (non-Javadoc) |
| 71 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ICommandResult#getOutput() |
| 72 | */ |
| 73 | @Override |
| 74 | public String[] getOutput() { |
| 75 | return Arrays.copyOf(fOutput, fOutput.length); |
| 76 | } |
| 77 | |
| 78 | /* |
| 79 | * (non-Javadoc) |
| 80 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ICommandResult#setOutput(java.lang.String[]) |
| 81 | */ |
| 82 | @Override |
| 83 | public void setOutput(String[] output) { |
| 84 | fOutput = new String[0]; |
| 85 | if (output != null) { |
| 86 | fOutput = Arrays.copyOf(output, output.length); |
| 87 | } |
| 88 | } |
| 89 | } |