fmi1_import_t* fmi1_import_parse_xml( fmi_import_context_t* context, const char* dirPath) { char* xmlPath; char absPath[FILENAME_MAX + 2]; jm_callbacks* cb; fmi1_import_t* fmu; if(!context) return 0; cb = context->callbacks; xmlPath = fmi_import_get_model_description_path(dirPath, context->callbacks); fmu = fmi1_import_allocate(context->callbacks); if(!fmu) { context->callbacks->free(xmlPath); return 0; } jm_log_verbose( cb, "FMILIB", "Parsing model description XML"); if(fmi1_xml_parse_model_description( fmu->md, xmlPath)) { fmi1_import_free(fmu); cb->free(xmlPath); return 0; } cb->free(xmlPath); fmu->dirPath = (char*)cb->calloc(strlen(dirPath) + 1, sizeof(char)); if(jm_get_dir_abspath(cb, dirPath, absPath, FILENAME_MAX + 2)) { fmu->location = fmi_import_create_URL_from_abs_path(cb, absPath); } if ((fmu->dirPath == NULL) || (fmu->location == 0)){ jm_log_fatal( cb, "FMILIB", "Could not allocated memory"); fmi1_import_free(fmu); cb->free(xmlPath); return 0; } strcpy(fmu->dirPath, dirPath); jm_log_verbose( cb, "FMILIB", "Parsing finished successfully"); return fmu; }
void FMI1ModelExchangeDestructor_OMC(void* in_fmi1me) { FMI1ModelExchange* FMI1ME = (FMI1ModelExchange*)in_fmi1me; fmi1_import_terminate(FMI1ME->FMIImportInstance); fmi1_import_free_model_instance(FMI1ME->FMIImportInstance); fmi1_import_destroy_dllfmu(FMI1ME->FMIImportInstance); fmi1_import_free(FMI1ME->FMIImportInstance); fmi_import_free_context(FMI1ME->FMIImportContext); free(FMI1ME->FMIWorkingDirectory); free(FMI1ME->FMIInstanceName); free(FMI1ME->FMIEventInfo); }
int main(int argc, char *argv[]) { fmi1_callback_functions_t callBackFunctions; const char* FMUPath; const char* tmpPath; jm_callbacks callbacks; fmi_import_context_t* context; fmi_version_enu_t version; jm_status_enu_t status; int register_active_fmu; fmi1_import_t* fmu; char* outfile; if(argc < 4) { printf("Usage: %s <fmu_file> <temporary_dir> <output_file>\n", argv[0]); do_exit(CTEST_RETURN_FAIL); } FMUPath = argv[1]; tmpPath = argv[2]; outfile = argv[3]; logFile = fopen(outfile, "wb"); if(!logFile) { printf("Could not open output file %s\n", outfile); do_exit(CTEST_RETURN_FAIL); } callbacks.malloc = malloc; callbacks.calloc = calloc; callbacks.realloc = realloc; callbacks.free = free; callbacks.logger = logger; callbacks.log_level = jm_log_level_info; callbacks.context = 0; callBackFunctions.logger = fmi1_log_forwarding; callBackFunctions.allocateMemory = calloc; callBackFunctions.freeMemory = free; #ifdef FMILIB_GENERATE_BUILD_STAMP printf("Library build stamp:\n%s\n", fmilib_get_build_stamp()); #endif context = fmi_import_allocate_context(&callbacks); version = fmi_import_get_fmi_version(context, FMUPath, tmpPath); if(version != fmi_version_1_enu) { printf("Only version 1.0 is supported so far\n"); do_exit(CTEST_RETURN_FAIL); } fmu = fmi1_import_parse_xml(context, tmpPath); if(!fmu) { printf("Error parsing XML, exiting\n"); do_exit(CTEST_RETURN_FAIL); } register_active_fmu = 1; /* Must be used to use our logger. (jm standard prints to strerr which does not generate out put test file) */ status = fmi1_import_create_dllfmu(fmu, callBackFunctions, register_active_fmu); if (status == jm_status_error) { printf("Could not create the DLL loading mechanism(C-API test).\n"); do_exit(CTEST_RETURN_FAIL); } test_logger(fmu); fmi1_import_destroy_dllfmu(fmu); fmi1_import_free(fmu); fmi_import_free_context(context); fclose(logFile); return 0; }