Skip to content

Commit

Permalink
feat: move to C++20, using custom event bus
Browse files Browse the repository at this point in the history
  • Loading branch information
ABeltramo committed Aug 26, 2024
1 parent 987544d commit 4c938ef
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)

# Optionally set things like CMAKE_CXX_STANDARD, CMAKE_POSITION_INDEPENDENT_CODE here

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

set(CMAKE_CXX_STANDARD_REQUIRED ON)

Expand Down
4 changes: 0 additions & 4 deletions src/core/src/core/gstreamer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ static bool run_pipeline(const std::string &pipeline_desc,
gst_element_set_state(pipeline.get(), GST_STATE_READY);
gst_element_set_state(pipeline.get(), GST_STATE_NULL);

for (const auto &handler : handlers) {
handler->unregister();
}

return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/src/platforms/all/docker/docker/formatters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ template <> struct [[maybe_unused]] formatter<docker::MountPoint> {
}
template <typename FormatContext>
auto format(const docker::MountPoint &mount, FormatContext &ctx) const -> decltype(ctx.out()) {
return format_to(ctx.out(), "{}:{}:{}", mount.source, mount.destination, mount.mode);
return format_to(ctx.out(), fmt::runtime("{}:{}:{}"), mount.source, mount.destination, mount.mode);
}
};

Expand All @@ -41,7 +41,7 @@ template <> struct [[maybe_unused]] formatter<docker::Device> {
}
template <typename FormatContext>
auto format(const docker::Device &dev, FormatContext &ctx) const -> decltype(ctx.out()) {
return format_to(ctx.out(), "{}:{}:{}", dev.path_on_host, dev.path_in_container, dev.cgroup_permission);
return format_to(ctx.out(), fmt::runtime("{}:{}:{}"), dev.path_on_host, dev.path_in_container, dev.cgroup_permission);
}
};

Expand All @@ -54,7 +54,7 @@ template <> struct [[maybe_unused]] formatter<docker::Container> {
auto format(const docker::Container &container, FormatContext &ctx) const -> decltype(ctx.out()) {
return format_to(
ctx.out(),
"{{\n id: {}\n name: {}\n image: {}\n status: {}\n ports: {}\n mounts: {}\n devices: {}\n env: {}\n}}",
fmt::runtime("{{\n id: {}\n name: {}\n image: {}\n status: {}\n ports: {}\n mounts: {}\n devices: {}\n env: {}\n}}"),
container.id,
container.name,
container.image,
Expand Down
5 changes: 3 additions & 2 deletions src/core/src/platforms/all/helpers/helpers/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(my_logger, my_logger_mt) {
* @param format_str: a valid fmt::format string
* @param args: optional additional args to be formatted
*/
template <typename S, typename... Args> inline void log(severity_level lvl, const S &format_str, const Args &...args) {
auto msg = fmt::format(format_str, args...);
template <typename... Args>
inline void log(severity_level lvl, fmt::format_string<Args...> format_str, Args &&...args) {
auto msg = fmt::format(format_str, std::forward<Args>(args)...);
BOOST_LOG_SEV(my_logger::get(), lvl) << msg;
}

Expand Down
4 changes: 2 additions & 2 deletions src/moonlight-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ target_link_libraries_system(wolf_runner PUBLIC fmt::fmt-header-only)

FetchContent_Declare(
eventbus
GIT_REPOSITORY https://github.com/DeveloperPaul123/eventbus
GIT_TAG 0.10.1
GIT_REPOSITORY https://github.com/games-on-whales/eventbus
GIT_TAG 8599ea2
)
set(EVENTBUS_BUILD_TESTS OFF)
FetchContent_MakeAvailable(eventbus)
Expand Down
4 changes: 3 additions & 1 deletion src/moonlight-server/platforms/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ static std::string to_hex(const std::basic_string<char32_t> &str) {
std::stringstream ss;
ss << std::hex << std::setfill('0');
for (const auto &ch : str) {
ss << ch;
ss << (char)(ch >> 16);
ss << (char)(ch >> 8);
ss << (char)ch;
}

std::string hex_unicode(ss.str());
Expand Down
4 changes: 2 additions & 2 deletions src/moonlight-server/streaming/streaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void start_streaming_video(const immer::box<state::VideoSession> &video_session,
break;
}

auto pipeline = fmt::format(video_session->gst_pipeline,
auto pipeline = fmt::format(fmt::runtime(video_session->gst_pipeline),
fmt::arg("width", video_session->display_mode.width),
fmt::arg("height", video_session->display_mode.height),
fmt::arg("fps", video_session->display_mode.refreshRate),
Expand Down Expand Up @@ -203,7 +203,7 @@ void start_streaming_audio(const immer::box<state::AudioSession> &audio_session,
const std::string &sink_name,
const std::string &server_name) {
auto pipeline = fmt::format(
audio_session->gst_pipeline,
fmt::runtime(audio_session->gst_pipeline),
fmt::arg("channels", audio_session->audio_mode.channels),
fmt::arg("bitrate", audio_session->audio_mode.bitrate),
// TODO: opusenc hardcodes those two
Expand Down
6 changes: 2 additions & 4 deletions src/moonlight-server/wolf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ void run() {
auto p_key_file = utils::get_env("WOLF_PRIVATE_KEY_FILE", "key.pem");
auto p_cert_file = utils::get_env("WOLF_PRIVATE_CERT_FILE", "cert.pem");
auto local_state = initialize(config_file, p_key_file, p_cert_file);
auto global_ev_handler = local_state->event_bus->register_global_handler(
[](std::any ev) { logs::log(logs::trace, "Fired event: {}", ev.type().name()); });

// HTTP APIs
auto http_thread = std::thread([local_state]() {
Expand Down Expand Up @@ -467,10 +469,6 @@ void run() {
auto sess_handlers = setup_sessions_handlers(local_state, runtime_dir, audio_server);

http_thread.join(); // Let's park the main thread over here

for (const auto &handler : sess_handlers) {
handler->unregister();
}
}

int main(int argc, char *argv[]) try {
Expand Down

0 comments on commit 4c938ef

Please sign in to comment.