org.fourthline.cling.model.gena.CancelReason Java Examples

The following examples show how to use org.fourthline.cling.model.gena.CancelReason. 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 Project: TVRemoteIME   Author: kingthy   File: SendingUnsubscribe.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void onUnsubscribe(final StreamResponseMessage response) {
    // Always remove from the registry and end the subscription properly - even if it's failed
    getUpnpService().getRegistry().removeRemoteSubscription(subscription);

    getUpnpService().getConfiguration().getRegistryListenerExecutor().execute(
        new Runnable() {
            public void run() {
                if (response == null) {
                    log.fine("Unsubscribe failed, no response received");
                    subscription.end(CancelReason.UNSUBSCRIBE_FAILED, null);
                } else if (response.getOperation().isFailed()) {
                    log.fine("Unsubscribe failed, response was: " + response);
                    subscription.end(CancelReason.UNSUBSCRIBE_FAILED, response.getOperation());
                } else {
                    log.fine("Unsubscribe successful, response was: " + response);
                    subscription.end(null, response.getOperation());
                }
            }
        }
    );
}
 
Example #2
Source Project: DroidDLNA   Author: offbye   File: SendingUnsubscribe.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected void onUnsubscribe(final StreamResponseMessage response) {
    // Always remove from the registry and end the subscription properly - even if it's failed
    getUpnpService().getRegistry().removeRemoteSubscription(subscription);

    getUpnpService().getConfiguration().getRegistryListenerExecutor().execute(
        new Runnable() {
            public void run() {
                if (response == null) {
                    log.fine("Unsubscribe failed, no response received");
                    subscription.end(CancelReason.UNSUBSCRIBE_FAILED, null);
                } else if (response.getOperation().isFailed()) {
                    log.fine("Unsubscribe failed, response was: " + response);
                    subscription.end(CancelReason.UNSUBSCRIBE_FAILED, response.getOperation());
                } else {
                    log.fine("Unsubscribe successful, response was: " + response);
                    subscription.end(null, response.getOperation());
                }
            }
        }
    );
}
 
Example #3
Source Project: TVRemoteIME   Author: kingthy   File: SendingRenewal.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected void onRenewalFailure() {
    log.fine("Subscription renewal failed, removing subscription from registry");
    getUpnpService().getRegistry().removeRemoteSubscription(subscription);
    getUpnpService().getConfiguration().getRegistryListenerExecutor().execute(
            new Runnable() {
                public void run() {
                    subscription.end(CancelReason.RENEWAL_FAILED, null);
                }
            }
    );
}
 
Example #4
Source Project: DroidDLNA   Author: offbye   File: SendingRenewal.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void onRenewalFailure() {
    log.fine("Subscription renewal failed, removing subscription from registry");
    getUpnpService().getRegistry().removeRemoteSubscription(subscription);
    getUpnpService().getConfiguration().getRegistryListenerExecutor().execute(
            new Runnable() {
                public void run() {
                    subscription.end(CancelReason.RENEWAL_FAILED, null);
                }
            }
    );
}
 
Example #5
Source Project: TVRemoteIME   Author: kingthy   File: ReceivingSubscribe.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected OutgoingSubscribeResponseMessage processNewSubscription(LocalService service,
                                                                  IncomingSubscribeRequestMessage requestMessage) {
    List<URL> callbackURLs = requestMessage.getCallbackURLs();

    // Error conditions UDA 1.0 section 4.1.1 and 4.1.2
    if (callbackURLs == null || callbackURLs.size() == 0) {
        log.fine("Missing or invalid Callback URLs in subscribe request: " + getInputMessage());
        return new OutgoingSubscribeResponseMessage(UpnpResponse.Status.PRECONDITION_FAILED);
    }

    if (!requestMessage.hasNotificationHeader()) {
        log.fine("Missing or invalid NT header in subscribe request: " + getInputMessage());
        return new OutgoingSubscribeResponseMessage(UpnpResponse.Status.PRECONDITION_FAILED);
    }

    Integer timeoutSeconds; 
    if(getUpnpService().getConfiguration().isReceivedSubscriptionTimeoutIgnored()) {
    	timeoutSeconds = null; // Use default value
    } else {
    	timeoutSeconds = requestMessage.getRequestedTimeoutSeconds();
    }
    
    try {
        subscription = new LocalGENASubscription(service, timeoutSeconds, callbackURLs) {
            public void established() {
            }

            public void ended(CancelReason reason) {
            }

            public void eventReceived() {
                // The only thing we are interested in, sending an event when the state changes
                getUpnpService().getConfiguration().getSyncProtocolExecutorService().execute(
                        getUpnpService().getProtocolFactory().createSendingEvent(this)
                );
            }
        };
    } catch (Exception ex) {
        log.warning("Couldn't create local subscription to service: " + Exceptions.unwrap(ex));
        return new OutgoingSubscribeResponseMessage(UpnpResponse.Status.INTERNAL_SERVER_ERROR);
    }

    log.fine("Adding subscription to registry: " + subscription);
    getUpnpService().getRegistry().addLocalSubscription(subscription);

    log.fine("Returning subscription response, waiting to send initial event");
    return new OutgoingSubscribeResponseMessage(subscription);
}
 
