org.whispercomm.manes.client.maclib
Class ManesInterface

java.lang.Object
  extended by org.whispercomm.manes.client.maclib.ManesInterface

public class ManesInterface
extends Object

This class represents an interface for sending and receiving one-hop broadcast packets via the MANES ad hoc network emulation system.

ManesInterface depends on ManesService, which must be installed.

Author:
Yue Liu
See Also:
ManesService

Field Summary
static int MANES_MTU
          The maximum allowable size in bytes of an outgoing packet.
 
Constructor Summary
ManesInterface(int appId, Context callerContext)
          Constructs a new ManesInterface object to send and receive packets with the specified application id.
 
Method Summary
 byte[] receive(long timeout)
          Retrieves an incoming packet, blocking until one is available, up to the specified timeout.
 void send(byte[] sendBuff)
          Broadcasts the given packet to this device's one-hop neighborhood.
 void unregister()
          Closes the interface, unbinding from ManesService.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MANES_MTU

public static final int MANES_MTU
The maximum allowable size in bytes of an outgoing packet.

See Also:
Constant Field Values
Constructor Detail

ManesInterface

public ManesInterface(int appId,
                      Context callerContext)
               throws RemoteException
Constructs a new ManesInterface object to send and receive packets with the specified application id.

The application id is used to filter incoming packets to the appropriate application and thus must consistent across all instances of the application and globally unique to the application. To ensure uniqueness, it should be registered in the MANES application id registry. Application ids 253, 254, and 255 are available for testing and experimentation.

The constructor binds the specified context to the ManesService background service. When finished, the ManesInterface instance must be unbound from the service by calling unregister.

Parameters:
appId - the registered identifier for this application.
callerContext - the context used to bind to ManesService.
Throws:
RemoteException
ManesIllegalAppIdException - if an illegal (i.e., negative) application id is supplied.
Method Detail

send

public void send(byte[] sendBuff)
          throws ManesFrameTooLargeException,
                 IOException
Broadcasts the given packet to this device's one-hop neighborhood.

The packet size must not exceed MANES_MTU.

Parameters:
sendBuff - the packet to be sent.
Throws:
ManesFrameTooLargeException - if the packet size exceeds MANES_MTU.
IOException - if the send fails on the local device. This exception is not guaranteed to be thrown.

receive

public byte[] receive(long timeout)
               throws IOException
Retrieves an incoming packet, blocking until one is available, up to the specified timeout.

Parameters:
timeout - the maximum time in milliseconds to block waiting for an incoming packet.
Returns:
the received packet; null if the timeout occurs.
Throws:
IOExeception - if a local error prevents listening for incoming packets. This exception is not guaranteed to be thrown.
IOException

unregister

public void unregister()
Closes the interface, unbinding from ManesService.

The method must be called when an application is finished with the interface, e.g., before exiting.