From ca834dd1192ba48ebdcb3263dad25a3361ee66fd Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 9 Oct 2024 11:11:07 -0500 Subject: [PATCH] refactor --- .../include/drives/fuse/events.hpp | 6 +- .../include/events/event_system.hpp | 38 +--- .../librepertory/include/events/events.hpp | 168 +++++++++--------- .../include/file_manager/events.hpp | 48 ++--- .../src/comm/packet/packet_client.cpp | 4 +- .../drives/fuse/remotefuse/remote_server.cpp | 4 +- .../winfsp/remotewinfsp/remote_client.cpp | 4 +- .../winfsp/remotewinfsp/remote_server.cpp | 4 +- .../src/drives/winfsp/winfsp_drive.cpp | 4 +- repertory/repertory_test/src/winfsp_test.cpp | 2 +- 10 files changed, 130 insertions(+), 152 deletions(-) diff --git a/repertory/librepertory/include/drives/fuse/events.hpp b/repertory/librepertory/include/drives/fuse/events.hpp index a21411ed..f64913bc 100644 --- a/repertory/librepertory/include/drives/fuse/events.hpp +++ b/repertory/librepertory/include/drives/fuse/events.hpp @@ -27,13 +27,13 @@ namespace repertory { // clang-format off E_SIMPLE3(fuse_event, debug, true, - std::string, function, func, E_STRING, - std::string, api_path, ap, E_STRING, + 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, - std::string, arguments, args, E_STRING + std::string, arguments, args, E_FROM_STRING ); // clang-format on } // namespace repertory diff --git a/repertory/librepertory/include/events/event_system.hpp b/repertory/librepertory/include/events/event_system.hpp index 63764a80..850f6c59 100644 --- a/repertory/librepertory/include/events/event_system.hpp +++ b/repertory/librepertory/include/events/event_system.hpp @@ -24,48 +24,26 @@ #include "events/event.hpp" #include "events/t_event_system.hpp" -#include "utils/string.hpp" namespace repertory { using event_system = t_event_system; using event_consumer = event_system::event_consumer; -#define E_CAST(t) ((std::string)t) -#define E_DOUBLE(d) std::to_string(d) -#define E_DOUBLE_PRECISE(dbl_val) \ +#define E_FROM_API_FILE_ERROR(e) api_error_to_string(e) +#define E_FROM_BOOL(t) std::to_string(t) +#define E_FROM_CURL_CODE(t) std::string(curl_easy_strerror(t)) +#define E_FROM_DOUBLE(d) std::to_string(d) +#define E_FROM_DOUBLE_PRECISE(dbl_val) \ ([](const double &d) -> std::string { \ std::stringstream ss; \ ss << std::fixed << std::setprecision(2) << d; \ return ss.str(); \ })(dbl_val) -#define E_FROM_BOOL(t) std::to_string(t) -#define E_FROM_EXCEPTION(e) std::string(e.what() ? e.what() : "") #define E_FROM_INT32(t) std::to_string(t) -#define E_FROM_INT64(t) std::to_string(t) -#define E_FROM_UINT16(t) std::to_string(t) -#define E_FROM_STRING_ARRAY(a) \ - ([](const auto &array) -> std::string { \ - std::stringstream ret; \ - for (const auto &item : array) { \ - ret << (std::string(item) + " "); \ - } \ - return std::string(ret).TrimRight(); \ - })(a) - -#define E_PERCENT(d) \ - ([](const double &d) -> std::string { \ - std::stringstream ss; \ - ss << std::fixed << std::setprecision(2) << d; \ - ss << "%"; \ - return ss; \ - })(d) -#define E_STRING(t) t -#define E_FROM_CURL_CODE(t) std::string(curl_easy_strerror(t)) -#define E_FROM_UINT8(t) std::to_string(t) -#define E_FROM_UINT32(t) std::to_string(t) -#define E_FROM_UINT64(t) std::to_string(t) #define E_FROM_SIZE_T(t) std::to_string(t) -#define E_FROM_API_FILE_ERROR(e) api_error_to_string(e) +#define E_FROM_STRING(t) t +#define E_FROM_UINT16(t) std::to_string(t) +#define E_FROM_UINT64(t) std::to_string(t) #define E_PROP(type, name, short_name, ts) \ private: \ diff --git a/repertory/librepertory/include/events/events.hpp b/repertory/librepertory/include/events/events.hpp index 424820bc..ed90cb7c 100644 --- a/repertory/librepertory/include/events/events.hpp +++ b/repertory/librepertory/include/events/events.hpp @@ -29,264 +29,264 @@ namespace repertory { // clang-format off E_SIMPLE2(curl_error, error, true, - std::string, url, url, E_STRING, + std::string, url, url, E_FROM_STRING, CURLcode, res, res, E_FROM_CURL_CODE ); E_SIMPLE3(debug_log, debug, true, - std::string, function, func, E_STRING, - std::string, api_path, ap, E_STRING, - std::string, data, data, E_STRING + 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, info, true, - std::string, api_path, ap, E_STRING + std::string, api_path, ap, E_FROM_STRING ); E_SIMPLE2(directory_removed_externally, warn, true, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, source, src, E_FROM_STRING ); E_SIMPLE2(directory_remove_failed, error, true, - std::string, api_path, ap, E_STRING, - std::string, error, err, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, error, err, E_FROM_STRING ); E_SIMPLE2(drive_mount_failed, error, true, - std::string, location, loc, E_STRING, - std::string, result, res, E_STRING + std::string, location, loc, E_FROM_STRING, + std::string, result, res, E_FROM_STRING ); E_SIMPLE1(drive_mounted, info, true, - std::string, location, loc, E_STRING + std::string, location, loc, E_FROM_STRING ); E_SIMPLE1(drive_mount_result, info, true, - std::string, result, res, E_STRING + std::string, result, res, E_FROM_STRING ); E_SIMPLE1(drive_unmount_pending, info, true, - std::string, location, loc, E_STRING + std::string, location, loc, E_FROM_STRING ); E_SIMPLE1(drive_unmounted, info, true, - std::string, location, loc, E_STRING + std::string, location, loc, E_FROM_STRING ); E_SIMPLE1(event_level_changed, info, true, - std::string, new_event_level, level, E_STRING + std::string, new_event_level, level, E_FROM_STRING ); E_SIMPLE1(failed_upload_queued, error, true, - std::string, api_path, ap, E_STRING + std::string, api_path, ap, E_FROM_STRING ); E_SIMPLE1(failed_upload_removed, warn, true, - std::string, api_path, ap, E_STRING + std::string, api_path, ap, E_FROM_STRING ); E_SIMPLE1(failed_upload_retry, info, true, - std::string, api_path, ap, E_STRING + std::string, api_path, ap, E_FROM_STRING ); E_SIMPLE2(file_get_failed, error, true, - std::string, api_path, ap, E_STRING, - std::string, error, err, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, error, err, E_FROM_STRING ); E_SIMPLE1(file_get_api_list_failed, error, true, - std::string, error, err, E_STRING + std::string, error, err, E_FROM_STRING ); E_SIMPLE1(file_pinned, info, true, - std::string, api_path, ap, E_STRING + std::string, api_path, ap, E_FROM_STRING ); E_SIMPLE3(file_read_bytes_failed, error, true, - std::string, api_path, ap, E_STRING, - std::string, error, err, E_STRING, + 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, - std::string, api_path, ap, E_STRING + std::string, api_path, ap, E_FROM_STRING ); E_SIMPLE2(file_removed_externally, warn, true, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, source, src, E_FROM_STRING ); E_SIMPLE2(file_remove_failed, error, true, - std::string, api_path, ap, E_STRING, - std::string, error, err, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, error, err, E_FROM_STRING ); E_SIMPLE3(file_rename_failed, error, true, - std::string, from_api_path, FROM, E_STRING, - std::string, to_api_path, TO, E_STRING, - std::string, error, err, E_STRING + 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, - std::string, api_path, ap, E_STRING, - std::string, error, err, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, error, err, E_FROM_STRING ); E_SIMPLE3(filesystem_item_added, debug, true, - std::string, api_path, ap, E_STRING, - std::string, parent, parent, E_STRING, + 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, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING, + 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, - std::string, api_path, ap, E_STRING, + std::string, api_path, ap, E_FROM_STRING, std::uint64_t, handle, handle, E_FROM_UINT64, - std::string, source, src, E_STRING, + std::string, source, src, E_FROM_STRING, bool, directory, dir, E_FROM_BOOL, bool, changed, changed, E_FROM_BOOL ); E_SIMPLE4(filesystem_item_handle_opened, trace, true, - std::string, api_path, ap, E_STRING, + std::string, api_path, ap, E_FROM_STRING, std::uint64_t, handle, handle, E_FROM_UINT64, - std::string, source, src, E_STRING, + std::string, source, src, E_FROM_STRING, bool, directory, dir, E_FROM_BOOL ); E_SIMPLE2(filesystem_item_evicted, info, true, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, source, src, E_FROM_STRING ); E_SIMPLE3(filesystem_item_opened, trace, true, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING, + 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, - std::string, api_path, ap, E_STRING + std::string, api_path, ap, E_FROM_STRING ); E_SIMPLE4(file_upload_completed, info, true, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING, + 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, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING, - std::string, error, err, E_STRING + 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, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, source, src, E_FROM_STRING ); E_SIMPLE2(file_upload_queued, info, true, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, source, src, E_FROM_STRING ); E_SIMPLE1(file_upload_removed, debug, true, - std::string, api_path, ap, E_STRING + std::string, api_path, ap, E_FROM_STRING ); E_SIMPLE3(file_upload_retry, info, true, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING, + 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, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, source, src, E_FROM_STRING ); E_SIMPLE1(orphaned_file_deleted, warn, true, - std::string, source, src, E_STRING + std::string, source, src, E_FROM_STRING ); E_SIMPLE1(orphaned_file_detected, warn, true, - std::string, source, src, E_STRING + std::string, source, src, E_FROM_STRING ); E_SIMPLE3(orphaned_file_processing_failed, error, true, - std::string, source, src, E_STRING, - std::string, dest, dest, E_STRING, - std::string, result, res, E_STRING + 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, - std::string, source, src, E_STRING + std::string, source, src, E_FROM_STRING ); E_SIMPLE1(orphaned_source_file_removed, info, true, - std::string, source, src, E_STRING + std::string, source, src, E_FROM_STRING ); E_SIMPLE1(polling_item_begin, debug, true, - std::string, item_name, item, E_STRING + std::string, item_name, item, E_FROM_STRING ); E_SIMPLE1(polling_item_end, debug, true, - std::string, item_name, item, E_STRING + std::string, item_name, item, E_FROM_STRING ); E_SIMPLE2(provider_offline, error, true, - std::string, host_name_or_ip, host, E_STRING, + 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, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, source, src, E_FROM_STRING ); E_SIMPLE3(provider_upload_end, info, true, - std::string, api_path, ap, E_STRING, - std::string, source, src, E_STRING, + 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, - std::string, function, func, E_STRING, - std::string, message, msg, E_STRING + std::string, function, func, E_FROM_STRING, + std::string, message, msg, E_FROM_STRING ); E_SIMPLE1(rpc_server_exception, error, true, - std::string, exception, exception, E_STRING + std::string, exception, exception, E_FROM_STRING ); E_SIMPLE1(service_shutdown_begin, debug, true, - std::string, service, svc, E_STRING + std::string, service, svc, E_FROM_STRING ); E_SIMPLE1(service_shutdown_end, debug, true, - std::string, service, svc, E_STRING + std::string, service, svc, E_FROM_STRING ); E_SIMPLE1(service_started, debug, true, - std::string, service, svc, E_STRING + std::string, service, svc, E_FROM_STRING ); E_SIMPLE(unmount_requested, info, true); #if !defined(_WIN32) E_SIMPLE2(unmount_result, info, true, - std::string, location, loc, E_STRING, - std::string, result, res, E_STRING + std::string, location, loc, E_FROM_STRING, + std::string, result, res, E_FROM_STRING ); #endif // clang-format on diff --git a/repertory/librepertory/include/file_manager/events.hpp b/repertory/librepertory/include/file_manager/events.hpp index 13bd3389..aad295ea 100644 --- a/repertory/librepertory/include/file_manager/events.hpp +++ b/repertory/librepertory/include/file_manager/events.hpp @@ -28,21 +28,21 @@ namespace repertory { // clang-format off E_SIMPLE2(download_begin, info, true, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, dest_path, dest, E_FROM_STRING ); E_SIMPLE5(download_chunk_begin, debug, true, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING, + std::string, api_path, ap, E_FROM_STRING, + std::string, dest_path, dest, E_FROM_STRING, std::size_t, chunk, chunk, E_FROM_SIZE_T, std::size_t, total, total, E_FROM_SIZE_T, std::size_t, complete, complete, E_FROM_SIZE_T ); E_SIMPLE6(download_chunk_end, debug, true, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING, + std::string, api_path, ap, E_FROM_STRING, + std::string, dest_path, dest, E_FROM_STRING, std::size_t, chunk, chunk, E_FROM_SIZE_T, std::size_t, total, total, E_FROM_SIZE_T, std::size_t, complete, complete, E_FROM_SIZE_T, @@ -50,46 +50,46 @@ E_SIMPLE6(download_chunk_end, debug, true, ); E_SIMPLE3(download_end, info, true, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING, + 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, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING, - double, progress, prog, E_DOUBLE_PRECISE + 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, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, dest_path, dest, E_FROM_STRING ); E_SIMPLE3(download_restore_failed, error, true, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING, - std::string, error, err, E_STRING + 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, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING, - std::string, error, err, E_STRING + 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, info, true, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, dest_path, dest, E_FROM_STRING ); E_SIMPLE2(download_resume_removed, info, true, - std::string, api_path, ap, E_STRING, - std::string, dest_path, dest, E_STRING + std::string, api_path, ap, E_FROM_STRING, + std::string, dest_path, dest, E_FROM_STRING ); E_SIMPLE1(item_timeout, debug, true, - std::string, api_path, ap, E_STRING + std::string, api_path, ap, E_FROM_STRING ); // clang-format on } // namespace repertory diff --git a/repertory/librepertory/src/comm/packet/packet_client.cpp b/repertory/librepertory/src/comm/packet/packet_client.cpp index 7826aeac..4f0c051a 100644 --- a/repertory/librepertory/src/comm/packet/packet_client.cpp +++ b/repertory/librepertory/src/comm/packet/packet_client.cpp @@ -33,8 +33,8 @@ namespace repertory { // clang-format off E_SIMPLE2(packet_client_timeout, error, true, - std::string, event_name, en, E_STRING, - std::string, message, msg, E_STRING + std::string, event_name, en, E_FROM_STRING, + std::string, message, msg, E_FROM_STRING ); // clang-format on diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp index ea768877..65a67ab0 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_server.cpp @@ -48,8 +48,8 @@ namespace repertory::remote_fuse { // clang-format off E_SIMPLE3(remote_fuse_server_event, debug, true, - std::string, function, func, E_STRING, - std::string, api_path, ap, E_STRING, + std::string, function, func, E_FROM_STRING, + std::string, api_path, ap, E_FROM_STRING, packet::error_type, result, res, E_FROM_INT32 ); // clang-format on diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp index 3b1c9213..8f0f03ab 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_client.cpp @@ -40,8 +40,8 @@ namespace repertory::remote_winfsp { // clang-format off E_SIMPLE3(remote_winfsp_client_event, debug, true, - std::string, function, func, E_STRING, - std::string, api_path, ap, E_STRING, + std::string, function, func, E_FROM_STRING, + std::string, api_path, ap, E_FROM_STRING, packet::error_type, result, res, E_FROM_INT32 ); // clang-format on diff --git a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp index 8ed80c1c..7aef88a7 100644 --- a/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp +++ b/repertory/librepertory/src/drives/winfsp/remotewinfsp/remote_server.cpp @@ -54,8 +54,8 @@ namespace repertory::remote_winfsp { // clang-format off E_SIMPLE3(remote_winfsp_server_event, debug, true, - std::string, function, FUNC, E_STRING, - std::string, api_path, AP, E_STRING, + std::string, function, FUNC, E_FROM_STRING, + std::string, api_path, AP, E_FROM_STRING, packet::error_type, result, RES, E_FROM_INT32 ); // clang-format on diff --git a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp index 99081fb5..38c0a490 100644 --- a/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp +++ b/repertory/librepertory/src/drives/winfsp/winfsp_drive.cpp @@ -44,8 +44,8 @@ namespace repertory { // clang-format off E_SIMPLE3(winfsp_event, debug, true, - std::string, function, func, E_STRING, - std::string, api_path, ap, E_STRING, + std::string, function, func, E_FROM_STRING, + std::string, api_path, ap, E_FROM_STRING, NTSTATUS, result, res, E_FROM_INT32 ); // clang-format on diff --git a/repertory/repertory_test/src/winfsp_test.cpp b/repertory/repertory_test/src/winfsp_test.cpp index b6482c45..36a7882b 100644 --- a/repertory/repertory_test/src/winfsp_test.cpp +++ b/repertory/repertory_test/src/winfsp_test.cpp @@ -49,7 +49,7 @@ void launch_app(std::string cmd) { EXPECT_EQ(0, code); } -E_SIMPLE1(test_begin, info, false, std::string, test_name, TN, E_STRING); +E_SIMPLE1(test_begin, info, false, std::string, test_name, TN, E_FROM_STRING); #define TEST_HEADER(func) \ event_system::instance().raise( \ std::string(func) + \