Example #6
Source Project: TVRemoteIME   Author: kingthy   File: SendingRenewal.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected IncomingSubscribeResponseMessage executeSync() throws RouterException {
    log.fine("Sending subscription renewal request: " + getInputMessage());

    StreamResponseMessage response;
    try {
        response = getUpnpService().getRouter().send(getInputMessage());
    } catch (RouterException ex) {
        onRenewalFailure();
        throw ex;
    }

    if (response == null) {
        onRenewalFailure();
        return null;
    }

    final IncomingSubscribeResponseMessage responseMessage = new IncomingSubscribeResponseMessage(response);

    if (response.getOperation().isFailed()) {
        log.fine("Subscription renewal failed, response was: " + response);
        getUpnpService().getRegistry().removeRemoteSubscription(subscription);
        getUpnpService().getConfiguration().getRegistryListenerExecutor().execute(
                new Runnable() {
                    public void run() {
                        subscription.end(CancelReason.RENEWAL_FAILED,responseMessage.getOperation());
                    }
                }
        );
    } else if (!responseMessage.isValidHeaders()) {
        log.severe("Subscription renewal failed, invalid or missing (SID, Timeout) response headers");
        getUpnpService().getConfiguration().getRegistryListenerExecutor().execute(
                new Runnable() {
                    public void run() {
                        subscription.end(CancelReason.RENEWAL_FAILED, responseMessage.getOperation());
                    }
                }
        );
    } else {
        log.fine("Subscription renewed, updating in registry, response was: " + response);
        subscription.setActualSubscriptionDurationSeconds(responseMessage.getSubscriptionDurationSeconds());
        getUpnpService().getRegistry().updateRemoteSubscription(subscription);
    }

    return responseMessage;
}
 
Example #7
Source Project: TVRemoteIME   Author: kingthy   File: SubscriptionCallback.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void establishLocalSubscription(LocalService service) {

        if (getControlPoint().getRegistry().getLocalDevice(service.getDevice().getIdentity().getUdn(), false) == null) {
            log.fine("Local device service is currently not registered, failing subscription immediately");
            failed(null, null, new IllegalStateException("Local device is not registered"));
            return;
        }

        // Local execution of subscription on local service re-uses the procedure and lifecycle that is
        // used for inbound subscriptions from remote control points on local services!
        // Except that it doesn't ever expire, we override the requested duration with Integer.MAX_VALUE!

        LocalGENASubscription localSubscription = null;
        try {
            localSubscription =
                    new LocalGENASubscription(service, Integer.MAX_VALUE, Collections.EMPTY_LIST) {

                        public void failed(Exception ex) {
                            synchronized (SubscriptionCallback.this) {
                                SubscriptionCallback.this.setSubscription(null);
                                SubscriptionCallback.this.failed(null, null, ex);
                            }
                        }

                        public void established() {
                            synchronized (SubscriptionCallback.this) {
                                SubscriptionCallback.this.setSubscription(this);
                                SubscriptionCallback.this.established(this);
                            }
                        }

                        public void ended(CancelReason reason) {
                            synchronized (SubscriptionCallback.this) {
                                SubscriptionCallback.this.setSubscription(null);
                                SubscriptionCallback.this.ended(this, reason, null);
                            }
                        }

                        public void eventReceived() {
                            synchronized (SubscriptionCallback.this) {
                                log.fine("Local service state updated, notifying callback, sequence is: " + getCurrentSequence());
                                SubscriptionCallback.this.eventReceived(this);
                                incrementSequence();
                            }
                        }
                    };

            log.fine("Local device service is currently registered, also registering subscription");
            getControlPoint().getRegistry().addLocalSubscription(localSubscription);

            log.fine("Notifying subscription callback of local subscription availablity");
            localSubscription.establish();

            log.fine("Simulating first initial event for local subscription callback, sequence: " + localSubscription.getCurrentSequence());
            eventReceived(localSubscription);
            localSubscription.incrementSequence();

            log.fine("Starting to monitor state changes of local service");
            localSubscription.registerOnService();

        } catch (Exception ex) {
            log.fine("Local callback creation failed: " + ex.toString());
            log.log(Level.FINE, "Exception root cause: ", Exceptions.unwrap(ex));
            if (localSubscription != null)
                getControlPoint().getRegistry().removeLocalSubscription(localSubscription);
            failed(localSubscription, null, ex);
        }
    }
 
