file name: database.hpp, database.cpp
classification: simulation
contents: struct SDelay, struct SRate, struct STimeInterval,
class CApplicationDatabase
use: stores all clock synchronization data (namely the delays,
rates and time information from the other nodes)
global items used:
struct SDelay:
contains transmission delay data
enum EDataType:
Delay, Rate, Time
The enums are used to specify which data list is to be accessed.
CAddressManager
*addressManager_: Needed for the mapping of the (user) node ID to
the network address and vice versa.
EBool initCalled_:
is set to True by Init(), to False by Dispose().
CDelaySetList
*listOfDelays_: stores the transmission delays.
CRateSetList
*listOfRates_: stores the clock rates.
CTimeSetList
*listOfTimes_: stores the time intervals.
member functions of CApplicationDatabase:
CApplicationDatabase():
Creates all dynamic members.
virtual
~CApplicationDatabase(): Deletes all dynamic members.
INT32 Cardinality
(EDataType type, SINT32 networkID): Returns the number of data entries
for the given network in the appropriate list of the given type.
void Delete
(EDataType type, SINT32 networkID, const CAddr& netAddress, int area):
Deletes the entry. If type is Delay, the area parameter is ignored.
void DeleteAll
(EDataType type, SINT32 networkID): Deletes all entries of the given
type and network.
void DeleteAll
(EDataType type): Deletes all entries of the given type (for all networks).
EBool DeleteAssociation
(SINT32 networkID, SINT32 nodeID): Deletes the network address associated
with the <networkID, nodeID> key from the list of addresses. If there
is no entry, False is returned, else True is returned.
virtual
void Dispose(): If initCalled is True, all dynamic members
are deleted and initCalled is set to False. If initCalled
is already False, the function has no effect.
EBool GetAssociation
(SINT32 networkID, SINT32 nodeID, CAddr& netAddress): Returns
True, if an associated network address exists. In that case, the address
is copied into netAddress. If the association does not exist,
False is returned and netAddress is not modified.
EBool GetAssociation
(SINT32 networkID, const CAddr& netAddress, SINT32* nodeID): Returns
True, if an associated nodeID exists. In that case, the value is copied
into nodeID. If the association does not exist, False is returned
and nodeID is not modified.
EBool GetDelay
(SDelay& delay, SINT32 networkID, const CAddr& netAddress) const:
If the entry exists, it is copied into delay and True is returned.
Else False is returned.
EBool GetFirstDelay
(SDelay& delay, SINT32 networkID): If the delay list is not empty,
the first entry is copied into delay and True is returned. Else
False is returned.
SRate *GetFirstRate
(SINT32 networkID): If the rate list is not empty, the pointer to
the first entry is returned. Else NULL is returned.
EBool GetFirstTime
(STimeInterval& time, SINT32 networkID): If the time list is not
empty, the first entry is copied into time and True is returned.
Else False is returned.
EBool GetNextDelay
(SDelay& delay, SINT32 networkID): If the delay list is not empty
and the last element is not reached, the next entry is copied into delay
and True is returned. Else False is returned.
SRate *GetNextRate
(SINT32 networkID): If the rate list is not empty and the last element
is not reached, the pointer to the next entry is returned. Else NULL is
returned.
EBool GetNextTime
(STimeInterval& time, SINT32 networkID): If the time list is not
empty and the last element is not reached, the next entry is copied into
time and True is returned. Else False is returned.
virtual
EBool GetParameter (SParameter& param) const: Returns True if the
parameter could be read.
SRate *GetRate
(SINT32 networkID, const CAddr& netAddress, int area) const: If
the entry exists, the pointer to it is returned. Else NULL is returned.
EBool GetTime
(STimeInterval& time, SINT32 networkID, const CAddr& netAddress,
int area) const: If the entry exists, it is copied into time
and True is returned. Else False is returned.
virtual
void Init (): If initCalled is False, the function creates
all dynamic members. initCalled is then set to True. If initCalled
is already True, the function has no effect.
EBool RemoveDelay
(SDelay& delay, SINT32 networkID, const CAddr& netAddress):
Remove the entry. If it is found, it is copied into delay and
True is returned, else False is returned.
SRate *RemoveRate
(SINT32 networkID, const CAddr& netAddress, int area): Remove
the entry. If it is found, the pointer is removed from the list and returned.
If it is not found, NULL is returned.
EBool RemoveTime
(STimeInterval& time, SINT32 networkID, const CAddr& netAddress,
int area): Remove the entry. If it is found, it is copied into time
and True is returned, else False is returned.
virtual
void Reset (): Restores the initial state. The function simply calls
Dispose() and then Init().
virtual
EBool SetAssociation (SINT32 networkID, const CAddr& address, SINT32
nodeID): Stores the association <networkID, address,
nodeID>. If another association already exists, the new data is
ignored and False is returned, else the triple is stored and True is returned.
Overload the function in the derived class to obtain different behaviour.
void SetDelay
(const SDelay& delay, SINT32 networkID, const CAddr& netAddress):
Store the delay data. Any old data is overwritten.
virtual
EBool SetParameter (const SParameter& param): Returns True if the
parameter could be set.
void SetRate
(SRate *rate, SINT32 networkID, const CAddr& netAddress, int area):
Store the pointer to the rate data. If there is already an entry stored,
the old data structure is deleted.
void SetTime
(const STimeInterval& time, SINT32 networkID, const CAddr& netAddress,
int area): Store the time data. Any old data is overwritten.