FMI Library: part of JModelica.org
fmi1_import_test.c
Go to the documentation of this file.
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 */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <stdarg.h>
19 
20 #include <config_test.h>
21 #include <fmilib.h>
22 #include <JM/jm_portability.h>
23 
24 #define BUFFER 1000
25 
26 /* Logger function used by the FMU internally */
27 static void fmi1logger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t status, fmi1_string_t category, fmi1_string_t message, ...)
28 {
29  int len;
30  char msg[BUFFER];
31  va_list argp;
32  va_start(argp, message);
33  len = jm_vsnprintf(msg, BUFFER, message, argp);
34  printf("fmiStatus = %d; %s (%s): %s\n", status, instanceName, category, msg);
35 }
36 
37 
38 int fmi1_test(fmi_import_context_t* context, const char* dirPath)
39 {
40  fmi1_callback_functions_t callBackFunctions;
41  const char* modelIdentifier;
42  const char* modelName;
43  const char* GUID;
44  jm_status_enu_t status;
45 
47 
48  callBackFunctions.logger = fmi1logger;
49  callBackFunctions.allocateMemory = calloc;
50  callBackFunctions.freeMemory = free;
51 
52  fmu = fmi1_import_parse_xml(context, dirPath);
53 
54  if(!fmu) {
55  printf("Error parsing XML, exiting\n");
56  return (CTEST_RETURN_FAIL);
57  }
58  modelIdentifier = fmi1_import_get_model_identifier(fmu);
59  modelName = fmi1_import_get_model_name(fmu);
60  GUID = fmi1_import_get_GUID(fmu);
61 
62  printf("Model name: %s\n", modelName);
63  printf("Model identifier: %s\n", modelIdentifier);
64  printf("Model GUID: %s\n", GUID);
65 
66  status = fmi1_import_create_dllfmu(fmu, callBackFunctions, 0);
67  if (status == jm_status_error) {
68  printf("Could not create the DLL loading mechanism(C-API).\n");
69  return(CTEST_RETURN_FAIL);
70  }
71 
72  printf("Version returned from FMU: %s\n", fmi1_import_get_version(fmu));
73 
75 
76  fmi1_import_free(fmu);
77 
78  return (CTEST_RETURN_SUCCESS);
79 }
80 
81 
int fmi1_test(fmi_import_context_t *context, const char *dirPath)
FMILIB_EXPORT const char * fmi1_import_get_GUID(fmi1_import_t *fmu)
Get FMU GUID.
FMILIB_EXPORT const char * fmi1_import_get_model_name(fmi1_import_t *fmu)
Get model name.
size_t jm_callbacks * c
fmi1_callback_logger_ft logger
fmi1_callback_allocate_memory_ft allocateMemory
FMILIB_EXPORT void fmi1_import_destroy_dllfmu(fmi1_import_t *fmu)
Free a C-API struct. All memory allocated since the struct was created is freed.
fmi1_capi_t * fmu
fmi1_status_t
FMILIB_EXPORT jm_status_enu_t fmi1_import_create_dllfmu(fmi1_import_t *fmu, fmi1_callback_functions_t callBackFunctions, int registerGlobally)
Create a C-API struct. The C-API struct is a placeholder for the FMI DLL functions.
#define BUFFER
FMILIB_EXPORT fmi1_import_t * fmi1_import_parse_xml(fmi_import_context_t *c, const char *dirName)
Parse FMI 1.0 XML file found in the directory dirName.
FMILIB_EXPORT const char * fmi1_import_get_model_identifier(fmi1_import_t *fmu)
Get model identifier.
Include file to be used in client applications of the FMI Library.
struct fmi_xml_context_t fmi_import_context_t
FMI version independent library context. Opaque struct returned from fmi_import_allocate_context() ...
FMILIB_EXPORT const char * fmi1_import_get_version(fmi1_import_t *fmu)
Wrapper for the FMI function fmiGetVersion()
fmi1_callback_free_memory_ft freeMemory
struct fmi1_import_t fmi1_import_t
FMU version 1.0 object.
jm_status_enu_t
Return status codes.
Definition: jm_types.h:44
FMILIB_EXPORT void fmi1_import_free(fmi1_import_t *fmu)
Release the memory allocated.
static void fmi1logger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t status, fmi1_string_t category, fmi1_string_t message,...)
FMILIB_EXPORT int jm_vsnprintf(char *str, size_t size, const char *fmt, va_list al)
C89 compatible implementation of C99 vsnprintf.