3 #include "Poco/Util/ServerApplication.h"
5 #include "Poco/TaskManager.h"
6 #include "Poco/Util/Option.h"
7 #include "Poco/Util/OptionSet.h"
8 #include "Poco/Util/HelpFormatter.h"
9 #include "Poco/Util/AbstractConfiguration.h"
10 #include "Poco/Util/IntValidator.h"
11 #include "Poco/AutoPtr.h"
12 #include "Poco/Thread.h"
18 #include "Tourist/App/Application.h"
19 #include "Tourist/Util/Config.h"
22 //#include "Poco/FileChannel.h"
25 using Poco::Util::Application
;
27 //using Poco::FileChannel;
28 using Poco::Util::ServerApplication
;
30 using Poco::TaskManager
;
31 using Poco::Util::Option
;
32 using Poco::Util::OptionSet
;
33 using Poco::Util::HelpFormatter
;
34 using Poco::Util::AbstractConfiguration
;
35 using Poco::Util::OptionCallback
;
38 class TouristClientTask
: public Task
{
40 TouristClientTask(): Task("TouristClientTask") {
45 fprintf(stdout
, "Tourist sequence initiating!!\n");
46 Application
&app
= Application::instance();
50 //To ensure that we get fairly random Id on
52 if (gettimeofday(&tv
, &tz
)==-1)
55 srand (tv
.tv_usec
); // Should be more random than time()
57 std::string logfile
= app
.config().getString("logfile");
58 std::string propfile
= app
.config().getString("propfile");
60 printf("Node properties file %s\n", propfile
.c_str());
61 printf("Logging properties file %s\n", logfile
.c_str());
63 Tourist::Util::Config
config(logfile
, propfile
);
64 Tourist::App::Application
app1(config
);
68 fprintf(stderr
, "Failed to initialize the application, check log for detail!");
80 class TouristClient
: public ServerApplication
{
82 TouristClient(): _helpRequested(false) {}
88 void initialize(Application
& self
) {
89 loadConfiguration(); // load default configuration files, if present
90 Application::initialize(self
);
91 // add your own initialization code here
95 // add your own uninitialization code here
96 Application::uninitialize();
99 void reinitialize(Application
& self
) {
100 Application::reinitialize(self
);
101 // add your own reinitialization code here
104 void defineOptions(OptionSet
& options
) {
105 Application::defineOptions(options
);
108 Option("help", "h", "display help information on command line arguments")
111 .callback(OptionCallback
<TouristClient
>(this, &TouristClient::handleHelp
)));
114 Option("config-file", "f", "load configuration data from a file")
118 .callback(OptionCallback<TouristClient>(this, &TouristClient::handleConfig)));*/
121 Option("properties", "l", "lists all configuration properties")
124 .binding("application.listprops"));
127 Option("propfile", "p", "Tourist node properties file")
131 .binding("propfile"));
134 Option("logfile", "o", "logging configuration")
138 .binding("logfile"));
142 void handleHelp(const std::string
& name
, const std::string
& value
) {
143 _helpRequested
= true;
145 stopOptionsProcessing();
148 void handleConfig(const std::string
& name
, const std::string
& value
) {
149 std::cout
<<"Name : "<<name
<<" value: " <<value
<<std::endl
;
150 loadConfiguration(value
);
154 HelpFormatter
helpFormatter(options());
155 helpFormatter
.setCommand(commandName());
156 helpFormatter
.setUsage("OPTIONS");
157 helpFormatter
.setHeader("A test application for the tourist libraries");
158 helpFormatter
.format(std::cout
);
161 void printProperties(const std::string
& base
) {
162 AbstractConfiguration::Keys keys
;
163 config().keys(base
, keys
);
165 if (config().hasProperty(base
)) {
169 msg
.append(config().getString(base
));
170 logger().information(msg
);
173 for (AbstractConfiguration::Keys::const_iterator it
= keys
.begin();
174 it
!= keys
.end(); ++it
) {
175 std::string fullKey
= base
;
176 if (!fullKey
.empty()) fullKey
+= '.';
178 printProperties(fullKey
);
183 int main(const std::vector
<std::string
>& args
) {
184 if (config().hasProperty("application.listprops") && !_helpRequested
){
186 return Application::EXIT_OK
;
189 if (_helpRequested
) return Application::EXIT_OK
;
192 tm
.start(new TouristClientTask
);
193 waitForTerminationRequest();
196 return Application::EXIT_OK
;
200 int main(int arg
, char** argv
)
202 TouristClient tourist
;
203 return tourist
.run(arg
, argv
);