ServerCore/Command.h

82 lines
2.6 KiB
C++

#ifndef __Command_h__
#define __Command_h__
#include "includes"
#include "Object.h"
#include "TCPSession.h"
#include "PString.h"
namespace core {
class Session;
///
/// Command
///
/// Use the Command object in combination with a CommandList object to maintain
/// a list of functions that can be invoked as a result of processing a request.
///
class Command : public Object {
public:
///
/// Implement check method to provide a special check rule upon the request to see
/// if the command should be processed.
///
/// The default rule is to verify that the first token in the request string matches
/// the name given on the registration of the command to the CommandList. This can
/// be overridden by implementing the check() method to perform the test and return
/// the condition of the command.
///
/// @param request The request passed to the parser to check the rule.
/// @return Return true to execute the command. Returning false will cause no action
/// on this command.
///
virtual bool check(std::string request);
///
/// This method is used to implement the functionality of the requested command.
/// This pure virtual function must be implemented in your inheriting object.
///
/// @param request The request that was entered by the user to invoke this command.
/// @param session Specify the requesting session so that the execution of the
/// command process can return its output to the session.
/// @return Returns 0 if execution of the command was successful. Otherwise returns
/// a non-zero value indicating an error condition.
///
virtual int processCommand(std::string request, TCPSession *session, std::stringstream &data);
///
/// Specify the output that will occur to the specified session.
///
/// @param session The session that will receive the output.
///
virtual void output(Session *session);
///
/// Set the name of this command used in default rule checking during request parsing.
/// NOTE: You do not need to call this under normal conditions as adding a Command
/// to a CommandList using the add() method contains a parameter to pass the name
/// of the Command.
///
/// @param name Specify the name of this command for default parsing.
///
void setName(std::string name);
std::string getName();
private:
std::string name;
};
}
#endif