code::LinearBuffer Class Reference

Inheritance diagram for code::LinearBuffer:

code::LBActionSource List of all members.

Detailed Description

LinearBuffer.h implements a class LinearBuffer that is a narrow interface to the ORPG lb library.

Objects of this class have to be specifically opened after creation. They are destroyed when they go out of scope. To prevent such destruction, allocate them using "new" and destroy them using "delete". LinearBuffers allow you to transfer files and messages across a LAN and are especially useful when creating distributed processes. LinearBuffer supports threading, mostly by setting mutex locks to ensure data integrity. Open, close, read and write are all thread-safe. OpenW and functions that depend on the file pointer position are not. Trying to read/write a closed LB will provide an error. To obtain the meaning of the various error codes, check the file lb.h .

The name "yak:.OPUP/AT.log" corresponds to a remote LB stored on yak in the user's home directory i.e. to ~/.OPUP/AT.log.  The name "AT.log" corresponds the LB stored in the current directory on the current machine. The LinearBuffer class presents an unified interface to both local and remote LBs.

Author:
Lakshman
Version:
Id
code_LinearBuffer.h,v 1.17 2009/06/02 20:17:38 lakshman Exp


Public Member Functions

 LinearBuffer ()
 A LinearBuffer when constructed is an empty shell.
virtual ~LinearBuffer ()
 Will close the LB if needed.
int open (const URL &lb_url)
 open() opens LB for reading.
int openW (const URL &lb_url)
 Opens LB for writing if the LB exists.
int openW (const URL &lb_url, int numMessages, int avgSize)
 A new LB is created if it doesn't already exist; if an LB of the same name already exists, the existing data is not clobbered.
int openOrCreate (const URL &lb_url)
 Recommended form of openW() for applications to call.
void close ()
 close() closes LB if open.
int read (char *msg, int msgLength, LB_id_t msgId=LB_NEXT, int errorToSupress=0)
 Reads message of specified id and returns the length of read-in message if successful.
int read (std::vector< char > &msg, LB_id_t msgId=LB_NEXT, int errorToSupress=0)
 Identical to read(char*,int,LB_id_t,int) except the client doesn't need to know the size of the message beforehand.
int rewind ()
 Makes LB_NEXT point to the first message in the LB.
int latest ()
 Makes LB_NEXT point to the last message in the LB.
int moveLBptr (int offset)
 Moves the LB pointer n messages from the current.
int seek (LB_id_t id, int offset)
 Move the LB pointer to the specified message in the LB.
void write (const void *buffer, int bufferLength, int *setme_error=0)
 Writes the buffer out to the LB as the latest message.
void write (int messageId, const void *buffer, int bufferLength, int *setme_error=0)
 Same as write() except that the buffer overwrites the message messageId.
LB_id_t msgId ()
 msgId() returns the message id of last read/written message.
const URLgetLocation () const
 Returns the name of the LB if already opened.
bool isOpen () const
 Returns 1 if LB is open, 0 if not.
int getMessageLength (LB_id_t messageId)
 Returns the length of the message.
int getLatestMsgInfo (LB_info &info)
 Fills in the latest-written message id & its size in the LB.
int getAllMsgInfo (std::vector< LB_info > &setme)
 Fills in information about all the messages currently in the LB.
int getLatestMsgInfo (std::vector< LB_info > &setme, size_t n_msgs)
 Fills in information about all the latest N messages in the LB.


Constructor & Destructor Documentation

code::LinearBuffer::LinearBuffer (  )  [inline]

A LinearBuffer when constructed is an empty shell.

Construction takes no arguments. To do anything with the LinearBuffer object, you need to call the member function open() or openW().

virtual code::LinearBuffer::~LinearBuffer (  )  [inline, virtual]

Will close the LB if needed.


Member Function Documentation

void code::LinearBuffer::close (  ) 

close() closes LB if open.

This function is automatically called by the destructor.

int code::LinearBuffer::getAllMsgInfo ( std::vector< LB_info > &  setme  ) 

Fills in information about all the messages currently in the LB.

int code::LinearBuffer::getLatestMsgInfo ( std::vector< LB_info > &  setme,
size_t  n_msgs 
)

Fills in information about all the latest N messages in the LB.

int code::LinearBuffer::getLatestMsgInfo ( LB_info &  info  ) 

Fills in the latest-written message id & its size in the LB.

See LB_info.

Returns:
negative integer (see lb.h: lb_seek) on error. If the message is to come or has expired, -199 is returned; in this case, the LB_id_t field of LB_info explains why the message doesn't exist.

