]> gerrit.simantics Code Review - simantics/fmil.git/blobdiff - org.simantics.fmil.core/native/FMUSimulator/fmi_util.c.txt
Linux 64 support for FMU
[simantics/fmil.git] / org.simantics.fmil.core / native / FMUSimulator / fmi_util.c.txt
index 7b90df5be85b8bb4560cc19594a8cc36456fb2ac..bfd6e203a552bb8144e48862945e32b5e3ce9180 100644 (file)
@@ -19,6 +19,7 @@
 #include <FMI/fmi_util.h>
 #include <FMI/fmi_zip_unzip.h>
 
+
 char* fmi_construct_dll_dir_name(jm_callbacks* callbacks, const char* fmu_unzipped_path) {
        char* dir_path;
        size_t len;
@@ -59,8 +60,6 @@ char* fmi_construct_dll_file_name(jm_callbacks* callbacks, const char* dll_dir_n
        return fname;
 }
 
-////
-
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -78,23 +77,23 @@ typedef struct {
        char *description;
        char *declaredType;
        long vr;
-       // 0 = real
+       /* 0 = real
        // 1 = integer
        // 2 = boolean
        // 3 = string
-       // 4 = enumeration
+       // 4 = enumeration */
        int type;
-       // 0 = constant
+       /* 0 = constant
        // 1 = parameter
        // 2 = discrete
        // 3 = continuous
-       // 4 = unknown
+       // 4 = unknown */
        int variability;
-       // 0 = input
+       /* 0 = input
        // 1 = output
        // 2 = internal
        // 3 = none
-       // 4 = unknown
+       // 4 = unknown */
        int causality;
 } FMIL_Variable;
 
@@ -105,27 +104,37 @@ typedef struct {
        char *unit;
 } FMIL_DeclaredType;
 
-__declspec(dllexport) int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPointer, int *fmuVersion, const char **error);
-
-__declspec(dllexport) int FMI1_CS_UNLOAD(void* fmu, const char **error);
-__declspec(dllexport) FMIL_Variable *FMI1_CS_GET_VARIABLES(void* fmu, int *count, const char **error);
-__declspec(dllexport) FMIL_DeclaredType *FMI1_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error);
-__declspec(dllexport) int FMI1_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error);
-__declspec(dllexport) int FMI1_CS_INITIALIZE(void* fmu, const char **error);
-__declspec(dllexport) int FMI1_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error);
-__declspec(dllexport) int FMI1_CS_SET_REAL(void* fmu, int vr, double value, const char **error);
-__declspec(dllexport) double FMI1_CS_GET_REAL(void* fmu, int vr, const char **error);
-__declspec(dllexport) int FMI1_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error);
-
-__declspec(dllexport) int FMI2_CS_UNLOAD(void* fmu, const char **error);
-__declspec(dllexport) FMIL_Variable *FMI2_CS_GET_VARIABLES(void* fmu, int *count, const char **error);
-__declspec(dllexport) FMIL_DeclaredType *FMI2_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error);
-__declspec(dllexport) int FMI2_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error);
-__declspec(dllexport) int FMI2_CS_INITIALIZE(void* fmu, const char **error);
-__declspec(dllexport) int FMI2_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error);
-__declspec(dllexport) int FMI2_CS_SET_REAL(void* fmu, int vr, double value, const char **error);
-__declspec(dllexport) double FMI2_CS_GET_REAL(void* fmu, int vr, const char **error);
-__declspec(dllexport) int FMI2_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error);
+#ifdef _MSC_VER
+#define DLLEXPORT __declspec(dllexport)
+#elif __GNUC__
+#define DLLEXPORT __attribute__((visibility("default")))
+#pragma warning Using GNUC default visibility
+#else
+#define DLLEXPORT
+#pragma warning Empty dynamic link EXPORT defined
+#endif
+
+DLLEXPORT int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPointer, int *fmuVersion, const char **error);
+
+DLLEXPORT int FMI1_CS_UNLOAD(void* fmu, const char **error);
+DLLEXPORT FMIL_Variable *FMI1_CS_GET_VARIABLES(void* fmu, int *count, const char **error);
+DLLEXPORT FMIL_DeclaredType *FMI1_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error);
+DLLEXPORT int FMI1_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error);
+DLLEXPORT int FMI1_CS_INITIALIZE(void* fmu, const char **error);
+DLLEXPORT int FMI1_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error);
+DLLEXPORT int FMI1_CS_SET_REAL(void* fmu, int vr, double value, const char **error);
+DLLEXPORT double FMI1_CS_GET_REAL(void* fmu, int vr, const char **error);
+DLLEXPORT int FMI1_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error);
+
+DLLEXPORT int FMI2_CS_UNLOAD(void* fmu, const char **error);
+DLLEXPORT FMIL_Variable *FMI2_CS_GET_VARIABLES(void* fmu, int *count, const char **error);
+DLLEXPORT FMIL_DeclaredType *FMI2_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error);
+DLLEXPORT int FMI2_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error);
+DLLEXPORT int FMI2_CS_INITIALIZE(void* fmu, const char **error);
+DLLEXPORT int FMI2_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error);
+DLLEXPORT int FMI2_CS_SET_REAL(void* fmu, int vr, double value, const char **error);
+DLLEXPORT double FMI2_CS_GET_REAL(void* fmu, int vr, const char **error);
+DLLEXPORT int FMI2_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error);
 
 #ifdef __cplusplus
 }
