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

The following examples show how to use org.fourthline.cling.model.meta.Device. 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: PlaybackCommand.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
public static void pause() {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null) return;

    Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new Pause(avtService) {
            @Override
            public void success(ActionInvocation invocation) {
                Log.i(TAG, "Pause success.");
            }

            @Override
            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                Log.e(TAG, "Pause failed");
            }
        });
    }
}
 
Example #2
Source File: ClingRegistryListener.java    From portmapper with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private Service<?, ?> findConnectionService(final Device[] connectionDevices) {
    for (final Device connectionDevice : connectionDevices) {

        final Service ipConnectionService = connectionDevice.findService(IP_SERVICE_TYPE);
        final Service pppConnectionService = connectionDevice.findService(PPP_SERVICE_TYPE);

        if (ipConnectionService != null) {
            logger.info("Device {} supports ip service type: {}", connectionDevice, ipConnectionService);
            return ipConnectionService;
        }
        if (pppConnectionService != null) {
            logger.info("Device {} supports ppp service type: {}", connectionDevice, pppConnectionService);
            return pppConnectionService;
        }

        logger.info("IGD {} doesn't support IP or PPP WAN connection service", connectionDevice);
    }
    logger.debug("None of the {} devices supports IP or PPP WAN connections", connectionDevices.length);
    return null;
}
 
Example #3
Source File: Namespace.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public Resource[] getResources(Device device) throws ValidationException {
    if (!device.isRoot()) return null;

    Set<Resource> resources = new HashSet<Resource>();
    List<ValidationError> errors = new ArrayList<ValidationError>();

    log.fine("Discovering local resources of device graph");
    Resource[] discoveredResources = device.discoverResources(this);
    for (Resource resource : discoveredResources) {
        log.finer("Discovered: " + resource);
        if (!resources.add(resource)) {
            log.finer("Local resource already exists, queueing validation error");
            errors.add(new ValidationError(
                    getClass(),
                    "resources",
                    "Local URI namespace conflict between resources of device: " + resource
            ));
        }
    }
    if (errors.size() > 0) {
        throw new ValidationException("Validation of device graph failed, call getErrors() on exception", errors);
    }
    return resources.toArray(new Resource[resources.size()]);
}
 
Example #4
Source File: MutableDevice.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public Device build(Device prototype, UDAVersion deviceVersion, URL baseURL) throws ValidationException {

        List<Device> embeddedDevicesList = new ArrayList();
        for (MutableDevice embeddedDevice : embeddedDevices) {
            embeddedDevicesList.add(embeddedDevice.build(prototype, deviceVersion, baseURL));
        }
        return prototype.newInstance(
                udn,
                deviceVersion,
                createDeviceType(),
                createDeviceDetails(baseURL),
                createIcons(),
                createServices(prototype),
                embeddedDevicesList
        );
    }
 
Example #5
Source File: DeviceListDialogFragment.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null)
        convertView = mInflater.inflate(R.layout.listview_items, null);

    Device item = getItem(position);
    if (item == null) {
        return convertView;
    }

    ImageView imageView = (ImageView)convertView.findViewById(R.id.listview_item_image);
    imageView.setBackgroundResource(R.drawable.ic_action_dock);

    TextView textView = (TextView) convertView.findViewById(R.id.listview_item_line_one);
    textView.setText(item.getDetails().getFriendlyName());
    return convertView;
}
 
Example #6
Source File: DeviceListDialogFragment.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
    final SystemManager deviceManager = SystemManager.getInstance();
    while (true) {
        Log.i(TAG, "Search devices");
        //Send search command
        deviceManager.searchAllDevices();
        //Update list values
        Collection<Device> devices = deviceManager.getDmrDevices();
        publishProgress(devices);
        //Break immediately while task was cancelled.
        if (isCancelled()) break;

        try {
            //Sleep 3 second
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            Log.e(TAG, "Interrupt update thread!");
            break;
        }
    }
    return null;
}
 
