diff options
Diffstat (limited to 'ace')
-rw-r--r-- | ace/CDR_Stream.cpp | 42 | ||||
-rw-r--r-- | ace/CDR_Stream.h | 10 | ||||
-rw-r--r-- | ace/Message_Block.cpp | 28 | ||||
-rw-r--r-- | ace/Message_Block.h | 32 | ||||
-rw-r--r-- | ace/Message_Block.i | 30 |
5 files changed, 119 insertions, 23 deletions
diff --git a/ace/CDR_Stream.cpp b/ace/CDR_Stream.cpp index 0a0c10f1581..75d3e8b1d61 100644 --- a/ace/CDR_Stream.cpp +++ b/ace/CDR_Stream.cpp @@ -562,10 +562,11 @@ ACE_InputCDR::ACE_InputCDR (const ACE_Message_Block *data, } ACE_InputCDR::ACE_InputCDR (ACE_Data_Block *data, + ACE_Message_Block::Message_Flags flag, int byte_order, ACE_CDR::Octet major_version, ACE_CDR::Octet minor_version) - : start_ (data), + : start_ (data, flag), do_byte_swap_ (byte_order != ACE_CDR_BYTE_ORDER), good_bit_ (1), char_translator_ (0), @@ -576,12 +577,13 @@ ACE_InputCDR::ACE_InputCDR (ACE_Data_Block *data, } ACE_InputCDR::ACE_InputCDR (ACE_Data_Block *data, + ACE_Message_Block::Message_Flags flag, size_t rd_pos, size_t wr_pos, int byte_order, ACE_CDR::Octet major_version, ACE_CDR::Octet minor_version) - : start_ (data), + : start_ (data, flag), do_byte_swap_ (byte_order != ACE_CDR_BYTE_ORDER), good_bit_ (1), char_translator_ (0), @@ -593,7 +595,8 @@ ACE_InputCDR::ACE_InputCDR (ACE_Data_Block *data, this->start_.rd_ptr (rd_pos); // Set the write pointer after doing a sanity check. - char* wrpos = this->start_.rd_ptr () + wr_pos; + char* wrpos = this->start_.base () + wr_pos; + if (this->start_.end () >= wrpos) { this->start_.wr_ptr (wr_pos); @@ -1101,7 +1104,11 @@ ACE_InputCDR::steal_from (ACE_InputCDR &cdr) { this->do_byte_swap_ = cdr.do_byte_swap_; this->start_.data_block (cdr.start_.data_block ()->duplicate ()); + + // If the message block had a DONT_DELETE flags, just clear it off.. + this->start_.clr_self_flags (ACE_Message_Block::DONT_DELETE); this->start_.rd_ptr (cdr.start_.rd_ptr ()); + this->start_.wr_ptr (cdr.start_.wr_ptr ()); this->major_version_ = cdr.major_version_; this->minor_version_ = cdr.minor_version_; @@ -1133,6 +1140,12 @@ ACE_InputCDR::exchange_data_blocks (ACE_InputCDR &cdr) this->start_.replace_data_block (cdr.start_.data_block ()); cdr.start_.replace_data_block (dnb); + // Exchange the flags information.. + ACE_Message_Block::Message_Flags df = cdr.start_.self_flags (); + ACE_Message_Block::Message_Flags sf = this->start_.self_flags (); + + cdr.start_.set_self_flags (sf); + this->start_.set_self_flags (df); // Reset the <cdr> pointers to zero before it is set again. cdr.start_.reset (); @@ -1151,9 +1164,15 @@ ACE_InputCDR::exchange_data_blocks (ACE_InputCDR &cdr) if (this->start_.size () >= dwr_pos) this->start_.wr_ptr (dwr_pos); - //Set the GIOP version info - this->major_version_ = cdr.major_version_; - this->minor_version_ = cdr.minor_version_; + CORBA::Octet dmajor = cdr.major_version_; + CORBA::Octet dminor = cdr.minor_version_; + + // Exchange the GIOP version info + cdr.major_version_ = this->major_version_; + cdr.minor_version_ = this->minor_version_; + + this->major_version_ = dmajor; + this->minor_version_ = dminor; } @@ -1163,6 +1182,11 @@ ACE_InputCDR::steal_contents (void) ACE_Message_Block* block = this->start_.clone (); this->start_.data_block (block->data_block ()->clone ()); + + // If at all our message had a DONT_DELETE flag set, just clear it + // off. + this->start_.clr_self_bit (ACE_Message_Block::DONT_DELETE); + ACE_CDR::mb_align (&this->start_); return block; @@ -1171,7 +1195,11 @@ ACE_InputCDR::steal_contents (void) void ACE_InputCDR::reset_contents (void) { - this->start_.data_block (this->start_.data_block ()->clone_nocopy ()); + this->start_.data_block (this->start_.data_block ()->clone_nocopy + ()); + + // Reset the flags... + this->start_.clr_self_bit (ACE_Message_Block::DONT_DELETE); } // -------------------------------------------------------------- diff --git a/ace/CDR_Stream.h b/ace/CDR_Stream.h index 7e6eb035465..a973fe071e9 100644 --- a/ace/CDR_Stream.h +++ b/ace/CDR_Stream.h @@ -481,8 +481,11 @@ public: ACE_CDR::Octet minor_version = ACE_CDR_GIOP_MINOR_VERSION); - /// Create an input stream from an ACE_Data_Block + /// Create an input stream from an ACE_Data_Block. The <flag> + /// indicates whether the <data> can be deleted by the CDR stream + /// or not ACE_InputCDR (ACE_Data_Block *data, + ACE_Message_Block::Message_Flags flag = 0, int byte_order = ACE_CDR_BYTE_ORDER, ACE_CDR::Octet major_version = ACE_CDR_GIOP_MAJOR_VERSION, @@ -494,8 +497,9 @@ public: /// helpful if the applications desires to create a new CDR stream /// from a semi-processed datablock. ACE_InputCDR (ACE_Data_Block *data, - size_t read_pointer_position, - size_t write_pointer_position, + ACE_Message_Block::Message_Flags flag = 0, + size_t read_pointer_position = 0, + size_t write_pointer_position = 0, int byte_order = ACE_CDR_BYTE_ORDER, ACE_CDR::Octet major_version = ACE_CDR_GIOP_MAJOR_VERSION, diff --git a/ace/Message_Block.cpp b/ace/Message_Block.cpp index 001b094f9ac..4d8d3473d5a 100644 --- a/ace/Message_Block.cpp +++ b/ace/Message_Block.cpp @@ -55,7 +55,9 @@ void ACE_Message_Block::data_block (ACE_Data_Block *db) { ACE_TRACE ("ACE_Message_Block::data_block"); - if (this->data_block_ != 0) + if (ACE_BIT_DISABLED (this->flags_, + ACE_Message_Block::DONT_DELETE) + && this->data_block_ != 0) this->data_block_->release (); this->data_block_ = db; @@ -321,7 +323,8 @@ ACE_Data_Block::ACE_Data_Block (size_t size, ACE_Message_Block::ACE_Message_Block (const char *data, size_t size, u_long priority) - : data_block_ (0) + : flags_ (0), + data_block_ (0) { ACE_TRACE ("ACE_Message_Block::ACE_Message_Block"); @@ -343,7 +346,8 @@ ACE_Message_Block::ACE_Message_Block (const char *data, } ACE_Message_Block::ACE_Message_Block (ACE_Allocator *message_block_allocator) - : data_block_ (0) + : flags_ (0), + data_block_ (0) { ACE_TRACE ("ACE_Message_Block::ACE_Message_Block"); @@ -375,7 +379,8 @@ ACE_Message_Block::ACE_Message_Block (size_t size, const ACE_Time_Value &deadline_time, ACE_Allocator *data_block_allocator, ACE_Allocator *message_block_allocator) - : data_block_ (0) + :flags_ (0), + data_block_ (0) { ACE_TRACE ("ACE_Message_Block::ACE_Message_Block"); @@ -461,7 +466,8 @@ ACE_Message_Block::ACE_Message_Block (size_t size, ACE_Data_Block *db, ACE_Allocator *data_block_allocator, ACE_Allocator *message_block_allocator) - : data_block_ (0) + : flags_ (0), + data_block_ (0) { ACE_TRACE ("ACE_Message_Block::ACE_Message_Block"); @@ -483,8 +489,10 @@ ACE_Message_Block::ACE_Message_Block (size_t size, } ACE_Message_Block::ACE_Message_Block (ACE_Data_Block *data_block, + ACE_Message_Block::Message_Flags flags, ACE_Allocator *message_block_allocator) - : data_block_ (0) + : flags_ (flags), + data_block_ (0) { ACE_TRACE ("ACE_Message_Block::ACE_Message_Block"); @@ -747,7 +755,9 @@ ACE_Message_Block::release_i (ACE_Lock *lock) int result = 0; - if (this->data_block ()) + if (ACE_BIT_DISABLED (this->flags_, + ACE_Message_Block::DONT_DELETE) && + this->data_block ()) { if (this->data_block ()->release_no_delete (lock) == 0) result = 1; @@ -781,7 +791,9 @@ ACE_Message_Block::~ACE_Message_Block (void) { ACE_TRACE ("ACE_Message_Block::~ACE_Message_Block"); - if (this->data_block ()) + if (ACE_BIT_DISABLED (this->flags_, + ACE_Message_Block::DONT_DELETE)&& + this->data_block ()) this->data_block ()->release (); this->prev_ = 0; diff --git a/ace/Message_Block.h b/ace/Message_Block.h index c1a34b77615..04c0c8146a7 100644 --- a/ace/Message_Block.h +++ b/ace/Message_Block.h @@ -123,8 +123,13 @@ public: /// Create an empty message. ACE_Message_Block (ACE_Allocator *message_block_allocator = 0); - /// Create an <ACE_Message_Block> that owns the <ACE_Data_Block> *. + /// Create an <ACE_Message_Block> that owns the <ACE_Data_Block> * + /// without copying it. If the <flags> is set to DONT_DELETE we + /// own't delete the ACE_Data_Block. It is left to the client's + /// responsibility to take care of the memory allocated for the + /// data_block ACE_Message_Block (ACE_Data_Block *, + Message_Flags flags = 0, ACE_Allocator *message_block_allocator = 0); /** @@ -242,6 +247,23 @@ public: /// Get the current message flags. Message_Flags flags (void) const; + // = Data Block flag accessors and mutators. + /// Bitwise-or the <more_flags> into the existing message flags and + /// return the new value. + /* @todo: I think the following set of methods could not be used at + * all. May be they are useless. Let us have it so that we dont + * mess up memory management of the Message_Block. Somebody correct + * me if I am totally totally wrong.. + */ + Message_Flags set_self_flags (ACE_Message_Block::Message_Flags more_flags); + + /// Clear the message flag bits specified in <less_flags> and return + /// the new value. + Message_Flags clr_self_flags (ACE_Message_Block::Message_Flags less_flags); + + /// Get the current message flags. + Message_Flags self_flags (void) const; + /// Get priority of the message. u_long msg_priority (void) const; @@ -311,6 +333,7 @@ public: */ static ACE_Message_Block *release (ACE_Message_Block *mb); + // = Operations on Message data /** @@ -334,7 +357,7 @@ public: /// Normalizes data in the top-level <Message_Block> to align with the base, /// i.e., it "shifts" the data pointed to by <rd_ptr> down to the <base> and /// then readjusts <rt_ptr> to point to <base> and <wr_ptr> to point - /// to <base> + the length of the moved data. + /// to <base> + the length of the moved data. void crunch (void); /// Resets the Message Block data to contain nothing, i.e., sets the @@ -542,6 +565,9 @@ protected: /// Pointer to previous message in the list. ACE_Message_Block *prev_; + /// Misc flags (e.g., DONT_DELETE and USER_FLAGS). + ACE_Message_Block::Message_Flags flags_; + /// Pointer to the reference counted data structure that contains the /// actual memory buffer. ACE_Data_Block *data_block_; @@ -709,7 +735,7 @@ protected: /// Misc flags (e.g., DONT_DELETE and USER_FLAGS). ACE_Message_Block::Message_Flags flags_; - /// Pointer to beginning of message payload. + /// Pointer To beginning of message payload. char *base_; // = Strategies. diff --git a/ace/Message_Block.i b/ace/Message_Block.i index 4989478c6db..dccd000636c 100644 --- a/ace/Message_Block.i +++ b/ace/Message_Block.i @@ -10,6 +10,32 @@ ACE_Message_Block::data_block (void) const return this->data_block_; } +ACE_INLINE ACE_Message_Block::Message_Flags +ACE_Message_Block::set_self_flags (ACE_Message_Block::Message_Flags more_flags) +{ + ACE_TRACE ("ACE_Message_Block::set_flags"); + // Later we might mask more_glags so that user can't change internal + // ones: more_flags &= ~(USER_FLAGS -1). + return ACE_SET_BITS (this->flags_, more_flags); +} + +ACE_INLINE ACE_Message_Block::Message_Flags +ACE_Message_Block::clr_self_flags (ACE_Message_Block::Message_Flags less_flags) +{ + ACE_TRACE ("ACE_Message_Block::clr_flags"); + // Later we might mask more_flags so that user can't change internal + // ones: less_flags &= ~(USER_FLAGS -1). + return ACE_CLR_BITS (this->flags_, less_flags); +} + +ACE_INLINE ACE_Message_Block::Message_Flags +ACE_Message_Block::self_flags (void) const +{ + ACE_TRACE ("ACE_Message_Block::flags"); + return this->flags_; +} + + // This function must comes before ACE_Message_Block::reference_count // to avoid a g++ warning. ACE_INLINE int @@ -206,7 +232,7 @@ ACE_Message_Block::msg_execution_time (void) const #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS) return this->execution_time_; #else - return ACE_Time_Value::zero; + return ACE_Time_Value::zero; #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */ } @@ -463,7 +489,7 @@ ACE_Dynamic_Message_Strategy::static_bit_field_mask (void) const // get static bit field mask ACE_INLINE void -ACE_Dynamic_Message_Strategy::static_bit_field_mask (u_long ul) +ACE_Dynamic_Message_Strategy::static_bit_field_mask (u_long ul) { static_bit_field_mask_ = ul; } |