ISO C++ DDS PSM


   Angelo Corsaro                  Rick Warren
  OMG DDS Co-Chair                       RTI
        PrismTech                 rick.warren@rti.com

angelo.corsaro@prismtech.com




   POC: Angelo Corsaro <angelo.corsaro@prismtech.com>1
Agenda
- Status Update
- Submission Scope
- API Overview
- Resource Management
- Code Example
- Type Mapping Example
- Next Steps
                  Copyright 2010, PrismTech / RTI
Status Update


- Tuesday 20th Sept. 2010, after a “conclave”
 of 4+ hours PrismTech and RTI have
 resolved all open issues and points of
 divergence!
- This presentation provides a unified view of
 what the joint final submission will be.



                  Copyright 2010, PrismTech / RTI
Agenda

- Status Update
- Submission Scope
- API Overview
- Resource Management
- Code Example
- Type Mapping Example
- Next Steps
                  Copyright 2010, PrismTech / RTI
Submission Scope


The ISO C++ DDS PSM has the following
scope:
- Full API for DCPS v1.2 PIM
- Full API for Extensible Topics
- ISO C++ mapping of DDS Type System (as
 defined in xtypes)


                   Copyright 2010, PrismTech / RTI
Agenda

- Status Update
- Submission Scope
- API Overview
- Resource Management
- Code Example
- Type Mapping Example
- Next Steps
                  Copyright 2010, PrismTech / RTI
Key Highlights
- Simple, safe, efficient, extensible and
 portable C++ API
- Well defined and safe resource management
- Use of C++ templates to ensure type safety
 and improve compile time error detection
- Consistent use of Standard C++ types and
 idioms, such as, std::string, std::vector,
 iterators, RAII Pattern, etc., throughout the
 API
                   Copyright 2010, PrismTech / RTI
API Organization
    DDS type constructors.
                                             Vendor Implementation for
                                             the DELEGATE layer


                   DELEGATE

               tdds                                     idds




                                             Standard API instantiated
                                             from the parametrized API
               dds                           and the vendor
                                             implementation of the
                                             DELEGATE layer.
        ANSI/ISO C++ PSM



                      Copyright 2010, PrismTech / RTI
Agenda

- Status Update
- Submission Scope
- API Overview
- Resource Management
- Code Example
- Type Mapping Example
- Next Steps
                  Copyright 2010, PrismTech / RTI
Resource Management
- Principles
   Safety: Never access uninitialized, freed, or
    undefined state
   Determinism: Applications control when local and
    remote resources are allocated and released
   Expressiveness: Maintain capabilities from PIM




                     Copyright 2010, PrismTech / RTI
Resource Management

- Expression of principles differ for
 different kinds of types
   Reference types: Identity based on reference
     • DDS Entities
     • Wait sets and conditions
   Value types: Identity based on state
     • Entity QoS and QoS policies
     • Status
     • Time and duration


                      Copyright 2010, PrismTech / RTI
Reference Type Usage
- Access is through smart pointers, allocated by
 factory methods. These:
   Provide null initialization
   Throw exception on access to “closed” object
   May automatically manage resources
- Examples:
   Null pointer:
      • Publisher pub;
      • if (pub == dds::core::null) { … }
   Initialization:
      • pub = dp.create_publisher();
   Copying reference:
      • Publisher pub2 = pub1; —or— Publisher pub2(pub1);
        // 2 references to same object
   Polymorphism & Down-Casting:
      • Entity e = pub; // Publisher pub
      • Publisher pub =
        dds::core::polymorphic_cast<Publisher>(e);

                         Copyright 2010, PrismTech / RTI
Reference Type Mgmt

- Reference types have close() method
   Disposes object and its contained objects

- Service may automatically close objects no longer
 in use
   “May” gives vendors flexibility to balance determinism,
    convenience for their users
   Similar to resource management practice in JMS
   Common-sense rules:
      • If I keep a reference to it, I intend to call it: still in use
      • If I set a listener, I want it to call me: still in use
      • If I call retain(): still in use

- Summary:
   Deterministic way to halt communication, reclaim resources
   Deterministic way to continue communication, maintain resources
   Flexibility for vendors

                                Copyright 2010, PrismTech / RTI
Agenda

- Status Update
- Submission Scope
- API Overview
- Resource Management
- Type Mapping Example
- Code Example
- Next Steps
                  Copyright 2010, PrismTech / RTI
DDS Types Mapping

