From 37a911cc7e766ea7e9f1dbb8b71fd70e726dd93e Mon Sep 17 00:00:00 2001 From: Jen Chitty Date: Fri, 5 Jul 2019 17:17:37 -0700 Subject: [PATCH] Fix placeholder interfering with I/O creation When a placeholder exists before an Input or Output is created, the data type and units of the placeholder were getting copied over the data type and units of the Input or Output. --- components/dataHub/resTree.c | 3 ++- components/dataHub/resource.c | 42 +++++++++++++++++++++++++++++------ components/dataHub/resource.h | 3 ++- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/components/dataHub/resTree.c b/components/dataHub/resTree.c index 392f6a3..da6b834 100644 --- a/components/dataHub/resTree.c +++ b/components/dataHub/resTree.c @@ -310,7 +310,7 @@ static void ReplaceResource // Note that this may result in lost settings. For example, Placeholders don't have // filter settings, but Observations do, so moving settings from an Observation to a // Placeholder will lose the Observation's filter settings. - res_MoveAdminSettings(entryRef->resourcePtr, replacementPtr); + res_MoveAdminSettings(entryRef->resourcePtr, replacementPtr, replacementType); // Delete the original resource. le_mem_Release(entryRef->resourcePtr); @@ -549,6 +549,7 @@ resTree_EntryRef_t resTree_GetInput { // If a Namespace or Placeholder currently resides at that spot in the tree, replace it with // an Input. + // NOTE: If a new entry was created for this, it will be a Namespace entry. case ADMIN_ENTRY_TYPE_NAMESPACE: case ADMIN_ENTRY_TYPE_PLACEHOLDER: { diff --git a/components/dataHub/resource.c b/components/dataHub/resource.c index 6a56644..5e360e8 100644 --- a/components/dataHub/resource.c +++ b/components/dataHub/resource.c @@ -739,20 +739,48 @@ bool res_HasAdminSettings void res_MoveAdminSettings ( res_Resource_t* srcPtr, ///< Move settings from this entry - res_Resource_t* destPtr ///< Move settings to this entry + res_Resource_t* destPtr, ///< Move settings to this entry + admin_EntryType_t replacementType ///< The type of the replacement resource. ) //-------------------------------------------------------------------------------------------------- { LE_ASSERT(srcPtr->entryRef != NULL); LE_ASSERT(destPtr->entryRef != NULL); - // Copy over the units string. - LE_ASSERT(LE_OK == le_utf8_Copy(destPtr->units, srcPtr->units, sizeof(destPtr->units), NULL)); + // If the destination is an Input or Output, it must be treated differently to other types + // of resources because the app that creates it has the final authority on what its data type + // and units are, and therefore we + // - don't want to clobber whatever data type and units the app has specified for its I/O, and + // - we have to check for data type compatibility before moving over the current value data + // sample (if any) to an Input or an Output. + if ((replacementType == ADMIN_ENTRY_TYPE_INPUT) || (replacementType == ADMIN_ENTRY_TYPE_OUTPUT)) + { + // If the old resource has a current value, + if (srcPtr->currentValue != NULL) + { + // If the data type is a match for the new resource, move the current value over. + if (srcPtr->currentType == destPtr->currentType) + { + destPtr->currentValue = srcPtr->currentValue; + srcPtr->currentValue = NULL; // dest took the reference count + } + else // The data type doesn't match, so drop the old resource's current value. + { + le_mem_Release(srcPtr->currentValue); + srcPtr->currentValue = NULL; + } + } + } + else // *Not* an Input or Output, + { + // Copy over the units string. + SetUnits(destPtr, srcPtr->units); - // Move the current value - destPtr->currentType = srcPtr->currentType; - destPtr->currentValue = srcPtr->currentValue; - srcPtr->currentValue = NULL; // dest took the reference count + // Move the current value (the new resource takes on the data type of the old resource). + destPtr->currentType = srcPtr->currentType; + destPtr->currentValue = srcPtr->currentValue; + srcPtr->currentValue = NULL; // dest took the reference count + } // Move the last pushed value destPtr->pushedType = srcPtr->pushedType; diff --git a/components/dataHub/resource.h b/components/dataHub/resource.h index 8c7d51a..20e8a08 100644 --- a/components/dataHub/resource.h +++ b/components/dataHub/resource.h @@ -317,7 +317,8 @@ bool res_HasAdminSettings void res_MoveAdminSettings ( res_Resource_t* srcPtr, ///< Move settings from this resource - res_Resource_t* destPtr ///< Move settings to this resource + res_Resource_t* destPtr, ///< Move settings to this resource + admin_EntryType_t replacementType ///< The type of the replacement resource. );