ServiceInstanceDescription.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 ServiceInstanceDescription.cpp
00024  * @Description ServiceInstanceDescription implementation
00025  * @Status Work in Progress
00026  * @Version $Id: ServiceInstanceDescription.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer mafb
00028  */
00029 
00030 
00031 #include "config.h"
00032 
00033 #include "ServiceInstanceDescription.hpp"
00034 #include "ServiceInterfaceDescription.hpp"
00035 #include "ServiceTypeDescription.hpp"
00036 
00037 #include "EntityDescription.hpp"
00038 
00039 #include "Exceptions/UnrecognizedServiceInterfaceException.hpp"
00040 
00041 #include <Exception.hpp>
00042 
00043 //#include <iostream>
00044 
00045 using namespace mermaid::support::service;
00046 using mermaid::support::errorhandling::Exception;
00047 using mermaid::support::service::exceptions::UnrecognizedServiceInterfaceException;
00048 
00049 ServiceInstanceDescription::ServiceInstanceDescription (shared_ptr<EntityDescription> entityDescription, std::string serviceInstanceName)
00050 {
00051   entityDescription_ = entityDescription;
00052   serviceInstanceName_ = serviceInstanceName;
00053 }; // ServiceInstanceDescription()
00054 
00055 void ServiceInstanceDescription::addServiceTypeDescription (shared_ptr<ServiceTypeDescription> serviceTypeDescription)
00056 {
00057   std::string typeName = serviceTypeDescription->getServiceTypeName();
00058   
00059   //std::cerr << "ServiceInstanceDescription::addServiceTypeDescription : serviceTypeName=" << typeName << std::endl;
00060   
00061   if (serviceTypeDescriptions_.find (typeName) == serviceTypeDescriptions_.end()) {
00062     serviceTypeDescriptions_[typeName] = serviceTypeDescription;
00063   }
00064   else {
00065     throw Exception ("ServiceInstanceDescription::addServiceTypeDescription : adding ServiceTypeDescription with an already used Service Type Name : " + typeName);
00066   }
00067 }; //addServiceTypeDescription()
00068 
00069 shared_ptr<EntityDescription> ServiceInstanceDescription::getEntityDescription()
00070 {
00071   return entityDescription_;
00072 }; // getEntityName()
00073 
00074 std::vector<shared_ptr<ServiceTypeDescription> > ServiceInstanceDescription::getServiceTypeDescriptions()
00075 {
00076   std::vector<shared_ptr<ServiceTypeDescription> > descriptions;
00077   
00078   std::map<std::string, shared_ptr<ServiceTypeDescription> >::iterator it;
00079   
00080   for (it = serviceTypeDescriptions_.begin(); it != serviceTypeDescriptions_.end(); it++) {
00081     shared_ptr<ServiceTypeDescription> std = (*it).second;
00082     //std::cerr << "ServiceInstanceDescription::getServiceTypeDescriptions : serviceTypeName=" << std->getServiceTypeName() << std::endl;
00083     descriptions.push_back (std);
00084   }
00085   
00086   return descriptions;
00087 }; // getServiceTypeDescriptions()
00088 
00089 shared_ptr<ServiceTypeDescription> ServiceInstanceDescription::getServiceTypeDescriptionWithInterfaceName (std::string interfaceName)
00090 {
00091   std::map<std::string, shared_ptr<ServiceTypeDescription> >::iterator it;
00092   
00093   for (it = serviceTypeDescriptions_.begin(); it != serviceTypeDescriptions_.end(); it++) {
00094     shared_ptr<ServiceTypeDescription> typeDescription = (*it).second;
00095     
00096     try {
00097       shared_ptr<ServiceInterfaceDescription> sid = typeDescription->getServiceInterfaceDescription (interfaceName);
00098       return typeDescription;
00099     }
00100     catch (Exception e) {
00101       //ignore
00102     }
00103   }
00104   
00105   throw UnrecognizedServiceInterfaceException ("ServiceInstanceDescription::getServiceTypeDescriptionWithInterfaceName : could not find ServiceInstanceDescription containing a Service Interface named " + interfaceName);
00106 }; // getServiceTypeDescriptionWithInterfaceName
00107 
00108 shared_ptr<ServiceTypeDescription> ServiceInstanceDescription::getServiceTypeDescriptionWithDataFeedName (std::string dataFeedName)
00109 {
00110   std::map<std::string, shared_ptr<ServiceTypeDescription> >::iterator it;
00111   
00112   for (it = serviceTypeDescriptions_.begin(); it != serviceTypeDescriptions_.end(); it++) {
00113     shared_ptr<ServiceTypeDescription> typeDescription = (*it).second;
00114     
00115     try {
00116       shared_ptr<DataFeedDescription> dfd = typeDescription->getDataFeedDescription (dataFeedName);
00117       return typeDescription;
00118     }
00119     catch (Exception e) {
00120       //ignore
00121     }
00122   }
00123   
00124   throw Exception ("ServiceInstanceDescription::getServiceTypeDescriptionWithDataFeedName : could not find ServiceTypeDescription containing a Data Feed named " + dataFeedName);
00125 } // getServiceTypeDescriptionWithDataFeedName()
00126 
00127 std::string ServiceInstanceDescription::getServiceInstanceName()
00128 {
00129   return serviceInstanceName_;
00130 }; // getServiceInstanceName()
00131 
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3