Example #8
Source Project: TVRemoteIME   Author: kingthy   File: RemoteItems.java    License: GNU General Public License v2.0 4 votes vote down vote up
boolean remove(final RemoteDevice remoteDevice, boolean shuttingDown) throws RegistrationException {
    final RemoteDevice registeredDevice = get(remoteDevice.getIdentity().getUdn(), true);
    if (registeredDevice != null) {

        log.fine("Removing remote device from registry: " + remoteDevice);

        // Resources
        for (Resource deviceResource : getResources(registeredDevice)) {
            if (registry.removeResource(deviceResource)) {
                log.fine("Unregistered resource: " + deviceResource);
            }
        }

        // Active subscriptions
        Iterator<RegistryItem<String, RemoteGENASubscription>> it = getSubscriptionItems().iterator();
        while (it.hasNext()) {
            final RegistryItem<String, RemoteGENASubscription> outgoingSubscription = it.next();

            UDN subscriptionForUDN =
                    outgoingSubscription.getItem().getService().getDevice().getIdentity().getUdn();

            if (subscriptionForUDN.equals(registeredDevice.getIdentity().getUdn())) {
                log.fine("Removing outgoing subscription: " + outgoingSubscription.getKey());
                it.remove();
                if (!shuttingDown) {
                    registry.getConfiguration().getRegistryListenerExecutor().execute(
                            new Runnable() {
                                public void run() {
                                    outgoingSubscription.getItem().end(CancelReason.DEVICE_WAS_REMOVED, null);
                                }
                            }
                    );
                }
            }
        }

        // Only notify listeners if we are NOT in the process of shutting down the registry
        if (!shuttingDown) {
            for (final RegistryListener listener : registry.getListeners()) {
                registry.getConfiguration().getRegistryListenerExecutor().execute(
                        new Runnable() {
                            public void run() {
                                listener.remoteDeviceRemoved(registry, registeredDevice);
                            }
                        }
                );
            }
        }

        // Finally, remove the device from the registry
        getDeviceItems().remove(new RegistryItem(registeredDevice.getIdentity().getUdn()));

        return true;
    }

    return false;
}
 
Example #9
Source Project: TVRemoteIME   Author: kingthy   File: LocalItems.java    License: GNU General Public License v2.0 4 votes vote down vote up
boolean remove(final LocalDevice localDevice, boolean shuttingDown) throws RegistrationException {

        LocalDevice registeredDevice = get(localDevice.getIdentity().getUdn(), true);
        if (registeredDevice != null) {

            log.fine("Removing local device from registry: " + localDevice);

            setDiscoveryOptions(localDevice.getIdentity().getUdn(), null);
            getDeviceItems().remove(new RegistryItem(localDevice.getIdentity().getUdn()));

            for (Resource deviceResource : getResources(localDevice)) {
                if (registry.removeResource(deviceResource)) {
                    log.fine("Unregistered resource: " + deviceResource);
                }
            }

            // Active subscriptions
            Iterator<RegistryItem<String, LocalGENASubscription>> it = getSubscriptionItems().iterator();
            while (it.hasNext()) {
                final RegistryItem<String, LocalGENASubscription> incomingSubscription = it.next();

                UDN subscriptionForUDN =
                        incomingSubscription.getItem().getService().getDevice().getIdentity().getUdn();

                if (subscriptionForUDN.equals(registeredDevice.getIdentity().getUdn())) {
                    log.fine("Removing incoming subscription: " + incomingSubscription.getKey());
                    it.remove();
                    if (!shuttingDown) {
                        registry.getConfiguration().getRegistryListenerExecutor().execute(
                                new Runnable() {
                                    public void run() {
                                        incomingSubscription.getItem().end(CancelReason.DEVICE_WAS_REMOVED);
                                    }
                                }
                        );
                    }
                }
            }

            if (isAdvertised(localDevice.getIdentity().getUdn()))
         		advertiseByebye(localDevice, !shuttingDown);

            if (!shuttingDown) {
                for (final RegistryListener listener : registry.getListeners()) {
                    registry.getConfiguration().getRegistryListenerExecutor().execute(
                            new Runnable() {
                                public void run() {
                                    listener.localDeviceRemoved(registry, localDevice);
                                }
                            }
                    );
                }
            }

            return true;
        }

        return false;
    }
 
