ACE_Message_Block Class Reference

Stores messages for use throughout ACE (particularly in an ACE_Message_Queue). More...

#include <Message_Block.h>

Collaboration diagram for ACE_Message_Block:

Collaboration graph
[legend]
List of all members.

Public Types

typedef int ACE_Message_Type
typedef unsigned long Message_Flags
 MB_DATA = 0x01
 Undifferentiated data message.
 MB_PROTO = 0x02
 Undifferentiated protocol control.
 MB_BREAK = 0x03
 Line break (regular and priority).
 MB_PASSFP = 0x04
 Pass file pointer.
 MB_EVENT = 0x05
 Post an event to an event queue.
 MB_SIG = 0x06
 Generate process signal.
 MB_IOCTL = 0x07
 ioctl; set/get params
 MB_SETOPTS = 0x08
 Set various stream head options.
 MB_IOCACK = 0x81
 Acknowledge ioctl (high priority; go to head of queue).
 MB_IOCNAK = 0x82
 Negative ioctl acknowledge.
 MB_PCPROTO = 0x83
 Priority proto message.
 MB_PCSIG = 0x84
 Generate process signal.
 MB_READ = 0x85
 Generate read notification.
 MB_FLUSH = 0x86
 Flush your queues.
 MB_STOP = 0x87
 Stop transmission immediately.
 MB_START = 0x88
 Restart transmission after stop.
 MB_HANGUP = 0x89
 Line disconnect.
 MB_ERROR = 0x8a
 Fatal error used to set u.u_error.
 MB_PCEVENT = 0x8b
 Post an event to an event queue.
 MB_NORMAL = 0x00
 Normal priority message mask.
 MB_PRIORITY = 0x80
 High priority control message mask.
 MB_USER = 0x200
 User-defined message mask.
 DONT_DELETE = 01
 Don't delete the data on exit since we don't own it.
 USER_FLAGS = 0x1000
 user defined flags start here
enum  {
  MB_DATA = 0x01, MB_PROTO = 0x02, MB_BREAK = 0x03, MB_PASSFP = 0x04,
  MB_EVENT = 0x05, MB_SIG = 0x06, MB_IOCTL = 0x07, MB_SETOPTS = 0x08,
  MB_IOCACK = 0x81, MB_IOCNAK = 0x82, MB_PCPROTO = 0x83, MB_PCSIG = 0x84,
  MB_READ = 0x85, MB_FLUSH = 0x86, MB_STOP = 0x87, MB_START = 0x88,
  MB_HANGUP = 0x89, MB_ERROR = 0x8a, MB_PCEVENT = 0x8b, MB_NORMAL = 0x00,
  MB_PRIORITY = 0x80, MB_USER = 0x200
}
enum  { DONT_DELETE = 01, USER_FLAGS = 0x1000 }

Public Member Functions

 ACE_Message_Block (ACE_Allocator *message_block_allocator=0)
 Create an empty message.
 ACE_Message_Block (ACE_Data_Block *, Message_Flags flags=0, ACE_Allocator *message_block_allocator=0)
 ACE_Message_Block (const char *data, size_t size=0, unsigned long priority=ACE_DEFAULT_MESSAGE_BLOCK_PRIORITY)
 ACE_Message_Block (size_t size, ACE_Message_Type type=MB_DATA, ACE_Message_Block *cont=0, const char *data=0, ACE_Allocator *allocator_strategy=0, ACE_Lock *locking_strategy=0, unsigned long priority=ACE_DEFAULT_MESSAGE_BLOCK_PRIORITY, const ACE_Time_Value &execution_time=ACE_Time_Value::zero, const ACE_Time_Value &deadline_time=ACE_Time_Value::max_time, ACE_Allocator *data_block_allocator=0, ACE_Allocator *message_block_allocator=0)
 ACE_Message_Block (const ACE_Message_Block &mb, size_t align)
int init (const char *data, size_t size=0)
int init (size_t size, ACE_Message_Type type=MB_DATA, ACE_Message_Block *cont=0, const char *data=0, ACE_Allocator *allocator_strategy=0, ACE_Lock *locking_strategy=0, unsigned long priority=ACE_DEFAULT_MESSAGE_BLOCK_PRIORITY, const ACE_Time_Value &execution_time=ACE_Time_Value::zero, const ACE_Time_Value &deadline_time=ACE_Time_Value::max_time, ACE_Allocator *data_block_allocator=0, ACE_Allocator *message_block_allocator=0)
virtual ~ACE_Message_Block (void)
ACE_Message_Type msg_type (void) const
 Get type of the message.
void msg_type (ACE_Message_Type type)
 Set type of the message.
int is_data_msg (void) const
 Find out what type of message this is.
ACE_Message_Type msg_class (void) const
Message_Flags set_flags (Message_Flags more_flags)
Message_Flags clr_flags (Message_Flags less_flags)
Message_Flags flags (void) const
 Get the current message flags.
Message_Flags set_self_flags (ACE_Message_Block::Message_Flags more_flags)
Message_Flags clr_self_flags (ACE_Message_Block::Message_Flags less_flags)
Message_Flags self_flags (void) const
 Get the current message flags.
unsigned long msg_priority (void) const
 Get priority of the message.
void msg_priority (unsigned long priority)
 Set priority of the message.
const ACE_Time_Valuemsg_execution_time (void) const
 Get execution time associated with the message.
void msg_execution_time (const ACE_Time_Value &et)
 Set execution time associated with the message.
const ACE_Time_Valuemsg_deadline_time (void) const
 Get absolute time of deadline associated with the message.
void msg_deadline_time (const ACE_Time_Value &dt)
 Set absolute time of deadline associated with the message.
virtual ACE_Message_Blockclone (Message_Flags mask=0) const
virtual ACE_Message_Blockduplicate (void) const
 Return a "shallow" copy that increments our reference count by 1.
virtual ACE_Message_Blockrelease (void)
int copy (const char *buf, size_t n)
int copy (const char *buf)
int crunch (void)
void reset (void)
void access_allocators (ACE_Allocator *&allocator_strategy, ACE_Allocator *&data_block_allocator, ACE_Allocator *&message_block_allocator)
void reset_allocators (ACE_Allocator *allocator_strategy=0, ACE_Allocator *data_block_allocator=0, ACE_Allocator *message_block_allocator=0)
char * base (void) const
 Get message data.
