edu.wisc.trace.urcsdk.client.upnpdcps
Class UpnpAvTun

java.lang.Object
  extended by edu.wisc.trace.urcsdk.client.upnpdcps.UpnpAvTun
All Implemented Interfaces:
IClientTun, org.cybergarage.upnp.event.EventListener

public class UpnpAvTun
extends java.lang.Object
implements IClientTun, org.cybergarage.upnp.event.EventListener

UpnpAvTun is a sample TUN for UPnP AV devices in Flat Mode for the SDK. Presently MediaRenderers and Media Servers can be operated using this TUN with the URC framework. This tun uses upnpdcpstun.properties file to configure various Map Parameter
e.g

Also other map parameters should be read from this file (map parameters from the program code will overwrite parameters from the properties file).All default values should go in the properties file, and not in the Java code.

Author:
Parikshit Thakur & team

Nested Class Summary
 class UpnpAvTun.DescriptionReader
          For SAX Parsing of DIDL-Lite document received from Media Server
 class UpnpAvTun.MediaServerRendererPair
          Maintains MediaServer-MediaRenderer pair for a particular Client
 class UpnpAvTun.RendererMonitorThread
          Thread to periodically monitor a running renderer.
 class UpnpAvTun.RendererSubscribeThread
          Thread for periodically subscribing a MediaRenderer.
 class UpnpAvTun.StopRunner
           
 
Field Summary
protected  java.util.HashMap<IClient,UpnpAvTun.MediaServerRendererPair> clientMediaServerRendererPairs
           
protected  java.util.logging.Logger logger
           
protected  java.util.HashMap<java.lang.String,TargetMirror> sessionIdTargetMirrorMap
           
protected  java.util.ArrayList<TargetMirror> targetMirrorList
           
 
Constructor Summary
UpnpAvTun()
          Creates instance of UpnpAvTun
 
Method Summary
 void abortSession(java.lang.String sessionId)
          Not supported by Upnp Targets
 void acknowledgeNotification(java.lang.String sessionId, IUISocketElement socketElement)
          Not supported by Upnp Targets
 boolean browse(java.lang.String mediaServerUdn)
          browse called for initial browse when Media Server is detected.
 boolean browse(java.lang.String mediaServerUdn, java.lang.String searchingId, int index, boolean isCalculateTotalCount)
          browse is used for browsing of particular index.
 boolean browse(java.lang.String mediaServerUdn, java.lang.String searchingId, int index, java.lang.String browseFlag, boolean isCalculateTotalCount)
          browse is used for browsing a particular index.
 void closeSession(java.lang.String sessionId)
          Called to alert the Target that the Client wants to close the session.
 void configureForClient(IClient client, java.util.Map<java.lang.String,java.lang.Object> parameterMap)
          Nothing specific to configure for Clients binding to this TUN
 void eventNotifyReceived(java.lang.String sid, long seq, java.lang.String name, java.lang.String value)
          Called by the CLink SDK for UPnP, when an event is received from a Subscribed UPnP Service
 void firstChildNode(java.lang.String mediaServerUdn, java.lang.String parentNode)
          firstChildNode called to invoke firstChildNode command.
 java.lang.Object getElementState(java.lang.String sessionId, java.lang.String elementId)
          Retrieve the current state of the element from the Upnp Target.
protected  UpnpAvTun.MediaServerRendererPair getMediaServerRendererPairByMediaRendererSid(java.lang.String mediaRendererSid)
          Returns the MediaServerRendererPair for requested mediaRendererSid (Subscription Id)
protected  UpnpAvTun.MediaServerRendererPair getMediaServerRendererPairByMediaRendererUdn(java.lang.String mediaRendererUdn)
          Returns the MediaServerRendererPair for requested mediaRendererUdn
