YarpDataFeedSetupTask.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 #ifdef USE_COMM
00031
00032 #include "config.h"
00033
00034 #include "YarpDataFeedSetupTask.hpp"
00035 #include "CommunicationGateway.hpp"
00036
00037 #include <Entity.hpp>
00038 #include <EntityDescription.hpp>
00039 #include <ServiceReplyHandlerMethod.hpp>
00040
00041 #include <Time.hpp>
00042 #include <ace/Date_Time.h>
00043
00044 #include <iostream>
00045
00046 using namespace mermaid::support::communication;
00047
00048 using mermaid::support::system::Time;
00049 using mermaid::support::communication::CommunicationGateway;
00050 using mermaid::support::service::Entity;
00051 using mermaid::support::service::EntityDescription;
00052 using mermaid::support::service::ServiceReplyHandlerMethodBase;
00053 using mermaid::support::service::ServiceReplyHandlerMethod;
00054
00055 YarpDataFeedSetupTask::YarpDataFeedSetupTask (shared_ptr<Service> requesterService, std::string producerEntityName,
00056 std::string producerServiceName, std::string dataFeedName, shared_ptr<ActiveObject> ao) : Task (Time::getCurrentTime(), true, 1.0)
00057 {
00058 requesterService_ = requesterService;
00059 producerEntityName_ = producerEntityName;
00060 producerServiceName_ = producerServiceName;
00061 dataFeedName_ = dataFeedName;
00062 activeObject_ = ao;
00063 };
00064
00065 void YarpDataFeedSetupTask::run()
00066 {
00067 std::cerr << "Attempting to setup Data Feed : " << producerEntityName_ << "::" << producerServiceName_ << "::" << dataFeedName_ << std::endl;
00068 std::string requesterEntityName = requesterService_->getEntity()->getEntityDescription()->getEntityName();
00069 if (requesterEntityName != producerEntityName_) {
00070 shared_ptr<ServiceRequest> sr = requesterService_->makeNewServiceRequest (requesterEntityName, "COMM", "setUpDataFeed");
00071 shared_ptr<DataBox> db = sr->getRequestDataBox();
00072 db->setString ("TargetEntity", producerEntityName_);
00073 db->setString ("TargetService", producerServiceName_);
00074 db->setString ("DataFeedName", dataFeedName_);
00075 shared_ptr<ServiceReplyHandlerMethodBase> setupDataFeedHandlerMethod (new ServiceReplyHandlerMethod<YarpDataFeedSetupTask> (this, &YarpDataFeedSetupTask::treatCommReply));
00076 requesterService_->sendServiceRequest (sr, setupDataFeedHandlerMethod);
00077 }
00078 else {
00079 cancelRepeat();
00080 }
00081 };
00082
00083 void YarpDataFeedSetupTask::treatCommReply (shared_ptr<ServiceReply> reply)
00084 {
00085 if (reply->executionIsOk() == true) {
00086 cancelRepeat();
00087 shared_ptr<CommunicationGateway> commGateway = activeObject_->getCommunicationGateway();
00088 commGateway->notifyDataFeedSetupEnded();
00089
00090 if (commGateway->isNewDataFeedSetupTaskAvailable()) {
00091 std::cout << "YarpDataFeedSetupTask::treatCommReply : adding following YarpDataFeedSetupTask" << std::endl;
00092 activeObject_->addTask (commGateway->getDataFeedSetupTask());
00093 }
00094 else {
00095 std::cout << "YarpDataFeedSetupTask::treatCommReply : no more YarpDataFeedSetupTask available" << std::endl;
00096 }
00097
00098 }
00099
00100 };
00101
00102 #endif // USE_COMM