Bugfix for restoring objects from the retention.dat file.

This commit is contained in:
Gunnar Beutner 2012-08-04 14:13:04 +02:00
parent 1de42d08f2
commit d8be3f088f
3 changed files with 34 additions and 4 deletions

View File

@ -436,7 +436,7 @@ void DynamicObject::RestoreObjects(const String& filename)
bool hasConfig = persistentObject->Contains("configTx"); bool hasConfig = persistentObject->Contains("configTx");
Dictionary::Ptr update = persistentObject->Get("update"); Dictionary::Ptr update = persistentObject->Get("update");
if (hasConfig) { if (hasConfig && ClassExists(type)) {
DynamicObject::Ptr object = Create(type, update); DynamicObject::Ptr object = Create(type, update);
object->Register(); object->Register();
} else { } else {
@ -466,6 +466,37 @@ void DynamicObject::RegisterClass(const String& type, DynamicObject::Factory fac
type + "': Objects of this type already exist.")); type + "': Objects of this type already exist."));
GetClasses()[type] = factory; GetClasses()[type] = factory;
/* restore persistent objects that match the newly-registered class */
map<pair<String, String>, Dictionary::Ptr>::iterator prev, st;
for (st = m_PersistentUpdates.begin(); st != m_PersistentUpdates.end(); st++)
{
/* check type of the update */
if (st->first.first != type) {
st++;
continue;
}
Dictionary::Ptr update = st->second;
bool hasConfig = update->Contains("configTx");
if (!hasConfig) {
st++;
continue;
}
DynamicObject::Ptr object = Create(type, update);
object->Register();
prev = st;
st++;
m_PersistentUpdates.erase(prev);
}
}
bool DynamicObject::ClassExists(const String& type)
{
return (GetClasses().find(type) != GetClasses().end());
} }
DynamicObject::Ptr DynamicObject::Create(const String& type, const Dictionary::Ptr& serializedUpdate) DynamicObject::Ptr DynamicObject::Create(const String& type, const Dictionary::Ptr& serializedUpdate)
@ -521,4 +552,4 @@ void DynamicObject::FinishTx(void)
} }
void DynamicObject::OnAttributeChanged(const String& name, const Value& oldValue) void DynamicObject::OnAttributeChanged(const String& name, const Value& oldValue)
{ } { }

View File

@ -118,6 +118,7 @@ public:
static void RestoreObjects(const String& filename); static void RestoreObjects(const String& filename);
static void RegisterClass(const String& type, Factory factory); static void RegisterClass(const String& type, Factory factory);
static bool ClassExists(const String& type);
static DynamicObject::Ptr Create(const String& type, const Dictionary::Ptr& serializedUpdate); static DynamicObject::Ptr Create(const String& type, const Dictionary::Ptr& serializedUpdate);
static double GetCurrentTx(void); static double GetCurrentTx(void);

View File

@ -160,8 +160,6 @@ void CheckerComponent::CheckerChangedHandler(const Service::Ptr& service)
if (m_PendingServices.find(service) != m_PendingServices.end()) if (m_PendingServices.find(service) != m_PendingServices.end())
return; return;
service->UpdateNextCheck();
m_IdleServices.insert(service); m_IdleServices.insert(service);
} else { } else {
m_IdleServices.erase(service); m_IdleServices.erase(service);