2 Copyright (C) 2012 Modelon AB
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the BSD style license.
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.
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>.
15 #include <JM/jm_vector.h>
16 #include "fmi1_xml_model_description_impl.h"
17 #include "fmi1_xml_parser.h"
19 static const char * module = "FMI1XML";
21 fmi1_fmu_kind_enu_t fmi1_xml_get_fmu_kind(fmi1_xml_model_description_t* md) {
25 fmi1_xml_capabilities_t* fmi1_xml_get_capabilities(fmi1_xml_model_description_t* md){
26 return md->capabilities;
29 size_t fmi1_xml_get_number_of_additional_models(fmi1_xml_model_description_t* md) {
30 return jm_vector_get_size(jm_string)(&md->additionalModels);
33 const char* fmi1_xml_get_additional_model_name(fmi1_xml_model_description_t* md, size_t index) {
34 if(fmi1_xml_get_number_of_additional_models(md) <= index) return 0;
35 return jm_vector_get_item(jm_string)(&md->additionalModels,index);
39 const char* fmi1_xml_get_entry_point(fmi1_xml_model_description_t* md) {
40 return jm_vector_char2string(&md->entryPoint);
43 const char* fmi1_xml_get_mime_type(fmi1_xml_model_description_t* md){
44 return jm_vector_char2string(&md->mimeType);
47 int fmi1_xml_get_manual_start(fmi1_xml_model_description_t* md){
48 return md->manual_start;
52 int fmi1_xml_handle_Implementation(fmi1_xml_parser_context_t *context, const char* data) {
53 fmi1_xml_model_description_t* md = context->modelDescription;
55 jm_log_info(context->callbacks, module, "Processing implementation element (co-simulation FMU detected)");
57 md->fmuKind = fmi1_fmu_kind_enu_unknown; /* Explicitly set the "unknown" FMU kind here, in order to
58 * detect if the required CoSimulation_StandAlone and
59 * CoSimulation_Tool elements has been parsed below.
63 /* According to https://trac.fmi-standard.org/ticket/309 we should report an error if neither of the
64 * requiered elements CoSimulation_StandAlone and CoSimulation_Tool is present in the Implementation
67 if (md->fmuKind != fmi1_fmu_kind_enu_cs_tool && md->fmuKind != fmi1_fmu_kind_enu_cs_standalone) {
68 jm_log_error(context->callbacks, module,
69 "Missing requiered XML element. Expected 'CoSimulation_StandAlone' or 'CoSimulation_Tool' element inside the 'Implementation' element.");
71 /* might give out a warning if(data[0] != 0) */
76 int fmi1_xml_handle_CoSimulation_StandAlone(fmi1_xml_parser_context_t *context, const char* data) {
77 fmi1_xml_model_description_t* md = context->modelDescription;
79 md->fmuKind = fmi1_fmu_kind_enu_cs_standalone;
82 /* might give out a warning if(data[0] != 0) */
89 int fmi1_xml_handle_CoSimulation_Tool(fmi1_xml_parser_context_t *context, const char* data) {
90 fmi1_xml_model_description_t* md = context->modelDescription;
92 md->fmuKind = fmi1_fmu_kind_enu_cs_tool;
95 /* might give out a warning if(data[0] != 0) */
100 int fmi1_xml_handle_Model(fmi1_xml_parser_context_t *context, const char* data) {
101 fmi1_xml_model_description_t* md = context->modelDescription;
104 /* <xs:attribute name="entryPoint" type="xs:anyURI" use="required"/> */
105 fmi1_xml_set_attr_string(context, fmi1_xml_elmID_Model, fmi_attr_id_entryPoint, 1, &(md->entryPoint)) ||
106 /* <xs:attribute name="manualStart" type="xs:boolean" default="false"/> */
107 fmi1_xml_set_attr_boolean(context,fmi1_xml_elmID_Model,fmi_attr_id_manualStart,0,&md->manual_start,0) ||
108 /* <xs:attribute name="type" type="xs:string" use="required"/> */
109 fmi1_xml_set_attr_string(context, fmi1_xml_elmID_Model, fmi_attr_id_type,1,&md->mimeType)
113 /* might give out a warning if(data[0] != 0) */
118 int fmi1_xml_handle_File(fmi1_xml_parser_context_t *context, const char* data) {
119 fmi1_xml_model_description_t* md = context->modelDescription;
121 jm_vector(char)* bufFileName = fmi1_xml_get_parse_buffer(context,2);
125 if(fmi1_xml_set_attr_string(context, fmi1_xml_elmID_Model, fmi_attr_id_file, 1, bufFileName))
127 len = jm_vector_get_size_char(bufFileName);
128 pname = jm_vector_push_back(jm_string)(&md->additionalModels,fileName);
129 if(pname) *pname = fileName = md->callbacks->malloc(len + 1);
130 if(!pname || !fileName) {
131 fmi1_xml_parse_fatal(context, "Could not allocate memory");
134 memcpy(fileName, jm_vector_get_itemp(char)(bufFileName,0), len);
138 /* might give out a warning if(data[0] != 0) */