SunSPOT host API V3.0


com.sun.spot.client
Class SpotClientCommands

java.lang.Object
  extended by com.sun.spot.client.SpotClientCommands

public class SpotClientCommands
extends Object

SpotClientCommands

An instance of this holds all the commands available in a SpotClient including user extensions. An instance must be created during the startup of a host application that wishes to use the SpotClient infrastructure, by doing something like:

IUI ui = new DummyUI();
// Use this constructor for locally connected SPOTs, or the other public one for remote SPOTs SpotClientCommands commandRepository = new SpotClientCommands(ui, appPath, libFile, sysBinPath, keyStorePath, port);

Then the instance can be used to execute commands, for example:

commandRepository.getCommand("flashapp").execute(null);

The required signature to the execute(...) method depends on the particular command class
(see ISpotClientCommand.getSignature()).

See the SPOT Developer's Guide for more details.


Field Summary
static int MODE_LOCAL
          value returned from getMode() when there is a locally connected SPOT
static int MODE_REMOTE_NON_SPECIFIC
          value returned from getMode() when there is no specific SPOT
static int MODE_REMOTE_SPECIFIC
          value returned from getMode() when there is a remotely connected SPOT
 
Constructor Summary
SpotClientCommands(IUI ui, String appFilePath, String libFile, File sysBinPath, String keyStorePath, String port)
          Create an instance to deal with a locally connected SPOT.
SpotClientCommands(IUI ui, String appFilePath, String libFile, File sysBinPath, String keyStorePath, String port, String remoteAddr, int remoteChannel, short remotePanId, int echoPort)
          Create an instance to deal with a remote SPOT or SPOTs.
 
Method Summary
 void addCommand(ISpotClientCommand command)
          Add or replace a command in the active command set (replaces if the new command has the same name as an existing one).
 boolean containsCommand(String commandName)
          Answer whether a command exists with the given name.
 Object execute(String commandName)
          Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_NOTHING.
 Object execute(String commandName, boolean arg0)
          Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_BOOLEAN.
 Object execute(String commandName, int arg0)
          Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_INT.
 Object execute(String commandName, long arg0)
          Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_LONG.
 Object execute(String commandName, String arg0)
          Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_STRING or ISpotClientCommand.SIGNATURE_OPTIONAL_STRING.
 Object execute(String commandName, String arg0, String arg1)
          Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_TWO_STRINGS or ISpotClientCommand.SIGNATURE_OPTIONAL_SECOND_STRING.
 Object execute(String commandName, String arg0, String arg1, String arg2)
          Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_THREE_STRINGS.
 ISpotClientCommand getCommand(String commandName)
          Answer an existing command if there is one with the given name.
 Set getCommandNames()
           
 int getMode()
          Answer the mode in which the SpotClient is operating.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_LOCAL

public static final int MODE_LOCAL
value returned from getMode() when there is a locally connected SPOT

See Also:
Constant Field Values

MODE_REMOTE_SPECIFIC

public static final int MODE_REMOTE_SPECIFIC
value returned from getMode() when there is a remotely connected SPOT

See Also:
Constant Field Values

MODE_REMOTE_NON_SPECIFIC

public static final int MODE_REMOTE_NON_SPECIFIC
value returned from getMode() when there is no specific SPOT

See Also:
Constant Field Values
Constructor Detail

SpotClientCommands

public SpotClientCommands(IUI ui,
                          String appFilePath,
                          String libFile,
                          File sysBinPath,
                          String keyStorePath,
                          String port)
                   throws FileNotFoundException,
                          IOException
Create an instance to deal with a locally connected SPOT.

The command "quit" should be executed when the instance is no longer required, to free resources. Note that the "startapp" command will implicitly call "quit" if the "fork" option is specified.

Parameters:
ui - the active IUI
appFilePath - the application path specified on the SpotClient command line. Normally this is the relative path from the launch folder of the SpotClient to the suite file of the application, minus the ".suite" extension. If the path is not specified on the command line, it will be the relative path to the launch folder (i.e. ".").
libFile - the fully qualified path to the SDK's current library suite.
sysBinPath - the fully qualified path to the folder containing arm-specific files (typically /arm)
keyStorePath - the path to the folder containing security keys
port - the name of the port to which the local SPOT to be communicated with is attached
Throws:
FileNotFoundException
IOException

SpotClientCommands

public SpotClientCommands(IUI ui,
                          String appFilePath,
                          String libFile,
                          File sysBinPath,
                          String keyStorePath,
                          String port,
                          String remoteAddr,
                          int remoteChannel,
                          short remotePanId,
                          int echoPort)
                   throws FileNotFoundException,
                          IOException
Create an instance to deal with a remote SPOT or SPOTs.

If remoteAddr is specified, this instance will be able to handle any command that is valid for a specific remote SPOT. If remoteAddr is null, this instance will only be able to handle commands that do not access SPOTs via the SPOT Client target-access code (at the time of writing the only such command is "hello").

In all cases the command "quit" should be executed when the instance is no longer required, to free resources. Note that the "startapp" command will implicitly call "quit" if the "fork" option is specified.