Example #10
Source Project: BeyondUPnP   Author: kevinshine   File: SystemService.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void ended(GENASubscription subscription, CancelReason reason, UpnpResponse responseStatus) {
    Log.i(TAG, "AVTransportSubscriptionCallback ended.");
}
 
Example #11
Source Project: DroidDLNA   Author: offbye   File: ReceivingSubscribe.java    License: GNU General Public License v3.0 4 votes vote down vote up
protected OutgoingSubscribeResponseMessage processNewSubscription(LocalService service,
                                                                  IncomingSubscribeRequestMessage requestMessage) {
    List<URL> callbackURLs = requestMessage.getCallbackURLs();

    // Error conditions UDA 1.0 section 4.1.1 and 4.1.2
    if (callbackURLs == null || callbackURLs.size() == 0) {
        log.fine("Missing or invalid Callback URLs in subscribe request: " + getInputMessage());
        return new OutgoingSubscribeResponseMessage(UpnpResponse.Status.PRECONDITION_FAILED);
    }

    if (!requestMessage.hasNotificationHeader()) {
        log.fine("Missing or invalid NT header in subscribe request: " + getInputMessage());
        return new OutgoingSubscribeResponseMessage(UpnpResponse.Status.PRECONDITION_FAILED);
    }

    Integer timeoutSeconds; 
    if(getUpnpService().getConfiguration().isReceivedSubscriptionTimeoutIgnored()) {
    	timeoutSeconds = null; // Use default value
    } else {
    	timeoutSeconds = requestMessage.getRequestedTimeoutSeconds();
    }
    
    try {
        subscription = new LocalGENASubscription(service, timeoutSeconds, callbackURLs) {
            public void established() {
            }

            public void ended(CancelReason reason) {
            }

            public void eventReceived() {
                // The only thing we are interested in, sending an event when the state changes
                getUpnpService().getConfiguration().getSyncProtocolExecutorService().execute(
                        getUpnpService().getProtocolFactory().createSendingEvent(this)
                );
            }
        };
    } catch (Exception ex) {
        log.warning("Couldn't create local subscription to service: " + Exceptions.unwrap(ex));
        return new OutgoingSubscribeResponseMessage(UpnpResponse.Status.INTERNAL_SERVER_ERROR);
    }

    log.fine("Adding subscription to registry: " + subscription);
    getUpnpService().getRegistry().addLocalSubscription(subscription);

    log.fine("Returning subscription response, waiting to send initial event");
    return new OutgoingSubscribeResponseMessage(subscription);
}
 
