forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
forest::ComtreeRegister Class Reference

Class that implements a register of information about comtrees, for use by ClientMgr. More...

#include <ComtreeRegister.h>

Collaboration diagram for forest::ComtreeRegister:

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
 
Comtreecvec
 vector of comtree structs
 
IdMap * comtMap
 maps comtree number to index
 
pthread_mutex_t mapLock
 must hold during add/remove ops More...
 

Detailed Description

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.

Constructor & Destructor Documentation

forest::ComtreeRegister::ComtreeRegister ( int  ,
int   
)

Constructor for ComtreeRegister, allocates space and initializes table.

Definition at line 15 of file ComtreeRegister.cpp.

Member Function Documentation

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.

Parameters
comtis the comtree number for the new entry
ctxis 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)
Returns
the index of the new table entry or 0 on failure;

Definition at line 135 of file ComtreeRegister.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

string & forest::ComtreeRegister::comtree2string ( int  ctx,
string &  s 
) const

Construct a string representation of a comtree entry.

This metghod does no locking.

Parameters
ctxis the comtree index of the entry
sis a reference to a string in which result is returned
Returns
a reference to s

Definition at line 253 of file ComtreeRegister.cpp.

Here is the call graph for this function:

ctx forest::ComtreeRegister::firstComtree ( )

Get the first comtree in the list of active comtrees.

Returns
the index of the first valid comtree, or 0 if there is no valid comtree; on a successful return, the comtree is locked

Definition at line 73 of file ComtreeRegister.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Forest::AccessMethod forest::ComtreeRegister::getAccessMethod ( int  ctx) const
inline

Get the access method of a comtree.

Parameters
ctxis the comtree index for some comtree
Returns
the access method of the comtree

Definition at line 164 of file ComtreeRegister.h.

Here is the caller graph for this function:

int forest::ComtreeRegister::getComtIndex ( comt_t  comt)

Get a comtree index for a given comtree.

Parameters
comtis a comtree number
Returns
the comtree index associated with the given comtree, or 0 if there is no table entry for the given comtree; on return, the table entry for the comtree is locked; the caller must release it when done using it

Definition at line 45 of file ComtreeRegister.cpp.

Here is the call graph for this function:

comt_t forest::ComtreeRegister::getComtree ( int  )
inline

Get the comtree number of a given entry.

Parameters
ctxis the comtree index for some comtree
Returns
a the actual comtree number

Definition at line 124 of file ComtreeRegister.h.

Here is the caller graph for this function:

Forest::ConfigMode forest::ComtreeRegister::getConfigMode ( int  ctx) const
inline

Get the configuration mode of a comtree.

Parameters
ctxis the comtree index for some comtree
Returns
the configuration mode of the comtree

Definition at line 156 of file ComtreeRegister.h.

Here is the caller graph for this function:

const string & forest::ComtreeRegister::getOwner ( int  ctx) const
inline

Get the owner of a comtree.

Parameters
ctxis the comtree index for some comtree
Returns
a const reference to a string naming the owner

Definition at line 132 of file ComtreeRegister.h.

Here is the caller graph for this function:

int forest::ComtreeRegister::getRepInterval ( int  ctx) const
inline

Get the reporting interval of a comtree.

Parameters
ctxis the comtree index for some comtree
Returns
the reporting interval of the comtree

Definition at line 172 of file ComtreeRegister.h.

time_t forest::ComtreeRegister::getStartTime ( int  ctx) const
inline

Get the start time of a comtree.

Parameters
ctxis the comtree index for some comtree
Returns
the start time of the comtree (in seconds since the epoch)

Definition at line 180 of file ComtreeRegister.h.

Here is the caller graph for this function:

fAdr_t forest::ComtreeRegister::getSuper ( int  ctx) const
inline

Get the supervisor of a comtree.

Parameters
ctxis the comtree index for some comtree
Returns
the forest address of the supervisor of the comtree

