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

The following examples show how to use org.fourthline.cling.model.types.UDN. 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: ReceivingSearch.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected void sendSearchResponseUDN(UDN udn, NetworkAddress activeStreamServer) throws RouterException {
    Device device = getUpnpService().getRegistry().getDevice(udn, false);
    if (device != null && device instanceof LocalDevice) {

        if (isAdvertisementDisabled((LocalDevice)device))
            return;

        log.fine("Responding to UDN device search: " + udn);
        OutgoingSearchResponse message =
            new OutgoingSearchResponseUDN(
                    getInputMessage(),
                    getDescriptorLocation(activeStreamServer, (LocalDevice) device),
                    (LocalDevice) device
            );
        prepareOutgoingSearchResponse(message);
        getUpnpService().getRouter().send(message);
    }
}
 
Example #2
Source File: BeyondUpnpService.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();

    //Create LocalDevice
    LocalService localService = new AnnotationLocalServiceBinder().read(BeyondContentDirectoryService.class);
    localService.setManager(new DefaultServiceManager<>(
            localService, BeyondContentDirectoryService.class));

    String macAddress = Utils.getMACAddress(Utils.WLAN0);
    //Generate UUID by MAC address
    UDN udn = UDN.valueOf(UUID.nameUUIDFromBytes(macAddress.getBytes()).toString());

    try {
        mLocalDevice = new LocalDevice(new DeviceIdentity(udn), new UDADeviceType("MediaServer"),
                new DeviceDetails("Local Media Server"), new LocalService[]{localService});
    } catch (ValidationException e) {
        e.printStackTrace();
    }
    upnpService.getRegistry().addDevice(mLocalDevice);

    //LocalBinder instead of binder
    binder = new LocalBinder();
}
 
Example #3
Source File: IncomingNotificationRequest.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @return The UDN value after parsing various USN header values, or <code>null</code>.
 */
public UDN getUDN() {
    // This processes the headers as specified in UDA 1.0, tables in section 1.1.12

    UpnpHeader<UDN> udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, USNRootDeviceHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, UDNHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    UpnpHeader<NamedDeviceType> deviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, DeviceUSNHeader.class);
    if (deviceTypeHeader != null) return deviceTypeHeader.getValue().getUdn();

    UpnpHeader<NamedServiceType> serviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, ServiceUSNHeader.class);
    if (serviceTypeHeader != null) return serviceTypeHeader.getValue().getUdn();

    return null;
}
 
Example #4
Source File: SempDiscovery.java    From SmartApplianceEnabler with GNU General Public License v2.0 6 votes vote down vote up
private LocalDevice createDevice()
        throws ValidationException, LocalServiceBindingException, IOException {

    DeviceIdentity identity =
            new DeviceIdentity(
                    UDN.uniqueSystemIdentifier(SmartApplianceEnabler.class.getSimpleName())
            );

    DeviceType type = new SmartApplianceEnablerDeviceType();

    DeviceDetails details =
            new DeviceDetails(
                    SmartApplianceEnabler.class.getSimpleName(),
                    new ManufacturerDetails(SmartApplianceEnabler.MANUFACTURER_NAME, URI.create(SmartApplianceEnabler.MANUFACTURER_URI)),
                    new ModelDetails(
                            SmartApplianceEnabler.class.getSimpleName(),
                            SmartApplianceEnabler.DESCRIPTION,
                            SmartApplianceEnabler.VERSION,
                            URI.create(SmartApplianceEnabler.MODEL_URI)
                    )
            );

    return new LocalDevice(identity, type, details, (Icon) null, (LocalService) null);
}
 
Example #5
Source File: IncomingSearchResponse.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public UDN getRootDeviceUDN() {
    // This processes the headers as specified in UDA 1.0, tables in section 1.1.12

    UpnpHeader<UDN> udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, USNRootDeviceHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, UDNHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    UpnpHeader<NamedDeviceType> deviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, DeviceUSNHeader.class);
    if (deviceTypeHeader != null) return deviceTypeHeader.getValue().getUdn();

    UpnpHeader<NamedServiceType> serviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, ServiceUSNHeader.class);
    if (serviceTypeHeader != null) return serviceTypeHeader.getValue().getUdn();

    return null;
}
 
