Lumiera  0.pre.03
»edityourfreedom«
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::cStr;
74  using util::isnil;
75  using lib::Literal;
76 
77 
80 
81 
82  namespace {
83 
84  void
85  pull_up_ConfigSystem ()
86  {
87  TRACE (common, "booting up config system");
89  }
90 
91  LifecycleHook trigger__ (ON_BASIC_INIT, &pull_up_ConfigSystem);
92  }
93 
94 
95 
96 
98  {
99  string extendedConfigSearchPath = AppState::instance().fetchSetupValue (KEY_CONFIG_PATH);
100  lumiera_config_init (cStr(extendedConfigSearchPath));
101  TRACE (config, "Config system ready.");
102  }
103 
104 
106  {
108  TRACE (config, "config system closed.");
109  }
110 
111 
112 
116  string
118  {
119  string value = AppState::instance().fetchSetupValue (key);
120  if (isnil (value))
121  throw error::Config ("Configuration value for key=\""+key+"\" is missing");
122 
123  return value;
124  }
125 
126 
127 
128 } // namespace lumiera
129 
130 
131 extern "C" { /* ==== implementation C interface for accessing setup.ini ======= */
132 
133 
134  using std::string;
135  using lumiera::Config;
137  using util::isnil;
138  using util::cStr;
139 
140 
141 
142  const char*
144  {
145  static string pathSpec;
146  if (isnil (pathSpec))
147  {
148  pathSpec += "plugin.path="; // syntax expected by lumiera_config_setdefault
149 
150  // fetch plugin search path from setup.ini and expand any $ORIGIN token
152  while (pathElement)
153  pathSpec += pathElement.next() +":";
154  }
155 
156  return cStr(pathSpec);
157  }
158 }
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.
inline string literal This is a marker type to indicate that
Definition: symbol.hpp:75
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
const char * cStr(string const &org)
convenience shortcut: conversion to c-String via string.
Definition: util.hpp:397
static string get(lib::Literal key)
#define KEY_CONFIG_PATH
key to fetch the search path for extended configuration.
const char * lumiera_get_plugin_path_default()
The lumiera::Config wrapper class addresses two issues.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
bool isnil(lib::time::Duration const &dur)
Definition: timevalue.hpp:642
TRACE(test, "inserted %d", data)
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:76
Lumiera public interface.
#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
LumieraError< LERR_(CONFIG), Invalid > Config
Definition: error.hpp:217
static lib::Depend< Config > instance
storage and setup for the single system-wide config facade instance
Definition: config-facade.h:78