CommunicationGateway.hpp

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 CommunicationGateway.hpp
00024  * @Description CommunicationGateway declaration
00025  * @Status Work in Progress
00026  * @Version $Id: CommunicationGateway.hpp 1 2011-03-04 18:13:18Z jreis $
00027  * @Maintainer
00028  */
00029 
00030 #ifndef __COMMUNICATION_COMMUNICATIONGATEWAY_H
00031 #define __COMMUNICATION_COMMUNICATIONGATEWAY_H
00032 
00033 namespace mermaid
00034 {
00035   namespace support
00036   {
00037     namespace communication
00038     {
00039       class CommunicationGateway;
00040     }
00041   }
00042 }
00043 
00044 
00045 #include <DataBox.hpp>
00046 
00047 #include "YarpDataFeedInputPort.hpp"
00048 #include "YarpDataFeedOutputPort.hpp"
00049 #include "YarpServiceAsynchInputPort.hpp"
00050 #include "YarpServiceAsynchReplyPort.hpp"
00051 #include "YarpServiceAsynchRequestPort.hpp"
00052 #include "YarpServiceAsynchOutputPort.hpp"
00053 
00054 #ifdef USE_COMM
00055 #include <Task.hpp>
00056 #endif
00057 
00058 #include <map>
00059 #include <vector>
00060 
00061 namespace mermaid
00062 {
00063   namespace support
00064   {
00065     namespace communication
00066     {
00067       using mermaid::support::data::DataBox;
00068       using boost::shared_ptr;
00069       
00070       using mermaid::support::service::Service;
00071       using mermaid::support::service::ServiceReply;
00072       using mermaid::support::service::ServiceRequest;
00073       using std::vector;
00074       
00075 #ifdef USE_COMM
00076       using mermaid::support::activeobject::Task;
00077 #endif
00078       
00079       /**
00080       * @Class CommunicationGateway CommunicationGateway.hpp "CommunicationGateway.hpp"
00081       * @Description CommunicationGateway class.
00082       * @Author Marco Barbosa
00083       */
00084       class CommunicationGateway
00085       {
00086         public:
00087         
00088           CommunicationGateway();
00089           ~CommunicationGateway();
00090           
00091           //service stuff
00092           
00093           void registerService (shared_ptr<Service> s);
00094           void sendServiceRequest (shared_ptr<Service> requesterService, shared_ptr<ServiceRequest> sr);
00095           
00096           void sendServiceReply (shared_ptr<Service> targetService, std::string requesterEntityName, std::string requesterServiceName, shared_ptr<ServiceReply> sr);
00097           
00098           
00099           shared_ptr<YarpServiceAsynchRequestPort> getYarpServiceAsynchRequestPort (shared_ptr<Service> requesterService, shared_ptr<ServiceRequest> request);
00100           
00101           shared_ptr<YarpServiceAsynchReplyPort> getYarpServiceAsynchReplyPort (std::string targetEntityName, std::string targetServiceName, std::string requesterEntityName, std::string requesterServiceName);
00102           
00103           shared_ptr<YarpServiceAsynchOutputPort> getYarpServiceAsynchOutputPort (shared_ptr<Service> targetService, std::string requesterEntityName, std::string requesterServiceName);
00104           
00105           
00106           //data feed stuff
00107 //                     void initializeDataFeed(std::string serviceName, std::string dataFeedName);
00108           void sendToDataFeed (std::string entityName, std::string serviceName, std::string dataFeedName, shared_ptr<DataBox> dataBox);
00109           void connectToDataFeed (std::string producerEntityName, std::string producerServiceName, std::string datafeedName, shared_ptr<Service> consumerService);
00110           
00111           
00112           void addYarpDataFeedOutputPort (shared_ptr<YarpDataFeedOutputPort> outputPort);
00113           shared_ptr<YarpDataFeedOutputPort> getYarpDataFeedOutputPort (std::string entityName, std::string serviceName, std::string feedName);
00114           
00115           void addYarpDataFeedInputPort (shared_ptr<YarpDataFeedInputPort> inputPort);
00116           shared_ptr<YarpDataFeedInputPort> getYarpDataFeedInputPort (std::string consumerEntityName, std::string consumerServiceName, std::string producerEntityName, std::string producerServiceName, std::string dataFeedName);
00117           
00118           //ServiceRequest map access
00119           void registerServiceRequest (shared_ptr<ServiceRequest> request);
00120           shared_ptr<ServiceRequest> getServiceRequest (std::string requesterEntityName, std::string requesterServiceName, int requestId);
00121           void unregisterServiceRequest (std::string requesterEntityName, std::string requesterServiceName, int requestId);
00122           
00123 #ifdef USE_COMM
00124           void addDataFeedSetupTask (shared_ptr<Task> dst);
00125           bool isNewDataFeedSetupTaskAvailable();
00126           shared_ptr<Task> getDataFeedSetupTask();
00127           void notifyDataFeedSetupEnded();
00128 #endif
00129           
00130         private:
00131         
00132           //asynch service request ports
00133           
00134           //map: pair<reqEnt,reqSer>->pair<tarEnt,tarSer>->requestPort
00135           std::map<std::pair<std::string, std::string>, std::map<std::pair<std::string, std::string>, shared_ptr<YarpServiceAsynchRequestPort> > > serviceAsynchRequestPorts_;
00136           
00137           //map: pair<reqEnt,reqSer>->pair<tarEnt,tarSer>->replyPort
00138           std::map<std::pair<std::string, std::string>, std::map<std::pair<std::string, std::string>, shared_ptr<YarpServiceAsynchReplyPort> > > serviceAsynchReplyPorts_;
00139           
00140           //map: serviceName->inputPort
00141           std::map<std::string, shared_ptr<YarpServiceAsynchInputPort> > serviceAsynchInputPorts_;
00142           
00143           //map: pair<reqEnt,reqSer>->pair<tarEnt,tarSer>->outputPort
00144           std::map<std::pair<std::string, std::string>, std::map<std::pair<std::string, std::string>, shared_ptr<YarpServiceAsynchOutputPort> > > serviceAsynchOutputPorts_;
00145           
00146           //data-feed ports: consumerEntityName -> consumerServiceName -> producerEntityName -> producerServiceName -> dataFeedName -> inputPort
00147           std::map<std::string, std::map<std::string, std::map<std::string, std::map<std::string, std::map<std::string, shared_ptr<YarpDataFeedInputPort> > > > > > dataFeedInputPorts_;
00148           
00149           //map: entityName -> serviceName -> feedname -> outputPort
00150           std::map<std::string, std::map<std::string, std::map<std::string, shared_ptr<YarpDataFeedOutputPort> > > > dataFeedOutputPorts_;
00151           
00152           //map: req entity name -> req. service name -> req. id -> ServiceRequest
00153           std::map<std::string, std::map<std::string, std::map<int, shared_ptr<ServiceRequest> > > > serviceRequests_;
00154           
00155 #ifdef USE_COMM
00156           //vector of data feed setup tasks
00157           std::vector<shared_ptr<Task> > dataFeedSetupTasks_;
00158           bool executingSetupTask_;
00159 #endif
00160           
00161       }; // class CommunicationGateway
00162     } // namespace communication
00163   } // namespace support
00164 } // namespace mermaid
00165 
00166 
00167 #endif // __COMMUNICATION_COMMUNICATIONGATEWAY_H
Generated on Fri Mar 4 22:14:58 2011 for MeRMaID::support by  doxygen 1.6.3