fgms 0.11.8
The
FlightGear MultiPlayer Server
project
mT_FG_List< T > Class Template Reference

a generic list implementation for fgms More...

#include <fg_list.hxx>

Public Types

typedef vector< T > ListElements
 
typedef vector< T >::iterator ListIterator
 

Public Member Functions

 mT_FG_List (const string &Name)
 
 ~mT_FG_List ()
 
size_t Add (T &Element, time_t TTL)
 
ListIterator Begin ()
 
void CheckTTL ()
 
void Clear ()
 
ListIterator Delete (const ListIterator &Element)
 
ListIterator End ()
 
ListIterator Find (const netAddress &Address, const string &Name="")
 
ListIterator FindByID (size_t ID)
 
ListIterator FindByName (const string &Name="")
 
void Lock ()
 
operator[] (const size_t &Index)
 
size_t Size ()
 
void Unlock ()
 
void UpdateRcvd (ListIterator &Element, size_t bytes)
 
void UpdateRcvd (size_t bytes)
 
void UpdateSent (ListIterator &Element, size_t bytes)
 
void UpdateSent (size_t bytes)
 

Public Attributes

uint64_t BytesRcvd
 Count of bytes recieved from client. More...
 
uint64_t BytesSent
 Count of bytes sent to client. More...
 
size_t MaxID
 maximum entries this list ever had More...
 
string Name
 
uint64_t PktsRcvd
 Count of packets recieved from client. More...
 
uint64_t PktsSent
 Count of packets sent to client. More...
 

Private Member Functions

 mT_FG_List ()
 

Private Attributes

ListElements Elements
 
time_t LastRun
 timestamp of last cleanup More...
 
pthread_mutex_t m_ListMutex
 mutex for thread safty More...
 

Detailed Description

template<class T>
class mT_FG_List< T >

a generic list implementation for fgms

Definition at line 141 of file fg_list.hxx.

Member Typedef Documentation

template<class T>
typedef vector<T> mT_FG_List< T >::ListElements

Definition at line 144 of file fg_list.hxx.

template<class T>
typedef vector<T>::iterator mT_FG_List< T >::ListIterator

Definition at line 145 of file fg_list.hxx.

Constructor & Destructor Documentation

template<class T >
mT_FG_List< T >::mT_FG_List ( const string &  Name)

constructor, must supply a Name

construct an element and initialise counters

Definition at line 218 of file fg_list.hxx.

template<class T >
mT_FG_List< T >::~mT_FG_List ( )

Definition at line 234 of file fg_list.hxx.

template<class T>
mT_FG_List< T >::mT_FG_List ( )
private

do not allow standard constructor

Member Function Documentation

template<class T>
size_t mT_FG_List< T >::Add ( T &  Element,
time_t  TTL 
)

add an element to this list

thread safe

Add an element to the list

Parameters
Elementthe FG_ListElement to add
TTLautomatic expiry of the element (time-to-live)
See also
Find()

Definition at line 268 of file fg_list.hxx.

Referenced by FG_CLI::cmd_blacklist_add(), FG_CLI::cmd_crossfeed_add(), and FG_CLI::cmd_relay_add().

template<class T >
vector< T >::iterator mT_FG_List< T >::Begin ( )

return an iterator of the first element

NOT thread safe

In general iterators are not thread safe. If you use them you have to ensure propper locking youself!

Returns
the first element of the list. If the list is empty this equals End()

Definition at line 451 of file fg_list.hxx.

template<class T >
void mT_FG_List< T >::CheckTTL ( )

Check entries for expired TTL

thread safe Check entries for expired TTL. All expired entries are removed from the list.

Definition at line 509 of file fg_list.hxx.

template<class T >
void mT_FG_List< T >::Clear ( )

delete all elements of this list

Delete all entries of the list.

Definition at line 657 of file fg_list.hxx.

template<class T >
vector< T >::iterator mT_FG_List< T >::Delete ( const ListIterator Element)

delete an element of this list

thread safe

Delete an entry from the list

Parameters
Elementiterator pointing to the element to delete

Definition at line 292 of file fg_list.hxx.

Referenced by FG_CLI::cmd_blacklist_delete(), FG_CLI::cmd_crossfeed_delete(), and FG_CLI::cmd_relay_delete().

template<class T >
vector< T >::iterator mT_FG_List< T >::End ( )

iterator of the end of the list

Returns
the end of the list (which is not a valid entry!)

Definition at line 465 of file fg_list.hxx.

Referenced by FG_CLI::cmd_blacklist_add(), FG_CLI::cmd_blacklist_delete(), FG_CLI::cmd_crossfeed_add(), FG_CLI::cmd_crossfeed_delete(), FG_CLI::cmd_relay_add(), and FG_CLI::cmd_relay_delete().

template<class T >
vector< T >::iterator mT_FG_List< T >::Find ( const netAddress Address,
const string &  Name = "" 
)

find an element by its IP address

NOT thread safe

Find an element by IP-address (and optionally Name). Automatically removes entries which TTL is expired, with the exception of the 'users' list which entries are deleted in FG_SERVER::HandlePacket()

Parameters
AddressIP address of the element
NameThe name (or description) of the element
Returns
iterator pointing to the found element, or End() if element could not be found

Definition at line 318 of file fg_list.hxx.

Referenced by FG_CLI::cmd_blacklist_add(), FG_CLI::cmd_blacklist_delete(), FG_CLI::cmd_crossfeed_add(), FG_CLI::cmd_crossfeed_delete(), FG_CLI::cmd_relay_add(), and FG_CLI::cmd_relay_delete().

template<class T >
vector< T >::iterator mT_FG_List< T >::FindByID ( size_t  ID)

find an element by its ID

