Fix restore_attribute not working in clusters

fixes #10386
This commit is contained in:
Michael Friedrich 2015-10-22 14:32:14 +02:00
parent 65a9ee0dbb
commit d516d16c9a
3 changed files with 32 additions and 3 deletions

View File

@ -232,7 +232,7 @@ void ConfigObject::ModifyAttribute(const String& attr, const Value& value, bool
NotifyOriginalAttributes();
}
void ConfigObject::RestoreAttribute(const String& attr)
void ConfigObject::RestoreAttribute(const String& attr, bool updateVersion)
{
Type::Ptr type = GetReflectionType();
@ -344,7 +344,8 @@ void ConfigObject::RestoreAttribute(const String& attr)
original_attributes->Remove(attr);
SetField(fid, newValue);
SetVersion(Utility::GetTime());
if (updateVersion)
SetVersion(Utility::GetTime());
}
bool ConfigObject::IsAttributeModified(const String& attr) const

View File

@ -54,7 +54,7 @@ public:
void ClearExtension(const String& key);
void ModifyAttribute(const String& attr, const Value& value, bool updateVersion = true);
void RestoreAttribute(const String& attr);
void RestoreAttribute(const String& attr, bool updateVersion = true);
bool IsAttributeModified(const String& attr) const;
void Register(void);

View File

@ -164,6 +164,28 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin
}
}
/* check whether original attributes changed and restore them locally */
Array::Ptr newOriginalAttributes = params->Get("original_attributes");
Dictionary::Ptr objOriginalAttributes = object->GetOriginalAttributes();
if (newOriginalAttributes && objOriginalAttributes) {
std::vector<String> restoreAttrs;
{
ObjectLock xlock(objOriginalAttributes);
BOOST_FOREACH(const Dictionary::Pair& kv, objOriginalAttributes) {
/* original attribute was removed, restore it */
if (!newOriginalAttributes->Contains(kv.first))
restoreAttrs.push_back(kv.first);
}
}
BOOST_FOREACH(const String& key, restoreAttrs) {
/* do not update the object version yet. */
object->RestoreAttribute(key, false);
}
}
/* keep the object version in sync with the sender */
object->SetVersion(objVersion, false, origin);
@ -278,6 +300,7 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
Dictionary::Ptr original_attributes = object->GetOriginalAttributes();
Dictionary::Ptr modified_attributes = new Dictionary();
Array::Ptr newOriginalAttributes = new Array();
if (original_attributes) {
ObjectLock olock(original_attributes);
@ -291,11 +314,16 @@ void ApiListener::UpdateConfigObject(const ConfigObject::Ptr& object, const Mess
}
modified_attributes->Set(kv.first, value);
newOriginalAttributes->Add(kv.first);
}
}
params->Set("modified_attributes", modified_attributes);
/* only send the original attribute keys */
params->Set("original_attributes", newOriginalAttributes);
message->Set("params", params);
#ifdef I2_DEBUG