const URL& code::LinearBuffer::getLocation (  )  const [inline]

Returns the name of the LB if already opened.

Undefined if the LB is not open already.

int code::LinearBuffer::getMessageLength ( LB_id_t  messageId  ) 

Returns the length of the message.

Returns:
the length of the message and a negative integer (see LB_msg_info) on error

bool code::LinearBuffer::isOpen (  )  const

Returns 1 if LB is open, 0 if not.

int code::LinearBuffer::latest (  )  [inline]

Makes LB_NEXT point to the last message in the LB.

Returns zero on success and a negative integer (see LB_seek) on error. Use lock() in a threaded application to keep the LB pointer where you have moved it.

int code::LinearBuffer::moveLBptr ( int  offset  )  [inline]

Moves the LB pointer n messages from the current.

Negative n moves it back and postitive n moves it forward.Returns zero on success and a negative integer (see LB_seek) on error. Use lock() in a threaded application to keep the LB pointer where you have moved it 

LB_id_t code::LinearBuffer::msgId (  )  [inline]

msgId() returns the message id of last read/written message.

Returns:
negative integer (see LB_msgId) on error.

int code::LinearBuffer::open ( const URL lb_url  ) 

open() opens LB for reading.

Returns:
0 on success and a negative integer on failure. For the meaning of these error codes, look at the documentation for LB_open.

int code::LinearBuffer::openOrCreate ( const URL lb_url  ) 

Recommended form of openW() for applications to call.

A new LB is created if it doesn't already exist; if an LB of the same name already exists, the existing data is not clobbered. Instead, a safer version of the open is performed. This function is not thread-safe. Pass in the expected numbers for number of messages and average size.

Returns:
0 on success and a negative integer on failure. For the meaning of these error codes, look at the documentation for LB_open.
The LB created is of the maximum size possible with an average of 512 bytes per message. (i.e. SHRT_MAX and 512 are passed to the openW method).

int code::LinearBuffer::openW ( const URL lb_url,
int  numMessages,
int  avgSize 
)

A new LB is created if it doesn't already exist; if an LB of the same name already exists, the existing data is not clobbered.

Instead, a safer version of the open is performed. This function is not thread-safe. Pass in the expected numbers for number of messages and average size.

Returns:
0 on success and a negative integer on failure. For the meaning of these error codes, look at the documentation for LB_open.

int code::LinearBuffer::openW ( const URL lb_url  ) 

Opens LB for writing if the LB exists.

It does not create an LB.

Returns:
0 on success and a negative integer on failure. For the meaning of these error codes, look at the documentation for LB_open.

int code::LinearBuffer::read ( std::vector< char > &  msg,
LB_id_t  msgId = LB_NEXT,
int  errorToSupress = 0 
)

Identical to read(char*,int,LB_id_t,int) except the client doesn't need to know the size of the message beforehand.

int code::LinearBuffer::read ( char *  msg,
int  msgLength,
LB_id_t  msgId = LB_NEXT,
int  errorToSupress = 0 
)

Reads message of specified id and returns the length of read-in message if successful.

The msg buffer should be large enough to hold msglen bytes. On failure, it returns a negative integer. For the meaning of these error codes, look at the documentation for LB_read. When the error to be suppressed is encountered, it returns zero.

Read using LB_NEXT is not thread-safe.  Read using a message id is.

int code::LinearBuffer::rewind (  )  [inline]

Makes LB_NEXT point to the first message in the LB.

Returns zero on success and a negative integer (see LB_seek) on error. Use lock() in a threaded application to keep the LB pointer where you have moved it.

int code::LinearBuffer::seek ( LB_id_t  id,
int  offset 
) [inline]

Move the LB pointer to the specified message in the LB.

Don't use this unless you know what you're doing. rewind(), latest(), and moveLBptr() are better for common use. Use lock() in a threaded application to keep the LB pointer where you have moved it.

void code::LinearBuffer::write ( int  messageId,
const void *  buffer,
int  bufferLength,
int *  setme_error = 0 
)

Same as write() except that the buffer overwrites the message messageId.

The replacing message should be the same size as the old one. Returns message id of the writen message on success and a negative number (see LB_write) on error.

void code::LinearBuffer::write ( const void *  buffer,
int  bufferLength,
int *  setme_error = 0 
)

Writes the buffer out to the LB as the latest message.

Returns message id of the writen message on success and a negative number (see LB_write) on error.


Generated on Fri May 4 13:40:12 2012 for WDSS-IIw2 by  doxygen 1.4.7