protected  UpnpAvTun.MediaServerRendererPair getMediaServerRendererPairByMediaServerUdn(java.lang.String mediaServerUdn)
          Returns the MediaServerRendererPair for requested mediaServerUdn
 boolean getPositionInfo(UpnpAvTun.MediaServerRendererPair mediaServerRendererPair)
          Get current connection info for specified connection ID.
 java.util.List<TargetMirror> getRegisteredTargets()
          Returns the List of Targets discovered by this TUN
 java.lang.String invokeCommandRequest(IUISocketElement socketElement)
          Should be implemented by the underlying network specific layer to indicate to the target that the user has invoked a commmand.
 void invokeLocator(java.lang.String locatorId, java.lang.String targetName)
          Not supported by Upnp Targets
 void nextNode(java.lang.String mediaServerUdn, java.lang.String parentNode)
          nextNode called to invoke nextNode command.
 ClientSession openSessionRequest(IClient client, TargetMirror target, UISocketMirror socket)
          Should be implemented by the underlying network specific layer to open a new Session with the Target
 void parentNode(java.lang.String mediaServerUdn, java.lang.String parentNode)
          parentNode called to invoke parentNode command.
 void pause(java.lang.String mediaRendererUdn)
          pause called to invoke pause command.
 void play(java.lang.String mediaRendererUdn)
          Invoke play command on the MediaRenderer
 void prevNode(java.lang.String mediaServerUdn, java.lang.String parentNode)
          prevNode called to invoke previousNode command.
 boolean setElementStateRequest(IUISocketElement element)
          To set a Upnp State Variable.
 void setListener(IClientTunListener clientTunListener)
          Sets the listener for this ClientTun
 void startMonitorThread(UpnpAvTun.MediaServerRendererPair mediaServerRendererPair)
          startMonitorThread is used to start monitor thread which retrieves the Relative Time Position of the Track which is playing
 void stopMonitorThread()
          stopMonitorThread is used to stop monitor thread
 void targetDiscarded(java.lang.String targetId)
          Called when a Target unregisters itself from the network.
 void targetDiscovered(java.net.URI tduri, java.lang.String targetId)
          Called when a new Target is discovered on the network.
 void unbindClient(IClient client)
          Not necessary for UPnP DCPs, as the standard UPnP devices have no knowledge about the URC Client
 void updateElementCsvList(java.lang.String sessionId, java.lang.String elementIdCsvList, java.lang.String valueCsvList)
          Called when the Target sends accumulated update using CSV list
 void updateElementState(java.lang.String sessionId, java.lang.String elementId, java.lang.Object elementValue)
          Called when the Target updates the value of a state element.
 void ustop(java.lang.String mediaRendererUdn)
          ustop called to invoke stop command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected java.util.logging.Logger logger

sessionIdTargetMirrorMap

protected java.util.HashMap<java.lang.String,TargetMirror> sessionIdTargetMirrorMap

clientMediaServerRendererPairs

protected java.util.HashMap<IClient,UpnpAvTun.MediaServerRendererPair> clientMediaServerRendererPairs

targetMirrorList

protected java.util.ArrayList<TargetMirror> targetMirrorList
Constructor Detail

UpnpAvTun

public UpnpAvTun()
Creates instance of UpnpAvTun

Method Detail

setListener

public void setListener(IClientTunListener clientTunListener)
Description copied from interface: IClientTun
Sets the listener for this ClientTun

Specified by:
setListener in interface IClientTun
Parameters:
clientTunListener - a IClientTunListener value

getRegisteredTargets

public java.util.List<TargetMirror> getRegisteredTargets()
Description copied from interface: IClientTun
Returns the List of Targets discovered by this TUN

Specified by:
getRegisteredTargets in interface IClientTun
Returns:
a List of TargetMirror

targetDiscovered

public void targetDiscovered(java.net.URI tduri,
                             java.lang.String targetId)
Description copied from interface: IClientTun
Called when a new Target is discovered on the network.

Specified by:
targetDiscovered in interface IClientTun
Parameters:
tduri - an URI value
targetId - a String value

targetDiscarded

public void targetDiscarded(java.lang.String targetId)
Description copied from interface: IClientTun
Called when a Target unregisters itself from the network.

Specified by:
targetDiscarded in interface IClientTun
Parameters:
targetId - a String value

invokeCommandRequest

public java.lang.String invokeCommandRequest(IUISocketElement socketElement)
Description copied from interface: IClientTun
Should be implemented by the underlying network specific layer to indicate to the target that the user has invoked a commmand.

Specified by:
invokeCommandRequest in interface IClientTun
Parameters:
socketElement - an IUISocketElement value
Returns:
The status of an invoked Command

openSessionRequest

public ClientSession openSessionRequest(IClient client,
                                        TargetMirror target,
                                        UISocketMirror socket)
                                 throws UrcException
