nConfItemVersionWatcher Class Reference

configuration item watcher that shuts out clients that don't support a certain interface More...

#include <nConfig.h>

Inheritance diagram for nConfItemVersionWatcher:

Inheritance graph
[legend]
Collaboration diagram for nConfItemVersionWatcher:

Collaboration graph
[legend]

List of all members.

Public Types

enum  Group {
  Group_Breaking, Group_Bumpy, Group_Annoying, Group_Cheating,
  Group_Visual, Group_Max
}
 enum describing the effect a nondefault setting has on clients that don't support it More...
typedef nConfigItemBehavior Behavior

Public Member Functions

 nConfItemVersionWatcher (nConfItemBase &item, Group group, int min, int max=-1)
 constructor
virtual ~nConfItemVersionWatcher ()
 destructor
Behavior GetBehavior (void) const
 Gets behavior if this setting is on non-default and a client that does not support it connects.
nConfItemVersionWatcher const & GetBehavior (Behavior &behavior) const
 Gets behavior if this setting is on non-default and a client that does not support it connects.
void FillTemplateParameters (tOutput &o) const
 fills output with template parameters about the setting

Static Public Member Functions

static void AdaptVersion (nVersion &version)
 adapt version so it is compatible with all settings
static void OnVersionChange (nVersion const &version)
 revert relevant settings that don't fit with the version to their defaults

Private Member Functions

virtual void OnChange (bool nonDefault)
 called on configuration item changes
virtual bool DoWritable () const
 returns whether the item should be writable

Private Attributes

nVersion version_
 the versions that support this
bool nonDefault_
 flag memorizing whether the setting is at default by the user
bool reverted_
 flag memorizing whether the setting has been reverted to the default temporarily
Group group_
 class of incompatibility
Behavior overrideGroupBehavior_
 if set, the global behavior for the class gets ignored
tSettingItem< BehavioroverrideGroupBehaviorConf_
 setting item for override


Detailed Description

configuration item watcher that shuts out clients that don't support a certain interface

Definition at line 230 of file nConfig.h.


Member Typedef Documentation

typedef nConfigItemBehavior nConfItemVersionWatcher::Behavior

Definition at line 245 of file nConfig.h.


Member Enumeration Documentation

enum nConfItemVersionWatcher::Group

enum describing the effect a nondefault setting has on clients that don't support it

Enumerator:
Group_Breaking  client breaks horribly
Group_Bumpy  client works, but physics are not simulated correctly
Group_Annoying  small, annoying incompatibility
Group_Cheating  the behavior of the old client is considered cheating
Group_Visual  some displayed value is wrong, but everything behaves right
Group_Max 

Definition at line 234 of file nConfig.h.

00235     {
00236         Group_Breaking,  
00237         Group_Bumpy,     
00238         Group_Annoying,  
00239         Group_Cheating,  
00240         Group_Visual,    
00241 
00242         Group_Max
00243     };


Constructor & Destructor Documentation

nConfItemVersionWatcher::nConfItemVersionWatcher ( nConfItemBase item,
Group  c,
int  min,
int  max = -1 
)

constructor

Parameters:
item 
feature 

Definition at line 378 of file nConfig.cpp.

References sn_GetStrongWatchers(), and sn_StrongWatchersAddRef().

00379         : nIConfItemWatcher( item )
00380         , version_( min, max > 0 ? max : 0x7FFFFFFF )
00381         , nonDefault_( false )
00382         , reverted_( false )
00383         , group_( c )
00384         , overrideGroupBehavior_( Behavior_Default )
00385         , overrideGroupBehaviorConf_( item.GetTitle() + "_OVERRIDE", overrideGroupBehavior_ )
00386 {
00387     sn_StrongWatchersAddRef();
00388     sn_GetStrongWatchers().insert(this);
00389 }

Here is the call graph for this function:

nConfItemVersionWatcher::~nConfItemVersionWatcher ( void   )  [virtual]

destructor

Definition at line 400 of file nConfig.cpp.

References sn_GetStrongWatchers(), and sn_StrongWatchersRelease().

00401 {
00402     sn_GetStrongWatchers().erase(this);
00403     sn_StrongWatchersRelease();
00404 }

Here is the call graph for this function:


Member Function Documentation

void nConfItemVersionWatcher::AdaptVersion ( nVersion version  )  [static]

adapt version so it is compatible with all settings

Definition at line 489 of file nConfig.cpp.

References Behavior_Block, con, FillTemplateParameters(), GetBehavior(), nVersion::Merge(), nVersion::Min(), nonDefault_, nSERVER, sn_GetNetState(), sn_GetStrongWatchers(), tVERIFY, and version_.