Example #7
Source File: DMCControl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public void seekBarPosition(String paramString) {
	try {
		Device localDevice = this.executeDeviceItem.getDevice();
		Log.e("control action", "seekBarPosition");
		Service localService = localDevice.findService(new UDAServiceType(
				"AVTransport"));
		if (localService != null) {
			Log.e("get seekBarPosition info", "get seekBarPosition info");
			this.upnpService.getControlPoint().execute(
					new SeekCallback(activity, localService, paramString,
							mHandle));
		} else {
			Log.e("null", "null");
		}
	} catch (Exception localException) {
		localException.printStackTrace();
	}
}
 
Example #8
Source File: UDA10DeviceDescriptorBinderImpl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected void generateIconList(Namespace namespace, Device deviceModel, Document descriptor, Element deviceElement) {
    if (!deviceModel.hasIcons()) return;

    Element iconListElement = appendNewElement(descriptor, deviceElement, ELEMENT.iconList);

    for (Icon icon : deviceModel.getIcons()) {
        Element iconElement = appendNewElement(descriptor, iconListElement, ELEMENT.icon);

        appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.mimetype, icon.getMimeType());
        appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.width, icon.getWidth());
        appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.height, icon.getHeight());
        appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.depth, icon.getDepth());
        if (deviceModel instanceof RemoteDevice) {
        	appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.url,  icon.getUri());
        } else if (deviceModel instanceof LocalDevice) {
        	appendNewElementIfNotNull(descriptor, iconElement, ELEMENT.url,  namespace.getIconPath(icon));
        }
    }
}
 
Example #9
Source File: DevicesListAdapter.java    From HPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.devices_list_item, null);
        holder = new ViewHolder();
        holder.name = (TextView) convertView.findViewById(R.id.device_name);
        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Device device = getItem(position);
    holder.name.setText(device.getDetails().getFriendlyName());

    return convertView;
}
 
Example #10
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 #11
Source File: PlaybackCommand.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
public static void play() {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null) return;

    Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new Play(avtService) {
            @Override
            public void success(ActionInvocation invocation) {
                Log.i(TAG, "Play success.");
            }

            @Override
            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                Log.e(TAG, "Play failed");
            }
        });
    }
}
 
Example #12
Source File: PlaybackCommand.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
public static void stop() {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null) return;

    Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new Stop(avtService) {
            @Override
            public void success(ActionInvocation invocation) {
                Log.i(TAG, "Stop success.");
            }

            @Override
            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                Log.e(TAG, "Stop failed");
            }
        });
    }
}
 
Example #13
Source File: UDA10DeviceDescriptorBinderImpl.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public Document buildDOM(Device deviceModel, RemoteClientInfo info, Namespace namespace) throws DescriptorBindingException {

        try {
            log.fine("Generating DOM from device model: " + deviceModel);

            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);

            Document d = factory.newDocumentBuilder().newDocument();
            generateRoot(namespace, deviceModel, d, info);

            return d;

        } catch (Exception ex) {
            throw new DescriptorBindingException("Could not generate device descriptor: " + ex.getMessage(), ex);
        }
    }
 
Example #14
Source File: ContentActivity.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
private void initData() {

		mCounter = 0;
		if (null == mSaveDirectoryMap) {
			mSaveDirectoryMap = new HashMap<Integer, ArrayList<ContentItem>>();
		} else {
			mSaveDirectoryMap.clear();
		}
		upnpService = mBaseApplication.upnpService;
		mTitleView.setText(mBaseApplication.deviceItem.toString());
		Device device = mBaseApplication.deviceItem.getDevice();
		Service service = device.findService(new UDAServiceType(
				"ContentDirectory"));
		upnpService.getControlPoint().execute(
				new ContentBrowseActionCallback(ContentActivity.this,
						service, createRootContainer(service), mContentList,
						mHandler));

		mLastDevice = mBaseApplication.deviceItem.toString();
	}
 