- The ISO C++ API is independent from the
 specific mapping used for DDS Topic Types,
 as far as generated types have value
 semantics
      The ISO C++ API can be used with the existing
      IDL2C++ type mapping, or
     It can be used with the ISO C++ mapping for
      DDS Types as defined in the DDS-XTypes
      specification

                      Copyright 2010, PrismTech / RTI
ISO C++ Mapping


- Main Characteristics
     Use of ISO C++ / StdLib types
     Full Attribute Encapsulation via accessors
     Container Safe

- Example... see next slide


                       Copyright 2010, PrismTech / RTI
DDS Type Mapping
   DDS Topic Type                                    ISO C++ Mapping
                                  class TelephoneNumber {

                                  public:
                                    TelephoneNumber();

struct TelephoneNumber {               explicit TelephoneNumber(
   string prefix;                        const std::string& prefix,
   string number;                         const std::string& number);
};
                                    virtual ~TelephoneNumber()
                                  public:
                                    const std::string& prefix() const;
                                    void prefix(const std::string& s);

                                       const std::string& number() const;
                                       void number(const std::string& s);

                                  // State representation
                                  // is implementation dependent
                                  };
                           Copyright 2010, PrismTech / RTI
DDS Type Mapping
       DDS Topic Type

enum MarrialStatus {
  SINGLE, MARRIED, DIVORCED };

struct Person {
   long age; //@id(1)
   wstring name;
   MarrialStatus married;
   sequence<TelephoneNumber> tel;
   sequence<TelefoneNumber, 2> fax;
   double height; //@optional
   double weight; //@optional
   sequence<byte> photo; //@shared
};




                           Copyright 2010, PrismTech / RTI
DDS Type Mapping
       DDS Topic Type                                ISO C++ Mapping

enum MarrialStatus {
  SINGLE, MARRIED, DIVORCED };
                                                      class Person {
struct Person {                                       public:
   long age; //@id(1)                                  int32_t age() const;
   wstring name;                                       void age(int32_t i);
   MarrialStatus married;                             };
   sequence<TelephoneNumber> tel;
   sequence<TelefoneNumber, 2> fax;
   double height; //@optional
   double weight; //@optional
   sequence<byte> photo; //@shared
};




                           Copyright 2010, PrismTech / RTI
DDS Type Mapping
       DDS Topic Type                                ISO C++ Mapping

enum MarrialStatus {
  SINGLE, MARRIED, DIVORCED };
                                                class Person {
struct Person {                                 public:
   long age; //@id(1)                            std::wstring name() const;
   wstring name;                                 void name(const std::wstring s);
   MarrialStatus married;                       };
   sequence<TelephoneNumber> tel;
   sequence<TelefoneNumber, 2> fax;
   double height; //@optional
   double weight; //@optional
   sequence<byte> photo; //@shared
};




                           Copyright 2010, PrismTech / RTI
DDS Type Mapping
       DDS Topic Type                                 ISO C++ Mapping

enum MarrialStatus {
  SINGLE, MARRIED, DIVORCED };

struct Person {
   long age; //@id(1)
   wstring name;
   MarrialStatus married;
   sequence<TelephoneNumber> tel;
   sequence<TelefoneNumber, 2> fax;
   double height; //@optional
   double weight; //@optional
   sequence<byte> photo; //@shared
};
                    class Person {
                    public:
                     const std::vector<TelephoneNumber>& tel() const;
                     void tel(const std::vector<TelephoneNumber>& s);
                    };
                            Copyright 2010, PrismTech / RTI
DDS Type Mapping
       DDS Topic Type                  ISO C++ Mapping

enum MarrialStatus {
  SINGLE, MARRIED, DIVORCED };

struct Person {
   long age; //@id(1)
   wstring name;
   MarrialStatus married;
   sequence<TelephoneNumber> tel;
   sequence<TelefoneNumber, 2> fax;
   double height; //@optional
   double weight; //@optional
   sequence<byte> photo; //@shared
};
                 class Person {
                 public:
                  const dds::core::optional<double>& height() const;
                  void height(double d);
                  void height(const dds::core::optional<double>& o);
                 };         Copyright 2010, PrismTech / RTI
DDS Type Mapping
       DDS Topic Type                                 ISO C++ Mapping

enum MarrialStatus {
  SINGLE, MARRIED, DIVORCED };

struct Person {
   long age; //@id(1)
   wstring name;
   MarrialStatus married;
   sequence<TelephoneNumber> tel;
   sequence<TelefoneNumber, 2> fax;
   double height; //@optional
   double weight; //@optional
   sequence<byte> photo; //@shared
};
                    class Person {
                    public:
                     std::vector<uint8_t>* photo() const;
                     void photo(std::vector<uint8_t>* v);
                    };
                            Copyright 2010, PrismTech / RTI