00490 {
00491     if ( sn_GetNetState() != nSERVER )
00492         return;
00493 
00494     // iterate over all watchers
00495     nStrongWatcherList & watchers = sn_GetStrongWatchers();
00496     for ( nStrongWatcherList::iterator iter = watchers.begin(); iter != watchers.end(); ++iter )
00497     {
00498         nConfItemVersionWatcher * run = *iter;
00499 
00500         // adapt version to needs
00501         if ( run->nonDefault_ && run->GetBehavior() >= Behavior_Block )
00502         {
00503             tVERIFY( version.Merge( version, run->version_ ) );
00504             if ( version.Min() > lastVersion.Min() )
00505             {
00506                 // inform user about potential problem
00507                 tOutput o;
00508                 run->FillTemplateParameters(o);
00509                 o << "$setting_legacy_clientblock";
00510                 con << o;
00511 
00512                 lastVersion = version;
00513             }
00514         }
00515     }
00516 }

Here is the call graph for this function:

void nConfItemVersionWatcher::OnVersionChange ( nVersion const &  version  )  [static]

revert relevant settings that don't fit with the version to their defaults

Parameters:
version the version to adapt the settings to

Definition at line 528 of file nConfig.cpp.

References Behavior_Block, Behavior_Default, Behavior_Nothing, Behavior_Revert, con, FillTemplateParameters(), GetBehavior(), group_, Group_Max, inited, nVersion::Max(), nVersion::Min(), nonDefault_, nSERVER, reverted_, nConfItemBase::RevertToDefaults(), nConfItemBase::RevertToSavedValue(), nConfItemBase::SaveValue(), sn_GetNetState(), sn_GetStrongWatchers(), sn_MyVersion(), version_, and nIConfItemWatcher::watched_.

00529 {
00530     // store version for reference
00531     lastVersion = version;
00532 
00533     if ( sn_GetNetState() != nSERVER )
00534         return;
00535 
00536     // iterate over all watchers
00537     nStrongWatcherList & watchers = sn_GetStrongWatchers();
00538     for ( nStrongWatcherList::iterator iter = watchers.begin(); iter != watchers.end(); ++iter )
00539     {
00540         nConfItemVersionWatcher * run = *iter;
00541 
00542         // warn about settings that will revert or be ignored
00543         Behavior behavior = run->GetBehavior();
00544         if (run->nonDefault_ && behavior != Behavior_Block )
00545         {
00546             // don't warn twice for the same group and behavior
00547             static int warnedRevert[ Behavior_Default ][ Group_Max ];
00548             {
00549                 static bool inited = false;
00550                 if (!inited)
00551                 {
00552                     inited = true;
00553                     for ( int i = Behavior_Default-1; i>=0; --i )
00554                         for ( int j = Group_Max-1; j>=0; --j )
00555                             warnedRevert[i][j] = sn_MyVersion().Min();
00556                 }
00557             }
00558             int & warned = warnedRevert[ behavior ][ run->group_ ];
00559 
00560             if ( warned < run->version_.Min() && run->version_.Min() > version.Min() )
00561             {
00562                 warned = run->version_.Min();
00563 
00564                 // inform user about potential problem with nondefault settings
00565                 tOutput o;
00566                 run->FillTemplateParameters(o);
00567                 o << ( ( behavior == Behavior_Revert ) ? "$setting_legacy_revert" : "$setting_legacy_ignore" );
00568                 con << o;
00569             }
00570         }
00571 
00572         // ignore settings where this is desired
00573         if ( run->GetBehavior() == Behavior_Nothing )
00574             continue;
00575 
00576         // if version is supported..
00577         if ( run->version_.Min() <= version.Max() )
00578         {
00579             // ...restore saved value of config item
00580             if ( run->reverted_ )
00581             {
00582                 run->reverted_ = false;
00583                 run->watched_.RevertToSavedValue();
00584             }
00585         }
00586         else
00587         {
00588             // version is not supported. Revert to defaults.
00589             if ( !run->reverted_ && run->nonDefault_ )
00590             {
00591                 run->reverted_ = true;
00592                 run->watched_.SaveValue();
00593                 run->watched_.RevertToDefaults();
00594             }
00595         }
00596 
00597     }
00598 }

Here is the call graph for this function:

nConfItemVersionWatcher::Behavior nConfItemVersionWatcher::GetBehavior ( void   )  const

Gets behavior if this setting is on non-default and a client that does not support it connects.

Returns:
behavior if this setting is on non-default and a client that does not support it connects

Definition at line 625 of file nConfig.cpp.

References Behavior_Default, group_, Group_Max, overrideGroupBehavior_, sn_GroupBehaviors, and tASSERT.

