EntityDescription.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 EntityDescription.cpp
00024  * @Description Support EntityDescription implementation
00025  * @Status Work in Progress
00026  * @Version $Id: EntityDescription.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer mafb
00028  */
00029 
00030 
00031 #include "config.h"
00032 
00033 #include "EntityDescription.hpp"
00034 #include "ServiceInterfaceDescription.hpp"
00035 #include "ServiceTypeDescription.hpp"
00036 
00037 #include <Exception.hpp>
00038 
00039 #include <sstream>
00040 
00041 using namespace mermaid::support::service;
00042 using mermaid::support::errorhandling::Exception;
00043 
00044 EntityDescription::EntityDescription (std::string entityName)
00045 {
00046   entityName_ = entityName;
00047 }; // EntityDescription()
00048 
00049 std::string EntityDescription::getEntityName()
00050 {
00051   return entityName_;
00052 }; // getEntityName()
00053 
00054 
00055 void EntityDescription::addServiceInstanceDescription (shared_ptr<ServiceInstanceDescription> serviceInstanceDescription)
00056 {
00057   std::string serviceInstanceName = serviceInstanceDescription->getServiceInstanceName();
00058   
00059   if (serviceMap_.find (serviceInstanceName) != serviceMap_.end()) {
00060     std::stringstream ss;
00061     ss << "EntityDescription::addServiceInstanceDescription : entity with entityName=\"" << entityName_ << "\" already has a service registered with serviceInstanceName=\"" << serviceInstanceName << "\"";
00062     throw Exception (ss.str());
00063   }
00064   
00065   serviceMap_[serviceInstanceName] = serviceInstanceDescription;
00066 }; // addServiceInstanceDescription()
00067 
00068 shared_ptr<ServiceInstanceDescription> EntityDescription::getServiceInstanceDescription (std::string serviceInstanceName)
00069 {
00070   shared_ptr<ServiceInstanceDescription> sd = serviceMap_[serviceInstanceName];
00071   
00072   if (sd == false) {
00073     std::stringstream ss;
00074     ss << "EntityDescription::getServiceDescription : request for an unknown service instance name: " << serviceInstanceName;
00075     throw Exception (ss.str());
00076   }
00077   
00078   return sd;
00079 }; // getServiceDescription()
00080 
00081 std::vector<shared_ptr<ServiceInstanceDescription> > EntityDescription::getAllServiceInstanceDescriptions()
00082 {
00083   //std::cerr << "EntityDescription::getAllServiceInstanceDescriptions : entityName=" << entityName_ << std::endl;
00084   std::vector<shared_ptr<ServiceInstanceDescription> > ret;
00085   std::map<std::string, shared_ptr<ServiceInstanceDescription> >::iterator it;
00086   
00087   for (it = serviceMap_.begin(); it != serviceMap_.end(); it++) {
00088     //std::cerr << "EntityDescription::getAllServiceInstanceDescriptions : serviceInstanceName=" << (*it).first << std::endl;
00089     ret.push_back ( (*it).second);
00090   }
00091   
00092   return ret;
00093 }; // getAllServiceInstanceDescriptions()
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3