public ControlPoint getControlPoint() { return upnpService.getControlPoint(); } }
@Override synchronized public void beforeShutdown(Registry registry) { for (Map.Entry<Service, List<PortMapping>> activeEntry : activePortMappings.entrySet()) { final Iterator<PortMapping> it = activeEntry.getValue().iterator(); while (it.hasNext()) { final PortMapping pm = it.next(); log.fine("Trying to delete port mapping on IGD: " + pm); new PortMappingDelete(activeEntry.getKey(), registry.getUpnpService().getControlPoint(), pm) { @Override public void success(ActionInvocation invocation) { log.fine("Port mapping deleted: " + pm); it.remove(); } @Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { handleFailureMessage("Failed to delete port mapping: " + pm); handleFailureMessage("Reason: " + defaultMsg); } }.run(); // Synchronous! } } }
@Override protected void connect(Service service) { if (service == null) return; callback = new SwitchPowerSubscriptionCallback(service, this); upnpService.getControlPoint().execute(callback); }
@Override synchronized public void deviceAdded(Registry registry, Device device) { Service connectionService; if ((connectionService = discoverConnectionService(device)) == null) return; log.fine("Activating port mappings on: " + connectionService); final List<PortMapping> activeForService = new ArrayList<>(); for (final PortMapping pm : portMappings) { new PortMappingAdd(connectionService, registry.getUpnpService().getControlPoint(), pm) { @Override public void success(ActionInvocation invocation) { log.fine("Port mapping added: " + pm); activeForService.add(pm); } @Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { handleFailureMessage("Failed to add port mapping: " + pm); handleFailureMessage("Reason: " + defaultMsg); } }.run(); // Synchronous! } activePortMappings.put(connectionService, activeForService); }
upnpService.getControlPoint().execute(getProtocolInfoActionCallback);
upnpService.getControlPoint().search(new STAllHeader());
protected void sendToMediaRenderer(final int instanceId, final Service avTransportService, String uri) { SetAVTransportURI setAVTransportURIActionCallback = new SetAVTransportURI(new UnsignedIntegerFourBytes(instanceId), avTransportService, uri) { @Override public void success(ActionInvocation invocation) { updateStatus( "Successfuly sent URI to: (Instance: " + instanceId + ") " + avTransportService.getDevice().getDetails().getFriendlyName() ); } @Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { updateStatusFailure( "Failed to send URI: " + defaultMsg ); } }; upnpService.getControlPoint().execute(setAVTransportURIActionCallback); }
@Override public void onSwitchToggle(final boolean on) { Service service = resolveService(); if (service == null) return; getUpnpService().getControlPoint().execute(new SetTarget(service, on) { @Override public void success(ActionInvocation invocation) { SwitchPowerControlPoint.LOGGER.info( "Target set to: " + (on ? "ON" : "OFF") ); } @Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { SwitchPowerControlPoint.LOGGER.warning( "Can't set target: " + defaultMsg ); } }); }
public ControlPoint getControlPoint() { return upnpService.getControlPoint(); } }
@Override synchronized public void beforeShutdown(Registry registry) { for (Map.Entry<Service, List<PortMapping>> activeEntry : activePortMappings.entrySet()) { final Iterator<PortMapping> it = activeEntry.getValue().iterator(); while (it.hasNext()) { final PortMapping pm = it.next(); log.fine("Trying to delete port mapping on IGD: " + pm); new PortMappingDelete(activeEntry.getKey(), registry.getUpnpService().getControlPoint(), pm) { @Override public void success(ActionInvocation invocation) { log.fine("Port mapping deleted: " + pm); it.remove(); } @Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { handleFailureMessage("Failed to delete port mapping: " + pm); handleFailureMessage("Reason: " + defaultMsg); } }.run(); // Synchronous! } } }
@Override synchronized public void deviceAdded(Registry registry, Device device) { Service connectionService; if ((connectionService = discoverConnectionService(device)) == null) return; log.fine("Activating port mappings on: " + connectionService); final List<PortMapping> activeForService = new ArrayList(); for (final PortMapping pm : portMappings) { new PortMappingAdd(connectionService, registry.getUpnpService().getControlPoint(), pm) { @Override public void success(ActionInvocation invocation) { log.fine("Port mapping added: " + pm); activeForService.add(pm); } @Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { handleFailureMessage("Failed to add port mapping: " + pm); handleFailureMessage("Reason: " + defaultMsg); } }.run(); // Synchronous! } activePortMappings.put(connectionService, activeForService); }
upnpService.getControlPoint().search(new STAllHeader());
public ControlPoint getControlPoint() { return upnpService.getControlPoint(); } }
private void doPortForwarding() { PortMapping[] desiredMapping = new PortMapping[2]; desiredMapping[0] = new PortMapping(8123, InetAddress.getLocalHost().getHostAddress(), PortMapping.Protocol.TCP, " TCP POT Forwarding"); desiredMapping[1] = new PortMapping(8123, InetAddress.getLocalHost().getHostAddress(), PortMapping.Protocol.UDP, " UDP POT Forwarding"); UpnpService upnpService = new UpnpServiceImpl(); RegistryListener registryListener = new PortMappingListener(desiredMapping); upnpService.getRegistry().addListener(registryListener); upnpService.getControlPoint().search(); }
/** * stop the player */ public void stopPlay() { if (this.playerService == null) { return; } ActionCallback stopAction = new Stop(this.playerService) { @Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { LOGGER.warn("Stopping failed! " + defaultMsg); } }; this.upnpService.getControlPoint().execute(stopAction); }
@Override synchronized public void beforeShutdown(Registry registry) { for (Map.Entry<Service, List<PortMapping>> activeEntry : activePortMappings.entrySet()) { final Iterator<PortMapping> it = activeEntry.getValue().iterator(); while (it.hasNext()) { final PortMapping pm = it.next(); log.fine("Trying to delete port mapping on IGD: " + pm); new PortMappingDelete(activeEntry.getKey(), registry.getUpnpService().getControlPoint(), pm) { @Override public void success(ActionInvocation invocation) { log.fine("Port mapping deleted: " + pm); it.remove(); } @Override public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) { handleFailureMessage("Failed to delete port mapping: " + pm); handleFailureMessage("Reason: " + defaultMsg); } }.run(); // Synchronous! } } }
/******************************************************************************************************************* * ******************************************************************************************************************/ public void execute (final @Nonnull ActionCallback actionCallback) { upnpService.getControlPoint().execute(actionCallback); }
@Override protected List<IRouter> findRoutersInternal() throws RouterException { final UpnpServiceConfiguration config = new DefaultUpnpServiceConfiguration(); final ClingRegistryListener clingRegistryListener = new ClingRegistryListener(); final UpnpService upnpService = new UpnpServiceImpl(config, clingRegistryListener); shutdownServiceOnExit(upnpService); log.debug("Start searching using upnp service"); upnpService.getControlPoint().search(); final RemoteService service = (RemoteService) clingRegistryListener .waitForServiceFound(DISCOVERY_TIMEOUT_SECONDS, TimeUnit.SECONDS); if (service == null) { log.debug("Did not find a service after {} seconds", DISCOVERY_TIMEOUT_SECONDS); return Collections.emptyList(); } log.debug("Found service {}", service); return Arrays .<IRouter> asList(new ClingRouter(service, upnpService.getRegistry(), upnpService.getControlPoint())); }
/** * Sends a UPNP broadcast message, to find some players.<br> * Should be available shortly via getAvailablePlayers() */ public void sendPlayerSearchRequest() { createUpnpService(); this.upnpService.getControlPoint().search(new UDADeviceTypeHeader(new UDADeviceType("MediaRenderer"))); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Override public void run() { try { log.info(">>>> starting discovery ..."); upnpService.getRegistry().addListener(listener); upnpService.getControlPoint().search(new STAllHeader()); } catch (Exception e) { log.error("", e); } }