nConfItemBase Class Reference

base clas for network configuration items More...

#include <nConfig.h>

Inheritance diagram for nConfItemBase:

Inheritance graph
[legend]
Collaboration diagram for nConfItemBase:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 nConfItemBase (const char *title)
virtual ~nConfItemBase ()
virtual void NetReadVal (nMessage &m)=0
virtual void NetWriteVal (nMessage &m)=0
virtual void WasChanged (bool nonDefault)
virtual bool Writable ()
void SendConfig (bool force=true, int peer=-1)
void RevertToDefaults ()
 revert this setting to its default
void SaveValue ()
 saves value for later restoring
void RevertToSavedValue ()
 reverts to the saved value

Static Public Member Functions

static void s_GetConfigMessage (nMessage &m)
static void s_SendConfig (bool force=true, int peer=-1)
static void s_RevertToDefaults ()
 revert all settings to defaults defined in the code
static void s_SaveValues ()
 saves all values for later restoring
static void s_RevertToSavedValues ()
 reverts all settings to the saved values

Protected Member Functions

 nConfItemBase ()

Private Member Functions

virtual void OnRevertToDefaults ()=0
 revert this setting to its default
virtual void OnSaveValue ()=0
 saves value for later restoring
virtual void OnRevertToSavedValue ()=0
 reverts to the saved value

Private Attributes

double lastChangeTime_
 the time of the last change
unsigned long lastChangeMessage_
 the ID of the networking message responsible for the change
nIConfItemWatcherwatcher_
 the watcher that reacts on changes of this item

Friends

class nIConfItemWatcher


Detailed Description

base clas for network configuration items

Definition at line 69 of file nConfig.h.


Constructor & Destructor Documentation

nConfItemBase::nConfItemBase (  )  [protected]

Definition at line 35 of file nConfig.cpp.

nConfItemBase::nConfItemBase ( const char *  title  ) 

Definition at line 41 of file nConfig.cpp.

nConfItemBase::~nConfItemBase (  )  [virtual]

Definition at line 44 of file nConfig.cpp.

00044 {}


Member Function Documentation

virtual void nConfItemBase::NetReadVal ( nMessage m  )  [pure virtual]

Implemented in nConfItem< T >, and nConfItem< tString >.

Referenced by s_GetConfigMessage().

Here is the caller graph for this function:

virtual void nConfItemBase::NetWriteVal ( nMessage m  )  [pure virtual]

Implemented in nConfItem< T >, and nConfItem< tString >.

Referenced by SendConfig().

Here is the caller graph for this function:

void nConfItemBase::s_GetConfigMessage ( nMessage m  )  [static]

Definition at line 46 of file nConfig.cpp.

References con, tConfItemBase::ConfItemMap(), lastChangeMessage_, lastChangeTime_, nMessage::MessageIDBig(), NetReadVal(), nReadError(), nSERVER, sn_GetNetState(), sn_Update(), and tSysTimeFloat().

00046                                                  {
00047     if (sn_GetNetState()==nSERVER){
00048         nReadError(); // never accept config messages from the clients
00049     }
00050     else{
00051         tString name;
00052         m >> name;
00053 
00054         //con << "got conf message for " << name << "\n";
00055 
00056         tConfItemMap & confmap = ConfItemMap();
00057         tConfItemMap::iterator iter = confmap.find( name );
00058         if ( iter != confmap.end() )
00059         {
00060             tConfItemBase * item = (*iter).second;
00061             nConfItemBase *netitem = dynamic_cast<nConfItemBase*> (item);
00062             if (netitem)
00063             {
00064                 // check if message was new
00065                 if ( tSysTimeFloat() > netitem->lastChangeTime_ + 100 || sn_Update( netitem->lastChangeMessage_, m.MessageIDBig() ) )
00066                 {
00067                     netitem->lastChangeMessage_ = m.MessageIDBig();
00068                     netitem->lastChangeTime_ = tSysTimeFloat();
00069                     netitem->NetReadVal(m);
00070                 }
00071                 else
00072                 {
00073                     static bool warn = true;
00074                     if ( warn )
00075                         con << tOutput( "$nconfig_error_ignoreold", name );
00076                     warn = false;
00077                 }
00078             }
00079             else
00080             {
00081                 static bool warn = true;
00082                 if ( warn )
00083                     con << tOutput( "$nconfig_error_nonet", name );
00084                 warn = false;
00085             }
00086         }
00087         else
00088         {
00089             static bool warn = true;
00090             if ( warn )
00091                 con << tOutput( "$nconfig_error_unknown", name );
00092             warn = false;
00093         }
00094     }
00095 }