Agenda

- Status Update
- Submission Scope
- API Overview
- Resource Management
- Type Mapping Example
- Code Example
- Next Steps
                  Copyright 2010, PrismTech / RTI
Code Example

 DDS Topic Type
 struct RadarTrack {
    string id;
    long x;
    long y;
 };




                       Copyright 2010, PrismTech / RTI
Data Writer

- Create DataWriter
 using dds::core; using dds::domain;
 using dds::pub; using dds::topic;

 DomainId id = 0;

 DomainParticipant dp =
    theParticipantFactory().create_participant(id);

 Publisher pub = dp.create_publisher();

 Topic<RadarTrack> topic = dp.create_topic("RadarTrackTopic");
 DataWriter<RadarTrack> dw = pub.create_datawriter();
 RadarTrack t("T101", 100, 200);
 dw.write(t);



                          Copyright 2010, PrismTech / RTI
Data Reader


 using dds::core; using dds::domain;
 using dds::pub; using dds::topic;

 DomainId id = 0;
 DomainParticipant dp(id);

 DomainParticipant dp =
    theParticipantFactory().create_participant();

 Publisher sub = dp.create_publisher();

 Topic<RadarTrack> topic = dp.create_topic("RadarTrackTopic");
 DataReader<RadarTrack> reader = sub.create_datareader();




                        Copyright 2010, PrismTech / RTI
Data Reader
                                                          std::vector<RadarTrack> t;
                                                          std::vector<SampleInfo> i;

                                                          RadarTrack at[MSIZE];
                                                          SampleInfo ai[MSIZE];

- User Provided Container
   dr.take(t.begin(), i.begin(), maxsize);



   dr.take(at, ai, MSIZE);




                        Copyright 2010, PrismTech / RTI
Data Reader


- Loaned Data
   LoanedSamples<RadarTrack> dt = dr.take();
    for (LoanedSamples<RadarTrack>::Iterator it = dt.begin();
          it != dt.end();
          ++it) {
      const Sample<RadarTrack>& sample = *it;
      if (sample.is_valid_data()) {
        const RadarTrack& data = sample.data();
        // …
      }
    }

                        Copyright 2010, PrismTech / RTI
Agenda

- Status Update
- Submission Scope
- API Overview
- Resource Management
- Type Mapping Example
- Code Example
- Next Steps
                  Copyright 2010, PrismTech / RTI
Next Steps


- XTopics API
     Add support for the XTopics API
     Complete the Type Mapping to include the full
      DDS-XTypes Type System

- Vote for Adoption
     December Meeting



                      Copyright 2010, PrismTech / RTI