Definition at line 148 of file ComtreeRegister.h.

Here is the caller graph for this function:

bool forest::ComtreeRegister::init ( )

Initialize lock and condition variables.

Definition at line 28 of file ComtreeRegister.cpp.

uint64_t forest::ComtreeRegister::key ( comt_t  comt) const
inlineprivate

helper functions

Compute key for use with comtMap.

Parameters
comtis a comtree number
Returns
a 64 bit hash key

Definition at line 248 of file ComtreeRegister.h.

Here is the caller graph for this function:

void forest::ComtreeRegister::lockMap ( )
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.

Here is the caller graph for this function:

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.

Parameters
ctxis the index of a valid client
Returns
the index of the next client in the list of valid clients or 0 if there is no next client; on return, the lock on ctx is released and the next client is locked.

Definition at line 97 of file ComtreeRegister.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Parameters
inis an open input stream
Returns
true on success, false on failure

Definition at line 239 of file ComtreeRegister.cpp.

Here is the call graph for this function:

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 ...

Parameters
inis an open file stream
ctxis 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.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::ComtreeRegister::releaseComtree ( int  ctx)

Release a previously locked comtree register entry.

Waiting threads are signalled to let them proceed.

Parameters
ctxis the index of a locked comtree.

Definition at line 62 of file ComtreeRegister.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
ctxis the index of the comtree to be deleted

Definition at line 153 of file ComtreeRegister.cpp.

Here is the call graph for this function:

void forest::ComtreeRegister::setConfigMode ( int  ,
Forest::ConfigMode   
)
inline

Set the configuration mode of a comtree.

Set the access method of a comtree.

Parameters
ctxis the comtree index for some comtree
Returns
the configuration mode of the comtree
Parameters
ctxis the comtree index for some comtree
axsis the access method of the comtree

Definition at line 216 of file ComtreeRegister.h.

Here is the caller graph for this function:

void forest::ComtreeRegister::setOwner ( int  ,
const string &   
)
inline

Set the owner of a comtree.

Parameters
ctxis the comtree index for some comtree
owneris a string naming the owner of the comtree

Definition at line 192 of file ComtreeRegister.h.

Here is the caller graph for this function:

void forest::ComtreeRegister::setRepInterval ( int  ctx,
int  interval 
)
inline

Set the reporting interval of a comtree.

Parameters
ctxis the comtree index for some comtree
intervalis the reporting interval of the comtree

Definition at line 232 of file ComtreeRegister.h.

void forest::ComtreeRegister::setStartTime ( int  ctx,
time_t  t 
)
inline

Get the start time of a comtree.

Parameters
ctxis the comtree index for some comtree
tis the start time of the comtree (in seconds since the epoch)

Definition at line 240 of file ComtreeRegister.h.

Here is the caller graph for this function:

void forest::ComtreeRegister::setSuper ( int  ,
fAdr_t   
)
inline

Set the supervisor of a comtree.

Parameters
ctxis the comtree index for some comtree
superis the forest address of the supervisor of the comtree

Definition at line 208 of file ComtreeRegister.h.

Here is the caller graph for this function:

string & forest::ComtreeRegister::toString ( string &  s)

Create a string representation of the comtree register.

Parameters
sis a reference to a string in which the result is returned
Returns
a reference to s

Definition at line 288 of file ComtreeRegister.cpp.

Here is the call graph for this function:

void forest::ComtreeRegister::write ( ostream &  out)

Write the complete client table to an output stream.

Does no locking.

Parameters
outis a reference to an open output stream

Definition at line 299 of file ComtreeRegister.cpp.

Here is the call graph for this function:

Member Data Documentation

pthread_mutex_t forest::ComtreeRegister::mapLock
private

must hold during add/remove ops

and while locking comtree

Definition at line 98 of file ComtreeRegister.h.


The documentation for this class was generated from the following files: