Nymph  v1.5.2
Flow-Based Data Processing Framework
TestApplication.cc
Go to the documentation of this file.
1 /*
2  * TestApplication.cc
3  *
4  * Created on: Aug 1, 2012
5  * Author: nsoblath
6  *
7  * To test the command-line interface:
8  * > TestApplication -c /path/to/TestConfigurator.json
9  * > TestApplication -c /path/to/TestConfigurator.json --test-app-opt=blah
10  * > TestApplication -c /path/to/TestConfigurator.json --int-data 20
11  */
12 
13 
14 #include "KTTestConfigurable.hh"
15 #include "KTApplication.hh"
16 #include "KTCommandLineOption.hh"
17 
18 #include "param.hh"
19 
20 using namespace Nymph;
21 using namespace std;
22 
23 KTLOGGER(testapplog, "TestApplication");
24 
25 // Add an application-specific command-line option
26 static KTCommandLineOption< string > sTestAppOption("TestApplication", "Application-specific command-line option", "test-app-opt", 'a');
27 
28 
29 int main(int argc, char** argv)
30 {
31  //****************************
32  // Create the app; this performs the initial command-line processing
33  //****************************
34 
35  KTApplication* app = NULL;
36  try
37  {
38  app = new KTApplication(argc, argv);
39  }
40  catch (std::exception& e)
41  {
42  KTERROR(testapplog, "Exception caught from KTApplication constructor:\n"
43  << '\t' << e.what());
44  return 0;
45  }
46 
47 
48  //****************************
49  // Check basic command-line reading
50  //****************************
51 
52  KTINFO(testapplog, "Application: " << app->GetCommandLineHandler()->GetExecutableName());
53  KTINFO(testapplog, "Config filename: " << app->GetCommandLineHandler()->GetConfigFilename());
54 
55 
56  //****************************
57  // Check reading of command-line options
58  //****************************
59 
60  if (app->GetCommandLineHandler()->IsCommandLineOptSet("test-app-opt"))
61  {
62  KTINFO(testapplog, "Test application option is set to value <" << app->GetCommandLineHandler()->GetCommandLineValue< string >("test-app-opt") << ">");
63  }
64  else
65  {
66  KTINFO(testapplog, "Test application option was not set");
67  }
68 
69  if (app->GetCommandLineHandler()->IsCommandLineOptSet("int-data"))
70  {
71  KTINFO(testapplog, "Test option <int-data> is set to value <" << app->GetCommandLineHandler()->GetCommandLineValue< int >("int-data") << ">");
72  }
73  else
74  {
75  KTINFO(testapplog, "Test option <int-data> was not set");
76  }
77 
78 
79  //****************************
80  // Check reading of the config file
81  //****************************
82 
83  KTTestConfigurable* testObj = new KTTestConfigurable();
84 
85  const scarab::param_node& topNode = app->GetConfigurator()->Config();
86 
87  if (testObj->Configure(topNode[testObj->GetConfigName()].as_node()))
88  {
89  KTINFO(testapplog, "Configuration complete:\n"
90  << "\tInt data: " << testObj->GetIntData() << '\n'
91  << "\tDouble data: " << testObj->GetDoubleData() << '\n'
92  << "\tString data: " << testObj->GetStringData());
93  }
94  else
95  {
96  KTERROR(testapplog, "Something went wrong during the configuration");
97  }
98 
99  delete testObj;
100 
101  return 0;
102 }
#define KTINFO(...)
Definition: KTLogger.hh:344
Interface for the command-line handler and the configurator.
bool IsCommandLineOptSet(const std::string &aCLOption)
Check if a command line option was set.
STL namespace.
const std::string & GetConfigFilename() const
Return the file name provided by the user on the command line for the config file.
static KTCommandLineOption< string > sTestAppOption("TestApplication", "Application-specific command-line option", "test-app-opt", 'a')
int main(int argc, char **argv)
bool Configure(const scarab::param_node &node)
Should perform parameter store and command-line configurations.
const std::string & GetStringData() const
XReturnType GetCommandLineValue(const std::string &aCLOption)
Return the value of a command line option; throws an exception if the value was not set...
KTLOGGER(applog, "KTApplication")
const std::string & GetExecutableName() const
Contains KTApplication.
const std::string & GetConfigName() const
#define KTERROR(...)
Definition: KTLogger.hh:347
const KTConfigurator * GetConfigurator() const
scarab::param_node & Config()
KTCommandLineHandler * GetCommandLineHandler() const