@@ -153,7 +162,7 @@ void fmilogger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t sta
     }*/
 }
 
-int FMI_CS_LOAD(char *zipFilePath, char *unzipFolder, void **fmuPointer, int *fmuVersion, const char **error) {
+int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPointer, int *fmuVersion, const char **error) {
 
        fmi1_callback_functions_t callBackFunctions;
        fmi2_callback_functions_t callBackFunctions2;
@@ -182,7 +191,7 @@ int FMI_CS_LOAD(char *zipFilePath, char *unzipFolder, void **fmuPointer, int *fm
                fmu = fmi1_import_parse_xml(context, unzipFolder);
                if (fmi1_import_get_fmu_kind(fmu) != fmi1_fmu_kind_enu_cs_standalone && fmi1_import_get_fmu_kind(fmu) != fmi1_fmu_kind_enu_cs_tool) {
                        *error = "Provided FMU is version 1 but wrong type me (Model Exchange) when it should be cs (Co-Simulation)";
-                       return 2; // wrong type, should be co-simulation
+                       return 2; /* wrong type, should be co-simulation */
                }
                
                callBackFunctions.logger = fmilogger;
@@ -202,7 +211,7 @@ int FMI_CS_LOAD(char *zipFilePath, char *unzipFolder, void **fmuPointer, int *fm
 
                if (fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_standalone && fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_tool) {
                        *error = "Provided FMU is version 2.0 but wrong type me (Model Exchange) when it should be cs (Co-Simulation)";
-                       return 2; // wrong type, should be co-simulation
+                       return 2; /* wrong type, should be co-simulation */
                }
 
                callBackFunctions2.logger = fmi2_log_forwarding;
@@ -222,7 +231,7 @@ int FMI_CS_LOAD(char *zipFilePath, char *unzipFolder, void **fmuPointer, int *fm
        
        fmi_import_free_context(context);
 
-       return 0; // success
+       return 0; /* success */
 }
 
 int FMI1_CS_UNLOAD(void *fmu_, const char **error) {
@@ -703,7 +712,7 @@ int FMI2_CS_STEP(void *fmu, double masterTime, double stepSize, const char **err
        return 0;
 }
 
-int FMI1_CS_SET_REAL(void *fmu, long valueId, double value, const char **error) {
+int FMI1_CS_SET_REAL(void *fmu, int valueId, double value, const char **error) {
 
        fmi1_status_t status;
 
@@ -716,7 +725,7 @@ int FMI1_CS_SET_REAL(void *fmu, long valueId, double value, const char **error)
        return 0;
 }
 
-int FMI2_CS_SET_REAL(void *fmu, long valueId, double value, const char **error) {
+int FMI2_CS_SET_REAL(void *fmu, int valueId, double value, const char **error) {
 
        fmi2_status_t status;
 
@@ -759,7 +768,7 @@ double FMI2_CS_GET_REAL(void *fmu, int valueReference, const char **error) {
 
 int FMI1_CS_GET_REALS(void *fmu, int *valueReferences, double *result, int count, const char **error) {
 
-       fmi1_value_reference_t *vrs = valueReferences;
+       fmi1_value_reference_t *vrs = (fmi1_value_reference_t*) valueReferences;
        fmi1_real_t value;
 
        fmi1_status_t status;
@@ -773,7 +782,7 @@ int FMI1_CS_GET_REALS(void *fmu, int *valueReferences, double *result, int count
 
 int FMI2_CS_GET_REALS(void *fmu, int *valueReferences, double *result, int count, const char **error) {
 
-       fmi2_value_reference_t *vrs = valueReferences;
+       fmi2_value_reference_t *vrs = (fmi2_value_reference_t*) valueReferences;
        fmi2_real_t value;
 
        fmi2_status_t status;