org.fourthline.cling.model.ServiceManager Java Examples

The following examples show how to use org.fourthline.cling.model.ServiceManager. 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: StateVariableAccessor.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
public StateVariableValue read(final StateVariable<LocalService> stateVariable, final Object serviceImpl) throws Exception {

        class AccessCommand implements Command {
            Object result;
            public void execute(ServiceManager serviceManager) throws Exception {
                result = read(serviceImpl);
                if (stateVariable.getService().isStringConvertibleType(result)) {
                    result = result.toString();
                }
            }
        }

        AccessCommand cmd = new AccessCommand();
        stateVariable.getService().getManager().execute(cmd);
        return new StateVariableValue(stateVariable, cmd.result);
    }
 
Example #2
Source File: StateVariableAccessor.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public StateVariableValue read(final StateVariable<LocalService> stateVariable, final Object serviceImpl) throws Exception {

        class AccessCommand implements Command {
            Object result;
            public void execute(ServiceManager serviceManager) throws Exception {
                result = read(serviceImpl);
                if (stateVariable.getService().isStringConvertibleType(result)) {
                    result = result.toString();
                }
            }
        }

        AccessCommand cmd = new AccessCommand();
        stateVariable.getService().getManager().execute(cmd);
        return new StateVariableValue(stateVariable, cmd.result);
    }
 
