diff --git a/CMakeLists.txt b/CMakeLists.txt index b00562b71..d9ab6cd29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,8 @@ set(AGENT_VERSION_MAJOR 2) set(AGENT_VERSION_MINOR 1) set(AGENT_VERSION_PATCH 0) -set(AGENT_VERSION_BUILD 3) -set(AGENT_VERSION_RC "_RC2") +set(AGENT_VERSION_BUILD 2) +set(AGENT_VERSION_RC "_RC1") # This minimum version is to support Visual Studio 2017 and C++ feature checking and FetchContent cmake_minimum_required(VERSION 3.16 FATAL_ERROR) @@ -15,6 +15,7 @@ if(POLICY CMP0077) endif() option(AGENT_ENABLE_UNITTESTS "Enables the agent's unit tests" ON) +option(SHARED_AGENT_LIB "Generate shared agent library. Conan options: shared" OFF) set(INSTALL_GTEST OFF FORCE) project(cppagent LANGUAGES C CXX) @@ -24,9 +25,9 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CXX_COMPILE_FEATURES cxx_std_17) +set(SHARED_AGENT_LIB OFF CACHE BOOL "Build Agent Lib as shared library") -set(WITH_PYTHON OFF CACHE STRING "With Python Support") -set(WITH_RUBY OFF CACHE STRING "With Ruby Support") +set(WITH_RUBY ON CACHE STRING "With Ruby Support") # By default only generate 2 configurations (Debug and Release) for simplicity. # The user can change this option if required for the additional ones such as 'RelWithDebInfo'. @@ -64,7 +65,11 @@ if(MSVC) endif() if (UNIX) - add_compile_options(-fPIC -Wno-psabi -fvisibility-inlines-hidden -fvisibility=hidden) + if (SHARED_AGENT_LIB) + add_compile_options(-fPIC -Wno-psabi -fvisibility-inlines-hidden) + else() + add_compile_options(-fPIC -Wno-psabi -fvisibility-inlines-hidden -fvisibility=hidden) + endif() ENDIF() include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) @@ -73,17 +78,16 @@ if (CONAN_USER_MRUBY_mruby) set(WITH_RUBY ON FORCE) endif() -conan_basic_setup(TARGETS) +conan_basic_setup(KEEP_RPATHS TARGETS) -if(WITH_PYTHON) - set(Python_USE_STATIC_LIBS ON) +if(SHARED_AGENT_LIB) + set(CMAKE_BUILD_RPATH "@load_path/;@executable_path/;@load_path/../lib;@executable_path/../lib") - find_package(Python3 COMPONENTS Interpreter Development Development.Embed) - message("Include dirs of Python: " ${Python3_INCLUDE_DIRS} ) - message("Libs of Python: " ${Python3_LIBRARIES} ) + if (MSVC) + include(InstallRequiredSystemLibraries) + endif() endif() -include(cmake/msvc_use_static_runtime.cmake) include(cmake/osx_no_app_or_frameworks.cmake) include(cmake/ClangFormat.cmake) include(cmake/ClangTidy.cmake) diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt index 8a37ac68a..82f5405e1 100644 --- a/agent/CMakeLists.txt +++ b/agent/CMakeLists.txt @@ -4,15 +4,12 @@ if(WIN32) # Version info string(TIMESTAMP AGENT_VERSION_TIME "%Y-%m-%dT%H:%M:%SZ" UTC) set(RESOURCE_FILE "${PROJECT_BINARY_DIR}/agent/version.rc") - configure_file("${CMAKE_CURRENT_LIST_DIR}/../src/version.rc.in" "${RESOURCE_FILE}") + configure_file("${CMAKE_CURRENT_LIST_DIR}/../src/mtconnect/version.rc.in" "${RESOURCE_FILE}") list(APPEND AGENT_SOURCES "${RESOURCE_FILE}") endif() add_executable(agent ${AGENT_SOURCES}) -set_property(TARGET agent PROPERTY - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - if(WITH_PYTHON) target_compile_definitions( agent @@ -36,7 +33,7 @@ endif() target_link_libraries( agent - PRIVATE + PUBLIC agent_lib $<$:shlwapi> ) @@ -44,3 +41,12 @@ target_link_libraries( target_clangtidy_setup(agent_lib) install(TARGETS agent RUNTIME DESTINATION bin) + + +if(SHARED_AGENT_LIB AND MSVC) + set(CMAKE_INSTALL_DEBUG_LIBRARIES ON) + include(InstallRequiredSystemLibraries) + install(FILES ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION bin COMPONENT Libraries) + install(DIRECTORY "${PROJECT_BINARY_DIR}/bin/" DESTINATION bin COMPONENT Libraries + FILES_MATCHING PATTERN "*.dll") +endif() diff --git a/agent/cppagent.cpp b/agent/cppagent.cpp index d8e279e22..ae86382a3 100644 --- a/agent/cppagent.cpp +++ b/agent/cppagent.cpp @@ -16,11 +16,11 @@ // #include -#include "agent.hpp" -#include "configuration/agent_config.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/configuration/agent_config.hpp" -#include "fcntl.h" -#include "sys/stat.h" +#include +#include #include diff --git a/agent_lib/CMakeLists.txt b/agent_lib/CMakeLists.txt index 748dd4234..99e1224e5 100644 --- a/agent_lib/CMakeLists.txt +++ b/agent_lib/CMakeLists.txt @@ -1,297 +1,293 @@ +set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../src/mtconnect") + set(AGENT_SOURCES # src HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/agent.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/logging.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/utilities.hpp" + "${SOURCE_DIR}/agent.hpp" + "${SOURCE_DIR}/config.hpp" + "${SOURCE_DIR}/logging.hpp" + "${SOURCE_DIR}/utilities.hpp" # src SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/agent.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/utilities.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/version.cpp" + "${SOURCE_DIR}/agent.cpp" + "${SOURCE_DIR}/utilities.cpp" + "${SOURCE_DIR}/version.cpp" # src/asset HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/asset.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/asset_buffer.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/asset_storage.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/cutting_tool.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/file_asset.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/raw_material.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/qif_document.hpp" + "${SOURCE_DIR}/asset/asset.hpp" + "${SOURCE_DIR}/asset/asset_buffer.hpp" + "${SOURCE_DIR}/asset/asset_storage.hpp" + "${SOURCE_DIR}/asset/cutting_tool.hpp" + "${SOURCE_DIR}/asset/file_asset.hpp" + "${SOURCE_DIR}/asset/raw_material.hpp" + "${SOURCE_DIR}/asset/qif_document.hpp" # src/asset SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/asset.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/cutting_tool.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/file_asset.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/raw_material.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/asset/qif_document.cpp" + "${SOURCE_DIR}/asset/asset.cpp" + "${SOURCE_DIR}/asset/cutting_tool.cpp" + "${SOURCE_DIR}/asset/file_asset.cpp" + "${SOURCE_DIR}/asset/raw_material.cpp" + "${SOURCE_DIR}/asset/qif_document.cpp" # src/buffer HEADER_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/buffer/checkpoint.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/buffer/circular_buffer.hpp" + "${SOURCE_DIR}/buffer/checkpoint.hpp" + "${SOURCE_DIR}/buffer/circular_buffer.hpp" # src/buffer SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/buffer/checkpoint.cpp" + "${SOURCE_DIR}/buffer/checkpoint.cpp" # src/configuration HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/configuration/agent_config.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/configuration/async_context.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/configuration/config_options.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/configuration/parser.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/configuration/service.hpp" + "${SOURCE_DIR}/configuration/agent_config.hpp" + "${SOURCE_DIR}/configuration/async_context.hpp" + "${SOURCE_DIR}/configuration/config_options.hpp" + "${SOURCE_DIR}/configuration/hook_manager.hpp" + "${SOURCE_DIR}/configuration/parser.hpp" + "${SOURCE_DIR}/configuration/service.hpp" # src/configuration SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/configuration/agent_config.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/configuration/parser.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/configuration/service.cpp" + "${SOURCE_DIR}/configuration/agent_config.cpp" + "${SOURCE_DIR}/configuration/parser.cpp" + "${SOURCE_DIR}/configuration/service.cpp" # src/device_model HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/agent_device.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/component.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/composition.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/description.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/device.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/reference.hpp" + "${SOURCE_DIR}/device_model/agent_device.hpp" + "${SOURCE_DIR}/device_model/component.hpp" + "${SOURCE_DIR}/device_model/composition.hpp" + "${SOURCE_DIR}/device_model/description.hpp" + "${SOURCE_DIR}/device_model/device.hpp" + "${SOURCE_DIR}/device_model/reference.hpp" # src/device_model SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/agent_device.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/component.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/composition.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/description.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/device.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/reference.cpp" + "${SOURCE_DIR}/device_model/agent_device.cpp" + "${SOURCE_DIR}/device_model/component.cpp" + "${SOURCE_DIR}/device_model/composition.cpp" + "${SOURCE_DIR}/device_model/description.cpp" + "${SOURCE_DIR}/device_model/device.cpp" + "${SOURCE_DIR}/device_model/reference.cpp" # src/device_model/configuration HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/configuration.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/coordinate_systems.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/motion.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/relationships.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/sensor_configuration.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/solid_model.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/specifications.hpp" + "${SOURCE_DIR}/device_model/configuration/configuration.hpp" + "${SOURCE_DIR}/device_model/configuration/coordinate_systems.hpp" + "${SOURCE_DIR}/device_model/configuration/motion.hpp" + "${SOURCE_DIR}/device_model/configuration/relationships.hpp" + "${SOURCE_DIR}/device_model/configuration/sensor_configuration.hpp" + "${SOURCE_DIR}/device_model/configuration/solid_model.hpp" + "${SOURCE_DIR}/device_model/configuration/specifications.hpp" # src/device_model/configuration SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/configuration.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/coordinate_systems.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/motion.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/relationships.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/sensor_configuration.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/solid_model.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/configuration/specifications.cpp" + "${SOURCE_DIR}/device_model/configuration/configuration.cpp" + "${SOURCE_DIR}/device_model/configuration/coordinate_systems.cpp" + "${SOURCE_DIR}/device_model/configuration/motion.cpp" + "${SOURCE_DIR}/device_model/configuration/relationships.cpp" + "${SOURCE_DIR}/device_model/configuration/sensor_configuration.cpp" + "${SOURCE_DIR}/device_model/configuration/solid_model.cpp" + "${SOURCE_DIR}/device_model/configuration/specifications.cpp" # src/device_model/data_item HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/data_item/constraints.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/data_item/data_item.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/data_item/definition.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/data_item/filter.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/data_item/relationships.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/data_item/source.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/data_item/unit_conversion.hpp" + "${SOURCE_DIR}/device_model/data_item/constraints.hpp" + "${SOURCE_DIR}/device_model/data_item/data_item.hpp" + "${SOURCE_DIR}/device_model/data_item/definition.hpp" + "${SOURCE_DIR}/device_model/data_item/filter.hpp" + "${SOURCE_DIR}/device_model/data_item/relationships.hpp" + "${SOURCE_DIR}/device_model/data_item/source.hpp" + "${SOURCE_DIR}/device_model/data_item/unit_conversion.hpp" # src/device_model/data_item SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/data_item/data_item.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/device_model/data_item/unit_conversion.cpp" + "${SOURCE_DIR}/device_model/data_item/data_item.cpp" + "${SOURCE_DIR}/device_model/data_item/unit_conversion.cpp" # src/entity HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/data_set.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/entity.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/factory.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/json_parser.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/json_printer.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/qname.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/requirement.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/xml_parser.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/xml_printer.hpp" + "${SOURCE_DIR}/entity/data_set.hpp" + "${SOURCE_DIR}/entity/entity.hpp" + "${SOURCE_DIR}/entity/factory.hpp" + "${SOURCE_DIR}/entity/json_parser.hpp" + "${SOURCE_DIR}/entity/json_printer.hpp" + "${SOURCE_DIR}/entity/qname.hpp" + "${SOURCE_DIR}/entity/requirement.hpp" + "${SOURCE_DIR}/entity/xml_parser.hpp" + "${SOURCE_DIR}/entity/xml_printer.hpp" # src/entity SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/data_set.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/entity.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/factory.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/json_parser.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/json_printer.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/requirement.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/xml_parser.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/entity/xml_printer.cpp" + "${SOURCE_DIR}/entity/data_set.cpp" + "${SOURCE_DIR}/entity/entity.cpp" + "${SOURCE_DIR}/entity/factory.cpp" + "${SOURCE_DIR}/entity/json_parser.cpp" + "${SOURCE_DIR}/entity/json_printer.cpp" + "${SOURCE_DIR}/entity/requirement.cpp" + "${SOURCE_DIR}/entity/xml_parser.cpp" + "${SOURCE_DIR}/entity/xml_printer.cpp" # src/mqtt HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/mqtt/mqtt_authorization.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/mqtt/mqtt_client.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/mqtt/mqtt_server.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/mqtt/mqtt_client_impl.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/mqtt/mqtt_server_impl.hpp" + "${SOURCE_DIR}/mqtt/mqtt_authorization.hpp" + "${SOURCE_DIR}/mqtt/mqtt_client.hpp" + "${SOURCE_DIR}/mqtt/mqtt_server.hpp" + "${SOURCE_DIR}/mqtt/mqtt_client_impl.hpp" + "${SOURCE_DIR}/mqtt/mqtt_server_impl.hpp" # src/observation HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/observation/change_observer.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/observation/observation.hpp" + "${SOURCE_DIR}/observation/change_observer.hpp" + "${SOURCE_DIR}/observation/observation.hpp" #src/observation SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/observation/change_observer.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/observation/observation.cpp" + "${SOURCE_DIR}/observation/change_observer.cpp" + "${SOURCE_DIR}/observation/observation.cpp" # src/parser HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/parser/xml_parser.hpp" + "${SOURCE_DIR}/parser/xml_parser.hpp" # src/parser SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/parser/xml_parser.cpp" + "${SOURCE_DIR}/parser/xml_parser.cpp" # src/pipeline HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/convert_sample.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/deliver.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/delta_filter.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/duplicate_filter.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/guard.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/message_mapper.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/mtconnect_xml_transform.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/period_filter.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/pipeline.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/pipeline_context.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/pipeline_contract.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/response_document.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/shdr_token_mapper.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/shdr_tokenizer.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/timestamp_extractor.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/topic_mapper.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/transform.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/upcase_value.hpp" + "${SOURCE_DIR}/pipeline/convert_sample.hpp" + "${SOURCE_DIR}/pipeline/deliver.hpp" + "${SOURCE_DIR}/pipeline/delta_filter.hpp" + "${SOURCE_DIR}/pipeline/duplicate_filter.hpp" + "${SOURCE_DIR}/pipeline/guard.hpp" + "${SOURCE_DIR}/pipeline/message_mapper.hpp" + "${SOURCE_DIR}/pipeline/mtconnect_xml_transform.hpp" + "${SOURCE_DIR}/pipeline/period_filter.hpp" + "${SOURCE_DIR}/pipeline/pipeline.hpp" + "${SOURCE_DIR}/pipeline/pipeline_context.hpp" + "${SOURCE_DIR}/pipeline/pipeline_contract.hpp" + "${SOURCE_DIR}/pipeline/response_document.hpp" + "${SOURCE_DIR}/pipeline/shdr_token_mapper.hpp" + "${SOURCE_DIR}/pipeline/shdr_tokenizer.hpp" + "${SOURCE_DIR}/pipeline/timestamp_extractor.hpp" + "${SOURCE_DIR}/pipeline/topic_mapper.hpp" + "${SOURCE_DIR}/pipeline/transform.hpp" + "${SOURCE_DIR}/pipeline/upcase_value.hpp" # src/pipeline SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/deliver.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/shdr_token_mapper.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/timestamp_extractor.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/pipeline/response_document.cpp" + "${SOURCE_DIR}/pipeline/deliver.cpp" + "${SOURCE_DIR}/pipeline/shdr_token_mapper.cpp" + "${SOURCE_DIR}/pipeline/timestamp_extractor.cpp" + "${SOURCE_DIR}/pipeline/response_document.cpp" # src/printer HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/printer/json_printer.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/printer/printer.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/printer/xml_helper.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/printer/xml_printer.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/printer/xml_printer_helper.hpp" + "${SOURCE_DIR}/printer/json_printer.hpp" + "${SOURCE_DIR}/printer/printer.hpp" + "${SOURCE_DIR}/printer/xml_helper.hpp" + "${SOURCE_DIR}/printer/xml_printer.hpp" + "${SOURCE_DIR}/printer/xml_printer_helper.hpp" # src/printer SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/printer/json_printer.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/printer/xml_printer.cpp" + "${SOURCE_DIR}/printer/json_printer.cpp" + "${SOURCE_DIR}/printer/xml_printer.cpp" # src/source HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/adapter.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/adapter_pipeline.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/agent_adapter/agent_adapter.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/agent_adapter/http_session.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/agent_adapter/https_session.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/agent_adapter/session.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/agent_adapter/session_impl.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/agent_adapter/url_parser.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/mqtt/mqtt_adapter.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/shdr/connector.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/shdr/shdr_adapter.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/shdr/shdr_pipeline.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/error_code.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/loopback_source.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/source.hpp" + "${SOURCE_DIR}/source/adapter/adapter.hpp" + "${SOURCE_DIR}/source/adapter/adapter_pipeline.hpp" + "${SOURCE_DIR}/source/adapter/agent_adapter/agent_adapter.hpp" + "${SOURCE_DIR}/source/adapter/agent_adapter/http_session.hpp" + "${SOURCE_DIR}/source/adapter/agent_adapter/https_session.hpp" + "${SOURCE_DIR}/source/adapter/agent_adapter/session.hpp" + "${SOURCE_DIR}/source/adapter/agent_adapter/session_impl.hpp" + "${SOURCE_DIR}/source/adapter/agent_adapter/url_parser.hpp" + "${SOURCE_DIR}/source/adapter/mqtt/mqtt_adapter.hpp" + "${SOURCE_DIR}/source/adapter/shdr/connector.hpp" + "${SOURCE_DIR}/source/adapter/shdr/shdr_adapter.hpp" + "${SOURCE_DIR}/source/adapter/shdr/shdr_pipeline.hpp" + "${SOURCE_DIR}/source/error_code.hpp" + "${SOURCE_DIR}/source/loopback_source.hpp" + "${SOURCE_DIR}/source/source.hpp" # src/source SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/adapter_pipeline.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/mqtt/mqtt_adapter.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/shdr/connector.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/shdr/shdr_adapter.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/shdr/shdr_pipeline.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/loopback_source.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/source.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/agent_adapter/agent_adapter.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/agent_adapter/url_parser.cpp" + "${SOURCE_DIR}/source/adapter/adapter_pipeline.cpp" + "${SOURCE_DIR}/source/adapter/mqtt/mqtt_adapter.cpp" + "${SOURCE_DIR}/source/adapter/shdr/connector.cpp" + "${SOURCE_DIR}/source/adapter/shdr/shdr_adapter.cpp" + "${SOURCE_DIR}/source/adapter/shdr/shdr_pipeline.cpp" + "${SOURCE_DIR}/source/loopback_source.cpp" + "${SOURCE_DIR}/source/source.cpp" + "${SOURCE_DIR}/source/adapter/agent_adapter/agent_adapter.cpp" + "${SOURCE_DIR}/source/adapter/agent_adapter/url_parser.cpp" # src/sink HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/sink.hpp" + "${SOURCE_DIR}/sink/sink.hpp" # src/sink SOURCE_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/sink.cpp" + "${SOURCE_DIR}/sink/sink.cpp" # src/sink/mqtt_sink HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/mqtt_sink/mqtt_service.hpp" + "${SOURCE_DIR}/sink/mqtt_sink/mqtt_service.hpp" #src/sink/mqtt_sink SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/mqtt_sink/mqtt_service.cpp" + "${SOURCE_DIR}/sink/mqtt_sink/mqtt_service.cpp" # src/sink/rest_sink HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/cached_file.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/file_cache.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/parameter.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/request.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/response.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/rest_service.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/routing.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/server.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/session.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/session_impl.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/tls_dector.hpp" + "${SOURCE_DIR}/sink/rest_sink/cached_file.hpp" + "${SOURCE_DIR}/sink/rest_sink/file_cache.hpp" + "${SOURCE_DIR}/sink/rest_sink/parameter.hpp" + "${SOURCE_DIR}/sink/rest_sink/request.hpp" + "${SOURCE_DIR}/sink/rest_sink/response.hpp" + "${SOURCE_DIR}/sink/rest_sink/rest_service.hpp" + "${SOURCE_DIR}/sink/rest_sink/routing.hpp" + "${SOURCE_DIR}/sink/rest_sink/server.hpp" + "${SOURCE_DIR}/sink/rest_sink/session.hpp" + "${SOURCE_DIR}/sink/rest_sink/session_impl.hpp" + "${SOURCE_DIR}/sink/rest_sink/tls_dector.hpp" # src/sink/rest_sink SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/file_cache.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/rest_service.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/server.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/session_impl.cpp" + "${SOURCE_DIR}/sink/rest_sink/file_cache.cpp" + "${SOURCE_DIR}/sink/rest_sink/rest_service.cpp" + "${SOURCE_DIR}/sink/rest_sink/server.cpp" + "${SOURCE_DIR}/sink/rest_sink/session_impl.cpp" ) -if(WITH_PYTHON) - set(AGENT_SOURCES ${AGENT_SOURCES} - - "${CMAKE_CURRENT_SOURCE_DIR}/../src/python/embedded.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/python/embedded.cpp" - ) -endif() - if(WITH_RUBY) set(AGENT_SOURCES ${AGENT_SOURCES} # HEADER_FILE_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/embedded.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/ruby_agent.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/ruby_entity.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/ruby_observation.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/ruby_pipeline.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/ruby_smart_ptr.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/ruby_transform.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/ruby_type.hpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/ruby_vm.hpp" + "${SOURCE_DIR}/ruby/embedded.hpp" + "${SOURCE_DIR}/ruby/ruby_agent.hpp" + "${SOURCE_DIR}/ruby/ruby_entity.hpp" + "${SOURCE_DIR}/ruby/ruby_observation.hpp" + "${SOURCE_DIR}/ruby/ruby_pipeline.hpp" + "${SOURCE_DIR}/ruby/ruby_smart_ptr.hpp" + "${SOURCE_DIR}/ruby/ruby_transform.hpp" + "${SOURCE_DIR}/ruby/ruby_type.hpp" + "${SOURCE_DIR}/ruby/ruby_vm.hpp" #SOURCE_FILES_ONLY - "${CMAKE_CURRENT_SOURCE_DIR}/../src/ruby/embedded.cpp" + "${SOURCE_DIR}/ruby/embedded.cpp" ) endif() ## configure a header file to pass some of the CMake settings to the source code -configure_file("${CMAKE_CURRENT_SOURCE_DIR}/../src/version.h.in" "${PROJECT_BINARY_DIR}/agent_lib/version.h") +configure_file("${SOURCE_DIR}/version.h.in" "${PROJECT_BINARY_DIR}/agent_lib/mtconnect/version.h") set(AGENT_LIB_HEADERS ${AGENT_SOURCES}) list(FILTER AGENT_LIB_HEADERS INCLUDE REGEX "\\.(h|hpp|ipp)$") @@ -301,29 +297,49 @@ list(FILTER AGENT_LIB_SOURCES INCLUDE REGEX "\\.(c|cpp)$") # For IDE Grouping source_group("Header Files") source_group("Source Files") -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/../src" PREFIX "Header Files" FILES ${AGENT_LIB_HEADERS}) -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/../src" PREFIX "Source Files" FILES ${AGENT_LIB_SOURCES}) +source_group(TREE "${SOURCE_DIR}" PREFIX "Header Files" FILES ${AGENT_LIB_HEADERS}) +source_group(TREE "${SOURCE_DIR}" PREFIX "Source Files" FILES ${AGENT_LIB_SOURCES}) if(MSVC) if(CMAKE_GENERATOR_TOOLSET) if(${CMAKE_GENERATOR_TOOLSET} MATCHES "v14[01]_xp") message(info ": Setting /Ob1 for rest_sink/session_impl.cpp") - set_property(SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/session_impl.cpp" + set_property(SOURCE "${SOURCE_DIR}/sink/rest_sink/session_impl.cpp" PROPERTY COMPILE_FLAGS "/Ob1") endif() endif() # The modules including Beast required the /bigobj option in Windows set_property(SOURCE - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/mqtt_sink/mqtt_service.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/sink/rest_sink/session_impl.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/mqtt/mqtt_adapter.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../src/source/adapter/agent_adapter/agent_adapter.cpp" + "${SOURCE_DIR}/sink/mqtt_sink/mqtt_service.cpp" + "${SOURCE_DIR}/sink/rest_sink/session_impl.cpp" + "${SOURCE_DIR}/source/adapter/mqtt/mqtt_adapter.cpp" + "${SOURCE_DIR}/source/adapter/agent_adapter/agent_adapter.cpp" + "${SOURCE_DIR}/source/adapter/shdr/shdr_pipeline.cpp" + "${SOURCE_DIR}/source/adapter/adapter_pipeline.cpp" + "${SOURCE_DIR}/device_model/component.cpp" + "${SOURCE_DIR}/configuration/agent_config.cpp" + "${SOURCE_DIR}/sink/rest_sink/rest_service.cpp" + "${SOURCE_DIR}/ruby/embedded.cpp" + "${SOURCE_DIR}/pipeline/deliver.cpp" + "${SOURCE_DIR}/agent.cpp" PROPERTY COMPILE_FLAGS "/bigobj") endif() +if(SHARED_AGENT_LIB) + add_library(agent_lib SHARED ${AGENT_SOURCES}) + target_compile_definitions( + agent_lib + PRIVATE + AGENT_BUILD_SHARED_LIB) + target_compile_definitions( + agent_lib + PUBLIC + SHARED_AGENT_LIB) +else() + add_library(agent_lib STATIC ${AGENT_SOURCES}) +endif() -add_library(agent_lib STATIC ${AGENT_SOURCES}) target_include_directories( agent_lib PUBLIC @@ -332,9 +348,6 @@ target_include_directories( "${CMAKE_CURRENT_LIST_DIR}/../src" ) -set_property(TARGET agent_lib PROPERTY - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - target_link_libraries( agent_lib PUBLIC @@ -344,13 +357,6 @@ target_link_libraries( $<$:bcrypt> ) -if(WITH_PYTHON) - target_link_libraries( - agent_lib - PUBLIC - Python3::Python) -endif() - if(WITH_RUBY) target_link_libraries( agent_lib diff --git a/appveyor.yml b/appveyor.yml index d3492868d..cf05ebc35 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,15 +7,14 @@ branches: image: - - Ubuntu2004 - - Visual Studio 2019 - macOS + - Visual Studio 2019 + - Ubuntu2004 environment: matrix: - - WITH_RUBY: True - -# - WITH_RUBY: False + - SHARED: True + - SHARED: False configuration: - Release @@ -43,18 +42,21 @@ init: before_build: - cmd: |- set PATH=C:\Python39-x64\;C:\Python39-x64\Scripts;C:\Ruby30\bin;%PATH% - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat" - set + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" if not exist C:\conan mkdir C:\conan + if %SHARED%==True (set CONAN_PROFILE=conan/profiles/vs64shared) else (set CONAN_PROFILE=conan/profiles/vs64) set CONAN_USER_HOME=C:\conan + set pip install conan conan export conan/mqtt_cpp conan export conan/mruby - conan install . -if build --build=missing -pr conan/profiles/vs32 -o run_tests=False -o with_ruby=%WITH_RUBY% + conan install . -if build --build=missing -pr %CONAN_PROFILE% -o run_tests=False -o shared=%SHARED% - sh: |- export PATH=$HOME/venv3.10/bin:$PATH if [[ $APPVEYOR_BUILD_WORKER_IMAGE = "Ubuntu2004" ]] then + sudo apt update + sudo apt install -y build-essential cmake gcc-11 g++-11 python3 export CONAN_PROFILE=conan/profiles/gcc-appveyor elif [[ $APPVEYOR_BUILD_WORKER_IMAGE = "macOS" ]] then @@ -66,7 +68,7 @@ before_build: pip install conan conan export conan/mqtt_cpp conan export conan/mruby - conan install . -if build --build=missing -pr $CONAN_PROFILE -o run_tests=False -o with_ruby=$WITH_RUBY + conan install . -if build --build=missing -pr $CONAN_PROFILE -o run_tests=False -o shared=$SHARED build: verbosity: minimal diff --git a/cmake/msvc_use_static_runtime.cmake b/cmake/msvc_use_static_runtime.cmake deleted file mode 100644 index af912d7ab..000000000 --- a/cmake/msvc_use_static_runtime.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# When building for Windows using the Microsoft compiler we wish to use -# the static multi-threaded runtime libraries (this makes deployment easier). -# -# By default CMake targets the dynamic runtime libaries using the '/MD' and 'MDd' options -# Change these to use the static variants 'MT' and 'MTd' -# -# Note: This must be done before adding any CMake targets (executables, libraries etc...) - -if(MSVC) - foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if(${flag_var} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") - endif() - endforeach() -endif() diff --git a/conan/profiles/gcc-appveyor b/conan/profiles/gcc-appveyor index a80246886..9891ae03b 100644 --- a/conan/profiles/gcc-appveyor +++ b/conan/profiles/gcc-appveyor @@ -2,8 +2,8 @@ include(default) [settings] compiler.libcxx=libstdc++11 -compiler.version=9 +compiler.version=11 [env] -CC=/usr/bin/gcc-9 -CXX=/usr/bin/g++-9 +CC=/usr/bin/gcc-11 +CXX=/usr/bin/g++-11 diff --git a/conan/profiles/vs32shared b/conan/profiles/vs32shared new file mode 100644 index 000000000..99bc71fbf --- /dev/null +++ b/conan/profiles/vs32shared @@ -0,0 +1,9 @@ +include(default) + +[settings] +compiler=Visual Studio +arch=x86 +arch_build=x86 +compiler.runtime=MD + +[env] \ No newline at end of file diff --git a/conan/profiles/vs64shared b/conan/profiles/vs64shared new file mode 100644 index 000000000..ee58ac80d --- /dev/null +++ b/conan/profiles/vs64shared @@ -0,0 +1,9 @@ +include(default) + +[settings] +compiler=Visual Studio +arch=x86_64 +arch_build=x86_64 +compiler.runtime=MD + +[env] \ No newline at end of file diff --git a/conan/profiles/vsxp b/conan/profiles/vsxp index 952c8f997..d61bbc81e 100644 --- a/conan/profiles/vsxp +++ b/conan/profiles/vsxp @@ -1,10 +1,17 @@ include(default) [settings] +compiler=Visual Studio arch=x86 -arch_build=x86 compiler.toolset=v141_xp compiler.runtime=MT +[options] +winver=0x0501 +with_ruby=False +date:header_only=True + [env] -WINVER=0x0501 \ No newline at end of file +WINVER=0x0501 +CFLAGS=/DWINVER=0x0501 /D_WIN32_WINNT=0x0501 /DNTDDI_VERSION=0x05010300 +CXXFLAGS=/DWINVER=0x0501 /D_WIN32_WINNT=0x0501 /DNTDDI_VERSION=0x05010300 diff --git a/conanfile.py b/conanfile.py index c4441fad8..7ee2f3acd 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,15 +1,22 @@ from conans import ConanFile, CMake, tools +from conans.errors import ConanInvalidConfiguration +import os +import io +import re +import itertools as it +import glob +from conan.tools.microsoft import is_msvc, is_msvc_static_runtime -class CppAgentConan(ConanFile): - name = "mtconnect_cppagent" - version = "2.0" +class MTConnectAgentConan(ConanFile): + name = "mtconnect_agent" + version = "2.1" generators = "cmake" url = "https://github.com/mtconnect/cppagent.git" license = "Apache License 2.0" settings = "os", "compiler", "arch", "build_type", "arch_build" - options = { "run_tests": [True, False], "build_tests": [True, False], "without_python": [True, False], - "without_ruby": [True, False], "without_ipv6": [True, False], "with_ruby": [True, False], - "with_python": [True, False] } + options = { "run_tests": [True, False], "build_tests": [True, False], + "without_ipv6": [True, False], "with_ruby": [True, False], + "development" : [True, False], "shared": [True, False], "winver": "ANY" } description = "MTConnect reference C++ agent copyright Association for Manufacturing Technology" requires = ["boost/1.79.0@#3249d9bd2b863a9489767bf9c8a05b4b", @@ -23,11 +30,11 @@ class CppAgentConan(ConanFile): default_options = { "run_tests": True, "build_tests": True, - "without_python": True, - "without_ruby": False, "without_ipv6": False, - "with_python": False, - "with_ruby": False, + "with_ruby": True, + "development": False, + "shared": False, + "winver": "0x600", "boost:shared": False, "boost:without_python": True, @@ -41,22 +48,45 @@ class CppAgentConan(ConanFile): "libxml2:zlib": False, "gtest:shared": False, + + "openssl:shared": False, "date:use_system_tz_db": True } + exports_sources = "*" + +# def source(self): +# git = tools.Git(self.source_folder) +# if self.options.development: +# git.clone("git@github.com:/mtconnect/cppagent_dev") +# else: +# git.clone("https://github.com/mtconnect/cppagent") + + def validate(self): + if self.settings.os == 'Windows' and self.options.shared and \ + str(self.settings.compiler.runtime).startswith('MT'): + raise ConanInvalidConfiguration("Shared can only be built with DLL runtime.") + def configure(self): - if not self.options.without_python: - self.options["boost"].without_python = False - self.windows_xp = self.settings.os == 'Windows' and self.settings.compiler.toolset and \ self.settings.compiler.toolset in ('v141_xp', 'v140_xp') if self.settings.os == 'Windows': - if self.settings.build_type and self.settings.build_type == 'Debug': - self.settings.compiler.runtime = 'MTd' - else: - self.settings.compiler.runtime = 'MT' + if self.windows_xp: + self.options.build_tests = False + self.options.winver == '0x501' + if self.options.shared: + if self.settings.build_type and self.settings.build_type == 'Debug': + self.settings.compiler.runtime = 'MDd' + else: + self.settings.compiler.runtime = 'MD' + else: + if self.settings.build_type and self.settings.build_type == 'Debug': + self.settings.compiler.runtime = 'MTd' + else: + self.settings.compiler.runtime = 'MT' + if not self.settings.compiler.version: self.settings.compiler.version = '16' @@ -65,20 +95,19 @@ def configure(self): self.settings.compiler.cppstd = 17 - if self.windows_xp: - self.options.build_tests = False if not self.options.build_tests: self.options.run_tests = False - if not self.options.without_ruby: - self.options.with_ruby = True - - if not self.options.without_python: - self.options.with_python = True - - if self.settings.os == "Macos": + if not self.options.shared and self.settings.os == "Macos": self.options["boost"].visibility = "hidden" + + # Make sure shared builds use shared boost + if is_msvc(self) and self.options.shared: + self.options["boost"].shared = True + self.options["libxml2"].shared = True + self.options["gtest"].shared = True + self.options["openssl"].shared = True def requirements(self): if not self.windows_xp: @@ -95,18 +124,16 @@ def build(self): if self.options.without_ipv6: cmake.definitions['AGENT_WITHOUT_IPV6'] = 'ON' - if self.options.with_python: - cmake.definitions['WITH_PYTHON'] = 'ON' - else: - cmake.definitions['WITH_PYTHON'] = 'OFF' - if self.options.with_ruby: cmake.definitions['WITH_RUBY'] = 'ON' else: cmake.definitions['WITH_RUBY'] = 'OFF' - - if self.windows_xp: - cmake.definitions['WINVER'] = '0x0501' + + if self.settings.os == 'Windows': + cmake.definitions['WINVER'] = self.options.winver + + if self.options.shared: + cmake.definitions['SHARED_AGENT_LIB'] = 'ON' cmake.configure() cmake.build() @@ -115,7 +142,37 @@ def build(self): def imports(self): self.copy("*.dll", "bin", "bin") - self.copy("*.so*", "bin", "lib") - self.copy("*.dylib", "bin", "lib") + self.copy("*.pdb", "bin", "bin", keep_path=False) + self.copy("*.pdb", "lib", "bin", keep_path=False) + self.copy("*.so*", "lib", "lib") + self.copy("*.dylib", "lib", "lib") + + def package_info(self): + self.cpp_info.includedirs = ['include'] + self.cpp_info.libs = ['agent_lib'] + + self.cpp_info.defines = [] + if self.options.with_ruby: + self.cpp_info.defines.append("WITH_RUBY=1") + if self.options.without_ipv6: + self.cpp_info.defines.append("AGENT_WITHOUT_IPV6=1") + if self.options.shared: + self.user_info.SHARED = 'ON' + self.cpp_info.defines.append("SHARED_AGENT_LIB=1") + self.cpp_info.defines.append("BOOST_ALL_DYN_LINK") + + if self.settings.os == 'Windows': + self.cpp_info.defines.append("WINVER=" + self.options.winver) + self.cpp_info.defines.append("_WIN32_WINNT=" + self.options.winver) + + def package(self): + self.copy("*", src=os.path.join(self.build_folder, "bin"), dst="bin", keep_path=False) + self.copy("*.a", src=os.path.join(self.build_folder, "lib"), dst="lib", keep_path=False) + self.copy("*.lib", src=os.path.join(self.build_folder, "lib"), dst="lib", keep_path=False) + self.copy("*.dylib", src=os.path.join(self.build_folder, "lib"), dst="lib", keep_path=False) + self.copy("*.so", src=os.path.join(self.build_folder, "lib"), dst="lib", keep_path=False) + self.copy("*.h", src=os.path.join(self.build_folder, "agent_lib"), dst="include") + self.copy("*.h", src="src", dst="include") + self.copy("*.hpp", src="src", dst="include") diff --git a/conanfile.py.bak b/conanfile.py.bak deleted file mode 100644 index 5240fc098..000000000 --- a/conanfile.py.bak +++ /dev/null @@ -1,116 +0,0 @@ -from conans import ConanFile, CMake, tools - -class CppAgentConan(ConanFile): - name = "mtconnect_cppagent" - version = "2.0" - generators = "cmake" - url = "https://github.com/mtconnect/cppagent.git" - license = "Apache License 2.0" - settings = "os", "compiler", "arch", "build_type", "arch_build" - options = { "run_tests": [True, False], "build_tests": [True, False], "without_python": [True, False], - "without_ruby": [True, False], "without_ipv6": [True, False], "with_ruby": [True, False], - "with_python": [True, False] } - description = "MTConnect reference C++ agent copyright Association for Manufacturing Technology" - - requires = ["boost/1.77.0", "libxml2/2.9.10", "date/2.4.1", "nlohmann_json/3.9.1", - "mqtt_cpp/11.0.0", "openssl/1.1.1k"] - build_policy = "missing" - default_options = { - "run_tests": True, - "build_tests": True, - "without_python": True, - "without_ruby": False, - "without_ipv6": False, - "with_python": False, - "with_ruby": False, - - "boost:shared": False, - "boost:without_python": True, - "boost:without_test": True, - - "libxml2:shared": False, - "libxml2:include_utils": False, - "libxml2:http": False, - "libxml2:ftp": False, - "libxml2:iconv": False, - "libxml2:zlib": False, - - "gtest:shared": False, - - "date:use_system_tz_db": True - } - - def configure(self): - if not self.options.without_python: - self.options["boost"].without_python = False - - self.windows_xp = self.settings.os == 'Windows' and self.settings.compiler.toolset and \ - self.settings.compiler.toolset in ('v141_xp', 'v140_xp') - if self.settings.os == 'Windows': - if self.settings.build_type and self.settings.build_type == 'Debug': - self.settings.compiler.runtime = 'MTd' - else: - self.settings.compiler.runtime = 'MT' - self.settings.compiler.version = '16' - - if "libcxx" in self.settings.compiler.fields and self.settings.compiler.libcxx == "libstdc++": - raise Exception("This package is only compatible with libstdc++11, add -s compiler.libcxx=libstdc++11") - - self.settings.compiler.cppstd = 17 - - if self.windows_xp: - self.options.build_tests = False - - if not self.options.build_tests: - self.options.run_tests = False - - if not self.options.without_ruby: - self.options.with_ruby = True - - if not self.options.without_python: - self.options.with_python = True - - if self.settings.os == "Macos": - self.options["boost"].visibility = "hidden" - - def requirements(self): - if not self.windows_xp: - self.requires("gtest/1.10.0") - if self.options.with_ruby: - self.requires("mruby/3.1.0") - - def build(self): - cmake = CMake(self) - cmake.verbose = True - if not self.options.build_tests: - cmake.definitions['AGENT_ENABLE_UNITTESTS'] = 'OFF' - - if self.options.without_ipv6: - cmake.definitions['AGENT_WITHOUT_IPV6'] = 'ON' - - if self.options.with_python: - cmake.definitions['WITH_PYTHON'] = 'ON' - else: - cmake.definitions['WITH_PYTHON'] = 'OFF' - - if self.options.with_ruby: - cmake.definitions['WITH_RUBY'] = 'ON' - else: - cmake.definitions['WITH_RUBY'] = 'OFF' - - if self.windows_xp: - cmake.definitions['WINVER'] = '0x0501' - - cmake.configure() - cmake.build() - if self.options.run_tests: - cmake.test() - - def imports(self): - self.copy("*.dll", "bin", "bin") - self.copy("*.so*", "bin", "lib") - self.copy("*.dylib", "bin", "lib") - - - - diff --git a/samples/configuration.xml b/samples/configuration.xml index dcba0e73d..27189e796 100644 --- a/samples/configuration.xml +++ b/samples/configuration.xml @@ -39,6 +39,7 @@ + diff --git a/simulator/nist.cfg b/simulator/nist.cfg new file mode 100755 index 000000000..3c8450b74 --- /dev/null +++ b/simulator/nist.cfg @@ -0,0 +1,60 @@ +Devices = nist.xml +AllowPut = true +ReconnectInterval = 1000 +BufferSize = 17 +SchemaVersion = 1.7 +MonitorConfigFiles = true +Pretty = true +# MinimumConfigReloadAge = 30 + +TlsPrivateKey = ../test/resources/user.key +TlsCertificateChain = ../test/resources/user.crt +TlsCertificatePassword = mtconnect +TlsDHKey = ../test/resources/dh2048.pem + +Adapters { + # Log file has all machines with device name prefixed + GFAgie01 { + Host = 127.0.0.1 + Port = 7878 + } + + #Mazak01 { + # Url = mqtt://localhost:1883/ + # Topics = "#" + #} +} + +PythonPath = "modules:other_modules" +PythonModules = my_transforms, other_stuff + +Files { + schemas { + Path = ../schemas + Location = /schemas/ + } + styles { + Path = ../styles + Location = /styles/ + } + Favicon { + Path = ../styles/favicon.ico + Location = /favicon.ico + } +} + +StreamsNamespaces { + x { + Urn = urn:nist.gov:NistStreams:1.3 + } +} + +StreamsStyle { + Location = /styles/Streams.xsl +} + +# Logger Configuration +logger_config +{ + logging_level = info +} diff --git a/simulator/nist.xml b/simulator/nist.xml new file mode 100644 index 000000000..e03ff6508 --- /dev/null +++ b/simulator/nist.xml @@ -0,0 +1,569 @@ + + + +
+ + + Agie Mikron HPM600U - GF Agie Charmilles HPM600U + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Mazak Integrex 100-IV + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Mazak QuickTurn - Mazak QuickTurn Nexus 300 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sload + + + + + + + + + + + S2load + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Hurco VMX 24 #1 + + + + + + + + + + + + spindle_speed + + + SspeedOvr + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Hurco VMX 24 #2 + + + + + + + + + + + + spindle_speed + + + SspeedOvr + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Hurco VMX 24 #3 + + + + + + + + + + + + spindle_speed + + + SspeedOvr + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Hurco VMX 24 #4 + + + + + + + + + + + + spindle_speed + + + SspeedOvr + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Hurco VMX 64 + + + + + + + + + + + + spindle_speed + + + SspeedOvr + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/simulator/out.xml b/simulator/out.xml new file mode 100644 index 000000000..427520473 --- /dev/null +++ b/simulator/out.xml @@ -0,0 +1,551 @@ + + + +
+ + + + + AVAILABLE + ARMED + UNAVAILABLE + UNAVAILABLE + + + Key non-functional + + + + + -0.0001 + + + + + 0 + + + + + 6.39211 + + + + + -26.3065 + + + + + 23.19091 + + + + + 99.25 + 100.75 + + + + + + + + + + + + + + -11.4562500000 -7.3124000000 21.2179700000 + + + READY + AUTOMATIC + TNC:\BRIAN\FACE BOTTOM.H + 0 + NORMAL + + + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + UNAVAILABLE + + + UNAVAILABLE + + + + + UNAVAILABLE + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + UNAVAILABLE + + + UNAVAILABLE + + + + + UNAVAILABLE + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + UNAVAILABLE + + + UNAVAILABLE + + + + + UNAVAILABLE + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + UNAVAILABLE + + + UNAVAILABLE + + + + + UNAVAILABLE + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + UNAVAILABLE + + + UNAVAILABLE + + + + + UNAVAILABLE + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + + + UNAVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + 0 + 0 + 90 + + + + + + + + 0 + 0 + 0 + 2852 + 47 + 270 + + + 100 + + + + + + + + + + 0 + 0 + 37 + + + + + + + + + -4.61264 + 28 + 1.507067 + + + + + + + + 6.933057 + 7 + 3.0099 + + + + + + + + -1.8542 + 3 + 0 + + + + + + + + + + + + + ARMED + + + + + + + + + + + + + + + + + ON + + + + + + + + + + + + + 8328015 + 41700838 + 4253246 + 67.29623 + + + 1006 + 16 + 0 + C + ACTIVE + AUTOMATIC + + + + 1 + 0 + 1 + 0 + 25 + 100 + + + + + + + + + + + + + + + + AVAILABLE + UNAVAILABLE + UNAVAILABLE + + + + + 0 + 0 + 180 + + + + + + + + 0 + 0 + 51 + + + + + + + + + 750 + 1 + 40 + + + + + + + + + 15.35684 + 44 + 0 + + + + + + + + -216.6747 + 1 + 0 + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + + + + ON + + + + + + + + + + + + + 2706723 + 14110123 + 1824843 + 0 + + + ACTIVE + AUTOMATIC + + + 100 + 9 + 0 + A + 31 + + 9 + 0 + 25 + 80 + 9 + 0 + + + ILLEGAL NUMBER INPUT + + + + + + + + + + + + + + + + + diff --git a/src/agent.cpp b/src/mtconnect/agent.cpp similarity index 97% rename from src/agent.cpp rename to src/mtconnect/agent.cpp index 8a0700e19..88fa39cca 100644 --- a/src/agent.cpp +++ b/src/mtconnect/agent.cpp @@ -15,7 +15,7 @@ // limitations under the License. // -#include "agent.hpp" +#include "mtconnect/agent.hpp" #include #include @@ -40,21 +40,21 @@ #include #include -#include "asset/asset.hpp" -#include "asset/cutting_tool.hpp" -#include "asset/file_asset.hpp" -#include "asset/qif_document.hpp" -#include "asset/raw_material.hpp" -#include "configuration/config_options.hpp" -#include "device_model/agent_device.hpp" -#include "entity/xml_parser.hpp" -#include "logging.hpp" -#include "observation/observation.hpp" -#include "printer/json_printer.hpp" -#include "printer/xml_printer.hpp" -#include "sink/rest_sink/file_cache.hpp" -#include "sink/rest_sink/session.hpp" -#include "version.h" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/asset/cutting_tool.hpp" +#include "mtconnect/asset/file_asset.hpp" +#include "mtconnect/asset/qif_document.hpp" +#include "mtconnect/asset/raw_material.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/device_model/agent_device.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/printer/json_printer.hpp" +#include "mtconnect/printer/xml_printer.hpp" +#include "mtconnect/sink/rest_sink/file_cache.hpp" +#include "mtconnect/sink/rest_sink/session.hpp" +#include "mtconnect/version.h" using namespace std; @@ -115,6 +115,8 @@ namespace mtconnect { { NAMED_SCOPE("Agent::initialize"); + m_beforeInitializeHooks.exec(*this); + m_pipelineContext = context; m_loopback = std::make_shared("AgentSource", m_strand, context, m_options); @@ -140,7 +142,10 @@ namespace mtconnect { addDevice(device); loadCachedProbe(); + m_initialized = true; + + m_afterInitializeHooks.exec(*this); } void Agent::initialDataItemObservations() @@ -177,8 +182,17 @@ namespace mtconnect { void Agent::start() { NAMED_SCOPE("Agent::start"); + + if (m_started) + { + LOG(warning) << "Agent already started."; + return; + } + try { + m_beforeStartHooks.exec(*this); + for (auto sink : m_sinks) sink->start(); @@ -199,11 +213,21 @@ namespace mtconnect { LOG(fatal) << "Cannot start server: " << e.what(); std::exit(1); } + + m_started = true; } void Agent::stop() { NAMED_SCOPE("Agent::stop"); + + if (!m_started) + { + LOG(warning) << "Agent already stopped."; + return; + } + + m_beforeStopHooks.exec(*this); // Stop all adapter threads... LOG(info) << "Shutting down sources"; @@ -224,6 +248,8 @@ namespace mtconnect { } LOG(info) << "Shutting down completed"; + + m_started = false; } // --------------------------------------- diff --git a/src/agent.hpp b/src/mtconnect/agent.hpp similarity index 88% rename from src/agent.hpp rename to src/mtconnect/agent.hpp index f9e1a1b03..08c70303c 100644 --- a/src/agent.hpp +++ b/src/mtconnect/agent.hpp @@ -36,22 +36,24 @@ #include #include -#include "asset/asset_buffer.hpp" -#include "buffer/checkpoint.hpp" -#include "buffer/circular_buffer.hpp" -#include "configuration/service.hpp" -#include "device_model/agent_device.hpp" -#include "device_model/device.hpp" -#include "parser/xml_parser.hpp" -#include "pipeline/pipeline.hpp" -#include "pipeline/pipeline_contract.hpp" -#include "printer/printer.hpp" -#include "sink/rest_sink/rest_service.hpp" -#include "sink/rest_sink/server.hpp" -#include "sink/sink.hpp" -#include "source/adapter/adapter.hpp" -#include "source/loopback_source.hpp" -#include "source/source.hpp" +#include "mtconnect/asset/asset_buffer.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/buffer/circular_buffer.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/configuration/hook_manager.hpp" +#include "mtconnect/configuration/service.hpp" +#include "mtconnect/device_model/agent_device.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/parser/xml_parser.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/pipeline/pipeline_contract.hpp" +#include "mtconnect/printer//printer.hpp" +#include "mtconnect/sink/rest_sink/rest_service.hpp" +#include "mtconnect/sink/rest_sink/server.hpp" +#include "mtconnect/sink/sink.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/loopback_source.hpp" +#include "mtconnect/source/source.hpp" namespace mtconnect { namespace mic = boost::multi_index; @@ -74,9 +76,12 @@ namespace mtconnect { using AssetChangeList = std::vector>; - class Agent + class AGENT_LIB_API Agent { public: + using Hook = std::function; + using HookList = std::list; + // Load agent with the xml configuration Agent(boost::asio::io_context &context, const std::string &deviceXmlPath, const ConfigOptions &options); @@ -84,6 +89,12 @@ namespace mtconnect { // Virtual destructor ~Agent(); + // Hooks + auto &beforeInitializeHooks() { return m_beforeInitializeHooks; } + auto &afterInitializeHooks() { return m_afterInitializeHooks; } + auto &beforeStartHooks() { return m_beforeStartHooks; } + auto &beforeStopHooks() { return m_beforeStopHooks; } + // Initialize models and pipeline void initialize(pipeline::PipelineContextPtr context); void initialDataItemObservations(); @@ -247,6 +258,8 @@ namespace mtconnect { boost::asio::io_context::strand m_strand; std::shared_ptr m_loopback; + + bool m_started { false }; // Asset Management std::unique_ptr m_assetStorage; @@ -308,9 +321,15 @@ namespace mtconnect { // For debugging bool m_pretty; + + // Agent hooks + configuration::HookManager m_beforeInitializeHooks; + configuration::HookManager m_afterInitializeHooks; + configuration::HookManager m_beforeStartHooks; + configuration::HookManager m_beforeStopHooks; }; - class AgentPipelineContract : public pipeline::PipelineContract + class AGENT_LIB_API AgentPipelineContract : public pipeline::PipelineContract { public: AgentPipelineContract(Agent *agent) : m_agent(agent) {} @@ -360,7 +379,7 @@ namespace mtconnect { return std::make_unique(this); } - class AgentSinkContract : public sink::SinkContract + class AGENT_LIB_API AgentSinkContract : public sink::SinkContract { public: AgentSinkContract(Agent *agent) : m_agent(agent) {} diff --git a/src/asset/asset.cpp b/src/mtconnect/asset/asset.cpp similarity index 98% rename from src/asset/asset.cpp rename to src/mtconnect/asset/asset.cpp index 31500a7f9..fe5eeab90 100644 --- a/src/asset/asset.cpp +++ b/src/mtconnect/asset/asset.cpp @@ -15,7 +15,7 @@ // limitations under the License. // -#include "asset/asset.hpp" +#include "mtconnect/asset/asset.hpp" #include #include diff --git a/src/asset/asset.hpp b/src/mtconnect/asset/asset.hpp similarity index 93% rename from src/asset/asset.hpp rename to src/mtconnect/asset/asset.hpp index 7f29df59c..ce71319fa 100644 --- a/src/asset/asset.hpp +++ b/src/mtconnect/asset/asset.hpp @@ -21,9 +21,10 @@ #include #include -#include "entity/entity.hpp" -#include "entity/factory.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace asset { @@ -31,7 +32,7 @@ namespace mtconnect { using AssetPtr = std::shared_ptr; using AssetList = std::list; - class Asset : public entity::Entity + class AGENT_LIB_API Asset : public entity::Entity { public: Asset(const std::string &name, const entity::Properties &props) @@ -112,7 +113,7 @@ namespace mtconnect { bool m_removed; }; - class ExtendedAsset : public Asset + class AGENT_LIB_API ExtendedAsset : public Asset { public: static entity::FactoryPtr getFactory(); diff --git a/src/asset/asset_buffer.hpp b/src/mtconnect/asset/asset_buffer.hpp similarity index 98% rename from src/asset/asset_buffer.hpp rename to src/mtconnect/asset/asset_buffer.hpp index b18819d53..41c53cd01 100644 --- a/src/asset/asset_buffer.hpp +++ b/src/mtconnect/asset/asset_buffer.hpp @@ -42,12 +42,13 @@ #include "asset.hpp" #include "asset_storage.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::asset { namespace mic = boost::multi_index; - class AssetBuffer : public AssetStorage + class AGENT_LIB_API AssetBuffer : public AssetStorage { public: struct AssetNode diff --git a/src/asset/asset_storage.hpp b/src/mtconnect/asset/asset_storage.hpp similarity index 94% rename from src/asset/asset_storage.hpp rename to src/mtconnect/asset/asset_storage.hpp index 455cd4929..b3f2e6f73 100644 --- a/src/asset/asset_storage.hpp +++ b/src/mtconnect/asset/asset_storage.hpp @@ -23,13 +23,14 @@ #include #include -#include "asset/asset.hpp" -#include "entity/entity.hpp" -#include "utilities.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace asset { - class AssetStorage + class AGENT_LIB_API AssetStorage { public: using TypeCount = std::map; diff --git a/src/asset/cutting_tool.cpp b/src/mtconnect/asset/cutting_tool.cpp similarity index 99% rename from src/asset/cutting_tool.cpp rename to src/mtconnect/asset/cutting_tool.cpp index 5855f05a0..f18abea51 100644 --- a/src/asset/cutting_tool.cpp +++ b/src/mtconnect/asset/cutting_tool.cpp @@ -15,11 +15,11 @@ // limitations under the License. // -#include "asset/cutting_tool.hpp" +#include "mtconnect/asset/cutting_tool.hpp" #include -#include "printer/printer.hpp" +#include "mtconnect/printer//printer.hpp" using namespace std; diff --git a/src/asset/cutting_tool.hpp b/src/mtconnect/asset/cutting_tool.hpp similarity index 86% rename from src/asset/cutting_tool.hpp rename to src/mtconnect/asset/cutting_tool.hpp index 9a30f7f2e..6f090fa7c 100644 --- a/src/asset/cutting_tool.hpp +++ b/src/mtconnect/asset/cutting_tool.hpp @@ -22,18 +22,19 @@ #include #include "asset.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace asset { - class CuttingToolArchetype : public Asset + class AGENT_LIB_API CuttingToolArchetype : public Asset { public: static entity::FactoryPtr getFactory(); static void registerAsset(); }; - class CuttingTool : public Asset + class AGENT_LIB_API CuttingTool : public Asset { public: static entity::FactoryPtr getFactory(); diff --git a/src/asset/file_asset.cpp b/src/mtconnect/asset/file_asset.cpp similarity index 98% rename from src/asset/file_asset.cpp rename to src/mtconnect/asset/file_asset.cpp index 414fde28a..bd6dce904 100644 --- a/src/asset/file_asset.cpp +++ b/src/mtconnect/asset/file_asset.cpp @@ -15,7 +15,7 @@ // limitations under the License. // -#include "asset/file_asset.hpp" +#include "mtconnect/asset/file_asset.hpp" namespace mtconnect { namespace asset { diff --git a/src/asset/file_asset.hpp b/src/mtconnect/asset/file_asset.hpp similarity index 80% rename from src/asset/file_asset.hpp rename to src/mtconnect/asset/file_asset.hpp index 4f96c0250..35d5c5c3b 100644 --- a/src/asset/file_asset.hpp +++ b/src/mtconnect/asset/file_asset.hpp @@ -22,20 +22,21 @@ #include #include "asset.hpp" -#include "entity/entity.hpp" -#include "entity/factory.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace asset { - class FileArchetypeAsset : public entity::Entity + class AGENT_LIB_API FileArchetypeAsset : public entity::Entity { public: static entity::FactoryPtr getFactory(); static void registerAsset(); }; - class FileAsset : public FileArchetypeAsset + class AGENT_LIB_API FileAsset : public FileArchetypeAsset { public: static entity::FactoryPtr getFactory(); diff --git a/src/asset/qif_document.cpp b/src/mtconnect/asset/qif_document.cpp similarity index 97% rename from src/asset/qif_document.cpp rename to src/mtconnect/asset/qif_document.cpp index f1a758567..9a9e33e61 100644 --- a/src/asset/qif_document.cpp +++ b/src/mtconnect/asset/qif_document.cpp @@ -15,7 +15,7 @@ // limitations under the License. // -#include "asset/qif_document.hpp" +#include "mtconnect/asset/qif_document.hpp" using namespace std; diff --git a/src/asset/qif_document.hpp b/src/mtconnect/asset/qif_document.hpp similarity index 82% rename from src/asset/qif_document.hpp rename to src/mtconnect/asset/qif_document.hpp index 51151f095..ca7d61a91 100644 --- a/src/asset/qif_document.hpp +++ b/src/mtconnect/asset/qif_document.hpp @@ -22,12 +22,13 @@ #include #include "asset.hpp" -#include "entity/entity.hpp" -#include "entity/factory.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::asset { - class QIFDocumentWrapper : public Asset + class AGENT_LIB_API QIFDocumentWrapper : public Asset { public: static entity::FactoryPtr getFactory(); diff --git a/src/asset/raw_material.cpp b/src/mtconnect/asset/raw_material.cpp similarity index 98% rename from src/asset/raw_material.cpp rename to src/mtconnect/asset/raw_material.cpp index abc3d0e55..beb8bc20c 100644 --- a/src/asset/raw_material.cpp +++ b/src/mtconnect/asset/raw_material.cpp @@ -15,7 +15,7 @@ // limitations under the License. // -#include "asset/raw_material.hpp" +#include "mtconnect/asset/raw_material.hpp" using namespace std; diff --git a/src/asset/raw_material.hpp b/src/mtconnect/asset/raw_material.hpp similarity index 83% rename from src/asset/raw_material.hpp rename to src/mtconnect/asset/raw_material.hpp index d42441f02..0fc60aeba 100644 --- a/src/asset/raw_material.hpp +++ b/src/mtconnect/asset/raw_material.hpp @@ -22,12 +22,13 @@ #include #include "asset.hpp" -#include "entity/entity.hpp" -#include "entity/factory.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::asset { - class RawMaterial : public Asset + class AGENT_LIB_API RawMaterial : public Asset { public: static entity::FactoryPtr getFactory(); diff --git a/src/buffer/checkpoint.cpp b/src/mtconnect/buffer/checkpoint.cpp similarity index 99% rename from src/buffer/checkpoint.cpp rename to src/mtconnect/buffer/checkpoint.cpp index f57e89f2c..da052170a 100644 --- a/src/buffer/checkpoint.cpp +++ b/src/mtconnect/buffer/checkpoint.cpp @@ -17,7 +17,7 @@ #include "checkpoint.hpp" -#include "device_model/data_item/data_item.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" using namespace std; diff --git a/src/buffer/checkpoint.hpp b/src/mtconnect/buffer/checkpoint.hpp similarity index 94% rename from src/buffer/checkpoint.hpp rename to src/mtconnect/buffer/checkpoint.hpp index d032883e9..f5dca83a3 100644 --- a/src/buffer/checkpoint.hpp +++ b/src/mtconnect/buffer/checkpoint.hpp @@ -23,11 +23,12 @@ #include #include -#include "observation/observation.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::buffer { - class Checkpoint + class AGENT_LIB_API Checkpoint { public: Checkpoint() = default; diff --git a/src/buffer/circular_buffer.hpp b/src/mtconnect/buffer/circular_buffer.hpp similarity index 98% rename from src/buffer/circular_buffer.hpp rename to src/mtconnect/buffer/circular_buffer.hpp index 912d267a8..06c63951a 100644 --- a/src/buffer/circular_buffer.hpp +++ b/src/mtconnect/buffer/circular_buffer.hpp @@ -24,13 +24,14 @@ #include #include "checkpoint.hpp" -#include "observation/observation.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::buffer { using SequenceNumber_t = uint64_t; - class CircularBuffer + class AGENT_LIB_API CircularBuffer { public: CircularBuffer(unsigned int bufferSize, int checkpointFreq) diff --git a/src/mtconnect/config.hpp b/src/mtconnect/config.hpp new file mode 100644 index 000000000..c5fa269a6 --- /dev/null +++ b/src/mtconnect/config.hpp @@ -0,0 +1,99 @@ +#pragma once + +// +// Copyright Copyright 2009-2022, AMT � The Association For Manufacturing Technology (�AMT�) +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#pragma once + +#include + +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif +#if _MSC_VER > 1500 +#include +#else +#endif +#ifndef UINT64_MAX +#define UINT64_MAX 0xFFFFFFFFFFFFFFFFull +#endif +#ifndef NOMINMAX +#define NOMINMAX 1 +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(_WIN32) || defined(_WIN64) +#ifndef _WINDOWS +#define _WINDOWS 1 +#endif +#define ISNAN(x) _isnan(x) +#if _MSC_VER < 1800 +#define NAN numeric_limits::quiet_NaN() +#endif +#if _MSC_VER >= 1900 +#define gets gets_s +#define timezone _timezone +#endif +typedef unsigned __int64 uint64_t; +#else +#define O_BINARY 0 +#define ISNAN(x) std::isnan(x) +#include +#include +#include +#include +#endif + +#ifdef _WINDOWS +#define AGENT_SYMBOL_EXPORT __declspec(dllexport) +#define AGENT_SYMBOL_IMPORT __declspec(dllimport) +#else // _WINDOWS +#define AGENT_SYMBOL_EXPORT __attribute__((visibility("default"))) +#define AGENT_SYMBOL_IMPORT __attribute__((visibility("default"))) +#endif // _WINDOWS + +#ifdef SHARED_AGENT_LIB + +#ifdef AGENT_BUILD_SHARED_LIB +#define AGENT_LIB_API AGENT_SYMBOL_EXPORT +#else +#define AGENT_LIB_API AGENT_SYMBOL_IMPORT +#endif + +#define AGENT_SYMBOL_VISIBLE AGENT_LIB_API + +#else // SHARED_AGENT_LIB + +#define AGENT_LIB_API +#define AGENT_SYMBOL_VISIBLE + +#endif diff --git a/src/configuration/agent_config.cpp b/src/mtconnect/configuration/agent_config.cpp similarity index 97% rename from src/configuration/agent_config.cpp rename to src/mtconnect/configuration/agent_config.cpp index a6b7a7e5a..2b86e51e4 100644 --- a/src/configuration/agent_config.cpp +++ b/src/mtconnect/configuration/agent_config.cpp @@ -32,6 +32,8 @@ #include #include +#include "mtconnect/config.hpp" + #ifdef __APPLE__ #include #endif @@ -50,23 +52,23 @@ #include #include -#include "agent.hpp" -#include "configuration/config_options.hpp" -#include "device_model/device.hpp" -#include "printer/xml_printer.hpp" -#include "sink/mqtt_sink/mqtt_service.hpp" -#include "sink/rest_sink/rest_service.hpp" -#include "source/adapter/agent_adapter/agent_adapter.hpp" -#include "source/adapter/mqtt/mqtt_adapter.hpp" -#include "source/adapter/shdr/shdr_adapter.hpp" -#include "version.h" +#include "mtconnect/agent.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/printer/xml_printer.hpp" +#include "mtconnect/sink/mqtt_sink/mqtt_service.hpp" +#include "mtconnect/sink/rest_sink/rest_service.hpp" +#include "mtconnect/source/adapter/agent_adapter/agent_adapter.hpp" +#include "mtconnect/source/adapter/mqtt/mqtt_adapter.hpp" +#include "mtconnect/source/adapter/shdr/shdr_adapter.hpp" +#include "mtconnect/version.h" #ifdef WITH_PYTHON -#include "python/embedded.hpp" +#include "mtconnect/python/embedded.hpp" #endif #ifdef WITH_RUBY -#include "ruby/embedded.hpp" +#include "mtconnect/ruby/embedded.hpp" #endif // If Windows XP @@ -96,6 +98,7 @@ BOOST_LOG_ATTRIBUTE_KEYWORD(named_scope, "Scope", logr::attributes::named_scope: BOOST_LOG_ATTRIBUTE_KEYWORD(utc_timestamp, "Timestamp", logr::attributes::utc_clock::value_type); namespace mtconnect::configuration { + AGENT_LIB_API boost::log::trivial::logger_type *gAgentLogger = nullptr; AgentConfiguration::AgentConfiguration() @@ -306,6 +309,7 @@ namespace mtconnect::configuration { LOG(warning) << "Monitor thread has detected change in configuration files."; LOG(warning) << ".... Restarting agent: " << m_configFile; + m_beforeStopHooks.exec(*this); m_agent->stop(); m_context->pause( @@ -320,6 +324,7 @@ namespace mtconnect::configuration { boost::optional(m_configFile.string()), false); options.insert(make_pair("config-file"s, value)); initialize(options); + m_beforeStartHooks.exec(*this); m_agent->start(); if (m_monitorFiles) @@ -382,6 +387,7 @@ namespace mtconnect::configuration { } m_context->setThreadCount(m_workerThreadCount); + m_beforeStartHooks.exec(*this); m_agent->start(); m_context->start(); } @@ -389,6 +395,7 @@ namespace mtconnect::configuration { void AgentConfiguration::stop() { LOG(info) << "Agent stopping"; + m_beforeStopHooks.exec(*this); m_monitorTimer.cancel(); m_restart = false; if (m_agent) @@ -719,6 +726,7 @@ namespace mtconnect::configuration { // Make the Agent m_agent = make_unique(getAsyncContext(), m_devicesFile, options); + m_afterAgentHooks.exec(*this); // Make the PipelineContext m_pipelineContext = std::make_shared(); @@ -849,9 +857,8 @@ namespace mtconnect::configuration { } // Override if protocol if not specified - string protocol; AddDefaultedOptions(block.second, adapterOptions, {{configuration::Protocol, "shdr"s}}); - protocol = *GetOption(adapterOptions, configuration::Protocol); + auto protocol = *GetOption(adapterOptions, configuration::Protocol); if (factory.empty()) factory = protocol; diff --git a/src/configuration/agent_config.hpp b/src/mtconnect/configuration/agent_config.hpp similarity index 87% rename from src/configuration/agent_config.hpp rename to src/mtconnect/configuration/agent_config.hpp index 7f8fa583b..e726a4595 100644 --- a/src/configuration/agent_config.hpp +++ b/src/mtconnect/configuration/agent_config.hpp @@ -27,16 +27,18 @@ #include #include -#include "agent.hpp" #include "async_context.hpp" +#include "hook_manager.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/sink/rest_sink/file_cache.hpp" +#include "mtconnect/sink/sink.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/shdr/shdr_pipeline.hpp" +#include "mtconnect/source/source.hpp" +#include "mtconnect/utilities.hpp" #include "parser.hpp" #include "service.hpp" -#include "sink/rest_sink/file_cache.hpp" -#include "sink/sink.hpp" -#include "source/adapter/adapter.hpp" -#include "source/adapter/shdr/shdr_pipeline.hpp" -#include "source/source.hpp" -#include "utilities.hpp" namespace mtconnect { namespace rest_sink { @@ -61,7 +63,7 @@ namespace mtconnect { namespace configuration { using DevicePtr = std::shared_ptr; - class AgentConfiguration : public MTConnectService + class AGENT_LIB_API AgentConfiguration : public MTConnectService { public: using InitializationFn = void(const boost::property_tree::ptree &, AgentConfiguration &); @@ -72,6 +74,11 @@ namespace mtconnect { AgentConfiguration(); virtual ~AgentConfiguration(); + // Hooks + auto &afterAgentHooks() { return m_afterAgentHooks; } + auto &beforeStartHooks() { return m_beforeStartHooks; } + auto &beforeStopHooks() { return m_beforeStopHooks; } + // For MTConnectService void stop() override; void start() override; @@ -176,6 +183,10 @@ namespace mtconnect { #ifdef WITH_PYTHON std::unique_ptr m_python; #endif + + HookManager m_afterAgentHooks; + HookManager m_beforeStartHooks; + HookManager m_beforeStopHooks; }; } // namespace configuration } // namespace mtconnect diff --git a/src/configuration/async_context.hpp b/src/mtconnect/configuration/async_context.hpp similarity index 97% rename from src/configuration/async_context.hpp rename to src/mtconnect/configuration/async_context.hpp index cf921f7bc..23de00498 100644 --- a/src/configuration/async_context.hpp +++ b/src/mtconnect/configuration/async_context.hpp @@ -20,13 +20,14 @@ #include #include -#include "logging.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/logging.hpp" namespace mtconnect::configuration { // Manages the boost asio context and allows for a syncronous // callback to execute when all the worker threads have stopped. - class AsyncContext + class AGENT_LIB_API AsyncContext { public: using SyncCallback = std::function; diff --git a/src/configuration/config_options.hpp b/src/mtconnect/configuration/config_options.hpp similarity index 99% rename from src/configuration/config_options.hpp rename to src/mtconnect/configuration/config_options.hpp index 752040102..9bd98101a 100644 --- a/src/configuration/config_options.hpp +++ b/src/mtconnect/configuration/config_options.hpp @@ -17,6 +17,8 @@ #pragma once +#include "mtconnect/config.hpp" + namespace mtconnect { namespace configuration { #define DECLARE_CONFIGURATION(name) inline const char *name = #name; diff --git a/src/mtconnect/configuration/hook_manager.hpp b/src/mtconnect/configuration/hook_manager.hpp new file mode 100644 index 000000000..608f208a0 --- /dev/null +++ b/src/mtconnect/configuration/hook_manager.hpp @@ -0,0 +1,82 @@ +// +// Copyright Copyright 2009-2022, AMT – The Association For Manufacturing Technology (“AMT”) +// All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#pragma once + +#include +#include +#include + +#include "mtconnect/config.hpp" + +namespace mtconnect::configuration { + template + class HookManager + { + public: + using Hook = std::function; + using HookEntry = std::pair, Hook>; + using HookList = std::list; + + HookManager() {} + ~HookManager() {} + + // Add hooks without name, cannot be removed + void add(Hook &hook) { m_hooks.emplace_back(std::make_pair(std::nullopt, hook)); } + void add(Hook &&hook) { m_hooks.emplace_back(std::make_pair(std::nullopt, std::move(hook))); } + void addFirst(Hook &hook) { m_hooks.emplace_front(std::make_pair(std::nullopt, hook)); } + void addFirst(Hook &&hook) + { + m_hooks.emplace_front(std::make_pair(std::nullopt, std::move(hook))); + } + + // Add by name + void add(std::string &name, Hook &hook) + { + m_hooks.emplace_back(std::make_pair(std::nullopt, hook)); + } + void add(std::string &name, Hook &&hook) + { + m_hooks.emplace_back(std::make_pair(std::nullopt, std::move(hook))); + } + void addFirst(std::string &name, Hook &hook) + { + m_hooks.emplace_front(std::make_pair(std::nullopt, hook)); + } + void addFirst(std::string &name, Hook &&hook) + { + m_hooks.emplace_front(std::make_pair(std::nullopt, std::move(hook))); + } + + // Remove by name + bool remove(const std::string &name) + { + auto v = m_hooks.remove_if([&name](const auto &v) { return v.first && *v.first == name; }); + return v > 0; + } + + // Execute hooks9i + void exec(T &obj) const + { + for (const auto &h : m_hooks) + h.second(obj); + } + + protected: + HookList m_hooks; + }; +} // namespace mtconnect::configuration diff --git a/src/configuration/parser.cpp b/src/mtconnect/configuration/parser.cpp similarity index 99% rename from src/configuration/parser.cpp rename to src/mtconnect/configuration/parser.cpp index b487c9f39..b36735d1d 100644 --- a/src/configuration/parser.cpp +++ b/src/mtconnect/configuration/parser.cpp @@ -20,7 +20,7 @@ #include #include -#include "utilities.hpp" +#include "mtconnect/utilities.hpp" //#define BOOST_SPIRIT_DEBUG 1 #ifdef BOOST_SPIRIT_DEBUG diff --git a/src/configuration/parser.hpp b/src/mtconnect/configuration/parser.hpp similarity index 89% rename from src/configuration/parser.hpp rename to src/mtconnect/configuration/parser.hpp index 0b874991c..2786c481a 100644 --- a/src/configuration/parser.hpp +++ b/src/mtconnect/configuration/parser.hpp @@ -21,15 +21,17 @@ #include +#include "mtconnect/config.hpp" + namespace mtconnect { namespace configuration { - class ParseError : public std::runtime_error + class AGENT_LIB_API ParseError : public std::runtime_error { public: using std::runtime_error::runtime_error; }; - struct Parser + struct AGENT_LIB_API Parser { static boost::property_tree::ptree parse(const std::string &text); static boost::property_tree::ptree parse(const std::filesystem::path &path); diff --git a/src/configuration/service.cpp b/src/mtconnect/configuration/service.cpp similarity index 99% rename from src/configuration/service.cpp rename to src/mtconnect/configuration/service.cpp index bc395e42b..b9669dba0 100644 --- a/src/configuration/service.cpp +++ b/src/mtconnect/configuration/service.cpp @@ -27,9 +27,9 @@ #include #include -#include "logging.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/version.h" #include "service.hpp" -#include "version.h" #ifdef _WINDOWS #define stricmp _stricmp diff --git a/src/configuration/service.hpp b/src/mtconnect/configuration/service.hpp similarity index 95% rename from src/configuration/service.hpp rename to src/mtconnect/configuration/service.hpp index b791a17d5..a5cf7ac74 100644 --- a/src/configuration/service.hpp +++ b/src/mtconnect/configuration/service.hpp @@ -23,11 +23,12 @@ #include #include -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace configuration { - class MTConnectService + class AGENT_LIB_API MTConnectService { public: MTConnectService() = default; diff --git a/src/device_model/agent_device.cpp b/src/mtconnect/device_model/agent_device.cpp similarity index 97% rename from src/device_model/agent_device.cpp rename to src/mtconnect/device_model/agent_device.cpp index b79a184f0..30c0edaab 100644 --- a/src/device_model/agent_device.cpp +++ b/src/mtconnect/device_model/agent_device.cpp @@ -17,11 +17,11 @@ #include "agent_device.hpp" -#include "configuration/config_options.hpp" #include "data_item/constraints.hpp" #include "data_item/data_item.hpp" -#include "logging.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using namespace std; using namespace std::literals; diff --git a/src/device_model/agent_device.hpp b/src/mtconnect/device_model/agent_device.hpp similarity index 91% rename from src/device_model/agent_device.hpp rename to src/mtconnect/device_model/agent_device.hpp index 84d1d026d..de62dabff 100644 --- a/src/device_model/agent_device.hpp +++ b/src/mtconnect/device_model/agent_device.hpp @@ -16,12 +16,14 @@ // #pragma once + #include #include "component.hpp" #include "data_item/data_item.hpp" -#include "device_model/device.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace source::adapter { @@ -30,7 +32,7 @@ namespace mtconnect { } // namespace source::adapter namespace device_model { - class AgentDevice : public Device + class AGENT_LIB_API AgentDevice : public Device { public: // Constructor that sets variables from an attribute map diff --git a/src/device_model/component.cpp b/src/mtconnect/device_model/component.cpp similarity index 98% rename from src/device_model/component.cpp rename to src/mtconnect/device_model/component.cpp index 86184c80e..1c9b6a139 100644 --- a/src/device_model/component.cpp +++ b/src/mtconnect/device_model/component.cpp @@ -20,12 +20,12 @@ #include #include -#include "agent.hpp" #include "composition.hpp" #include "configuration/configuration.hpp" #include "data_item/data_item.hpp" #include "description.hpp" -#include "device_model/device.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/device_model/device.hpp" #include "reference.hpp" using namespace std; diff --git a/src/device_model/component.hpp b/src/mtconnect/device_model/component.hpp similarity index 97% rename from src/device_model/component.hpp rename to src/mtconnect/device_model/component.hpp index 8683b2ac1..ee79b216a 100644 --- a/src/device_model/component.hpp +++ b/src/mtconnect/device_model/component.hpp @@ -26,8 +26,9 @@ #include "composition.hpp" #include "configuration/configuration.hpp" -#include "entity/factory.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace device_model { @@ -42,7 +43,7 @@ namespace mtconnect { using DevicePtr = std::shared_ptr; using DataItemPtr = std::shared_ptr; - class Component : public entity::Entity + class AGENT_LIB_API Component : public entity::Entity { public: Component(const std::string &name, const entity::Properties &props); diff --git a/src/device_model/composition.cpp b/src/mtconnect/device_model/composition.cpp similarity index 98% rename from src/device_model/composition.cpp rename to src/mtconnect/device_model/composition.cpp index 306ace616..568aec495 100644 --- a/src/device_model/composition.cpp +++ b/src/mtconnect/device_model/composition.cpp @@ -21,7 +21,6 @@ #include "configuration/configuration.hpp" #include "description.hpp" -#include "entity/entity.hpp" using namespace std; diff --git a/src/device_model/composition.hpp b/src/mtconnect/device_model/composition.hpp similarity index 93% rename from src/device_model/composition.hpp rename to src/mtconnect/device_model/composition.hpp index f832c376b..386ec6d9c 100644 --- a/src/device_model/composition.hpp +++ b/src/mtconnect/device_model/composition.hpp @@ -17,12 +17,13 @@ #pragma once -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" namespace mtconnect { namespace device_model { class Component; - class Composition : public entity::Entity + class AGENT_LIB_API Composition : public entity::Entity { public: using entity::Entity::Entity; diff --git a/src/device_model/configuration/configuration.cpp b/src/mtconnect/device_model/configuration/configuration.cpp similarity index 98% rename from src/device_model/configuration/configuration.cpp rename to src/mtconnect/device_model/configuration/configuration.cpp index 0f356d4a4..90040e883 100644 --- a/src/device_model/configuration/configuration.cpp +++ b/src/mtconnect/device_model/configuration/configuration.cpp @@ -18,8 +18,8 @@ #include "configuration.hpp" #include "coordinate_systems.hpp" -#include "entity/factory.hpp" #include "motion.hpp" +#include "mtconnect/entity/factory.hpp" #include "relationships.hpp" #include "sensor_configuration.hpp" #include "solid_model.hpp" diff --git a/src/device_model/configuration/configuration.hpp b/src/mtconnect/device_model/configuration/configuration.hpp similarity index 90% rename from src/device_model/configuration/configuration.hpp rename to src/mtconnect/device_model/configuration/configuration.hpp index b4d23bde3..bcce229df 100644 --- a/src/device_model/configuration/configuration.hpp +++ b/src/mtconnect/device_model/configuration/configuration.hpp @@ -17,8 +17,9 @@ #pragma once -#include "entity/entity.hpp" -#include "entity/factory.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" namespace mtconnect { namespace device_model { diff --git a/src/device_model/configuration/coordinate_systems.cpp b/src/mtconnect/device_model/configuration/coordinate_systems.cpp similarity index 100% rename from src/device_model/configuration/coordinate_systems.cpp rename to src/mtconnect/device_model/configuration/coordinate_systems.cpp diff --git a/src/device_model/configuration/coordinate_systems.hpp b/src/mtconnect/device_model/configuration/coordinate_systems.hpp similarity index 97% rename from src/device_model/configuration/coordinate_systems.hpp rename to src/mtconnect/device_model/configuration/coordinate_systems.hpp index 001b6280f..fe57bd943 100644 --- a/src/device_model/configuration/coordinate_systems.hpp +++ b/src/mtconnect/device_model/configuration/coordinate_systems.hpp @@ -18,6 +18,7 @@ #pragma once #include "configuration.hpp" +#include "mtconnect/config.hpp" namespace mtconnect { using namespace entity; diff --git a/src/device_model/configuration/motion.cpp b/src/mtconnect/device_model/configuration/motion.cpp similarity index 100% rename from src/device_model/configuration/motion.cpp rename to src/mtconnect/device_model/configuration/motion.cpp diff --git a/src/device_model/configuration/motion.hpp b/src/mtconnect/device_model/configuration/motion.hpp similarity index 96% rename from src/device_model/configuration/motion.hpp rename to src/mtconnect/device_model/configuration/motion.hpp index eee7d6443..4bd3e2524 100644 --- a/src/device_model/configuration/motion.hpp +++ b/src/mtconnect/device_model/configuration/motion.hpp @@ -18,6 +18,7 @@ #pragma once #include "configuration.hpp" +#include "mtconnect/config.hpp" namespace mtconnect { using namespace entity; diff --git a/src/device_model/configuration/relationships.cpp b/src/mtconnect/device_model/configuration/relationships.cpp similarity index 73% rename from src/device_model/configuration/relationships.cpp rename to src/mtconnect/device_model/configuration/relationships.cpp index c98445f5a..bf993f03b 100644 --- a/src/device_model/configuration/relationships.cpp +++ b/src/mtconnect/device_model/configuration/relationships.cpp @@ -35,21 +35,27 @@ namespace mtconnect { auto deviceRelationship = make_shared(*relationship); - deviceRelationship->addRequirements(Requirements { - Requirement("deviceUuidRef", true), - Requirement("role", ControlledVocab {"SYSTEM", "AUXILIARY"}, false), - Requirement("href", false), - Requirement("xlink:type", false), - }); + deviceRelationship->addRequirements( + Requirements {Requirement("deviceUuidRef", true), + Requirement("role", ControlledVocab {"SYSTEM", "AUXILIARY"}, false), + Requirement("href", false), Requirement("xlink:type", false)}); auto componentRelationship = make_shared(*relationship); componentRelationship->addRequirements(Requirements {Requirement("idRef", true)}); + auto assetRelationship = make_shared(*relationship); + + assetRelationship->addRequirements( + Requirements {Requirement("assetIdRef", true), Requirement("assetType", true), + Requirement("href", false), Requirement("xlink:type", false)}); + relationships = make_shared( Requirements {Requirement("ComponentRelationship", ENTITY, componentRelationship, 0, Requirement::Infinite), Requirement("DeviceRelationship", ENTITY, deviceRelationship, 0, + Requirement::Infinite), + Requirement("AssetRelationship", ENTITY, assetRelationship, 0, Requirement::Infinite)}); relationships->registerMatchers(); diff --git a/src/device_model/configuration/relationships.hpp b/src/mtconnect/device_model/configuration/relationships.hpp similarity index 97% rename from src/device_model/configuration/relationships.hpp rename to src/mtconnect/device_model/configuration/relationships.hpp index 55766ac3c..bd36349ba 100644 --- a/src/device_model/configuration/relationships.hpp +++ b/src/mtconnect/device_model/configuration/relationships.hpp @@ -18,6 +18,7 @@ #pragma once #include "configuration.hpp" +#include "mtconnect/config.hpp" namespace mtconnect { using namespace entity; diff --git a/src/device_model/configuration/sensor_configuration.cpp b/src/mtconnect/device_model/configuration/sensor_configuration.cpp similarity index 100% rename from src/device_model/configuration/sensor_configuration.cpp rename to src/mtconnect/device_model/configuration/sensor_configuration.cpp diff --git a/src/device_model/configuration/sensor_configuration.hpp b/src/mtconnect/device_model/configuration/sensor_configuration.hpp similarity index 97% rename from src/device_model/configuration/sensor_configuration.hpp rename to src/mtconnect/device_model/configuration/sensor_configuration.hpp index 73dac26c3..ec026b908 100644 --- a/src/device_model/configuration/sensor_configuration.hpp +++ b/src/mtconnect/device_model/configuration/sensor_configuration.hpp @@ -18,6 +18,7 @@ #pragma once #include "configuration.hpp" +#include "mtconnect/config.hpp" namespace mtconnect { using namespace entity; diff --git a/src/device_model/configuration/solid_model.cpp b/src/mtconnect/device_model/configuration/solid_model.cpp similarity index 100% rename from src/device_model/configuration/solid_model.cpp rename to src/mtconnect/device_model/configuration/solid_model.cpp diff --git a/src/device_model/configuration/solid_model.hpp b/src/mtconnect/device_model/configuration/solid_model.hpp similarity index 97% rename from src/device_model/configuration/solid_model.hpp rename to src/mtconnect/device_model/configuration/solid_model.hpp index a1c58239a..b810b60f8 100644 --- a/src/device_model/configuration/solid_model.hpp +++ b/src/mtconnect/device_model/configuration/solid_model.hpp @@ -18,6 +18,7 @@ #pragma once #include "configuration.hpp" +#include "mtconnect/config.hpp" namespace mtconnect { using namespace entity; diff --git a/src/device_model/configuration/specifications.cpp b/src/mtconnect/device_model/configuration/specifications.cpp similarity index 100% rename from src/device_model/configuration/specifications.cpp rename to src/mtconnect/device_model/configuration/specifications.cpp diff --git a/src/device_model/configuration/specifications.hpp b/src/mtconnect/device_model/configuration/specifications.hpp similarity index 97% rename from src/device_model/configuration/specifications.hpp rename to src/mtconnect/device_model/configuration/specifications.hpp index 533034cae..c4dd2b0cf 100644 --- a/src/device_model/configuration/specifications.hpp +++ b/src/mtconnect/device_model/configuration/specifications.hpp @@ -18,6 +18,7 @@ #pragma once #include "configuration.hpp" +#include "mtconnect/config.hpp" namespace mtconnect { using namespace entity; diff --git a/src/device_model/data_item/constraints.hpp b/src/mtconnect/device_model/data_item/constraints.hpp similarity index 91% rename from src/device_model/data_item/constraints.hpp rename to src/mtconnect/device_model/data_item/constraints.hpp index 3be93d391..2c8f328bd 100644 --- a/src/device_model/data_item/constraints.hpp +++ b/src/mtconnect/device_model/data_item/constraints.hpp @@ -17,14 +17,15 @@ #pragma once -#include "entity/entity.hpp" -#include "entity/factory.hpp" #include "filter.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" namespace mtconnect { namespace device_model { namespace data_item { - class Constraints : public entity::Entity + class AGENT_LIB_API Constraints : public entity::Entity { public: static entity::FactoryPtr getFactory() diff --git a/src/device_model/data_item/data_item.cpp b/src/mtconnect/device_model/data_item/data_item.cpp similarity index 98% rename from src/device_model/data_item/data_item.cpp rename to src/mtconnect/device_model/data_item/data_item.cpp index a07a60bc8..b4df08de0 100644 --- a/src/device_model/data_item/data_item.cpp +++ b/src/mtconnect/device_model/data_item/data_item.cpp @@ -24,9 +24,9 @@ #include #include -#include "device_model/device.hpp" -#include "entity/requirement.hpp" -#include "logging.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/entity/requirement.hpp" +#include "mtconnect/logging.hpp" using namespace std; diff --git a/src/device_model/data_item/data_item.hpp b/src/mtconnect/device_model/data_item/data_item.hpp similarity index 96% rename from src/device_model/data_item/data_item.hpp rename to src/mtconnect/device_model/data_item/data_item.hpp index fb680aa91..fe7991a95 100644 --- a/src/device_model/data_item/data_item.hpp +++ b/src/mtconnect/device_model/data_item/data_item.hpp @@ -16,18 +16,19 @@ // #pragma once + #include #include "constraints.hpp" #include "definition.hpp" -#include "device_model/component.hpp" -#include "entity/entity.hpp" #include "filter.hpp" -#include "observation/change_observer.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/component.hpp" +#include "mtconnect/observation/change_observer.hpp" +#include "mtconnect/utilities.hpp" #include "relationships.hpp" #include "source.hpp" #include "unit_conversion.hpp" -#include "utilities.hpp" #ifdef PASCAL #undef PASCAL @@ -41,7 +42,7 @@ namespace mtconnect { class Composition; namespace data_item { - class DataItem : public entity::Entity, public observation::ChangeSignaler + class AGENT_LIB_API DataItem : public entity::Entity, public observation::ChangeSignaler { public: // Enumeration for data item category diff --git a/src/device_model/data_item/definition.hpp b/src/mtconnect/device_model/data_item/definition.hpp similarity index 95% rename from src/device_model/data_item/definition.hpp rename to src/mtconnect/device_model/data_item/definition.hpp index 405b32d0c..50cded529 100644 --- a/src/device_model/data_item/definition.hpp +++ b/src/mtconnect/device_model/data_item/definition.hpp @@ -19,15 +19,16 @@ #include -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" namespace mtconnect { namespace device_model { namespace data_item { - class Definition : public entity::Entity + class AGENT_LIB_API Definition : public entity::Entity { public: - class Entry : public entity::Entity + class AGENT_LIB_API Entry : public entity::Entity { public: using entity::Entity::Entity; diff --git a/src/device_model/data_item/filter.hpp b/src/mtconnect/device_model/data_item/filter.hpp similarity index 89% rename from src/device_model/data_item/filter.hpp rename to src/mtconnect/device_model/data_item/filter.hpp index b29a635c0..50d93720c 100644 --- a/src/device_model/data_item/filter.hpp +++ b/src/mtconnect/device_model/data_item/filter.hpp @@ -17,13 +17,14 @@ #pragma once -#include "entity/entity.hpp" -#include "entity/factory.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" namespace mtconnect { namespace device_model { namespace data_item { - class Filter : public entity::Entity + class AGENT_LIB_API Filter : public entity::Entity { public: static entity::FactoryPtr getFactory() diff --git a/src/device_model/data_item/relationships.hpp b/src/mtconnect/device_model/data_item/relationships.hpp similarity index 94% rename from src/device_model/data_item/relationships.hpp rename to src/mtconnect/device_model/data_item/relationships.hpp index 1402ed16b..e78e10ad0 100644 --- a/src/device_model/data_item/relationships.hpp +++ b/src/mtconnect/device_model/data_item/relationships.hpp @@ -19,13 +19,14 @@ #include -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" namespace mtconnect { namespace device_model { namespace data_item { class DataItem; - class Relationship : public entity::Entity + class AGENT_LIB_API Relationship : public entity::Entity { public: using entity::Entity::Entity; @@ -73,7 +74,7 @@ namespace mtconnect { std::weak_ptr m_target; }; - class Relationships : public entity::Entity + class AGENT_LIB_API Relationships : public entity::Entity { public: using entity::Entity::Entity; diff --git a/src/device_model/data_item/source.hpp b/src/mtconnect/device_model/data_item/source.hpp similarity index 91% rename from src/device_model/data_item/source.hpp rename to src/mtconnect/device_model/data_item/source.hpp index ff9fd06e9..35d549b4f 100644 --- a/src/device_model/data_item/source.hpp +++ b/src/mtconnect/device_model/data_item/source.hpp @@ -17,10 +17,11 @@ #pragma once -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" namespace mtconnect::device_model::data_item { - class Source : public entity::Entity + class AGENT_LIB_API Source : public entity::Entity { public: static entity::FactoryPtr getFactory() diff --git a/src/device_model/data_item/unit_conversion.cpp b/src/mtconnect/device_model/data_item/unit_conversion.cpp similarity index 100% rename from src/device_model/data_item/unit_conversion.cpp rename to src/mtconnect/device_model/data_item/unit_conversion.cpp diff --git a/src/device_model/data_item/unit_conversion.hpp b/src/mtconnect/device_model/data_item/unit_conversion.hpp similarity index 95% rename from src/device_model/data_item/unit_conversion.hpp rename to src/mtconnect/device_model/data_item/unit_conversion.hpp index 087a4e81c..cc3baa17d 100644 --- a/src/device_model/data_item/unit_conversion.hpp +++ b/src/mtconnect/device_model/data_item/unit_conversion.hpp @@ -22,12 +22,13 @@ #include #include -#include "entity/requirement.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/requirement.hpp" namespace mtconnect { namespace device_model { namespace data_item { - class UnitConversion + class AGENT_LIB_API UnitConversion { public: UnitConversion(double factor = 1.0, double offset = 0.0) diff --git a/src/device_model/description.cpp b/src/mtconnect/device_model/description.cpp similarity index 100% rename from src/device_model/description.cpp rename to src/mtconnect/device_model/description.cpp diff --git a/src/device_model/description.hpp b/src/mtconnect/device_model/description.hpp similarity index 87% rename from src/device_model/description.hpp rename to src/mtconnect/device_model/description.hpp index 0d30cbdb9..bbaf8da9e 100644 --- a/src/device_model/description.hpp +++ b/src/mtconnect/device_model/description.hpp @@ -23,9 +23,10 @@ #include #include -#include "entity/entity.hpp" -#include "entity/factory.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace device_model { diff --git a/src/device_model/device.cpp b/src/mtconnect/device_model/device.cpp similarity index 96% rename from src/device_model/device.cpp rename to src/mtconnect/device_model/device.cpp index 6a08c2027..1fa11d784 100644 --- a/src/device_model/device.cpp +++ b/src/mtconnect/device_model/device.cpp @@ -17,9 +17,9 @@ #include "device.hpp" -#include "configuration/config_options.hpp" -#include "entity/factory.hpp" -#include "logging.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/logging.hpp" using namespace std; diff --git a/src/device_model/device.hpp b/src/mtconnect/device_model/device.hpp similarity index 89% rename from src/device_model/device.hpp rename to src/mtconnect/device_model/device.hpp index 33d5852f8..078a01173 100644 --- a/src/device_model/device.hpp +++ b/src/mtconnect/device_model/device.hpp @@ -31,7 +31,8 @@ #include "component.hpp" #include "data_item/data_item.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace mic = boost::multi_index; @@ -41,7 +42,7 @@ namespace mtconnect { } namespace device_model { - class Device : public Component + class AGENT_LIB_API Device : public Component { public: struct ByName @@ -50,6 +51,8 @@ namespace mtconnect { {}; struct BySource {}; + struct ByType + {}; struct ExtractId { @@ -96,11 +99,28 @@ namespace mtconnect { } }; + struct ExtractType + { + using result_type = std::string; + const result_type &operator()(const WeakDataItemPtr &d) const + { + const static result_type none {}; + if (d.expired()) + return none; + else + { + auto di = d.lock(); + return di->getType(); + } + } + }; + // Mapping of device names to data items using DataItemIndex = mic::multi_index_container< WeakDataItemPtr, mic::indexed_by, ExtractId>, mic::hashed_unique, ExtractName>, - mic::hashed_unique, ExtractSource>>>; + mic::hashed_unique, ExtractSource>, + mic::ordered_non_unique, ExtractType>>>; // Constructor that sets variables from an attribute map Device(const std::string &name, entity::Properties &props); @@ -145,6 +165,7 @@ namespace mtconnect { // Return the mapping of Device to data items const auto &getDeviceDataItems() const { return m_dataItems.get(); } + const auto &getDataItemIndex() const { return m_dataItems; } void addDataItem(DataItemPtr dataItem, entity::ErrorList &errors) override; diff --git a/src/device_model/reference.cpp b/src/mtconnect/device_model/reference.cpp similarity index 96% rename from src/device_model/reference.cpp rename to src/mtconnect/device_model/reference.cpp index 6aa8f9b3f..08d1e34f7 100644 --- a/src/device_model/reference.cpp +++ b/src/mtconnect/device_model/reference.cpp @@ -24,9 +24,9 @@ #include #include "device.hpp" -#include "entity/entity.hpp" -#include "logging.hpp" -#include "utilities.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/utilities.hpp" using namespace std; diff --git a/src/device_model/reference.hpp b/src/mtconnect/device_model/reference.hpp similarity index 91% rename from src/device_model/reference.hpp rename to src/mtconnect/device_model/reference.hpp index 7093e8c4e..5681d1146 100644 --- a/src/device_model/reference.hpp +++ b/src/mtconnect/device_model/reference.hpp @@ -23,8 +23,9 @@ #include #include -#include "entity/entity.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace device_model { @@ -35,7 +36,7 @@ namespace mtconnect { class Device; using DevicePtr = std::shared_ptr; - class Reference : public entity::Entity + class AGENT_LIB_API Reference : public entity::Entity { public: using entity::Entity::Entity; diff --git a/src/entity/data_set.cpp b/src/mtconnect/entity/data_set.cpp similarity index 99% rename from src/entity/data_set.cpp rename to src/mtconnect/entity/data_set.cpp index 304ca4a1a..68186567e 100644 --- a/src/entity/data_set.cpp +++ b/src/mtconnect/entity/data_set.cpp @@ -17,7 +17,7 @@ #include "data_set.hpp" -#include "utilities.hpp" +#include "mtconnect/utilities.hpp" //#define BOOST_SPIRIT_DEBUG 1 diff --git a/src/entity/data_set.hpp b/src/mtconnect/entity/data_set.hpp similarity index 94% rename from src/entity/data_set.hpp rename to src/mtconnect/entity/data_set.hpp index d2f93b277..b92bfe9e1 100644 --- a/src/entity/data_set.hpp +++ b/src/mtconnect/entity/data_set.hpp @@ -25,13 +25,14 @@ #include #include -#include "logging.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::entity { struct DataSetEntry; - class DataSet : public std::set + class AGENT_LIB_API DataSet : public std::set { public: using base = std::set; @@ -104,7 +105,7 @@ namespace mtconnect::entity { if (v == end()) return std::nullopt; else - return get(v->m_value); + return std::get(v->m_value); } inline bool DataSetValueSame::operator()(const DataSet &v) diff --git a/src/entity/entity.cpp b/src/mtconnect/entity/entity.cpp similarity index 100% rename from src/entity/entity.cpp rename to src/mtconnect/entity/entity.cpp diff --git a/src/entity/entity.hpp b/src/mtconnect/entity/entity.hpp similarity index 99% rename from src/entity/entity.hpp rename to src/mtconnect/entity/entity.hpp index 6452fbb45..70cdfbc4e 100644 --- a/src/entity/entity.hpp +++ b/src/mtconnect/entity/entity.hpp @@ -22,6 +22,7 @@ #include #include "data_set.hpp" +#include "mtconnect/config.hpp" #include "qname.hpp" #include "requirement.hpp" @@ -57,7 +58,7 @@ namespace mtconnect { return std::nullopt; } - class Entity : public std::enable_shared_from_this + class AGENT_LIB_API Entity : public std::enable_shared_from_this { public: using super = std::nullptr_t; diff --git a/src/entity/factory.cpp b/src/mtconnect/entity/factory.cpp similarity index 99% rename from src/entity/factory.cpp rename to src/mtconnect/entity/factory.cpp index 4b48f352f..9b42b28b5 100644 --- a/src/entity/factory.cpp +++ b/src/mtconnect/entity/factory.cpp @@ -19,7 +19,7 @@ #include -#include "logging.hpp" +#include "mtconnect/logging.hpp" using namespace std; diff --git a/src/entity/factory.hpp b/src/mtconnect/entity/factory.hpp similarity index 98% rename from src/entity/factory.hpp rename to src/mtconnect/entity/factory.hpp index d6a571a4e..bff6bb132 100644 --- a/src/entity/factory.hpp +++ b/src/mtconnect/entity/factory.hpp @@ -21,13 +21,14 @@ #include #include -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" namespace mtconnect { namespace entity { using Requirements = std::list; - class Factory : public Matcher, public std::enable_shared_from_this + class AGENT_LIB_API Factory : public Matcher, public std::enable_shared_from_this { public: using Function = std::function; diff --git a/src/entity/json_parser.cpp b/src/mtconnect/entity/json_parser.cpp similarity index 98% rename from src/entity/json_parser.cpp rename to src/mtconnect/entity/json_parser.cpp index 136438933..03db5f97c 100644 --- a/src/entity/json_parser.cpp +++ b/src/mtconnect/entity/json_parser.cpp @@ -15,11 +15,11 @@ // limitations under the License. // -#include "entity/json_parser.hpp" +#include "mtconnect/entity/json_parser.hpp" #include -#include "logging.hpp" +#include "mtconnect/logging.hpp" using namespace std; using json = nlohmann::json; diff --git a/src/entity/json_parser.hpp b/src/mtconnect/entity/json_parser.hpp similarity index 89% rename from src/entity/json_parser.hpp rename to src/mtconnect/entity/json_parser.hpp index 0625489cd..9e4e1652e 100644 --- a/src/entity/json_parser.hpp +++ b/src/mtconnect/entity/json_parser.hpp @@ -21,14 +21,15 @@ #include #include -#include "entity/entity.hpp" #include "factory.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/utilities.hpp" #include "requirement.hpp" -#include "utilities.hpp" namespace mtconnect { namespace entity { - class JsonParser + class AGENT_LIB_API JsonParser { public: JsonParser(uint32_t version = 1) : m_version(version) {} diff --git a/src/entity/json_printer.cpp b/src/mtconnect/entity/json_printer.cpp similarity index 99% rename from src/entity/json_printer.cpp rename to src/mtconnect/entity/json_printer.cpp index 775c130f4..89eaa46a5 100644 --- a/src/entity/json_printer.cpp +++ b/src/mtconnect/entity/json_printer.cpp @@ -19,7 +19,7 @@ #include -#include "logging.hpp" +#include "mtconnect/logging.hpp" using namespace std; using json = nlohmann::json; diff --git a/src/entity/json_printer.hpp b/src/mtconnect/entity/json_printer.hpp similarity index 92% rename from src/entity/json_printer.hpp rename to src/mtconnect/entity/json_printer.hpp index 96f5d3f04..5c84904af 100644 --- a/src/entity/json_printer.hpp +++ b/src/mtconnect/entity/json_printer.hpp @@ -19,13 +19,14 @@ #include -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" using json = nlohmann::json; namespace mtconnect { namespace entity { - class JsonPrinter + class AGENT_LIB_API JsonPrinter { public: JsonPrinter(uint32_t version) : m_version(version) {}; diff --git a/src/entity/qname.hpp b/src/mtconnect/entity/qname.hpp similarity index 97% rename from src/entity/qname.hpp rename to src/mtconnect/entity/qname.hpp index db5cb43ed..30194e136 100644 --- a/src/entity/qname.hpp +++ b/src/mtconnect/entity/qname.hpp @@ -21,9 +21,11 @@ #include #include +#include "mtconnect/config.hpp" + namespace mtconnect { namespace entity { - class QName : public std::string + class AGENT_LIB_API QName : public std::string { public: QName() = default; diff --git a/src/entity/requirement.cpp b/src/mtconnect/entity/requirement.cpp similarity index 99% rename from src/entity/requirement.cpp rename to src/mtconnect/entity/requirement.cpp index 760a4f0ec..5ac1a4972 100644 --- a/src/entity/requirement.cpp +++ b/src/mtconnect/entity/requirement.cpp @@ -26,9 +26,9 @@ #include #include -#include "entity/entity.hpp" #include "factory.hpp" -#include "logging.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/logging.hpp" using namespace std; diff --git a/src/entity/requirement.hpp b/src/mtconnect/entity/requirement.hpp similarity index 95% rename from src/entity/requirement.hpp rename to src/mtconnect/entity/requirement.hpp index 6b8356648..77336aeda 100644 --- a/src/entity/requirement.hpp +++ b/src/mtconnect/entity/requirement.hpp @@ -37,7 +37,8 @@ #include #include "data_set.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace entity { @@ -49,7 +50,7 @@ namespace mtconnect { using Value = std::variant; - enum ValueType : int16_t + enum ValueType : std::uint16_t { EMPTY = 0x0, ENTITY = 0x1, @@ -75,9 +76,9 @@ namespace mtconnect { using Pattern = std::optional; using VocabSet = std::optional>; - bool ConvertValueToType(Value &value, ValueType type, bool table = false); + bool AGENT_LIB_API ConvertValueToType(Value &value, ValueType type, bool table = false); - class EntityError : public std::logic_error + class AGENT_LIB_API EntityError : public std::logic_error { public: explicit EntityError(const std::string &s, const std::string &e = "") @@ -112,7 +113,8 @@ namespace mtconnect { std::string m_text; std::string m_entity; }; - class PropertyError : public EntityError + + class AGENT_LIB_API PropertyError : public EntityError { public: explicit PropertyError(const std::string &s, const std::string &p = "", @@ -158,7 +160,7 @@ namespace mtconnect { using MatcherPtr = std::weak_ptr; - class Requirement + class AGENT_LIB_API Requirement { public: const static auto Infinite {std::numeric_limits::max()}; diff --git a/src/entity/xml_parser.cpp b/src/mtconnect/entity/xml_parser.cpp similarity index 98% rename from src/entity/xml_parser.cpp rename to src/mtconnect/entity/xml_parser.cpp index 71a4f75f9..1190994b1 100644 --- a/src/entity/xml_parser.cpp +++ b/src/mtconnect/entity/xml_parser.cpp @@ -15,14 +15,14 @@ // limitations under the License. // -#include "entity/xml_parser.hpp" +#include "mtconnect/entity/xml_parser.hpp" #include #include #include -#include "logging.hpp" -#include "printer/xml_helper.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/printer/xml_helper.hpp" using namespace std; diff --git a/src/entity/xml_parser.hpp b/src/mtconnect/entity/xml_parser.hpp similarity index 91% rename from src/entity/xml_parser.hpp rename to src/mtconnect/entity/xml_parser.hpp index 28e9c7c7c..3e8cca740 100644 --- a/src/entity/xml_parser.hpp +++ b/src/mtconnect/entity/xml_parser.hpp @@ -21,15 +21,16 @@ #include #include -#include "entity/entity.hpp" #include "factory.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/utilities.hpp" #include "requirement.hpp" -#include "utilities.hpp" struct _xmlNode; namespace mtconnect { namespace entity { - class XmlParser + class AGENT_LIB_API XmlParser { public: XmlParser() = default; diff --git a/src/entity/xml_printer.cpp b/src/mtconnect/entity/xml_printer.cpp similarity index 99% rename from src/entity/xml_printer.cpp rename to src/mtconnect/entity/xml_printer.cpp index 93892f30d..4eadbd197 100644 --- a/src/entity/xml_printer.cpp +++ b/src/mtconnect/entity/xml_printer.cpp @@ -21,8 +21,8 @@ #include -#include "logging.hpp" -#include "printer/xml_printer_helper.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/printer/xml_printer_helper.hpp" using namespace std; diff --git a/src/entity/xml_printer.hpp b/src/mtconnect/entity/xml_printer.hpp similarity index 91% rename from src/entity/xml_printer.hpp rename to src/mtconnect/entity/xml_printer.hpp index 95a8c1738..1d92435a5 100644 --- a/src/entity/xml_printer.hpp +++ b/src/mtconnect/entity/xml_printer.hpp @@ -19,7 +19,8 @@ #include -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" extern "C" { @@ -29,7 +30,7 @@ extern "C" namespace mtconnect { namespace entity { - class XmlPrinter + class AGENT_LIB_API XmlPrinter { public: XmlPrinter() = default; diff --git a/src/logging.hpp b/src/mtconnect/logging.hpp similarity index 94% rename from src/logging.hpp rename to src/mtconnect/logging.hpp index 4f2b396d4..b420259fc 100644 --- a/src/logging.hpp +++ b/src/mtconnect/logging.hpp @@ -20,6 +20,8 @@ #include #include +#include "mtconnect/config.hpp" + #define LOG BOOST_LOG_TRIVIAL #define NAMED_SCOPE BOOST_LOG_NAMED_SCOPE @@ -28,8 +30,9 @@ // After that, use PLUGIN_LOG(lvl) << ...; namespace mtconnect { namespace configuration { + AGENT_LIB_API extern boost::log::trivial::logger_type *gAgentLogger; - } + } // namespace configuration } // namespace mtconnect #define PLUGIN_LOG(lvl) \ diff --git a/src/mqtt/mqtt_authorization.hpp b/src/mtconnect/mqtt/mqtt_authorization.hpp similarity index 87% rename from src/mqtt/mqtt_authorization.hpp rename to src/mtconnect/mqtt/mqtt_authorization.hpp index 35576c766..c616b3e65 100644 --- a/src/mqtt/mqtt_authorization.hpp +++ b/src/mtconnect/mqtt/mqtt_authorization.hpp @@ -42,7 +42,7 @@ namespace mtconnect { Both }; - void MqttTopicPermission(const std::string &topic, const std::string& clientId) + void MqttTopicPermission(const std::string& topic, const std::string& clientId) { m_topic = topic; m_clientId = clientId; @@ -51,7 +51,7 @@ namespace mtconnect { } void MqttTopicPermission(const std::string& topic, const std::string& clientId, - AuthorizationType type) + AuthorizationType type) { m_topic = topic; m_clientId = clientId; @@ -60,7 +60,7 @@ namespace mtconnect { } void MqttTopicPermission(const std::string& topic, const std::string& clientId, - AuthorizationType type, TopicMode mode) + AuthorizationType type, TopicMode mode) { m_topic = topic; m_clientId = clientId; @@ -78,7 +78,7 @@ namespace mtconnect { class MqttAuthorization : public std::enable_shared_from_this { public: - MqttAuthorization(const ConfigOptions &options) : m_options(options) + MqttAuthorization(const ConfigOptions& options) : m_options(options) { m_clientId = GetOption(options, configuration::MqttClientId); m_username = GetOption(options, configuration::MqttUserName); @@ -86,16 +86,16 @@ namespace mtconnect { } virtual ~MqttAuthorization() = default; - - bool checkCredentials() - { + + bool checkCredentials() + { if (!m_username && !m_password) { LOG(error) << "MQTT USERNAME_OR_PASSWORD are Not Available"; return false; } - return true; + return true; } protected: @@ -104,5 +104,5 @@ namespace mtconnect { std::string m_clientId; ConfigOptions m_options; }; - } // namespace MqttAuthorization + } // namespace mqtt_client } // namespace mtconnect diff --git a/src/mqtt/mqtt_client.hpp b/src/mtconnect/mqtt/mqtt_client.hpp similarity index 94% rename from src/mqtt/mqtt_client.hpp rename to src/mtconnect/mqtt/mqtt_client.hpp index 0386f9233..f44ac89fe 100644 --- a/src/mqtt/mqtt_client.hpp +++ b/src/mtconnect/mqtt/mqtt_client.hpp @@ -17,8 +17,9 @@ #pragma once -#include "source/adapter/adapter.hpp" -#include "source/adapter/adapter_pipeline.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/adapter_pipeline.hpp" namespace mtconnect { namespace mqtt_client { diff --git a/src/mqtt/mqtt_client_impl.hpp b/src/mtconnect/mqtt/mqtt_client_impl.hpp similarity index 97% rename from src/mqtt/mqtt_client_impl.hpp rename to src/mtconnect/mqtt/mqtt_client_impl.hpp index c895211cb..64a3a99a5 100644 --- a/src/mqtt/mqtt_client_impl.hpp +++ b/src/mtconnect/mqtt/mqtt_client_impl.hpp @@ -24,10 +24,10 @@ #include #include -#include "configuration/config_options.hpp" #include "mqtt_client.hpp" -#include "source/adapter/adapter.hpp" -#include "source/adapter/mqtt/mqtt_adapter.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/mqtt/mqtt_adapter.hpp" using namespace std; namespace asio = boost::asio; @@ -134,7 +134,7 @@ namespace mtconnect { else { LOG(debug) << "No connect handler, setting connected"; - m_connected = true; + m_connected = true; } } else @@ -341,7 +341,7 @@ namespace mtconnect { boost::asio::steady_timer m_reconnectTimer; }; - class MqttTcpClient : public MqttClientImpl + class AGENT_LIB_API MqttTcpClient : public MqttClientImpl { public: using base = MqttClientImpl; @@ -425,7 +425,7 @@ namespace mtconnect { if (cacert) { m_client->get_ssl_context().load_verify_file(*cacert); - } + } } return m_client; diff --git a/src/mqtt/mqtt_server.hpp b/src/mtconnect/mqtt/mqtt_server.hpp similarity index 90% rename from src/mqtt/mqtt_server.hpp rename to src/mtconnect/mqtt/mqtt_server.hpp index 7708ecffe..95231374b 100644 --- a/src/mqtt/mqtt_server.hpp +++ b/src/mtconnect/mqtt/mqtt_server.hpp @@ -13,8 +13,9 @@ #pragma once -#include "source/adapter/adapter.hpp" -#include "source/adapter/adapter_pipeline.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/adapter_pipeline.hpp" namespace mtconnect { namespace mqtt_server { diff --git a/src/mqtt/mqtt_server_impl.hpp b/src/mtconnect/mqtt/mqtt_server_impl.hpp similarity index 98% rename from src/mqtt/mqtt_server_impl.hpp rename to src/mtconnect/mqtt/mqtt_server_impl.hpp index eba69851f..01afabd4e 100644 --- a/src/mqtt/mqtt_server_impl.hpp +++ b/src/mtconnect/mqtt/mqtt_server_impl.hpp @@ -27,10 +27,10 @@ #include #include -#include "configuration/config_options.hpp" #include "mqtt_server.hpp" -#include "source/adapter/adapter.hpp" -#include "source/adapter/mqtt/mqtt_adapter.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/mqtt/mqtt_adapter.hpp" using namespace std; namespace asio = boost::asio; @@ -302,7 +302,7 @@ namespace mtconnect { boost::asio::ssl::context::single_dh_use); if (HasOption(m_options, configuration::TlsCertificateChain) && - HasOption(m_options, configuration::TlsPrivateKey) && + HasOption(m_options, configuration::TlsPrivateKey) && HasOption(m_options, configuration::TlsDHKey)) { LOG(info) << "Server: Initializing TLS support"; @@ -317,7 +317,7 @@ namespace mtconnect { auto serverPrivateKey = GetOption(m_options, configuration::TlsPrivateKey); auto serverCert = GetOption(m_options, configuration::TlsCertificateChain); auto serverDHKey = GetOption(m_options, configuration::TlsDHKey); - + ctx.use_certificate_chain_file(*serverCert); ctx.use_private_key_file(*serverPrivateKey, boost::asio::ssl::context::pem); ctx.use_tmp_dh_file(*serverDHKey); diff --git a/src/observation/change_observer.cpp b/src/mtconnect/observation/change_observer.cpp similarity index 100% rename from src/observation/change_observer.cpp rename to src/mtconnect/observation/change_observer.cpp diff --git a/src/observation/change_observer.hpp b/src/mtconnect/observation/change_observer.hpp similarity index 95% rename from src/observation/change_observer.hpp rename to src/mtconnect/observation/change_observer.hpp index 63eb7d633..fbb4c383c 100644 --- a/src/observation/change_observer.hpp +++ b/src/mtconnect/observation/change_observer.hpp @@ -24,12 +24,13 @@ #include #include -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace observation { class ChangeSignaler; - class ChangeObserver + class AGENT_LIB_API ChangeObserver { public: ChangeObserver(boost::asio::io_context::strand &strand) @@ -90,7 +91,7 @@ namespace mtconnect { bool removeSignaler(ChangeSignaler *sig); }; - class ChangeSignaler + class AGENT_LIB_API ChangeSignaler { public: // Observer Management diff --git a/src/observation/observation.cpp b/src/mtconnect/observation/observation.cpp similarity index 99% rename from src/observation/observation.cpp rename to src/mtconnect/observation/observation.cpp index d5fcd722b..c97584094 100644 --- a/src/observation/observation.cpp +++ b/src/mtconnect/observation/observation.cpp @@ -20,9 +20,9 @@ #include #include -#include "device_model/data_item/data_item.hpp" -#include "entity/factory.hpp" -#include "logging.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/logging.hpp" #ifdef _WINDOWS #define strcasecmp stricmp diff --git a/src/observation/observation.hpp b/src/mtconnect/observation/observation.hpp similarity index 92% rename from src/observation/observation.hpp rename to src/mtconnect/observation/observation.hpp index fafe1f954..b730e94ad 100644 --- a/src/observation/observation.hpp +++ b/src/mtconnect/observation/observation.hpp @@ -25,10 +25,11 @@ #include #include -#include "device_model/component.hpp" -#include "device_model/data_item/data_item.hpp" -#include "entity/entity.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/component.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace observation { @@ -40,7 +41,7 @@ namespace mtconnect { using ObservationPtr = std::shared_ptr; using ObservationList = std::list; - class Observation : public entity::Entity + class AGENT_LIB_API Observation : public entity::Entity { public: using super = entity::Entity; @@ -148,7 +149,7 @@ namespace mtconnect { uint64_t m_sequence {0}; }; - class Sample : public Observation + class AGENT_LIB_API Sample : public Observation { public: using super = Observation; @@ -160,7 +161,7 @@ namespace mtconnect { ObservationPtr copy() const override { return std::make_shared(*this); } }; - class ThreeSpaceSample : public Sample + class AGENT_LIB_API ThreeSpaceSample : public Sample { public: using super = Sample; @@ -170,7 +171,7 @@ namespace mtconnect { ~ThreeSpaceSample() override = default; }; - class Timeseries : public Sample + class AGENT_LIB_API Timeseries : public Sample { public: using super = Sample; @@ -186,7 +187,7 @@ namespace mtconnect { using ConditionPtr = std::shared_ptr; using ConditionList = std::list; - class Condition : public Observation + class AGENT_LIB_API Condition : public Observation { public: using super = Observation; @@ -309,7 +310,7 @@ namespace mtconnect { ConditionPtr m_prev; }; - class Event : public Observation + class AGENT_LIB_API Event : public Observation { public: using super = Observation; @@ -320,7 +321,7 @@ namespace mtconnect { ObservationPtr copy() const override { return std::make_shared(*this); } }; - class DoubleEvent : public Observation + class AGENT_LIB_API DoubleEvent : public Observation { public: using super = Observation; @@ -331,7 +332,7 @@ namespace mtconnect { ObservationPtr copy() const override { return std::make_shared(*this); } }; - class IntEvent : public Observation + class AGENT_LIB_API IntEvent : public Observation { public: using super = Observation; @@ -342,7 +343,7 @@ namespace mtconnect { ObservationPtr copy() const override { return std::make_shared(*this); } }; - class DataSetEvent : public Event + class AGENT_LIB_API DataSetEvent : public Event { public: using super = Event; @@ -372,7 +373,7 @@ namespace mtconnect { using DataSetEventPtr = std::shared_ptr; - class TableEvent : public DataSetEvent + class AGENT_LIB_API TableEvent : public DataSetEvent { public: using DataSetEvent::DataSetEvent; @@ -380,7 +381,7 @@ namespace mtconnect { ObservationPtr copy() const override { return std::make_shared(*this); } }; - class AssetEvent : public Event + class AGENT_LIB_API AssetEvent : public Event { public: using Event::Event; @@ -391,7 +392,7 @@ namespace mtconnect { protected: }; - class Message : public Event + class AGENT_LIB_API Message : public Event { public: using super = Event; @@ -402,7 +403,7 @@ namespace mtconnect { ObservationPtr copy() const override { return std::make_shared(*this); } }; - class Alarm : public Event + class AGENT_LIB_API Alarm : public Event { public: using super = Event; diff --git a/src/parser/xml_parser.cpp b/src/mtconnect/parser/xml_parser.cpp similarity index 98% rename from src/parser/xml_parser.cpp rename to src/mtconnect/parser/xml_parser.cpp index 773bbb5e2..b45e60bda 100644 --- a/src/parser/xml_parser.cpp +++ b/src/mtconnect/parser/xml_parser.cpp @@ -32,11 +32,11 @@ #include #include -#include "asset/cutting_tool.hpp" -#include "device_model/composition.hpp" -#include "entity/xml_parser.hpp" -#include "logging.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/asset/cutting_tool.hpp" +#include "mtconnect/device_model/composition.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/printer/xml_printer.hpp" #if _MSC_VER >= 1900 #define gets gets_s diff --git a/src/parser/xml_parser.hpp b/src/mtconnect/parser/xml_parser.hpp similarity index 83% rename from src/parser/xml_parser.hpp rename to src/mtconnect/parser/xml_parser.hpp index 932052caa..5c0edcf68 100644 --- a/src/parser/xml_parser.hpp +++ b/src/mtconnect/parser/xml_parser.hpp @@ -23,19 +23,20 @@ #include -#include "asset/cutting_tool.hpp" -#include "buffer/checkpoint.hpp" -#include "device_model/component.hpp" -#include "device_model/data_item/data_item.hpp" -#include "device_model/device.hpp" -#include "utilities.hpp" +#include "mtconnect/asset/cutting_tool.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/component.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::printer { class XmlPrinter; } namespace mtconnect::parser { - class XmlParser + class AGENT_LIB_API XmlParser { public: // Constructor to set the open the correct file diff --git a/src/pipeline/convert_sample.hpp b/src/mtconnect/pipeline/convert_sample.hpp similarity index 90% rename from src/pipeline/convert_sample.hpp rename to src/mtconnect/pipeline/convert_sample.hpp index b5ebb61b2..4c920575a 100644 --- a/src/pipeline/convert_sample.hpp +++ b/src/mtconnect/pipeline/convert_sample.hpp @@ -17,13 +17,14 @@ #pragma once -#include "asset/asset.hpp" -#include "observation/observation.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/observation/observation.hpp" #include "transform.hpp" namespace mtconnect { namespace pipeline { - class ConvertSample : public Transform + class AGENT_LIB_API ConvertSample : public Transform { public: ConvertSample() : Transform("ConvertSample") diff --git a/src/pipeline/deliver.cpp b/src/mtconnect/pipeline/deliver.cpp similarity index 96% rename from src/pipeline/deliver.cpp rename to src/mtconnect/pipeline/deliver.cpp index cbf4a27bc..02ce087b7 100644 --- a/src/pipeline/deliver.cpp +++ b/src/mtconnect/pipeline/deliver.cpp @@ -23,10 +23,10 @@ #include -#include "agent.hpp" -#include "asset/cutting_tool.hpp" -#include "asset/file_asset.hpp" -#include "logging.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/asset/cutting_tool.hpp" +#include "mtconnect/asset/file_asset.hpp" +#include "mtconnect/logging.hpp" using namespace std::literals::chrono_literals; diff --git a/src/pipeline/deliver.hpp b/src/mtconnect/pipeline/deliver.hpp similarity index 91% rename from src/pipeline/deliver.hpp rename to src/mtconnect/pipeline/deliver.hpp index 8c2139a42..4724e2985 100644 --- a/src/pipeline/deliver.hpp +++ b/src/mtconnect/pipeline/deliver.hpp @@ -21,8 +21,9 @@ #include -#include "asset/asset.hpp" -#include "observation/observation.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/observation/observation.hpp" #include "transform.hpp" namespace mtconnect { @@ -63,7 +64,7 @@ namespace mtconnect { double m_lastAvg {0.0}; }; - class MeteredTransform : public Transform + class AGENT_LIB_API MeteredTransform : public Transform { public: MeteredTransform(const std::string &name, PipelineContextPtr context, @@ -107,7 +108,7 @@ namespace mtconnect { std::optional m_dataItem; }; - class DeliverObservation : public MeteredTransform + class AGENT_LIB_API DeliverObservation : public MeteredTransform { public: using Deliver = std::function; @@ -120,7 +121,7 @@ namespace mtconnect { const entity::EntityPtr operator()(const entity::EntityPtr entity) override; }; - class DeliverAsset : public MeteredTransform + class AGENT_LIB_API DeliverAsset : public MeteredTransform { public: using Deliver = std::function; @@ -133,7 +134,7 @@ namespace mtconnect { const entity::EntityPtr operator()(const entity::EntityPtr entity) override; }; - class DeliverConnectionStatus : public Transform + class AGENT_LIB_API DeliverConnectionStatus : public Transform { public: using Deliver = std::function; @@ -154,7 +155,7 @@ namespace mtconnect { bool m_autoAvailable; }; - class DeliverAssetCommand : public Transform + class AGENT_LIB_API DeliverAssetCommand : public Transform { public: using Deliver = std::function; @@ -169,7 +170,7 @@ namespace mtconnect { PipelineContract *m_contract; }; - class DeliverCommand : public Transform + class AGENT_LIB_API DeliverCommand : public Transform { public: using Deliver = std::function; diff --git a/src/pipeline/delta_filter.hpp b/src/mtconnect/pipeline/delta_filter.hpp similarity index 95% rename from src/pipeline/delta_filter.hpp rename to src/mtconnect/pipeline/delta_filter.hpp index 513cebca3..860e9d96e 100644 --- a/src/pipeline/delta_filter.hpp +++ b/src/mtconnect/pipeline/delta_filter.hpp @@ -17,13 +17,14 @@ #pragma once -#include "observation/observation.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/observation/observation.hpp" #include "transform.hpp" namespace mtconnect { class Agent; namespace pipeline { - class DeltaFilter : public Transform + class AGENT_LIB_API DeltaFilter : public Transform { public: struct State : TransformState diff --git a/src/pipeline/duplicate_filter.hpp b/src/mtconnect/pipeline/duplicate_filter.hpp similarity index 96% rename from src/pipeline/duplicate_filter.hpp rename to src/mtconnect/pipeline/duplicate_filter.hpp index adfe05793..f2f01fb96 100644 --- a/src/pipeline/duplicate_filter.hpp +++ b/src/mtconnect/pipeline/duplicate_filter.hpp @@ -17,11 +17,12 @@ #pragma once +#include "mtconnect/config.hpp" #include "transform.hpp" namespace mtconnect { namespace pipeline { - class DuplicateFilter : public Transform + class AGENT_LIB_API DuplicateFilter : public Transform { public: struct State : TransformState diff --git a/src/pipeline/guard.hpp b/src/mtconnect/pipeline/guard.hpp similarity index 96% rename from src/pipeline/guard.hpp rename to src/mtconnect/pipeline/guard.hpp index f6bf5a9e1..a5595523b 100644 --- a/src/pipeline/guard.hpp +++ b/src/mtconnect/pipeline/guard.hpp @@ -17,7 +17,8 @@ #pragma once -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" namespace mtconnect { namespace pipeline { @@ -55,6 +56,12 @@ namespace mtconnect { return *this; } + auto &operator||(GuardAction other) + { + m_alternative = GuardCls(other); + return *this; + } + protected: Guard m_alternative; GuardAction m_match; diff --git a/src/pipeline/message_mapper.hpp b/src/mtconnect/pipeline/message_mapper.hpp similarity index 92% rename from src/pipeline/message_mapper.hpp rename to src/mtconnect/pipeline/message_mapper.hpp index b3dc27f80..b5b4fddb7 100644 --- a/src/pipeline/message_mapper.hpp +++ b/src/mtconnect/pipeline/message_mapper.hpp @@ -24,9 +24,10 @@ #include -#include "device_model/device.hpp" -#include "entity/entity.hpp" -#include "observation/observation.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/observation/observation.hpp" #include "shdr_tokenizer.hpp" #include "timestamp_extractor.hpp" #include "topic_mapper.hpp" @@ -36,7 +37,7 @@ namespace mtconnect { class Device; namespace pipeline { - class JsonMapper : public Transform + class AGENT_LIB_API JsonMapper : public Transform { public: JsonMapper(const JsonMapper &) = default; @@ -56,7 +57,7 @@ namespace mtconnect { PipelineContextPtr m_context; }; - class DataMapper : public Transform + class AGENT_LIB_API DataMapper : public Transform { public: DataMapper(const DataMapper &) = default; diff --git a/src/pipeline/mtconnect_xml_transform.hpp b/src/mtconnect/pipeline/mtconnect_xml_transform.hpp similarity index 91% rename from src/pipeline/mtconnect_xml_transform.hpp rename to src/mtconnect/pipeline/mtconnect_xml_transform.hpp index a8aa4172c..0eb6d436a 100644 --- a/src/pipeline/mtconnect_xml_transform.hpp +++ b/src/mtconnect/pipeline/mtconnect_xml_transform.hpp @@ -19,11 +19,12 @@ #include #include -#include "entity/entity.hpp" -#include "observation/observation.hpp" -#include "pipeline/transform.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/transform.hpp" +#include "mtconnect/source/error_code.hpp" #include "response_document.hpp" -#include "source/error_code.hpp" namespace mtconnect::pipeline { struct XmlTransformFeedback @@ -35,7 +36,7 @@ namespace mtconnect::pipeline { }; using namespace mtconnect::entity; - class MTConnectXmlTransform : public Transform + class AGENT_LIB_API MTConnectXmlTransform : public Transform { public: MTConnectXmlTransform(const MTConnectXmlTransform &) = default; diff --git a/src/pipeline/period_filter.hpp b/src/mtconnect/pipeline/period_filter.hpp similarity index 95% rename from src/pipeline/period_filter.hpp rename to src/mtconnect/pipeline/period_filter.hpp index 5277184e8..0b9acf0e3 100644 --- a/src/pipeline/period_filter.hpp +++ b/src/mtconnect/pipeline/period_filter.hpp @@ -17,13 +17,14 @@ #pragma once -#include "observation/observation.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/observation/observation.hpp" #include "transform.hpp" namespace mtconnect { class Agent; namespace pipeline { - class PeriodFilter : public Transform + class AGENT_LIB_API PeriodFilter : public Transform { public: struct LastObservation @@ -195,8 +196,10 @@ namespace mtconnect { // Bind the strand so we do not have races. Use the data item id so there are // no race conditions due to LastObservation lifecycle. - last.m_timer.async_wait(boost::asio::bind_executor( - m_strand, boost::bind(&PeriodFilter::sendObservation, this, id, _1))); + last.m_timer.async_wait([this, id](boost::system::error_code ec) { + boost::asio::dispatch(m_strand, + boost::bind(&PeriodFilter::sendObservation, this, id, ec)); + }); } void sendObservation(const std::string id, boost::system::error_code ec) diff --git a/src/pipeline/pipeline.hpp b/src/mtconnect/pipeline/pipeline.hpp similarity index 98% rename from src/pipeline/pipeline.hpp rename to src/mtconnect/pipeline/pipeline.hpp index 6a67ee2e7..64b8fd394 100644 --- a/src/pipeline/pipeline.hpp +++ b/src/mtconnect/pipeline/pipeline.hpp @@ -19,6 +19,7 @@ #include +#include "mtconnect/config.hpp" #include "pipeline_context.hpp" #include "pipeline_contract.hpp" #include "transform.hpp" @@ -37,7 +38,7 @@ namespace mtconnect { class Adapter; } // namespace source::adapter namespace pipeline { - class Pipeline + class AGENT_LIB_API Pipeline { public: using Splice = std::function; @@ -236,7 +237,7 @@ namespace mtconnect { const auto &getContract() { return m_context->m_contract; } protected: - class Start : public Transform + class AGENT_LIB_API Start : public Transform { public: Start() : Transform("Start") diff --git a/src/pipeline/pipeline_context.hpp b/src/mtconnect/pipeline/pipeline_context.hpp similarity index 93% rename from src/pipeline/pipeline_context.hpp rename to src/mtconnect/pipeline/pipeline_context.hpp index df58df515..63b1fdcd6 100644 --- a/src/pipeline/pipeline_context.hpp +++ b/src/mtconnect/pipeline/pipeline_context.hpp @@ -21,6 +21,7 @@ #include #include +#include "mtconnect/config.hpp" #include "pipeline_contract.hpp" namespace mtconnect { @@ -37,7 +38,7 @@ namespace mtconnect { }; using TransformStatePtr = std::shared_ptr; - class PipelineContext : public std::enable_shared_from_this + class AGENT_LIB_API PipelineContext : public std::enable_shared_from_this { public: auto getptr() { return shared_from_this(); } diff --git a/src/pipeline/pipeline_contract.hpp b/src/mtconnect/pipeline/pipeline_contract.hpp similarity index 97% rename from src/pipeline/pipeline_contract.hpp rename to src/mtconnect/pipeline/pipeline_contract.hpp index bc4981f97..51f824488 100644 --- a/src/pipeline/pipeline_contract.hpp +++ b/src/mtconnect/pipeline/pipeline_contract.hpp @@ -21,6 +21,8 @@ #include #include +#include "mtconnect/config.hpp" + namespace mtconnect { namespace device_model { namespace data_item { @@ -46,7 +48,7 @@ namespace mtconnect { } // namespace entity namespace pipeline { - class PipelineContract + class AGENT_LIB_API PipelineContract { public: PipelineContract() = default; diff --git a/src/pipeline/response_document.cpp b/src/mtconnect/pipeline/response_document.cpp similarity index 97% rename from src/pipeline/response_document.cpp rename to src/mtconnect/pipeline/response_document.cpp index 3fb7ca56b..b9c793679 100644 --- a/src/pipeline/response_document.cpp +++ b/src/mtconnect/pipeline/response_document.cpp @@ -23,12 +23,12 @@ #include #include -#include "asset/asset.hpp" -#include "device_model/device.hpp" -#include "entity/data_set.hpp" -#include "entity/xml_parser.hpp" -#include "observation/observation.hpp" -#include "pipeline/timestamp_extractor.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/entity/data_set.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" using namespace std; diff --git a/src/pipeline/response_document.hpp b/src/mtconnect/pipeline/response_document.hpp similarity index 84% rename from src/pipeline/response_document.hpp rename to src/mtconnect/pipeline/response_document.hpp index f97b26572..50471ffb3 100644 --- a/src/pipeline/response_document.hpp +++ b/src/mtconnect/pipeline/response_document.hpp @@ -17,15 +17,16 @@ #pragma once -#include "entity/entity.hpp" -#include "pipeline/pipeline_context.hpp" -#include "printer/xml_helper.hpp" -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/pipeline/pipeline_context.hpp" +#include "mtconnect/printer/xml_helper.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::pipeline { using namespace mtconnect; - struct ResponseDocument + struct AGENT_LIB_API ResponseDocument { struct Error { diff --git a/src/pipeline/shdr_token_mapper.cpp b/src/mtconnect/pipeline/shdr_token_mapper.cpp similarity index 98% rename from src/pipeline/shdr_token_mapper.cpp rename to src/mtconnect/pipeline/shdr_token_mapper.cpp index 57c2387d8..3c878d437 100644 --- a/src/pipeline/shdr_token_mapper.cpp +++ b/src/mtconnect/pipeline/shdr_token_mapper.cpp @@ -17,12 +17,12 @@ #include "shdr_token_mapper.hpp" -#include "asset/asset.hpp" -#include "device_model/device.hpp" -#include "entity/factory.hpp" -#include "entity/xml_parser.hpp" -#include "logging.hpp" -#include "observation/observation.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/observation/observation.hpp" #include "upcase_value.hpp" using namespace std; diff --git a/src/pipeline/shdr_token_mapper.hpp b/src/mtconnect/pipeline/shdr_token_mapper.hpp similarity index 88% rename from src/pipeline/shdr_token_mapper.hpp rename to src/mtconnect/pipeline/shdr_token_mapper.hpp index fe469d925..579c58a29 100644 --- a/src/pipeline/shdr_token_mapper.hpp +++ b/src/mtconnect/pipeline/shdr_token_mapper.hpp @@ -19,8 +19,9 @@ #include #include -#include "entity/entity.hpp" -#include "observation/observation.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/observation/observation.hpp" #include "shdr_tokenizer.hpp" #include "timestamp_extractor.hpp" #include "transform.hpp" @@ -30,7 +31,13 @@ namespace mtconnect { namespace pipeline { using namespace entity; - class ShdrTokenMapper : public Transform + class AGENT_LIB_API Observations : public Timestamped + { + public: + using Timestamped::Timestamped; + }; + + class AGENT_LIB_API ShdrTokenMapper : public Transform { public: ShdrTokenMapper(const ShdrTokenMapper &) = default; diff --git a/src/pipeline/shdr_tokenizer.hpp b/src/mtconnect/pipeline/shdr_tokenizer.hpp similarity index 96% rename from src/pipeline/shdr_tokenizer.hpp rename to src/mtconnect/pipeline/shdr_tokenizer.hpp index 9a1033f15..7e09090ec 100644 --- a/src/pipeline/shdr_tokenizer.hpp +++ b/src/mtconnect/pipeline/shdr_tokenizer.hpp @@ -20,7 +20,8 @@ #include #include -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" #include "transform.hpp" namespace mtconnect { @@ -28,7 +29,7 @@ namespace mtconnect { namespace pipeline { using TokenList = std::list; - class Tokens : public entity::Entity + class AGENT_LIB_API Tokens : public entity::Entity { public: using entity::Entity::Entity; @@ -39,7 +40,7 @@ namespace mtconnect { TokenList m_tokens; }; - class ShdrTokenizer : public Transform + class AGENT_LIB_API ShdrTokenizer : public Transform { public: ShdrTokenizer(const ShdrTokenizer &) = default; diff --git a/src/pipeline/timestamp_extractor.cpp b/src/mtconnect/pipeline/timestamp_extractor.cpp similarity index 98% rename from src/pipeline/timestamp_extractor.cpp rename to src/mtconnect/pipeline/timestamp_extractor.cpp index 27641dc16..7ca5da872 100644 --- a/src/pipeline/timestamp_extractor.cpp +++ b/src/mtconnect/pipeline/timestamp_extractor.cpp @@ -20,7 +20,7 @@ #include #include -#include "logging.hpp" +#include "mtconnect/logging.hpp" using namespace std; diff --git a/src/pipeline/timestamp_extractor.hpp b/src/mtconnect/pipeline/timestamp_extractor.hpp similarity index 92% rename from src/pipeline/timestamp_extractor.hpp rename to src/mtconnect/pipeline/timestamp_extractor.hpp index d96badb36..406b59007 100644 --- a/src/pipeline/timestamp_extractor.hpp +++ b/src/mtconnect/pipeline/timestamp_extractor.hpp @@ -17,9 +17,10 @@ #pragma once +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" #include "shdr_tokenizer.hpp" #include "transform.hpp" -#include "utilities.hpp" namespace mtconnect { class Agent; @@ -27,7 +28,7 @@ namespace mtconnect { namespace pipeline { using namespace entity; - class Timestamped : public Tokens + class AGENT_LIB_API Timestamped : public Tokens { public: using Tokens::Tokens; @@ -42,19 +43,13 @@ namespace mtconnect { }; using TimestampedPtr = std::shared_ptr; - class AssetCommand : public Timestamped + class AGENT_LIB_API AssetCommand : public Timestamped { public: using Timestamped::Timestamped; }; - class Observations : public Timestamped - { - public: - using Timestamped::Timestamped; - }; - - class ExtractTimestamp : public Transform + class AGENT_LIB_API ExtractTimestamp : public Transform { public: ExtractTimestamp(const ExtractTimestamp &) = default; @@ -104,7 +99,7 @@ namespace mtconnect { Microseconds m_offset; }; - class IgnoreTimestamp : public ExtractTimestamp + class AGENT_LIB_API IgnoreTimestamp : public ExtractTimestamp { public: IgnoreTimestamp() : ExtractTimestamp("IgnoreTimestamp") {} diff --git a/src/pipeline/topic_mapper.hpp b/src/mtconnect/pipeline/topic_mapper.hpp similarity index 92% rename from src/pipeline/topic_mapper.hpp rename to src/mtconnect/pipeline/topic_mapper.hpp index a5a8bb05a..a0d5c70ef 100644 --- a/src/pipeline/topic_mapper.hpp +++ b/src/mtconnect/pipeline/topic_mapper.hpp @@ -22,16 +22,17 @@ #include #include -#include "device_model/device.hpp" -#include "entity/entity.hpp" -#include "observation/observation.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/observation/observation.hpp" #include "shdr_tokenizer.hpp" #include "timestamp_extractor.hpp" #include "transform.hpp" namespace mtconnect { namespace pipeline { - class PipelineMessage : public Entity + class AGENT_LIB_API PipelineMessage : public Entity { public: using Entity::Entity; @@ -42,18 +43,18 @@ namespace mtconnect { }; using PipelineMessagePtr = std::shared_ptr; - class JsonMessage : public PipelineMessage + class AGENT_LIB_API JsonMessage : public PipelineMessage { public: using PipelineMessage::PipelineMessage; }; - class DataMessage : public PipelineMessage + class AGENT_LIB_API DataMessage : public PipelineMessage { public: using PipelineMessage::PipelineMessage; }; - class TopicMapper : public Transform + class AGENT_LIB_API TopicMapper : public Transform { public: TopicMapper(const TopicMapper &) = default; diff --git a/src/pipeline/transform.hpp b/src/mtconnect/pipeline/transform.hpp similarity index 96% rename from src/pipeline/transform.hpp rename to src/mtconnect/pipeline/transform.hpp index 247e1112d..a5c0aba0c 100644 --- a/src/pipeline/transform.hpp +++ b/src/mtconnect/pipeline/transform.hpp @@ -20,8 +20,9 @@ #include #include -#include "entity/entity.hpp" #include "guard.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" #include "pipeline_context.hpp" namespace mtconnect { @@ -46,7 +47,7 @@ namespace mtconnect { using EachDataItem = std::function; using FindDataItem = std::function; - class Transform : public std::enable_shared_from_this + class AGENT_LIB_API Transform : public std::enable_shared_from_this { public: Transform(const Transform &) = default; @@ -211,7 +212,7 @@ namespace mtconnect { Guard m_guard; }; - class NullTransform : public Transform + class AGENT_LIB_API NullTransform : public Transform { public: NullTransform(Guard guard) : Transform("NullTransform") { m_guard = guard; } diff --git a/src/pipeline/upcase_value.hpp b/src/mtconnect/pipeline/upcase_value.hpp similarity index 91% rename from src/pipeline/upcase_value.hpp rename to src/mtconnect/pipeline/upcase_value.hpp index 9c6f0666c..baa7cb36f 100644 --- a/src/pipeline/upcase_value.hpp +++ b/src/mtconnect/pipeline/upcase_value.hpp @@ -19,8 +19,9 @@ #include #include -#include "entity/entity.hpp" -#include "observation/observation.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/observation/observation.hpp" #include "shdr_tokenizer.hpp" #include "timestamp_extractor.hpp" #include "transform.hpp" @@ -36,7 +37,7 @@ namespace mtconnect { return s; } - class UpcaseValue : public Transform + class AGENT_LIB_API UpcaseValue : public Transform { public: UpcaseValue(const UpcaseValue &) = default; diff --git a/src/printer/json_printer.cpp b/src/mtconnect/printer/json_printer.cpp similarity index 97% rename from src/printer/json_printer.cpp rename to src/mtconnect/printer/json_printer.cpp index 86af54bc1..67bfe4ace 100644 --- a/src/printer/json_printer.cpp +++ b/src/mtconnect/printer/json_printer.cpp @@ -25,13 +25,13 @@ #include -#include "device_model/composition.hpp" -#include "device_model/configuration/configuration.hpp" -#include "device_model/device.hpp" -#include "device_model/reference.hpp" -#include "entity/json_printer.hpp" -#include "logging.hpp" -#include "version.h" +#include "mtconnect/device_model/composition.hpp" +#include "mtconnect/device_model/configuration/configuration.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/device_model/reference.hpp" +#include "mtconnect/entity/json_printer.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/version.h" using namespace std; using json = nlohmann::json; @@ -200,7 +200,7 @@ namespace mtconnect::printer { return print(doc, m_pretty); } - class CategoryRef + class AGENT_LIB_API CategoryRef { public: CategoryRef(const char *cat, uint32_t version) : m_category(cat), m_version(version) {} @@ -244,7 +244,7 @@ namespace mtconnect::printer { uint32_t m_version; }; - class ComponentRef + class AGENT_LIB_API ComponentRef { public: ComponentRef(const ComponentPtr component, uint32_t version) @@ -307,7 +307,7 @@ namespace mtconnect::printer { uint32_t m_version; }; - class DeviceRef + class AGENT_LIB_API DeviceRef { public: DeviceRef(const DevicePtr device, uint32_t version) : m_device(device), m_version(version) {} diff --git a/src/printer/json_printer.hpp b/src/mtconnect/printer/json_printer.hpp similarity index 91% rename from src/printer/json_printer.hpp rename to src/mtconnect/printer/json_printer.hpp index 759d9cbe4..2179715c0 100644 --- a/src/printer/json_printer.hpp +++ b/src/mtconnect/printer/json_printer.hpp @@ -17,12 +17,13 @@ #pragma once -#include "asset/cutting_tool.hpp" -#include "printer/printer.hpp" -#include "utilities.hpp" +#include "mtconnect/asset/cutting_tool.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/printer/printer.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::printer { - class JsonPrinter : public Printer + class AGENT_LIB_API JsonPrinter : public Printer { public: JsonPrinter(uint32_t jsonVersion, bool pretty = false); diff --git a/src/printer/printer.hpp b/src/mtconnect/printer/printer.hpp similarity index 94% rename from src/printer/printer.hpp rename to src/mtconnect/printer/printer.hpp index e658029d8..aeb1929b3 100644 --- a/src/printer/printer.hpp +++ b/src/mtconnect/printer/printer.hpp @@ -22,10 +22,11 @@ #include #include -#include "asset/asset.hpp" -#include "observation/observation.hpp" -#include "utilities.hpp" -#include "version.h" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/utilities.hpp" +#include "mtconnect/version.h" namespace mtconnect { namespace device_model { @@ -41,7 +42,7 @@ namespace mtconnect { using ProtoErrorList = std::list>; - class Printer + class AGENT_LIB_API Printer { public: Printer(bool pretty = false) : m_pretty(pretty) {} diff --git a/src/printer/xml_helper.hpp b/src/mtconnect/printer/xml_helper.hpp similarity index 94% rename from src/printer/xml_helper.hpp rename to src/mtconnect/printer/xml_helper.hpp index 089b5ae71..8f3de51e6 100644 --- a/src/printer/xml_helper.hpp +++ b/src/mtconnect/printer/xml_helper.hpp @@ -19,6 +19,8 @@ #include +#include "mtconnect/config.hpp" + #define xml_strfy(line) #line #define THROW_IF_XML2_ERROR(expr) \ if ((expr) < 0) \ @@ -32,7 +34,7 @@ } namespace mtconnect::printer { - class XmlError : public std::logic_error + class AGENT_LIB_API XmlError : public std::logic_error { public: using std::logic_error::logic_error; diff --git a/src/printer/xml_printer.cpp b/src/mtconnect/printer/xml_printer.cpp similarity index 97% rename from src/printer/xml_printer.cpp rename to src/mtconnect/printer/xml_printer.cpp index 5dfaf2672..ec0ffea58 100644 --- a/src/printer/xml_printer.cpp +++ b/src/mtconnect/printer/xml_printer.cpp @@ -15,7 +15,7 @@ // limitations under the License. // -#include "entity/xml_printer.hpp" +#include "mtconnect/entity/xml_printer.hpp" #include @@ -26,13 +26,13 @@ #include -#include "asset/asset.hpp" -#include "asset/cutting_tool.hpp" -#include "device_model/composition.hpp" -#include "device_model/configuration/configuration.hpp" -#include "device_model/device.hpp" -#include "logging.hpp" -#include "version.h" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/asset/cutting_tool.hpp" +#include "mtconnect/device_model/composition.hpp" +#include "mtconnect/device_model/configuration/configuration.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/version.h" #include "xml_printer.hpp" #define strfy(line) #line @@ -54,7 +54,7 @@ namespace mtconnect::printer { using namespace asset; using namespace device_model::configuration; - class XmlWriter + class AGENT_LIB_API XmlWriter { public: XmlWriter(bool pretty) : m_writer(nullptr), m_buf(nullptr) @@ -272,7 +272,7 @@ namespace mtconnect::printer { THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); } - class AutoElement + class AGENT_LIB_API AutoElement { public: AutoElement(xmlTextWriterPtr writer) : m_writer(writer) {} diff --git a/src/printer/xml_printer.hpp b/src/mtconnect/printer/xml_printer.hpp similarity index 96% rename from src/printer/xml_printer.hpp rename to src/mtconnect/printer/xml_printer.hpp index 4f6a21eda..50cfacc3f 100644 --- a/src/printer/xml_printer.hpp +++ b/src/mtconnect/printer/xml_printer.hpp @@ -19,9 +19,10 @@ #include -#include "asset/asset.hpp" -#include "printer/printer.hpp" -#include "utilities.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/printer/printer.hpp" +#include "mtconnect/utilities.hpp" extern "C" { @@ -35,7 +36,7 @@ namespace mtconnect { namespace printer { class XmlWriter; - class XmlPrinter : public Printer + class AGENT_LIB_API XmlPrinter : public Printer { public: XmlPrinter(bool pretty = false); diff --git a/src/printer/xml_printer_helper.hpp b/src/mtconnect/printer/xml_printer_helper.hpp similarity index 95% rename from src/printer/xml_printer_helper.hpp rename to src/mtconnect/printer/xml_printer_helper.hpp index 598a08d1f..826c8032f 100644 --- a/src/printer/xml_printer_helper.hpp +++ b/src/mtconnect/printer/xml_printer_helper.hpp @@ -19,10 +19,11 @@ #include -#include "printer/xml_helper.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/printer/xml_helper.hpp" namespace mtconnect::printer { - class XmlWriter + class AGENT_LIB_API XmlWriter { public: XmlWriter(bool pretty) : m_writer(nullptr), m_buf(nullptr) @@ -78,7 +79,7 @@ namespace mtconnect::printer { THROW_IF_XML2_ERROR(xmlTextWriterEndElement(writer)); } - class AutoElement + class AGENT_LIB_API AutoElement { public: AutoElement(xmlTextWriterPtr writer) : m_writer(writer) {} diff --git a/src/python/embedded.cpp b/src/mtconnect/python/embedded.cpp similarity index 100% rename from src/python/embedded.cpp rename to src/mtconnect/python/embedded.cpp diff --git a/src/python/embedded.hpp b/src/mtconnect/python/embedded.hpp similarity index 100% rename from src/python/embedded.hpp rename to src/mtconnect/python/embedded.hpp diff --git a/src/ruby/embedded.cpp b/src/mtconnect/ruby/embedded.cpp similarity index 95% rename from src/ruby/embedded.cpp rename to src/mtconnect/ruby/embedded.cpp index a0e281388..31b3e2352 100644 --- a/src/ruby/embedded.cpp +++ b/src/mtconnect/ruby/embedded.cpp @@ -24,12 +24,12 @@ #include #include -#include "agent.hpp" -#include "entity/data_set.hpp" -#include "entity/entity.hpp" -#include "logging.hpp" -#include "pipeline/pipeline.hpp" -#include "utilities.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/entity/data_set.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/utilities.hpp" #ifdef _WINDOWS #undef timezone diff --git a/src/ruby/embedded.hpp b/src/mtconnect/ruby/embedded.hpp similarity index 92% rename from src/ruby/embedded.hpp rename to src/mtconnect/ruby/embedded.hpp index 8f9d703a0..71f85b8f8 100644 --- a/src/ruby/embedded.hpp +++ b/src/mtconnect/ruby/embedded.hpp @@ -21,7 +21,8 @@ #include -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace Rice { class Module; @@ -32,7 +33,7 @@ namespace mtconnect { class Agent; namespace ruby { class RubyVM; - class Embedded + class AGENT_LIB_API Embedded { public: Embedded(Agent *agent, const ConfigOptions &options); diff --git a/src/ruby/ruby_agent.hpp b/src/mtconnect/ruby/ruby_agent.hpp similarity index 97% rename from src/ruby/ruby_agent.hpp rename to src/mtconnect/ruby/ruby_agent.hpp index 6ff22b069..2e171e18f 100644 --- a/src/ruby/ruby_agent.hpp +++ b/src/mtconnect/ruby/ruby_agent.hpp @@ -17,10 +17,11 @@ #pragma once -#include "agent.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/sink/sink.hpp" +#include "mtconnect/source/source.hpp" #include "ruby_smart_ptr.hpp" -#include "sink/sink.hpp" -#include "source/source.hpp" namespace mtconnect::ruby { using namespace mtconnect::device_model; diff --git a/src/ruby/ruby_entity.hpp b/src/mtconnect/ruby/ruby_entity.hpp similarity index 98% rename from src/ruby/ruby_entity.hpp rename to src/mtconnect/ruby/ruby_entity.hpp index 609f1e7d4..ed7e27e62 100644 --- a/src/ruby/ruby_entity.hpp +++ b/src/mtconnect/ruby/ruby_entity.hpp @@ -22,12 +22,13 @@ #include #include -#include "device_model/data_item/data_item.hpp" -#include "device_model/device.hpp" -#include "entity/data_set.hpp" -#include "entity/entity.hpp" -#include "pipeline/shdr_tokenizer.hpp" -#include "pipeline/timestamp_extractor.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/entity/data_set.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/pipeline/shdr_tokenizer.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" #include "ruby_smart_ptr.hpp" #include "ruby_type.hpp" diff --git a/src/ruby/ruby_observation.hpp b/src/mtconnect/ruby/ruby_observation.hpp similarity index 98% rename from src/ruby/ruby_observation.hpp rename to src/mtconnect/ruby/ruby_observation.hpp index 1b6932f86..40b5c5934 100644 --- a/src/ruby/ruby_observation.hpp +++ b/src/mtconnect/ruby/ruby_observation.hpp @@ -17,7 +17,8 @@ #pragma once -#include "observation/observation.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/observation/observation.hpp" #include "ruby_entity.hpp" #include "ruby_vm.hpp" diff --git a/src/ruby/ruby_pipeline.hpp b/src/mtconnect/ruby/ruby_pipeline.hpp similarity index 97% rename from src/ruby/ruby_pipeline.hpp rename to src/mtconnect/ruby/ruby_pipeline.hpp index 53e70cc1d..d66881555 100644 --- a/src/ruby/ruby_pipeline.hpp +++ b/src/mtconnect/ruby/ruby_pipeline.hpp @@ -17,9 +17,10 @@ #pragma once -#include "device_model/data_item/data_item.hpp" -#include "device_model/device.hpp" -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/entity/entity.hpp" #include "ruby_smart_ptr.hpp" namespace mtconnect::ruby { diff --git a/src/ruby/ruby_smart_ptr.hpp b/src/mtconnect/ruby/ruby_smart_ptr.hpp similarity index 97% rename from src/ruby/ruby_smart_ptr.hpp rename to src/mtconnect/ruby/ruby_smart_ptr.hpp index bf8a3d521..97e34f3d3 100644 --- a/src/ruby/ruby_smart_ptr.hpp +++ b/src/mtconnect/ruby/ruby_smart_ptr.hpp @@ -17,13 +17,15 @@ #pragma once +#include "mtconnect/config.hpp" + namespace mtconnect::ruby { template struct MRubySharedPtr { using SharedPtr = std::shared_ptr; - static mrb_data_type *type() + AGENT_SYMBOL_VISIBLE static mrb_data_type *type() { static mrb_data_type s_type {nullptr, nullptr}; if (s_type.struct_name == nullptr) @@ -128,7 +130,7 @@ namespace mtconnect::ruby { { using Ptr = T *; - static mrb_data_type *type() + AGENT_SYMBOL_VISIBLE static mrb_data_type *type() { static mrb_data_type s_type {nullptr, nullptr}; @@ -186,7 +188,7 @@ namespace mtconnect::ruby { { using UniquePtr = std::unique_ptr; - static mrb_data_type *type() + AGENT_SYMBOL_VISIBLE static mrb_data_type *type() { static mrb_data_type s_type {nullptr, nullptr}; if (s_type.struct_name == nullptr) diff --git a/src/ruby/ruby_transform.hpp b/src/mtconnect/ruby/ruby_transform.hpp similarity index 97% rename from src/ruby/ruby_transform.hpp rename to src/mtconnect/ruby/ruby_transform.hpp index 38843bc8a..0c8368844 100644 --- a/src/ruby/ruby_transform.hpp +++ b/src/mtconnect/ruby/ruby_transform.hpp @@ -17,9 +17,10 @@ #pragma once -#include "pipeline/guard.hpp" -#include "pipeline/topic_mapper.hpp" -#include "pipeline/transform.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/pipeline/guard.hpp" +#include "mtconnect/pipeline/topic_mapper.hpp" +#include "mtconnect/pipeline/transform.hpp" #include "ruby_entity.hpp" #include "ruby_observation.hpp" #include "ruby_pipeline.hpp" @@ -31,7 +32,7 @@ namespace mtconnect::ruby { using namespace entity; using namespace observation; - class RubyTransform : public pipeline::Transform + class AGENT_LIB_API RubyTransform : public pipeline::Transform { public: static void initialize(mrb_state *mrb, RClass *module) diff --git a/src/ruby/ruby_type.hpp b/src/mtconnect/ruby/ruby_type.hpp similarity index 97% rename from src/ruby/ruby_type.hpp rename to src/mtconnect/ruby/ruby_type.hpp index 7a6d44cfa..34641cd3b 100644 --- a/src/ruby/ruby_type.hpp +++ b/src/mtconnect/ruby/ruby_type.hpp @@ -22,7 +22,8 @@ #include #include -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" namespace mtconnect::ruby { using namespace mtconnect; diff --git a/src/ruby/ruby_vm.hpp b/src/mtconnect/ruby/ruby_vm.hpp similarity index 98% rename from src/ruby/ruby_vm.hpp rename to src/mtconnect/ruby/ruby_vm.hpp index c60438dbc..d33134ba9 100644 --- a/src/ruby/ruby_vm.hpp +++ b/src/mtconnect/ruby/ruby_vm.hpp @@ -17,8 +17,10 @@ #pragma once +#include "mtconnect/config.hpp" + namespace mtconnect::ruby { - class RubyVM + class AGENT_LIB_API RubyVM { public: RubyVM() diff --git a/src/sink/mqtt_sink/mqtt_service.cpp b/src/mtconnect/sink/mqtt_sink/mqtt_service.cpp similarity index 95% rename from src/sink/mqtt_sink/mqtt_service.cpp rename to src/mtconnect/sink/mqtt_sink/mqtt_service.cpp index e008f4a16..ef049f3d7 100644 --- a/src/sink/mqtt_sink/mqtt_service.cpp +++ b/src/mtconnect/sink/mqtt_sink/mqtt_service.cpp @@ -17,12 +17,12 @@ #include "mqtt_service.hpp" -#include "configuration/config_options.hpp" -#include "entity/entity.hpp" -#include "entity/factory.hpp" -#include "entity/json_parser.hpp" -#include "mqtt/mqtt_client_impl.hpp" -#include "printer/json_printer.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" +#include "mtconnect/entity/json_parser.hpp" +#include "mtconnect/mqtt/mqtt_client_impl.hpp" +#include "mtconnect/printer/json_printer.hpp" using json = nlohmann::json; using ptree = boost::property_tree::ptree; diff --git a/src/sink/mqtt_sink/mqtt_service.hpp b/src/mtconnect/sink/mqtt_sink/mqtt_service.hpp similarity index 82% rename from src/sink/mqtt_sink/mqtt_service.hpp rename to src/mtconnect/sink/mqtt_sink/mqtt_service.hpp index 7ba0a782d..2fa4192f4 100644 --- a/src/sink/mqtt_sink/mqtt_service.hpp +++ b/src/mtconnect/sink/mqtt_sink/mqtt_service.hpp @@ -20,15 +20,16 @@ #include "boost/asio/io_context.hpp" #include -#include "buffer/checkpoint.hpp" -#include "configuration/agent_config.hpp" -#include "entity/json_printer.hpp" -#include "mqtt/mqtt_client.hpp" -#include "observation/observation.hpp" -#include "printer/printer.hpp" -#include "printer/xml_printer_helper.hpp" -#include "sink/sink.hpp" -#include "utilities.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/configuration/agent_config.hpp" +#include "mtconnect/entity/json_printer.hpp" +#include "mtconnect/mqtt/mqtt_client.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/printer/printer.hpp" +#include "mtconnect/printer/xml_printer_helper.hpp" +#include "mtconnect/sink/sink.hpp" +#include "mtconnect/utilities.hpp" using namespace std; using namespace mtconnect::entity; @@ -39,7 +40,7 @@ namespace mtconnect { namespace sink { namespace mqtt_sink { - class MqttService : public sink::Sink + class AGENT_LIB_API MqttService : public sink::Sink { // dynamic loading of sink diff --git a/src/sink/rest_sink/cached_file.hpp b/src/mtconnect/sink/rest_sink/cached_file.hpp similarity index 98% rename from src/sink/rest_sink/cached_file.hpp rename to src/mtconnect/sink/rest_sink/cached_file.hpp index 11a5f14d0..1d8220c1a 100644 --- a/src/sink/rest_sink/cached_file.hpp +++ b/src/mtconnect/sink/rest_sink/cached_file.hpp @@ -22,7 +22,8 @@ #include #include -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace sink { diff --git a/src/sink/rest_sink/file_cache.cpp b/src/mtconnect/sink/rest_sink/file_cache.cpp similarity index 99% rename from src/sink/rest_sink/file_cache.cpp rename to src/mtconnect/sink/rest_sink/file_cache.cpp index 3bad7e085..2e443641c 100644 --- a/src/sink/rest_sink/file_cache.cpp +++ b/src/mtconnect/sink/rest_sink/file_cache.cpp @@ -31,7 +31,7 @@ #include #include "cached_file.hpp" -#include "logging.hpp" +#include "mtconnect/logging.hpp" using namespace std; diff --git a/src/sink/rest_sink/file_cache.hpp b/src/mtconnect/sink/rest_sink/file_cache.hpp similarity index 98% rename from src/sink/rest_sink/file_cache.hpp rename to src/mtconnect/sink/rest_sink/file_cache.hpp index 790d3b0a7..9a9773367 100644 --- a/src/sink/rest_sink/file_cache.hpp +++ b/src/mtconnect/sink/rest_sink/file_cache.hpp @@ -23,6 +23,7 @@ #include #include "cached_file.hpp" +#include "mtconnect/config.hpp" namespace boost { namespace asio { @@ -33,7 +34,7 @@ namespace boost { namespace mtconnect::sink::rest_sink { using XmlNamespace = std::pair; using XmlNamespaceList = std::list; - class FileCache + class AGENT_LIB_API FileCache { public: using Directory = std::pair>; diff --git a/src/sink/rest_sink/parameter.hpp b/src/mtconnect/sink/rest_sink/parameter.hpp similarity index 93% rename from src/sink/rest_sink/parameter.hpp rename to src/mtconnect/sink/rest_sink/parameter.hpp index adc3fee3f..6113aa560 100644 --- a/src/sink/rest_sink/parameter.hpp +++ b/src/mtconnect/sink/rest_sink/parameter.hpp @@ -22,13 +22,15 @@ #include #include +#include "mtconnect/config.hpp" + namespace mtconnect::sink::rest_sink { - class ParameterError : public std::logic_error + class AGENT_LIB_API ParameterError : public std::logic_error { using std::logic_error::logic_error; }; - enum ParameterType + enum ParameterType : uint8_t { NONE = 0, STRING = 1, diff --git a/src/sink/rest_sink/request.hpp b/src/mtconnect/sink/rest_sink/request.hpp similarity index 95% rename from src/sink/rest_sink/request.hpp rename to src/mtconnect/sink/rest_sink/request.hpp index e18f2f3dd..71b0a148d 100644 --- a/src/sink/rest_sink/request.hpp +++ b/src/mtconnect/sink/rest_sink/request.hpp @@ -22,10 +22,11 @@ #include +#include "mtconnect/config.hpp" #include "parameter.hpp" namespace mtconnect::sink::rest_sink { - class RequestError : public std::logic_error + class AGENT_LIB_API RequestError : public std::logic_error { public: RequestError(const char *w) : std::logic_error::logic_error(w) {} diff --git a/src/sink/rest_sink/response.hpp b/src/mtconnect/sink/rest_sink/response.hpp similarity index 96% rename from src/sink/rest_sink/response.hpp rename to src/mtconnect/sink/rest_sink/response.hpp index 9feb3eb7e..2e0954104 100644 --- a/src/sink/rest_sink/response.hpp +++ b/src/mtconnect/sink/rest_sink/response.hpp @@ -24,8 +24,9 @@ #include #include "cached_file.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" #include "request.hpp" -#include "utilities.hpp" namespace mtconnect { namespace printer { diff --git a/src/sink/rest_sink/rest_service.cpp b/src/mtconnect/sink/rest_sink/rest_service.cpp similarity index 97% rename from src/sink/rest_sink/rest_service.cpp rename to src/mtconnect/sink/rest_sink/rest_service.cpp index 3704000af..5f1297888 100644 --- a/src/sink/rest_sink/rest_service.cpp +++ b/src/mtconnect/sink/rest_sink/rest_service.cpp @@ -17,12 +17,12 @@ #include "rest_service.hpp" -#include "configuration/config_options.hpp" -#include "entity/xml_parser.hpp" -#include "pipeline/shdr_token_mapper.hpp" -#include "pipeline/shdr_tokenizer.hpp" -#include "pipeline/timestamp_extractor.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/pipeline/shdr_token_mapper.hpp" +#include "mtconnect/pipeline/shdr_tokenizer.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" +#include "mtconnect/printer/xml_printer.hpp" #include "server.hpp" namespace asio = boost::asio; @@ -728,6 +728,7 @@ namespace mtconnect { m_timer(strand.context()) {} + std::weak_ptr m_service; rest_sink::SessionPtr m_session; ofstream m_log; SequenceNumber_t m_sequence {0}; @@ -767,7 +768,8 @@ namespace mtconnect { asyncResponse->m_count = count; asyncResponse->m_printer = printer; asyncResponse->m_heartbeat = std::chrono::milliseconds(heartbeatIn); - + asyncResponse->m_service = getptr(); + checkPath(asyncResponse->m_printer, path, dev, asyncResponse->m_filter); if (m_logStreamData) @@ -829,10 +831,16 @@ namespace mtconnect { using boost::placeholders::_1; using boost::placeholders::_2; - if (!m_server->isRunning()) + auto service = asyncResponse->m_service.lock(); + + if (!service || !m_server || !m_server->isRunning()) { - asyncResponse->m_session->fail(boost::beast::http::status::internal_server_error, - "Agent shutting down, aborting stream"); + LOG(warning) << "Trying to send chunk when service has stopped"; + if (service) + { + asyncResponse->m_session->fail(boost::beast::http::status::internal_server_error, + "Agent shutting down, aborting stream"); + } return; } @@ -938,7 +946,8 @@ namespace mtconnect { AsyncCurrentResponse(rest_sink::SessionPtr session, asio::io_context &context) : m_session(session), m_timer(context) {} - + + std::weak_ptr m_service; rest_sink::SessionPtr m_session; chrono::milliseconds m_interval; const Printer *m_printer {nullptr}; @@ -966,6 +975,7 @@ namespace mtconnect { } asyncResponse->m_interval = chrono::milliseconds {interval}; asyncResponse->m_printer = printer; + asyncResponse->m_service = getptr(); asyncResponse->m_session->beginStreaming( printer->mimeType(), boost::asio::bind_executor(m_strand, [this, asyncResponse]() { @@ -978,10 +988,16 @@ namespace mtconnect { { using boost::placeholders::_1; - if (!m_server->isRunning()) + auto service = asyncResponse->m_service.lock(); + + if (!service || !m_server || !m_server->isRunning()) { - asyncResponse->m_session->fail(boost::beast::http::status::internal_server_error, - "Agent shutting down, aborting stream"); + LOG(warning) << "Trying to send chunk when service has stopped"; + if (service) + { + asyncResponse->m_session->fail(boost::beast::http::status::internal_server_error, + "Agent shutting down, aborting stream"); + } return; } diff --git a/src/sink/rest_sink/rest_service.hpp b/src/mtconnect/sink/rest_sink/rest_service.hpp similarity index 96% rename from src/sink/rest_sink/rest_service.hpp rename to src/mtconnect/sink/rest_sink/rest_service.hpp index 8f894a4f2..7980955a8 100644 --- a/src/sink/rest_sink/rest_service.hpp +++ b/src/mtconnect/sink/rest_sink/rest_service.hpp @@ -17,15 +17,16 @@ #pragma once -#include "boost/asio/io_context.hpp" +#include -#include "buffer/circular_buffer.hpp" +#include "mtconnect/buffer/circular_buffer.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/sink/sink.hpp" +#include "mtconnect/source/loopback_source.hpp" +#include "mtconnect/utilities.hpp" #include "request.hpp" #include "response.hpp" #include "server.hpp" -#include "sink/sink.hpp" -#include "source/loopback_source.hpp" -#include "utilities.hpp" namespace mtconnect { namespace printer { @@ -41,7 +42,7 @@ namespace mtconnect { const std::string &); using StyleFunction = void (printer::XmlPrinter::*)(const std::string &); - class RestService : public Sink + class AGENT_LIB_API RestService : public Sink { public: RestService(boost::asio::io_context &context, SinkContractPtr &&contract, diff --git a/src/sink/rest_sink/routing.hpp b/src/mtconnect/sink/rest_sink/routing.hpp similarity index 98% rename from src/sink/rest_sink/routing.hpp rename to src/mtconnect/sink/rest_sink/routing.hpp index 54c8c80fc..9bd1ac5f4 100644 --- a/src/sink/rest_sink/routing.hpp +++ b/src/mtconnect/sink/rest_sink/routing.hpp @@ -27,7 +27,8 @@ #include #include -#include "logging.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/logging.hpp" #include "parameter.hpp" #include "request.hpp" #include "session.hpp" @@ -36,7 +37,7 @@ namespace mtconnect::sink::rest_sink { class Session; using SessionPtr = std::shared_ptr; - class Routing + class AGENT_LIB_API Routing { public: using Function = std::function; diff --git a/src/sink/rest_sink/server.cpp b/src/mtconnect/sink/rest_sink/server.cpp similarity index 99% rename from src/sink/rest_sink/server.cpp rename to src/mtconnect/sink/rest_sink/server.cpp index 88dada4f5..95cded059 100644 --- a/src/sink/rest_sink/server.cpp +++ b/src/mtconnect/sink/rest_sink/server.cpp @@ -29,7 +29,7 @@ #include -#include "logging.hpp" +#include "mtconnect/logging.hpp" #include "session_impl.hpp" namespace mtconnect::sink::rest_sink { diff --git a/src/sink/rest_sink/server.hpp b/src/mtconnect/sink/rest_sink/server.hpp similarity index 97% rename from src/sink/rest_sink/server.hpp rename to src/mtconnect/sink/rest_sink/server.hpp index 15db9d8e4..f6e5005e2 100644 --- a/src/sink/rest_sink/server.hpp +++ b/src/mtconnect/sink/rest_sink/server.hpp @@ -33,16 +33,17 @@ #include #include -#include "configuration/config_options.hpp" #include "file_cache.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/utilities.hpp" #include "response.hpp" #include "routing.hpp" #include "session.hpp" #include "tls_dector.hpp" -#include "utilities.hpp" namespace mtconnect::sink::rest_sink { - class Server + class AGENT_LIB_API Server { public: Server(boost::asio::io_context &context, const ConfigOptions &options = {}) diff --git a/src/sink/rest_sink/session.hpp b/src/mtconnect/sink/rest_sink/session.hpp similarity index 99% rename from src/sink/rest_sink/session.hpp rename to src/mtconnect/sink/rest_sink/session.hpp index 1b9792fca..1cca5c7c4 100644 --- a/src/sink/rest_sink/session.hpp +++ b/src/mtconnect/sink/rest_sink/session.hpp @@ -24,6 +24,7 @@ #include #include +#include "mtconnect/config.hpp" #include "routing.hpp" namespace mtconnect::sink::rest_sink { diff --git a/src/sink/rest_sink/session_impl.cpp b/src/mtconnect/sink/rest_sink/session_impl.cpp similarity index 99% rename from src/sink/rest_sink/session_impl.cpp rename to src/mtconnect/sink/rest_sink/session_impl.cpp index 46ba93826..e93e6f0be 100644 --- a/src/sink/rest_sink/session_impl.cpp +++ b/src/mtconnect/sink/rest_sink/session_impl.cpp @@ -30,7 +30,7 @@ #include #include -#include "logging.hpp" +#include "mtconnect/logging.hpp" #include "request.hpp" #include "response.hpp" #include "tls_dector.hpp" diff --git a/src/sink/rest_sink/session_impl.hpp b/src/mtconnect/sink/rest_sink/session_impl.hpp similarity index 97% rename from src/sink/rest_sink/session_impl.hpp rename to src/mtconnect/sink/rest_sink/session_impl.hpp index 7c49af48b..f9ca17151 100644 --- a/src/sink/rest_sink/session_impl.hpp +++ b/src/mtconnect/sink/rest_sink/session_impl.hpp @@ -24,9 +24,10 @@ #include #include -#include "configuration/config_options.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/utilities.hpp" #include "session.hpp" -#include "utilities.hpp" namespace mtconnect { namespace printer { diff --git a/src/sink/rest_sink/tls_dector.hpp b/src/mtconnect/sink/rest_sink/tls_dector.hpp similarity index 96% rename from src/sink/rest_sink/tls_dector.hpp rename to src/mtconnect/sink/rest_sink/tls_dector.hpp index 2cbc01f93..1ec7ced26 100644 --- a/src/sink/rest_sink/tls_dector.hpp +++ b/src/mtconnect/sink/rest_sink/tls_dector.hpp @@ -20,9 +20,9 @@ #include #include -#include "configuration/config_options.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/utilities.hpp" #include "session.hpp" -#include "utilities.hpp" namespace mtconnect::sink::rest_sink { class TlsDector : public std::enable_shared_from_this diff --git a/src/sink/sink.cpp b/src/mtconnect/sink/sink.cpp similarity index 97% rename from src/sink/sink.cpp rename to src/mtconnect/sink/sink.cpp index 55982064f..4fb757485 100644 --- a/src/sink/sink.cpp +++ b/src/mtconnect/sink/sink.cpp @@ -17,7 +17,7 @@ #include "sink.hpp" -#include "logging.hpp" +#include "mtconnect/logging.hpp" namespace mtconnect { namespace sink { diff --git a/src/sink/sink.hpp b/src/mtconnect/sink/sink.hpp similarity index 88% rename from src/sink/sink.hpp rename to src/mtconnect/sink/sink.hpp index cdbf94155..d7599b356 100644 --- a/src/sink/sink.hpp +++ b/src/mtconnect/sink/sink.hpp @@ -25,11 +25,12 @@ #include #include -#include "asset/asset_storage.hpp" -#include "buffer/circular_buffer.hpp" -#include "device_model/device.hpp" -#include "observation/observation.hpp" -#include "printer/printer.hpp" +#include "mtconnect/asset/asset_storage.hpp" +#include "mtconnect/buffer/circular_buffer.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/printer//printer.hpp" namespace mtconnect { namespace printer { @@ -47,7 +48,7 @@ namespace mtconnect { } namespace sink { - class SinkContract + class AGENT_LIB_API SinkContract { public: virtual ~SinkContract() = default; @@ -79,7 +80,7 @@ namespace mtconnect { const std::string &name, boost::asio::io_context &io, SinkContractPtr &&contract, const ConfigOptions &options, const boost::property_tree::ptree &block)>; - class Sink + class AGENT_LIB_API Sink : public std::enable_shared_from_this { public: Sink(const std::string &name, SinkContractPtr &&contract) @@ -87,6 +88,8 @@ namespace mtconnect { {} virtual ~Sink() = default; + SinkPtr getptr() const { return const_cast(this)->shared_from_this(); } + virtual void start() = 0; virtual void stop() = 0; @@ -101,7 +104,7 @@ namespace mtconnect { std::string m_name; }; - class SinkFactory + class AGENT_LIB_API SinkFactory { public: void registerFactory(const std::string &name, SinkFactoryFn function) diff --git a/src/source/adapter/adapter.hpp b/src/mtconnect/source/adapter/adapter.hpp similarity index 89% rename from src/source/adapter/adapter.hpp rename to src/mtconnect/source/adapter/adapter.hpp index 3a36db3bb..d4cbe925b 100644 --- a/src/source/adapter/adapter.hpp +++ b/src/mtconnect/source/adapter/adapter.hpp @@ -17,11 +17,12 @@ #pragma once -#include "source/adapter/adapter_pipeline.hpp" -#include "source/source.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/source/adapter/adapter_pipeline.hpp" +#include "mtconnect/source/source.hpp" namespace mtconnect::source::adapter { - class Adapter : public Source + class AGENT_LIB_API Adapter : public Source { public: Adapter(const std::string &name, boost::asio::io_context &io, const ConfigOptions &options) diff --git a/src/source/adapter/adapter_pipeline.cpp b/src/mtconnect/source/adapter/adapter_pipeline.cpp similarity index 88% rename from src/source/adapter/adapter_pipeline.cpp rename to src/mtconnect/source/adapter/adapter_pipeline.cpp index e3ae04b42..acf2a1d33 100644 --- a/src/source/adapter/adapter_pipeline.cpp +++ b/src/mtconnect/source/adapter/adapter_pipeline.cpp @@ -15,20 +15,20 @@ // limitations under the License. // -#include "source/adapter/adapter_pipeline.hpp" - -#include "agent.hpp" -#include "configuration/agent_config.hpp" -#include "configuration/config_options.hpp" -#include "pipeline/convert_sample.hpp" -#include "pipeline/deliver.hpp" -#include "pipeline/delta_filter.hpp" -#include "pipeline/duplicate_filter.hpp" -#include "pipeline/period_filter.hpp" -#include "pipeline/timestamp_extractor.hpp" -#include "pipeline/topic_mapper.hpp" -#include "pipeline/upcase_value.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/adapter_pipeline.hpp" + +#include "mtconnect/agent.hpp" +#include "mtconnect/configuration/agent_config.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/pipeline/convert_sample.hpp" +#include "mtconnect/pipeline/deliver.hpp" +#include "mtconnect/pipeline/delta_filter.hpp" +#include "mtconnect/pipeline/duplicate_filter.hpp" +#include "mtconnect/pipeline/period_filter.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" +#include "mtconnect/pipeline/topic_mapper.hpp" +#include "mtconnect/pipeline/upcase_value.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using namespace std; using namespace std::literals; diff --git a/src/source/adapter/adapter_pipeline.hpp b/src/mtconnect/source/adapter/adapter_pipeline.hpp similarity index 89% rename from src/source/adapter/adapter_pipeline.hpp rename to src/mtconnect/source/adapter/adapter_pipeline.hpp index 7f885ac7a..c342e7950 100644 --- a/src/source/adapter/adapter_pipeline.hpp +++ b/src/mtconnect/source/adapter/adapter_pipeline.hpp @@ -17,8 +17,9 @@ #pragma once -#include "pipeline/pipeline.hpp" -#include "pipeline/transform.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/pipeline/transform.hpp" namespace mtconnect::source::adapter { struct Handler @@ -37,7 +38,7 @@ namespace mtconnect::source::adapter { Connect m_disconnected; }; - class AdapterPipeline : public pipeline::Pipeline + class AGENT_LIB_API AdapterPipeline : public pipeline::Pipeline { public: AdapterPipeline(pipeline::PipelineContextPtr context, boost::asio::io_context::strand &st) @@ -47,6 +48,8 @@ namespace mtconnect::source::adapter { void build(const ConfigOptions &options) override; virtual std::unique_ptr makeHandler(); + const auto &getDevice() const { return m_device; } + protected: void buildDeviceList(); void buildCommandAndStatusDelivery(); diff --git a/src/source/adapter/agent_adapter/agent_adapter.cpp b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp similarity index 99% rename from src/source/adapter/agent_adapter/agent_adapter.cpp rename to src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp index 597f7290e..c2eb9648c 100644 --- a/src/source/adapter/agent_adapter/agent_adapter.cpp +++ b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.cpp @@ -29,11 +29,11 @@ #include #include -#include "configuration/config_options.hpp" #include "http_session.hpp" #include "https_session.hpp" -#include "logging.hpp" -#include "pipeline/deliver.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/pipeline/deliver.hpp" #include "session_impl.hpp" using namespace std; diff --git a/src/source/adapter/agent_adapter/agent_adapter.hpp b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp similarity index 92% rename from src/source/adapter/agent_adapter/agent_adapter.hpp rename to src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp index cb83c2a49..7de6887d4 100644 --- a/src/source/adapter/agent_adapter/agent_adapter.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/agent_adapter.hpp @@ -17,10 +17,11 @@ #pragma once -#include "pipeline/mtconnect_xml_transform.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/pipeline/mtconnect_xml_transform.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/adapter_pipeline.hpp" #include "session.hpp" -#include "source/adapter/adapter.hpp" -#include "source/adapter/adapter_pipeline.hpp" #include "url_parser.hpp" namespace boost::asio::ssl { @@ -31,7 +32,7 @@ namespace mtconnect::source::adapter::agent_adapter { using namespace mtconnect; using namespace source::adapter; - class AgentAdapterPipeline : public AdapterPipeline + class AGENT_LIB_API AgentAdapterPipeline : public AdapterPipeline { public: AgentAdapterPipeline(pipeline::PipelineContextPtr context, boost::asio::io_context::strand &st, @@ -44,7 +45,7 @@ namespace mtconnect::source::adapter::agent_adapter { pipeline::XmlTransformFeedback &m_feedback; }; - class AgentAdapter : public Adapter + class AGENT_LIB_API AgentAdapter : public Adapter { public: AgentAdapter(boost::asio::io_context &io, pipeline::PipelineContextPtr context, diff --git a/src/source/adapter/agent_adapter/http_session.hpp b/src/mtconnect/source/adapter/agent_adapter/http_session.hpp similarity index 98% rename from src/source/adapter/agent_adapter/http_session.hpp rename to src/mtconnect/source/adapter/agent_adapter/http_session.hpp index 70a8be475..a8b1eead6 100644 --- a/src/source/adapter/agent_adapter/http_session.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/http_session.hpp @@ -18,6 +18,7 @@ #pragma once +#include "mtconnect/config.hpp" #include "session_impl.hpp" namespace mtconnect::source::adapter::agent_adapter { diff --git a/src/source/adapter/agent_adapter/https_session.hpp b/src/mtconnect/source/adapter/agent_adapter/https_session.hpp similarity index 99% rename from src/source/adapter/agent_adapter/https_session.hpp rename to src/mtconnect/source/adapter/agent_adapter/https_session.hpp index b55a031b0..43b31fe30 100644 --- a/src/source/adapter/agent_adapter/https_session.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/https_session.hpp @@ -20,6 +20,7 @@ #include +#include "mtconnect/config.hpp" #include "session_impl.hpp" namespace mtconnect::source::adapter::agent_adapter { diff --git a/src/source/adapter/agent_adapter/session.hpp b/src/mtconnect/source/adapter/agent_adapter/session.hpp similarity index 97% rename from src/source/adapter/agent_adapter/session.hpp rename to src/mtconnect/source/adapter/agent_adapter/session.hpp index 9c3d62fb7..7872cf693 100644 --- a/src/source/adapter/agent_adapter/session.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/session.hpp @@ -22,7 +22,8 @@ #include -#include "entity/entity.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/entity/entity.hpp" #include "url_parser.hpp" namespace mtconnect::source::adapter { diff --git a/src/source/adapter/agent_adapter/session_impl.hpp b/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp similarity index 99% rename from src/source/adapter/agent_adapter/session_impl.hpp rename to src/mtconnect/source/adapter/agent_adapter/session_impl.hpp index 53c60b410..5d727eba5 100644 --- a/src/source/adapter/agent_adapter/session_impl.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/session_impl.hpp @@ -25,8 +25,9 @@ #include #include -#include "pipeline/mtconnect_xml_transform.hpp" -#include "pipeline/response_document.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/pipeline/mtconnect_xml_transform.hpp" +#include "mtconnect/pipeline/response_document.hpp" #include "session.hpp" namespace mtconnect::source::adapter::agent_adapter { diff --git a/src/source/adapter/agent_adapter/url_parser.cpp b/src/mtconnect/source/adapter/agent_adapter/url_parser.cpp similarity index 100% rename from src/source/adapter/agent_adapter/url_parser.cpp rename to src/mtconnect/source/adapter/agent_adapter/url_parser.cpp diff --git a/src/source/adapter/agent_adapter/url_parser.hpp b/src/mtconnect/source/adapter/agent_adapter/url_parser.hpp similarity index 95% rename from src/source/adapter/agent_adapter/url_parser.hpp rename to src/mtconnect/source/adapter/agent_adapter/url_parser.hpp index 641d98ad2..7d0f58ba1 100644 --- a/src/source/adapter/agent_adapter/url_parser.hpp +++ b/src/mtconnect/source/adapter/agent_adapter/url_parser.hpp @@ -27,12 +27,13 @@ #include #include -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::source::adapter::agent_adapter { using UrlQueryPair = std::pair; - struct UrlQuery : public std::map + struct AGENT_LIB_API UrlQuery : public std::map { using std::map::map; std::string join() const @@ -61,7 +62,7 @@ namespace mtconnect::source::adapter::agent_adapter { } }; - struct Url + struct AGENT_LIB_API Url { using Host = std::variant; diff --git a/src/source/adapter/mqtt/mqtt_adapter.cpp b/src/mtconnect/source/adapter/mqtt/mqtt_adapter.cpp similarity index 89% rename from src/source/adapter/mqtt/mqtt_adapter.cpp rename to src/mtconnect/source/adapter/mqtt/mqtt_adapter.cpp index a97018e6e..d17ce64bb 100644 --- a/src/source/adapter/mqtt/mqtt_adapter.cpp +++ b/src/mtconnect/source/adapter/mqtt/mqtt_adapter.cpp @@ -23,20 +23,20 @@ #include #include -#include "configuration/config_options.hpp" -#include "device_model/device.hpp" -#include "mqtt/mqtt_client_impl.hpp" -#include "pipeline/convert_sample.hpp" -#include "pipeline/deliver.hpp" -#include "pipeline/delta_filter.hpp" -#include "pipeline/duplicate_filter.hpp" -#include "pipeline/message_mapper.hpp" -#include "pipeline/period_filter.hpp" -#include "pipeline/shdr_token_mapper.hpp" -#include "pipeline/shdr_tokenizer.hpp" -#include "pipeline/timestamp_extractor.hpp" -#include "pipeline/topic_mapper.hpp" -#include "pipeline/upcase_value.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/mqtt/mqtt_client_impl.hpp" +#include "mtconnect/pipeline/convert_sample.hpp" +#include "mtconnect/pipeline/deliver.hpp" +#include "mtconnect/pipeline/delta_filter.hpp" +#include "mtconnect/pipeline/duplicate_filter.hpp" +#include "mtconnect/pipeline/message_mapper.hpp" +#include "mtconnect/pipeline/period_filter.hpp" +#include "mtconnect/pipeline/shdr_token_mapper.hpp" +#include "mtconnect/pipeline/shdr_tokenizer.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" +#include "mtconnect/pipeline/topic_mapper.hpp" +#include "mtconnect/pipeline/upcase_value.hpp" using namespace std; namespace asio = boost::asio; diff --git a/src/source/adapter/mqtt/mqtt_adapter.hpp b/src/mtconnect/source/adapter/mqtt/mqtt_adapter.hpp similarity index 87% rename from src/source/adapter/mqtt/mqtt_adapter.hpp rename to src/mtconnect/source/adapter/mqtt/mqtt_adapter.hpp index 1941de4ba..9cab7b5d2 100644 --- a/src/source/adapter/mqtt/mqtt_adapter.hpp +++ b/src/mtconnect/source/adapter/mqtt/mqtt_adapter.hpp @@ -17,15 +17,16 @@ #pragma once -#include "mqtt/mqtt_client.hpp" -#include "source/adapter/adapter.hpp" -#include "source/adapter/adapter_pipeline.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/mqtt/mqtt_client.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/adapter_pipeline.hpp" using namespace mtconnect::mqtt_client; namespace mtconnect::source::adapter::mqtt_adapter { - class MqttPipeline : public AdapterPipeline + class AGENT_LIB_API MqttPipeline : public AdapterPipeline { public: MqttPipeline(pipeline::PipelineContextPtr context, boost::asio::io_context::strand &strand) @@ -39,7 +40,7 @@ namespace mtconnect::source::adapter::mqtt_adapter { ConfigOptions m_options; }; - class MqttAdapter : public Adapter + class AGENT_LIB_API MqttAdapter : public Adapter { public: MqttAdapter(boost::asio::io_context &io, pipeline::PipelineContextPtr pipelineContext, diff --git a/src/source/adapter/shdr/connector.cpp b/src/mtconnect/source/adapter/shdr/connector.cpp similarity index 85% rename from src/source/adapter/shdr/connector.cpp rename to src/mtconnect/source/adapter/shdr/connector.cpp index 03f62d01d..bb144eb16 100644 --- a/src/source/adapter/shdr/connector.cpp +++ b/src/mtconnect/source/adapter/shdr/connector.cpp @@ -29,7 +29,7 @@ #include #include -#include "logging.hpp" +#include "mtconnect/logging.hpp" using namespace std; using namespace std::chrono; @@ -102,13 +102,13 @@ namespace mtconnect::source::adapter::shdr { << " milliseconds"; m_timer.expires_from_now(m_reconnectInterval); - m_timer.async_wait(asio::bind_executor(m_strand, [this](boost::system::error_code ec) { + m_timer.async_wait([this](boost::system::error_code ec) { if (ec != boost::asio::error::operation_aborted) { - LOG(info) << "reconnect: retrying connection"; - resolve(); + LOG(info) << "resolve: retrying connection"; + asio::dispatch(m_strand, boost::bind(&Connector::resolve, this)); } - })); + }); } else { @@ -131,7 +131,9 @@ namespace mtconnect::source::adapter::shdr { asio::async_connect( m_socket, m_results.begin(), m_results.end(), - asio::bind_executor(m_strand, boost::bind(&Connector::connected, this, _1, _2))); + [this](const boost::system::error_code &ec, ip::tcp::resolver::iterator it) { + asio::dispatch(m_strand, boost::bind(&Connector::connected, this, ec, it)); + }); return true; } @@ -141,13 +143,13 @@ namespace mtconnect::source::adapter::shdr { NAMED_SCOPE("Connector::asyncTryConnect"); m_timer.expires_from_now(m_reconnectInterval); - m_timer.async_wait(asio::bind_executor(m_strand, [this](boost::system::error_code ec) { + m_timer.async_wait([this](boost::system::error_code ec) { if (ec != boost::asio::error::operation_aborted) { LOG(info) << "reconnect: retrying connection"; - connect(); + asio::dispatch(m_strand, boost::bind(&Connector::connect, this)); } - })); + }); } void Connector::reconnect() @@ -199,8 +201,6 @@ namespace mtconnect::source::adapter::shdr { } } -#include - void Connector::reader(sys::error_code ec, size_t len) { NAMED_SCOPE("Connector::reader"); @@ -215,33 +215,34 @@ namespace mtconnect::source::adapter::shdr { } else { - reenter(m_coroutine) + if (!m_socket.is_open()) { - while (m_connected && m_socket.is_open()) - { - m_timer.expires_from_now(m_receiveTimeLimit); - m_timer.async_wait(asio::bind_executor(m_strand, [this](boost::system::error_code ec) { - if (ec != boost::asio::error::operation_aborted) - { - LOG(warning) << "operation timed out after " << m_receiveTimeLimit.count() << "ms"; - reconnect(); - } - })); - yield asio::async_read_until( - m_socket, m_incoming, '\n', - asio::bind_executor(m_strand, boost::bind(&Connector::reader, this, _1, _2))); - m_timer.cancel(); - while (parseSocketBuffer()) - ; - } + LOG(error) << "Socket closed"; reconnect(); + return; } + + m_timer.cancel(); + + while (parseSocketBuffer()) + ; + + m_timer.expires_from_now(m_receiveTimeLimit); + m_timer.async_wait([this](boost::system::error_code ec) { + if (ec != boost::asio::error::operation_aborted) + { + LOG(warning) << "operation timed out after " << m_receiveTimeLimit.count() << "ms"; + asio::dispatch(m_strand, boost::bind(&Connector::reconnect, this)); + } + }); + + asio::async_read_until(m_socket, m_incoming, '\n', [this](sys::error_code ec, size_t len) { + asio::dispatch(m_strand, boost::bind(&Connector::reader, this, ec, len)); + }); } } -#include - - void Connector::writer(sys::error_code ec, size_t lenght) + void Connector::writer(sys::error_code ec, size_t length) { NAMED_SCOPE("Connector::writer"); @@ -265,20 +266,20 @@ namespace mtconnect::source::adapter::shdr { NAMED_SCOPE("Connector::setReceiveTimeout"); m_receiveTimeout.expires_from_now(m_receiveTimeLimit); - m_receiveTimeout.async_wait(asio::bind_executor(m_strand, [this](sys::error_code ec) { + m_receiveTimeout.async_wait([this](sys::error_code ec) { if (!ec) { LOG(error) << "(Port:" << m_localPort << ")" << " connect: Did not receive data for over: " << m_receiveTimeLimit.count() << " ms"; - reconnect(); + asio::dispatch(m_strand, boost::bind(&Connector::reconnect, this)); } else if (ec != boost::asio::error::operation_aborted) { LOG(error) << "Receive timeout: " << ec.category().message(ec.value()) << ": " << ec.message(); } - })); + }); } inline void Connector::processLine(const std::string &line) @@ -375,9 +376,9 @@ namespace mtconnect::source::adapter::shdr { << "Sending " << command; ostream os(&m_outgoing); os << "* " << command << "\n"; - asio::async_write( - m_socket, m_outgoing, - asio::bind_executor(m_strand, boost::bind(&Connector::writer, this, _1, _2))); + asio::async_write(m_socket, m_outgoing, [this](sys::error_code ec, size_t length) { + asio::dispatch(m_strand, boost::bind(&Connector::writer, this, ec, length)); + }); } } @@ -390,8 +391,9 @@ namespace mtconnect::source::adapter::shdr { LOG(debug) << "Sending heartbeat"; sendCommand("PING"); m_heartbeatTimer.expires_from_now(m_heartbeatFrequency); - m_heartbeatTimer.async_wait( - asio::bind_executor(m_strand, boost::bind(&Connector::heartbeat, this, _1))); + m_heartbeatTimer.async_wait([this](boost::system::error_code ec) { + asio::dispatch(m_strand, boost::bind(&Connector::heartbeat, this, ec)); + }); } else if (ec != boost::asio::error::operation_aborted) { @@ -420,8 +422,9 @@ namespace mtconnect::source::adapter::shdr { setReceiveTimeout(); m_heartbeatTimer.expires_from_now(m_heartbeatFrequency); - m_heartbeatTimer.async_wait( - asio::bind_executor(m_strand, boost::bind(&Connector::heartbeat, this, _1))); + m_heartbeatTimer.async_wait([this](boost::system::error_code ec) { + asio::dispatch(m_strand, boost::bind(&Connector::heartbeat, this, ec)); + }); } else { diff --git a/src/source/adapter/shdr/connector.hpp b/src/mtconnect/source/adapter/shdr/connector.hpp similarity index 97% rename from src/source/adapter/shdr/connector.hpp rename to src/mtconnect/source/adapter/shdr/connector.hpp index 06a1005c5..183a48d4c 100644 --- a/src/source/adapter/shdr/connector.hpp +++ b/src/mtconnect/source/adapter/shdr/connector.hpp @@ -24,12 +24,13 @@ #include #include -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" #define HEARTBEAT_FREQ 60000 namespace mtconnect::source::adapter::shdr { - class Connector + class AGENT_LIB_API Connector { public: // Instantiate the server by assigning it a server and port/ diff --git a/src/source/adapter/shdr/shdr_adapter.cpp b/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp similarity index 94% rename from src/source/adapter/shdr/shdr_adapter.cpp rename to src/mtconnect/source/adapter/shdr/shdr_adapter.cpp index 59fa60365..0496ff38a 100644 --- a/src/source/adapter/shdr/shdr_adapter.cpp +++ b/src/mtconnect/source/adapter/shdr/shdr_adapter.cpp @@ -26,9 +26,9 @@ #include #include -#include "configuration/config_options.hpp" -#include "device_model/device.hpp" -#include "logging.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/logging.hpp" using namespace std; using namespace std::literals; diff --git a/src/source/adapter/shdr/shdr_adapter.hpp b/src/mtconnect/source/adapter/shdr/shdr_adapter.hpp similarity index 92% rename from src/source/adapter/shdr/shdr_adapter.hpp rename to src/mtconnect/source/adapter/shdr/shdr_adapter.hpp index 96ad7f7cd..4c839b100 100644 --- a/src/source/adapter/shdr/shdr_adapter.hpp +++ b/src/mtconnect/source/adapter/shdr/shdr_adapter.hpp @@ -26,11 +26,12 @@ #include #include "connector.hpp" -#include "device_model/data_item/data_item.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/source.hpp" +#include "mtconnect/utilities.hpp" #include "shdr_pipeline.hpp" -#include "source/adapter/adapter.hpp" -#include "source/source.hpp" -#include "utilities.hpp" namespace mtconnect { class Agent; @@ -39,7 +40,7 @@ namespace mtconnect { } namespace source::adapter::shdr { - class ShdrAdapter : public adapter::Adapter, public Connector + class AGENT_LIB_API ShdrAdapter : public adapter::Adapter, public Connector { public: // Associate adapter with a device & connect to the server & port diff --git a/src/source/adapter/shdr/shdr_pipeline.cpp b/src/mtconnect/source/adapter/shdr/shdr_pipeline.cpp similarity index 78% rename from src/source/adapter/shdr/shdr_pipeline.cpp rename to src/mtconnect/source/adapter/shdr/shdr_pipeline.cpp index fe795ec6c..2a2f6d55a 100644 --- a/src/source/adapter/shdr/shdr_pipeline.cpp +++ b/src/mtconnect/source/adapter/shdr/shdr_pipeline.cpp @@ -17,18 +17,18 @@ #include "shdr_pipeline.hpp" -#include "agent.hpp" -#include "configuration/agent_config.hpp" -#include "configuration/config_options.hpp" -#include "pipeline/convert_sample.hpp" -#include "pipeline/deliver.hpp" -#include "pipeline/delta_filter.hpp" -#include "pipeline/duplicate_filter.hpp" -#include "pipeline/period_filter.hpp" -#include "pipeline/shdr_token_mapper.hpp" -#include "pipeline/shdr_tokenizer.hpp" -#include "pipeline/timestamp_extractor.hpp" -#include "pipeline/upcase_value.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/configuration/agent_config.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/pipeline/convert_sample.hpp" +#include "mtconnect/pipeline/deliver.hpp" +#include "mtconnect/pipeline/delta_filter.hpp" +#include "mtconnect/pipeline/duplicate_filter.hpp" +#include "mtconnect/pipeline/period_filter.hpp" +#include "mtconnect/pipeline/shdr_token_mapper.hpp" +#include "mtconnect/pipeline/shdr_tokenizer.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" +#include "mtconnect/pipeline/upcase_value.hpp" #include "shdr_adapter.hpp" using namespace std; diff --git a/src/source/adapter/shdr/shdr_pipeline.hpp b/src/mtconnect/source/adapter/shdr/shdr_pipeline.hpp similarity index 87% rename from src/source/adapter/shdr/shdr_pipeline.hpp rename to src/mtconnect/source/adapter/shdr/shdr_pipeline.hpp index 0148384cb..29177e785 100644 --- a/src/source/adapter/shdr/shdr_pipeline.hpp +++ b/src/mtconnect/source/adapter/shdr/shdr_pipeline.hpp @@ -17,10 +17,11 @@ #pragma once -#include "source/adapter/adapter_pipeline.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/source/adapter/adapter_pipeline.hpp" namespace mtconnect::source::adapter::shdr { - class ShdrPipeline : public AdapterPipeline + class AGENT_LIB_API ShdrPipeline : public AdapterPipeline { public: ShdrPipeline(pipeline::PipelineContextPtr context, boost::asio::io_context::strand &st) diff --git a/src/source/error_code.hpp b/src/mtconnect/source/error_code.hpp similarity index 95% rename from src/source/error_code.hpp rename to src/mtconnect/source/error_code.hpp index e269f8519..e3fd8b900 100644 --- a/src/source/error_code.hpp +++ b/src/mtconnect/source/error_code.hpp @@ -21,6 +21,8 @@ #include #include +#include "mtconnect/config.hpp" + namespace mtconnect::source { enum class ErrorCode { @@ -79,7 +81,7 @@ namespace mtconnect::source { } }; - inline const std::error_category &TheErrorCategory() + AGENT_SYMBOL_VISIBLE inline const std::error_category &TheErrorCategory() { static const ErrorCategory theErrorCategory {}; return theErrorCategory; diff --git a/src/source/loopback_source.cpp b/src/mtconnect/source/loopback_source.cpp similarity index 90% rename from src/source/loopback_source.cpp rename to src/mtconnect/source/loopback_source.cpp index 86dc9a765..3ea7da945 100644 --- a/src/source/loopback_source.cpp +++ b/src/mtconnect/source/loopback_source.cpp @@ -15,18 +15,18 @@ // limitations under the License. // -#include "source/loopback_source.hpp" - -#include "configuration/config_options.hpp" -#include "device_model/device.hpp" -#include "entity/xml_parser.hpp" -#include "pipeline/convert_sample.hpp" -#include "pipeline/deliver.hpp" -#include "pipeline/delta_filter.hpp" -#include "pipeline/duplicate_filter.hpp" -#include "pipeline/period_filter.hpp" -#include "pipeline/timestamp_extractor.hpp" -#include "pipeline/upcase_value.hpp" +#include "mtconnect/source/loopback_source.hpp" + +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/pipeline/convert_sample.hpp" +#include "mtconnect/pipeline/deliver.hpp" +#include "mtconnect/pipeline/delta_filter.hpp" +#include "mtconnect/pipeline/duplicate_filter.hpp" +#include "mtconnect/pipeline/period_filter.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" +#include "mtconnect/pipeline/upcase_value.hpp" using namespace std; diff --git a/src/source/loopback_source.hpp b/src/mtconnect/source/loopback_source.hpp similarity index 87% rename from src/source/loopback_source.hpp rename to src/mtconnect/source/loopback_source.hpp index b4f572641..5d9b85e07 100644 --- a/src/source/loopback_source.hpp +++ b/src/mtconnect/source/loopback_source.hpp @@ -17,15 +17,16 @@ #pragma once -#include "asset/asset.hpp" -#include "observation/observation.hpp" -#include "pipeline/pipeline.hpp" -#include "pipeline/pipeline_context.hpp" -#include "source/source.hpp" -#include "utilities.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/pipeline/pipeline_context.hpp" +#include "mtconnect/source/source.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect::source { - class LoopbackPipeline : public pipeline::Pipeline + class AGENT_LIB_API LoopbackPipeline : public pipeline::Pipeline { public: LoopbackPipeline(pipeline::PipelineContextPtr context, boost::asio::io_context::strand &st) @@ -37,7 +38,7 @@ namespace mtconnect::source { ConfigOptions m_options; }; - class LoopbackSource : public Source + class AGENT_LIB_API LoopbackSource : public Source { public: LoopbackSource(const std::string &name, boost::asio::io_context::strand &io, diff --git a/src/source/source.cpp b/src/mtconnect/source/source.cpp similarity index 95% rename from src/source/source.cpp rename to src/mtconnect/source/source.cpp index 40fe71715..f529d708b 100644 --- a/src/source/source.cpp +++ b/src/mtconnect/source/source.cpp @@ -15,9 +15,9 @@ // limitations under the License. // -#include "source/source.hpp" +#include "mtconnect/source/source.hpp" -#include "logging.hpp" +#include "mtconnect/logging.hpp" namespace mtconnect::source { source::SourcePtr SourceFactory::make(const std::string &factoryName, const std::string &sinkName, diff --git a/src/source/source.hpp b/src/mtconnect/source/source.hpp similarity index 94% rename from src/source/source.hpp rename to src/mtconnect/source/source.hpp index 0f6cf23fd..b98ce27b6 100644 --- a/src/source/source.hpp +++ b/src/mtconnect/source/source.hpp @@ -20,7 +20,8 @@ #include #include -#include "utilities.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" namespace mtconnect { namespace pipeline { @@ -36,7 +37,7 @@ namespace mtconnect { std::shared_ptr pipelineContext, const ConfigOptions &options, const boost::property_tree::ptree &block)>; - class Source : public std::enable_shared_from_this + class AGENT_LIB_API Source : public std::enable_shared_from_this { public: Source(boost::asio::io_context &io) : m_strand(io) {} @@ -64,7 +65,7 @@ namespace mtconnect { boost::asio::io_context::strand m_strand; }; - class SourceFactory + class AGENT_LIB_API SourceFactory { public: SourcePtr make(const std::string &factoryName, const std::string &sinkName, diff --git a/src/utilities.cpp b/src/mtconnect/utilities.cpp similarity index 92% rename from src/utilities.cpp rename to src/mtconnect/utilities.cpp index 7c2a6e695..2089997bf 100644 --- a/src/utilities.cpp +++ b/src/mtconnect/utilities.cpp @@ -15,7 +15,7 @@ // limitations under the License. // -#include "utilities.hpp" +#include "mtconnect/utilities.hpp" #include #include @@ -45,9 +45,9 @@ using namespace std; using namespace std::chrono; namespace mtconnect { - void mt_localtime(const time_t *time, struct tm *buf) { localtime_r(time, buf); } + AGENT_LIB_API void mt_localtime(const time_t *time, struct tm *buf) { localtime_r(time, buf); } - uint64_t parseTimeMicro(const std::string &aTime) + AGENT_LIB_API uint64_t parseTimeMicro(const std::string &aTime) { struct tm timeinfo; memset(&timeinfo, 0, sizeof(timeinfo)); @@ -119,7 +119,7 @@ namespace mtconnect { return false; } - string addNamespace(const string aPath, const string aPrefix) + AGENT_LIB_API string addNamespace(const string aPath, const string aPrefix) { if (aPrefix.empty()) return aPath; diff --git a/src/utilities.hpp b/src/mtconnect/utilities.hpp similarity index 88% rename from src/utilities.hpp rename to src/mtconnect/utilities.hpp index efb4a59de..d213785a9 100644 --- a/src/utilities.hpp +++ b/src/mtconnect/utilities.hpp @@ -17,58 +17,6 @@ #pragma once -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif -#if _MSC_VER > 1500 -#include -#else -#endif -#ifndef UINT64_MAX -#define UINT64_MAX 0xFFFFFFFFFFFFFFFFull -#endif -#ifndef NOMINMAX -#define NOMINMAX 1 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(_WIN32) || defined(_WIN64) -#ifndef _WINDOWS -#define _WINDOWS 1 -#endif -#define ISNAN(x) _isnan(x) -#if _MSC_VER < 1800 -#define NAN numeric_limits::quiet_NaN() -#endif -#if _MSC_VER >= 1900 -#define gets gets_s -#define timezone _timezone -#endif -typedef unsigned __int64 uint64_t; -#else -#define O_BINARY 0 -#define ISNAN(x) std::isnan(x) -#include -#include -#include -#include -#endif - #include #include #include @@ -76,7 +24,9 @@ typedef unsigned __int64 uint64_t; #include #include -#include +#include + +#include "mtconnect/config.hpp" //####### CONSTANTS ####### @@ -205,7 +155,7 @@ namespace mtconnect { return true; } - void mt_localtime(const time_t *time, struct tm *buf); + AGENT_LIB_API void mt_localtime(const time_t *time, struct tm *buf); // Get a specified time formatted inline std::string getCurrentTime(std::chrono::time_point timePoint, @@ -254,10 +204,7 @@ namespace mtconnect { inline uint64_t getCurrentTimeInSec() { return getCurrentTimeIn(); } - // Get the current time in number of seconds as an integer - uint64_t getCurrentTimeInSec(); - - uint64_t parseTimeMicro(const std::string &aTime); + AGENT_LIB_API uint64_t parseTimeMicro(const std::string &aTime); // Replace illegal XML characters with the correct corresponding characters inline void replaceIllegalCharacters(std::string &data) @@ -283,7 +230,7 @@ namespace mtconnect { } } - std::string addNamespace(const std::string aPath, const std::string aPrefix); + AGENT_LIB_API std::string addNamespace(const std::string aPath, const std::string aPrefix); // Ends with inline bool ends_with(const std::string &value, const std::string_view &ending) diff --git a/src/version.cpp b/src/mtconnect/version.cpp similarity index 97% rename from src/version.cpp rename to src/mtconnect/version.cpp index 5568d78d5..b27f769f2 100644 --- a/src/version.cpp +++ b/src/mtconnect/version.cpp @@ -14,7 +14,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -#include "version.h" +#include "mtconnect/version.h" #include #include diff --git a/src/version.h.in b/src/mtconnect/version.h.in similarity index 100% rename from src/version.h.in rename to src/mtconnect/version.h.in diff --git a/src/version.rc.in b/src/mtconnect/version.rc.in similarity index 100% rename from src/version.rc.in rename to src/mtconnect/version.rc.in diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e1e296d79..1ac613660 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,6 @@ include(GoogleTest) +enable_testing() add_library(sink_plugin_test SHARED testsink_service.cpp testsink_service.hpp) target_include_directories( @@ -18,8 +19,6 @@ target_compile_definitions(sink_plugin_test $<$:_WIN32_WINNT=${WINVER}>) target_compile_features(sink_plugin_test PUBLIC ${CXX_COMPILE_FEATURES}) -set_property(TARGET sink_plugin_test PROPERTY - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) target_link_libraries( sink_plugin_test @@ -68,8 +67,6 @@ if (APPLE) endif() target_compile_features(adapter_plugin_test PUBLIC ${CXX_COMPILE_FEATURES}) -set_property(TARGET adapter_plugin_test PROPERTY - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) target_link_libraries( adapter_plugin_test @@ -84,7 +81,7 @@ target_clangformat_setup(adapter_plugin_test) ########### -set(AGENT_TEST_LIB_SOURCES test_utilities.cpp agent_test_helper.cpp agent_test_helper.hpp test_utilities.hpp json_helper.hpp) +set(AGENT_TEST_LIB_SOURCES agent_test_helper.cpp agent_test_helper.hpp test_utilities.hpp json_helper.hpp) add_library(agent_test_lib STATIC ${AGENT_TEST_LIB_SOURCES}) target_include_directories( agent_test_lib @@ -93,12 +90,11 @@ target_include_directories( "${PROJECT_BINARY_DIR}/agent_lib" "${CMAKE_CURRENT_LIST_DIR}/../src" ) -set_property(TARGET agent_test_lib PROPERTY - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + target_link_libraries( agent_test_lib PUBLIC - agent_lib + agent_lib CONAN_PKG::gtest ) target_compile_definitions(agent_test_lib PUBLIC @@ -112,8 +108,6 @@ set_target_properties(agent_test_lib PROPERTIES FOLDER "test") macro(add_agent_test AGENT_TEST_NAME ADD_TEST_HELPER SUB_FOLDER) set(_sources ${AGENT_TEST_NAME}_test.cpp) add_executable(${AGENT_TEST_NAME}_test ${_sources}) - set_property(TARGET ${AGENT_TEST_NAME}_test PROPERTY - MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) # set_property(TARGET ${AGENT_TEST_NAME}_test PROPERTY LINK_FLAGS_DEBUG "${COVERAGE_FLAGS}") target_link_libraries(${AGENT_TEST_NAME}_test agent_lib agent_test_lib CONAN_PKG::gtest) @@ -131,7 +125,7 @@ macro(add_agent_test AGENT_TEST_NAME ADD_TEST_HELPER SUB_FOLDER) message(info ": Setting /bigobj for ${_sources}") set_property(SOURCE ${_sources} - PROPERTY COMPILE_FLAGS "/bigobj") + PROPERTY COMPILE_FLAGS "/bigobj") endif() target_clangformat_setup(${AGENT_TEST_NAME}_test) diff --git a/test/adapter_test.cpp b/test/adapter_test.cpp index e3a55bdef..c30b4ea52 100644 --- a/test/adapter_test.cpp +++ b/test/adapter_test.cpp @@ -27,9 +27,9 @@ #include #include -#include "configuration/config_options.hpp" -#include "pipeline/pipeline_context.hpp" -#include "source/adapter/shdr/shdr_adapter.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/pipeline/pipeline_context.hpp" +#include "mtconnect/source/adapter/shdr/shdr_adapter.hpp" using namespace std; using namespace mtconnect; @@ -38,6 +38,13 @@ using namespace mtconnect::source::adapter::shdr; namespace asio = boost::asio; using namespace std::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + TEST(AdapterTest, MultilineData) { asio::io_context ioc; diff --git a/test/agent_adapter_test.cpp b/test/agent_adapter_test.cpp index 1aafbd191..7ffdf82b8 100644 --- a/test/agent_adapter_test.cpp +++ b/test/agent_adapter_test.cpp @@ -26,15 +26,15 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "device_model/reference.hpp" -#include "pipeline/mtconnect_xml_transform.hpp" -#include "pipeline/response_document.hpp" -#include "printer/xml_printer.hpp" -#include "source/adapter/adapter.hpp" -#include "source/adapter/agent_adapter/agent_adapter.hpp" -#include "source/adapter/agent_adapter/url_parser.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/device_model/reference.hpp" +#include "mtconnect/pipeline/mtconnect_xml_transform.hpp" +#include "mtconnect/pipeline/response_document.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/agent_adapter/agent_adapter.hpp" +#include "mtconnect/source/adapter/agent_adapter/url_parser.hpp" #include "test_utilities.hpp" // Registers the fixture into the 'registry' @@ -52,6 +52,13 @@ using namespace mtconnect::observation; using status = boost::beast::http::status; namespace asio = boost::asio; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + struct MockPipelineContract : public PipelineContract { MockPipelineContract(DevicePtr &device) : m_device(device) {} diff --git a/test/agent_device_test.cpp b/test/agent_device_test.cpp index f30c21c3d..c0062f0be 100644 --- a/test/agent_device_test.cpp +++ b/test/agent_device_test.cpp @@ -22,12 +22,12 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "device_model/agent_device.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" -#include "version.h" +#include "mtconnect/agent.hpp" +#include "mtconnect/device_model/agent_device.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/version.h" using namespace std; using namespace mtconnect; @@ -41,6 +41,13 @@ namespace ip = boost::asio::ip; namespace sys = boost::system; namespace config = mtconnect::configuration; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class AgentDeviceTest : public testing::Test { protected: diff --git a/test/agent_test.cpp b/test/agent_test.cpp index c8b0f1b60..5b8371c49 100644 --- a/test/agent_test.cpp +++ b/test/agent_test.cpp @@ -26,12 +26,12 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "asset/file_asset.hpp" -#include "device_model/reference.hpp" -#include "printer/xml_printer.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/asset/file_asset.hpp" +#include "mtconnect/device_model/reference.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/source/adapter/adapter.hpp" #include "test_utilities.hpp" #if defined(WIN32) && _MSC_VER < 1500 @@ -48,6 +48,13 @@ using namespace mtconnect::observation; using status = boost::beast::http::status; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class AgentTest : public testing::Test { public: @@ -2869,3 +2876,62 @@ TEST_F(AgentTest, asset_should_also_work_using_post_with_assets) ASSERT_EQ((unsigned int)2, storage->getCount()); } } + +TEST_F(AgentTest, pre_start_hook_should_be_called) +{ + bool called = false; + Agent::Hook lambda = [&](Agent &agent) { called = true; }; + AgentTestHelper::Hook helperHook = [&](AgentTestHelper &helper) { + helper.getAgent()->beforeStartHooks().add(lambda); + }; + m_agentTestHelper->setAgentCreateHook(helperHook); + auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + + ASSERT_FALSE(called); + agent->start(); + ASSERT_TRUE(called); + agent->stop(); +} + +TEST_F(AgentTest, pre_initialize_hooks_should_be_called) +{ + bool called = false; + Agent::Hook lambda = [&](Agent &agent) { called = true; }; + AgentTestHelper::Hook helperHook = [&](AgentTestHelper &helper) { + helper.getAgent()->beforeInitializeHooks().add(lambda); + }; + m_agentTestHelper->setAgentCreateHook(helperHook); + m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + + ASSERT_TRUE(called); +} + +TEST_F(AgentTest, post_initialize_hooks_should_be_called) +{ + bool called = false; + Agent::Hook lambda = [&](Agent &agent) { called = true; }; + AgentTestHelper::Hook helperHook = [&](AgentTestHelper &helper) { + helper.getAgent()->afterInitializeHooks().add(lambda); + }; + m_agentTestHelper->setAgentCreateHook(helperHook); + m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + + ASSERT_TRUE(called); +} + +TEST_F(AgentTest, pre_stop_hook_should_be_called) +{ + static bool called = false; + Agent::Hook lambda = [&](Agent &agent) { called = true; }; + AgentTestHelper::Hook helperHook = [&lambda](AgentTestHelper &helper) { + helper.getAgent()->beforeStopHooks().add(lambda); + }; + m_agentTestHelper->setAgentCreateHook(helperHook); + auto agent = m_agentTestHelper->createAgent("/samples/test_config.xml", 8, 4, "2.0", 4, true); + + ASSERT_FALSE(called); + agent->start(); + ASSERT_FALSE(called); + agent->stop(); + ASSERT_TRUE(called); +} diff --git a/test/agent_test_helper.cpp b/test/agent_test_helper.cpp index 394d0e17b..8cc85fba0 100644 --- a/test/agent_test_helper.cpp +++ b/test/agent_test_helper.cpp @@ -23,9 +23,9 @@ #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "sink/rest_sink/server.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/sink/rest_sink/server.hpp" using namespace std; using namespace std::chrono; diff --git a/test/agent_test_helper.hpp b/test/agent_test_helper.hpp index c8db23b2c..c667453ec 100644 --- a/test/agent_test_helper.hpp +++ b/test/agent_test_helper.hpp @@ -24,18 +24,19 @@ #include -#include "agent.hpp" -#include "configuration/agent_config.hpp" -#include "configuration/config_options.hpp" -#include "pipeline/pipeline.hpp" -#include "sink/mqtt_sink/mqtt_service.hpp" -#include "sink/rest_sink/response.hpp" -#include "sink/rest_sink/rest_service.hpp" -#include "sink/rest_sink/routing.hpp" -#include "sink/rest_sink/server.hpp" -#include "sink/rest_sink/session.hpp" -#include "source/adapter/shdr/shdr_adapter.hpp" -#include "source/loopback_source.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/config.hpp" +#include "mtconnect/configuration/agent_config.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/sink/mqtt_sink/mqtt_service.hpp" +#include "mtconnect/sink/rest_sink/response.hpp" +#include "mtconnect/sink/rest_sink/rest_service.hpp" +#include "mtconnect/sink/rest_sink/routing.hpp" +#include "mtconnect/sink/rest_sink/server.hpp" +#include "mtconnect/sink/rest_sink/session.hpp" +#include "mtconnect/source/adapter/shdr/shdr_adapter.hpp" +#include "mtconnect/source/loopback_source.hpp" #include "test_utilities.hpp" namespace mtconnect { @@ -114,6 +115,8 @@ namespace observe = mtconnect::observation; class AgentTestHelper { public: + using Hook = std::function; + AgentTestHelper() : m_incomingIp("127.0.0.1"), m_strand(m_ioContext), m_socket(m_ioContext) {} ~AgentTestHelper() @@ -128,6 +131,8 @@ class AgentTestHelper auto session() { return m_session; } + void setAgentCreateHook(Hook &hook) { m_agentCreateHook = hook; } + // Helper method to test expected string, given optional query, & run tests void responseHelper(const char *file, int line, const mtconnect::sink::rest_sink::QueryMap &aQueries, xmlDocPtr *doc, @@ -191,9 +196,13 @@ class AgentTestHelper options.emplace(configuration::SchemaVersion, version); options.emplace(configuration::Pretty, true); options.emplace(configuration::Port, 0); + options.emplace(configuration::ServerIp, std::string("127.0.0.1")); options.emplace(configuration::JsonVersion, 1); m_agent = std::make_unique(m_ioContext, PROJECT_ROOT_DIR + file, options); + if (m_agentCreateHook) + m_agentCreateHook(*this); + m_context = std::make_shared(); m_context->m_contract = m_agent->makePipelineContract(); @@ -308,6 +317,8 @@ class AgentTestHelper mtconnect::sink::SinkFactory m_sinkFactory; mtconnect::source::SourceFactory m_sourceFactory; + + Hook m_agentCreateHook; }; struct XmlDocFreer diff --git a/test/asset_buffer_test.cpp b/test/asset_buffer_test.cpp index b83e0c94b..54d5c4076 100644 --- a/test/asset_buffer_test.cpp +++ b/test/asset_buffer_test.cpp @@ -26,9 +26,9 @@ #include #include "agent_test_helper.hpp" -#include "asset/asset_buffer.hpp" -#include "entity/entity.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/asset/asset_buffer.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/printer//xml_printer.hpp" #include "test_utilities.hpp" #if defined(WIN32) && _MSC_VER < 1500 @@ -42,6 +42,13 @@ using namespace mtconnect; using namespace mtconnect::entity; using namespace mtconnect::asset; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class AssetBufferTest : public testing::Test { protected: diff --git a/test/asset_test.cpp b/test/asset_test.cpp index b2231b944..82d3aebf9 100644 --- a/test/asset_test.cpp +++ b/test/asset_test.cpp @@ -26,15 +26,15 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "asset/asset.hpp" -#include "entity/entity.hpp" -#include "entity/xml_parser.hpp" -#include "entity/xml_printer.hpp" #include "json_helper.hpp" -#include "printer/xml_printer_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/entity/xml_printer.hpp" +#include "mtconnect/printer//xml_printer_helper.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -42,6 +42,13 @@ using namespace mtconnect; using namespace mtconnect::entity; using namespace mtconnect::asset; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class AssetTest : public testing::Test { protected: @@ -69,7 +76,7 @@ TEST_F(AssetTest, TestExtendedAsset) auto entity = parser.parse(Asset::getRoot(), doc, "1.7", errors); ASSERT_EQ(0, errors.size()); - auto asset = dynamic_cast(entity.get()); + auto asset = dynamic_cast(entity.get()); ASSERT_NE(nullptr, asset); entity::XmlPrinter printer; @@ -97,6 +104,6 @@ TEST_F(AssetTest, asset_should_parse_and_load_if_asset_id_is_missing_from_xml) auto entity = parser.parse(Asset::getRoot(), doc, "1.7", errors); ASSERT_EQ(0, errors.size()); - auto asset = dynamic_cast(entity.get()); + auto asset = dynamic_cast(entity.get()); ASSERT_NE(nullptr, asset); } diff --git a/test/change_observer_test.cpp b/test/change_observer_test.cpp index f08627aea..561e7d9f9 100644 --- a/test/change_observer_test.cpp +++ b/test/change_observer_test.cpp @@ -22,10 +22,17 @@ #include #include -#include "observation/change_observer.hpp" +#include "mtconnect/observation/change_observer.hpp" using namespace std::chrono_literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + namespace mtconnect { using namespace observation; class ChangeObserverTest : public testing::Test diff --git a/test/checkpoint_test.cpp b/test/checkpoint_test.cpp index 2540b516c..5af6a77b2 100644 --- a/test/checkpoint_test.cpp +++ b/test/checkpoint_test.cpp @@ -20,7 +20,7 @@ // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) #include "agent_test_helper.hpp" -#include "buffer/checkpoint.hpp" +#include "mtconnect/buffer/checkpoint.hpp" using namespace std; using namespace mtconnect; @@ -34,6 +34,13 @@ using namespace data_item; using namespace std::literals; using namespace date::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + inline ConditionPtr Cond(ObservationPtr &ptr) { return dynamic_pointer_cast(ptr); } class CheckpointTest : public testing::Test diff --git a/test/circular_buffer_test.cpp b/test/circular_buffer_test.cpp index 69c90a714..ca19a6ea2 100644 --- a/test/circular_buffer_test.cpp +++ b/test/circular_buffer_test.cpp @@ -20,8 +20,8 @@ // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) #include "agent_test_helper.hpp" -#include "buffer/checkpoint.hpp" -#include "buffer/circular_buffer.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/buffer/circular_buffer.hpp" using namespace std; using namespace mtconnect; @@ -35,6 +35,13 @@ using namespace data_item; using namespace std::literals; using namespace date::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + inline ConditionPtr Cond(ObservationPtr &ptr) { return dynamic_pointer_cast(ptr); } class CircularBufferTest : public testing::Test diff --git a/test/component_test.cpp b/test/component_test.cpp index 8d86631d5..53c8c583c 100644 --- a/test/component_test.cpp +++ b/test/component_test.cpp @@ -19,8 +19,8 @@ #include // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) -#include "device_model/component.hpp" -#include "device_model/device.hpp" +#include "mtconnect/device_model/component.hpp" +#include "mtconnect/device_model/device.hpp" using namespace std; using namespace mtconnect; @@ -28,6 +28,13 @@ using namespace device_model; using namespace data_item; using namespace entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class ComponentTest : public testing::Test { protected: diff --git a/test/composition_test.cpp b/test/composition_test.cpp index e97870ef1..b9e75879b 100644 --- a/test/composition_test.cpp +++ b/test/composition_test.cpp @@ -27,11 +27,11 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "device_model/composition.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/device_model/composition.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -39,6 +39,13 @@ using namespace mtconnect; using namespace device_model; using namespace entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class CompositionTest : public testing::Test { protected: diff --git a/test/config_parser_test.cpp b/test/config_parser_test.cpp index 0278ed26c..2bc8f9872 100644 --- a/test/config_parser_test.cpp +++ b/test/config_parser_test.cpp @@ -19,12 +19,19 @@ #include // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) -#include "configuration/parser.hpp" +#include "mtconnect/configuration/parser.hpp" using namespace mtconnect; using namespace configuration; using namespace std; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + TEST(ConfigParserTest, parse_simple_properties) { string cfg = R"DOC( diff --git a/test/config_test.cpp b/test/config_test.cpp index d1f888110..08c75b6c6 100644 --- a/test/config_test.cpp +++ b/test/config_test.cpp @@ -25,12 +25,12 @@ #include #include -#include "agent.hpp" -#include "configuration/agent_config.hpp" -#include "configuration/config_options.hpp" -#include "printer/xml_printer.hpp" -#include "sink/rest_sink/rest_service.hpp" -#include "source/adapter/shdr/shdr_adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/configuration/agent_config.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/sink/rest_sink/rest_service.hpp" +#include "mtconnect/source/adapter/shdr/shdr_adapter.hpp" #ifdef _WIN32 #include @@ -45,6 +45,13 @@ namespace fs = std::filesystem; using namespace std::chrono_literals; using namespace boost::algorithm; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + namespace { class ConfigTest : public testing::Test { @@ -494,7 +501,6 @@ namespace { ASSERT_TRUE(rest); const auto server = rest->getServer(); - // TODO: Get headers working again const auto &headers = server->getHttpHeaders(); ASSERT_EQ(1, headers.size()); diff --git a/test/connector_test.cpp b/test/connector_test.cpp index bbee7e091..d44fc62df 100644 --- a/test/connector_test.cpp +++ b/test/connector_test.cpp @@ -28,7 +28,7 @@ #include #include -#include "source/adapter/shdr/connector.hpp" +#include "mtconnect/source/adapter/shdr/connector.hpp" namespace date {}; using namespace date; @@ -44,6 +44,13 @@ using tcp = boost::asio::ip::tcp; namespace ip = boost::asio::ip; namespace sys = boost::system; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class TestConnector : public Connector { public: @@ -128,7 +135,8 @@ class ConnectorTest : public testing::Test template void runUntil(chrono::duration to, function pred) { - for (int runs = 0; runs < 10 && !pred(); runs++) + int runs; + for (runs = 0; runs < 50 && !pred(); runs++) { if (m_context.run_one_for(to) == 0) break; @@ -193,7 +201,7 @@ TEST_F(ConnectorTest, Connection) m_connector->start(m_port); - runUntil(2s, [this]() -> bool { return m_connected && m_connector->isConnected(); }); + runUntil(5s, [this]() -> bool { return m_connected && m_connector->isConnected(); }); EXPECT_FALSE(m_connector->m_disconnected); auto line = read(1s); diff --git a/test/coordinate_system_test.cpp b/test/coordinate_system_test.cpp index 587d19d49..3b9c380a0 100644 --- a/test/coordinate_system_test.cpp +++ b/test/coordinate_system_test.cpp @@ -26,10 +26,10 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -37,6 +37,13 @@ using namespace mtconnect; using namespace mtconnect::source::adapter; using namespace entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class CoordinateSystemTest : public testing::Test { protected: diff --git a/test/cutting_tool_test.cpp b/test/cutting_tool_test.cpp index 21ad82172..4ff96a0c8 100644 --- a/test/cutting_tool_test.cpp +++ b/test/cutting_tool_test.cpp @@ -26,17 +26,17 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "asset/cutting_tool.hpp" -#include "entity/entity.hpp" -#include "entity/json_printer.hpp" -#include "entity/xml_parser.hpp" -#include "entity/xml_printer.hpp" #include "json_helper.hpp" -#include "printer/xml_printer.hpp" -#include "printer/xml_printer_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/asset/cutting_tool.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/json_printer.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/entity/xml_printer.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/printer//xml_printer_helper.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -45,6 +45,13 @@ using namespace mtconnect::entity; using namespace mtconnect::source::adapter; using namespace mtconnect::asset; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class CuttingToolTest : public testing::Test { protected: diff --git a/test/data_item_mapping_test.cpp b/test/data_item_mapping_test.cpp index c5678796a..eda6f9229 100644 --- a/test/data_item_mapping_test.cpp +++ b/test/data_item_mapping_test.cpp @@ -21,10 +21,10 @@ #include -#include "observation/observation.hpp" -#include "pipeline/pipeline_context.hpp" -#include "pipeline/shdr_token_mapper.hpp" -#include "pipeline/timestamp_extractor.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/pipeline_context.hpp" +#include "mtconnect/pipeline/shdr_token_mapper.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" using namespace mtconnect; using namespace mtconnect::pipeline; @@ -34,6 +34,13 @@ using namespace device_model; using namespace data_item; using namespace std; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class MockPipelineContract : public PipelineContract { public: diff --git a/test/data_item_test.cpp b/test/data_item_test.cpp index 413e83650..178bb1ca0 100644 --- a/test/data_item_test.cpp +++ b/test/data_item_test.cpp @@ -19,8 +19,8 @@ #include // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) -#include "device_model/data_item/data_item.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using namespace std; using namespace mtconnect; @@ -28,6 +28,13 @@ using namespace mtconnect::source::adapter; using namespace mtconnect::entity; using namespace mtconnect::device_model::data_item; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class DataItemTest : public testing::Test { protected: diff --git a/test/data_set_test.cpp b/test/data_set_test.cpp index f936d94bf..e8b789040 100644 --- a/test/data_set_test.cpp +++ b/test/data_set_test.cpp @@ -21,10 +21,10 @@ #include -#include "agent.hpp" #include "agent_test_helper.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -35,6 +35,13 @@ using namespace mtconnect::observation; using namespace mtconnect::sink::rest_sink; using namespace mtconnect::buffer; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class DataSetTest : public testing::Test { protected: diff --git a/test/device_test.cpp b/test/device_test.cpp index 5dd1ac029..a0a728922 100644 --- a/test/device_test.cpp +++ b/test/device_test.cpp @@ -19,13 +19,20 @@ #include // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) -#include "device_model/device.hpp" +#include "mtconnect/device_model/device.hpp" using namespace std; using namespace mtconnect; using namespace entity; using namespace device_model; using namespace data_item; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class DeviceTest : public testing::Test { protected: diff --git a/test/duplicate_filter_test.cpp b/test/duplicate_filter_test.cpp index 990fb9952..a96d8e951 100644 --- a/test/duplicate_filter_test.cpp +++ b/test/duplicate_filter_test.cpp @@ -21,12 +21,12 @@ #include -#include "observation/observation.hpp" -#include "pipeline/delta_filter.hpp" -#include "pipeline/duplicate_filter.hpp" -#include "pipeline/period_filter.hpp" -#include "pipeline/pipeline.hpp" -#include "pipeline/shdr_token_mapper.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/delta_filter.hpp" +#include "mtconnect/pipeline/duplicate_filter.hpp" +#include "mtconnect/pipeline/period_filter.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/pipeline/shdr_token_mapper.hpp" using namespace mtconnect; using namespace mtconnect::pipeline; @@ -39,6 +39,13 @@ using namespace std; using namespace std::literals; using namespace std::chrono_literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class MockPipelineContract : public PipelineContract { public: diff --git a/test/embedded_ruby_test.cpp b/test/embedded_ruby_test.cpp index 64ea3829d..f5290eff7 100644 --- a/test/embedded_ruby_test.cpp +++ b/test/embedded_ruby_test.cpp @@ -39,16 +39,16 @@ #include #include -#include "agent.hpp" -#include "configuration/agent_config.hpp" -#include "configuration/config_options.hpp" -#include "device_model/data_item/data_item.hpp" -#include "pipeline/shdr_tokenizer.hpp" -#include "printer/xml_printer.hpp" -#include "ruby/ruby_smart_ptr.hpp" -#include "ruby/ruby_vm.hpp" -#include "sink/rest_sink/rest_service.hpp" -#include "source/adapter/shdr/shdr_adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/configuration/agent_config.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/pipeline/shdr_tokenizer.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/ruby/ruby_smart_ptr.hpp" +#include "mtconnect/ruby/ruby_vm.hpp" +#include "mtconnect/sink/rest_sink/rest_service.hpp" +#include "mtconnect/source/adapter/shdr/shdr_adapter.hpp" #ifdef _WIN32 #include @@ -56,6 +56,13 @@ #define chdir _chdir #endif +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + namespace { using namespace std; using namespace mtconnect; diff --git a/test/entity_parser_test.cpp b/test/entity_parser_test.cpp index 9ba0ca7dd..91a8f029b 100644 --- a/test/entity_parser_test.cpp +++ b/test/entity_parser_test.cpp @@ -26,17 +26,24 @@ #include #include -#include "agent.hpp" -#include "entity/entity.hpp" -#include "entity/xml_parser.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; using namespace mtconnect; using namespace mtconnect::entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class EntityParserTest : public testing::Test { protected: diff --git a/test/entity_printer_test.cpp b/test/entity_printer_test.cpp index 0fa14cb99..d8b844b54 100644 --- a/test/entity_printer_test.cpp +++ b/test/entity_printer_test.cpp @@ -28,18 +28,25 @@ #include -#include "agent.hpp" -#include "entity/entity.hpp" -#include "entity/xml_parser.hpp" -#include "entity/xml_printer.hpp" -#include "printer/xml_printer_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/entity/xml_printer.hpp" +#include "mtconnect/printer//xml_printer_helper.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using namespace std; using namespace mtconnect; using namespace mtconnect::entity; using namespace std::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class EntityPrinterTest : public testing::Test { protected: diff --git a/test/entity_test.cpp b/test/entity_test.cpp index 50880e28e..974c0992e 100644 --- a/test/entity_test.cpp +++ b/test/entity_test.cpp @@ -26,14 +26,21 @@ #include #include -#include "entity/entity.hpp" -#include "entity/factory.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/factory.hpp" using namespace std; using namespace std::literals; using namespace mtconnect; using namespace mtconnect::entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + static inline int64_t operator"" _i64(unsigned long long int i) { return int64_t(i); } class EntityTest : public testing::Test diff --git a/test/file_asset_test.cpp b/test/file_asset_test.cpp index b5c75d012..5a8c0aba9 100644 --- a/test/file_asset_test.cpp +++ b/test/file_asset_test.cpp @@ -26,15 +26,15 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "asset/asset.hpp" -#include "asset/file_asset.hpp" -#include "entity/xml_parser.hpp" -#include "entity/xml_printer.hpp" #include "json_helper.hpp" -#include "printer/xml_printer_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/asset/file_asset.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/entity/xml_printer.hpp" +#include "mtconnect/printer//xml_printer_helper.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -44,6 +44,13 @@ using namespace mtconnect::source::adapter; using namespace mtconnect::asset; using namespace mtconnect::printer; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class FileAssetTest : public testing::Test { protected: @@ -79,7 +86,7 @@ TEST_F(FileAssetTest, TestMinmalArchetype) auto entity = parser.parse(Asset::getRoot(), doc, "1.7", errors); ASSERT_EQ(0, errors.size()); - auto asset = dynamic_cast(entity.get()); + auto asset = dynamic_cast(entity.get()); ASSERT_NE(nullptr, asset); ASSERT_EQ("F1", asset->getAssetId()); @@ -137,7 +144,7 @@ TEST_F(FileAssetTest, TestMinmalFile) auto entity = parser.parse(Asset::getRoot(), doc, "1.7", errors); ASSERT_EQ(0, errors.size()); - auto asset = dynamic_cast(entity.get()); + auto asset = dynamic_cast(entity.get()); ASSERT_NE(nullptr, asset); EXPECT_EQ("F1", asset->getAssetId()); diff --git a/test/file_cache_test.cpp b/test/file_cache_test.cpp index 9d30232e6..049802002 100644 --- a/test/file_cache_test.cpp +++ b/test/file_cache_test.cpp @@ -30,7 +30,7 @@ #include #include -#include "sink/rest_sink/file_cache.hpp" +#include "mtconnect/sink/rest_sink/file_cache.hpp" #ifndef _WINDOWS #include @@ -40,6 +40,13 @@ using namespace std; using namespace mtconnect; using namespace mtconnect::sink::rest_sink; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + #define RESOURCE_ROOT PROJECT_ROOT_DIR "/test/resources" class FileCacheTest : public testing::Test diff --git a/test/globals_test.cpp b/test/globals_test.cpp index 73d26a51d..1db17c32e 100644 --- a/test/globals_test.cpp +++ b/test/globals_test.cpp @@ -22,11 +22,18 @@ #include #include -#include "utilities.hpp" +#include "mtconnect/utilities.hpp" using namespace std; using namespace mtconnect; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + TEST(GlobalsTest, IntToString) { ASSERT_EQ((string) "1234", to_string(1234)); diff --git a/test/http_server_test.cpp b/test/http_server_test.cpp index ae35d0ec5..9c64f9c35 100644 --- a/test/http_server_test.cpp +++ b/test/http_server_test.cpp @@ -32,8 +32,8 @@ #include #include -#include "logging.hpp" -#include "sink/rest_sink/server.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/sink/rest_sink/server.hpp" using namespace std; using namespace mtconnect; @@ -44,6 +44,13 @@ namespace beast = boost::beast; namespace http = boost::beast::http; using tcp = boost::asio::ip::tcp; +// main +int main(int argc, char* argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class Client { public: diff --git a/test/json_parser_test.cpp b/test/json_parser_test.cpp index 40cae7598..f36422994 100644 --- a/test/json_parser_test.cpp +++ b/test/json_parser_test.cpp @@ -28,15 +28,22 @@ #include -#include "entity/entity.hpp" -#include "entity/json_parser.cpp" -#include "entity/json_parser.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/json_parser.cpp" +#include "mtconnect/entity/json_parser.hpp" using json = nlohmann::json; using namespace std; using namespace mtconnect; using namespace mtconnect::entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class JsonParserTest : public testing::Test { protected: diff --git a/test/json_printer_asset_test.cpp b/test/json_printer_asset_test.cpp index bc25da63d..02d40c792 100644 --- a/test/json_printer_asset_test.cpp +++ b/test/json_printer_asset_test.cpp @@ -27,19 +27,19 @@ #include -#include "asset/cutting_tool.hpp" -#include "asset/file_asset.hpp" -#include "buffer/checkpoint.hpp" -#include "device_model/data_item/data_item.hpp" -#include "device_model/device.hpp" -#include "entity/xml_parser.hpp" #include "json_helper.hpp" -#include "observation/observation.hpp" -#include "parser/xml_parser.hpp" -#include "printer/json_printer.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/asset/cutting_tool.hpp" +#include "mtconnect/asset/file_asset.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/parser/xml_parser.hpp" +#include "mtconnect/printer//json_printer.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/utilities.hpp" #include "test_utilities.hpp" -#include "utilities.hpp" using json = nlohmann::json; using namespace std; @@ -47,6 +47,13 @@ using namespace mtconnect; using namespace mtconnect::buffer; using namespace mtconnect::asset; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class JsonPrinterAssetTest : public testing::Test { protected: diff --git a/test/json_printer_error_test.cpp b/test/json_printer_error_test.cpp index 2f063d749..147ce7967 100644 --- a/test/json_printer_error_test.cpp +++ b/test/json_printer_error_test.cpp @@ -27,18 +27,25 @@ #include -#include "buffer/checkpoint.hpp" -#include "device_model/data_item/data_item.hpp" -#include "device_model/device.hpp" #include "json_helper.hpp" -#include "observation/observation.hpp" -#include "printer/json_printer.hpp" -#include "utilities.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/printer//json_printer.hpp" +#include "mtconnect/utilities.hpp" using namespace std; using namespace mtconnect; using json = nlohmann::json; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class JsonPrinterErrorTest : public testing::Test { protected: diff --git a/test/json_printer_probe_test.cpp b/test/json_printer_probe_test.cpp index 40324b859..064c757f8 100644 --- a/test/json_printer_probe_test.cpp +++ b/test/json_printer_probe_test.cpp @@ -27,23 +27,30 @@ #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "buffer/checkpoint.hpp" -#include "device_model/data_item/data_item.hpp" -#include "device_model/device.hpp" #include "json_helper.hpp" -#include "observation/observation.hpp" -#include "parser/xml_parser.hpp" -#include "printer/json_printer.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/parser/xml_parser.hpp" +#include "mtconnect/printer//json_printer.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/utilities.hpp" #include "test_utilities.hpp" -#include "utilities.hpp" using namespace std; using namespace mtconnect; using json = nlohmann::json; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class JsonPrinterProbeTest : public testing::Test { protected: diff --git a/test/json_printer_stream_test.cpp b/test/json_printer_stream_test.cpp index 48cdbc498..d37023f79 100644 --- a/test/json_printer_stream_test.cpp +++ b/test/json_printer_stream_test.cpp @@ -27,16 +27,16 @@ #include -#include "buffer/checkpoint.hpp" -#include "device_model/data_item/data_item.hpp" -#include "device_model/device.hpp" #include "json_helper.hpp" -#include "observation/observation.hpp" -#include "parser/xml_parser.hpp" -#include "printer/json_printer.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/parser/xml_parser.hpp" +#include "mtconnect/printer//json_printer.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/utilities.hpp" #include "test_utilities.hpp" -#include "utilities.hpp" using json = nlohmann::json; using namespace std; @@ -45,6 +45,13 @@ using namespace mtconnect::buffer; using namespace mtconnect::observation; using namespace mtconnect::entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class JsonPrinterStreamTest : public testing::Test { protected: diff --git a/test/json_printer_test.cpp b/test/json_printer_test.cpp index efaaebffa..815983cf8 100644 --- a/test/json_printer_test.cpp +++ b/test/json_printer_test.cpp @@ -30,20 +30,27 @@ #include -#include "agent.hpp" -#include "configuration/config_options.hpp" -#include "entity/entity.hpp" -#include "entity/json_printer.hpp" -#include "entity/xml_parser.hpp" -#include "entity/xml_printer.hpp" -#include "printer/xml_printer_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/configuration/config_options.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/json_printer.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/entity/xml_printer.hpp" +#include "mtconnect/printer//xml_printer_helper.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; using namespace mtconnect; using namespace mtconnect::entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class JsonPrinterTest : public testing::Test { protected: diff --git a/test/kinematics_test.cpp b/test/kinematics_test.cpp index 35a735bd2..1dd927cb1 100644 --- a/test/kinematics_test.cpp +++ b/test/kinematics_test.cpp @@ -26,16 +26,23 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; using namespace mtconnect; using namespace mtconnect::entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class KinematicsTest : public testing::Test { protected: diff --git a/test/mqtt_adapter_test.cpp b/test/mqtt_adapter_test.cpp index bb249bf66..9a14699be 100644 --- a/test/mqtt_adapter_test.cpp +++ b/test/mqtt_adapter_test.cpp @@ -27,8 +27,8 @@ #include #include -#include "pipeline/pipeline_context.hpp" -#include "source/adapter/mqtt/mqtt_adapter.hpp" +#include "mtconnect/pipeline/pipeline_context.hpp" +#include "mtconnect/source/adapter/mqtt/mqtt_adapter.hpp" using namespace std; using namespace mtconnect; @@ -36,6 +36,13 @@ using namespace mtconnect::source::adapter; using namespace mtconnect::source::adapter::mqtt_adapter; namespace asio = boost::asio; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class MqttAdapterTest : public testing::Test { protected: diff --git a/test/mqtt_isolated_test.cpp b/test/mqtt_isolated_test.cpp index ad08765a2..733caa008 100644 --- a/test/mqtt_isolated_test.cpp +++ b/test/mqtt_isolated_test.cpp @@ -23,13 +23,13 @@ #include #include "agent_test_helper.hpp" -#include "buffer/checkpoint.hpp" -#include "device_model/data_item/data_item.hpp" -#include "entity/json_parser.hpp" -#include "mqtt/mqtt_client_impl.hpp" -#include "mqtt/mqtt_server_impl.hpp" -#include "printer/json_printer.hpp" -#include "sink/mqtt_sink/mqtt_service.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/entity/json_parser.hpp" +#include "mtconnect/mqtt/mqtt_client_impl.hpp" +#include "mtconnect/mqtt/mqtt_server_impl.hpp" +#include "mtconnect/printer//json_printer.hpp" +#include "mtconnect/sink/mqtt_sink/mqtt_service.hpp" using namespace std; using namespace mtconnect; @@ -49,6 +49,13 @@ const string ServerKeyFile {PROJECT_ROOT_DIR "/test/resources/user.key"}; const string ServerDhFile {PROJECT_ROOT_DIR "/test/resources/dh2048.pem"}; const string ClientCA(PROJECT_ROOT_DIR "/test/resources/clientca.crt"); +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class MqttIsolatedUnitTest : public testing::Test { protected: @@ -59,10 +66,9 @@ class MqttIsolatedUnitTest : public testing::Test } void TearDown() override - { + { if (m_client) { - m_client->stop(); while (m_agentTestHelper->m_ioContext.run_one_for(10ms)) ; @@ -75,13 +81,13 @@ class MqttIsolatedUnitTest : public testing::Test m_agentTestHelper->m_ioContext.run_for(500ms); m_server.reset(); } - + m_agentTestHelper.reset(); m_jsonPrinter.reset(); } void createServer(const ConfigOptions &options) - { + { bool withTlsOption = IsOptionSet(options, configuration::MqttTls); if (withTlsOption) @@ -133,7 +139,7 @@ class MqttIsolatedUnitTest : public testing::Test void createClient(const ConfigOptions &options, unique_ptr &&handler) { - bool withTlsOption = IsOptionSet(options, configuration::MqttTls); + bool withTlsOption = IsOptionSet(options, configuration::MqttTls); ConfigOptions opts(options); @@ -152,7 +158,7 @@ class MqttIsolatedUnitTest : public testing::Test } bool startClient() - { + { bool started = m_client && m_client->start(); if (started) { @@ -169,16 +175,12 @@ class MqttIsolatedUnitTest : public testing::Test uint16_t m_port {0}; }; - TEST_F(MqttIsolatedUnitTest, mqtt_client_should_connect_to_broker) { - ConfigOptions options{{ServerIp, "127.0.0.1"s}, - {MqttPort, 0}, - {MqttTls, false}, - {AutoAvailable, false}, - {MqttCaCert, MqttClientCACert}, - {RealTime, false}}; - + ConfigOptions options { + {ServerIp, "127.0.0.1"s}, {MqttPort, 0}, {MqttTls, false}, {AutoAvailable, false}, + {MqttCaCert, MqttClientCACert}, {RealTime, false}}; + createServer(options); startServer(); @@ -215,75 +217,77 @@ TEST_F(MqttIsolatedUnitTest, mqtt_tcp_client_should_receive_loopback_publication client->set_clean_session(true); client->set_keep_alive_sec(30); - client->set_connack_handler( - [&client, &pid_sub1](bool sp, mqtt::connect_return_code connack_return_code) { - std::cout << "Connack handler called" << std::endl; - std::cout << "Session Present: " << std::boolalpha << sp << std::endl; - std::cout << "Connack Return Code: " << connack_return_code << std::endl; - if (connack_return_code == mqtt::connect_return_code::accepted) - { - pid_sub1 = client->acquire_unique_packet_id(); - - client->async_subscribe(pid_sub1, "mqtt_tcp_client_cpp/topic1", MQTT_NS::qos::at_most_once, - //[optional] checking async_subscribe completion code - [](MQTT_NS::error_code ec) { - EXPECT_FALSE(ec); - std::cout << "async_tcp_subscribe callback: " << ec.message() - << std::endl; - }); - } - return true; - }); - client->set_close_handler([] { std::cout << "closed" << std::endl; }); - - client->set_suback_handler([&client, &pid_sub1](std::uint16_t packet_id, - std::vector results) { - std::cout << "suback received. packet_id: " << packet_id << std::endl; - for (auto const &e : results) + client->set_connack_handler([&client, &pid_sub1](bool sp, + mqtt::connect_return_code connack_return_code) { + std::cout << "Connack handler called" << std::endl; + std::cout << "Session Present: " << std::boolalpha << sp << std::endl; + std::cout << "Connack Return Code: " << connack_return_code << std::endl; + if (connack_return_code == mqtt::connect_return_code::accepted) { - std::cout << "subscribe result: " << e << std::endl; - } + pid_sub1 = client->acquire_unique_packet_id(); - if (packet_id == pid_sub1) - { - client->async_publish("mqtt_tcp_client_cpp/topic1", "test1", MQTT_NS::qos::at_most_once, - //[optional] checking async_publish completion code - [](MQTT_NS::error_code ec) { - EXPECT_FALSE(ec); - - std::cout << "async_tcp_publish callback: " << ec.message() << std::endl; - EXPECT_EQ(ec.message(), "Success"); - }); - return true; + client->async_subscribe(pid_sub1, "mqtt_tcp_client_cpp/topic1", MQTT_NS::qos::at_most_once, + //[optional] checking async_subscribe completion code + [](MQTT_NS::error_code ec) { + EXPECT_FALSE(ec); + std::cout << "async_tcp_subscribe callback: " << ec.message() + << std::endl; + }); } - return true; }); + client->set_close_handler([] { std::cout << "closed" << std::endl; }); + + client->set_suback_handler( + [&client, &pid_sub1](std::uint16_t packet_id, std::vector results) { + std::cout << "suback received. packet_id: " << packet_id << std::endl; + for (auto const &e : results) + { + std::cout << "subscribe result: " << e << std::endl; + } + + if (packet_id == pid_sub1) + { + client->async_publish("mqtt_tcp_client_cpp/topic1", "test1", MQTT_NS::qos::at_most_once, + //[optional] checking async_publish completion code + [](MQTT_NS::error_code ec) { + EXPECT_FALSE(ec); + + std::cout << "async_tcp_publish callback: " << ec.message() + << std::endl; + EXPECT_EQ(ec.message(), "Success"); + }); + return true; + } + + return true; + }); client->set_close_handler([] { std::cout << "closed" << std::endl; }); - client->set_suback_handler([&client, &pid_sub1](std::uint16_t packet_id, - std::vector results) { - std::cout << "suback received. packet_id: " << packet_id << std::endl; - for (auto const &e : results) - { - std::cout << "subscribe result: " << e << std::endl; - } + client->set_suback_handler( + [&client, &pid_sub1](std::uint16_t packet_id, std::vector results) { + std::cout << "suback received. packet_id: " << packet_id << std::endl; + for (auto const &e : results) + { + std::cout << "subscribe result: " << e << std::endl; + } - if (packet_id == pid_sub1) - { - client->async_publish("mqtt_tcp_client_cpp/topic1", "test1", MQTT_NS::qos::at_most_once, - //[optional] checking async_publish completion code - [packet_id](MQTT_NS::error_code ec) { - EXPECT_FALSE(ec); - - std::cout << "async_tcp_publish callback: " << ec.message() << std::endl; - ASSERT_TRUE(packet_id); - }); - } + if (packet_id == pid_sub1) + { + client->async_publish("mqtt_tcp_client_cpp/topic1", "test1", MQTT_NS::qos::at_most_once, + //[optional] checking async_publish completion code + [packet_id](MQTT_NS::error_code ec) { + EXPECT_FALSE(ec); - return true; - }); + std::cout << "async_tcp_publish callback: " << ec.message() + << std::endl; + ASSERT_TRUE(packet_id); + }); + } + + return true; + }); bool received = false; client->set_publish_handler([&client, &received](mqtt::optional packet_id, @@ -313,9 +317,9 @@ TEST_F(MqttIsolatedUnitTest, mqtt_tcp_client_should_receive_loopback_publication } TEST_F(MqttIsolatedUnitTest, mqtt_tls_client_should_receive_loopback_publication) -{ +{ GTEST_SKIP(); - + ConfigOptions options {{ServerIp, "127.0.0.1"s}, {MqttPort, 0}, {MqttTls, true}, @@ -323,7 +327,7 @@ TEST_F(MqttIsolatedUnitTest, mqtt_tls_client_should_receive_loopback_publication {TlsCertificateChain, ServerCertFile}, {TlsPrivateKey, ServerKeyFile}, {TlsDHKey, ServerDhFile}, - {TlsVerifyClientCertificate,true}, + {TlsVerifyClientCertificate, true}, {TlsClientCAs, MqttClientCACert}, {MqttCaCert, MqttClientCACert}, {MqttCert, MqttClientCert}, @@ -470,8 +474,8 @@ TEST_F(MqttIsolatedUnitTest, should_connect_using_tls) /*{TlsVerifyClientCertificate, true}, {TlsClientCAs, ClientCA},*/ {MqttCaCert, MqttClientCACert}, - /* {MqttCert, MqttClientCert}, - {MqttPrivateKey, MqttClientKey},*/ + /* {MqttCert, MqttClientCert}, + {MqttPrivateKey, MqttClientKey},*/ {RealTime, false}}; createServer(options); diff --git a/test/mqtt_sink_test.cpp b/test/mqtt_sink_test.cpp index 6665b27d3..213ad4c37 100644 --- a/test/mqtt_sink_test.cpp +++ b/test/mqtt_sink_test.cpp @@ -23,14 +23,14 @@ #include #include "agent_test_helper.hpp" -#include "buffer/checkpoint.hpp" -#include "device_model/data_item/data_item.hpp" -#include "entity/entity.hpp" -#include "entity/json_parser.hpp" -#include "mqtt/mqtt_client_impl.hpp" -#include "mqtt/mqtt_server_impl.hpp" -#include "printer/json_printer.hpp" -#include "sink/mqtt_sink/mqtt_service.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/json_parser.hpp" +#include "mtconnect/mqtt/mqtt_client_impl.hpp" +#include "mtconnect/mqtt/mqtt_server_impl.hpp" +#include "mtconnect/printer//json_printer.hpp" +#include "mtconnect/sink/mqtt_sink/mqtt_service.hpp" using namespace std; using namespace mtconnect; @@ -39,6 +39,13 @@ using namespace mtconnect::sink::mqtt_sink; using namespace mtconnect::asset; using namespace mtconnect::configuration; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + using json = nlohmann::json; class MqttSinkTest : public testing::Test diff --git a/test/mtconnect_xml_transform_test.cpp b/test/mtconnect_xml_transform_test.cpp index 77f504bcc..32e9cdc0f 100644 --- a/test/mtconnect_xml_transform_test.cpp +++ b/test/mtconnect_xml_transform_test.cpp @@ -21,10 +21,10 @@ #include -#include "agent.hpp" -#include "entity/entity.hpp" -#include "pipeline/mtconnect_xml_transform.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/pipeline/mtconnect_xml_transform.hpp" +#include "mtconnect/printer//xml_printer.hpp" using namespace mtconnect; using namespace mtconnect::pipeline; @@ -34,6 +34,13 @@ using namespace std; using namespace date::literals; using namespace std::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class MockPipelineContract : public PipelineContract { public: diff --git a/test/observation_test.cpp b/test/observation_test.cpp index 3e632e2d0..867e549b3 100644 --- a/test/observation_test.cpp +++ b/test/observation_test.cpp @@ -21,13 +21,13 @@ #include -#include "device_model/data_item/data_item.hpp" -#include "entity/json_printer.hpp" -#include "entity/xml_parser.hpp" -#include "entity/xml_printer.hpp" -#include "observation/observation.hpp" -#include "pipeline/convert_sample.hpp" -#include "printer/xml_printer_helper.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/entity/json_printer.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/entity/xml_printer.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/convert_sample.hpp" +#include "mtconnect/printer//xml_printer_helper.hpp" #include "test_utilities.hpp" using namespace std; @@ -40,6 +40,13 @@ using namespace data_item; using namespace std::literals; using namespace date::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class ObservationTest : public testing::Test { protected: diff --git a/test/period_filter_test.cpp b/test/period_filter_test.cpp index cc2600742..351a950ca 100644 --- a/test/period_filter_test.cpp +++ b/test/period_filter_test.cpp @@ -21,13 +21,13 @@ #include -#include "observation/observation.hpp" -#include "pipeline/deliver.hpp" -#include "pipeline/delta_filter.hpp" -#include "pipeline/duplicate_filter.hpp" -#include "pipeline/period_filter.hpp" -#include "pipeline/pipeline.hpp" -#include "pipeline/shdr_token_mapper.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/deliver.hpp" +#include "mtconnect/pipeline/delta_filter.hpp" +#include "mtconnect/pipeline/duplicate_filter.hpp" +#include "mtconnect/pipeline/period_filter.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/pipeline/shdr_token_mapper.hpp" using namespace mtconnect; using namespace mtconnect::pipeline; @@ -40,6 +40,13 @@ using namespace std; using namespace std::literals; using namespace std::chrono_literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + struct MockPipelineContract : public PipelineContract { MockPipelineContract(std::map &items) : m_dataItems(items) {} diff --git a/test/pipeline_deliver_test.cpp b/test/pipeline_deliver_test.cpp index 8b1aba6b9..6399837f1 100644 --- a/test/pipeline_deliver_test.cpp +++ b/test/pipeline_deliver_test.cpp @@ -22,13 +22,13 @@ #include #include "agent_test_helper.hpp" -#include "observation/observation.hpp" -#include "pipeline/deliver.hpp" -#include "pipeline/delta_filter.hpp" -#include "pipeline/duplicate_filter.hpp" -#include "pipeline/pipeline.hpp" -#include "pipeline/shdr_token_mapper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/deliver.hpp" +#include "mtconnect/pipeline/delta_filter.hpp" +#include "mtconnect/pipeline/duplicate_filter.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/pipeline/shdr_token_mapper.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using namespace mtconnect; using namespace mtconnect::source::adapter; @@ -39,6 +39,13 @@ using namespace std::literals; using namespace std::chrono_literals; using namespace mtconnect::sink::rest_sink; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class PipelineDeliverTest : public testing::Test { protected: diff --git a/test/pipeline_edit_test.cpp b/test/pipeline_edit_test.cpp index 107064191..b2ea1c830 100644 --- a/test/pipeline_edit_test.cpp +++ b/test/pipeline_edit_test.cpp @@ -22,13 +22,13 @@ #include #include "agent_test_helper.hpp" -#include "observation/observation.hpp" -#include "pipeline/deliver.hpp" -#include "pipeline/delta_filter.hpp" -#include "pipeline/duplicate_filter.hpp" -#include "pipeline/pipeline.hpp" -#include "pipeline/shdr_token_mapper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/deliver.hpp" +#include "mtconnect/pipeline/delta_filter.hpp" +#include "mtconnect/pipeline/duplicate_filter.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/pipeline/shdr_token_mapper.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using namespace mtconnect; using namespace mtconnect::source::adapter; @@ -40,6 +40,13 @@ using namespace std::literals; using namespace std::chrono_literals; using namespace mtconnect::sink::rest_sink; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + using TransformFun = std::function; class TestTransform : public Transform { diff --git a/test/python_transform_test.cpp b/test/python_transform_test.cpp index 8f06cab6d..06fff49dc 100644 --- a/test/python_transform_test.cpp +++ b/test/python_transform_test.cpp @@ -45,6 +45,13 @@ using namespace std::literals; using namespace std::chrono_literals; using namespace mtconnect::rest_sink; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class PythonTransformTest : public testing::Test { protected: diff --git a/test/qif_document_test.cpp b/test/qif_document_test.cpp index fc986d7d2..9e4ec6afd 100644 --- a/test/qif_document_test.cpp +++ b/test/qif_document_test.cpp @@ -27,18 +27,18 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "asset/asset.hpp" -#include "asset/qif_document.hpp" -#include "entity/entity.hpp" -#include "entity/json_printer.hpp" -#include "entity/xml_parser.hpp" -#include "entity/xml_printer.hpp" #include "json_helper.hpp" -#include "printer/xml_printer.hpp" -#include "printer/xml_printer_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/asset/qif_document.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/json_printer.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/entity/xml_printer.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/printer//xml_printer_helper.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -48,6 +48,13 @@ using namespace mtconnect::source::adapter; using namespace mtconnect::asset; using namespace mtconnect::printer; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class QIFDocumentTest : public testing::Test { protected: diff --git a/test/qname_test.cpp b/test/qname_test.cpp index a47a0294e..9462d1e0e 100644 --- a/test/qname_test.cpp +++ b/test/qname_test.cpp @@ -19,11 +19,18 @@ #include // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) -#include "entity/qname.hpp" +#include "mtconnect/entity/qname.hpp" using namespace mtconnect::entity; using namespace std; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + TEST(QNameTest, should_handle_simple_name_without_prefix) { QName qname("SomeName"); diff --git a/test/raw_material_test.cpp b/test/raw_material_test.cpp index 114e65cae..f9586c1df 100644 --- a/test/raw_material_test.cpp +++ b/test/raw_material_test.cpp @@ -27,18 +27,18 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "asset/asset.hpp" -#include "asset/raw_material.hpp" -#include "entity/entity.hpp" -#include "entity/json_printer.hpp" -#include "entity/xml_parser.hpp" -#include "entity/xml_printer.hpp" #include "json_helper.hpp" -#include "printer/xml_printer.hpp" -#include "printer/xml_printer_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/asset/raw_material.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/entity/json_printer.hpp" +#include "mtconnect/entity/xml_parser.hpp" +#include "mtconnect/entity/xml_printer.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/printer//xml_printer_helper.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -48,6 +48,13 @@ using namespace mtconnect::source::adapter; using namespace mtconnect::asset; using namespace mtconnect::printer; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class RawMaterialTest : public testing::Test { protected: diff --git a/test/references_test.cpp b/test/references_test.cpp index 39e380d69..c87835386 100644 --- a/test/references_test.cpp +++ b/test/references_test.cpp @@ -26,10 +26,10 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -38,6 +38,13 @@ using namespace device_model; using namespace mtconnect::source::adapter; using namespace entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class ReferencesTest : public testing::Test { protected: diff --git a/test/relationship_test.cpp b/test/relationship_test.cpp index eba64cc44..86d330d7f 100644 --- a/test/relationship_test.cpp +++ b/test/relationship_test.cpp @@ -26,11 +26,11 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" -#include "entity/json_printer.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/entity/json_printer.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -39,6 +39,13 @@ using namespace mtconnect::source::adapter; using namespace entity; using namespace device_model; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class RelationshipTest : public testing::Test { protected: @@ -70,10 +77,11 @@ TEST_F(RelationshipTest, ParseDeviceAndComponentRelationships) auto rels = clc->getList("Relationships"); - ASSERT_EQ(2, rels->size()); + ASSERT_EQ(3, rels->size()); auto it = rels->begin(); + EXPECT_EQ("ComponentRelationship", (*it)->getName()); EXPECT_EQ("ref1", (*it)->get("id")); EXPECT_EQ("Power", (*it)->get("name")); EXPECT_EQ("PEER", (*it)->get("type")); @@ -82,6 +90,7 @@ TEST_F(RelationshipTest, ParseDeviceAndComponentRelationships) it++; + EXPECT_EQ("DeviceRelationship", (*it)->getName()); EXPECT_EQ("ref2", (*it)->get("id")); EXPECT_EQ("coffee", (*it)->get("name")); EXPECT_EQ("PARENT", (*it)->get("type")); @@ -89,6 +98,18 @@ TEST_F(RelationshipTest, ParseDeviceAndComponentRelationships) EXPECT_EQ("AUXILIARY", (*it)->get("role")); EXPECT_EQ("http://127.0.0.1:2000/coffee", (*it)->get("href")); EXPECT_EQ("bfccbfb0-5111-0138-6cd5-0c85909298d9", (*it)->get("deviceUuidRef")); + + it++; + + EXPECT_EQ("AssetRelationship", (*it)->getName()); + EXPECT_EQ("ref3", (*it)->get("id")); + EXPECT_EQ("asset", (*it)->get("name")); + EXPECT_EQ("CuttingTool", (*it)->get("assetType")); + EXPECT_EQ("PEER", (*it)->get("type")); + EXPECT_EQ("NON_CRITICAL", (*it)->get("criticality")); + EXPECT_EQ("http://127.0.0.1:2000/asset/f7de7350-6f7a-013b-ca4c-4e7f553bbb76", + (*it)->get("href")); + EXPECT_EQ("f7de7350-6f7a-013b-ca4c-4e7f553bbb76", (*it)->get("assetIdRef")); } #define CONFIGURATION_PATH "//m:Rotary[@id='c']/m:Configuration" @@ -100,7 +121,7 @@ TEST_F(RelationshipTest, XmlPrinting) PARSE_XML_RESPONSE("/probe"); ASSERT_XML_PATH_COUNT(doc, RELATIONSHIPS_PATH, 1); - ASSERT_XML_PATH_COUNT(doc, RELATIONSHIPS_PATH "/*", 2); + ASSERT_XML_PATH_COUNT(doc, RELATIONSHIPS_PATH "/*", 3); ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:ComponentRelationship@id", "ref1"); ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:ComponentRelationship@name", "Power"); @@ -119,6 +140,17 @@ TEST_F(RelationshipTest, XmlPrinting) "http://127.0.0.1:2000/coffee"); ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:DeviceRelationship@deviceUuidRef", "bfccbfb0-5111-0138-6cd5-0c85909298d9"); + + ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:AssetRelationship@id", "ref3"); + ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:AssetRelationship@name", "asset"); + ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:AssetRelationship@type", "PEER"); + ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:AssetRelationship@assetType", "CuttingTool"); + ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:AssetRelationship@criticality", + "NON_CRITICAL"); + ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:AssetRelationship@assetIdRef", + "f7de7350-6f7a-013b-ca4c-4e7f553bbb76"); + ASSERT_XML_PATH_EQUAL(doc, RELATIONSHIPS_PATH "/m:AssetRelationship@href", + "http://127.0.0.1:2000/asset/f7de7350-6f7a-013b-ca4c-4e7f553bbb76"); } } @@ -134,7 +166,7 @@ TEST_F(RelationshipTest, JsonPrinting) auto relationships = rotary.at("/Configuration/Relationships"_json_pointer); ASSERT_TRUE(relationships.is_array()); - ASSERT_EQ(2_S, relationships.size()); + ASSERT_EQ(3_S, relationships.size()); auto crel = relationships.at(0); auto cfields = crel.at("/ComponentRelationship"_json_pointer); @@ -153,5 +185,15 @@ TEST_F(RelationshipTest, JsonPrinting) EXPECT_EQ("AUXILIARY", dfields["role"]); EXPECT_EQ("http://127.0.0.1:2000/coffee", dfields["href"]); EXPECT_EQ("bfccbfb0-5111-0138-6cd5-0c85909298d9", dfields["deviceUuidRef"]); + + auto arel = relationships.at(2); + auto afields = arel.at("/AssetRelationship"_json_pointer); + EXPECT_EQ("ref3", afields["id"]); + EXPECT_EQ("asset", afields["name"]); + EXPECT_EQ("PEER", afields["type"]); + EXPECT_EQ("CuttingTool", afields["assetType"]); + EXPECT_EQ("NON_CRITICAL", afields["criticality"]); + EXPECT_EQ("http://127.0.0.1:2000/asset/f7de7350-6f7a-013b-ca4c-4e7f553bbb76", afields["href"]); + EXPECT_EQ("f7de7350-6f7a-013b-ca4c-4e7f553bbb76", afields["assetIdRef"]); } } diff --git a/test/response_document_test.cpp b/test/response_document_test.cpp index 30a6bc5ab..92a650798 100644 --- a/test/response_document_test.cpp +++ b/test/response_document_test.cpp @@ -21,10 +21,10 @@ #include -#include "agent.hpp" -#include "entity/entity.hpp" -#include "pipeline/mtconnect_xml_transform.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/pipeline/mtconnect_xml_transform.hpp" +#include "mtconnect/printer//xml_printer.hpp" using namespace mtconnect; using namespace mtconnect::pipeline; @@ -36,6 +36,13 @@ using namespace std; using namespace date::literals; using namespace std::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class MockPipelineContract : public PipelineContract { public: diff --git a/test/routing_test.cpp b/test/routing_test.cpp index 9b7216c80..b26a86576 100644 --- a/test/routing_test.cpp +++ b/test/routing_test.cpp @@ -26,14 +26,21 @@ #include #include -#include "sink/rest_sink/response.hpp" -#include "sink/rest_sink/routing.hpp" +#include "mtconnect/sink/rest_sink/response.hpp" +#include "mtconnect/sink/rest_sink/routing.hpp" using namespace std; using namespace mtconnect; using namespace mtconnect::sink::rest_sink; using verb = boost::beast::http::verb; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class RoutingTest : public testing::Test { protected: diff --git a/test/sensor_configuration_test.cpp b/test/sensor_configuration_test.cpp index 277890e11..1d94d46ab 100644 --- a/test/sensor_configuration_test.cpp +++ b/test/sensor_configuration_test.cpp @@ -26,10 +26,10 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -37,6 +37,13 @@ using namespace mtconnect; using namespace mtconnect::source::adapter; using namespace entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class SensorConfigurationTest : public testing::Test { protected: diff --git a/test/shdr_tokenizer_test.cpp b/test/shdr_tokenizer_test.cpp index a2ad16b87..1e426eb2d 100644 --- a/test/shdr_tokenizer_test.cpp +++ b/test/shdr_tokenizer_test.cpp @@ -21,9 +21,9 @@ #include -#include "entity/entity.hpp" -#include "pipeline/shdr_tokenizer.hpp" -#include "pipeline/timestamp_extractor.hpp" +#include "mtconnect/entity/entity.hpp" +#include "mtconnect/pipeline/shdr_tokenizer.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" using namespace mtconnect; using namespace mtconnect::pipeline; @@ -32,6 +32,13 @@ using namespace std; using namespace date::literals; using namespace std::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class ShdrTokenizerTest : public testing::Test { protected: diff --git a/test/solid_model_test.cpp b/test/solid_model_test.cpp index b3d35a057..169eea1ef 100644 --- a/test/solid_model_test.cpp +++ b/test/solid_model_test.cpp @@ -26,10 +26,10 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -37,6 +37,13 @@ using namespace mtconnect; using namespace mtconnect::source::adapter; using namespace entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class SolidModelTest : public testing::Test { protected: diff --git a/test/specification_test.cpp b/test/specification_test.cpp index 6f26c7523..dff297813 100644 --- a/test/specification_test.cpp +++ b/test/specification_test.cpp @@ -27,10 +27,10 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -38,6 +38,13 @@ using namespace mtconnect; using namespace entity; using namespace device_model; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class SpecificationTest : public testing::Test { protected: diff --git a/test/table_test.cpp b/test/table_test.cpp index a6d3ea356..8da67faa2 100644 --- a/test/table_test.cpp +++ b/test/table_test.cpp @@ -26,10 +26,10 @@ #include #include -#include "agent.hpp" #include "agent_test_helper.hpp" #include "json_helper.hpp" -#include "source/adapter/adapter.hpp" +#include "mtconnect/agent.hpp" +#include "mtconnect/source/adapter/adapter.hpp" using json = nlohmann::json; using namespace std; @@ -43,6 +43,13 @@ using namespace std::literals; using namespace chrono_literals; using namespace date::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class TableTest : public testing::Test { protected: diff --git a/test/test_utilities.cpp b/test/test_utilities.cpp deleted file mode 100644 index 682f5c521..000000000 --- a/test/test_utilities.cpp +++ /dev/null @@ -1,338 +0,0 @@ -// -// Copyright Copyright 2009-2022, AMT – The Association For Manufacturing Technology (“AMT”) -// All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -// Ensure that gtest is the first header otherwise Windows raises an error -#include -// Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) - -#include - -#include -#include -#include - -#include "test_utilities.hpp" - -using namespace std; - -namespace { - template - std::string toString(T value) - { - std::ostringstream stm; - stm << value; - return stm.str(); - } -} // namespace - -string getFile(string file) -{ - string path = string(PROJECT_ROOT_DIR "/test/resources/") + file; - ifstream ifs(path.c_str()); - stringstream stream; - stream << ifs.rdbuf(); - return stream.str(); -} - -void fillErrorText(string &errorXml, const string &text) -{ - size_t pos = errorXml.find(""); - - // Error in case was not found - if (pos == string::npos) - { - return; - } - - // Trim everything between >.... - size_t gT = pos; - - while (errorXml[gT - 1] != '>') - { - gT--; - } - - errorXml.erase(gT, pos - gT); - - // Insert new text into pos - pos = errorXml.find(""); - errorXml.insert(pos, text); -} - -void fillAttribute(string &xmlString, const string &attribute, const string &value) -{ - size_t pos = xmlString.find(attribute + "=\"\""); - - if (pos == string::npos) - { - return; - } - else - { - pos += attribute.length() + 2; - } - - xmlString.insert(pos, value); -} - -void xpathTest(xmlDocPtr doc, const char *xpath, const char *expected, const std::string &file, - int line) -{ - xmlNodePtr root = xmlDocGetRootElement(doc); - - string path(xpath), attribute; - size_t pos = path.find_first_of('@'); - - while (pos != string::npos && attribute.empty()) - { - if (xpath[pos - 1] != '[') - { - attribute = path.substr(pos + 1); - path = path.substr(0, pos); - } - - pos = path.find_first_of('@', pos + 1); - } - - xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); - - bool any = false; - - for (xmlNsPtr ns = root->nsDef; ns; ns = ns->next) - { - if (ns->prefix) - { - xmlXPathRegisterNs(xpathCtx, ns->prefix, ns->href); - any = true; - } - } - - if (!any) - xmlXPathRegisterNs(xpathCtx, BAD_CAST "m", root->ns->href); - - xmlXPathObjectPtr obj = xmlXPathEvalExpression(BAD_CAST path.c_str(), xpathCtx); - - if (!obj || !obj->nodesetval || obj->nodesetval->nodeNr == 0) - { - int size; - xmlChar *memory; - xmlDocDumpFormatMemory(doc, &memory, &size, 1); - - stringstream message; - message << file << "(" << line << "): " - << "Xpath " << xpath << " did not match any nodes in XML document" << endl - << ((const char *)memory); - xmlFree(memory); - - FAIL() << message.str(); - - if (obj) - xmlXPathFreeObject(obj); - - xmlXPathFreeContext(xpathCtx); - return; - } - - // Special case when no children are expected - xmlNodePtr first = obj->nodesetval->nodeTab[0]; - - if (expected == nullptr) - { - bool has_content = false; - stringstream message; - - if (attribute.empty()) - { - message << "Xpath " << xpath << " was not supposed to have any children."; - - for (xmlNodePtr child = first->children; !has_content && child; child = child->next) - { - if (child->type == XML_ELEMENT_NODE) - { - has_content = true; - } - else if (child->type == XML_TEXT_NODE) - { - string res = (const char *)child->content; - has_content = !trim(res).empty(); - } - } - } - else - { - message << "Xpath " << xpath << " was not supposed to have an attribute."; - xmlChar *text = xmlGetProp(first, BAD_CAST attribute.c_str()); - - if (text) - { - message << "Value was: " << text; - has_content = true; - xmlFree(text); - } - } - - xmlXPathFreeObject(obj); - xmlXPathFreeContext(xpathCtx); - - failIf(has_content, message.str(), file, line); - return; - } - - string actual; - xmlChar *text = nullptr; - - switch (first->type) - { - case XML_ELEMENT_NODE: - if (attribute.empty()) - { - text = xmlNodeGetContent(first); - } - else if (first->properties) - { - text = xmlGetProp(first, BAD_CAST attribute.c_str()); - if (text == nullptr) - { - text = xmlStrdup(BAD_CAST "ATTRIBUTE NOT FOUND"); - } - } - - if (text) - { - actual = (const char *)text; - xmlFree(text); - } - - break; - - case XML_ATTRIBUTE_NODE: - actual = (const char *)first->content; - break; - - case XML_TEXT_NODE: - actual = (const char *)first->content; - break; - - default: - cerr << "Cannot handle type: " << first->type << endl; - } - - xmlXPathFreeObject(obj); - xmlXPathFreeContext(xpathCtx); - - trim(actual); - string message = (string) "Incorrect value for path " + xpath; - - if (expected[0] != '!') - { - failNotEqualIf(actual != expected, expected, actual, message, file, line); - } - else - { - expected += 1; - failNotEqualIf(actual == expected, expected, actual, message, file, line); - } -} - -void xpathTestCount(xmlDocPtr doc, const char *xpath, int expected, const std::string &file, - int line) - -{ - xmlNodePtr root = xmlDocGetRootElement(doc); - - xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); - - bool any = false; - - for (xmlNsPtr ns = root->nsDef; ns; ns = ns->next) - { - if (ns->prefix) - { - xmlXPathRegisterNs(xpathCtx, ns->prefix, ns->href); - any = true; - } - } - - if (!any) - xmlXPathRegisterNs(xpathCtx, BAD_CAST "m", root->ns->href); - - xmlXPathObjectPtr obj = xmlXPathEvalExpression(BAD_CAST xpath, xpathCtx); - - if (!obj || !obj->nodesetval) - { - stringstream message; - message << "Xpath " << xpath << " did not match any nodes in XML document"; - failIf(true, message.str(), file, line); - - if (obj) - xmlXPathFreeObject(obj); - - xmlXPathFreeContext(xpathCtx); - return; - } - - string message = (string) "Incorrect count of elements for path " + xpath; - - int actual = obj->nodesetval->nodeNr; - - xmlXPathFreeObject(obj); - xmlXPathFreeContext(xpathCtx); - - failNotEqualIf(actual != expected, toString(expected), toString(actual), message, file, line); -} - -string &trim(string &str) -{ - char const *delims = " \t\r\n"; - - // trim leading whitespace - string::size_type not_white = str.find_first_not_of(delims); - - if (not_white == string::npos) - str.erase(); - else if (not_white > 0) - str.erase(0, not_white); - - if (not_white != string::npos) - { - // trim trailing whitespace - not_white = str.find_last_not_of(delims); - - if (not_white < (str.length() - 1)) - str.erase(not_white + 1); - } - - return str; -} - -void failIf(bool condition, const std::string &message, const std::string &file, int line) -{ - ASSERT_FALSE(condition) << file << "(" << line << "): Failed " << message; -} - -void failNotEqualIf(bool condition, const std::string &expected, const std::string &actual, - const std::string &message, const std::string &file, int line) -{ - ASSERT_FALSE(condition) << file << "(" << line << "): Failed not equal " << message << "\n" - << " Expected: " << expected << "\n" - << " Actual: " << actual; -} - -void assertIf(bool condition, const std::string &message, const std::string &file, int line) -{ - ASSERT_TRUE(condition) << file << "(" << line << "): Failed " << message; -} diff --git a/test/test_utilities.hpp b/test/test_utilities.hpp index 35fb3a349..c3259fdbd 100644 --- a/test/test_utilities.hpp +++ b/test/test_utilities.hpp @@ -17,33 +17,88 @@ #pragma once +// Must be first +#include +// Here + #include +#include #include #include #include #include +#include #include +#include + +#include "mtconnect/config.hpp" +#include "mtconnect/utilities.hpp" // Retrieve a sample file, open it, and return it as a string -std::string getFile(std::string fileLoc); +inline std::string getFile(std::string file) +{ + using namespace std; + + string path = string(PROJECT_ROOT_DIR "/test/resources/") + file; + ifstream ifs(path.c_str()); + stringstream stream; + stream << ifs.rdbuf(); + return stream.str(); +} // Fill the error -void fillErrorText(std::string &errorXml, const std::string &text); +inline void fillErrorText(std::string &errorXml, const std::string &text) +{ + using namespace std; + + size_t pos = errorXml.find(""); + + // Error in case was not found + if (pos == string::npos) + { + return; + } + + // Trim everything between >.... + size_t gT = pos; + + while (errorXml[gT - 1] != '>') + { + gT--; + } + + errorXml.erase(gT, pos - gT); + + // Insert new text into pos + pos = errorXml.find(""); + errorXml.insert(pos, text); +} // Search the xml and insert a value into an attribute (attribute="") -void fillAttribute(std::string &xmlString, const std::string &attribute, const std::string &value); +inline void fillAttribute(std::string &xmlString, const std::string &attribute, + const std::string &value) +{ + using namespace std; + + size_t pos = xmlString.find(attribute + "=\"\""); -// Trim white space from string -std::string &trim(std::string &str); + if (pos == string::npos) + { + return; + } + else + { + pos += attribute.length() + 2; + } + + xmlString.insert(pos, value); +} /// Asserts that two XML strings are equivalent. #define ASSERT_XML_PATH_EQUAL(doc, path, expected) \ xpathTest(doc, path, expected, __FILE__, __LINE__) -void xpathTest(xmlDocPtr doc, const char *xpath, const char *expected, const std::string &file, - int line); - #define PARSE_XML(expr) \ string result = expr; \ auto doc = xmlParseMemory(result.c_str(), static_cast(result.length())); \ @@ -53,12 +108,231 @@ void xpathTest(xmlDocPtr doc, const char *xpath, const char *expected, const std #define ASSERT_XML_PATH_COUNT(doc, path, expected) \ xpathTestCount(doc, path, expected, __FILE__, __LINE__) -void xpathTestCount(xmlDocPtr doc, const char *xpath, int expected, const std::string &file, - int line); +inline void failIf(bool condition, const std::string &message, const std::string &file, int line) +{ + ASSERT_FALSE(condition) << file << "(" << line << "): Failed " << message; +} + +inline void failNotEqualIf(bool condition, const std::string &expected, const std::string &actual, + const std::string &message, const std::string &file, int line) +{ + ASSERT_FALSE(condition) << file << "(" << line << "): Failed not equal " << message << "\n" + << " Expected: " << expected << "\n" + << " Actual: " << actual; +} + +inline void assertIf(bool condition, const std::string &message, const std::string &file, int line) +{ + ASSERT_TRUE(condition) << file << "(" << line << "): Failed " << message; +} + +inline void xpathTest(xmlDocPtr doc, const char *xpath, const char *expected, + const std::string &file, int line) +{ + using namespace std; + + xmlNodePtr root = xmlDocGetRootElement(doc); + + string path(xpath), attribute; + size_t pos = path.find_first_of('@'); + + while (pos != string::npos && attribute.empty()) + { + if (xpath[pos - 1] != '[') + { + attribute = path.substr(pos + 1); + path = path.substr(0, pos); + } + + pos = path.find_first_of('@', pos + 1); + } + + xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); + + bool any = false; + + for (xmlNsPtr ns = root->nsDef; ns; ns = ns->next) + { + if (ns->prefix) + { + xmlXPathRegisterNs(xpathCtx, ns->prefix, ns->href); + any = true; + } + } + + if (!any) + xmlXPathRegisterNs(xpathCtx, BAD_CAST "m", root->ns->href); + + xmlXPathObjectPtr obj = xmlXPathEvalExpression(BAD_CAST path.c_str(), xpathCtx); + + if (!obj || !obj->nodesetval || obj->nodesetval->nodeNr == 0) + { + int size; + xmlChar *memory; + xmlDocDumpFormatMemory(doc, &memory, &size, 1); + + stringstream message; + message << file << "(" << line << "): " + << "Xpath " << xpath << " did not match any nodes in XML document" << endl + << ((const char *)memory); + xmlFree(memory); + + FAIL() << message.str(); + + if (obj) + xmlXPathFreeObject(obj); + + xmlXPathFreeContext(xpathCtx); + return; + } + + // Special case when no children are expected + xmlNodePtr first = obj->nodesetval->nodeTab[0]; + + if (expected == nullptr) + { + bool has_content = false; + stringstream message; + + if (attribute.empty()) + { + message << "Xpath " << xpath << " was not supposed to have any children."; + + for (xmlNodePtr child = first->children; !has_content && child; child = child->next) + { + if (child->type == XML_ELEMENT_NODE) + { + has_content = true; + } + else if (child->type == XML_TEXT_NODE) + { + string res = (const char *)child->content; + has_content = !mtconnect::trim(res).empty(); + } + } + } + else + { + message << "Xpath " << xpath << " was not supposed to have an attribute."; + xmlChar *text = xmlGetProp(first, BAD_CAST attribute.c_str()); + + if (text) + { + message << "Value was: " << text; + has_content = true; + xmlFree(text); + } + } + + xmlXPathFreeObject(obj); + xmlXPathFreeContext(xpathCtx); + + failIf(has_content, message.str(), file, line); + return; + } + + string actual; + xmlChar *text = nullptr; + + switch (first->type) + { + case XML_ELEMENT_NODE: + if (attribute.empty()) + { + text = xmlNodeGetContent(first); + } + else if (first->properties) + { + text = xmlGetProp(first, BAD_CAST attribute.c_str()); + if (text == nullptr) + { + text = xmlStrdup(BAD_CAST "ATTRIBUTE NOT FOUND"); + } + } + + if (text) + { + actual = (const char *)text; + xmlFree(text); + } + + break; + + case XML_ATTRIBUTE_NODE: + actual = (const char *)first->content; + break; + + case XML_TEXT_NODE: + actual = (const char *)first->content; + break; + + default: + cerr << "Cannot handle type: " << first->type << endl; + } + + xmlXPathFreeObject(obj); + xmlXPathFreeContext(xpathCtx); + + actual = mtconnect::trim(actual); + string message = (string) "Incorrect value for path " + xpath; + + if (expected[0] != '!') + { + failNotEqualIf(actual != expected, expected, actual, message, file, line); + } + else + { + expected += 1; + failNotEqualIf(actual == expected, expected, actual, message, file, line); + } +} + +inline void xpathTestCount(xmlDocPtr doc, const char *xpath, int expected, const std::string &file, + int line) + +{ + using namespace std; + + xmlNodePtr root = xmlDocGetRootElement(doc); + + xmlXPathContextPtr xpathCtx = xmlXPathNewContext(doc); + + bool any = false; + + for (xmlNsPtr ns = root->nsDef; ns; ns = ns->next) + { + if (ns->prefix) + { + xmlXPathRegisterNs(xpathCtx, ns->prefix, ns->href); + any = true; + } + } + + if (!any) + xmlXPathRegisterNs(xpathCtx, BAD_CAST "m", root->ns->href); + + xmlXPathObjectPtr obj = xmlXPathEvalExpression(BAD_CAST xpath, xpathCtx); + + if (!obj || !obj->nodesetval) + { + stringstream message; + message << "Xpath " << xpath << " did not match any nodes in XML document"; + failIf(true, message.str(), file, line); + + if (obj) + xmlXPathFreeObject(obj); + + xmlXPathFreeContext(xpathCtx); + return; + } + + string message = (string) "Incorrect count of elements for path " + xpath; -void failIf(bool condition, const std::string &message, const std::string &file, int line); + int actual = obj->nodesetval->nodeNr; -void failNotEqualIf(bool condition, const std::string &expected, const std::string &actual, - const std::string &message, const std::string &file, int line); + xmlXPathFreeObject(obj); + xmlXPathFreeContext(xpathCtx); -void assertIf(bool condition, const std::string &message, const std::string &file, int line); + failNotEqualIf(actual != expected, boost::lexical_cast(expected), + boost::lexical_cast(actual), message, file, line); +} diff --git a/test/testadapter_service.hpp b/test/testadapter_service.hpp index 3143f6154..29ec1c06e 100644 --- a/test/testadapter_service.hpp +++ b/test/testadapter_service.hpp @@ -19,11 +19,11 @@ #include -#include "configuration/agent_config.hpp" -#include "pipeline/pipeline.hpp" -#include "source/adapter/adapter.hpp" -#include "source/adapter/adapter_pipeline.hpp" -#include "source/source.hpp" +#include "mtconnect/configuration/agent_config.hpp" +#include "mtconnect/pipeline/pipeline.hpp" +#include "mtconnect/source/adapter/adapter.hpp" +#include "mtconnect/source/adapter/adapter_pipeline.hpp" +#include "mtconnect/source/source.hpp" using namespace std; diff --git a/test/testsink_service.hpp b/test/testsink_service.hpp index ad18d2d8a..96a726309 100644 --- a/test/testsink_service.hpp +++ b/test/testsink_service.hpp @@ -19,7 +19,7 @@ #include -#include "configuration/agent_config.hpp" +#include "mtconnect/configuration/agent_config.hpp" using namespace std; diff --git a/test/timestamp_extractor_test.cpp b/test/timestamp_extractor_test.cpp index a1149d355..49f05525d 100644 --- a/test/timestamp_extractor_test.cpp +++ b/test/timestamp_extractor_test.cpp @@ -21,8 +21,8 @@ #include -#include "pipeline/shdr_tokenizer.hpp" -#include "pipeline/timestamp_extractor.hpp" +#include "mtconnect/pipeline/shdr_tokenizer.hpp" +#include "mtconnect/pipeline/timestamp_extractor.hpp" using namespace mtconnect; using namespace mtconnect::pipeline; @@ -32,6 +32,13 @@ using namespace std::literals; using namespace date; using namespace date::literals; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + TEST(TimestampExtractorTest, TestTimeExtraction) { auto tokens = make_shared("Tokens", Properties()); diff --git a/test/tls_http_server_test.cpp b/test/tls_http_server_test.cpp index 27910bed1..393a0eae2 100644 --- a/test/tls_http_server_test.cpp +++ b/test/tls_http_server_test.cpp @@ -33,8 +33,8 @@ #include #include -#include "logging.hpp" -#include "sink/rest_sink/server.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/sink/rest_sink/server.hpp" using namespace std; using namespace mtconnect; @@ -46,6 +46,13 @@ namespace http = boost::beast::http; namespace ssl = boost::asio::ssl; using tcp = boost::asio::ip::tcp; +// main +int main(int argc, char* argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class Client { public: diff --git a/test/topic_mapping_test.cpp b/test/topic_mapping_test.cpp index 8b7f55b80..ab277ad0e 100644 --- a/test/topic_mapping_test.cpp +++ b/test/topic_mapping_test.cpp @@ -21,10 +21,10 @@ #include -#include "device_model/device.hpp" -#include "observation/observation.hpp" -#include "pipeline/pipeline_context.hpp" -#include "pipeline/topic_mapper.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/pipeline/pipeline_context.hpp" +#include "mtconnect/pipeline/topic_mapper.hpp" using namespace mtconnect; using namespace mtconnect::pipeline; @@ -34,6 +34,13 @@ using namespace device_model; using namespace data_item; using namespace std; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class MockPipelineContract : public PipelineContract { public: diff --git a/test/unit_conversion_test.cpp b/test/unit_conversion_test.cpp index 0203242d1..970778cab 100644 --- a/test/unit_conversion_test.cpp +++ b/test/unit_conversion_test.cpp @@ -19,12 +19,19 @@ #include // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) -#include "device_model/data_item/unit_conversion.hpp" +#include "mtconnect/device_model/data_item/unit_conversion.hpp" using namespace std; using namespace mtconnect::device_model::data_item; using namespace mtconnect::entity; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + TEST(UnitConversionTest, check_inch_3d) { auto conv = UnitConversion::make("INCH_3D", "MILLIMETER_3D"); diff --git a/test/url_parser_test.cpp b/test/url_parser_test.cpp index 256993c2b..51afc286f 100644 --- a/test/url_parser_test.cpp +++ b/test/url_parser_test.cpp @@ -19,7 +19,7 @@ #include // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) -#include "source/adapter/agent_adapter/url_parser.hpp" +#include "mtconnect/source/adapter/agent_adapter/url_parser.hpp" using namespace std; using namespace mtconnect; @@ -28,6 +28,13 @@ using namespace std::literals; using namespace mtconnect::source::adapter::agent_adapter; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + TEST(UrlParserTest, should_parse_url_with_port) { Url url = Url::parse("http://127.0.0.1:5000/Device"); diff --git a/test/xml_parser_test.cpp b/test/xml_parser_test.cpp index e06dec731..7ce318b93 100644 --- a/test/xml_parser_test.cpp +++ b/test/xml_parser_test.cpp @@ -23,9 +23,9 @@ #include #include -#include "device_model/reference.hpp" -#include "parser/xml_parser.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/device_model/reference.hpp" +#include "mtconnect/parser/xml_parser.hpp" +#include "mtconnect/printer//xml_printer.hpp" #include "test_utilities.hpp" using namespace std; @@ -35,6 +35,13 @@ using namespace entity; using namespace device_model; using namespace data_item; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + class XmlParserTest : public testing::Test { protected: diff --git a/test/xml_printer_test.cpp b/test/xml_printer_test.cpp index f87e2ad8d..a929b2f1d 100644 --- a/test/xml_printer_test.cpp +++ b/test/xml_printer_test.cpp @@ -19,15 +19,15 @@ #include // Keep this comment to keep gtest.h above. (clang-format off/on is not working here!) -#include "asset/asset.hpp" -#include "buffer/checkpoint.hpp" -#include "device_model/data_item/data_item.hpp" -#include "device_model/device.hpp" -#include "observation/observation.hpp" -#include "parser/xml_parser.hpp" -#include "printer/xml_printer.hpp" +#include "mtconnect/asset/asset.hpp" +#include "mtconnect/buffer/checkpoint.hpp" +#include "mtconnect/device_model/data_item/data_item.hpp" +#include "mtconnect/device_model/device.hpp" +#include "mtconnect/observation/observation.hpp" +#include "mtconnect/parser/xml_parser.hpp" +#include "mtconnect/printer//xml_printer.hpp" +#include "mtconnect/utilities.hpp" #include "test_utilities.hpp" -#include "utilities.hpp" using namespace std; using namespace mtconnect; @@ -37,6 +37,13 @@ using namespace mtconnect::entity; using namespace mtconnect::printer; using namespace mtconnect::parser; +// main +int main(int argc, char *argv[]) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + Properties operator"" _value(const char *value, size_t s) { return Properties {{"VALUE", string(value)}};