org.fourthline.cling.model.meta.RemoteService Java Examples

The following examples show how to use org.fourthline.cling.model.meta.RemoteService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractClingAction.java    From portmapper with GNU General Public License v3.0 6 votes vote down vote up
private ActionArgumentValue<RemoteService>[] getArguments(final Action<RemoteService> action) {
    @SuppressWarnings("unchecked")
    final ActionArgument<RemoteService>[] actionArguments = action.getArguments();
    final Map<String, Object> argumentValues = getArgumentValues();
    final List<ActionArgumentValue<RemoteService>> actionArgumentValues = new ArrayList<>(actionArguments.length);

    for (final ActionArgument<RemoteService> actionArgument : actionArguments) {
        if (actionArgument.getDirection() == Direction.IN) {
            final Object value = argumentValues.get(actionArgument.getName());
            logger.trace("Action {}: add arg value for {}: {} (expected datatype: {})", action.getName(),
                    actionArgument, value, actionArgument.getDatatype().getDisplayString());
            actionArgumentValues.add(new ActionArgumentValue<>(actionArgument, value));
        }
    }
    @SuppressWarnings("unchecked")
    final ActionArgumentValue<RemoteService>[] array = actionArgumentValues
            .toArray(new ActionArgumentValue[0]);
    return array;
}
 
Example #2
Source File: RetrieveRemoteDescriptors.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected List<RemoteService> filterExclusiveServices(RemoteService[] services) {
    ServiceType[] exclusiveTypes = getUpnpService().getConfiguration().getExclusiveServiceTypes();

    if (exclusiveTypes == null || exclusiveTypes.length == 0)
        return Arrays.asList(services);

    List<RemoteService> exclusiveServices = new ArrayList();
    for (RemoteService discoveredService : services) {
        for (ServiceType exclusiveType : exclusiveTypes) {
            if (discoveredService.getServiceType().implementsVersion(exclusiveType)) {
                log.fine("Including exclusive service: " + discoveredService);
                exclusiveServices.add(discoveredService);
            } else {
                log.fine("Excluding unwanted service: " + exclusiveType);
            }
        }
    }
    return exclusiveServices;
}
 
Example #3
Source File: ClingRouterFactory.java    From portmapper with GNU General Public License v3.0 6 votes vote down vote up
@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);

    final UpnpHeader<?> searchType = new UDADeviceTypeHeader(ClingRegistryListener.IGD_DEVICE_TYPE);
    log.info("Start searching {} for device type {}", DISCOVERY_TIMEOUT, searchType);
    upnpService.getControlPoint().search(searchType, (int) DISCOVERY_TIMEOUT.toSeconds());
    return clingRegistryListener
            .waitForServiceFound(DISCOVERY_TIMEOUT) //
            .map(service -> (RemoteService) service)
            .map(service -> createRouter(service, upnpService)) //
            .collect(toList());
}
 
Example #4
Source File: UDA10DeviceDescriptorBinderImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected void generateServiceList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) {
    if (!deviceModel.hasServices()) return;

    Element serviceListElement = appendNewElement(descriptor, deviceElement, ELEMENT.serviceList);

    for (Service service : deviceModel.getServices()) {
        Element serviceElement = appendNewElement(descriptor, serviceListElement, ELEMENT.service);

        appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceType, service.getServiceType());
        appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceId, service.getServiceId());
        if (service instanceof RemoteService) {
            RemoteService rs = (RemoteService) service;
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, rs.getDescriptorURI());
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, rs.getControlURI());
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, rs.getEventSubscriptionURI());
        } else if (service instanceof LocalService) {
            LocalService ls = (LocalService) service;
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, namespace.getDescriptorPath(ls));
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, namespace.getControlPath(ls));
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, namespace.getEventSubscriptionPath(ls));
        }
    }
}
 
