SlideShare uma empresa Scribd logo
1 de 35
Baixar para ler offline
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 http://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.2 available from the OMG website
as formal/2015-08-01
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 :
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.2
IDL compiler with front end supporting IDL2, IDL3,
and IDL3+
Free evaluation versions available from
http://swsupport.remedy.nl!
More details at http://taox11.remedy.nl
34
Want to know more?
Look at TAOX11 at http://taox11.remedy.nl
Check the Remedy IT provided examples at
https://github.com/RemedyIT/idl2cpp11
Contact us, see http://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: www.remedy.nl
Twitter: @RemedyIT
Slideshare: RemedyIT
Subscribe to our mailing list

Mais conteúdo relacionado

Mais procurados

05 rpc-case studies
05 rpc-case studies05 rpc-case studies
05 rpc-case studies
hushu
 
Boogie 2011 Hi-Lite
Boogie 2011 Hi-LiteBoogie 2011 Hi-Lite
Boogie 2011 Hi-Lite
AdaCore
 
Net serialization
Net serializationNet serialization
Net serialization
Greg Sohl
 
CORBA Component Model
CORBA Component Model CORBA Component Model
CORBA Component Model
Elham Hormozi
 
Component object model and
Component object model andComponent object model and
Component object model and
Saransh Garg
 
RMI and CORBA Why both are valuable tools
RMI and CORBA Why both are valuable toolsRMI and CORBA Why both are valuable tools
RMI and CORBA Why both are valuable tools
elliando dias
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lines
lokeshG38
 

Mais procurados (20)

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...
 
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
 
Objc
ObjcObjc
Objc
 
05 rpc-case studies
05 rpc-case studies05 rpc-case studies
05 rpc-case studies
 
COM
COMCOM
COM
 
Boogie 2011 Hi-Lite
Boogie 2011 Hi-LiteBoogie 2011 Hi-Lite
Boogie 2011 Hi-Lite
 
COM Introduction
COM IntroductionCOM Introduction
COM Introduction
 
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
 
Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)Component Object Model (COM, DCOM, COM+)
Component Object Model (COM, DCOM, COM+)
 
C O R B A Unit 4
C O R B A    Unit 4C O R B A    Unit 4
C O R B A Unit 4
 
Common Object Request Broker Architecture - CORBA
Common Object Request Broker Architecture - CORBACommon Object Request Broker Architecture - CORBA
Common Object Request Broker Architecture - CORBA
 
Corba model ppt
Corba model pptCorba model ppt
Corba model ppt
 
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
 
Presentation On Com Dcom
Presentation On Com DcomPresentation On Com Dcom
Presentation On Com Dcom
 
Net serialization
Net serializationNet serialization
Net serialization
 
Corba by Example
Corba by ExampleCorba by Example
Corba by Example
 
CORBA Component Model
CORBA Component Model CORBA Component Model
CORBA Component Model
 
Component object model and
Component object model andComponent object model and
Component object model and
 
RMI and CORBA Why both are valuable tools
RMI and CORBA Why both are valuable toolsRMI and CORBA Why both are valuable tools
RMI and CORBA Why both are valuable tools
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lines
 

Semelhante a Comparing IDL to C++ with IDL to C++11

Semelhante a 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
 
AMI4CCM_IDL2CPP
AMI4CCM_IDL2CPPAMI4CCM_IDL2CPP
AMI4CCM_IDL2CPP
 
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
 
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
 
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++
 
Chapter 17 corba
Chapter 17 corbaChapter 17 corba
Chapter 17 corba
 
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
 
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
 
Rcpp
RcppRcpp
Rcpp
 
C LANGUAGE NOTES
C LANGUAGE NOTESC LANGUAGE NOTES
C LANGUAGE NOTES
 
Unix system programming
Unix system programmingUnix system programming
Unix system programming
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 

Mais de Remedy IT

F6COM: A Case Study in Extending Container Services through Connectors
F6COM: A Case Study in Extending Container Services through ConnectorsF6COM: A Case Study in Extending Container Services through Connectors
F6COM: A Case Study in Extending Container Services through Connectors
Remedy IT
 
Test What Matters Most
Test What Matters MostTest What Matters Most
Test What Matters Most
Remedy IT
 

Mais de Remedy IT (20)

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
 
Remedy IT Company presentation
Remedy IT Company presentationRemedy IT Company presentation
Remedy IT Company presentation
 
Comparing IDL to C++ with IDL to C++11
Comparing IDL to C++ with IDL to C++11Comparing IDL to C++ with IDL to C++11
Comparing IDL to C++ with IDL to C++11
 
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...
 
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
 
IDL to C++03 RFC
IDL to C++03 RFCIDL to C++03 RFC
IDL to C++03 RFC
 
Model Driven, Component Based Development for CBDDS and IDL to C++11
Model Driven, Component Based Development for CBDDS and IDL to C++11Model Driven, Component Based Development for CBDDS and IDL to C++11
Model Driven, Component Based Development for CBDDS and IDL to C++11
 
F6COM: A Case Study in Extending Container Services through Connectors
F6COM: A Case Study in Extending Container Services through ConnectorsF6COM: A Case Study in Extending Container Services through Connectors
F6COM: A Case Study in Extending Container Services through Connectors
 
Draft Request For Proposal Unified Component Model for Distributed, Real-Time...
Draft Request For Proposal Unified Component Model for Distributed, Real-Time...Draft Request For Proposal Unified Component Model for Distributed, Real-Time...
Draft Request For Proposal Unified Component Model for Distributed, Real-Time...
 
Test What Matters Most
Test What Matters MostTest What Matters Most
Test What Matters Most
 

Último

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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...
 

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 http://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.2 available from the OMG website as formal/2015-08-01 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 : 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.2 IDL compiler with front end supporting IDL2, IDL3, and IDL3+ Free evaluation versions available from http://swsupport.remedy.nl! More details at http://taox11.remedy.nl 34
  • 34. Want to know more? Look at TAOX11 at http://taox11.remedy.nl Check the Remedy IT provided examples at https://github.com/RemedyIT/idl2cpp11 Contact us, see http://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: www.remedy.nl Twitter: @RemedyIT Slideshare: RemedyIT Subscribe to our mailing list