Example #12
Source Project: DroidDLNA   Author: offbye   File: SendingRenewal.java    License: GNU General Public License v3.0 4 votes vote down vote up
protected IncomingSubscribeResponseMessage executeSync() throws RouterException {
    log.fine("Sending subscription renewal request: " + getInputMessage());

    StreamResponseMessage response;
    try {
        response = getUpnpService().getRouter().send(getInputMessage());
    } catch (RouterException ex) {
        onRenewalFailure();
        throw ex;
    }

    if (response == null) {
        onRenewalFailure();
        return null;
    }

    final IncomingSubscribeResponseMessage responseMessage = new IncomingSubscribeResponseMessage(response);

    if (response.getOperation().isFailed()) {
        log.fine("Subscription renewal failed, response was: " + response);
        getUpnpService().getRegistry().removeRemoteSubscription(subscription);
        getUpnpService().getConfiguration().getRegistryListenerExecutor().execute(
                new Runnable() {
                    public void run() {
                        subscription.end(CancelReason.RENEWAL_FAILED,responseMessage.getOperation());
                    }
                }
        );
    } else if (!responseMessage.isValidHeaders()) {
        log.severe("Subscription renewal failed, invalid or missing (SID, Timeout) response headers");
        getUpnpService().getConfiguration().getRegistryListenerExecutor().execute(
                new Runnable() {
                    public void run() {
                        subscription.end(CancelReason.RENEWAL_FAILED, responseMessage.getOperation());
                    }
                }
        );
    } else {
        log.fine("Subscription renewed, updating in registry, response was: " + response);
        subscription.setActualSubscriptionDurationSeconds(responseMessage.getSubscriptionDurationSeconds());
        getUpnpService().getRegistry().updateRemoteSubscription(subscription);
    }

    return responseMessage;
}
 
Example #13
Source Project: DroidDLNA   Author: offbye   File: SubscriptionCallback.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void establishLocalSubscription(LocalService service) {

        if (getControlPoint().getRegistry().getLocalDevice(service.getDevice().getIdentity().getUdn(), false) == null) {
            log.fine("Local device service is currently not registered, failing subscription immediately");
            failed(null, null, new IllegalStateException("Local device is not registered"));
            return;
        }

        // Local execution of subscription on local service re-uses the procedure and lifecycle that is
        // used for inbound subscriptions from remote control points on local services!
        // Except that it doesn't ever expire, we override the requested duration with Integer.MAX_VALUE!

        LocalGENASubscription localSubscription = null;
        try {
            localSubscription =
                    new LocalGENASubscription(service, Integer.MAX_VALUE, Collections.EMPTY_LIST) {

                        public void failed(Exception ex) {
                            synchronized (SubscriptionCallback.this) {
                                SubscriptionCallback.this.setSubscription(null);
                                SubscriptionCallback.this.failed(null, null, ex);
                            }
                        }

                        public void established() {
                            synchronized (SubscriptionCallback.this) {
                                SubscriptionCallback.this.setSubscription(this);
                                SubscriptionCallback.this.established(this);
                            }
                        }

                        public void ended(CancelReason reason) {
                            synchronized (SubscriptionCallback.this) {
                                SubscriptionCallback.this.setSubscription(null);
                                SubscriptionCallback.this.ended(this, reason, null);
                            }
                        }

                        public void eventReceived() {
                            synchronized (SubscriptionCallback.this) {
                                log.fine("Local service state updated, notifying callback, sequence is: " + getCurrentSequence());
                                SubscriptionCallback.this.eventReceived(this);
                                incrementSequence();
                            }
                        }
                    };

            log.fine("Local device service is currently registered, also registering subscription");
            getControlPoint().getRegistry().addLocalSubscription(localSubscription);

            log.fine("Notifying subscription callback of local subscription availablity");
            localSubscription.establish();

            log.fine("Simulating first initial event for local subscription callback, sequence: " + localSubscription.getCurrentSequence());
            eventReceived(localSubscription);
            localSubscription.incrementSequence();

            log.fine("Starting to monitor state changes of local service");
            localSubscription.registerOnService();

        } catch (Exception ex) {
            log.fine("Local callback creation failed: " + ex.toString());
            log.log(Level.FINE, "Exception root cause: ", Exceptions.unwrap(ex));
            if (localSubscription != null)
                getControlPoint().getRegistry().removeLocalSubscription(localSubscription);
            failed(localSubscription, null, ex);
        }
    }
 
