Lumiera  0.pre.03
»edit your freedom«
configfacade.cpp
Go to the documentation of this file.
1 /*
2  ConfigFacade - C++ convenience wrapper and startup of the config system
3 
4  Copyright (C)
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
14 
33 #include "include/logging.h"
34 #include "include/lifecycle.h"
35 #include "include/config-facade.h"
36 #include "common/appstate.hpp"
37 #include "lib/searchpath.hpp"
38 #include "lib/util.hpp"
39 
40 extern "C" {
41  #include "common/config.h"
42 }
43 
44 
50 #define KEY_CONFIG_PATH "Lumiera.configpath"
51 
57 #define KEY_PLUGIN_PATH "Lumiera.modulepath"
58 
59 
60 
61 
62 namespace lumiera {
63 
64  using util::isnil;
65  using lib::Literal;
66 
67 
70 
71 
72  namespace {
73 
74  void
75  pull_up_ConfigSystem ()
76  {
77  TRACE (common, "booting up config system");
79  }
80 
81  LifecycleHook trigger__ (ON_BASIC_INIT, &pull_up_ConfigSystem);
82  }
83 
84 
85 
86 
87  Config::Config ()
88  {
89  string extendedConfigSearchPath = AppState::instance().fetchSetupValue (KEY_CONFIG_PATH);
90  lumiera_config_init (cStr(extendedConfigSearchPath));
91  TRACE (config, "Config system ready.");
92  }
93 
94 
95  Config::~Config()
96  {
98  TRACE (config, "config system closed.");
99  }
100 
101 
102 
106  string
108  {
109  string value = AppState::instance().fetchSetupValue (key);
110  if (isnil (value))
111  throw error::Config ("Configuration value for key=\""+key+"\" is missing");
112 
113  return value;
114  }
115 
116 
117 
118 } // namespace lumiera
119 
120 
121 extern "C" { /* ==== implementation C interface for accessing setup.ini ======= */
122 
123 
124  using std::string;
125  using lumiera::Config;
127  using util::isnil;
128 
129 
130 
131  const char*
132  lumiera_get_plugin_path_default ()
133  {
134  static string pathSpec;
135  if (isnil (pathSpec))
136  {
137  pathSpec += "plugin.path="; // syntax expected by lumiera_config_setdefault
138 
139  // fetch plugin search path from setup.ini and expand any $ORIGIN token
141  while (pathElement)
142  pathSpec += pathElement.next() +":";
143  }
144 
145  return cStr(pathSpec);
146  }
147 }
const char * ON_BASIC_INIT
automatic static init. treated specially to run as soon as possible
Installing and invoking of application lifecycle event callbacks.
Helpers to handle directory search paths.
CStr cStr(std::string const &rendered)
convenience shortcut: forced conversion to c-String via string.
Definition: symbol.hpp:59
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:76
Interface for a lumiera configuration system (draft).
This header is for including and configuring NoBug.
Access point to singletons and other kinds of dependencies designated by type.
Definition: depend.hpp:280
static string get(lib::Literal key)
#define KEY_CONFIG_PATH
key to fetch the search path for extended configuration.
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
The lumiera::Config wrapper class addresses two issues.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
define and register a callback for a specific lifecycle event.
Definition: lifecycle.h:67
C++ wrapper for convenient access to the Lumiera config system.
Definition: config-facade.h:64
void lumiera_config_destroy()
Destroys the configuration subsystem.
Definition: config.c:105
Registering and managing primary application-global services.
Helper: Access a path Specification as a sequence of filesystem Paths.
Definition: searchpath.hpp:62
Lumiera public interface.
Definition: advice.cpp:104
#define KEY_PLUGIN_PATH
Similarly, this key is used to fetch the configured default plugin/module search path from the basic ...
int lumiera_config_init(const char *path)
Initialise the configuration subsystem.
Definition: config.c:77
static lib::Depend< AppState > instance
get the (single) AppState instance.
Definition: appstate.hpp:74
static lib::Depend< Config > instance
storage and setup for the single system-wide config facade instance
Definition: config-facade.h:69