]> gerrit.simantics Code Review - simantics/fmil.git/blobdiff - org.simantics.fmil.core/native/FMUSimulator/src/fmi_util.c
Add FMILibrary-2.0.3 to org.simantics.fmil.core\native.
[simantics/fmil.git] / org.simantics.fmil.core / native / FMUSimulator / src / fmi_util.c
similarity index 83%
rename from org.simantics.fmil.core/native/FMUSimulator/fmi_util.c.txt
rename to org.simantics.fmil.core/native/FMUSimulator/src/fmi_util.c
index 31ef175a6f74bb2f0ec524361af206f0914036a4..32bf32f80cf39008d6d9f178288203bffd184cdf 100644 (file)
@@ -1,64 +1,3 @@
-/*
-    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>.
-*/
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#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;
-
-       assert( fmu_unzipped_path && callbacks);
-
-       len = 
-               strlen(fmu_unzipped_path) + strlen(FMI_FILE_SEP)
-               + strlen(FMI_BINARIES) + strlen(FMI_FILE_SEP) 
-               + strlen(FMI_PLATFORM) + strlen(FMI_FILE_SEP) + 1;
-
-       dir_path = (char*)callbacks->malloc(len);
-       if (dir_path == NULL) {
-               jm_log_fatal(callbacks, "FMIUT", "Failed to allocate memory.");
-               return NULL;
-       }
-
-       sprintf(dir_path, "%s%s%s%s%s%s", fmu_unzipped_path, FMI_FILE_SEP, FMI_BINARIES, FMI_FILE_SEP, FMI_PLATFORM, FMI_FILE_SEP);/*safe */
-
-       return dir_path;
-}
-
-char* fmi_construct_dll_file_name(jm_callbacks* callbacks, const char* dll_dir_name, const char* model_identifier) {
-       char* fname;
-       size_t len;
-       assert(callbacks && model_identifier);
-       len = 
-               strlen(dll_dir_name) +
-               strlen(model_identifier) 
-               + strlen(FMI_DLL_EXT) + 1;
-       fname = (char*)callbacks->malloc(len);
-       if (fname == NULL) {
-               jm_log_fatal(callbacks, "FMIUT", "Failed to allocate memory.");
-               return NULL;
-       }
-       sprintf(fname, "%s%s%s", dll_dir_name, model_identifier, FMI_DLL_EXT);/*safe */
-
-       return fname;
-}
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -73,9 +12,9 @@ extern "C" {
 #endif
 
 typedef struct {
-       char *name;
-       char *description;
-       char *declaredType;
+       const char *name;
+       const char *description;
+       const char *declaredType;
        long vr;
        /* 0 = real
        // 1 = integer
@@ -98,43 +37,33 @@ typedef struct {
 } FMIL_Variable;
 
 typedef struct {
-       char *name;
-       char *description;
-       char *quantity;
-       char *unit;
+       const char *name;
+       const char *description;
+       const char *quantity;
+       const char *unit;
 } FMIL_DeclaredType;
 
-#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);
+int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPointer, int *fmuVersion, const char **error);
+
+int FMI1_CS_UNLOAD(void* fmu, const char **error);
+FMIL_Variable *FMI1_CS_GET_VARIABLES(void* fmu, int *count, const char **error);
+FMIL_DeclaredType *FMI1_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error);
+int FMI1_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error);
+int FMI1_CS_INITIALIZE(void* fmu, const char **error);
+int FMI1_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error);
+int FMI1_CS_SET_REAL(void* fmu, int vr, double value, const char **error);
+double FMI1_CS_GET_REAL(void* fmu, int vr, const char **error);
+int FMI1_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error);
+
+int FMI2_CS_UNLOAD(void* fmu, const char **error);
+FMIL_Variable *FMI2_CS_GET_VARIABLES(void* fmu, int *count, const char **error);
+FMIL_DeclaredType *FMI2_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error);
+int FMI2_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error);
+int FMI2_CS_INITIALIZE(void* fmu, const char **error);
+int FMI2_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error);
+int FMI2_CS_SET_REAL(void* fmu, int vr, double value, const char **error);
+double FMI2_CS_GET_REAL(void* fmu, int vr, const char **error);
+int FMI2_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error);
 
 #ifdef __cplusplus
 }
@@ -153,7 +82,7 @@ void fmilogger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t sta
 {
        char msg[BUFFER];
     int len;
-       va_list argp;   
+       va_list argp;
        va_start(argp, message);
        /*len=jm_vsnprintf(msg, BUFFER, message, argp);
        printf("fmiStatus = %d;  %s (%s): %s\n", status, instanceName, category, msg);
@@ -197,7 +126,7 @@ int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPoin
                        *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 */
                }
-               
+
                callBackFunctions.logger = fmilogger;
                callBackFunctions.allocateMemory = calloc;
                callBackFunctions.freeMemory = free;
@@ -228,14 +157,14 @@ int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPoin
                        *error = fmi2_import_get_last_error(fmu2);
                        return 3;
                }
-               
+
                *fmuPointer = fmu2;
                *fmuVersion = 2;
        } else {
            *error = "Couldn't find version of FMU - possibly incorrect file!";
            return 1;
        }
-       
+
        fmi_import_free_context(context);
 
        return 0; /* success */
@@ -409,7 +338,7 @@ FMIL_Variable *FMI1_CS_GET_VARIABLES(void *fmu, int *count, const char **error)
                                result[i].type = 4;
                                break;
                        }
-                       
+
                        result[i].vr = fmi1_import_get_variable_vr(var);
 
                        type = fmi1_import_get_variable_declared_type(var);
@@ -507,7 +436,7 @@ FMIL_Variable *FMI2_CS_GET_VARIABLES(void *fmu, int *count, const char **error)
                                result[i].type = 4;
                                break;
                        }
-                       
+
                        result[i].vr = fmi2_import_get_variable_vr(var);
 
                        type = fmi2_import_get_variable_declared_type(var);
@@ -690,7 +619,7 @@ int FMI2_CS_INITIALIZE(void *fmu, const char **error) {
     if(fmistatus != fmi2_status_ok) {
         *error = ("fmi2_import_exit_initialization_mode failed\n");
                return 1;
-    }   
+    }
 
        return 0;
 }