Inheritance diagram for code::LBActionSource:
This class can be used to synchronize an external data base with the messages in an LB. The class LBEvent is what is posted.
The Listeners have to be re-entrant functions (except on OPUP where they will automatically happen in a signal-safe thread). In an EventHandler, this re-entrancy restriction is not there. However, you have to let EventHandler take over in the main loop.
Public Types | |
OpenReadOnly | |
OpenForWrite | |
enum | OpenMode { OpenReadOnly, OpenForWrite } |
Modes in which this linear buffer may be opened. More... | |
Public Member Functions | |
LBActionSource (const std::string &lb_name, OpenMode md=OpenReadOnly) | |
Pass in the name of the LinearBuffer you wish to monitor and the mode that you wish to open it with. | |
LBActionSource () | |
The default constructor is a shell and requires an explicit call to setLinearBuffer(). | |
int | setLinearBuffer (const std::string &lb_name, OpenMode md=OpenReadOnly) |
Use this to set the linear buffer being listened to. | |
virtual | ~LBActionSource () |
void | copyListenersFrom (const ActionSource &other) |
copy all the listeners from the other source (replacing our own) | |
size_t | getNumListeners () const |
returns the number of listeners linked to this source. | |
std::string | getDir () |
Returns a source-specific disk directory. | |
void | addActionListener (SmartPtr< ActionListener > lstnr) |
Subscribe lstnr such that it receives all events from this ActionSource. | |
void | addActionListener (const std::string &event_type, SmartPtr< ActionListener > lstnr) |
Subscribe lstnr such that it receives only this event type from this ActionSource. | |
void | removeActionListener (SmartPtr< ActionListener > lstner) |
Unsubscribe lstnr such that it no longer receives events from this ActionSource. | |
void | removeActionListener (const std::string &eventType, SmartPtr< ActionListener > lstner) |
Unsubscribe the listener so that it does not respond to the the event type noted. | |
void | fireActionPerformed (const ActionEvent &e) |
Convenience function for subclasses to notify ActionListeners of events. | |
void | fireActionPerformed (const ActionEvent *e) |
Convenience function for subclasses to notify ActionListeners of events. | |
void | fireActionPerformed (const std::string &type) |
Convenience function for subclasses to notify ActionListeners of events. | |
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 URL & | getLocation () 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 | getLatestMsgInfo (std::vector< LB_info > &setme, size_t n_msgs) |
Fills in information about all the latest N messages in the LB. | |
int | getAllMsgInfo (std::vector< LB_info > &setme) |
Fills in information about all the messages currently in the LB. | |
Classes | |
class | LBEvent |
LBEvent is the ActionEvent posted by the LBActionSource. More... |
code::LBActionSource::LBActionSource | ( | const std::string & | lb_name, | |
OpenMode | md = OpenReadOnly | |||
) |
Pass in the name of the LinearBuffer you wish to monitor and the mode that you wish to open it with.
This LinearBuffer will be opened with the mode provided and will be available to provide notification. The OpenReadOnly mode is sufficient for notification; use OpenForWrite only if you need to write to the LB.
code::LBActionSource::LBActionSource | ( | ) |
The default constructor is a shell and requires an explicit call to setLinearBuffer().
virtual code::LBActionSource::~LBActionSource | ( | ) | [inline, virtual] |
void code::ActionSource::addActionListener | ( | const std::string & | event_type, | |
SmartPtr< ActionListener > | lstnr | |||
) | [inline, inherited] |
Subscribe lstnr such that it receives only this event type from this ActionSource.
evt_type | the event type we are subscribing to | |
lstnr | the action listener to be subscribed. |
void code::ActionSource::addActionListener | ( | SmartPtr< ActionListener > | lstnr | ) | [inline, inherited] |
Subscribe lstnr such that it receives all events from this ActionSource.
l | the action listener to be subscribed. |
void code::LinearBuffer::close | ( | ) | [inherited] |
close() closes LB if open.
This function is automatically called by the destructor.
void code::ActionSource::copyListenersFrom | ( | const ActionSource & | other | ) | [inline, inherited] |
copy all the listeners from the other source (replacing our own)
void code::ActionSource::fireActionPerformed | ( | const std::string & | type | ) | [inline, inherited] |
Convenience function for subclasses to notify ActionListeners of events.
type | the type of the ActionEvent to be passed along to the action listeners. |
void code::ActionSource::fireActionPerformed | ( | const ActionEvent * | e | ) | [inline, inherited] |
Convenience function for subclasses to notify ActionListeners of events.
actionEvent | the event to be passed along to the action listeners. |
void code::ActionSource::fireActionPerformed | ( | const ActionEvent & | e | ) | [inline, inherited] |
Convenience function for subclasses to notify ActionListeners of events.
actionEvent | the event to be passed along to the action listeners. |
int code::LinearBuffer::getAllMsgInfo | ( | std::vector< LB_info > & | setme | ) | [inherited] |
Fills in information about all the messages currently in the LB.
std::string code::ActionSource::getDir | ( | ) | [inline, inherited] |
Returns a source-specific disk directory.
Default implementation does nothing --- this should be overridden.
int code::LinearBuffer::getLatestMsgInfo | ( | std::vector< LB_info > & | setme, | |
size_t | n_msgs | |||
) | [inherited] |
Fills in information about all the latest N messages in the LB.
int code::LinearBuffer::getLatestMsgInfo | ( | LB_info & | info | ) | [inherited] |
Fills in the latest-written message id & its size in the LB.
See LB_info.
const URL& code::LinearBuffer::getLocation | ( | ) | const [inline, inherited] |
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 | ) | [inherited] |
Returns the length of the message.
size_t code::ActionSource::getNumListeners | ( | ) | const [inline, inherited] |
returns the number of listeners linked to this source.
bool code::LinearBuffer::isOpen | ( | ) | const [inherited] |
Returns 1 if LB is open, 0 if not.
int code::LinearBuffer::latest | ( | ) | [inline, inherited] |
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, inherited] |
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, inherited] |
msgId() returns the message id of last read/written message.
int code::LinearBuffer::open | ( | const URL & | lb_url | ) | [inherited] |
open() opens LB for reading.
int code::LinearBuffer::openOrCreate | ( | const URL & | lb_url | ) | [inherited] |
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.
int code::LinearBuffer::openW | ( | const URL & | lb_url, | |
int | numMessages, | |||
int | avgSize | |||
) | [inherited] |
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.
int code::LinearBuffer::openW | ( | const URL & | lb_url | ) | [inherited] |
Opens LB for writing if the LB exists.
It does not create an LB.
int code::LinearBuffer::read | ( | std::vector< char > & | msg, | |
LB_id_t | msgId = LB_NEXT , |
|||
int | errorToSupress = 0 | |||
) | [inherited] |
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 | |||
) | [inherited] |
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.
void code::ActionSource::removeActionListener | ( | const std::string & | eventType, | |
SmartPtr< ActionListener > | lstner | |||
) | [inline, inherited] |
Unsubscribe the listener so that it does not respond to the the event type noted.
This works only if the listener was added via addActionListener( type, SmartPtr )
type | The event type | |
lstnr | The listener to remove |
void code::ActionSource::removeActionListener | ( | SmartPtr< ActionListener > | lstner | ) | [inline, inherited] |
Unsubscribe lstnr such that it no longer receives events from this ActionSource.
lstnr | the action listener to be unsubscribed. |
int code::LinearBuffer::rewind | ( | ) | [inline, inherited] |
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, inherited] |
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.
int code::LBActionSource::setLinearBuffer | ( | const std::string & | lb_name, | |
OpenMode | md = OpenReadOnly | |||
) |
Use this to set the linear buffer being listened to.
Returns -ve on error.
void code::LinearBuffer::write | ( | int | messageId, | |
const void * | buffer, | |||
int | bufferLength, | |||
int * | setme_error = 0 | |||
) | [inherited] |
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 | |||
) | [inherited] |
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.