Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Advanced CORBA Programming wit C++ - M. Henning, S. Vinoski.pdf
Скачиваний:
57
Добавлен:
24.05.2014
Размер:
5 Mб
Скачать

IT-SC book: Advanced CORBA® Programming with C++

props[0].value_type = CORBA::TypeCode::_duplicate( CORBA::_tc_ulong

);

props[0].mode = ServiceTypeRepository::PROP_MANDATORY;

//Base type list is already initialized...

//Create wireless controller service type. repos->add_type(

"CCS::WLControllers",

"IDL:acme.com/CCS/WLController:1.0",

props, base_types

);

//Create wireless multiprotocol controller service type.

//(This type does not create additional properties.) props.length(0);

base_types.length(2);

base_types[0] = "CCS::MPControllers"; base_types[1] = "CCS::WLControllers";

//Create wireless multiprotocol controller service type. repos->add_type(

"CCS::WLMPControllers",

"IDL:acme.com/CCS/WLMPController:1.0",

props, base_types

);

Note that we tacitly assume here that the IDL types for the three derived controllers follow the inheritance structure shown in Figure 19.4.

19.6 The Trader Interfaces

The 11 trader interfaces are all part of the CosTrading module. They provide the functionality to import and export service offers, export proxy service offers, modify the federation structure, and configure a trader. Following is an outline of the IDL structure.

//File: CosTrading.idl #pragma prefix "omg.org" module CosTrading {

interface TraderComponents

{ /* ... */ };

// Abstract

interface SupportAttributes { /* ... */ };

// Abstract

interface ImportAttributes

{ /* ... */ };

// Abstract

interface LinkAttributes

{ /* ... */ };

// Abstract

interface Lookup :

 

 

TraderComponents,

 

 

SupportAttributes,

{ /* ... */ };

 

ImportAttributes

 

interface Register :

735

IT-SC book: Advanced CORBA® Programming with C++

TraderComponents,

{ /* ... */ };

SupportAttributes

interface Link :

 

TraderComponents,

 

SupportAttributes,

{ /* ... */ };

LinkAttributes

interface Proxy :

 

TraderComponents,

{ /* ... */ };

SupportAttributes

interface Admin :

 

TraderComponents,

 

SupportAttributes,

 

ImportAttributes,

{ /* ... */ };

LinkAttributes

interface OfferIterator

{ /* ... */ };

interface OfferIdIterator

{ /* ... */ };

};

Note that the IDL defines four abstract base interfaces that are used to group related functionality that is used by the other interfaces. Figure 19.5 shows the corresponding IDL inheritance graph.

Figure 19.5 Inheritance hierarchy for the trader interfaces.

736

IT-SC book: Advanced CORBA® Programming with C++

19.6.1 Main Interfaces

Figure 19.5 is intimidating at first glance, but it is not as bad as it looks. The main trader interfaces are as follows.

Lookup

Importers use the Lookup interface to retrieve the results of a service request.

Register

Exporters use the Register interface to create new service offers.

Admin

Trader administrators use the Admin interface to control policy values.

Link

Trader administrators use the Link interface to control the federation structure of a trader.

Proxy

Exporters use the Proxy interface to create new proxy offers.

All five interfaces are singleton interfaces, so a trader offers exactly one instance of each interface to its clients.

The reason for the fine-grained object model in Figure 19.5 is that the OMG Trading Service specification defines a number of compliance classes. A compliant trader is not required to support all these interfaces. Instead, the Lookup interface is the only interface that all OMG-compliant traders are required to implement. Apart from this requirement, any other combination of support for the remaining main interfaces is legal. (Support for dynamic properties, in the CosTradingDynamic module, is also optional.) The specification suggests, but does not limit traders to, a number of common compliance classes.

Query trader

A query trader supports only the Lookup interface. Such a trader is read-only and most commonly is used as a front end to an existing database.

Simple trader

A simple trader supports the Lookup and Register interfaces, so it permits both import and export operations.

Stand-alone trader

A stand-alone trader is a simple trader but also supports the Admin interface and therefore allows fine-grained control over the trader configuration via policies.

Linked trader

A linked trader adds federation support to a stand-alone trader by also supporting the Link interface.

Proxy trader

737

IT-SC book: Advanced CORBA® Programming with C++

A proxy trader adds proxy offer support to a stand-alone trader by also supporting the Proxy interface.

Full-service trader

A full-service trader supports all five of the main interfaces, possibly adding support for dynamic properties.

19.6.2 Abstract Base Interfaces

The base interfaces for the trader use inheritance to group common functionality that is required by the main interfaces. That is, the base interfaces are used as mix-in interfaces.

The SupportAttributes Interface

interface SupportAttributes {

readonly attribute boolean supports_modifiable_properties; readonly attribute boolean supports_dynamic_properties; readonly attribute boolean supports_proxy_offers; readonly attribute TypeRepository type_repos;

};

All five of the main interfaces inherit from SupportAttributes. The interface contains the type_repos attribute so that clients can obtain a reference to the type repository (see Section 19.5.4). The remaining three attributes indicate the level of support provided by this trader. For example, the supports_modifiable_properties attribute is true only if this trader permits updates of properties in place. The SupportAttributes interface permits clients to obtain the level of support available from their trader at run time and to dynamically adjust their behavior according to the level of support.

The TraderComponents Interface

interface TraderComponents {

lookup_if;

readonly attribute Lookup

readonly attribute Register

register_if;

readonly attribute Link

link_if;

readonly attribute Proxy

proxy_if;

readonly attribute Admin

admin_if;

};

 

All five of the main interfaces inherit from TraderComponents. The interface is a navigation interface. Given an object reference to an arbitrary trader interface, you can navigate to any one of the other interfaces by reading the appropriate attribute.

738

IT-SC book: Advanced CORBA® Programming with C++

The main motivation for the TraderComponents interface is to avoid adding too many service name tokens to resolve_initial_references. Recall from Section 19.5. 4 that only a single token is defined for the trader—namely, "TradingService". This token returns a Lookup interface, which in turn provides access to the remaining interfaces. Without this design, the specification would have had to add five new tokens to resolve_initial_references (six tokens if you count the type repository).

If a trader does not support the full functionality of the specification, the corresponding attribute contains a nil reference. For example, if a trader does not support federation, the link_if attribute is nil.

The ImportAttributes Interface

enum FollowOption { local_only, if_no_local, always };

interface ImportAttributes { readonly attribute unsigned long readonly attribute unsigned long readonly attribute unsigned long readonly attribute unsigned long readonly attribute unsigned long readonly attribute unsigned long readonly attribute unsigned long readonly attribute unsigned long readonly attribute unsigned long readonly attribute FollowOption readonly attribute FollowOption

};

def_search_card; max_search_card; def_match_card; max_match_card; def_return_card; max_return_card; max_list; def_hop_count; max_hop_count; def_follow_policy; max_follow_policy;

The ImportAttributes interface allows importers to inquire about the setting of the import policies of a trader. We cover these policies in Section 19.11.6.

The LinkAttributes Interface

interface LinkAttributes {

readonly attribute FollowOption max_link_follow_policy;

};

The LinkAttributes interface contains a single attribute that informs a client of the federation policy limit established by this trader (see Section 19.16.1).

19.6.3 Iterators

interface OfferIterator {

unsigned long max_left() raises(UnknownMaxLeft); boolean next_n(

739