IDL to C++11 OMG RTWS presentations


Published on

Johnny Willemsen as CTO of Remedy IT presented this presentation to the OMG RealTime 2012 Workshop in Paris. It gives a global overview of the new IDL to C++11 language mapping

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

IDL to C++11 OMG RTWS presentations

  1. 1. IDL to C++11 Language Mapping making CORBA, DDS, and CCM development easy, safe, and fast Johnny Willemsen jwillemsen@remedy.nlCopyright © 2012 Page 1
  2. 2. The history of IDL to C++ Created end of the 90s Two different approaches for IDL to C++ were proposed Selection was done based on formal voting, it was more a political decision than a technical oneCopyright © 2012 Page 2
  3. 3. What happened the last decade Lot of ideas were posted and raised throughout the years Any change to the C++ mapping would break a lot of code As a result the IDL to C++ mapping was just impossible to changeCopyright © 2012 Page 3
  4. 4. What changed now? A new revision of the C++ programming language itself was in progress This introduces several new constructs for which a new C++ compiler is mandatory When using the new C++ constructs you cant go back anymore to old C++ The new C++ language is now formally standardized as C++11Copyright © 2012 Page 4
  5. 5. IDL to C++11 goals A much more simplified mapping than the current C++ mapping Use C++11 features to – Gain performance – Reduce coding errors – Prevent memory leaks and double deletes – Reuse STL and C++11 features rather than reinventing themCopyright © 2012 Page 5
  6. 6. C++11 type mapping Map basic types to their C++ counterparts IDL (w)string maps to std::(w)string IDL sequence maps to std::vector IDL array maps to std::array IDL fixed maps to CORBA::FixedCopyright © 2012 Page 6
  7. 7. Argument passing Argument passing for Argument passing for basic types, and complex types: reference types – in: T – in: const T& – inout: T& – inout: T& – out: T& – out: T& – return: T – return: TCopyright © 2012 Page 7
  8. 8. Struct/union Struct and union now both map to a C++ class Providing constructor(s), copy and move operators Set of accessors for each member: void A (T); void A (const T&); T A (void) const; void A (T&&); T& A (void); const T& A (void) const; T& A (void);Copyright © 2012 Page 8
  9. 9. Enum mapping IDL enum is mapped to the new C++11 enum class // IDL enum Color { red, green, blue }; // C++ enum class Color : uint32_t { red, green, blue };Copyright © 2012 Page 9
  10. 10. Reference types (1) Reference types are used for – Object references – Valuetypes – Typecodes Strong references behave as std::shared_ptr Weak references behave as std::weak_ptr References can only be created using CORBA::make_reference<> No C++ pointers can be passed to the APICopyright © 2012 Page 10
  11. 11. Reference types (2) C++11 introduces a new type for a nil pointer: nullptr_t References can be checked for nil by comparing them with nullptr Explicit bool conversion operators for comparisonCopyright © 2012 Page 11
  12. 12. CORBA? Beta 1 specification lists CORBA as namespace in a few places Will be moved to omg idl traits that are independent of the specific middleware being used Allows meta programming without knowing whether you are using CORBA, DDS, or something elseCopyright © 2012 Page 12
  13. 13. Client interface mapping When defining interface Foo, than CORBA::object_traits<Foo>::ref_type (aka CORBA::object_reference<Foo>, aka Foo::_ref_type) is the object reference type C++ traits are used to determine types, no naming rules to be remembered by the user Narrowing using the narrow method (with CORBA could trigger a remote call)Copyright © 2012 Page 13
  14. 14. Servant interface mapping When defining interface Foo, than CORBA::servant_traits<Foo>::base_type is the base class for the user servant class Servant references are available as CORBA::servant_traits<Foo>::ref_type (aka CORBA::servant_reference<Foo>) C++ traits are used to determine types, no naming rules to be remembered by the userCopyright © 2012 Page 14
  15. 15. Client example // IDL to C++ Language Mapping CORBA::Object_var obj = orb->string_to_object(ior); Test::Hello_var hello = Test::Hello::_narrow( ()); if (!CORBA::is_nil ( ())) { CORBA::String_var the_string = hello->get_string (); std::cout << "hello->get_string () returned " << () << std::endl; hello->shutdown (); } // IDL to C++11 Language Mapping CORBA::object_reference<CORBA::Object> obj = orb->string_to_object (ior); Test::Hello::_ref_type hello = Test::Hello::_narrow (obj); if (hello) { std::cout << "hello->get_string () returned " << hello->get_string () << std::endl; hello->shutdown (); }Copyright © 2012 Page 15
  16. 16. Servant example // IDL to C++ Language Mapping class Hello : public virtual POA_Test::Hello { public: Hello (CORBA::ORB_ptr orb) : orb_ (CORBA::ORB::_duplicate (orb)) { } virtual char * get_string (void) { return CORBA::string_dup ("Hello there!"); } virtual void shutdown (void) { this->orb_->shutdown (0); } private: CORBA::ORB_var orb_; }; // IDL to C++11 Language Mapping class Hello : public virtual CORBA::servant_traits<Test::Hello>::base_type { public: Hello (CORBA::object_reference<CORBA::ORB> orb) : orb_ (orb) { } virtual std::string get_string (void) { return "Hello there!"; } virtual void shutdown (void) { this->orb_->shutdown (false); } private: CORBA::object_reference<CORBA::ORB> orb_; };Copyright © 2012 Page 16
  17. 17. OMG Standardization stage Revised submission got recommended for adoption at the OMG March 2012 meeting Finalization Task Force (FTF) has started work IDL to C++11 beta 1 specification available on the OMG website FTF will deliver a V1.0 specification at the OMG September 2012 meetingCopyright © 2012 Page 17
  18. 18. More information For more information about IDL to C++11 check: – ORBzone at ▪ Discussion forum ▪ Articles – Osportal at ▪ More examplesCopyright © 2012 Page 18