Here is the call graph for this function:

void nConfItemBase::WasChanged ( bool  nonDefault  )  [virtual]

Definition at line 132 of file nConfig.cpp.

References nIConfItemWatcher::Change(), SendConfig(), and watcher_.

00132                                                {
00133     // inform watcher
00134     if (this->watcher_ )
00135         this->watcher_->Change( nonDefault );
00136 
00137     SendConfig();
00138 }

Here is the call graph for this function:

bool nConfItemBase::Writable ( void   )  [virtual]

Reimplemented from tConfItemBase.

Definition at line 140 of file nConfig.cpp.

References nCLIENT, sn_GetNetState(), watcher_, and nIConfItemWatcher::Writable().

00141 {
00142     // network settings are read only on the client
00143     if ( sn_GetNetState() == nCLIENT )
00144         return false;
00145 
00146     // on the server, we need to check for a watcher...
00147     if ( !watcher_ )
00148         return true;
00149 
00150     // delegate
00151     return watcher_->Writable();
00152 }

Here is the call graph for this function:

void nConfItemBase::s_SendConfig ( bool  force = true,
int  peer = -1 
) [static]

Definition at line 101 of file nConfig.cpp.

References tConfItemBase::ConfItemMap(), nSERVER, SendConfig(), and sn_GetNetState().

Referenced by gGame::StateUpdate().

