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