#include <ArServerHandlerConfig.h>
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:
A reply packet containing a string is sent to the client. If the string is empty, then the config was successfully updated. Otherwise, the string contains the name of the first parameter that caused an error during the update handling.
For each requested section, the reply packet contains:
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).
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) | |
Constructor. | |
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, ArPriority::Priority lastPriority) |
Helper method for getConfigBySections and getConfig. | |
bool | internalSetConfig (ArServerClient *client, ArNetPacket *packet) |
Protected Attributes | |
bool | myAddedDefaultServerCommands |
ArConfig * | myConfig |
ArMutex | myConfigMutex |
std::list< ArFunctor * > | myConfigUpdatedCallbacks |
ArConfig * | myDefault |
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 |
ArServerBase * | myServer |
ArFunctor2C< ArServerHandlerConfig, ArServerClient *, ArNetPacket * > | mySetConfigCB |
ArServerHandlerConfig::ArServerHandlerConfig | ( | ArServerBase * | server, | |
ArConfig * | config, | |||
const char * | defaultFile = NULL , |
|||
const char * | defaultFileBaseDirectory = NULL | |||
) |
Constructor.
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 |
bool ArServerHandlerConfig::internalSetConfig | ( | ArServerClient * | client, | |
ArNetPacket * | packet | |||
) | [protected] |
Internal method that handles a setConfig packet for myConfig or myDefaults