java.lang.Object
org.cybergarage.upnp.Device
- All Implemented Interfaces:
HTTPRequestListener, SearchListener
Represents a UPnP device in the CyberLink framework.
This class provides the core functionality for UPnP devices, including:
- Device description and advertisement via SSDP
- HTTP server functionality for handling requests
- Service management and action invocation
- Event notification and subscription handling
- Hierarchical device relationships (root/embedded devices)
A Device can be either a root device or an embedded device within another device. Each device contains services that provide specific functionality through actions and state variables.
Key features:
- Automatic device discovery and announcement
- SOAP-based control message handling
- GENA-based event notification
- Multi-homed network interface support
- NMPR (Network Media Profile Requirements) compliance
Field Summary
Modifier and TypeFieldDescriptionprivate intThe boot id advertised in notifications.private static CalendarShared calendar for formatting dates.private static final StringTag name for the configuration id.static final StringPath served for the device description document.static final intMilliseconds to wait between repeats of an SSDP search.static final intAdvertisement lifetime in seconds assigned to a freshly loaded description.static final StringPath served for the device's presentation page.static final intMilliseconds to wait before sending the first SSDP announcement.private static final StringTag name for the device type.private NodeThis device's node within the description.private StringThe device's UUID, without the UDN prefix.static final StringElement name of a device node in the description document.private static final StringTag name for the friendly name.static final intPort the built-inHTTPserver binds to when none is set.Icon data by icon id.private static final StringTag name for the manufacturer.private static final StringTag name for the manufacturer URL.private static final StringTag name for the model description.private static final StringTag name for the model name.private static final StringTag name for the model number.private static final StringTag name for the model URL.private MutexLock guarding the device's state.private PresentationListenerListener notified of presentation requests.private static final StringTag name for the presentation URL.private NodeThe root node of the description document.private static final StringTag name for the serial number.private static final StringTag name for the unique device name.private static final StringTag name for the UPC code.static final StringElement name marking the root of a description document.private static final StringTag name for the base URL.private ObjectArbitrary data attached by the application.private booleanWhether wireless mode is on for notifications.Constructor Summary
ConstructorsConstructorDescriptionDevice()Creates an empty device with no description nodes.Creates a device by loading its description from a file.Device(InputStream input) Creates a device by loading its description from a stream.Creates a device by loading its description from the named file.Creates a device with no root node but the given device node.Creates a device from a root description node and its own node.Method Summary
Modifier and TypeMethodDescriptionvoidAdd a Device to device without checking for duplicate or syntax error.booleanAppends an icon to this device's icon list.voidAdd a Service to device without checking for duplicate or syntax errorvoidannounce()Announces this device on every bound address after a discovery delay.voidSends the alive advertisement for this device tree from one bind address.voidbyebye()Sends the byebye from every bound address; a no-op in this build.voidSends the byebye for this device tree from one bind address; a no-op in this build.private voiddeviceActionControlRecieved(ActionRequest ctlReq, Service service) Runs an action on the target service.private voiddeviceControlRequestRecieved(ControlRequest ctlReq, Service service) Dispatches a control request to the right service.private voiddeviceEventNewSubscriptionRecieved(Service service, SubscriptionRequest subReq) Creates a new event subscription.private voiddeviceEventRenewSubscriptionRecieved(Service service, SubscriptionRequest subReq) Renews an existing event subscription.private voidDispatches an event subscription request.private voiddeviceEventUnsubscriptionRecieved(Service service, SubscriptionRequest subReq) Cancels an event subscription.private voiddeviceQueryControlRecieved(QueryRequest ctlReq, Service service) Answers a state variable query.voiddeviceSearchReceived(SSDPPacket ssdpPacket) Handles an incoming search request by answering it.voiddeviceSearchResponse(SSDPPacket ssdpPacket) Answers a search request for every device in this tree that matches it.getAbsoluteURL(String urlString) Resolves a possibly relative URL against the root device's base and location.getAbsoluteURL(String urlString, String baseURLStr, String locationURLStr) Resolves a possibly relative URL against a base URL and a description location.Finds an action by name across every service.private AdvertiserReturns the advertiser sending alive messages.intGets the boot ID this device announces.intGets the configuration ID computed for this device.private byte[]getDescriptionData(String host) Builds the description document bytes for a host.Gets the file this device's description was loaded from.Gets the directory holding this device's description file.private StringReturns the URI the description is served at.Finds an embedded device by UDN, friendly name or device type.Finds an embedded device served at the given description URI.private DeviceDataReturns the device's data for notifications.Gets the devices embedded in this one.Gets this device's own element node.Gets the device type URN.longGets the seconds elapsed since this device was last announced.Gets the name advertised for this device.Gets the addresses the HTTP server is bound to.intGets the port the HTTP server binds to.private HTTPServerListReturns the running HTTP servers, starting them if needed.getIcon(int n) Gets the icon at a position in this device's icon list.getIconByURI(String uri) Finds an icon by its URL.Gets the icons of this device.Gets the local address this device was announced from.intGets the advertisement lifetime, preferring the announced packet's value.Gets the URL this device's description is served from.getLocation(boolean preferIPv6) I2P for multiple location supportgetLocationURL(String host) Builds the URL this device's description is served from on a given host.Gets the name of the company that makes this device.Gets the URL of the manufacturer's home page.Gets the free-form description of this model.Gets the model name.Gets the model number.Gets the URL of the documentation for this model.Get the IPv4 address SSDP multicasts to.Get the IPv6 address SSDP multicasts to.private StringReturns the notification header for the device.private StringReturns the notification header for the device type.private StringReturns the notification USN for the device type.private StringReturns the notification USN for the device.Get the device that contains this one.Gets the handler for this device's control page.Gets the URI path serving this device's control page.Gets the root of this device's description tree.Gets the node holding this device's root description.Gets the serial number of this unit.getService(String name) Finds a service of this or an embedded device by type or ID.getServiceByControlURL(String searchUrl) Finds a service by its control URL.getServiceByEventSubURL(String searchUrl) Finds a service by its event subscription URL.getServiceBySCPDURL(String searchUrl) Finds a service by its service control description (SCPD) URL.Gets the services of this device.Finds the icon with the narrowest width.intGets how many SSDP announcements this device should send.Get the addresses the SSDP service binds to.Get the IPv4 address SSDP multicasts to.voidSet the IPv4 address SSDP multicasts to.Get the IPv6 address SSDP multicasts to.voidSet the IPv6 address SSDP multicasts to.Gets the SSDP packet that announced this device.getSSDPPacket(boolean preferIPv6) I2P for multiple location supportintGet the port the SSDP service binds to.private SSDPSearchSocketListReturns the SSDP search sockets, starting them if needed.getStateVariable(String name) Finds a state variable by name across every service.getStateVariable(String serviceType, String name) Finds a state variable by name, optionally restricted to one service type.getSubscriberService(String uuid) Finds the service a subscriber holds a subscription on.longGets when this device was last announced.getUDN()Gets the unique device name.getUPC()Gets the Universal Product Code.Gets the root device's URLBase.Gets the caller-defined data attached to this device's node.getUUID()Gets the UUID generated when this device was created.booleanTests whether a control page handler is installed.booleanhasUDN()Tests whether a non-empty unique device name is set.private voidhttpGetRequestRecieved(HTTPRequest httpReq) Handles a GET request to the device's server.private voidhttpPostRequestRecieved(HTTPRequest httpReq) Handles a POST request to the device's server.voidhttpRequestRecieved(HTTPRequest httpReq) Routes an incoming HTTP request to the presentation, GET, POST or event handler.private booleanInitializes the device fields from a loaded description.private voidAnswers a control request naming an invalid action.private voidAnswers a control request with invalid arguments.private booleanisDescriptionURI(String uri) Checks whether a URI names this device's description.booleanTests whether a name identifies this device.static booleanisDeviceNode(Node node) Tests whether a node is a device element.booleanisDeviceType(String value) Tests whether this device carries the given device type URN.booleanTests whether this device's advertisement has outlived its lease time.booleanisIconBytesURI(String uri) Tests whether an icon's bytes are already cached.booleanTests whether the device is marked NMPR compliant.private booleanisPresentationRequest(HTTPRequest httpReq) Checks whether a request targets the presentation URL.booleanTests whether this device is the root of its description tree.booleanTests whether this device's advertiser is running.booleanTests whether this device is announced over a wireless link.booleanloadDescription(File file) Loads the device description from a file.booleanloadDescription(InputStream input) Load the device description from a stream.booleanloadDescription(String descString) Loads the device description from description XML text.voidlock()Acquires the mutex guarding this device.static final voidSleeps a random interval so SSDP replies from many devices do not collide.booleanpostSearchResponse(SSDPPacket ssdpPacket, String st, String usn) Sends a search response naming this device's root description.booleanRemoves the presentation page, leaving the listener installed.voidsetActionListener(ActionListener listener) Installs the action handler on every service of this device.voidsetActionListener(ActionListener listener, boolean includeSubDevices) Installs the action handler on every service, optionally descending into embedded devices.private voidsetAdvertiser(Advertiser adv) Sets the advertiser sending alive messages.private voidsetDescriptionFile(File file) Sets the file holding the description document.private voidsetDescriptionURI(String uri) Sets the URI the description is served at.voidsetDeviceNode(Node node) Sets this device's own element node.voidsetDeviceType(String value) Sets the device type URN.voidsetFriendlyName(String value) Sets the name advertised for this device.voidsetHTTPBindAddress(InetAddress[] inets) Sets the addresses the HTTP server binds to.voidsetHTTPPort(int port) Sets the port the HTTP server binds to.voidsetLeaseTime(int value) Sets the advertisement lifetime, re-announcing a running device.voidsetLocation(String value) Sets the URL this device's description is served from.voidsetManufacture(String value) Sets the name of the company that makes this device.voidsetManufactureURL(String value) Sets the URL of the manufacturer's home page.voidsetModelDescription(String value) Sets the free-form description of this model.voidsetModelName(String value) Sets the model name.voidsetModelNumber(String value) Sets the model number.voidsetModelURL(String value) Sets the URL of the documentation for this model.voidSet the IPv4 address SSDP multicasts to.voidSet the IPv6 address SSDP multicasts to.voidsetNMPRMode(boolean flag) Marks the device NMPR compliant, or removes the NMPR elements.voidsetPresentationListener(PresentationListener listener) Installs the handler for this device's control page.voidsetPresentationURL(String value) Sets the URI path serving this device's control page.voidsetQueryListener(QueryListener listener) Installs the query handler on every service of this device.voidsetQueryListener(QueryListener listener, boolean includeSubDevices) Installs the query handler on every service, optionally descending into embedded devices.voidsetRootNode(Node node) Sets the node holding this device's root description.voidsetSerialNumber(String value) Sets the serial number of this unit.voidsetSSDPBindAddress(InetAddress[] inets) Set the addresses the SSDP service binds to.voidsetSSDPPacket(SSDPPacket packet) Records the SSDP packet that announced this device.voidsetSSDPPort(int port) Set the port the SSDP service binds to.voidSets the unique device name.voidSets the Universal Product Code.private voidsetURLBase(String value) Sets the base URL for service URLs.voidsetUserData(Object data) Attaches caller-defined data to this device's node.private voidSets the device's UUID and refreshes the UDN.voidsetWirelessMode(boolean flag) Records whether this device is announced over a wireless link.private voidsoapActionRecieved(HTTPRequest soapReq) Handles a SOAP action request.private voidsoapBadActionRecieved(HTTPRequest soapReq) Answers a SOAP request with an unknown action.booleanstart()Starts the HTTP server and begins SSDP advertising for this device.booleanstop()Stops SSDP advertising and shuts down the HTTP server.private booleanstop(boolean doByeBye) Stops the device's servers and advertiser.voidunlock()Releases the mutex guarding this device.private voidSets the boot id from the current time.voidRecomputes the configuration ID of this device and everything below it.private voidupdateConfigId(Device dev) Copies the configuration id from another device.private voidRebuilds the UDN string from the UUID.private voidupdateURLBase(String host) Rewrites the base URL for a host.private voidupnpBadSubscriptionRecieved(SubscriptionRequest subReq, int code) Answers a subscription request with an error code.
Field Details
ELEM_NAME
Element name of a device node in the description document.- See Also:
UPNP_ROOTDEVICE
Element name marking the root of a description document.- See Also:
DEFAULT_STARTUP_WAIT_TIME
public static final int DEFAULT_STARTUP_WAIT_TIMEMilliseconds to wait before sending the first SSDP announcement.- See Also:
DEFAULT_DISCOVERY_WAIT_TIME
public static final int DEFAULT_DISCOVERY_WAIT_TIMEMilliseconds to wait between repeats of an SSDP search.- See Also:
DEFAULT_LEASE_TIME
public static final int DEFAULT_LEASE_TIMEAdvertisement lifetime in seconds assigned to a freshly loaded description.- See Also:
HTTP_DEFAULT_PORT
public static final int HTTP_DEFAULT_PORTPort the built-inHTTPserver binds to when none is set.- See Also:
DEFAULT_DESCRIPTION_URI
Path served for the device description document.- See Also:
DEFAULT_PRESENTATION_URI
Path served for the device's presentation page.- See Also:
rootNode
The root node of the description document.deviceNode
This device's node within the description.mutex
Lock guarding the device's state.wirelessMode
private boolean wirelessModeWhether wireless mode is on for notifications.devUUID
The device's UUID, without the UDN prefix.bootId
private int bootIdThe boot id advertised in notifications.CONFIG_ID
Tag name for the configuration id.- See Also:
URLBASE_NAME
DEVICE_TYPE
FRIENDLY_NAME
Tag name for the friendly name.- See Also:
MANUFACTURE
MANUFACTURE_URL
Tag name for the manufacturer URL.- See Also:
MODEL_DESCRIPTION
Tag name for the model description.- See Also:
MODEL_NAME
MODEL_NUMBER
Tag name for the model number.- See Also:
MODEL_URL
SERIAL_NUMBER
Tag name for the serial number.- See Also:
UDN
UPC
presentationURL
Tag name for the presentation URL.- See Also:
presentationListener
Listener notified of presentation requests.iconBytesMap
cal
Shared calendar for formatting dates.userData
Arbitrary data attached by the application.
Constructor Details
Device
Device
public Device()Creates an empty device with no description nodes.Device
Creates a device with no root node but the given device node.- Parameters:
device- this device's owndeviceelement
Device
Creates a device by loading its description from a file.- Parameters:
descriptionFile- the file holding the description XML- Throws:
InvalidDescriptionException- if the description cannot be parsed or has no root or device element
Device
Creates a device by loading its description from a stream.- Parameters:
input- the stream to read the description XML from- Throws:
InvalidDescriptionException- if the description cannot be parsed or has no root or device element
Device
Creates a device by loading its description from the named file.- Parameters:
descriptionFileName- the name of the file holding the description XML- Throws:
InvalidDescriptionException- if the description cannot be parsed or has no root or device element
Method Details
getRootNode
Gets the node holding this device's root description.- Returns:
- the node holding the root description, or null
getDeviceNode
Gets this device's own element node.- Returns:
- this device's own
deviceelement
setRootNode
Sets the node holding this device's root description.- Parameters:
node- the node holding the root description, or null to derive it from the device node
setDeviceNode
Sets this device's own element node.- Parameters:
node- this device's owndeviceelement
lock
public void lock()Acquires the mutex guarding this device.unlock
public void unlock()Releases the mutex guarding this device.getAbsoluteURL
Resolves a possibly relative URL against a base URL and a description location.- Parameters:
urlString- the URL to resolve, which may be relativebaseURLStr- the URLBase to resolve against, or nulllocationURLStr- the description location to resolve against, or null- Returns:
- the resolved URL, or urlString itself if it cannot be resolved
getAbsoluteURL
setNMPRMode
public void setNMPRMode(boolean flag) Marks the device NMPR compliant, or removes the NMPR elements.- Parameters:
flag- true to describe the device as NMPR compliant, false to drop the NMPR elements
isNMPRMode
public boolean isNMPRMode()Tests whether the device is marked NMPR compliant.- Returns:
- true if the device is marked NMPR compliant
setWirelessMode
public void setWirelessMode(boolean flag) Records whether this device is announced over a wireless link.- Parameters:
flag- true when the device is announced over a wireless link
isWirelessMode
public boolean isWirelessMode()Tests whether this device is announced over a wireless link.- Returns:
- true when the device is announced over a wireless link
getSSDPAnnounceCount
public int getSSDPAnnounceCount()Gets how many SSDP announcements this device should send.- Returns:
- how many times this device should be announced
setUUID
Sets the device's UUID and refreshes the UDN.- Parameters:
uuid- the new UUID
getUUID
Gets the UUID generated when this device was created.- Returns:
- the UUID generated for this device
updateUDN
private void updateUDN()Rebuilds the UDN string from the UUID.updateBootId
private void updateBootId()Sets the boot id from the current time.getBootId
public int getBootId()Gets the boot ID this device announces.- Returns:
- the boot ID announced by this device, or 0 until it is started
updateConfigId
Copies the configuration id from another device.- Parameters:
dev- the device to copy from
updateConfigId
public void updateConfigId()Recomputes the configuration ID of this device and everything below it.getConfigId
public int getConfigId()Gets the configuration ID computed for this device.- Returns:
- the configuration ID of this device, or 0 until it is computed
getRootDevice
Gets the root of this device's description tree.- Returns:
- the root of this device's description tree, or null if it has no root
getParentDevice
Get the device that contains this one.- Returns:
- A Device that contain this object.
Returnnullif this is a root device.
addService
Add a Service to device without checking for duplicate or syntax error- Parameters:
s- Add Service s to the Device
addDevice
Add a Device to device without checking for duplicate or syntax error. This method set or reset the root node of the Device and itself
Note: This method should be used to create a dynamic
Device without writing any XML that describe the device- Parameters:
d- Add Device d to the Device
getDeviceData
Returns the device's data for notifications.- Returns:
- the device data
setDescriptionFile
Sets the file holding the description document.- Parameters:
file- the description file
getDescriptionFile
Gets the file this device's description was loaded from.- Returns:
- the file the description was loaded from, or null if it came from a stream or string
setDescriptionURI
Sets the URI the description is served at.- Parameters:
uri- the description URI
getDescriptionURI
Returns the URI the description is served at.- Returns:
- the description URI
isDescriptionURI
Checks whether a URI names this device's description.- Parameters:
uri- the URI to check- Returns:
- true if it is the description URI
getDescriptionFilePath
Gets the directory holding this device's description file.- Returns:
- the directory holding the description file, or an empty string if there is none
loadDescription
Load the device description from a stream.- Parameters:
input- the stream to read the description XML from- Returns:
- true if the description was loaded
- Throws:
InvalidDescriptionException- if the description cannot be parsed or has no root or device element
loadDescription
Loads the device description from description XML text.- Parameters:
descString- the description XML- Returns:
- true if the description was loaded
- Throws:
InvalidDescriptionException- if the description cannot be parsed or has no root or device element
loadDescription
Loads the device description from a file.- Parameters:
file- the file holding the description XML- Returns:
- true if the description was loaded
- Throws:
InvalidDescriptionException- if the description cannot be parsed or has no root or device element
initializeLoadedDescription
private boolean initializeLoadedDescription()Initializes the device fields from a loaded description.- Returns:
- true on success
isDeviceNode
Tests whether a node is a device element.- Parameters:
node- the node to test- Returns:
- true if the node is a
deviceelement
isRootDevice
public boolean isRootDevice()Tests whether this device is the root of its description tree.- Returns:
- true if this device is the root of its description tree
setSSDPPacket
Records the SSDP packet that announced this device.- Parameters:
packet- the SSDP packet that announced this device
getSSDPPacket
Gets the SSDP packet that announced this device.- Returns:
- the SSDP packet that announced this device, or null
getSSDPPacket
I2P for multiple location support- Parameters:
preferIPv6- whether to prefer the IPv6 packet when both were advertised- Returns:
- the SSDP packet that announced this device, or null
setLocation
Sets the URL this device's description is served from.- Parameters:
value- the URL the description is served from
getLocation
Gets the URL this device's description is served from.- Returns:
- the URL the description is served from
getLocation
I2P for multiple location support- Parameters:
preferIPv6- whether to prefer the IPv6 location when both were advertised- Returns:
- the URL the description is served from
setLeaseTime
public void setLeaseTime(int value) Sets the advertisement lifetime, re-announcing a running device.- Parameters:
value- the advertisement lifetime in seconds
getLeaseTime
public int getLeaseTime()Gets the advertisement lifetime, preferring the announced packet's value.- Returns:
- the advertisement lifetime in seconds
getTimeStamp
public long getTimeStamp()Gets when this device was last announced.- Returns:
- when this device was last announced, in milliseconds since the epoch, or 0
getElapsedTime
public long getElapsedTime()Gets the seconds elapsed since this device was last announced.- Returns:
- the seconds since this device was last announced
isExpired
public boolean isExpired()Tests whether this device's advertisement has outlived its lease time.- Returns:
- true if this device has not been announced within its lease time
setURLBase
Sets the base URL for service URLs.- Parameters:
value- the base URL
updateURLBase
Rewrites the base URL for a host.- Parameters:
host- the host name to use
getURLBase
Gets the root device's URLBase.- Returns:
- the root device's URLBase, or an empty string if this device is not the root
setDeviceType
Sets the device type URN.- Parameters:
value- the device type URN
getDeviceType
isDeviceType
Tests whether this device carries the given device type URN.- Parameters:
value- the device type URN to compare against- Returns:
- true if this device has that type
setFriendlyName
Sets the name advertised for this device.- Parameters:
value- the name to advertise for this device
getFriendlyName
Gets the name advertised for this device.- Returns:
- the name advertised for this device
setManufacture
Sets the name of the company that makes this device.- Parameters:
value- the name of the company that makes this device
getManufacture
Gets the name of the company that makes this device.- Returns:
- the name of the company that makes this device
setManufactureURL
Sets the URL of the manufacturer's home page.- Parameters:
value- the URL of the manufacturer's home page
getManufactureURL
Gets the URL of the manufacturer's home page.- Returns:
- the URL of the manufacturer's home page
setModelDescription
Sets the free-form description of this model.- Parameters:
value- the free-form description of this model
getModelDescription
Gets the free-form description of this model.- Returns:
- the free-form description of this model
setModelName
getModelName
setModelNumber
getModelNumber
setModelURL
Sets the URL of the documentation for this model.- Parameters:
value- the URL of the documentation for this model
getModelURL
Gets the URL of the documentation for this model.- Returns:
- the URL of the documentation for this model
setSerialNumber
Sets the serial number of this unit.- Parameters:
value- the serial number of this unit
getSerialNumber
Gets the serial number of this unit.- Returns:
- the serial number of this unit
setUDN
Sets the unique device name.- Parameters:
value- the unique device name, this device's UUID prefixed withuuid:
getUDN
hasUDN
public boolean hasUDN()Tests whether a non-empty unique device name is set.- Returns:
- true if a non-empty UDN is set
setUPC
Sets the Universal Product Code.- Parameters:
value- the Universal Product Code
getUPC
setPresentationURL
Sets the URI path serving this device's control page.- Parameters:
value- the URI path serving this device's control page
getPresentationURL
Gets the URI path serving this device's control page.- Returns:
- the URI path serving this device's control page
removePresentationURL
public boolean removePresentationURL()Removes the presentation page, leaving the listener installed.- Returns:
- true if there was a presentation URL to remove
isPresentationRequest
Checks whether a request targets the presentation URL.- Parameters:
httpReq- the request to check- Returns:
- true if it is a presentation request
setPresentationListener
Installs the handler for this device's control page.- Parameters:
listener- the handler for control page requests, or null to stop serving one
hasPresentationListener
public boolean hasPresentationListener()Tests whether a control page handler is installed.- Returns:
- true if a control page handler is set
getPresentationListener
Gets the handler for this device's control page.- Returns:
- the handler for control page requests, or null
getDeviceList
Gets the devices embedded in this one.- Returns:
- the devices embedded in this one
isDevice
Tests whether a name identifies this device.- Parameters:
name- the UDN, friendly name or device type to test against- Returns:
- true if that name identifies this device
getDevice
getDeviceByDescriptionURI
getServiceList
Gets the services of this device.- Returns:
- the services of this device
getService
getServiceBySCPDURL
getServiceByControlURL
getServiceByEventSubURL
getSubscriberService
getStateVariable
Finds a state variable by name, optionally restricted to one service type.- Parameters:
serviceType- the service type to restrict the search to, or null to search every servicename- the state variable name to search for- Returns:
- the matching state variable, or null
getStateVariable
Finds a state variable by name across every service.- Parameters:
name- the state variable name to search for- Returns:
- the matching state variable, or null
getAction
isIconBytesURI
Tests whether an icon's bytes are already cached.- Parameters:
uri- the icon URL to look up- Returns:
- true if the bytes for that icon are cached
getIconByURI
addIcon
Appends an icon to this device's icon list.- Parameters:
icon- the icon to add- Returns:
- true if the icon was added
getIconList
getIcon
Gets the icon at a position in this device's icon list.- Parameters:
n- the position in the icon list- Returns:
- the icon at that position, or null if there is none
getSmallestIcon
Finds the icon with the narrowest width.- Returns:
- the narrowest icon, or null if this device has none
getLocationURL
getNotifyDeviceNT
Returns the notification header for the device.- Returns:
- the NT value
getNotifyDeviceUSN
Returns the notification USN for the device.- Returns:
- the USN value
getNotifyDeviceTypeNT
Returns the notification header for the device type.- Returns:
- the NT value
getNotifyDeviceTypeUSN
Returns the notification USN for the device type.- Returns:
- the USN value
notifyWait
public static final void notifyWait()Sleeps a random interval so SSDP replies from many devices do not collide.announce
Sends the alive advertisement for this device tree from one bind address.- Parameters:
bindAddr- the address to send the SSDP advertisement from
announce
public void announce()Announces this device on every bound address after a discovery delay.byebye
Sends the byebye for this device tree from one bind address; a no-op in this build.- Parameters:
bindAddr- the address to send the SSDP byebye from
byebye
public void byebye()Sends the byebye from every bound address; a no-op in this build.postSearchResponse
Sends a search response naming this device's root description.- Parameters:
ssdpPacket- the search request being answeredst- the search target being answeredusn- the unique service name naming this device- Returns:
- true if the response was sent
deviceSearchResponse
Answers a search request for every device in this tree that matches it.- Parameters:
ssdpPacket- the search request to answer
deviceSearchReceived
Handles an incoming search request by answering it.- Specified by:
deviceSearchReceivedin interfaceSearchListener- Parameters:
ssdpPacket- received SSDP packet containing search request data
setHTTPPort
public void setHTTPPort(int port) Sets the port the HTTP server binds to.- Parameters:
port- the port the HTTP server binds to
getHTTPPort
public int getHTTPPort()Gets the port the HTTP server binds to.- Returns:
- the port the HTTP server binds to
setHTTPBindAddress
Sets the addresses the HTTP server binds to.- Parameters:
inets- the addresses to bind the HTTP server to, or null for the default
getHTTPBindAddress
Gets the addresses the HTTP server is bound to.- Returns:
- the addresses the HTTP server is bound to
getSSDPIPv4MulticastAddress
Get the IPv4 address SSDP multicasts to.- Returns:
- SSDPIPv4MulticastAddress
getSSDPIPv4MulticastAddress
Set the IPv4 address SSDP multicasts to.- Parameters:
ip- the IPv4 multicast address
getSSDPIPv6MulticastAddress
Get the IPv6 address SSDP multicasts to.- Returns:
- SSDPIPv6MulticastAddress
getSSDPIPv6MulticastAddress
Set the IPv6 address SSDP multicasts to.- Parameters:
ip- the IPv6 multicast address
httpRequestRecieved
Routes an incoming HTTP request to the presentation, GET, POST or event handler.- Specified by:
httpRequestRecievedin interfaceHTTPRequestListener- Parameters:
httpReq- the received HTTP request
getDescriptionData
Builds the description document bytes for a host.- Parameters:
host- the host to embed- Returns:
- the description bytes
httpGetRequestRecieved
Handles a GET request to the device's server.- Parameters:
httpReq- the request received
httpPostRequestRecieved
Handles a POST request to the device's server.- Parameters:
httpReq- the request received
soapBadActionRecieved
Answers a SOAP request with an unknown action.- Parameters:
soapReq- the request received
soapActionRecieved
Handles a SOAP action request.- Parameters:
soapReq- the request received
deviceControlRequestRecieved
Dispatches a control request to the right service.- Parameters:
ctlReq- the control requestservice- the target service
invalidActionControlRecieved
Answers a control request naming an invalid action.- Parameters:
ctlReq- the control request
invalidArgumentsControlRecieved
Answers a control request with invalid arguments.- Parameters:
ctlReq- the control request
deviceActionControlRecieved
Runs an action on the target service.- Parameters:
ctlReq- the action requestservice- the target service
deviceQueryControlRecieved
Answers a state variable query.- Parameters:
ctlReq- the query requestservice- the target service
upnpBadSubscriptionRecieved
Answers a subscription request with an error code.- Parameters:
subReq- the subscription requestcode- the error code to return
deviceEventSubscriptionRecieved
Dispatches an event subscription request.- Parameters:
subReq- the subscription request
deviceEventNewSubscriptionRecieved
Creates a new event subscription.- Parameters:
service- the subscribed servicesubReq- the subscription request
deviceEventRenewSubscriptionRecieved
Renews an existing event subscription.- Parameters:
service- the subscribed servicesubReq- the subscription request
deviceEventUnsubscriptionRecieved
Cancels an event subscription.- Parameters:
service- the subscribed servicesubReq- the subscription request
getHTTPServerList
Returns the running HTTP servers, starting them if needed.- Returns:
- the server list
setSSDPPort
public void setSSDPPort(int port) Set the port the SSDP service binds to.- Parameters:
port- The port to use for binding the SSDP service
getSSDPPort
public int getSSDPPort()Get the port the SSDP service binds to.- Returns:
- The port to use for binding the SSDP service
setSSDPBindAddress
Set the addresses the SSDP service binds to.- Parameters:
inets- The IP that will be used for binding the SSDP service. Usenullto get the default behavior
getSSDPBindAddress
Get the addresses the SSDP service binds to.- Returns:
- inets The IP that will be used for binding the SSDP service. null means the default set by the class UPnP
setMulticastIPv4Address
Set the IPv4 address SSDP multicasts to.- Parameters:
ip- The IPv4 address used for Multicast communication
getMulticastIPv4Address
Get the IPv4 address SSDP multicasts to.- Returns:
- The IPv4 address used for Multicast communication
setMulticastIPv6Address
Set the IPv6 address SSDP multicasts to.- Parameters:
ip- The IPv address used for Multicast communication
getMulticastIPv6Address
Get the IPv6 address SSDP multicasts to.- Returns:
- The IPv address used for Multicast communication
getSSDPSearchSocketList
Returns the SSDP search sockets, starting them if needed.- Returns:
- the socket list
setAdvertiser
Sets the advertiser sending alive messages.- Parameters:
adv- the advertiser sending alive messages
getAdvertiser
Returns the advertiser sending alive messages.- Returns:
- the advertiser sending alive messages
start
public boolean start()Starts the HTTP server and begins SSDP advertising for this device.- Returns:
- true if the device was started
stop
private boolean stop(boolean doByeBye) Stops the device's servers and advertiser.- Parameters:
doByeBye- true to send byebye notifications- Returns:
- true on success
stop
public boolean stop()Stops SSDP advertising and shuts down the HTTP server.- Returns:
- true if the device was stopped
isRunning
public boolean isRunning()Tests whether this device's advertiser is running.- Returns:
- true if the device is running
getInterfaceAddress
Gets the local address this device was announced from.- Returns:
- the address this device was discovered on, or an empty string
setActionListener
Installs the action handler on every service of this device.- Parameters:
listener- the handler for incoming action requests
setQueryListener
Installs the query handler on every service of this device.- Parameters:
listener- the handler for incoming variable queries
setActionListener
Installs the action handler on every service, optionally descending into embedded devices.- Parameters:
listener- the handler for incoming action requestsincludeSubDevices- true to set the handler on embedded devices too
setQueryListener
Installs the query handler on every service, optionally descending into embedded devices.- Parameters:
listener- the handler for incoming variable queriesincludeSubDevices- true to set the handler on embedded devices too
setUserData
Attaches caller-defined data to this device's node.- Parameters:
data- any object; only read back bygetUserData()
getUserData
Gets the caller-defined data attached to this device's node.- Returns:
- whatever was passed to
setUserData(Object), or null if none was