in serializer/src/codefirst.c [208:361]
static CODEFIRST_RESULT buildModel(SCHEMA_HANDLE schemaHandle, const REFLECTED_DATA_FROM_DATAPROVIDER* reflectedData, const REFLECTED_SOMETHING* modelReflectedData)
{
CODEFIRST_RESULT result = CODEFIRST_OK;
const REFLECTED_SOMETHING* something;
SCHEMA_MODEL_TYPE_HANDLE modelTypeHandle;
modelTypeHandle = Schema_GetModelByName(schemaHandle, modelReflectedData->what.model.name);
if (modelTypeHandle == NULL)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("cannot get model %s %s", modelReflectedData->what.model.name, MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
for (something = reflectedData->reflectedData; something != NULL; something = something->next)
{
/* looking for all elements that belong to a model: properties and actions */
if ((something->type == REFLECTION_PROPERTY_TYPE) &&
(strcmp(something->what.property.modelName, modelReflectedData->what.model.name) == 0))
{
SCHEMA_MODEL_TYPE_HANDLE childModelHande = Schema_GetModelByName(schemaHandle, something->what.property.type);
/* if this is a model type use the appropriate APIs for it */
if (childModelHande != NULL)
{
if (Schema_AddModelModel(modelTypeHandle, something->what.property.name, childModelHande, something->what.property.offset, NULL) != SCHEMA_OK)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add model failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
}
else
{
if (Schema_AddModelProperty(modelTypeHandle, something->what.property.name, something->what.property.type) != SCHEMA_OK)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add property failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
}
}
if ((something->type == REFLECTION_REPORTED_PROPERTY_TYPE) &&
(strcmp(something->what.reportedProperty.modelName, modelReflectedData->what.model.name) == 0))
{
SCHEMA_MODEL_TYPE_HANDLE childModelHande = Schema_GetModelByName(schemaHandle, something->what.reportedProperty.type);
/* if this is a model type use the appropriate APIs for it */
if (childModelHande != NULL)
{
if (Schema_AddModelModel(modelTypeHandle, something->what.reportedProperty.name, childModelHande, something->what.reportedProperty.offset, NULL) != SCHEMA_OK)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add model failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
}
else
{
if (Schema_AddModelReportedProperty(modelTypeHandle, something->what.reportedProperty.name, something->what.reportedProperty.type) != SCHEMA_OK)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add reported property failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
}
}
if ((something->type == REFLECTION_DESIRED_PROPERTY_TYPE) &&
(strcmp(something->what.desiredProperty.modelName, modelReflectedData->what.model.name) == 0))
{
SCHEMA_MODEL_TYPE_HANDLE childModelHande = Schema_GetModelByName(schemaHandle, something->what.desiredProperty.type);
/* if this is a model type use the appropriate APIs for it */
if (childModelHande != NULL)
{
if (Schema_AddModelModel(modelTypeHandle, something->what.desiredProperty.name, childModelHande, something->what.desiredProperty.offset, something->what.desiredProperty.onDesiredProperty) != SCHEMA_OK)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add model failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
}
else
{
if (Schema_AddModelDesiredProperty(modelTypeHandle,
something->what.desiredProperty.name,
something->what.desiredProperty.type,
something->what.desiredProperty.FromAGENT_DATA_TYPE,
something->what.desiredProperty.desiredPropertInitialize,
something->what.desiredProperty.desiredPropertDeinitialize,
something->what.desiredProperty.offset,
something->what.desiredProperty.onDesiredProperty) != SCHEMA_OK)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add desired property failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
}
}
if ((something->type == REFLECTION_ACTION_TYPE) &&
(strcmp(something->what.action.modelName, modelReflectedData->what.model.name) == 0))
{
SCHEMA_ACTION_HANDLE actionHandle;
size_t i;
if ((actionHandle = Schema_CreateModelAction(modelTypeHandle, something->what.action.name)) == NULL)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add model action failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
for (i = 0; i < something->what.action.nArguments; i++)
{
if (Schema_AddModelActionArgument(actionHandle, something->what.action.arguments[i].name, something->what.action.arguments[i].type) != SCHEMA_OK)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add model action argument failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
}
}
if ((something->type == REFLECTION_METHOD_TYPE) &&
(strcmp(something->what.method.modelName, modelReflectedData->what.model.name) == 0))
{
SCHEMA_METHOD_HANDLE methodHandle;
size_t i;
if ((methodHandle = Schema_CreateModelMethod(modelTypeHandle, something->what.method.name)) == NULL)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add model method failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
for (i = 0; i < something->what.method.nArguments; i++)
{
if (Schema_AddModelMethodArgument(methodHandle, something->what.method.arguments[i].name, something->what.method.arguments[i].type) != SCHEMA_OK)
{
result = CODEFIRST_SCHEMA_ERROR;
LogError("add model method argument failed %s", MU_ENUM_TO_STRING(CODEFIRST_RESULT, result));
goto out;
}
}
}
}
out:
return result;
}