HCE project C++ developers source code library
1.1.1
HCE project developer library
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
ServerApplication.hpp
Go to the documentation of this file.
1
14
#ifndef HCE_SERVER_APPLICATION
15
#define HCE_SERVER_APPLICATION
16
17
#include <Poco/Util/HelpFormatter.h>
18
#include <Poco/Util/ServerApplication.h>
19
#include <Poco/Util/OptionSet.h>
20
#include <Poco/SharedPtr.h>
21
#include <Poco/AutoPtr.h>
22
#include <Poco/Exception.h>
23
#include <Poco/Bugcheck.h>
24
25
#include <string>
26
#include <vector>
27
#include <iostream>
28
#include <map>
29
#include <unistd.h>
30
#include <stdio.h>
31
#include <sstream>
32
#include <algorithm>
33
34
#include "
Logger.hpp
"
35
#include "
DBSession.hpp
"
36
37
#include "
exceptions/AlreadyInitializedException.hpp
"
38
#include "
exceptions/NotSetDatabaseParameters.hpp
"
39
#include "
exceptions/NotSetDatabaseType.hpp
"
40
42
45
47
48
namespace
HCE {
54
class
ServerApplication
:
public
Poco::Util::ServerApplication {
55
public
:
56
ServerApplication
();
57
virtual
~ServerApplication
()
throw
();
58
protected
:
59
//must be overridden
60
void
initialize
(Poco::Util::Application&
self
);
61
void
reinitialize
(Poco::Util::Application&
self
);
62
void
uninitialize
();
63
void
defineOptions
(Poco::Util::OptionSet& options);
64
66
void
initializeConfigurationFile
();
67
69
bool
isDataBaseSectionExists
();
71
std::string
getDBType
()
const
;
72
75
std::string
initializeMySQLConnectionString
()
const
;
76
std::string
initializeSQLiteConnectionString
()
const
;
77
79
void
initializeDataBaseSession
();
80
void
uninitializeDataBaseSession
();
81
82
//initialize loggers
83
void
initializeLoggers
();
84
87
virtual
void
handleConfigFile
(
const
std::string&,
const
std::string& value);
89
virtual
void
handleHelp
(
const
std::string& name,
const
std::string& value);
91
virtual
void
handleVersion
(
const
std::string& name,
const
std::string& value);
92
protected
:
94
bool
_configFileRequest
;
95
std::string
_configFile
;
97
bool
_showHelpInfo
;
100
bool
_initializedHCEServerApplication
;
101
std::string
dataBaseType
;
102
protected
:
103
//error messages, instead of macros definitions
104
const
std::string
APPLICATION_NOT_INITIALIZED_EXCEPTION
=
"Class HCE::ServerApplication incorrectly initialized. Maybe problem with configuration,logger or database initializing."
;
105
const
std::string
MESSAGE_ALREADY_INITIALIZED_EXCEPTION
=
"Object already initialized."
;
106
const
std::string
NOT_SET_DB_TYPE_ERROR
=
"Not set database type in configuration type."
;
107
const
std::string
ADDITION_INFORM_STRING_NOT_FOUND
=
"config param or Not found config file"
;
108
};
109
110
}
111
112
#define HCE_SERVER_MAIN(App) \
113
int main(int argc, char** argv) { \
114
const std::string UNKNOWN_EXCEPTION = "Unknown exception"; \
115
int rc = Poco::Util::Application::EXIT_OK; \
116
try { \
117
App app; \
118
rc = app.run(argc, argv); \
119
} \
120
catch (const Poco::Exception& exc) { \
121
std::cerr << exc.displayText() << std::endl; \
122
rc = exc.code(); \
123
} \
124
catch (const std::exception& exc) { \
125
std::cerr << exc.what() << std::endl; \
126
rc = Poco::Util::Application::EXIT_SOFTWARE; \
127
} \
128
catch (...) { \
129
std::cerr << UNKNOWN_EXCEPTION << std::endl; \
130
rc = Poco::Util::Application::EXIT_SOFTWARE; \
131
} \
132
return rc; \
133
} \
134
135
#endif
sources
applicationFramework
src
ServerApplication.hpp
Generated on Mon Jan 13 2014 13:08:36 for HCE project C++ developers source code library by
1.8.1.2