#include <Message_Block.h>
Collaboration diagram for ACE_Message_Block:
Public Types | |
typedef int | ACE_Message_Type |
typedef unsigned long | Message_Flags |
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_Value & | msg_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_Value & | msg_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_Block * | clone (Message_Flags mask=0) const |
virtual ACE_Message_Block * | duplicate (void) const |
Return a "shallow" copy that increments our reference count by 1. | |
virtual ACE_Message_Block * | release (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_Block * | data_block (void) const |
void | data_block (ACE_Data_Block *) |
ACE_Data_Block * | replace_data_block (ACE_Data_Block *) |
ACE_Message_Block * | cont (void) const |
Get the continuation field. | |
void | cont (ACE_Message_Block *) |
Set the continuation field. | |
ACE_Message_Block * | next (void) const |
Get link to next message. | |
void | next (ACE_Message_Block *) |
Set link to next message. | |
ACE_Message_Block * | prev (void) const |
Get link to prev message. | |
void | prev (ACE_Message_Block *) |
Set link to prev message. | |
ACE_Lock * | locking_strategy (void) |
Get the locking strategy. | |
ACE_Lock * | locking_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 | |
ACE_Message_Block * | duplicate (const ACE_Message_Block *mb) |
ACE_Message_Block * | release (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_Block * | cont_ |
Pointer to next message block in the chain. | |
ACE_Message_Block * | next_ |
Pointer to next message in the list. | |
ACE_Message_Block * | prev_ |
Pointer to previous message in the list. | |
ACE_Message_Block::Message_Flags | flags_ |
Misc flags (e.g., DONT_DELETE and USER_FLAGS). | |
ACE_Data_Block * | data_block_ |
ACE_Allocator * | message_block_allocator_ |
Private Member Functions | |
ACE_Message_Block & | operator= (const ACE_Message_Block &) |
ACE_Message_Block (const ACE_Message_Block &) | |
Friends | |
class | ACE_Data_Block |
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:
|
|
|
|
|
|
|
|
Create an empty message.
|
|
Create an ACE_Message_Block that owns the specified ACE_Data_Block without copying it. If the flags is set to |
|
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 |
|
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
|
|
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>. |
|
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. |
|
Perform the actual initialization.
|
|
|
|
This method returns the allocators only from the first message block in the chain.
|
|
Set message data (doesn't reallocate).
|
|
Get message data.
|
|
Get the number of allocated bytes in the top-level <message_block>.
|
|
Return an exact "deep copy" of the message, i.e., create fresh new copies of all the Data_Blocks and continuations. |
|
Clear the message flag bits specified in <less_flags> and return the new value. |
|
Clear the message flag bits specified in <less_flags> and return the new value. |
|
Set the continuation field.
|
|
Get the continuation field.
|
|
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.
|
|
Copies data into this ACE_Message_Block. Data is copied into the block starting at the current write pointer.
|
|
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. Returns -1 and does nothing if the <rd_ptr> is > <wr_ptr>, else 0 on success. |
|
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. |
|
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. |
|
Dump the state of an object.
|
|
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. |
|
Return a "shallow" copy that increments our reference count by 1.
|
|
Return a pointer to 1 past the end of the allocated data in a message.
|
|
Get the current message flags.
|
|
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> 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. |
|
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. |
|
Perform the actual initialization.
|
|
Find out what type of message this is.
|
|
Set the length of the message.
|
|
Get the length of the message.
|
|
Set a new locking strategy and return the hold one.
|
|
Get the locking strategy.
|
|
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(). |
|
Find out what class of message this is (there are two classes, <normal> messages and <high-priority> messages). |
|
Set absolute time of deadline associated with the message.
|
|
Get absolute time of deadline associated with the message.
|
|
Set execution time associated with the message.
|
|
Get execution time associated with the message.
|
|
Set priority of the message.
|
|
Get priority of the message.
|
|
Set type of the message.
|
|
Get type of the message.
|
|
Set link to next message.
|
|
Get link to next message.
|
|
|
|
Set link to prev message.
|
|
Get link to prev message.
|
|
Set the read pointer ahead <n> bytes.
|
|
Set the read pointer to <ptr>.
|
|
Get the read pointer.
|
|
Get the current reference count.
|
|
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>. |
|
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.
|
|
Internal release implementation Returns 1 if the data block has to be destroyed. |
|
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>). |
|
Resets the Message Block data to contain nothing, i.e., sets the read and write pointers to align with the base. |
|
This method resets the allocators in all the message blocks in the chain. |
|
Get the current message flags.
|
|
Bitwise-or the <more_flags> into the existing message flags and return the new value. |
|
Bitwise-or the <more_flags> into the existing message flags and return the new value. |
|
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. |
|
Get the number of bytes in the top-level <message_block> (i.e., does not consider the bytes in chained <message_block>s). |
|
Get the number of bytes available after the <wr_ptr_> in the top-level <message_block>. |
|
Get the number of allocated bytes in all <message_block>, including chained <message_block>s. |
|
Get the length of the <message_block>s, including chained <message_block>s. |
|
Get the total number of bytes in all <message_block>s, including chained <message_block>s. |
|
Get the total number of bytes and total length in all <message_block>s, including chained <message_block>s. |
|
Set the write pointer ahead <n> bytes. This is used to compute the <length> of a message. |
|
Set the write pointer to <ptr>.
|
|
Get the write pointer.
|
|
|
|
Declare the dynamic allocation hooks.
|
|
Pointer to next message block in the chain.
|
|
Pointer to the reference counted data structure that contains the actual memory buffer. |
|
Misc flags (e.g., DONT_DELETE and USER_FLAGS).
|
|
The allocator used to destroy ourselves when release is called and create new message blocks on duplicate. |
|
Pointer to next message in the list.
|
|
Pointer to previous message in the list.
|
|
Priority of message.
|
|
Pointer to beginning of next read.
|
|
Pointer to beginning of next write.
|