Create DServerClass commands.

Create one instance of all classes representing command available for
device of the DServer class.
These commands are QueryDevice, QueryClass, Kill, SetTraceLevel,
GetTraceLevel, SetTraceOutput and GetTraceOutput
966000
public void command_factory()
	{
		command_list.addElement(new DevRestartCmd(
					"DevRestart",
					Tango_DEV_STRING,
					Tango_DEV_VOID,
					"Device name"));
		command_list.addElement(new RestartServerCmd(
					"RestartServer",
					Tango_DEV_VOID,
					Tango_DEV_VOID));
		command_list.addElement(new QueryClassCmd(
					"QueryClass",
					Tango_DEV_VOID,
					Tango_DEVVAR_STRINGARRAY,
					"Device server class(es) list"));
		command_list.addElement(new QueryDeviceCmd(
					"QueryDevice",
					Tango_DEV_VOID,
					Tango_DEVVAR_STRINGARRAY,
					"Device server device(s) list"));
		command_list.addElement(new KillCmd(
					"Kill",
					Tango_DEV_VOID,
					Tango_DEV_VOID));
		command_list.addElement(new AddLoggingTargetCmd(
					"AddLoggingTarget",
					Tango_DEVVAR_STRINGARRAY,
					Tango_DEV_VOID,
					"Str[i]=Device-name - Str[i+1]=target_type::target_name"));
		command_list.addElement(new RemoveLoggingTargetCmd(
					"RemoveLoggingTarget",
					Tango_DEVVAR_STRINGARRAY,
					Tango_DEV_VOID,
					"Str[i]=Device-name - Str[i+1]=target_type::target_name"));
		command_list.addElement(new GetLoggingTargetCmd("GetLoggingTarget",
					Tango_DEV_STRING,
					Tango_DEVVAR_STRINGARRAY,
					"Device name",
					"Logging target list"));
		command_list.addElement(new SetLoggingLevelCmd(
					"SetLoggingLevel",
					Tango_DEVVAR_LONGSTRINGARRAY,
                    Tango_DEV_VOID,
                    "Lg[i]=Logging level. Str[i]=Device name."));
		command_list.addElement(new GetLoggingLevelCmd(
					"GetLoggingLevel",
					Tango_DEVVAR_STRINGARRAY,
                    Tango_DEVVAR_LONGSTRINGARRAY,
                    "Device list",
                    "Lg[i]=Logging level. Str[i]=Device name."));
		command_list.addElement(new StopLoggingCmd(
					"StopLogging",
					Tango_DEV_VOID,
					Tango_DEV_VOID));
		command_list.addElement(new StartLoggingCmd(
					"StartLogging",
					Tango_DEV_VOID,
					Tango_DEV_VOID));

		// Now, commands related to polling
		command_list.addElement(new PolledDeviceCmd(
					"PolledDevice",
					Tango_DEV_VOID,
					Tango_DEVVAR_STRINGARRAY,
					"Polled device name list"));
		command_list.addElement(new DevPollStatusCmd(
					"DevPollStatus",
					Tango_DEV_STRING,
					Tango_DEVVAR_STRINGARRAY,
					"Device name",
					"Device polling status"));

		String	msg = "Lg[0]=Upd period. Str[0]=Device name. Str[1]=Object type. Str[2]=Object name";
		command_list.addElement(new AddObjPollingCmd(
					"AddObjPolling",
					Tango_DEVVAR_LONGSTRINGARRAY,
					Tango_DEV_VOID,
					msg));
						    
		command_list.addElement(new UpdObjPollingPeriodCmd(
					"UpdObjPollingPeriod",
					Tango_DEVVAR_LONGSTRINGARRAY,
					Tango_DEV_VOID,
					msg));

		msg = "Lg[0]=Upd period. Str[0]=Device name. Str[1]=Object type. Str[2]=Object name";
		command_list.addElement(new RemObjPollingCmd(
					"RemObjPolling",
					Tango_DEVVAR_STRINGARRAY,
					Tango_DEV_VOID,
					msg));
						    
		command_list.addElement(new StopPollingCmd(
					"StopPolling",
					Tango_DEV_VOID,
					Tango_DEV_VOID));
						  
		command_list.addElement(new StartPollingCmd(
					"StartPolling",
					Tango_DEV_VOID,
					Tango_DEV_VOID));
}
646779
private function createFromCommand()
    {
        $command = TagCommand::getInstance($this->getRepository())->listTags();
        $outputLines = $this->getCaller()->execute($command, true, $this->getRepository()->getPath())->getOutputLines();
        $this->parseOutputLines($outputLines);
    }
