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

ArNetServer Class Reference

Class for running a simple net server to send/recv commands via text. More...

#include <ArNetServer.h>

List of all members.

Public Member Functions

bool addCommand (const char *command, ArFunctor3< char **, int, ArSocket * > *functor, const char *help)
 Adds a new command.
 ArNetServer (bool addAriaExitCB=true)
 Constructor.
void close (void)
 Closes the server.
const char * getExtraString (void)
 Gets an extra string that the server holds for passing around.
bool getLoggingDataReceived (void)
 Gets whether we are logging all data received or not.
bool getLoggingDataSent (void)
 Gets whether we are logging all data sent or not.
void internalAddSocketToDeleteList (ArSocket *socket)
 The internal function that adds a client to our delete list.
void internalAddSocketToList (ArSocket *socket)
 The internal function that adds a client to our list.
void internalEcho (char **argv, int argc, ArSocket *socket)
 The internal function for echo.
void internalGreeting (ArSocket *socket)
 the internal function that gives the greeting message
void internalHelp (char **argv, int argc, ArSocket *socket)
 The internal function for the help cb.
void internalHelp (ArSocket *socket)
 The internal function that does the help.
void internalQuit (char **argv, int argc, ArSocket *socket)
 The internal function for closing this connection.
void internalShutdownServer (char **argv, int argc, ArSocket *socket)
 The internal function for shutting down.
bool isOpen (void)
 Sees if the server is running and open.
int lock ()
 Lock the server.
bool open (ArRobot *robot, unsigned int port, const char *password, bool multipleClients=true)
 Initializes the server.
void parseCommandOnSocket (ArArgumentBuilder *args, ArSocket *socket, bool allowLog=true)
 The internal function for parsing a command on a socket.
bool remCommand (const char *command)
 Removes a command.
void runOnce (void)
 the internal sync task we use for our loop
void sendToAllClients (const char *str,...)
 Sends the given string to all the clients.
void sendToAllClientsPlain (const char *str)
 Sends the given string to all the clients, no varargs, wrapper for java.
void setExtraString (const char *str)
 Sets an extra string that the server holds for passing around.
void setLoggingDataReceived (bool loggingData)
 Sets whether we are logging all data received or not.
void setLoggingDataSent (bool loggingData)
 Sets whether we are logging all data sent or not.
void squelchNormal (void)
 This squelchs all the normal commands and help.
int tryLock ()
 Try to lock the server without blocking.
int unlock ()
 Unlock the server.
 ~ArNetServer ()
 Destructor.

Protected Attributes

ArFunctorC< ArNetServermyAriaExitCB
std::list< ArSocket * > myConnectingConns
std::list< ArSocket * > myConns
std::list< ArSocket * > myDeleteList
ArFunctor3C< ArNetServer,
char **, int, ArSocket * > 
myEchoCB
std::string myExtraString
std::map< std::string, ArFunctor3<
char **, int, ArSocket * > *,
ArStrCaseCmpOp > 
myFunctorMap
ArFunctor3C< ArNetServer,
char **, int, ArSocket * > 
myHelpCB
std::map< std::string, std::string,
ArStrCaseCmpOp > 
myHelpMap
bool myLoggingDataReceived
bool myLoggingDataSent
bool myMultipleClients
ArMutex myMutex
bool myOpened
std::string myPassword
unsigned int myPort
ArFunctor3C< ArNetServer,
char **, int, ArSocket * > 
myQuitCB
ArRobotmyRobot
ArSocket myServerSocket
ArFunctor3C< ArNetServer,
char **, int, ArSocket * > 
myShutdownServerCB
bool mySquelchNormal
ArFunctorC< ArNetServermyTaskCB
bool myWantToClose


Detailed Description

Class for running a simple net server to send/recv commands via text.

This class is for running a simple net server which will have a list of commands to use and a fairly simple set of interactions... Start the server with the open function, add commands with the addCommand function and remove commands with remCommand, and close the server with the close function.

It has a built in mutex, if you only use sendToAllClients through the normal commands or during the robot loop you don't need to worry about locking anything and the server is locked before any of the callbacks for the commands are called so you really only need to lock the server if you're dealing with it from outside the way.

Definition at line 55 of file ArNetServer.h.


Member Function Documentation

bool ArNetServer::addCommand const char *  command,
ArFunctor3< char **, int, ArSocket * > *  functor,
const char *  help
 

Adds a new command.

This adds a command to the list, when the command is given the broken up argv and argc are given along with the socket it came from (so that acks can occur)

Definition at line 150 of file ArNetServer.cpp.

References ArLog::log().

Referenced by ArNetServer().

bool ArNetServer::getLoggingDataReceived void   ) 
 

Gets whether we are logging all data received or not.

Returns:
if true data will be logged which means that all commands received from clients are logged

Definition at line 255 of file ArNetServer.cpp.

bool ArNetServer::getLoggingDataSent void   ) 
 

Gets whether we are logging all data sent or not.

Returns:
if true data will be logged which means that all data sent out to the all the clients will be logged

Definition at line 237 of file ArNetServer.cpp.

bool ArNetServer::open ArRobot robot,
unsigned int  port,
const char *  password,
bool  multipleClients = true
 

Initializes the server.

Open the server, if you supply a robot this will run in the robots attached, if you do not supply a robot then it will be open and you'll have to call runOnce yourself (this is only recommended for advanced users)

Parameters:
robot the robot that this should be attached to and run in the sync task of or NULL not to run in any robot's task
port the port to start up the service on
password the password needed to use the service
multipleClients if false only one client is allowed to connect, if false multiple clients are allowed to connect or just one
Returns:
true if the server could be started, false otherwise

Definition at line 96 of file ArNetServer.cpp.

References ArSyncTask::addNewLeaf(), ArSyncTask::findNonRecursive(), ArSocket::getErrorStr(), ArRobot::getSyncTaskRoot(), ArLog::log(), ArSocket::open(), ArSocket::setLinger(), and ArSocket::setNonBlock().

bool ArNetServer::remCommand const char *  command  ) 
 

Removes a command.

Parameters:
command the command to remove
Returns:
true if the command was there to remove, false otherwise

Definition at line 171 of file ArNetServer.cpp.

Referenced by squelchNormal().

void ArNetServer::sendToAllClients const char *  str,
  ...
 

Sends the given string to all the clients.

This sends the given string to all the clients, this string cannot be more than 2048 number of bytes

Definition at line 201 of file ArNetServer.cpp.

References sendToAllClientsPlain().

Referenced by close(), and internalShutdownServer().

void ArNetServer::setLoggingDataReceived bool  loggingData  ) 
 

Sets whether we are logging all data received or not.

Parameters:
loggingData if true data will be logged which means that all commands received from clients are logged

Definition at line 246 of file ArNetServer.cpp.

void ArNetServer::setLoggingDataSent bool  loggingData  ) 
 

Sets whether we are logging all data sent or not.

Parameters:
loggingData if true data will be logged which means that all data sent out to the all the clients will be logged

Definition at line 223 of file ArNetServer.cpp.


The documentation for this class was generated from the following files:
Generated on Wed Oct 19 12:56:51 2005 for Aria by  doxygen 1.4.0