YarpServiceAsynchRequestPort.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 #include "config.h"
00031
00032 #include "YarpServiceAsynchRequestPort.hpp"
00033 #include "YarpServiceRequestPortReporter.hpp"
00034 #include "PortNamingConvention.hpp"
00035
00036 #include <Exception.hpp>
00037
00038 #include <yarp/os/all.h>
00039
00040 #include <iostream>
00041
00042 using namespace mermaid::support::communication;
00043
00044 using mermaid::support::errorhandling::Exception;
00045 using yarp::os::Network;
00046
00047 YarpServiceAsynchRequestPort::YarpServiceAsynchRequestPort (shared_ptr<Service> requesterService, shared_ptr<ServiceRequest> request) : BufferedPort<YarpServiceAsynchRequestType>()
00048 {
00049
00050
00051 requesterService_ = requesterService;
00052 request_ = request;
00053
00054
00055 std::string requesterEntityName = request_->getRequesterEntityName();
00056 std::string requesterServiceName = request_->getRequesterServiceName();
00057 std::string targetEntityName = request_->getTargetEntityName();
00058 std::string targetServiceName = request_->getTargetServiceName();
00059
00060
00061 std::string portName = PortNamingConvention::getServiceRequestRequestPortName (requesterEntityName, requesterServiceName, targetEntityName, targetServiceName);
00062
00063
00064 if (!open (portName.c_str())) {
00065 throw Exception ("YarpServiceAsynchRequestPort::YarpServiceAsynchRequestPort : could not open YARP port with name: " + portName);
00066 }
00067
00068
00069 this->setStrict (true);
00070
00071
00072 setReporter (* (new YarpServiceRequestPortReporter (this)));
00073
00074 };
00075
00076
00077 YarpServiceAsynchRequestType& YarpServiceAsynchRequestPort::prepare()
00078 {
00079
00080
00081
00082
00083 if (getOutputCount() == 0) {
00084 std::string targetServiceInputPortName;
00085 #ifdef USE_COMM
00086 std::string requesterEntityName = request_->getRequesterEntityName();
00087 std::string targetEntityName = request_->getTargetEntityName();
00088 if (requesterEntityName == targetEntityName)
00089 targetServiceInputPortName = PortNamingConvention::getServiceRequestInputPortName (targetEntityName, request_->getTargetServiceName());
00090 else
00091 targetServiceInputPortName = PortNamingConvention::getServiceRequestInputPortName (requesterEntityName, "COMM");
00092 #else
00093 targetServiceInputPortName = PortNamingConvention::getServiceRequestInputPortName (request_->getTargetEntityName(), request_->getTargetServiceName());
00094 #endif
00095
00096
00097 bool connectOk = Network::connect (this->getName().c_str(), targetServiceInputPortName.c_str());
00098 if (!connectOk) {
00099 throw Exception ("YarpServiceAsynchRequestPort::prepare() : could not connect to service with port name: " + targetServiceInputPortName);
00100 }
00101 else {
00102
00103 }
00104
00105 };
00106
00107 return BufferedPort<YarpServiceAsynchRequestType>::prepare();
00108 };