org.fourthline.cling.model.types.ServiceType Java Examples

The following examples show how to use org.fourthline.cling.model.types.ServiceType. 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: UpnpService.java    From HPlayer with Apache License 2.0 6 votes vote down vote up
@Override
protected AndroidUpnpServiceConfiguration createConfiguration() {
    return new AndroidUpnpServiceConfiguration() {

        @Override
        public int getRegistryMaintenanceIntervalMillis() {
            return 7000;
        }

        @Override
        public ServiceType[] getExclusiveServiceTypes() {
            // only care the these service below
            return new ServiceType[]{
                    new UDAServiceType(UpnpServiceType.AVTRANSPORT),
                    new UDAServiceType(UpnpServiceType.RENDERING_CONTROL),
                    new UDAServiceType(UpnpServiceType.CONTENT_DIRECTORY),
            };
        }

    };
}
 
Example #2
Source File: UDA10DeviceDescriptorBinderSAXImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void endElement(ELEMENT element) throws SAXException {
    switch (element) {
        case serviceType:
            getInstance().serviceType = ServiceType.valueOf(getCharacters());
            break;
        case serviceId:
            getInstance().serviceId = ServiceId.valueOf(getCharacters());
            break;
        case SCPDURL:
            getInstance().descriptorURI = parseURI(getCharacters());
            break;
        case controlURL:
            getInstance().controlURI = parseURI(getCharacters());
            break;
        case eventSubURL:
            getInstance().eventSubscriptionURI = parseURI(getCharacters());
            break;
    }
}
 
Example #3
Source File: AnnotationLocalServiceBinder.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public LocalService read(Class<?> clazz, ServiceId id, ServiceType type,
                               boolean supportsQueryStateVariables, Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<StateVariable, StateVariableAccessor> stateVariables = readStateVariables(clazz, stringConvertibleTypes);
    Map<Action, ActionExecutor> actions = readActions(clazz, stateVariables, stringConvertibleTypes);

    // Special treatment of the state variable querying action
    if (supportsQueryStateVariables) {
        actions.put(new QueryStateVariableAction(), new QueryStateVariableExecutor());
    }

    try {
        return new LocalService(type, id, actions, stateVariables, stringConvertibleTypes, supportsQueryStateVariables);

    } catch (ValidationException ex) {
        log.severe("Could not validate device model: " + ex.toString());
        for (ValidationError validationError : ex.getErrors()) {
            log.severe(validationError.toString());
        }
        throw new LocalServiceBindingException("Validation of model failed, check the log");
    }
}
 
Example #4
Source File: ReceivingSearch.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected List<OutgoingSearchResponse> createServiceTypeMessages(LocalDevice device,
                                                                 NetworkAddress activeStreamServer) {
    List<OutgoingSearchResponse> msgs = new ArrayList<OutgoingSearchResponse>();
    for (ServiceType serviceType : device.findServiceTypes()) {
        OutgoingSearchResponse message =
            new OutgoingSearchResponseServiceType(
                    getInputMessage(),
                    getDescriptorLocation(activeStreamServer, device),
                    device,
                    serviceType
            );
        prepareOutgoingSearchResponse(message);
        msgs.add(message);
    }
    return msgs;
}
 
Example #5
Source File: ReceivingSearch.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected void sendSearchResponseServiceType(ServiceType serviceType, NetworkAddress activeStreamServer) throws RouterException {
    log.fine("Responding to service type search: " + serviceType);
    Collection<Device> devices = getUpnpService().getRegistry().getDevices(serviceType);
    for (Device device : devices) {
        if (device instanceof LocalDevice) {

            if (isAdvertisementDisabled((LocalDevice)device))
                continue;

            log.finer("Sending matching service type search result: " + device);
            OutgoingSearchResponse message =
                new OutgoingSearchResponseServiceType(
                        getInputMessage(),
                        getDescriptorLocation(activeStreamServer, (LocalDevice) device),
                        (LocalDevice) device,
                        serviceType
                );
            prepareOutgoingSearchResponse(message);
            getUpnpService().getRouter().send(message);
        }
    }
}
 
Example #6
Source File: ProtocolFactoryImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected boolean isSupportedServiceAdvertisement(IncomingDatagramMessage message) {
    ServiceType[] exclusiveServiceTypes = getUpnpService().getConfiguration().getExclusiveServiceTypes();
    if (exclusiveServiceTypes == null) return false; // Discovery is disabled
    if (exclusiveServiceTypes.length == 0) return true; // Any advertisement is fine

    String usnHeader = message.getHeaders().getFirstHeader(UpnpHeader.Type.USN.getHttpName());
    if (usnHeader == null) return false; // Not a service advertisement, drop it

    try {
        NamedServiceType nst = NamedServiceType.valueOf(usnHeader);
        for (ServiceType exclusiveServiceType : exclusiveServiceTypes) {
            if (nst.getServiceType().implementsVersion(exclusiveServiceType))
                return true;
        }
    } catch (InvalidValueException ex) {
        log.finest("Not a named service type header value: " + usnHeader);
    }
    log.fine("Service advertisement not supported, dropping it: " + usnHeader);
    return false;
}
 
