meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

peerhood:configuration [2011/09/02 12:05] (current)
Line 1: Line 1:
 +====== 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 - [[wiki:​user:​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
 +<​code>​
 +using namespace std;
 +</​code>​
 +Config
 +<​code>​
 +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();
 +
 +}
 +</​code>​
 +<​code>​
 +class Value {
 +  string ToString();
 +  int ToInt();
 +  bool ToBool();
 +}
 +</​code>​
 +usage ..
 +<​code>​
 +Config &cfg = TheConfig::​Instance();​
 +try {
 +  if(cfg.Get("​interwal"​).ToInt() < 14) { .. }
 +} catch(TypeError &e) {
 +  ..
 +}
 +</​code>​
 +
 +
 +TheConfig
 +<​code>​
 +class TheConfig : Config {
 +  static TheConfig* Instance();
 +}
 +</​code>​
 +ConfigStorage
 +<​code>​
 +class ConfigStorage {
 +  void Load();
 +  void Save();
 +  void Reload();
 +  void IsValid();
 +}
 +</​code>​
 +FileConfigStorage
 +<​code>​
 +class FileConfigStorage : ConfigStorage {
 +   ​FileConfigStorage(list<​string>​ &​locations);​
 +}
 +</​code>​
 +
 +===== More =====
 +  * Interprocess configuration could done by [[messaging]] in future.
 +
 +
 +====== Related c++/c configuration systems ======
 +  * [[http://​www.hyperrealm.com/​libconfig/​|libconfig – C/C++ Configuration File Library]]
 +  * [[http://​autogen.sourceforge.net/​autoopts.html|AutoGen'​s Automated Option Processing]]