Scopira  20080306
core/loop.h
1 
2 /*
3  * Copyright (c) 2004-2005 National Research Council
4  *
5  * All rights reserved.
6  *
7  * This material is confidential and proprietary information of
8  * National Research Council Canada ("Confidential Information").
9  * This Confidential Information may only be used and reproduced
10  * in accordance with the terms of the license agreement.
11  *
12  */
13 
14 #ifndef __INCLUDED_SCOPIRA_CORE_LOOP_H__
15 #define __INCLUDED_SCOPIRA_CORE_LOOP_H__
16 
17 #include <string>
18 #include <vector>
19 #include <map>
20 
21 #include <scopira/tool/export.h>
22 #include <scopira/tool/output.h>
23 #include <scopira/tool/fileflow.h>
24 #include <scopira/tool/netflow.h>
25 #include <scopira/tool/objflowloader.h>
26 
27 namespace scopira
28 {
29  namespace tool
30  {
31  class dll; //fwd
32  }
37  namespace core
38  {
39  class basic_loop;
40 
41  class objecttype; //fwd
42  }
43 }
44 
65 {
66  public:
68  static basic_loop * instance(void) { return dm_instance; }
69 
75  SCOPIRA_EXPORT basic_loop(int &argc, char **&argv);
76 
78  SCOPIRA_EXPORT ~basic_loop();
79 
86  SCOPIRA_EXPORT void list_config(std::vector<std::string> &out) const;
87 
93  SCOPIRA_EXPORT bool has_config(const std::string &key) const;
94 
101  SCOPIRA_EXPORT const std::string & get_config(const std::string &key) const;
102 
113  SCOPIRA_EXPORT bool get_config(const std::string &key, std::string &out) const;
114 
120  SCOPIRA_EXPORT void set_config(const std::string &key, const std::string &val);
121 
128  SCOPIRA_EXPORT void set_config_default(const std::string &key, const std::string &val);
129 
136  SCOPIRA_EXPORT void set_config_save(const std::string &key, const std::string &val);
137 
138 
147  SCOPIRA_EXPORT void commit_config(void);
148 
156  SCOPIRA_EXPORT static std::string config_expand(const std::string &s);
157 
163  SCOPIRA_EXPORT objecttype * get_root_objecttype(void);
164 
171  const std::string &get_context_name(void) const { return dm_appctx; }
172 
178  const std::string &get_config_dir(void) const { return dm_configdir; }
179 
189  SCOPIRA_EXPORT bool save_object(const std::string &name, scopira::tool::object *o);
190 
199  SCOPIRA_EXPORT bool load_object(const std::string &name, scopira::tool::count_ptr<scopira::tool::object> &out);
200 
201  private:
203  SCOPIRA_EXPORT static basic_loop *dm_instance;
204 
205 #ifndef NDEBUG
206  // used to balance reference counts in debug mode only
207  scopira::tool::objrefcounter dm_refcounter;
208 #endif
209  scopira::tool::fileflow dm_default_out;
210  scopira::tool::output_stack dm_outputstack;
212 
213  struct value_t
214  {
215  std::string pm_val; // the current value
216  bool pm_disk; // is thie value marked for saving
217  int pm_creatorid; // the stack level that this value was created at (used in config stacks)
218 
219  value_t(void) : pm_disk(false), pm_creatorid(0) { }
220  value_t(const std::string &val, int creatorid) : pm_val(val), pm_disk(false),
221  pm_creatorid(creatorid) { }
222  };
223 
224  typedef std::map<std::string, value_t> configmap_t;
225  configmap_t dm_configmap;
226 
227  // the current creator id to assign to new values
228  // its incremented between each "phase" or level or context of parsing
229  struct parse_context_t {
230  int pm_creatorid;
231  bool pm_disk; // mark new nodes for writing (sets the value_t->pm_disk)
232  };
233 
234  parse_context_t dm_parse_context;
235 
236  std::string dm_emptrystring;
237  std::string dm_appctx;
238  std::string dm_configdir;
239 
240  scopira::tool::count_ptr<objecttype> dm_root_objecttype;
241 
242  std::vector<scopira::tool::count_ptr< scopira::tool::dll > > dm_dynlibs;
243 
244 #ifdef PLATFORM_win32
245  scopira::tool::net_loop dm_netlooper;
246 #endif
247 
248  private:
249  void parse_config(int argc, char **argv);
250  void parse_config_file(const std::string &filename, bool cryonerrors);
251  void parse_config_string(const std::string &s, bool newlinesonly);
252  void parse_config_pair(const std::string &s);
253  void process_config(void);
254  void process_lib(const std::string &libname);
255  void process_libdir(const std::string &dirname);
256 };
257 
343 #endif
344 
Definition: objecttype.h:38
Definition: archiveflow.h:20
Definition: object.h:650
const std::string & get_config_dir(void) const
Definition: core/loop.h:178
Definition: object.h:71
Definition: core/loop.h:64
Definition: fileflow.h:60
static basic_loop * instance(void)
returns the static instance
Definition: core/loop.h:68
Definition: netflow.h:227
const std::string & get_context_name(void) const
Definition: core/loop.h:171
Definition: output.h:80