forest-net
an overlay networks for large-scale virtual worlds
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
AdminTable.h
Go to the documentation of this file.
1
9
#ifndef CLIENTTABLE_H
10
#define CLIENTTABLE_H
11
12
#include <map>
13
#include "
Forest.h
"
14
#include "
RateSpec.h
"
15
#include "UiClist.h"
16
#include "UiSetPair.h"
17
#include "IdMap.h"
18
19
namespace
forest {
20
29
class
AdminTable
{
30
public
:
31
AdminTable
(
int
);
32
~AdminTable
();
33
bool
init
();
34
35
bool
validAdmin(
int
)
const
;
36
37
// iteration methods
38
int
firstAdmin
();
39
int
nextAdmin
(
int
);
40
41
// access routines for admin info
42
bool
isLocked(
int
)
const
;
43
int
getAdmin
(
const
string
&);
44
void
releaseAdmin
(
int
);
45
const
string
&
getPassword
(
int
)
const
;
46
const
string
&
getAdminName
(
int
)
const
;
47
const
string
&
getRealName
(
int
)
const
;
48
const
string
&
getEmail
(
int
)
const
;
49
bool
checkPassword
(
int
,
string
&)
const
;
50
51
int
getNumAdmins()
const
;
52
int
getMaxAdmins()
const
;
53
int
getMaxAdx()
const
;
54
55
// add/remove/modify table entries
56
int
addAdmin
(
string
&,
string
&,
int
=0);
57
void
removeAdmin
(
int
);
58
59
void
setAdminName
(
int
,
const
string
&);
60
void
setPassword
(
int
,
const
string
&);
61
void
setRealName
(
int
,
const
string
&);
62
void
setEmail
(
int
,
const
string
&);
63
64
// input/output of table contents
65
bool
readEntry
(istream&,
int
=0);
66
bool
read
(istream&);
67
string
&
toString
(
string
&);
68
string
&
admin2string
(
int
,
string
&)
const
;
69
void
write
(ostream&);
70
71
// locking/unlocking the internal maps
72
// (admin name-to-index, admin address-to-session)
73
void
lockMap
();
74
void
unlockMap
();
75
private
:
76
int
maxAdm
;
77
int
maxAdx
;
78
79
struct
Admin
{
80
string
aname
;
81
string
pwd
;
82
string
realName
;
83
string
email
;
84
bool
busyBit
;
85
pthread_cond_t
busyCond
;
86
};
87
88
Admin
*
avec
;
89
90
static
const
int
RECORD_SIZE
= 128;
91
fstream
adminFile
;
92
93
UiSetPair *
admins
;
94
map<string, int> *
nameMap
;
95
96
pthread_mutex_t
mapLock
;
97
100
bool
readEntry
(istream&);
101
int
fileSize();
102
};
103
104
inline
bool
AdminTable::validAdmin(
int
adx)
const
{
105
return
admins
->isIn(adx);
106
}
107
108
inline
int
AdminTable::getNumAdmins()
const
{
109
return
admins
->getNumIn();
110
}
111
112
inline
int
AdminTable::getMaxAdmins()
const
{
return
maxAdm
; }
113
114
inline
int
AdminTable::getMaxAdx()
const
{
return
maxAdx
; }
115
116
inline
bool
AdminTable::isLocked(
int
adx)
const
{
117
return
avec
[adx].
busyBit
;
118
}
119
125
inline
const
string
&
AdminTable::getPassword
(
int
adx)
const
{
126
return
avec
[adx].
pwd
;
127
}
128
133
inline
const
string
&
AdminTable::getAdminName
(
int
adx)
const
{
134
return
avec
[adx].
aname
;
135
}
136
142
inline
bool
AdminTable::checkPassword
(
int
adx,
string
& pwd)
const
{
143
return
avec
[adx].
pwd
== pwd;
144
}
145
150
inline
const
string
&
AdminTable::getRealName
(
int
adx)
const
{
151
return
avec
[adx].
realName
;
152
}
153
158
inline
const
string
&
AdminTable::getEmail
(
int
adx)
const
{
159
return
avec
[adx].
email
;
160
}
161
166
inline
void
AdminTable::setAdminName
(
int
adx,
const
string
& aname) {
167
avec
[adx].
aname
= aname;
168
}
169
174
inline
void
AdminTable::setPassword
(
int
adx,
const
string
& pwd) {
175
avec
[adx].
pwd
= pwd;
176
}
177
182
inline
void
AdminTable::setRealName
(
int
adx,
const
string
& realName) {
183
avec
[adx].
realName
= realName;
184
}
185
190
inline
void
AdminTable::setEmail
(
int
adx,
const
string
& email) {
191
avec
[adx].
email
= email;
192
}
193
200
inline
void
AdminTable::lockMap
() { pthread_mutex_lock(&
mapLock
); }
201
204
inline
void
AdminTable::unlockMap
() { pthread_mutex_unlock(&
mapLock
); }
205
206
}
// ends namespace
207
208
209
#endif
forest-net
cpp
include
AdminTable.h
Generated on Mon Aug 4 2014 11:13:35 for forest-net by
1.8.4