@Override public void run() { try { UpnpService upnpService = new UpnpServiceImpl(); // Adiciona um verificador de novos registros de dispositivos UPNP / Add a listener for device // registration events upnpService.getRegistry().addListener(createRegistryListener(upnpService)); // Envia a mensagem de busca de novos dispositivos UPNP para todos os dispositivos da rede / // Broadcast a search message for all devices // Acontece só uma vez upnpService.getControlPoint().search(new STAllHeader()); Scanner scanner = new Scanner(System.in); String command = ""; while (!"quit".equals(command)) { command = scanner.next(); // leitor de comandos do servidor de borda if ("getDevices".equals(command)) { Collection<Device> devices = upnpService.getRegistry().getDevices(); int devicessize = devices.size(); System.out.printf("Esses são os dispositivos locais ( %d )\n", devicessize); System.out.println(Arrays.toString(upnpService.getRegistry().getDevices().toArray())); RemoteDevice newdevice; for (int i = 0; i < devices.size(); i++) { newdevice = (RemoteDevice) devices.toArray()[i]; System.out.println(newdevice.getDetails().getFriendlyName()); } } else if ("exec".equals(command)) { /*Collection<Device> devices = upnpService.getRegistry().getDevices(); ServiceId serviceId = new UDAServiceId("NodoTemp"); RemoteDevice newdevice; for(int i = 0 ; i < devices.size() ; i++){ newdevice = (RemoteDevice) devices.toArray()[i]; Service edgeServer; if ((edgeServer = newdevice.findService(serviceId)) != null) { //AÇÃO A SER EXECUTADA QUANDO ENCONTRADO DISPOSITIVO //ADICIONAR O DISPOSITIVO EM ALGUM LUGAR PRA MONITORAMENTO executeAction(upnpService, edgeServer); } }*/ } else if ("countCadGateways".equals(command)) { synchronized (gatewaysCadastrados) { System.out.println(gatewaysCadastrados.size()); } } } System.exit(0); } catch (Exception ex) { System.err.println("Exception occured: " + ex); System.exit(1); } }
public void onRemoteDeviceComplete(@Observes @Phase.Complete RemoteDeviceDiscovery discovery) { RemoteDevice device = discovery.getDevice(); Workbench.log(new LogMessage(Level.INFO, "Remote device added: " + device)); final DeviceItem deviceItem = new DeviceItem( device, device.getDetails().getFriendlyName(), device.getDisplayString(), "(REMOTE) " + device.getType().getDisplayString()); Icon usableIcon = findUsableIcon(device); if (usableIcon != null) { // We retrieve it using our own infrastructure, we know how that works and behaves final StreamRequestMessage iconRetrievalMsg = new StreamRequestMessage( UpnpRequest.Method.GET, device.normalizeURI(usableIcon.getUri())); StreamResponseMessage responseMsg = router.send(iconRetrievalMsg); if (responseMsg != null && !responseMsg.getOperation().isFailed()) { MimeType contentType = responseMsg .getHeaders() .getFirstHeader(UpnpHeader.Type.CONTENT_TYPE, ContentTypeHeader.class) .getValue(); if (isUsableImageType(contentType)) { byte[] imageBody = (byte[]) responseMsg.getBody(); if (imageBody != null) { ImageIcon imageIcon = new ImageIcon(imageBody); deviceItem.setIcon(imageIcon); } else { Workbench.log( Level.WARNING, "Icon request did not return with response body '" + contentType + "': " + iconRetrievalMsg.getUri()); } } else { Workbench.log( Level.WARNING, "Icon was delivered with unsupported content type '" + contentType + "': " + iconRetrievalMsg.getUri()); } } else { if (responseMsg != null) { Workbench.log( Level.WARNING, "Icon retrieval of '" + iconRetrievalMsg.getUri() + "' failed: " + responseMsg.getOperation().getResponseDetails()); } else { Workbench.log( Level.WARNING, "Icon retrieval of '" + iconRetrievalMsg.getUri() + "' failed, no response received."); } } } if (deviceItem.getIcon() == null) { deviceItem.setIcon(getUnknownDeviceIcon(deviceItem.getLabel()[0])); } SwingUtilities.invokeLater( new Runnable() { public void run() { view.addDeviceItem(deviceItem); } }); }