Search in sources :

Example 1 with PortMappingAdd

use of org.fourthline.cling.support.igd.callback.PortMappingAdd in project libresonic by Libresonic.

the class ClingRouter method addPortMappingImpl.

private void addPortMappingImpl(Service connectionService, int port) throws Exception {
    final Semaphore gotReply = new Semaphore(0);
    final AtomicReference<String> error = new AtomicReference<String>();
    upnpService.getControlPoint().execute(new PortMappingAdd(connectionService, createPortMapping(port)) {

        @Override
        public void success(ActionInvocation invocation) {
            gotReply.release();
        }

        @Override
        public void failure(ActionInvocation invocation, UpnpResponse response, String defaultMsg) {
            error.set(String.valueOf(response) + ": " + defaultMsg);
            gotReply.release();
        }
    });
    gotReply.acquire();
    if (error.get() != null) {
        throw new Exception(error.get());
    }
}
Also used : UpnpResponse(org.fourthline.cling.model.message.UpnpResponse) ActionInvocation(org.fourthline.cling.model.action.ActionInvocation) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) PortMappingAdd(org.fourthline.cling.support.igd.callback.PortMappingAdd) UnknownHostException(java.net.UnknownHostException)

Aggregations

UnknownHostException (java.net.UnknownHostException)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ActionInvocation (org.fourthline.cling.model.action.ActionInvocation)1 UpnpResponse (org.fourthline.cling.model.message.UpnpResponse)1 PortMappingAdd (org.fourthline.cling.support.igd.callback.PortMappingAdd)1