ServiceTypeDescription.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico
00003 
00004 This file is part of MeRMaID.
00005 
00006 MeRMaID is free software: you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation, either version 3 of the License, or
00009 (at your option) any later version.
00010 
00011 MeRMaID is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with MeRMaID.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 
00021 
00022 /**
00023  * @Filename ServiceTypeDescription.cpp
00024  * @Description ServiceTypeDescription implementation
00025  * @Status Work in Progress
00026  * @Version $Id: ServiceTypeDescription.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer nmsra (nmsra@mega.ist.utl.pt)
00028  */
00029 
00030 #include "config.h"
00031 
00032 #include "ServiceTypeDescription.hpp"
00033 #include "Service.hpp"
00034 #include "DataFeedDescription.hpp"
00035 #include "ServiceInterfaceDescription.hpp"
00036 
00037 
00038 
00039 #include <Exception.hpp>
00040 #include <XmlElement.hpp>
00041 #include <XmlElementVector.hpp>
00042 
00043 #include <sstream>
00044 
00045 using namespace mermaid::support::service;
00046 using mermaid::support::errorhandling::Exception;
00047 using boost::shared_ptr;
00048 
00049 using mermaid::support::xml::XmlElement;
00050 
00051 ServiceTypeDescription::ServiceTypeDescription (std::string serviceTypeName, std::string serviceTypeComment)
00052 {
00053   serviceTypeName_ = serviceTypeName;
00054   serviceTypeComment_ = serviceTypeComment;
00055 }; //ServiceTypeDescription()
00056 
00057 std::string ServiceTypeDescription::getServiceTypeName()
00058 {
00059   return serviceTypeName_;
00060 }; // getServiceTypeName()
00061 
00062 std::string ServiceTypeDescription::getServiceTypeComment()
00063 {
00064   return serviceTypeComment_;
00065 }; // getServiceTypeComment()
00066 
00067 
00068 void ServiceTypeDescription::addServiceInterfaceDescription (shared_ptr<ServiceInterfaceDescription> interfaceDescription)
00069 {
00070   std::string interfaceName = interfaceDescription->getServiceInterfaceName();
00071   
00072   if (interfaceDescriptionMap_.find (interfaceName) != interfaceDescriptionMap_.end()) {
00073     std::stringstream ss;
00074     ss << "ServiceTypeDescription::addServiceInterfaceDescription : ServiceTypeDescription with serviceTypeName=\"" << serviceTypeName_ << "\" already has a ServiceInterfaceDescription with serviceInterfaceName=\"" << interfaceName << "\"";
00075     throw Exception (ss.str());
00076   }
00077   
00078   interfaceDescriptionMap_[interfaceName] = interfaceDescription;
00079 }; // addServiceInterfaceDescription()
00080 
00081 shared_ptr<ServiceInterfaceDescription> ServiceTypeDescription::getServiceInterfaceDescription (std::string interfaceName)
00082 {
00083   shared_ptr<ServiceInterfaceDescription> interfaceDescription = interfaceDescriptionMap_[interfaceName];
00084   
00085   if (interfaceDescription == false) {
00086     std::stringstream ss;
00087     ss << "ServiceTypeDescription::getServiceInterfaceDescription : ServiceTypeDescription with serviceTypeName=\"" << serviceTypeName_ << "\" does not have a ServiceInterfaceDescription with serviceInterfaceName=\"" << interfaceName << "\"";
00088     throw Exception (ss.str());
00089   }
00090   
00091   return interfaceDescription;
00092 }; // getServiceInterface()
00093 
00094 std::vector<shared_ptr<ServiceInterfaceDescription> > ServiceTypeDescription::getAllServiceInterfaceDescriptions()
00095 {
00096   std::vector<shared_ptr<ServiceInterfaceDescription> > ret;
00097   
00098   std::map<std::string, shared_ptr<ServiceInterfaceDescription> >::iterator it;
00099   
00100   for (it = interfaceDescriptionMap_.begin(); it != interfaceDescriptionMap_.end(); it++) {
00101     ret.push_back ( (*it).second);
00102   }
00103   
00104   return ret;
00105 }; // getAllServiceInterfaceDescriptions()
00106 
00107 void ServiceTypeDescription::addDataFeedDescription (shared_ptr<DataFeedDescription> dataFeedDescription)
00108 {
00109   std::string dataFeedName = dataFeedDescription->getDataFeedName();
00110   
00111   if (dataFeedDescriptionMap_.find (dataFeedName) != dataFeedDescriptionMap_.end()) {
00112     std::stringstream ss;
00113     ss << "ServiceTypeDescription::addDataFeedDescription: ServiceTypeDescription with serviceTypeName=\"" << serviceTypeName_ << "\" already has a DataFeedDescription with dataFeedName=\"" << dataFeedName << "\"";
00114     throw Exception (ss.str());
00115   }
00116   
00117   dataFeedDescriptionMap_[dataFeedName] = dataFeedDescription;
00118 }; // addDataFeedDescription()
00119 
00120 shared_ptr<DataFeedDescription> ServiceTypeDescription::getDataFeedDescription (std::string dataFeedName)
00121 {
00122   std::map<std::string, shared_ptr<DataFeedDescription> >::iterator it;
00123   
00124   it = dataFeedDescriptionMap_.find (dataFeedName);
00125   
00126   if (it == dataFeedDescriptionMap_.end()) {
00127     std::stringstream ss;
00128     ss << "ServiceTypeDescription::getDataFeedName: ServiceTypeDescription with serviceTypeName=\"" << serviceTypeName_ << "\" does not have a DataFeedDescription with dataFeedName=\"" << dataFeedName << "\"";
00129     throw Exception (ss.str());
00130   }
00131   
00132   return (*it).second;
00133 }; // getDataFeedDescription()
00134 
00135 std::vector< shared_ptr<DataFeedDescription> > ServiceTypeDescription::getAllDataFeedDescriptions()
00136 {
00137   std::vector<shared_ptr<DataFeedDescription> > ret;
00138   
00139   std::map<std::string, shared_ptr<DataFeedDescription> >::iterator it;
00140   
00141   for (it = dataFeedDescriptionMap_.begin(); it != dataFeedDescriptionMap_.end(); it++) {
00142     ret.push_back ( (*it).second);
00143   }
00144   
00145   return ret;
00146 }; // getAllDataFeedDescriptions()
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3