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

The following examples show how to use org.fourthline.cling.model.types.UDN. These examples are extracted from open source projects. 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 Project: TVRemoteIME   Source File: ReceivingSearch.java    License: 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 Project: DroidDLNA   Source File: UpnpUtil.java    License: 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 3
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 4
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 5
/**
 * @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 6
Source Project: BeyondUPnP   Source File: BeyondUpnpService.java    License: 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 7
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 8
Source Project: DroidDLNA   Source File: RegistryImpl.java    License: 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 9
Source Project: TVRemoteIME   Source File: RemoteDevice.java    License: 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 10
Source Project: DroidDLNA   Source File: RemoteItems.java    License: 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 11
Source Project: TVRemoteIME   Source File: LocalDevice.java    License: 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 12
Source Project: DroidDLNA   Source File: LocalItems.java    License: 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 13
Source Project: TVRemoteIME   Source File: UDNHeader.java    License: 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 14
Source Project: TVRemoteIME   Source File: ServiceReference.java    License: 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 15
Source Project: TVRemoteIME   Source File: RegistryItems.java    License: 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 16
Source Project: TVRemoteIME   Source File: RegistryItems.java    License: 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 17
Source Project: TVRemoteIME   Source File: RegistryItems.java    License: 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 18
Source Project: TVRemoteIME   Source File: RemoteItems.java    License: 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 19
Source Project: DroidDLNA   Source File: ServiceReference.java    License: 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 20
Source Project: TVRemoteIME   Source File: RegistryImpl.java    License: 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 21
Source Project: DroidDLNA   Source File: UDNHeader.java    License: 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 22
Source Project: TVRemoteIME   Source File: LocalItems.java    License: 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 23
Source Project: DroidDLNA   Source File: RegistryItems.java    License: 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 24
Source Project: DroidDLNA   Source File: Device.java    License: 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 25
private LocalDevice createMediaServerDevice() throws Exception {

        String serverName = settingsService.getDlnaServerName();
        DeviceIdentity identity = new DeviceIdentity(UDN.uniqueSystemIdentifier(serverName));
        DeviceType type = new UDADeviceType("MediaServer", 1);

        // TODO: DLNACaps

        DeviceDetails details = new DeviceDetails(serverName, new ManufacturerDetails(serverName),
                new ModelDetails(serverName),
                new DLNADoc[]{new DLNADoc("DMS", DLNADoc.Version.V1_5)}, null);

        InputStream in = getClass().getResourceAsStream("logo-512.png");
        Icon icon = new Icon("image/png", 512, 512, 32, "logo-512", in);
        FileUtil.closeQuietly(in);

        LocalService<CustomContentDirectory> contentDirectoryservice = new AnnotationLocalServiceBinder().read(CustomContentDirectory.class);
        contentDirectoryservice.setManager(new DefaultServiceManager<CustomContentDirectory>(contentDirectoryservice) {

            @Override
            protected CustomContentDirectory createServiceInstance() {
                return dispatchingContentDirectory;
            }
        });

        final ProtocolInfos protocols = new ProtocolInfos();
        for (DLNAProfiles dlnaProfile : DLNAProfiles.values()) {
            if (dlnaProfile == DLNAProfiles.NONE) {
                continue;
            }
            try {
                protocols.add(new DLNAProtocolInfo(dlnaProfile));
            } catch (Exception e) {
                // Silently ignored.
            }
        }

        LocalService<ConnectionManagerService> connetionManagerService = new AnnotationLocalServiceBinder().read(ConnectionManagerService.class);
        connetionManagerService.setManager(new DefaultServiceManager<ConnectionManagerService>(connetionManagerService) {
            @Override
            protected ConnectionManagerService createServiceInstance() {
                return new ConnectionManagerService(protocols, null);
            }
        });

        // For compatibility with Microsoft
        LocalService<MSMediaReceiverRegistrarService> receiverService = new AnnotationLocalServiceBinder().read(MSMediaReceiverRegistrarService.class);
        receiverService.setManager(new DefaultServiceManager<>(receiverService, MSMediaReceiverRegistrarService.class));

        return new LocalDevice(identity, type, details, new Icon[]{icon}, new LocalService[]{contentDirectoryservice, connetionManagerService, receiverService});
    }
 
Example 26
Source Project: DroidDLNA   Source File: LocalDevice.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public LocalDevice findDevice(UDN udn) {
    return find(udn, this);
}
 
Example 27
Source Project: DroidDLNA   Source File: RemoteItems.java    License: GNU General Public License v3.0 4 votes vote down vote up
boolean update(RemoteDeviceIdentity rdIdentity) {

        for (LocalDevice localDevice : registry.getLocalDevices()) {
            if (localDevice.findDevice(rdIdentity.getUdn()) != null) {
                log.fine("Ignoring update, a local device graph contains UDN");
                return true;
            }
        }

        RemoteDevice registeredRemoteDevice = get(rdIdentity.getUdn(), false);
        if (registeredRemoteDevice != null) {

            if (!registeredRemoteDevice.isRoot()) {
                log.fine("Updating root device of embedded: " + registeredRemoteDevice);
                registeredRemoteDevice = registeredRemoteDevice.getRoot();
            }

            // Override the device's maximum age if configured (systems without multicast support)
            final RegistryItem<UDN, RemoteDevice> item = new RegistryItem<UDN, RemoteDevice>(
                    registeredRemoteDevice.getIdentity().getUdn(),
                    registeredRemoteDevice,
                    registry.getConfiguration().getRemoteDeviceMaxAgeSeconds() != null
                            ? registry.getConfiguration().getRemoteDeviceMaxAgeSeconds()
                            : rdIdentity.getMaxAgeSeconds()
            );

            log.fine("Updating expiration of: " + registeredRemoteDevice);
            getDeviceItems().remove(item);
            getDeviceItems().add(item);

            log.fine("Remote device updated, calling listeners: " + registeredRemoteDevice);
            for (final RegistryListener listener : registry.getListeners()) {
                registry.getConfiguration().getRegistryListenerExecutor().execute(
                        new Runnable() {
                            public void run() {
                                listener.remoteDeviceUpdated(registry, item.getItem());
                            }
                        }
                );
            }

            return true;

        }
        return false;
    }
 
Example 28
Source Project: DroidDLNA   Source File: DeviceItem.java    License: GNU General Public License v3.0 4 votes vote down vote up
public UDN getUdn() {
    return udn;
}
 
Example 29
Source Project: DroidDLNA   Source File: DeviceUSNHeader.java    License: GNU General Public License v3.0 4 votes vote down vote up
public DeviceUSNHeader(UDN udn, DeviceType deviceType) {
    setValue(new NamedDeviceType(udn, deviceType));
}
 
Example 30
Source Project: TVRemoteIME   Source File: Device.java    License: GNU General Public License v2.0 4 votes vote down vote up
public abstract D newInstance(UDN udn, UDAVersion version, DeviceType type, DeviceDetails details,
Icon[] icons, S[] services, List<D> embeddedDevices) throws ValidationException;