Search in sources :

Example 16 with Service

use of org.cybergarage.upnp.Service in project i2p.i2p by i2p.

the class UPnP method getDownstreamMaxBitRate.

/**
 * @return the reported downstream bit rate in bits per second. -1 if it's not available. Blocking.
 */
private int getDownstreamMaxBitRate() {
    Service service;
    synchronized (lock) {
        if (!isNATPresent() || thinksWeAreDoubleNatted)
            return -1;
        service = _service;
    }
    Action getIP = service.getAction("GetLinkLayerMaxBitRates");
    if (getIP == null || !getIP.postControlAction())
        return -1;
    Argument a = getIP.getOutputArgumentList().getArgument("NewDownstreamMaxBitRate");
    if (a == null)
        return -1;
    try {
        return Integer.parseInt(a.getValue());
    } catch (NumberFormatException nfe) {
        return -1;
    }
}
Also used : Action(org.cybergarage.upnp.Action) Argument(org.cybergarage.upnp.Argument) Service(org.cybergarage.upnp.Service)

Example 17 with Service

use of org.cybergarage.upnp.Service in project i2p.i2p by i2p.

the class UPnP method discoverService.

/**
 * Traverses the structure of the router device looking for the port mapping service.
 */
private void discoverService() {
    synchronized (lock) {
        for (Device current : _router.getDeviceList()) {
            String type = current.getDeviceType();
            if (!(WAN_DEVICE.equals(type) || WAN_DEVICE_2.equals(type)))
                continue;
            DeviceList l = current.getDeviceList();
            for (int i = 0; i < current.getDeviceList().size(); i++) {
                Device current2 = l.getDevice(i);
                type = current2.getDeviceType();
                if (!(WANCON_DEVICE.equals(type) || WANCON_DEVICE_2.equals(type)))
                    continue;
                _service = current2.getService(WAN_IP_CONNECTION_2);
                if (_service == null) {
                    _service = current2.getService(WAN_IP_CONNECTION);
                    if (_service == null) {
                        _service = current2.getService(WAN_PPP_CONNECTION);
                        if (_service == null) {
                            if (_log.shouldWarn())
                                _log.warn(_router.getFriendlyName() + " doesn't have any recognized connection type; we won't be able to use it!");
                        }
                    }
                }
                if (_log.shouldWarn()) {
                    Service svc2 = current2.getService(WAN_IPV6_CONNECTION);
                    if (svc2 != null)
                        _log.warn(_router.getFriendlyName() + " supports WANIPv6Connection, but we don't");
                }
                _serviceLacksAPM = false;
                return;
            }
        }
    }
}
Also used : Device(org.cybergarage.upnp.Device) Service(org.cybergarage.upnp.Service) DeviceList(org.cybergarage.upnp.DeviceList) ControlPoint(org.cybergarage.upnp.ControlPoint)

Example 18 with Service

use of org.cybergarage.upnp.Service in project i2p.i2p by i2p.

the class UPnP method getNATAddress.

/**
 * @return the external IPv4 address the NAT thinks we have.  Blocking.
 * null if we can't find it.
 */
private String getNATAddress() {
    Service service;
    synchronized (lock) {
        if (!isNATPresent())
            return null;
        service = _service;
    }
    Action getIP = service.getAction("GetExternalIPAddress");
    if (getIP == null || !getIP.postControlAction())
        return null;
    Argument a = getIP.getOutputArgumentList().getArgument("NewExternalIPAddress");
    if (a == null)
        return null;
    String rv = a.getValue();
    // I2P some devices return 0.0.0.0 when not connected
    if ("0.0.0.0".equals(rv) || rv == null || rv.length() <= 0)
        return null;
    return rv;
}
Also used : Action(org.cybergarage.upnp.Action) Argument(org.cybergarage.upnp.Argument) Service(org.cybergarage.upnp.Service)

Example 19 with Service

use of org.cybergarage.upnp.Service in project i2p.i2p by i2p.

the class UPnP method getUpstreamMaxBitRate.

/**
 * @return the reported upstream bit rate in bits per second. -1 if it's not available. Blocking.
 */
private int getUpstreamMaxBitRate() {
    Service service;
    synchronized (lock) {
        if (!isNATPresent() || thinksWeAreDoubleNatted)
            return -1;
        service = _service;
    }
    Action getIP = service.getAction("GetLinkLayerMaxBitRates");
    if (getIP == null || !getIP.postControlAction())
        return -1;
    Argument a = getIP.getOutputArgumentList().getArgument("NewUpstreamMaxBitRate");
    if (a == null)
        return -1;
    try {
        return Integer.parseInt(a.getValue());
    } catch (NumberFormatException nfe) {
        return -1;
    }
}
Also used : Action(org.cybergarage.upnp.Action) Argument(org.cybergarage.upnp.Argument) Service(org.cybergarage.upnp.Service)

Aggregations

Service (org.cybergarage.upnp.Service)19 ControlPoint (org.cybergarage.upnp.ControlPoint)7 Action (org.cybergarage.upnp.Action)6 Device (org.cybergarage.upnp.Device)6 UPnPService (org.osgi.service.upnp.UPnPService)6 Vector (java.util.Vector)5 UPnPDevice (org.osgi.service.upnp.UPnPDevice)5 Argument (org.cybergarage.upnp.Argument)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 FirstMessage (org.apache.felix.upnp.basedriver.importer.core.event.message.FirstMessage)3 ServiceList (org.cybergarage.upnp.ServiceList)3 StateVariable (org.cybergarage.upnp.StateVariable)3 Enumeration (java.util.Enumeration)2 Hashtable (java.util.Hashtable)2 Iterator (java.util.Iterator)2 UPnPServiceImpl (org.apache.felix.upnp.basedriver.importer.core.upnp.UPnPServiceImpl)2 DeviceList (org.cybergarage.upnp.DeviceList)2 ServiceReference (org.osgi.framework.ServiceReference)2 UPnPEventListener (org.osgi.service.upnp.UPnPEventListener)2 UPnPStateVariable (org.osgi.service.upnp.UPnPStateVariable)2