Example #15
Source File: SempDeviceDescriptorBinderImpl.java    From SmartApplianceEnabler with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void generateDevice(Namespace namespace, Device deviceModel, Document descriptor, Element rootElement,
        RemoteClientInfo info) {
    super.generateDevice(namespace, deviceModel, descriptor, rootElement, info);
    
    
    NodeList deviceElements = rootElement.getElementsByTagName(org.fourthline.cling.binding.xml.Descriptor.Device.ELEMENT.device.toString());
    if(deviceElements.getLength() > 0) {
        Element deviceElement = (Element) deviceElements.item(0);
        
        Element sempServiceElement = appendNewElementIfNotNull(
                descriptor, deviceElement, Semp.prefixed(ELEMENT.X_SEMPSERVICE),
                "", "urn:" + Semp.NAMESPACE + ":service-1-0"
        );
        
        appendNewElementIfNotNull(descriptor, sempServiceElement, Semp.prefixed(ELEMENT.server), sempServerUrl);
        appendNewElementIfNotNull(descriptor, sempServiceElement, Semp.prefixed(ELEMENT.basePath), "/semp");
        appendNewElementIfNotNull(descriptor, sempServiceElement, Semp.prefixed(ELEMENT.transport), "HTTP/Pull");
        appendNewElementIfNotNull(descriptor, sempServiceElement, Semp.prefixed(ELEMENT.exchangeFormat), "XML");
        appendNewElementIfNotNull(descriptor, sempServiceElement, Semp.prefixed(ELEMENT.wsVersion), Semp.XSD_VERSION);
    }
}
 
Example #16
Source File: BrowserActivity.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public void onServiceConnected(ComponentName className, IBinder service) {
    upnpService = (AndroidUpnpService) service;

    // Clear the list
    listAdapter.clear();

    // Get ready for future device advertisements
    upnpService.getRegistry().addListener(registryListener);

    // Now add all devices to the list we already know about
    for (Device device : upnpService.getRegistry().getDevices()) {
        registryListener.deviceAdded(device);
    }

    // Search asynchronously for all devices, they will respond soon
    upnpService.getControlPoint().search();
}
 
Example #17
Source File: Namespace.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public Resource[] getResources(Device device) throws ValidationException {
    if (!device.isRoot()) return null;

    Set<Resource> resources = new HashSet<Resource>();
    List<ValidationError> errors = new ArrayList<ValidationError>();

    log.fine("Discovering local resources of device graph");
    Resource[] discoveredResources = device.discoverResources(this);
    for (Resource resource : discoveredResources) {
        log.finer("Discovered: " + resource);
        if (!resources.add(resource)) {
            log.finer("Local resource already exists, queueing validation error");
            errors.add(new ValidationError(
                    getClass(),
                    "resources",
                    "Local URI namespace conflict between resources of device: " + resource
            ));
        }
    }
    if (errors.size() > 0) {
        throw new ValidationException("Validation of device graph failed, call getErrors() on exception", errors);
    }
    return resources.toArray(new Resource[resources.size()]);
}
 
Example #18
Source File: ReceivingSearch.java    From DroidDLNA with GNU General Public License v3.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 #19
Source File: ReceivingSearch.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #20
Source File: MutableDevice.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public Device build(Device prototype, UDAVersion deviceVersion, URL baseURL) throws ValidationException {

        List<Device> embeddedDevicesList = new ArrayList();
        for (MutableDevice embeddedDevice : embeddedDevices) {
            embeddedDevicesList.add(embeddedDevice.build(prototype, deviceVersion, baseURL));
        }
        return prototype.newInstance(
                udn,
                deviceVersion,
                createDeviceType(),
                createDeviceDetails(baseURL),
                createIcons(),
                createServices(prototype),
                embeddedDevicesList
        );
    }
 
Example #21
Source File: BrowserActivity.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public void deviceAdded(final Device device) {
    runOnUiThread(new Runnable() {
        public void run() {
            DeviceDisplay d = new DeviceDisplay(device);
            int position = listAdapter.getPosition(d);
            if (position >= 0) {
                // Device already in the list, re-set new value at same
                // position
                listAdapter.remove(d);
                listAdapter.insert(d, position);
            } else {
                listAdapter.add(d);
            }
        }
    });
}
 
