]> gerrit.simantics Code Review - simantics/fmil.git/blob - org.simantics.fmil.core/native/FMILibrary/src/Import/src/FMI/fmi_import_util.c
Ensure unloadFMU is called only if FMU instance (pointer) exists
[simantics/fmil.git] / org.simantics.fmil.core / native / FMILibrary / src / Import / src / FMI / fmi_import_util.c
1 /*
2     Copyright (C) 2012 Modelon AB
3
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the BSD style license.
6
7      This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10     FMILIB_License.txt file for more details.
11
12     You should have received a copy of the FMILIB_License.txt file
13     along with this program. If not, contact Modelon AB <http://www.modelon.com>.
14 */\r
15 \r
16 #include <stdlib.h>
17 #include <stdio.h>\r
18 #include <string.h>\r
19 #include <assert.h>\r
20 \r
21 #include <fmilib_config.h>\r
22 #include <JM/jm_portability.h>\r
23 #include <FMI/fmi_import_util.h>\r
24 \r
25 char* fmi_import_mk_temp_dir(jm_callbacks* cb, const char* systemTempDir, const char* tempPrefix) {
26         if(!tempPrefix) tempPrefix = "fmil";
27         return jm_mk_temp_dir(cb, systemTempDir, tempPrefix);
28 }
29
30 char* fmi_import_create_URL_from_abs_path(jm_callbacks* cb, const char* absPath) {
31         return jm_create_URL_from_abs_path(cb, absPath);
32 }
33 \r
34 jm_status_enu_t fmi_import_rmdir(jm_callbacks* cb, const char* dir) {\r
35         return jm_rmdir(cb, dir);\r
36 }\r
37 \r
38 char* fmi_import_get_dll_path(const char* fmu_unzipped_path, const char* model_identifier, jm_callbacks* callbacks)\r
39 {\r
40         char* dll_path;\r
41         size_t len;\r
42 \r
43         if (model_identifier == NULL || fmu_unzipped_path == NULL) {\r
44                 assert(0);\r
45                 return NULL;\r
46         }\r
47 \r
48         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
49 \r
50         dll_path = (char*)callbacks->calloc(len, sizeof(char));\r
51         if (dll_path == NULL) {\r
52                 jm_log_fatal(callbacks, "FMILIB", "Failed to allocate memory.");\r
53                 return NULL;\r
54         }\r
55 \r
56         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
57 \r
58         return dll_path;\r
59 }\r
60 \r
61 char* fmi_import_get_model_description_path(const char* fmu_unzipped_path, jm_callbacks* callbacks)\r
62 {\r
63         char* model_description_path;\r
64         size_t len;\r
65 \r
66         len = strlen(fmu_unzipped_path) + strlen(FMI_FILE_SEP) + strlen(FMI_MODEL_DESCRIPTION_XML) + 1;\r
67 \r
68         model_description_path = (char*)callbacks->calloc(len, sizeof(char));\r
69         if (model_description_path == NULL) {\r
70                 callbacks->logger(NULL, "FMIIMPORTUTIL", jm_log_level_error, "Failed to allocate memory.");\r
71                 return NULL;\r
72         }\r
73 \r
74         jm_snprintf(model_description_path, len, "%s%s%s", fmu_unzipped_path, FMI_FILE_SEP, FMI_MODEL_DESCRIPTION_XML);\r
75 \r
76         return model_description_path;\r
77 }