Skip to content

Commit

Permalink
Replace "proxyfmu" with SimpleSocket + msgpack (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
markaren authored Oct 21, 2024
1 parent 9626a40 commit ec82648
Show file tree
Hide file tree
Showing 35 changed files with 1,078 additions and 710 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ IncludeCategories:
Priority: 10
- Regex: '^[<"]ecos[/.]'
Priority: 20
- Regex: '^[<"](CLI|thrift|ssp|spdlog|fmilibcpp|proxyfmu|subprocess)[/.]'
- Regex: '^[<"](CLI|msgpack|simple_socket|ssp|spdlog|fmilibcpp|proxyfmu|subprocess)[/.]'
Priority: 30
- Regex: '^"'
Priority: 10
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on: [ push, workflow_dispatch ]
jobs:
cmake-on-linux:

timeout-minutes: 15
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -45,6 +46,7 @@ jobs:

cmake-on-windows:

timeout-minutes: 15
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.17)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
cmake_minimum_required(VERSION 3.19)
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED $ENV{VCPKG_ROOT})
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file")
endif ()
file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" projectVersion)
project("libecos" VERSION ${projectVersion})
message("Current ${PROJECT_NAME} version: ${CMAKE_PROJECT_VERSION}\n")
Expand Down Expand Up @@ -47,12 +49,21 @@ set(SUBPROCESS_INCLUDE_DIR "${CMAKE_BINARY_DIR}/thirdparty")
file(DOWNLOAD https://raw.githubusercontent.com/Ecos-platform/subprocess.h/master/subprocess.h
"${SUBPROCESS_INCLUDE_DIR}/subprocess/subprocess.h")

include(FetchContent)
set(SIMPLE_SOCKET_BUILD_TESTS OFF)
FetchContent_Declare(
SimpleSocket
GIT_REPOSITORY https://github.com/markaren/SimpleSocket.git
GIT_TAG e0e989bdd52137d743a4599e25167d5681a0de00
)
FetchContent_MakeAvailable(SimpleSocket)

find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(libzip CONFIG REQUIRED)
find_package(pugixml CONFIG REQUIRED)
find_package(Thrift CONFIG REQUIRED)
find_package(CLI11 CONFIG REQUIRED)
find_package(msgpack-cxx CONFIG REQUIRED)
find_package(unofficial-fmilib CONFIG REQUIRED)

# ==============================================================================
Expand All @@ -74,7 +85,7 @@ if (ECOS_BUILD_EXAMPLES OR ECOS_BUILD_TESTS)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.3.2
GIT_TAG v3.7.1
)
FetchContent_MakeAvailable(Catch2)

Expand Down
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ RUN apt-get update \
tar \
pkg-config \
libtbb-dev \
flex \
bison \
&& apt-get clean

WORKDIR /home
Expand Down
2 changes: 2 additions & 0 deletions examples/spring_mass_damper/spring_mass_damper_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
int main()
{

log::set_logging_level(log::level::trace);

simulation_structure ss;
ss.add_model("mass", "proxyfmu://localhost?file=" + std::string(DATA_FOLDER) + "/fmus/1.0/Mass.fmu");
ss.add_model("spring", "proxyfmu://localhost?file=" + std::string(DATA_FOLDER) + "/fmus/1.0/Spring.fmu");
Expand Down
7 changes: 3 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

add_subdirectory(proxyfmu)

set(publicHeaders

"ecos/connection.hpp"
Expand Down Expand Up @@ -64,6 +62,7 @@ set(privateHeaders
"fmilibcpp/fmi2/fmi2_slave.hpp"
"fmilibcpp/fmi2/fmi2_model_description.hpp"

"proxyfmu/opcodes.hpp"
"proxyfmu/process_helper.hpp"
"proxyfmu/proxy_fmu.hpp"
"proxyfmu/proxy_slave.hpp"
Expand Down Expand Up @@ -161,15 +160,15 @@ target_link_libraries(libecos
PUBLIC
fmt::fmt
PRIVATE
simple_socket
msgpack-cxx
libzip::zip
spdlog::spdlog
thrift::thrift
pugixml::pugixml
unofficial::fmilib::fmilib
"$<TARGET_OBJECTS:util>"
"$<TARGET_OBJECTS:logger>"
"$<TARGET_OBJECTS:fmilibcpp>"
"$<TARGET_OBJECTS:proxyfmu-service>"
)
if (UNIX)
target_link_libraries(libecos INTERFACE stdc++fs tbb)
Expand Down
7 changes: 4 additions & 3 deletions src/ecos/fmi/proxy/proxy_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
#include "proxyfmu/proxy_fmu.hpp"

#include <filesystem>
#include <utility>

namespace ecos
{

class proxy_model : public model
{
public:
explicit proxy_model(const std::filesystem::path& fmuPath)
: fmu_(fmuPath)
explicit proxy_model(const std::filesystem::path& fmuPath, std::optional<proxy::remote_info> remote = std::nullopt)
: fmu_(fmuPath, std::move(remote))
{
}

Expand All @@ -26,7 +27,7 @@ class proxy_model : public model
}

private:
proxyfmu::proxy_fmu fmu_;
proxy::proxy_fmu fmu_;
};

} // namespace ecos
Expand Down
29 changes: 28 additions & 1 deletion src/ecos/fmi/proxy/proxy_model_sub_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@

using namespace ecos;

namespace
{
std::optional<proxy::remote_info> parse(const std::string& url)
{
// Find the start of the host (after "proxyfmu://")
std::size_t start_pos = url.find("://");
if (start_pos == std::string::npos) {
return std::nullopt; // Return empty if no protocol found
}
start_pos += 3; // Move past "://"

std::size_t end_pos = url.find('?', start_pos);
if (end_pos == std::string::npos) {
end_pos = url.length();
}

const std::string path = url.substr(start_pos, end_pos - start_pos);
if (path.find(':') == std::string::npos) {
return std::nullopt;
}

return proxy::remote_info::parse(path);
}

} // namespace

std::unique_ptr<model> proxy_model_sub_resolver::resolve(const std::filesystem::path& base, const std::string& uri)
{
if (uri.rfind("proxyfmu", 0) == 0) {
Expand All @@ -13,7 +39,8 @@ std::unique_ptr<model> proxy_model_sub_resolver::resolve(const std::filesystem::
throw std::runtime_error("proxyfmu source missing file= component..");
}
const auto fmuFile = base / uri.substr(find + 5);
return std::make_unique<proxy_model>(fmuFile);
std::optional<proxy::remote_info> info = parse(uri);
return std::make_unique<proxy_model>(fmuFile, info);
}
return nullptr;
}
52 changes: 0 additions & 52 deletions src/proxyfmu/CMakeLists.txt

This file was deleted.

7 changes: 0 additions & 7 deletions src/proxyfmu/boot.thrift

This file was deleted.

95 changes: 0 additions & 95 deletions src/proxyfmu/defs.thrift

This file was deleted.

Loading

0 comments on commit ec82648

Please sign in to comment.