@Override public ThingUID getThingUID(ServiceInfo service) { if (service != null) { if (service.getType() != null) { if (service.getType().equals(getServiceType())) { logger.trace("Discovered a Miele@Home gateway thing with name '{}'", service.getName()); return new ThingUID( MieleBindingConstants.THING_TYPE_XGW3000, service.getName().replace(" ", "_")); } } } return null; }
/** * During recovery we need to duplicate service info to reregister them * * @param info */ ServiceInfoImpl(ServiceInfo info) { this._ipv4Addresses = Collections.synchronizedSet(new LinkedHashSet<Inet4Address>()); this._ipv6Addresses = Collections.synchronizedSet(new LinkedHashSet<Inet6Address>()); if (info != null) { this._domain = info.getDomain(); this._protocol = info.getProtocol(); this._application = info.getApplication(); this._name = info.getName(); this._subtype = info.getSubtype(); this._port = info.getPort(); this._weight = info.getWeight(); this._priority = info.getPriority(); this._text = info.getTextBytes(); this._persistent = info.isPersistent(); Inet6Address[] ipv6Addresses = info.getInet6Addresses(); for (Inet6Address address : ipv6Addresses) { this._ipv6Addresses.add(address); } Inet4Address[] ipv4Addresses = info.getInet4Addresses(); for (Inet4Address address : ipv4Addresses) { this._ipv4Addresses.add(address); } } this._state = new ServiceInfoState(this); }
public static void main(final String[] args) throws Exception { /* Make sure AirReceiver shuts down gracefully */ Runtime.getRuntime() .addShutdownHook( new Thread( new Runnable() { @Override public void run() { onShutdown(); } })); /* Create about dialog */ final Dialog aboutDialog = new Dialog((Dialog) null); final GridBagLayout aboutLayout = new GridBagLayout(); aboutDialog.setLayout(aboutLayout); aboutDialog.setVisible(false); aboutDialog.setTitle("About AirReceiver"); aboutDialog.setResizable(false); { /* Message */ final TextArea title = new TextArea(AboutMessage.split("\n").length + 1, 64); title.setText(AboutMessage); title.setEditable(false); final GridBagConstraints titleConstraints = new GridBagConstraints(); titleConstraints.gridx = 1; titleConstraints.gridy = 1; titleConstraints.fill = GridBagConstraints.HORIZONTAL; titleConstraints.insets = new Insets(0, 0, 0, 0); aboutLayout.setConstraints(title, titleConstraints); aboutDialog.add(title); } { /* Done button */ final Button aboutDoneButton = new Button("Done"); aboutDoneButton.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent evt) { aboutDialog.setVisible(false); } }); final GridBagConstraints aboutDoneConstraints = new GridBagConstraints(); aboutDoneConstraints.gridx = 1; aboutDoneConstraints.gridy = 2; aboutDoneConstraints.anchor = GridBagConstraints.PAGE_END; aboutDoneConstraints.fill = GridBagConstraints.NONE; aboutDoneConstraints.insets = new Insets(0, 0, 0, 0); aboutLayout.setConstraints(aboutDoneButton, aboutDoneConstraints); aboutDialog.add(aboutDoneButton); } aboutDialog.setVisible(false); aboutDialog.setLocationByPlatform(true); aboutDialog.pack(); /* Create tray icon */ final URL trayIconUrl = AirReceiver.class.getClassLoader().getResource("icon_32.png"); final TrayIcon trayIcon = new TrayIcon((new ImageIcon(trayIconUrl, "AirReceiver").getImage())); trayIcon.setToolTip("AirReceiver"); trayIcon.setImageAutoSize(true); final PopupMenu popupMenu = new PopupMenu(); final MenuItem aboutMenuItem = new MenuItem("About"); aboutMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent evt) { aboutDialog.setLocationByPlatform(true); aboutDialog.setVisible(true); } }); popupMenu.add(aboutMenuItem); final MenuItem exitMenuItem = new MenuItem("Quit"); exitMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent evt) { onShutdown(); System.exit(0); } }); popupMenu.add(exitMenuItem); trayIcon.setPopupMenu(popupMenu); SystemTray.getSystemTray().add(trayIcon); /* Create AirTunes RTSP server */ final ServerBootstrap airTunesRtspBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(ExecutorService, ExecutorService)); airTunesRtspBootstrap.setPipelineFactory(new RaopRtspPipelineFactory()); airTunesRtspBootstrap.setOption("reuseAddress", true); airTunesRtspBootstrap.setOption("child.tcpNoDelay", true); airTunesRtspBootstrap.setOption("child.keepAlive", true); s_allChannels.add( airTunesRtspBootstrap.bind( new InetSocketAddress(Inet4Address.getByName("0.0.0.0"), AirtunesServiceRTSPPort))); s_logger.info("Launched RTSP service on port " + AirtunesServiceRTSPPort); /* Create mDNS responders. */ synchronized (s_jmDNSInstances) { for (final NetworkInterface iface : Collections.list(NetworkInterface.getNetworkInterfaces())) { if (iface.isLoopback()) continue; if (iface.isPointToPoint()) continue; if (!iface.isUp()) continue; for (final InetAddress addr : Collections.list(iface.getInetAddresses())) { if (!(addr instanceof Inet4Address) && !(addr instanceof Inet6Address)) continue; try { /* Create mDNS responder for address */ final JmDNS jmDNS = JmDNS.create(addr, HostName + "-jmdns"); s_jmDNSInstances.add(jmDNS); /* Publish RAOP service */ final ServiceInfo airTunesServiceInfo = ServiceInfo.create( AirtunesServiceType, HardwareAddressString + "@" + HostName + " (" + iface.getName() + ")", AirtunesServiceRTSPPort, 0 /* weight */, 0 /* priority */, AirtunesServiceProperties); jmDNS.registerService(airTunesServiceInfo); s_logger.info( "Registered AirTunes service '" + airTunesServiceInfo.getName() + "' on " + addr); } catch (final Throwable e) { s_logger.log(Level.SEVERE, "Failed to publish service on " + addr, e); } } } } }