org.cybergarage.upnp

## Class Device

- java.lang.Object
- - org.cybergarage.upnp.Device

- All Implemented Interfaces:
    HTTPRequestListener, SearchListener

      public class Device
      extends 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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_DESCRIPTION_URI`
    `static int` | `DEFAULT_DISCOVERY_WAIT_TIME`
    `static int` | `DEFAULT_LEASE_TIME`
    `static String` | `DEFAULT_PRESENTATION_URI`
    `static int` | `DEFAULT_STARTUP_WAIT_TIME`
    `static String` | `ELEM_NAME`
    `static int` | `HTTP_DEFAULT_PORT`
    `static String` | `UPNP_ROOTDEVICE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Device()`
    `Device(File descriptionFile)`
    `Device(InputStream input)`
    `Device(Node device)`
    `Device(Node root, Node device)`
    `Device(String descriptionFileName)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDevice(Device d)` Add a Device to device without checking for duplicate or syntax error.
    `boolean` | `addIcon(Icon icon)`
    `void` | `addService(Service s)` Add a Service to device without checking for duplicate or syntax error
    `void` | `announce()`
    `void` | `announce(String bindAddr)`
    `void` | `byebye()`
    `void` | `byebye(String bindAddr)`
    `void` | `deviceSearchReceived(SSDPPacket ssdpPacket)` Called when an SSDP search request is received from a UPnP control point.
    `void` | `deviceSearchResponse(SSDPPacket ssdpPacket)`
    `String` | `getAbsoluteURL(String urlString)`
    `String` | `getAbsoluteURL(String urlString, String baseURLStr, String locationURLStr)`
    `Action` | `getAction(String name)`
    `int` | `getBootId()`
    `int` | `getConfigId()`
    `File` | `getDescriptionFile()`
    `String` | `getDescriptionFilePath()`
    `Device` | `getDevice(String name)`
    `Device` | `getDeviceByDescriptionURI(String uri)`
    `DeviceList` | `getDeviceList()`
    `Node` | `getDeviceNode()`
    `String` | `getDeviceType()`
    `long` | `getElapsedTime()`
    `String` | `getFriendlyName()`
    `InetAddress[]` | `getHTTPBindAddress()`
    `int` | `getHTTPPort()`
    `Icon` | `getIcon(int n)`
    `Icon` | `getIconByURI(String uri)`
    `IconList` | `getIconList()`
    `String` | `getInterfaceAddress()`
    `int` | `getLeaseTime()`
    `String` | `getLocation()`
    `String` | `getLocation(boolean preferIPv6)` I2P for multiple location support
    `String` | `getLocationURL(String host)`
    `String` | `getManufacture()`
    `String` | `getManufactureURL()`
    `String` | `getModelDescription()`
    `String` | `getModelName()`
    `String` | `getModelNumber()`
    `String` | `getModelURL()`
    `String` | `getMulticastIPv4Address()`
    `String` | `getMulticastIPv6Address()`
    `Device` | `getParentDevice()`
    `PresentationListener` | `getPresentationListener()`
    `String` | `getPresentationURL()`
    `Device` | `getRootDevice()`
    `Node` | `getRootNode()`
    `String` | `getSerialNumber()`
    `Service` | `getService(String name)`
    `Service` | `getServiceByControlURL(String searchUrl)`
    `Service` | `getServiceByEventSubURL(String searchUrl)`
    `Service` | `getServiceBySCPDURL(String searchUrl)`
    `ServiceList` | `getServiceList()`
    `Icon` | `getSmallestIcon()`
    `int` | `getSSDPAnnounceCount()`
    `InetAddress[]` | `getSSDPBindAddress()`
    `String` | `getSSDPIPv4MulticastAddress()`
    `void` | `getSSDPIPv4MulticastAddress(String ip)`
    `String` | `getSSDPIPv6MulticastAddress()`
    `void` | `getSSDPIPv6MulticastAddress(String ip)`
    `SSDPPacket` | `getSSDPPacket()`
    `SSDPPacket` | `getSSDPPacket(boolean preferIPv6)` I2P for multiple location support
    `int` | `getSSDPPort()`
    `StateVariable` | `getStateVariable(String name)`
    `StateVariable` | `getStateVariable(String serviceType, String name)`
    `Service` | `getSubscriberService(String uuid)`
    `long` | `getTimeStamp()`
    `String` | `getUDN()`
    `String` | `getUPC()`
    `String` | `getURLBase()`
    `Object` | `getUserData()`
    `String` | `getUUID()`
    `boolean` | `hasPresentationListener()`
    `boolean` | `hasUDN()`
    `void` | `httpRequestRecieved(HTTPRequest httpReq)` Called when an HTTP request is received.
    `boolean` | `isDevice(String name)`
    `static boolean` | `isDeviceNode(Node node)`
    `boolean` | `isDeviceType(String value)`
    `boolean` | `isExpired()`
    `boolean` | `isIconBytesURI(String uri)`
    `boolean` | `isNMPRMode()`
    `boolean` | `isRootDevice()`
    `boolean` | `isRunning()`
    `boolean` | `isWirelessMode()`
    `boolean` | `loadDescription(File file)`
    `boolean` | `loadDescription(InputStream input)`
    `boolean` | `loadDescription(String descString)`
    `void` | `lock()`
    `static void` | `notifyWait()`
    `boolean` | `postSearchResponse(SSDPPacket ssdpPacket, String st, String usn)`
    `boolean` | `removePresentationURL()`
    `void` | `setActionListener(ActionListener listener)`
    `void` | `setActionListener(ActionListener listener, boolean includeSubDevices)`
    `void` | `setDeviceNode(Node node)`
    `void` | `setDeviceType(String value)`
    `void` | `setFriendlyName(String value)`
    `void` | `setHTTPBindAddress(InetAddress[] inets)`
    `void` | `setHTTPPort(int port)`
    `void` | `setLeaseTime(int value)`
    `void` | `setLocation(String value)`
    `void` | `setManufacture(String value)`
    `void` | `setManufactureURL(String value)`
    `void` | `setModelDescription(String value)`
    `void` | `setModelName(String value)`
    `void` | `setModelNumber(String value)`
    `void` | `setModelURL(String value)`
    `void` | `setMulticastIPv4Address(String ip)`
    `void` | `setMulticastIPv6Address(String ip)`
    `void` | `setNMPRMode(boolean flag)`
    `void` | `setPresentationListener(PresentationListener listener)`
    `void` | `setPresentationURL(String value)`
    `void` | `setQueryListener(QueryListener listener)`
    `void` | `setQueryListener(QueryListener listener, boolean includeSubDevices)`
    `void` | `setRootNode(Node node)`
    `void` | `setSerialNumber(String value)`
    `void` | `setSSDPBindAddress(InetAddress[] inets)`
    `void` | `setSSDPPacket(SSDPPacket packet)`
    `void` | `setSSDPPort(int port)`
    `void` | `setUDN(String value)`
    `void` | `setUPC(String value)`
    `void` | `setUserData(Object data)`
    `void` | `setWirelessMode(boolean flag)`
    `boolean` | `start()`
    `boolean` | `stop()`
    `void` | `unlock()`
    `void` | `updateConfigId()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_DESCRIPTION_URI

          public static final String DEFAULT_DESCRIPTION_URI

      See Also:
        Constant Field Values

    - #### DEFAULT_DISCOVERY_WAIT_TIME

          public static final int DEFAULT_DISCOVERY_WAIT_TIME

      See Also:
        Constant Field Values

    - #### DEFAULT_LEASE_TIME

          public static final int DEFAULT_LEASE_TIME

      See Also:
        Constant Field Values

    - #### DEFAULT_PRESENTATION_URI

          public static final String DEFAULT_PRESENTATION_URI

      See Also:
        Constant Field Values

    - #### DEFAULT_STARTUP_WAIT_TIME

          public static final int DEFAULT_STARTUP_WAIT_TIME

      See Also:
        Constant Field Values

    - #### ELEM_NAME

          public static final String ELEM_NAME

      See Also:
        Constant Field Values

    - #### HTTP_DEFAULT_PORT

          public static final int HTTP_DEFAULT_PORT

      See Also:
        Constant Field Values

    - #### UPNP_ROOTDEVICE

          public static final String UPNP_ROOTDEVICE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Device

          public Device()

    - #### Device

          public Device(File descriptionFile)
                 throws InvalidDescriptionException

      Throws:
        `InvalidDescriptionException`

    - #### Device

          public Device(InputStream input)
                 throws InvalidDescriptionException

      Throws:
        `InvalidDescriptionException`

    - #### Device

          public Device(Node device)

    - #### Device

          public Device(Node root,
                        Node device)

    - #### Device

          public Device(String descriptionFileName)
                 throws InvalidDescriptionException

      Throws:
        `InvalidDescriptionException`

  - ### Method Detail

    - #### 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 withtout writing any XML that describe the device
      Parameters:
        `d` - Add Device d to the Device

    - #### addIcon

          public boolean addIcon(Icon icon)

    - #### 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

    - #### announce

          public void announce()

    - #### announce

          public void announce(String bindAddr)

    - #### byebye

          public void byebye()

    - #### byebye

          public void byebye(String bindAddr)

    - #### deviceSearchReceived

          public void deviceSearchReceived(SSDPPacket ssdpPacket)

      Description copied from interface: `SearchListener`
      Called when an SSDP search request is received from a UPnP control point.
      Specified by:
        `deviceSearchReceived` in interface `SearchListener`
      Parameters:
        `ssdpPacket` - received SSDP packet containing search request data

    - #### deviceSearchResponse

          public void deviceSearchResponse(SSDPPacket ssdpPacket)

    - #### getAbsoluteURL

          public String getAbsoluteURL(String urlString)

    - #### getAbsoluteURL

          public String getAbsoluteURL(String urlString,
                                       String baseURLStr,
                                       String locationURLStr)

    - #### getAction

          public Action getAction(String name)

    - #### getBootId

          public int getBootId()

    - #### getConfigId

          public int getConfigId()

    - #### getDescriptionFile

          public File getDescriptionFile()

    - #### getDescriptionFilePath

          public String getDescriptionFilePath()

    - #### getDevice

          public Device getDevice(String name)

    - #### getDeviceByDescriptionURI

          public Device getDeviceByDescriptionURI(String uri)

    - #### getDeviceList

          public DeviceList getDeviceList()

    - #### getDeviceNode

          public Node getDeviceNode()

    - #### getDeviceType

          public String getDeviceType()

    - #### getElapsedTime

          public long getElapsedTime()

    - #### getFriendlyName

          public String getFriendlyName()

    - #### getHTTPBindAddress

          public InetAddress[] getHTTPBindAddress()

    - #### getHTTPPort

          public int getHTTPPort()

    - #### getIcon

          public Icon getIcon(int n)

    - #### getIconByURI

          public Icon getIconByURI(String uri)

    - #### getIconList

          public IconList getIconList()

    - #### getInterfaceAddress

          public String getInterfaceAddress()

    - #### getLeaseTime

          public int getLeaseTime()

    - #### getLocation

          public String getLocation()

    - #### getLocation

          public String getLocation(boolean preferIPv6)

      I2P for multiple location support

    - #### getLocationURL

          public String getLocationURL(String host)

    - #### getManufacture

          public String getManufacture()

    - #### getManufactureURL

          public String getManufactureURL()

    - #### getModelDescription

          public String getModelDescription()

    - #### getModelName

          public String getModelName()

    - #### getModelNumber

          public String getModelNumber()

    - #### getModelURL

          public String getModelURL()

    - #### getMulticastIPv4Address

          public String getMulticastIPv4Address()

      Returns:
        The IPv4 address used for Multicast comunication

    - #### getMulticastIPv6Address

          public String getMulticastIPv6Address()

      Returns:
        The IPv address used for Multicast comunication

    - #### getParentDevice

          public Device getParentDevice()

      Returns:
        A Device that contain this object.
        Return `null` if this is a root device.

    - #### getPresentationListener

          public PresentationListener getPresentationListener()

    - #### getPresentationURL

          public String getPresentationURL()

    - #### getRootDevice

          public Device getRootDevice()

    - #### getRootNode

          public Node getRootNode()

    - #### getSerialNumber

          public String getSerialNumber()

    - #### getService

          public Service getService(String name)

    - #### getServiceByControlURL

          public Service getServiceByControlURL(String searchUrl)

    - #### getServiceByEventSubURL

          public Service getServiceByEventSubURL(String searchUrl)

    - #### getServiceBySCPDURL

          public Service getServiceBySCPDURL(String searchUrl)

    - #### getServiceList

          public ServiceList getServiceList()

    - #### getSmallestIcon

          public Icon getSmallestIcon()

    - #### getSSDPAnnounceCount

          public int getSSDPAnnounceCount()

    - #### getSSDPBindAddress

          public InetAddress[] getSSDPBindAddress()

      Returns:
        inets The IP that will be used for binding the SSDP service. null means the default setted by the class UPnP

    - #### getSSDPIPv4MulticastAddress

          public String getSSDPIPv4MulticastAddress()

      Returns:
        SSDPIPv4MulticastAddress

    - #### getSSDPIPv4MulticastAddress

          public void getSSDPIPv4MulticastAddress(String ip)

      Parameters:
        `ip` -

    - #### getSSDPIPv6MulticastAddress

          public String getSSDPIPv6MulticastAddress()

      Returns:
        SSDPIPv6MulticastAddress

    - #### getSSDPIPv6MulticastAddress

          public void getSSDPIPv6MulticastAddress(String ip)

      Parameters:
        `ip` -

    - #### getSSDPPacket

          public SSDPPacket getSSDPPacket()

    - #### getSSDPPacket

          public SSDPPacket getSSDPPacket(boolean preferIPv6)

      I2P for multiple location support

    - #### getSSDPPort

          public int getSSDPPort()

      Returns:
        The port to use for binding the SSDP service

    - #### getStateVariable

          public StateVariable getStateVariable(String name)

    - #### getStateVariable

          public StateVariable getStateVariable(String serviceType,
                                                String name)

    - #### getSubscriberService

          public Service getSubscriberService(String uuid)

    - #### getTimeStamp

          public long getTimeStamp()

    - #### getUDN

          public String getUDN()

    - #### getUPC

          public String getUPC()

    - #### getURLBase

          public String getURLBase()

    - #### getUserData

          public Object getUserData()

    - #### getUUID

          public String getUUID()

    - #### hasPresentationListener

          public boolean hasPresentationListener()

    - #### hasUDN

          public boolean hasUDN()

    - #### httpRequestRecieved

          public void httpRequestRecieved(HTTPRequest httpReq)

      Description copied from interface: `HTTPRequestListener`
      Called when an HTTP request is received.
      Specified by:
        `httpRequestRecieved` in interface `HTTPRequestListener`
      Parameters:
        `httpReq` - the received HTTP request

    - #### isDevice

          public boolean isDevice(String name)

    - #### isDeviceNode

          public static boolean isDeviceNode(Node node)

    - #### isDeviceType

          public boolean isDeviceType(String value)

    - #### isExpired

          public boolean isExpired()

    - #### isIconBytesURI

          public boolean isIconBytesURI(String uri)

    - #### isNMPRMode

          public boolean isNMPRMode()

    - #### isRootDevice

          public boolean isRootDevice()

    - #### isRunning

          public boolean isRunning()

    - #### isWirelessMode

          public boolean isWirelessMode()

    - #### loadDescription

          public boolean loadDescription(File file)
                                  throws InvalidDescriptionException

      Throws:
        `InvalidDescriptionException`

    - #### loadDescription

          public boolean loadDescription(InputStream input)
                                  throws InvalidDescriptionException

      Throws:
        `InvalidDescriptionException`

    - #### loadDescription

          public boolean loadDescription(String descString)
                                  throws InvalidDescriptionException

      Throws:
        `InvalidDescriptionException`

    - #### lock

          public void lock()

    - #### notifyWait

          public static final void notifyWait()

    - #### postSearchResponse

          public boolean postSearchResponse(SSDPPacket ssdpPacket,
                                            String st,
                                            String usn)

    - #### removePresentationURL

          public boolean removePresentationURL()

    - #### setActionListener

          public void setActionListener(ActionListener listener)

    - #### setActionListener

          public void setActionListener(ActionListener listener,
                                        boolean includeSubDevices)

    - #### setDeviceNode

          public void setDeviceNode(Node node)

    - #### setDeviceType

          public void setDeviceType(String value)

    - #### setFriendlyName

          public void setFriendlyName(String value)

    - #### setHTTPBindAddress

          public void setHTTPBindAddress(InetAddress[] inets)

    - #### setHTTPPort

          public void setHTTPPort(int port)

    - #### setLeaseTime

          public void setLeaseTime(int value)

    - #### setLocation

          public void setLocation(String value)

    - #### setManufacture

          public void setManufacture(String value)

    - #### setManufactureURL

          public void setManufactureURL(String value)

    - #### setModelDescription

          public void setModelDescription(String value)

    - #### setModelName

          public void setModelName(String value)

    - #### setModelNumber

          public void setModelNumber(String value)

    - #### setModelURL

          public void setModelURL(String value)

    - #### setMulticastIPv4Address

          public void setMulticastIPv4Address(String ip)

      Parameters:
        `ip` - The IPv4 address used for Multicast comunication

    - #### setMulticastIPv6Address

          public void setMulticastIPv6Address(String ip)

      Parameters:
        `ip` - The IPv address used for Multicast comunication

    - #### setNMPRMode

          public void setNMPRMode(boolean flag)

    - #### setPresentationListener

          public void setPresentationListener(PresentationListener listener)

    - #### setPresentationURL

          public void setPresentationURL(String value)

    - #### setQueryListener

          public void setQueryListener(QueryListener listener)

    - #### setQueryListener

          public void setQueryListener(QueryListener listener,
                                       boolean includeSubDevices)

    - #### setRootNode

          public void setRootNode(Node node)

    - #### setSerialNumber

          public void setSerialNumber(String value)

    - #### setSSDPBindAddress

          public void setSSDPBindAddress(InetAddress[] inets)

      Parameters:
        `inets` - The IP that will be used for binding the SSDP service. Use `null` to get the default beahvior

    - #### setSSDPPacket

          public void setSSDPPacket(SSDPPacket packet)

    - #### setSSDPPort

          public void setSSDPPort(int port)

      Parameters:
        `port` - The port to use for binding the SSDP service

    - #### setUDN

          public void setUDN(String value)

    - #### setUPC

          public void setUPC(String value)

    - #### setUserData

          public void setUserData(Object data)

    - #### setWirelessMode

          public void setWirelessMode(boolean flag)

    - #### start

          public boolean start()

    - #### stop

          public boolean stop()

    - #### unlock

          public void unlock()

    - #### updateConfigId

          public void updateConfigId()