YarpServiceReplyConversionTask.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 YarpServiceReplyConversionTask.cpp
00024  * @Description YarpServiceReplyConversionTask implementation
00025  * @Status Work in Progress
00026  * @Version $Id: YarpServiceReplyConversionTask.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer
00028  */
00029 
00030 
00031 #include "config.h"
00032 
00033 #include "YarpServiceReplyConversionTask.hpp"
00034 
00035 #include <ActiveObject.hpp>
00036 #include "CommunicationGateway.hpp"
00037 #include <Exception.hpp>
00038 #include <ServiceReplyDeliveryTask.hpp>
00039 #include <Task.hpp>
00040 
00041 #include <iostream>
00042 
00043 using namespace mermaid::support::communication;
00044 using mermaid::support::activeobject::ActiveObject;
00045 using mermaid::support::activeobject::Task;
00046 using mermaid::support::errorhandling::Exception;
00047 using mermaid::support::service::ServiceReplyDeliveryTask;
00048 
00049 
00050 YarpServiceReplyConversionTask::YarpServiceReplyConversionTask (shared_ptr<Service> requesterService, YarpServiceAsynchReplyType &reply) : Task()
00051 {
00052   requesterService_ = requesterService;
00053   reply_ = shared_ptr<YarpServiceAsynchReplyType> (new YarpServiceAsynchReplyType (reply)); // copying because this object is under yarp's control
00054 }; // YarpServiceReplyConversionTask()
00055 
00056 void YarpServiceReplyConversionTask::run()
00057 {
00058   //std::cerr << "YarpServiceReplyConversionTask" << std::endl;
00059   try {
00060     //std::cerr << "YarpServiceReplyConversionTask::run()" << std::endl;
00061     
00062     std::string requesterEntityName = reply_->getRequesterEntityName();
00063     std::string requesterServiceName = reply_->getRequesterServiceName();
00064     int requestId = reply_->getRequestId();
00065     
00066 //         std::cerr << "YarpServiceReplyConversionTask::run() : reply with requestId=" << requestId << std::endl;
00067 
00068     //throw Exception("YarpServiceReplyConversionTask::run() : got here");
00069     
00070     shared_ptr<ActiveObject> ao = requesterService_->getActiveObject();
00071     shared_ptr<CommunicationGateway> commGateway = ao->getCommunicationGateway();
00072     
00073     shared_ptr<ServiceRequest> originalRequest = commGateway->getServiceRequest (requesterEntityName, requesterServiceName, requestId);
00074     shared_ptr<ServiceReply> serviceReply = reply_->convertToServiceReply (originalRequest);
00075     originalRequest->notifyReplyReceived();
00076     shared_ptr<Task> dt ( (Task*) new ServiceReplyDeliveryTask (requesterService_, serviceReply));
00077     ao->addTask (dt);
00078   }
00079   catch (Exception &e) {
00080     std::cerr << "YarpServiceReplyConversionTask::run : failed to create reply : " << e.what() << std::endl;
00081     
00082     if (reply_) {
00083       std::cerr << "\tBadly formatted reply data? : reply data was: \"" << reply_->getReplyData().toString().c_str() << "\"" << std::endl;
00084     }
00085   }
00086 }; // run()
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3