platform/include/pion/platform/CodecFactory.hpp

00001 // ------------------------------------------------------------------------
00002 // Pion is a development platform for building Reactors that process Events
00003 // ------------------------------------------------------------------------
00004 // Copyright (C) 2007-2008 Atomic Labs, Inc.  (http://www.atomiclabs.com)
00005 //
00006 // Pion is free software: you can redistribute it and/or modify it under the
00007 // terms of the GNU Affero General Public License as published by the Free
00008 // Software Foundation, either version 3 of the License, or (at your option)
00009 // any later version.
00010 //
00011 // Pion is distributed in the hope that it will be useful, but WITHOUT ANY
00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00013 // FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
00014 // more details.
00015 //
00016 // You should have received a copy of the GNU Affero General Public License
00017 // along with Pion.  If not, see <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #ifndef __PION_CODECFACTORY_HEADER__
00021 #define __PION_CODECFACTORY_HEADER__
00022 
00023 #include <string>
00024 #include <libxml/tree.h>
00025 #include <pion/PionConfig.hpp>
00026 #include <pion/PionException.hpp>
00027 #include <pion/platform/Codec.hpp>
00028 #include <pion/platform/PluginConfig.hpp>
00029 
00030 
00031 namespace pion {        // begin namespace pion
00032 namespace platform {    // begin namespace platform (Pion Platform Library)
00033 
00037 class PION_PLATFORM_API CodecFactory :
00038     public PluginConfig<Codec>
00039 {
00040 public:
00041 
00043     class CodecNotFoundException : public PionException {
00044     public:
00045         CodecNotFoundException(const std::string& codec_id)
00046             : PionException("No codecs found for identifier: ", codec_id) {}
00047     };
00048 
00049     
00051     virtual ~CodecFactory() {}
00052     
00058     explicit CodecFactory(const VocabularyManager& vocab_mgr);
00059 
00066     CodecPtr getCodec(const std::string& codec_id);
00067 
00075     void setCodecConfig(const std::string& codec_id, const xmlNodePtr config_ptr);
00076 
00085     std::string addCodec(const xmlNodePtr config_ptr);
00086     
00092     void removeCodec(const std::string& codec_id);
00093 
00102     static xmlNodePtr createCodecConfig(const char *buf, std::size_t len) {
00103         return ConfigManager::createResourceConfig(CODEC_ELEMENT_NAME, buf, len);
00104     }
00105 
00107     std::string getPermissionType(void) const { return CODECS_PERMISSION_TYPE; }
00108 
00109 protected:
00110     
00122     virtual void addPluginNoLock(const std::string& plugin_id,
00123                                  const std::string& plugin_name,
00124                                  const xmlNodePtr config_ptr)
00125     {
00126         try {
00127             Codec *new_plugin_ptr = m_plugins.load(plugin_id, plugin_name);
00128             new_plugin_ptr->setId(plugin_id);
00129             new_plugin_ptr->setCodecFactory(*this);
00130             if (config_ptr != NULL) {
00131                 VocabularyPtr vocab_ptr(m_vocab_mgr.getVocabulary());
00132                 new_plugin_ptr->setConfig(*vocab_ptr, config_ptr);
00133             }
00134         } catch (PionPlugin::PluginNotFoundException&) {
00135             throw;
00136         } catch (std::exception& e) {
00137             throw PluginException(e.what());
00138         }
00139     }
00140 
00141     
00142 private:
00143     
00145     static const std::string        DEFAULT_CONFIG_FILE;
00146 
00148     static const std::string        CODEC_ELEMENT_NAME;
00149 
00151     static const std::string        CODECS_PERMISSION_TYPE;
00152 };
00153 
00154 
00155 }   // end namespace platform
00156 }   // end namespace pion
00157 
00158 #endif

Generated on Wed Apr 13 16:38:34 2011 for pion-platform by  doxygen 1.4.7