buffer_manager Class Reference

A buffer_manager maintains a group of buffers. More...

#include <buffer_manager.h>

Collaboration diagram for buffer_manager:

Collaboration graph
[legend]
List of all members.

Public Types

enum  kind_to_find { EITHER, WHOLE, NON_WHOLE }

Public Member Functions

 buffer_manager (int total_memory, int connection_memory)
 constructs a buffer_manager with the given limits.
virtual ~buffer_manager ()
 IMPLEMENT_CLASS_NAME ("buffer_manager")
int buffers () const
 the total number of buffers we are managing.
int total_memory_allowed () const
 returns the size we were configured to allow for buffer storage.
int total_allocated () const
 returns the amount of memory currently consumed by buffers.
int space_left () const
 the amount of memory we can still use for allocating buffers.
outcome add_buffer (buffer_base *to_add)
 adds a buffer to the buffer list.
outcome extract (buffer_key &key, byte_array &to_fill, byte_array &attachment, int offset=0, bool remove_buffer=true)
 finds any buffer matching "key".
buffer_basedisengage (buffer_key &key)
 retrieves the buffer specified by the key or NIL.
void show_buffers (istring &dump, int indentation=0)
 prints out information about the active buffers to the string "dump".
buffer_baselock_buffer (int &start, const buffer_key &key)
 this finds a buffer with "key" as its key.
void unlock_buffer (buffer_base *to_unlock)
 this must be called for each successful lock_buffer() call.
bool zap (buffer_id to_whack)
 simplest form of zap; removes the buffer with id "to_whack" if found.
bool zap_match (int &start, const buffer_key &key)
 the first matching buffer encountered is deleted.
bool zap_all_matches (const buffer_key &key)
 all buffers matching the "key" are deleted.
void zap_all ()
 clears out absolutely all buffers.
bool zap_expired (istring &text_form, buffer_key &dead_key, int &start, int age, kind_to_find which)
 finds any buffers at the "start" index or after that have expired.

Detailed Description

A buffer_manager maintains a group of buffers.

It provides support for adding new buffers, finding existing buffers and removing unused buffers. It also allows the "payload" of a buffer to be retrieved.

Definition at line 31 of file buffer_manager.h.


Member Enumeration Documentation

enum buffer_manager::kind_to_find

Enumerator:
EITHER 
WHOLE 
NON_WHOLE 

Definition at line 112 of file buffer_manager.h.


Constructor & Destructor Documentation

buffer_manager::buffer_manager ( int  total_memory,
int  connection_memory 
)

constructs a buffer_manager with the given limits.

there will be a limit of "total_memory" on the total size of all buffers stored here. no overall limit is enforced if the "total_memory" is zero. the "connection_memory" is the amount of memory allowed to each connection individually; this also is not checked if passed as zero.

Definition at line 40 of file buffer_manager.cpp.

buffer_manager::~buffer_manager (  )  [virtual]

Definition at line 46 of file buffer_manager.cpp.

References WHACK().


Member Function Documentation

buffer_manager::IMPLEMENT_CLASS_NAME ( "buffer_manager"   ) 

int buffer_manager::buffers (  )  const

the total number of buffers we are managing.

Definition at line 53 of file buffer_manager.cpp.

References LOCKIT.

Referenced by extract().

int buffer_manager::total_memory_allowed (  )  const

returns the size we were configured to allow for buffer storage.

Definition at line 59 of file buffer_manager.cpp.

References LOCKIT, and memory_limiter::overall_limit().

int buffer_manager::total_allocated (  )  const

returns the amount of memory currently consumed by buffers.

Definition at line 65 of file buffer_manager.cpp.

References LOCKIT, and memory_limiter::overall_usage().

int buffer_manager::space_left (  )  const [inline]

the amount of memory we can still use for allocating buffers.

Definition at line 52 of file buffer_manager.h.

outcome buffer_manager::add_buffer ( buffer_base to_add  ) 

adds a buffer to the buffer list.

