#include <history.h>
Public Member Functions | |
History (const int size) | |
Constructor for a History object. | |
virtual | ~History () |
std::string | get_id (void) const |
Identification routine. | |
Data * | read () |
Add the "owning" object, which is to be notified of disconnections. | |
ssize_t | write (const Data &) |
Write a blob of data to the underlying connection. | |
virtual bool | connected (void) const |
Indicate that we're connected. | |
Private Member Functions | |
void | connect (void) |
void | disconnect (void) |
Clear the CircBuffer, and return. | |
Private Attributes | |
CircBuffer< std::string > | lines |
A CircBuffer of strings that are the most recent CircBuffer::circ_size lines. | |
pthread_mutex_t | buf_mutex |
to protect the lines | |
bool | start_a_new_line |
This bool tracks whether new data should be placed in the next line. |
It also needs to handle messages asking for some [or all] of its contents, which it always has in-memory in a circular buffer.
Definition at line 97 of file history.h.
History::History | ( | const int | size | ) |
Constructor for a History object.
size | Lines of history that should be kept. (given to CircBuffer) |
Definition at line 48 of file history.cc.
References buf_mutex, and Guard::initialize_mutex().
History::~History | ( | ) | [virtual] |
Definition at line 55 of file history.cc.
References buf_mutex, Guard::destroy_mutex(), and disconnect().
std::string History::get_id | ( | void | ) | const [virtual] |
Identification routine.
Implements Connector.
Definition at line 71 of file history.cc.
References lines, and CircBuffer< _Tp >::max_size().
Referenced by write().
Data * History::read | ( | ) | [virtual] |
Add the "owning" object, which is to be notified of disconnections.
Implements Connector.
Definition at line 81 of file history.cc.
ssize_t History::write | ( | const Data & | b | ) | [virtual] |
Write a blob of data to the underlying connection.
Implements Connector.
Definition at line 87 of file history.cc.
References buf_mutex, Data::data(), get_id(), Data::len(), lines, PTHREAD_CHECK_AND_THROW, CircBuffer< _Tp >::push_back(), and start_a_new_line.
virtual bool History::connected | ( | void | ) | const [inline, virtual] |
Indicate that we're connected.
The CircBuffer is set up in our constructor, so we're always connected to it.
Implements Connector.
void History::connect | ( | void | ) | [inline, private] |
No-op since we don't have anything to establish/connect.
void History::disconnect | ( | void | ) | [private, virtual] |
Clear the CircBuffer, and return.
This function doesn't really disconnect anything, but go ahead and empty out the CircBuffer just to free up the memory.
Implements Connector.
Definition at line 173 of file history.cc.
References buf_mutex, and lines.
Referenced by ~History().
CircBuffer<std::string> History::lines [private] |
A CircBuffer of strings that are the most recent CircBuffer::circ_size lines.
Definition at line 125 of file history.h.
Referenced by disconnect(), get_id(), and write().
pthread_mutex_t History::buf_mutex [private] |
to protect the lines
Definition at line 126 of file history.h.
Referenced by disconnect(), History(), write(), and ~History().
bool History::start_a_new_line [private] |