YarpDataFeedSetupTask.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 YarpDataFeedSetupTask.cpp
00024  * @Description YarpDataFeedSetupTask implementation
00025  * @Status Work in Progress
00026  * @Version $Id: YarpDataFeedSetupTask.cpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer
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 }; // YarpDataFeedSetupTask()
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 }; // run()
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 }; //treatCommReply()
00101 
00102 #endif // USE_COMM
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3