/** * Adds a property change listener on the {@link org.fourthline.cling.model.ServiceManager}. */ synchronized public void registerOnService() { getService().getManager().getPropertyChangeSupport().addPropertyChangeListener(this); }
/** * Removes a property change listener on the {@link org.fourthline.cling.model.ServiceManager}. */ synchronized public void end(CancelReason reason) { try { getService().getManager().getPropertyChangeSupport().removePropertyChangeListener(this); } catch (Exception ex) { log.warning("Removal of local service property change listener failed: " + Exceptions.unwrap(ex)); } ended(reason); }
@Override protected void onDestroy() { super.onDestroy(); // Stop monitoring the power switch LocalService<SwitchPower> switchPowerService = getSwitchPowerService(); if (switchPowerService != null) switchPowerService.getManager().getImplementation().getPropertyChangeSupport() .removePropertyChangeListener(this); getApplicationContext().unbindService(serviceConnection); }
public void onServiceConnected(ComponentName className, IBinder service) { upnpService = (AndroidUpnpService) service; LocalService<SwitchPower> switchPowerService = getSwitchPowerService(); // Register the device when this activity binds to the service for the first time if (switchPowerService == null) { try { LocalDevice binaryLightDevice = createDevice(); Toast.makeText(LightActivity.this, R.string.registeringDevice, Toast.LENGTH_SHORT).show(); upnpService.getRegistry().addDevice(binaryLightDevice); switchPowerService = getSwitchPowerService(); } catch (Exception ex) { log.log(Level.SEVERE, "Creating BinaryLight device failed", ex); Toast.makeText(LightActivity.this, R.string.createDeviceFailed, Toast.LENGTH_SHORT).show(); return; } } // Obtain the state of the power switch and update the UI setLightbulb(switchPowerService.getManager().getImplementation().getStatus()); // Start monitoring the power switch switchPowerService.getManager().getImplementation().getPropertyChangeSupport() .addPropertyChangeListener(LightActivity.this); }
if (service.getManager() == null) { throw new IllegalStateException("Service has no implementation factory, can't get service instance"); service.getManager().execute(new Command() { public void execute(ServiceManager serviceManager) throws Exception { AbstractActionExecutor.this.execute(
public LocalGENASubscription(LocalService service, Integer requestedDurationSeconds, List<URL> callbackURLs) throws Exception { super(service); setSubscriptionDuration(requestedDurationSeconds); log.fine("Reading initial state of local service at subscription time"); long currentTime = new Date().getTime(); this.currentValues.clear(); Collection<StateVariableValue> values = getService().getManager().getCurrentState(); log.finer("Got evented state variable values: " + values.size()); for (StateVariableValue value : values) { this.currentValues.put(value.getStateVariable().getName(), value); if (log.isLoggable(Level.FINEST)) { log.finer("Read state variable value '" + value.getStateVariable().getName() + "': " + value.toString()); } // Preserve "last sent" state for future moderation lastSentTimestamp.put(value.getStateVariable().getName(), currentTime); if (value.getStateVariable().isModeratedNumericType()) { lastSentNumericValue.put(value.getStateVariable().getName(), Long.valueOf(value.toString())); } } this.subscriptionId = SubscriptionIdHeader.PREFIX + UUID.randomUUID(); this.currentSequence = new UnsignedIntegerFourBytes(0); this.callbackURLs = callbackURLs; }
stateVariable.getService().getManager().execute(cmd); return new StateVariableValue(stateVariable, cmd.result);
/** * Adds a property change listener on the {@link org.fourthline.cling.model.ServiceManager}. */ synchronized public void registerOnService() { getService().getManager().getPropertyChangeSupport().addPropertyChangeListener(this); }
/** * Removes a property change listener on the {@link org.fourthline.cling.model.ServiceManager}. */ synchronized public void end(CancelReason reason) { try { getService().getManager().getPropertyChangeSupport().removePropertyChangeListener(this); } catch (Exception ex) { log.warning("Removal of local service property change listener failed: " + Exceptions.unwrap(ex)); } ended(reason); }
if (service.getManager() == null) { throw new IllegalStateException("Service has no implementation factory, can't get service instance"); service.getManager().execute(new Command() { public void execute(ServiceManager serviceManager) throws Exception { AbstractActionExecutor.this.execute(
public LocalGENASubscription(LocalService service, Integer requestedDurationSeconds, List<URL> callbackURLs) throws Exception { super(service); setSubscriptionDuration(requestedDurationSeconds); log.fine("Reading initial state of local service at subscription time"); long currentTime = new Date().getTime(); this.currentValues.clear(); Collection<StateVariableValue> values = getService().getManager().getCurrentState(); log.finer("Got evented state variable values: " + values.size()); for (StateVariableValue value : values) { this.currentValues.put(value.getStateVariable().getName(), value); if (log.isLoggable(Level.FINEST)) { log.finer("Read state variable value '" + value.getStateVariable().getName() + "': " + value.toString()); } // Preserve "last sent" state for future moderation lastSentTimestamp.put(value.getStateVariable().getName(), currentTime); if (value.getStateVariable().isModeratedNumericType()) { lastSentNumericValue.put(value.getStateVariable().getName(), Long.valueOf(value.toString())); } } this.subscriptionId = SubscriptionIdHeader.PREFIX + UUID.randomUUID(); this.currentSequence = new UnsignedIntegerFourBytes(0); this.callbackURLs = callbackURLs; }
stateVariable.getService().getManager().execute(cmd); return new StateVariableValue(stateVariable, cmd.result);
/** * Adds a property change listener on the {@link org.fourthline.cling.model.ServiceManager}. */ synchronized public void registerOnService() { getService().getManager().getPropertyChangeSupport().addPropertyChangeListener(this); }
/** * Removes a property change listener on the {@link org.fourthline.cling.model.ServiceManager}. */ synchronized public void end(CancelReason reason) { try { getService().getManager().getPropertyChangeSupport().removePropertyChangeListener(this); } catch (Exception ex) { log.warning("Removal of local service property change listener failed: " + Exceptions.unwrap(ex)); } ended(reason); }
if (service.getManager() == null) { throw new IllegalStateException("Service has no implementation factory, can't get service instance"); service.getManager().execute(new Command() { public void execute(ServiceManager serviceManager) throws Exception { AbstractActionExecutor.this.execute(
public LocalGENASubscription(LocalService service, Integer requestedDurationSeconds, List<URL> callbackURLs) throws Exception { super(service); setSubscriptionDuration(requestedDurationSeconds); log.fine("Reading initial state of local service at subscription time"); long currentTime = new Date().getTime(); this.currentValues.clear(); Collection<StateVariableValue> values = getService().getManager().getCurrentState(); log.finer("Got evented state variable values: " + values.size()); for (StateVariableValue value : values) { this.currentValues.put(value.getStateVariable().getName(), value); if (log.isLoggable(Level.FINEST)) { log.finer("Read state variable value '" + value.getStateVariable().getName() + "': " + value.toString()); } // Preserve "last sent" state for future moderation lastSentTimestamp.put(value.getStateVariable().getName(), currentTime); if (value.getStateVariable().isModeratedNumericType()) { lastSentNumericValue.put(value.getStateVariable().getName(), Long.valueOf(value.toString())); } } this.subscriptionId = SubscriptionIdHeader.PREFIX + UUID.randomUUID(); this.currentSequence = new UnsignedIntegerFourBytes(0); this.callbackURLs = callbackURLs; }
stateVariable.getService().getManager().execute(cmd); return new StateVariableValue(stateVariable, cmd.result);
public MediaServer(InetAddress localAddress, Context ctx) throws ValidationException { super(null, port, null, true); Log.i(TAG, "Creating media server !"); localService = new AnnotationLocalServiceBinder() .read(ContentDirectoryService.class); localService.setManager(new DefaultServiceManager<ContentDirectoryService>( localService, ContentDirectoryService.class)); udn = UDN.valueOf(new UUID(0,10).toString()); this.localAddress = localAddress; this.ctx = ctx; createLocalDevice(); ContentDirectoryService contentDirectoryService = (ContentDirectoryService)localService.getManager().getImplementation(); contentDirectoryService.setContext(ctx); contentDirectoryService.setBaseURL(getAddress()); }