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 #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
00081
00082
00083
00084 class CommunicationGateway
00085 {
00086 public:
00087
00088 CommunicationGateway();
00089 ~CommunicationGateway();
00090
00091
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
00107
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
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
00133
00134
00135 std::map<std::pair<std::string, std::string>, std::map<std::pair<std::string, std::string>, shared_ptr<YarpServiceAsynchRequestPort> > > serviceAsynchRequestPorts_;
00136
00137
00138 std::map<std::pair<std::string, std::string>, std::map<std::pair<std::string, std::string>, shared_ptr<YarpServiceAsynchReplyPort> > > serviceAsynchReplyPorts_;
00139
00140
00141 std::map<std::string, shared_ptr<YarpServiceAsynchInputPort> > serviceAsynchInputPorts_;
00142
00143
00144 std::map<std::pair<std::string, std::string>, std::map<std::pair<std::string, std::string>, shared_ptr<YarpServiceAsynchOutputPort> > > serviceAsynchOutputPorts_;
00145
00146
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
00150 std::map<std::string, std::map<std::string, std::map<std::string, shared_ptr<YarpDataFeedOutputPort> > > > dataFeedOutputPorts_;
00151
00152
00153 std::map<std::string, std::map<std::string, std::map<int, shared_ptr<ServiceRequest> > > > serviceRequests_;
00154
00155 #ifdef USE_COMM
00156
00157 std::vector<shared_ptr<Task> > dataFeedSetupTasks_;
00158 bool executingSetupTask_;
00159 #endif
00160
00161 };
00162 }
00163 }
00164 }
00165
00166
00167 #endif // __COMMUNICATION_COMMUNICATIONGATEWAY_H