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) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
42 #include "include/logging.h"
43 #include "include/lifecycle.h"
44 #include "include/config-facade.h"
45 #include "common/appstate.hpp"
46 #include "lib/searchpath.hpp"
47 #include "lib/util.hpp"
48 
49 extern "C" {
50  #include "common/config.h"
51 }
52 
53 
59 #define KEY_CONFIG_PATH "Lumiera.configpath"
60 
66 #define KEY_PLUGIN_PATH "Lumiera.modulepath"
67 
68 
69 
70 
71 namespace lumiera {
72 
73  using util::isnil;
74  using lib::Literal;
75 
76 
79 
80 
81  namespace {
82 
83  void
84  pull_up_ConfigSystem ()
85  {
86  TRACE (common, "booting up config system");
88  }
89 
90  LifecycleHook trigger__ (ON_BASIC_INIT, &pull_up_ConfigSystem);
91  }
92 
93 
94 
95 
96  Config::Config ()
97  {
98  string extendedConfigSearchPath = AppState::instance().fetchSetupValue (KEY_CONFIG_PATH);
99  lumiera_config_init (cStr(extendedConfigSearchPath));
100  TRACE (config, "Config system ready.");
101  }
102 
103 
104  Config::~Config()
105  {
107  TRACE (config, "config system closed.");
108  }
109 
110 
111 
115  string
117  {
118  string value = AppState::instance().fetchSetupValue (key);
119  if (isnil (value))
120  throw error::Config ("Configuration value for key=\""+key+"\" is missing");
121 
122  return value;
123  }
124 
125 
126 
127 } // namespace lumiera
128 
129 
130 extern "C" { /* ==== implementation C interface for accessing setup.ini ======= */
131 
132 
133  using std::string;
134  using lumiera::Config;
136  using util::isnil;
137 
138 
139 
140  const char*
141  lumiera_get_plugin_path_default ()
142  {
143  static string pathSpec;
144  if (isnil (pathSpec))
145  {
146  pathSpec += "plugin.path="; // syntax expected by lumiera_config_setdefault
147 
148  // fetch plugin search path from setup.ini and expand any $ORIGIN token
150  while (pathElement)
151  pathSpec += pathElement.next() +":";
152  }
153 
154  return cStr(pathSpec);
155  }
156 }
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:68
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:85
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:289
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:199
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:76
C++ wrapper for convenient access to the Lumiera config system.
Definition: config-facade.h:73
void lumiera_config_destroy()
Destroys the configuration subsystem.
Definition: config.c:114
Registering and managing primary application-global services.
Helper: Access a path Specification as a sequence of filesystem Paths.
Definition: searchpath.hpp:71
Lumiera public interface.
Definition: advice.cpp:113
#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:86
static lib::Depend< AppState > instance
get the (single) AppState instance.
Definition: appstate.hpp:83
static lib::Depend< Config > instance
storage and setup for the single system-wide config facade instance
Definition: config-facade.h:78