YarpServiceReplyConversionTask.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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));
00054 };
00055
00056 void YarpServiceReplyConversionTask::run()
00057 {
00058
00059 try {
00060
00061
00062 std::string requesterEntityName = reply_->getRequesterEntityName();
00063 std::string requesterServiceName = reply_->getRequesterServiceName();
00064 int requestId = reply_->getRequestId();
00065
00066
00067
00068
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 };