THANKS

  `

DDS ISO C++ PSM

  • 1.
    ISO C++ DDSPSM Angelo Corsaro Rick Warren OMG DDS Co-Chair RTI PrismTech rick.warren@rti.com angelo.corsaro@prismtech.com POC: Angelo Corsaro <angelo.corsaro@prismtech.com>1
  • 2.
    Agenda - Status Update -Submission Scope - API Overview - Resource Management - Code Example - Type Mapping Example - Next Steps Copyright 2010, PrismTech / RTI
  • 3.
    Status Update - Tuesday20th Sept. 2010, after a “conclave” of 4+ hours PrismTech and RTI have resolved all open issues and points of divergence! - This presentation provides a unified view of what the joint final submission will be. Copyright 2010, PrismTech / RTI
  • 4.
    Agenda - Status Update -Submission Scope - API Overview - Resource Management - Code Example - Type Mapping Example - Next Steps Copyright 2010, PrismTech / RTI
  • 5.
    Submission Scope The ISOC++ DDS PSM has the following scope: - Full API for DCPS v1.2 PIM - Full API for Extensible Topics - ISO C++ mapping of DDS Type System (as defined in xtypes) Copyright 2010, PrismTech / RTI
  • 6.
    Agenda - Status Update -Submission Scope - API Overview - Resource Management - Code Example - Type Mapping Example - Next Steps Copyright 2010, PrismTech / RTI
  • 7.
    Key Highlights - Simple,safe, efficient, extensible and portable C++ API - Well defined and safe resource management - Use of C++ templates to ensure type safety and improve compile time error detection - Consistent use of Standard C++ types and idioms, such as, std::string, std::vector, iterators, RAII Pattern, etc., throughout the API Copyright 2010, PrismTech / RTI
  • 8.
    API Organization DDS type constructors. Vendor Implementation for the DELEGATE layer DELEGATE tdds idds Standard API instantiated from the parametrized API dds and the vendor implementation of the DELEGATE layer. ANSI/ISO C++ PSM Copyright 2010, PrismTech / RTI
  • 9.
    Agenda - Status Update -Submission Scope - API Overview - Resource Management - Code Example - Type Mapping Example - Next Steps Copyright 2010, PrismTech / RTI
  • 10.
    Resource Management - Principles  Safety: Never access uninitialized, freed, or undefined state  Determinism: Applications control when local and remote resources are allocated and released  Expressiveness: Maintain capabilities from PIM Copyright 2010, PrismTech / RTI
  • 11.
    Resource Management - Expressionof principles differ for different kinds of types  Reference types: Identity based on reference • DDS Entities • Wait sets and conditions  Value types: Identity based on state • Entity QoS and QoS policies • Status • Time and duration Copyright 2010, PrismTech / RTI
  • 12.
    Reference Type Usage -Access is through smart pointers, allocated by factory methods. These:  Provide null initialization  Throw exception on access to “closed” object  May automatically manage resources - Examples:  Null pointer: • Publisher pub; • if (pub == dds::core::null) { … }  Initialization: • pub = dp.create_publisher();  Copying reference: • Publisher pub2 = pub1; —or— Publisher pub2(pub1); // 2 references to same object  Polymorphism & Down-Casting: • Entity e = pub; // Publisher pub • Publisher pub = dds::core::polymorphic_cast<Publisher>(e); Copyright 2010, PrismTech / RTI
  • 13.
    Reference Type Mgmt -Reference types have close() method  Disposes object and its contained objects - Service may automatically close objects no longer in use  “May” gives vendors flexibility to balance determinism, convenience for their users  Similar to resource management practice in JMS  Common-sense rules: • If I keep a reference to it, I intend to call it: still in use • If I set a listener, I want it to call me: still in use • If I call retain(): still in use - Summary:  Deterministic way to halt communication, reclaim resources  Deterministic way to continue communication, maintain resources  Flexibility for vendors Copyright 2010, PrismTech / RTI
  • 14.
    Agenda - Status Update -Submission Scope - API Overview - Resource Management - Type Mapping Example - Code Example - Next Steps Copyright 2010, PrismTech / RTI
  • 15.
    DDS Types Mapping -The ISO C++ API is independent from the specific mapping used for DDS Topic Types, as far as generated types have value semantics  The ISO C++ API can be used with the existing IDL2C++ type mapping, or  It can be used with the ISO C++ mapping for DDS Types as defined in the DDS-XTypes specification Copyright 2010, PrismTech / RTI
  • 16.
    ISO C++ Mapping -Main Characteristics  Use of ISO C++ / StdLib types  Full Attribute Encapsulation via accessors  Container Safe - Example... see next slide Copyright 2010, PrismTech / RTI
  • 17.
    DDS Type Mapping DDS Topic Type ISO C++ Mapping class TelephoneNumber { public: TelephoneNumber(); struct TelephoneNumber { explicit TelephoneNumber( string prefix; const std::string& prefix, string number; const std::string& number); }; virtual ~TelephoneNumber() public: const std::string& prefix() const; void prefix(const std::string& s); const std::string& number() const; void number(const std::string& s); // State representation // is implementation dependent }; Copyright 2010, PrismTech / RTI
  • 18.
    DDS Type Mapping DDS Topic Type enum MarrialStatus { SINGLE, MARRIED, DIVORCED }; struct Person { long age; //@id(1) wstring name; MarrialStatus married; sequence<TelephoneNumber> tel; sequence<TelefoneNumber, 2> fax; double height; //@optional double weight; //@optional sequence<byte> photo; //@shared }; Copyright 2010, PrismTech / RTI
  • 19.
    DDS Type Mapping DDS Topic Type ISO C++ Mapping enum MarrialStatus { SINGLE, MARRIED, DIVORCED }; class Person { struct Person { public: long age; //@id(1) int32_t age() const; wstring name; void age(int32_t i); MarrialStatus married; }; sequence<TelephoneNumber> tel; sequence<TelefoneNumber, 2> fax; double height; //@optional double weight; //@optional sequence<byte> photo; //@shared }; Copyright 2010, PrismTech / RTI
  • 20.
    DDS Type Mapping DDS Topic Type ISO C++ Mapping enum MarrialStatus { SINGLE, MARRIED, DIVORCED }; class Person { struct Person { public: long age; //@id(1) std::wstring name() const; wstring name; void name(const std::wstring s); MarrialStatus married; }; sequence<TelephoneNumber> tel; sequence<TelefoneNumber, 2> fax; double height; //@optional double weight; //@optional sequence<byte> photo; //@shared }; Copyright 2010, PrismTech / RTI
  • 21.
    DDS Type Mapping DDS Topic Type ISO C++ Mapping enum MarrialStatus { SINGLE, MARRIED, DIVORCED }; struct Person { long age; //@id(1) wstring name; MarrialStatus married; sequence<TelephoneNumber> tel; sequence<TelefoneNumber, 2> fax; double height; //@optional double weight; //@optional sequence<byte> photo; //@shared }; class Person { public: const std::vector<TelephoneNumber>& tel() const; void tel(const std::vector<TelephoneNumber>& s); }; Copyright 2010, PrismTech / RTI
  • 22.
    DDS Type Mapping DDS Topic Type ISO C++ Mapping enum MarrialStatus { SINGLE, MARRIED, DIVORCED }; struct Person { long age; //@id(1) wstring name; MarrialStatus married; sequence<TelephoneNumber> tel; sequence<TelefoneNumber, 2> fax; double height; //@optional double weight; //@optional sequence<byte> photo; //@shared }; class Person { public: const dds::core::optional<double>& height() const; void height(double d); void height(const dds::core::optional<double>& o); }; Copyright 2010, PrismTech / RTI
  • 23.
    DDS Type Mapping DDS Topic Type ISO C++ Mapping enum MarrialStatus { SINGLE, MARRIED, DIVORCED }; struct Person { long age; //@id(1) wstring name; MarrialStatus married; sequence<TelephoneNumber> tel; sequence<TelefoneNumber, 2> fax; double height; //@optional double weight; //@optional sequence<byte> photo; //@shared }; class Person { public: std::vector<uint8_t>* photo() const; void photo(std::vector<uint8_t>* v); }; Copyright 2010, PrismTech / RTI
  • 24.
    Agenda - Status Update -Submission Scope - API Overview - Resource Management - Type Mapping Example - Code Example - Next Steps Copyright 2010, PrismTech / RTI
  • 25.
    Code Example DDSTopic Type struct RadarTrack { string id; long x; long y; }; Copyright 2010, PrismTech / RTI
  • 26.
    Data Writer - CreateDataWriter using dds::core; using dds::domain; using dds::pub; using dds::topic; DomainId id = 0; DomainParticipant dp = theParticipantFactory().create_participant(id); Publisher pub = dp.create_publisher(); Topic<RadarTrack> topic = dp.create_topic("RadarTrackTopic"); DataWriter<RadarTrack> dw = pub.create_datawriter(); RadarTrack t("T101", 100, 200); dw.write(t); Copyright 2010, PrismTech / RTI
  • 27.
    Data Reader usingdds::core; using dds::domain; using dds::pub; using dds::topic; DomainId id = 0; DomainParticipant dp(id); DomainParticipant dp = theParticipantFactory().create_participant(); Publisher sub = dp.create_publisher(); Topic<RadarTrack> topic = dp.create_topic("RadarTrackTopic"); DataReader<RadarTrack> reader = sub.create_datareader(); Copyright 2010, PrismTech / RTI
  • 28.
    Data Reader std::vector<RadarTrack> t; std::vector<SampleInfo> i; RadarTrack at[MSIZE]; SampleInfo ai[MSIZE]; - User Provided Container dr.take(t.begin(), i.begin(), maxsize); dr.take(at, ai, MSIZE); Copyright 2010, PrismTech / RTI
  • 29.
    Data Reader - LoanedData LoanedSamples<RadarTrack> dt = dr.take(); for (LoanedSamples<RadarTrack>::Iterator it = dt.begin(); it != dt.end(); ++it) { const Sample<RadarTrack>& sample = *it; if (sample.is_valid_data()) { const RadarTrack& data = sample.data(); // … } } Copyright 2010, PrismTech / RTI
  • 30.
    Agenda - Status Update -Submission Scope - API Overview - Resource Management - Type Mapping Example - Code Example - Next Steps Copyright 2010, PrismTech / RTI
  • 31.
    Next Steps - XTopicsAPI  Add support for the XTopics API  Complete the Type Mapping to include the full DDS-XTypes Type System - Vote for Adoption  December Meeting Copyright 2010, PrismTech / RTI
  • 32.