Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

ArServerHandlerConfig Class Reference

ArServerHandlerConfig defines the network packet handlers used to transmit ArConfig objects to a client, and to modify them based on information received from the client. More...

#include <ArServerHandlerConfig.h>

List of all members.

Public Member Functions

void addConfigUpdatedCallback (ArFunctor *functor, ArListPos::Pos position=ArListPos::LAST)
 Adds a callback to be called when the config is updated.
void addPostWriteCallback (ArFunctor *functor, ArListPos::Pos position=ArListPos::LAST)
 Adds a callback to be called after writing to disk.
void addPreWriteCallback (ArFunctor *functor, ArListPos::Pos position=ArListPos::LAST)
 Adds a callback to be called before writing to disk.
 ArServerHandlerConfig (ArServerBase *server, ArConfig *config, const char *defaultFile=NULL, const char *defaultFileBaseDirectory=NULL)
bool configUpdated (ArServerClient *client=NULL)
 Notifies the clients that the config was updated.
void createEmptyConfigDefaults (void)
 Creates an empty default config...
void getConfig (ArServerClient *client, ArNetPacket *packet)
 Handles the (deprecated) "getConfig" request.
void getConfigBySections (ArServerClient *client, ArNetPacket *packet)
 Handles the "getConfigBySections" request.
void getConfigDefaults (ArServerClient *client, ArNetPacket *packet)
 Handles the "getConfigDefaults" request.
void getConfigSectionFlags (ArServerClient *client, ArNetPacket *packet)
 Handles the "getConfigSectionFlags" request.
bool loadDefaultsFromFile (void)
 loads the whole of a default file (for internal use)
bool loadDefaultsFromPacket (ArNetPacket *packet)
 Parses a line of the default config (for internal use).
int lockConfig (void)
 Locks the config so we don't do anything with it.
void reloadConfig (ArServerClient *client, ArNetPacket *packet)
 Handles the "reloadConfig" request.
void remConfigUpdatedCallback (ArFunctor *functor)
 Removes a callback to be called when the config is updated.
void remPostWriteCallback (ArFunctor *functor)
 Removes a callback to be called after writing to disk.
void remPreWriteCallback (ArFunctor *functor)
 Removes a callback to be called before writing to disk.
void setConfig (ArServerClient *client, ArNetPacket *packet)
 Handles the "setConfig" request.
int tryLockConfig (void)
 Tries to lock the config so we don't do anything with it.
int unlockConfig (void)
 Unlocks the config so we can use it again.
bool writeConfig (void)
 Writes the config out.
virtual ~ArServerHandlerConfig ()
 Destructor.

Protected Member Functions

void addDefaultServerCommands (void)
 Adds the default config callbacks;.