Description copied from interface: IClientTun
Should be implemented by the underlying network specific layer to open a new Session with the Target

Specified by:
openSessionRequest in interface IClientTun
Returns:
a ClientSession value
Throws:
UrcException

updateElementState

public void updateElementState(java.lang.String sessionId,
                               java.lang.String elementId,
                               java.lang.Object elementValue)
Description copied from interface: IClientTun
Called when the Target updates the value of a state element.

Specified by:
updateElementState in interface IClientTun
Parameters:
sessionId - a String value
elementId - a String value
elementValue - an Object array containing propogated values

updateElementCsvList

public void updateElementCsvList(java.lang.String sessionId,
                                 java.lang.String elementIdCsvList,
                                 java.lang.String valueCsvList)
Description copied from interface: IClientTun
Called when the Target sends accumulated update using CSV list

Specified by:
updateElementCsvList in interface IClientTun
Parameters:
sessionId - a String value
elementIdCsvList - a String with CSV
valueCsvList - a String with CSV

closeSession

public void closeSession(java.lang.String sessionId)
                  throws UrcException
Description copied from interface: IClientTun
Called to alert the Target that the Client wants to close the session.

Specified by:
closeSession in interface IClientTun
Parameters:
sessionId - a String value
Throws:
UrcException

getMediaServerRendererPairByMediaServerUdn

protected UpnpAvTun.MediaServerRendererPair getMediaServerRendererPairByMediaServerUdn(java.lang.String mediaServerUdn)
Returns the MediaServerRendererPair for requested mediaServerUdn

Parameters:
mediaServerUdn -
Returns:
MediaServerRendererPair

getMediaServerRendererPairByMediaRendererUdn

protected UpnpAvTun.MediaServerRendererPair getMediaServerRendererPairByMediaRendererUdn(java.lang.String mediaRendererUdn)
Returns the MediaServerRendererPair for requested mediaRendererUdn

Parameters:
mediaRendererUdn -
Returns:
MediaServerRendererPair

getMediaServerRendererPairByMediaRendererSid

protected UpnpAvTun.MediaServerRendererPair getMediaServerRendererPairByMediaRendererSid(java.lang.String mediaRendererSid)
Returns the MediaServerRendererPair for requested mediaRendererSid (Subscription Id)

Parameters:
mediaRendererSid -
Returns:
MediaServerRendererPair

play

public void play(java.lang.String mediaRendererUdn)
Invoke play command on the MediaRenderer

Parameters:
mediaRendererUdn - Unique Device Name of the MediaRenderer on which the Play command has to be invoked

pause

public void pause(java.lang.String mediaRendererUdn)
pause called to invoke pause command.

Parameters:
mediaRendererUdn - Unique Device Name of the MediaRenderer on which the Pause command has to be invoked

ustop

public void ustop(java.lang.String mediaRendererUdn)
ustop called to invoke stop command.

Parameters:
mediaRendererUdn - Unique Device Name of the MediaRenderer on which the Stop command has to be invoked

prevNode

public void prevNode(java.lang.String mediaServerUdn,
                     java.lang.String parentNode)
prevNode called to invoke previousNode command.

Parameters:
mediaServerUdn - Unique Device Name of the MediaServer on which the previousNode command has to be invoked
parentNode - a String Parent Node ID

nextNode

public void nextNode(java.lang.String mediaServerUdn,
                     java.lang.String parentNode)
nextNode called to invoke nextNode command.

Parameters:
mediaServerUdn - Unique Device Name of the MediaServer on which the nextNode command has to be invoked
parentNode - a String Parent Node ID

firstChildNode

public void firstChildNode(java.lang.String mediaServerUdn,
                           java.lang.String parentNode)
firstChildNode called to invoke firstChildNode command.

Parameters:
mediaServerUdn - Unique Device Name of the MediaServer on which the firstChildNode command has to be invoked
parentNode - a String Parent Node ID

parentNode

public void parentNode(java.lang.String mediaServerUdn,
                       java.lang.String parentNode)
parentNode called to invoke parentNode command.

Parameters:
mediaServerUdn - Unique Device Name of the MediaServer on which the parentNode command has to be invoked
parentNode - a String Parent Node ID

browse

public boolean browse(java.lang.String mediaServerUdn)
browse called for initial browse when Media Server is detected.

