Presentation is loading. Please wait.

Presentation is loading. Please wait.

CORBA Object-by-Value

Similar presentations


Presentation on theme: "CORBA Object-by-Value"— Presentation transcript:

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

2 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. Vanderbilt University

3 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 caller’s parameter. OBV requires that the receiving entity have access to an implementation of the valuetype. Vanderbilt University

4 When to Use Valuetypes Valuetypes are often useful when:
An application needs a “copy” of an object. An object’s 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. Vanderbilt University

5 Basic Valuetype Capabilities
Valuetypes in CCM (cont.) An abstract valuetype serves as a base for all event types. When a IDL eventtype is declared, a valuetype that inherits from EventBase is implied. module Components { abstract valuetype EventBase {}; }; Cookies store connection identifiers as a sequence of octets: valuetype Cookie { private CORBA::OctetSeq cookieValue; 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. Vanderbilt University

6 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. Vanderbilt University

7 Valuetype C++ Mapping (2/3)
…a class with “OBV_” prepended to the fully-scoped name… 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; }; 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. Vanderbilt University

8 Valuetype C++ Mapping (3/3)
…and a factory class with “_init” appended to the valuetype name. 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(). class Cookie_init : public virtual CORBA::ValueFactoryBase { public: Cookie_init (void); virtual CORBA::ValueBase * create_for_unmarshal (void); protected: virtual ~Cookie_init (void); }; Vanderbilt University

9 Unmarshaling Valuetypes
ValueFactoryBase declares a pure virtual create_for_unmarshal() method. 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. 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(); }; Vanderbilt University

10 Abstract Valuetypes An IDL valuetype can be declared abstract.
interface valuetype single multiple 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. Vanderbilt University

11 Supporting a Concrete Interface
A valuetype is declared to support a concrete interface with the IDL keyword supports. A valuetype that supports a concrete interface is NOT a subtype of the interface and is NOT substitutable. The interface’s 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. Vanderbilt University

12 Supporting an Abstract Interface
Valuetypes can support multiple abstract interfaces. 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. Vanderbilt University

13 Reference Counting Valuetypes must fulfill the ValueBase reference counting interface with custom implementations or mix-in classes. 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. Vanderbilt University

14 Other Features A valuetype with only a single state member is a “valuebox.” 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 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. Vanderbilt University

15 Conclusions The valuetype is extremely useful, but: Questions?
Has some convoluted mapping rules. Doesn’t totally solve the original problem. Standard CORBA objects still can’t be passed by value. Has some questionable features. Questions? Vanderbilt University


Download ppt "CORBA Object-by-Value"

Similar presentations


Ads by Google