Nymph  v1.5.2
Flow-Based Data Processing Framework
KTConfigurable.cc
Go to the documentation of this file.
1 /*
2  * KTConfigurable.cc
3  *
4  * Created on: Aug 21, 2012
5  * Author: nsoblath
6  */
7 
8 #include "KTConfigurable.hh"
9 
10 #include "KTCommandLineHandler.hh"
11 #include "KTLogger.hh"
12 #include "KTConfigurator.hh"
13 
14 #include "param_codec.hh"
15 
16 using std::string;
17 
18 namespace Nymph
19 {
20 
21  KTLOGGER(conflog, "KTConfigurable");
22 
23  //******************
24  // KTConfigurable
25  //******************
26 
27  KTConfigurable::KTConfigurable(const string& name) :
28  fCLHandler(KTCommandLineHandler::get_instance()),
29  fConfigName(name)
30  {
31  }
32 
34  {
35  }
36 
37  bool KTConfigurable::Configure(const std::string& config)
38  {
39  scarab::param_translator translator;
40  scarab::param_node optNode;
41  optNode.add( "encoding", new scarab::param_value( "json" ) );
42  return Configure( translator.read_string( config, optNode )->as_node() );;
43  }
44 
45 
46  //**********************
47  // KTSelfConfigurable
48  //**********************
49 
51  KTConfigurable(name),
52  fIsConfigured(false)
53  {
54  }
55 
57  {
58  }
59 
61  {
62  if (fIsConfigured) return true;
63 
64  const scarab::param_node& node = KTConfigurator::get_instance()->Config();
65  if (! this->Configure(node))
66  {
67  KTERROR(conflog, "An error occurred while configuring <" << fConfigName << ">");
68  return false;
69  }
71  return fIsConfigured;
72  }
73 
74 } /* namespace Nymph */
::Nymph::KTLogger conflog("KTConfigurable")
virtual bool IsReady() const =0
Check if everything has been correctly configured.
virtual bool Configure(const scarab::param_node &node)=0
Should perform parameter store and command-line configurations.
Parses and stores command-line options.
KTConfigurable(const std::string &name="default-name")
KTLOGGER(applog, "KTApplication")
KTSelfConfigurable(const std::string &name="default-self-name")
Contains KTCommandLineHandler.
#define KTERROR(...)
Definition: KTLogger.hh:347
virtual bool Configure()
Configure by getting the top-level node from the parameter store.
Contains the logger class and macros, based on Kasper&#39;s KLogger class.