850165
private List<RequestDispatcher> createRequestDispatchers(Configuration pConfig,
                                                             Converters pConverters,
                                                             ServerHandle pServerHandle,
                                                             Restrictor pRestrictor) {
        List<RequestDispatcher> ret = new ArrayList<RequestDispatcher>();
        String classes = pConfig != null ? pConfig.get(DISPATCHER_CLASSES) : null;
        if (classes != null && classes.length() > 0) {
            String[] names = classes.split("\\s*,\\s*");
            for (String name : names) {
                ret.add(createDispatcher(name, pConverters, pServerHandle, pRestrictor, pConfig));
            }
        }
        return ret;
    }
1191400
def __make_server(self):
        ""
        notice('Making server, getting listening socket', self.color)
        self.mode = 's'
        sock = utils.get_server_sock()
        self.__s = sock
        with self.__client_list_lock:
            self.clients = deque()
        self.threads = deque()
        notice('Making beacon', self.color)
        b = Thread(target=self.__beacon_thread, name='beacon')
        b.start()
        self.threads.append(b)
        l = Thread(target=self.__listen_thread, name='listen')
        notice('Starting listen thread', self.color)
        l.start()
        self.threads.append(l)
1288133
public String[] query_device() throws DevFailed {
        Util.out4.println("In QueryDevice command");

        final int nb_class = class_list.size();
        final Vector tmp_name = new Vector();

        for (int i = 0; i < nb_class; i++) {
            final int nb_dev = ((DeviceClass) class_list.elementAt(i)).get_device_list().size();
            for (int j = 0; j < nb_dev; j++) {
                tmp_name.addElement(((DeviceImpl) ((DeviceClass) class_list.elementAt(i))
                        .get_device_list().elementAt(j)).get_name());
            }
        }

        String[] ret = null;
        try {
            ret = new String[tmp_name.size()];

            for (int i = 0; i < tmp_name.size(); i++) {
                ret[i] = (String) tmp_name.elementAt(i);
            }
        } catch (final BAD_OPERATION ex) {
            Util.out3.println("Memory Allocation error in DServer.query_device method");
            Except.throw_exception("API_MemoryAllocation", "Can't allocate memory in server",
                    "DServer.query_device");
        }
        return ret;
    }
1287205
def _make_command_method(cls, command_name, many=False):
        
        def func(self, *args, **kwargs):
            if many:
                args = self.from_python_many(*args)
            else:
                if 'value' in kwargs:
                    kwargs['value'] = self.from_python(kwargs['value'])
                else:
                    args = list(args)
                    args[0] = self.from_python(args[0])

            # call the super method, with real pk
            sup_method = getattr(super(cls, self), command_name)
            return sup_method(*args, **kwargs)
        return func
1186148
public void addCommandClass(ZWaveCommandClass commandClass)
	{
		ZWaveCommandClass.CommandClass key = commandClass.getCommandClass();
		
		if (!supportedCommandClasses.containsKey(key)) {
			supportedCommandClasses.put(key, commandClass);
			
			if (commandClass instanceof ZWaveEventListener)
				this.controller.addEventListener((ZWaveEventListener)commandClass);
			
			this.lastUpdated = Calendar.getInstance().getTime();
		}
	}
1330042
function CommandProcessor(conn) {
	events.EventEmitter.call(this);

	this.conn = conn;

	this.connected_at = +new Date();
	this.last_data_at = 0;
	this.last_ping_at = 0;

	p.data_timeout = -1; // disabled
	p.data_timeout_TID = null;

	p.ping_timeout = -1; // disabled
	p.ping_timeout_TID = null;

	this._request_id = 0;
	this._requests_in_flight = {};

	this.last_line   = '';

	// handling disconnection can only be done once
	var _handle_disconnection = _.once(this._handle_disconnection.bind(this));

	conn.on('data',  this.process_data.bind(this));
	conn.on('error', _handle_disconnection);
	conn.on('end',   _handle_disconnection); // Do we really need this?
	conn.on('close', _handle_disconnection);

	// bind some methods to current instance for easy reuse
	this._emit_data_timeout = this._emit_data_timeout .bind(this);
	this._emit_ping_timeout = this._emit_ping_timeout .bind(this);
	this.set_timeouts();
}
756522
public void addCommandClass(ZWaveCommandClass commandClass) {
		ZWaveCommandClass.CommandClass key = commandClass.getCommandClass();
		if (!supportedCommandClasses.containsKey(key)) {
			supportedCommandClasses.put(key, commandClass);
		}
	}
