Previous Table of Contents Next


19.11.3 Mapping an OMG Object Service to Automation


   This section provides an example of mapping an OMG-defined interface to an equivalent Automation interface. This example is based on the OMG Naming Service and follows the mapping rules from the Mapping: Automation and CORBA chapter. The Naming Service is defined by two interfaces and some associated types, which are scoped in the OMG IDL CosNaming module.

   Table 19-10 Interfaces of the OMG Naming Service

Interface Description
CosNaming::NamingContext Used by a client to establish the name space in which new associations between names and object references can be created, and to retrieve an object reference that has been associated with a given name.
CosNaming::BindingIterator Used by a client to establish a list of registered names that exist within a naming context.

   Microsoft ODL does not explicitly support the notions of modules or scoping domains. To avoid name conflicts, all types defined in the scoping space of CosNaming are expanded to global names.

   The data type portion (interfaces excluded) of the CosNaming interface is shown next.

   // OMG IDL

   module CosNaming{ typedef string Istring; struct NameComponent { Istring id; Istring kind; }; typedef sequence <NameComponent> Name; enum BindingType { nobject, ncontext }; struct Binding {

   Name binding_name;

   BindingType binding_type;};typedef sequence <Binding> BindingList;

   interface BindingIterator;interface NamingContext;// ...

   }

   The corresponding portion (interfaces excluded) of the Microsoft ODL interface is shown next.

   [uuid(a1789c86-1b2c-11cf-9884-08000970dac7)] // from COMID associa-

   tion library CosNaming {

   importlib(“stdole32.tlb?);importlib(“corba.tlb?); / for standard CORBA typestypedef CORBA_string CosNaming_Istring;[uuid((04b8a791-338c-afcf-1dec-cf2733995279), help-

   string(“struct NameComponent?),

   oleautomation, dual]interface CosNaming_NameComponent: ICORBAStruct {[propget] HRESULT id([out, retval]CosNaming_Istring **val);[propput] HRESULT id([in]CosNaming_IString* val);[propget] HRESULT kind([out, retval]CosNaming_Istring ** val);[propget] HRESULT kind([in]CosNaming_Istring *val);

   };

   # define Name SAFEARRAY(CosNaming_NameComponent *) // typedef doesn’t worktypedef enum { [helpstring(“nobject?)]nobject,

   [helpstring(“ncontext?)]ncontext} CosNaming_BindingType;#define CosNaming_BindingList SAFEARRAY(CosNaming_Binding *)

   [uuid(58fbe618-2d20-d19f-1dc2-560cc6195add),helpstring(“struct Binding?),oleautomation, dual]

   interface DICosNaming_Binding: ICORBAStruct {[propget] HRESULT binding_name([retval, out]CosNaming_IString ** val);[propput] HRESULT binding_name([in] CosNaming_IString * vall);[propget] HRESULT binding_type([retval, out]CosNaming_BindingType *val);[propset] HRESULT binding_type([in] CosNaming_BindingType val);};# define CosNaming_BindingList SAFEAR-

   RAY(CosNaming_Binding)interface DICosNaming_BindingIterator;interface DICosNaming_NamingContext;// ...

   };

   The types scoped in an OMG IDL interface are also expanded using the notation [<modulename>_]*[<interfacename>_]typename. Thus the types defined within the CosNaming::NamingContext interface (shown next) are expanded in Microsoft ODL as shown in the second following example.

   module CosNaming{// ...interface NamingContext

   { enum NotFoundReason { missing_node, not_context, not_object }; exception NotFound {

   NotFoundReason why;

   Name rest_of_name; }; exception CannotProceed {

   NamingContext cxt;

   Name rest_of_name; }; exception InvalidName {}; exception AlreadyBound {}; exception NotEmpty {}; void bind(in Name n, in Object obj)

   raises( NotFound, CannotProceed, InvalidName, AlreadyBound ); void rebind(in Name n, in Object obj) raises( NotFound, CannotProceed, InvalidName );

   void bind_context(in Name n, in NamingContext nc) raises( NotFound, CannotProceed, InvalidName, AlreadyBound );

   void rebind_context(in Name n, in NamingContext nc) raises( NotFound, CannotProceed, InvalidName ); Object resolve(in Name n) raises( NotFound, CannotProceed, InvalidName ); void unbind(in Name n)

   raises( NotFound, CannotProceed, InvalidName ); NamingContext new_context(); NamingContext bind_new_context(in Name n)

   raises( NotFound, AlreadyBound, CannotProceed, InvalidName ); void destroy() raises( NotEmpty ); void list(in unsigned long how_many, out BindingList bl, out BindingIterator bi );

   };// ...};

   [uuid(d5991293-3e9f-0e16-1d72-7858c85798d1)] library CosNaming

    { // ...interface DICosNaming_NamingContext;[uuid(311089b4-8f88-30f6-1dfb-9ae72ca5b337),

   helpstring(“exception NotFound?),oleautomation, dual]interface DICosNaming_NamingContext_NotFound:

   ICORBAException {[propget] HRESULT why([out, retval] long* _val);[propput] HRESULT why([in] long _val);[propget] HRESULT rest_of_name([out, retval] CosNaming_Name ** _val);[propput] HRESULT rest_of_name([in] CosNaming_Name * _val);

   };

   [uuid(d2fc8748-3650-cedd-1df6-026237b92940),helpstring(“exception CannotProceed?),oleautomation, dual]

   interface DICosNaming_NamingContext_CannotProceed:

   DICORBAException{[propget] HRESULT cxt([out, retval] DICosNaming_NamingContext ** _val);[propput] HRESULT cxt([in] DICosNaming_NamingContext * _val);[propget] HRESULT rest_of_name([out, retval] CosNaming_Name ** _val);[propput] HRESULT rest_of_name([in] CosNaming_Name * _val);};[uuid(7edaca7a-c123-42a1-1dca-a7e317aafe69),

   helpstring(“exception InvalidName?),oleautomation, dual]interface DICosNaming_NamingContext_InvalidName: DICORBAException {};

   [uuid(fee85a90-1f6b-c47a-1dd0-f1a2fc1ab67f),helpstring(“exception AlreadyBound?),oleautomation, dual]

   interface DICosNaming_NamingContext_AlreadyBound: DICORBAException {};

   [uuid(8129b3e1-16cf-86fc-1de4-b3080e6184c3),helpstring(“exception NotEmpty?), oleautomation, dual]

   interface CosNaming_NamingContext_NotEmpty:

   DICORBAException {};typedef enum {[helpstring(“missing_node?)]NamingContext_missing_node,

   [helpstring(“not_context?) NamingContext_not_context,

   [helpstring(“not_object?) NamingContext_not_object} CosNaming_NamingContext_NotFoundReason;[uuid(4bc122ed-f9a8-60d4-1dfb-0ff1dc65b39a),

   helpstring(“NamingContext?),

   oleautomation,dual]interface DICosNaming_NamingContext {HRESULT bind([in] CosNaming_Name * n, [in] IDispatch * obj,

   [out, optional] VARIANT * _user_exception);HRESULT rebind([in] CosNaming_Name * n, in] IDispatch * obj,[out, optional] VARIANT * _user_exception);

   HRESULT bind_context([in] CosNaming_Name * n,[in] DICosNaming_NamingContext * nc, [out, optional] VARIANT * _user_exception);

   HRESULT rebind_context([in] CosNaming_Name * n,[in] DICosNaming_NamingContext * nc,[out, optional ] VARIANT * _user_exception);

   HRESULT resolve([in] CosNaming_Name * n,

   [out, retval] IDispatch** pResult,[out, optional] VARIANT * _user_exception)HRESULT unbind([in] CosNaming_Name * n,

   [out, optional] VARIANT * _user_exception);HRESULT new_context([out, retval] DICosNaming_NamingContext ** pResult);HRESULT bind_new_context([in] CosNaming_Name * n,

   [out, retval] DICosNaming_NamingContext ** pResult,

   [out, optional] VARIANT * _user_exception);HRESULT destroy([out, optional] VARIANT* _user_exception);HRESULT list([in] unsigned long how_many, [out]

   CosNaming_BindingList ** bl,[out] DICosNaming_BindingIterator ** bi);};};

   The BindingIterator interface is mapped in a similar manner, as shown in the next two examples.

   module CosNaming { //... interface BindingIterator { boolean next_one(out Binding b); boolean next_n(in unsigned long how_many, out BindingList bl); void destroy(); };

   };

   [uuid(a1789c86-1b2c-11cf-9884-08000970dac7)] library CosNaming

    { // ...[uuid(5fb41e3b-652b-0b24-1dcc-a05c95edf9d3),help string(“BindingIterator?),helpcontext(1), oleautomation, dual]interface DICosNaming_IBindingIterator: IDispatch {

   HRESULT next_one([out] DICosNaming_Binding ** b,[out, retval] boolean* pResult);

   HRESULT next_n([in] unsigned long how_many,[out] CosNaming_BindingList ** bl,[out, retval] boolean* pResult);

   HRESULT destroy();};}