once this buffer is added, the buffer_manager owns it and the buffer should not be used externally any more (unless given out by the buffer_manager's lock_buffer() method). NOTE: buffer ids and connection ids must be unique; they are the two required members of the buffer_key in "to_add". buffer ids must be unique within a particular owner; otherwise the connection's other side is generating buffers erroneously. if the buffer appears to match an existing buffer, then IN_USE is returned and the request is ignored. in that case, the buffer "to_add" is whacked before returning.

Definition at line 164 of file buffer_manager.cpp.

References buffer_base::BAD_INPUT, buffer_key::buff_id, buffer_key::connection, FUNCDEF, buffer_base::IN_USE, buffer_base::key(), LOCKIT, LOG, buffer_base::NO_SPACE, buffer_base::OKAY, unique_id< uniquifier >::raw_id(), istring::SPRINTF, and WHACK().

outcome buffer_manager::extract ( buffer_key key,
byte_array to_fill,
byte_array attachment,
int  offset = 0,
bool  remove_buffer = true 
)

finds any buffer matching "key".

stores the contents of one ready buffer into "to_fill". if none are ready, INCOMPLETE is returned. if "remove_buffer" is true, then the returned buffer is zapped. the "attachment" holds any information that was attached to the buffer. if a buffer was successfully found, the key is altered to reflect the actual key of the buffer being returned.

Definition at line 357 of file buffer_manager.cpp.

References buffer_key::buff_id, buffers(), buffer_base::dump(), FUNCDEF, buffer_base::get_attachment(), buffer_base::INCOMPLETE, buffer_base::key(), LOCKIT, LOG, buffer_base::OKAY, unique_id< uniquifier >::raw_id(), istring::SPRINTF, buffer_base::whole(), and zap().

buffer_base * buffer_manager::disengage ( buffer_key key  ) 

retrieves the buffer specified by the key or NIL.

after this call, that buffer is no longer listed in the buffer manager. the caller must delete the pointer.

Definition at line 344 of file buffer_manager.cpp.

References FUNCDEF, LOCKIT, negative(), and NIL.

void buffer_manager::show_buffers ( istring dump,
int  indentation = 0 
)

prints out information about the active buffers to the string "dump".

the output string is appended to.

Definition at line 325 of file buffer_manager.cpp.

References string_manipulation::indentation(), LOCKIT, log_base::platform_ending(), and memory_limiter::text_form().

buffer_base * buffer_manager::lock_buffer ( int &  start,
const buffer_key key 
)

this finds a buffer with "key" as its key.

if the "buffer_id" field of the key is set, then only that buffer will match. otherwise, if the message id is zero, any buffer with the same connection id will be matched. the search begins at "start" in the list. if a match is found, then "start" is set to just after the position of the match. NOTE: you MUST unlock the buffer after this call. also note that you can never lock more than one buffer at a time.

Definition at line 204 of file buffer_manager.cpp.

References mutex_base::lock(), NIL, and mutex_base::unlock().

void buffer_manager::unlock_buffer ( buffer_base to_unlock  ) 

this must be called for each successful lock_buffer() call.

Definition at line 216 of file buffer_manager.cpp.

References NIL, and mutex_base::unlock().

bool buffer_manager::zap ( buffer_id  to_whack  ) 

simplest form of zap; removes the buffer with id "to_whack" if found.

Definition at line 232 of file buffer_manager.cpp.

References FUNCDEF, LOCKIT, negative(), and WHACK().

Referenced by extract().

bool buffer_manager::zap_match ( int &  start,
const buffer_key key 
)

the first matching buffer encountered is deleted.

this uses the same search method as lock_buffer() (above). the position where it was found plus one is stored in start.

Definition at line 252 of file buffer_manager.cpp.

References FUNCDEF, LOCKIT, negative(), and WHACK().

bool buffer_manager::zap_all_matches ( const buffer_key key  ) 

all buffers matching the "key" are deleted.

Definition at line 268 of file buffer_manager.cpp.

References FUNCDEF, LOCKIT, negative(), non_negative(), and WHACK().

void buffer_manager::zap_all (  ) 

clears out absolutely all buffers.

Definition at line 289 of file buffer_manager.cpp.

References FUNCDEF, LOCKIT, and memory_limiter::reset().

bool buffer_manager::zap_expired ( istring text_form,
buffer_key dead_key,
int &  start,
int  age,
kind_to_find  which 
)

finds any buffers at the "start" index or after that have expired.

the buffers that have not been modified for at least "age" milliseconds get dropped. the "which" value determines whether whole buffers, non-whole buffers or both are returned. if a buffer meets the criteria, then it is removed, and "text_form" is set to its info while "dead_key" is set to its key.

Definition at line 297 of file buffer_manager.cpp.

References EITHER, FUNCDEF, LOCKIT, NON_WHOLE, text_form(), and WHOLE.


The documentation for this class was generated from the following files:
Generated on Fri Oct 10 04:30:04 2008 for HOOPLE Libraries by  doxygen 1.5.1