Parameters:
mediaServerUdn - Unique Device Name of the MediaServer on which the browse command has to be invoked

browse

public boolean browse(java.lang.String mediaServerUdn,
                      java.lang.String searchingId,
                      int index,
                      boolean isCalculateTotalCount)
browse is used for browsing of particular index.

Parameters:
mediaServerUdn - Unique Device Name of the MediaServer on which the browse command has to be invoked
searchingId - a String
index - an int
isCalculateTotalCount - aboolean Flag indicating Total Number Of node to be calculated or not. True in case of navigation through firstChildNode or parentNode invoke false in other case

browse

public boolean browse(java.lang.String mediaServerUdn,
                      java.lang.String searchingId,
                      int index,
                      java.lang.String browseFlag,
                      boolean isCalculateTotalCount)
browse is used for browsing a particular index.

Parameters:
mediaServerUdn - Unique Device Name of the MediaServer on which the browse command has to be invoked
searchingId - a String
index - a int
browseFlag - a String Flag indicates browsing mode i.e. 'BrowseDirectChildren' or 'BrowseMetaData'
isCalculateTotalCount - a boolean Flag indicates Total Number Of node to be calculated or not. True in case of navigation through firstChildNode or parentNode invoke false in other case

getPositionInfo

public boolean getPositionInfo(UpnpAvTun.MediaServerRendererPair mediaServerRendererPair)
Get current connection info for specified connection ID. Modify the local renderer state model using the returned information

Parameters:
mediaServerRendererPair -

eventNotifyReceived

public void eventNotifyReceived(java.lang.String sid,
                                long seq,
                                java.lang.String name,
                                java.lang.String value)
Called by the CLink SDK for UPnP, when an event is received from a Subscribed UPnP Service

Specified by:
eventNotifyReceived in interface org.cybergarage.upnp.event.EventListener
Parameters:
sid - Subscription Id of the subscribed Service
seq -
name -
value -

startMonitorThread

public void startMonitorThread(UpnpAvTun.MediaServerRendererPair mediaServerRendererPair)
startMonitorThread is used to start monitor thread which retrieves the Relative Time Position of the Track which is playing


stopMonitorThread

public void stopMonitorThread()
stopMonitorThread is used to stop monitor thread


abortSession

public void abortSession(java.lang.String sessionId)
Not supported by Upnp Targets

Specified by:
abortSession in interface IClientTun
Parameters:
sessionId - a String value

acknowledgeNotification

public void acknowledgeNotification(java.lang.String sessionId,
                                    IUISocketElement socketElement)
                             throws UrcException
Not supported by Upnp Targets

Specified by:
acknowledgeNotification in interface IClientTun
Parameters:
sessionId - a String value
socketElement - an IUISocketElement value
Throws:
UrcException

configureForClient

public void configureForClient(IClient client,
                               java.util.Map<java.lang.String,java.lang.Object> parameterMap)
                        throws UrcException
Nothing specific to configure for Clients binding to this TUN

Specified by:
configureForClient in interface IClientTun
parameterMap - a Map
Throws:
UrcException

unbindClient

public void unbindClient(IClient client)
                  throws UrcException
Not necessary for UPnP DCPs, as the standard UPnP devices have no knowledge about the URC Client

Specified by:
unbindClient in interface IClientTun
Parameters:
client - a IClient value
Throws:
UrcException

getElementState

public java.lang.Object getElementState(java.lang.String sessionId,
                                        java.lang.String elementId)
                                 throws UrcException
Retrieve the current state of the element from the Upnp Target. To be implemented.

Specified by:
getElementState in interface IClientTun
Parameters:
sessionId - a String value
elementId - a String value
Returns:
a Object value
Throws:
UrcException

setElementStateRequest

public boolean setElementStateRequest(IUISocketElement element)
To set a Upnp State Variable. To be implemented.

Specified by:
setElementStateRequest in interface IClientTun
Parameters:
element - an IUISocketElement value
Returns:
True if the request was successful

invokeLocator

public void invokeLocator(java.lang.String locatorId,
                          java.lang.String targetName)
Not supported by Upnp Targets

Specified by:
invokeLocator in interface IClientTun


Copyright © 2006 Trace R&D Center, University of Wisconsin-Madison. All Rights Reserved.