Java Code Examples for javax.jmdns.ServiceInfo#getName()

The following examples show how to use javax.jmdns.ServiceInfo#getName() . 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: DNSRecord.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public ServiceEvent getServiceEvent(JmDNSImpl dns) {
    ServiceInfo info = this.getServiceInfo(false);
    ((ServiceInfoImpl) info).setDns(dns);
    // String domainName = "";
    // String serviceName = this.getServer();
    // int index = serviceName.indexOf('.');
    // if (index > 0)
    // {
    // serviceName = this.getServer().substring(0, index);
    // if (index + 1 < this.getServer().length())
    // domainName = this.getServer().substring(index + 1);
    // }
    // return new ServiceEventImpl(dns, domainName, serviceName, info);
    return new ServiceEventImpl(dns, info.getType(), info.getName(), info);

}
 
Example 2
Source File: BridgeMDNSDiscoveryParticipant.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public ThingUID getThingUID(ServiceInfo service) {
    if (service.getApplication().contains("dssweb")) {
        String hostAddress = service.getName() + "." + service.getDomain() + ".";
        DsAPI digitalSTROMClient = new DsAPIImpl(hostAddress, Config.DEFAULT_CONNECTION_TIMEOUT,
                Config.DEFAULT_READ_TIMEOUT, true);
        Map<String, String> dsidMap = digitalSTROMClient.getDSID(null);
        String dSID = null;
        if (dsidMap != null) {
            dSID = dsidMap.get(JSONApiResponseKeysEnum.DSID.getKey());
        }
        if (StringUtils.isNotBlank(dSID)) {
            return new ThingUID(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE, dSID);
        } else {
            logger.error("Can't get server dSID to generate thing UID. Please add the server manually.");
        }
    }
    return null;
}
 
Example 3
Source File: BridgeMDNSDiscoveryParticipant.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public DiscoveryResult createResult(ServiceInfo service) {
    if (service.getApplication().contains("dssweb")) {
        ThingUID uid = getThingUID(service);

        if (uid != null) {
            String hostAddress = service.getName() + "." + service.getDomain() + ".";
            Map<String, Object> properties = new HashMap<>(2);
            properties.put(DigitalSTROMBindingConstants.HOST, hostAddress);
            return DiscoveryResultBuilder.create(uid).withProperties(properties)
                    .withRepresentationProperty(uid.getId()).withLabel("digitalSTROM-Server").build();
        }
    }
    return null;
}
 
Example 4
Source File: DNSRecord.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@Override
public ServiceEvent getServiceEvent(JmDNSImpl dns) {
    ServiceInfo info = this.getServiceInfo(false);
    ((ServiceInfoImpl) info).setDns(dns);
    return new ServiceEventImpl(dns, info.getType(), info.getName(), info);
}
 
Example 5
Source File: DNSRecord.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@Override
public ServiceEvent getServiceEvent(JmDNSImpl dns) {
    ServiceInfo info = this.getServiceInfo(false);
    ((ServiceInfoImpl) info).setDns(dns);
    return new ServiceEventImpl(dns, info.getType(), info.getName(), info);
}
 
Example 6
Source File: DNSRecord.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@Override
public ServiceEvent getServiceEvent(JmDNSImpl dns) {
    ServiceInfo info = this.getServiceInfo(false);
    ((ServiceInfoImpl) info).setDns(dns);
    return new ServiceEventImpl(dns, info.getType(), info.getName(), info);
}
 
Example 7
Source File: SoundTouchDiscoveryParticipant.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public DiscoveryResult createResult(ServiceInfo info) {
    DiscoveryResult result = null;
    ThingUID uid = getThingUID(info);
    if (uid != null) {

        // remove the domain from the name
        InetAddress[] addrs = info.getInetAddresses();

        Map<String, Object> properties = new HashMap<>(2);
        
        String label = null;
        if (BST_10_THING_TYPE_UID.equals(uid.getThingTypeUID())) {
            try {
                String group = DiscoveryUtil
                        .executeUrl("http://" + addrs[0].getHostAddress() + ":8090/getGroup");
                label = DiscoveryUtil.getContentOfFirstElement(group, "name");
            } catch (IOException e) {
                logger.debug("Can't obtain label for group. Will use the default one");
            }
        }

        if (label == null || label.isEmpty()) {
            label = info.getName();
        }
        
        if (label == null || label.isEmpty()) {
            label = "Bose SoundTouch";
        }

        // we expect only one address per device..
        if (addrs.length > 1) {
            logger.warn("Bose SoundTouch device {} ({}) reports multiple addresses - using the first one: {}",
                    info.getName(), label, Arrays.toString(addrs));
        }

        properties.put(BoseSoundTouchConfiguration.HOST, addrs[0].getHostAddress());
        if (getMacAddress(info) != null) {
            properties.put(BoseSoundTouchConfiguration.MAC_ADDRESS, new String(getMacAddress(info), StandardCharsets.UTF_8));
        }
        
        // Set manufacturer as thing property (if available)
        byte[] manufacturer = info.getPropertyBytes("MANUFACTURER");
        if (manufacturer != null) {
            properties.put(Thing.PROPERTY_VENDOR, new String(manufacturer, StandardCharsets.UTF_8));
        }
        return DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(label).withTTL(600).build();
    }
    return result;
}