CoreDX Data Distribution Service
The High Performance, Small Footprint DDS from Twin Oaks Computing, Inc
function_call.hh
Go to the documentation of this file.
1 /*****************************************************************
2  *
3  * file: function_call.hh
4  * desc:
5  *
6  *****************************************************************
7  *
8  * Copyright(C) 2014-2016 Twin Oaks Computing, Inc
9  * All rights reserved. Castle Rock, CO 80108
10  *
11  *****************************************************************
12  *
13  * This software has been provided pursuant to a License Agreement
14  * containing restrictions on its use. This software contains
15  * valuable trade secrets and proprietary information of
16  * Twin Oaks Computing, Inc and is protected by law. It may not be
17  * copied or distributed in any form or medium, disclosed to third
18  * parties, reverse engineered or used in any manner not provided
19  * for in said License Agreement except with the prior written
20  * authorization from Twin Oaks Computing, Inc.
21  *
22  *****************************************************************/
23 
24 #ifndef OMG_DDS_RPC_FUNCTION_CALL_HH
25 #define OMG_DDS_RPC_FUNCTION_CALL_HH
26 
27 #include <dds/request_reply.hh>
28 
35 namespace DDS
36 {
37  namespace rpc
38  {
39  // -------------------------------------------------------------------
40  // -------------------------------------------------------------------
47  };
48 
49  // -------------------------------------------------------------------
50  // -------------------------------------------------------------------
51  template <class Iface>
52  struct interface_traits
53  {
54  typedef Iface InterfaceType;
55  typedef typename Iface::ProxyType ProxyType;
56  typedef typename Iface::RequestType RequestType;
57  typedef typename Iface::ReplyType ReplyType;
58  };
59 
60  // -------------------------------------------------------------------
61  // ServiceParams
62  // -------------------------------------------------------------------
72  class COREDX_RPC_CPP_CLASS_EXPORT ServiceParams
73  {
74  public:
78  ServiceParams();
82  ServiceParams(const ServiceParams & other);
86  ServiceParams & operator = (const ServiceParams & that);
87 
91  ServiceParams & service_name(const std::string &service_name) {
92  this->_params.service_name(service_name);
93  return *this;
94  }
98  ServiceParams & instance_name(const std::string &instance_name) {
99  this->_params.instance_name(instance_name);
100  return *this;
101  }
105  ServiceParams & request_topic_name(const std::string &req_topic) {
106  this->_params.request_topic_name(req_topic);
107  return *this;
108  }
112  ServiceParams & reply_topic_name(const std::string &rep_topic) {
113  this->_params.reply_topic_name(rep_topic);
114  return *this;
115  }
119  ServiceParams & datawriter_qos(dds_entity_traits::DataWriterQos qos);
123  ServiceParams & datareader_qos(dds_entity_traits::DataReaderQos qos);
127  ServiceParams & publisher(dds_entity_traits::Publisher publisher);
131  ServiceParams & subscriber(dds_entity_traits::Subscriber subscriber);
135  ServiceParams & domain_participant(dds_entity_traits::DomainParticipant part);
136 
140  std::string service_name() const {
141  return this->_params.service_name();
142  }
146  std::string instance_name() const {
147  return this->_params.instance_name();
148  }
152  std::string request_topic_name() const {
153  return this->_params.request_topic_name();
154  }
158  std::string reply_topic_name() const {
159  return this->_params.reply_topic_name();
160  }
164  dds_entity_traits::DataWriterQos datawriter_qos() const;
168  dds_entity_traits::DataReaderQos datareader_qos() const;
172  dds_entity_traits::Publisher publisher() const;
176  dds_entity_traits::Subscriber subscriber() const;
180  dds_entity_traits::DomainParticipant domain_participant() const;
181 
182  const ReplierParams & get_params() const { return _params; }
183 
184  protected:
185  ReplierParams _params;
186  };
187 
188  // -------------------------------------------------------------------
189  // ClientParams
190  // -------------------------------------------------------------------
200  class COREDX_RPC_CPP_CLASS_EXPORT ClientParams
201  {
202  public:
206  ClientParams();
210  ~ClientParams ();
214  ClientParams(const ClientParams & other);
215  ClientParams(const RequesterParams & rp,
216  std::string instance_name,
217  DDS::Duration_t & timeout ) {
218  this->_params = rp;
219  this->_instance_name = toc_strdup(instance_name.c_str());
220  this->_timeout = timeout;
221  }
225  ClientParams & operator = (const ClientParams & that);
226 
230  ClientParams & timeout(const DDS::Duration_t & t );
234  ClientParams & service_name(const std::string &service_name) {
235  this->_params.service_name(service_name);
236  return *this;
237  }
241  ClientParams & instance_name(const std::string &instance_name) {
242  toc_strfree( this->_instance_name );
243  this->_instance_name = toc_strdup(instance_name.c_str() );
244  return *this;
245  }
249  ClientParams & request_topic_name(const std::string &req_topic) {
250  this->_params.request_topic_name(req_topic);
251  return *this;
252  }
256  ClientParams & reply_topic_name(const std::string &rep_topic) {
257  this->_params.reply_topic_name(rep_topic);
258  return *this;
259  }
263  ClientParams & datawriter_qos(const dds_entity_traits::DataWriterQos & qos);
267  ClientParams & datareader_qos(const dds_entity_traits::DataReaderQos & qos);
271  ClientParams & publisher(dds_entity_traits::Publisher publisher);
275  ClientParams & subscriber(dds_entity_traits::Subscriber subscriber);
279  ClientParams & domain_participant(dds_entity_traits::DomainParticipant part);
280 
284  const DDS::Duration_t timeout() const;
288  const std::string service_name() const {
289  return this->_params.service_name();
290  }
294  const std::string instance_name() const {
295  return std::string(this->_instance_name?this->_instance_name:"");
296  }
300  const std::string request_topic_name() const {
301  return this->_params.request_topic_name();
302  }
306  const std::string reply_topic_name() const {
307  return this->_params.reply_topic_name();
308  }
312  const dds_entity_traits::DataWriterQos datawriter_qos() const;
316  const dds_entity_traits::DataReaderQos datareader_qos() const;
320  dds_entity_traits::Publisher publisher() const;
324  dds_entity_traits::Subscriber subscriber() const;
328  dds_entity_traits::DomainParticipant domain_participant() const;
329 
330  const RequesterParams & get_req_params() const { return _params; }
331 
332  protected:
333  RequesterParams _params;
334  char * _instance_name;
335  DDS::Duration_t _timeout;
336  };
337 
338  // -------------------------------------------------------------------
339  // ServiceEndpoint
340  // -------------------------------------------------------------------
350  class COREDX_RPC_CPP_CLASS_EXPORT ServiceEndpoint : public RPCEntity
351  {
352  protected:
353 
354  template <class Impl>
355  explicit ServiceEndpoint(Impl impl);
356 
357  public:
358  typedef rpc_entity_traits::ServiceEndpoint * VendorDependent;
359 
363  ServiceEndpoint();
364 
368  template <class TReq>
369  typename dds_type_traits<TReq>::DataReader get_request_datareader() const;
373  template <class TRep>
374  typename dds_type_traits<TRep>::DataWriter get_reply_datawriter() const;
375 
380  void pause();
387  void resume();
391  ServiceStatus status() const;
395  ServiceParams get_service_params() const;
396  VendorDependent get_impl() const;
397 
398  protected:
399  ServiceStatus _status;
400  };
401 
402  // -------------------------------------------------------------------
403  // ClientEndpoint
404  // -------------------------------------------------------------------
413  class COREDX_RPC_CPP_CLASS_EXPORT ClientEndpoint : public ServiceProxy
414  {
415  protected:
416  DDS::Duration_t timeout;
417 
418  public:
422  ClientEndpoint( const DDS::Duration_t & tout ) { this->timeout = tout; }
423 
427  template <class TReq>
428  typename dds_type_traits<TReq>::DataWriter get_request_datawriter() const;
432  template <class TRep>
433  typename dds_type_traits<TRep>::DataReader get_reply_datareader() const;
439  RequesterParams rp = ((VendorDependent)this->impl_)->get_rparams( );
440  ClientParams cp( rp, this->get_bound_instance_name(), this->timeout );
441  return cp;
442  }
443 
444  };
445 
446 #if defined(CDX_HAS_RPC_SERVER)
447  /* Note the current spec for Server is incomplete. */
448  class Server;
449 
450  // -------------------------------------------------------------------
451  // ServerParams
452  // -------------------------------------------------------------------
458  class ServerParams
459  {
460  public:
461  ServerParams();
462  ServerParams(const ServerParams & other);
463  ServerParams & operator = (const ServerParams & that);
464  ServerParams & default_service_params(const ServiceParams & service_params);
465  ServiceParams default_service_params() const;
466 
467  protected:
468  typedef rpc_entity_traits::ServerParams * VendorDependent;
469  VendorDependent impl_;
470 
471  public:
472  VendorDependent get_impl() const;
473  };
474 
475  // -------------------------------------------------------------------
476  // Server
477  // -------------------------------------------------------------------
487  class Server : public RPCEntity
488  {
489  public:
490  //typedef details::vendor_dependent<Server>::type VendorDependent;
491  typedef rpc_entity_traits::Server * VendorDependent;
492 
493  // may reuse an exising participant
494  Server();
495  explicit Server(const ServerParams & server_params);
496 
497  void run(); // blocking
498  void run(const DDS::Duration_t & max_wait); // non-blocking
499  VendorDependent get_impl() const;
500 
501  // SPEC: if 'Server' contains multiple 'Service's,
502  // how do we add a 'Service' to the 'Server' ?
503 
504  };
505 #endif
506 
507  template <class TReq>
508  typename dds_type_traits<TReq>::DataWriter
510  {
511  return (typename dds_type_traits<TReq>::DataWriter)
512  ((VendorDependent)this->impl_)->get_req_dw( );
513  }
514 
515  template <class TRep>
516  typename dds_type_traits<TRep>::DataReader
518  {
519  return (typename dds_type_traits<TRep>::DataReader)
520  ((VendorDependent)this->impl_)->get_rep_dr( );
521  }
522 
523  } // namespace rpc
524 } // namespace dds
525 
526 #endif
527 
Definition: function_call.hh:44
ServiceParams & reply_topic_name(const std::string &rep_topic)
Assign the reply_topic_name configured in this instance of ServiceParams.
Definition: function_call.hh:112
const std::string request_topic_name() const
Access the request_topic_name configured in this instance of ClientParams.
Definition: function_call.hh:300
ServiceStatus
Definition: function_call.hh:44
std::string reply_topic_name() const
Access the reply_topic_name configured in this instance of ServiceParams.
Definition: function_call.hh:158
std::string service_name() const
Access the service_name configured in this instance of ServiceParams.
Definition: function_call.hh:140
std::string instance_name() const
Access the instance_name configured in this instance of ServiceParams.
Definition: function_call.hh:146
ClientEndpoint(const DDS::Duration_t &tout)
Default constructor.
Definition: function_call.hh:422
ClientParams & service_name(const std::string &service_name)
Assign the service_name configured in this instance of ClientParams.
Definition: function_call.hh:234
ClientParams & request_topic_name(const std::string &req_topic)
Assign the request_topic_name configured in this instance of ClientParams.
Definition: function_call.hh:249
Used to pass configuration parameters when constructing a Service.
Definition: function_call.hh:72
ServiceParams & request_topic_name(const std::string &req_topic)
Assign the request_topic_name configured in this instance of ServiceParams.
Definition: function_call.hh:105
ServiceParams & service_name(const std::string &service_name)
Assign the service_name configured in this instance of ServiceParams.
Definition: function_call.hh:91
Used to pass configuration parameters when constructing a Client.
Definition: function_call.hh:200
Definition: function_call.hh:350
const std::string service_name() const
Access the service_name configured in this instance of ClientParams.
Definition: function_call.hh:288
Definition: function_call.hh:46
const std::string instance_name() const
Access the instance_name configured in this instance of ClientParams.
Definition: function_call.hh:294
Provides the DDS infrastructure.
Definition: dds_builtin_basic.hh:27
ClientParams & reply_topic_name(const std::string &rep_topic)
Assign the reply_topic_name configured in this instance of ClientParams.
Definition: function_call.hh:256
dds_type_traits< TReq >::DataWriter get_request_datawriter() const
Access the DataWriter used to send TReq requests.
Definition: function_call.hh:509
Definition: function_call.hh:413
ServiceProxy.
Definition: request_reply.hh:254
RPCEntity is a base abstract class.
Definition: request_reply.hh:206
dds_type_traits< TRep >::DataReader get_reply_datareader() const
Access the DataReader used to receive TRep replies.
Definition: function_call.hh:517
Used to pass configuration parameters when constructing a Requester.
Definition: request_reply.hh:930
DDS::rpc::ClientParams get_client_params()
Access the ClientParams defining the configuration of this ClientEndpoint.
Definition: function_call.hh:438
ServiceParams & instance_name(const std::string &instance_name)
Assign the instance_name configured in this instance of ServiceParams.
Definition: function_call.hh:98
const std::string reply_topic_name() const
Access the reply_topic_name configured in this instance of ClientParams.
Definition: function_call.hh:306
std::string request_topic_name() const
Access the request_topic_name configured in this instance of ServiceParams.
Definition: function_call.hh:152
ClientParams & instance_name(const std::string &instance_name)
Assign the instance_name configured in this instance of ClientParams.
Definition: function_call.hh:241
Definition: function_call.hh:45
Used to pass configuration parameters when constructing a Replier.
Definition: request_reply.hh:1110
The Duration_t structure contains data to define a time duration.
Definition: dds_builtin_basic.hh:289

© 2009-2020 Twin Oaks Computing, Inc
Castle Rock, CO 80104
All rights reserved.