Example #5
Source File: UDA10DeviceDescriptorBinderImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected void generateServiceList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) {
    if (!deviceModel.hasServices()) return;

    Element serviceListElement = appendNewElement(descriptor, deviceElement, ELEMENT.serviceList);

    for (Service service : deviceModel.getServices()) {
        Element serviceElement = appendNewElement(descriptor, serviceListElement, ELEMENT.service);

        appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceType, service.getServiceType());
        appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.serviceId, service.getServiceId());
        if (service instanceof RemoteService) {
            RemoteService rs = (RemoteService) service;
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, rs.getDescriptorURI());
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, rs.getControlURI());
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, rs.getEventSubscriptionURI());
        } else if (service instanceof LocalService) {
            LocalService ls = (LocalService) service;
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.SCPDURL, namespace.getDescriptorPath(ls));
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.controlURL, namespace.getControlPath(ls));
            appendNewElementIfNotNull(descriptor, serviceElement, ELEMENT.eventSubURL, namespace.getEventSubscriptionPath(ls));
        }
    }
}
 
Example #6
Source File: RetrieveRemoteDescriptors.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected List<RemoteService> filterExclusiveServices(RemoteService[] services) {
    ServiceType[] exclusiveTypes = getUpnpService().getConfiguration().getExclusiveServiceTypes();

    if (exclusiveTypes == null || exclusiveTypes.length == 0)
        return Arrays.asList(services);

    List<RemoteService> exclusiveServices = new ArrayList();
    for (RemoteService discoveredService : services) {
        for (ServiceType exclusiveType : exclusiveTypes) {
            if (discoveredService.getServiceType().implementsVersion(exclusiveType)) {
                log.fine("Including exclusive service: " + discoveredService);
                exclusiveServices.add(discoveredService);
            } else {
                log.fine("Excluding unwanted service: " + exclusiveType);
            }
        }
    }
    return exclusiveServices;
}
 
Example #7
Source File: SubscriptionCallback.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
synchronized public void run() {
    if (getControlPoint()  == null) {
        throw new IllegalStateException("Callback must be executed through ControlPoint");
    }

    if (getService() instanceof LocalService) {
        establishLocalSubscription((LocalService) service);
    } else if (getService() instanceof RemoteService) {
        establishRemoteSubscription((RemoteService) service);
    }
}
 
Example #8
Source File: GetPortMappingEntryAction.java    From portmapper with GNU General Public License v3.0 5 votes vote down vote up
@Override
public PortMapping convert(final ActionInvocation<RemoteService> response) {
    final Protocol protocol = Protocol.getProtocol(getStringValue(response, "NewProtocol"));
    final String remoteHost = getStringValue(response, "NewRemoteHost");
    final int externalPort = getIntValue(response, "NewExternalPort");
    final String internalClient = getStringValue(response, "NewInternalClient");
    final int internalPort = getIntValue(response, "NewInternalPort");
    final String description = getStringValue(response, "NewPortMappingDescription");
    final boolean enabled = getBooleanValue(response, "NewEnabled");
    final long leaseDuration = getLongValue(response, "NewLeaseDuration");
    return new PortMapping(protocol, remoteHost, externalPort, internalClient, internalPort, description, enabled,
            leaseDuration);
}
 
Example #9
Source File: UDA10ServiceDescriptorBinderImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected void hydrateBasic(MutableService descriptor, Service undescribedService) {
    descriptor.serviceId = undescribedService.getServiceId();
    descriptor.serviceType = undescribedService.getServiceType();
    if (undescribedService instanceof RemoteService) {
        RemoteService rs = (RemoteService) undescribedService;
        descriptor.controlURI = rs.getControlURI();
        descriptor.eventSubscriptionURI = rs.getEventSubscriptionURI();
        descriptor.descriptorURI = rs.getDescriptorURI();
    }
}
 
Example #10
Source File: SubscriptionCallback.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
synchronized public void run() {
    if (getControlPoint()  == null) {
        throw new IllegalStateException("Callback must be executed through ControlPoint");
    }

    if (getService() instanceof LocalService) {
        establishLocalSubscription((LocalService) service);
    } else if (getService() instanceof RemoteService) {
        establishRemoteSubscription((RemoteService) service);
    }
}
 
