Skip to content

Commit 55dc93e

Browse files
committed
stack: Refactor stack into its own library
Move nop controller and simulator plugin to models where all the other Nop classes are.
1 parent 3f017f3 commit 55dc93e

38 files changed

+292
-170
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ add_subdirectory(runtime)
3232
add_subdirectory(models)
3333
add_subdirectory(osi)
3434
add_subdirectory(oak)
35+
add_subdirectory(stack)
3536
add_subdirectory(engine)
3637
add_subdirectory(plugins)
3738

Makefile.all

+3-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ALL_PKGS := \
5050
fable \
5151
runtime \
5252
models \
53+
stack \
5354
osi \
5455
oak \
5556
engine \
@@ -77,7 +78,8 @@ runtime: fable
7778
models: runtime
7879
osi: runtime models
7980
oak: runtime
80-
engine: models oak
81+
stack: runtime models
82+
engine: models oak stack
8183
$(PLUGIN_PKGS): runtime models
8284
plugins/esmini: osi
8385

engine/CMakeLists.txt

+8-64
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if(CLOE_FIND_PACKAGES)
77
find_package(fable REQUIRED QUIET)
88
find_package(cloe-runtime REQUIRED QUIET)
99
find_package(cloe-models REQUIRED QUIET)
10+
find_package(cloe-stack REQUIRED QUIET)
1011
endif()
1112
find_package(Boost REQUIRED QUIET)
1213
find_package(CLI11 REQUIRED QUIET)
@@ -22,67 +23,6 @@ string(TIMESTAMP CLOE_ENGINE_TIMESTAMP "%Y-%m-%d")
2223
set(CLOE_ENGINE_VERSION ${CLOE_PROJECT_VERSION})
2324
set(PROJECT_GIT_REF "unknown")
2425

