Remote.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Remote
  2. //
  3. // Douglas
  4. //
  5. // Remote.java
  6. /* Copyright 2011 Douglas Thrift
  7. *
  8. * This file is part of Big Screen Bot.
  9. *
  10. * Big Screen Bot is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * Big Screen Bot is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with Big Screen Bot. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. package net.douglasthrift.bigscreenbot;
  24. import java.io.IOException;
  25. import java.net.InetAddress;
  26. import java.net.UnknownHostException;
  27. import java.util.ArrayList;
  28. import java.util.List;
  29. import javax.jmdns.JmDNS;
  30. import javax.jmdns.ServiceInfo;
  31. import com.google.anymote.common.AnymoteFactory;
  32. import com.google.anymote.common.ErrorListener;
  33. import com.google.anymote.device.DeviceAdapter;
  34. import com.google.anymote.device.MessageReceiver;
  35. public class Remote
  36. {
  37. private static final String TYPE = "_anymote._tcp.local.";
  38. private Settings settings;
  39. private JmDNS mdns;
  40. public Remote(Settings settings) throws UnknownHostException, IOException
  41. {
  42. this.settings = settings;
  43. String interfaze = settings.getProperty("interface");
  44. if (interfaze != null)
  45. mdns = JmDNS.create(InetAddress.getByName(interfaze));
  46. else
  47. mdns = JmDNS.create();
  48. }
  49. public List<String> listDevices()
  50. {
  51. List<String> devices = new ArrayList<String>();
  52. for (ServiceInfo info : mdns.list(TYPE))
  53. devices.add(info.getName());
  54. return devices;
  55. }
  56. @Override
  57. protected void finalize() throws IOException
  58. {
  59. mdns.close();
  60. }
  61. }
  62. // vim: expandtab