00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PION_PLATFORMCONFIG_HEADER__
00021 #define __PION_PLATFORMCONFIG_HEADER__
00022
00023 #include <string>
00024 #include <vector>
00025 #include <libxml/tree.h>
00026 #include <boost/cstdint.hpp>
00027 #include <boost/thread/mutex.hpp>
00028 #include <pion/PionConfig.hpp>
00029 #include <pion/PionException.hpp>
00030 #include <pion/platform/ConfigManager.hpp>
00031 #include <pion/platform/VocabularyManager.hpp>
00032 #include <pion/platform/ReactionEngine.hpp>
00033 #include <pion/platform/CodecFactory.hpp>
00034 #include <pion/platform/ProtocolFactory.hpp>
00035 #include <pion/platform/DatabaseManager.hpp>
00036 #include "ServiceManager.hpp"
00037 #include "UserManager.hpp"
00038
00039
00040 namespace pion {
00041 namespace server {
00042
00043
00047 class PION_SERVER_API PlatformConfig :
00048 public pion::platform::ConfigManager
00049 {
00050 public:
00051
00053 class MissingVocabularyConfigException : public PionException {
00054 public:
00055 MissingVocabularyConfigException(const std::string& config_file)
00056 : PionException("Platform configuration file does not define a Vocabulary configuration file: ", config_file) {}
00057 };
00058
00060 class MissingCodecConfigException : public PionException {
00061 public:
00062 MissingCodecConfigException(const std::string& config_file)
00063 : PionException("Platform configuration file does not define a Codec configuration file: ", config_file) {}
00064 };
00065
00067 class MissingProtocolConfigException : public PionException {
00068 public:
00069 MissingProtocolConfigException(const std::string& config_file)
00070 : PionException("Platform configuration file does not define a Protocol configuration file: ", config_file) {}
00071 };
00072
00074 class MissingDatabaseConfigException : public PionException {
00075 public:
00076 MissingDatabaseConfigException(const std::string& config_file)
00077 : PionException("Platform configuration file does not define a Database configuration file: ", config_file) {}
00078 };
00079
00081 class MissingReactorConfigException : public PionException {
00082 public:
00083 MissingReactorConfigException(const std::string& config_file)
00084 : PionException("Platform configuration file does not define a Reactor configuration file: ", config_file) {}
00085 };
00086
00088 class MissingServiceConfigException : public PionException {
00089 public:
00090 MissingServiceConfigException(const std::string& config_file)
00091 : PionException("Platform configuration file does not define a Service configuration file: ", config_file) {}
00092 };
00093
00095 class MissingUserConfigException : public PionException {
00096 public:
00097 MissingUserConfigException(const std::string& config_file)
00098 : PionException("Platform configuration file does not define a User configuration file: ", config_file) {}
00099 };
00100
00102 class EmptyPluginPathException : public PionException {
00103 public:
00104 EmptyPluginPathException(const std::string& config_file)
00105 : PionException("Platform configuration includes an empty plug-in path: ", config_file) {}
00106 };
00107
00109 class MissingDataDirectoryException : public PionException {
00110 public:
00111 MissingDataDirectoryException(const std::string& config_file)
00112 : PionException("Platform configuration file does not define a data directory: ", config_file) {}
00113 };
00114
00116 class DirectoryNotFoundException : public PionException {
00117 public:
00118 DirectoryNotFoundException(const std::string& dir)
00119 : PionException("Platform configuration DataDirectory not found: ", dir) {}
00120 };
00121
00123 class NotADirectoryException : public PionException {
00124 public:
00125 NotADirectoryException(const std::string& dir)
00126 : PionException("Platform configuration DataDirectory is not a directory: ", dir) {}
00127 };
00128
00130 PlatformConfig(void);
00131
00133 virtual ~PlatformConfig() {
00134
00135
00136 m_reaction_engine.stop();
00137
00138
00139
00140 m_service_mgr.shutdown();
00141
00142 m_reaction_engine.shutdown();
00143 }
00144
00146 virtual void openConfigFile(void);
00147
00153 virtual void writeConfigXML(std::ostream& out) const;
00154
00156 inline pion::platform::VocabularyManager& getVocabularyManager(void) { return m_vocab_mgr; }
00157
00159 inline pion::platform::CodecFactory& getCodecFactory(void) { return m_codec_factory; }
00160
00162 inline pion::platform::ProtocolFactory& getProtocolFactory(void) { return m_protocol_factory; }
00163
00165 inline pion::platform::DatabaseManager& getDatabaseManager(void) { return m_database_mgr; }
00166
00168 inline pion::platform::ReactionEngine& getReactionEngine(void) { return m_reaction_engine; }
00169
00171 inline const pion::platform::ReactionEngine& getReactionEngine(void) const { return m_reaction_engine; }
00172
00174 inline ServiceManager& getServiceManager(void) { return m_service_mgr; }
00175
00177 inline const UserManagerPtr getUserManagerPtr(void) const { return m_user_mgr_ptr; }
00178
00180 inline const std::string& getLogConfigFile(void) const { return m_log_config_file; }
00181
00183 inline const std::string& getDataDirectory(void) const { return m_data_directory; }
00184
00186 inline bool getDebugMode(void) const { return m_debug_mode; }
00187
00188
00189 private:
00190
00199 boost::int32_t findSystemId(const std::string& name, const std::string& file);
00200
00202 void parseUser(void);
00203
00205 void parseGroup(void);
00206
00207
00209 static const std::string DEFAULT_CONFIG_FILE;
00210
00212 static const std::string VERSION_ELEMENT_NAME;
00213
00215 static const std::string PLATFORM_CONFIG_ELEMENT_NAME;
00216
00218 static const std::string VOCABULARY_CONFIG_ELEMENT_NAME;
00219
00221 static const std::string CODEC_CONFIG_ELEMENT_NAME;
00222
00224 static const std::string PROTOCOL_CONFIG_ELEMENT_NAME;
00225
00227 static const std::string DATABASE_CONFIG_ELEMENT_NAME;
00228
00230 static const std::string REACTOR_CONFIG_ELEMENT_NAME;
00231
00233 static const std::string SERVICE_CONFIG_ELEMENT_NAME;
00234
00236 static const std::string USER_CONFIG_ELEMENT_NAME;
00237
00239 static const std::string LOG_CONFIG_ELEMENT_NAME;
00240
00242 static const std::string VOCABULARY_PATH_ELEMENT_NAME;
00243
00245 static const std::string PLUGIN_PATH_ELEMENT_NAME;
00246
00248 static const std::string DATA_DIRECTORY_ELEMENT_NAME;
00249
00251 static const std::string DEBUG_MODE_ELEMENT_NAME;
00252
00254 static const std::string REACTION_ENGINE_ELEMENT_NAME;
00255
00257 static const std::string MAX_THREADS_ELEMENT_NAME;
00258
00260 static const std::string MULTITHREAD_BRANCHES_ELEMENT_NAME;
00261
00263 static const std::string USER_ELEMENT_NAME;
00264
00266 static const std::string GROUP_ELEMENT_NAME;
00267
00268
00270 pion::platform::VocabularyManager m_vocab_mgr;
00271
00273 pion::platform::CodecFactory m_codec_factory;
00274
00276 pion::platform::ProtocolFactory m_protocol_factory;
00277
00279 pion::platform::DatabaseManager m_database_mgr;
00280
00282 pion::platform::ReactionEngine m_reaction_engine;
00283
00285 ServiceManager m_service_mgr;
00286
00288 UserManagerPtr m_user_mgr_ptr;
00289
00291 std::string m_log_config_file;
00292
00294 std::string m_data_directory;
00295
00297 std::string m_user_name;
00298
00300 std::string m_group_name;
00301
00303 boost::int32_t m_user_id;
00304
00306 boost::int32_t m_group_id;
00307
00309 std::vector<std::string> m_plugin_paths;
00310
00312 bool m_debug_mode;
00313
00315 mutable boost::mutex m_mutex;
00316 };
00317
00318
00319 }
00320 }
00321
00322 #endif