25-
# Library libstack ---------------------------------------------------
26-
message(STATUS "Building cloe-stacklib library.")
27-
add_library(cloe-stacklib STATIC
28-
src/config.hpp
29-
src/stack.hpp
30-
src/stack.cpp
31-
src/stack_factory.hpp
32-
src/stack_factory.cpp
33-
src/plugin.hpp
34-
src/plugin.cpp
35-
36-
# Built-in plugins:
37-
src/plugins/nop_controller.cpp
38-
src/plugins/nop_controller.hpp
39-
src/plugins/nop_simulator.cpp
40-
src/plugins/nop_simulator.hpp
41-
)
42-
add_library(cloe::stacklib ALIAS cloe-stacklib)
43-
set_target_properties(cloe-stacklib PROPERTIES
44-
CXX_STANDARD 17
45-
CXX_STANDARD_REQUIRED ON
46-
OUTPUT_NAME stack
47-
)
48-
target_include_directories(cloe-stacklib
49-
PRIVATE
50-
src
51-
)
52-
target_link_libraries(cloe-stacklib
53-
PUBLIC
54-
cloe::runtime
55-
cloe::models
56-
fable::fable
57-
Boost::headers
58-
Threads::Threads
59-
${CMAKE_DL_LIBS}
60-
)
61-
62-
include(CTest)
63-
if(BUILD_TESTING)
64-
find_package(GTest REQUIRED QUIET)
65-
include(GoogleTest)
66-
67-
message(STATUS "Building test-stacklib executable.")
68-
add_executable(test-stacklib
69-
src/stack_test.cpp
70-
src/stack_component_test.cpp
71-
)
72-
set_target_properties(test-stacklib PROPERTIES
73-
CXX_STANDARD 17
74-
CXX_STANDARD_REQUIRED ON
75-
)
76-
target_link_libraries(test-stacklib
77-
GTest::gtest
78-
GTest::gtest_main
79-
Boost::boost
80-
cloe::models
81-
cloe::stacklib
82-
)
83-
gtest_add_tests(TARGET test-stacklib)
84-
endif()
85-
8626
# Library libengine ----------------------------------------------
8727
message(STATUS "Building cloe-enginelib library.")
8828
add_library(cloe-enginelib STATIC
@@ -157,7 +97,7 @@ target_include_directories(cloe-enginelib
15797
)
15898
target_link_libraries(cloe-enginelib
15999
PUBLIC
160-
cloe::stacklib
100+
cloe::stack
161101
cloe::models
162102
cloe::runtime
163103
fable::fable
@@ -189,8 +129,11 @@ else()
189129
target_compile_definitions(cloe-enginelib PUBLIC CLOE_ENGINE_WITH_LRDB=0)
190130
endif()
191131

132+
include(CTest)
192133
if(BUILD_TESTING)
193134
message(STATUS "Building test-enginelib executable.")
135+
find_package(GTest REQUIRED QUIET)
136+
include(GoogleTest)
194137
add_executable(test-enginelib
195138
src/lua_stack_test.cpp
196139
src/lua_setup_test.cpp
@@ -204,11 +147,12 @@ if(BUILD_TESTING)
204147
CXX_STANDARD_REQUIRED ON
205148
)
206149
target_link_libraries(test-enginelib
150+
PRIVATE
207151
GTest::gtest
208152
GTest::gtest_main
209153
Boost::boost
210154
cloe::models
211-
cloe::stacklib
155+
cloe::stack
212156
cloe::enginelib
213157
)
214158
gtest_add_tests(TARGET test-enginelib)
@@ -245,7 +189,7 @@ target_include_directories(cloe-engine
245189
)
246190
target_link_libraries(cloe-engine
247191
PRIVATE
248-
cloe::stacklib
192+
cloe::stack
249193
cloe::enginelib
250194
CLI11::CLI11
251195
linenoise::linenoise

engine/conanfile.py

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def set_version(self):
5757
def requirements(self):
5858
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
5959
self.requires(f"cloe-models/{self.version}@cloe/develop")
60+
self.requires(f"cloe-stack/{self.version}@cloe/develop")
6061
self.requires("cli11/2.3.2", private=True)
6162
self.requires("sol2/3.3.1")
6263
if self.options.server:

engine/src/lua_setup.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828

2929
#include <cloe/utility/std_extensions.hpp> // for split_string
3030

31+
#include <cloe/stack.hpp>
3132
#include <fable/utility/sol.hpp> // for Json(sol::object)
3233
#include <fable/utility/string.hpp> // for join_vector
3334

3435
#include "error_handler.hpp" // for format_cloe_error
3536
#include "lua_api.hpp"
36-
#include "stack.hpp"
3737
#include "utility/command.hpp" // for CommandExecuter, CommandResult
3838

3939
// This variable is set from CMakeLists.txt, but in case it isn't,

engine/src/lua_setup_stack.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
*/
1818

1919
#include <fable/utility/sol.hpp>
20+
#include <cloe/stack.hpp>
2021

2122
#include "lua_api.hpp"
2223
#include "lua_setup.hpp"
23-
#include "stack.hpp"
2424

2525
namespace cloe {
2626

engine/src/lua_setup_test.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
#include <fstream>
2424
#include <string_view>
2525

26+
#include <cloe/stack.hpp> // for Stack
2627
#include <sol/state.hpp>
2728

2829
#include "lua_api.hpp" // for lua_safe_script_file
2930
#include "lua_setup.hpp" // for setup_lua
30-
#include "stack.hpp" // for Stack
3131
using namespace cloe; // NOLINT(build/namespaces)
3232

3333
#ifndef CLOE_LUA_PATH
@@ -87,7 +87,8 @@ TEST_F(cloe_lua_setup, cloe_engine_is_available) {
8787

8888
TEST_F(cloe_lua_setup, describe_cloe) {
8989
setup_lua(lua, opt, stack);
90-
ASSERT_EQ(lua.script("local cloe = require('cloe'); return cloe.inspect(cloe.LogLevel.CRITICAL)").get<std::string>(),
90+
ASSERT_EQ(lua.script("local cloe = require('cloe'); return cloe.inspect(cloe.LogLevel.CRITICAL)")
91+
.get<std::string>(),
9192
std::string("\"critical\""));
9293
}
9394

engine/src/lua_stack_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222

2323
#include <sol/state.hpp>
2424

25-
#include <cloe/core.hpp> // for Json
25+
#include <cloe/core.hpp> // for Json
26+
#include <cloe/stack.hpp> // for Stack
2627
#include <fable/utility.hpp>
2728
#include <fable/utility/gtest.hpp> // for assert_from_conf
2829
#include <fable/utility/sol.hpp>
2930

3031
#include "lua_setup.hpp"
31-
#include "stack.hpp" // for Stack
3232
using namespace cloe; // NOLINT(build/namespaces)
3333

3434
TEST(cloe_lua_stack, deserialize_vehicle_conf) {

engine/src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525
#include <cloe/core/error.hpp>
2626
#include <cloe/core/logger.hpp>
27+
#include <cloe/stack_config.hpp>
2728

28-
#include "config.hpp"
2929
#include "main_commands.hpp"
3030

3131
int main(int argc, char** argv) {

engine/src/main_check.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include <vector> // for vector<>
2222

2323
#include <cloe/core/fable.hpp>
24+
#include <cloe/stack.hpp>
2425

2526
#include "main_commands.hpp"
26-
#include "stack.hpp"
2727

2828
namespace engine {
2929

engine/src/main_commands.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
#include <boost/uuid/uuid_io.hpp>
3838

3939
#include <cloe/core.hpp> // for logger::get
40+
#include <cloe/stack.hpp> // for Stack
4041
#include <fable/utility.hpp> // for read_conf
4142

4243
#include "error_handler.hpp" // for conclude_error
4344
#include "simulation.hpp" // for Simulation
44-
#include "stack.hpp" // for Stack
4545

4646
namespace engine {
4747

@@ -89,7 +89,7 @@ std::string handle_uuid(const ProbeOptions& opt) { return handle_uuid_impl(opt);
8989

9090
template <typename Options>
9191
std::tuple<cloe::Stack, sol::state> handle_config_impl(const Options& opt,
92-
const std::vector<std::string>& filepaths) {
92+
const std::vector<std::string>& filepaths) {
9393
assert(opt.output != nullptr && opt.error != nullptr);
9494
auto log = cloe::logger::get("cloe");
9595
cloe::logger::get("cloe")->info("Cloe {}", CLOE_ENGINE_VERSION);
@@ -122,13 +122,13 @@ std::tuple<cloe::Stack, sol::state> handle_config_impl(const Options& opt,
122122
return {std::move(stack), std::move(lua_state)};
123123
}
124124

125-
std::tuple<cloe::Stack, sol::state> handle_config(
126-
const RunOptions& opt, const std::vector<std::string>& filepaths) {
125+
std::tuple<cloe::Stack, sol::state> handle_config(const RunOptions& opt,
126+
const std::vector<std::string>& filepaths) {
127127
return handle_config_impl(opt, filepaths);
128128
}
129129

130-
std::tuple<cloe::Stack, sol::state> handle_config(
131-
const ProbeOptions& opt, const std::vector<std::string>& filepaths) {
130+
std::tuple<cloe::Stack, sol::state> handle_config(const ProbeOptions& opt,
131+
const std::vector<std::string>& filepaths) {
132132
return handle_config_impl(opt, filepaths);
133133
}
134134

engine/src/main_commands.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
#include <string>
2525
#include <vector>
2626

27-
#include "config.hpp"
27+
#include <cloe/stack_config.hpp>
28+
#include <cloe/stack_factory.hpp>
29+
2830
#include "lua_setup.hpp"
29-
#include "stack_factory.hpp"
3031

3132
namespace engine {
3233

engine/src/main_dump.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#include <vector> // for vector<>
2222

2323
#include <cloe/core/error.hpp>
24+
#include <cloe/stack.hpp> // for Stack
2425

2526
#include "main_commands.hpp" // for DumpOptions, new_stack
26-
#include "stack.hpp" // for Stack
2727

2828
namespace engine {
2929

engine/src/main_run.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
*/
1818

1919
#include <csignal> // for signal
20-
#include <tuple> // for tuple
20+
#include <tuple> // for tuple
21+
22+
#include <cloe/stack.hpp> // for Stack
2123

2224
#include "error_handler.hpp" // for conclude_error
2325
#include "main_commands.hpp" // for RunOptions, handle_*
2426
#include "simulation.hpp" // for Simulation
2527
#include "simulation_result.hpp" // for SimulationResult
26-
#include "stack.hpp" // for Stack
2728

2829
namespace engine {
2930

engine/src/main_shell.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
#include <linenoise.h>
2626

2727
#include <fmt/format.h>
28+
#include <cloe/stack.hpp>
2829
#include <fable/utility/string.hpp> // for ends_with
2930

3031
#include "lua_api.hpp" // for lua_safe_script_file
3132
#include "main_commands.hpp" // for Stack, new_stack, LuaOptions, new_lua
32-
#include "stack.hpp" // for Stack
3333

3434
namespace engine {
3535

@@ -53,8 +53,8 @@ bool evaluate(sol::state_view lua, std::ostream& os, const char* buf) {
5353
return true;
5454
}
5555

56-
int noninteractive_shell(sol::state_view lua, std::ostream& os, const std::vector<std::string>& actions,
57-
bool ignore_errors) {
56+
int noninteractive_shell(sol::state_view lua, std::ostream& os,
57+
const std::vector<std::string>& actions, bool ignore_errors) {
5858
int errors = 0;
5959
for (const auto& action : actions) {
6060
auto ok = evaluate(lua, os, action.c_str());
@@ -68,8 +68,8 @@ int noninteractive_shell(sol::state_view lua, std::ostream& os, const std::vecto
6868
return errors;
6969
}
7070

71-
void interactive_shell(sol::state_view lua, std::ostream& os, const std::vector<std::string>& actions,
72-
bool ignore_errors) {
71+
void interactive_shell(sol::state_view lua, std::ostream& os,
72+
const std::vector<std::string>& actions, bool ignore_errors) {
7373
constexpr auto PROMPT = "> ";
7474
constexpr auto PROMPT_CONTINUE = ">> ";
7575
constexpr auto PROMPT_HISTORY = "< ";

engine/src/main_usage.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
#include <utility> // for pair<>, move
2323
#include <vector> // for vector<>
2424

25+
#include <cloe/stack.hpp> // for Stack
2526
#include <cloe/utility/xdg.hpp> // for find_all_config
2627

2728
#include "main_commands.hpp" // for new_stack
28-
#include "stack.hpp" // for Stack
2929

3030
namespace engine {
3131

engine/src/main_version.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
#include <cloe/core/fable.hpp>
2222
#include <cloe/plugin.hpp> // for CLOE_PLUGIN_MANIFEST_VERSION
23+
#include <cloe/stack_config.hpp> // for CLOE_STACK_VERSION
2324
#include <cloe/utility/inja.hpp> // for inja_env
2425

25-
#include "config.hpp" // for CLOE_STACK_VERSION
2626
#include "main_commands.hpp" // for VersionOptions
2727

2828
namespace engine {

engine/src/registrar.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#include <string> // for string
2626
#include <string_view> // for string_view
2727

28-
#include <cloe/core/logger.hpp> // for logger::get
29-
#include <cloe/registrar.hpp> // for cloe::Registrar
28+
#include <cloe/core/logger.hpp> // for logger::get
29+
#include <cloe/registrar.hpp> // for cloe::Registrar
30+
#include <cloe/stack_config.hpp> // for CLOE_TRIGGER_PATH_DELIMITER, ...
3031

31-
#include "config.hpp" // for CLOE_TRIGGER_PATH_DELIMITER, ...
3232
#include "coordinator.hpp" // for Coordinator
3333
#include "server.hpp" // for Server, ServerRegistrar
3434

0 commit comments

Comments
 (0)