Poco::OSP::Shell

class CommandProcessor

File Information

Library: OSP/Shell
Package: Shell
Header: Poco/OSP/Shell/CommandProcessor.h

Description

The CommandProcessor parses command lines and invokes commands.

Member Summary

Member Functions: addCommand, aliases, context, createCommand, execute, listCommands, parseCommandLine, removeBundle, removeCommand

Types Aliases

FactoryPtr

using FactoryPtr = Poco::SharedPtr < CommandFactory >;

Constructors

CommandProcessor

CommandProcessor(
    Poco::OSP::BundleContext::Ptr pContext
);

Creates the CommandProcessor, using the given bundle context.

Destructor

~CommandProcessor

~CommandProcessor();

Destroys the CommandProcessor.

Member Functions

addCommand

void addCommand(
    const std::string & command,
    const std::set < std::string > & aliases,
    FactoryPtr pFactory,
    const std::string & permission
);

Adds a command to the command processor.

The given command name must be unique, otherwise an ExistsException will be thrown. The given aliases set can be empty. Upon execution of the command, the given permission is checked against the current user's permissions. It can be empty to disable the check.

aliases

void aliases(
    const std::string & command,
    std::set < std::string > & aliases
) const;

Fills the given set with all aliases for the given command.

context inline

Poco::OSP::BundleContext::Ptr context() const;

Returns the BundleContext used by the CommandProcessor.

execute

int execute(
    Session & session,
    const std::string & commandLine,
    std::ostream & ostr
);

Executes the command given in commandLine in the given session.

Throws a Poco::NotFoundException if the given command is not known.

The following commands are builtin:

  • .login <userName> <credentials>: Attempts to log the user into the current session with the given userName and credentials (password).
  • .help Displays a list of all registered commands.
  • .quit Ends the session.

listCommands

void listCommands(
    std::vector < std::string > & commands
) const;

Fills the given vector with the names of all registered commands.

removeBundle

void removeBundle(
    Poco::OSP::Bundle::Ptr pBundle
);

Removes all commands defined by the given bundle.

removeCommand

void removeCommand(
    const std::string & command
);

Removes the given command.

createCommand protected

Command * createCommand(
    const Session & session,
    const std::string & command
);

Creates a Command object for the given command name.

Throws a Poco::NotFoundException if the given command is unknown. Returns a new command object, or a null pointer if the user is not authorized to call the command.

parseCommandLine protected

void parseCommandLine(
    const std::string & commandLine,
    std::vector < std::string > & items
);

Parses the command line into single items.

The first item is used as command name. Remaining items are arguments to the command. Items are separated by one or more space or tab characters. An item can be enclosed in single or double quotes. Characters can be escaped with a backslash.

Variables

COMMAND_HELP static

static const std::string COMMAND_HELP;

COMMAND_LOGIN static

static const std::string COMMAND_LOGIN;

COMMAND_QUIT static

static const std::string COMMAND_QUIT;

Securely control IoT edge devices from anywhere   Connect a Device