in src/adapters/mc/OsConfigResource.c [392:497]
static MI_Result GetReportedObjectValueFromDevice(const char* who, const char* componentName, MI_Context* context)
{
JSON_Value* jsonValue = NULL;
const char* jsonString = NULL;
char* objectValue = NULL;
int objectValueLength = 0;
char* payloadString = NULL;
int mpiResult = MPI_OK;
MI_Result miResult = MI_RESULT_OK;
if (NULL == componentName)
{
LogError(context, miResult, GetLog(), "[%s] GetReportedObjectValueFromDevice called with an invalid component name", who);
return MI_RESULT_INVALID_PARAMETER;
}
// If this reported object has a corresponding init object, initalize it with the desired object value
if ((NULL != g_initObjectName) && (0 != strcmp(g_initObjectName, g_defaultValue)) &&
(NULL != g_desiredObjectValue) && (0 != strcmp(g_desiredObjectValue, g_defaultValue)))
{
SetDesiredObjectValueToDevice(who, componentName, g_initObjectName, g_desiredObjectValue, context);
}
mpiResult = BaselineMmiGet(componentName, g_reportedObjectName, &objectValue, &objectValueLength, MAX_PAYLOAD_LENGTH, GetLog());
LogInfo(context, GetLog(), "[%s] BaselineMmiGet(%s, %s): '%s' (%d)", who, componentName, g_reportedObjectName, objectValue, objectValueLength);
if (MPI_OK != mpiResult)
{
if (NULL == g_mpiHandle)
{
g_mpiHandle = RefreshMpiClientSession(g_mpiHandle, context);
}
if (NULL != g_mpiHandle)
{
mpiResult = CallMpiGet(componentName, g_reportedObjectName, &objectValue, &objectValueLength, GetLog());
LogInfo(context, GetLog(), "[%s] CallMpiGet(%s, %s): '%s' (%d)", who, componentName, g_reportedObjectName, objectValue, objectValueLength);
}
}
if (MPI_OK == mpiResult)
{
if (NULL == objectValue)
{
mpiResult = ENODATA;
miResult = MI_RESULT_FAILED;
LogError(context, miResult, GetLog(), "[%s] CallMpiGet(%s, %s): no payload (%s, %d) (%d)",
who, componentName, g_reportedObjectName, objectValue, objectValueLength, mpiResult);
}
else
{
if (NULL != (payloadString = malloc(objectValueLength + 1)))
{
memset(payloadString, 0, objectValueLength + 1);
memcpy(payloadString, objectValue, objectValueLength);
if (NULL != (jsonValue = json_parse_string(payloadString)))
{
jsonString = json_value_get_string(jsonValue);
if (jsonString)
{
FREE_MEMORY(g_reportedObjectValue);
if (NULL == (g_reportedObjectValue = DuplicateString(jsonString)))
{
mpiResult = ENOMEM;
miResult = MI_RESULT_FAILED;
LogError(context, miResult, GetLog(), "[%s] DuplicateString(%s) failed", who, jsonString);
}
}
else
{
mpiResult = EINVAL;
miResult = MI_RESULT_INVALID_PARAMETER;
LogError(context, miResult, GetLog(), "[%s] json_value_get_string(%s) failed", who, payloadString);
}
json_value_free(jsonValue);
}
else
{
mpiResult = EINVAL;
miResult = MI_RESULT_INVALID_PARAMETER;
LogError(context, miResult, GetLog(), "[%s] json_parse_string(%s) failed", who, payloadString);
}
FREE_MEMORY(payloadString);
}
else
{
mpiResult = ENOMEM;
miResult = MI_RESULT_FAILED;
LogError(context, miResult, GetLog(), "[%s] Failed to allocate %d bytes", who, objectValueLength + 1);
}
FREE_MEMORY(objectValue);
}
}
else
{
miResult = MI_RESULT_FAILED;
}
g_reportedMpiResult = mpiResult;
return miResult;
}