void createDefaultConfig (const char *defaultFileBaseDir)
 just creates the default config... (internal, don't use)
void handleGetConfig (ArServerClient *client, ArNetPacket *packet, bool isMultiplePackets)
 Helper method for getConfigBySections and getConfig.
bool internalSetConfig (ArServerClient *client, ArNetPacket *packet)
 Internal method that handles a setConfig packet for myConfig or myDefaults.

Protected Attributes

bool myAddedDefaultServerCommands
ArConfigmyConfig
ArMutex myConfigMutex
std::list< ArFunctor * > myConfigUpdatedCallbacks
ArConfigmyDefault
ArMutex myDefaultConfigMutex
std::string myDefaultFile
std::string myDefaultFileBaseDir
ArFunctor2C< ArServerHandlerConfig,
ArServerClient *, ArNetPacket * > 
myGetConfigBySectionsCB
ArFunctor2C< ArServerHandlerConfig,
ArServerClient *, ArNetPacket * > 
myGetConfigCB
ArFunctor2C< ArServerHandlerConfig,
ArServerClient *, ArNetPacket * > 
myGetConfigDefaultsCB
ArFunctor2C< ArServerHandlerConfig,
ArServerClient *, ArNetPacket * > 
myGetConfigSectionFlagsCB
std::list< ArFunctor * > myPostWriteCallbacks
std::list< ArFunctor * > myPreWriteCallbacks
ArFunctor2C< ArServerHandlerConfig,
ArServerClient *, ArNetPacket * > 
myReloadConfigCB
ArServerBasemyServer
ArFunctor2C< ArServerHandlerConfig,
ArServerClient *, ArNetPacket * > 
mySetConfigCB


Detailed Description

ArServerHandlerConfig defines the network packet handlers used to transmit ArConfig objects to a client, and to modify them based on information received from the client.

Since the packet structure for the ArConfig is rather complex, this class is best used in conjunction with the ArClientHandlerConfig.

This class handles the following requests:

If you are using this class with the default file option you'll want to make it AFTER you're done adding things to the config, ie last, so that the default code can work correctly (it needs to know about all the info).

Definition at line 108 of file ArServerHandlerConfig.h.


Constructor & Destructor Documentation

ArServerHandlerConfig::ArServerHandlerConfig ArServerBase server,
ArConfig config,
const char *  defaultFile = NULL,
const char *  defaultFileBaseDirectory = NULL
 

Parameters:
server the ArServerBase * used to send and receive network packets; must be non-NULL
config the ArConfig * that is maintained by this server handler
defaultFile the char * name of the file that contains the default values for the ArConfig; if NULL, then getConfigDefaults will not be supported
defaultFileBaseDirectory the char * name of the directory that contains the default file

Definition at line 43 of file ArServerHandlerConfig.cpp.

References ArServerBase::addData(), loadDefaultsFromFile(), myDefaultFile, myDefaultFileBaseDir, myGetConfigBySectionsCB, myGetConfigCB, myGetConfigSectionFlagsCB, myReloadConfigCB, myServer, and mySetConfigCB.

ArServerHandlerConfig::~ArServerHandlerConfig  )  [virtual]
 

Destructor.

Definition at line 106 of file ArServerHandlerConfig.cpp.


Member Function Documentation

void ArServerHandlerConfig::addConfigUpdatedCallback ArFunctor functor,
ArListPos::Pos  position = ArListPos::LAST
 

Adds a callback to be called when the config is updated.

Definition at line 653 of file ArServerHandlerConfig.cpp.

References ArLog::log(), and myConfigUpdatedCallbacks.

void ArServerHandlerConfig::addDefaultServerCommands void   )  [protected]
 

Adds the default config callbacks;.

Definition at line 273 of file ArServerHandlerConfig.cpp.

References ArServerBase::addData(), myAddedDefaultServerCommands, myGetConfigDefaultsCB, and myServer.

Referenced by createEmptyConfigDefaults(), loadDefaultsFromFile(), and loadDefaultsFromPacket().

void ArServerHandlerConfig::addPostWriteCallback ArFunctor functor,
ArListPos::Pos  position = ArListPos::LAST
 

Adds a callback to be called after writing to disk.

Definition at line 635 of file ArServerHandlerConfig.cpp.

References ArLog::log(), and myPostWriteCallbacks.

void ArServerHandlerConfig::addPreWriteCallback ArFunctor functor,
ArListPos::Pos  position = ArListPos::LAST
 

Adds a callback to be called before writing to disk.

Definition at line 617 of file ArServerHandlerConfig.cpp.

References ArLog::log(), and myPreWriteCallbacks.

bool ArServerHandlerConfig::configUpdated ArServerClient client = NULL  ) 
 

Notifies the clients that the config was updated.

Definition at line 704 of file ArServerHandlerConfig.cpp.

References ArServerBase::broadcastPacketTcpWithExclusion(), client, myConfigUpdatedCallbacks, and myServer.

Referenced by internalSetConfig(), and reloadConfig().

void ArServerHandlerConfig::createDefaultConfig const char *  defaultFileBaseDir  )  [protected]
 