Example #11
Source File: AbstractClingAction.java    From portmapper with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ActionInvocation<RemoteService> getActionInvocation() {
    final Action<RemoteService> action = service.getAction(actionName);
    if (action == null) {
        throw new ClingRouterException("No action found for name '" + actionName + "'. Available actions: "
                + Arrays.toString(service.getActions()));
    }
    final ActionArgumentValue<RemoteService>[] argumentArray = getArguments(action);
    return new ActionInvocation<>(action, argumentArray);
}
 
Example #12
Source File: UDA10ServiceDescriptorBinderImpl.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
protected void hydrateBasic(MutableService descriptor, Service undescribedService) {
    descriptor.serviceId = undescribedService.getServiceId();
    descriptor.serviceType = undescribedService.getServiceType();
    if (undescribedService instanceof RemoteService) {
        RemoteService rs = (RemoteService) undescribedService;
        descriptor.controlURI = rs.getControlURI();
        descriptor.eventSubscriptionURI = rs.getEventSubscriptionURI();
        descriptor.descriptorURI = rs.getDescriptorURI();
    }
}
 
Example #13
Source File: AddPortMappingAction.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Void convert(final ActionInvocation<RemoteService> response) {
    return null;
}
 
Example #14
Source File: RemoteGENASubscription.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
protected RemoteGENASubscription(RemoteService service,
                                 int requestedDurationSeconds) {
    super(service, requestedDurationSeconds);
}
 
Example #15
Source File: ActionCallback.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public void run() {
    Service service = actionInvocation.getAction().getService();

    // Local execution
    if (service instanceof LocalService) {
        LocalService localService = (LocalService)service;

        // Executor validates input inside the execute() call immediately
        localService.getExecutor(actionInvocation.getAction()).execute(actionInvocation);

        if (actionInvocation.getFailure() != null) {
            failure(actionInvocation, null);
        } else {
            success(actionInvocation);
        }

    // Remote execution
    } else if (service instanceof RemoteService){

        if (getControlPoint()  == null) {
            throw new IllegalStateException("Callback must be executed through ControlPoint");
        }

        RemoteService remoteService = (RemoteService)service;

        // Figure out the remote URL where we'd like to send the action request to
        URL controLURL = remoteService.getDevice().normalizeURI(remoteService.getControlURI());

        // Do it
        SendingAction prot = getControlPoint().getProtocolFactory().createSendingAction(actionInvocation, controLURL);
        prot.run();

        IncomingActionResponseMessage response = prot.getOutputMessage();

        if (response == null) {
            failure(actionInvocation, null);
        } else if (response.getOperation().isFailed()) {
            failure(actionInvocation, response.getOperation());
        } else {
            success(actionInvocation);
        }
    }
}
 
Example #16
Source File: ClingRouter.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
public ClingRouter(final RemoteService service, final Registry registry, final ControlPoint controlPoint) {
    super(getName(service));
    this.service = service;
    this.registry = registry;
    actionService = new ActionService(service, controlPoint);
}
 
Example #17
Source File: ClingRouterFactory.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
private ClingRouter createRouter(final RemoteService service, final UpnpService upnpService) {
    return new ClingRouter(service, upnpService.getRegistry(), upnpService.getControlPoint());
}
 
Example #18
Source File: GetPortMappingEntryAction.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
public GetPortMappingEntryAction(final Service<RemoteDevice, RemoteService> service, final int index) {
    super(service, "GetGenericPortMappingEntry");
    this.index = index;
}
 
Example #19
Source File: AbstractClingAction.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
public AbstractClingAction(final Service<RemoteDevice, RemoteService> service, final String actionName) {
    this.service = service;
    this.actionName = actionName;
}
 
Example #20
Source File: DeletePortMappingAction.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
public DeletePortMappingAction(final RemoteService service, final PortMapping portMapping) {
    super(service, "DeletePortMapping");
    this.externalPort = portMapping.getExternalPort();
    this.protocol = portMapping.getProtocol().getName();
    this.remoteHost = portMapping.getRemoteHost();
}
 