00101                                                     {
00102     if(sn_GetNetState()==nSERVER){
00103         tConfItemMap & confmap = ConfItemMap();
00104         for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
00105         {
00106             tConfItemBase * item = (*iter).second;
00107 
00108             nConfItemBase *netitem = dynamic_cast<nConfItemBase*> (item);
00109             if (netitem)
00110                 netitem->SendConfig(force, peer);
00111         }
00112     }
00113 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nConfItemBase::SendConfig ( bool  force = true,
int  peer = -1 
)

Definition at line 115 of file nConfig.cpp.

References nMessage::BroadCast(), tConfItemBase::changed, NetWriteVal(), nSERVER, nMessage::Send(), sn_GetNetState(), tConfItemBase::title, and transferConfig.

Referenced by s_SendConfig(), and WasChanged().

00115                                                   {
00116     if ( (changed || force) && sn_GetNetState()==nSERVER)
00117     {
00118         //con << "sending conf message for " << tConfItems(i)->title << "\n";
00119         nMessage *m=new nMessage(transferConfig);
00120         *m << title;
00121         NetWriteVal(*m);
00122         if (peer==-1)
00123         {
00124             m->BroadCast();
00125             changed = false;
00126         }
00127         else
00128             m->Send(peer);
00129     }
00130 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nConfItemBase::s_RevertToDefaults ( void   )  [static]

revert all settings to defaults defined in the code

Definition at line 163 of file nConfig.cpp.

References tConfItemBase::ConfItemMap(), and RevertToDefaults().

Referenced by gSettingsReverter::gSettingsReverter().

00164 {
00165     tConfItemMap & confmap = ConfItemMap();
00166     for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
00167     {
00168         tConfItemBase * item = (*iter).second;
00169         nConfItemBase *netitem = dynamic_cast<nConfItemBase*> (item);
00170         if (netitem)
00171         {
00172             netitem->RevertToDefaults();
00173         }
00174     }
00175 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nConfItemBase::RevertToDefaults ( void   )  [inline]

revert this setting to its default

Definition at line 316 of file nConfig.h.

References nIConfItemWatcher::Change(), lastChangeMessage_, lastChangeTime_, OnRevertToDefaults(), and watcher_.

Referenced by nConfItemVersionWatcher::OnVersionChange(), and s_RevertToDefaults().

00317 {
00318     // inform watcher
00319     if (this->watcher_ )
00320         this->watcher_->Change( false );
00321 
00322     // reset last change information
00323     lastChangeMessage_ = 0;
00324     lastChangeTime_ = -1000000;
00325 
00326     this->OnRevertToDefaults();
00327 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nConfItemBase::s_SaveValues ( void   )  [static]

saves all values for later restoring

Definition at line 186 of file nConfig.cpp.

References tConfItemBase::ConfItemMap(), and SaveValue().

Referenced by gSettingsReverter::gSettingsReverter().

00187 {
00188     tConfItemMap & confmap = ConfItemMap();
00189     for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
00190     {
00191         tConfItemBase * item = (*iter).second;
00192         nConfItemBase *netitem = dynamic_cast<nConfItemBase*> (item);
00193         if (netitem)
00194         {
00195             netitem->SaveValue();
00196         }
00197     }
00198 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nConfItemBase::SaveValue ( void   )  [inline]

saves value for later restoring

Definition at line 338 of file nConfig.h.

References OnSaveValue().

Referenced by nConfItemVersionWatcher::OnVersionChange(), and s_SaveValues().

00339 {
00340     this->OnSaveValue();
00341 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nConfItemBase::s_RevertToSavedValues ( void   )  [static]

reverts all settings to the saved values

Definition at line 209 of file nConfig.cpp.

References tConfItemBase::ConfItemMap(), and RevertToSavedValue().

Referenced by gSettingsReverter::~gSettingsReverter().

00210 {
00211     tConfItemMap & confmap = ConfItemMap();
00212     for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
00213     {
00214         tConfItemBase * item = (*iter).second;
00215         nConfItemBase *netitem = dynamic_cast<nConfItemBase*> (item);
00216         if (netitem)
00217         {
00218             netitem->RevertToSavedValue();
00219         }
00220     }
00221 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nConfItemBase::RevertToSavedValue ( void   )  [inline]

reverts to the saved value

Definition at line 352 of file nConfig.h.

References OnRevertToSavedValue().

Referenced by nConfItemVersionWatcher::OnVersionChange(), and s_RevertToSavedValues().

00353 {
00354     this->OnRevertToSavedValue();
00355 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void nConfItemBase::OnRevertToDefaults (  )  [private, pure virtual]

revert this setting to its default

Implemented in nConfItem< T >, and nConfItem< tString >.

Referenced by RevertToDefaults().

Here is the caller graph for this function:

virtual void nConfItemBase::OnSaveValue (  )  [private, pure virtual]

saves value for later restoring

Implemented in nConfItem< T >, and nConfItem< tString >.

Referenced by SaveValue().

Here is the caller graph for this function:

virtual void nConfItemBase::OnRevertToSavedValue (  )  [private, pure virtual]

reverts to the saved value

Implemented in nConfItem< T >, and nConfItem< tString >.

Referenced by RevertToSavedValue().

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nIConfItemWatcher [friend]

Definition at line 71 of file nConfig.h.


Member Data Documentation

double nConfItemBase::lastChangeTime_ [private]

the time of the last change

Definition at line 73 of file nConfig.h.

Referenced by RevertToDefaults(), and s_GetConfigMessage().

unsigned long nConfItemBase::lastChangeMessage_ [private]

the ID of the networking message responsible for the change

Definition at line 74 of file nConfig.h.

Referenced by RevertToDefaults(), and s_GetConfigMessage().

nIConfItemWatcher* nConfItemBase::watcher_ [private]

the watcher that reacts on changes of this item

Definition at line 75 of file nConfig.h.

Referenced by nIConfItemWatcher::nIConfItemWatcher(), RevertToDefaults(), WasChanged(), Writable(), and nIConfItemWatcher::~nIConfItemWatcher().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:47:21 2008 for Armagetron Advanced by  doxygen 1.5.4