Example #7
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 #8
Source File: Service.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public Service(ServiceType serviceType, ServiceId serviceId,
               Action<S>[] actions, StateVariable<S>[] stateVariables) throws ValidationException {

    this.serviceType = serviceType;
    this.serviceId = serviceId;

    if (actions != null) {
        for (Action action : actions) {
            this.actions.put(action.getName(), action);
            action.setService(this);
        }
    }

    if (stateVariables != null) {
        for (StateVariable stateVariable : stateVariables) {
            this.stateVariables.put(stateVariable.getName(), stateVariable);
            stateVariable.setService(this);
        }
    }

}
 
Example #9
Source File: LocalService.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public LocalService(ServiceType serviceType, ServiceId serviceId,
                    Map<Action, ActionExecutor> actionExecutors,
                    Map<StateVariable, StateVariableAccessor> stateVariableAccessors,
                    Set<Class> stringConvertibleTypes,
                    boolean supportsQueryStateVariables) throws ValidationException {

    super(serviceType, serviceId,
            actionExecutors.keySet().toArray(new Action[actionExecutors.size()]),
            stateVariableAccessors.keySet().toArray(new StateVariable[stateVariableAccessors.size()])
    );

    this.supportsQueryStateVariables = supportsQueryStateVariables;
    this.stringConvertibleTypes = stringConvertibleTypes;
    this.stateVariableAccessors = stateVariableAccessors;
    this.actionExecutors = actionExecutors;
}
 
Example #10
Source File: UpnpService.java    From HPlayer with Apache License 2.0 6 votes vote down vote up
@Override
protected AndroidUpnpServiceConfiguration createConfiguration() {
    return new AndroidUpnpServiceConfiguration() {

        @Override
        public int getRegistryMaintenanceIntervalMillis() {
            return 7000;
        }

        @Override
        public ServiceType[] getExclusiveServiceTypes() {
            // only care the these service below
            return new ServiceType[]{
                    new UDAServiceType(UpnpServiceType.AVTRANSPORT),
                    new UDAServiceType(UpnpServiceType.RENDERING_CONTROL),
            };
        }

    };
}
 
Example #11
Source File: UpnpService.java    From HPlayer with Apache License 2.0 6 votes vote down vote up
@Override
protected AndroidUpnpServiceConfiguration createConfiguration() {
    return new AndroidUpnpServiceConfiguration() {

        @Override
        public int getRegistryMaintenanceIntervalMillis() {
            return 7000;
        }

        @Override
        public ServiceType[] getExclusiveServiceTypes() {
            // only care the these service below
            return new ServiceType[]{
                    new UDAServiceType(UpnpServiceType.CONTENT_DIRECTORY),
            };
        }

    };
}
 
Example #12
Source File: ProtocolFactoryImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected boolean isSupportedServiceAdvertisement(IncomingDatagramMessage message) {
    ServiceType[] exclusiveServiceTypes = getUpnpService().getConfiguration().getExclusiveServiceTypes();
    if (exclusiveServiceTypes == null) return false; // Discovery is disabled
    if (exclusiveServiceTypes.length == 0) return true; // Any advertisement is fine

    String usnHeader = message.getHeaders().getFirstHeader(UpnpHeader.Type.USN.getHttpName());
    if (usnHeader == null) return false; // Not a service advertisement, drop it

    try {
        NamedServiceType nst = NamedServiceType.valueOf(usnHeader);
        for (ServiceType exclusiveServiceType : exclusiveServiceTypes) {
            if (nst.getServiceType().implementsVersion(exclusiveServiceType))
                return true;
        }
    } catch (InvalidValueException ex) {
        log.finest("Not a named service type header value: " + usnHeader);
    }
    log.fine("Service advertisement not supported, dropping it: " + usnHeader);
    return false;
}
 
Example #13
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 #14
Source File: ReceivingSearch.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected List<OutgoingSearchResponse> createServiceTypeMessages(LocalDevice device,
                                                                 NetworkAddress activeStreamServer) {
    List<OutgoingSearchResponse> msgs = new ArrayList<OutgoingSearchResponse>();
    for (ServiceType serviceType : device.findServiceTypes()) {
        OutgoingSearchResponse message =
            new OutgoingSearchResponseServiceType(
                    getInputMessage(),
                    getDescriptorLocation(activeStreamServer, device),
                    device,
                    serviceType
            );
        prepareOutgoingSearchResponse(message);
        msgs.add(message);
    }
    return msgs;
}
 