Example #21
Source File: GetPortMappingEntryAction.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
private boolean getBooleanValue(final ActionInvocation<RemoteService> response, final String argumentName) {
    return (boolean) response.getOutput(argumentName).getValue();
}
 
Example #22
Source File: AddPortMappingAction.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
public AddPortMappingAction(final Service<RemoteDevice, RemoteService> service, final PortMapping portMapping) {
    super(service, "AddPortMapping");
    this.portMapping = portMapping;
}
 
Example #23
Source File: GetExternalIpAction.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
public GetExternalIpAction(final RemoteService service) {
    super(service, "GetExternalIPAddress");
}
 
Example #24
Source File: GetExternalIpAction.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String convert(final ActionInvocation<RemoteService> invocation) {
    return (String) invocation.getOutput("NewExternalIPAddress").getValue();
}
 
Example #25
Source File: ActionService.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
public ActionService(final RemoteService remoteService, final ControlPoint controlPoint) {
    this.remoteService = remoteService;
    this.controlPoint = controlPoint;
}
 
Example #26
Source File: DeletePortMappingAction.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Void convert(final ActionInvocation<RemoteService> response) {
    return null;
}
 
Example #27
Source File: ActionService.java    From portmapper with GNU General Public License v3.0 4 votes vote down vote up
public RemoteService getService() {
    return remoteService;
}
 
Example #28
Source File: DefaultUpnpServiceConfiguration.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public UpnpHeaders getEventSubscriptionHeaders(RemoteService service) {
    return null;
}
 
Example #29
Source File: RetrieveRemoteDescriptors.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
protected RemoteService describeService(RemoteService service)
        throws RouterException, DescriptorBindingException, ValidationException {

	URL descriptorURL;
	try {
		descriptorURL = service.getDevice().normalizeURI(service.getDescriptorURI());
	}  catch(IllegalArgumentException e) {
		log.warning("Could not normalize service descriptor URL: " + service.getDescriptorURI());
		return null;
	}

    StreamRequestMessage serviceDescRetrievalMsg = new StreamRequestMessage(UpnpRequest.Method.GET, descriptorURL);

    // Extra headers
    UpnpHeaders headers =
        getUpnpService().getConfiguration().getDescriptorRetrievalHeaders(service.getDevice().getIdentity());
    if (headers != null)
        serviceDescRetrievalMsg.getHeaders().putAll(headers);

    log.fine("Sending service descriptor retrieval message: " + serviceDescRetrievalMsg);
    StreamResponseMessage serviceDescMsg = getUpnpService().getRouter().send(serviceDescRetrievalMsg);

    if (serviceDescMsg == null) {
        log.warning("Could not retrieve service descriptor, no response: " + service);
        return null;
    }

    if (serviceDescMsg.getOperation().isFailed()) {
        log.warning("Service descriptor retrieval failed: "
                            + descriptorURL
                            + ", "
                            + serviceDescMsg.getOperation().getResponseDetails());
        return null;
    }

    if (!serviceDescMsg.isContentTypeTextUDA()) {
        log.fine("Received service descriptor without or with invalid Content-Type: " + descriptorURL);
        // We continue despite the invalid UPnP message because we can still hope to convert the content
    }

    String descriptorContent = serviceDescMsg.getBodyString();
    if (descriptorContent == null || descriptorContent.length() == 0) {
        log.warning("Received empty service descriptor:" + descriptorURL);
        return null;
    }

    log.fine("Received service descriptor, hydrating service model: " + serviceDescMsg);
    ServiceDescriptorBinder serviceDescriptorBinder =
            getUpnpService().getConfiguration().getServiceDescriptorBinderUDA10();

    return serviceDescriptorBinder.describe(service, descriptorContent);
}
 
Example #30
Source File: IncomingEventRequestMessage.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public IncomingEventRequestMessage(StreamRequestMessage source, RemoteService service) {
    super(source);
    this.service = service;
}