232089
function CommandController(descriptor){

	Object.defineProperties(this, {
		name: {
			get: function(){
				return descriptor.name;
			}
		},
		description: {
			get: function(){
				return descriptor.description;
			}
		},
		CommandError: {
			get: function(){
				return LocalCommandError;
			}
		},
		RuntimeCommandError: {
			get: function (){
				return LocalRuntimeCommandError;
			}
		},
		errorLvl: {
			get: function(){
				return Object.create(CONST.errorLvl);
			}
		}
	});

	function LocalCommandError(message, level){
		CommandError.call(this, message, descriptor.name, level);
	}
	LocalCommandError.prototype = Object.create(CommandError.prototype);

	function LocalRuntimeCommandError(message){
		RuntimeCommandError.call(this, message, descriptor.name);
	}
	LocalRuntimeCommandError.prototype = Object.create(RuntimeCommandError.prototype);
}
239539
function Command(types, commandSpec) {
  Object.keys(commandSpec).forEach(function(key) {
    this[key] = commandSpec[key];
  }, this);

  if (!this.name) {
    throw new Error('All registered commands must have a name');
  }

  if (this.params == null) {
    this.params = [];
  }
  if (!Array.isArray(this.params)) {
    throw new Error('command.params must be an array in ' + this.name);
  }

  this.hasNamedParameters = false;
  this.description = 'description' in this ? this.description : undefined;
  this.description = lookup(this.description, 'canonDescNone');
  this.manual = 'manual' in this ? this.manual : undefined;
  this.manual = lookup(this.manual);

  // At this point this.params has nested param groups. We want to flatten it
  // out and replace the param object literals with Parameter objects
  var paramSpecs = this.params;
  this.params = [];
  this.paramGroups = {};
  this._shortParams = {};

  var addParam = function(param) {
    var groupName = param.groupName || l10n.lookup('canonDefaultGroupName');
    this.params.push(param);
    if (!this.paramGroups.hasOwnProperty(groupName)) {
      this.paramGroups[groupName] = [];
    }
    this.paramGroups[groupName].push(param);
  }.bind(this);

  // Track if the user is trying to mix default params and param groups.
  // All the non-grouped parameters must come before all the param groups
  // because non-grouped parameters can be assigned positionally, so their
  // index is important. We don't want 'holes' in the order caused by
  // parameter groups.
  var usingGroups = false;

  // In theory this could easily be made recursive, so param groups could
  // contain nested param groups. Current thinking is that the added
  // complexity for the UI probably isn't worth it, so this implementation
  // prevents nesting.
  paramSpecs.forEach(function(spec) {
    if (!spec.group) {
      var param = new Parameter(types, spec, this, null);
      addParam(param);

      if (!param.isPositionalAllowed) {
        this.hasNamedParameters = true;
      }

      if (usingGroups && param.groupName == null) {
        throw new Error('Parameters can\'t come after param groups.' +
                        ' Ignoring ' + this.name + '/' + spec.name);
      }

      if (param.groupName != null) {
        usingGroups = true;
      }
    }
    else {
      spec.params.forEach(function(ispec) {
        var param = new Parameter(types, ispec, this, spec.group);
        addParam(param);

        if (!param.isPositionalAllowed) {
          this.hasNamedParameters = true;
        }
      }, this);

      usingGroups = true;
    }
  }, this);

  this.params.forEach(function(param) {
    if (param.short != null) {
      if (this._shortParams[param.short] != null) {
        throw new Error('Multiple params using short name ' + param.short);
      }
      this._shortParams[param.short] = param;
    }
  }, this);
}
467602
public static Class<? extends Command<? extends CLIContext>> getCommandClass(
            CLIContext context, String commandName) {
        return context.getHostApplication().getCommands().get(commandName.toLowerCase());
    }