just creates the default config... (internal, don't use)

For internal use only.

doesn't delete the old one, do that if you're going to call this yourself and make sure you lock around all that

Definition at line 201 of file ArServerHandlerConfig.cpp.

References ArConfig::addParam(), ArConfigArg::getBool(), ArConfigArg::getConfigPriority(), ArConfigArg::getDescription(), ArConfigArg::getDisplayHint(), ArConfigArg::getDouble(), ArConfigArg::getInt(), ArConfigArg::getMaxDouble(), ArConfigArg::getMaxInt(), ArConfigArg::getMinDouble(), ArConfigArg::getMinInt(), ArConfigSection::getName(), ArConfigArg::getName(), ArConfigSection::getParams(), ArConfig::getSections(), ArConfigArg::getString(), ArConfigArg::getType(), myConfig, and myDefault.

Referenced by loadDefaultsFromFile(), and loadDefaultsFromPacket().

void ArServerHandlerConfig::createEmptyConfigDefaults void   ) 
 

Creates an empty default config...

Definition at line 180 of file ArServerHandlerConfig.cpp.

References addDefaultServerCommands(), ArServerBase::broadcastPacketTcp(), lockConfig(), myDefault, myServer, and unlockConfig().

void ArServerHandlerConfig::getConfig ArServerClient client,
ArNetPacket packet
 

Handles the (deprecated) "getConfig" request.

Definition at line 409 of file ArServerHandlerConfig.cpp.

References client, and handleGetConfig().

void ArServerHandlerConfig::getConfigBySections ArServerClient client,
ArNetPacket packet
 

Handles the "getConfigBySections" request.

Definition at line 400 of file ArServerHandlerConfig.cpp.

References client, and handleGetConfig().

void ArServerHandlerConfig::getConfigDefaults ArServerClient client,
ArNetPacket packet
 

Handles the "getConfigDefaults" request.

Definition at line 544 of file ArServerHandlerConfig.cpp.

References ArClientArg::argTextToBuf(), client, ArConfigArg::getName(), ArConfigSection::getName(), ArConfigSection::getParams(), ArConfig::getSections(), ArClientArg::isSendableParamType(), ArMutex::lock(), ArLog::log(), myConfigMutex, myDefault, ArClientBase::sendPacketTcp(), ArBasePacket::strToBuf(), and ArMutex::unlock().

void ArServerHandlerConfig::getConfigSectionFlags ArServerClient client,
ArNetPacket packet
 

Handles the "getConfigSectionFlags" request.

Definition at line 723 of file ArServerHandlerConfig.cpp.

References ArBasePacket::byte4ToBuf(), client, ArConfigSection::getFlags(), ArConfigSection::getName(), ArConfig::getSections(), ArLog::log(), myConfig, ArClientBase::sendPacketTcp(), and ArBasePacket::strToBuf().

void ArServerHandlerConfig::handleGetConfig ArServerClient client,
ArNetPacket packet,
bool  isMultiplePackets
[protected]
 

Helper method for getConfigBySections and getConfig.

Definition at line 290 of file ArServerHandlerConfig.cpp.

References ArBasePacket::byteToBuf(), client, ArClientArg::createPacket(), ArNetPacket::empty(), ArConfigSection::getComment(), ArConfigArg::getName(), ArConfigSection::getName(), ArConfigSection::getParams(), ArConfig::getSections(), ArConfigArg::getType(), ArClientArg::isSendableParamType(), ArBasePacket::isValid(), ArLog::log(), myConfig, ArClientBase::sendPacketTcp(), and ArBasePacket::strToBuf().

Referenced by getConfig(), and getConfigBySections().

bool ArServerHandlerConfig::internalSetConfig ArServerClient client,
ArNetPacket packet
[protected]
 

Internal method that handles a setConfig packet for myConfig or myDefaults.

Parameters:
client If client is NULL it means use the default config

Definition at line 430 of file ArServerHandlerConfig.cpp.

