An update will be applied January 25th, between 12PM and 1:00PM EST (UTC -5:00). The site may be slow during that time.

Commit e06ae3cc authored by Jeff Webb's avatar Jeff Webb
Browse files

Merge.

parents fc2138ba 661fa2cb
......@@ -41,8 +41,9 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif()
set (SUPERBUILD ON CACHE BOOL "Initial pull and build of all dependent libraries/executables")
set (PULSE_SUPERBUILD ON CACHE BOOL "Initial pull and build of all dependent libraries/executables")
set (PULSE_DOWNLOAD_BASELINES OFF CACHE BOOL "Download all V&V Scenarios and their baseline result files")
set (PULSE_BUILD_JAVA_UTILS ON CACHE BOOL "Build Java utils for data generation and testing")
if(MSVC)
set(PULSE_BUILD_CLR OFF CACHE BOOL "Build the CLR interface, ensure visual studio was installed with the C++/CLR option enabled")
else()
......@@ -51,7 +52,7 @@ endif()
set (PULSE_IL2CPP_PATCH OFF CACHE BOOL "Patch Protobuf C# to be compatible with the Unity IL2CPP compiler")
mark_as_advanced(PULSE_IL2CPP_PATCH)
if(SUPERBUILD)
if(PULSE_SUPERBUILD)
include(SuperBuild.cmake)
else()
include(Pulse.cmake)
......
......@@ -83,6 +83,8 @@ set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL INTERNAL FORCE)
add_subdirectory("${protobuf_SRC}/cmake" "${protobuf_SRC}-build")
set_target_properties (libprotobuf libprotobuf-lite PROPERTIES FOLDER protobufs)
set(logger_lib)
set(logger_SRC)
if (${PULSE_LOGGER} STREQUAL "log4cpp")
# log4cpp src should have been download to somewhere
if(NOT logger_SRC)
......@@ -98,7 +100,7 @@ if (${PULSE_LOGGER} STREQUAL "log4cpp")
set(BUILD_TESTING OFF CACHE BOOL INTERNAL FORCE)
add_subdirectory(${logger_SRC} ${logger_SRC}-build)
set(logger_lib log4cpp)
else()
elseif (${PULSE_LOGGER} STREQUAL "log4cplus")
# log4cplus src should have been download to somewhere
if(NOT logger_SRC)
# It should be here if the outer build ran
......
if(NOT MSVC)
if(NOT PULSE_BUILD_JAVA_UTILS)
return()
endif()
......
if(NOT PULSE_BUILD_JAVA_UTILS)
return()
endif()
find_package(Java REQUIRED)
include(UseJava)
......
......@@ -3,6 +3,13 @@ include(ExternalProject)
include(CMakeDetermineSystem)
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_GENERATION
CMAKE_GENERATOR ${CMAKE_GENERATOR}
CMAKE_GENERATOR_PLATFORM ${CMAKE_GENERATOR_PLATFORM}
CMAKE_GENERATOR_TOOLSET ${CMAKE_GENERATOR_TOOLSET}
CMAKE_GENERATOR_INSTANCE ${CMAKE_GENERATOR_INSTANCE}
)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_INSTALL_PREFIX})
if(MSVC OR XCode)
# For multi configuration IDE environments start with release
......@@ -25,7 +32,9 @@ ExternalProject_Add( eigen
#UPDATE_COMMAND
# COMMAND ${CMAKE_COMMAND} -Deigen_source=${eigen_SRC} -Deigen_patch=${eigen_Patch} -P ${eigen_Patch}/Patch.cmake
INSTALL_DIR "${CMAKE_INSTALL_PREFIX}"
${CMAKE_GENERATION}
CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE:FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_VERBOSE_MAKEFILE:BOOL=OFF
-DCMAKE_INSTALL_PREFIX:STRING=${CMAKE_INSTALL_PREFIX}
-DINCLUDE_INSTALL_DIR:STRING=${CMAKE_INSTALL_PREFIX}/include
......@@ -36,10 +45,11 @@ message(STATUS "Eigen is here : ${eigen_SRC}" )
# Loggers are built in the Inner build
# It will be easier to switch cofigurations in MSVC/XCode
set(PULSE_LOGGER "log4cpp" CACHE STRING "Select Logger Library")
set(AVAILABLE_PULSE_LOGGERS "log4cpp;log4cplus" CACHE INTERNAL "List of available loggers")
set(PULSE_LOGGER "simple" CACHE STRING "Select Logger Library")
set(AVAILABLE_PULSE_LOGGERS "simple;log4cpp;log4cplus" CACHE INTERNAL "List of available loggers")
set_property(CACHE PULSE_LOGGER PROPERTY STRINGS ${AVAILABLE_PULSE_LOGGERS})
set(logger_SRC)
if (${PULSE_LOGGER} STREQUAL "log4cpp")
###################################################
## log4cpp ##
......@@ -60,16 +70,17 @@ if (${PULSE_LOGGER} STREQUAL "log4cpp")
#GIT_REPOSITORY "https://github.com/log4cplus/log4cpp.git"
#GIT_TAG 411a262b92a7bdc26348d6ae6b15f76763c21b44
#GIT_SHALLOW TRUE
${CMAKE_GENERATION}
UPDATE_COMMAND
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/cmake/log4cpp-patches/CMakeLists.txt ${logger_SRC}/CMakeLists.txt
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/cmake/log4cpp-patches/config.guess ${logger_SRC}/config/config.guess
COMMAND ${CONFIGURE}
#COMMAND ${CONFIGURE}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
list(APPEND Pulse_DEPENDENCIES log4cpp)
else()
elseif(${PULSE_LOGGER} STREQUAL "log4cplus")
###################################################
## log4cplus ##
## General logging utility ##
......@@ -84,9 +95,10 @@ else()
URL_HASH MD5=cb075cd19ce561273b1c74907cc66b6a
#GIT_REPOSITORY "https://github.com/log4cplus/log4cplus.git"
#GIT_TAG 411a262b92a7bdc26348d6ae6b15f76763c21b44
# GIT_SHALLOW TRUE
# Build this in the Inner build
# It will be easier to switch cofigurations in MSVC/XCode
# GIT_SHALLOW TRUE
# Build this in the Inner build
# It will be easier to switch cofigurations in MSVC/XCode
${CMAKE_GENERATION}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
......@@ -115,7 +127,9 @@ ExternalProject_Add( protobuf
SOURCE_SUBDIR ./cmake
UPDATE_COMMAND
COMMAND ${CMAKE_COMMAND} -DPULSE_IL2CPP_PATCH=${PULSE_IL2CPP_PATCH} -Dprotobuf_source=${protobuf_SRC} -Dprotobuf_patch=${protobuf_Patch} -P ${protobuf_Patch}/Patch.cmake
${CMAKE_GENERATION}
CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE:FILE=${CMAKE_TOOLCHAIN_FILE}
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:STRING=${CMAKE_INSTALL_PREFIX}
......@@ -143,10 +157,12 @@ if(WIN32)
PREFIX dirent
URL "https://github.com/tronkko/dirent/archive/1.22.zip"
URL_MD5 ${dirent_MD5}
${CMAKE_GENERATION}
CMAKE_ARGS
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DCMAKE_INSTALL_PREFIX:STRING=${CMAKE_INSTALL_PREFIX}
-DINCLUDE_INSTALL_DIR:STRING=${CMAKE_INSTALL_PREFIX}/include
-DCMAKE_TOOLCHAIN_FILE:FILE=${CMAKE_TOOLCHAIN_FILE}
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DCMAKE_INSTALL_PREFIX:STRING=${CMAKE_INSTALL_PREFIX}
-DINCLUDE_INSTALL_DIR:STRING=${CMAKE_INSTALL_PREFIX}/include
)
message(STATUS "dirent is here : ${dirent_DIR}" )
list(APPEND Pulse_DEPENDENCIES dirent)
......@@ -163,20 +179,25 @@ ExternalProject_Add( Pulse
DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}
SOURCE_DIR ${CMAKE_SOURCE_DIR}
BINARY_DIR ${CMAKE_BINARY_DIR}/Pulse
${CMAKE_GENERATION}
CMAKE_ARGS
-DSUPERBUILD:BOOL=OFF
-DCMAKE_TOOLCHAIN_FILE:FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_PREFIX_PATH:STRING=${CMAKE_PREFIX_PATH}
-DCMAKE_INSTALL_PREFIX:STRING=${CMAKE_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
# Pulse Specific
-DPULSE_SUPERBUILD:BOOL=OFF
-DPULSE_BUILD_JAVA_UTILS:BOOL=${PULSE_BUILD_JAVA_UTILS}
-DPULSE_BUILD_CLR:BOOL=${PULSE_BUILD_CLR}
-DPULSE_LOGGER:STRING=${PULSE_LOGGER}
-DPULSE_LOGGER:STRING=${PULSE_LOGGER}
# Let InnerBuild build and install these
-Dlogger_SRC=${logger_SRC}
-Dprotobuf_SRC=${protobuf_SRC}
)
# Need Java Utils to generate data
if (PULSE_BUILD_JAVA_UTILS)
add_custom_target(PulseData ALL)
add_dependencies(PulseData Pulse)
add_custom_command(TARGET PulseData POST_BUILD
......@@ -185,6 +206,11 @@ add_custom_command(TARGET PulseData POST_BUILD
add_custom_command(TARGET PulseData POST_BUILD
COMMAND ${CMAKE_COMMAND} -DTYPE:STRING=genStates -P run.cmake WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin
WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)
else()
message(WARNING "Without Java Utils, this build will not generate required data files needed for Pulse to execute")
message(WARNING "You will need to get these required data files from another build/source")
endif()
if(PULSE_DOWNLOAD_BASELINES)
message(STATUS "I am going to pull the latest Pulse Baselines!")
add_custom_command(TARGET PulseData POST_BUILD
......
......@@ -106,23 +106,28 @@ file(GLOB INHALER_FILES "cpp/system/equipment/inhaler/*.h" "cpp/system/equipment
source_group("System\\Equipment\\Inhaler" FILES ${INHALER_FILES})
file(GLOB INHALER_ACTION_FILES "cpp/system/equipment/inhaler/actions/*.h" "cpp/system/equipment/inhaler/actions/*.cpp")
source_group("System\\Equipment\\Inhaler\\Actions" FILES ${INHALER_ACTION_FILES})
list(APPEND SOURCE ${ANESTHESIA_FILES})
list(APPEND SOURCE ${ANESTHESIA_ACTION_FILES})
list(APPEND SOURCE ${ECG_FILES})
list(APPEND SOURCE ${INHALER_FILES})
list(APPEND SOURCE ${INHALER_ACTION_FILES})
list(APPEND SOURCE ${MECHANICAL_VENTILATOR_FILES})
list(APPEND SOURCE ${MECHANICAL_VENTILATOR_ACTION_FILES})
list(APPEND SOURCE ${ANESTHESIA_FILES})
list(APPEND SOURCE ${ANESTHESIA_ACTION_FILES})
list(APPEND SOURCE ${ECG_FILES})
list(APPEND SOURCE ${INHALER_FILES})
list(APPEND SOURCE ${INHALER_ACTION_FILES})
list(APPEND SOURCE ${MECHANICAL_VENTILATOR_FILES})
list(APPEND SOURCE ${MECHANICAL_VENTILATOR_ACTION_FILES})
# System\Physiology
file(GLOB PHYSIOLOGY_FILES "cpp/system/physiology/*.h" "cpp/system/physiology/*.cpp")
source_group("System\\Physiology" FILES ${PHYSIOLOGY_FILES})
list(APPEND SOURCE ${PHYSIOLOGY_FILES})
# Utils
file(GLOB UTILS_FILES "cpp/utils/*.h" "cpp/utils/*.cpp")
if (${PULSE_LOGGER} STREQUAL "log4cpp")
if (${PULSE_LOGGER} STREQUAL "simple")
list(REMOVE_ITEM UTILS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/utils/Log4cplus.cpp)
else()
list(REMOVE_ITEM UTILS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/utils/Log4cpp.cpp)
elseif (${PULSE_LOGGER} STREQUAL "log4cplus")
list(REMOVE_ITEM UTILS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/utils/SimpleLogger.cpp)
list(REMOVE_ITEM UTILS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/utils/Log4cpp.cpp)
elseif (${PULSE_LOGGER} STREQUAL "log4cpp")
list(REMOVE_ITEM UTILS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/utils/SimpleLogger.cpp)
list(REMOVE_ITEM UTILS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/utils/Log4cplus.cpp)
endif()
source_group("Utils" FILES ${UTILS_FILES})
file(GLOB UTILS_TESTING_FILES "cpp/utils/testing/*.h" "cpp/utils/testing/*.cpp")
......@@ -177,10 +182,12 @@ set_target_properties(CommonDataModel PROPERTIES
DEBUG_POSTFIX "${PULSE_DEBUG_POSTFIX}"
RELWITHDEBINFO_POSTFIX "${PULSE_RELWITHDEBINFO_POSTFIX}")
if(APPLE)
set_target_properties(CommonDataModel PROPERTIES MACOSX_RPATH ON)
set_target_properties(CommonDataModel PROPERTIES MACOSX_RPATH ON)
endif()
target_link_libraries(CommonDataModel DataModelBindings)
target_link_libraries(CommonDataModel ${logger_lib})
if(logger_lib)
target_link_libraries(CommonDataModel ${logger_lib})
endif()
if(${BUILD_SHARED_LIBS})
add_custom_command(TARGET CommonDataModel POST_BUILD
......
......@@ -36,6 +36,7 @@
#include <fstream>
#include <stdexcept>
#include <algorithm>
#include <cmath>
#ifdef _MSC_VER
#include <direct.h>
......
......@@ -21,7 +21,6 @@
#include "properties/SEScalarMassPerVolume.h"
#include "properties/SEScalarAmountPerVolume.h"
#include <cmath>
#include <iterator>
DataTrack::DataTrack() : DataTrack(nullptr)
......
......@@ -74,7 +74,6 @@ public:
enum class level
{
Trace,
Debug,
Info,
Warn,
......
/* Distributed under the Apache License, Version 2.0.
See accompanying NOTICE file for details.*/
#include "stdafx.h"
#include "utils/Logger.h"
#include "utils/FileUtils.h"
#include "properties/SEScalarTime.h"
const std::string Loggable::empty("");
class log_lib
{
public:
log_lib()
{
}
virtual ~log_lib()
{
}
bool log(Logger::level requested_level)
{
if (_log_level < requested_level)
return false;
if (!_log_to_console && !_log_to_file)
return false;
return true;
}
void log(Logger::level requested_level, const std::string& out)
{
if (_last_requested_level != requested_level)
{
switch (requested_level)
{
case Logger::level::Debug:
_str_requested_level = "[DEBUG]";
break;
case Logger::level::Info:
_str_requested_level = "[INFO]";
break;
case Logger::level::Warn:
_str_requested_level = "[WARN]";
break;
case Logger::level::Error:
_str_requested_level = "[ERROR]";
break;
case Logger::level::Fatal:
_str_requested_level = "[FATAL]";
break;
}
_last_requested_level = requested_level;
}
if (_log_to_console)
std::cout << _str_requested_level << out << "\n";
if (_log_to_file)
_file << _str_requested_level << out << std::endl;
}
bool _log_to_console = true;
bool _log_to_file = true;
Logger::level _log_level = Logger::level::Info;
std::string _str_requested_level = "[INFO]";
Logger::level _last_requested_level = Logger::level::Info;
std::ofstream _file;
};
void Logger::Initialize() {}
void Logger::Deinitialize() {}
//logger constructor
Logger::Logger(const std::string& logFilename)
{
m_Forward = nullptr;
m_time = nullptr;
_log_lib = new log_lib();
ResetLogFile(logFilename);
}
void Logger::LogToConsole(bool b)
{
_log_lib->_log_to_console = b;
}
void Logger::ResetLogFile(const std::string& logFilename)
{
if (logFilename.empty())
{
_log_lib->_log_to_file = false;
return;
}
_log_lib->_log_to_file = true;
SetLogLevel(level::Info);
CreateFilePath(logFilename);
_log_lib->_file.close();
// delete previous log contents if it exists
_log_lib->_file.open(logFilename.c_str(), std::ofstream::out | std::ofstream::trunc);
}
Logger::~Logger()
{
delete _log_lib;
}
void Logger::SetLogTime(const SEScalarTime* time)
{
m_time = time;
}
//This function will change the priority of the logger
void Logger::SetLogLevel(Logger::level l)
{
_log_lib->_log_level = l;
}
//This function will return the priority of the logger
Logger::level Logger::GetLogLevel()
{
return _log_lib->_log_level;
}
void Logger::SetForward(LoggerForward* forward)
{
m_Forward = forward;
}
bool Logger::HasForward()
{
return m_Forward == nullptr ? false : true;
}
std::string Logger::FormatLogMessage(const std::string& msg, const std::string& origin)
{
m_ss.str("");
m_ss.clear();
if (m_time != nullptr && m_time->IsValid())
m_ss << "[" << *m_time << "] " << msg;
else
m_ss << msg;
if (msg.empty())
return origin;
return origin + " : " + m_ss.str();
}
void Logger::Debug(std::string const& msg, const std::string& origin)
{
if (_log_lib->log(level::Debug))
{
_log_lib->log(level::Debug, FormatLogMessage(msg, origin));
if (m_Forward != nullptr)
m_Forward->ForwardDebug(m_ss.str().c_str(), origin.c_str());
}
}
void Logger::Debug(std::stringstream &msg, const std::string& origin)
{
Debug(msg.str(), origin);
msg.str("");
msg.clear();
}
void Logger::Debug(std::ostream &msg, const std::string& origin)
{
std::stringstream ss;
ss << msg.rdbuf();
Debug(ss.str(), origin);
}
void Logger::Info(const std::string& msg, const std::string& origin)
{
if (_log_lib->log(level::Info))
{
_log_lib->log(level::Info, FormatLogMessage(msg, origin));
if (m_Forward != nullptr)
m_Forward->ForwardInfo(m_ss.str().c_str(), origin.c_str());
}
}
void Logger::Info(std::stringstream &msg, const std::string& origin)
{
Info(msg.str(), origin);
msg.str("");
msg.clear();
}
void Logger::Info(const std::stringstream &msg, const std::string& origin)
{
Info(msg.str(), origin);
}
void Logger::Info(std::ostream &msg, const std::string& origin)
{
std::stringstream ss;
ss << msg.rdbuf();
Info(ss.str(), origin);
}
void Logger::Warning(const std::string& msg, const std::string& origin)
{
if (_log_lib->log(level::Warn))
{
_log_lib->log(level::Warn, FormatLogMessage(msg, origin));
if (m_Forward != nullptr)
m_Forward->ForwardWarning(m_ss.str().c_str(), origin.c_str());
}
}
void Logger::Warning(std::stringstream &msg, const std::string& origin)
{
Warning(msg.str(), origin);
msg.str("");
msg.clear();
}
void Logger::Warning(std::ostream &msg, const std::string& origin)
{
std::stringstream ss;
ss << msg.rdbuf();
Warning(ss.str(), origin);
}
void Logger::Error(const std::string& msg, const std::string& origin)
{
if (_log_lib->log(level::Error))
{
_log_lib->log(level::Error, FormatLogMessage(msg, origin));
if (m_Forward != nullptr)
m_Forward->ForwardError(m_ss.str().c_str(), origin.c_str());
}
}
void Logger::Error(std::stringstream &msg, const std::string& origin)
{
Error(msg.str(), origin);
msg.str("");
msg.clear();
}
void Logger::Error(std::ostream &msg, const std::string& origin)
{
std::stringstream ss;
ss << msg.rdbuf();
Error(ss.str(), origin);
}
void Logger::Fatal(const std::string& msg, const std::string& origin)
{
if (_log_lib->log(level::Fatal))
{
_log_lib->log(level::Fatal, FormatLogMessage(msg, origin));
if (m_Forward != nullptr)
m_Forward->ForwardFatal(m_ss.str().c_str(), origin.c_str());
}
}
void Logger::Fatal(std::stringstream &msg, const std::string& origin)
{
Fatal(msg.str(), origin);
msg.str("");
msg.clear();
}
void Logger::Fatal(std::ostream &msg, const std::string& origin)
{
std::stringstream ss;
ss << msg.rdbuf();
Fatal(ss.str(), origin);
}
Loggable::Loggable()
{
m_Logger = nullptr;
}
Loggable::Loggable(Logger* logger)
{
m_Logger = logger;
}
Loggable::~Loggable()
{
}
Logger* Loggable::GetLogger() const
{
return m_Logger;
}
void Loggable::Debug(const std::string& msg, const std::string& origin) const
{
if (m_Logger)
m_Logger->Debug(msg, origin);
}
void Loggable::Debug(std::stringstream& msg, const std::string& origin) const
{
Debug(msg.str(), origin);
msg.str("");
msg.clear();
}
void Loggable::Debug(std::ostream& msg, const std::string& origin) const
{
std::stringstream ss;
ss << msg.rdbuf();
Debug(ss.str(), origin);
}
void Loggable::Info(const std::stringstream &msg, const std::string& origin) const
{
Info(msg.str(), origin);
}
void Loggable::Info(std::ostream &msg, const std::string& origin) const
{
std::stringstream ss;
ss << msg.rdbuf();
Info(ss.str(), origin);
}
void Loggable::Warning(const std::string& msg, const std::string& origin) const
{
if (m_Logger)
m_Logger->Warning(msg, origin);
}
void Loggable::Warning(std::stringstream &msg, const std::string& origin) const
{
Warning(msg.str(), origin);
msg.str("");
msg.clear();
}
void Loggable::Warning(std::ostream &msg, const std::string& origin) const
{
std::stringstream ss;
ss << msg.rdbuf();
Warning(ss.str(), origin);
}
void Loggable::Error(const std::string& msg, const std::string& origin) const
{
if (m_Logger)
m_Logger->Error(msg, origin);
}
void Loggable::Error(std::stringstream& msg, const std::string& origin) const
{
Error(msg.str(), origin);
msg.str("");
msg.clear();
}
void Loggable::Error(std::ostream& msg, const std::string& origin) const
{
std::stringstream ss;