]> gerrit.simantics Code Review - simantics/fmil.git/blobdiff - org.simantics.fmil.core/native/FMILibrary/src/Import/src/FMI/fmi_import_util.c
Add FMILibrary-2.0.3 to org.simantics.fmil.core\native.
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / src / Import / src / FMI / fmi_import_util.c
diff --git a/org.simantics.fmil.core/native/FMILibrary/src/Import/src/FMI/fmi_import_util.c b/org.simantics.fmil.core/native/FMILibrary/src/Import/src/FMI/fmi_import_util.c
new file mode 100644 (file)
index 0000000..52ad61d
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+    Copyright (C) 2012 Modelon AB
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the BSD style license.
+
+     This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    FMILIB_License.txt file for more details.
+
+    You should have received a copy of the FMILIB_License.txt file
+    along with this program. If not, contact Modelon AB <http://www.modelon.com>.
+*/\r
+\r
+#include <stdlib.h>
+#include <stdio.h>\r
+#include <string.h>\r
+#include <assert.h>\r
+\r
+#include <fmilib_config.h>\r
+#include <JM/jm_portability.h>\r
+#include <FMI/fmi_import_util.h>\r
+\r
+char* fmi_import_mk_temp_dir(jm_callbacks* cb, const char* systemTempDir, const char* tempPrefix) {
+       if(!tempPrefix) tempPrefix = "fmil";
+       return jm_mk_temp_dir(cb, systemTempDir, tempPrefix);
+}
+
+char* fmi_import_create_URL_from_abs_path(jm_callbacks* cb, const char* absPath) {
+       return jm_create_URL_from_abs_path(cb, absPath);
+}
+\r
+jm_status_enu_t fmi_import_rmdir(jm_callbacks* cb, const char* dir) {\r
+       return jm_rmdir(cb, dir);\r
+}\r
+\r
+char* fmi_import_get_dll_path(const char* fmu_unzipped_path, const char* model_identifier, jm_callbacks* callbacks)\r
+{\r
+       char* dll_path;\r
+       size_t len;\r
+\r
+       if (model_identifier == NULL || fmu_unzipped_path == NULL) {\r
+               assert(0);\r
+               return NULL;\r
+       }\r
+\r
+       len = strlen(fmu_unzipped_path) + strlen(FMI_FILE_SEP) + strlen(FMI_BINARIES) + strlen(FMI_FILE_SEP) + strlen(FMI_PLATFORM) + strlen(FMI_FILE_SEP) + strlen(model_identifier) + strlen(FMI_DLL_EXT) + 1;\r
+\r
+       dll_path = (char*)callbacks->calloc(len, sizeof(char));\r
+       if (dll_path == NULL) {\r
+               jm_log_fatal(callbacks, "FMILIB", "Failed to allocate memory.");\r
+               return NULL;\r
+       }\r
+\r
+       jm_snprintf(dll_path, len, "%s%s%s%s%s%s%s%s", fmu_unzipped_path, FMI_FILE_SEP, FMI_BINARIES, FMI_FILE_SEP, FMI_PLATFORM, FMI_FILE_SEP, model_identifier, FMI_DLL_EXT);\r
+\r
+       return dll_path;\r
+}\r
+\r
+char* fmi_import_get_model_description_path(const char* fmu_unzipped_path, jm_callbacks* callbacks)\r
+{\r
+       char* model_description_path;\r
+       size_t len;\r
+\r
+       len = strlen(fmu_unzipped_path) + strlen(FMI_FILE_SEP) + strlen(FMI_MODEL_DESCRIPTION_XML) + 1;\r
+\r
+       model_description_path = (char*)callbacks->calloc(len, sizeof(char));\r
+       if (model_description_path == NULL) {\r
+               callbacks->logger(NULL, "FMIIMPORTUTIL", jm_log_level_error, "Failed to allocate memory.");\r
+               return NULL;\r
+       }\r
+\r
+       jm_snprintf(model_description_path, len, "%s%s%s", fmu_unzipped_path, FMI_FILE_SEP, FMI_MODEL_DESCRIPTION_XML);\r
+\r
+       return model_description_path;\r
+}