Referenced by AdaptVersion(), DoWritable(), GetBehavior(), and OnVersionChange().

00626 {
00627     // look up default behavior
00628     tASSERT( 0 <= group_ && group_ < nConfItemVersionWatcher::Group_Max );
00629     Behavior behavior = sn_GroupBehaviors[ group_ ];
00630 
00631     // override it
00632     if ( Behavior_Default != this->overrideGroupBehavior_ )
00633         behavior = this->overrideGroupBehavior_;
00634 
00635     return behavior;
00636 }

Here is the caller graph for this function:

nConfItemVersionWatcher const & nConfItemVersionWatcher::GetBehavior ( Behavior behavior  )  const

Gets behavior if this setting is on non-default and a client that does not support it connects.

Parameters:
behavior behavior if this setting is on non-default and a client that does not support it connects to fill
Returns:
A reference to this to allow chaining

Definition at line 649 of file nConfig.cpp.

References GetBehavior().

00650 {
00651     behavior = this->GetBehavior();
00652     return *this;
00653 }

Here is the call graph for this function:

void nConfItemVersionWatcher::FillTemplateParameters ( tOutput o  )  const

fills output with template parameters about the setting

Parameters:
o output to fill. Template parameter 1 will be the setting name, parameter 2 the setting's group, and parameter 3 the first version supporting the setting

Definition at line 696 of file nConfig.cpp.

References tConfItemBase::GetTitle(), group_, nVersion::Min(), tOutput::SetTemplateParameter(), sn_GetVersionString(), sn_groupName, version_, and nIConfItemWatcher::watched_.

Referenced by AdaptVersion(), DoWritable(), and OnVersionChange().

Here is the call graph for this function:

Here is the caller graph for this function:

void nConfItemVersionWatcher::OnChange ( bool  nonDefault  )  [private, virtual]

called on configuration item changes

Parameters:
nonDefault flag indicating whether the change was away from the default

Implements nIConfItemWatcher.

Definition at line 416 of file nConfig.cpp.

References nonDefault_, and sn_UpdateCurrentVersion().

00417 {
00418     bool changed = ( nonDefault != nonDefault_ );
00419 
00420     nonDefault_ = nonDefault;
00421     if ( changed )
00422     {
00423         sn_UpdateCurrentVersion();
00424     }
00425 }

Here is the call graph for this function:

bool nConfItemVersionWatcher::DoWritable ( void   )  const [private, virtual]

returns whether the item should be writable

Returns:
true if the watched item is changable

Implements nIConfItemWatcher.

Definition at line 665 of file nConfig.cpp.

References Behavior_Revert, con, FillTemplateParameters(), GetBehavior(), nVersion::Max(), nVersion::Min(), sn_CurrentVersion(), and version_.

00666 {
00667     // if we're not set to revert, the setting is writable
00668     if ( GetBehavior() != Behavior_Revert )
00669         return true;
00670 
00671     // and if the setting is currently supported by all parites, it's writable too
00672     if ( version_.Min() <= sn_CurrentVersion().Max() )
00673         return true;
00674 
00675     // inform user about impossible change
00676     tOutput o;
00677     FillTemplateParameters(o);
00678     o << "$setting_legacy_change_blocked";
00679     con << o;
00680 
00681     // only if it's not, it needs to be protected.
00682     return false;
00683 
00684 }

Here is the call graph for this function:


Member Data Documentation

nVersion nConfItemVersionWatcher::version_ [private]

the versions that support this

Definition at line 261 of file nConfig.h.

Referenced by AdaptVersion(), DoWritable(), FillTemplateParameters(), and OnVersionChange().

bool nConfItemVersionWatcher::nonDefault_ [private]

flag memorizing whether the setting is at default by the user

Definition at line 262 of file nConfig.h.

Referenced by AdaptVersion(), OnChange(), and OnVersionChange().

bool nConfItemVersionWatcher::reverted_ [private]

flag memorizing whether the setting has been reverted to the default temporarily

Definition at line 263 of file nConfig.h.

Referenced by OnVersionChange().

Group nConfItemVersionWatcher::group_ [private]

class of incompatibility

Definition at line 265 of file nConfig.h.

Referenced by FillTemplateParameters(), GetBehavior(), and OnVersionChange().

Behavior nConfItemVersionWatcher::overrideGroupBehavior_ [private]

if set, the global behavior for the class gets ignored

Definition at line 266 of file nConfig.h.

Referenced by GetBehavior().

tSettingItem< Behavior > nConfItemVersionWatcher::overrideGroupBehaviorConf_ [private]

setting item for override

Definition at line 267 of file nConfig.h.


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