java.lang.Object
org.cybergarage.upnp.ControlPoint
All Implemented Interfaces:
HTTPRequestListener
Direct Known Subclasses:
UPnP

public class ControlPointextends Object implements HTTPRequestListener
Main UPnP control point implementation for device discovery and control.

This class implements HTTPRequestListener to provide comprehensive UPnP control point functionality including device discovery, service enumeration, action invocation, and event subscription management. It serves as the primary interface for UPnP control applications.

Key features:

  • SSDP device discovery and advertisement monitoring
  • HTTP server for receiving control requests
  • Device and service lifecycle management
  • Event subscription and notification handling
  • SOAP action invocation and response processing
  • Multi-homed network interface support
  • Expired device cleanup and monitoring

This class is used by UPnP control applications to discover, control, and monitor UPnP devices on the network, providing a complete framework for building UPnP control point functionality.

  • Field Details

    • DEFAULT_EVENTSUB_PORT

      private static final int DEFAULT_EVENTSUB_PORT
      Default port for the event subscription callback.
      See Also:
    • DEFAULT_SSDP_PORT

      private static final int DEFAULT_SSDP_PORT
      Default port for SSDP discovery.
      See Also:
    • DEFAULT_EXPIRED_DEVICE_MONITORING_INTERVAL

      private static final int DEFAULT_EXPIRED_DEVICE_MONITORING_INTERVAL
      Default expired device check interval, in seconds.
      See Also:
    • DEFAULT_EVENTSUB_URI

      private static final String DEFAULT_EVENTSUB_URI
      Default URI for the event subscription callback.
      See Also:
    • ALLOW_IPV6_LOCATION

      private static final boolean ALLOW_IPV6_LOCATION
      True to allow IPv6 location URLs.
      See Also:
    • ssdpNotifySocketList

      private SSDPNotifySocketList ssdpNotifySocketList
      /////////////////////////////////////////////
    • ssdpSearchResponseSocketList

      private SSDPSearchResponseSocketList ssdpSearchResponseSocketList
      Sockets receiving the SSDP search responses.
    • mutex

      private Mutex mutex
      /////////////////////////////////////////////
    • ssdpPort

      private int ssdpPort
      /////////////////////////////////////////////
    • httpPort

      private int httpPort
      /////////////////////////////////////////////
    • nmprMode

      private boolean nmprMode
      /////////////////////////////////////////////
    • devNodeList

      private NodeList devNodeList
      /////////////////////////////////////////////
    • deviceDisposer

      private Disposer deviceDisposer
      /////////////////////////////////////////////
    • expiredDeviceMonitoringInterval

      private long expiredDeviceMonitoringInterval
      Interval between the expired device checks.
    • deviceNotifyListenerList

      private ListenerList deviceNotifyListenerList
      /////////////////////////////////////////////
    • deviceSearchResponseListenerList

      private ListenerList deviceSearchResponseListenerList
      /////////////////////////////////////////////
    • deviceChangeListenerList

      ListenerList deviceChangeListenerList
      //////////////////////////////////////////////////////////////////
    • searchMx

      private int searchMx
      /////////////////////////////////////////////
    • httpServerList

      private HTTPServerList httpServerList
      /////////////////////////////////////////////
    • eventListenerList

      private ListenerList eventListenerList
      /////////////////////////////////////////////
    • eventSubURI

      private String eventSubURI
      /////////////////////////////////////////////
    • renewSubscriber

      private RenewSubscriber renewSubscriber
      /////////////////////////////////////////////
    • userData

      private Object userData
      /////////////////////////////////////////////
  • Constructor Details

    • ControlPoint

      public ControlPoint(int ssdpPort, int httpPort, InetAddress[] binds)
      Create a control point with specified ports and network bindings.
      Parameters:
      ssdpPort - the SSDP port
      httpPort - the HTTP port
      binds - the network interfaces to bind to, or null for all
    • ControlPoint

      public ControlPoint(int ssdpPort, int httpPort)
      Create a control point with specified SSDP and HTTP ports.
      Parameters:
      ssdpPort - the SSDP port
      httpPort - the HTTP port
    • ControlPoint

      public ControlPoint()
      Default constructor using default ports
  • Method Details

    • getSSDPNotifySocketList

      protected SSDPNotifySocketList getSSDPNotifySocketList()
      Get the SSDP notify socket list.
      Returns:
      the SSDP notify socket list
    • getSSDPSearchResponseSocketList

      protected SSDPSearchResponseSocketList getSSDPSearchResponseSocketList()
      Get the SSDP search response socket list.
      Returns:
      the SSDP search response socket list
    • finalize

      public void finalize()
    • lock

      public void lock()
      Lock the mutex
    • unlock

      public void unlock()
      Unlock the mutex
    • getSSDPPort

      public int getSSDPPort()
      Get the SSDP port.
      Returns:
      the port the SSDP search response sockets bind to
    • setSSDPPort

      public void setSSDPPort(int port)
      Set the SSDP port.
      Parameters:
      port - the port the SSDP search response sockets bind to
    • getHTTPPort

      public int getHTTPPort()
      Get the HTTP port.
      Returns:
      the port the event subscription HTTP server is reached on
    • setHTTPPort

      public void setHTTPPort(int port)
      Set the HTTP port.
      Parameters:
      port - the port the event subscription HTTP server is reached on
    • setNMPRMode

      public void setNMPRMode(boolean flag)
      Set the NMPR mode flag.
      Parameters:
      flag - true to enable NMPR mode
    • isNMPRMode

      public boolean isNMPRMode()
      Check if NMPR mode is enabled.
      Returns:
      true if NMPR mode is enabled
    • addDevice

      private void addDevice(Node rootNode)
      Adds a device described by the node.
      Parameters:
      rootNode - the device description node
    • addDevice

      private void addDevice(SSDPPacket ssdpPacket)
      Adds a device found in an SSDP packet.
      Parameters:
      ssdpPacket - the SSDP packet announcing the device
    • getDevice

      private Device getDevice(Node rootNode)
      Finds the device matching the description node.
      Parameters:
      rootNode - the device description node
      Returns:
      the device, null if absent
    • getDeviceList

      public DeviceList getDeviceList()
      Get the list of discovered devices.
      Returns:
      the list of discovered devices
    • getDevice

      public Device getDevice(String name)
      Get a device by its name or UDN.
      Parameters:
      name - the device name or UDN
      Returns:
      the device, or null
    • hasDevice

      public boolean hasDevice(String name)
      Check if a device with the given name or UDN exists.
      Parameters:
      name - the device name or UDN
      Returns:
      true if a device with that name exists
    • removeDevice

      private void removeDevice(Node rootNode)
      Removes the device matching the description node.
      Parameters:
      rootNode - the device description node
    • removeDevice

      protected void removeDevice(Device dev)
      Remove a device from the device list.
      Parameters:
      dev - the device to remove
    • removeDevice

      protected void removeDevice(String name)
      Remove a device by its name or UDN.
      Parameters:
      name - the name or UDN of the device to remove
    • removeDevice

      private void removeDevice(SSDPPacket packet)
      Removes the device announced in an SSDP packet.
      Parameters:
      packet - the SSDP packet announcing the device
    • removeExpiredDevices

      public void removeExpiredDevices()
      Remove all expired devices
    • setExpiredDeviceMonitoringInterval

      public void setExpiredDeviceMonitoringInterval(long interval)
      Set the expired device monitoring interval.
      Parameters:
      interval - the seconds the disposer waits between expiry checks
    • getExpiredDeviceMonitoringInterval

      public long getExpiredDeviceMonitoringInterval()
      Get the expired device monitoring interval.
      Returns:
      the seconds the disposer waits between expiry checks
    • setDeviceDisposer

      public void setDeviceDisposer(Disposer disposer)
      Set the device disposer.
      Parameters:
      disposer - the thread that periodically removes expired devices
    • getDeviceDisposer

      public Disposer getDeviceDisposer()
      Get the device disposer.
      Returns:
      the thread that periodically removes expired devices
    • addNotifyListener

      public void addNotifyListener(NotifyListener listener)
      Add a notify listener.
      Parameters:
      listener - the notify listener to add
    • removeNotifyListener

      public void removeNotifyListener(NotifyListener listener)
      Remove a notify listener.
      Parameters:
      listener - the notify listener to remove
    • performNotifyListener

      public void performNotifyListener(SSDPPacket ssdpPacket)
      Notify all registered notify listeners of a received SSDP packet.
      Parameters:
      ssdpPacket - the received SSDP packet
    • addSearchResponseListener

      public void addSearchResponseListener(SearchResponseListener listener)
      Add a search response listener.
      Parameters:
      listener - the search response listener to add
    • removeSearchResponseListener

      public void removeSearchResponseListener(SearchResponseListener listener)
      Remove a search response listener.
      Parameters:
      listener - the search response listener to remove
    • performSearchResponseListener

      public void performSearchResponseListener(SSDPPacket ssdpPacket)
      Notify all registered search response listeners of a received SSDP packet.
      Parameters:
      ssdpPacket - the received SSDP packet
    • addDeviceChangeListener

      public void addDeviceChangeListener(DeviceChangeListener listener)
      Add a device change listener.
      Parameters:
      listener - the device change listener to add
    • removeDeviceChangeListener

      public void removeDeviceChangeListener(DeviceChangeListener listener)
      Remove a device change listener.
      Parameters:
      listener - the device change listener to remove
    • performAddDeviceListener

      public void performAddDeviceListener(Device dev)
      Notify all registered device change listeners of an added device.
      Parameters:
      dev - the device that was added
    • performRemoveDeviceListener

      public void performRemoveDeviceListener(Device dev)
      Notify all registered device change listeners of a removed device.
      Parameters:
      dev - the device that was removed
    • notifyReceived

      public void notifyReceived(SSDPPacket packet)
      Handle a received SSDP notification packet.
      Parameters:
      packet - the received SSDP packet
    • searchResponseReceived

      public void searchResponseReceived(SSDPPacket packet)
      Handle a received SSDP search response packet.
      Parameters:
      packet - the search response packet
    • getSearchMx

      public int getSearchMx()
      Get the search MX value.
      Returns:
      the seconds devices are given to answer a search
    • setSearchMx

      public void setSearchMx(int mx)
      Set the search MX value.
      Parameters:
      mx - the seconds devices are given to answer a search
    • search

      public void search(String target, int mx)
      Broadcast an M-SEARCH for devices matching a target.
      Parameters:
      target - the search target
      mx - the maximum wait time in seconds
    • search

      public void search(String target)
      Broadcast an M-SEARCH for devices matching a target.
      Parameters:
      target - the search target
    • search

      public void search()
      Search for all root devices
    • getHTTPServerList

      protected HTTPServerList getHTTPServerList()
      I2P was private
      Returns:
      the HTTP server list
    • 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
    • addEventListener

      public void addEventListener(EventListener listener)
      Add an event listener.
      Parameters:
      listener - the event listener to add
    • removeEventListener

      public void removeEventListener(EventListener listener)
      Remove an event listener.
      Parameters:
      listener - the event listener to remove
    • performEventListener

      public void performEventListener(String uuid, long seq, String name, String value)
      Notify all registered event listeners of a state variable change.
      Parameters:
      uuid - the subscription ID
      seq - the sequence number
      name - the property name
      value - the property value
    • getEventSubURI

      public String getEventSubURI()
      Get the event subscription URI.
      Returns:
      the event subscription URI
    • setEventSubURI

      public void setEventSubURI(String url)
      Set the event subscription URI.
      Parameters:
      url - the URI path on this control point that devices notify
    • getEventSubCallbackURL

      private String getEventSubCallbackURL(String host)
      The callback URL for event subscriptions.
      Parameters:
      host - the local host name
      Returns:
      the callback URL
    • subscribe

      public boolean subscribe(Service service, long timeout)
      Subscribe to a service, renewing an existing subscription if there is one.
      Parameters:
      service - the UPnP service whose subscription is being renewed to subscribe to
      timeout - the requested lifetime in seconds
      Returns:
      true if successful
    • subscribe

      public boolean subscribe(Service service)
      Subscribe to a service with an infinite lifetime.
      Parameters:
      service - the UPnP service whose subscription is being renewed to subscribe to
      Returns:
      true if successful
    • subscribe

      public boolean subscribe(Service service, String uuid, long timeout)
      Renew an existing subscription to a service.
      Parameters:
      service - the UPnP service whose subscription is being renewed
      uuid - the subscription ID
      timeout - the requested lifetime in seconds
      Returns:
      true if successful
    • subscribe

      public boolean subscribe(Service service, String uuid)
      Renew an existing subscription to a service with an infinite lifetime.
      Parameters:
      service - the UPnP service whose subscription is being renewed
      uuid - the subscription ID
      Returns:
      true if successful
    • isSubscribed

      public boolean isSubscribed(Service service)
      Check whether this control point holds a subscription to a service.
      Parameters:
      service - the UPnP service whose subscription is being renewed
      Returns:
      true if subscribed
    • unsubscribe

      public boolean unsubscribe(Service service)
      Cancel a subscription to a service.
      Parameters:
      service - the UPnP service whose subscription is being renewed
      Returns:
      true if successful
    • unsubscribe

      public void unsubscribe(Device device)
      Cancel the subscriptions of a device and of its embedded devices.
      Parameters:
      device - the device to unsubscribe
    • unsubscribe

      public void unsubscribe()
      Unsubscribe from all services
    • getSubscriberService

      public Service getSubscriberService(String uuid)
      Find the service holding a subscription.
      Parameters:
      uuid - the subscription ID
      Returns:
      the service with that subscription, or null
    • renewSubscriberService

      public void renewSubscriberService(Device dev, long timeout)
      Renew the subscriptions of a device and of its embedded devices.
      Parameters:
      dev - the device whose subscriptions to renew
      timeout - the requested lifetime in seconds
    • renewSubscriberService

      public void renewSubscriberService(long timeout)
      Renew the subscriptions of every discovered device.
      Parameters:
      timeout - the requested lifetime in seconds
    • renewSubscriberService

      public void renewSubscriberService()
      Renew all subscriber services with infinite timeout
    • setRenewSubscriber

      public void setRenewSubscriber(RenewSubscriber sub)
      Set the renew subscriber.
      Parameters:
      sub - the thread that periodically renews subscriptions
    • getRenewSubscriber

      public RenewSubscriber getRenewSubscriber()
      Get the renew subscriber.
      Returns:
      the thread that periodically renews subscriptions
    • start

      public boolean start(String target, int mx)
      Start the listening sockets and search for devices.
      Parameters:
      target - the search target
      mx - the maximum wait time for responses
      Returns:
      true if started successfully
    • start

      public boolean start(String target)
      Start listening and search for devices of the given target.
      Parameters:
      target - the search target
      Returns:
      true if started successfully
    • start

      public boolean start()
      Start with default search target
      Returns:
      true if started successfully
    • stop

      public boolean stop()
      Stop listening, release the ports and cancel all subscriptions.
      Returns:
      true if stopped successfully
    • setUserData

      public void setUserData(Object data)
      Set the user-defined data.
      Parameters:
      data - the object to store and hand back from getUserData(), may be null
    • getUserData

      public Object getUserData()
      Get the user-defined data.
      Returns:
      whatever was passed to setUserData(), or null if unset
    • print

      public void print()
      /////////////////////////////////////////////