References ArArgumentBuilder::add(), ArConfig::callProcessFileCallBacks(), client, configUpdated(), lockConfig(), ArLog::log(), myConfig, myDefault, ArConfig::parseArgument(), ArConfig::parseSection(), ArClientBase::sendPacketTcp(), ArArgumentBuilder::setExtraString(), ArBasePacket::strToBuf(), unlockConfig(), and writeConfig().

Referenced by loadDefaultsFromPacket(), and setConfig().

bool ArServerHandlerConfig::loadDefaultsFromFile void   ) 
 

loads the whole of a default file (for internal use)

Definition at line 111 of file ArServerHandlerConfig.cpp.

References addDefaultServerCommands(), ArServerBase::broadcastPacketTcp(), ArConfig::clearAllValueSet(), createDefaultConfig(), lockConfig(), ArLog::log(), myDefault, myDefaultFile, myDefaultFileBaseDir, myServer, ArConfig::parseFile(), ArConfig::removeAllUnsetValues(), and unlockConfig().

Referenced by ArServerHandlerConfig().

bool ArServerHandlerConfig::loadDefaultsFromPacket ArNetPacket packet  ) 
 

Parses a line of the default config (for internal use).

Definition at line 147 of file ArServerHandlerConfig.cpp.

References addDefaultServerCommands(), ArServerBase::broadcastPacketTcp(), ArConfig::clearAllValueSet(), createDefaultConfig(), internalSetConfig(), lockConfig(), ArLog::log(), myDefault, myServer, ArConfig::removeAllUnsetValues(), and unlockConfig().

int ArServerHandlerConfig::lockConfig void   )  [inline]
 

Locks the config so we don't do anything with it.

Definition at line 177 of file ArServerHandlerConfig.h.

References ArMutex::lock(), and myConfigMutex.

Referenced by createEmptyConfigDefaults(), internalSetConfig(), loadDefaultsFromFile(), and loadDefaultsFromPacket().

void ArServerHandlerConfig::reloadConfig ArServerClient client,
ArNetPacket packet
 

Handles the "reloadConfig" request.

Definition at line 537 of file ArServerHandlerConfig.cpp.

References configUpdated(), ArConfig::getFileName(), myConfig, and ArConfig::parseFile().

void ArServerHandlerConfig::remConfigUpdatedCallback ArFunctor functor  ) 
 

Removes a callback to be called when the config is updated.

Definition at line 665 of file ArServerHandlerConfig.cpp.

References myConfigUpdatedCallbacks.

void ArServerHandlerConfig::remPostWriteCallback ArFunctor functor  ) 
 

Removes a callback to be called after writing to disk.

Definition at line 647 of file ArServerHandlerConfig.cpp.

References myPostWriteCallbacks.

void ArServerHandlerConfig::remPreWriteCallback ArFunctor functor  ) 
 

Removes a callback to be called before writing to disk.

Definition at line 629 of file ArServerHandlerConfig.cpp.

References myPreWriteCallbacks.

void ArServerHandlerConfig::setConfig ArServerClient client,
ArNetPacket packet
 

Handles the "setConfig" request.

Definition at line 420 of file ArServerHandlerConfig.cpp.

References client, and internalSetConfig().

int ArServerHandlerConfig::tryLockConfig void   )  [inline]
 

Tries to lock the config so we don't do anything with it.

Definition at line 179 of file ArServerHandlerConfig.h.

References myConfigMutex, and ArMutex::tryLock().

int ArServerHandlerConfig::unlockConfig void   )  [inline]
 

Unlocks the config so we can use it again.

Definition at line 181 of file ArServerHandlerConfig.h.

References myConfigMutex, and ArMutex::unlock().

Referenced by createEmptyConfigDefaults(), internalSetConfig(), loadDefaultsFromFile(), and loadDefaultsFromPacket().

bool ArServerHandlerConfig::writeConfig void   ) 
 

Writes the config out.

Definition at line 671 of file ArServerHandlerConfig.cpp.

References ArConfig::getFileName(), ArLog::log(), myConfig, myPostWriteCallbacks, myPreWriteCallbacks, and ArConfig::writeFile().

