24 #ifndef OMG_DDS_RPC_REQUEST_REPLY_HH 25 #define OMG_DDS_RPC_REQUEST_REPLY_HH 30 #include "vendor_dependent.hh" 31 #include <dds/sample.hh> 50 class RequesterParams;
53 template <
typename TReq,
typename TRep>
56 template <
typename TReq,
typename TRep>
62 class COREDX_RPC_CPP_CLASS_EXPORT Exception :
public std::exception
66 Exception() : message_(NULL) { }
67 Exception(
const char *msg) { message_ = toc_strdup(msg); }
70 #if !defined(TOC_NO_EXCEPTIONS) 74 if (message_) toc_strfree(message_);
82 class COREDX_RPC_CPP_CLASS_EXPORT TimeoutException :
public Exception
85 TimeoutException() : Exception() { }
86 TimeoutException(
const char * msg ) : Exception( msg ) { }
113 template <
class TReq,
class TRep>
138 template <
class TReq,
class TRep>
162 template <
class TRep>
186 template <
class TReq,
class TRep>
227 bool is_null()
const;
231 template <
class Impl>
234 typedef DDS::rpc::rpc_entity_traits::RPCEntity * VendorDependent;
235 VendorDependent impl_;
238 VendorDependent get_impl()
const;
266 void bind(
const std::string & instance_name) {
267 ((VendorDependent)this->impl_)->bind(instance_name.c_str());
278 bool is_bound()
const;
284 const char * iname = ((VendorDependent)this->impl_)->get_bound_instance_name();
285 return std::string(iname?iname:
"");
294 return this->get_discovered_service_instances();
302 std::vector<std::string> retval;
303 instances = ((VendorDependent)this->impl_)->get_discovered_service_instances();
306 for (
unsigned int i = 0;i < instances->
size(); i++)
308 if ( (*instances)[i] )
309 retval.
push_back( std::string( (*instances)[i] ) );
319 uint32_t get_discovered_service_count()
const;
325 void wait_for_service();
338 ((VendorDependent)this->impl_)->wait_for_service(instanceName.c_str());
347 std::string instanceName) {
348 return ((VendorDependent)this->impl_)->wait_for_service(maxWait, instanceName.c_str());
355 void wait_for_services(uint32_t count);
369 for (
unsigned int i = 0; i < instanceNames.size(); i++)
370 instances.
push_back((
char*)instanceNames[i].c_str());
371 ((VendorDependent)this->impl_)->wait_for_services(&instances);
380 const std::vector<std::string> & instanceNames) {
382 for (
unsigned int i = 0; i < instanceNames.size(); i++)
383 instances.
push_back((
char*)instanceNames[i].c_str());
384 return ((VendorDependent)this->impl_)->wait_for_services(maxWait, &instances);
388 #if defined(CDX_HAS_FUTURE) && 0 389 future<void> wait_for_service_async();
390 future<void> wait_for_service_async(std::string instanceName);
391 future<void> wait_for_services_async(uint32_t count);
392 future<void> wait_for_services_async(
const std::vector<std::string> & instanceNames);
396 virtual void listener_process_reply(
const void * ,
398 virtual void listener_on_reply_available(
ServiceProxy * ) {}
401 typedef DDS::rpc::rpc_entity_traits::Requester * VendorDependent;
429 template <
typename TReq,
typename TRep>
434 typedef TReq RequestType;
435 typedef TRep ReplyType;
436 typedef typename DDS::dds_type_traits<TReq>::DataWriter RequestDataWriter;
437 typedef typename DDS::dds_type_traits<TRep>::DataReader ReplyDataReader;
441 typedef DDS::rpc::rpc_entity_traits::Requester * VendorDependent;
470 #if defined(CDX_HAS_FUTURE) 471 future<DDS::Sample<TRep> > send_request_async(
const TReq &);
474 #ifdef OMG_DDS_RPC_BASIC_PROFILE 479 void send_request(TReq & request);
484 void send_request_oneway(TReq &);
487 #ifdef OMG_DDS_RPC_ENHANCED_PROFILE 488 void send_request(
const TReq & request);
489 void send_request_oneway(
const TReq &);
551 bool wait_for_replies(uint32_t min_count,
569 bool wait_for_replies(uint32_t min_count,
675 bool receive_nondata_samples(
bool enable);
685 RequestDataWriter get_request_datawriter()
const;
690 ReplyDataReader get_reply_datareader()
const;
693 VendorDependent get_impl();
694 virtual void listener_process_reply(
const void * reply,
696 virtual void listener_on_reply_available(
ServiceProxy * sp );
718 virtual void listener_process_request(
const void * ,
720 virtual void listener_on_request_available(
ReplierBase * ) { }
724 friend struct coredx::rpc::ReplierImpl;
742 template <
typename TReq,
typename TRep>
747 typedef TReq RequestType;
748 typedef TRep ReplyType;
749 typedef typename DDS::dds_type_traits<TRep>::DataWriter ReplyDataWriter;
750 typedef typename DDS::dds_type_traits<TReq>::DataReader RequestDataReader;
754 typedef DDS::rpc::rpc_entity_traits::Replier * VendorDependent;
785 #ifdef OMG_DDS_RPC_BASIC_PROFILE 790 void send_reply(TRep & reply,
794 #ifdef OMG_DDS_RPC_ENHANCED_PROFILE 795 void send_reply(
const TRep & reply,
822 LoanedSamplesType receive_requests(uint32_t min_request_count,
823 uint32_t max_request_count,
835 bool wait_for_requests(uint32_t min_count,
857 LoanedSamplesType take_requests(
int max_samples);
878 LoanedSamplesType read_requests(
int max_samples);
890 bool receive_nondata_samples(
bool enable);
895 RequestDataReader get_request_datareader()
const;
900 ReplyDataWriter get_reply_datawriter()
const;
903 VendorDependent get_impl()
const;
905 virtual void listener_process_request(
const void * ,
907 virtual void listener_on_request_available(
ReplierBase * );
954 template <
class TRep>
961 template <
class TReq,
class TRep>
969 RequesterParams & domain_participant(dds_entity_traits::DomainParticipant participant);
981 RequesterParams & subscriber(dds_entity_traits::Subscriber subscriber);
986 RequesterParams & datawriter_qos(dds_entity_traits::DataWriterQos qos);
991 RequesterParams & datareader_qos(dds_entity_traits::DataReaderQos qos);
1002 toc_strfree( this->impl_->_service_name );
1003 this->impl_->_service_name = toc_strdup( name.c_str() );
1012 toc_strfree( this->impl_->_req_topic_name );
1013 this->impl_->_req_topic_name = toc_strdup( name.c_str() );
1022 toc_strfree( this->impl_->_rep_topic_name );
1023 this->impl_->_rep_topic_name = toc_strdup( name.c_str() );
1031 dds_entity_traits::DomainParticipant domain_participant()
const;
1036 dds_entity_traits::Publisher publisher()
const;
1041 dds_entity_traits::Subscriber subscriber()
const;
1046 dds_entity_traits::DataWriterQos datawriter_qos()
const;
1051 dds_entity_traits::DataReaderQos datareader_qos()
const;
1067 const char * i = this->impl_->_service_name;
1068 return std::string(i?i:
"" );
1075 const char * i = this->impl_->_req_topic_name;
1076 return std::string( i?i:
"");
1083 const char * i = this->impl_->_rep_topic_name;
1084 return std::string( i?i:
"" );
1089 typedef DDS::rpc::rpc_entity_traits::RequesterParams * VendorDependent;
1090 VendorDependent impl_;
1092 friend struct coredx::rpc::ServiceProxyImpl;
1095 VendorDependent get_impl()
const {
return this->impl_; }
1134 template <
class TReq,
class TRep>
1141 template <
class TReq,
class TRep>
1147 ReplierParams & domain_participant(dds_entity_traits::DomainParticipant participant);
1153 toc_strfree( this->impl_->_service_name );
1154 this->impl_->_service_name = toc_strdup( service_name.c_str() );
1162 toc_strfree( this->impl_->_instance_name );
1163 this->impl_->_instance_name = toc_strdup( instance_name.c_str() );
1171 toc_strfree( this->impl_->_req_topic_name );
1172 this->impl_->_req_topic_name = toc_strdup( req_topic.c_str() );
1180 toc_strfree( this->impl_->_rep_topic_name );
1181 this->impl_->_rep_topic_name = toc_strdup( rep_topic.c_str() );
1188 ReplierParams & datawriter_qos(dds_entity_traits::DataWriterQos qos);
1193 ReplierParams & datareader_qos(dds_entity_traits::DataReaderQos qos);
1198 ReplierParams & publisher(dds_entity_traits::Publisher publisher);
1203 ReplierParams & subscriber(dds_entity_traits::Subscriber subscriber);
1208 dds_entity_traits::DomainParticipant domain_participant()
const;
1221 const char * i = this->impl_->_service_name ;
1222 return std::string( i?i:
"" );
1228 const char * i = this->impl_->_instance_name;
1229 return std::string( i?i:
"" );
1235 const char * i = this->impl_->_req_topic_name;
1236 return std::string( i?i:
"" );
1242 const char * i = this->impl_->_rep_topic_name;
1243 return std::string( i?i:
"" );
1248 dds_entity_traits::DataWriterQos datawriter_qos()
const;
1252 dds_entity_traits::DataReaderQos datareader_qos()
const;
1256 dds_entity_traits::Publisher publisher()
const;
1260 dds_entity_traits::Subscriber subscriber()
const;
1264 typedef DDS::rpc::rpc_entity_traits::ReplierParams * VendorDependent;
1265 VendorDependent impl_;
1267 friend class coredx::rpc::Replier;
1268 friend struct coredx::rpc::ReplierImpl;
1271 VendorDependent get_impl()
const {
return this->impl_; }
1278 #include "request_reply_tmpl.hh" ReturnCode_t wait_for_service(const DDS::Duration_t &maxWait, std::string instanceName)
Block up to 'maxWait' until a service matching 'instanceNmae' is discovered.
Definition: request_reply.hh:346
SimpleRequesterListener can be installed on a Requester.
Definition: request_reply.hh:163
long ReturnCode_t
Definition: dds.hh:208
SimpleReplierListener can be installed on a Replier.
Definition: request_reply.hh:114
Basis for all rpc related listener classes.
Definition: request_reply.hh:95
A Requester sends requests and receives replies.
Definition: request_reply.hh:54
std::string reply_topic_name() const
Access the reply_topic_name configured in this instance of ReplierParams.
Definition: request_reply.hh:1241
RequesterParams & reply_topic_name(const std::string &name)
Assign the 'reply_topic_name'.
Definition: request_reply.hh:1021
void wait_for_services(const std::vector< std::string > &instanceNames)
Block until discovering a service for each of the listed 'instanceNames'.
Definition: request_reply.hh:367
A replier receives requests and send replies.
Definition: request_reply.hh:57
Holds a collection of sample data and related meta-data.
Definition: sample.hh:65
uint32_t size() const
Returns the current size (number of elements) of the sequence.
Definition: dds_seq.hh:218
void wait_for_service(std::string instanceName)
Wait for a service with matching 'instanceName' to be discovered.
Definition: request_reply.hh:337
Sequence data type.
Definition: dds_seq.hh:61
Holds a reference to sample data intended for transmission.
Definition: sample.hh:64
std::string service_name() const
Access the service_name configured in this instance of RequesterParams.
Definition: request_reply.hh:1066
ReplierParams & service_name(const std::string &service_name)
Assign the service_name configured in this instance of ReplierParams.
Definition: request_reply.hh:1152
Sample holds the data and related meta information.
Definition: sample.hh:61
std::string instance_name() const
Access the instance_name configured in this instance of ReplierParams.
Definition: request_reply.hh:1227
ReturnCode_t wait_for_services(const DDS::Duration_t &maxWait, const std::vector< std::string > &instanceNames)
Block until discovering a service for each of the listed 'instanceNames', or 'maxWait' elapses...
Definition: request_reply.hh:379
SampleRef holds a reference to data and related meta information.
Definition: sample.hh:62
std::string service_name() const
Access the service_name configured in this instance of ReplierParams.
Definition: request_reply.hh:1220
std::string request_topic_name() const
Access the request_topic_name configured in this instance of RequesterParams.
Definition: request_reply.hh:1074
Provides the DDS infrastructure.
Definition: dds_builtin_basic.hh:27
void bind(const std::string &instance_name)
Bind the ServiceProxy to service(s) with the provided 'instance_name'.
Definition: request_reply.hh:266
Holds sample data intended for transmission.
Definition: sample.hh:63
std::vector< std::string > get_discoverd_service_instances() const
Access a list of instance_names that have been discovered by the ServiceProxy.
Definition: request_reply.hh:293
Definition: dds_builtin_basic.hh:238
ReplierParams & instance_name(const std::string &instance_name)
Assign the instance_name configured in this instance of ReplierParams.
Definition: request_reply.hh:1161
ServiceProxy.
Definition: request_reply.hh:254
RPCEntity is a base abstract class.
Definition: request_reply.hh:206
ReplierParams & reply_topic_name(const std::string &rep_topic)
Assign the reply_topic_name configured in this instance of ReplierParams.
Definition: request_reply.hh:1179
Used to pass configuration parameters when constructing a Requester.
Definition: request_reply.hh:930
RequesterListener can be installed on a Requester.
Definition: request_reply.hh:187
Provides a generic basis for all Replier objects.
Definition: request_reply.hh:714
std::vector< std::string > get_discovered_service_instances() const
Access a list of instance_names that have been discovered by the ServiceProxy.
Definition: request_reply.hh:300
std::string reply_topic_name() const
Access the reply_topic_name configured in this instance of RequesterParams.
Definition: request_reply.hh:1082
RequesterParams & request_topic_name(const std::string &name)
Assign the 'request_topic_name' to use as the Request topic name.
Definition: request_reply.hh:1011
std::string request_topic_name() const
Access the request_topic_name configured in this instance of ReplierParams.
Definition: request_reply.hh:1234
Used to pass configuration parameters when constructing a Replier.
Definition: request_reply.hh:1110
bool push_back(const T &v)
Definition: dds_seq.hh:379
ReplierLister can be installed on a Replier.
Definition: request_reply.hh:139
std::string get_bound_instance_name() const
Provides the instance_name to which the ServiceProxy is currently bound.
Definition: request_reply.hh:283
ReplierParams & request_topic_name(const std::string &req_topic)
Assign the request_topic_name configured in this instance of ReplierParams.
Definition: request_reply.hh:1170
The Duration_t structure contains data to define a time duration.
Definition: dds_builtin_basic.hh:289
RequesterParams & service_name(const std::string &name)
Assign the service_name to use when creating the Request and Reply topic names.
Definition: request_reply.hh:1001