Package de.mnl.srcpd4cu.srcp

Examples of de.mnl.srcpd4cu.srcp.Device


                = CommandUtil.findDeviceGroup(session, args);
            if (!deviceGroup.getSupportedDeviceTypes()
                .contains(GettableDevice.class)) {
                throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            Device device;
            if (deviceGroup instanceof SingleDeviceGroup) {
                device = ((SingleDeviceGroup)deviceGroup).getDevice();
            } else {
                long address = CommandUtil.consumeNumber(args);
                device = deviceGroup.getDevice(address);
                if (device == null) {
                    if (!deviceGroup.allowImplicitCreation()) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_DEVICE);
                    }
                    device = deviceGroup.createDevice(address);
                    if (!(device instanceof InitializableDevice)
                        || !(device instanceof GettableDevice)) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_DEVICE);
                    }
                    ((InitializableDevice)device).init
                        (session, deviceGroup,
                         ((InitializableDevice)device).getDescription());
                    device.addStateChangeListener(session.getServer());
                }
            }
            if (!(device instanceof GettableDevice)) {
                throw new CommandExecutionException
                    (ERROR_UNSUPPORTED_OPERATION);
            }
            String info;
            if (args.size() > 0) {
                if (device instanceof AddressableStateProvider) {
                    synchronized (device) {
                        info = ((AddressableStateProvider)device)
                            .getState(session, args);
                    }
                } else {
                    throw new CommandExecutionException(ERROR_LIST_TOO_LONG);
                }
            } else {
                synchronized (device) {
                    String[] states
                        = ((GettableDevice)device).getState(session);
                    if (states.length != 1) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_OPERATION);
                    }
                    info = states[0];
                }
            }
            String details = "INFO "
                + device.getDeviceGroup().getBus().getNumber()
                + " " + device.getDeviceGroup().getName();
            if (device instanceof AddressableDevice) {
                details += " " + ((AddressableDevice)device).getAddress();
            }
            if (info != null && info.length() > 0) {
                details += " " + info;
View Full Code Here


     * #getInfo(de.mnl.srcpd4cu.devices.Session, java.util.List)
     */
    @Override
    public String getState(SessionDevice session, List<String> args)
            throws CommandExecutionException {
        Device device = CommandUtil
            .findDevice(session, getDeviceGroup().getBus(), args, false);
        if (!(device instanceof InitializableDevice)) {
            throw new CommandExecutionException
                (Command.ERROR_UNSUPPORTED_OPERATION);
        }
        StringBuffer sb = new StringBuffer();
        sb.append(device.getDeviceGroup().getName());
        if (device instanceof AddressableDevice) {
            sb.append(' ');
            sb.append(((AddressableDevice)device).getAddress());
        }
        String info = ((InitializableDevice)device).getDescription();
View Full Code Here

    @Override
    public Response execute(SessionDevice session, String arguments) {
        try {
            List<String> args
                = new ArrayList<String>(Arrays.asList(arguments.split(" ")));
            Device device = CommandUtil.findDevice(session, args, true);
            if (!device.getDeviceGroup().getSupportedDeviceTypes()
                    .contains(TerminatableDevice.class)) {
                    throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            if (!(device instanceof TerminatableDevice)) {
                return ERROR_NOT_SUPPORTED;
View Full Code Here

    @Override
    public Response execute(SessionDevice session, String arguments) {
        try {
            List<String> args
                = new ArrayList<String>(Arrays.asList(arguments.split(" ")));
            Device device = CommandUtil.findDevice(session, args);
            if (!device.getDeviceGroup().getSupportedDeviceTypes()
                .contains(ResettableDevice.class)) {
                    throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            if (!(device instanceof ResettableDevice)) {
                return ERROR_NOT_SUPPORTED;
View Full Code Here

                = CommandUtil.findDeviceGroup(session, args);
            if (!deviceGroup.getSupportedDeviceTypes()
                .contains(SettableDevice.class)) {
                throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            Device device;
            if (deviceGroup instanceof SingleDeviceGroup) {
                device = ((SingleDeviceGroup)deviceGroup).getDevice();
            } else {
                long address = CommandUtil.consumeNumber(args);
                device = deviceGroup.getDevice(address);
                if (device == null) {
                    if (!deviceGroup.allowImplicitCreation()) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_DEVICE);
                    }
                    device = deviceGroup.createDevice(address);
                    if (!(device instanceof InitializableDevice)
                        || !(device instanceof SettableDevice)) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_DEVICE);
                    }
                    ((InitializableDevice)device).init
                        (session, deviceGroup,
                         ((InitializableDevice)device).getDescription());
                    device.addStateChangeListener(session.getServer());
                }
            }
            if (!(device instanceof SettableDevice)) {
                return ERROR_NOT_SUPPORTED;
            }
View Full Code Here

                = CommandUtil.findDeviceGroup(session, args);
            if (!deviceGroup.getSupportedDeviceTypes()
                .contains(InitializableDevice.class)) {
                throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            Device device;
            if (deviceGroup instanceof SingleDeviceGroup) {
                device = ((SingleDeviceGroup)deviceGroup).getDevice();
            } else {
                long address = CommandUtil.consumeNumber(args);
                device = deviceGroup.getDevice(address);
                if (device == null) {
                    device = deviceGroup.createDevice(address);
                    device.addStateChangeListener(session.getServer());
                }
            }
            if (!(device instanceof InitializableDevice)) {
                return ERROR_NOT_SUPPORTED;
            }
View Full Code Here

        throws CommandExecutionException {
        List<String> idsCopy = new ArrayList<String>(ids);
        try {
            DeviceGroup deviceGroup
                = CommandUtil.findDeviceGroup(session, bus, ids);
            Device device = null;
            if (deviceGroup instanceof SingleDeviceGroup) {
                return ((SingleDeviceGroup) deviceGroup).getDevice();
            }
            // Special case: although devices have addresses and therefore
            // an address must be specified, the address may be omitted
View Full Code Here

TOP

Related Classes of de.mnl.srcpd4cu.srcp.Device

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.