YarpServiceAsynchOutputPort.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 "YarpServiceAsynchOutputPort.hpp"
00033 #include "PortNamingConvention.hpp"
00034
00035 #include <Entity.hpp>
00036 #include <EntityDescription.hpp>
00037 #include <Exception.hpp>
00038 #include <Service.hpp>
00039 #include <ServiceInterfaceDescription.hpp>
00040
00041 #include <yarp/os/all.h>
00042
00043 #include <iostream>
00044
00045 using namespace mermaid::support::communication;
00046
00047 using mermaid::support::errorhandling::Exception;
00048 using mermaid::support::service::Entity;
00049 using mermaid::support::service::EntityDescription;
00050 using mermaid::support::service::Service;
00051 using mermaid::support::service::ServiceInterfaceDescription;
00052
00053 using yarp::os::Network;
00054
00055 YarpServiceAsynchOutputPort::YarpServiceAsynchOutputPort (shared_ptr<Service> targetService, std::string requesterEntityName, std::string requesterServiceName) : BufferedPort<YarpServiceAsynchReplyType>()
00056 {
00057
00058
00059 targetService_ = targetService;
00060 requesterEntityName_ = requesterEntityName;
00061 requesterServiceName_ = requesterServiceName;
00062
00063 std::string targetEntityName = targetService->getEntity()->getEntityDescription()->getEntityName();
00064 std::string targetServiceName = targetService->getServiceInstanceDescription()->getServiceInstanceName();
00065
00066 std::string outputPortName = PortNamingConvention::getServiceRequestOutputPortName (targetEntityName, targetServiceName, requesterEntityName, requesterServiceName);
00067
00068
00069 if (!open (outputPortName.c_str())) {
00070 throw Exception ("YarpServiceAsynchOutputPort::YarpServiceAsynchOutputPort: could not open YARP port with name: " + outputPortName);
00071 }
00072
00073
00074 this->setStrict (true);
00075
00076 };
00077
00078
00079 YarpServiceAsynchReplyType& YarpServiceAsynchOutputPort::prepare()
00080 {
00081
00082 if (getOutputCount() == 0) {
00083 std::string targetEntityName = targetService_->getEntity()->getEntityDescription()->getEntityName();
00084 std::string targetServiceName = targetService_->getServiceInstanceDescription()->getServiceInstanceName();
00085
00086 std::string requesterServiceReplyPortName = PortNamingConvention::getServiceRequestReplyPortName (requesterEntityName_, requesterServiceName_, targetEntityName, targetServiceName);
00087
00088
00089 bool connectOk = Network::connect (this->getName().c_str(), requesterServiceReplyPortName.c_str());
00090 if (!connectOk) {
00091 throw Exception ("YarpServiceAsynchOutputPort::prepare() : could not connect to client with port name: \"" + requesterServiceReplyPortName + "\"");
00092 }
00093 else {
00094
00095 }
00096 };
00097
00098 return BufferedPort<YarpServiceAsynchReplyType>::prepare();
00099 };