Example #22
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 #23
Source File: DLNARouteProvider.java    From Popeens-DSub with GNU General Public License v3.0 6 votes vote down vote up
private void deviceRemoved(Device device) {
	if(device.getType().getType().equals("MediaRenderer") && device instanceof RemoteDevice) {
		final String id = device.getIdentity().getUdn().toString();
		removing.add(id);

		// Delay removal for a few seconds to make sure that it isn't just a temp disconnect
		dlnaService.getControlPoint().search();
		downloadService.postDelayed(new Runnable() {
			@Override
			public void run() {
				if(removing.contains(id)) {
					devices.remove(id);
					removing.remove(id);
					broadcastDescriptors();
				}
			}
		}, 5000L);
	}
}
 
Example #24
Source File: SystemManager.java    From BeyondUPnP with Apache License 2.0 5 votes vote down vote up
public Collection<Device> getDmcDevices() {
    if (mUpnpService == null) return Collections.EMPTY_LIST;

    List<Device> devices = new ArrayList<>();
    devices.addAll(mUpnpService.getRegistry().getDevices(CONTENT_DIRECTORY_SERVICE));
    return devices;
}
 
Example #25
Source File: DeviceListDialogFragment.java    From BeyondUPnP with Apache License 2.0 5 votes vote down vote up
@Override
protected void onProgressUpdate(Collection<Device>... values) {
    Collection<Device> devices = values[0];
    mArrayAdapter.clear();
    mArrayAdapter.addAll(devices);
    Log.i(TAG, "Device list update.");
}
 
Example #26
Source File: RegistryImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
synchronized public Collection<Device> getDevices(ServiceType serviceType) {
    Collection<Device> devices = new HashSet();

    devices.addAll(localItems.get(serviceType));
    devices.addAll(remoteItems.get(serviceType));

    return Collections.unmodifiableCollection(devices);
}
 
Example #27
Source File: UpnpUtil.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isLocalIpAddress(Device device) {
    try {
        String addrip = device.getDetails().getBaseURL().toString();
        addrip = addrip.substring("http://".length(), addrip.length());
        addrip = addrip.substring(0, addrip.indexOf(":"));
        boolean ret = isLocalIpAddress(addrip);
        ret = false;
        return ret;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return false;
}
 
Example #28
Source File: UpnpUtil.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isMediaRenderDevice(Device device) {
    if ("urn:schemas-upnp-org:device:MediaRenderer:1".equalsIgnoreCase(device.getType()
            .getType())) {
        return true;
    }
    return false;
}
 
Example #29
Source File: UDA10DeviceDescriptorBinderImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
protected void generateRoot(Namespace namespace, Device deviceModel, Document descriptor, RemoteClientInfo info) {

        Element rootElement = descriptor.createElementNS(Descriptor.Device.NAMESPACE_URI, ELEMENT.root.toString());
        descriptor.appendChild(rootElement);

        generateSpecVersion(namespace, deviceModel, descriptor, rootElement);

        /* UDA 1.1 spec says: Don't use URLBase anymore
        if (deviceModel.getBaseURL() != null) {
            appendChildElementWithTextContent(descriptor, rootElement, "URLBase", deviceModel.getBaseURL());
        }
        */

        generateDevice(namespace, deviceModel, descriptor, rootElement, info);
    }
 
Example #30
Source File: PortMappingListener.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
@Override
synchronized public void deviceRemoved(Registry registry, Device device) {
    for (Service service : device.findServices()) {
        Iterator<Map.Entry<Service, List<PortMapping>>> it = activePortMappings.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<Service, List<PortMapping>> activeEntry = it.next();
            if (!activeEntry.getKey().equals(service)) continue;

            if (activeEntry.getValue().size() > 0)
                handleFailureMessage("Device disappeared, couldn't delete port mappings: " + activeEntry.getValue().size());

            it.remove();
        }
    }
}