void base (char *data, size_t size, Message_Flags=DONT_DELETE)
 Set message data (doesn't reallocate).
char * end (void) const
 Return a pointer to 1 past the end of the allocated data in a message.
char * mark (void) const
char * rd_ptr (void) const
 Get the read pointer.
void rd_ptr (char *ptr)
 Set the read pointer to ptr.
void rd_ptr (size_t n)
 Set the read pointer ahead n bytes.
char * wr_ptr (void) const
 Get the write pointer.
void wr_ptr (char *ptr)
 Set the write pointer to ptr.
void wr_ptr (size_t n)
ACE_Data_Blockdata_block (void) const
void data_block (ACE_Data_Block *)
ACE_Data_Blockreplace_data_block (ACE_Data_Block *)
ACE_Message_Blockcont (void) const
 Get the continuation field.
void cont (ACE_Message_Block *)
 Set the continuation field.
ACE_Message_Blocknext (void) const
 Get link to next message.
void next (ACE_Message_Block *)
 Set link to next message.
ACE_Message_Blockprev (void) const
 Get link to prev message.
void prev (ACE_Message_Block *)
 Set link to prev message.
ACE_Locklocking_strategy (void)
 Get the locking strategy.
ACE_Locklocking_strategy (ACE_Lock *)
 Set a new locking strategy and return the hold one.
int reference_count (void) const
 Get the current reference count.
void dump (void) const
 Dump the state of an object.
Message length and size operations
Message length is (wr_ptr - rd_ptr).

Message size is capacity of the message, including data outside the [rd_ptr,wr_ptr] range.

size_t length (void) const
 Get the length of the message.
void length (size_t n)
 Set the length of the message.
size_t total_length (void) const
size_t total_size (void) const
void total_size_and_length (size_t &mb_size, size_t &mb_length) const
size_t size (void) const
int size (size_t length)
size_t total_capacity (void) const
size_t capacity (void) const
 Get the number of allocated bytes in the top-level <Message_Block>.
size_t space (void) const

Static Public Member Functions

static ACE_Message_Blockduplicate (const ACE_Message_Block *mb)
static ACE_Message_Blockrelease (ACE_Message_Block *mb)

Public Attributes

 ACE_ALLOC_HOOK_DECLARE
 Declare the dynamic allocation hooks.

Protected Member Functions

 ACE_Message_Block (size_t size, ACE_Message_Type type, ACE_Message_Block *cont, const char *data, ACE_Allocator *allocator_strategy, ACE_Lock *locking_strategy, Message_Flags flags, unsigned long priority, const ACE_Time_Value &execution_time, const ACE_Time_Value &deadline_time, ACE_Data_Block *db, ACE_Allocator *data_block_allocator, ACE_Allocator *message_block_allocator)
 Perform the actual initialization.
int release_i (ACE_Lock *lock)
int init_i (size_t size, ACE_Message_Type type, ACE_Message_Block *cont, const char *data, ACE_Allocator *allocator_strategy, ACE_Lock *locking_strategy, Message_Flags flags, unsigned long priority, const ACE_Time_Value &execution_time, const ACE_Time_Value &deadline_time, ACE_Data_Block *db, ACE_Allocator *data_block_allocator, ACE_Allocator *message_block_allocator)
 Perform the actual initialization.

Protected Attributes

size_t rd_ptr_
 Pointer to beginning of next read.
size_t wr_ptr_
 Pointer to beginning of next write.
unsigned long priority_
 Priority of message.
ACE_Message_Blockcont_
 Pointer to next message block in the chain.
ACE_Message_Blocknext_
 Pointer to next message in the list.
ACE_Message_Blockprev_
 Pointer to previous message in the list.
ACE_Message_Block::Message_Flags flags_
 Misc flags (e.g., DONT_DELETE and USER_FLAGS).
ACE_Data_Blockdata_block_
ACE_Allocatormessage_block_allocator_

Private Member Functions

ACE_Message_Blockoperator= (const ACE_Message_Block &)
 ACE_Message_Block (const ACE_Message_Block &)

Friends

class ACE_Data_Block

Detailed Description

Stores messages for use throughout ACE (particularly in an ACE_Message_Queue).

An ACE_Message_Block is modeled after the message data structures used in System V STREAMS. Its purpose is to enable efficient manipulation of arbitrarily large messages without incurring much memory copying overhead. Here are the main characteristics of an ACE_Message_Block:

See also:
C++NPv1, section 4.2; APG, section 12.3.2.

Definition at line 59 of file Message_Block.h.


Member Typedef Documentation

typedef int ACE_Message_Block::ACE_Message_Type

Definition at line 119 of file Message_Block.h.

typedef unsigned long ACE_Message_Block::Message_Flags

Definition at line 120 of file Message_Block.h.


Member Enumeration Documentation

anonymous enum

Enumerator:
MB_DATA  Undifferentiated data message.
MB_PROTO  Undifferentiated protocol control.
MB_BREAK  Line break (regular and priority).
MB_PASSFP  Pass file pointer.
MB_EVENT  Post an event to an event queue.
MB_SIG  Generate process signal.
MB_IOCTL  ioctl; set/get params
MB_SETOPTS  Set various stream head options.
MB_IOCACK  Acknowledge ioctl (high priority; go to head of queue).
MB_IOCNAK  Negative ioctl acknowledge.
MB_PCPROTO  Priority proto message.
MB_PCSIG  Generate process signal.
MB_READ  Generate read notification.
MB_FLUSH  Flush your queues.
MB_STOP  Stop transmission immediately.
MB_START  Restart transmission after stop.
MB_HANGUP  Line disconnect.
MB_ERROR  Fatal error used to set u.u_error.
MB_PCEVENT  Post an event to an event queue.
MB_NORMAL  Normal priority message mask.
MB_PRIORITY  High priority control message mask.
MB_USER  User-defined message mask.

Definition at line 64 of file Message_Block.h.

00065   {
00066     // = Data and proto
00067     /// Undifferentiated data message
00068     MB_DATA     = 0x01,
00069     /// Undifferentiated protocol control
00070     MB_PROTO    = 0x02,
00071 
00072     // = Control messages
00073     /// Line break (regular and priority)
00074     MB_BREAK    = 0x03,
00075     /// Pass file pointer
00076     MB_PASSFP   = 0x04,
00077     /// Post an event to an event queue
00078     MB_EVENT    = 0x05,
00079     /// Generate process signal
00080     MB_SIG      = 0x06,
00081     /// ioctl; set/get params
00082     MB_IOCTL    = 0x07,
00083     /// Set various stream head options
00084     MB_SETOPTS  = 0x08,
00085 
00086     // = Control messages
00087     /// Acknowledge ioctl (high priority; go to head of queue)
00088     MB_IOCACK   = 0x81,
00089     /// Negative ioctl acknowledge
00090     MB_IOCNAK   = 0x82,
00091     /// Priority proto message
00092     MB_PCPROTO  = 0x83,
00093     /// Generate process signal
00094     MB_PCSIG    = 0x84,
00095     /// Generate read notification
00096     MB_READ     = 0x85,
00097     /// Flush your queues
00098     MB_FLUSH    = 0x86,
00099     /// Stop transmission immediately
00100     MB_STOP     = 0x87,
00101     /// Restart transmission after stop
00102     MB_START    = 0x88,
00103     /// Line disconnect
00104     MB_HANGUP   = 0x89,
00105     /// Fatal error used to set u.u_error
00106     MB_ERROR    = 0x8a,
00107     /// Post an event to an event queue
00108     MB_PCEVENT  = 0x8b,
00109 
00110     // = Message class masks
00111     /// Normal priority message mask
00112     MB_NORMAL   = 0x00,
00113     /// High priority control message mask
00114     MB_PRIORITY = 0x80,
00115     /// User-defined message mask
00116     MB_USER     = 0x200
00117   };

anonymous enum

Enumerator:
DONT_DELETE  Don't delete the data on exit since we don't own it.
USER_FLAGS  user defined flags start here

Definition at line 122 of file Message_Block.h.

00123   {
00124     /// Don't delete the data on exit since we don't own it.
00125     DONT_DELETE = 01,
00126     /// user defined flags start here
00127     USER_FLAGS = 0x1000
00128   };


Constructor & Destructor Documentation

ACE_Message_Block::ACE_Message_Block ( ACE_Allocator message_block_allocator = 0  ) 

Create an empty message.

Definition at line 414 of file Message_Block.cpp.

References ACE_ERROR, ACE_TEXT, ACE_TRACE, DONT_DELETE, LM_ERROR, ACE_Time_Value::max_time, MB_DATA, and ACE_Time_Value::zero.

00415   : flags_ (0),
00416     data_block_ (0)
00417 {
00418   ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
00419 
00420   if (this->init_i (0,       // size
00421                     MB_DATA, // type
00422                     0,       // cont
00423                     0,       // data
00424                     0,       // allocator
00425                     0,       // locking strategy
00426                     ACE_Message_Block::DONT_DELETE, // flags
00427                     0, // priority
00428                     ACE_Time_Value::zero,     // execution time
00429                     ACE_Time_Value::max_time, // absolute time of deadline
00430                     0, // data block
00431                     0, // data_block allocator
00432                     message_block_allocator) == -1) // message_block allocator
00433     ACE_ERROR ((LM_ERROR,
00434                 ACE_TEXT ("ACE_Message_Block")));
00435 }

ACE_Message_Block::ACE_Message_Block ( ACE_Data_Block ,
Message_Flags  flags = 0,
ACE_Allocator message_block_allocator = 0 
)

Create an ACE_Message_Block that owns the specified ACE_Data_Block without copying it. If the flags is set to DONT_DELETE we don'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

Definition at line 557 of file Message_Block.cpp.

References ACE_ERROR, ACE_TEXT, ACE_TRACE, data_block(), ACE_Data_Block::data_block_allocator(), LM_ERROR, ACE_Time_Value::max_time, MB_NORMAL, and ACE_Time_Value::zero.

00560   : flags_ (flags),
00561     data_block_ (0)
00562 {
00563   ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
00564 
00565   if (this->init_i (0,         // size
00566                     MB_NORMAL, // type
00567                     0,         // cont
00568                     0,         // data
00569                     0,         // allocator
00570                     0,         // locking strategy
00571                     0,         // flags
00572                     0,         // priority
00573                     ACE_Time_Value::zero,     // execution time
00574                     ACE_Time_Value::max_time, // absolute time of deadline
00575                     data_block, // data block
00576                     data_block->data_block_allocator (),
00577                     message_block_allocator) == -1)
00578     ACE_ERROR ((LM_ERROR,
00579                 ACE_TEXT ("ACE_Message_Block")));
00580 }

ACE_Message_Block::ACE_Message_Block ( const char *  data,
size_t  size = 0,
unsigned long  priority = ACE_DEFAULT_MESSAGE_BLOCK_PRIORITY 
)

Create an ACE_Message_Block that refers to data without copying it. The data memory will not be freed when this block is destroyed; memory management of data is left to the caller. Note that the size of the new ACE_Message_Block will be size, but the length will be 0 until the write pointer is changed.

Definition at line 389 of file Message_Block.cpp.

References ACE_ERROR, ACE_TEXT, ACE_TRACE, DONT_DELETE, LM_ERROR, ACE_Time_Value::max_time, MB_DATA, and ACE_Time_Value::zero.

00392   : flags_ (0),
00393     data_block_ (0)
00394 {
00395   ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
00396 
00397   if (this->init_i (size,    // size
00398                     MB_DATA, // type
00399                     0,       // cont
00400                     data,    // data
00401                     0,       // allocator
00402                     0,       // locking strategy
00403                     ACE_Message_Block::DONT_DELETE, // flags
00404                     priority, // priority
00405                     ACE_Time_Value::zero,     // execution time
00406                     ACE_Time_Value::max_time, // absolute time of deadline
00407                     0,  // data block
00408                     0,  // data_block allocator
00409                     0) == -1) // message_block allocator
00410     ACE_ERROR ((LM_ERROR,
00411                 ACE_TEXT ("ACE_Message_Block")));
00412 }

ACE_Message_Block::ACE_Message_Block ( size_t  size,
ACE_Message_Type  type = MB_DATA,
ACE_Message_Block cont = 0,
const char *  data = 0,
ACE_Allocator allocator_strategy = 0,
ACE_Lock locking_strategy = 0,
unsigned long  priority = ACE_DEFAULT_MESSAGE_BLOCK_PRIORITY,
const ACE_Time_Value execution_time = ACE_Time_Value::zero,
const ACE_Time_Value deadline_time = ACE_Time_Value::max_time,
ACE_Allocator data_block_allocator = 0,
ACE_Allocator message_block_allocator = 0 
)

Create an initialized message of type type containing size bytes. The cont argument initializes the continuation field in the ACE_Message_Block. If data == 0 then this block allocates and owns the block's memory, using allocator to get the data if it's non-0. If data != 0 then this block refers to that memory until this this block ceases to exist; this object will not free data on destruction. If locking_strategy is non-0 then this is used to protect regions of code that access shared state (e.g., reference counting) from race conditions. Note that the size of the ACE_Message_Block will be size, but the length will be 0 until the write pointer is set. The data_block_allocator is used to allocate the data blocks while the allocator_strategy is used to allocate the buffers contained by those. The message_block_allocator is used to allocate new ACE_Message_Block objects when the duplicate() method is called. If a message_block_allocator is given, this ACE_Message_Block and future ACE_Message_Block objects created by duplicate() will be freed using this allocator when they are released.

Note:
If you use this allocator, the ACE_Message_Block you created should have been created using this allocator because it will be released to the same allocator.

Definition at line 437 of file Message_Block.cpp.

References ACE_ERROR, ACE_TEXT, ACE_TRACE, DONT_DELETE, LM_ERROR, and locking_strategy().

00448   :flags_ (0),
00449    data_block_ (0)
00450 {
00451   ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
00452 
00453   if (this->init_i (size,
00454                     msg_type,
00455                     msg_cont,
00456                     msg_data,
00457                     allocator_strategy,
00458                     locking_strategy,
00459                     msg_data ? ACE_Message_Block::DONT_DELETE : 0,
00460                     priority,
00461                     execution_time,
00462                     deadline_time,
00463                     0, // data block
00464                     data_block_allocator,
00465                     message_block_allocator) == -1)
00466     ACE_ERROR ((LM_ERROR,
00467                 ACE_TEXT ("ACE_Message_Block")));
00468 }

ACE_Message_Block::ACE_Message_Block ( const ACE_Message_Block mb,
size_t  align 
)

A copy constructor. This constructor is a bit different. If the incoming Message Block has a data block from the stack this constructor does a deep copy ie. allocates a new data block on the heap and does a copy of the data from the incoming message block. As a final note, the alignment information is used to align the data block if it is created afresh. If the incoming mb has a data block has a data block allocated from the heap, then this constructor just duplicates (ie. a shallow copy) the data block of the incoming mb.

Definition at line 582 of file Message_Block.cpp.

References ACE_BIT_DISABLED, ACE_ERROR, ACE_ptr_align_binary(), ACE_TEXT, ACE_TRACE, base(), ACE_Data_Block::clone_nocopy(), data_block(), ACE_Data_Block::data_block_allocator(), DONT_DELETE, ACE_Data_Block::duplicate(), flags_, LM_ERROR, ACE_Time_Value::max_time, MB_NORMAL, ACE_OS::memcpy(), message_block_allocator_, rd_ptr(), wr_ptr(), wr_ptr_, and ACE_Time_Value::zero.

00584   :flags_ (0),
00585    data_block_ (0)
00586 {
00587   ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
00588 
00589   if (ACE_BIT_DISABLED (mb.flags_,
00590                         ACE_Message_Block::DONT_DELETE))
00591     {
00592       if (this->init_i (0,         // size
00593                         MB_NORMAL, // type
00594                         0,         // cont
00595                         0,         // data
00596                         0,         // allocator
00597                         0,         // locking strategy
00598                         0,         // flags
00599                         0,         // priority
00600                         ACE_Time_Value::zero,     // execution time
00601                         ACE_Time_Value::max_time, // absolute time of deadline
00602                         mb.data_block ()->duplicate (), // data block
00603                         mb.data_block ()->data_block_allocator (),
00604                         mb.message_block_allocator_) == -1)
00605         ACE_ERROR ((LM_ERROR,
00606                     ACE_TEXT ("ACE_Message_Block")));
00607 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
00608       // Align ourselves
00609       char *start = ACE_ptr_align_binary (this->base (),
00610                                           align);
00611 #else
00612       char *start = this->base ();
00613 #endif /* ACE_LACKS_CDR_ALIGNMENT */
00614 
00615       // Set our rd & wr pointers
00616       this->rd_ptr (start);
00617       this->wr_ptr (start);
00618 
00619     }
00620   else
00621     {
00622       if (this->init_i (0,         // size
00623                         MB_NORMAL, // type
00624                         0,         // cont
00625                         0,         // data
00626                         0,         // allocator
00627                         0,         // locking strategy
00628                         0,         // flags
00629                         0,         // priority
00630                         ACE_Time_Value::zero,     // execution time
00631                         ACE_Time_Value::max_time, // absolute time of deadline
00632                         mb.data_block ()->clone_nocopy (),// data block
00633                         mb.data_block ()->data_block_allocator (),
00634                         mb.message_block_allocator_) == -1)
00635         ACE_ERROR ((LM_ERROR,
00636                     ACE_TEXT ("ACE_Message_Block")));
00637 
00638 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
00639       // Align ourselves
00640       char *start = ACE_ptr_align_binary (this->base (),
00641                                           align);
00642 #else
00643       char *start = this->base ();
00644 #endif /* ACE_LACKS_CDR_ALIGNMENT */
00645 
00646       // Set our rd & wr pointers
00647       this->rd_ptr (start);
00648       this->wr_ptr (start);
00649 
00650 #if !defined (ACE_LACKS_CDR_ALIGNMENT)
00651       // Get the alignment offset of the incoming ACE_Message_Block
00652       start = ACE_ptr_align_binary (mb.base (),
00653                                     align);
00654 #else
00655       start = mb.base ();
00656 #endif /* ACE_LACKS_CDR_ALIGNMENT */
00657 
00658       // Actual offset for the incoming message block assuming that it
00659       // is also aligned to the same "align" byte
00660       size_t const wr_offset = mb.wr_ptr_ - (start - mb.base ());
00661 
00662       // Copy wr_offset amount of data in to <this->data_block>
00663       (void) ACE_OS::memcpy (this->wr_ptr (),
00664                              start,
00665                              wr_offset);
00666 
00667       // Dont move the write pointer, just leave it to the application
00668       // to do what it wants
00669 
00670     }
00671 #if defined (ACE_LACKS_CDR_ALIGNMENT)
00672   ACE_UNUSED_ARG (align);
00673 #endif /* ACE_LACKS_CDR_ALIGNMENT */
00674 }

ACE_Message_Block::~ACE_Message_Block ( void   )  [virtual]

Delete all the resources held in the message.

Note that <release()> is designed to release the continuation chain; the destructor is not. See <release()> for details.

Definition at line 972 of file Message_Block.cpp.

References ACE_BIT_DISABLED, ACE_TRACE, DONT_DELETE, next_, and prev_.

00973 {
00974   ACE_TRACE ("ACE_Message_Block::~ACE_Message_Block");
00975 
00976   if (ACE_BIT_DISABLED (this->flags_,
00977                         ACE_Message_Block::DONT_DELETE)&&
00978       this->data_block ())
00979     this->data_block ()->release ();
00980 
00981   this->prev_ = 0;
00982   this->next_ = 0;
00983 }

ACE_Message_Block::ACE_Message_Block ( size_t  size,
ACE_Message_Type  type,
ACE_Message_Block cont,
const char *  data,
ACE_Allocator allocator_strategy,
ACE_Lock locking_strategy,
Message_Flags  flags,
unsigned long  priority,
const ACE_Time_Value execution_time,
const ACE_Time_Value deadline_time,
ACE_Data_Block db,
ACE_Allocator data_block_allocator,
ACE_Allocator message_block_allocator 
) [protected]

Perform the actual initialization.

Definition at line 522 of file Message_Block.cpp.

References ACE_ERROR, ACE_TEXT, ACE_TRACE, LM_ERROR, and locking_strategy().

00535   : flags_ (0),
00536     data_block_ (0)
00537 {
00538   ACE_TRACE ("ACE_Message_Block::ACE_Message_Block");
00539 
00540   if (this->init_i (size,
00541                     msg_type,
00542                     msg_cont,
00543                     msg_data,
00544                     allocator_strategy,
00545                     locking_strategy,
00546                     flags,
00547                     priority,
00548                     execution_time,
00549                     deadline_time,
00550                     db,
00551                     data_block_allocator,
00552                     message_block_allocator) == -1)
00553     ACE_ERROR ((LM_ERROR,
00554                 ACE_TEXT ("ACE_Message_Block")));
00555 }

ACE_Message_Block::ACE_Message_Block ( const ACE_Message_Block  )  [private]


Member Function Documentation

ACE_INLINE void ACE_Message_Block::access_allocators ( ACE_Allocator *&  allocator_strategy,
ACE_Allocator *&  data_block_allocator,
ACE_Allocator *&  message_block_allocator 
)

This method returns the allocators only from the first message block in the chain.

Parameters:
allocator_strategy Strategy used to allocate the underlying buffer
data_block_allocator Strategy used to allocate the underlying data block
message_block_allocator Strategy used to allocate the message block

Definition at line 272 of file Message_Block.inl.

References ACE_Data_Block::allocator_strategy_, data_block_, ACE_Data_Block::data_block_allocator_, and message_block_allocator_.

00275 {
00276   allocator_strategy =
00277     this->data_block_->allocator_strategy_;
00278   data_block_allocator =
00279     this->data_block_->data_block_allocator_;
00280   message_block_allocator =
00281     this->message_block_allocator_;
00282 }

ACE_INLINE void ACE_Message_Block::base ( char *  data,
size_t  size,
Message_Flags  = DONT_DELETE 
)

Set message data (doesn't reallocate).

Definition at line 292 of file Message_Block.inl.

References ACE_TRACE, ACE_Data_Block::base(), data_block(), rd_ptr_, and wr_ptr_.

00295 {
00296   ACE_TRACE ("ACE_Message_Block::base");
00297   this->rd_ptr_ = 0;
00298   this->wr_ptr_ = 0;
00299   this->data_block ()->base (msg_data, msg_length, msg_flags);
00300 }

ACE_INLINE char * ACE_Message_Block::base ( void   )  const

Get message data.

Definition at line 285 of file Message_Block.inl.

References ACE_TRACE, ACE_Data_Block::base(), and data_block().

Referenced by ACE_InputCDR::ACE_InputCDR(), ACE_Message_Block(), ACE_Activation_Queue::dequeue(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::dequeue_deadline(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::dequeue_head(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::dequeue_prio(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::dequeue_tail(), ACE_InputCDR::exchange_data_blocks(), ACE_CDR::mb_align(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::peek_dequeue_head(), rd_ptr(), and wr_ptr().

00286 {
00287   ACE_TRACE ("ACE_Message_Block::base");
00288   return this->data_block ()->base ();
00289 }

ACE_INLINE size_t ACE_Message_Block::capacity ( void   )  const

Get the number of allocated bytes in the top-level <Message_Block>.

Definition at line 154 of file Message_Block.inl.

References ACE_TRACE, ACE_Data_Block::capacity(), and data_block().

00155 {
00156   ACE_TRACE ("ACE_Message_Block::capacity");
00157   return this->data_block ()->capacity ();
00158 }

ACE_Message_Block * ACE_Message_Block::clone ( Message_Flags  mask = 0  )  const [virtual]

Return an exact "deep copy" of the message, i.e., create fresh new copies of all the Data_Blocks and continuations.

Definition at line 1170 of file Message_Block.cpp.

References ACE_DEADLINE_TIME, ACE_EXECUTION_TIME, ACE_NEW_RETURN, ACE_TRACE, clone(), ACE_Data_Block::clone(), cont(), cont_, data_block(), ACE_Data_Block::data_block_allocator(), ACE_Allocator::malloc(), message_block_allocator_, rd_ptr(), release(), ACE_Data_Block::release(), and wr_ptr().

Referenced by clone(), and ACE_InputCDR::steal_contents().

01171 {
01172   ACE_TRACE ("ACE_Message_Block::clone");
01173 
01174   // Get a pointer to a "cloned" <ACE_Data_Block> (will copy the
01175   // values rather than increment the reference count).
01176   ACE_Data_Block *db = this->data_block ()->clone (mask);
01177 
01178   if (db == 0)
01179     return 0;
01180 
01181   ACE_Message_Block *nb = 0;
01182 
01183   if(message_block_allocator_ == 0)
01184     {
01185       ACE_NEW_RETURN (nb,
01186                       ACE_Message_Block (0, // size
01187                                          ACE_Message_Type (0), // type
01188                                          0, // cont
01189                                          0, // data
01190                                          0, // allocator
01191                                          0, // locking strategy
01192                                          0, // flags
01193                                          this->priority_, // priority
01194                                          ACE_EXECUTION_TIME, // execution time
01195                                          ACE_DEADLINE_TIME, // absolute time to deadline
01196                                          // Get a pointer to a
01197                                          // "duplicated" <ACE_Data_Block>
01198                                          // (will simply increment the
01199                                          // reference count).
01200                                          db,
01201                                          db->data_block_allocator (),
01202                                          this->message_block_allocator_),
01203                       0);
01204     }
01205   else
01206     {
01207       // This is the ACE_NEW_MALLOC macro with the return check removed.
01208       // We need to do it this way because if it fails we need to release
01209       // the cloned data block that was created above.  If we used
01210       // ACE_NEW_MALLOC_RETURN, there would be a memory leak because the
01211       // above db pointer would be left dangling.
01212       nb = static_cast<ACE_Message_Block*> (message_block_allocator_->malloc (sizeof (ACE_Message_Block)));
01213       if(nb != 0)
01214         new (nb) ACE_Message_Block (0, // size
01215                                     ACE_Message_Type (0), // type
01216                                     0, // cont
01217                                     0, // data
01218                                     0, // allocator
01219                                     0, // locking strategy
01220                                     0, // flags
01221                                     this->priority_, // priority
01222                                     ACE_EXECUTION_TIME, // execution time
01223                                     ACE_DEADLINE_TIME, // absolute time to deadline
01224                                     db,
01225                                     db->data_block_allocator (),
01226                                     this->message_block_allocator_);
01227     }
01228 
01229   if (nb == 0)
01230     {
01231       db->release ();
01232       return 0;
01233     }
01234 
01235   // Set the read and write pointers in the new <Message_Block> to the
01236   // same relative offset as in the existing <Message_Block>.
01237   nb->rd_ptr (this->rd_ptr_);
01238   nb->wr_ptr (this->wr_ptr_);
01239 
01240   // Clone all the continuation messages if necessary.
01241   if (this->cont () != 0
01242       && (nb->cont_ = this->cont ()->clone (mask)) == 0)
01243     {
01244       nb->release ();
01245       return 0;
01246     }
01247   return nb;
01248 }

ACE_INLINE ACE_Message_Block::Message_Flags ACE_Message_Block::clr_flags ( Message_Flags  less_flags  ) 

Clear the message flag bits specified in less_flags and return the new value.

Definition at line 112 of file Message_Block.inl.

References ACE_TRACE, ACE_Data_Block::clr_flags(), and data_block().

00113 {
00114   ACE_TRACE ("ACE_Message_Block::clr_flags");
00115   return this->data_block ()->clr_flags (less_flags);
00116 }

ACE_INLINE ACE_Message_Block::Message_Flags ACE_Message_Block::clr_self_flags ( ACE_Message_Block::Message_Flags  less_flags  ) 

Clear the message flag bits specified in less_flags and return the new value.

Definition at line 24 of file Message_Block.inl.

References ACE_CLR_BITS, and ACE_TRACE.

Referenced by ACE_InputCDR::clone_from(), ACE_InputCDR::exchange_data_blocks(), ACE_CDR::grow(), ACE_InputCDR::reset_contents(), ACE_InputCDR::steal_contents(), and ACE_InputCDR::steal_from().

00025 {
00026   ACE_TRACE ("ACE_Message_Block::clr_self_flags");
00027   // Later we might mask more_flags so that user can't change internal
00028   // ones: less_flags &= ~(USER_FLAGS -1).
00029   return ACE_CLR_BITS (this->flags_, less_flags);
00030 }

ACE_INLINE void ACE_Message_Block::cont ( ACE_Message_Block  ) 

Set the continuation field.

Definition at line 409 of file Message_Block.inl.

References ACE_TRACE, and cont_.

00410 {
00411   ACE_TRACE ("ACE_Message_Block::cont");
00412   this->cont_ = cont_msg;
00413 }

ACE_INLINE ACE_Message_Block * ACE_Message_Block::cont ( void   )  const

Get the continuation field.

Definition at line 416 of file Message_Block.inl.

References ACE_TRACE, and cont_.

Referenced by ACE_InputCDR::ACE_InputCDR(), clone(), ACE_OutputCDR::consolidate(), ACE_Stream_Tail<>::control(), ACE_Stream_Head<>::control(), ACE_OutputCDR::end(), ACE_OutputCDR::find(), ACE_OutputCDR::grow_and_adjust(), ACE::recv_n(), ACE_OutputCDR::reset(), ACE::send_n(), ACE_CDR::total_length(), ACE::write_n(), ACE_OutputCDR::write_octet_array_mb(), and ACE_OutputCDR::~ACE_OutputCDR().

00417 {
00418   ACE_TRACE ("ACE_Message_Block::cont");
00419   return this->cont_;
00420 }

int ACE_Message_Block::copy ( const char *  buf  ) 

Copies a 0-terminated character string into this ACE_Message_Block. The string is copied into the block starting at the current write pointer. The 0-terminator is included in the copied data.

Parameters:
buf Pointer to the character string to copy from.
Return values:
0 on success; the write pointer is advanced by the string's length, including the 0 terminator.
-1 if the amount of free space following the write pointer in the block is less than required to hold the entire string. Free space can be checked by calling space().

Definition at line 102 of file Message_Block.cpp.

References ACE_TRACE, ACE_OS::memcpy(), space(), ACE_OS::strlen(), and wr_ptr().

00103 {
00104   ACE_TRACE ("ACE_Message_Block::copy");
00105 
00106   /* size_t len = static_cast<size_t> (this->end () - this->wr_ptr ()); */
00107   // Note that for this to work correct, end() *must* be >= wr_ptr().
00108   size_t len = this->space ();
00109 
00110   size_t buflen = ACE_OS::strlen (buf) + 1;
00111 
00112   if (len < buflen)
00113     {
00114       errno = ENOSPC;
00115       return -1;
00116     }
00117   else
00118     {
00119       (void) ACE_OS::memcpy (this->wr_ptr (),
00120                              buf,
00121                              buflen);
00122       this->wr_ptr (buflen);
00123       return 0;
00124     }
00125 }

int ACE_Message_Block::copy ( const char *  buf,
size_t  n 
)

Copies data into this ACE_Message_Block. Data is copied into the block starting at the current write pointer.

Parameters:
buf Pointer to the buffer to copy from.
n The number of bytes to copy.
Return values:
0 on success; the write pointer is advanced by
  • n.
-1 if the amount of free space following the write pointer in the block is less than
  • n. Free space can be checked by calling space().

Definition at line 78 of file Message_Block.cpp.

References ACE_TRACE, ACE_OS::memcpy(), space(), and wr_ptr().

Referenced by ACE_OutputCDR::consolidate(), and ACE_CDR::consolidate().

00079 {
00080   ACE_TRACE ("ACE_Message_Block::copy");
00081 
00082   /*size_t len = static_cast<size_t> (this->end () - this->wr_ptr ());*/
00083   // Note that for this to work correct, end () *must* be >= mark ().
00084   size_t len = this->space ();
00085 
00086   if (len < n)
00087     {
00088       errno = ENOSPC;
00089       return -1;
00090     }
00091   else
00092     {
00093       (void) ACE_OS::memcpy (this->wr_ptr (),
00094                              buf,
00095                              n);
00096       this->wr_ptr (n);
00097       return 0;
00098     }
00099 }

int ACE_Message_Block::crunch ( void   ) 

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 <rd_ptr> to point to <base> and <wr_ptr> to point to <base> + the length of the moved data. Returns -1 and does nothing if the <rd_ptr> is > <wr_ptr>, else 0 on success.

Definition at line 128 of file Message_Block.cpp.

References length(), ACE_OS::memmove(), rd_ptr(), and wr_ptr().

00129 {
00130   if (this->rd_ptr_ != 0)
00131     {
00132       if (this->rd_ptr_ > this->wr_ptr_)
00133         return -1;
00134 
00135       size_t const len = this->length ();
00136       (void) ACE_OS::memmove (this->base (),
00137                               this->rd_ptr (),
00138                               len);
00139       this->rd_ptr (this->base ());
00140       this->wr_ptr (this->base () + len);
00141     }
00142   return 0;
00143 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL void ACE_Message_Block::data_block ( ACE_Data_Block  ) 

Set a new data block pointer. The original ACE_Data_Block is released as a result of this call. If you need to keep the original block, call <replace_data_block> instead. Upon return, this ACE_Message_Block holds a pointer to the new ACE_Data_Block, taking over the reference you held on it prior to the call.

Definition at line 61 of file Message_Block.cpp.

References ACE_BIT_DISABLED, ACE_TRACE, data_block_, DONT_DELETE, rd_ptr(), ACE_Data_Block::release(), and wr_ptr().

00062 {
00063   ACE_TRACE ("ACE_Message_Block::data_block");
00064   if (ACE_BIT_DISABLED (this->flags_,
00065                         ACE_Message_Block::DONT_DELETE)
00066       && this->data_block_ != 0)
00067     this->data_block_->release ();
00068 
00069   this->data_block_ = db;
00070 
00071   // Set the read and write pointers in the <Message_Block> to point
00072   // to the buffer in the <ACE_Data_Block>.
00073   this->rd_ptr (this->data_block ()->base ());
00074   this->wr_ptr (this->data_block ()->base ());
00075 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE ACE_Data_Block * ACE_Message_Block::data_block ( void   )  const

Get a pointer to the data block. Note that the ACE_Message_Block still references the block; this call does not change the reference count.

Definition at line 8 of file Message_Block.inl.

References ACE_TRACE, and data_block_.

Referenced by ACE_InputCDR::ACE_InputCDR(), ACE_Message_Block(), base(), capacity(), clone(), ACE_InputCDR::clone_from(), clr_flags(), dump(), duplicate(), end(), ACE_InputCDR::exchange_data_blocks(), flags(), ACE_CDR::grow(), ACE_OutputCDR::grow_and_adjust(), init_i(), locking_strategy(), mark(), msg_type(), ACE_InputCDR::operator=(), reference_count(), release(), release_i(), ACE_InputCDR::reset_contents(), set_flags(), size(), ACE_InputCDR::steal_contents(), and ACE_InputCDR::steal_from().

00009 {
00010   ACE_TRACE ("ACE_Message_Block::data_block");
00011   return this->data_block_;
00012 }

void ACE_Message_Block::dump ( void   )  const

Dump the state of an object.

Definition at line 174 of file Message_Block.cpp.

References ACE_BEGIN_DUMP, ACE_DEBUG, ACE_END_DUMP, ACE_TEXT, ACE_TRACE, data_block(), ACE_Data_Block::dump(), and LM_DEBUG.

00175 {
00176 #if defined (ACE_HAS_DUMP)
00177   ACE_TRACE ("ACE_Message_Block::dump");
00178   ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
00179   ACE_DEBUG ((LM_DEBUG,
00180               ACE_TEXT ("-----( Message Block )-----\n")
00181               ACE_TEXT ("priority_ = %d\n")
00182               ACE_TEXT ("next_ = %u\n")
00183               ACE_TEXT ("prev_ = %u\n")
00184               ACE_TEXT ("cont_ = %u\n")
00185               ACE_TEXT ("rd_ptr_ = %u\n")
00186               ACE_TEXT ("wr_ptr_ = %u\n")
00187               ACE_TEXT ("---------------------------\n"),
00188               this->priority_,
00189               this->next_,
00190               this->prev_,
00191               this->cont_,
00192               this->rd_ptr_,
00193               this->wr_ptr_));
00194   this->data_block ()->dump ();
00195   ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
00196 #endif /* ACE_HAS_DUMP */
00197 }

ACE_Message_Block * ACE_Message_Block::duplicate ( const ACE_Message_Block mb  )  [static]

Return a "shallow" copy that increments our reference count by 1. This is similar to CORBA's <_duplicate> method, which is useful if you want to eliminate lots of checks for NULL mb pointers before calling <_duplicate> on them.

Definition at line 1092 of file Message_Block.cpp.

References ACE_TRACE, and duplicate().

01093 {
01094   ACE_TRACE ("ACE_Message_Block::duplicate");
01095   if (mb == 0)
01096     return 0;
01097   else
01098     return mb->duplicate ();
01099 }

ACE_Message_Block * ACE_Message_Block::duplicate ( void   )  const [virtual]

Return a "shallow" copy that increments our reference count by 1.

Definition at line 1013 of file Message_Block.cpp.

References ACE_DEADLINE_TIME, ACE_EXECUTION_TIME, ACE_NEW_MALLOC_RETURN, ACE_NEW_RETURN, ACE_TRACE, cont_, data_block(), ACE_Data_Block::data_block_allocator(), duplicate(), ACE_Allocator::malloc(), message_block_allocator_, rd_ptr(), release(), and wr_ptr().

Referenced by duplicate().

01014 {
01015   ACE_TRACE ("ACE_Message_Block::duplicate");
01016 
01017   ACE_Message_Block *nb = 0;
01018 
01019   // Create a new <ACE_Message_Block> that contains unique copies of
01020   // the message block fields, but a reference counted duplicate of
01021   // the <ACE_Data_Block>.
01022 
01023   // If there is no allocator, use the standard new and delete calls.
01024   if (this->message_block_allocator_ == 0)
01025     ACE_NEW_RETURN (nb,
01026                     ACE_Message_Block (0, // size
01027                                        ACE_Message_Type (0), // type
01028                                        0, // cont
01029                                        0, // data
01030                                        0, // allocator
01031                                        0, // locking strategy
01032                                        0, // flags
01033                                        this->priority_, // priority
01034                                        ACE_EXECUTION_TIME,
01035                                        ACE_DEADLINE_TIME,
01036                                        // Get a pointer to a
01037                                        // "duplicated" <ACE_Data_Block>
01038                                        // (will simply increment the
01039                                        // reference count).
01040                                        this->data_block ()->duplicate  (),
01041                                        this->data_block ()->data_block_allocator (),
01042                                        this->message_block_allocator_),
01043                   0);
01044   else // Otherwise, use the message_block_allocator passed in.
01045     ACE_NEW_MALLOC_RETURN (nb,
01046                            static_cast<ACE_Message_Block*> (
01047                              message_block_allocator_->malloc (sizeof (ACE_Message_Block))),
01048                            ACE_Message_Block (0, // size
01049                                               ACE_Message_Type (0), // type
01050                                               0, // cont
01051                                               0, // data
01052                                               0, // allocator
01053                                               0, // locking strategy
01054                                               0, // flags
01055                                               this->priority_, // priority
01056                                               ACE_EXECUTION_TIME,
01057                                               ACE_DEADLINE_TIME,
01058                                               // Get a pointer to a
01059                                               // "duplicated" <ACE_Data_Block>
01060                                               // (will simply increment the
01061                                               // reference count).
01062                                               this->data_block ()->duplicate  (),
01063                                               this->data_block ()->data_block_allocator (),
01064                                               this->message_block_allocator_),
01065                            0);
01066 
01067   // Set the read and write pointers in the new <Message_Block> to the
01068   // same relative offset as in the existing <Message_Block>.  Note
01069   // that we are assuming that the data_block()->base() pointer
01070   // doesn't change when it's duplicated.
01071   nb->rd_ptr (this->rd_ptr_);
01072   nb->wr_ptr (this->wr_ptr_);
01073 
01074   // Increment the reference counts of all the continuation messages.
01075   if (this->cont_)
01076     {
01077       nb->cont_ = this->cont_->duplicate ();
01078 
01079       // If things go wrong, release all of our resources and return
01080       // 0.
01081       if (nb->cont_ == 0)
01082         {
01083           nb->release ();
01084           nb = 0;
01085         }
01086     }
01087 
01088   return nb;
01089 }

ACE_INLINE char * ACE_Message_Block::end ( void   )  const

Return a pointer to 1 past the end of the allocated data in a message.

Definition at line 340 of file Message_Block.inl.

References ACE_TRACE, data_block(), and ACE_Data_Block::end().

Referenced by ACE_OutputCDR::adjust(), ACE_InputCDR::end(), and ACE_OutputCDR::write_octet_array_mb().

00341 {
00342   ACE_TRACE ("ACE_Message_Block::end");
00343   return this->data_block ()->end ();
00344 }

ACE_INLINE ACE_Message_Block::Message_Flags ACE_Message_Block::flags ( void   )  const

Get the current message flags.

Definition at line 119 of file Message_Block.inl.

References ACE_TRACE, data_block(), and ACE_Data_Block::flags().

00120 {
00121   ACE_TRACE ("ACE_Message_Block::flags");
00122    return this->data_block ()->flags ();
00123 }

int ACE_Message_Block::init ( size_t  size,
ACE_Message_Type  type = MB_DATA,
ACE_Message_Block cont = 0,
const char *  data = 0,
ACE_Allocator allocator_strategy = 0,
ACE_Lock locking_strategy = 0,
unsigned long  priority = ACE_DEFAULT_MESSAGE_BLOCK_PRIORITY,
const ACE_Time_Value execution_time = ACE_Time_Value::zero,
const ACE_Time_Value deadline_time = ACE_Time_Value::max_time,
ACE_Allocator data_block_allocator = 0,
ACE_Allocator message_block_allocator = 0 
)

Create an initialized message of type type containing size bytes. The cont argument initializes the continuation field in the <Message_Block>. If data == 0 then we create and own the data, using allocator_strategy to get the data if it's non-0. If data != 0 we assume that we have ownership of the data till this object ceases to exist (and don't delete it during destruction). If locking_strategy is non-0 then this is used to protect regions of code that access shared state (e.g., reference counting) from race conditions. Note that the size of the <Message_Block> will be size, but the length will be 0 until <wr_ptr> is set. The data_block_allocator is use to allocate the data blocks while the allocator_strategy is used to allocate the buffers contained by those.

Definition at line 471 of file Message_Block.cpp.

References ACE_TRACE, DONT_DELETE, init_i(), and locking_strategy().

00482 {
00483   ACE_TRACE ("ACE_Message_Block::init");
00484 
00485   return this->init_i (size,
00486                        msg_type,
00487                        msg_cont,
00488                        msg_data,
00489                        allocator_strategy,
00490                        locking_strategy,
00491                        msg_data ? ACE_Message_Block::DONT_DELETE : 0,
00492                        priority,
00493                        execution_time,
00494                        deadline_time,
00495                        0,  // data block
00496                        data_block_allocator,
00497                        message_block_allocator);
00498 }

int ACE_Message_Block::init ( const char *  data,
size_t  size = 0 
)

Create a Message Block that assumes it has ownership of data, but in reality it doesnt (i.e., cannot delete it since it didn't malloc it!). Note that the size of the Message_Block will be size, but the length will be 0 until <wr_ptr> is set.

Definition at line 501 of file Message_Block.cpp.

References ACE_TRACE, DONT_DELETE, init_i(), ACE_Time_Value::max_time, MB_DATA, and ACE_Time_Value::zero.

00503 {
00504   ACE_TRACE ("ACE_Message_Block::init");
00505   // Should we also initialize all the other fields, as well?
00506 
00507   return this->init_i (size,    // size
00508                        MB_DATA, // type
00509                        0,       // cont
00510                        data,    // data
00511                        0,       // allocator
00512                        0,       // locking strategy
00513                        ACE_Message_Block::DONT_DELETE,  // flags
00514                        0,  // priority
00515                        ACE_Time_Value::zero,     // execution time
00516                        ACE_Time_Value::max_time, // absolute time of deadline
00517                        0,  // data block
00518                        0,  // data_block allocator
00519                        0); // message_block allocator
00520 }

int ACE_Message_Block::init_i ( size_t  size,
ACE_Message_Type  type,
ACE_Message_Block cont,
const char *  data,
ACE_Allocator allocator_strategy,
ACE_Lock locking_strategy,
Message_Flags  flags,
unsigned long  priority,
const ACE_Time_Value execution_time,
const ACE_Time_Value deadline_time,
ACE_Data_Block db,
ACE_Allocator data_block_allocator,
ACE_Allocator message_block_allocator 
) [protected]

Perform the actual initialization.

Definition at line 677 of file Message_Block.cpp.

References ACE_ALLOCATOR_RETURN, ACE_FUNCTION_TIMEPROBE, ACE_NEW_MALLOC_RETURN, ACE_TIMEPROBE, ACE_TRACE, cont_, data_block(), data_block_, ACE_Allocator::free(), ACE_Allocator::instance(), locking_strategy(), ACE_Allocator::malloc(), message_block_allocator_, next_, prev_, priority_, rd_ptr_, ACE_Data_Block::release(), size(), ACE_Data_Block::size(), and wr_ptr_.

Referenced by init().

00690 {
00691   ACE_TRACE ("ACE_Message_Block::init_i");
00692   ACE_FUNCTION_TIMEPROBE (ACE_MESSAGE_BLOCK_INIT_I_ENTER);
00693 
00694   this->rd_ptr_ = 0;
00695   this->wr_ptr_ = 0;
00696   this->priority_ = priority;
00697 #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
00698   this->execution_time_ = execution_time;
00699   this->deadline_time_ = deadline_time;
00700 #else
00701   ACE_UNUSED_ARG (execution_time);
00702   ACE_UNUSED_ARG (deadline_time);
00703 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
00704   this->cont_ = msg_cont;
00705   this->next_ = 0;
00706   this->prev_ = 0;
00707 
00708   this->message_block_allocator_ = message_block_allocator;
00709 
00710   if (this->data_block_ != 0)
00711     {
00712       this->data_block_->release ();
00713       this->data_block_ = 0;
00714     }
00715 
00716   if (db == 0)
00717     {
00718       if (data_block_allocator == 0)
00719         ACE_ALLOCATOR_RETURN (data_block_allocator,
00720                               ACE_Allocator::instance (),
00721                               -1);
00722 
00723       ACE_TIMEPROBE (ACE_MESSAGE_BLOCK_INIT_I_DB_ALLOC);
00724 
00725       // Allocate the <ACE_Data_Block> portion, which is reference
00726       // counted.
00727       ACE_NEW_MALLOC_RETURN (db,
00728                              static_cast<ACE_Data_Block *> (
00729                                data_block_allocator->malloc (sizeof (ACE_Data_Block))),
00730                              ACE_Data_Block (size,
00731                                              msg_type,
00732                                              msg_data,
00733                                              allocator_strategy,
00734                                              locking_strategy,
00735                                              flags,
00736                                              data_block_allocator),
00737                              -1);
00738       ACE_TIMEPROBE (ACE_MESSAGE_BLOCK_INIT_I_DB_CTOR);
00739 
00740       // Message block initialization may fail, while the construction
00741       // succeds.  Since ACE may throw no exceptions, we have to do a
00742       // separate check and clean up, like this:
00743       if (db != 0 && db->size () < size)
00744         {
00745           db->ACE_Data_Block::~ACE_Data_Block();  // placement destructor ...
00746           data_block_allocator->free (db); // free ...
00747           errno = ENOMEM;
00748           return -1;
00749         }
00750     }
00751 
00752   // Reset the data_block_ pointer.
00753   this->data_block (db);
00754 
00755   return 0;
00756 }

ACE_INLINE int ACE_Message_Block::is_data_msg ( void   )  const

Find out what type of message this is.

Definition at line 202 of file Message_Block.inl.

References ACE_TRACE, MB_DATA, MB_PCPROTO, MB_PROTO, and msg_type().

00203 {
00204   ACE_TRACE ("ACE_Message_Block::is_data_msg");
00205   ACE_Message_Type mt = this->msg_type ();
00206   return
00207     mt == ACE_Message_Block::MB_DATA
00208     || mt == ACE_Message_Block::MB_PROTO
00209     || mt == ACE_Message_Block::MB_PCPROTO;
00210 }

ACE_INLINE void ACE_Message_Block::length ( size_t  n  ) 

Set the length of the message.

Definition at line 138 of file Message_Block.inl.

References ACE_TRACE, rd_ptr_, and wr_ptr_.

00139 {
00140   ACE_TRACE ("ACE_Message_Block::length");
00141   this->wr_ptr_ = this->rd_ptr_ + len;
00142 }

ACE_INLINE size_t ACE_Message_Block::length ( void   )  const

Get the length of the message.

Definition at line 128 of file Message_Block.inl.

References ACE_TRACE, rd_ptr_, and wr_ptr_.

Referenced by crunch(), ACE_CDR::grow(), ACE_InputCDR::length(), ACE_OutputCDR::length(), ACE::recv_n(), ACE::send_n(), total_length(), and ACE::write_n().

00129 {
00130   ACE_TRACE ("ACE_Message_Block::length");
00131   return this->wr_ptr_ - this->rd_ptr_;
00132 }

ACE_INLINE ACE_Lock * ACE_Message_Block::locking_strategy ( ACE_Lock  ) 

Set a new locking strategy and return the hold one.

Definition at line 500 of file Message_Block.inl.

References ACE_TRACE, data_block(), and ACE_Data_Block::locking_strategy().

00501 {
00502   ACE_TRACE ("ACE_Message_Block::locking_strategy");
00503   ACE_Lock *ols = this->data_block ()->locking_strategy ();
00504   this->data_block ()->locking_strategy (nls);
00505   return ols;
00506 }

ACE_INLINE ACE_Lock * ACE_Message_Block::locking_strategy ( void   ) 

Get the locking strategy.

Definition at line 493 of file Message_Block.inl.

References ACE_TRACE, data_block(), and ACE_Data_Block::locking_strategy().

Referenced by ACE_Message_Block(), init(), and init_i().

00494 {
00495   ACE_TRACE ("ACE_Message_Block::locking_strategy");
00496   return this->data_block ()->locking_strategy ();
00497 }

ACE_INLINE char * ACE_Message_Block::mark ( void   )  const

Return a pointer to 1 past the end of the allotted data in a message. Allotted data may be less than allocated data if a value smaller than capacity() to is passed to size().

Definition at line 326 of file Message_Block.inl.

References ACE_TRACE, data_block(), and ACE_Data_Block::mark().

Referenced by space().

00327 {
00328   ACE_TRACE ("ACE_Message_Block::mark");
00329   return this->data_block ()->mark ();
00330 }

ACE_INLINE ACE_Message_Block::ACE_Message_Type ACE_Message_Block::msg_class ( void   )  const

Find out what class of message this is (there are two classes, normal messages and high-priority messages).

Definition at line 189 of file Message_Block.inl.

References ACE_TRACE, MB_NORMAL, MB_PRIORITY, and MB_USER.

00190 {
00191   ACE_TRACE ("ACE_Message_Block::msg_class");
00192 
00193   if (this->msg_type () < ACE_Message_Block::MB_PRIORITY)
00194     return ACE_Message_Block::MB_NORMAL;
00195   else if (this->msg_type () < ACE_Message_Block::MB_USER)
00196     return ACE_Message_Block::MB_PRIORITY;
00197   else
00198     return ACE_Message_Block::MB_USER;
00199 }

ACE_INLINE void ACE_Message_Block::msg_deadline_time ( const ACE_Time_Value dt  ) 

Set absolute time of deadline associated with the message.

Definition at line 261 of file Message_Block.inl.

References ACE_TRACE.

00262 {
00263   ACE_TRACE ("ACE_Message_Block::msg_deadline_time (const ACE_Time_Value & et)");
00264 #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
00265   this->deadline_time_ = dt;
00266 #else
00267   ACE_UNUSED_ARG (dt);
00268 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
00269 }

ACE_INLINE const ACE_Time_Value & ACE_Message_Block::msg_deadline_time ( void   )  const

Get absolute time of deadline associated with the message.

Definition at line 249 of file Message_Block.inl.

References ACE_TRACE, and ACE_Time_Value::max_time.

Referenced by ACE_Laxity_Message_Strategy::convert_priority(), ACE_Deadline_Message_Strategy::convert_priority(), and ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_deadline_i().

00250 {
00251   ACE_TRACE ("ACE_Message_Block::msg_deadline_time (void)");
00252 
00253 #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
00254   return this->deadline_time_;
00255 #else
00256   return ACE_Time_Value::max_time; // absolute time of deadline
00257 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
00258 }

ACE_INLINE void ACE_Message_Block::msg_execution_time ( const ACE_Time_Value et  ) 

Set execution time associated with the message.

Definition at line 238 of file Message_Block.inl.

References ACE_TRACE.

00239 {
00240   ACE_TRACE ("ACE_Message_Block::msg_execution_time (const ACE_Time_Value & et)");
00241 #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
00242   this->execution_time_ = et;
00243 #else
00244   ACE_UNUSED_ARG (et);
00245 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
00246 }

ACE_INLINE const ACE_Time_Value & ACE_Message_Block::msg_execution_time ( void   )  const

Get execution time associated with the message.

Definition at line 227 of file Message_Block.inl.

References ACE_TRACE, and ACE_Time_Value::zero.

Referenced by ACE_Laxity_Message_Strategy::convert_priority().

00228 {
00229   ACE_TRACE ("ACE_Message_Block::msg_execution_time (void)");
00230 #if defined (ACE_HAS_TIMED_MESSAGE_BLOCKS)
00231   return this->execution_time_;
00232 #else
00233   return ACE_Time_Value::zero;
00234 #endif /* ACE_HAS_TIMED_MESSAGE_BLOCKS */
00235 }

ACE_INLINE void ACE_Message_Block::msg_priority ( unsigned long  priority  ) 

Set priority of the message.

Definition at line 220 of file Message_Block.inl.

References ACE_TRACE, and priority_.

00221 {
00222   ACE_TRACE ("ACE_Message_Block::msg_priority");
00223   this->priority_ = pri;
00224 }

ACE_INLINE unsigned long ACE_Message_Block::msg_priority ( void   )  const

Get priority of the message.

Definition at line 213 of file Message_Block.inl.

References ACE_TRACE, and priority_.

Referenced by ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_i(), ACE_Dynamic_Message_Strategy::priority_status(), and ACE_Dynamic_Message_Queue<>::sublist_enqueue_i().

00214 {
00215   ACE_TRACE ("ACE_Message_Block::msg_priority");
00216   return this->priority_;
00217 }

ACE_INLINE void ACE_Message_Block::msg_type ( ACE_Message_Type  type  ) 

Set type of the message.

Definition at line 182 of file Message_Block.inl.

References ACE_TRACE, data_block(), and ACE_Data_Block::msg_type().

00183 {
00184   ACE_TRACE ("ACE_Message_Block::msg_type");
00185   this->data_block ()->msg_type (t);
00186 }

ACE_INLINE ACE_Message_Block::ACE_Message_Type ACE_Message_Block::msg_type ( void   )  const

Get type of the message.

Definition at line 175 of file Message_Block.inl.

References ACE_TRACE, data_block(), and ACE_Data_Block::msg_type().

Referenced by ACE_Stream_Tail<>::control(), is_data_msg(), ACE_Stream_Tail<>::put(), and ACE_Stream_Head<>::put().

00176 {
00177   ACE_TRACE ("ACE_Message_Block::msg_type");
00178   return this->data_block ()->msg_type ();
00179 }

ACE_INLINE void ACE_Message_Block::next ( ACE_Message_Block  ) 

Set link to next message.

Definition at line 441 of file Message_Block.inl.

References ACE_TRACE, and next_.

00442 {
00443   ACE_TRACE ("ACE_Message_Block::next");
00444   this->next_ = next_msg;
00445 }

ACE_INLINE ACE_Message_Block * ACE_Message_Block::next ( void   )  const

Get link to next message.

Definition at line 448 of file Message_Block.inl.

References ACE_TRACE, and next_.

Referenced by ACE_Message_Queue_Iterator<>::advance(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_deadline_i(), ACE_Dynamic_Message_Queue<>::dequeue_head_i(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_head_i(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_prio_i(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_tail_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_deadline_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_head_i(), ACE_Dynamic_Message_Queue<>::enqueue_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_tail_i(), ACE_Message_Queue< ACE_SYNCH_USE >::flush_i(), ACE::recv_n(), ACE_Dynamic_Message_Queue<>::refresh_late_queue(), ACE_Dynamic_Message_Queue<>::refresh_pending_queue(), ACE_Dynamic_Message_Queue<>::remove_messages(), ACE::send_n(), ACE_Dynamic_Message_Queue<>::sublist_enqueue_i(), ACE_Message_Queue_Ex_N< ACE_MESSAGE_TYPE, >::wrap_with_mbs_i(), and ACE::write_n().

00449 {
00450   ACE_TRACE ("ACE_Message_Block::next");
00451   return this->next_;
00452 }

ACE_Message_Block & ACE_Message_Block::operator= ( const ACE_Message_Block  )  [private]

Definition at line 1252 of file Message_Block.cpp.

References ACE_TRACE.

01253 {
01254   ACE_TRACE ("ACE_Message_Block::operator=");
01255   return *this;
01256 }

ACE_INLINE void ACE_Message_Block::prev ( ACE_Message_Block  ) 

Set link to prev message.

Definition at line 455 of file Message_Block.inl.

References ACE_TRACE, and prev_.

00456 {
00457   ACE_TRACE ("ACE_Message_Block::prev");
00458   this->prev_ = next_msg;
00459 }

ACE_INLINE ACE_Message_Block * ACE_Message_Block::prev ( void   )  const

Get link to prev message.

Definition at line 462 of file Message_Block.inl.

References ACE_TRACE, and prev_.

Referenced by ACE_Message_Queue_Reverse_Iterator<>::advance(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_deadline_i(), ACE_Dynamic_Message_Queue<>::dequeue_head_i(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_head_i(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_prio_i(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_tail_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_deadline_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_head_i(), ACE_Dynamic_Message_Queue<>::enqueue_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_tail_i(), ACE_Dynamic_Message_Queue<>::refresh_late_queue(), ACE_Dynamic_Message_Queue<>::refresh_pending_queue(), ACE_Dynamic_Message_Queue<>::remove_messages(), and ACE_Dynamic_Message_Queue<>::sublist_enqueue_i().

00463 {
00464   ACE_TRACE ("ACE_Message_Block::prev");
00465   return this->prev_;
00466 }

ACE_INLINE void ACE_Message_Block::rd_ptr ( size_t  n  ) 

Set the read pointer ahead n bytes.

Definition at line 355 of file Message_Block.inl.

References ACE_TRACE, and rd_ptr_.

00356 {
00357   ACE_TRACE ("ACE_Message_Block::rd_ptr");
00358   this->rd_ptr_ += n;
00359 }

ACE_INLINE void ACE_Message_Block::rd_ptr ( char *  ptr  ) 

Set the read pointer to ptr.

Definition at line 348 of file Message_Block.inl.

References ACE_TRACE, base(), and rd_ptr_.

00349 {
00350   ACE_TRACE ("ACE_Message_Block::rd_ptr");
00351   this->rd_ptr_ = new_ptr - this->base ();
00352 }

ACE_INLINE char * ACE_Message_Block::rd_ptr ( void   )  const

Get the read pointer.

Definition at line 303 of file Message_Block.inl.

References ACE_TRACE, base(), and rd_ptr_.

Referenced by ACE_InputCDR::ACE_InputCDR(), ACE_Message_Block(), ACE_InputCDR::adjust(), ACE_InputCDR::align_read_ptr(), ACE_OutputCDR::buffer(), ACE_Stream_Tail<>::canonical_flush(), ACE_Stream_Head<>::canonical_flush(), clone(), ACE_InputCDR::clone_from(), ACE_CDR::consolidate(), ACE_Stream_Tail<>::control(), ACE_Stream_Head<>::control(), ACE_Stream<>::control(), crunch(), data_block(), duplicate(), ACE_InputCDR::exchange_data_blocks(), ACE_OutputCDR::find(), ACE_CDR::grow(), ACE_OutputCDR::grow_and_adjust(), ACE_Log_Msg_IPC::log(), ACE_CDR::mb_align(), ACE_InputCDR::operator=(), ACE_InputCDR::rd_ptr(), ACE_InputCDR::read_1(), ACE::recv_n(), replace_data_block(), ACE::send_n(), ACE_InputCDR::steal_from(), ACE::write_n(), and ACE_OutputCDR::write_octet_array_mb().

00304 {
00305   ACE_TRACE ("ACE_Message_Block::rd_ptr");
00306   return this->base () + this->rd_ptr_;
00307 }

ACE_INLINE int ACE_Message_Block::reference_count ( void   )  const

Get the current reference count.

Definition at line 46 of file Message_Block.inl.

References data_block(), and ACE_Data_Block::reference_count().

00047 {
00048   return data_block () ? data_block ()->reference_count () : 0;
00049 }

ACE_Message_Block * ACE_Message_Block::release ( ACE_Message_Block mb  )  [static]

This behaves like the non-static method <release>, except that it checks if mb is 0. This is similar to <CORBA::release>, which is useful if you want to eliminate lots of checks for NULL pointers before calling <release> on them. Returns mb.

Definition at line 962 of file Message_Block.cpp.

References ACE_TRACE, and release().

00963 {
00964   ACE_TRACE ("ACE_Message_Block::release");
00965 
00966   if (mb != 0)
00967     return mb->release ();
00968   else
00969     return 0;
00970 }

ACE_Message_Block * ACE_Message_Block::release ( void   )  [virtual]

Decrease the shared ACE_Data_Block's reference count by 1. If the ACE_Data_Block's reference count goes to 0, it is deleted. In all cases, this ACE_Message_Block is deleted - it must have come from the heap, or there will be trouble.

release() is designed to release the continuation chain; the destructor is not. If we make the destructor release the continuation chain by calling release() or delete on the message blocks in the continuation chain, the following code will not work since the message block in the continuation chain is not off the heap:

ACE_Message_Block mb1 (1024); ACE_Message_Block mb2 (1024);

mb1.cont (&mb2);

And hence, call release() on a dynamically allocated message block. This will release all the message blocks in the continuation chain. If you call delete or let the message block fall off the stack, cleanup of the message blocks in the continuation chain becomes the responsibility of the user.

Return values:
0,always,and the object this method was invoked on is no longer valid.

Definition at line 855 of file Message_Block.cpp.

References ACE_DES_FREE, ACE_GUARD_RETURN, ACE_TRACE, data_block(), ACE_Data_Block::data_block_allocator(), ACE_Allocator::free(), and release_i().

Referenced by ACE_Stream_Tail<>::canonical_flush(), clone(), ACE_OutputCDR::consolidate(), ACE_Stream<>::control(), ACE_Activation_Queue::dequeue(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::dequeue_deadline(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::dequeue_head(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::dequeue_prio(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::dequeue_tail(), duplicate(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::enqueue_deadline(), ACE_Message_Queue_Ex_N< ACE_MESSAGE_TYPE, >::enqueue_head(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::enqueue_head(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::enqueue_prio(), ACE_Message_Queue_Ex_N< ACE_MESSAGE_TYPE, >::enqueue_tail(), ACE_Message_Queue_Ex< ACE_MESSAGE_TYPE, ACE_SYNCH_USE >::enqueue_tail(), ACE_Message_Queue< ACE_SYNCH_USE >::flush_i(), release(), ACE_OutputCDR::reset(), ACE_Message_Queue_Ex_N< ACE_MESSAGE_TYPE, >::wrap_with_mbs_i(), ACE_OutputCDR::write_octet_array_mb(), and ACE_OutputCDR::~ACE_OutputCDR().

00856 {
00857   ACE_TRACE ("ACE_Message_Block::release");
00858 
00859   // We want to hold the data block in a temporary variable because we
00860   // invoked "delete this;" at some point, so using this->data_block_
00861   // could be a bad idea.
00862   ACE_Data_Block *tmp = this->data_block ();
00863 
00864   // This flag is set to 1 when we have to destroy the data_block
00865   int destroy_dblock = 0;
00866 
00867   ACE_Lock *lock = 0;
00868 
00869   // Do we have a valid data block
00870   if (this->data_block ())
00871     {
00872       // Grab the lock that belongs to my data block
00873       lock = this->data_block ()->locking_strategy ();
00874 
00875       // if we have a lock
00876       if (lock != 0)
00877         {
00878           // One guard for all
00879           ACE_GUARD_RETURN (ACE_Lock, ace_mon, *lock, 0);
00880 
00881           // Call non-guarded release with <lock>
00882           destroy_dblock = this->release_i (lock);
00883         }
00884       // This is the case when we have a valid data block but no lock
00885       else
00886         // Call non-guarded release with no lock
00887         destroy_dblock = this->release_i (0);
00888     }
00889   else
00890     // This is the case when we don't even have a valid data block
00891     destroy_dblock = this->release_i (0);
00892 
00893   if (destroy_dblock != 0)
00894     {
00895       ACE_Allocator *allocator = tmp->data_block_allocator ();
00896       ACE_DES_FREE (tmp,
00897                     allocator->free,
00898                     ACE_Data_Block);
00899     }
00900 
00901   return 0;
00902 }

int ACE_Message_Block::release_i ( ACE_Lock lock  )  [protected]

Internal release implementation Returns 1 if the data block has to be destroyed.

Definition at line 905 of file Message_Block.cpp.

References ACE_BIT_DISABLED, ACE_DES_FREE, ACE_TRACE, cont_, data_block(), data_block_, ACE_Data_Block::data_block_allocator(), DONT_DELETE, ACE_Allocator::free(), message_block_allocator_, and release_i().

Referenced by release(), and release_i().

00906 {
00907   ACE_TRACE ("ACE_Message_Block::release_i");
00908 
00909   // Free up all the continuation messages.
00910   if (this->cont_)
00911     {
00912       ACE_Message_Block *mb = this->cont_;
00913       ACE_Message_Block *tmp = 0;
00914 
00915       do
00916         {
00917           tmp = mb;
00918           mb = mb->cont_;
00919           tmp->cont_ = 0;
00920 
00921           ACE_Data_Block *db = tmp->data_block ();
00922           if (tmp->release_i (lock) != 0)
00923             {
00924               ACE_Allocator *allocator = db->data_block_allocator ();
00925               ACE_DES_FREE (db,
00926                             allocator->free,
00927                             ACE_Data_Block);
00928             }
00929         }
00930       while (mb);
00931 
00932       this->cont_ = 0;
00933     }
00934 
00935   int result = 0;
00936 
00937   if (ACE_BIT_DISABLED (this->flags_,
00938                         ACE_Message_Block::DONT_DELETE) &&
00939       this->data_block ())
00940     {
00941       if (this->data_block ()->release_no_delete (lock) == 0)
00942         result = 1;
00943       this->data_block_ = 0;
00944     }
00945 
00946   // We will now commit suicide: this object *must* have come from the
00947   // allocator given.
00948   if (this->message_block_allocator_ == 0)
00949     delete this;
00950   else
00951     {
00952       ACE_Allocator *allocator = this->message_block_allocator_;
00953       ACE_DES_FREE (this,
00954                     allocator->free,
00955                     ACE_Message_Block);
00956     }
00957 
00958   return result;
00959 }

ACE_INLINE ACE_Data_Block * ACE_Message_Block::replace_data_block ( ACE_Data_Block  ) 

Set a new data block pointer. A pointer to the original ACE_Data_Block is returned, and not released (as it is with <data_block>).

Definition at line 391 of file Message_Block.inl.

References ACE_TRACE, data_block_, rd_ptr(), and wr_ptr().

Referenced by ACE_InputCDR::ACE_InputCDR(), ACE_InputCDR::clone_from(), and ACE_InputCDR::exchange_data_blocks().

00392 {
00393   ACE_TRACE ("ACE_Message_Block::replace_data_block");
00394   ACE_Data_Block *old = this->data_block_;
00395   this->data_block_ = db;
00396 
00397   if (db != 0)
00398     {
00399       // Set the read and write pointers in the <Message_Block> to point
00400       // to the buffer in the <ACE_Data_Block>.
00401       this->rd_ptr (this->data_block ()->base ());
00402       this->wr_ptr (this->data_block ()->base ());
00403     }
00404 
00405   return old;
00406 }

ACE_INLINE void ACE_Message_Block::reset ( void   ) 

Resets the Message Block data to contain nothing, i.e., sets the read and write pointers to align with the base.

Definition at line 376 of file Message_Block.inl.

References ACE_TRACE, rd_ptr_, and wr_ptr_.

Referenced by ACE_InputCDR::clone_from(), and ACE_InputCDR::exchange_data_blocks().

00377 {
00378   ACE_TRACE ("ACE_Message_Block::reset");
00379   this->rd_ptr_ = 0;
00380   this->wr_ptr_ = 0;
00381 }

ACE_INLINE void ACE_Message_Block::reset_allocators ( ACE_Allocator allocator_strategy = 0,
ACE_Allocator data_block_allocator = 0,
ACE_Allocator message_block_allocator = 0 
)

This method resets the allocators in all the message blocks in the chain.

Definition at line 423 of file Message_Block.inl.

References ACE_Data_Block::allocator_strategy_, data_block_, ACE_Data_Block::data_block_allocator_, and message_block_allocator_.

00426 {
00427   this->data_block_->allocator_strategy_ =
00428     allocator_strategy;
00429   this->data_block_->data_block_allocator_ =
00430     data_block_allocator;
00431   this->message_block_allocator_ =
00432     message_block_allocator;
00433 
00434   if (this->cont () != 0)
00435     this->cont ()->reset_allocators (allocator_strategy,
00436                                      data_block_allocator,
00437                                      message_block_allocator);
00438 }

ACE_INLINE ACE_Message_Block::Message_Flags ACE_Message_Block::self_flags ( void   )  const

Get the current message flags.

Definition at line 33 of file Message_Block.inl.

References ACE_TRACE, and flags_.

Referenced by ACE_InputCDR::exchange_data_blocks().

00034 {
00035   ACE_TRACE ("ACE_Message_Block::self_flags");
00036   return this->flags_;
00037 }

ACE_INLINE ACE_Message_Block::Message_Flags ACE_Message_Block::set_flags ( Message_Flags  more_flags  ) 

Bitwise-or the more_flags into the existing message flags and return the new value.

Definition at line 105 of file Message_Block.inl.

References ACE_TRACE, data_block(), and ACE_Data_Block::set_flags().

00106 {
00107   ACE_TRACE ("ACE_Message_Block::set_flags");
00108   return this->data_block ()->set_flags (more_flags);
00109 }

ACE_INLINE ACE_Message_Block::Message_Flags ACE_Message_Block::set_self_flags ( ACE_Message_Block::Message_Flags  more_flags  ) 

Bitwise-or the more_flags into the existing message flags and return the new value.

Definition at line 15 of file Message_Block.inl.

References ACE_SET_BITS, and ACE_TRACE.

Referenced by ACE_InputCDR::exchange_data_blocks().

00016 {
00017   ACE_TRACE ("ACE_Message_Block::set_self_flags");
00018   // Later we might mask more_glags so that user can't change internal
00019   // ones: more_flags &= ~(USER_FLAGS -1).
00020   return ACE_SET_BITS (this->flags_, more_flags);
00021 }

int ACE_Message_Block::size ( size_t  length  ) 

Set the number of bytes in the top-level <Message_Block>, reallocating space if necessary. However, the <rd_ptr_> and <wr_ptr_> remain at the original offsets into the buffer, even if it is reallocated. Returns 0 if successful, else -1.

Definition at line 246 of file Message_Block.cpp.

References ACE_TRACE.

00247 {
00248   ACE_TRACE ("ACE_Message_Block::size");
00249 
00250   // Resize the underlying <ACE_Data_Block>.
00251   if (this->data_block ()->size (length) == -1)
00252     return -1;
00253 
00254   return 0;
00255 }

ACE_INLINE size_t ACE_Message_Block::size ( void   )  const

Get the number of bytes in the top-level <Message_Block> (i.e., does not consider the bytes in chained <Message_Block>s).

Definition at line 147 of file Message_Block.inl.

References ACE_TRACE, data_block(), and ACE_Data_Block::size().

Referenced by ACE_CDR::consolidate(), ACE_InputCDR::exchange_data_blocks(), ACE_OutputCDR::grow_and_adjust(), init_i(), total_capacity(), and total_size().

00148 {
00149   ACE_TRACE ("ACE_Message_Block::size");
00150   return this->data_block ()->size ();
00151 }

ACE_INLINE size_t ACE_Message_Block::space ( void   )  const

Get the number of bytes available after the <wr_ptr_> in the top-level <Message_Block>.

Definition at line 384 of file Message_Block.inl.

References ACE_TRACE, mark(), and wr_ptr().

Referenced by ACE_InputCDR::ACE_InputCDR(), and copy().

00385 {
00386   ACE_TRACE ("ACE_Message_Block::space");
00387   return this->mark () - this->wr_ptr ();
00388 }

size_t ACE_Message_Block::total_capacity ( void   )  const

Get the number of allocated bytes in all <Message_Block>, including chained <Message_Block>s.

Definition at line 301 of file Message_Block.cpp.

References ACE_TRACE, and size().

00302 {
00303   ACE_TRACE ("ACE_Message_Block::total_capacity");
00304 
00305   size_t size = 0;
00306 
00307   for (const ACE_Message_Block *i = this;
00308        i != 0;
00309        i = i->cont ())
00310     size += i->capacity ();
00311 
00312   return size;
00313 }

size_t ACE_Message_Block::total_length ( void   )  const

Get the length of the <Message_Block>s, including chained <Message_Block>s.

Definition at line 287 of file Message_Block.cpp.

References ACE_TRACE, and length().

00288 {
00289   ACE_TRACE ("ACE_Message_Block::total_length");
00290 
00291   size_t length = 0;
00292   for (const ACE_Message_Block *i = this;
00293        i != 0;
00294        i = i->cont ())
00295     length += i->length ();
00296 
00297   return length;
00298 }

size_t ACE_Message_Block::total_size ( void   )  const

Get the total number of bytes in all <Message_Block>s, including chained <Message_Block>s.

Definition at line 273 of file Message_Block.cpp.

References ACE_TRACE, and size().

Referenced by ACE_Buffered_Svc_Handler<, >::put().

00274 {
00275   ACE_TRACE ("ACE_Message_Block::total_size");
00276 
00277   size_t size = 0;
00278   for (const ACE_Message_Block *i = this;
00279        i != 0;
00280        i = i->cont ())
00281     size += i->size ();
00282 
00283   return size;
00284 }

void ACE_Message_Block::total_size_and_length ( size_t &  mb_size,
size_t &  mb_length 
) const

Get the total number of bytes and total length in all <Message_Block>s, including chained <Message_Block>s.

Definition at line 258 of file Message_Block.cpp.

References ACE_TRACE.

Referenced by ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_deadline_i(), ACE_Dynamic_Message_Queue<>::dequeue_head_i(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_head_i(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_prio_i(), ACE_Message_Queue< ACE_SYNCH_USE >::dequeue_tail_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_deadline_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_head_i(), ACE_Dynamic_Message_Queue<>::enqueue_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_i(), ACE_Message_Queue< ACE_SYNCH_USE >::enqueue_tail_i(), ACE_Message_Queue< ACE_SYNCH_USE >::flush_i(), and ACE_Dynamic_Message_Queue<>::remove_messages().

00260 {
00261   ACE_TRACE ("ACE_Message_Block::total_size_and_length");
00262 
00263   for (const ACE_Message_Block *i = this;
00264        i != 0;
00265        i = i->cont ())
00266     {
00267       mb_size += i->size ();
00268       mb_length += i->length ();
00269     }
00270 }

ACE_INLINE void ACE_Message_Block::wr_ptr ( size_t  n  ) 

Set the write pointer ahead n bytes. This is used to compute the <length> of a message.

Definition at line 369 of file Message_Block.inl.

References ACE_TRACE, and wr_ptr_.

00370 {
00371   ACE_TRACE ("ACE_Message_Block::wr_ptr");
00372   this->wr_ptr_ += n;
00373 }

ACE_INLINE void ACE_Message_Block::wr_ptr ( char *  ptr  ) 

Set the write pointer to ptr.

Definition at line 310 of file Message_Block.inl.

References ACE_TRACE, base(), and wr_ptr_.

00311 {
00312   ACE_TRACE ("ACE_Message_Block::wr_ptr");
00313   this->wr_ptr_ = new_ptr - this->base ();
00314 }

ACE_INLINE char * ACE_Message_Block::wr_ptr ( void   )  const

Get the write pointer.

Definition at line 362 of file Message_Block.inl.

References ACE_TRACE, base(), and wr_ptr_.

Referenced by ACE_InputCDR::ACE_InputCDR(), ACE_Message_Block(), ACE_OutputCDR::adjust(), clone(), ACE_InputCDR::clone_from(), ACE_CDR::consolidate(), copy(), crunch(), data_block(), duplicate(), ACE_InputCDR::exchange_data_blocks(), ACE_InputCDR::grow(), ACE_CDR::grow(), ACE_OutputCDR::grow_and_adjust(), ACE_CDR::mb_align(), ACE_InputCDR::operator=(), replace_data_block(), space(), ACE_InputCDR::steal_from(), ACE_InputCDR::wr_ptr(), and ACE_OutputCDR::write_octet_array_mb().

00363 {
00364   ACE_TRACE ("ACE_Message_Block::wr_ptr");
00365   return this->base () + this->wr_ptr_;
00366 }


Friends And Related Function Documentation

friend class ACE_Data_Block [friend]

Definition at line 62 of file Message_Block.h.


Member Data Documentation

ACE_Message_Block::ACE_ALLOC_HOOK_DECLARE

Declare the dynamic allocation hooks.

Definition at line 583 of file Message_Block.h.

ACE_Message_Block* ACE_Message_Block::cont_ [protected]

Pointer to next message block in the chain.

Definition at line 640 of file Message_Block.h.

Referenced by clone(), cont(), duplicate(), init_i(), and release_i().

ACE_Data_Block* ACE_Message_Block::data_block_ [protected]

Pointer to the reference counted data structure that contains the actual memory buffer.

Definition at line 653 of file Message_Block.h.

Referenced by access_allocators(), data_block(), init_i(), release_i(), replace_data_block(), and reset_allocators().

ACE_Message_Block::Message_Flags ACE_Message_Block::flags_ [protected]

Misc flags (e.g., DONT_DELETE and USER_FLAGS).

Definition at line 649 of file Message_Block.h.

Referenced by ACE_Message_Block(), and self_flags().

ACE_Allocator* ACE_Message_Block::message_block_allocator_ [protected]

The allocator used to destroy ourselves when release is called and create new message blocks on duplicate.

Definition at line 657 of file Message_Block.h.

Referenced by access_allocators(), ACE_Message_Block(), clone(), duplicate(), init_i(), release_i(), and reset_allocators().

ACE_Message_Block* ACE_Message_Block::next_ [protected]

Pointer to next message in the list.

Definition at line 643 of file Message_Block.h.

Referenced by init_i(), next(), and ~ACE_Message_Block().

ACE_Message_Block* ACE_Message_Block::prev_ [protected]

Pointer to previous message in the list.

Definition at line 646 of file Message_Block.h.

Referenced by init_i(), prev(), and ~ACE_Message_Block().

unsigned long ACE_Message_Block::priority_ [protected]

Priority of message.

Definition at line 628 of file Message_Block.h.

Referenced by init_i(), and msg_priority().

size_t ACE_Message_Block::rd_ptr_ [protected]

Pointer to beginning of next read.

Definition at line 622 of file Message_Block.h.

Referenced by base(), init_i(), length(), rd_ptr(), and reset().

size_t ACE_Message_Block::wr_ptr_ [protected]

Pointer to beginning of next write.

Definition at line 625 of file Message_Block.h.

Referenced by ACE_Message_Block(), base(), init_i(), length(), reset(), and wr_ptr().


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:35:20 2010 for ACE by  doxygen 1.4.7