NOT thread safe

Find an element by ID.

Parameters
IDThe ID of the element
Returns
iterator pointing to the found element, or End() if element could not be found

Definition at line 417 of file fg_list.hxx.

Referenced by FG_CLI::cmd_blacklist_delete(), FG_CLI::cmd_crossfeed_delete(), and FG_CLI::cmd_relay_delete().

template<class T >
vector< T >::iterator mT_FG_List< T >::FindByName ( const string &  Name = "")

find an element by its Name

NOT thread safe

Find an element by Name.

Parameters
NameThe name (or description) of the element
Returns
iterator pointing to the found element, or End() if element could not be found

Definition at line 383 of file fg_list.hxx.

template<class T >
void mT_FG_List< T >::Lock ( )

thread lock the list

Set a mutex lock on the list, so concurrent operations are blocked until the lock is released.

See also
Unlock()

Definition at line 481 of file fg_list.hxx.

template<class T >
T mT_FG_List< T >::operator[] ( const size_t &  Index)

return a copy of an element at position x (thread safe)

thread safe Use this for element access whenever possible. However, if you need to modify the element you have to use iterators which are not thread safe and make sure to use Lock() and Unlock() yourself.

Parameters
Indexindex of the element
Returns
a copy the the element at index Index

Definition at line 550 of file fg_list.hxx.

template<class T >
size_t mT_FG_List< T >::Size ( )

return the number of elements in this list

NOT thread safe

Return the number of elements of this list. If working with threads make sure to * use Lock() and Unlock()

See also
Lock()
Unlock()

Definition at line 251 of file fg_list.hxx.

Referenced by FG_CLI::cmd_blacklist_show(), FG_CLI::cmd_crossfeed_show(), FG_CLI::cmd_relay_show(), FG_CLI::cmd_show_stats(), FG_CLI::cmd_user_show(), and FG_SERVER::Show_Stats().

template<class T >
void mT_FG_List< T >::Unlock ( )

thread unlock the list

Release a mutex lock

Definition at line 495 of file fg_list.hxx.

template<class T >
void mT_FG_List< T >::UpdateRcvd ( ListIterator Element,
size_t  bytes 
)

update receive counter of an element and of the list

Update receive-counters of the list and of an element. Every call of this method means we received a single packet (and the packet counter is increased by 1).

Parameters
ElementThe element from which data was received
bytesThe number of bytes received

Definition at line 598 of file fg_list.hxx.

template<class T >
void mT_FG_List< T >::UpdateRcvd ( size_t  bytes)

update receive counter of the list

Update received-counters of the list. Every call of this method means we received a single packet (and the packet counter is increased by 1).

Parameters
bytesThe number of bytes received.

Definition at line 640 of file fg_list.hxx.

template<class T >
void mT_FG_List< T >::UpdateSent ( ListIterator Element,
size_t  bytes 
)

update sent counter of an element and of the list

Update sent-counters of the list and of an element. Every call of this method means we sent a single packet (and the packet counter is increased by 1).

Parameters
ElementThe element to which data was sent
bytesThe number of bytes sent

Definition at line 575 of file fg_list.hxx.

template<class T >
void mT_FG_List< T >::UpdateSent ( size_t  bytes)

update sent counter of the list

Update sent-counters of the list. Every call of this method means we sent a single packet (and the packet counter is increased by 1).

Parameters
bytesThe number of bytes sent

Definition at line 620 of file fg_list.hxx.

Member Data Documentation

template<class T>
uint64_t mT_FG_List< T >::BytesRcvd

Count of bytes recieved from client.

Definition at line 190 of file fg_list.hxx.

Referenced by FG_CLI::cmd_blacklist_show(), FG_CLI::cmd_relay_show(), FG_CLI::cmd_show_stats(), and FG_CLI::cmd_user_show().

template<class T>
uint64_t mT_FG_List< T >::BytesSent

Count of bytes sent to client.

Definition at line 192 of file fg_list.hxx.

Referenced by FG_CLI::cmd_crossfeed_show(), FG_CLI::cmd_relay_show(), FG_CLI::cmd_show_stats(), and FG_CLI::cmd_user_show().

template<class T>
ListElements mT_FG_List< T >::Elements
private

the actual storage of elements

Definition at line 203 of file fg_list.hxx.

template<class T>
time_t mT_FG_List< T >::LastRun
private

timestamp of last cleanup

Definition at line 199 of file fg_list.hxx.

template<class T>
pthread_mutex_t mT_FG_List< T >::m_ListMutex
private

mutex for thread safty

Definition at line 197 of file fg_list.hxx.

template<class T>
size_t mT_FG_List< T >::MaxID

maximum entries this list ever had

Definition at line 184 of file fg_list.hxx.

template<class T>
string mT_FG_List< T >::Name

the name (or description) of this element

Definition at line 194 of file fg_list.hxx.

Referenced by FG_CLI::cmd_blacklist_show(), FG_CLI::cmd_crossfeed_show(), FG_CLI::cmd_relay_show(), and FG_CLI::cmd_user_show().

template<class T>
uint64_t mT_FG_List< T >::PktsRcvd

Count of packets recieved from client.

Definition at line 186 of file fg_list.hxx.

Referenced by FG_CLI::cmd_blacklist_show(), FG_CLI::cmd_relay_show(), FG_CLI::cmd_show_stats(), and FG_CLI::cmd_user_show().

template<class T>
uint64_t mT_FG_List< T >::PktsSent

Count of packets sent to client.

Definition at line 188 of file fg_list.hxx.

Referenced by FG_CLI::cmd_crossfeed_show(), FG_CLI::cmd_relay_show(), FG_CLI::cmd_show_stats(), and FG_CLI::cmd_user_show().


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