From 881778e48544507714d02cf694ea42d01e9888aa Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 22 Jan 2025 07:14:21 -0600 Subject: [PATCH] refactor events --- .../include/drives/fuse/events.hpp | 4 +- .../librepertory/include/events/event.hpp | 45 +---- .../include/events/event_system.hpp | 73 ++++---- .../librepertory/include/events/events.hpp | 108 +++++------ .../include/events/t_event_system.hpp | 16 +- .../include/file_manager/events.hpp | 20 +-- .../librepertory/include/types/repertory.hpp | 28 +++ .../src/comm/packet/packet_client.cpp | 14 +- .../drives/fuse/remotefuse/remote_server.cpp | 169 ++++++++++-------- .../winfsp/remotewinfsp/remote_client.cpp | 2 +- .../winfsp/remotewinfsp/remote_server.cpp | 2 +- .../src/drives/winfsp/winfsp_drive.cpp | 9 +- repertory/librepertory/src/events/event.cpp | 75 -------- .../src/file_manager/cache_size_mgr.cpp | 4 +- .../librepertory/src/types/repertory.cpp | 48 +++++ .../repertory_test/src/file_mgr_db_test.cpp | 2 +- 16 files changed, 295 insertions(+), 324 deletions(-) delete mode 100644 repertory/librepertory/src/events/event.cpp diff --git a/repertory/librepertory/include/drives/fuse/events.hpp b/repertory/librepertory/include/drives/fuse/events.hpp index c043c3ef..822a4a9f 100644 --- a/repertory/librepertory/include/drives/fuse/events.hpp +++ b/repertory/librepertory/include/drives/fuse/events.hpp @@ -26,13 +26,13 @@ namespace repertory { // clang-format off -E_SIMPLE3(fuse_event, debug, true, +E_SIMPLE3(fuse_event, debug, std::string, function, func, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING, int, result, res, E_FROM_INT32 ); -E_SIMPLE1(fuse_args_parsed, info, true, +E_SIMPLE1(fuse_args_parsed, info, std::string, arguments, args, E_FROM_STRING ); // clang-format on diff --git a/repertory/librepertory/include/events/event.hpp b/repertory/librepertory/include/events/event.hpp index 3937af44..ce46a887 100644 --- a/repertory/librepertory/include/events/event.hpp +++ b/repertory/librepertory/include/events/event.hpp @@ -22,29 +22,15 @@ #ifndef REPERTORY_INCLUDE_EVENTS_EVENT_HPP_ #define REPERTORY_INCLUDE_EVENTS_EVENT_HPP_ +#include "types/repertory.hpp" + namespace repertory { -enum class event_level { - critical, - error, - warn, - info, - debug, - trace, -}; - -[[nodiscard]] auto -event_level_from_string(std::string level, - event_level default_level = event_level::info) - -> event_level; - -[[nodiscard]] auto event_level_to_string(event_level level) -> std::string; - class event { protected: - explicit event(bool allow_async) : allow_async_(allow_async) {} + event() = default; - event(const std::stringstream &ss, json j, bool allow_async) - : allow_async_(allow_async), ss_(ss.str()), j_(std::move(j)) {} + event(const std::stringstream &ss, json j) + : ss_(ss.str()), j_(std::move(j)) {} public: event(const event &) = delete; @@ -53,18 +39,13 @@ public: auto operator=(event &&) -> event & = delete; virtual ~event() = default; -private: - bool allow_async_; - protected: std::stringstream ss_; - json j_; + json j_{}; public: [[nodiscard]] virtual auto clone() const -> std::shared_ptr = 0; - [[nodiscard]] auto get_allow_async() const -> bool { return allow_async_; } - [[nodiscard]] virtual auto get_event_level() const -> event_level = 0; [[nodiscard]] auto get_json() const -> json { return j_; } @@ -75,18 +56,4 @@ public: }; } // namespace repertory -NLOHMANN_JSON_NAMESPACE_BEGIN -template <> struct adl_serializer> { - static void to_json(json &data, - const std::atomic &value) { - data = repertory::event_level_to_string(value.load()); - } - - static void from_json(const json &data, - std::atomic &value) { - value.store(repertory::event_level_from_string(data.get())); - } -}; -NLOHMANN_JSON_NAMESPACE_END - #endif // REPERTORY_INCLUDE_EVENTS_EVENT_HPP_ diff --git a/repertory/librepertory/include/events/event_system.hpp b/repertory/librepertory/include/events/event_system.hpp index 9cc4e87c..4c73f35a 100644 --- a/repertory/librepertory/include/events/event_system.hpp +++ b/repertory/librepertory/include/events/event_system.hpp @@ -24,6 +24,7 @@ #include "events/event.hpp" #include "events/t_event_system.hpp" +#include "types/repertory.hpp" namespace repertory { using event_system = t_event_system; @@ -60,8 +61,7 @@ public: \ #define E_BEGIN(name, el) \ class name final : public virtual event { \ private: \ - name(const std::stringstream &ss, const json &j, bool allow_async) \ - : event(ss, j, allow_async) {} \ + name(const std::stringstream &ss, const json &j) : event(ss, j) {} \ \ public: \ ~name() override = default; \ @@ -84,28 +84,26 @@ public: \ } \ \ [[nodiscard]] auto clone() const -> std::shared_ptr override { \ - return std::shared_ptr(new name(ss_, j_, get_allow_async())); \ + return std::shared_ptr(new name(ss_, j_)); \ } #define E_END() } -#define E_SIMPLE(event_name, el, allow_async) \ +#define E_SIMPLE(event_name, el) \ E_BEGIN(event_name, el) \ public: \ - event_name() : event(allow_async) {} \ + event_name() {} \ E_END() -#define E_SIMPLE1(event_name, el, allow_async, type, name, short_name, tc) \ +#define E_SIMPLE1(event_name, el, type, name, short_name, tc) \ E_BEGIN(event_name, el) \ - explicit event_name(const type &tv) : event(allow_async) { \ - init_##short_name(tv); \ - } \ + explicit event_name(const type &tv) { init_##short_name(tv); } \ E_PROP(type, name, short_name, tc) \ E_END() -#define E_SIMPLE2(event_name, el, allow_async, type, name, short_name, tc, \ - type2, name2, short_name2, tc2) \ +#define E_SIMPLE2(event_name, el, type, name, short_name, tc, type2, name2, \ + short_name2, tc2) \ E_BEGIN(event_name, el) \ - explicit event_name(const type &tv, const type2 &tv2) : event(allow_async) { \ + explicit event_name(const type &tv, const type2 &tv2) { \ init_##short_name(tv); \ init_##short_name2(tv2); \ } \ @@ -113,12 +111,10 @@ public: \ E_PROP(type2, name2, short_name2, tc2) \ E_END() -#define E_SIMPLE3(event_name, el, allow_async, type, name, short_name, tc, \ - type2, name2, short_name2, tc2, type3, name3, short_name3, \ - tc3) \ +#define E_SIMPLE3(event_name, el, type, name, short_name, tc, type2, name2, \ + short_name2, tc2, type3, name3, short_name3, tc3) \ E_BEGIN(event_name, el) \ - explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3) \ - : event(allow_async) { \ + explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3) { \ init_##short_name(tv); \ init_##short_name2(tv2); \ init_##short_name3(tv3); \ @@ -128,13 +124,12 @@ public: \ E_PROP(type3, name3, short_name3, tc3) \ E_END() -#define E_SIMPLE4(event_name, el, allow_async, type, name, short_name, tc, \ - type2, name2, short_name2, tc2, type3, name3, short_name3, \ - tc3, type4, name4, short_name4, tc4) \ +#define E_SIMPLE4(event_name, el, type, name, short_name, tc, type2, name2, \ + short_name2, tc2, type3, name3, short_name3, tc3, type4, \ + name4, short_name4, tc4) \ E_BEGIN(event_name, el) \ explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \ - const type4 &tv4) \ - : event(allow_async) { \ + const type4 &tv4) { \ init_##short_name(tv); \ init_##short_name2(tv2); \ init_##short_name3(tv3); \ @@ -146,14 +141,12 @@ public: \ E_PROP(type4, name4, short_name4, tc4) \ E_END() -#define E_SIMPLE5(event_name, el, allow_async, type, name, short_name, tc, \ - type2, name2, short_name2, tc2, type3, name3, short_name3, \ - tc3, type4, name4, short_name4, tc4, type5, name5, \ - short_name5, tc5) \ +#define E_SIMPLE5(event_name, el, type, name, short_name, tc, type2, name2, \ + short_name2, tc2, type3, name3, short_name3, tc3, type4, \ + name4, short_name4, tc4, type5, name5, short_name5, tc5) \ E_BEGIN(event_name, el) \ explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \ - const type4 &tv4, const type5 &tv5) \ - : event(allow_async) { \ + const type4 &tv4, const type5 &tv5) { \ init_##short_name(tv); \ init_##short_name2(tv2); \ init_##short_name3(tv3); \ @@ -167,14 +160,13 @@ public: \ E_PROP(type5, name5, short_name5, tc5) \ E_END() -#define E_SIMPLE6(event_name, el, allow_async, type, name, short_name, tc, \ - type2, name2, short_name2, tc2, type3, name3, short_name3, \ - tc3, type4, name4, short_name4, tc4, type5, name5, \ - short_name5, tc5, type6, name6, short_name6, tc6) \ +#define E_SIMPLE6(event_name, el, type, name, short_name, tc, type2, name2, \ + short_name2, tc2, type3, name3, short_name3, tc3, type4, \ + name4, short_name4, tc4, type5, name5, short_name5, tc5, \ + type6, name6, short_name6, tc6) \ E_BEGIN(event_name, el) \ explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \ - const type4 &tv4, const type5 &tv5, const type6 &tv6) \ - : event(allow_async) { \ + const type4 &tv4, const type5 &tv5, const type6 &tv6) { \ init_##short_name(tv); \ init_##short_name2(tv2); \ init_##short_name3(tv3); \ @@ -190,16 +182,15 @@ public: \ E_PROP(type6, name6, short_name6, tc6) \ E_END() -#define E_SIMPLE7(event_name, el, allow_async, type, name, short_name, tc, \ - type2, name2, short_name2, tc2, type3, name3, short_name3, \ - tc3, type4, name4, short_name4, tc4, type5, name5, \ - short_name5, tc5, type6, name6, short_name6, tc6, type7, \ - name7, short_name7, tc7) \ +#define E_SIMPLE7(event_name, el, type, name, short_name, tc, type2, name2, \ + short_name2, tc2, type3, name3, short_name3, tc3, type4, \ + name4, short_name4, tc4, type5, name5, short_name5, tc5, \ + type6, name6, short_name6, tc6, type7, name7, short_name7, \ + tc7) \ E_BEGIN(event_name, el) \ explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \ const type4 &tv4, const type5 &tv5, const type6 &tv6, \ - const type7 &tv7) \ - : event(allow_async) { \ + const type7 &tv7) { \ init_##short_name(tv); \ init_##short_name2(tv2); \ init_##short_name3(tv3); \ diff --git a/repertory/librepertory/include/events/events.hpp b/repertory/librepertory/include/events/events.hpp index 92214f41..fcb7e5fc 100644 --- a/repertory/librepertory/include/events/events.hpp +++ b/repertory/librepertory/include/events/events.hpp @@ -28,126 +28,126 @@ namespace repertory { // clang-format off -E_SIMPLE2(curl_error, error, true, +E_SIMPLE2(curl_error, error, std::string, url, url, E_FROM_STRING, CURLcode, res, res, E_FROM_CURL_CODE ); -E_SIMPLE3(debug_log, debug, true, +E_SIMPLE3(debug_log, debug, std::string, function, func, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING, std::string, data, data, E_FROM_STRING ); -E_SIMPLE1(directory_removed, debug, true, +E_SIMPLE1(directory_removed, debug, std::string, api_path, ap, E_FROM_STRING ); -E_SIMPLE2(directory_removed_externally, warn, true, +E_SIMPLE2(directory_removed_externally, warn, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING ); -E_SIMPLE2(directory_remove_failed, error, true, +E_SIMPLE2(directory_remove_failed, error, std::string, api_path, ap, E_FROM_STRING, std::string, error, err, E_FROM_STRING ); -E_SIMPLE2(drive_mount_failed, error, true, +E_SIMPLE2(drive_mount_failed, error, std::string, location, loc, E_FROM_STRING, std::string, result, res, E_FROM_STRING ); -E_SIMPLE1(drive_mounted, info, true, +E_SIMPLE1(drive_mounted, info, std::string, location, loc, E_FROM_STRING ); -E_SIMPLE1(drive_mount_result, info, true, +E_SIMPLE1(drive_mount_result, info, std::string, result, res, E_FROM_STRING ); -E_SIMPLE1(drive_unmount_pending, info, true, +E_SIMPLE1(drive_unmount_pending, info, std::string, location, loc, E_FROM_STRING ); -E_SIMPLE1(drive_unmounted, info, true, +E_SIMPLE1(drive_unmounted, info, std::string, location, loc, E_FROM_STRING ); -E_SIMPLE1(event_level_changed, info, true, +E_SIMPLE1(event_level_changed, info, std::string, new_event_level, level, E_FROM_STRING ); -E_SIMPLE1(failed_upload_queued, error, true, +E_SIMPLE1(failed_upload_queued, error, std::string, api_path, ap, E_FROM_STRING ); -E_SIMPLE1(failed_upload_removed, warn, true, +E_SIMPLE1(failed_upload_removed, warn, std::string, api_path, ap, E_FROM_STRING ); -E_SIMPLE1(failed_upload_retry, info, true, +E_SIMPLE1(failed_upload_retry, info, std::string, api_path, ap, E_FROM_STRING ); -E_SIMPLE2(file_get_failed, error, true, +E_SIMPLE2(file_get_failed, error, std::string, api_path, ap, E_FROM_STRING, std::string, error, err, E_FROM_STRING ); -E_SIMPLE1(file_get_api_list_failed, error, true, +E_SIMPLE1(file_get_api_list_failed, error, std::string, error, err, E_FROM_STRING ); -E_SIMPLE1(file_pinned, info, true, +E_SIMPLE1(file_pinned, info, std::string, api_path, ap, E_FROM_STRING ); -E_SIMPLE3(file_read_bytes_failed, error, true, +E_SIMPLE3(file_read_bytes_failed, error, std::string, api_path, ap, E_FROM_STRING, std::string, error, err, E_FROM_STRING, std::size_t, retry, retry, E_FROM_SIZE_T ); -E_SIMPLE1(file_removed, debug, true, +E_SIMPLE1(file_removed, debug, std::string, api_path, ap, E_FROM_STRING ); -E_SIMPLE2(file_removed_externally, warn, true, +E_SIMPLE2(file_removed_externally, warn, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING ); -E_SIMPLE2(file_remove_failed, error, true, +E_SIMPLE2(file_remove_failed, error, std::string, api_path, ap, E_FROM_STRING, std::string, error, err, E_FROM_STRING ); -E_SIMPLE3(file_rename_failed, error, true, +E_SIMPLE3(file_rename_failed, error, std::string, from_api_path, FROM, E_FROM_STRING, std::string, to_api_path, TO, E_FROM_STRING, std::string, error, err, E_FROM_STRING ); -E_SIMPLE2(file_get_size_failed, error, true, +E_SIMPLE2(file_get_size_failed, error, std::string, api_path, ap, E_FROM_STRING, std::string, error, err, E_FROM_STRING ); -E_SIMPLE3(filesystem_item_added, debug, true, +E_SIMPLE3(filesystem_item_added, debug, std::string, api_path, ap, E_FROM_STRING, std::string, parent, parent, E_FROM_STRING, bool, directory, dir, E_FROM_BOOL ); -E_SIMPLE4(filesystem_item_closed, trace, true, +E_SIMPLE4(filesystem_item_closed, trace, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING, bool, directory, dir, E_FROM_BOOL, bool, changed, changed, E_FROM_BOOL ); -E_SIMPLE5(filesystem_item_handle_closed, trace, true, +E_SIMPLE5(filesystem_item_handle_closed, trace, std::string, api_path, ap, E_FROM_STRING, std::uint64_t, handle, handle, E_FROM_UINT64, std::string, source, src, E_FROM_STRING, @@ -155,136 +155,136 @@ E_SIMPLE5(filesystem_item_handle_closed, trace, true, bool, changed, changed, E_FROM_BOOL ); -E_SIMPLE4(filesystem_item_handle_opened, trace, true, +E_SIMPLE4(filesystem_item_handle_opened, trace, std::string, api_path, ap, E_FROM_STRING, std::uint64_t, handle, handle, E_FROM_UINT64, std::string, source, src, E_FROM_STRING, bool, directory, dir, E_FROM_BOOL ); -E_SIMPLE2(filesystem_item_evicted, info, true, +E_SIMPLE2(filesystem_item_evicted, info, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING ); -E_SIMPLE3(filesystem_item_opened, trace, true, +E_SIMPLE3(filesystem_item_opened, trace, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING, bool, directory, dir, E_FROM_BOOL ); -E_SIMPLE1(file_unpinned, info, true, +E_SIMPLE1(file_unpinned, info, std::string, api_path, ap, E_FROM_STRING ); -E_SIMPLE4(file_upload_completed, info, true, +E_SIMPLE4(file_upload_completed, info, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING, api_error, result, res, E_FROM_API_FILE_ERROR, bool, cancelled, cancel, E_FROM_BOOL ); -E_SIMPLE3(file_upload_failed, error, true, +E_SIMPLE3(file_upload_failed, error, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING, std::string, error, err, E_FROM_STRING ); -E_SIMPLE2(file_upload_not_found, warn, true, +E_SIMPLE2(file_upload_not_found, warn, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING ); -E_SIMPLE2(file_upload_queued, info, true, +E_SIMPLE2(file_upload_queued, info, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING ); -E_SIMPLE1(file_upload_removed, debug, true, +E_SIMPLE1(file_upload_removed, debug, std::string, api_path, ap, E_FROM_STRING ); -E_SIMPLE3(file_upload_retry, info, true, +E_SIMPLE3(file_upload_retry, info, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING, api_error, result, res, E_FROM_API_FILE_ERROR ); -E_SIMPLE2(file_upload_started, info, true, +E_SIMPLE2(file_upload_started, info, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING ); -E_SIMPLE1(orphaned_file_deleted, warn, true, +E_SIMPLE1(orphaned_file_deleted, warn, std::string, source, src, E_FROM_STRING ); -E_SIMPLE1(orphaned_file_detected, warn, true, +E_SIMPLE1(orphaned_file_detected, warn, std::string, source, src, E_FROM_STRING ); -E_SIMPLE3(orphaned_file_processing_failed, error, true, +E_SIMPLE3(orphaned_file_processing_failed, error, std::string, source, src, E_FROM_STRING, std::string, dest, dest, E_FROM_STRING, std::string, result, res, E_FROM_STRING ); -E_SIMPLE1(orphaned_source_file_detected, info, true, +E_SIMPLE1(orphaned_source_file_detected, info, std::string, source, src, E_FROM_STRING ); -E_SIMPLE1(orphaned_source_file_removed, info, true, +E_SIMPLE1(orphaned_source_file_removed, info, std::string, source, src, E_FROM_STRING ); -E_SIMPLE1(polling_item_begin, debug, true, +E_SIMPLE1(polling_item_begin, debug, std::string, item_name, item, E_FROM_STRING ); -E_SIMPLE1(polling_item_end, debug, true, +E_SIMPLE1(polling_item_end, debug, std::string, item_name, item, E_FROM_STRING ); -E_SIMPLE2(provider_offline, error, true, +E_SIMPLE2(provider_offline, error, std::string, host_name_or_ip, host, E_FROM_STRING, std::uint16_t, port, port, E_FROM_UINT16 ); -E_SIMPLE2(provider_upload_begin, info, true, +E_SIMPLE2(provider_upload_begin, info, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING ); -E_SIMPLE3(provider_upload_end, info, true, +E_SIMPLE3(provider_upload_end, info, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING, api_error, result, res, E_FROM_API_FILE_ERROR ); -E_SIMPLE2(repertory_exception, error, true, +E_SIMPLE2(repertory_exception, error, std::string, function, func, E_FROM_STRING, std::string, message, msg, E_FROM_STRING ); -E_SIMPLE1(rpc_server_exception, error, true, +E_SIMPLE1(rpc_server_exception, error, std::string, exception, exception, E_FROM_STRING ); -E_SIMPLE1(service_shutdown_begin, debug, true, +E_SIMPLE1(service_shutdown_begin, debug, std::string, service, svc, E_FROM_STRING ); -E_SIMPLE1(service_shutdown_end, debug, true, +E_SIMPLE1(service_shutdown_end, debug, std::string, service, svc, E_FROM_STRING ); -E_SIMPLE1(service_started, debug, true, +E_SIMPLE1(service_started, debug, std::string, service, svc, E_FROM_STRING ); -E_SIMPLE(unmount_requested, info, true); +E_SIMPLE(unmount_requested, info); #if !defined(_WIN32) -E_SIMPLE2(unmount_result, info, true, +E_SIMPLE2(unmount_result, info, std::string, location, loc, E_FROM_STRING, std::string, result, res, E_FROM_STRING ); diff --git a/repertory/librepertory/include/events/t_event_system.hpp b/repertory/librepertory/include/events/t_event_system.hpp index 6770ce5c..c19e937d 100644 --- a/repertory/librepertory/include/events/t_event_system.hpp +++ b/repertory/librepertory/include/events/t_event_system.hpp @@ -104,7 +104,6 @@ private: event_list_.clear(); } - event_notify_.notify_all(); lock.unlock(); if (events.empty()) { @@ -117,14 +116,10 @@ private: recur_mutex_lock consumer_lock(consumer_mutex_); if (event_consumers_.find(name) != event_consumers_.end()) { for (auto *consumer : event_consumers_[name]) { - if (event.get_allow_async()) { - futures.emplace_back( - std::async(std::launch::async, [consumer, &event]() { - consumer->notify_event(event); - })); - } else { - consumer->notify_event(event); - } + futures.emplace_back( + std::async(std::launch::async, [consumer, &event]() { + consumer->notify_event(event); + })); } } @@ -138,9 +133,6 @@ private: notify_events("", *evt.get()); notify_events(evt->get_name(), *evt.get()); } - - lock.lock(); - event_notify_.notify_all(); } void queue_event(std::shared_ptr evt) { diff --git a/repertory/librepertory/include/file_manager/events.hpp b/repertory/librepertory/include/file_manager/events.hpp index dae3d9f9..01cca60a 100644 --- a/repertory/librepertory/include/file_manager/events.hpp +++ b/repertory/librepertory/include/file_manager/events.hpp @@ -27,55 +27,55 @@ namespace repertory { // clang-format off -E_SIMPLE2(download_begin, info, true, +E_SIMPLE2(download_begin, info, std::string, api_path, ap, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING ); -E_SIMPLE3(download_end, info, true, +E_SIMPLE3(download_end, info, std::string, api_path, ap, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING, api_error, result, result, E_FROM_API_FILE_ERROR ); -E_SIMPLE3(download_progress, info, true, +E_SIMPLE3(download_progress, info, std::string, api_path, ap, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING, double, progress, prog, E_FROM_DOUBLE_PRECISE ); -E_SIMPLE2(download_restored, info, true, +E_SIMPLE2(download_restored, info, std::string, api_path, ap, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING ); -E_SIMPLE3(download_restore_failed, error, true, +E_SIMPLE3(download_restore_failed, error, std::string, api_path, ap, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING, std::string, error, err, E_FROM_STRING ); -E_SIMPLE3(download_resume_add_failed, error, true, +E_SIMPLE3(download_resume_add_failed, error, std::string, api_path, ap, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING, std::string, error, err, E_FROM_STRING ); -E_SIMPLE2(download_resume_added, debug, true, +E_SIMPLE2(download_resume_added, debug, std::string, api_path, ap, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING ); -E_SIMPLE2(download_resume_removed, debug, true, +E_SIMPLE2(download_resume_removed, debug, std::string, api_path, ap, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING ); -E_SIMPLE1(item_timeout, trace, true, +E_SIMPLE1(item_timeout, trace, std::string, api_path, ap, E_FROM_STRING ); -E_SIMPLE3(download_type_selected, debug, true, +E_SIMPLE3(download_type_selected, debug, std::string, api_path, ap, E_FROM_STRING, std::string, source, src, E_FROM_STRING, download_type, download_type, type, E_FROM_DOWNLOAD_TYPE diff --git a/repertory/librepertory/include/types/repertory.hpp b/repertory/librepertory/include/types/repertory.hpp index 8ed2d10b..434205da 100644 --- a/repertory/librepertory/include/types/repertory.hpp +++ b/repertory/librepertory/include/types/repertory.hpp @@ -246,6 +246,22 @@ download_type_from_string(std::string type, [[nodiscard]] auto download_type_to_string(const download_type &type) -> std::string; +enum class event_level { + critical, + error, + warn, + info, + debug, + trace, +}; + +[[nodiscard]] auto +event_level_from_string(std::string level, + event_level default_level = event_level::info) + -> event_level; + +[[nodiscard]] auto event_level_to_string(event_level level) -> std::string; + enum class exit_code : std::int32_t { success = 0, communication_error = -1, @@ -654,6 +670,18 @@ template <> struct adl_serializer { value = repertory::download_type_from_string(data.get()); } }; + +template <> struct adl_serializer> { + static void to_json(json &data, + const std::atomic &value) { + data = repertory::event_level_to_string(value.load()); + } + + static void from_json(const json &data, + std::atomic &value) { + value.store(repertory::event_level_from_string(data.get())); + } +}; NLOHMANN_JSON_NAMESPACE_END #endif // REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_ diff --git a/repertory/librepertory/src/comm/packet/packet_client.cpp b/repertory/librepertory/src/comm/packet/packet_client.cpp index ac49d98c..3544e4f4 100644 --- a/repertory/librepertory/src/comm/packet/packet_client.cpp +++ b/repertory/librepertory/src/comm/packet/packet_client.cpp @@ -32,7 +32,7 @@ namespace repertory { // clang-format off -E_SIMPLE2(packet_client_timeout, error, true, +E_SIMPLE2(packet_client_timeout, error, std::string, event_name, en, E_FROM_STRING, std::string, message, msg, E_FROM_STRING ); @@ -112,8 +112,8 @@ void packet_client::put_client(std::shared_ptr &cli) { } } -auto packet_client::read_packet(client &cli, - packet &response) const -> packet::error_type { +auto packet_client::read_packet(client &cli, packet &response) const + -> packet::error_type { data_buffer buffer(sizeof(std::uint32_t)); const auto read_buffer = [&]() { std::uint32_t offset{}; @@ -154,8 +154,8 @@ void packet_client::resolve() { .resolve(cfg_.host_name_or_ip, std::to_string(cfg_.api_port)); } -auto packet_client::send(std::string_view method, - std::uint32_t &service_flags) -> packet::error_type { +auto packet_client::send(std::string_view method, std::uint32_t &service_flags) + -> packet::error_type { packet request; return send(method, request, service_flags); } @@ -167,8 +167,8 @@ auto packet_client::send(std::string_view method, packet &request, } auto packet_client::send(std::string_view method, packet &request, - packet &response, - std::uint32_t &service_flags) -> packet::error_type { + packet &response, std::uint32_t &service_flags) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); auto success = false; diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp index 4cf8ca72..be216674 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp @@ -47,7 +47,7 @@ namespace repertory::remote_fuse { file, ret) // clang-format off -E_SIMPLE3(remote_fuse_server_event, debug, true, +E_SIMPLE3(remote_fuse_server_event, debug, std::string, function, func, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING, packet::error_type, result, res, E_FROM_INT32 @@ -208,8 +208,8 @@ auto remote_server::fuse_access(const char *path, const std::int32_t &mask) return ret; } -auto remote_server::fuse_chflags(const char *path, - std::uint32_t flags) -> packet::error_type { +auto remote_server::fuse_chflags(const char *path, std::uint32_t flags) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto api_path = utils::path::create_api_path(path); @@ -321,9 +321,10 @@ length); ret = ((res < 0) ? -errno : 0); #endif return ret; }*/ -auto remote_server::fuse_fgetattr( - const char *path, remote::stat &r_stat, bool &directory, - const remote::file_handle &handle) -> packet::error_type { +auto remote_server::fuse_fgetattr(const char *path, remote::stat &r_stat, + bool &directory, + const remote::file_handle &handle) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); r_stat = {}; @@ -333,7 +334,7 @@ auto remote_server::fuse_fgetattr( auto res = has_open_info(static_cast(handle), EBADF); if (res == 0) { directory = utils::file::directory(file_path).exists(); - struct stat64 unix_st {}; + struct stat64 unix_st{}; res = fstat64(static_cast(handle), &unix_st); if (res == 0) { populate_stat(unix_st, r_stat); @@ -345,9 +346,10 @@ auto remote_server::fuse_fgetattr( return ret; } -auto remote_server::fuse_fsetattr_x( - const char *path, const remote::setattr_x &attr, - const remote::file_handle &handle) -> packet::error_type { +auto remote_server::fuse_fsetattr_x(const char *path, + const remote::setattr_x &attr, + const remote::file_handle &handle) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto api_path = utils::path::create_api_path(path); @@ -463,9 +465,10 @@ auto remote_server::fuse_fsync(const char *path, const std::int32_t &datasync, return ret; } -auto remote_server::fuse_ftruncate( - const char *path, const remote::file_offset &size, - const remote::file_handle &handle) -> packet::error_type { +auto remote_server::fuse_ftruncate(const char *path, + const remote::file_offset &size, + const remote::file_handle &handle) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto file_path = construct_path(path); @@ -493,7 +496,7 @@ auto remote_server::fuse_getattr(const char *path, remote::stat &r_stat, directory = utils::file::directory(file_path).exists(); - struct stat64 unix_st {}; + struct stat64 unix_st{}; auto res = stat64(file_path.c_str(), &unix_st); if (res == 0) { populate_stat(unix_st, r_stat); @@ -558,9 +561,10 @@ STATUS_NOT_IMPLEMENTED; #endif RAISE_REMOTE_FUSE_SERVER_EVENT(function_name, file_path, ret); return ret; }*/ -auto remote_server::fuse_getxtimes( - const char *path, remote::file_time &bkuptime, - remote::file_time &crtime) -> packet::error_type { +auto remote_server::fuse_getxtimes(const char *path, + remote::file_time &bkuptime, + remote::file_time &crtime) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto api_path = utils::path::create_api_path(path); @@ -665,10 +669,11 @@ auto remote_server::fuse_opendir(const char *path, remote::file_handle &handle) return ret; } -auto remote_server::fuse_read( - const char *path, char *buffer, const remote::file_size &read_size, - const remote::file_offset &read_offset, - const remote::file_handle &handle) -> packet::error_type { +auto remote_server::fuse_read(const char *path, char *buffer, + const remote::file_size &read_size, + const remote::file_offset &read_offset, + const remote::file_handle &handle) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto file_path = construct_path(path); @@ -689,8 +694,8 @@ auto remote_server::fuse_read( return static_cast(ret); } -auto remote_server::fuse_rename(const char *from, - const char *to) -> packet::error_type { +auto remote_server::fuse_rename(const char *from, const char *to) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto from_path = utils::path::combine(mount_location_, {from}); @@ -728,8 +733,9 @@ auto remote_server::fuse_readdir(const char *path, return ret; } -auto remote_server::fuse_release( - const char *path, const remote::file_handle &handle) -> packet::error_type { +auto remote_server::fuse_release(const char *path, + const remote::file_handle &handle) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); packet::error_type ret = 0; @@ -746,8 +752,9 @@ auto remote_server::fuse_release( return ret; } -auto remote_server::fuse_releasedir( - const char *path, const remote::file_handle &handle) -> packet::error_type { +auto remote_server::fuse_releasedir(const char *path, + const remote::file_handle &handle) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto file_path = construct_path(path); @@ -792,8 +799,9 @@ auto remote_server::fuse_setattr_x(const char *path, remote::setattr_x &attr) return ret; } -auto remote_server::fuse_setbkuptime( - const char *path, const remote::file_time &bkuptime) -> packet::error_type { +auto remote_server::fuse_setbkuptime(const char *path, + const remote::file_time &bkuptime) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto api_path = utils::path::create_api_path(path); @@ -812,8 +820,9 @@ auto remote_server::fuse_setbkuptime( return ret; } -auto remote_server::fuse_setchgtime( - const char *path, const remote::file_time &chgtime) -> packet::error_type { +auto remote_server::fuse_setchgtime(const char *path, + const remote::file_time &chgtime) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto api_path = utils::path::create_api_path(path); @@ -832,8 +841,9 @@ auto remote_server::fuse_setchgtime( return ret; } -auto remote_server::fuse_setcrtime( - const char *path, const remote::file_time &crtime) -> packet::error_type { +auto remote_server::fuse_setcrtime(const char *path, + const remote::file_time &crtime) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto api_path = utils::path::create_api_path(path); @@ -924,8 +934,9 @@ auto remote_server::fuse_statfs_x(const char *path, std::uint64_t bsize, return 0; } -auto remote_server::fuse_truncate( - const char *path, const remote::file_offset &size) -> packet::error_type { +auto remote_server::fuse_truncate(const char *path, + const remote::file_offset &size) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto file_path = construct_path(path); @@ -946,8 +957,8 @@ auto remote_server::fuse_unlink(const char *path) -> packet::error_type { } auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv, - std::uint64_t op0, - std::uint64_t op1) -> packet::error_type { + std::uint64_t op0, std::uint64_t op1) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto file_path = construct_path(path); @@ -974,10 +985,11 @@ auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv, return ret; } -auto remote_server::fuse_write( - const char *path, const char *buffer, const remote::file_size &write_size, - const remote::file_offset &write_offset, - const remote::file_handle &handle) -> packet::error_type { +auto remote_server::fuse_write(const char *path, const char *buffer, + const remote::file_size &write_size, + const remote::file_offset &write_offset, + const remote::file_handle &handle) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto file_path = construct_path(path); @@ -1007,8 +1019,8 @@ auto remote_server::fuse_write_base64( } // WinFSP Layer -auto remote_server::winfsp_can_delete(PVOID file_desc, - PWSTR file_name) -> packet::error_type { +auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR file_name) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto relative_path = utils::string::to_utf8(file_name); @@ -1033,8 +1045,8 @@ auto remote_server::winfsp_can_delete(PVOID file_desc, } auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name, - UINT32 flags, - BOOLEAN &was_deleted) -> packet::error_type { + UINT32 flags, BOOLEAN &was_deleted) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto relative_path = utils::string::to_utf8(file_name); @@ -1111,8 +1123,8 @@ auto remote_server::winfsp_create(PWSTR file_name, UINT32 create_options, UINT32 granted_access, UINT32 attributes, UINT64 /*allocation_size*/, PVOID *file_desc, remote::file_info *file_info, - std::string &normalized_name, - BOOLEAN &exists) -> packet::error_type { + std::string &normalized_name, BOOLEAN &exists) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto relative_path = utils::string::to_utf8(file_name); @@ -1184,8 +1196,9 @@ auto remote_server::winfsp_flush(PVOID file_desc, remote::file_info *file_info) return ret; } -auto remote_server::winfsp_get_file_info( - PVOID file_desc, remote::file_info *file_info) -> packet::error_type { +auto remote_server::winfsp_get_file_info(PVOID file_desc, + remote::file_info *file_info) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto handle = reinterpret_cast(file_desc); @@ -1228,9 +1241,10 @@ auto remote_server::winfsp_get_security_by_name( return ret; } -auto remote_server::winfsp_get_volume_info( - UINT64 &total_size, UINT64 &free_size, - std::string &volume_label) -> packet::error_type { +auto remote_server::winfsp_get_volume_info(UINT64 &total_size, + UINT64 &free_size, + std::string &volume_label) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); drive_.get_volume_info(total_size, free_size, volume_label); @@ -1247,10 +1261,11 @@ auto remote_server::winfsp_mounted(const std::wstring &location) return STATUS_SUCCESS; } -auto remote_server::winfsp_open( - PWSTR file_name, UINT32 create_options, UINT32 granted_access, - PVOID *file_desc, remote::file_info *file_info, - std::string &normalized_name) -> packet::error_type { +auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options, + UINT32 granted_access, PVOID *file_desc, + remote::file_info *file_info, + std::string &normalized_name) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto relative_path = utils::string::to_utf8(file_name); @@ -1291,10 +1306,11 @@ auto remote_server::winfsp_open( return ret; } -auto remote_server::winfsp_overwrite( - PVOID file_desc, UINT32 attributes, BOOLEAN replace_attributes, - UINT64 /*allocation_size*/, - remote::file_info *file_info) -> packet::error_type { +auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes, + BOOLEAN replace_attributes, + UINT64 /*allocation_size*/, + remote::file_info *file_info) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto handle = reinterpret_cast(file_desc); @@ -1410,9 +1426,10 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/, return ret; } -auto remote_server::winfsp_rename( - PVOID /*file_desc*/, PWSTR file_name, PWSTR new_file_name, - BOOLEAN replace_if_exists) -> packet::error_type { +auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name, + PWSTR new_file_name, + BOOLEAN replace_if_exists) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto relative_path = utils::string::to_utf8(file_name); @@ -1506,9 +1523,10 @@ auto remote_server::winfsp_set_basic_info( return ret; } -auto remote_server::winfsp_set_file_size( - PVOID file_desc, UINT64 new_size, BOOLEAN set_allocation_size, - remote::file_info *file_info) -> packet::error_type { +auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size, + BOOLEAN set_allocation_size, + remote::file_info *file_info) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto handle = reinterpret_cast(file_desc); @@ -1544,10 +1562,12 @@ auto remote_server::winfsp_unmounted(const std::wstring &location) return STATUS_SUCCESS; } -auto remote_server::winfsp_write( - PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, - BOOLEAN write_to_end, BOOLEAN constrained_io, PUINT32 bytes_transferred, - remote::file_info *file_info) -> packet::error_type { +auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, + UINT32 length, BOOLEAN write_to_end, + BOOLEAN constrained_io, + PUINT32 bytes_transferred, + remote::file_info *file_info) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); *bytes_transferred = 0; @@ -1595,8 +1615,9 @@ auto remote_server::winfsp_write( return ret; } -auto remote_server::json_create_directory_snapshot( - const std::string &path, json &json_data) -> packet::error_type { +auto remote_server::json_create_directory_snapshot(const std::string &path, + json &json_data) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto api_path = utils::path::create_api_path(path); @@ -1655,8 +1676,8 @@ auto remote_server::json_read_directory_snapshot( } auto remote_server::json_release_directory_snapshot( - const std::string &path, - const remote::file_handle &handle) -> packet::error_type { + const std::string &path, const remote::file_handle &handle) + -> packet::error_type { REPERTORY_USES_FUNCTION_NAME(); const auto file_path = construct_path(path); diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp index 97860eee..ecb09587 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp @@ -39,7 +39,7 @@ namespace repertory::remote_winfsp { std::string{func}, file, ret) // clang-format off -E_SIMPLE3(remote_winfsp_client_event, debug, true, +E_SIMPLE3(remote_winfsp_client_event, debug, std::string, function, func, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING, packet::error_type, result, res, E_FROM_INT32 diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp index b447fd9d..2f2b8922 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp @@ -53,7 +53,7 @@ namespace repertory::remote_winfsp { std::string{func}, file, ret) // clang-format off -E_SIMPLE3(remote_winfsp_server_event, debug, true, +E_SIMPLE3(remote_winfsp_server_event, debug, std::string, function, FUNC, E_FROM_STRING, std::string, api_path, AP, E_FROM_STRING, packet::error_type, result, RES, E_FROM_INT32 diff --git a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp index f8d1e91b..e9bc705b 100644 --- a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp +++ b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp @@ -19,7 +19,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include #if defined(_WIN32) #include "drives/winfsp/winfsp_drive.hpp" @@ -45,15 +44,15 @@ namespace repertory { // clang-format off -E_SIMPLE3(winfsp_event, debug, true, +E_SIMPLE3(winfsp_event, debug, std::string, function, func, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING, NTSTATUS, result, res, E_FROM_INT32 ); -E_SIMPLE(drive_stop_begin, info, true); -E_SIMPLE(drive_stop_end, info, true); -E_SIMPLE(drive_stop_timed_out, info, true); +E_SIMPLE(drive_stop_begin, info); +E_SIMPLE(drive_stop_end, info); +E_SIMPLE(drive_stop_timed_out, info); // clang-format on #define RAISE_WINFSP_EVENT(func, file, ret) \ diff --git a/repertory/librepertory/src/events/event.cpp b/repertory/librepertory/src/events/event.cpp deleted file mode 100644 index f2976a3c..00000000 --- a/repertory/librepertory/src/events/event.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - Copyright <2018-2025> - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ -#include "events/event.hpp" - -#include "utils/string.hpp" - -namespace repertory { -auto event_level_from_string(std::string level, - event_level default_level) -> event_level { - level = utils::string::to_lower(level); - if (level == "critical" || level == "event_level::critical") { - return event_level::critical; - } - - if (level == "debug" || level == "event_level::debug") { - return event_level::debug; - } - - if (level == "warn" || level == "event_level::warn") { - return event_level::warn; - } - - if (level == "info" || level == "event_level::info") { - return event_level::info; - } - - if (level == "error" || level == "event_level::error") { - return event_level::error; - } - - if (level == "trace" || level == "event_level::trace") { - return event_level::trace; - } - - return default_level; -} - -auto event_level_to_string(event_level level) -> std::string { - switch (level) { - case event_level::critical: - return "critical"; - case event_level::debug: - return "debug"; - case event_level::error: - return "error"; - case event_level::info: - return "info"; - case event_level::warn: - return "warn"; - case event_level::trace: - return "trace"; - default: - return "info"; - } -} -} // namespace repertory diff --git a/repertory/librepertory/src/file_manager/cache_size_mgr.cpp b/repertory/librepertory/src/file_manager/cache_size_mgr.cpp index ce7d1e09..0a3da1d7 100644 --- a/repertory/librepertory/src/file_manager/cache_size_mgr.cpp +++ b/repertory/librepertory/src/file_manager/cache_size_mgr.cpp @@ -29,12 +29,12 @@ namespace repertory { // clang-format off -E_SIMPLE2(invalid_cache_size, warn, true, +E_SIMPLE2(invalid_cache_size, warn, std::uint64_t, cache_size, sz, E_FROM_UINT64, std::uint64_t, by, by, E_FROM_UINT64 ); -E_SIMPLE2(max_cache_size_reached, warn, true, +E_SIMPLE2(max_cache_size_reached, warn, std::uint64_t, cache_size, sz, E_FROM_UINT64, std::uint64_t, max_cache_size, max, E_FROM_UINT64 ); diff --git a/repertory/librepertory/src/types/repertory.cpp b/repertory/librepertory/src/types/repertory.cpp index 20b965f6..7c8d10e5 100644 --- a/repertory/librepertory/src/types/repertory.cpp +++ b/repertory/librepertory/src/types/repertory.cpp @@ -81,6 +81,54 @@ auto download_type_to_string(const download_type &type) -> std::string { } } +auto event_level_from_string(std::string level, event_level default_level) + -> event_level { + level = utils::string::to_lower(level); + if (level == "critical" || level == "event_level::critical") { + return event_level::critical; + } + + if (level == "debug" || level == "event_level::debug") { + return event_level::debug; + } + + if (level == "warn" || level == "event_level::warn") { + return event_level::warn; + } + + if (level == "info" || level == "event_level::info") { + return event_level::info; + } + + if (level == "error" || level == "event_level::error") { + return event_level::error; + } + + if (level == "trace" || level == "event_level::trace") { + return event_level::trace; + } + + return default_level; +} + +auto event_level_to_string(event_level level) -> std::string { + switch (level) { + case event_level::critical: + return "critical"; + case event_level::debug: + return "debug"; + case event_level::error: + return "error"; + case event_level::info: + return "info"; + case event_level::warn: + return "warn"; + case event_level::trace: + return "trace"; + default: + return "info"; + } +} static const std::unordered_map LOOKUP = { {api_error::success, "success"}, {api_error::access_denied, "access_denied"}, diff --git a/repertory/repertory_test/src/file_mgr_db_test.cpp b/repertory/repertory_test/src/file_mgr_db_test.cpp index 219bb416..57e41f58 100644 --- a/repertory/repertory_test/src/file_mgr_db_test.cpp +++ b/repertory/repertory_test/src/file_mgr_db_test.cpp @@ -21,7 +21,7 @@ */ #include "fixtures/file_mgr_db_fixture.hpp" -#include +#include "utils/time.hpp" namespace repertory { TYPED_TEST_CASE(file_mgr_db_test, file_mgr_db_types);