refactor events

This commit is contained in:
2025-01-22 07:14:21 -06:00
parent 3efb2b817f
commit 881778e485
16 changed files with 295 additions and 324 deletions

View File

@ -26,13 +26,13 @@
namespace repertory { namespace repertory {
// clang-format off // clang-format off
E_SIMPLE3(fuse_event, debug, true, E_SIMPLE3(fuse_event, debug,
std::string, function, func, E_FROM_STRING, std::string, function, func, E_FROM_STRING,
std::string, api_path, ap, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING,
int, result, res, E_FROM_INT32 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 std::string, arguments, args, E_FROM_STRING
); );
// clang-format on // clang-format on

View File

@ -22,29 +22,15 @@
#ifndef REPERTORY_INCLUDE_EVENTS_EVENT_HPP_ #ifndef REPERTORY_INCLUDE_EVENTS_EVENT_HPP_
#define REPERTORY_INCLUDE_EVENTS_EVENT_HPP_ #define REPERTORY_INCLUDE_EVENTS_EVENT_HPP_
#include "types/repertory.hpp"
namespace repertory { 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 { class event {
protected: protected:
explicit event(bool allow_async) : allow_async_(allow_async) {} event() = default;
event(const std::stringstream &ss, json j, bool allow_async) event(const std::stringstream &ss, json j)
: allow_async_(allow_async), ss_(ss.str()), j_(std::move(j)) {} : ss_(ss.str()), j_(std::move(j)) {}
public: public:
event(const event &) = delete; event(const event &) = delete;
@ -53,18 +39,13 @@ public:
auto operator=(event &&) -> event & = delete; auto operator=(event &&) -> event & = delete;
virtual ~event() = default; virtual ~event() = default;
private:
bool allow_async_;
protected: protected:
std::stringstream ss_; std::stringstream ss_;
json j_; json j_{};
public: public:
[[nodiscard]] virtual auto clone() const -> std::shared_ptr<event> = 0; [[nodiscard]] virtual auto clone() const -> std::shared_ptr<event> = 0;
[[nodiscard]] auto get_allow_async() const -> bool { return allow_async_; }
[[nodiscard]] virtual auto get_event_level() const -> event_level = 0; [[nodiscard]] virtual auto get_event_level() const -> event_level = 0;
[[nodiscard]] auto get_json() const -> json { return j_; } [[nodiscard]] auto get_json() const -> json { return j_; }
@ -75,18 +56,4 @@ public:
}; };
} // namespace repertory } // namespace repertory
NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<std::atomic<repertory::event_level>> {
static void to_json(json &data,
const std::atomic<repertory::event_level> &value) {
data = repertory::event_level_to_string(value.load());
}
static void from_json(const json &data,
std::atomic<repertory::event_level> &value) {
value.store(repertory::event_level_from_string(data.get<std::string>()));
}
};
NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_EVENTS_EVENT_HPP_ #endif // REPERTORY_INCLUDE_EVENTS_EVENT_HPP_

View File

@ -24,6 +24,7 @@
#include "events/event.hpp" #include "events/event.hpp"
#include "events/t_event_system.hpp" #include "events/t_event_system.hpp"
#include "types/repertory.hpp"
namespace repertory { namespace repertory {
using event_system = t_event_system<event>; using event_system = t_event_system<event>;
@ -60,8 +61,7 @@ public: \
#define E_BEGIN(name, el) \ #define E_BEGIN(name, el) \
class name final : public virtual event { \ class name final : public virtual event { \
private: \ private: \
name(const std::stringstream &ss, const json &j, bool allow_async) \ name(const std::stringstream &ss, const json &j) : event(ss, j) {} \
: event(ss, j, allow_async) {} \
\ \
public: \ public: \
~name() override = default; \ ~name() override = default; \
@ -84,28 +84,26 @@ public: \
} \ } \
\ \
[[nodiscard]] auto clone() const -> std::shared_ptr<event> override { \ [[nodiscard]] auto clone() const -> std::shared_ptr<event> override { \
return std::shared_ptr<name>(new name(ss_, j_, get_allow_async())); \ return std::shared_ptr<name>(new name(ss_, j_)); \
} }
#define E_END() } #define E_END() }
#define E_SIMPLE(event_name, el, allow_async) \ #define E_SIMPLE(event_name, el) \
E_BEGIN(event_name, el) \ E_BEGIN(event_name, el) \
public: \ public: \
event_name() : event(allow_async) {} \ event_name() {} \
E_END() 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) \ E_BEGIN(event_name, el) \
explicit event_name(const type &tv) : event(allow_async) { \ explicit event_name(const type &tv) { init_##short_name(tv); } \
init_##short_name(tv); \
} \
E_PROP(type, name, short_name, tc) \ E_PROP(type, name, short_name, tc) \
E_END() E_END()
#define E_SIMPLE2(event_name, el, allow_async, type, name, short_name, tc, \ #define E_SIMPLE2(event_name, el, type, name, short_name, tc, type2, name2, \
type2, name2, short_name2, tc2) \ short_name2, tc2) \
E_BEGIN(event_name, el) \ 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_name(tv); \
init_##short_name2(tv2); \ init_##short_name2(tv2); \
} \ } \
@ -113,12 +111,10 @@ public: \
E_PROP(type2, name2, short_name2, tc2) \ E_PROP(type2, name2, short_name2, tc2) \
E_END() E_END()
#define E_SIMPLE3(event_name, el, allow_async, type, name, short_name, tc, \ #define E_SIMPLE3(event_name, el, type, name, short_name, tc, type2, name2, \
type2, name2, short_name2, tc2, type3, name3, short_name3, \ short_name2, tc2, type3, name3, short_name3, tc3) \
tc3) \
E_BEGIN(event_name, el) \ E_BEGIN(event_name, el) \
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3) \ explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3) { \
: event(allow_async) { \
init_##short_name(tv); \ init_##short_name(tv); \
init_##short_name2(tv2); \ init_##short_name2(tv2); \
init_##short_name3(tv3); \ init_##short_name3(tv3); \
@ -128,13 +124,12 @@ public: \
E_PROP(type3, name3, short_name3, tc3) \ E_PROP(type3, name3, short_name3, tc3) \
E_END() E_END()
#define E_SIMPLE4(event_name, el, allow_async, type, name, short_name, tc, \ #define E_SIMPLE4(event_name, el, type, name, short_name, tc, type2, name2, \
type2, name2, short_name2, tc2, type3, name3, short_name3, \ short_name2, tc2, type3, name3, short_name3, tc3, type4, \
tc3, type4, name4, short_name4, tc4) \ name4, short_name4, tc4) \
E_BEGIN(event_name, el) \ E_BEGIN(event_name, el) \
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \ explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \
const type4 &tv4) \ const type4 &tv4) { \
: event(allow_async) { \
init_##short_name(tv); \ init_##short_name(tv); \
init_##short_name2(tv2); \ init_##short_name2(tv2); \
init_##short_name3(tv3); \ init_##short_name3(tv3); \
@ -146,14 +141,12 @@ public: \
E_PROP(type4, name4, short_name4, tc4) \ E_PROP(type4, name4, short_name4, tc4) \
E_END() E_END()
#define E_SIMPLE5(event_name, el, allow_async, type, name, short_name, tc, \ #define E_SIMPLE5(event_name, el, type, name, short_name, tc, type2, name2, \
type2, name2, short_name2, tc2, type3, name3, short_name3, \ short_name2, tc2, type3, name3, short_name3, tc3, type4, \
tc3, type4, name4, short_name4, tc4, type5, name5, \ name4, short_name4, tc4, type5, name5, short_name5, tc5) \
short_name5, tc5) \
E_BEGIN(event_name, el) \ E_BEGIN(event_name, el) \
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \ explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \
const type4 &tv4, const type5 &tv5) \ const type4 &tv4, const type5 &tv5) { \
: event(allow_async) { \
init_##short_name(tv); \ init_##short_name(tv); \
init_##short_name2(tv2); \ init_##short_name2(tv2); \
init_##short_name3(tv3); \ init_##short_name3(tv3); \
@ -167,14 +160,13 @@ public: \
E_PROP(type5, name5, short_name5, tc5) \ E_PROP(type5, name5, short_name5, tc5) \
E_END() E_END()
#define E_SIMPLE6(event_name, el, allow_async, type, name, short_name, tc, \ #define E_SIMPLE6(event_name, el, type, name, short_name, tc, type2, name2, \
type2, name2, short_name2, tc2, type3, name3, short_name3, \ short_name2, tc2, type3, name3, short_name3, tc3, type4, \
tc3, type4, name4, short_name4, tc4, type5, name5, \ name4, short_name4, tc4, type5, name5, short_name5, tc5, \
short_name5, tc5, type6, name6, short_name6, tc6) \ type6, name6, short_name6, tc6) \
E_BEGIN(event_name, el) \ E_BEGIN(event_name, el) \
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \ explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \
const type4 &tv4, const type5 &tv5, const type6 &tv6) \ const type4 &tv4, const type5 &tv5, const type6 &tv6) { \
: event(allow_async) { \
init_##short_name(tv); \ init_##short_name(tv); \
init_##short_name2(tv2); \ init_##short_name2(tv2); \
init_##short_name3(tv3); \ init_##short_name3(tv3); \
@ -190,16 +182,15 @@ public: \
E_PROP(type6, name6, short_name6, tc6) \ E_PROP(type6, name6, short_name6, tc6) \
E_END() E_END()
#define E_SIMPLE7(event_name, el, allow_async, type, name, short_name, tc, \ #define E_SIMPLE7(event_name, el, type, name, short_name, tc, type2, name2, \
type2, name2, short_name2, tc2, type3, name3, short_name3, \ short_name2, tc2, type3, name3, short_name3, tc3, type4, \
tc3, type4, name4, short_name4, tc4, type5, name5, \ name4, short_name4, tc4, type5, name5, short_name5, tc5, \
short_name5, tc5, type6, name6, short_name6, tc6, type7, \ type6, name6, short_name6, tc6, type7, name7, short_name7, \
name7, short_name7, tc7) \ tc7) \
E_BEGIN(event_name, el) \ E_BEGIN(event_name, el) \
explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \ explicit event_name(const type &tv, const type2 &tv2, const type3 &tv3, \
const type4 &tv4, const type5 &tv5, const type6 &tv6, \ const type4 &tv4, const type5 &tv5, const type6 &tv6, \
const type7 &tv7) \ const type7 &tv7) { \
: event(allow_async) { \
init_##short_name(tv); \ init_##short_name(tv); \
init_##short_name2(tv2); \ init_##short_name2(tv2); \
init_##short_name3(tv3); \ init_##short_name3(tv3); \

View File

@ -28,126 +28,126 @@
namespace repertory { namespace repertory {
// clang-format off // clang-format off
E_SIMPLE2(curl_error, error, true, E_SIMPLE2(curl_error, error,
std::string, url, url, E_FROM_STRING, std::string, url, url, E_FROM_STRING,
CURLcode, res, res, E_FROM_CURL_CODE 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, function, func, E_FROM_STRING,
std::string, api_path, ap, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING,
std::string, data, data, 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 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, api_path, ap, E_FROM_STRING,
std::string, source, src, 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, api_path, ap, E_FROM_STRING,
std::string, error, err, 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, location, loc, E_FROM_STRING,
std::string, result, res, 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 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 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 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 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 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 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 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 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, api_path, ap, E_FROM_STRING,
std::string, error, err, 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 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 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, api_path, ap, E_FROM_STRING,
std::string, error, err, E_FROM_STRING, std::string, error, err, E_FROM_STRING,
std::size_t, retry, retry, E_FROM_SIZE_T 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 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, api_path, ap, E_FROM_STRING,
std::string, source, src, 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, api_path, ap, E_FROM_STRING,
std::string, error, err, 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, from_api_path, FROM, E_FROM_STRING,
std::string, to_api_path, TO, E_FROM_STRING, std::string, to_api_path, TO, E_FROM_STRING,
std::string, error, err, 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, api_path, ap, E_FROM_STRING,
std::string, error, err, 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, api_path, ap, E_FROM_STRING,
std::string, parent, parent, E_FROM_STRING, std::string, parent, parent, E_FROM_STRING,
bool, directory, dir, E_FROM_BOOL 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, api_path, ap, E_FROM_STRING,
std::string, source, src, E_FROM_STRING, std::string, source, src, E_FROM_STRING,
bool, directory, dir, E_FROM_BOOL, bool, directory, dir, E_FROM_BOOL,
bool, changed, changed, 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::string, api_path, ap, E_FROM_STRING,
std::uint64_t, handle, handle, E_FROM_UINT64, std::uint64_t, handle, handle, E_FROM_UINT64,
std::string, source, src, E_FROM_STRING, 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 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::string, api_path, ap, E_FROM_STRING,
std::uint64_t, handle, handle, E_FROM_UINT64, std::uint64_t, handle, handle, E_FROM_UINT64,
std::string, source, src, E_FROM_STRING, std::string, source, src, E_FROM_STRING,
bool, directory, dir, E_FROM_BOOL 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, api_path, ap, E_FROM_STRING,
std::string, source, src, 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, api_path, ap, E_FROM_STRING,
std::string, source, src, E_FROM_STRING, std::string, source, src, E_FROM_STRING,
bool, directory, dir, E_FROM_BOOL 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 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, api_path, ap, E_FROM_STRING,
std::string, source, src, E_FROM_STRING, std::string, source, src, E_FROM_STRING,
api_error, result, res, E_FROM_API_FILE_ERROR, api_error, result, res, E_FROM_API_FILE_ERROR,
bool, cancelled, cancel, E_FROM_BOOL 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, api_path, ap, E_FROM_STRING,
std::string, source, src, E_FROM_STRING, std::string, source, src, E_FROM_STRING,
std::string, error, err, 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, api_path, ap, E_FROM_STRING,
std::string, source, src, 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, api_path, ap, E_FROM_STRING,
std::string, source, src, 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 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, api_path, ap, E_FROM_STRING,
std::string, source, src, E_FROM_STRING, std::string, source, src, E_FROM_STRING,
api_error, result, res, E_FROM_API_FILE_ERROR 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, api_path, ap, E_FROM_STRING,
std::string, source, src, 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 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 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, source, src, E_FROM_STRING,
std::string, dest, dest, E_FROM_STRING, std::string, dest, dest, E_FROM_STRING,
std::string, result, res, 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 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 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 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 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::string, host_name_or_ip, host, E_FROM_STRING,
std::uint16_t, port, port, E_FROM_UINT16 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, api_path, ap, E_FROM_STRING,
std::string, source, src, 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, api_path, ap, E_FROM_STRING,
std::string, source, src, E_FROM_STRING, std::string, source, src, E_FROM_STRING,
api_error, result, res, E_FROM_API_FILE_ERROR 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, function, func, E_FROM_STRING,
std::string, message, msg, 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 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 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 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 std::string, service, svc, E_FROM_STRING
); );
E_SIMPLE(unmount_requested, info, true); E_SIMPLE(unmount_requested, info);
#if !defined(_WIN32) #if !defined(_WIN32)
E_SIMPLE2(unmount_result, info, true, E_SIMPLE2(unmount_result, info,
std::string, location, loc, E_FROM_STRING, std::string, location, loc, E_FROM_STRING,
std::string, result, res, E_FROM_STRING std::string, result, res, E_FROM_STRING
); );

View File

@ -104,7 +104,6 @@ private:
event_list_.clear(); event_list_.clear();
} }
event_notify_.notify_all();
lock.unlock(); lock.unlock();
if (events.empty()) { if (events.empty()) {
@ -117,14 +116,10 @@ private:
recur_mutex_lock consumer_lock(consumer_mutex_); recur_mutex_lock consumer_lock(consumer_mutex_);
if (event_consumers_.find(name) != event_consumers_.end()) { if (event_consumers_.find(name) != event_consumers_.end()) {
for (auto *consumer : event_consumers_[name]) { for (auto *consumer : event_consumers_[name]) {
if (event.get_allow_async()) { futures.emplace_back(
futures.emplace_back( std::async(std::launch::async, [consumer, &event]() {
std::async(std::launch::async, [consumer, &event]() { consumer->notify_event(event);
consumer->notify_event(event); }));
}));
} else {
consumer->notify_event(event);
}
} }
} }
@ -138,9 +133,6 @@ private:
notify_events("", *evt.get()); notify_events("", *evt.get());
notify_events(evt->get_name(), *evt.get()); notify_events(evt->get_name(), *evt.get());
} }
lock.lock();
event_notify_.notify_all();
} }
void queue_event(std::shared_ptr<event_type> evt) { void queue_event(std::shared_ptr<event_type> evt) {

View File

@ -27,55 +27,55 @@
namespace repertory { namespace repertory {
// clang-format off // clang-format off
E_SIMPLE2(download_begin, info, true, E_SIMPLE2(download_begin, info,
std::string, api_path, ap, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, 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, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING,
api_error, result, result, E_FROM_API_FILE_ERROR 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, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING,
double, progress, prog, E_FROM_DOUBLE_PRECISE 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, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, 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, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING,
std::string, error, err, 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, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, E_FROM_STRING, std::string, dest_path, dest, E_FROM_STRING,
std::string, error, err, 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, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, 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, api_path, ap, E_FROM_STRING,
std::string, dest_path, dest, 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 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, api_path, ap, E_FROM_STRING,
std::string, source, src, E_FROM_STRING, std::string, source, src, E_FROM_STRING,
download_type, download_type, type, E_FROM_DOWNLOAD_TYPE download_type, download_type, type, E_FROM_DOWNLOAD_TYPE

View File

@ -246,6 +246,22 @@ download_type_from_string(std::string type,
[[nodiscard]] auto download_type_to_string(const download_type &type) [[nodiscard]] auto download_type_to_string(const download_type &type)
-> std::string; -> 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 { enum class exit_code : std::int32_t {
success = 0, success = 0,
communication_error = -1, communication_error = -1,
@ -654,6 +670,18 @@ template <> struct adl_serializer<repertory::download_type> {
value = repertory::download_type_from_string(data.get<std::string>()); value = repertory::download_type_from_string(data.get<std::string>());
} }
}; };
template <> struct adl_serializer<std::atomic<repertory::event_level>> {
static void to_json(json &data,
const std::atomic<repertory::event_level> &value) {
data = repertory::event_level_to_string(value.load());
}
static void from_json(const json &data,
std::atomic<repertory::event_level> &value) {
value.store(repertory::event_level_from_string(data.get<std::string>()));
}
};
NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_END
#endif // REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_ #endif // REPERTORY_INCLUDE_TYPES_REPERTORY_HPP_

View File

@ -32,7 +32,7 @@
namespace repertory { namespace repertory {
// clang-format off // 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, event_name, en, E_FROM_STRING,
std::string, message, msg, E_FROM_STRING std::string, message, msg, E_FROM_STRING
); );
@ -112,8 +112,8 @@ void packet_client::put_client(std::shared_ptr<client> &cli) {
} }
} }
auto packet_client::read_packet(client &cli, auto packet_client::read_packet(client &cli, packet &response) const
packet &response) const -> packet::error_type { -> packet::error_type {
data_buffer buffer(sizeof(std::uint32_t)); data_buffer buffer(sizeof(std::uint32_t));
const auto read_buffer = [&]() { const auto read_buffer = [&]() {
std::uint32_t offset{}; std::uint32_t offset{};
@ -154,8 +154,8 @@ void packet_client::resolve() {
.resolve(cfg_.host_name_or_ip, std::to_string(cfg_.api_port)); .resolve(cfg_.host_name_or_ip, std::to_string(cfg_.api_port));
} }
auto packet_client::send(std::string_view method, auto packet_client::send(std::string_view method, std::uint32_t &service_flags)
std::uint32_t &service_flags) -> packet::error_type { -> packet::error_type {
packet request; packet request;
return send(method, request, service_flags); 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, auto packet_client::send(std::string_view method, packet &request,
packet &response, packet &response, std::uint32_t &service_flags)
std::uint32_t &service_flags) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
auto success = false; auto success = false;

View File

@ -47,7 +47,7 @@ namespace repertory::remote_fuse {
file, ret) file, ret)
// clang-format off // 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, function, func, E_FROM_STRING,
std::string, api_path, ap, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING,
packet::error_type, result, res, E_FROM_INT32 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; return ret;
} }
auto remote_server::fuse_chflags(const char *path, auto remote_server::fuse_chflags(const char *path, std::uint32_t flags)
std::uint32_t flags) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -321,9 +321,10 @@ length); ret = ((res < 0) ? -errno : 0); #endif
return ret; return ret;
}*/ }*/
auto remote_server::fuse_fgetattr( auto remote_server::fuse_fgetattr(const char *path, remote::stat &r_stat,
const char *path, remote::stat &r_stat, bool &directory, bool &directory,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
r_stat = {}; r_stat = {};
@ -333,7 +334,7 @@ auto remote_server::fuse_fgetattr(
auto res = has_open_info(static_cast<native_handle>(handle), EBADF); auto res = has_open_info(static_cast<native_handle>(handle), EBADF);
if (res == 0) { if (res == 0) {
directory = utils::file::directory(file_path).exists(); directory = utils::file::directory(file_path).exists();
struct stat64 unix_st {}; struct stat64 unix_st{};
res = fstat64(static_cast<native_handle>(handle), &unix_st); res = fstat64(static_cast<native_handle>(handle), &unix_st);
if (res == 0) { if (res == 0) {
populate_stat(unix_st, r_stat); populate_stat(unix_st, r_stat);
@ -345,9 +346,10 @@ auto remote_server::fuse_fgetattr(
return ret; return ret;
} }
auto remote_server::fuse_fsetattr_x( auto remote_server::fuse_fsetattr_x(const char *path,
const char *path, const remote::setattr_x &attr, const remote::setattr_x &attr,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); 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; return ret;
} }
auto remote_server::fuse_ftruncate( auto remote_server::fuse_ftruncate(const char *path,
const char *path, const remote::file_offset &size, const remote::file_offset &size,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); 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(); directory = utils::file::directory(file_path).exists();
struct stat64 unix_st {}; struct stat64 unix_st{};
auto res = stat64(file_path.c_str(), &unix_st); auto res = stat64(file_path.c_str(), &unix_st);
if (res == 0) { if (res == 0) {
populate_stat(unix_st, r_stat); 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; file_path, ret); return ret;
}*/ }*/
auto remote_server::fuse_getxtimes( auto remote_server::fuse_getxtimes(const char *path,
const char *path, remote::file_time &bkuptime, remote::file_time &bkuptime,
remote::file_time &crtime) -> packet::error_type { remote::file_time &crtime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); 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; return ret;
} }
auto remote_server::fuse_read( auto remote_server::fuse_read(const char *path, char *buffer,
const char *path, char *buffer, const remote::file_size &read_size, const remote::file_size &read_size,
const remote::file_offset &read_offset, const remote::file_offset &read_offset,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
@ -689,8 +694,8 @@ auto remote_server::fuse_read(
return static_cast<packet::error_type>(ret); return static_cast<packet::error_type>(ret);
} }
auto remote_server::fuse_rename(const char *from, auto remote_server::fuse_rename(const char *from, const char *to)
const char *to) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto from_path = utils::path::combine(mount_location_, {from}); const auto from_path = utils::path::combine(mount_location_, {from});
@ -728,8 +733,9 @@ auto remote_server::fuse_readdir(const char *path,
return ret; return ret;
} }
auto remote_server::fuse_release( auto remote_server::fuse_release(const char *path,
const char *path, const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
packet::error_type ret = 0; packet::error_type ret = 0;
@ -746,8 +752,9 @@ auto remote_server::fuse_release(
return ret; return ret;
} }
auto remote_server::fuse_releasedir( auto remote_server::fuse_releasedir(const char *path,
const char *path, const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); 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; return ret;
} }
auto remote_server::fuse_setbkuptime( auto remote_server::fuse_setbkuptime(const char *path,
const char *path, const remote::file_time &bkuptime) -> packet::error_type { const remote::file_time &bkuptime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -812,8 +820,9 @@ auto remote_server::fuse_setbkuptime(
return ret; return ret;
} }
auto remote_server::fuse_setchgtime( auto remote_server::fuse_setchgtime(const char *path,
const char *path, const remote::file_time &chgtime) -> packet::error_type { const remote::file_time &chgtime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); const auto api_path = utils::path::create_api_path(path);
@ -832,8 +841,9 @@ auto remote_server::fuse_setchgtime(
return ret; return ret;
} }
auto remote_server::fuse_setcrtime( auto remote_server::fuse_setcrtime(const char *path,
const char *path, const remote::file_time &crtime) -> packet::error_type { const remote::file_time &crtime)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); 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; return 0;
} }
auto remote_server::fuse_truncate( auto remote_server::fuse_truncate(const char *path,
const char *path, const remote::file_offset &size) -> packet::error_type { const remote::file_offset &size)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); 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, auto remote_server::fuse_utimens(const char *path, const remote::file_time *tv,
std::uint64_t op0, std::uint64_t op0, std::uint64_t op1)
std::uint64_t op1) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); 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; return ret;
} }
auto remote_server::fuse_write( auto remote_server::fuse_write(const char *path, const char *buffer,
const char *path, const char *buffer, const remote::file_size &write_size, const remote::file_size &write_size,
const remote::file_offset &write_offset, const remote::file_offset &write_offset,
const remote::file_handle &handle) -> packet::error_type { const remote::file_handle &handle)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);
@ -1007,8 +1019,8 @@ auto remote_server::fuse_write_base64(
} }
// WinFSP Layer // WinFSP Layer
auto remote_server::winfsp_can_delete(PVOID file_desc, auto remote_server::winfsp_can_delete(PVOID file_desc, PWSTR file_name)
PWSTR file_name) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_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, auto remote_server::winfsp_cleanup(PVOID /*file_desc*/, PWSTR file_name,
UINT32 flags, UINT32 flags, BOOLEAN &was_deleted)
BOOLEAN &was_deleted) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_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, UINT32 granted_access, UINT32 attributes,
UINT64 /*allocation_size*/, PVOID *file_desc, UINT64 /*allocation_size*/, PVOID *file_desc,
remote::file_info *file_info, remote::file_info *file_info,
std::string &normalized_name, std::string &normalized_name, BOOLEAN &exists)
BOOLEAN &exists) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_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; return ret;
} }
auto remote_server::winfsp_get_file_info( auto remote_server::winfsp_get_file_info(PVOID file_desc,
PVOID file_desc, remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc); const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1228,9 +1241,10 @@ auto remote_server::winfsp_get_security_by_name(
return ret; return ret;
} }
auto remote_server::winfsp_get_volume_info( auto remote_server::winfsp_get_volume_info(UINT64 &total_size,
UINT64 &total_size, UINT64 &free_size, UINT64 &free_size,
std::string &volume_label) -> packet::error_type { std::string &volume_label)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
drive_.get_volume_info(total_size, free_size, volume_label); 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; return STATUS_SUCCESS;
} }
auto remote_server::winfsp_open( auto remote_server::winfsp_open(PWSTR file_name, UINT32 create_options,
PWSTR file_name, UINT32 create_options, UINT32 granted_access, UINT32 granted_access, PVOID *file_desc,
PVOID *file_desc, remote::file_info *file_info, remote::file_info *file_info,
std::string &normalized_name) -> packet::error_type { std::string &normalized_name)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name); const auto relative_path = utils::string::to_utf8(file_name);
@ -1291,10 +1306,11 @@ auto remote_server::winfsp_open(
return ret; return ret;
} }
auto remote_server::winfsp_overwrite( auto remote_server::winfsp_overwrite(PVOID file_desc, UINT32 attributes,
PVOID file_desc, UINT32 attributes, BOOLEAN replace_attributes, BOOLEAN replace_attributes,
UINT64 /*allocation_size*/, UINT64 /*allocation_size*/,
remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc); const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1410,9 +1426,10 @@ auto remote_server::winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/,
return ret; return ret;
} }
auto remote_server::winfsp_rename( auto remote_server::winfsp_rename(PVOID /*file_desc*/, PWSTR file_name,
PVOID /*file_desc*/, PWSTR file_name, PWSTR new_file_name, PWSTR new_file_name,
BOOLEAN replace_if_exists) -> packet::error_type { BOOLEAN replace_if_exists)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto relative_path = utils::string::to_utf8(file_name); const auto relative_path = utils::string::to_utf8(file_name);
@ -1506,9 +1523,10 @@ auto remote_server::winfsp_set_basic_info(
return ret; return ret;
} }
auto remote_server::winfsp_set_file_size( auto remote_server::winfsp_set_file_size(PVOID file_desc, UINT64 new_size,
PVOID file_desc, UINT64 new_size, BOOLEAN set_allocation_size, BOOLEAN set_allocation_size,
remote::file_info *file_info) -> packet::error_type { remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto handle = reinterpret_cast<remote::file_handle>(file_desc); const auto handle = reinterpret_cast<remote::file_handle>(file_desc);
@ -1544,10 +1562,12 @@ auto remote_server::winfsp_unmounted(const std::wstring &location)
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
auto remote_server::winfsp_write( auto remote_server::winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset,
PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length, UINT32 length, BOOLEAN write_to_end,
BOOLEAN write_to_end, BOOLEAN constrained_io, PUINT32 bytes_transferred, BOOLEAN constrained_io,
remote::file_info *file_info) -> packet::error_type { PUINT32 bytes_transferred,
remote::file_info *file_info)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
*bytes_transferred = 0; *bytes_transferred = 0;
@ -1595,8 +1615,9 @@ auto remote_server::winfsp_write(
return ret; return ret;
} }
auto remote_server::json_create_directory_snapshot( auto remote_server::json_create_directory_snapshot(const std::string &path,
const std::string &path, json &json_data) -> packet::error_type { json &json_data)
-> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto api_path = utils::path::create_api_path(path); 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( auto remote_server::json_release_directory_snapshot(
const std::string &path, const std::string &path, const remote::file_handle &handle)
const remote::file_handle &handle) -> packet::error_type { -> packet::error_type {
REPERTORY_USES_FUNCTION_NAME(); REPERTORY_USES_FUNCTION_NAME();
const auto file_path = construct_path(path); const auto file_path = construct_path(path);

View File

@ -39,7 +39,7 @@ namespace repertory::remote_winfsp {
std::string{func}, file, ret) std::string{func}, file, ret)
// clang-format off // 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, function, func, E_FROM_STRING,
std::string, api_path, ap, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING,
packet::error_type, result, res, E_FROM_INT32 packet::error_type, result, res, E_FROM_INT32

View File

@ -53,7 +53,7 @@ namespace repertory::remote_winfsp {
std::string{func}, file, ret) std::string{func}, file, ret)
// clang-format off // 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, function, FUNC, E_FROM_STRING,
std::string, api_path, AP, E_FROM_STRING, std::string, api_path, AP, E_FROM_STRING,
packet::error_type, result, RES, E_FROM_INT32 packet::error_type, result, RES, E_FROM_INT32

View File

@ -19,7 +19,6 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include <mutex>
#if defined(_WIN32) #if defined(_WIN32)
#include "drives/winfsp/winfsp_drive.hpp" #include "drives/winfsp/winfsp_drive.hpp"
@ -45,15 +44,15 @@
namespace repertory { namespace repertory {
// clang-format off // clang-format off
E_SIMPLE3(winfsp_event, debug, true, E_SIMPLE3(winfsp_event, debug,
std::string, function, func, E_FROM_STRING, std::string, function, func, E_FROM_STRING,
std::string, api_path, ap, E_FROM_STRING, std::string, api_path, ap, E_FROM_STRING,
NTSTATUS, result, res, E_FROM_INT32 NTSTATUS, result, res, E_FROM_INT32
); );
E_SIMPLE(drive_stop_begin, info, true); E_SIMPLE(drive_stop_begin, info);
E_SIMPLE(drive_stop_end, info, true); E_SIMPLE(drive_stop_end, info);
E_SIMPLE(drive_stop_timed_out, info, true); E_SIMPLE(drive_stop_timed_out, info);
// clang-format on // clang-format on
#define RAISE_WINFSP_EVENT(func, file, ret) \ #define RAISE_WINFSP_EVENT(func, file, ret) \

View File

@ -1,75 +0,0 @@
/*
Copyright <2018-2025> <scott.e.graves@protonmail.com>
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

View File

@ -29,12 +29,12 @@
namespace repertory { namespace repertory {
// clang-format off // 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, cache_size, sz, E_FROM_UINT64,
std::uint64_t, by, by, 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, cache_size, sz, E_FROM_UINT64,
std::uint64_t, max_cache_size, max, E_FROM_UINT64 std::uint64_t, max_cache_size, max, E_FROM_UINT64
); );

View File

@ -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<api_error, std::string> LOOKUP = { static const std::unordered_map<api_error, std::string> LOOKUP = {
{api_error::success, "success"}, {api_error::success, "success"},
{api_error::access_denied, "access_denied"}, {api_error::access_denied, "access_denied"},

View File

@ -21,7 +21,7 @@
*/ */
#include "fixtures/file_mgr_db_fixture.hpp" #include "fixtures/file_mgr_db_fixture.hpp"
#include <utils/time.hpp> #include "utils/time.hpp"
namespace repertory { namespace repertory {
TYPED_TEST_CASE(file_mgr_db_test, file_mgr_db_types); TYPED_TEST_CASE(file_mgr_db_test, file_mgr_db_types);