Example #6
Source File: IncomingSearchResponse.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public UDN getRootDeviceUDN() {
    // This processes the headers as specified in UDA 1.0, tables in section 1.1.12

    UpnpHeader<UDN> udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, USNRootDeviceHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    udnHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, UDNHeader.class);
    if (udnHeader != null) return udnHeader.getValue();

    UpnpHeader<NamedDeviceType> deviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, DeviceUSNHeader.class);
    if (deviceTypeHeader != null) return deviceTypeHeader.getValue().getUdn();

    UpnpHeader<NamedServiceType> serviceTypeHeader = getHeaders().getFirstHeader(UpnpHeader.Type.USN, ServiceUSNHeader.class);
    if (serviceTypeHeader != null) return serviceTypeHeader.getValue().getUdn();

    return null;
}
 
Example #7
Source File: UpnpUtil.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public static UDN uniqueSystemIdentifier(String salt) {
    StringBuilder systemSalt = new StringBuilder();
    Log.d(TAG,  "host:" + BaseApplication.getHostName() + " ip:" +   BaseApplication.getHostAddress());
    if (null != BaseApplication.getHostName()
            && null != BaseApplication.getHostAddress()) {
        systemSalt.append(BaseApplication.getHostName()).append(
                BaseApplication.getHostAddress());
    }
    systemSalt.append(android.os.Build.MODEL);
    systemSalt.append(android.os.Build.MANUFACTURER);

    try {
        byte[] hash = MessageDigest.getInstance("MD5").digest(systemSalt.toString().getBytes());
        return new UDN(new UUID(new BigInteger(-1, hash).longValue(), salt.hashCode()));
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example #8
Source File: LocalItems.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
Collection<LocalDevice> get() {
    Set<LocalDevice> c = new HashSet();
    for (RegistryItem<UDN, LocalDevice> item : getDeviceItems()) {
        c.add(item.getItem());
    }
    return Collections.unmodifiableCollection(c);
}
 
Example #9
Source File: RegistryImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
synchronized public boolean removeDevice(UDN udn) {
    Device device = getDevice(udn, true);
    if (device != null && device instanceof LocalDevice)
        return removeDevice((LocalDevice) device);
    if (device != null && device instanceof RemoteDevice)
        return removeDevice((RemoteDevice) device);
    return false;
}
 
Example #10
Source File: UDNHeader.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public void setString(String s) throws InvalidHeaderException {
    if (!s.startsWith(UDN.PREFIX)) {
        throw new InvalidHeaderException("Invalid UDA header value, must start with '"+UDN.PREFIX+"': " + s);
    }

    if (s.contains("::urn")) {
        throw new InvalidHeaderException("Invalid UDA header value, must not contain '::urn': " + s);
    }

    UDN udn = new UDN( s.substring(UDN.PREFIX.length()) );
    setValue(udn);
}
 
Example #11
Source File: Device.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected D find(UDN udn, D current) {
    if (current.getIdentity().getUdn().equals(udn)) return current;
    if (current.hasEmbeddedDevices()) {
        for (D embeddedDevice : (D[]) current.getEmbeddedDevices()) {
            D match;
            if ((match = find(udn, embeddedDevice)) != null) return match;
        }
    }
    return null;
}
 
Example #12
Source File: RegistryImpl.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
synchronized public boolean removeDevice(UDN udn) {
    Device device = getDevice(udn, true);
    if (device != null && device instanceof LocalDevice)
        return removeDevice((LocalDevice) device);
    if (device != null && device instanceof RemoteDevice)
        return removeDevice((RemoteDevice) device);
    return false;
}
 
Example #13
Source File: ServiceReference.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public ServiceReference(String s) {
    String[] split = s.split("/");
    if (split.length == 2) {
        this.udn =  UDN.valueOf(split[0]);
        this.serviceId = ServiceId.valueOf(split[1]);
    } else {
        this.udn = null;
        this.serviceId = null;
    }
}
 
Example #14
Source File: RemoteDevice.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RemoteDevice newInstance(UDN udn, UDAVersion version, DeviceType type, DeviceDetails details,
                                Icon[] icons, RemoteService[] services,
                                List<RemoteDevice> embeddedDevices) throws ValidationException {
    return new RemoteDevice(
            new RemoteDeviceIdentity(udn, getIdentity()),
            version, type, details, icons,
            services,
            embeddedDevices.size() > 0 ? embeddedDevices.toArray(new RemoteDevice[embeddedDevices.size()]) : null
    );
}
 
Example #15
Source File: RemoteItems.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public void resume() {
    log.fine("Updating remote device expiration timestamps on resume");
    List<RemoteDeviceIdentity> toUpdate = new ArrayList<RemoteDeviceIdentity>();
    for (RegistryItem<UDN, RemoteDevice> remoteItem : getDeviceItems()) {
        toUpdate.add(remoteItem.getItem().getIdentity());
    }
    for (RemoteDeviceIdentity identity : toUpdate) {
        update(identity);
    }
}
 
Example #16
Source File: LocalDevice.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LocalDevice newInstance(UDN udn, UDAVersion version, DeviceType type, DeviceDetails details,
                               Icon[] icons, LocalService[] services, List<LocalDevice> embeddedDevices)
        throws ValidationException {
    return new LocalDevice(
            new DeviceIdentity(udn, getIdentity().getMaxAgeSeconds()),
            version, type, details, icons,
            services,
            embeddedDevices.size() > 0 ? embeddedDevices.toArray(new LocalDevice[embeddedDevices.size()]) : null
    );
}
 
Example #17
Source File: RemoteItems.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public void resume() {
    log.fine("Updating remote device expiration timestamps on resume");
    List<RemoteDeviceIdentity> toUpdate = new ArrayList<RemoteDeviceIdentity>();
    for (RegistryItem<UDN, RemoteDevice> remoteItem : getDeviceItems()) {
        toUpdate.add(remoteItem.getItem().getIdentity());
    }
    for (RemoteDeviceIdentity identity : toUpdate) {
        update(identity);
    }
}
 
Example #18
Source File: LocalItems.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
Collection<LocalDevice> get() {
    Set<LocalDevice> c = new HashSet();
    for (RegistryItem<UDN, LocalDevice> item : getDeviceItems()) {
        c.add(item.getItem());
    }
    return Collections.unmodifiableCollection(c);
}
 
Example #19
Source File: RegistryItems.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns root and embedded devices registered under the given UDN.
 *
 * @param udn A unique device name.
 * @param rootOnly Set to true if only root devices (no embedded) should be searched
 * @return Any registered root or embedded device under the given UDN, <tt>null</tt> if
 *         no device with the given UDN has been registered.
 */
D get(UDN udn, boolean rootOnly) {
    for (RegistryItem<UDN, D> item : deviceItems) {
        D device = item.getItem();
        if (device.getIdentity().getUdn().equals(udn)) {
            return device;
        }
        if (!rootOnly) {
            D foundDevice = (D)item.getItem().findDevice(udn);
            if (foundDevice != null) return foundDevice;
        }
    }
    return null;
}
 
Example #20
Source File: UDNHeader.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public void setString(String s) throws InvalidHeaderException {
    if (!s.startsWith(UDN.PREFIX)) {
        throw new InvalidHeaderException("Invalid UDA header value, must start with '"+UDN.PREFIX+"': " + s);
    }

    if (s.contains("::urn")) {
        throw new InvalidHeaderException("Invalid UDA header value, must not contain '::urn': " + s);
    }

    UDN udn = new UDN( s.substring(UDN.PREFIX.length()) );
    setValue(udn);
}
 
Example #21
Source File: ServiceReference.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public ServiceReference(String s) {
    String[] split = s.split("/");
    if (split.length == 2) {
        this.udn =  UDN.valueOf(split[0]);
        this.serviceId = ServiceId.valueOf(split[1]);
    } else {
        this.udn = null;
        this.serviceId = null;
    }
}
 
Example #22
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 #23
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) with a compatible type.
 * <p>
 * This routine will check compatible versions, as described by the UDA.
 * </p>
 *
 * @param deviceType The minimum device type required.
 * @return Any registered root or embedded device with a compatible type.
 */
Collection<D> get(DeviceType deviceType) {
    Collection<D> devices = new HashSet();
    for (RegistryItem<UDN, D> item : deviceItems) {
        D[] d = (D[])item.getItem().findDevices(deviceType);
        if (d != null) {
            devices.addAll(Arrays.asList(d));
        }
    }
    return devices;
}
 
Example #24
Source File: RegistryItems.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns root and embedded devices registered under the given UDN.
 *
 * @param udn A unique device name.
 * @param rootOnly Set to true if only root devices (no embedded) should be searched
 * @return Any registered root or embedded device under the given UDN, <tt>null</tt> if
 *         no device with the given UDN has been registered.
 */
D get(UDN udn, boolean rootOnly) {
    for (RegistryItem<UDN, D> item : deviceItems) {
        D device = item.getItem();
        if (device.getIdentity().getUdn().equals(udn)) {
            return device;
        }
        if (!rootOnly) {
            D foundDevice = (D)item.getItem().findDevice(udn);
            if (foundDevice != null) return foundDevice;
        }
    }
    return null;
}
 
Example #25
Source File: LocalItems.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public void advertiseLocalDevices() {
    for (RegistryItem<UDN, LocalDevice> localItem : deviceItems) {
        if (isAdvertised(localItem.getKey()))
            advertiseAlive(localItem.getItem());
    }
}
 
Example #26
Source File: RegistryImpl.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
synchronized public RemoteDevice getRemoteDevice(UDN udn, boolean rootOnly) {
    return remoteItems.get(udn, rootOnly);
}
 
Example #27
Source File: LocalItems.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
void add(final LocalDevice localDevice, DiscoveryOptions options) throws RegistrationException {

        // Always set/override the options, even if we don't end up adding the device
        setDiscoveryOptions(localDevice.getIdentity().getUdn(), options);

        if (registry.getDevice(localDevice.getIdentity().getUdn(), false) != null) {
            log.fine("Ignoring addition, device already registered: " + localDevice);
            return;
        }

        log.fine("Adding local device to registry: " + localDevice);

        for (Resource deviceResource : getResources(localDevice)) {

            if (registry.getResource(deviceResource.getPathQuery()) != null) {
                throw new RegistrationException("URI namespace conflict with already registered resource: " + deviceResource);
            }

            registry.addResource(deviceResource);
            log.fine("Registered resource: " + deviceResource);

        }

        log.fine("Adding item to registry with expiration in seconds: " + localDevice.getIdentity().getMaxAgeSeconds());

        RegistryItem<UDN, LocalDevice> localItem = new RegistryItem<UDN, LocalDevice>(
                localDevice.getIdentity().getUdn(),
                localDevice,
                localDevice.getIdentity().getMaxAgeSeconds()
        );

        getDeviceItems().add(localItem);
        log.fine("Registered local device: " + localItem);

        if (isByeByeBeforeFirstAlive(localItem.getKey()))
            advertiseByebye(localDevice, true);

        if (isAdvertised(localItem.getKey()))
             advertiseAlive(localDevice);

        for (final RegistryListener listener : registry.getListeners()) {
            registry.getConfiguration().getRegistryListenerExecutor().execute(
                new Runnable() {
                    public void run() {
                        listener.localDeviceAdded(registry, localDevice);
                    }
                }
            );
        }

    }
 
Example #28
Source File: LocalItems.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
protected boolean isByeByeBeforeFirstAlive(UDN udn) {
    // Defaults to false
    return getDiscoveryOptions(udn) != null && getDiscoveryOptions(udn).isByeByeBeforeFirstAlive();
}
 
Example #29
Source File: DeviceIdentity.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public DeviceIdentity(UDN udn, Integer maxAgeSeconds) {
    this.udn = udn;
    this.maxAgeSeconds = maxAgeSeconds;
}
 
Example #30
Source File: USNRootDeviceHeader.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public USNRootDeviceHeader(UDN udn) {
    setValue(udn);
}