Hi Hung, Ack from me. Reviewed and tested the patch.
Best regards, Zoran -----Original Message----- From: Hung Nguyen [mailto:[email protected]] Sent: Wednesday, September 16, 2015 10:43 AM To: Anders Björnerstedt; Zoran Milinkovic; [email protected] Cc: [email protected] Subject: [PATCH 1 of 1] imm: Don't allow default values to be defined with NO_DANGLING flag when creating classes [#1474] osaf/services/saf/immsv/immnd/ImmModel.cc | 31 +++++++++++++++++++++++++++++-- 1 files changed, 29 insertions(+), 2 deletions(-) Default values are not allowed to be defined with NO_DANGLING flag when creating classes. Existing classes with that kind of definition are still able to be loaded from file. When loading, default values will not be assigned to NULL attributes that have default no-dangling reference. diff --git a/osaf/services/saf/immsv/immnd/ImmModel.cc b/osaf/services/saf/immsv/immnd/ImmModel.cc --- a/osaf/services/saf/immsv/immnd/ImmModel.cc +++ b/osaf/services/saf/immsv/immnd/ImmModel.cc @@ -2844,6 +2844,8 @@ ImmModel::classCreate(const ImmsvOmClass AttrMap newAttrs; AttrMap changedAttrs; ImmsvAttrDefList* list = req->attrDefinitions; + bool isLoading = (sImmNodeState == IMM_NODE_LOADING || /* LOADING-SEVER, LOADING-CLIENT */ + sImmNodeState == IMM_NODE_W_AVAILABLE); /* SYNC-CLIENT */ TRACE_ENTER2("cont:%p connp:%p nodep:%p", continuationIdPtr, pbeConnPtr, pbeNodeIdPtr); size_t sz = strnlen((char *) req->className.buf, (size_t)req->className.size); @@ -3057,6 +3059,16 @@ ImmModel::classCreate(const ImmsvOmClass illegal = 1; } + if (attr->attrFlags & SA_IMM_ATTR_NO_DANGLING) { + if (isLoading) { + LOG_WA("Attribute '%s' of class '%s' has a default no-dangling reference, " + "the class definition should be corrected", attNm, className.c_str()); + } else { + LOG_NO("ERR_INVALID_PARAM: No dangling attribute '%s' can not have a default", attNm); + illegal = 1; + } + } + if(attr->attrFlags & SA_IMM_ATTR_INITIALIZED) { LOG_NO("ERR_INVALID_PARAM: Attribute %s declared as SA_IMM_ATTR_INITIALIZED " "inconsistent with having default", attNm); @@ -6972,14 +6984,20 @@ SaAisErrorT ImmModel::ccbObjectCreate(Im ImmAttrValue* attrValue = NULL; if(attr->mFlags & SA_IMM_ATTR_MULTI_VALUE) { - if(attr->mDefaultValue.empty()) { + if(attr->mDefaultValue.empty() || + (isLoading && (attr->mFlags & SA_IMM_ATTR_NO_DANGLING))) { + /* Don't assign default value to attributes that + * have default no-dangling reference when loading */ attrValue = new ImmAttrMultiValue(); } else { attrValue = new ImmAttrMultiValue(attr->mDefaultValue); } } else { - if(attr->mDefaultValue.empty()) { + if(attr->mDefaultValue.empty() || + (isLoading && (attr->mFlags & SA_IMM_ATTR_NO_DANGLING))) { + /* Don't assign default value to attributes that + * have default no-dangling reference when loading */ attrValue = new ImmAttrValue(); } else { attrValue = new @@ -7152,6 +7170,8 @@ SaAisErrorT ImmModel::ccbObjectCreate(Im //Also: append missing attributes and default values to immsv_attr_values_list //so the generated SaImmOiCcbObjectCreateCallbackT_2 will be complete. See #847. //But dont append non persistent runtime attributes. + // + //Also: write notice message for attributes that have default no-dangling reference isSpecialApplForClass = specialApplyForClass(classInfo); for(i6=object->mAttrValueMap.begin(); @@ -7164,6 +7184,13 @@ SaAisErrorT ImmModel::ccbObjectCreate(Im osafassert(i4!=classInfo->mAttrMap.end()); AttrInfo* attr = i4->second; + if ((attr->mFlags & SA_IMM_ATTR_NO_DANGLING) && + !attr->mDefaultValue.empty() && attrValue->empty()) { + osafassert(isLoading); + LOG_NO("Attribute '%s' of object '%s' is NULL and has a default no-dangling reference, " + "default is not assigned when loading", attrName.c_str(), objectName.c_str()); + } + if((attr->mFlags & SA_IMM_ATTR_INITIALIZED) && attrValue->empty()) { LOG_NO("ERR_INVALID_PARAM: attr '%s' must be initialized " ------------------------------------------------------------------------------ Monitor Your Dynamic Infrastructure at Any Scale With Datadog! Get real-time metrics from all of your servers, apps and tools in one place. SourceForge users - Click here to start your Free Trial of Datadog now! http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140 _______________________________________________ Opensaf-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/opensaf-devel
