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

Class that implements a table of information about Forest administrators. More...

#include <AdminTable.h>

Collaboration diagram for forest::AdminTable:

Classes

struct  Admin
 

Public Member Functions

 AdminTable (int)
 Constructor for AdminTable, allocates space and initializes table. More...
 
 ~AdminTable ()
 Destructor for AdminTable, frees dynamic storage.
 
bool init ()
 Initialize lock and condition variables. More...
 
bool validAdmin (int) const
 
int firstAdmin ()
 Get the first admin in the list of valid admins. More...
 
int nextAdmin (int)
 Get the index of the next admin. More...
 
bool isLocked (int) const
 
int getAdmin (const string &)
 Lock an admin's table entry. More...
 
void releaseAdmin (int)
 Release a previously locked admin table entry. More...
 
const string & getPassword (int) const
 Get an admin's password. More...
 
const string & getAdminName (int) const
 Get an admin's name. More...
 
const string & getRealName (int) const
 Get an admin's real world name. More...
 
const string & getEmail (int) const
 Get an admin's email address. More...
 
bool checkPassword (int, string &) const
 Check an admin's password. More...
 
int getNumAdmins () const
 
int getMaxAdmins () const
 
int getMaxAdx () const
 
int addAdmin (string &, string &, int=0)
 Add a new admin. More...
 
void removeAdmin (int)
 Remove an admin. More...
 
void setAdminName (int, const string &)
 Set an admin's name. More...
 
void setPassword (int, const string &)
 Set an admin's password. More...
 
void setRealName (int, const string &)
 Set an admin's real world name. More...
 
void setEmail (int, const string &)
 Set an admin's email address. More...
 
bool readEntry (istream &, int=0)
 Read an admin record from an input file and initialize its table entry. More...
 
bool read (istream &)
 Read admin table entries from an input stream. More...
 
string & toString (string &)
 Create a string representation of the admin table. More...
 
string & admin2string (int, string &) const
 Construct a string representation of an admin. More...
 
void write (ostream &)
 Write the complete admin table to an output stream. More...
 
void lockMap ()
 Lock the admin table. More...
 
void unlockMap ()
 Unlock the admin table.
 

Private Member Functions

bool readEntry (istream &)
 helper functions
 
int fileSize ()
 

Private Attributes

int maxAdm
 max number of admins
 
int maxAdx
 largest defined adx
 
Adminavec
 vector of admin structs
 
fstream adminFile
 file stream for admin file
 
UiSetPair * admins
 active and free admin indexes
 
map< string, int > * nameMap
 maps admin name to admin index
 
pthread_mutex_t mapLock
 must hold during add/remove ops More...
 

Static Private Attributes

static const int RECORD_SIZE = 128
 

of bytes per record


 

Detailed Description

Class that implements a table of information about Forest administrators.

Table entries are accessed using an "admin index", which can be obtained using the getAdmin() method. This also locks the admin's table entry to permit exclusive access to the data for that admin. Other methods also lock table entries.

Definition at line 29 of file AdminTable.h.

Constructor & Destructor Documentation

forest::AdminTable::AdminTable ( int  maxAdmins)

Constructor for AdminTable, allocates space and initializes table.

Definition at line 15 of file AdminTable.cpp.

Member Function Documentation

int forest::AdminTable::addAdmin ( string &  aname,
string &  pwd,
int  adx = 0 
)

Add a new admin.

Attempts to add a new admin to the table. Can fail if the specified user name is already in use, or if there is no more space. On return, the new admin's table entry is locked; the caller must release it when done.

Parameters
anameis the admin name
pwdis the admin password
adxis an optional argument specifying the admin index to be used for this new admin; if adx == 0, the admin index is assigned automatically (this is the default behavior)
Returns
the index of the new table entry or 0 on failure; can fail if aname clashes with an existing name, or there is no space left

Definition at line 165 of file AdminTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

string & forest::AdminTable::admin2string ( int  adx,
string &  s 
) const

Construct a string representation of an admin.

This metghod does no locking.

Parameters
adxis the admin index of the admin to be written
sis a reference to a string in which result is returned
Returns
a reference to s

Definition at line 259 of file AdminTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool forest::AdminTable::checkPassword ( int  adx,
string &  pwd 
) const
inline

Check an admin's password.

Parameters
adxis a valid admin index
pwdis a reference to a string containing the admin's password
Returns
true if the provided password is consistent with the stored value

Definition at line 142 of file AdminTable.h.

int forest::AdminTable::firstAdmin ( )

Get the first admin in the list of valid admins.

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

Definition at line 101 of file AdminTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int forest::AdminTable::getAdmin ( const string &  aname)

Lock an admin's table entry.