Example #14
Source Project: DroidDLNA   Author: offbye   File: RemoteItems.java    License: GNU General Public License v3.0 4 votes vote down vote up
boolean remove(final RemoteDevice remoteDevice, boolean shuttingDown) throws RegistrationException {
    final RemoteDevice registeredDevice = get(remoteDevice.getIdentity().getUdn(), true);
    if (registeredDevice != null) {

        log.fine("Removing remote device from registry: " + remoteDevice);

        // Resources
        for (Resource deviceResource : getResources(registeredDevice)) {
            if (registry.removeResource(deviceResource)) {
                log.fine("Unregistered resource: " + deviceResource);
            }
        }

        // Active subscriptions
        Iterator<RegistryItem<String, RemoteGENASubscription>> it = getSubscriptionItems().iterator();
        while (it.hasNext()) {
            final RegistryItem<String, RemoteGENASubscription> outgoingSubscription = it.next();

            UDN subscriptionForUDN =
                    outgoingSubscription.getItem().getService().getDevice().getIdentity().getUdn();

            if (subscriptionForUDN.equals(registeredDevice.getIdentity().getUdn())) {
                log.fine("Removing outgoing subscription: " + outgoingSubscription.getKey());
                it.remove();
                if (!shuttingDown) {
                    registry.getConfiguration().getRegistryListenerExecutor().execute(
                            new Runnable() {
                                public void run() {
                                    outgoingSubscription.getItem().end(CancelReason.DEVICE_WAS_REMOVED, null);
                                }
                            }
                    );
                }
            }
        }

        // Only notify listeners if we are NOT in the process of shutting down the registry
        if (!shuttingDown) {
            for (final RegistryListener listener : registry.getListeners()) {
                registry.getConfiguration().getRegistryListenerExecutor().execute(
                        new Runnable() {
                            public void run() {
                                listener.remoteDeviceRemoved(registry, registeredDevice);
                            }
                        }
                );
            }
        }

        // Finally, remove the device from the registry
        getDeviceItems().remove(new RegistryItem(registeredDevice.getIdentity().getUdn()));

        return true;
    }

    return false;
}
 
Example #15
Source Project: DroidDLNA   Author: offbye   File: LocalItems.java    License: GNU General Public License v3.0 4 votes vote down vote up
boolean remove(final LocalDevice localDevice, boolean shuttingDown) throws RegistrationException {

        LocalDevice registeredDevice = get(localDevice.getIdentity().getUdn(), true);
        if (registeredDevice != null) {

            log.fine("Removing local device from registry: " + localDevice);

            setDiscoveryOptions(localDevice.getIdentity().getUdn(), null);
            getDeviceItems().remove(new RegistryItem(localDevice.getIdentity().getUdn()));

            for (Resource deviceResource : getResources(localDevice)) {
                if (registry.removeResource(deviceResource)) {
                    log.fine("Unregistered resource: " + deviceResource);
                }
            }

            // Active subscriptions
            Iterator<RegistryItem<String, LocalGENASubscription>> it = getSubscriptionItems().iterator();
            while (it.hasNext()) {
                final RegistryItem<String, LocalGENASubscription> incomingSubscription = it.next();

                UDN subscriptionForUDN =
                        incomingSubscription.getItem().getService().getDevice().getIdentity().getUdn();

                if (subscriptionForUDN.equals(registeredDevice.getIdentity().getUdn())) {
                    log.fine("Removing incoming subscription: " + incomingSubscription.getKey());
                    it.remove();
                    if (!shuttingDown) {
                        registry.getConfiguration().getRegistryListenerExecutor().execute(
                                new Runnable() {
                                    public void run() {
                                        incomingSubscription.getItem().end(CancelReason.DEVICE_WAS_REMOVED);
                                    }
                                }
                        );
                    }
                }
            }

            if (isAdvertised(localDevice.getIdentity().getUdn()))
         		advertiseByebye(localDevice, !shuttingDown);

            if (!shuttingDown) {
                for (final RegistryListener listener : registry.getListeners()) {
                    registry.getConfiguration().getRegistryListenerExecutor().execute(
                            new Runnable() {
                                public void run() {
                                    listener.localDeviceRemoved(registry, localDevice);
                                }
                            }
                    );
                }
            }

            return true;
        }

        return false;
    }
 
Example #16
Source Project: Popeens-DSub   Author: popeen   File: DLNAController.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void create(final boolean playing, final int seconds) {
	downloadService.setPlayerState(PlayerState.PREPARING);

	callback = new SubscriptionCallback(getTransportService(), 600) {
		@Override
		protected void failed(GENASubscription genaSubscription, UpnpResponse upnpResponse, Exception e, String msg) {
			Log.w(TAG, "Register subscription callback failed: " + msg, e);
		}

		@Override
		protected void established(GENASubscription genaSubscription) {
			Action seekAction = genaSubscription.getService().getAction("Seek");
			if(seekAction != null) {
				StateVariable seekMode = genaSubscription.getService().getStateVariable("A_ARG_TYPE_SeekMode");
				for(String allowedValue: seekMode.getTypeDetails().getAllowedValues()) {
					if("REL_TIME".equals(allowedValue)) {
						supportsSeek = true;
					}
				}
			}
			Action setupNextAction = genaSubscription.getService().getAction("SetNextAVTransportURI");
			if(setupNextAction != null) {
				supportsSetupNext = true;
			}

			startSong(downloadService.getCurrentPlaying(), playing, seconds);
			downloadService.postDelayed(searchDLNA, SEARCH_UPDATE_INTERVAL_SECONDS);
		}

		@Override
		protected void ended(GENASubscription genaSubscription, CancelReason cancelReason, UpnpResponse upnpResponse) {
			Log.i(TAG, "Ended subscription");
			if(cancelReason != null) {
				Log.i(TAG, "Cancel Reason: " + cancelReason.toString());
			}
			if(upnpResponse != null) {
				Log.i(TAG, "Reponse Message: " + upnpResponse.getStatusMessage());
				Log.i(TAG, "Response Details: " + upnpResponse.getResponseDetails());
			}
		}

		@Override
		protected void eventReceived(GENASubscription genaSubscription) {
			Map<String, StateVariableValue> m = genaSubscription.getCurrentValues();
			try {
				String lastChangeText = m.get("LastChange").toString();
				lastChangeText = lastChangeText.replace(",X_DLNA_SeekTime","").replace(",X_DLNA_SeekByte", "");
				LastChange lastChange = new LastChange(new AVTransportLastChangeParser(), lastChangeText);

				if (lastChange.getEventedValue(0, AVTransportVariable.TransportState.class) == null) {
					return;
				}

				switch (lastChange.getEventedValue(0, AVTransportVariable.TransportState.class).getValue()) {
					case PLAYING:
						downloadService.setPlayerState(PlayerState.STARTED);
						break;
					case PAUSED_PLAYBACK:
						downloadService.setPlayerState(PlayerState.PAUSED);
						break;
					case STOPPED:
						boolean failed = false;
						for(StateVariableValue val: m.values()) {
							if(val.toString().indexOf("TransportStatus val=\"ERROR_OCCURRED\"") != -1) {
								Log.w(TAG, "Failed to load with event: " + val.toString());
								failed = true;
							}
						}

						if(failed) {
							failedLoad();
						} else if(downloadService.getPlayerState() == PlayerState.STARTED) {
							// Played until the end
							downloadService.onSongCompleted();
						} else {
							downloadService.setPlayerState(PlayerState.STOPPED);
						}
						break;
					case TRANSITIONING:
						downloadService.setPlayerState(PlayerState.PREPARING);
						break;
					case NO_MEDIA_PRESENT:
						downloadService.setPlayerState(PlayerState.IDLE);
						break;
					default:
				}
			}
			catch (Exception e) {
				Log.w(TAG, "Failed to parse UPNP event", e);
			}
		}

		@Override
		protected void eventsMissed(GENASubscription genaSubscription, int i) {
			Log.w(TAG, "Event missed: " + i);
		}
	};
	controlPoint.execute(callback);
}
 
Example #17
Source Project: TVRemoteIME   Author: kingthy   File: SubscriptionCallback.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Called when a local or remote subscription ended, either on user request or because of a failure.
 *
 * @param subscription   The ended subscription instance.
 * @param reason         If the subscription ended regularly (through <tt>end()</tt>), this is <tt>null</tt>.
 * @param responseStatus For a remote subscription, if the cause implies a remopte response and it was
 *                       received, this is it (e.g. renewal failure response).
 */
protected abstract void ended(GENASubscription subscription, CancelReason reason, UpnpResponse responseStatus);
 
Example #18
Source Project: DroidDLNA   Author: offbye   File: SubscriptionCallback.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * Called when a local or remote subscription ended, either on user request or because of a failure.
 *
 * @param subscription   The ended subscription instance.
 * @param reason         If the subscription ended regularly (through <tt>end()</tt>), this is <tt>null</tt>.
 * @param responseStatus For a remote subscription, if the cause implies a remopte response and it was
 *                       received, this is it (e.g. renewal failure response).
 */
protected abstract void ended(GENASubscription subscription, CancelReason reason, UpnpResponse responseStatus);