ISO C++ DDS PSM

2,555 views

Published on

This presentation summarizes the revised submission for the ISO C++ DDS PSM presented at the March 2010 OMG Meeting.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,555
On SlideShare
0
From Embeds
0
Number of Embeds
149
Actions
Shares
0
Downloads
71
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

ISO C++ DDS PSM

  1. 1. OpenSplice DDS Delivering Performance, Openness, and Freedom Angelo Corsaro, Ph.D. Chief Technology Officer ISO C++ DDS PSM OMG DDS SIG Co-Chair angelo.corsaro@prismtech.com
  2. 2. OpenSplice DDS Delivering Performance, Openness, and Freedom Rationale
  3. 3. ISO C++ PSM Motivations The “Native C++ Language DDS PSM” (CxxDDS) was motivated by the following reasons: ‣Provide better integration with the C++ programming language ‣Provide a simpler and safer API to facilitate adoption within and beyond current user domains ‣Ensure 100% source-code portability across DDS implementations © 2010, PrismTech. All Rights Reserved
  4. 4. Integration with C++ The current IDL-derived PSM suffers the following shortcomings: ‣ Limited integration of IDL-derived types with the C++ language ‣e.g. char* vs. std::string, Sequence vs. std::vector, etc. ‣ Limited use of features and idioms universally supported by C++ compilers and widely used by C++ programmers ‣e.g. template and template-meta-programming, iterators, etc. © 2010, PrismTech. All Rights Reserved
  5. 5. API Complexity ‣ The current API suffers from accidental complexity mostly induced by the limited expressiveness of IDL and the dated IDL2C++ mapping © 2010, PrismTech. All Rights Reserved
  6. 6. Portability ‣ The current IDL-derived API leaves some types defined as native, thus allowing different vendors to use different representations ‣e.g. the type of the domainid ‣ The current IDL-derived API does not specifies the DDS interfaces as local, yet semantically those are local. This has also been source of portability issues © 2010, PrismTech. All Rights Reserved
  7. 7. OpenSplice DDS Delivering Performance, Openness, and Freedom Submission Overview Foundations
  8. 8. CxxDDS API Organization ‣ Different packages are introduced to limit the dependencies and group together relevant classes ‣ The submission separates clearly those files features that are specific to publication and subscription so that application can include only the minimal set of files ‣ The API is parametrized w.r.t. a DELEGATE layer © 2010, PrismTech. All Rights Reserved
  9. 9. Delegation Layer ‣ The delegation layer, is provided by vendors and used to instantiate the CxxDDS API into a concrete API ‣ This standard provide a reference implementation that shows how that can be done. ‣ Under any circumstances, compliant implementation shall not change the CxxDDS API, as detailed in Section 8, vendor-specific extensions shall be added only via DELEGATEs. ‣ The CxxDDS API provides a standard way of accessing vendor specific extensions ‣ Finally, although the specification allows for vendor-specific extensibility, it should be clear that this specification does not encourage nor recommend their use Using vendor specific extensions will make application non-source-code-portable to other CxxDDS compliant implementations and might also adversely impact on-the- wire interoperability. © 2010, PrismTech. All Rights Reserved
  10. 10. Object Model The Native C++ Language DDS PSM (CxxDDS) is based on an object model structured in two different kinds of object types: reference-types and value-types © 2010, PrismTech. All Rights Reserved
  11. 11. Reference Types ‣ Reference-types have a shallow (polymorphic) assignment operator that Ref simply changes the value of the reference Impl. ‣ Reference-types are safe. Under no Ref circumstances a reference can point to an invalid object. Ref ‣ Memory for reference-types is CxxDDS Delegate (provided by a automatically managed by the runtime. specific vendor implementation) © 2010, PrismTech. All Rights Reserved
  12. 12. Reference Types (cont.) ‣ The semantics for Reference types is defined by the CxxDDS class dds::core::Reference. namespace dds { namespace core { template <typename DELEGATE> class Reference; }} ‣ The specification mandates the semantics implied by the Reference class, yet the implementation provided as part of this standard is provided to show one possible way of implementing this semantics © 2010, PrismTech. All Rights Reserved
  13. 13. Reference Types © 2010, PrismTech. All Rights Reserved
  14. 14. WeakReferences ‣ The CxxDDS also provides safe Weak References implemented by the class dds::core::WeakReference ‣ Weak References can be constructed only from strong references ‣ Weak References do not expose other method other than checking wether the reference is valid and getting a strong-reference namespace dds { namespace core { template <typename class R <typename D>> class WeakReference; }} © 2010, PrismTech. All Rights Reserved
  15. 15. Value Types ‣ All objects that have a value-type have a deep-copy assignment semantics. ‣ It should also be pointed out that value-types are not “pure-value-types” in the sense that they are immutable (as in functional programming languages). ‣ The CxxPSM makes value-types mutable to limit the number of copies as well limit the time-overhead necessary to change a value-type (note that for immutable value-types the only form of change is to create a new value-type). ‣ Value-types always inherit from the CxxPSM dds::core::Value The CxxDDS models all DDS entities as reference-types while QoS and Topic samples are all modeled as value-types. © 2010, PrismTech. All Rights Reserved
  16. 16. API Extensibility ‣ The CxxPSM allows for QoS to be extended, either by new version of the standard or by vendor specific extension without any impact on the public API. ‣ The CxxPSM provides this level of extensibility while also enjoying a very compact representation of a QoS which leverages the combination of a DELEGEATE QoS implementation along with template getter and setters. © 2010, PrismTech. All Rights Reserved
  17. 17. QoS as an Example of Extensibility Although the CxxPSM specifies the EntityQoS by leveraging variadic C++ templates for providing a constructor taking an arbitrary number or arguments, some implementation might have to leverage other techniques for emulating variadic templates on non-supported compilers. The standard technique for doing this is to define several template constructors accepting an increasing number of arguments. © 2010, PrismTech. All Rights Reserved
  18. 18. Primitive Types Mapping ‣ The CxxDDS API provides its own interoperable definition of DDS primitive types and represents them in terms of standard (and portable) C/C++ types. © 2010, PrismTech. All Rights Reserved
  19. 19. Sequence Mapping ‣ Bounded and Unbounded IDL Sequences for a type T map to std::vector<T> © 2010, PrismTech. All Rights Reserved
  20. 20. Parameters Passing Constant-size Primitive types ‣ in T => T ‣ out T => T& ‣ inout T => T& Variable-size Primitive types (e.g string, wsting) ‣ in T => const T& ‣ out T => T& ‣ inout T => T& © 2010, PrismTech. All Rights Reserved
  21. 21. Parameters Passing Value Types ‣ in T => const T& ‣ out T => T& ‣ inout T => T& Reference Types ‣ in T => const T& ‣ out T => T& ‣ inout T => T& © 2010, PrismTech. All Rights Reserved
  22. 22. Return Parameters Attribute Accessors for fixed-size primitive types ‣ T => T Attribute Accessors for any other type ‣ T => const T& Non-attribute return-values ‣ T => T © 2010, PrismTech. All Rights Reserved
  23. 23. OpenSplice DDS Delivering Performance, Openness, and Freedom Submission Overview API Overview
  24. 24. DDS Entities © 2010, PrismTech. All Rights Reserved
  25. 25. Entity QoS template <typename DELEGATE> class Publisher : public dds::core::Entity<DELEGATE> { public: ‣ To improve the // -- QoS related methods -- level of compile template <typename POLICY> void set_policy(const POLICY& p) { time error impl_->set_policy(p); detection, the } current submission template <typename POLICY> const POLICY& get_policy() const { separates the return impl_->get_policy(); initialization of } entity QoS policy dds::PublisherQos get_qos() const { from the update of return impl_->get_qos(); } some of its policies. // -- Other Publisher Methods not shown // for space constraints }; © 2010, PrismTech. All Rights Reserved
  26. 26. QoS Extensibility Vendor-specific DDS Entity QoS (topic in this case) XYZVendorTopicQoS vtqos = { /* values */ }; dds::Topic<MyType> topic("MyTopic", vtqos); ‣ The current submission provides two Vendor-specific QoS Policy (topic in this case) ways of dds::Topic<MyType> topic("MyTopic"); providing vendor XYZVendorPolicy policy = { /* values */ }; topic.set_policy(policy); specific QoS © 2010, PrismTech. All Rights Reserved
  27. 27. Reading/Taking Data The new API simplify and extends the ways in which data can be read/taken by providing: ‣ std::vector based reads/takes ‣ The std::vector API allows for zero copy optimization ‣ Iterators based read/take supporting both: ‣ Forward Iterators ‣ Back Inserting Iterators © 2010, PrismTech. All Rights Reserved
  28. 28. std::vector-based read/take /** * Reads all new samples from any view state and alive instances. If the provided containers have * zero-size than the middleware will loan memory to the application to support zero-copy reads. * The memory will be returned to the middleware when the container is destroyed or by explicitly * invoking the <code>return_loan</code> method on the data reader. */ void read(std::vector<T>& samples, dds::SampleInfoSeq& infos); /** * Reads at most <code>max_samples</code> samples that have not been read yet from all views * and alive instances. */ void read(std::vector<T>& samples, uint32_t max_samples); /** * Most generic <code>read</code> exposing all the knobs provided by * the OMG DDS API. */ void read(std::vector<T>& samples, dds::SampleInfoSeq& infos, uint32_t max_samples, dds::SampleStateMask samples_state, dds::ViewStateMask views_state, dds::InstanceStateMask instances_state); © 2010, PrismTech. All Rights Reserved
  29. 29. std::vector-based take /** * Reads all new samples from any view state and alive instances. If the provided containers have * zero-size than the middleware will loan memory to the application to support zero-copy reads. * The memory will be returned to the middleware when the container is destroyed or by explicitly * invoking the <code>return_loan</code> method on the data reader. */ void take(std::vector<T>& samples, dds::SampleInfoSeq& infos); /** * Reads at most <code>max_samples</code> samples that have not been read yet from all views * and alive instances. */ void take(std::vector<T>& samples, uint32_t max_samples); /** * Most generic <code>read</code> exposing all the knobs provided by * the OMG DDS API. */ void take(std::vector<T>& samples, dds::SampleInfoSeq& infos, uint32_t max_samples, dds::SampleStateMask samples_state, dds::ViewStateMask views_state, dds::InstanceStateMask instances_state); © 2010, PrismTech. All Rights Reserved
  30. 30. FWD-Iterator-based read /** * Reads new samples from any view state and alive instances. */ template <typename SamplesFWIterator, typename InfoFWIterator> void read(SamplesIterator sfit, InfoIterator ifit, uint32_t max_samples); /** * Reads at most <code>max_samples</code> samples that have not been read yet from all vies and * alive instances. */ template <typename SamplesFWIterator> void read(SamplesFWIterator samples, uint32_t max_samples); /** * Most generic <code>read</code> exposing all the knobs provided by * the OMG DDS API. */ template <typename SamplesFWIterator, typename InfoFWIterator> void read(SamplesFWIterator sfit, InfoFWIterator ifit, uint32_t max_samples, dds::SampleStateMask samples_state, dds::ViewStateMask views_state, dds::InstanceStateMask instances_state); © 2010, PrismTech. All Rights Reserved
  31. 31. FWD-Iterator-based take /** * Reads new samples from any view state and alive instances. */ template <typename SamplesFWIterator, typename InfoFWIterator> void take(SamplesIterator sfit, InfoIterator ifit, uint32_t max_samples); /** * Reads at most <code>max_samples</code> samples that have not been read yet from all vies and * alive instances. */ template <typename SamplesFWIterator> void take(SamplesFWIterator samples, uint32_t max_samples); /** * Most generic <code>read</code> exposing all the knobs provided by * the OMG DDS API. */ template <typename SamplesFWIterator, typename InfoFWIterator> void take(SamplesFWIterator sfit, InfoFWIterator ifit, uint32_t max_samples, dds::SampleStateMask samples_state, dds::ViewStateMask views_state, dds::InstanceStateMask instances_state); © 2010, PrismTech. All Rights Reserved
  32. 32. BI-Iterator-based read /** * Reads all new samples from any view state and alive instances. */ template <typename SamplesBIIterator, typename InfoBIIterator> void read(SamplesIterator sbit, InfoIterator ibit); /** * Most generic <code>take</code> exposing all the knobs provided by * the OMG DDS API. */ template <typename SamplesBIIterator, typename InfoBIIterator> void read(SamplesBIIterator ifit, InfoBIIterator ifit, dds::SampleStateMask samples_state, dds::ViewStateMask views_state, dds::InstanceStateMask instances_state); © 2010, PrismTech. All Rights Reserved
  33. 33. BI-Iterator-based take /** * Reads all new samples from any view state and alive instances. */ template <typename SamplesBIIterator, typename InfoBIIterator> void take(SamplesIterator sbit, InfoIterator ibit); /** * Most generic <code>take</code> exposing all the knobs provided by * the OMG DDS API. */ template <typename SamplesBIIterator, typename InfoBIIterator> void take(SamplesBIIterator ifit, InfoBIIterator ifit, dds::SampleStateMask samples_state, dds::ViewStateMask views_state, dds::InstanceStateMask instances_state); © 2010, PrismTech. All Rights Reserved
  34. 34. Conditions © 2010, PrismTech. All Rights Reserved
  35. 35. Creating a Condition (ex.) /** * Creates an <code>ActiveReadCondition</code> that waits for new samples to * be arriving in order to notify. */ template <typename F> ::dds::Condition create_readcondition(const F& f); © 2010, PrismTech. All Rights Reserved
  36. 36. OpenSplice DDS Delivering Performance, Openness, and Freedom Submission Overview Writing an application
  37. 37. IDL as Usual enum TemperatureScale { ! CELSIUS, ! KELVIN, ! FAHRENHEIT }; ! struct TempSensorType { ! short id; ! float temp; ! float hum; TemperatureScale scale; }; #pragma keylist TempSensor id © 2010, PrismTech. All Rights Reserved
  38. 38. Writer: As simple as it gets /********************************************************** * DataWriter **********************************************************/ dds::Topic<TempSensorType> tsTopic("TempSensorTopic"); // Create a Publisher connected to the proper partition // Create a DataWriter dds::DataWriter<TempSensorType> dw(tsTopic); TempSensorType ts = {1, 26.0F, 70.0F, CELSIUS}; // Write Data dw.write(ts); © 2010, PrismTech. All Rights Reserved
  39. 39. Customizing the Writer QoS /********************************************************** * DataWriter **********************************************************/ dds::DomainParticipant dp(did); dds::Publisher pub(dp, pqos); dds::Topic<TempSensorType> tsTopic("TempSensorTopic"); // Create a Publisher connected to the proper partition // Create a DataWriter dds::DataWriter<TempSensorType> dw(tsTopic, pub, dwqos); TempSensorType ts = {1, 26.0F, 70.0F, CELSIUS}; // Write Data dw.write(ts); © 2010, PrismTech. All Rights Reserved
  40. 40. Data Reader /********************************************************** * DataReader **********************************************************/ dds::Topic<TempSensorType> tsTopic("TempSensorTopic"); // Create a DataReader dds::DataReader<TempSensorType> dr(tsTopic); // If no initial size is provided than the read will read // all available samples std::vector<TempSensorType> data; SampleInfoSeq info; // This is a std::vector too! while (true) { dr.read(data, info); for (int i = 0; i < data.length(); ++i) std::cout << data[i] << std::endl; sleep(1); © 2010, PrismTech. All Rights Reserved
  41. 41. Data Reader (with FW Iterators) /********************************************************** * DataReader **********************************************************/ dds::Topic<TempSensorType> tsTopic("TempSensorTopic"); // Create a DataReader dds::DataReader<TempSensorType> dr(tsTopic); std::vector<TempSensorType> data(length); SampleInfoSeq info(length); // This is a std::vector too! while (true) { dr.read(data.begin(), info.begin(), length); for (int i = 0; i < data.length(); ++i) std::cout << data[i] << std::endl; sleep(1); } © 2010, PrismTech. All Rights Reserved
  42. 42. Data Reader (with BI Iterators) /********************************************************** * DataReader **********************************************************/ dds::Topic<TempSensorType> tsTopic("TempSensorTopic"); // Create a DataReader dds::DataReader<TempSensorType> dr(tsTopic); std::vector<TempSensorType> data; SampleInfoSeq info; // This is a std::vector too! std::back_insert_iterator<std::vector<TempSensorType>> bid(data); std::back_insert_iterator<SampleInfoSeq> bii(info); while (true) { dr.read(bid, bii); for (int i = 0; i < data.length(); ++i) std::cout << data[i] << std::endl; sleep(1); © 2010, PrismTech. All Rights Reserved
  43. 43. OpenSplice DDS Delivering Performance, Openness, and Freedom Interoperability with IDL2C++ API and CORBA
  44. 44. C++2IDL and CORBA Interop ‣ The new mapping defines implicit conversion methods to create the equivalent C+ +2IDL type when needed ‣ This allows to pass a new DDS Type to a CORBA call by leveraging automatically generated conversions ‣ Conversion can be enabled/disabled via IDL compilers flags © 2010, PrismTech. All Rights Reserved
  45. 45. OpenSplice DDS Delivering Performance, Openness, and Freedom Résumé & Next Steps
  46. 46. Résumé ‣ The CxxDDS addresses the goals of the RFP by providing a simpler, safer and well integrated C++ API for DDS ‣ The current submission addresses extensibility and portability ‣ Efficiency and determinism is not impacted by the higher level of abstraction © 2010, PrismTech. All Rights Reserved
  47. 47. Next Steps ‣ Vote a finalized version of this submission on June Meeting © 2010, PrismTech. All Rights Reserved
  48. 48. Online Resources http://www.opensplice.com/ http://www.slideshare.net/angelo.corsaro emailto:opensplicedds@prismtech.com http://bit.ly/1Sreg http://twitter.com/acorsaro/ http://opensplice.blogspot.com http://www.youtube.com/OpenSpliceTube © 2009, PrismTech. All Rights Reserved
  49. 49. Thank You... © 2009, PrismTech. All Rights Reserved

×