Parameters:
ui - the active IUI
appFilePath - the application path specified on the SpotClient command line. Normally this is the relative path from the launch folder of the SpotClient to the suite file of the application, minus the ".suite" extension. If the path is not specified on the command line, it will be the relative path to the launch folder (i.e. ".").
libFile - the fully qualified path to the SDK's current library suite.
sysBinPath - the fully qualified path to the folder containing arm-specific files (typically /arm)
keyStorePath - the path to the folder containing security keys
port - the name of the port to which the basestation is connected, or null if already set in system property SERIAL_PORT
remoteAddr - the IEEE address of the remote SPOT, or null if no commands that access a specific target will be called
remoteChannel - the radio channel to communicate with the remote SPOT
remotePanId - the PAN id to communicate with the remote SPOT
echoPort - the radiostream port on which to receive remote printing output
Throws:
FileNotFoundException
IOException
Method Detail

getMode

public int getMode()
Answer the mode in which the SpotClient is operating. Should be one of MODE_LOCAL, MODE_REMOTE_NON_SPECIFIC and MODE_REMOTE_SPECIFIC

Returns:
the current mode

addCommand

public void addCommand(ISpotClientCommand command)
Add or replace a command in the active command set (replaces if the new command has the same name as an existing one).

Parameters:
command - to add to the available set

getCommand

public ISpotClientCommand getCommand(String commandName)
                              throws SpotClientArgumentException
Answer an existing command if there is one with the given name.

Parameters:
commandName - the name of the command to answer
Returns:
the command with the given name
Throws:
SpotClientArgumentException - if there is no command with the given name

containsCommand

public boolean containsCommand(String commandName)
Answer whether a command exists with the given name.

Parameters:
commandName - the command name to search for.
Returns:
true if the command exists, otherwise false.

getCommandNames

public Set getCommandNames()
Returns:
the set of the names (Strings) of the available commands

execute

public Object execute(String commandName)
               throws SpotClientException,
                      IOException
Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_NOTHING. If this is the wrong signature for this command, throw an IllegalStateException. If no command is registered for the given name throws SpotClientArgumentException.

Parameters:
commandName - the command to execute
Returns:
the command result (type and meaning varies according the command)
Throws:
SpotClientException
IOException

execute

public Object execute(String commandName,
                      int arg0)
               throws SpotClientException,
                      IOException
Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_INT. If this is the wrong signature for this command, throw an IllegalStateException. If no command is registered for the given name throws SpotClientArgumentException.

Parameters:
commandName - the command to execute
Returns:
the command result (type and meaning varies according the command)
Throws:
SpotClientException
IOException

execute

public Object execute(String commandName,
                      long arg0)
               throws SpotClientException,
                      IOException
Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_LONG. If this is the wrong signature for this command, throw an IllegalStateException. If no command is registered for the given name throws SpotClientArgumentException.

Parameters:
commandName - the command to execute
Returns:
the command result (type and meaning varies according the command)
Throws:
SpotClientException
IOException

execute

public Object execute(String commandName,
                      boolean arg0)
               throws SpotClientException,
                      IOException
Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_BOOLEAN. If this is the wrong signature for this command, throw an IllegalStateException. If no command is registered for the given name throws SpotClientArgumentException.

Parameters:
commandName - the command to execute
Returns:
the command result (type and meaning varies according the command)
Throws:
SpotClientException
IOException

execute

public Object execute(String commandName,
                      String arg0)
               throws SpotClientException,
                      IOException
Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_STRING or ISpotClientCommand.SIGNATURE_OPTIONAL_STRING. If this is the wrong signature for this command, throw an IllegalStateException. If no command is registered for the given name throws SpotClientArgumentException.

Parameters:
commandName - the command to execute
Returns:
the command result (type and meaning varies according the command)
Throws:
SpotClientException
IOException

execute

public Object execute(String commandName,
                      String arg0,
                      String arg1)
               throws SpotClientException,
                      IOException
Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_TWO_STRINGS or ISpotClientCommand.SIGNATURE_OPTIONAL_SECOND_STRING. If this is the wrong signature for this command, throw an IllegalStateException. If no command is registered for the given name throws SpotClientArgumentException.

Parameters:
commandName - the command to execute
Returns:
the command result (type and meaning varies according the command)
Throws:
SpotClientException
IOException

execute

public Object execute(String commandName,
                      String arg0,
                      String arg1,
                      String arg2)
               throws SpotClientException,
                      IOException
Execute the ISpotClientCommand registered with the given name, assuming that the ISpotClientCommand implements ISpotClientCommand.SIGNATURE_THREE_STRINGS. If this is the wrong signature for this command, throw an IllegalStateException. If no command is registered for the given name throws SpotClientArgumentException.

Parameters:
commandName - the command to execute
Returns:
the command result (type and meaning varies according the command)
Throws:
SpotClientException
IOException

SunSPOT host API V3.0


Copyright © 2006, 2007 Sun Microsystems, Inc. All Rights Reserved.