java.lang.Object
org.cybergarage.upnp.ControlPoint
- All Implemented Interfaces:
HTTPRequestListener
- Direct Known Subclasses:
UPnP
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanTrue to allow IPv6 location URLs.private static final intDefault port for the event subscription callback.private static final StringDefault URI for the event subscription callback.private static final intDefault expired device check interval, in seconds.private static final intDefault port for SSDP discovery.(package private) ListenerList//////////////////////////////////////////////////////////////////private Disposer/////////////////////////////////////////////private ListenerList/////////////////////////////////////////////private ListenerList/////////////////////////////////////////////private NodeList/////////////////////////////////////////////private ListenerList/////////////////////////////////////////////private String/////////////////////////////////////////////private longInterval between the expired device checks.private int/////////////////////////////////////////////private HTTPServerList/////////////////////////////////////////////private Mutex/////////////////////////////////////////////private boolean/////////////////////////////////////////////private RenewSubscriber/////////////////////////////////////////////private int/////////////////////////////////////////////private SSDPNotifySocketList/////////////////////////////////////////////private int/////////////////////////////////////////////private SSDPSearchResponseSocketListSockets receiving the SSDP search responses.private Object/////////////////////////////////////////////Constructor Summary
ConstructorsConstructorDescriptionDefault constructor using default portsControlPoint(int ssdpPort, int httpPort) Create a control point with specified SSDP and HTTP ports.ControlPoint(int ssdpPort, int httpPort, InetAddress[] binds) Create a control point with specified ports and network bindings.Method Summary
Modifier and TypeMethodDescriptionprivate voidaddDevice(SSDPPacket ssdpPacket) Adds a device found in an SSDP packet.private voidAdds a device described by the node.voidaddDeviceChangeListener(DeviceChangeListener listener) Add a device change listener.voidaddEventListener(EventListener listener) Add an event listener.voidaddNotifyListener(NotifyListener listener) Add a notify listener.voidAdd a search response listener.voidfinalize()Get a device by its name or UDN.private DeviceFinds the device matching the description node.Get the device disposer.Get the list of discovered devices.private StringgetEventSubCallbackURL(String host) The callback URL for event subscriptions.Get the event subscription URI.longGet the expired device monitoring interval.intGet the HTTP port.protected HTTPServerListI2P was privateGet the renew subscriber.intGet the search MX value.protected SSDPNotifySocketListGet the SSDP notify socket list.intGet the SSDP port.protected SSDPSearchResponseSocketListGet the SSDP search response socket list.getSubscriberService(String uuid) Find the service holding a subscription.Get the user-defined data.booleanCheck if a device with the given name or UDN exists.voidhttpRequestRecieved(HTTPRequest httpReq) Called when an HTTP request is received.booleanCheck if NMPR mode is enabled.booleanisSubscribed(Service service) Check whether this control point holds a subscription to a service.voidlock()Lock the mutexvoidnotifyReceived(SSDPPacket packet) Handle a received SSDP notification packet.voidNotify all registered device change listeners of an added device.voidperformEventListener(String uuid, long seq, String name, String value) Notify all registered event listeners of a state variable change.voidperformNotifyListener(SSDPPacket ssdpPacket) Notify all registered notify listeners of a received SSDP packet.voidNotify all registered device change listeners of a removed device.voidperformSearchResponseListener(SSDPPacket ssdpPacket) Notify all registered search response listeners of a received SSDP packet.voidprint()/////////////////////////////////////////////protected voidremoveDevice(String name) Remove a device by its name or UDN.protected voidremoveDevice(Device dev) Remove a device from the device list.private voidremoveDevice(SSDPPacket packet) Removes the device announced in an SSDP packet.private voidremoveDevice(Node rootNode) Removes the device matching the description node.voidRemove a device change listener.voidremoveEventListener(EventListener listener) Remove an event listener.voidRemove all expired devicesvoidremoveNotifyListener(NotifyListener listener) Remove a notify listener.voidRemove a search response listener.voidRenew all subscriber services with infinite timeoutvoidrenewSubscriberService(long timeout) Renew the subscriptions of every discovered device.voidrenewSubscriberService(Device dev, long timeout) Renew the subscriptions of a device and of its embedded devices.voidsearch()Search for all root devicesvoidBroadcast an M-SEARCH for devices matching a target.voidBroadcast an M-SEARCH for devices matching a target.voidsearchResponseReceived(SSDPPacket packet) Handle a received SSDP search response packet.voidsetDeviceDisposer(Disposer disposer) Set the device disposer.voidsetEventSubURI(String url) Set the event subscription URI.voidsetExpiredDeviceMonitoringInterval(long interval) Set the expired device monitoring interval.voidsetHTTPPort(int port) Set the HTTP port.voidsetNMPRMode(boolean flag) Set the NMPR mode flag.voidSet the renew subscriber.voidsetSearchMx(int mx) Set the search MX value.voidsetSSDPPort(int port) Set the SSDP port.voidsetUserData(Object data) Set the user-defined data.booleanstart()Start with default search targetbooleanStart listening and search for devices of the given target.booleanStart the listening sockets and search for devices.booleanstop()Stop listening, release the ports and cancel all subscriptions.booleanSubscribe to a service with an infinite lifetime.booleanSubscribe to a service, renewing an existing subscription if there is one.booleanRenew an existing subscription to a service with an infinite lifetime.booleanRenew an existing subscription to a service.voidunlock()Unlock the mutexvoidUnsubscribe from all servicesvoidunsubscribe(Device device) Cancel the subscriptions of a device and of its embedded devices.booleanunsubscribe(Service service) Cancel a subscription to a service.
Field Details
DEFAULT_EVENTSUB_PORT
private static final int DEFAULT_EVENTSUB_PORTDefault port for the event subscription callback.- See Also:
DEFAULT_SSDP_PORT
private static final int DEFAULT_SSDP_PORTDefault port for SSDP discovery.- See Also:
DEFAULT_EXPIRED_DEVICE_MONITORING_INTERVAL
private static final int DEFAULT_EXPIRED_DEVICE_MONITORING_INTERVALDefault expired device check interval, in seconds.- See Also:
DEFAULT_EVENTSUB_URI
Default URI for the event subscription callback.- See Also:
ALLOW_IPV6_LOCATION
private static final boolean ALLOW_IPV6_LOCATIONTrue to allow IPv6 location URLs.- See Also:
ssdpNotifySocketList
/////////////////////////////////////////////ssdpSearchResponseSocketList
Sockets receiving the SSDP search responses.mutex
/////////////////////////////////////////////ssdpPort
private int ssdpPort/////////////////////////////////////////////httpPort
private int httpPort/////////////////////////////////////////////nmprMode
private boolean nmprMode/////////////////////////////////////////////devNodeList
/////////////////////////////////////////////deviceDisposer
/////////////////////////////////////////////expiredDeviceMonitoringInterval
private long expiredDeviceMonitoringIntervalInterval between the expired device checks.deviceNotifyListenerList
/////////////////////////////////////////////deviceSearchResponseListenerList
/////////////////////////////////////////////deviceChangeListenerList
ListenerList deviceChangeListenerList//////////////////////////////////////////////////////////////////searchMx
private int searchMx/////////////////////////////////////////////httpServerList
/////////////////////////////////////////////eventListenerList
/////////////////////////////////////////////eventSubURI
/////////////////////////////////////////////renewSubscriber
/////////////////////////////////////////////userData
/////////////////////////////////////////////
Constructor Details
ControlPoint
Create a control point with specified ports and network bindings.- Parameters:
ssdpPort- the SSDP porthttpPort- the HTTP portbinds- 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 porthttpPort- the HTTP port
ControlPoint
public ControlPoint()Default constructor using default ports
Method Details
getSSDPNotifySocketList
Get the SSDP notify socket list.- Returns:
- the SSDP notify socket list
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 mutexunlock
public void unlock()Unlock the mutexgetSSDPPort
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
Adds a device described by the node.- Parameters:
rootNode- the device description node
addDevice
Adds a device found in an SSDP packet.- Parameters:
ssdpPacket- the SSDP packet announcing the device
getDevice
getDeviceList
Get the list of discovered devices.- Returns:
- the list of discovered devices
getDevice
hasDevice
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
Removes the device matching the description node.- Parameters:
rootNode- the device description node
removeDevice
Remove a device from the device list.- Parameters:
dev- the device to remove
removeDevice
Remove a device by its name or UDN.- Parameters:
name- the name or UDN of the device to remove
removeDevice
Removes the device announced in an SSDP packet.- Parameters:
packet- the SSDP packet announcing the device
removeExpiredDevices
public void removeExpiredDevices()Remove all expired devicessetExpiredDeviceMonitoringInterval
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
Set the device disposer.- Parameters:
disposer- the thread that periodically removes expired devices
getDeviceDisposer
Get the device disposer.- Returns:
- the thread that periodically removes expired devices
addNotifyListener
Add a notify listener.- Parameters:
listener- the notify listener to add
removeNotifyListener
Remove a notify listener.- Parameters:
listener- the notify listener to remove
performNotifyListener
Notify all registered notify listeners of a received SSDP packet.- Parameters:
ssdpPacket- the received SSDP packet
addSearchResponseListener
Add a search response listener.- Parameters:
listener- the search response listener to add
removeSearchResponseListener
Remove a search response listener.- Parameters:
listener- the search response listener to remove
performSearchResponseListener
Notify all registered search response listeners of a received SSDP packet.- Parameters:
ssdpPacket- the received SSDP packet
addDeviceChangeListener
Add a device change listener.- Parameters:
listener- the device change listener to add
removeDeviceChangeListener
Remove a device change listener.- Parameters:
listener- the device change listener to remove
performAddDeviceListener
Notify all registered device change listeners of an added device.- Parameters:
dev- the device that was added
performRemoveDeviceListener
Notify all registered device change listeners of a removed device.- Parameters:
dev- the device that was removed
notifyReceived
Handle a received SSDP notification packet.- Parameters:
packet- the received SSDP packet
searchResponseReceived
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
Broadcast an M-SEARCH for devices matching a target.- Parameters:
target- the search targetmx- the maximum wait time in seconds
search
Broadcast an M-SEARCH for devices matching a target.- Parameters:
target- the search target
search
public void search()Search for all root devicesgetHTTPServerList
httpRequestRecieved
Description copied from interface:HTTPRequestListenerCalled when an HTTP request is received.- Specified by:
httpRequestRecievedin interfaceHTTPRequestListener- Parameters:
httpReq- the received HTTP request
addEventListener
Add an event listener.- Parameters:
listener- the event listener to add
removeEventListener
Remove an event listener.- Parameters:
listener- the event listener to remove
performEventListener
getEventSubURI
setEventSubURI
Set the event subscription URI.- Parameters:
url- the URI path on this control point that devices notify
getEventSubCallbackURL
subscribe
Subscribe to a service, renewing an existing subscription if there is one.- Parameters:
service- the UPnP service whose subscription is being renewed to subscribe totimeout- the requested lifetime in seconds- Returns:
- true if successful
subscribe
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
subscribe
isSubscribed
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
Cancel a subscription to a service.- Parameters:
service- the UPnP service whose subscription is being renewed- Returns:
- true if successful
unsubscribe
Cancel the subscriptions of a device and of its embedded devices.- Parameters:
device- the device to unsubscribe
unsubscribe
public void unsubscribe()Unsubscribe from all servicesgetSubscriberService
renewSubscriberService
Renew the subscriptions of a device and of its embedded devices.- Parameters:
dev- the device whose subscriptions to renewtimeout- 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 timeoutsetRenewSubscriber
Set the renew subscriber.- Parameters:
sub- the thread that periodically renews subscriptions
getRenewSubscriber
Get the renew subscriber.- Returns:
- the thread that periodically renews subscriptions
start
Start the listening sockets and search for devices.- Parameters:
target- the search targetmx- the maximum wait time for responses- Returns:
- true if started successfully
start
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
Set the user-defined data.- Parameters:
data- the object to store and hand back fromgetUserData(), may be null
getUserData
Get the user-defined data.- Returns:
- whatever was passed to
setUserData(), or null if unset
print
public void print()/////////////////////////////////////////////