ArNetworking: ArServerHandlerConfig Class Reference

- Main Page
- Classes
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# ArServerHandlerConfig Class Reference

`#include <ArServerHandlerConfig.h>`

List of all members.

## Detailed Description

Class for sending and receiving ArConfig data via ArNetworking.

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:

- getConfigBySections: Replies with multiple packets, one for each ArConfig section plus an empty packet that terminates the reply. Each packet contains the following header information:
  1. Section Indicator: Always set to 'S' (byte)
  2. Section Name: (string)
  3. Section Comment: (string)
  For each parameter in the section, the packet then contains a a Parameter Indicator (always set to 'P' (byte)) followed by a complete description of the parameter (display hints are included). See ArClientArgUtils for more information.
- getConfig: This request has been superceded by getConfigBySections. (It replies with a single packet containing all of the ArConfig sections as described above. If the ArConfig is large, then it may not be sent successfully. In addition, it contains no parameter display hints.)
- setConfig: Parses the received packet and updates the robot's ArConfig (and saves it to the file). For each modified section, the received packet is expected to contain:
  1. Section Indicator: Always set to "Section" (string)
  2. Section Name: (string)
  Followed by a brief "text" description of each modified parameter. This is the parameter name (string) followed by the parameter value formatted as text (string). See ArClientArgUtils for more information.

  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.

- reloadConfig: Reloads the ArConfig from the text file.
- configUpdated: An empty packet is broadcast to all interested clients after setConfig or reloadConfig has been completed. The clients may then request the modified ArConfig data with getConfigBySections (or getConfig).
- getConfigDefaults: If a "default" configuration file is available, then this command can be used to send the preferred default values to the client. The received packet should contain a single string, which is the name of the section to be retrieved, or an empty string to indicate all sections.

  For each requested section, the reply packet contains:

  1. Section Indicator: Always set to "Section" (string)
  2. Section Name: (string)
  Followed by a brief "text" description of each default parameter value. This is the parameter name (string) followed by the parameter value formatted as text (string). See ArClientArgUtils for more information.

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

## Constructor & Destructor Documentation

ArServerHandlerConfig::ArServerHandlerConfig | ( | ArServerBase * | server,
|  | ArConfig * | config,
|  | const char * | defaultFile = `NULL`,
|  | const char * | defaultFileBaseDirectory = `NULL` |
| ) |  |  |

Constructor.

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

## Member Function Documentation

bool ArServerHandlerConfig::internalSetConfig | ( | ArServerClient * | client,
|  | ArNetPacket * | packet |
| ) |  |  | `[protected]`

Internal method that handles a setConfig packet for myConfig or myDefaults

The documentation for this class was generated from the following file:

- ArServerHandlerConfig.h