java.lang.Object
org.cybergarage.upnp.Device
All Implemented Interfaces:
HTTPRequestListener, SearchListener

public class Deviceextends Object implements 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 Details

    • ELEM_NAME

      public static final String ELEM_NAME
      Element name of a device node in the description document.
      See Also:
    • UPNP_ROOTDEVICE

      public static final String UPNP_ROOTDEVICE
      Element name marking the root of a description document.
      See Also:
    • DEFAULT_STARTUP_WAIT_TIME

      public static final int DEFAULT_STARTUP_WAIT_TIME
      Milliseconds to wait before sending the first SSDP announcement.
      See Also:
    • DEFAULT_DISCOVERY_WAIT_TIME

      public static final int DEFAULT_DISCOVERY_WAIT_TIME
      Milliseconds to wait between repeats of an SSDP search.
      See Also:
    • DEFAULT_LEASE_TIME

      public static final int DEFAULT_LEASE_TIME
      Advertisement lifetime in seconds assigned to a freshly loaded description.
      See Also:
    • HTTP_DEFAULT_PORT

      public static final int HTTP_DEFAULT_PORT
      Port the built-in HTTP server binds to when none is set.
      See Also:
    • DEFAULT_DESCRIPTION_URI

      public static final String DEFAULT_DESCRIPTION_URI
      Path served for the device description document.
      See Also:
    • DEFAULT_PRESENTATION_URI

      public static final String DEFAULT_PRESENTATION_URI
      Path served for the device's presentation page.
      See Also:
    • rootNode

      private Node rootNode
      The root node of the description document.
    • deviceNode

      private Node deviceNode
      This device's node within the description.
    • mutex

      private Mutex mutex
      Lock guarding the device's state.
    • wirelessMode

      private boolean wirelessMode
      Whether wireless mode is on for notifications.
    • devUUID

      private String devUUID
      The device's UUID, without the UDN prefix.
    • bootId

      private int bootId
      The boot id advertised in notifications.
    • CONFIG_ID

      private static final String CONFIG_ID
      Tag name for the configuration id.
      See Also:
    • URLBASE_NAME

      private static final String URLBASE_NAME
      Tag name for the base URL.
      See Also:
    • DEVICE_TYPE

      private static final String DEVICE_TYPE
      Tag name for the device type.
      See Also:
    • FRIENDLY_NAME

      private static final String FRIENDLY_NAME
      Tag name for the friendly name.
      See Also:
    • MANUFACTURE

      private static final String MANUFACTURE
      Tag name for the manufacturer.
      See Also:
    • MANUFACTURE_URL

      private static final String MANUFACTURE_URL
      Tag name for the manufacturer URL.
      See Also:
    • MODEL_DESCRIPTION

      private static final String MODEL_DESCRIPTION
      Tag name for the model description.
      See Also:
    • MODEL_NAME

      private static final String MODEL_NAME
      Tag name for the model name.
      See Also:
    • MODEL_NUMBER

      private static final String MODEL_NUMBER
      Tag name for the model number.
      See Also:
    • MODEL_URL

      private static final String MODEL_URL
      Tag name for the model URL.
      See Also:
    • SERIAL_NUMBER

      private static final String SERIAL_NUMBER
      Tag name for the serial number.
      See Also:
    • UDN

      private static final String UDN
      Tag name for the unique device name.
      See Also:
    • UPC

      private static final String UPC
      Tag name for the UPC code.
      See Also:
    • presentationURL

      private static final String presentationURL
      Tag name for the presentation URL.
      See Also:
    • presentationListener

      private PresentationListener presentationListener
      Listener notified of presentation requests.
    • iconBytesMap

      private HashMap<String,byte[]> iconBytesMap
      Icon data by icon id.
    • cal

      private static Calendar cal
      Shared calendar for formatting dates.
    • userData

      private Object userData
      Arbitrary data attached by the application.
  • Constructor Details

    • Device

      public Device(Node root, Node device)
      Creates a device from a root description node and its own node.
      Parameters:
      root - the node holding the root description, or null
      device - this device's own device element
    • Device

      public Device()
      Creates an empty device with no description nodes.
    • Device

      public Device(Node device)
      Creates a device with no root node but the given device node.
      Parameters:
      device - this device's own device element
    • Device

      public Device(File descriptionFile) throws InvalidDescriptionException
      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

      public Device(InputStream input) throws InvalidDescriptionException
      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

      public Device(String descriptionFileName) throws InvalidDescriptionException
      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

      public Node getRootNode()
      Gets the node holding this device's root description.
      Returns:
      the node holding the root description, or null
    • getDeviceNode

      public Node getDeviceNode()
      Gets this device's own element node.
      Returns:
      this device's own device element
    • setRootNode

      public void setRootNode(Node node)
      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

      public void setDeviceNode(Node node)
      Sets this device's own element node.
      Parameters:
      node - this device's own device element
    • lock

      public void lock()
      Acquires the mutex guarding this device.
    • unlock

      public void unlock()
      Releases the mutex guarding this device.
    • getAbsoluteURL

      public String getAbsoluteURL(String urlString, String baseURLStr, String locationURLStr)
      Resolves a possibly relative URL against a base URL and a description location.
      Parameters:
      urlString - the URL to resolve, which may be relative
      baseURLStr - the URLBase to resolve against, or null
      locationURLStr - the description location to resolve against, or null
      Returns:
      the resolved URL, or urlString itself if it cannot be resolved
    • getAbsoluteURL

      public String getAbsoluteURL(String urlString)
      Resolves a possibly relative URL against the root device's base and location.
      Parameters:
      urlString - the URL to resolve, which may be relative
      Returns:
      the URL resolved against the root device's URLBase and location
    • 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

      private void setUUID(String uuid)
      Sets the device's UUID and refreshes the UDN.
      Parameters:
      uuid - the new UUID
    • getUUID

      public String 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

      private void updateConfigId(Device dev)
      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

      public Device 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

      public Device getParentDevice()
      Get the device that contains this one.
      Returns:
      A Device that contain this object.
      Return null if this is a root device.
    • addService

      public void addService(Service s)
      Add a Service to device without checking for duplicate or syntax error
      Parameters:
      s - Add Service s to the Device
    • addDevice

      public void addDevice(Device d)
      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

      private DeviceData getDeviceData()
      Returns the device's data for notifications.
      Returns:
      the device data
    • setDescriptionFile

      private void setDescriptionFile(File file)
      Sets the file holding the description document.
      Parameters:
      file - the description file
    • getDescriptionFile

      public 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

      private void setDescriptionURI(String uri)
      Sets the URI the description is served at.
      Parameters:
      uri - the description URI
    • getDescriptionURI

      private String getDescriptionURI()
      Returns the URI the description is served at.
      Returns:
      the description URI
    • isDescriptionURI

      private boolean isDescriptionURI(String uri)
      Checks whether a URI names this device's description.
      Parameters:
      uri - the URI to check
      Returns:
      true if it is the description URI
    • getDescriptionFilePath

      public String 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

      public boolean loadDescription(InputStream input) throws InvalidDescriptionException
      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

      public boolean loadDescription(String descString) throws InvalidDescriptionException
      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

      public boolean loadDescription(File file) throws InvalidDescriptionException
      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

      public static boolean isDeviceNode(Node node)
      Tests whether a node is a device element.
      Parameters:
      node - the node to test
      Returns:
      true if the node is a device element
    • 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

      public void setSSDPPacket(SSDPPacket packet)
      Records the SSDP packet that announced this device.
      Parameters:
      packet - the SSDP packet that announced this device
    • getSSDPPacket

      public SSDPPacket getSSDPPacket()
      Gets the SSDP packet that announced this device.
      Returns:
      the SSDP packet that announced this device, or null
    • getSSDPPacket

      public SSDPPacket getSSDPPacket(boolean preferIPv6)
      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

      public void setLocation(String value)
      Sets the URL this device's description is served from.
      Parameters:
      value - the URL the description is served from
    • getLocation

      public String getLocation()
      Gets the URL this device's description is served from.
      Returns:
      the URL the description is served from
    • getLocation

      public String getLocation(boolean preferIPv6)
      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

      private void setURLBase(String value)
      Sets the base URL for service URLs.
      Parameters:
      value - the base URL
    • updateURLBase

      private void updateURLBase(String host)
      Rewrites the base URL for a host.
      Parameters:
      host - the host name to use
    • getURLBase

      public String 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

      public void setDeviceType(String value)
      Sets the device type URN.
      Parameters:
      value - the device type URN
    • getDeviceType

      public String getDeviceType()
      Gets the device type URN.
      Returns:
      the device type URN
    • isDeviceType

      public boolean isDeviceType(String value)
      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

      public void setFriendlyName(String value)
      Sets the name advertised for this device.
      Parameters:
      value - the name to advertise for this device
    • getFriendlyName

      public String getFriendlyName()
      Gets the name advertised for this device.
      Returns:
      the name advertised for this device
    • setManufacture

      public void setManufacture(String value)
      Sets the name of the company that makes this device.
      Parameters:
      value - the name of the company that makes this device
    • getManufacture

      public String getManufacture()
      Gets the name of the company that makes this device.
      Returns:
      the name of the company that makes this device
    • setManufactureURL

      public void setManufactureURL(String value)
      Sets the URL of the manufacturer's home page.
      Parameters:
      value - the URL of the manufacturer's home page
    • getManufactureURL

      public String getManufactureURL()
      Gets the URL of the manufacturer's home page.
      Returns:
      the URL of the manufacturer's home page
    • setModelDescription

      public void setModelDescription(String value)
      Sets the free-form description of this model.
      Parameters:
      value - the free-form description of this model
    • getModelDescription

      public String getModelDescription()
      Gets the free-form description of this model.
      Returns:
      the free-form description of this model
    • setModelName

      public void setModelName(String value)
      Sets the model name.
      Parameters:
      value - the model name
    • getModelName

      public String getModelName()
      Gets the model name.
      Returns:
      the model name
    • setModelNumber

      public void setModelNumber(String value)
      Sets the model number.
      Parameters:
      value - the model number
    • getModelNumber

      public String getModelNumber()
      Gets the model number.
      Returns:
      the model number
    • setModelURL

      public void setModelURL(String value)
      Sets the URL of the documentation for this model.
      Parameters:
      value - the URL of the documentation for this model
    • getModelURL

      public String getModelURL()
      Gets the URL of the documentation for this model.
      Returns:
      the URL of the documentation for this model
    • setSerialNumber

      public void setSerialNumber(String value)
      Sets the serial number of this unit.
      Parameters:
      value - the serial number of this unit
    • getSerialNumber

      public String getSerialNumber()
      Gets the serial number of this unit.
      Returns:
      the serial number of this unit
    • setUDN

      public void setUDN(String value)
      Sets the unique device name.
      Parameters:
      value - the unique device name, this device's UUID prefixed with uuid:
    • getUDN

      public String getUDN()
      Gets the unique device name.
      Returns:
      the unique device name
    • hasUDN

      public boolean hasUDN()
      Tests whether a non-empty unique device name is set.
      Returns:
      true if a non-empty UDN is set
    • setUPC

      public void setUPC(String value)
      Sets the Universal Product Code.
      Parameters:
      value - the Universal Product Code
    • getUPC

      public String getUPC()
      Gets the Universal Product Code.
      Returns:
      the Universal Product Code
    • setPresentationURL

      public void setPresentationURL(String value)
      Sets the URI path serving this device's control page.
      Parameters:
      value - the URI path serving this device's control page
    • getPresentationURL

      public String 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

      private boolean isPresentationRequest(HTTPRequest httpReq)
      Checks whether a request targets the presentation URL.
      Parameters:
      httpReq - the request to check
      Returns:
      true if it is a presentation request
    • setPresentationListener

      public void setPresentationListener(PresentationListener listener)
      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

      public PresentationListener getPresentationListener()
      Gets the handler for this device's control page.
      Returns:
      the handler for control page requests, or null
    • getDeviceList

      public DeviceList getDeviceList()
      Gets the devices embedded in this one.
      Returns:
      the devices embedded in this one
    • isDevice

      public boolean isDevice(String name)
      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

      public Device getDevice(String name)
      Finds an embedded device by UDN, friendly name or device type.
      Parameters:
      name - the UDN, friendly name or device type to search for
      Returns:
      the matching embedded device, or null
    • getDeviceByDescriptionURI

      public Device getDeviceByDescriptionURI(String uri)
      Finds an embedded device served at the given description URI.
      Parameters:
      uri - the description URI to search for
      Returns:
      the embedded device served at that URI, or null
    • getServiceList

      public ServiceList getServiceList()
      Gets the services of this device.
      Returns:
      the services of this device
    • getService

      public Service getService(String name)
      Finds a service of this or an embedded device by type or ID.
      Parameters:
      name - the service type or service ID to search for
      Returns:
      the matching service of this or an embedded device, or null
    • getServiceBySCPDURL

      public Service getServiceBySCPDURL(String searchUrl)
      Finds a service by its service control description (SCPD) URL.
      Parameters:
      searchUrl - the service control URL to search for
      Returns:
      the matching service of this or an embedded device, or null
    • getServiceByControlURL

      public Service getServiceByControlURL(String searchUrl)
      Finds a service by its control URL.
      Parameters:
      searchUrl - the control URL to search for
      Returns:
      the matching service of this or an embedded device, or null
    • getServiceByEventSubURL

      public Service getServiceByEventSubURL(String searchUrl)
      Finds a service by its event subscription URL.
      Parameters:
      searchUrl - the event subscription URL to search for
      Returns:
      the matching service of this or an embedded device, or null
    • getSubscriberService

      public Service getSubscriberService(String uuid)
      Finds the service a subscriber holds a subscription on.
      Parameters:
      uuid - the subscription ID to search for
      Returns:
      the subscribed service with that ID, or null
    • getStateVariable

      public StateVariable getStateVariable(String serviceType, String name)
      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 service
      name - the state variable name to search for
      Returns:
      the matching state variable, or null
    • getStateVariable

      public StateVariable getStateVariable(String name)
      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

      public Action getAction(String name)
      Finds an action by name across every service.
      Parameters:
      name - the action name to search for
      Returns:
      the matching action, or null
    • isIconBytesURI

      public boolean isIconBytesURI(String uri)
      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

      public Icon getIconByURI(String uri)
      Finds an icon by its URL.
      Parameters:
      uri - the icon URL to search for
      Returns:
      the matching icon, or null
    • addIcon

      public boolean addIcon(Icon icon)
      Appends an icon to this device's icon list.
      Parameters:
      icon - the icon to add
      Returns:
      true if the icon was added
    • getIconList

      public IconList getIconList()
      Gets the icons of this device.
      Returns:
      the icons of this device
    • getIcon

      public Icon getIcon(int n)
      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

      public Icon getSmallestIcon()
      Finds the icon with the narrowest width.
      Returns:
      the narrowest icon, or null if this device has none
    • getLocationURL

      public String getLocationURL(String host)
      Builds the URL this device's description is served from on a given host.
      Parameters:
      host - the address this device is reached on
      Returns:
      the URL its description is served from on that address
    • getNotifyDeviceNT

      private String getNotifyDeviceNT()
      Returns the notification header for the device.
      Returns:
      the NT value
    • getNotifyDeviceUSN

      private String getNotifyDeviceUSN()
      Returns the notification USN for the device.
      Returns:
      the USN value
    • getNotifyDeviceTypeNT

      private String getNotifyDeviceTypeNT()
      Returns the notification header for the device type.
      Returns:
      the NT value
    • getNotifyDeviceTypeUSN

      private String 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

      public void announce(String bindAddr)
      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

      public void byebye(String bindAddr)
      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

      public boolean postSearchResponse(SSDPPacket ssdpPacket, String st, String usn)
      Sends a search response naming this device's root description.
      Parameters:
      ssdpPacket - the search request being answered
      st - the search target being answered
      usn - the unique service name naming this device
      Returns:
      true if the response was sent
    • deviceSearchResponse

      public void deviceSearchResponse(SSDPPacket ssdpPacket)
      Answers a search request for every device in this tree that matches it.
      Parameters:
      ssdpPacket - the search request to answer
    • deviceSearchReceived

      public void deviceSearchReceived(SSDPPacket ssdpPacket)
      Handles an incoming search request by answering it.
      Specified by:
      deviceSearchReceived in interface SearchListener
      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

      public void setHTTPBindAddress(InetAddress[] inets)
      Sets the addresses the HTTP server binds to.
      Parameters:
      inets - the addresses to bind the HTTP server to, or null for the default
    • getHTTPBindAddress

      public InetAddress[] getHTTPBindAddress()
      Gets the addresses the HTTP server is bound to.
      Returns:
      the addresses the HTTP server is bound to
    • getSSDPIPv4MulticastAddress

      public String getSSDPIPv4MulticastAddress()
      Get the IPv4 address SSDP multicasts to.
      Returns:
      SSDPIPv4MulticastAddress
    • getSSDPIPv4MulticastAddress

      public void getSSDPIPv4MulticastAddress(String ip)
      Set the IPv4 address SSDP multicasts to.
      Parameters:
      ip - the IPv4 multicast address
    • getSSDPIPv6MulticastAddress

      public String getSSDPIPv6MulticastAddress()
      Get the IPv6 address SSDP multicasts to.
      Returns:
      SSDPIPv6MulticastAddress
    • getSSDPIPv6MulticastAddress

      public void getSSDPIPv6MulticastAddress(String ip)
      Set the IPv6 address SSDP multicasts to.
      Parameters:
      ip - the IPv6 multicast address
    • httpRequestRecieved

      public void httpRequestRecieved(HTTPRequest httpReq)
      Routes an incoming HTTP request to the presentation, GET, POST or event handler.
      Specified by:
      httpRequestRecieved in interface HTTPRequestListener
      Parameters:
      httpReq - the received HTTP request
    • getDescriptionData

      private byte[] getDescriptionData(String host)
      Builds the description document bytes for a host.
      Parameters:
      host - the host to embed
      Returns:
      the description bytes
    • httpGetRequestRecieved

      private void httpGetRequestRecieved(HTTPRequest httpReq)
      Handles a GET request to the device's server.
      Parameters:
      httpReq - the request received
    • httpPostRequestRecieved

      private void httpPostRequestRecieved(HTTPRequest httpReq)
      Handles a POST request to the device's server.
      Parameters:
      httpReq - the request received
    • soapBadActionRecieved

      private void soapBadActionRecieved(HTTPRequest soapReq)
      Answers a SOAP request with an unknown action.
      Parameters:
      soapReq - the request received
    • soapActionRecieved

      private void soapActionRecieved(HTTPRequest soapReq)
      Handles a SOAP action request.
      Parameters:
      soapReq - the request received
    • deviceControlRequestRecieved

      private void deviceControlRequestRecieved(ControlRequest ctlReq, Service service)
      Dispatches a control request to the right service.
      Parameters:
      ctlReq - the control request
      service - the target service
    • invalidActionControlRecieved

      private void invalidActionControlRecieved(ControlRequest ctlReq)
      Answers a control request naming an invalid action.
      Parameters:
      ctlReq - the control request
    • invalidArgumentsControlRecieved

      private void invalidArgumentsControlRecieved(ControlRequest ctlReq)
      Answers a control request with invalid arguments.
      Parameters:
      ctlReq - the control request
    • deviceActionControlRecieved

      private void deviceActionControlRecieved(ActionRequest ctlReq, Service service)
      Runs an action on the target service.
      Parameters:
      ctlReq - the action request
      service - the target service
    • deviceQueryControlRecieved

      private void deviceQueryControlRecieved(QueryRequest ctlReq, Service service)
      Answers a state variable query.
      Parameters:
      ctlReq - the query request
      service - the target service
    • upnpBadSubscriptionRecieved

      private void upnpBadSubscriptionRecieved(SubscriptionRequest subReq, int code)
      Answers a subscription request with an error code.
      Parameters:
      subReq - the subscription request
      code - the error code to return
    • deviceEventSubscriptionRecieved

      private void deviceEventSubscriptionRecieved(SubscriptionRequest subReq)
      Dispatches an event subscription request.
      Parameters:
      subReq - the subscription request
    • deviceEventNewSubscriptionRecieved

      private void deviceEventNewSubscriptionRecieved(Service service, SubscriptionRequest subReq)
      Creates a new event subscription.
      Parameters:
      service - the subscribed service
      subReq - the subscription request
    • deviceEventRenewSubscriptionRecieved

      private void deviceEventRenewSubscriptionRecieved(Service service, SubscriptionRequest subReq)
      Renews an existing event subscription.
      Parameters:
      service - the subscribed service
      subReq - the subscription request
    • deviceEventUnsubscriptionRecieved

      private void deviceEventUnsubscriptionRecieved(Service service, SubscriptionRequest subReq)
      Cancels an event subscription.
      Parameters:
      service - the subscribed service
      subReq - the subscription request
    • getHTTPServerList

      private HTTPServerList 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

      public void setSSDPBindAddress(InetAddress[] inets)
      Set the addresses the SSDP service binds to.
      Parameters:
      inets - The IP that will be used for binding the SSDP service. Use null to get the default behavior
    • getSSDPBindAddress

      public InetAddress[] 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

      public void setMulticastIPv4Address(String ip)
      Set the IPv4 address SSDP multicasts to.
      Parameters:
      ip - The IPv4 address used for Multicast communication
    • getMulticastIPv4Address

      public String getMulticastIPv4Address()
      Get the IPv4 address SSDP multicasts to.
      Returns:
      The IPv4 address used for Multicast communication
    • setMulticastIPv6Address

      public void setMulticastIPv6Address(String ip)
      Set the IPv6 address SSDP multicasts to.
      Parameters:
      ip - The IPv address used for Multicast communication
    • getMulticastIPv6Address

      public String getMulticastIPv6Address()
      Get the IPv6 address SSDP multicasts to.
      Returns:
      The IPv address used for Multicast communication
    • getSSDPSearchSocketList

      private SSDPSearchSocketList getSSDPSearchSocketList()
      Returns the SSDP search sockets, starting them if needed.
      Returns:
      the socket list
    • setAdvertiser

      private void setAdvertiser(Advertiser adv)
      Sets the advertiser sending alive messages.
      Parameters:
      adv - the advertiser sending alive messages
    • getAdvertiser

      private Advertiser 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

      public String getInterfaceAddress()
      Gets the local address this device was announced from.
      Returns:
      the address this device was discovered on, or an empty string
    • setActionListener

      public void setActionListener(ActionListener listener)
      Installs the action handler on every service of this device.
      Parameters:
      listener - the handler for incoming action requests
    • setQueryListener

      public void setQueryListener(QueryListener listener)
      Installs the query handler on every service of this device.
      Parameters:
      listener - the handler for incoming variable queries
    • setActionListener

      public void setActionListener(ActionListener listener, boolean includeSubDevices)
      Installs the action handler on every service, optionally descending into embedded devices.
      Parameters:
      listener - the handler for incoming action requests
      includeSubDevices - true to set the handler on embedded devices too
    • setQueryListener

      public void setQueryListener(QueryListener listener, boolean includeSubDevices)
      Installs the query handler on every service, optionally descending into embedded devices.
      Parameters:
      listener - the handler for incoming variable queries
      includeSubDevices - true to set the handler on embedded devices too
    • setUserData

      public void setUserData(Object data)
      Attaches caller-defined data to this device's node.
      Parameters:
      data - any object; only read back by getUserData()
    • getUserData

      public Object getUserData()
      Gets the caller-defined data attached to this device's node.
      Returns:
      whatever was passed to setUserData(Object), or null if none was