SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
Comparing
IDL to C++
with
IDL to C++11
Simplify development of CORBA, DDS, and CCM based
applications
Overview
This presentations gives a comparison between the
IDL to C++ and IDL to C++11 language mappings
It assumes basic understanding of IDL and CORBA
For more information take a look at our TAOX11
website at https://taox11.remedy.nl
2
Introduction
3
Problems with IDL to C++
The IDL to C++ language mapping is from the 90’s
IDL to C++ could not depend on various C++ features
as
• C++ namespace
• C++ exceptions
• Standard Template Library
As a result
• Mapping is hard to use correctly
• Uses its own constructs for everything
4
Why a new language mapping?
IDL to C++ language mapping is impossible to
change because
• Multiple implementations are on the market (open
source and commercial)
• A huge amount of applications have been developed
An updated IDL to C++ language mapping would
force all vendors and users to update their products
The standardization of a new C++ revision in 2011
(ISO/IEC 14882:2011, called C++11) gives the
opportunity to define a new language mapping
• C++11 features are not backward compatible with
C++03 or C++99
• A new C++11 mapping leaves the existing mapping
intact
5
Goals
Simplify mapping for C++
Make use of the new C++11 features to
• Reduce amount of application code
• Reduce amount of possible errors made
• Gain runtime performance
• Speedup development and testing
Faster time to market
Reduced costs
Reduced training time
6
OMG Specification
IDL to C++11 v1.3 available from the OMG website at
http://www.omg.org/spec/CPP11/
Revision Task Force (RTF) is active to work on
issues reported
7
IDL Constructs
8
Modules
An IDL module maps to a C++ namespace with the
same name, same for both mappings
module M
{
// definitions
};
module A
{
module B
{
// definitions
};
};
IDL C++/C++11
namespace M
{
// definitions
};
namespace A
{
namespace B
{
// definitions
};
};
9 Copyright © Remedy IT
Basic types
IDL C++ C++11 C++11 Default value
short CORBA::Short int16_t 0
long CORBA::Long int32_t 0
long long CORBA::LongLong int64_t 0
unsigned short CORBA::UShort uint16_t 0
unsigned long CORBA::ULong uint32_t 0
unsigned long long CORBA::ULongLong uint64_t 0
float CORBA::Float float 0.0
double CORBA::Double double 0.0
long double CORBA::LongDouble long double 0.0
char CORBA::Char char 0
wchar CORBA::WChar wchar_t 0
boolean CORBA::Boolean bool false
octet CORBA::Octet uint8_t 0
10
Constants
const string name = "testing";
interface A
{
const float pi = 3.14159;
};
const char *const name = "testing";
class A
{
public:
static const CORBA::Float pi;
};
C++ C++11
const std::string name {"testing"};
class A
{
public:
static constexpr float pi {3.14159F};
};
11 Copyright © Remedy IT
String types
string name;
wstring w_name;
CORBA::String_var name;
CORBA::WString_var w_name;
name = CORBA::string_dup (“Hello”);
std::cout << name.in () << std::endl;
C++ C++11
std::string name {“Hello”};
std::wstring w_name;
std::cout << name << std::endl;
12 Copyright © Remedy IT
Enum
enum Color {
red,
green,
blue
};
enum Color
{
red,
green,
blue
};
Color mycolor
mycolor = red;
if (mycolor == red)
{
std::cout << “Correct color”;
}
C++ C++11
enum class Color : uint32_t
{
red,
green,
blue
};
Color mycolor {Color::red};
if (mycolor == Color::red)
{
std::cout << “Correct color”;
}
13 Copyright © Remedy IT
Sequence
typedef sequence<long> LongSeq;
LongSeq mysequence;
// Add an element to the vector
Mysequence.length (1)
Mysequence[1] = 5;
for (CORBA::ULong i = 0; I <
mysequence.length(); i++)
{
std::cout << mysequence[i] << “;” <<
std::end;
}
C++ C++11
LongSeq mysequence;
// Add an element to the vector
mysequence.push_back (5);
// Dump using C++11 range based for loop
for (const int32_t& e : mysequence)
{
std::cout << e << “;” << std::end;
}
14 Copyright © Remedy IT
Struct (1)
struct Variable {
string name;
};
struct Variable {
string name;
};
C++ C++11
class Variable final
{
public:
Variable ();
~Variable ();
Variable (const Variable&);
Variable (Variable&&);
Variable& operator= (const Variable& x);
Variable& operator= (Variable&& x);
explicit Variable (std::string name);
void name (const std::string& _name);
void name (std::string&& _name);
const std::string& name () const;
std::string& name ();
};
namespace std
{
template <>
void swap (Variable& m1, Variable& m2);
};
15 Copyright © Remedy IT
Struct (2)
Variable v;
Variable v2 (“Hello”);
CORBA::String_var myname =
CORBA::String_dup (“Hello”);
// Set a struct member
v.name = CORBA::String_dup (myname.in ());
// Get a struct member
CORBA::String_var l_name =
CORBA::String_dup (v.name.in ());
std::cout << “name” << l_name.in () <<
std::endl;
if (strcmp (v.in (), v2.in () != 0)
{
std::cerr << “names are different”
<<std::endl;
}
C++ C++11
Variable v;
Variable v2 (“Hello”);
std::string myname {“Hello”};
// Set a struct member
v.name (myname);
// Get a struct member
std::cout << “name” << v.name () <<
std::endl;
if (v != v2)
{
std::cerr << “names are different”
<<std::endl;
}
16 Copyright © Remedy IT
C++11 Reference types (1)
An IDL interface maps to so called reference types
Reference types are reference counted, for example
given type A
• Strong reference type behaves like
std::shared_ptr and is available as
IDL::traits<A>::ref_type
• Weak reference type behaves like std::weak_ptr
and is available as
IDL::traits<A>::weak_ref_type
A nil reference type is represented as nullptr
Invoking an operation on a nil reference results in a
INV_OBJREF exception
18
C++11 Reference types (2)
Given IDL type A the mapping delivers
IDL::traits<A> with type traits
interface A
{
// definitions
};
IDL C++11
// Obtain a reference
IDL::traits<A>::ref_type a = // .. obtain a
// reference
// Obtain a weak reference
IDL::traits<A>::weak_ref_type w =
a.weak_reference();
// Obtain a strong reference from a weak one
IDL::traits<A>::ref_type p = w.lock ();
if (a == nullptr) // Legal comparisons
if (a != nullptr ) // legal comparison
if (a) // legal usage, true if a != nullptr
if (!a) // legal usage, true if a == nullptr
if (a == 0) // illegal, results in a compile
// error
delete a; // illegal, results in a compile error
19 Copyright © Remedy IT
C++11 Reference types (2)
Reference types can only be constructed using
CORBA::make_reference
interface A
{
// definitions
};
IDL C++11
// Servant implementation class
class A_impl final :
CORBA::servant_traits<A>::base_type
{
}
// Create a servant reference using
// make_reference
CORBA::servant_traits<A>::ref_type a_ref =
CORBA::make_reference<A_impl> ();
// We could use new, but the resulting
// pointer can’t be used for making any
// CORBA call because the pointer can’t be
// used to construct a reference type which
// is the only thing the API accepts
A_impl* p = new ACE_impl ();
// Or we can obtain a reference from another
// method
IDL::traits<A>::ref_type = foo->get_a ();
20 Copyright © Remedy IT
C++11 Reference types (3)
Widening and narrowing references
interface A
{
// definitions
};
interface B : A
{
// definitions
};
IDL C++11
IDL::traits<B>::ref_type bp = ...
// Implicit widening
IDL::traits<A>::ref_type ap = bp;
// Implicit widening
IDL::traits<Object>::ref_type objp = bp;
// Implicit widening
objp = ap;
// Explicit narrowing
bp = IDL::traits<B>::narrow (ap)
21 Copyright © Remedy IT
Reference types
Using a reference type
class B {
public:
// Store the reference in a member
B (A_ptr a) : a_(A::_duplicate (a)) {}
// Return a reference
A_ptr get_A () { return A::_duplicate
(a_.in ());
private:
A_var a_;
};
22
C++ C++11
class B {
public:
// Store the reference in a member
B (IDL::ref_type<A> a) : a_ (a)
// Return a reference
IDL::ref_type<A> get_A() { return a_;}
private:
IDL::ref_type<A> a_;
};
Copyright © Remedy IT
Argument passing
Simplified rules for argument passing compared to
IDL to C++
No need for new/delete when passing arguments
The C++11 move semantics can be used to prevent
copying of data
Given an argument of A of type P:
• In: for all primitive types, enums, and reference
types, the argument is passed as P. For all other
types, the argument is passed as const P&
• Inout: passed as P&
• Out: passed as P&
• Return type: returned as P
23
Interfaces implementation
Given a local interface A the implementation has to
be derived from IDL::traits<A>::base_type
Given a regular interface A the CORBA servant
implementation has to be derived from
CORBA::servant_traits<A>::base_type
In both cases a client reference is available as
IDL::traits<A>::ref_type
24
Implementing a servant
Implement a CORBA servant for interface A
class A_impl : public virtual
POA::A
{
};
25
C++ C++11
class A_impl : public virtual
CORBA::servant_traits<A>::ref_type
{
};
Copyright © Remedy IT
C++11 Example application
26
CORBA Hello world
interface Hello
{
/// Return a simple string
string get_string ();
/// A method to shutdown the server
oneway void shutdown ();
};
IDL
27
Copyright © Remedy IT
Copyright © Remedy IT
CORBA client
int main(int argc, char* argv[])
{
try
{
// Obtain the ORB
IDL::traits<CORBA::ORB>::ref_type orb = CORBA::ORB_init (argc, argv);
// Create the object reference
IDL::traits<CORBA::Object>::ref_type obj = orb->string_to_object ("file://test.ior");
// Narrow it to the needed type
IDL::traits<Hello>::ref_type hello = IDL::traits<Hello>::narrow (obj);
// Invoke a method, invoking on a nil reference will result in an exception
std::cout << "hello->get_string () returned " << hello->get_string () << std::endl;
// Shutdown the server
hello->shutdown ();
// Cleanup our ORB
orb->destroy ();
}
catch (const std::exception& e)
{
// All exceptions are derived from std::exception
std::cerr << "exception caught: " << e.what () << std::endl;
}
return 0;
}
28
CORBA servant
C++11 CORBA servant for type T must be derived
from CORBA::servant_traits<T>::base_type
class Hello final : public virtual CORBA::servant_traits<Hello>::base_type
{
public:
// Constructor
Hello (IDL::traits<CORBA::ORB>::ref_type orb) : orb_ (orb) {}
// Destructor
virtual ~Hello () {}
// Implement pure virtual methods from the base_type
virtual std::string get_string () override
{
return “Hello!”;
}
virtual void shutdown () override
{
this->orb_->shutdown (false);
}
private:
// Use an ORB reference to shutdown the application.
IDL::traits<CORBA::ORB>::ref_type orb_;
};
29
CORBA server (1)
int main(int argc, char* argv[])
{
try
{
// Obtain our ORB
IDL::traits<CORBA::ORB>::ref_type orb = CORBA::ORB_init (argc, argv);
// Obtain our POA and POAManager
IDL::traits<CORBA::Object>::ref_type obj = orb->resolve_initial_references ("RootPOA");
IDL::traits<PortableServer::POA>::ref_type root_poa =
IDL::traits<PortableServer::POA>::narrow (obj);
IDL::traits<PortableServer::POAManager>::ref_type poaman = root_poa->the_POAManager ();
// Create the servant
CORBA::servant_traits<Hello>::ref_type hello_impl =
CORBA::make_reference<Hello> (orb);
// Activate the servant as CORBA object
PortableServer::ObjectId id = root_poa->activate_object (hello_impl);
IDL::traits<CORBA::Object>::ref_type hello_obj = root_poa->id_to_reference (id);
IDL::traits<Hello>::ref_type hello =
IDL::traits<Hello>::narrow (hello_obj);
// Put the IOR on disk
std::string ior = orb->object_to_string (hello);
std::ofstream fos("test.ior");
fos << ior;
fos.close ();
30
CORBA server (2)
// Activate our POA
poaman->activate ();
// And run the ORB, this method will return at the moment the ORB has been shutdown
orb->run ();
// Cleanup our resources
root_poa->destroy (true, true);
orb->destroy ();
}
catch (const std::exception& e)
{
// Any exception will be caught here
std::cerr << "exception caught: " << e.what () << std::endl;
}
return 0;
}
31
Tips & Tricks
Don’t use new/delete
Use pass by value together with C++11 move
semantics
32
Conclusion
C++11 simplifies CORBA programming
The combination of reference counting and C++11
move semantics make the code much safer and
secure
Application code is much smaller and easier to read
33
TAOX11
Commercial CORBA implementation from Remedy IT
Compliant with IDL to C++11 v1.3
IDL compiler with front end supporting IDL2, IDL3,
and IDL3+
Free evaluation versions available from
https://swsupport.remedy.nl/!
More details at https://taox11.remedy.nl/
34
Want to know more?
Look at TAOX11 at https://taox11.remedy.nl/
Check the Remedy IT provided examples at
https://github.com/RemedyIT/idl2cpp11
Contact us, see https://www.remedy.nl/
35
Contact
36
Remedy IT
Postbus 81
6930 AB Westervoort
The Netherlands
tel.: +31(0)88 – 053 0000
e-mail: sales@remedy.nl
website: https://www.remedy.nl/
Twitter: @RemedyIT
Slideshare: RemedyIT
Subscribe to our mailing list

Contenu connexe

Tendances

Introduction to llvm
Introduction to llvmIntroduction to llvm
Introduction to llvm
Tao He
 

Tendances (20)

C and C++ Industrial Training Jalandhar
C and C++ Industrial Training JalandharC and C++ Industrial Training Jalandhar
C and C++ Industrial Training Jalandhar
 
C programming
C programmingC programming
C programming
 
Introduction to llvm
Introduction to llvmIntroduction to llvm
Introduction to llvm
 
OOP in C++
OOP in C++OOP in C++
OOP in C++
 
C sharp
C sharpC sharp
C sharp
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Syntactic Salt and Sugar Presentation
Syntactic Salt and Sugar PresentationSyntactic Salt and Sugar Presentation
Syntactic Salt and Sugar Presentation
 
COM1407: Introduction to C Programming
COM1407: Introduction to C Programming COM1407: Introduction to C Programming
COM1407: Introduction to C Programming
 
C# in depth
C# in depthC# in depth
C# in depth
 
C programming
C programmingC programming
C programming
 
Syntutic
SyntuticSyntutic
Syntutic
 
What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)What's coming to c# (Tel-Aviv, 2018)
What's coming to c# (Tel-Aviv, 2018)
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 
(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i(2) c sharp introduction_basics_part_i
(2) c sharp introduction_basics_part_i
 
CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
 
C Programming
C ProgrammingC Programming
C Programming
 
The smartpath information systems c plus plus
The smartpath information systems  c plus plusThe smartpath information systems  c plus plus
The smartpath information systems c plus plus
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 

Similaire à Comparing IDL to C++ with IDL to C++11

Similaire à Comparing IDL to C++ with IDL to C++11 (20)

CORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorialCORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorial
 
IDL to C++11 OMG RTWS presentations
IDL to C++11 OMG RTWS presentationsIDL to C++11 OMG RTWS presentations
IDL to C++11 OMG RTWS presentations
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
DCOM Comparison
DCOM ComparisonDCOM Comparison
DCOM Comparison
 
Strategy and best practice for modern RPG
Strategy and best practice for modern RPGStrategy and best practice for modern RPG
Strategy and best practice for modern RPG
 
Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++
 
AMI4CCM, custom DDS connectors, and IDL to C++11
AMI4CCM, custom DDS connectors, and IDL to C++11AMI4CCM, custom DDS connectors, and IDL to C++11
AMI4CCM, custom DDS connectors, and IDL to C++11
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
C++ Interface Versioning
C++ Interface VersioningC++ Interface Versioning
C++ Interface Versioning
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
IDL to C++11 revised submission presentation
IDL to C++11 revised submission presentationIDL to C++11 revised submission presentation
IDL to C++11 revised submission presentation
 
Gude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic ServerGude for C++11 in Apache Traffic Server
Gude for C++11 in Apache Traffic Server
 
Chapter 17 corba
Chapter 17 corbaChapter 17 corba
Chapter 17 corba
 
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1
 
Corba model ppt
Corba model pptCorba model ppt
Corba model ppt
 
Rcpp
RcppRcpp
Rcpp
 
Unix system programming
Unix system programmingUnix system programming
Unix system programming
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 

Plus de Remedy IT

Plus de Remedy IT (20)

Integrating DDS into AXCIOMA, the component approach
Integrating DDS into AXCIOMA, the component approachIntegrating DDS into AXCIOMA, the component approach
Integrating DDS into AXCIOMA, the component approach
 
AXCIOMA, the component framework for distributed, real-time and embedded systems
AXCIOMA, the component framework for distributed, real-time and embedded systemsAXCIOMA, the component framework for distributed, real-time and embedded systems
AXCIOMA, the component framework for distributed, real-time and embedded systems
 
AXCIOMA, the internals, the component framework for distributed, real-time, a...
AXCIOMA, the internals, the component framework for distributed, real-time, a...AXCIOMA, the internals, the component framework for distributed, real-time, a...
AXCIOMA, the internals, the component framework for distributed, real-time, a...
 
Remedy IT Company presentation
Remedy IT Company presentationRemedy IT Company presentation
Remedy IT Company presentation
 
Integrating DDS into AXCIOMA, the component approach
Integrating DDS into AXCIOMA, the component approachIntegrating DDS into AXCIOMA, the component approach
Integrating DDS into AXCIOMA, the component approach
 
Modernizing SCA through new Object Management Group (OMG) standards
Modernizing SCA through new Object Management Group (OMG) standardsModernizing SCA through new Object Management Group (OMG) standards
Modernizing SCA through new Object Management Group (OMG) standards
 
AXCIOMA, the internals, the component framework for distributed, real-time, a...
AXCIOMA, the internals, the component framework for distributed, real-time, a...AXCIOMA, the internals, the component framework for distributed, real-time, a...
AXCIOMA, the internals, the component framework for distributed, real-time, a...
 
Modernizing SCA through new Object Management Group (OMG) standards
Modernizing SCA through new Object Management Group (OMG) standardsModernizing SCA through new Object Management Group (OMG) standards
Modernizing SCA through new Object Management Group (OMG) standards
 
ACE/TAO/CIAO/DAnCE Maintenance overview
ACE/TAO/CIAO/DAnCE Maintenance overviewACE/TAO/CIAO/DAnCE Maintenance overview
ACE/TAO/CIAO/DAnCE Maintenance overview
 
Remedy IT Revised Submission Presentation for the Unified Component Model (UC...
Remedy IT Revised Submission Presentation for the Unified Component Model (UC...Remedy IT Revised Submission Presentation for the Unified Component Model (UC...
Remedy IT Revised Submission Presentation for the Unified Component Model (UC...
 
Revised submission for Unified Component Model (UCM) for Distributed, Real-Ti...
Revised submission for Unified Component Model (UCM) for Distributed, Real-Ti...Revised submission for Unified Component Model (UCM) for Distributed, Real-Ti...
Revised submission for Unified Component Model (UCM) for Distributed, Real-Ti...
 
DDS Programming with IDL to C++11 tutorial
DDS Programming with IDL to C++11 tutorialDDS Programming with IDL to C++11 tutorial
DDS Programming with IDL to C++11 tutorial
 
Component Based DDS with C++11 and R2DDS
Component Based DDS with C++11 and R2DDSComponent Based DDS with C++11 and R2DDS
Component Based DDS with C++11 and R2DDS
 
AXCIOMA, the component framework for distributed, real-time and embedded systems
AXCIOMA, the component framework for distributed, real-time and embedded systemsAXCIOMA, the component framework for distributed, real-time and embedded systems
AXCIOMA, the component framework for distributed, real-time and embedded systems
 
Component Technologies for Fractionated Satellites
Component Technologies for Fractionated SatellitesComponent Technologies for Fractionated Satellites
Component Technologies for Fractionated Satellites
 
UCM Initial Submission presentation
UCM Initial Submission presentationUCM Initial Submission presentation
UCM Initial Submission presentation
 
Remedy IT Initial Submission for the Unified Component Model (UCM) for Distri...
Remedy IT Initial Submission for the Unified Component Model (UCM) for Distri...Remedy IT Initial Submission for the Unified Component Model (UCM) for Distri...
Remedy IT Initial Submission for the Unified Component Model (UCM) for Distri...
 
Unified Component Model for Distributed, Real- Time and Embedded Systems Requ...
Unified Component Model for Distributed, Real- Time and Embedded Systems Requ...Unified Component Model for Distributed, Real- Time and Embedded Systems Requ...
Unified Component Model for Distributed, Real- Time and Embedded Systems Requ...
 
Request For Proposal Unified Component Model for Distributed, Real-Time and E...
Request For Proposal Unified Component Model for Distributed, Real-Time and E...Request For Proposal Unified Component Model for Distributed, Real-Time and E...
Request For Proposal Unified Component Model for Distributed, Real-Time and E...
 
Test What Matters Most
Test What Matters MostTest What Matters Most
Test What Matters Most
 

Dernier

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Dernier (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Comparing IDL to C++ with IDL to C++11

  • 1. Comparing IDL to C++ with IDL to C++11 Simplify development of CORBA, DDS, and CCM based applications
  • 2. Overview This presentations gives a comparison between the IDL to C++ and IDL to C++11 language mappings It assumes basic understanding of IDL and CORBA For more information take a look at our TAOX11 website at https://taox11.remedy.nl 2
  • 4. Problems with IDL to C++ The IDL to C++ language mapping is from the 90’s IDL to C++ could not depend on various C++ features as • C++ namespace • C++ exceptions • Standard Template Library As a result • Mapping is hard to use correctly • Uses its own constructs for everything 4
  • 5. Why a new language mapping? IDL to C++ language mapping is impossible to change because • Multiple implementations are on the market (open source and commercial) • A huge amount of applications have been developed An updated IDL to C++ language mapping would force all vendors and users to update their products The standardization of a new C++ revision in 2011 (ISO/IEC 14882:2011, called C++11) gives the opportunity to define a new language mapping • C++11 features are not backward compatible with C++03 or C++99 • A new C++11 mapping leaves the existing mapping intact 5
  • 6. Goals Simplify mapping for C++ Make use of the new C++11 features to • Reduce amount of application code • Reduce amount of possible errors made • Gain runtime performance • Speedup development and testing Faster time to market Reduced costs Reduced training time 6
  • 7. OMG Specification IDL to C++11 v1.3 available from the OMG website at http://www.omg.org/spec/CPP11/ Revision Task Force (RTF) is active to work on issues reported 7
  • 9. Modules An IDL module maps to a C++ namespace with the same name, same for both mappings module M { // definitions }; module A { module B { // definitions }; }; IDL C++/C++11 namespace M { // definitions }; namespace A { namespace B { // definitions }; }; 9 Copyright © Remedy IT
  • 10. Basic types IDL C++ C++11 C++11 Default value short CORBA::Short int16_t 0 long CORBA::Long int32_t 0 long long CORBA::LongLong int64_t 0 unsigned short CORBA::UShort uint16_t 0 unsigned long CORBA::ULong uint32_t 0 unsigned long long CORBA::ULongLong uint64_t 0 float CORBA::Float float 0.0 double CORBA::Double double 0.0 long double CORBA::LongDouble long double 0.0 char CORBA::Char char 0 wchar CORBA::WChar wchar_t 0 boolean CORBA::Boolean bool false octet CORBA::Octet uint8_t 0 10
  • 11. Constants const string name = "testing"; interface A { const float pi = 3.14159; }; const char *const name = "testing"; class A { public: static const CORBA::Float pi; }; C++ C++11 const std::string name {"testing"}; class A { public: static constexpr float pi {3.14159F}; }; 11 Copyright © Remedy IT
  • 12. String types string name; wstring w_name; CORBA::String_var name; CORBA::WString_var w_name; name = CORBA::string_dup (“Hello”); std::cout << name.in () << std::endl; C++ C++11 std::string name {“Hello”}; std::wstring w_name; std::cout << name << std::endl; 12 Copyright © Remedy IT
  • 13. Enum enum Color { red, green, blue }; enum Color { red, green, blue }; Color mycolor mycolor = red; if (mycolor == red) { std::cout << “Correct color”; } C++ C++11 enum class Color : uint32_t { red, green, blue }; Color mycolor {Color::red}; if (mycolor == Color::red) { std::cout << “Correct color”; } 13 Copyright © Remedy IT
  • 14. Sequence typedef sequence<long> LongSeq; LongSeq mysequence; // Add an element to the vector Mysequence.length (1) Mysequence[1] = 5; for (CORBA::ULong i = 0; I < mysequence.length(); i++) { std::cout << mysequence[i] << “;” << std::end; } C++ C++11 LongSeq mysequence; // Add an element to the vector mysequence.push_back (5); // Dump using C++11 range based for loop for (const int32_t& e : mysequence) { std::cout << e << “;” << std::end; } 14 Copyright © Remedy IT
  • 15. Struct (1) struct Variable { string name; }; struct Variable { string name; }; C++ C++11 class Variable final { public: Variable (); ~Variable (); Variable (const Variable&); Variable (Variable&&); Variable& operator= (const Variable& x); Variable& operator= (Variable&& x); explicit Variable (std::string name); void name (const std::string& _name); void name (std::string&& _name); const std::string& name () const; std::string& name (); }; namespace std { template <> void swap (Variable& m1, Variable& m2); }; 15 Copyright © Remedy IT
  • 16. Struct (2) Variable v; Variable v2 (“Hello”); CORBA::String_var myname = CORBA::String_dup (“Hello”); // Set a struct member v.name = CORBA::String_dup (myname.in ()); // Get a struct member CORBA::String_var l_name = CORBA::String_dup (v.name.in ()); std::cout << “name” << l_name.in () << std::endl; if (strcmp (v.in (), v2.in () != 0) { std::cerr << “names are different” <<std::endl; } C++ C++11 Variable v; Variable v2 (“Hello”); std::string myname {“Hello”}; // Set a struct member v.name (myname); // Get a struct member std::cout << “name” << v.name () << std::endl; if (v != v2) { std::cerr << “names are different” <<std::endl; } 16 Copyright © Remedy IT
  • 17. C++11 Reference types (1) An IDL interface maps to so called reference types Reference types are reference counted, for example given type A • Strong reference type behaves like std::shared_ptr and is available as IDL::traits<A>::ref_type • Weak reference type behaves like std::weak_ptr and is available as IDL::traits<A>::weak_ref_type A nil reference type is represented as nullptr Invoking an operation on a nil reference results in a INV_OBJREF exception 18
  • 18. C++11 Reference types (2) Given IDL type A the mapping delivers IDL::traits<A> with type traits interface A { // definitions }; IDL C++11 // Obtain a reference IDL::traits<A>::ref_type a = // .. obtain a // reference // Obtain a weak reference IDL::traits<A>::weak_ref_type w = a.weak_reference(); // Obtain a strong reference from a weak one IDL::traits<A>::ref_type p = w.lock (); if (a == nullptr) // Legal comparisons if (a != nullptr ) // legal comparison if (a) // legal usage, true if a != nullptr if (!a) // legal usage, true if a == nullptr if (a == 0) // illegal, results in a compile // error delete a; // illegal, results in a compile error 19 Copyright © Remedy IT
  • 19. C++11 Reference types (2) Reference types can only be constructed using CORBA::make_reference interface A { // definitions }; IDL C++11 // Servant implementation class class A_impl final : CORBA::servant_traits<A>::base_type { } // Create a servant reference using // make_reference CORBA::servant_traits<A>::ref_type a_ref = CORBA::make_reference<A_impl> (); // We could use new, but the resulting // pointer can’t be used for making any // CORBA call because the pointer can’t be // used to construct a reference type which // is the only thing the API accepts A_impl* p = new ACE_impl (); // Or we can obtain a reference from another // method IDL::traits<A>::ref_type = foo->get_a (); 20 Copyright © Remedy IT
  • 20. C++11 Reference types (3) Widening and narrowing references interface A { // definitions }; interface B : A { // definitions }; IDL C++11 IDL::traits<B>::ref_type bp = ... // Implicit widening IDL::traits<A>::ref_type ap = bp; // Implicit widening IDL::traits<Object>::ref_type objp = bp; // Implicit widening objp = ap; // Explicit narrowing bp = IDL::traits<B>::narrow (ap) 21 Copyright © Remedy IT
  • 21. Reference types Using a reference type class B { public: // Store the reference in a member B (A_ptr a) : a_(A::_duplicate (a)) {} // Return a reference A_ptr get_A () { return A::_duplicate (a_.in ()); private: A_var a_; }; 22 C++ C++11 class B { public: // Store the reference in a member B (IDL::ref_type<A> a) : a_ (a) // Return a reference IDL::ref_type<A> get_A() { return a_;} private: IDL::ref_type<A> a_; }; Copyright © Remedy IT
  • 22. Argument passing Simplified rules for argument passing compared to IDL to C++ No need for new/delete when passing arguments The C++11 move semantics can be used to prevent copying of data Given an argument of A of type P: • In: for all primitive types, enums, and reference types, the argument is passed as P. For all other types, the argument is passed as const P& • Inout: passed as P& • Out: passed as P& • Return type: returned as P 23
  • 23. Interfaces implementation Given a local interface A the implementation has to be derived from IDL::traits<A>::base_type Given a regular interface A the CORBA servant implementation has to be derived from CORBA::servant_traits<A>::base_type In both cases a client reference is available as IDL::traits<A>::ref_type 24
  • 24. Implementing a servant Implement a CORBA servant for interface A class A_impl : public virtual POA::A { }; 25 C++ C++11 class A_impl : public virtual CORBA::servant_traits<A>::ref_type { }; Copyright © Remedy IT
  • 26. CORBA Hello world interface Hello { /// Return a simple string string get_string (); /// A method to shutdown the server oneway void shutdown (); }; IDL 27 Copyright © Remedy IT Copyright © Remedy IT
  • 27. CORBA client int main(int argc, char* argv[]) { try { // Obtain the ORB IDL::traits<CORBA::ORB>::ref_type orb = CORBA::ORB_init (argc, argv); // Create the object reference IDL::traits<CORBA::Object>::ref_type obj = orb->string_to_object ("file://test.ior"); // Narrow it to the needed type IDL::traits<Hello>::ref_type hello = IDL::traits<Hello>::narrow (obj); // Invoke a method, invoking on a nil reference will result in an exception std::cout << "hello->get_string () returned " << hello->get_string () << std::endl; // Shutdown the server hello->shutdown (); // Cleanup our ORB orb->destroy (); } catch (const std::exception& e) { // All exceptions are derived from std::exception std::cerr << "exception caught: " << e.what () << std::endl; } return 0; } 28
  • 28. CORBA servant C++11 CORBA servant for type T must be derived from CORBA::servant_traits<T>::base_type class Hello final : public virtual CORBA::servant_traits<Hello>::base_type { public: // Constructor Hello (IDL::traits<CORBA::ORB>::ref_type orb) : orb_ (orb) {} // Destructor virtual ~Hello () {} // Implement pure virtual methods from the base_type virtual std::string get_string () override { return “Hello!”; } virtual void shutdown () override { this->orb_->shutdown (false); } private: // Use an ORB reference to shutdown the application. IDL::traits<CORBA::ORB>::ref_type orb_; }; 29
  • 29. CORBA server (1) int main(int argc, char* argv[]) { try { // Obtain our ORB IDL::traits<CORBA::ORB>::ref_type orb = CORBA::ORB_init (argc, argv); // Obtain our POA and POAManager IDL::traits<CORBA::Object>::ref_type obj = orb->resolve_initial_references ("RootPOA"); IDL::traits<PortableServer::POA>::ref_type root_poa = IDL::traits<PortableServer::POA>::narrow (obj); IDL::traits<PortableServer::POAManager>::ref_type poaman = root_poa->the_POAManager (); // Create the servant CORBA::servant_traits<Hello>::ref_type hello_impl = CORBA::make_reference<Hello> (orb); // Activate the servant as CORBA object PortableServer::ObjectId id = root_poa->activate_object (hello_impl); IDL::traits<CORBA::Object>::ref_type hello_obj = root_poa->id_to_reference (id); IDL::traits<Hello>::ref_type hello = IDL::traits<Hello>::narrow (hello_obj); // Put the IOR on disk std::string ior = orb->object_to_string (hello); std::ofstream fos("test.ior"); fos << ior; fos.close (); 30
  • 30. CORBA server (2) // Activate our POA poaman->activate (); // And run the ORB, this method will return at the moment the ORB has been shutdown orb->run (); // Cleanup our resources root_poa->destroy (true, true); orb->destroy (); } catch (const std::exception& e) { // Any exception will be caught here std::cerr << "exception caught: " << e.what () << std::endl; } return 0; } 31
  • 31. Tips & Tricks Don’t use new/delete Use pass by value together with C++11 move semantics 32
  • 32. Conclusion C++11 simplifies CORBA programming The combination of reference counting and C++11 move semantics make the code much safer and secure Application code is much smaller and easier to read 33
  • 33. TAOX11 Commercial CORBA implementation from Remedy IT Compliant with IDL to C++11 v1.3 IDL compiler with front end supporting IDL2, IDL3, and IDL3+ Free evaluation versions available from https://swsupport.remedy.nl/! More details at https://taox11.remedy.nl/ 34
  • 34. Want to know more? Look at TAOX11 at https://taox11.remedy.nl/ Check the Remedy IT provided examples at https://github.com/RemedyIT/idl2cpp11 Contact us, see https://www.remedy.nl/ 35
  • 35. Contact 36 Remedy IT Postbus 81 6930 AB Westervoort The Netherlands tel.: +31(0)88 – 053 0000 e-mail: sales@remedy.nl website: https://www.remedy.nl/ Twitter: @RemedyIT Slideshare: RemedyIT Subscribe to our mailing list