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 #include <pion/platform/CodecFactory.hpp> 00021 00022 00023 namespace pion { // begin namespace pion 00024 namespace platform { // begin namespace platform (Pion Platform Library) 00025 00026 00027 // static members of CodecFactory 00028 const std::string CodecFactory::DEFAULT_CONFIG_FILE = "codecs.xml"; 00029 const std::string CodecFactory::CODEC_ELEMENT_NAME = "Codec"; 00030 const std::string CodecFactory::CODECS_PERMISSION_TYPE = "Codecs"; 00031 00032 00033 // CodecFactory member functions 00034 00035 CodecFactory::CodecFactory(const VocabularyManager& vocab_mgr) 00036 : PluginConfig<Codec>(vocab_mgr, DEFAULT_CONFIG_FILE, CODEC_ELEMENT_NAME) 00037 { 00038 setLogger(PION_GET_LOGGER("pion.platform.CodecFactory")); 00039 } 00040 00041 CodecPtr CodecFactory::getCodec(const std::string& codec_id) 00042 { 00043 boost::mutex::scoped_lock factory_lock(m_mutex); 00044 Codec *codec_ptr = m_plugins.get(codec_id); 00045 // throw an exception if the codec was not found 00046 if (codec_ptr == NULL) 00047 throw CodecNotFoundException(codec_id); 00048 // return a cloned instance of the Codec since its state may change 00049 // while encoding or decoding data streams 00050 return codec_ptr->clone(); 00051 } 00052 00053 void CodecFactory::setCodecConfig(const std::string& codec_id, 00054 const xmlNodePtr config_ptr) 00055 { 00056 // convert PluginNotFound exceptions into CodecNotFound exceptions 00057 try { 00058 PluginConfig<Codec>::setPluginConfig(codec_id, config_ptr); 00059 } catch (PluginManager<Codec>::PluginNotFoundException&) { 00060 throw CodecNotFoundException(codec_id); 00061 } 00062 } 00063 00064 std::string CodecFactory::addCodec(const xmlNodePtr config_ptr) 00065 { 00066 return PluginConfig<Codec>::addPlugin(config_ptr); 00067 } 00068 00069 void CodecFactory::removeCodec(const std::string& codec_id) { 00070 // convert PluginNotFound exceptions into CodecNotFound exceptions 00071 try { 00072 PluginConfig<Codec>::removePlugin(codec_id); 00073 } catch (PluginManager<Codec>::PluginNotFoundException&) { 00074 throw CodecNotFoundException(codec_id); 00075 } 00076 } 00077 00078 00079 } // end namespace platform 00080 } // end namespace pion
1.4.7