VisiBroker for C++ API Reference Guide : Real-Time CORBA interfaces and classes

Real-Time CORBA interfaces and classes
This section describes the Real-Time CORBA interfaces and classes supported by VisiBroker for C++.
Note
Before using these interfaces, read “Real-Time CORBA Extensions” in the VisiBroker for C++ Developer's Guide for descriptions and usage information on the supported extensions.
Introduction
Real-Time CORBA provides a set of APIs that support the development of predictable CORBA-based systems, through the control of the number and priority of threads involved in the execution of CORBA invocations.
The majority of the Real-Time CORBA API is specified in IDL, and is mapped to C++ according to the rules of the CORBA C++ language mapping. The Real-Time CORBA IDL is scoped within module RTCORBA, and hence the C++ class names are all prefixed RTCORBA::.
The following Real-Time CORBA interfaces and classes are described in the sections that follow:
Include file
To use any of the Real-Time CORBA features described in this chapter, the application should include the file rtcorba.h, which is one of the include files supplied with VisiBroker for C++.
RTCORBA::Current
class RTCORBA::Current : public virtual CORBA::Current,
public virtual CORBA::LocalObject
typedef RTCORBA::Current* Current_ptr
class RTCORBA::Current_var
The class RTCORBA::Current provides methods that allow a Real-Time CORBA Priority value to be associated with the current thread of execution, and the reading of the Real-Time CORBA Priority value presently associated with the current thread.
When a Real-Time CORBA Priority value is associated with the current thread, that value is immediately used to set the Native Priority of the underlying thread. The Native Priority value to apply to the thread is obtained by means of the currently installed Priority Mapping.
Where the Client Propagated Priority Model is in use, the Priority associated with a thread also determines the priority of CORBA invocations made from that thread. For details, see “Real-Time CORBA Priority Models” in the VisiBroker for C++ Developer's Guide.
RTCORBA::Current is defined in IDL, as a locality constrained interface. Hence applications handle RTCORBA::Current by means of CORBA LocalObject References, using the C++ classes RTCORBA::Current_ptr and RTCORBA::Current_var.
See“RTCORBA::Priority” for more information.
RTCORBA::Current Creation and Destruction
RTCORBA::Current is a special interface. Applications need not be concerned by which instance of it they are dealing with. A reference to RTCORBA::Current is obtained through the resolve_initial_references method of RTCORBA::RTORB, and is released in the normal way when it is no longer required. For details see “Real-Time CORBA Current” in VisiBroker for C++ Developer's Guide.
IDL definition
//Locality Constrained Object
local interface Current : CORBA::Current {
attribute Priority base_priority;
};
RTCORBA::Current methods
void base_priority(Priority _val);
Associates the RTCORBA::Priority value _val with the current thread of execution.
Priority base_priority();
Gets the RTCORBA::Priority value associated with the current thread of execution.
RTCORBA::Mutex
class RTCORBA::Mutex :local interface Current : CORBA::Current
typedef RTCORBA::Mutex* RTCORBA::Mutex_ptr
class RTCORBA::Mutex_var
class TimeBase {
typedef unsigned long long TimeT;
};
The interface RTCORBA::Mutex provides applications with a mutex synchronization primitive that is guaranteed to have the same priority inheritance properties as mutexes used internally by VisiBroker to protect ORB resources. For details, see “Real-Time CORBA Mutex API” in the VisiBroker for C++ Developer's Guide.
RTCORBA::Mutex is defined in IDL, as a locality constrained interface. Hence applications handle RTCORBA::Mutex instances by means of CORBA LocalObject References, using the C++ classes RTCORBA::Mutex_ptr and RTCORBA::Mutex_var. See “RTCORBA::RTORB” for more information.
Mutex Creation and Destruction
A new RTCORBA::Mutex is obtained using the create_mutex operation of the RTCORBA::RTORB interface. The new RTCORBA::Mutex is created in an unlocked state.
When the RTCORBA::Mutex is no longer needed, it is destroyed using the destroy_mutex operation of RTCORBA::RTORB. See “RTCORBA::RTORB” for details.
Note that if the RTCORBA::Mutex_var type is used in place of the RTCORBA::Mutex_ptr type, the reference is automatically released when the _var instance goes out of scope, but the RTCORBA::Mutex instance it refers to is not automatically destroyed. The RTCORBA::Mutex instance must still be destroyed with a call to destroy_mutex.
IDL definition
// Locality Constrained Object
local interface Mutex {
void lock();
void unlock();
boolean try_lock ( in TimeBase::TimeT max_wait );
};
 
local interface RTORB {
ƒ
Mutex create_mutex();
void destroy_mutex( in Mutex the_mutex );
ƒ
};
 
