protected void sendSearchResponseDeviceType(DeviceType deviceType, NetworkAddress activeStreamServer) throws RouterException{ log.fine("Responding to device type search: " + deviceType); Collection<Device> devices = getUpnpService().getRegistry().getDevices(deviceType); for (Device device : devices) { if (device instanceof LocalDevice) { if (isAdvertisementDisabled((LocalDevice)device)) continue; log.finer("Sending matching device type search result for: " + device); OutgoingSearchResponse message = new OutgoingSearchResponseDeviceType( getInputMessage(), getDescriptorLocation(activeStreamServer, (LocalDevice) device), (LocalDevice) device ); prepareOutgoingSearchResponse(message); getUpnpService().getRouter().send(message); } } }
synchronized protected void updateMediaRenderers() { ContentDirectoryControlPoint.LOGGER.fine("Updating media renderers"); Collection<Device> foundMediaRenderers = upnpService.getRegistry().getDevices(SUPPORTED_MEDIA_RENDERER_TYPE); upnpService.getControlPoint().execute(getProtocolInfoActionCallback);
upnpService.getControlPoint().search(new STAllHeader()); upnpService.shutdown();
protected void onRenewalFailure() { log.fine("Subscription renewal failed, removing subscription from registry"); getUpnpService().getRegistry().removeRemoteSubscription(subscription); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { subscription.end(CancelReason.RENEWAL_FAILED, null); } } ); } }
public void eventReceived() { // The only thing we are interested in, sending an event when the state changes getUpnpService().getConfiguration().getSyncProtocolExecutorService().execute( getUpnpService().getProtocolFactory().createSendingEvent(this) ); } };
public Registry getRegistry() { return upnpService.getRegistry(); }
public ControlPoint getControlPoint() { return upnpService.getControlPoint(); } }
response = getUpnpService().getRouter().send(getInputMessage()); } catch (RouterException ex) { onRenewalFailure(); getUpnpService().getRegistry().removeRemoteSubscription(subscription); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { } else if (!responseMessage.isValidHeaders()) { log.severe("Subscription renewal failed, invalid or missing (SID, Timeout) response headers"); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { log.fine("Subscription renewed, updating in registry, response was: " + response); subscription.setActualSubscriptionDurationSeconds(responseMessage.getSubscriptionDurationSeconds()); getUpnpService().getRegistry().updateRemoteSubscription(subscription);
@Override public void onWakeupClicked() { try { upnpService.getRouter().broadcast(wakeOnLANBytes); } catch (RouterException ex) { Workbench.Log.MAIN.warning( "Broadcasting wakeup bytes on LAN failed: " + ex ); } }
@Override public void responseSent(StreamResponseMessage responseMessage) { if (subscription == null) return; // Preconditions failed very early on if (responseMessage != null && !responseMessage.getOperation().isFailed() && subscription.getCurrentSequence().getValue() == 0) { // Note that renewals should not have 0 // This is a minor concurrency issue: If we now register on the service and henceforth send a new // event message whenever the state of the service changes, there is still a chance that the initial // event message arrives later than the first on-change event message. Shouldn't be a problem as the // subscriber is supposed to figure out what to do with out-of-sequence messages. I would be // surprised though if actual implementations won't crash! log.fine("Establishing subscription"); subscription.registerOnService(); subscription.establish(); log.fine("Response to subscription sent successfully, now sending initial event asynchronously"); getUpnpService().getConfiguration().getAsyncProtocolExecutor().execute( getUpnpService().getProtocolFactory().createSendingEvent(subscription) ); } else if (subscription.getCurrentSequence().getValue() == 0) { log.fine("Subscription request's response aborted, not sending initial event"); if (responseMessage == null) { log.fine("Reason: No response at all from subscriber"); } else { log.fine("Reason: " + responseMessage.getOperation()); } log.fine("Removing subscription from registry: " + subscription); getUpnpService().getRegistry().removeLocalSubscription(subscription); } }
protected StreamResponseMessage sendRemoteRequest(OutgoingActionRequestMessage requestMessage) throws ActionException, RouterException { try { log.fine("Writing SOAP request body of: " + requestMessage); getUpnpService().getConfiguration().getSoapActionProcessor().writeBody(requestMessage, actionInvocation); log.fine("Sending SOAP body of message as stream to remote device"); return getUpnpService().getRouter().send(requestMessage); } catch (RouterException ex) { Throwable cause = Exceptions.unwrap(ex); if (cause instanceof InterruptedException) { if (log.isLoggable(Level.FINE)) { log.fine("Sending action request message was interrupted: " + cause); } throw new ActionCancelledException((InterruptedException)cause); } throw ex; } catch (UnsupportedDataException ex) { if (log.isLoggable(Level.FINE)) { log.fine("Error writing SOAP body: " + ex); log.log(Level.FINE, "Exception root cause: ", Exceptions.unwrap(ex)); } throw new ActionException(ErrorCode.ACTION_FAILED, "Error writing request message. " + ex.getMessage()); } }
/** * Stops the UPnP service, when the last Activity unbinds from this Service. */ @Override public void onDestroy() { upnpService.shutdown(); super.onDestroy(); }
public UpnpServiceConfiguration getConfiguration() { return upnpService.getConfiguration(); }
public ProtocolFactory getProtocolFactory() { return getUpnpService().getProtocolFactory(); }
protected void removeDevice() { LocalDevice device; if ((device = upnpService.getRegistry().getLocalDevice(DEMO_DEVICE_UDN, true)) != null) { upnpService.getRegistry().removeDevice(device); } }
@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! } } }
getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { getUpnpService().getRegistry().registerPendingRemoteSubscription(subscription); response = getUpnpService().getRouter().send(getInputMessage()); } catch (RouterException ex) { onSubscriptionFailure(); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { } else if (!responseMessage.isValidHeaders()) { log.severe("Subscription failed, invalid or missing (SID, Timeout) response headers"); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { getUpnpService().getRegistry().addRemoteSubscription(subscription); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { getUpnpService().getRegistry().unregisterPendingRemoteSubscription(subscription);
protected void onUnsubscribe(final StreamResponseMessage response) { // Always remove from the registry and end the subscription properly - even if it's failed getUpnpService().getRegistry().removeRemoteSubscription(subscription); getUpnpService().getConfiguration().getRegistryListenerExecutor().execute( new Runnable() { public void run() { if (response == null) { log.fine("Unsubscribe failed, no response received"); subscription.end(CancelReason.UNSUBSCRIBE_FAILED, null); } else if (response.getOperation().isFailed()) { log.fine("Unsubscribe failed, response was: " + response); subscription.end(CancelReason.UNSUBSCRIBE_FAILED, response.getOperation()); } else { log.fine("Unsubscribe successful, response was: " + response); subscription.end(null, response.getOperation()); } } } ); } }
case 0: if (upnpService != null) { Router router = upnpService.get().getRouter(); try { if (router.isEnabled()) {