776973
def _make_serverproxy_handler(name, command, environment, timeout, absolute_url, port):
    
    # FIXME: Set 'name' properly
    class _Proxy(SuperviseAndProxyHandler):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.name = name
            self.proxy_base = name
            self.absolute_url = absolute_url
            self.requested_port = port

        @property
        def process_args(self):
            return {
                'port': self.port,
                'base_url': self.base_url,
            }

        def _render_template(self, value):
            args = self.process_args
            if type(value) is str:
                return value.format(**args)
            elif type(value) is list:
                return [self._render_template(v) for v in value]
            elif type(value) is dict:
                return {
                    self._render_template(k): self._render_template(v)
                    for k, v in value.items()
                }
            else:
                raise ValueError('Value of unrecognized type {}'.format(type(value)))

        def get_cmd(self):
            if callable(command):
                return self._render_template(call_with_asked_args(command, self.process_args))
            else:
                return self._render_template(command)

        def get_env(self):
            if callable(environment):
                return self._render_template(call_with_asked_args(environment, self.process_args))
            else:
                return self._render_template(environment)

        def get_timeout(self):
            return timeout

    return _Proxy
1328281
def _cmd(self, command, data=None, params=None, api_version=1):
    
    return self._post("commands/" + command, ApiCommand,
        data=data, params=params, api_version=api_version)
1179854
def list_commands(self, **kwargs):
        
        commands = self._commands

        command_id = kwargs.get('CommandId', None)
        if command_id:
            commands = [self.get_command_by_id(command_id)]
        instance_id = kwargs.get('InstanceId', None)
        if instance_id:
            commands = self.get_commands_by_instance_id(instance_id)

        return {
            'Commands': [command.response_object() for command in commands]
        }
116559
def run_and_exit(command_class):
    ''''''
    cmd = command_class(sys.argv[1:])
    if cmd.error:
        print('error: {0}'.format(cmd.error))
        sys.exit(1)
    else:
        sys.exit(cmd.run())
1060360
void polling_configure() {
	// Send a stop polling command to thread in order not to poll devices
	final DServer adm_dev = get_dserver_device();

	try {
	    adm_dev.stop_polling();
	} catch (final DevFailed e) {
	    Except.print_exception(e);
	}

	final Vector tmp_cl_list = adm_dev.get_class_list();// DeviceClass
	int upd;

	// Create the structure used to send data to the polling thread
	final DevVarLongStringArray send = new DevVarLongStringArray();
	send.lvalue = new int[1];
	send.svalue = new String[3];

	// A loop on each class and each device in class
	for (int i = 0; i < tmp_cl_list.size(); i++) {
	    final DeviceClass dc = (DeviceClass) tmp_cl_list.elementAt(i);
	    final Vector dev_list = dc.get_device_list(); // <DeviceImpl *
	    for (int j = 0; j < dev_list.size(); j++) {
		final DeviceImpl dev = (DeviceImpl) dev_list.elementAt(j);
		final Vector poll_cmd_list = dev.get_polled_cmd();
		final Vector poll_attr_list = dev.get_polled_attr();

		// Send a Add Object command to the polling thread only
		// if the polling period is different than zero
		for (int k = 0; k < poll_cmd_list.size(); k++) {
		    if (k == 0) {
			send.svalue[0] = dev.get_name();
			send.svalue[1] = "command";
		    }

		    // Convert polling period to a number
		    final String strval = (String) poll_cmd_list.elementAt(k + 1);
		    upd = Integer.parseInt(strval);

		    // Send command to the polling thread
		    if (upd != 0) {
			send.lvalue[0] = upd;
			send.svalue[2] = (String) poll_cmd_list.elementAt(k);

			try {
			    adm_dev.add_obj_polling(send, false);
			} catch (final DevFailed e) {
			}
		    }
		    k++;
		}

		// Send a Add Object attribute to the polling thread only
		// if the polling period is different than zero
		for (int k = 0; k < poll_attr_list.size(); k++) {

		    if (k == 0) {
			send.svalue[0] = dev.get_name();
			send.svalue[1] = "attribute";
		    }
		    // Convert polling period to a number
		    final String strval = (String) poll_attr_list.elementAt(k + 1);
		    upd = Integer.parseInt(strval);

		    // Send command to the polling thread
		    if (upd != 0) {
			send.lvalue[0] = upd;
			send.svalue[2] = (String) poll_attr_list.elementAt(k);

			try {
			    adm_dev.add_obj_polling(send, false);
			} catch (final DevFailed e) {
			}
		    }
		    k++;
		}
	    }
	}

	// Now, start the real polling
	try {
	    adm_dev.start_polling();
	} catch (final DevFailed e) {
	    Except.print_exception(e);
	}
    }