CORBA::NVList implementation. More...
#include <NVList.h>
Public Types | |
typedef NVList_ptr | _ptr_type |
typedef NVList_var | _var_type |
typedef NVList_out | _out_type |
Public Member Functions | |
ULong | count (void) const |
return the current number of elements in the list | |
NamedValue_ptr | add (Flags) |
add an element and just initialize the flags | |
NamedValue_ptr | add_item (const char *, Flags) |
add an element and initialize its name and flags | |
NamedValue_ptr | add_value (const char *, const Any &, Flags) |
initializes a value, name, and flags | |
NamedValue_ptr | add_item_consume (char *, Flags) |
NamedValue_ptr | add_value_consume (char *, Any_ptr, Flags) |
NamedValue_ptr | item (ULong n) |
retrieve the item at the nth location. Raises Bounds | |
void | remove (ULong n) |
remove element at index n. Raises Bounds | |
ULong | _incr_refcnt (void) |
ULong | _decr_refcnt (void) |
void | _tao_incoming_cdr (TAO_InputCDR &cdr, int flag, bool &lazy_evaluation) |
void | _tao_encode (TAO_OutputCDR &cdr, int flag) |
void | _tao_decode (TAO_InputCDR &cdr, int flag) |
Decode the NVList arguments from the cdr stream. | |
ptrdiff_t | _tao_target_alignment (void) |
Boolean | _lazy_has_arguments (void) const |
Static Public Member Functions | |
static NVList * | _duplicate (NVList *) |
static NVList * | _nil (void) |
Protected Member Functions | |
~NVList (void) | |
Destructor. | |
Private Member Functions | |
NVList (void) | |
NamedValue_ptr | add_element (Flags) |
void | evaluate (void) |
Private Attributes | |
ACE_Unbounded_Queue < NamedValue_ptr > | values_ |
Internal list of parameters stored as NamedValues. | |
ULong | max_ |
Maximum length of list. | |
ACE_Atomic_Op< TAO_SYNCH_MUTEX, unsigned long > | refcount_ |
Reference counter. | |
TAO_SYNCH_MUTEX | lock_ |
Protects the incoming pointer. | |
TAO_InputCDR * | incoming_ |
int | incoming_flag_ |
Friends | |
class | ::TAO_NVList_Adapter_Impl |
class | Request |
CORBA::NVList implementation.
This is used in the (client side) DII (Dynamic Invocation Interface) to hold parameters, except for the return parameter. It's used in the same role in the (server side) DSI (Dynamic Skeleton Interface).
Each user (client, server) provides the typecode and memory for each parameter using an NVList, then talks to the ORB using a Request or ServerRequest pseudo-object. The ORB copies data to/from the IPC messages (e.g. IIOP::Request, IIOP::Response) as appropriate.
Definition at line 159 of file NVList.h.
typedef NVList_out CORBA::NVList::_out_type |
typedef NVList_ptr CORBA::NVList::_ptr_type |
typedef NVList_var CORBA::NVList::_var_type |
CORBA::NVList::~NVList | ( | void | ) | [protected] |
Destructor.
Protected destructor to enforce proper memory management through the reference counting mechanism.
Definition at line 79 of file NVList.cpp.
{ // initialize an iterator and delete each NamedValue ACE_Unbounded_Queue_Iterator<CORBA::NamedValue_ptr> iter (this->values_); for (iter.first (); !iter.done (); iter.advance ()) { CORBA::NamedValue_ptr *nv = 0; (void) iter.next (nv); delete *nv; } this->max_ = 0; // Remove the CDR stream if it is present. delete this->incoming_; }
CORBA::NVList::NVList | ( | void | ) | [private] |
Constructor - cannot be instantiated directly other than through the CORBA::ORB::create_list method
Definition at line 92 of file NVList.inl.
: max_ (0), refcount_ (1), incoming_ (0), incoming_flag_ (0) { }
CORBA::ULong CORBA::NVList::_decr_refcnt | ( | void | ) |
Definition at line 69 of file NVList.cpp.
{ CORBA::ULong const new_count = --this->refcount_; if (new_count == 0) delete this; return new_count; }
CORBA::NVList * CORBA::NVList::_duplicate | ( | CORBA::NVList * | x | ) | [static] |
Definition at line 111 of file NVList.inl.
{ if (x != 0) { x->_incr_refcnt (); } return x; }
CORBA::ULong CORBA::NVList::_incr_refcnt | ( | void | ) |
Definition at line 63 of file NVList.cpp.
{ return ++this->refcount_; }
CORBA::Boolean CORBA::NVList::_lazy_has_arguments | ( | void | ) | const |
If this list is used by a DII request, this will tell us if our CDR stream contains any marshaled arguments (needed for GIOP 1.2).
Definition at line 452 of file NVList.cpp.
CORBA::NVList * CORBA::NVList::_nil | ( | void | ) | [static] |
Definition at line 123 of file NVList.inl.
{
return 0;
}
void CORBA::NVList::_tao_decode | ( | TAO_InputCDR & | cdr, | |
int | flag | |||
) |
Decode the NVList arguments from the cdr stream.
Definition at line 373 of file NVList.cpp.
{ if (TAO_debug_level > 3) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) : NVList::_tao_decode\n"))); } // Then unmarshal each "in" and "inout" parameter. ACE_Unbounded_Queue_Iterator<CORBA::NamedValue_ptr> i (this->values_); for (i.first (); !i.done (); i.advance ()) { CORBA::NamedValue_ptr *item = 0; (void) i.next (item); CORBA::NamedValue_ptr nv = *item; // check if it is an in or inout parameter // @@ this is where we assume that the NVList is coming from // a Server-side request, we could probably handle both // cases with a flag, but there is no clear need for that. if (ACE_BIT_DISABLED (nv->flags (), flag)) { continue; } if (TAO_debug_level > 3) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TAO (%P|%t) : NVList::_tao_decode - %C\n"), nv->name ()? nv->name () : "(no name given)" )); } CORBA::Any_ptr any = nv->value (); any->impl ()->_tao_decode (incoming ); } }
void CORBA::NVList::_tao_encode | ( | TAO_OutputCDR & | cdr, | |
int | flag | |||
) |
Encode the NVList into the CDR stream. flag masks the type of arguments (IN, OUT or INOUT) that are to be marshaled.
Definition at line 292 of file NVList.cpp.
{ ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_); if (this->incoming_ != 0) { if (this->max_ == 0) { // The list is empty aggresively reduce copies and just send // the CDR stream, we assume that // TAO_Server_Request::init_reply // has inserted appropiated padding already to make this // operation correct cdr.write_octet_array_mb (this->incoming_->start ()); return; } // Then unmarshal each "in" and "inout" parameter. ACE_Unbounded_Queue_Iterator<CORBA::NamedValue_ptr> i (this->values_); for (i.first (); !i.done (); i.advance ()) { CORBA::NamedValue_ptr *item = 0; (void) i.next (item); CORBA::NamedValue_ptr nv = *item; if (ACE_BIT_DISABLED (nv->flags (), flag)) { continue; } if (TAO_debug_level > 3) { const char* arg = nv->name (); if (arg == 0) { arg = "(nil)"; } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("NVList::_tao_encode - parameter <%C>\n"), arg)); } CORBA::TypeCode_ptr tc = nv->value ()->_tao_get_typecode (); (void) TAO_Marshal_Object::perform_append (tc, this->incoming_, &cdr); } delete this->incoming_; this->incoming_ = 0; return; } // The list is already evaluated, we cannot optimize the copies, go // ahead with the slow way to do things. // Then marshal each "in" and "inout" parameter. ACE_Unbounded_Queue_Iterator<CORBA::NamedValue_ptr> i (this->values_); for (i.first (); !i.done (); i.advance ()) { CORBA::NamedValue_ptr *item = 0; (void) i.next (item); CORBA::NamedValue_ptr nv = *item; if (ACE_BIT_DISABLED (nv->flags (), flag)) { continue; } nv->value ()->impl ()->marshal_value (cdr); } }
void CORBA::NVList::_tao_incoming_cdr | ( | TAO_InputCDR & | cdr, | |
int | flag, | |||
bool & | lazy_evaluation | |||
) |
Set the incoming CDR stream, this is used by TAO to perform lazy evaluation of the NVList in an incoming ServerRequest. The <flag> is used to check which parameters (IN, OUT and/or INOUT) are to be extracted
Definition at line 259 of file NVList.cpp.
{ // If the list is empty then using lazy evaluation is the only // choice. // @@ There are other cases where we can use lazy evaluation, for // example if the list is not empty but the anys own all their // objects. if (lazy_evaluation == false && this->max_ == 0) { lazy_evaluation = true; } if (lazy_evaluation == false) { this->_tao_decode (cdr, flag); return; } ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_); if (this->incoming_ != 0) { delete this->incoming_; this->incoming_ = 0; } ACE_NEW (this->incoming_, TAO_InputCDR (cdr)); this->incoming_flag_ = flag; }
ptrdiff_t CORBA::NVList::_tao_target_alignment | ( | void | ) |
Return the required alignment to marshal the NVList without any re-alignment. It returns ACE_CDR::MAX_ALIGNMENT to indicate errors.
Definition at line 414 of file NVList.cpp.
{ ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, ACE_CDR::MAX_ALIGNMENT); if (this->incoming_ == 0) { return ACE_CDR::MAX_ALIGNMENT; } const char* rd = this->incoming_->start ()->rd_ptr (); ptrdiff_t t = ptrdiff_t (rd) % ACE_CDR::MAX_ALIGNMENT; if (t < 0) { t += ACE_CDR::MAX_ALIGNMENT; } return t; }
CORBA::NamedValue_ptr CORBA::NVList::add | ( | CORBA::Flags | flags | ) |
add an element and just initialize the flags
Definition at line 99 of file NVList.cpp.
{ // call the helper to allocate a NamedValue element (if necessary) return this->add_element (flags); }
CORBA::NamedValue_ptr CORBA::NVList::add_element | ( | CORBA::Flags | flags | ) | [private] |
Helper to increase the list size. This is used by all the add_ methods of the NVList class
Definition at line 211 of file NVList.cpp.
{ this->evaluate (); if (ACE_BIT_DISABLED (flags, CORBA::ARG_IN | CORBA::ARG_OUT | CORBA::ARG_INOUT)) { throw ::CORBA::BAD_PARAM (); } CORBA::NamedValue_ptr nv; // allocate a new NamedValue ACE_NEW_THROW_EX (nv, CORBA::NamedValue, CORBA::NO_MEMORY ()); // set the flags and enqueue in the queue nv->flags_ = flags; if (this->values_.enqueue_tail (nv) == -1) { delete nv; return 0; } ++this->max_; return nv; // success }
CORBA::NamedValue_ptr CORBA::NVList::add_item | ( | const char * | name, | |
CORBA::Flags | flags | |||
) |
add an element and initialize its name and flags
Definition at line 107 of file NVList.cpp.
{ // call the helper to allocate a NamedValue element CORBA::NamedValue_ptr nv = this->add_element (flags); if (nv) { // now initialize the fields nv->name_ = CORBA::string_dup (name); return nv; } else { return 0; } }
CORBA::NamedValue_ptr CORBA::NVList::add_item_consume | ( | char * | name, | |
CORBA::Flags | flags | |||
) |
just like add_item. In addition, memory management of char * name is taken over by the NVList
Definition at line 154 of file NVList.cpp.
{ // call the helper to allocate a NamedValue element CORBA::NamedValue_ptr nv = this->add_element (flags); if (nv) { // now initialize the fields // consume the name nv->name_ = name; return nv; } else { return 0; } }
CORBA::NamedValue_ptr CORBA::NVList::add_value | ( | const char * | name, | |
const Any & | value, | |||
CORBA::Flags | flags | |||
) |
initializes a value, name, and flags
Definition at line 126 of file NVList.cpp.
{ // Call the helper to allocate a NamedValue element. CORBA::NamedValue_ptr nv = this->add_element (flags); if (nv) { nv->name_ = CORBA::string_dup (name); // With the original Any implementation, we had alternate // paths for the assignment based on the IN_COPY_VALUE flag. // Now that the Any's contained Any_Impl is refcounted, the // distinction between the ORB "copying" or "borrowing" the // memory is irrelevant. The IN_COPY_VALUE flag was not // checked anywhere else in the ORB anyway. nv->any_ = value; return nv; } else { return 0; } }
NamedValue_ptr CORBA::NVList::add_value_consume | ( | char * | , | |
Any_ptr | , | |||
Flags | ||||
) |
CORBA::ULong CORBA::NVList::count | ( | void | ) | const |
return the current number of elements in the list
Definition at line 102 of file NVList.inl.
{ (const_cast<CORBA::NVList *> (this))->evaluate (); return this->max_; }
void CORBA::NVList::evaluate | ( | void | ) | [private] |
Lazy evaluation routine to fill up the Anys in the NVList from the CDR stream.
Definition at line 438 of file NVList.cpp.
{ ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->lock_); if (this->incoming_ != 0) { auto_ptr<TAO_InputCDR> incoming (this->incoming_); this->incoming_ = 0; this->_tao_decode (*(incoming.get ()), this->incoming_flag_); } }
CORBA::NamedValue_ptr CORBA::NVList::item | ( | CORBA::ULong | n | ) |
retrieve the item at the nth location. Raises Bounds
Definition at line 243 of file NVList.cpp.
{ this->evaluate (); if (n >= this->max_) { throw ::CORBA::Bounds (); } CORBA::NamedValue_ptr *nv = 0; this->values_.get (nv, n); return *nv; }
void CORBA::NVList::remove | ( | CORBA::ULong | n | ) |
remove element at index n. Raises Bounds
Definition at line 203 of file NVList.cpp.
{ // not implemented // @@ (ASG) - TODO }
friend class ::TAO_NVList_Adapter_Impl [friend] |
TAO_InputCDR* CORBA::NVList::incoming_ [private] |
int CORBA::NVList::incoming_flag_ [private] |
TAO_SYNCH_MUTEX CORBA::NVList::lock_ [private] |
ULong CORBA::NVList::max_ [private] |
ACE_Atomic_Op<TAO_SYNCH_MUTEX, unsigned long> CORBA::NVList::refcount_ [private] |