#include <ArServerHandlerConfig.h>
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) | |
| 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) |
| Internal method that handles a setConfig packet for myConfig or myDefaults. | |
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 | |||
| ) |
| 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 |
| ArServerHandlerConfig::~ArServerHandlerConfig | ( | ) | [virtual] |
Destructor.
| void ArServerHandlerConfig::addConfigUpdatedCallback | ( | ArFunctor * | functor, | |
| ArListPos::Pos | position = ArListPos::LAST | |||
| ) |
Adds a callback to be called when the config is updated.
| void ArServerHandlerConfig::addDefaultServerCommands | ( | void | ) | [protected] |
Adds the default config callbacks;.
| void ArServerHandlerConfig::addPostWriteCallback | ( | ArFunctor * | functor, | |
| ArListPos::Pos | position = ArListPos::LAST | |||
| ) |
Adds a callback to be called after writing to disk.
| void ArServerHandlerConfig::addPreWriteCallback | ( | ArFunctor * | functor, | |
| ArListPos::Pos | position = ArListPos::LAST | |||
| ) |
Adds a callback to be called before writing to disk.
| bool ArServerHandlerConfig::configUpdated | ( | ArServerClient * | client = NULL |
) |
Notifies the clients that the config was updated.
| 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 (okay, it deletes it now, but the stuff that calls it should still take care of it)
| void ArServerHandlerConfig::createEmptyConfigDefaults | ( | void | ) |
Creates an empty default config...
| void ArServerHandlerConfig::getConfig | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) |
Handles the (deprecated) "getConfig" request.
| void ArServerHandlerConfig::getConfigBySections | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) |
Handles the "getConfigBySections" request.
| void ArServerHandlerConfig::getConfigDefaults | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) |
Handles the "getConfigDefaults" request.
| void ArServerHandlerConfig::getConfigSectionFlags | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) |
Handles the "getConfigSectionFlags" request.
| void ArServerHandlerConfig::handleGetConfig | ( | ArServerClient * | client, | |
| ArNetPacket * | packet, | |||
| bool | isMultiplePackets, | |||
| ArPriority::Priority | lastPriority | |||
| ) | [protected] |
Helper method for getConfigBySections and getConfig.
| client | the ArServerClient * to which to send the config | |
| packet | the ArNetPacket * which accompanied the client's request | |
| isMultiplePackets | a bool set to true if the server should send a packet for each config section followed by the empty packet; false if the server should send the entire config in one packet (i.e. the old style) | |
| lastPriority | the last ArPriority::Priority that should be sent to the client (this is the greatest numerical value and the least semantic priority). |
| bool ArServerHandlerConfig::internalSetConfig | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) | [protected] |
Internal method that handles a setConfig packet for myConfig or myDefaults.
| client | If client is NULL it means use the default config | |
| packet | request packet containing config options |
| bool ArServerHandlerConfig::loadDefaultsFromFile | ( | void | ) |
loads the whole of a default file (for internal use)
| bool ArServerHandlerConfig::loadDefaultsFromPacket | ( | ArNetPacket * | packet | ) |
Parses a line of the default config (for internal use).
| int ArServerHandlerConfig::lockConfig | ( | void | ) | [inline] |
Locks the config so we don't do anything with it.
| void ArServerHandlerConfig::reloadConfig | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) |
Handles the "reloadConfig" request.
| void ArServerHandlerConfig::remConfigUpdatedCallback | ( | ArFunctor * | functor | ) |
Removes a callback to be called when the config is updated.
| void ArServerHandlerConfig::remPostWriteCallback | ( | ArFunctor * | functor | ) |
Removes a callback to be called after writing to disk.
| void ArServerHandlerConfig::remPreWriteCallback | ( | ArFunctor * | functor | ) |
Removes a callback to be called before writing to disk.
| void ArServerHandlerConfig::setConfig | ( | ArServerClient * | client, | |
| ArNetPacket * | packet | |||
| ) |
Handles the "setConfig" request.
| int ArServerHandlerConfig::tryLockConfig | ( | void | ) | [inline] |
Tries to lock the config so we don't do anything with it.
| int ArServerHandlerConfig::unlockConfig | ( | void | ) | [inline] |
Unlocks the config so we can use it again.
| bool ArServerHandlerConfig::writeConfig | ( | void | ) |
Writes the config out.
bool ArServerHandlerConfig::myAddedDefaultServerCommands [protected] |
ArConfig* ArServerHandlerConfig::myConfig [protected] |
ArMutex ArServerHandlerConfig::myConfigMutex [protected] |
std::list<ArFunctor *> ArServerHandlerConfig::myConfigUpdatedCallbacks [protected] |
ArConfig* ArServerHandlerConfig::myDefault [protected] |
ArMutex ArServerHandlerConfig::myDefaultConfigMutex [protected] |
std::string ArServerHandlerConfig::myDefaultFile [protected] |
std::string ArServerHandlerConfig::myDefaultFileBaseDir [protected] |
ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myGetConfigBySectionsCB [protected] |
ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myGetConfigCB [protected] |
ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myGetConfigDefaultsCB [protected] |
ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myGetConfigSectionFlagsCB [protected] |
std::list<ArFunctor *> ArServerHandlerConfig::myPostWriteCallbacks [protected] |
std::list<ArFunctor *> ArServerHandlerConfig::myPreWriteCallbacks [protected] |
ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::myReloadConfigCB [protected] |
ArServerBase* ArServerHandlerConfig::myServer [protected] |
ArFunctor2C<ArServerHandlerConfig, ArServerClient*, ArNetPacket *> ArServerHandlerConfig::mySetConfigCB [protected] |
1.4.7