Example #3
Source File: LocalGENASubscription.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Moderates {@link org.fourthline.cling.model.ServiceManager#EVENTED_STATE_VARIABLES} events and state variable
 * values, calls {@link #eventReceived()}.
 */
synchronized public void propertyChange(PropertyChangeEvent e) {
    if (!e.getPropertyName().equals(ServiceManager.EVENTED_STATE_VARIABLES)) return;

    log.fine("Eventing triggered, getting state for subscription: " + getSubscriptionId());

    long currentTime = new Date().getTime();

    Collection<StateVariableValue> newValues = (Collection) e.getNewValue();
    Set<String> excludedVariables = moderateStateVariables(currentTime, newValues);

    currentValues.clear();
    for (StateVariableValue newValue : newValues) {
        String name = newValue.getStateVariable().getName();
        if (!excludedVariables.contains(name)) {
            log.fine("Adding state variable value to current values of event: " + newValue.getStateVariable() + " = " + newValue);
            currentValues.put(newValue.getStateVariable().getName(), newValue);

            // Preserve "last sent" state for future moderation
            lastSentTimestamp.put(name, currentTime);
            if (newValue.getStateVariable().isModeratedNumericType()) {
                lastSentNumericValue.put(name, Long.valueOf(newValue.toString()));
            }
        }
    }

    if (currentValues.size() > 0) {
        log.fine("Propagating new state variable values to subscription: " + this);
        // TODO: I'm not happy with this design, this dispatches to a separate thread which _then_
        // is supposed to lock and read the values off this instance. That obviously doesn't work
        // so it's currently a hack in SendingEvent.java
        eventReceived();
    } else {
        log.fine("No state variable values for event (all moderated out?), not triggering event");
    }
}
 
Example #4
Source File: LocalGENASubscription.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Moderates {@link org.fourthline.cling.model.ServiceManager#EVENTED_STATE_VARIABLES} events and state variable
 * values, calls {@link #eventReceived()}.
 */
synchronized public void propertyChange(PropertyChangeEvent e) {
    if (!e.getPropertyName().equals(ServiceManager.EVENTED_STATE_VARIABLES)) return;

    log.fine("Eventing triggered, getting state for subscription: " + getSubscriptionId());

    long currentTime = new Date().getTime();

    Collection<StateVariableValue> newValues = (Collection) e.getNewValue();
    Set<String> excludedVariables = moderateStateVariables(currentTime, newValues);

    currentValues.clear();
    for (StateVariableValue newValue : newValues) {
        String name = newValue.getStateVariable().getName();
        if (!excludedVariables.contains(name)) {
            log.fine("Adding state variable value to current values of event: " + newValue.getStateVariable() + " = " + newValue);
            currentValues.put(newValue.getStateVariable().getName(), newValue);

            // Preserve "last sent" state for future moderation
            lastSentTimestamp.put(name, currentTime);
            if (newValue.getStateVariable().isModeratedNumericType()) {
                lastSentNumericValue.put(name, Long.valueOf(newValue.toString()));
            }
        }
    }

    if (currentValues.size() > 0) {
        log.fine("Propagating new state variable values to subscription: " + this);
        // TODO: I'm not happy with this design, this dispatches to a separate thread which _then_
        // is supposed to lock and read the values off this instance. That obviously doesn't work
        // so it's currently a hack in SendingEvent.java
        eventReceived();
    } else {
        log.fine("No state variable values for event (all moderated out?), not triggering event");
    }
}
 
Example #5
Source File: LocalService.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
synchronized public void setManager(ServiceManager<T> manager) {
    if (this.manager != null) {
        throw new IllegalStateException("Manager is final");
    }
    this.manager = manager;
}
 
Example #6
Source File: LocalService.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
synchronized public ServiceManager<T> getManager() {
    if (manager == null) {
        throw new IllegalStateException("Unmanaged service, no implementation instance available");
    }
    return manager;
}
 
Example #7
Source File: ZxtMediaRenderer.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public ServiceManager<ZxtConnectionManagerService> getConnectionManager() {
    return connectionManager;
}
 
Example #8
Source File: ZxtMediaRenderer.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public ServiceManager<AVTransportService> getAvTransport() {
    return avTransport;
}
 
Example #9
Source File: ZxtMediaRenderer.java    From TVRemoteIME with GNU General Public License v2.0 4 votes vote down vote up
public ServiceManager<AudioRenderingControl> getRenderingControl() {
    return renderingControl;
}
 
Example #10
Source File: MediaServer.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
public MediaServer(final Context context) throws ValidationException, UnknownHostException {

        localAddress = getWIFIIpAddress(context);

        generateContentTask = new GenerateContentTask();
        generateContentTask.execute(context);

        udn = new UDN(UUID.randomUUID());
        DeviceType type = new UDADeviceType(deviceType, version);

        DeviceDetails details = new DeviceDetails(android.os.Build.MODEL,
                new ManufacturerDetails(android.os.Build.MANUFACTURER),
                new ModelDetails("HPlayer", "HPlayer MediaServer for Android", "v1"));

        LocalServiceBinder binder = new AnnotationLocalServiceBinder();

        // 文件共享服务
        LocalService<ContentDirectoryService> contentDirectoryService
                = binder.read(ContentDirectoryService.class);
        ServiceManager<ContentDirectoryService> contentDirectoryManger
                = new DefaultServiceManager<ContentDirectoryService>(contentDirectoryService) {
            @Override
            protected ContentDirectoryService createServiceInstance() throws Exception {
                return new ContentDirectoryService();
            }
        };
        contentDirectoryService.setManager(contentDirectoryManger);

        // 连接管理服务
        LocalService<ConnectionManagerService> connectionManagerService
                = binder.read(ConnectionManagerService.class);
        connectionManagerService.setManager(new DefaultServiceManager<>(
                connectionManagerService, ConnectionManagerService.class));

        // TODO 添加 AVTransportService
        // TODO 添加 AudioRenderingControl

        localDevice = new LocalDevice(new DeviceIdentity(udn), type, details,
                new LocalService[]{contentDirectoryService, connectionManagerService});

        // 启动服务器
        try {
            nanoHttpServer = new NanoHttpServer(port);
            nanoHttpServer.start();
            Log.d(TAG, "Started Http Server on port " + port);
        } catch (IOException e) {
            Log.d(TAG, "Started Http Server on error:" + e.getMessage());
            Toast.makeText(context, "启动服务器失败!", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }

    }
 
Example #11
Source File: LocalService.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
synchronized public void setManager(ServiceManager<T> manager) {
    if (this.manager != null) {
        throw new IllegalStateException("Manager is final");
    }
    this.manager = manager;
}
 
Example #12
Source File: LocalService.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
synchronized public ServiceManager<T> getManager() {
    if (manager == null) {
        throw new IllegalStateException("Unmanaged service, no implementation instance available");
    }
    return manager;
}
 
Example #13
Source File: ZxtMediaRenderer.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ServiceManager<ZxtConnectionManagerService> getConnectionManager() {
    return connectionManager;
}
 
Example #14
Source File: ZxtMediaRenderer.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ServiceManager<AVTransportService> getAvTransport() {
    return avTransport;
}
 
Example #15
Source File: ZxtMediaRenderer.java    From DroidDLNA with GNU General Public License v3.0 4 votes vote down vote up
public ServiceManager<AudioRenderingControl> getRenderingControl() {
    return renderingControl;
}