Example #15
Source File: ReceivingSearch.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected void sendSearchResponseServiceType(ServiceType serviceType, NetworkAddress activeStreamServer) throws RouterException {
    log.fine("Responding to service type search: " + serviceType);
    Collection<Device> devices = getUpnpService().getRegistry().getDevices(serviceType);
    for (Device device : devices) {
        if (device instanceof LocalDevice) {

            if (isAdvertisementDisabled((LocalDevice)device))
                continue;

            log.finer("Sending matching service type search result: " + device);
            OutgoingSearchResponse message =
                new OutgoingSearchResponseServiceType(
                        getInputMessage(),
                        getDescriptorLocation(activeStreamServer, (LocalDevice) device),
                        (LocalDevice) device,
                        serviceType
                );
            prepareOutgoingSearchResponse(message);
            getUpnpService().getRouter().send(message);
        }
    }
}
 
Example #16
Source File: UDA10DeviceDescriptorBinderSAXImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void endElement(ELEMENT element) throws SAXException {
    switch (element) {
        case serviceType:
            getInstance().serviceType = ServiceType.valueOf(getCharacters());
            break;
        case serviceId:
            getInstance().serviceId = ServiceId.valueOf(getCharacters());
            break;
        case SCPDURL:
            getInstance().descriptorURI = parseURI(getCharacters());
            break;
        case controlURL:
            getInstance().controlURI = parseURI(getCharacters());
            break;
        case eventSubURL:
            getInstance().eventSubscriptionURI = parseURI(getCharacters());
            break;
    }
}
 
Example #17
Source File: AnnotationLocalServiceBinder.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public LocalService read(Class<?> clazz, ServiceId id, ServiceType type,
                               boolean supportsQueryStateVariables, Set<Class> stringConvertibleTypes)
        throws LocalServiceBindingException {

    Map<StateVariable, StateVariableAccessor> stateVariables = readStateVariables(clazz, stringConvertibleTypes);
    Map<Action, ActionExecutor> actions = readActions(clazz, stateVariables, stringConvertibleTypes);

    // Special treatment of the state variable querying action
    if (supportsQueryStateVariables) {
        actions.put(new QueryStateVariableAction(), new QueryStateVariableExecutor());
    }

    try {
        return new LocalService(type, id, actions, stateVariables, stringConvertibleTypes, supportsQueryStateVariables);

    } catch (ValidationException ex) {
        log.severe("Could not validate device model: " + ex.toString());
        for (ValidationError validationError : ex.getErrors()) {
            log.severe(validationError.toString());
        }
        throw new LocalServiceBindingException("Validation of model failed, check the log");
    }
}
 
Example #18
Source File: Service.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public Service(ServiceType serviceType, ServiceId serviceId,
               Action<S>[] actions, StateVariable<S>[] stateVariables) throws ValidationException {

    this.serviceType = serviceType;
    this.serviceId = serviceId;

    if (actions != null) {
        for (Action action : actions) {
            this.actions.put(action.getName(), action);
            action.setService(this);
        }
    }

    if (stateVariables != null) {
        for (StateVariable stateVariable : stateVariables) {
            this.stateVariables.put(stateVariable.getName(), stateVariable);
            stateVariable.setService(this);
        }
    }

}
 
Example #19
Source File: LocalService.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public LocalService(ServiceType serviceType, ServiceId serviceId,
                    Map<Action, ActionExecutor> actionExecutors,
                    Map<StateVariable, StateVariableAccessor> stateVariableAccessors,
                    Set<Class> stringConvertibleTypes,
                    boolean supportsQueryStateVariables) throws ValidationException {

    super(serviceType, serviceId,
            actionExecutors.keySet().toArray(new Action[actionExecutors.size()]),
            stateVariableAccessors.keySet().toArray(new StateVariable[stateVariableAccessors.size()])
    );

    this.supportsQueryStateVariables = supportsQueryStateVariables;
    this.stringConvertibleTypes = stringConvertibleTypes;
    this.stateVariableAccessors = stateVariableAccessors;
    this.actionExecutors = actionExecutors;
}
 
Example #20
Source File: DLNAController.java    From Popeens-DSub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setVolume(int volume) {
	if(volume < 0) {
		volume = 0;
	} else if(volume > device.volumeMax) {
		volume = device.volumeMax;
	}

	device.volume = volume;
	try {
		controlPoint.execute(new SetVolume(device.renderer.findService(new ServiceType("schemas-upnp-org", "RenderingControl")), volume) {
			@SuppressWarnings("rawtypes")
			@Override
			public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMessage) {
				Log.w(TAG, "Set volume failed: " + defaultMessage);
			}
		});
	} catch(Exception e) {
		Log.w(TAG, "Failed to set volume");
	}
}
 