Parameters
adxis an admin index
Returns
true if able to a lock on the specified admin; return false if the admin index does not refer to a valid admin bool AdminTable::lockAdmin(int adx) { lockMap(); if (!admins->isIn(adx)) { unlockMap(); return 0; } while (avec[adx].busyBit) { // wait until admin's entry is not busy pthread_cond_wait(&avec[adx].busyCond,&mapLock); if (!admins->isIn(adx)) { pthread_cond_signal(&avec[adx].busyCond); unlockMap(); return false; } } avec[adx].busyBit = true; // set busyBit to lock admin table entry unlockMap(); return true; }Get an admin by name and lock its table entry.
Parameters
anameis an admin name
Returns
the admin index associated with the given admin name, or 0 if the name does not match any admin; on a successful return, the table entry for the admin is locked; the caller must release it when done using it

Definition at line 68 of file AdminTable.cpp.

Here is the call graph for this function:

const string & forest::AdminTable::getAdminName ( int  adx) const
inline

Get an admin's name.

Parameters
adxis a valid admin index
Returns
a const reference to the admin name string

Definition at line 133 of file AdminTable.h.

Here is the caller graph for this function:

const string & forest::AdminTable::getEmail ( int  adx) const
inline

Get an admin's email address.

Parameters
adxis a valid admin index
Returns
a const reference to the admin's email string

Definition at line 158 of file AdminTable.h.

Here is the caller graph for this function:

const string & forest::AdminTable::getPassword ( int  adx) const
inline

Get an admin's password.

The caller should already hold a lock for the admin.

Parameters
adxis a valid admin index
Returns
a const reference to the password string.

Definition at line 125 of file AdminTable.h.

Here is the caller graph for this function:

const string & forest::AdminTable::getRealName ( int  adx) const
inline

Get an admin's real world name.

Parameters
adxis a valid admin index
Returns
a const reference to the admin's realName string

Definition at line 150 of file AdminTable.h.

Here is the caller graph for this function:

bool forest::AdminTable::init ( )

Initialize lock and condition variables.

Definition at line 29 of file AdminTable.cpp.

void forest::AdminTable::lockMap ( )
inline

Lock the admin table.

This method is meant primarily for internal use. Applications should normally just lock single admins using the methods provided for that purpose. Use extreme caution when using this method directly.

Definition at line 200 of file AdminTable.h.

Here is the caller graph for this function:

int forest::AdminTable::nextAdmin ( int  adx)

Get the index of the next admin.

The caller is assumed to have a lock on the current admin.

Parameters
adxis the index of a valid admin
Returns
the index of the next admin in the list of valid admins or 0 if there is no next admin; on return, the lock on adx is released and the next admin is locked.

Definition at line 125 of file AdminTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool forest::AdminTable::read ( istream &  in)

Read admin table 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 245 of file AdminTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool forest::AdminTable::readEntry ( istream &  in,
int  adx = 0 
)

Read an admin record from an input file and initialize its table entry.

A record includes an admin name, password, real name (in quotes), an email address, a default rate spec and a total rate spec.

Parameters
inis an open file stream
adxis an optional argument specifying the admin index for this entry; if zero, an admin index is selected automatically (this is the default behavior)

Definition at line 209 of file AdminTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::AdminTable::releaseAdmin ( int  adx)

Release a previously locked admin table entry.

Waiting threads are signalled to let them proceed.

Parameters
adxis the index of a locked comtree.

Definition at line 90 of file AdminTable.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void forest::AdminTable::removeAdmin ( int  adx)

Remove an admin.

Assumes that the calling thread has already locked the admin. The lock is released on return.

Parameters
adxis the index of the admin to be deleted

Definition at line 192 of file AdminTable.cpp.

Here is the call graph for this function:

void forest::AdminTable::setAdminName ( int  adx,
const string &  aname 
)
inline

Set an admin's name.

Parameters
adxis a valid admin index
anameis the admin's name string

Definition at line 166 of file AdminTable.h.

Here is the caller graph for this function:

void forest::AdminTable::setEmail ( int  adx,
const string &  email 
)
inline

Set an admin's email address.

Parameters
adxis a valid admin index
emailis the admin's new email address

Definition at line 190 of file AdminTable.h.

Here is the caller graph for this function:

void forest::AdminTable::setPassword ( int  adx,
const string &  pwd 
)
inline

Set an admin's password.

Parameters
adxis a valid admin index
Returns
a const reference to the password string

Definition at line 174 of file AdminTable.h.

Here is the caller graph for this function:

void forest::AdminTable::setRealName ( int  adx,
const string &  realName 
)
inline

Set an admin's real world name.

Parameters
adxis a valid admin index
Returns
a const reference to the admin's realName string

Definition at line 182 of file AdminTable.h.

Here is the caller graph for this function:

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

Create a string representation of the admin table.

Parameters
sis a reference to a string in which the result is returned
includeSessis true if sessions are to be included, default=false
Returns
a reference to s

Definition at line 272 of file AdminTable.cpp.

Here is the call graph for this function:

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

Write the complete admin table to an output stream.

Parameters
outis a reference to an open output stream

Definition at line 282 of file AdminTable.cpp.

Here is the call graph for this function:

Member Data Documentation

pthread_mutex_t forest::AdminTable::mapLock
private

must hold during add/remove ops

and while locking admin

Definition at line 96 of file AdminTable.h.


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