This commit is contained in:
Alex Lin 2019-11-01 14:10:57 -05:00
commit 6205864d92
13 changed files with 236 additions and 34 deletions

@ -63,6 +63,7 @@ namespace Trick {
#endif
void print_xml( std::ofstream & outfile ) ;
void print_json(std::ofstream & sie_out ) ;
private:
std::map<std::string, ATTRIBUTES *> name_to_attr_map ;

@ -55,6 +55,7 @@ namespace Trick {
}
void print_xml( std::ofstream & outfile ) ;
void print_json(std::ofstream & sie_out ) ;
private:
std::map<std::string, ENUM_ATTR *> name_to_attr_map ;

@ -40,10 +40,12 @@ namespace Trick {
void class_attr_map_print_xml() ;
void enum_attr_map_print_xml() ;
void top_level_objects_print_xml() ;
void sie_print_json() ;
private:
void top_level_objects_print(std::ofstream & sie_out) ;
void top_level_objects_json(std::ofstream & sie_out) ;
// These are singleton maps holding all attributes known to the sim
Trick::AttributesMap * class_attr_map ; /* ** -- This is be ignored by ICG */

@ -1,13 +1,7 @@
# Downloads the external java packages Trick uses. We use the maven repository to
# get the jar file. Currently we fix the version of the jar files we download.
# I wonder how long the links stay unchanged and active (Alex 1/22/15)
# Running in parallel works fine. Not running in parallel makes the output messages
# readable. I chose readability.
.NOTPARALLEL:
EXTERNAL_JARS = \
bsaf-1.9.2.jar \
jcommon-1.0.23.jar \
@ -28,44 +22,46 @@ EXTERNAL_JARS = \
jaxb-core-2.3.0.1.jar \
javax.activation-1.2.0.jar
curl := curl --retry 4 -O -s -S
.PHONY: external_jars
external_jars : ${EXTERNAL_JARS}
bsaf-1.9.2.jar :
curl --retry 4 -O http://repo.maven.apache.org/maven2/org/jdesktop/bsaf/bsaf/1.9.2/bsaf-1.9.2.jar
jcommon-1.0.23.jar :
curl --retry 4 -O http://repo.maven.apache.org/maven2/org/jfree/jcommon/1.0.23/jcommon-1.0.23.jar
jfreechart-1.0.19.jar :
curl --retry 4 -O http://repo.maven.apache.org/maven2/org/jfree/jfreechart/1.0.19/jfreechart-1.0.19.jar
jfreesvg-2.1.jar :
curl --retry 4 -O http://repo.maven.apache.org/maven2/org/jfree/jfreesvg/2.1/jfreesvg-2.1.jar
jopt-simple-4.8.jar :
curl --retry 4 -O http://repo.maven.apache.org/maven2/net/sf/jopt-simple/jopt-simple/4.8/jopt-simple-4.8.jar
bsaf-1.9.2.jar:
$(curl) http://repo.maven.apache.org/maven2/org/jdesktop/bsaf/bsaf/1.9.2/bsaf-1.9.2.jar
jcommon-1.0.23.jar:
$(curl) http://repo.maven.apache.org/maven2/org/jfree/jcommon/1.0.23/jcommon-1.0.23.jar
jfreechart-1.0.19.jar:
$(curl) http://repo.maven.apache.org/maven2/org/jfree/jfreechart/1.0.19/jfreechart-1.0.19.jar
jfreesvg-2.1.jar:
$(curl) http://repo.maven.apache.org/maven2/org/jfree/jfreesvg/2.1/jfreesvg-2.1.jar
jopt-simple-4.8.jar:
$(curl) http://repo.maven.apache.org/maven2/net/sf/jopt-simple/jopt-simple/4.8/jopt-simple-4.8.jar
junit-4.12.jar:
curl --retry 4 -O http://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar
swingx-1.6.1.jar :
curl --retry 4 -O http://repo.maven.apache.org/maven2/org/swinglabs/swingx/1.6.1/swingx-1.6.1.jar
hamcrest-core-1.3.jar :
curl --retry 4 -O http://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
pdfbox-2.0.11.jar :
curl --retry 4 -O http://repo.maven.apache.org/maven2/org/apache/pdfbox/pdfbox/2.0.11/pdfbox-2.0.11.jar
fontbox-2.0.11.jar :
curl --retry 4 -O http://repo.maven.apache.org/maven2/org/apache/pdfbox/fontbox/2.0.11/fontbox-2.0.11.jar
$(curl) http://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar
swingx-1.6.1.jar:
$(curl) http://repo.maven.apache.org/maven2/org/swinglabs/swingx/1.6.1/swingx-1.6.1.jar
hamcrest-core-1.3.jar:
$(curl) http://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
pdfbox-2.0.11.jar:
$(curl) http://repo.maven.apache.org/maven2/org/apache/pdfbox/pdfbox/2.0.11/pdfbox-2.0.11.jar
fontbox-2.0.11.jar:
$(curl) http://repo.maven.apache.org/maven2/org/apache/pdfbox/fontbox/2.0.11/fontbox-2.0.11.jar
commons-logging-1.2.jar :
curl --retry 4 -O https://repo1.maven.org/maven2/commons-logging/commons-logging/1.2/commons-logging-1.2.jar
jaxb-runtime-2.4.0-b180830.0438.jar:
curl --retry 4 -O http://repo.maven.apache.org/maven2/org/glassfish/jaxb/jaxb-runtime/2.4.0-b180830.0438/jaxb-runtime-2.4.0-b180830.0438.jar
$(curl) https://repo1.maven.org/maven2/commons-logging/commons-logging/1.2/commons-logging-1.2.jar
jaxb-runtime-2.4.0-b180830.0438.jar:
$(curl) http://repo.maven.apache.org/maven2/org/glassfish/jaxb/jaxb-runtime/2.4.0-b180830.0438/jaxb-runtime-2.4.0-b180830.0438.jar
jaxb-xjc-2.4.0-b180830.0438.jar:
curl --retry 4 -O http://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-xjc/2.4.0-b180830.0438/jaxb-xjc-2.4.0-b180830.0438.jar
$(curl) http://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-xjc/2.4.0-b180830.0438/jaxb-xjc-2.4.0-b180830.0438.jar
jaxb-jxc-2.4.0-b180830.0438.jar:
curl --retry 4 -O http://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-jxc/2.4.0-b180830.0438/jaxb-jxc-2.4.0-b180830.0438.jar
$(curl) http://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-jxc/2.4.0-b180830.0438/jaxb-jxc-2.4.0-b180830.0438.jar
jaxb-impl-2.4.0-b180830.0438.jar:
curl --retry 4 -O http://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-impl/2.4.0-b180830.0438/jaxb-impl-2.4.0-b180830.0438.jar
$(curl) http://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-impl/2.4.0-b180830.0438/jaxb-impl-2.4.0-b180830.0438.jar
jaxb-core-2.3.0.1.jar:
curl --retry 4 -O http://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-core/2.3.0.1/jaxb-core-2.3.0.1.jar
$(curl) http://repo.maven.apache.org/maven2/com/sun/xml/bind/jaxb-core/2.3.0.1/jaxb-core-2.3.0.1.jar
jaxb-api-2.4.0-b180725.0427.jar:
curl --retry 4 -O http://repo.maven.apache.org/maven2/javax/xml/bind/jaxb-api/2.4.0-b180725.0427/jaxb-api-2.4.0-b180725.0427.jar
$(curl) http://repo.maven.apache.org/maven2/javax/xml/bind/jaxb-api/2.4.0-b180725.0427/jaxb-api-2.4.0-b180725.0427.jar
javax.activation-1.2.0.jar:
curl --retry 4 -O http://repo.maven.apache.org/maven2/com/sun/activation/javax.activation/1.2.0/javax.activation-1.2.0.jar
$(curl) http://repo.maven.apache.org/maven2/com/sun/activation/javax.activation/1.2.0/javax.activation-1.2.0.jar
clean:
rm -f ${EXTERNAL_JARS}

@ -18,6 +18,7 @@ S_document.xml
S_library_list
S_main_*
S_sie.resource
S_sie.json
S_source.cpp
S_source.hh
T_main_*

@ -98,3 +98,64 @@ void Trick::AttributesMap::print_xml(std::ofstream & sie_out ) {
}
}
void Trick::AttributesMap::print_json(std::ofstream & sie_out ) {
std::map<std::string, ATTRIBUTES *>::iterator it ;
int jj ;
sie_out << " \"classes\": [\n" ;
for ( it = name_to_attr_map.begin() ; it != name_to_attr_map.end() ; it++ ) {
ATTRIBUTES * attr = (*it).second ;
std::string class_name = (*it).first;
std::replace(class_name.begin(), class_name.end(), ':', '_');
sie_out << " {\n";
sie_out << " \"name\": \"" << class_name << "\",\n" ;
if(attr->name[0] == '\0' || (attr->type_name == NULL)) {
sie_out << " \"members\": []\n" ;
} else {
sie_out << " \"members\": [\n" ;
while ( attr->name[0] != '\0' and (attr->type_name != NULL)) {
sie_out << " {\n";
sie_out << " \"name\": \"" << attr->name << "\",\n" ;
std::string type_name = attr->type_name;
std::replace(type_name.begin(), type_name.end(), ':', '_');
sie_out << " \"type\": \"" << type_remove_dims(type_name) << "\",\n" ;
sie_out << " \"io_attributes\": \"" << attr->io << "\",\n" ;
sie_out << " \"units\": \"" ;
// If the mods bit is set for using -- as the units
if ( attr->mods & TRICK_MODS_UNITSDASHDASH ) {
sie_out << "--" ;
} else {
sie_out << attr->units ;
}
sie_out << "\"" ;
std::string description = attr->des;
if ( ! description.empty() ) {
sie_out << ",\n \"description\": \"" << replace_special_chars(description) << "\"" ;
}
if ( attr->num_index > 0 ) {
sie_out << ",\n \"dimensions\": [" ;
for (jj = 0; jj < attr->num_index - 1; jj++) {
sie_out << " \"" << attr->index[jj].size << "\"," ;
}
sie_out << " \"" << attr->index[attr->num_index - 1].size << "\" " ;
sie_out << "]\n" ;
} else {
sie_out << '\n' ;
}
sie_out << " }" ;
if((attr + 1)->name[0] != '\0') {
sie_out << ',';
}
sie_out << '\n';
attr++ ;
}
sie_out << " ]\n" ;
}
sie_out << " }" ;
if(std::next(it, 1) != name_to_attr_map.end()) {
sie_out << ',' ;
}
sie_out << "\n" ;
}
sie_out << " ],\n" ;
}

@ -31,3 +31,38 @@ void Trick::EnumAttributesMap::print_xml(std::ofstream & sie_out ) {
}
}
void Trick::EnumAttributesMap::print_json(std::ofstream & sie_out ) {
std::map<std::string, ENUM_ATTR *>::iterator it ;
ENUM_ATTR * enum_attr ;
sie_out << " \"enumerations\": [\n" ;
for ( it = name_to_attr_map.begin() ; it != name_to_attr_map.end() ; it++ ) {
enum_attr = (*it).second ;
if ( enum_attr != NULL ) {
sie_out << " {\n";
std::string name = it->first;
std::replace(name.begin(), name.end(), ':', '_');
sie_out << " \"name\": \"" << name << "\",\n" ;
sie_out << " \"pairs\": [\n";
while ( enum_attr->label[0] != '\0' ) {
sie_out << " {\n" ;
sie_out << " \"label\": \"" << enum_attr->label << "\",\n" ;
sie_out << " \"value\": \"" << enum_attr->value << "\"\n" ;
sie_out << " }" ;
if((enum_attr + 1)->label[0] != '\0') {
sie_out << ',';
}
sie_out << "\n";
enum_attr++ ;
}
sie_out << " ]\n" ;
sie_out << " }" ;
if(std::next(it, 1) != name_to_attr_map.end()) {
sie_out << ',' ;
}
sie_out << '\n';
}
}
sie_out << " ],\n";
}

