void fmi1_import_free(fmi1_import_t* fmu) { jm_callbacks* cb = fmu->callbacks; if(!fmu) return; jm_log_verbose( fmu->callbacks, "FMILIB", "Releasing allocated library resources"); fmi1_import_destroy_dllfmu(fmu); fmi1_xml_free_model_description(fmu->md); jm_vector_free_data(char)(&fmu->logMessageBuffer); cb->free(fmu->dirPath); cb->free(fmu->location); cb->free(fmu); }
int main(int argc, char *argv[]) { fmiCallbackFunctions callBackFunctions; fmi_dll_t* fmu; const char* FMUPath = "C:\\P510-JModelica\\FMIToolbox\\trunk\\src\\wrapperfolder\\Furuta.fmu"; const char* tmpPath = "C:\\Documents and Settings\\p418_baa\\Desktop\\XMLtest\\temporaryfolder"; const char* dllPath; const char* modelIdentifier; const char* modelName; const char* model_description_path; const char* instanceName; const char* GUID; fmi_dll_standard_enu_t standard = FMI_ME1; /* or FMI_CS1 */ fmiBoolean loggingOn = fmiTrue; fmi1_xml_model_description_t* md; jm_status_enu_t status; PRINT_MY_DEBUG; if (jm_status_error == fmi_zip_unzip(FMUPath, tmpPath)) { printf("Failed to unzip the FMU file\n"); abort(); } callBackFunctions.logger = mylogger; callBackFunctions.allocateMemory = calloc; callBackFunctions.freeMemory = free; model_description_path = fmi_import_get_model_description_path(tmpPath, callBackFunctions); md = fmi1_xml_allocate_model_description(0); if(!md) abort(); if(fmi1_xml_parse(md, model_description_path)) { printf("Error parsing XML file %s:%s\n", FMUPath, fmi1_xml_get_last_error(md)); fmi1_xml_free_model_description(md); abort(); } printf("Model name: %s\n", fmi1_xml_get_model_name(md)); printf("Model identifier: %s\n", fmi1_xml_get_model_identifier(md)); printf("Model GUID: %s\n", fmi1_xml_get_GUID(md)); modelIdentifier = fmi1_xml_get_model_identifier(md); modelName = fmi1_xml_get_model_name(md); GUID = fmi1_xml_get_GUID(md); modelIdentifier = fmi1_xml_get_model_identifier(md); dllPath = fmi_import_get_dll_path(tmpPath, modelIdentifier, callBackFunctions); fmu = fmi_dll_common_create_dllfmu(dllPath, modelIdentifier, callBackFunctions, standard); if (fmu == NULL) { printf("An error occured while fmi_dll_common_create_dllfmu was called, an error message should been printed.\n"); do_pause(); return 0; } status = fmi_dll_common_load_dll(fmu); if (status == jm_status_error) { printf("Error in fmi_dll_common_load_dll: %s\n", fmi_dll_common_get_last_error(fmu)); do_pause(); return 0; } status = fmi_dll_common_load_fcn(fmu); if (status == jm_status_error) { printf("Error in fmi_dll_common_load_fcn: %s\n", fmi_dll_common_get_last_error(fmu)); do_pause(); return 0; } printf("fmi_dll_1_0_me_get_version: %s\n", fmi_dll_1_0_me_get_version(fmu)); fmi_dll_common_free_dll(fmu); fmi_dll_common_destroy_dllfmu(fmu); fmi1_xml_free_model_description(md); printf("Everything seems to be OK since you got this far=)!\n"); do_pause(); }