ioio.lib.util.android
Class IOIOService

java.lang.Object
  extended by Service
      extended by ioio.lib.util.android.IOIOService
All Implemented Interfaces:
IOIOLooperProvider

public abstract class IOIOService
extends Service
implements IOIOLooperProvider

A convenience class for easy creation of IOIO-based services. It is used by creating a concrete Service in your application, which extends this class. This class then takes care of proper creation and abortion of the IOIO connection and of a dedicated thread for IOIO communication.

In the basic usage the client should extend this class and implement createIOIOLooper(), which should return an implementation of the IOIOLooper interface. In this implementation, the client implements the IOIOLooper.setup(ioio.lib.api.IOIO) method, which gets called as soon as communication with the IOIO is established, and the IOIOLooper.loop() method, which gets called repetitively as long as the IOIO is connected.

In addition, the IOIOLooper.disconnected() method may be overridden in order to execute logic as soon as a disconnection occurs for whichever reason. The IOIOLooper.incompatible() method may be overridden in order to take action in case where a IOIO whose firmware is incompatible with the IOIOLib version that application is built with.

In a more advanced use case, more than one IOIO is available. In this case, a thread will be created for each IOIO, whose semantics are as defined above. If the client needs to be able to distinguish between them, it is possible to override createIOIOLooper(String, Object) instead of createIOIOLooper(). The first argument provided will contain the connection class name, such as ioio.lib.impl.SocketIOIOConnection for a connection established over a TCP socket (which is used over ADB). The second argument will contain information specific to the connection type. For example, in the case of SocketIOIOConnection, the second argument will contain an Integer representing the local port number.


Constructor Summary
IOIOService()
           
 
Method Summary
 IOIOLooper createIOIOLooper(java.lang.String connectionType, java.lang.Object extra)
          Subclasses should implement this method by returning an implementation of IOIOLooper.
 void onCreate()
          Subclasses should call this method from their own onCreate() if overloaded.
 void onDestroy()
          Subclasses should call this method from their own onDestroy() if overloaded.
 void onStart(Intent intent, int startId)
          Subclasses should call this method from their own onStart() if overloaded.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IOIOService

public IOIOService()
Method Detail

onCreate

public void onCreate()
Subclasses should call this method from their own onCreate() if overloaded. It takes care of connecting with the IOIO.


onDestroy

public void onDestroy()
Subclasses should call this method from their own onDestroy() if overloaded. It takes care of connecting with the IOIO.


onStart

public void onStart(Intent intent,
                    int startId)
Subclasses should call this method from their own onStart() if overloaded. It takes care of connecting with the IOIO.


createIOIOLooper

public IOIOLooper createIOIOLooper(java.lang.String connectionType,
                                   java.lang.Object extra)
Description copied from interface: IOIOLooperProvider
Subclasses should implement this method by returning an implementation of IOIOLooper. The caller provide enough information to uniquely identify the connection, through the parameters. null may be returned if the client is not interested to create a thread for this IOIO. This can be used in order to filter out unwanted connections, for example if the application is only intended for wireless connection, any wired connection attempts may be rejected, thus saving resources used for listening for incoming wired connections.

Specified by:
createIOIOLooper in interface IOIOLooperProvider
Parameters:
connectionType - A unique name of the connection type. Typically, the fully-qualified name of the connection class used to connect to the IOIO.
extra - A connection-type-specific object with extra information on the specific connection. Should provide information that enables distinguishing between different IOIO instances using the same connection class. For example, a Bluetooth connection type, might have the remote IOIO's Bluetooth name as extra.
Returns:
An implementation of IOIOLooper, or null to skip.