Example #21
Source File: RemoteService.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public RemoteService(ServiceType serviceType, ServiceId serviceId,
                     URI descriptorURI, URI controlURI, URI eventSubscriptionURI,
                     Action<RemoteService>[] actions, StateVariable<RemoteService>[] stateVariables) throws ValidationException {
    super(serviceType, serviceId, actions, stateVariables);

    this.descriptorURI = descriptorURI;
    this.controlURI = controlURI;
    this.eventSubscriptionURI = eventSubscriptionURI;

    List<ValidationError> errors = validateThis();
    if (errors.size() > 0) {
        throw new ValidationException("Validation of device graph failed, call getErrors() on exception", errors);
    }
}
 
Example #22
Source File: Device.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected Collection<D> find(ServiceType serviceType, D current) {
    Collection<S> services = findServices(serviceType, null, current);
    Collection<D> devices = new HashSet();
    for (Service service : services) {
        devices.add((D) service.getDevice());
    }
    return devices;
}
 
Example #23
Source File: Device.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public ServiceType[] findServiceTypes() {
    Collection<S> services = findServices(null, null, (D) this);
    Collection<ServiceType> col = new HashSet();
    for (S service : services) {
        col.add(service.getServiceType());
    }
    return col.toArray(new ServiceType[col.size()]);
}
 
Example #24
Source File: SendingNotification.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
protected List<OutgoingNotificationRequest> createServiceTypeMessages(LocalDevice device,
                                                                      Location descriptorLocation) {
    List<OutgoingNotificationRequest> msgs = new ArrayList();

    for (ServiceType serviceType : device.findServiceTypes()) {
        msgs.add(
                new OutgoingNotificationRequestServiceType(
                        descriptorLocation, device,
                        getNotificationSubtype(), serviceType
                )
        );
    }

    return msgs;
}
 
Example #25
Source File: RemoteDevice.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public RemoteService newInstance(ServiceType serviceType, ServiceId serviceId,
                                 URI descriptorURI, URI controlURI, URI eventSubscriptionURI,
                                 Action<RemoteService>[] actions, StateVariable<RemoteService>[] stateVariables) throws ValidationException {
    return new RemoteService(
            serviceType, serviceId,
            descriptorURI, controlURI, eventSubscriptionURI,
            actions, stateVariables
    );
}
 
Example #26
Source File: LocalDevice.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
public LocalService newInstance(ServiceType serviceType, ServiceId serviceId,
                                URI descriptorURI, URI controlURI, URI eventSubscriptionURI,
                                Action<LocalService>[] actions, StateVariable<LocalService>[] stateVariables) throws ValidationException {
    return new LocalService(
            serviceType, serviceId,
            actions, stateVariables
    );
}
 
Example #27
Source File: OutgoingNotificationRequestServiceType.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public OutgoingNotificationRequestServiceType(Location location,
                                              LocalDevice device, NotificationSubtype type,
                                              ServiceType serviceType) {

    super(location, device, type);

    getHeaders().add(UpnpHeader.Type.NT, new ServiceTypeHeader(serviceType));
    getHeaders().add(UpnpHeader.Type.USN, new ServiceUSNHeader(device.getIdentity().getUdn(), serviceType));
}
 
Example #28
Source File: RegistryItems.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns all devices (root or embedded) which have at least one matching service.
 *
 * @param serviceType The type of service to search for.
 * @return Any registered root or embedded device with at least one matching service.
 */
Collection<D> get(ServiceType serviceType) {
    Collection<D> devices = new HashSet();
    for (RegistryItem<UDN, D> item : deviceItems) {

        D[] d = (D[])item.getItem().findDevices(serviceType);
        if (d != null) {
            devices.addAll(Arrays.asList(d));
        }
    }
    return devices;
}
 
Example #29
Source File: OutgoingSearchResponseServiceType.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public OutgoingSearchResponseServiceType(IncomingDatagramMessage request,
                                         Location location,
                                         LocalDevice device,
                                         ServiceType serviceType) {
    super(request, location, device);

    getHeaders().add(UpnpHeader.Type.ST, new ServiceTypeHeader(serviceType));
    getHeaders().add(UpnpHeader.Type.USN, new ServiceUSNHeader(device.getIdentity().getUdn(), serviceType));
}
 
Example #30
Source File: LocalService.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public LocalService(ServiceType serviceType, ServiceId serviceId,
                    Action[] actions, StateVariable[] stateVariables) throws ValidationException {
    super(serviceType, serviceId, actions, stateVariables);
    this.manager = null;
    this.actionExecutors = new HashMap();
    this.stateVariableAccessors = new HashMap();
    this.stringConvertibleTypes = new HashSet();
    this.supportsQueryStateVariables = true;
}