// defined in TimeBase.idl
module TimeBase {
typedef unsigned long long TimeT;
};
RTCORBA::Mutex Methods
void lock();
Locks the RTCORBA::Mutex. When the RTCORBA::Mutex object is in the unlocked state, the first thread to call the lock() operation causes the Mutex object to change to the locked state. Subsequent threads that call the lock() operation while the Mutex object is still in the locked state will block until the owner thread unlocks it.
void unlock();
Unlocks the locked RTCORBA::Mutex.
CORBA::Boolean try_lock( const TimeBase::TimeT _max_wait );
Attempts to lock the RTCORBA::Mutex, waiting for a maximum of _max_wait amount of time. Returns true if the lock is successfully taken within the time, or false if it could not be taken before the time expired.
RTCORBA::NativePriority
typedef CORBA::Short RTCORBA::NativePriority
The type RTCORBA::NativePriority is used to represent priorities in the priority scheme of the particular Operating System that the Real-Time ORB is running on. Real-Time CORBA applications only use RTCORBA::NativePriority values in special circumstances:
Normally, within a Real-Time CORBA application, priorities are expressed in terms of RTCORBA::Priority values.
IDL definition
typedef short NativePriority;
RTCORBA::Priority
typedef CORBA::Short RTCORBA::Priority
static const Priority RTCORBA::minPriority; // 0
static const Priority RTCORBA::maxPriority; // 32767
The type RTCORBA::Priority should be used to represent priority values in a Real-Time CORBA application. These values are mapped on to the Native Priority scheme of the particular Operating System that the application is running on by the currently installed Priority Mapping. For a detailed discussion of Real-Time CORBA Priority, see “Real-Time CORBA Priority” in the VisiBroker for C++ Developer's Guide.
The only time a Real-Time CORBA application should use Native Priority values is when interacting directly with the Operating System or some other non-CORBA subsystem. Even then, this should still be done using the installed Priority Mapping. For details see 'Using Native Priorities in VisiBroker Application Code' in the VisiBroker for C++ Developer's Guide.
RTCORBA::Priority values are in the range 0 to 32767. However, it is not expected that this full range of priorities will be used in a Real-Time CORBA system. Instead, the application system designer should decide on a suitable range of priorities for that system, and implement a Priority Mapping that only allows priority values in that range. For many applications the default valid range of 0 to 31 is acceptable, but there might still be reasons to override the default Priority Mapping. See “RTCORBA::PriorityMapping” for details.
IDL definition
typedef short Priority;
static const Priority minPriority; // 0
static const Priority maxPriority; // 32767
RTCORBA::PriorityMapping
class RTCORBA::PriorityMapping
The RTCORBA::PriorityMapping class facilitates the mapping of RTCORBA::Priority values to and from the Native Priority scheme of the Operating System the Real-Time ORB is running on. The ORB calls out to a Priority Mapping object whenever it needs to map a RTCORBA::Priority value to a RTCORBA::NativePriority value or vice versa.
A Real-Time CORBA application should describe its priorities in terms of RTCORBA::Priority values. However, the application might need to make explicit use of the installed Priority Mapping, in order to interact directly with the Operating System or some other non-CORBA subsystem. For details see “Using Native Priorities in VisiBroker Application Code” in the VisiBroker for C++ Developer's Guide.
The range of RTCORBA::Priority values supported by a Priority Mapping should always start from zero. The Real-Time ORB expects RTCORBA::Priority zero to be valid. Also, this convention makes integration of different Real-Time CORBA systems on the same node easier.
PriorityMapping Creation and Destruction
It is not necessary to create instances of a Priority Mapping in the code of a normal Real-Time CORBA application. The available Priority Mapping is automatically used by the ORB, and can be accessed by the application if necessary.
Exactly one Priority Mapping is 'installed' at any one time. A 'default' Priority Mapping is provided, which is installed by default. This Default Priority Mapping can be overridden by installing an application-implemented Priority Mapping object. The installation process is described in the section “Replacing the Default Priority Mapping” in the VisiBroker for C++ Developer's Guide.
IDL definition
// 'native' IDL type
native PriorityMapping;
The RTCORBA::PriorityMapping IDL type is defined as a 'native' IDL type. This means that its mapping to different programming languages is defined on a per-language basis. The C++ class representing RTCORBA::PriorityMapping has the following declaration:
class PriorityMapping {
public:
virtual CORBA::Boolean to_native(
RTCORBA::Priority corba_priority,
RTCORBA::NativePriority &native_priority )=0;
virtual CORBA::Boolean to_CORBA(
RTCORBA::NativePriority native_priority,
RTCORBA::Priority &corba_priority )=0;
virtual RTCORBA::Priority max_priority() = 0;
PriorityMapping();
virtual ~PriorityMapping() {}
static RTCORBA::PriorityMapping * instance();
};
The purpose of each method is explained in the next section, “PriorityMapping Methods”.
PriorityMapping Methods
static RTCORBA::PriorityMapping * instance();
This static method, implemented by VisiBroker for C++, can be used by Real-Time CORBA applications to access the currently installed Priority Mapping. For details see “Using Native Priorities in VisiBroker Application Code” in the VisiBroker for C++ Developer's Guide.
virtual RTCORBA::Priority max_priority() = 0;
This method returns the maximum Real-Time CORBA Priority value that is valid using this Priority Mapping. For example, if the installed Priority Mapping maps Real-Time CORBA Priorities in the range 0 to 31, the value 31 will be returned every time this method is called.
This method must be implemented when implementing a new Priority Mapping.
virtual CORBA::Boolean to_CORBA (
RTCORBA::NativePriority native_priority,
RTCORBA::Priority &corba_priority ) = 0;
This method maps a given Native Priority value, native_priority, to a Real-Time CORBA Priority value. If the Native Priority value is in the range supported by this Priority Mapping, the resultant Real-Time CORBA Priority value is stored in corba_priority, and a true value is returned. Otherwise corba_priority is not changed, and a false is returned.
This method must be implemented when implementing a new Priority Mapping.
virtual CORBA::Boolean to_native (
RTCORBA::Priority corba_priority,
RTCORBA::NativePriority &native_priority ) = 0;
This method maps a given Real-Time CORBA Priority value, corba_priority, to a Native Priority value. If the Real-Time CORBA Priority value is in the range supported by this Priority Mapping, the resultant Native Priority value is stored in native_priority, and a true value is returned. Otherwise native_priority is not changed, and a false value is returned.
This method must be implemented when implementing a new Priority Mapping.
RTCORBA::PriorityModel
enum RTCORBA::PriorityModel {
CLIENT_PROPAGATED,
SERVER_DECLARED
};
This enumeration specifies the two Real-Time CORBA Priority Models: Client Propagated Priority Model and Server Declared Priority Model. These are described in the section “Real-Time CORBA Priority Models” in the VisiBroker for C++ Developer's Guide.
These enumeration values are used as values for a parameter to the create_priority_model_policy method of RTCORBA::RTORB. See “RTCORBA::PriorityModelPolicy”for details.
RTCORBA::PriorityModelPolicy
class RTCORBA::PriorityModelPolicy : public virtual CORBA::Policy, public virtual CORBA::LocalObject
An instance of this Real-Time Policy type is created by calling the create_priority_model_policy method of RTCORBA::RTORB. The Policy instance can then be used to configure a Real-Time POA at the time of its creation, by passing it into the create_POA method, as a member of the Policy List parameter.
See “RTCORBA::RTORB” and “RTCORBA::PriorityModel” for more information.
IDL definition
local interface PriorityModelPolicy : CORBA::Policy {
readonly attribute PriorityModel priority_model;
readonly attribute Priority server_priority;
};
RTCORBA::RTORB
class RTCORBA::RTORB : public virtual CORBA::LocalObject
typedef RTCORBA::RTORB* RTCORBA::RTORB_ptr
class RTCORBA::RTORB_var
The interface RTCORBA::RTORB provides methods for the management of Real-Time CORBA Threadpools and Mutexes, and to create instances of Real-Time CORBA Policies.
RTCORBA::RTORB is defined in IDL, as a locality constrained interface. Hence applications handle RTCORBA::RTORB by means of CORBA LocalObject References, using the C++ classes RTCORBA::RTORB_ptr and RTCORBA::RTORB_var.
Note
As stated in the VisiBroker for C++ Developer's Guide, to support Real-Time CORBA Extensions the VisiBroker for C++ ORB has to operate in a special 'real-time compatible' mode, the behavior and semantics of which differ from the regular mode of operation. Since obtaining an “RTORB” reference automatically puts the ORB in this special mode, you should obtain an “RTORB” reference as early as possible in your application code to avoid any possible inconsistency in behavior.
See “RTCORBA::Mutex”, “RTCORBA::Priority”, “RTCORBA::ThreadpoolId”, and “RTCORBA::ThreadpoolPolicy”. For details on the use of Real-Time CORBA Threadpools, see “Threadpools” in the VisiBroker for C++ Developer's Guide.
RTORB Creation and Destruction
The Real-Time ORB does not need to be explicitly initialized—it is initialized implicitly as part of the regular CORBA::ORB_init call.
To use the Real-Time ORB operations, the application must have a reference to the Real-Time ORB instance. This reference can be obtained any time after the call to ORB_init, and is obtained through the resolve_initial_references operation on CORBA::ORB, with the object ID string “RTORB” as the parameter. For details, see “Real-Time CORBA ORB” in the VisiBroker for C++ Developer's Guide.
IDL definition
// locality constrained interface
local interface RTORB {
Mutex create_mutex();
void destroy_mutex( in Mutex the_mutex );
 
exception InvalidThreadpool {};
 
ThreadpoolId create_threadpool (
in unsigned long stacksize,
in unsigned long static_threads,
in unsigned long dynamic_threads,
in Priority default_priority,
in boolean allow_request_buffering,
in unsigned long max_buffered_requests,
in unsigned long max_request_buffer_size );
 
void destroy_threadpool( in ThreadpoolId threadpool )
raises (InvalidThreadpool);
 
void threadpool_idle_time( in ThreadpoolId threadpool,
in unsigned long seconds )
raises (InvalidThreadpool);
 
PriorityModelPolicy create_priority_model_policy(
in PriorityModel priority_model,
in Priority server_priority );
 
ThreadpoolPolicy create_threadpool_policy(
in ThreadpoolId threadpool );
};
RTORB Methods
Mutex_ptr create_mutex();
Creates a new Real-Time CORBA Mutex and returns a reference to it.
void destroy_mutex( Mutex_ptr _the_mutex );
Destroys a Real-Time CORBA Mutex.
ThreadpoolId create_threadpool(
CORBA::ULong _stacksize,
CORBA::ULong _static_threads,
CORBA::ULong _dynamic_threads,
Priority _default_priority,
CORBA::Boolean _allow_request_buffering = 0,
CORBA::ULong _max_buffered_requests = 0,
CORBA::ULong _max_request_buffer_size = 0 );
Creates a new Real-Time CORBA Threadpool with the specified configuration, and returns a RTCORBA::ThreadpoolId for it.
void destroy_threadpool( ThreadpoolId _threadpool );
Destroys a Real-Time CORBA Threadpool. The Threadpool must not be in use by any Object Adapter, or the operation will fail, and a CORBA system exception is raised.
void threadpool_idle_time(
ThreadpoolId _threadpool,
CORBA::ULong _seconds );
Sets the time, in seconds, that dynamically allocated threads remain idle before they are garbage collected. Configured on a per-Threadpool basis. The default is to garbage collect dynamically allocated threads after 300 seconds.
This method is a proprietary VisiBroker extension.
PriorityModelPolicy create_priority_model_policy(
in PriorityModel _priority_model,
in Priority _server_priority );
Creates an instance of the RTCORBA::PriorityModelPolicy policy object, for use in configuring one or more Real-Time POAs. See “RTCORBA::PriorityModel” and “RTCORBA::PriorityModelPolicy”.
Either RTCORBA::SERVER_DECLARED for the Server Declared Priority Model, or RTCORBA::CLIENT_PROPAGATED for the Client Priority Propagation Model.
ThreadpoolPolicy create_threadpool_policy(
in ThreadpoolId _threadpool );
Creates an instance of the RTCORBA::ThreadpoolPolicy policy object, for use in configuring one or more Real-Time POAs.
RTCORBA::ThreadpoolId
typedef CORBA::ULong RTCORBA::ThreadpoolId
Values of the type RTCORBA::ThreadpoolId are used to identify Real-Time CORBA Thread-pools. A value of this type is returned from the create_threadpool method of RTCORBA::RTORB.
The ID can be used to initialize an instance of a Threadpool Policy, which in turn can be passed in to a call to create_POA, as a member of the PolicyList parameter, to configure a Real-Time POA. For details, see “RTCORBA::RTORB”, “RTCORBA::ThreadpoolPolicy”, and the section “Association of an Object Adapter with a Threadpool” in the VisiBroker for C++ Developer's Guide.
IDL definition
typedef unsigned long ThreadpoolId;
RTCORBA::ThreadpoolPolicy
class RTCORBA::ThreadpoolPolicy : public virtual CORBA::Policy, public virtual CORBA::LocalObject
An instance of this Real-Time Policy type is created by calling the create_threadpool_policy method of RTCORBA::RTORB. The Policy instance can then be used to configure a Real-Time POA at the time of its creation, by passing it into the create_POA method, as a member of the Policy List parameter. See “RTCORBA::RTORB”, “RTCORBA::ThreadpoolId”, and the section “Association of an Object Adapter with a Threadpool” in the VisiBroker for C++ Developer's Guide for more information.
IDL definition
local interface ThreadpoolPolicy : CORBA::Policy {
readonly attribute ThreadpoolId threadpool;
};