refactor event system
This commit is contained in:
@ -23,10 +23,12 @@
|
|||||||
#define REPERTORY_INCLUDE_EVENTS_CONSUMERS_CONSOLE_CONSUMER_HPP_
|
#define REPERTORY_INCLUDE_EVENTS_CONSUMERS_CONSOLE_CONSUMER_HPP_
|
||||||
|
|
||||||
#include "events/event_system.hpp"
|
#include "events/event_system.hpp"
|
||||||
|
#include "events/event_system2.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
class console_consumer final {
|
class console_consumer final {
|
||||||
E_CONSUMER();
|
E_CONSUMER();
|
||||||
|
E_CONSUMER2();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
console_consumer();
|
console_consumer();
|
||||||
@ -36,7 +38,9 @@ public:
|
|||||||
~console_consumer();
|
~console_consumer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void process_event(const event &e) const;
|
static void process_event(const event &evt);
|
||||||
|
|
||||||
|
static void process_event2(const i_event &evt);
|
||||||
};
|
};
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
|
@ -23,10 +23,12 @@
|
|||||||
#define REPERTORY_INCLUDE_EVENTS_CONSUMERS_LOGGING_CONSUMER_HPP_
|
#define REPERTORY_INCLUDE_EVENTS_CONSUMERS_LOGGING_CONSUMER_HPP_
|
||||||
|
|
||||||
#include "events/event_system.hpp"
|
#include "events/event_system.hpp"
|
||||||
|
#include "events/event_system2.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
class logging_consumer {
|
class logging_consumer {
|
||||||
E_CONSUMER();
|
E_CONSUMER();
|
||||||
|
E_CONSUMER2();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
logging_consumer(event_level level, std::string log_directory);
|
logging_consumer(event_level level, std::string log_directory);
|
||||||
@ -39,7 +41,9 @@ private:
|
|||||||
5ULL};
|
5ULL};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void process_event(const event &event) const;
|
static void process_event(const event &evt);
|
||||||
|
|
||||||
|
static void process_event2(const i_event &evt);
|
||||||
};
|
};
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
|
@ -51,26 +51,26 @@ protected:
|
|||||||
~event_system2() { stop(); }
|
~event_system2() { stop(); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class event_consumer final {
|
class event_consumer2 final {
|
||||||
public:
|
public:
|
||||||
explicit event_consumer(std::function<void(const i_event &)> callback)
|
explicit event_consumer2(std::function<void(const i_event &)> callback)
|
||||||
: callback_(std::move(callback)) {
|
: callback_(std::move(callback)) {
|
||||||
event_system2::instance().attach(this);
|
event_system2::instance().attach(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
event_consumer(std::string_view event_name,
|
event_consumer2(std::string_view event_name,
|
||||||
std::function<void(const i_event &)> callback)
|
std::function<void(const i_event &)> callback)
|
||||||
: callback_(std::move(callback)) {
|
: callback_(std::move(callback)) {
|
||||||
event_system2::instance().attach(event_name, this);
|
event_system2::instance().attach(event_name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
~event_consumer() { event_system2::instance().release(this); }
|
~event_consumer2() { event_system2::instance().release(this); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
event_consumer(const event_consumer &) = delete;
|
event_consumer2(const event_consumer2 &) = delete;
|
||||||
event_consumer(event_consumer &&) = delete;
|
event_consumer2(event_consumer2 &&) = delete;
|
||||||
auto operator=(const event_consumer &) -> event_consumer & = delete;
|
auto operator=(const event_consumer2 &) -> event_consumer2 & = delete;
|
||||||
auto operator=(event_consumer &&) -> event_consumer & = delete;
|
auto operator=(event_consumer2 &&) -> event_consumer2 & = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::function<void(const i_event &)> callback_;
|
std::function<void(const i_event &)> callback_;
|
||||||
@ -80,13 +80,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static event_system2 event_system_;
|
static event_system2 instance_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static auto instance() -> event_system2 &;
|
[[nodiscard]] static auto instance() -> event_system2 &;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::deque<event_consumer *>>
|
std::unordered_map<std::string, std::deque<event_consumer2 *>>
|
||||||
event_consumers_;
|
event_consumers_;
|
||||||
std::recursive_mutex consumer_mutex_;
|
std::recursive_mutex consumer_mutex_;
|
||||||
std::vector<std::shared_ptr<i_event>> event_list_;
|
std::vector<std::shared_ptr<i_event>> event_list_;
|
||||||
@ -104,20 +104,42 @@ private:
|
|||||||
void queue_event(std::shared_ptr<i_event> evt);
|
void queue_event(std::shared_ptr<i_event> evt);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void attach(event_consumer *consumer);
|
void attach(event_consumer2 *consumer);
|
||||||
|
|
||||||
void attach(std::string_view event_name, event_consumer *consumer);
|
void attach(std::string_view event_name, event_consumer2 *consumer);
|
||||||
|
|
||||||
template <typename evt_t, typename... arg_t> void raise(arg_t &&...args) {
|
template <typename evt_t, typename... arg_t> void raise(arg_t &&...args) {
|
||||||
queue_event(std::make_shared<evt_t>(std::forward<arg_t>(args)...));
|
queue_event(std::make_shared<evt_t>(std::forward<arg_t>(args)...));
|
||||||
}
|
}
|
||||||
|
|
||||||
void release(event_consumer *consumer);
|
void release(event_consumer2 *consumer);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using event_consumer2 = event_system2::event_consumer2;
|
||||||
|
|
||||||
|
#define E_CONSUMER2() \
|
||||||
|
private: \
|
||||||
|
std::vector<std::shared_ptr<repertory::event_consumer2>> event_consumers2_
|
||||||
|
|
||||||
|
#define E_CONSUMER2_RELEASE() event_consumers2_.clear()
|
||||||
|
|
||||||
|
#define E_SUBSCRIBE2(name, callback) \
|
||||||
|
event_consumers2_.emplace_back(std::make_shared<repertory::event_consumer2>( \
|
||||||
|
#name, [this](const i_event &evt) { callback(evt); }))
|
||||||
|
|
||||||
|
#define E_SUBSCRIBE_EXACT2(name, callback) \
|
||||||
|
event_consumers2_.emplace_back(std::make_shared<repertory::event_consumer2>( \
|
||||||
|
#name, [this](const i_event &evt) { \
|
||||||
|
callback(dynamic_cast<const name &>(evt)); \
|
||||||
|
}))
|
||||||
|
|
||||||
|
#define E_SUBSCRIBE_ALL2(callback) \
|
||||||
|
event_consumers2_.emplace_back(std::make_shared<repertory::event_consumer2>( \
|
||||||
|
[this](const i_event &evt) { callback(evt); }))
|
||||||
} // namespace repertory
|
} // namespace repertory
|
||||||
|
|
||||||
#endif // REPERTORY_INCLUDE_EVENTS_EVENT_SYSTEM2_HPP_
|
#endif // REPERTORY_INCLUDE_EVENTS_EVENT_SYSTEM2_HPP_
|
||||||
|
@ -28,18 +28,6 @@
|
|||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
E_SIMPLE1(drive_unmount_pending, info,
|
|
||||||
std::string, location, loc, E_FROM_STRING
|
|
||||||
);
|
|
||||||
|
|
||||||
E_SIMPLE1(drive_unmounted, info,
|
|
||||||
std::string, location, loc, E_FROM_STRING
|
|
||||||
);
|
|
||||||
|
|
||||||
E_SIMPLE1(event_level_changed, info,
|
|
||||||
std::string, new_event_level, level, E_FROM_STRING
|
|
||||||
);
|
|
||||||
|
|
||||||
E_SIMPLE1(failed_upload_queued, error,
|
E_SIMPLE1(failed_upload_queued, error,
|
||||||
std::string, api_path, ap, E_FROM_STRING
|
std::string, api_path, ap, E_FROM_STRING
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
#ifndef REPERTORY_INCLUDE_EVENTS_TYPES_DRIVE_UNMOUNT_PENDING_HPP_
|
||||||
|
#define REPERTORY_INCLUDE_EVENTS_TYPES_DRIVE_UNMOUNT_PENDING_HPP_
|
||||||
|
|
||||||
|
#include "events/i_event.hpp"
|
||||||
|
#include "types/repertory.hpp"
|
||||||
|
|
||||||
|
namespace repertory {
|
||||||
|
struct drive_unmount_pending final : public i_event {
|
||||||
|
drive_unmount_pending() = default;
|
||||||
|
drive_unmount_pending(std::string_view function_name_,
|
||||||
|
std::string mount_location_)
|
||||||
|
: function_name(std::string(function_name_)),
|
||||||
|
mount_location(std::move(mount_location_)) {}
|
||||||
|
|
||||||
|
static constexpr const std::string_view name{"drive_unmount_pending"};
|
||||||
|
|
||||||
|
std::string function_name;
|
||||||
|
std::string mount_location;
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_event_level() const -> event_level override {
|
||||||
|
return event_level::info;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_name() const -> std::string_view override {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_single_line() const -> std::string override {
|
||||||
|
return fmt::format("{}|func|{}|location|{}", name, function_name,
|
||||||
|
mount_location);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace repertory
|
||||||
|
|
||||||
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
|
template <> struct adl_serializer<repertory::drive_unmount_pending> {
|
||||||
|
static void to_json(json &data,
|
||||||
|
const repertory::drive_unmount_pending &value) {
|
||||||
|
data["function_name"] = value.function_name;
|
||||||
|
data["mount_location"] = value.mount_location;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void from_json(const json &data,
|
||||||
|
repertory::drive_unmount_pending &value) {
|
||||||
|
data.at("function_name").get_to<std::string>(value.function_name);
|
||||||
|
data.at("mount_location").get_to<std::string>(value.mount_location);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|
||||||
|
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DRIVE_UNMOUNT_PENDING_HPP_
|
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
#ifndef REPERTORY_INCLUDE_EVENTS_TYPES_DRIVE_UNMOUNTED_HPP_
|
||||||
|
#define REPERTORY_INCLUDE_EVENTS_TYPES_DRIVE_UNMOUNTED_HPP_
|
||||||
|
|
||||||
|
#include "events/i_event.hpp"
|
||||||
|
#include "types/repertory.hpp"
|
||||||
|
|
||||||
|
namespace repertory {
|
||||||
|
struct drive_unmounted final : public i_event {
|
||||||
|
drive_unmounted() = default;
|
||||||
|
drive_unmounted(std::string_view function_name_, std::string mount_location_)
|
||||||
|
: function_name(std::string(function_name_)),
|
||||||
|
mount_location(std::move(mount_location_)) {}
|
||||||
|
|
||||||
|
static constexpr const std::string_view name{"drive_unmounted"};
|
||||||
|
|
||||||
|
std::string function_name;
|
||||||
|
std::string mount_location;
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_event_level() const -> event_level override {
|
||||||
|
return event_level::info;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_name() const -> std::string_view override {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_single_line() const -> std::string override {
|
||||||
|
return fmt::format("{}|func|{}|location|{}", name, function_name,
|
||||||
|
mount_location);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace repertory
|
||||||
|
|
||||||
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
|
template <> struct adl_serializer<repertory::drive_unmounted> {
|
||||||
|
static void to_json(json &data, const repertory::drive_unmounted &value) {
|
||||||
|
data["function_name"] = value.function_name;
|
||||||
|
data["mount_location"] = value.mount_location;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void from_json(const json &data, repertory::drive_unmounted &value) {
|
||||||
|
data.at("function_name").get_to<std::string>(value.function_name);
|
||||||
|
data.at("mount_location").get_to<std::string>(value.mount_location);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|
||||||
|
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DRIVE_UNMOUNTED_HPP_
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
#ifndef REPERTORY_INCLUDE_EVENTS_TYPES_EVENT_LEVEL_CHANGED_HPP_
|
||||||
|
#define REPERTORY_INCLUDE_EVENTS_TYPES_EVENT_LEVEL_CHANGED_HPP_
|
||||||
|
|
||||||
|
#include "events/i_event.hpp"
|
||||||
|
#include "types/repertory.hpp"
|
||||||
|
|
||||||
|
namespace repertory {
|
||||||
|
struct event_level_changed final : public i_event {
|
||||||
|
event_level_changed() = default;
|
||||||
|
event_level_changed(std::string_view function_name_, event_level level_)
|
||||||
|
: function_name(std::string(function_name_)), level(level_) {}
|
||||||
|
|
||||||
|
static constexpr const std::string_view name{"event_level_changed"};
|
||||||
|
|
||||||
|
std::string function_name;
|
||||||
|
event_level level{};
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_event_level() const -> event_level override {
|
||||||
|
return event_level::info;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_name() const -> std::string_view override {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto get_single_line() const -> std::string override {
|
||||||
|
return fmt::format("{}|func|{}|level|{}", name, function_name,
|
||||||
|
event_level_to_string(level));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace repertory
|
||||||
|
|
||||||
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||||
|
template <> struct adl_serializer<repertory::event_level_changed> {
|
||||||
|
static void to_json(json &data, const repertory::event_level_changed &value) {
|
||||||
|
data["event_level"] = repertory::event_level_to_string(value.level);
|
||||||
|
data["function_name"] = value.function_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void from_json(const json &data,
|
||||||
|
repertory::event_level_changed &value) {
|
||||||
|
value.level = repertory::event_level_from_string(
|
||||||
|
data.at("event_level").get<std::string>());
|
||||||
|
data.at("function_name").get_to<std::string>(value.function_name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
NLOHMANN_JSON_NAMESPACE_END
|
||||||
|
|
||||||
|
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_EVENT_LEVEL_CHANGED_HPP_
|
@ -21,8 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "app_config.hpp"
|
#include "app_config.hpp"
|
||||||
|
|
||||||
#include "events/event_system.hpp"
|
#include "events/event_system2.hpp"
|
||||||
#include "events/events.hpp"
|
#include "events/types/event_level_changed.hpp"
|
||||||
#include "file_manager/cache_size_mgr.hpp"
|
#include "file_manager/cache_size_mgr.hpp"
|
||||||
#include "platform/platform.hpp"
|
#include "platform/platform.hpp"
|
||||||
#include "types/startup_exception.hpp"
|
#include "types/startup_exception.hpp"
|
||||||
@ -1146,9 +1146,10 @@ void app_config::set_enable_mount_manager(bool value) {
|
|||||||
#endif // defined(_WIN32)
|
#endif // defined(_WIN32)
|
||||||
|
|
||||||
void app_config::set_event_level(const event_level &value) {
|
void app_config::set_event_level(const event_level &value) {
|
||||||
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
if (set_value(event_level_, value)) {
|
if (set_value(event_level_, value)) {
|
||||||
event_system::instance().raise<event_level_changed>(
|
event_system2::instance().raise<event_level_changed>(function_name, value);
|
||||||
event_level_to_string(value));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@
|
|||||||
#include "events/events.hpp"
|
#include "events/events.hpp"
|
||||||
#include "events/types/drive_mount_result.hpp"
|
#include "events/types/drive_mount_result.hpp"
|
||||||
#include "events/types/drive_mounted.hpp"
|
#include "events/types/drive_mounted.hpp"
|
||||||
|
#include "events/types/drive_unmount_pending.hpp"
|
||||||
|
#include "events/types/drive_unmounted.hpp"
|
||||||
#include "platform/platform.hpp"
|
#include "platform/platform.hpp"
|
||||||
#include "providers/i_provider.hpp"
|
#include "providers/i_provider.hpp"
|
||||||
#include "rpc/server/full_server.hpp"
|
#include "rpc/server/full_server.hpp"
|
||||||
@ -293,7 +295,8 @@ void fuse_drive::stop_all() {
|
|||||||
void fuse_drive::destroy_impl(void *ptr) {
|
void fuse_drive::destroy_impl(void *ptr) {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
|
event_system2::instance().raise<drive_unmount_pending>(function_name,
|
||||||
|
get_mount_location());
|
||||||
|
|
||||||
stop_all();
|
stop_all();
|
||||||
|
|
||||||
@ -301,7 +304,8 @@ void fuse_drive::destroy_impl(void *ptr) {
|
|||||||
|
|
||||||
fuse_base::destroy_impl(ptr);
|
fuse_base::destroy_impl(ptr);
|
||||||
|
|
||||||
event_system::instance().raise<drive_unmounted>(get_mount_location());
|
event_system2::instance().raise<drive_unmounted>(function_name,
|
||||||
|
get_mount_location());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
|
auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#include "events/events.hpp"
|
#include "events/events.hpp"
|
||||||
#include "events/types/drive_mount_result.hpp"
|
#include "events/types/drive_mount_result.hpp"
|
||||||
#include "events/types/drive_mounted.hpp"
|
#include "events/types/drive_mounted.hpp"
|
||||||
|
#include "events/types/drive_unmount_pending.hpp"
|
||||||
|
#include "events/types/drive_unmounted.hpp"
|
||||||
#include "platform/platform.hpp"
|
#include "platform/platform.hpp"
|
||||||
#include "rpc/server/server.hpp"
|
#include "rpc/server/server.hpp"
|
||||||
#include "types/remote.hpp"
|
#include "types/remote.hpp"
|
||||||
@ -93,7 +95,8 @@ auto remote_fuse_drive::create_impl(std::string api_path, mode_t mode,
|
|||||||
void remote_fuse_drive::destroy_impl(void *ptr) {
|
void remote_fuse_drive::destroy_impl(void *ptr) {
|
||||||
REPERTORY_USES_FUNCTION_NAME();
|
REPERTORY_USES_FUNCTION_NAME();
|
||||||
|
|
||||||
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
|
event_system2::instance().raise<drive_unmount_pending>(function_name,
|
||||||
|
get_mount_location());
|
||||||
|
|
||||||
if (server_) {
|
if (server_) {
|
||||||
server_->stop();
|
server_->stop();
|
||||||
@ -114,7 +117,8 @@ void remote_fuse_drive::destroy_impl(void *ptr) {
|
|||||||
utils::error::raise_error(function_name, "failed to set mount state");
|
utils::error::raise_error(function_name, "failed to set mount state");
|
||||||
}
|
}
|
||||||
|
|
||||||
event_system::instance().raise<drive_unmounted>(get_mount_location());
|
event_system2::instance().raise<drive_unmounted>(function_name,
|
||||||
|
get_mount_location());
|
||||||
|
|
||||||
fuse_base::destroy_impl(ptr);
|
fuse_base::destroy_impl(ptr);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include "events/event_system2.hpp"
|
#include "events/event_system2.hpp"
|
||||||
#include "events/events.hpp"
|
#include "events/events.hpp"
|
||||||
#include "events/types/drive_mounted.hpp"
|
#include "events/types/drive_mounted.hpp"
|
||||||
|
#include "events/types/drive_unmount_pending.hpp"
|
||||||
|
#include "events/types/drive_unmounted.hpp"
|
||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
#include "utils/path.hpp"
|
#include "utils/path.hpp"
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
@ -572,7 +574,8 @@ auto remote_client::winfsp_unmounted(const std::wstring &location)
|
|||||||
auto mount_location{
|
auto mount_location{
|
||||||
utils::string::to_utf8(location),
|
utils::string::to_utf8(location),
|
||||||
};
|
};
|
||||||
event_system::instance().raise<drive_unmount_pending>(mount_location);
|
event_system2::instance().raise<drive_unmount_pending>(function_name,
|
||||||
|
mount_location);
|
||||||
packet request;
|
packet request;
|
||||||
request.encode(location);
|
request.encode(location);
|
||||||
|
|
||||||
@ -580,7 +583,8 @@ auto remote_client::winfsp_unmounted(const std::wstring &location)
|
|||||||
auto ret{
|
auto ret{
|
||||||
packet_client_.send(function_name, request, service_flags),
|
packet_client_.send(function_name, request, service_flags),
|
||||||
};
|
};
|
||||||
event_system::instance().raise<drive_unmounted>(mount_location);
|
event_system2::instance().raise<drive_unmounted>(function_name,
|
||||||
|
mount_location);
|
||||||
|
|
||||||
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
|
RAISE_REMOTE_WINFSP_CLIENT_EVENT(function_name, mount_location, ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#include "events/types/drive_mount_failed.hpp"
|
#include "events/types/drive_mount_failed.hpp"
|
||||||
#include "events/types/drive_mount_result.hpp"
|
#include "events/types/drive_mount_result.hpp"
|
||||||
#include "events/types/drive_mounted.hpp"
|
#include "events/types/drive_mounted.hpp"
|
||||||
|
#include "events/types/drive_unmount_pending.hpp"
|
||||||
|
#include "events/types/drive_unmounted.hpp"
|
||||||
#include "platform/platform.hpp"
|
#include "platform/platform.hpp"
|
||||||
#include "providers/i_provider.hpp"
|
#include "providers/i_provider.hpp"
|
||||||
#include "types/repertory.hpp"
|
#include "types/repertory.hpp"
|
||||||
@ -1226,11 +1228,13 @@ VOID winfsp_drive::Unmounted(PVOID host) {
|
|||||||
|
|
||||||
auto *file_system_host = reinterpret_cast<FileSystemHost *>(host);
|
auto *file_system_host = reinterpret_cast<FileSystemHost *>(host);
|
||||||
auto mount_location = parse_mount_location(file_system_host->MountPoint());
|
auto mount_location = parse_mount_location(file_system_host->MountPoint());
|
||||||
event_system::instance().raise<drive_unmount_pending>(mount_location);
|
event_system2::instance().raise<drive_unmount_pending>(function_name,
|
||||||
|
mount_location);
|
||||||
|
|
||||||
stop_all();
|
stop_all();
|
||||||
|
|
||||||
event_system::instance().raise<drive_unmounted>(mount_location);
|
event_system2::instance().raise<drive_unmounted>(function_name,
|
||||||
|
mount_location);
|
||||||
config_.save();
|
config_.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "events/consumers/console_consumer.hpp"
|
#include "events/consumers/console_consumer.hpp"
|
||||||
|
|
||||||
#include "events/events.hpp"
|
#include "events/i_event.hpp"
|
||||||
|
#include "events/types/event_level_changed.hpp"
|
||||||
#include "spdlog/async.h"
|
#include "spdlog/async.h"
|
||||||
#include "spdlog/sinks/stdout_color_sinks.h"
|
#include "spdlog/sinks/stdout_color_sinks.h"
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
@ -62,35 +63,57 @@ console_consumer::console_consumer(event_level level) {
|
|||||||
set_level(level);
|
set_level(level);
|
||||||
|
|
||||||
E_SUBSCRIBE_ALL(process_event);
|
E_SUBSCRIBE_ALL(process_event);
|
||||||
E_SUBSCRIBE_EXACT(event_level_changed,
|
E_SUBSCRIBE2_ALL(process_event2);
|
||||||
[](const event_level_changed &changed) {
|
E_SUBSCRIBE2_EXACT(event_level_changed,
|
||||||
set_level(event_level_from_string(
|
[](auto &&evt) { set_level(evt.level); });
|
||||||
changed.get_new_event_level().get<std::string>()));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console_consumer::~console_consumer() { E_CONSUMER_RELEASE(); }
|
console_consumer::~console_consumer() { E_CONSUMER_RELEASE(); }
|
||||||
|
|
||||||
void console_consumer::process_event(const event &event) const {
|
void console_consumer::process_event(const event &event) {
|
||||||
switch (event.get_event_level()) {
|
switch (evt.get_event_level()) {
|
||||||
case event_level::critical:
|
case event_level::critical:
|
||||||
spdlog::get("console")->critical(event.get_single_line());
|
spdlog::get("console")->critical(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::error:
|
case event_level::error:
|
||||||
spdlog::get("console")->error(event.get_single_line());
|
spdlog::get("console")->error(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::warn:
|
case event_level::warn:
|
||||||
spdlog::get("console")->warn(event.get_single_line());
|
spdlog::get("console")->warn(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::info:
|
case event_level::info:
|
||||||
spdlog::get("console")->info(event.get_single_line());
|
spdlog::get("console")->info(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::debug:
|
case event_level::debug:
|
||||||
spdlog::get("console")->debug(event.get_single_line());
|
spdlog::get("console")->debug(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::trace:
|
case event_level::trace:
|
||||||
default:
|
default:
|
||||||
spdlog::get("console")->trace(event.get_single_line());
|
spdlog::get("console")->trace(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void console_consumer::process_event(const i_event &evt) const {
|
||||||
|
switch (evt.get_event_level()) {
|
||||||
|
case event_level::critical:
|
||||||
|
spdlog::get("console")->critical(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::error:
|
||||||
|
spdlog::get("console")->error(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::warn:
|
||||||
|
spdlog::get("console")->warn(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::info:
|
||||||
|
spdlog::get("console")->info(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::debug:
|
||||||
|
spdlog::get("console")->debug(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::trace:
|
||||||
|
default:
|
||||||
|
spdlog::get("console")->trace(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include "events/consumers/logging_consumer.hpp"
|
#include "events/consumers/logging_consumer.hpp"
|
||||||
|
|
||||||
#include "events/events.hpp"
|
#include "events/events.hpp"
|
||||||
|
#include "events/i_event.hpp"
|
||||||
|
#include "events/types/event_level_changed.hpp"
|
||||||
#include "spdlog/async.h"
|
#include "spdlog/async.h"
|
||||||
#include "spdlog/sinks/rotating_file_sink.h"
|
#include "spdlog/sinks/rotating_file_sink.h"
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
@ -66,35 +68,60 @@ logging_consumer::logging_consumer(event_level level,
|
|||||||
set_level(level);
|
set_level(level);
|
||||||
|
|
||||||
E_SUBSCRIBE_ALL(process_event);
|
E_SUBSCRIBE_ALL(process_event);
|
||||||
E_SUBSCRIBE_EXACT(event_level_changed,
|
E_SUBSCRIBE2_ALL(process_event2);
|
||||||
[](const event_level_changed &changed) {
|
E_SUBSCRIBE2_EXACT(event_level_changed,
|
||||||
set_level(event_level_from_string(
|
[](auto &&evt) { set_level(evt.level); });
|
||||||
changed.get_new_event_level().get<std::string>()));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logging_consumer::~logging_consumer() { E_CONSUMER_RELEASE(); }
|
logging_consumer::~logging_consumer() {
|
||||||
|
E_CONSUMER_RELEASE();
|
||||||
|
E_CONSUMER2_RELEASE();
|
||||||
|
}
|
||||||
|
|
||||||
void logging_consumer::process_event(const event &event) const {
|
void logging_consumer::process_event(const event &evt) {
|
||||||
switch (event.get_event_level()) {
|
switch (evt.get_event_level()) {
|
||||||
case event_level::critical:
|
case event_level::critical:
|
||||||
spdlog::get("file")->critical(event.get_single_line());
|
spdlog::get("file")->critical(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::error:
|
case event_level::error:
|
||||||
spdlog::get("file")->error(event.get_single_line());
|
spdlog::get("file")->error(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::warn:
|
case event_level::warn:
|
||||||
spdlog::get("file")->warn(event.get_single_line());
|
spdlog::get("file")->warn(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::info:
|
case event_level::info:
|
||||||
spdlog::get("file")->info(event.get_single_line());
|
spdlog::get("file")->info(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::debug:
|
case event_level::debug:
|
||||||
spdlog::get("file")->debug(event.get_single_line());
|
spdlog::get("file")->debug(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
case event_level::trace:
|
case event_level::trace:
|
||||||
default:
|
default:
|
||||||
spdlog::get("file")->trace(event.get_single_line());
|
spdlog::get("file")->trace(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void logging_consumer::process_event2(const i_event &evt) {
|
||||||
|
switch (evt.get_event_level()) {
|
||||||
|
case event_level::critical:
|
||||||
|
spdlog::get("file")->critical(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::error:
|
||||||
|
spdlog::get("file")->error(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::warn:
|
||||||
|
spdlog::get("file")->warn(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::info:
|
||||||
|
spdlog::get("file")->info(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::debug:
|
||||||
|
spdlog::get("file")->debug(evt.get_single_line());
|
||||||
|
break;
|
||||||
|
case event_level::trace:
|
||||||
|
default:
|
||||||
|
spdlog::get("file")->trace(evt.get_single_line());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,24 +26,26 @@
|
|||||||
#include "utils/collection.hpp"
|
#include "utils/collection.hpp"
|
||||||
|
|
||||||
namespace repertory {
|
namespace repertory {
|
||||||
void event_system2::attach(event_consumer *consumer) {
|
event_system2 event_system2::instance_{};
|
||||||
|
|
||||||
|
auto event_system2::instance() -> event_system2 & { return instance_; }
|
||||||
|
|
||||||
|
void event_system2::attach(event_consumer2 *consumer) {
|
||||||
recur_mutex_lock lock(consumer_mutex_);
|
recur_mutex_lock lock(consumer_mutex_);
|
||||||
event_consumers_[""].push_back(consumer);
|
event_consumers_[""].push_back(consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_system2::attach(std::string_view event_name,
|
void event_system2::attach(std::string_view event_name,
|
||||||
event_consumer *consumer) {
|
event_consumer2 *consumer) {
|
||||||
recur_mutex_lock lock(consumer_mutex_);
|
recur_mutex_lock lock(consumer_mutex_);
|
||||||
event_consumers_[std::string{event_name}].push_back(consumer);
|
event_consumers_[std::string{event_name}].push_back(consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] auto event_system2::get_stop_requested() const -> bool {
|
auto event_system2::get_stop_requested() const -> bool {
|
||||||
return stop_requested_ || app_config::get_stop_requested();
|
return stop_requested_ || app_config::get_stop_requested();
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_system2::process_events() {
|
void event_system2::process_events() {
|
||||||
std::vector<std::shared_ptr<i_event>> events;
|
|
||||||
|
|
||||||
unique_mutex_lock lock(event_mutex_);
|
unique_mutex_lock lock(event_mutex_);
|
||||||
const auto lock_and_notify = [this, &lock]() {
|
const auto lock_and_notify = [this, &lock]() {
|
||||||
lock.lock();
|
lock.lock();
|
||||||
@ -55,14 +57,11 @@ void event_system2::process_events() {
|
|||||||
event_notify_.wait_for(lock, queue_wait_secs);
|
event_notify_.wait_for(lock, queue_wait_secs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not event_list_.empty()) {
|
std::vector<std::shared_ptr<i_event>> event_list;
|
||||||
events.insert(events.end(), event_list_.begin(), event_list_.end());
|
std::swap(event_list, event_list_);
|
||||||
event_list_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
if (events.empty()) {
|
if (event_list.empty()) {
|
||||||
lock_and_notify();
|
lock_and_notify();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -83,7 +82,7 @@ void event_system2::process_events() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const auto &evt : events) {
|
for (const auto &evt : event_list) {
|
||||||
notify_events("", *evt.get());
|
notify_events("", *evt.get());
|
||||||
notify_events(evt->get_name(), *evt.get());
|
notify_events(evt->get_name(), *evt.get());
|
||||||
}
|
}
|
||||||
@ -114,15 +113,15 @@ void event_system2::queue_event(std::shared_ptr<i_event> evt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_system2::release(event_consumer *consumer) {
|
void event_system2::release(event_consumer2 *consumer) {
|
||||||
recur_mutex_lock lock(consumer_mutex_);
|
recur_mutex_lock lock(consumer_mutex_);
|
||||||
auto iter =
|
auto iter =
|
||||||
std::ranges::find_if(event_consumers_, [&](const auto &item) -> bool {
|
std::ranges::find_if(event_consumers_, [&consumer](auto &&item) -> bool {
|
||||||
return utils::collection::includes(item.second, consumer);
|
return utils::collection::includes(item.second, consumer);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (iter != event_consumers_.end()) {
|
if (iter != event_consumers_.end()) {
|
||||||
utils::collection::remove_element((*iter).second, consumer);
|
utils::collection::remove_element(iter->second, consumer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user