Referenced by internalSetConfig().


Member Data Documentation

bool ArServerHandlerConfig::myAddedDefaultServerCommands [protected]
 

Definition at line 219 of file ArServerHandlerConfig.h.

Referenced by addDefaultServerCommands().

ArConfig* ArServerHandlerConfig::myConfig [protected]
 

Definition at line 212 of file ArServerHandlerConfig.h.

Referenced by createDefaultConfig(), getConfigSectionFlags(), handleGetConfig(), internalSetConfig(), reloadConfig(), and writeConfig().

ArMutex ArServerHandlerConfig::myConfigMutex [protected]
 

Definition at line 221 of file ArServerHandlerConfig.h.

Referenced by getConfigDefaults(), lockConfig(), tryLockConfig(), and unlockConfig().

std::list<ArFunctor *> ArServerHandlerConfig::myConfigUpdatedCallbacks [protected]
 

Definition at line 225 of file ArServerHandlerConfig.h.

Referenced by addConfigUpdatedCallback(), configUpdated(), and remConfigUpdatedCallback().

ArConfig* ArServerHandlerConfig::myDefault [protected]
 

Definition at line 215 of file ArServerHandlerConfig.h.

Referenced by createDefaultConfig(), createEmptyConfigDefaults(), getConfigDefaults(), internalSetConfig(), loadDefaultsFromFile(), and loadDefaultsFromPacket().

ArMutex ArServerHandlerConfig::myDefaultConfigMutex [protected]
 

Definition at line 218 of file ArServerHandlerConfig.h.

std::string ArServerHandlerConfig::myDefaultFile [protected]
 

Definition at line 216 of file ArServerHandlerConfig.h.

Referenced by ArServerHandlerConfig(), and loadDefaultsFromFile().

std::string ArServerHandlerConfig::myDefaultFileBaseDir [protected]
 

Definition at line 217 of file ArServerHandlerConfig.h.

Referenced by ArServerHandlerConfig(), and loadDefaultsFromFile().

ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myGetConfigBySectionsCB [protected]
 

Definition at line 227 of file ArServerHandlerConfig.h.

Referenced by ArServerHandlerConfig().

ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myGetConfigCB [protected]
 

Definition at line 228 of file ArServerHandlerConfig.h.

Referenced by ArServerHandlerConfig().

ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myGetConfigDefaultsCB [protected]
 

Definition at line 231 of file ArServerHandlerConfig.h.

Referenced by addDefaultServerCommands().

ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myGetConfigSectionFlagsCB [protected]
 

Definition at line 232 of file ArServerHandlerConfig.h.

Referenced by ArServerHandlerConfig().

std::list<ArFunctor *> ArServerHandlerConfig::myPostWriteCallbacks [protected]
 

Definition at line 224 of file ArServerHandlerConfig.h.

Referenced by addPostWriteCallback(), remPostWriteCallback(), and writeConfig().

std::list<ArFunctor *> ArServerHandlerConfig::myPreWriteCallbacks [protected]
 

Definition at line 223 of file ArServerHandlerConfig.h.

Referenced by addPreWriteCallback(), remPreWriteCallback(), and writeConfig().

ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myReloadConfigCB [protected]
 

Definition at line 230 of file ArServerHandlerConfig.h.

Referenced by ArServerHandlerConfig().

ArServerBase* ArServerHandlerConfig::myServer [protected]
 

Definition at line 211 of file ArServerHandlerConfig.h.

Referenced by addDefaultServerCommands(), ArServerHandlerConfig(), configUpdated(), createEmptyConfigDefaults(), loadDefaultsFromFile(), and loadDefaultsFromPacket().

ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::mySetConfigCB [protected]
 

Definition at line 229 of file ArServerHandlerConfig.h.

Referenced by ArServerHandlerConfig().


The documentation for this class was generated from the following files:
Generated on Tue Feb 20 10:51:51 2007 for ArNetworking by  doxygen 1.4.0