CoreDX DDS C++ Reference Manual
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  // Exception
62  // -------------------------------------------------------------------
63  class Exception : public std::exception
64  {
65  std::string message_;
66 
67  public:
68  Exception();
69  Exception(const char *msg);
70 
71  virtual ~Exception() throw();
72  virtual void raise() const = 0;
73  };
74 
75  // -------------------------------------------------------------------
76  // ServiceParams
77  // -------------------------------------------------------------------
88  {
89  public:
93  ServiceParams();
97  ServiceParams(const ServiceParams & other);
101  ServiceParams & operator = (const ServiceParams & that);
102 
106  ServiceParams & service_name(const std::string &service_name);
110  ServiceParams & instance_name(const std::string &instance_name);
114  ServiceParams & request_topic_name(const std::string &req_topic);
118  ServiceParams & reply_topic_name(const std::string &rep_topic);
122  ServiceParams & datawriter_qos(dds_entity_traits::DataWriterQos qos);
126  ServiceParams & datareader_qos(dds_entity_traits::DataReaderQos qos);
130  ServiceParams & publisher(dds_entity_traits::Publisher publisher);
134  ServiceParams & subscriber(dds_entity_traits::Subscriber subscriber);
138  ServiceParams & domain_participant(dds_entity_traits::DomainParticipant part);
139 
143  std::string service_name() const;
147  std::string instance_name() const;
151  std::string request_topic_name() const;
155  std::string reply_topic_name() const;
159  dds_entity_traits::DataWriterQos datawriter_qos() const;
163  dds_entity_traits::DataReaderQos datareader_qos() const;
167  dds_entity_traits::Publisher publisher() const;
171  dds_entity_traits::Subscriber subscriber() const;
175  dds_entity_traits::DomainParticipant domain_participant() const;
176 
177  const ReplierParams & get_params() const { return _params; }
178 
179  protected:
180  ReplierParams _params;
181  };
182 
183  // -------------------------------------------------------------------
184  // ClientParams
185  // -------------------------------------------------------------------
196  {
197  public:
201  ClientParams();
205  ClientParams(const ClientParams & other);
206  ClientParams(const RequesterParams & rp,
207  std::string instance_name);
211  ClientParams & operator = (const ClientParams & that);
212 
216  ClientParams & service_name(const std::string &service_name);
220  ClientParams & instance_name(const std::string &instance_name);
224  ClientParams & request_topic_name(const std::string &req_topic);
228  ClientParams & reply_topic_name(const std::string &rep_topic);
232  ClientParams & datawriter_qos(const dds_entity_traits::DataWriterQos & qos);
236  ClientParams & datareader_qos(const dds_entity_traits::DataReaderQos & qos);
240  ClientParams & publisher(dds_entity_traits::Publisher publisher);
244  ClientParams & subscriber(dds_entity_traits::Subscriber subscriber);
248  ClientParams & domain_participant(dds_entity_traits::DomainParticipant part);
249 
253  const std::string service_name() const;
257  const std::string instance_name() const;
261  const std::string request_topic_name() const;
265  const std::string reply_topic_name() const;
269  const dds_entity_traits::DataWriterQos datawriter_qos() const;
273  const dds_entity_traits::DataReaderQos datareader_qos() const;
277  dds_entity_traits::Publisher publisher() const;
281  dds_entity_traits::Subscriber subscriber() const;
285  dds_entity_traits::DomainParticipant domain_participant() const;
286 
287  const RequesterParams & get_req_params() const { return _params; }
288 
289  protected:
290  RequesterParams _params;
291  std::string _instance_name;
292  };
293 
294  // -------------------------------------------------------------------
295  // ServiceEndpoint
296  // -------------------------------------------------------------------
306  class ServiceEndpoint : public RPCEntity
307  {
308  protected:
309 
310  template <class Impl>
311  explicit ServiceEndpoint(Impl impl);
312 
313  public:
314  typedef rpc_entity_traits::ServiceEndpoint * VendorDependent;
315 
319  ServiceEndpoint();
320 
324  template <class TReq>
325  typename dds_type_traits<TReq>::DataReader get_request_datareader() const;
329  template <class TRep>
330  typename dds_type_traits<TRep>::DataWriter get_reply_datawriter() const;
331 
336  void pause();
343  void resume();
347  ServiceStatus status() const;
351  ServiceParams get_service_params() const;
352  VendorDependent get_impl() const;
353 
354  protected:
355  ServiceStatus _status;
356  };
357 
358  // -------------------------------------------------------------------
359  // ClientEndpoint
360  // -------------------------------------------------------------------
370  {
371  protected:
372 
373  public:
378 
382  template <class TReq>
383  typename dds_type_traits<TReq>::DataWriter get_request_datawriter() const;
387  template <class TRep>
388  typename dds_type_traits<TRep>::DataReader get_reply_datareader() const;
394  RequesterParams rp = ((VendorDependent)this->impl_)->get_rparams( );
395  ClientParams cp(rp, this->get_bound_instance_name());
396  return cp;
397  }
398 
399  };
400 
401 #if defined(CDX_HAS_RPC_SERVER)
402  /* Note the current spec for Server is incomplete. */
403  class Server;
404 
405  // -------------------------------------------------------------------
406  // ServerParams
407  // -------------------------------------------------------------------
413  class ServerParams
414  {
415  public:
416  ServerParams();
417  ServerParams(const ServerParams & other);
418  ServerParams & operator = (const ServerParams & that);
419  ServerParams & default_service_params(const ServiceParams & service_params);
420  ServiceParams default_service_params() const;
421 
422  protected:
423  typedef rpc_entity_traits::ServerParams * VendorDependent;
424  VendorDependent impl_;
425 
426  public:
427  VendorDependent get_impl() const;
428  };
429 
430  // -------------------------------------------------------------------
431  // Server
432  // -------------------------------------------------------------------
442  class Server : public RPCEntity
443  {
444  public:
445  //typedef details::vendor_dependent<Server>::type VendorDependent;
446  typedef rpc_entity_traits::Server * VendorDependent;
447 
448  // may reuse an exising participant
449  Server();
450  explicit Server(const ServerParams & server_params);
451 
452  void run(); // blocking
453  void run(const DDS::Duration_t & max_wait); // non-blocking
454  VendorDependent get_impl() const;
455 
456  // SPEC: if 'Server' contains multiple 'Service's,
457  // how do we add a 'Service' to the 'Server' ?
458 
459  };
460 #endif
461 
462  template <class TReq>
463  typename dds_type_traits<TReq>::DataWriter
465  {
466  return (typename dds_type_traits<TReq>::DataWriter)
467  ((VendorDependent)this->impl_)->get_req_dw( );
468  }
469 
470  template <class TRep>
471  typename dds_type_traits<TRep>::DataReader
473  {
474  return (typename dds_type_traits<TRep>::DataReader)
475  ((VendorDependent)this->impl_)->get_rep_dr( );
476  }
477 
478  } // namespace rpc
479 } // namespace dds
480 
481 #endif
482 
Definition: function_call.hh:44
ServiceStatus
Definition: function_call.hh:44
dds_type_traits< TRep >::DataReader get_reply_datareader() const
Access the DataReader used to receive TRep replies.
Definition: function_call.hh:472
dds_type_traits< TReq >::DataWriter get_request_datawriter() const
Access the DataWriter used to send TReq requests.
Definition: function_call.hh:464
Used to pass configuration parameters when constructing a Service.
Definition: function_call.hh:87
Used to pass configuration parameters when constructing a Client.
Definition: function_call.hh:195
Definition: function_call.hh:306
Definition: function_call.hh:46
ClientEndpoint()
Default constructor.
Definition: function_call.hh:377
Provides the DDS infrastructure.
Definition: dds_builtin_basic.hh:28
Definition: function_call.hh:369
ServiceProxy.
Definition: request_reply.hh:224
RPCEntity is a base abstract class.
Definition: request_reply.hh:176
Used to pass configuration parameters when constructing a Requester.
Definition: request_reply.hh:862
DDS::rpc::ClientParams get_client_params()
Access the ClientParams defining the configuration of this ClientEndpoint.
Definition: function_call.hh:393
Definition: function_call.hh:45
Used to pass configuration parameters when constructing a Replier.
Definition: request_reply.hh:1016
The Duration_t structure contains data to define a time duration.
Definition: dds_builtin.hh:45

© 2009-2017 Twin Oaks Computing, Inc
Castle Rock, CO 80108
All rights reserved.