00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PION_PROTOCOLFACTORY_HEADER__
00021 #define __PION_PROTOCOLFACTORY_HEADER__
00022
00023 #include <string>
00024 #include <libxml/tree.h>
00025 #include <pion/PionConfig.hpp>
00026 #include <pion/PionException.hpp>
00027 #include <pion/platform/Protocol.hpp>
00028 #include <pion/platform/PluginConfig.hpp>
00029
00030
00031 namespace pion {
00032 namespace platform {
00033
00037 class PION_PLATFORM_API ProtocolFactory :
00038 public PluginConfig<Protocol>
00039 {
00040 public:
00041
00043 class ProtocolNotFoundException : public PionException {
00044 public:
00045 ProtocolNotFoundException(const std::string& protocol_id)
00046 : PionException("No protocol found for identifier: ", protocol_id) {}
00047 };
00048
00049
00051 virtual ~ProtocolFactory() {}
00052
00058 explicit ProtocolFactory(const VocabularyManager& vocab_mgr);
00059
00066 ProtocolPtr getProtocol(const std::string& protocol_id);
00067
00075 void setProtocolConfig(const std::string& protocol_id, const xmlNodePtr config_ptr);
00076
00085 std::string addProtocol(const xmlNodePtr config_ptr);
00086
00092 void removeProtocol(const std::string& protocol_id);
00093
00102 static xmlNodePtr createProtocolConfig(const char *buf, std::size_t len) {
00103 return ConfigManager::createResourceConfig(PROTOCOL_ELEMENT_NAME, buf, len);
00104 }
00105
00106 protected:
00107
00119 virtual void addPluginNoLock(const std::string& plugin_id,
00120 const std::string& plugin_name,
00121 const xmlNodePtr config_ptr)
00122 {
00123 try {
00124 Protocol *new_plugin_ptr = m_plugins.load(plugin_id, plugin_name);
00125 new_plugin_ptr->setId(plugin_id);
00126 new_plugin_ptr->setProtocolFactory(*this);
00127 if (config_ptr != NULL) {
00128 VocabularyPtr vocab_ptr(m_vocab_mgr.getVocabulary());
00129 new_plugin_ptr->setConfig(*vocab_ptr, config_ptr);
00130 }
00131 } catch (PionPlugin::PluginNotFoundException&) {
00132 throw;
00133 } catch (std::exception& e) {
00134 throw PluginException(e.what());
00135 }
00136 }
00137
00138
00139 private:
00140
00142 static const std::string DEFAULT_CONFIG_FILE;
00143
00145 static const std::string PROTOCOL_ELEMENT_NAME;
00146 };
00147
00148
00149 }
00150 }
00151
00152 #endif