15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George...

15
19 July 2022 CORBA Object-by-Value An overview of the value type and its IDL-to- C++ mapping. George Edwards <[email protected]> Institute for Software- Integrated Systems Vanderbilt University

Transcript of 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George...

Page 1: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

18 April 2023

CORBA Object-by-ValueAn overview of the value type and its IDL-to-C++ mapping.

George Edwards<[email protected]>

Institute for Software-Integrated Systems

Vanderbilt University

Page 2: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

What is Object-by-Value?

Object-by-Value (OBV) is the CORBA mechanism for enabling objects to have pass-by-value semantics in CORBA operations.

Conventional CORBA objects always have pass-by-reference semantics.

The IDL keyword valuetype declares an object that will be passed by value.

Valuetype instances are guaranteed to be local to the context in which they are used.

Page 3: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Object-by-Value Semantics

OBV implies similar semantics to pass-by-value in standard programming languages. The receiving entity of a valuetype

parameter (or returned object) instantiates a new object with identical state to the parameter.

The new instance has a separate identity and no relationship to the callers parameter.

OBV requires that the receiving entity have access to an implementation of the valuetype.

Page 4: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

When to Use Valuetypes

Valuetypes are often useful when:

An application needs a copy of an object.

An objects primary purpose is encapsulation of data, rather than operation implementations.

An application needs the performance predictability of local method invocations.

An application needs to transfer an arbitrarily complex or recursive tree, lattice, or other graph data structure.

CASE STUDY:

Valuetypes in the CORBA Component Model

CCM employs valuetypes for events and cookies.

Events are messages that are transmitted asynchronously between components.

Cookies encapsulate port connection ID information.

Page 5: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Basic Valuetype Capabilities

An IDL valuetype can:

have operations, public and private attributes, and factories.

be recursively defined. be declared abstract. inherit from a single concrete

valuetype. inherit from multiple abstract

valuetypes.

Valuetypes in CCM (cont.)

An abstract valuetype serves as a base forall event types. When a IDL eventtype isdeclared, a valuetype that inherits from EventBase is implied.

module Components { abstract valuetype EventBase {};};

Cookies store connection identifiers as asequence of octets:

module Components { valuetype Cookie { private CORBA::OctetSeq cookieValue; };};

Page 6: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Valuetype C++ Mapping (1/3)

An IDL valuetype maps to an abstract base

class with the same name...

class Cookie : public virtual CORBA::ValueBase{ // ... protected: virtual void cookieValue ( const CORBA::OctetSeq &) = 0; virtual const CORBA::OctetSeq& cookieValue (void) const = 0; virtual CORBA::OctetSeq& cookieValue (void) = 0; Cookie (void); virtual ~Cookie (void); // ...};

Inherits from CORBA::ValueBase.

Pure virtual methods corresponding to operations.

Pure virtual accessor and modifier methods corresponding to state members.

Protected default constructor and destructor.

Page 7: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Valuetype C++ Mapping (2/3)

a class with OBV_ prepended to the

fully-scoped name

Inherits from the abstract base class. Is abstract if the valuetype has operations; concrete otherwise. Provides default implementations of accessors and modifiers. Provides a protected constructor that initializes state members.

namespace OBV_Components { class Cookie : public virtual Components::Cookie { // ... protected: virtual void cookieValue ( const CORBA::OctetSeq &); virtual CORBA::OctetSeq& cookieValue (void); Cookie (const CORBA::OctetSeq&); private: CORBA::OctetSeq _pd_cookieValue; // ... };

Page 8: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Valuetype C++ Mapping (3/3)

Inherits from CORBA::ValueFactoryBase.

Each factory method declared in IDL maps to pure virtual method that returns an instance of the valuetype. Must be registered with the ORB via ORB::register_value_factory().

and a factory class with _init appended to the valuetype name.

class Cookie_init : public virtual CORBA::ValueFactoryBase{ public: Cookie_init (void); virtual CORBA::ValueBase * create_for_unmarshal (void); protected: virtual ~Cookie_init (void);};

Page 9: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Unmarshaling Valuetypes

The ORB calls create_for_unmarshal() to create an instance of a valuetype received as a parameter or return type.

The factory class is concrete for valueboxes and valuetypes that have no IDL factories or operations; an implementation of create_for_unmarshal() is generated.

Otherwise, the programmer must provide an implementation of create_for_unmarshal() and any factories declared in IDL.

ValueFactoryBase declares a pure virtual create_for_unmarshal() method.

class ValueFactoryBase{public: void _add_ref (void); void _remove_ref (void); virtual CORBA::ValueBase * create_for_unmarshal (void)=0; virtual CORBA::AbstractBase * create_for_unmarshal_abstract();};

Page 10: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Abstract Valuetypes

Have only operations no state or factories.

Have no generated OBV_ classes.

Are not subject to single inheritance restrictions.

Are inherited as public virtual base classes.

Cannot be instantiated; cannot be parameters or the return type of an IDL operation.

Essentially just a bundle of operation signatures.

An IDL valuetype can be declared abstract.

abstract interfaceinterface

abstractvaluetype

valuetype

single

multiple

Page 11: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Supporting a Concrete Interface

A valuetype that supports a concrete interface is NOT a subtype of the interface and is NOT substitutable.

The interfaces operations are mapped to pure virtual methods in the valuetype ABC.

A skeleton (POA_) class is generated for the valuetype that inherits from the interface skeleton.

The valuetype can be registered with a POA and manipulated via an object reference of the interface type; pass-by-reference semantics apply.

A valuetype is declared to support a concrete interface with the IDL keyword supports.

Page 12: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Supporting an Abstract Interface

Abstract interfaces inherit from CORBA::AbstractBase, not CORBA::Object.

Abstract interfaces have unique parameter passing semantics to their operations.

A valuetype that supports an abstract interface IS a subtype of the interface and IS substitutable.

Allows determination of pass-by-value vs. pass-by-reference semantics to be made at run-time.

Valuetypes can support multiple abstract interfaces.

Page 13: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Reference Counting

CORBA::ValueBase declares pure virtual _add_ref() and _remove_ref() methods.

CORBA::DefaultValueRefCountBase can serve as a base class for valuetypes that will never be registered with a POA.

PortableServer::ValueRefCountBase must serve as a base class for valuetypes that will be registered with a POA.

Valuetypes must fulfill the ValueBase reference counting interface with custom implementations or mix-in classes.

Page 14: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Other Features

Any IDL type except a valuetype can be boxed. Valueboxes may not be a subtype or base type. Valueboxes for string and wstring are included in the CORBA

module as StringValue and WStringValue.

A valuetype with only a single state member is a valuebox.

A programmer can provide custom code to marshal and unmarshal valuetype instances.

A valuetype that is declared custom in IDL implicitly inherits from the abstract valuetype CustomMarshal.

The concrete valuetype must provide implementations of the marshal () and unmarshal () operations.

Intended to facilitate the integration of legacy code.

Page 15: 15 May, 2015 CORBA Object-by-Value An overview of the value type and its IDL-to-C++ mapping. George Edwards Institute for Software-Integrated Systems Vanderbilt.

Vanderbilt UniversityNovember 17,

2003

George EdwardsCORBA Object-by-Value

Conclusions The valuetype is extremely useful, but:

Has some convoluted mapping rules. Doesnt totally solve the original problem.

Standard CORBA objects still cant be passed by value. Has some questionable features.

Questions?