org.teleal.cling.android
Class AndroidWifiSwitchingRouter

java.lang.Object
  extended by android.content.BroadcastReceiver
      extended by org.teleal.cling.android.AndroidWifiSwitchingRouter
All Implemented Interfaces:
Router

public class AndroidWifiSwitchingRouter
extends android.content.BroadcastReceiver
implements Router

Wrapping a regular RouterImpl, making it on/off switchable.

This implementation listens to connectivity changes in an Android environment (register for intent "android.net.conn.CONNECTIVITY_CHANGE"). It then enables/disables UPnP network transport whenever the WiFi network interface is turned on/off.

While WiFi is switched off, only mock responses (mostly null) will be returned from this network transport layer, and all operations are NOOPs.

Author:
Christian Bauer

Constructor Summary
AndroidWifiSwitchingRouter(UpnpServiceConfiguration configuration, ProtocolFactory protocolFactory, android.net.wifi.WifiManager wifiManager, android.net.ConnectivityManager connectivityManager)
           
 
Method Summary
 void broadcast(byte[] bytes)
           Call this method to broadcast a UDP message to all hosts on the network.
 UpnpServiceConfiguration getConfiguration()
           
protected  android.net.ConnectivityManager getConnectivityManager()
           
 int getLocalStreamPort(InetAddress address)
           
 NetworkAddressFactory getNetworkAddressFactory()
           
 ProtocolFactory getProtocolFactory()
           
protected  android.net.wifi.WifiManager getWifiManager()
           
 void onReceive(android.content.Context c, android.content.Intent intent)
           
 void received(IncomingDatagramMessage msg)
           This method is called internally by the transport layer when a datagram, either unicast or multicast, has been received.
 void received(UpnpStream stream)
           This method is called internally by the transport layer when a TCP stream connection has been made and a response has to be returned to the sender.
 void send(OutgoingDatagramMessage msg)
           Call this method to send a UDP datagram message.
 StreamResponseMessage send(StreamRequestMessage msg)
           Call this method to send a TCP (HTTP) stream message.
 void shutdown()
          Unbinds all sockets and stops all listening threads for datagrams and streams.
 
Methods inherited from class android.content.BroadcastReceiver
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, isInitialStickyBroadcast, isOrderedBroadcast, peekService, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AndroidWifiSwitchingRouter

public AndroidWifiSwitchingRouter(UpnpServiceConfiguration configuration,
                                  ProtocolFactory protocolFactory,
                                  android.net.wifi.WifiManager wifiManager,
                                  android.net.ConnectivityManager connectivityManager)
Method Detail

getConfiguration

public UpnpServiceConfiguration getConfiguration()
Specified by:
getConfiguration in interface Router
Returns:
The configuration used by this router.

getProtocolFactory

public ProtocolFactory getProtocolFactory()
Specified by:
getProtocolFactory in interface Router
Returns:
The protocol factory used by this router.

getWifiManager

protected android.net.wifi.WifiManager getWifiManager()

getConnectivityManager

protected android.net.ConnectivityManager getConnectivityManager()

onReceive

public void onReceive(android.content.Context c,
                      android.content.Intent intent)
Specified by:
onReceive in class android.content.BroadcastReceiver

getNetworkAddressFactory

public NetworkAddressFactory getNetworkAddressFactory()
Specified by:
getNetworkAddressFactory in interface Router
Returns:
The network interface and address binding configuration of this router.

getLocalStreamPort

public int getLocalStreamPort(InetAddress address)
Specified by:
getLocalStreamPort in interface Router
Parameters:
address - A bound address of a local network interface.
Returns:
The local port this router is listening on for TCP stream (HTTP) requests or 0 if the given address was not managed by this router.

shutdown

public void shutdown()
Description copied from interface: Router
Unbinds all sockets and stops all listening threads for datagrams and streams.

Specified by:
shutdown in interface Router

received

public void received(IncomingDatagramMessage msg)
Description copied from interface: Router

This method is called internally by the transport layer when a datagram, either unicast or multicast, has been received. An implementation of this interface has to handle the received message, e.g. selecting and executing a UPnP protocol. This method should not block until the execution completes, the calling thread should be free to handle the next reception as soon as possible.

Specified by:
received in interface Router
Parameters:
msg - The received datagram message.

received

public void received(UpnpStream stream)
Description copied from interface: Router

This method is called internally by the transport layer when a TCP stream connection has been made and a response has to be returned to the sender. An implementation of this interface has to handle the received stream connection and return a response, e.g. selecting and executing a UPnP protocol. This method should not block until the execution completes, the calling thread should be free to process the next reception as soon as possible. Typically this means starting a new thread of execution in this method.

Specified by:
received in interface Router

send

public void send(OutgoingDatagramMessage msg)
Description copied from interface: Router

Call this method to send a UDP datagram message.

Specified by:
send in interface Router
Parameters:
msg - The UDP datagram message to send.

send

public StreamResponseMessage send(StreamRequestMessage msg)
Description copied from interface: Router

Call this method to send a TCP (HTTP) stream message.

Specified by:
send in interface Router
Parameters:
msg - The TCP (HTTP) stream message to send.
Returns:
The response received from the server.

broadcast

public void broadcast(byte[] bytes)
Description copied from interface: Router

Call this method to broadcast a UDP message to all hosts on the network.

Specified by:
broadcast in interface Router
Parameters:
bytes - The byte payload of the UDP datagram.


Copyright © 2010 Teleal GmbH, Switzerland. All Rights Reserved.