Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

CmdServer Class Reference

Inheritance diagram for CmdServer:

BasicTcpServer List of all members.

Detailed Description

Definition at line 23 of file cmd_server.h.

Public Types

enum  { SINGLE, MULTI }
 Enum constants used for 'access' flag. More...

Public Member Functions

void addCtlCmd (void *object, const char *label, CmdMeth statMeth, int access=SINGLE)
 Adds a 'control' method to the list of methods recognised as commands by the CmdServer.
void addMonCmd (void *object, const char *label, CmdMeth statMeth)
 Adds a 'monitor' method to the list of methods recognised as commands by the CmdServer.
void blockOn ()
 A method to block the calling thread as long as the BasicTcpServer exists.
 CmdServer (int sockPort, const char *prompt=">", const char *intro=NULL)
 Constructor.
void init ()
 A method to initialise and start the server.
int send (const char *buf, int nBytes)
void setDebug (bool onOff)
 Enables/disables printing of debug statements for a single object.
void setID (const char *id)
 A method to enable/disable printing of debug statements for the class.
 ~CmdServer ()
 Destructor.

Static Public Member Functions

static void setDebugAll (bool onOff)
 Enables/disables printing of debug statements for the class.

Protected Member Functions

int readLine (int fd, char *buf, int maxBytes)
int readn (int fd, char *buf, int nBytes, int timeOut)

Protected Attributes

std::list< ClientInfo * > clientList
 List of connected clients.
pthread_mutex_t clientListMutex
 List access mutex.
char errMsg [120]
const char * id
 Identifier for debug output.
std::list< ClientInfo
* >::const_iterator 
pos
 List iterator.
pthread_attr_t threadAttr
sched_param threadParam

Static Protected Attributes

static const int SCHED_POLICY = SCHED_RR

Classes

struct  CppOp
 Structure for command list elements.


Member Enumeration Documentation

anonymous enum
 

Enum constants used for 'access' flag.

See also:
addCtlCmd.

Definition at line 30 of file cmd_server.h.


Constructor & Destructor Documentation

CmdServer::CmdServer int  sockPort,
const char *  prompt = ">",
const char *  intro = NULL
 

Constructor.

Parameters:
sockPort The socket port number.
prompt A string sent to the client with each new line.
intro A string sent to the client when it first connects.

Definition at line 34 of file cmd_server.cc.


Member Function Documentation

void CmdServer::addCtlCmd void *  object,
const char *  label,
CmdMeth  statMeth,
int  access = SINGLE
 

Adds a 'control' method to the list of methods recognised as commands by the CmdServer.

The CmdServer calls method 'statMeth' on 'object' whenever it receives the text string 'label' from the client. Access to control methods is restricted. A client must be the 'active controller' to call a control method unless the 'access' flag is set to 'MULTI'. Method statMeth must of course be a static method of object's class and must conform to the typedef above. The return string from statMeth is sent to the client.

Parameters:
object The object that the method applies to. Must be passed explicitly since the method is static.
label A name to associate with the method.
statMeth A pointer to the method to-be-called.
access Method access flag. Either 'SINGLE' active controller only or 'MULTIple' controllers.

Definition at line 71 of file cmd_server.cc.

Referenced by Instrument::add().

void CmdServer::addMonCmd void *  object,
const char *  label,
CmdMeth  statMeth
 

Adds a 'monitor' method to the list of methods recognised as commands by the CmdServer.

Access to monitor methods is unrestricted. Any client may call a monitor method.

Parameters:
object The object that the method applies to. Must be passed explicitly since the method is static.
label A name to associate with the method.
statMeth A pointer to the method to-be-called. CmdServer will call 'statMeth' on 'object' whenever it receives the text string 'label' from the client. Method statMeth must of course be a static method of object's class and must conform to the typedef above. The return string from statMeth is sent to the client.

Definition at line 86 of file cmd_server.cc.

Referenced by Instrument::add().

int BasicTcpServer::readLine int  fd,
char *  buf,
int  maxBytes
[protected, inherited]
 

A method to read a line of text from a socket. The method returns when either a newline character is encountered or the specified maximum number of bytes have been read.

Parameters:
fd The open file descriptor for the socket.
buf A pointer to a buffer large enough to hold the number of bytes to be read.
maxBytes The maximum number of bytes to be read.
Returns:
The (positive) number of bytes read on success, 0 if client has closed the socket connection or a negative number from error codes above.

Definition at line 221 of file server.cc.

int BasicTcpServer::readn int  fd,
char *  buf,
int  nBytes,
int  timeOut
[protected, inherited]
 

A method to read a specified number of bytes from a socket.

Parameters:
fd The open file descriptor for the socket.
buf A pointer to a buffer large enough to hold the number of bytes to be read.
nBytes The number of bytes to be read.
timeout The total allowable time in microseconds to complete the read. Minimum value of timeout is 1 microsec per byte.
Returns:
The (positive) number of bytes read on success, zero if client has closed the socket connection or a negative number from error codes above.

Definition at line 157 of file server.cc.


The documentation for this class was generated from the following files:
Generated on Mon Apr 30 13:32:42 2007 for Parkes M & C - PKMC C++ library API by  doxygen 1.4.4