00001 #ifndef INI_ROLLER_IMPLEMENTATION_FILE
00002 #define INI_ROLLER_IMPLEMENTATION_FILE
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "ini_roller.h"
00019 #include "roller.cpp"
00020
00021 #include <basis/function.h>
00022 #include <basis/istring.h>
00023 #include <basis/mutex.h>
00024 #include <data_struct/configurator.h>
00025
00026
00027
00028
00029 const int ID_FACTOR = 28;
00030
00031
00032 ini_roller::ini_roller(configurator &config, const istring §ion,
00033 const istring &entry, int min, int max)
00034 : _ini(config),
00035 _ids(new int_roller(min, max)),
00036 _section(new istring(section)),
00037 _entry(new istring(entry)),
00038 _lock(new mutex)
00039 {
00040 int current = _ini.load(section, entry, min);
00041 _ids->set_current(current);
00042
00043
00044 _ini.store(section, entry, _ids->current() + ID_FACTOR);
00045 }
00046
00047 ini_roller::~ini_roller()
00048 {
00049
00050 _ini.store(*_section, *_entry, _ids->current() + 1);
00051 WHACK(_ids);
00052 WHACK(_section);
00053 WHACK(_entry);
00054 WHACK(_lock);
00055 }
00056
00057 int ini_roller::current_id() const
00058 {
00059 auto_synchronizer l(*_lock);
00060 return _ids->current();
00061 }
00062
00063 int ini_roller::next_id()
00064 {
00065 FUNCDEF("next_id");
00066 auto_synchronizer l(*_lock);
00067 int to_return = _ids->current();
00068
00069
00070
00071
00072
00073
00074 if ( (_ids->current() < _ids->maximum() - 2)
00075 && (_ids->current() % ID_FACTOR) ) {
00076
00077 _ids->next_id();
00078 #ifdef DEBUG_ID_GRANTING
00079 LOG(istring(istring::SPRINTF, "standard id issue: %d.", to_return));
00080 #endif
00081 return to_return;
00082 }
00083
00084
00085 int new_range = to_return + ID_FACTOR;
00086 #ifdef DEBUG_ID_GRANTING
00087 LOG(istring(istring::SPRINTF, "finding next range, new start in ini "
00088 "is: %d.", new_range));
00089 #endif
00090
00091 if ( (new_range < 0) || (new_range >= _ids->maximum()) )
00092 new_range = ID_FACTOR;
00093 #ifdef DEBUG_ID_GRANTING
00094 LOG(istring(istring::SPRINTF, "after check, new ini id is: %d.",
00095 new_range));
00096 #endif
00097 _ini.store(*_section, *_entry, new_range);
00098
00099 _ids->next_id();
00100 #ifdef DEBUG_ID_GRANTING
00101 LOG(istring(istring::SPRINTF, "after store, id is: %d.", to_return));
00102 #endif
00103 return to_return;
00104 }
00105
00106
00107
00108 #endif //INI_ROLLER_IMPLEMENTATION_FILE
00109