Esempio n. 1
0
 @Override
 public void serviceAdded(ServiceEvent event) {
   Log.d(TAG, "serviceAdded:" + event);
   ZeroServiceInfo zsi = new ZeroServiceInfo(null, event);
   String name = event.getName();
   if (mName.equals(name)) {
     mZsinfo = zsi;
     if (null != mServiceListener) {
       mServiceListener.onServiceRegistered(zsi);
     }
   } else {
     ServiceInfo sinfo = event.getInfo();
     if (null != sinfo) {
       InetAddress[] addrs = sinfo.getInetAddresses();
       if (null != addrs && addrs.length > 0) {
         for (InetAddress addr : addrs) {
           Log.d(TAG, "the addr is:" + addr.getHostName());
         }
         if (null != mDiscoverListener) {
           mDiscoverListener.onServiceFound(zsi);
         }
       }
     }
   }
 }
Esempio n. 2
0
  @Override
  public void serviceRemoved(final ServiceEvent event) {
    Log.i(TAG, "Service removed: " + event.getType() + "\n Info: " + event.getInfo());
    final Server srv = new Server(null, null, event.getInfo().getHostAddresses()[0]);
    inUI(
        new Runnable() {

          @Override
          public void run() {
            serversList.remove(srv);
            serversListAdapter.notifyDataSetChanged();
          }
        });
  }
Esempio n. 3
0
  // @Test // not working by 22/09/2013
  public void testRegisterDevice() {

    try {
      JmDNS jmdns =
          JmDNS.create(
              InetAddress.getByName(
                  PropertiesLoader.getInstance()
                      .getProperties()
                      .getProperty("iotsys.gateway.authNsAddr6", "fe80::acbc:b659:71db:5cb7%20")));
      jmdns.addServiceListener(
          "_obix._coap."
              + PropertiesLoader.getInstance()
                  .getProperties()
                  .getProperty("iotsys.gateway.authDomain", "local."),
          new ServiceListener() {

            @Override
            public void serviceAdded(ServiceEvent event) {}

            @Override
            public void serviceRemoved(ServiceEvent event) {}

            @Override
            public void serviceResolved(ServiceEvent event) {
              resolvedEvents.add(event);
            }
          });
      lock.await(20000, TimeUnit.MILLISECONDS);
      ArrayList<String> eventNames = new ArrayList<String>();
      for (ServiceEvent e : resolvedEvents) {
        eventNames.add(e.getName());
      }
      // test all elements in testDeviceNames are returned in eventNames
      for (String qName : testDeviceNames) {
        // if eventNames not contain qName -> fail
        String fk = qName.split("\\.")[0].toLowerCase();
        if (!eventNames.contains(fk)) fail();
      }

    } catch (UnknownHostException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 4
0
 public static ServiceLookup getServiceLookup(List<ServiceEvent> services) {
   ArrayList<ServiceLookup> lookups = new ArrayList<>();
   for (ServiceEvent service : services) {
     ServiceLookup lookup = ServiceLookup.get(service.getType());
     if (lookup != null && lookup.getPriority() > 0) {
       lookups.add(lookup);
     }
   }
   Timber.v("lookups for " + services + " are " + lookups);
   if (lookups.isEmpty()) {
     return null;
   }
   Collections.sort(lookups);
   return lookups.get(lookups.size() - 1);
 }
 @Override
 public void serviceRemoved(ServiceEvent serviceEvent) {
   String name = serviceEvent.getName();
   synchronized (this) {
     removeBoardswithSameName(name);
   }
 }
  @Override
  public void serviceAdded(ServiceEvent serviceEvent) {
    String type = serviceEvent.getType();
    String name = serviceEvent.getName();

    try (JmDNS dns = serviceEvent.getDNS()) {
      dns.requestServiceInfo(type, name);
      ServiceInfo serviceInfo = dns.getServiceInfo(type, name);
      if (serviceInfo != null) {
        dns.requestServiceInfo(type, name);
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 7
0
  @Override
  public void serviceResolved(final ServiceEvent event) {
    Log.i(TAG, "Service resolved: " + event.getType() + "\n Info: " + event.getInfo());
    inUI(
        new Runnable() {

          @Override
          public void run() {
            String name = event.getInfo().getPropertyString(GameServer.KEY_SERVER_NAME);
            String descr = event.getInfo().getName();
            String ip = event.getInfo().getInetAddresses()[0].getHostAddress();
            Server srv = new Server(name, descr, ip);
            if (!serversList.contains(srv)) {
              serversList.add(srv);
              serversListAdapter.notifyDataSetChanged();
            }
          }
        });
  }
  @Override
  public void serviceResolved(ServiceEvent serviceEvent) {
    ServiceInfo info = serviceEvent.getInfo();
    for (InetAddress inetAddress : info.getInet4Addresses()) {
      bonour newItem = new bonour();
      newItem.address = inetAddress.getHostAddress();
      newItem.name = serviceEvent.getName();
      if (info.hasData()) {
        newItem.board = info.getPropertyString("board"); // $NON-NLS-1$
        newItem.distroversion = info.getPropertyString("distro_version"); // $NON-NLS-1$
        newItem.name = info.getServer();
      }
      while (newItem.name.endsWith(".")) { // $NON-NLS-1$
        newItem.name = newItem.name.substring(0, newItem.name.length() - 1);
      }
      newItem.port = Integer.toString(info.getPort());

      synchronized (this) {
        removeBoardswithSameAdress(newItem);
        this.myComPorts.add(newItem);
      }
    }
  }
Esempio n. 9
0
 @Override
 public void serviceRemoved(ServiceEvent event) {
   Log.d(TAG, "serviceRemoved:" + event);
   ZeroServiceInfo zsi = new ZeroServiceInfo(null, event);
   String name = event.getName();
   if (mName.equals(name)) {
     if (null != mServiceListener) {
       mServiceListener.onServiceUnregistered(zsi);
     }
   } else {
     if (null != mDiscoverListener) {
       mDiscoverListener.onServiceLost(zsi);
     }
   }
 }
Esempio n. 10
0
 @Override
 public void serviceAdded(ServiceEvent event) {
   Log.i(TAG, "Service added: " + event.getType() + "\n Info: " + event.getInfo());
   // Для вызова serviceResolved(...)
   event.getDNS().requestServiceInfo(event.getType(), event.getName(), 100);
 }
 public void serviceRemoved(ServiceEvent event) {
   removeService(event.getDNS(), event.getType(), event.getName());
 }
 public void serviceAdded(ServiceEvent event) {
   addService(event.getDNS(), event.getType(), event.getName());
 }
Esempio n. 13
0
 public static String hostIdentifierForService(ServiceEvent service) {
   return service.getInfo().getHostAddress();
 }
Esempio n. 14
0
 @Override
 public void serviceResolved(ServiceEvent event) {
   System.out.println(
       "Service resolved: " + event.getName() + "." + event.getType() + "\n" + event.getInfo());
 }
Esempio n. 15
0
 @Override
 public void serviceAdded(ServiceEvent event) {
   System.out.println("Service added   : " + event.getName() + "." + event.getType());
 }