meta data for this page
PeerHood configuration class
In module libpeerhood/
Objectives
- Provides key (name) - value pairs.
- Values could be defined.
- Separation of configuration data usage and storage.
- Location independence.
- Dynamic configuration [future].
- Thread safety.
Functionalities
- Configuration instances and access.
- Configuration interface.
- Configuration information sources: files, command line paramerts, environment variables.
- Configuration file locations.
- Configuration file syntax [future]
- Configuration schema (type, description for name-value) [future, phase2, msc thesis]
PeerHood uses local unix socket to communicate with local clients, clients could set&get configuration parameters through the local socket? Then the instance of configuration class should be owned and invoked only by PeerHood daemon. Requires adding some new opcodes into libpeerhood/pdu.h, variable containing opcodes when sending to clients is a 8-bit integer → plenty of “space” for new codes. Or is it a more sophisticated way (easier to maintain) to implement configurator as a service which is provided by daemon? Might cause overhead: request service → get service → use service - julaakko yes, but future task.
- Error management: key not found, incorrect type, not required key provided, …
Current situation
Configuration mechanism is spread out and hardcoded over the code. No configuration object instances at the moment, but load-style approach.
Design
Dependencies
using namespace std;
Config
class Config { // string ??? static const char* STRING = "string"; static const char* INT = "int"; static const char* BOOL = "bool"; static const char* REQUIRED = "REQUIRED"; string Define(const char* key,const char* default_value,const char* type, const char* desc); string Get(const char* key); string Get(string key); Value Get(const char* key); string Set(string key,string value); // clumsy usage, but flexible usage would require 4 functions for const char and string combinations. string Type(string key); void Load(); void Save(); void Reload(); void IsValid(); }
class Value { string ToString(); int ToInt(); bool ToBool(); }
usage ..
Config &cfg = TheConfig::Instance(); try { if(cfg.Get("interwal").ToInt() < 14) { .. } } catch(TypeError &e) { .. }
TheConfig
class TheConfig : Config { static TheConfig* Instance(); }
ConfigStorage
class ConfigStorage { void Load(); void Save(); void Reload(); void IsValid(); }
FileConfigStorage
class FileConfigStorage : ConfigStorage { FileConfigStorage(list<string> &locations); }
More
- Interprocess configuration could done by messaging in future.