forest-net
an overlay networks for large-scale virtual worlds
|
Class that implements a table of information about Forest administrators. More...
#include <AdminTable.h>
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 | |
Admin * | avec |
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 | |
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.
forest::AdminTable::AdminTable | ( | int | maxAdmins) |
Constructor for AdminTable, allocates space and initializes table.
Definition at line 15 of file AdminTable.cpp.
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.
aname | is the admin name |
pwd | is the admin password |
adx | is 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) |
Definition at line 165 of file AdminTable.cpp.
string & forest::AdminTable::admin2string | ( | int | adx, |
string & | s | ||
) | const |
Construct a string representation of an admin.
This metghod does no locking.
adx | is the admin index of the admin to be written |
s | is a reference to a string in which result is returned |
Definition at line 259 of file AdminTable.cpp.
|
inline |
Check an admin's password.
adx | is a valid admin index |
pwd | is a reference to a string containing the admin's password |
Definition at line 142 of file AdminTable.h.
int forest::AdminTable::firstAdmin | ( | ) |
Get the first admin in the list of valid admins.
Definition at line 101 of file AdminTable.cpp.
int forest::AdminTable::getAdmin | ( | const string & | aname) |
Lock an admin's table entry.
adx | is an admin index |
aname | is an admin name |
Definition at line 68 of file AdminTable.cpp.
|
inline |
Get an admin's name.
adx | is a valid admin index |
Definition at line 133 of file AdminTable.h.
|
inline |
Get an admin's email address.
adx | is a valid admin index |
Definition at line 158 of file AdminTable.h.
|
inline |
Get an admin's password.
The caller should already hold a lock for the admin.
adx | is a valid admin index |
Definition at line 125 of file AdminTable.h.
|
inline |
Get an admin's real world name.
adx | is a valid admin index |
Definition at line 150 of file AdminTable.h.
bool forest::AdminTable::init | ( | ) |
Initialize lock and condition variables.
Definition at line 29 of file AdminTable.cpp.
|
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.
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.
adx | is the index of a valid admin |
Definition at line 125 of file AdminTable.cpp.
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
in | is an open input stream |
Definition at line 245 of file AdminTable.cpp.
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.
in | is an open file stream |
adx | is 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.
void forest::AdminTable::releaseAdmin | ( | int | adx) |
Release a previously locked admin table entry.
Waiting threads are signalled to let them proceed.
adx | is the index of a locked comtree. |
Definition at line 90 of file AdminTable.cpp.
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.
adx | is the index of the admin to be deleted |
Definition at line 192 of file AdminTable.cpp.
|
inline |
Set an admin's name.
adx | is a valid admin index |
aname | is the admin's name string |
Definition at line 166 of file AdminTable.h.
|
inline |
Set an admin's email address.
adx | is a valid admin index |
is the admin's new email address |
Definition at line 190 of file AdminTable.h.
|
inline |
Set an admin's password.
adx | is a valid admin index |
Definition at line 174 of file AdminTable.h.
|
inline |
Set an admin's real world name.
adx | is a valid admin index |
Definition at line 182 of file AdminTable.h.
string & forest::AdminTable::toString | ( | string & | s) |
Create a string representation of the admin table.
s | is a reference to a string in which the result is returned |
includeSess | is true if sessions are to be included, default=false |
Definition at line 272 of file AdminTable.cpp.
void forest::AdminTable::write | ( | ostream & | out) |
Write the complete admin table to an output stream.
out | is a reference to an open output stream |
Definition at line 282 of file AdminTable.cpp.
|
private |