The ControlPoint automatically manages the device list based on network notifications. You can intercept these events by implementing specific listener interfaces:
Receive Notify Events
Implement NotifyListener to receive raw SSDPPacket messages when devices send notifications. Use addNotifyListener(this) to register.
Monitor Device Changes
Implement DeviceChangeListener to specifically track when devices are added or removed from the control point. Use addDeviceChangeListener(this) to register.
Handle Search Responses
To manually trigger a search and handle the results, call search(String target) and implement SearchResponseListener. Use addSearchResponseListener(this) to register.
// Example: Implementing NotifyListener
public class MyCtrlPoint extends ControlPoint implements NotifyListener {
public MyCtrlPoint() {
addNotifyListener(this);
start();
}
public void deviceNotifyReceived(SSDPPacket ssdpPacket) {
String uuid = ssdpPacket.getUSN();
String target = ssdpPacket.getNT();
String subType = ssdpPacket.getNTS();
String location = ssdpPacket.getLocation();
}
}
// Example: Implementing DeviceChangeListener
public class MyCtrlPoint extends ControlPoint implements DeviceChangeListener {
public MyCtrlPoint() {
addDeviceChangeListener(this);
start();
}
public void deviceAdded(Device dev) {
// Handle added device
}
public void deviceRemoved(Device dev) {
// Handle removed device
}
}
// Example: Implementing SearchResponseListener
public class MyCtrlPoint extends ControlPoint implements SearchResponseListener {
public MyCtrlPoint() {
addSearchResponseListener(this);
start();
search("upnp:rootdevice");
}
public void deviceSearchResponseReceived(SSDPPacket ssdpPacket) {
String uuid = ssdpPacket.getUSN();
String target = ssdpPacket.getST();
String location = ssdpPacket.getLocation();
}
}