@ -1,3 +1,5 @@
include $(dir $(lastword $(MAKEFILE_LIST)))../../../share/trick/makefiles/Makefile.common
include ${TRICK_HOME}/share/trick/makefiles/Makefile.tricklib
-include Makefile_deps
TRICK_CXXFLAGS += -std=c++11

@ -37,6 +37,7 @@ int Trick::Sie::process_sim_args() {
/* If main is being invoked by the configuration processor (cp) to generate the sie resource file... */
/* Generate the sie resource file */
sie_print_xml();
sie_print_json();
// Silently exit the sim without printing the termination message
exit(0) ;
@ -73,6 +74,42 @@ void Trick::Sie::top_level_objects_print(std::ofstream & sie_out) {
}
}
void Trick::Sie::top_level_objects_json(std::ofstream & sie_out) {
Trick::VARIABLE_MAP_ITER vit ;
int jj ;
sie_out << " \"top_level_objects\": [\n";
for ( vit = trick_MM->variable_map_begin() ; vit != trick_MM->variable_map_end() ; vit++ ) {
ALLOC_INFO * alloc_info = (*vit).second ;
if ( alloc_info != NULL ) {
sie_out << " {\n" ;
sie_out << " \"name\": \"" << vit->first << "\",\n" ;
sie_out << " \"type\": \"" ;
std::string type = trickTypeCharString(alloc_info->type, alloc_info->user_type_name );
std::replace(type.begin(), type.end(), ':', '_') ;
sie_out << type << "\",\n" ;
sie_out << " \"alloc_memory_init\": \"" << alloc_info->alloced_in_memory_init << "\"";
if ( alloc_info->num_index > 0 ) {
sie_out << ",\n \"dimensions\": [" ;
for (jj = 0; jj < alloc_info->num_index - 1; jj++) {
sie_out << " \"" << alloc_info->index[jj] << "\"," ;
}
sie_out << " \"" << alloc_info->index[alloc_info->num_index - 1] << "\" " ;
sie_out << "]\n" ;
} else {
sie_out << '\n' ;
}
sie_out << " }" ;
if(std::next(vit, 1) != trick_MM->variable_map_end()) {
sie_out << ',' ;
}
sie_out << '\n';
}
}
sie_out << " ]\n";
}
void Trick::Sie::sie_print_xml() {
std::ofstream sie_out ;
std::string file_name = std::string(command_line_args_get_default_dir()) + "/" + "S_sie.resource" ;
@ -86,6 +123,19 @@ void Trick::Sie::sie_print_xml() {
sie_out.close() ;
}
void Trick::Sie::sie_print_json() {
std::ofstream sie_out ;
std::string file_name = std::string(command_line_args_get_default_dir()) + "/" + "S_sie.json" ;
sie_out.open(file_name.c_str()) ;
sie_out << "{\n" ;
class_attr_map->print_json(sie_out) ;
enum_attr_map->print_json(sie_out) ;
top_level_objects_json(sie_out) ;
sie_out << "}\n" ;
sie_out.close() ;
}
void Trick::Sie::class_attr_map_print_xml() {
std::ofstream sie_out ;
std::string file_name = std::string(command_line_args_get_default_dir()) + "/" + "S_sie_class.xml" ;

@ -31,6 +31,8 @@ class VariableServerSession : public WebSocketSession {
private:
int sendErrorMessage(const char* fmt, ... );
int sendSieMessage(void);
int sendUnitsMessage(const char* vname);
REF2* make_error_ref(const char* in_name);
double stageTime;
bool dataStaged;

@ -20,6 +20,7 @@ class VariableServerVariable {
VariableServerVariable( REF2* variableType);
~VariableServerVariable();
const char* getName();
const char* getUnits();
void stageValue();
void writeValue( std::ostream& chkpnt_os );

@ -9,6 +9,7 @@ LIBRARY DEPENDENCIES:
#include <iostream>
#include <sstream>
#include <iomanip> // for setprecision
#include <fstream>
#include <algorithm>
#include "trick/memorymanager_c_intf.h"
#include "trick/input_processor_proto.h"
@ -117,6 +118,12 @@ int VariableServerSession::handleMessage(std::string client_msg) {
pycode.erase(std::remove(pycode.begin(), pycode.end(), '\r'), pycode.end());
// Call the Trick input processor.
ip_parse(pycode.c_str());
} else if (cmd == "sie") {
// send S_sie.json
sendSieMessage();
} else if (cmd == "units") {
// send S_sie.json
sendUnitsMessage(var_name.c_str());
} else {
sendErrorMessage("Unknown Command: \"%s\".\n", cmd.c_str());
status = 1;
@ -223,3 +230,42 @@ REF2* VariableServerSession::make_error_ref(const char* in_name) {
WebSocketSession* makeVariableServerSession( struct mg_connection *nc ) {
return new VariableServerSession(nc);
}
int VariableServerSession::sendSieMessage(void) {
std::ifstream file("./S_sie.json");
std::stringstream ss;
ss << "{ \"msg_type\": \"sie\", \"data\": ";
ss << file.rdbuf();
file.close();
ss << "}";
std::string tmp = ss.str();
const char* message = tmp.c_str();
mg_send_websocket_frame(connection, WEBSOCKET_OP_TEXT, message, strlen(message));
return 0;
}
int VariableServerSession::sendUnitsMessage(const char* vname) {
std::vector<VariableServerVariable*>::iterator it;
std::stringstream ss;
ss << "{ \"msg_type\": \"units\", \"var_name\": \"" << vname << "\", \"data\": \"";
for (it = sessionVariables.begin(); it != sessionVariables.end(); it++ ) {
if(!strcmp((*it)->getName(), vname)) {
ss << (
(
(
(*it)->getUnits() != NULL
) &&
(
(*it)->getUnits()[0] != '\0'
)
) ? (*it)->getUnits() : "--") << "\"}";
std::string tmp = ss.str();
const char* message = tmp.c_str();
mg_send_websocket_frame(connection, WEBSOCKET_OP_TEXT, message, strlen(message));
return 0;
}
}
sendErrorMessage("Variable Server: var_units cannot get units for \"%s\" because it must be added to the variable server first\n", vname);
return 0;
}

@ -50,6 +50,10 @@ const char* VariableServerVariable::getName() {
return varInfo->reference;
}
const char* VariableServerVariable::getUnits() {
return varInfo->attr->units;
}
static void write_quoted_str( std::ostream& os, const char* s) {
int ii;
int len = strlen(s);