YarpServiceAsynchInputPort.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 YarpServiceAsynchInputPort.cpp
00024  * @Description YarpServiceAsynchInputPort implementation
00025  * @Status Work in Progress
00026  * @Version $Id: YarpServiceAsynchInputPort.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer
00028  */
00029 
00030 #include "config.h"
00031 
00032 #include "YarpServiceAsynchInputPort.hpp"
00033 #include "PortNamingConvention.hpp"
00034 #include "YarpServiceRequestConversionTask.hpp"
00035 
00036 #include <ActiveObject.hpp>
00037 #include <Entity.hpp>
00038 #include <EntityDescription.hpp>
00039 #include <Exception.hpp>
00040 #include <ServiceInstanceDescription.hpp>
00041 #include <ServiceInterfaceDescription.hpp>
00042 #include <ServiceRequest.hpp>
00043 #include <ServiceRequestDeliveryTask.hpp>
00044 #include <ServiceTypeDescription.hpp>
00045 #include <Task.hpp>
00046 
00047 #include <DataFactory.hpp>
00048 #include <DataValueVector.hpp>
00049 
00050 #include <iostream>
00051 
00052 using namespace mermaid::support::communication;
00053 
00054 using mermaid::support::activeobject::ActiveObject;
00055 using mermaid::support::activeobject::Task;
00056 using mermaid::support::errorhandling::Exception;
00057 using mermaid::support::service::Entity;
00058 using mermaid::support::service::EntityDescription;
00059 using mermaid::support::service::ServiceInstanceDescription;
00060 using mermaid::support::service::ServiceInterfaceDescription;
00061 using mermaid::support::service::ServiceRequest;
00062 using mermaid::support::service::ServiceRequestDeliveryTask;
00063 using mermaid::support::service::ServiceTypeDescription;
00064 
00065 using mermaid::support::data::DataFactory;
00066 using mermaid::support::data::DataValueVector;
00067 
00068 
00069 YarpServiceAsynchInputPort::YarpServiceAsynchInputPort (shared_ptr<Service> s) : BufferedPort<YarpServiceAsynchRequestType>()
00070 {
00071   //std::cerr << "YarpServiceAsynchInputPort::YarpServiceAsynchInputPort(service=" << s.get() << ")" << std::endl;
00072   targetService_ = s;
00073   
00074   std::string entityName = s->getEntity()->getEntityDescription()->getEntityName();
00075   std::string serviceName = s->getServiceInstanceDescription()->getServiceInstanceName();
00076   std::string portName = PortNamingConvention::getServiceRequestInputPortName (entityName, serviceName);
00077   
00078   //open port
00079   if (!open (portName.c_str())) {
00080     throw Exception ("YarpServiceAsynchInputPort::YarpServiceAsynchInputPort : could not open YARP port with name: " + portName);
00081   }
00082   this->useCallback();
00083   
00084   //set strict output
00085   this->setStrict (true);
00086   
00087 }; // YarpServiceAsynchInputPort()
00088 
00089 YarpServiceAsynchInputPort::~YarpServiceAsynchInputPort()
00090 {
00091   //std::cerr << "YarpServiceAsynchInputPort::~YarpServiceAsynchInputPort()" << std::endl;
00092 }; // ~YarpServiceAsynchInputPort()
00093 
00094 void YarpServiceAsynchInputPort::onRead (YarpServiceAsynchRequestType& request)
00095 {
00096   //std::cerr << "YarpServiceAsynchInputPort::onRead()" << std::endl;
00097   
00098   std::string targetEntityName = targetService_->getEntity()->getEntityDescription()->getEntityName();
00099   std::string targetServiceName = targetService_->getServiceInstanceDescription()->getServiceInstanceName();
00100   request.setTargetEntityName (targetEntityName);
00101   request.setTargetServiceName (targetServiceName);
00102   
00103   //This will be called from a thread controlled by YARP. We need to pass all the processing into an ActiveObject
00104   shared_ptr<Task> ct ( (Task*) new YarpServiceRequestConversionTask (targetService_, request));
00105   shared_ptr<ActiveObject> ao = targetService_->getActiveObject();
00106   ao->addTask (ct);
00107   
00108 }; // onRead()
00109 
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3