forest-net
an overlay networks for large-scale virtual worlds
|
Class that implements a register of information about comtrees, for use by ClientMgr. More...
#include <ComtreeRegister.h>
Classes | |
struct | Comtree |
Public Member Functions | |
ComtreeRegister (int, int) | |
Constructor for ComtreeRegister, allocates space and initializes table. More... | |
~ComtreeRegister () | |
Destructor for ComtreeRegister, frees dynamic storage. | |
bool | init () |
Initialize lock and condition variables. More... | |
bool | validComtree (int) const |
int | firstComtree () |
Get the first comtree in the list of active comtrees. More... | |
int | nextComtree (int) |
Get the index of the next client. More... | |
bool | isLocked (int) const |
int | getComtIndex (comt_t) |
Get a comtree index for a given comtree. More... | |
void | releaseComtree (int) |
Release a previously locked comtree register entry. More... | |
comt_t | getComtree (int) |
Get the comtree number of a given entry. More... | |
const string & | getOwner (int) const |
Get the owner of a comtree. More... | |
fAdr_t | getSuper (int) const |
Get the supervisor of a comtree. More... | |
Forest::ConfigMode | getConfigMode (int) const |
Get the configuration mode of a comtree. More... | |
Forest::AccessMethod | getAccessMethod (int) const |
Get the access method of a comtree. More... | |
int | getRepInterval (int) const |
Get the reporting interval of a comtree. More... | |
time_t | getStartTime (int) const |
Get the start time of a comtree. More... | |
int | addComtree (comt_t, string &) |
Add a new comtree. More... | |
void | removeComtree (int) |
Remove a comtree. More... | |
void | setOwner (int, const string &) |
Set the owner of a comtree. More... | |
void | setSuper (int, fAdr_t) |
Set the supervisor of a comtree. More... | |
void | setConfigMode (int, Forest::ConfigMode) |
Set the configuration mode of a comtree. More... | |
void | setAccessMethod (int, Forest::ConfigMode) |
void | setRepInterval (int, int) |
Set the reporting interval of a comtree. More... | |
void | setStartTime (int, time_t) |
Get the start time of a comtree. More... | |
bool | readEntry (istream &, int=0) |
Read a comtree record from an input file and initialize its table entry. More... | |
bool | read (istream &) |
Read comtree register entries from an input stream. More... | |
string & | toString (string &) |
Create a string representation of the comtree register. More... | |
string & | comtree2string (int, string &) const |
Construct a string representation of a comtree entry. More... | |
void | write (ostream &) |
Write the complete client table to an output stream. More... | |
void | lockMap () |
Lock the client table. More... | |
void | unlockMap () |
Unlock the client table. | |
Private Member Functions | |
uint64_t | key (comt_t) const |
helper functions More... | |
bool | readEntry (istream &) |
int | fileSize () |
Private Attributes | |
int | maxComt |
max number of comtrees | |
int | maxCtx |
largest defined ctx | |
Comtree * | cvec |
vector of comtree structs | |
IdMap * | comtMap |
maps comtree number to index | |
pthread_mutex_t | mapLock |
must hold during add/remove ops More... | |
Class that implements a register of information about comtrees, for use by ClientMgr.
Entries are accessed using a "comtree index", which can be obtained using the getComtIndex() method. This also locks the comtree's table entry to permit exclusive access to the data for that comtree. Other methods also lock table entries.
Definition at line 30 of file ComtreeRegister.h.
forest::ComtreeRegister::ComtreeRegister | ( | int | , |
int | |||
) |
Constructor for ComtreeRegister, allocates space and initializes table.
Definition at line 15 of file ComtreeRegister.cpp.
int forest::ComtreeRegister::addComtree | ( | comt_t | , |
string & | |||
) |
Add a new comtree.
Attempts to add a new comtree to the register. Can fail if the specified comtree is already in use, or if there is no more space. On return, the new entry is locked; the caller must release it when done.
comt | is the comtree number for the new entry |
ctx | is an optional argument specifying the comtree index to be used for this new comtree; if ctx == 0, the comtree index is assigned automatically (this is the default behavior) |
Definition at line 135 of file ComtreeRegister.cpp.
string & forest::ComtreeRegister::comtree2string | ( | int | ctx, |
string & | s | ||
) | const |
Construct a string representation of a comtree entry.
This metghod does no locking.
ctx | is the comtree index of the entry |
s | is a reference to a string in which result is returned |
Definition at line 253 of file ComtreeRegister.cpp.
ctx forest::ComtreeRegister::firstComtree | ( | ) |
Get the first comtree in the list of active comtrees.
Definition at line 73 of file ComtreeRegister.cpp.
|
inline |
Get the access method of a comtree.
ctx | is the comtree index for some comtree |
Definition at line 164 of file ComtreeRegister.h.
int forest::ComtreeRegister::getComtIndex | ( | comt_t | comt) |
Get a comtree index for a given comtree.
comt | is a comtree number |
Definition at line 45 of file ComtreeRegister.cpp.
|
inline |
Get the comtree number of a given entry.
ctx | is the comtree index for some comtree |
Definition at line 124 of file ComtreeRegister.h.
|
inline |
Get the configuration mode of a comtree.
ctx | is the comtree index for some comtree |
Definition at line 156 of file ComtreeRegister.h.
|
inline |
Get the owner of a comtree.
ctx | is the comtree index for some comtree |
Definition at line 132 of file ComtreeRegister.h.
|
inline |
Get the reporting interval of a comtree.
ctx | is the comtree index for some comtree |
Definition at line 172 of file ComtreeRegister.h.
|
inline |
Get the start time of a comtree.
ctx | is the comtree index for some comtree |
Definition at line 180 of file ComtreeRegister.h.
|
inline |
Get the supervisor of a comtree.
ctx | is the comtree index for some comtree |
Definition at line 148 of file ComtreeRegister.h.
bool forest::ComtreeRegister::init | ( | ) |
Initialize lock and condition variables.
Definition at line 28 of file ComtreeRegister.cpp.
|
inlineprivate |
helper functions
Compute key for use with comtMap.
comt | is a comtree number |
Definition at line 248 of file ComtreeRegister.h.
|
inline |
Lock the client table.
This method is meant primarily for internal use. Applications should normally just lock single clients using the methods provided for that purpose. Use extreme caution when using this method directly.
Definition at line 258 of file ComtreeRegister.h.
int forest::ComtreeRegister::nextComtree | ( | int | ctx) |
Get the index of the next client.
The caller is assumed to have a lock on the current client.
ctx | is the index of a valid client |
Definition at line 97 of file ComtreeRegister.cpp.
bool forest::ComtreeRegister::read | ( | istream & | in) |
Read comtree register entries from an input stream.
The first line of the input must contain an integer, giving the number of entries to be read. The input may include blank lines and comment lines (any text starting with '#'). The operation may fail if the input is misformatted or if an entry does not pass some basic sanity checks. In this case, an error message is printed that identifies the entry on which a problem was detected
in | is an open input stream |
Definition at line 239 of file ComtreeRegister.cpp.
bool forest::ComtreeRegister::readEntry | ( | istream & | in, |
int | ctx = 0 |
||
) |
Read a comtree record from an input file and initialize its table entry.
A record includes ...
in | is an open file stream |
ctx | is an optional argument specifying the comtree index for this entry; if zero, a comtree index is selected automatically (this is the default behavior) |
Definition at line 168 of file ComtreeRegister.cpp.
void forest::ComtreeRegister::releaseComtree | ( | int | ctx) |
Release a previously locked comtree register entry.
Waiting threads are signalled to let them proceed.
ctx | is the index of a locked comtree. |
Definition at line 62 of file ComtreeRegister.cpp.
void forest::ComtreeRegister::removeComtree | ( | int | ctx) |
Remove a comtree.
Assumes that the calling thread has already locked the comtree. The lock is released on return.
ctx | is the index of the comtree to be deleted |
Definition at line 153 of file ComtreeRegister.cpp.
|
inline |
Set the configuration mode of a comtree.
Set the access method of a comtree.
ctx | is the comtree index for some comtree |
ctx | is the comtree index for some comtree |
axs | is the access method of the comtree |
Definition at line 216 of file ComtreeRegister.h.
|
inline |
Set the owner of a comtree.
ctx | is the comtree index for some comtree |
owner | is a string naming the owner of the comtree |
Definition at line 192 of file ComtreeRegister.h.
|
inline |
Set the reporting interval of a comtree.
ctx | is the comtree index for some comtree |
interval | is the reporting interval of the comtree |
Definition at line 232 of file ComtreeRegister.h.
|
inline |
Get the start time of a comtree.
ctx | is the comtree index for some comtree |
t | is the start time of the comtree (in seconds since the epoch) |
Definition at line 240 of file ComtreeRegister.h.
|
inline |
Set the supervisor of a comtree.
ctx | is the comtree index for some comtree |
super | is the forest address of the supervisor of the comtree |
Definition at line 208 of file ComtreeRegister.h.
string & forest::ComtreeRegister::toString | ( | string & | s) |
Create a string representation of the comtree register.
s | is a reference to a string in which the result is returned |
Definition at line 288 of file ComtreeRegister.cpp.
void forest::ComtreeRegister::write | ( | ostream & | out) |
Write the complete client table to an output stream.
Does no locking.
out | is a reference to an open output stream |
Definition at line 299 of file ComtreeRegister.cpp.
|
private |
must hold during add/remove ops
and while locking comtree
Definition at line 98 of file ComtreeRegister.h.