refactor event system
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
Some checks failed
BlockStorage/repertory/pipeline/head There was a failure building this commit
This commit is contained in:
parent
3b46a48078
commit
094aec0afb
@ -31,7 +31,7 @@ class app_config;
|
||||
class i_provider;
|
||||
|
||||
class fuse_base {
|
||||
E_CONSUMER2();
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
explicit fuse_base(app_config &config);
|
||||
|
@ -32,13 +32,13 @@ class lock_data;
|
||||
class server;
|
||||
namespace remote_winfsp {
|
||||
class remote_winfsp_drive final : public virtual FileSystemBase {
|
||||
E_CONSUMER2();
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
remote_winfsp_drive(app_config &config, remote_instance_factory factory,
|
||||
lock_data &lock);
|
||||
|
||||
~remote_winfsp_drive() override { E_CONSUMER2_RELEASE(); }
|
||||
~remote_winfsp_drive() override { E_CONSUMER_RELEASE(); }
|
||||
|
||||
public:
|
||||
class winfsp_service : virtual public Service {
|
||||
|
@ -37,12 +37,12 @@ class i_provider;
|
||||
|
||||
class winfsp_drive final : public virtual i_winfsp_drive,
|
||||
public virtual FileSystemBase {
|
||||
E_CONSUMER2();
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
winfsp_drive(app_config &config, lock_data &lockData, i_provider &provider);
|
||||
|
||||
~winfsp_drive() override { E_CONSUMER2_RELEASE(); }
|
||||
~winfsp_drive() override { E_CONSUMER_RELEASE(); }
|
||||
|
||||
private:
|
||||
class winfsp_service final : virtual public Service {
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
namespace repertory {
|
||||
class console_consumer final {
|
||||
E_CONSUMER2();
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
console_consumer();
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
namespace repertory {
|
||||
class logging_consumer final {
|
||||
E_CONSUMER2();
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
logging_consumer(event_level level, std::string log_directory);
|
||||
|
@ -121,24 +121,24 @@ public:
|
||||
|
||||
using event_consumer = event_system::event_consumer;
|
||||
|
||||
#define E_CONSUMER2() \
|
||||
#define E_CONSUMER() \
|
||||
private: \
|
||||
std::vector<std::shared_ptr<repertory::event_consumer>> event_consumers2_
|
||||
std::vector<std::shared_ptr<repertory::event_consumer>> event_consumers_
|
||||
|
||||
#define E_CONSUMER2_RELEASE() event_consumers2_.clear()
|
||||
#define E_CONSUMER_RELEASE() event_consumers_.clear()
|
||||
|
||||
#define E_SUBSCRIBE2(name, callback) \
|
||||
event_consumers2_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
#define E_SUBSCRIBE(name, callback) \
|
||||
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
#name, [this](const i_event &evt) { callback(evt); }))
|
||||
|
||||
#define E_SUBSCRIBE2_EXACT(name, callback) \
|
||||
event_consumers2_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
#define E_SUBSCRIBE_EXACT(name, callback) \
|
||||
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
#name, [this](const i_event &evt) { \
|
||||
callback(dynamic_cast<const name &>(evt)); \
|
||||
}))
|
||||
|
||||
#define E_SUBSCRIBE2_ALL(callback) \
|
||||
event_consumers2_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
#define E_SUBSCRIBE_ALL(callback) \
|
||||
event_consumers_.emplace_back(std::make_shared<repertory::event_consumer>( \
|
||||
[this](const i_event &evt) { callback(evt); }))
|
||||
} // namespace repertory
|
||||
|
||||
|
@ -37,7 +37,7 @@ class app_config;
|
||||
class i_provider;
|
||||
|
||||
class file_manager final : public i_file_manager, public i_upload_manager {
|
||||
E_CONSUMER2();
|
||||
E_CONSUMER();
|
||||
|
||||
private:
|
||||
static constexpr const std::chrono::seconds queue_wait_secs{
|
||||
|
@ -90,12 +90,12 @@ fuse_base::fuse_base(app_config &config) : config_(config) {
|
||||
fuse_ops_.flag_reserved = 0;
|
||||
#endif // FUSE_USE_VERSION < 30
|
||||
|
||||
E_SUBSCRIBE2_EXACT(unmount_requested, [this](const unmount_requested &) {
|
||||
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) {
|
||||
std::thread([this]() { this->shutdown(); }).detach();
|
||||
});
|
||||
}
|
||||
|
||||
fuse_base::~fuse_base() { E_CONSUMER2_RELEASE(); }
|
||||
fuse_base::~fuse_base() { E_CONSUMER_RELEASE(); }
|
||||
|
||||
auto fuse_base::access_(const char *path, int mask) -> int {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
@ -105,7 +105,7 @@ remote_winfsp_drive::remote_winfsp_drive(app_config &config,
|
||||
config_(config),
|
||||
lock_(lock),
|
||||
factory_(std::move(factory)) {
|
||||
E_SUBSCRIBE2_EXACT(unmount_requested, [this](const unmount_requested &) {
|
||||
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) {
|
||||
std::thread([this]() { this->shutdown(); }).detach();
|
||||
});
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ auto winfsp_drive::winfsp_service::OnStop() -> NTSTATUS {
|
||||
winfsp_drive::winfsp_drive(app_config &config, lock_data &lock,
|
||||
i_provider &provider)
|
||||
: provider_(provider), config_(config), lock_(lock) {
|
||||
E_SUBSCRIBE2_EXACT(unmount_requested, [this](const unmount_requested &) {
|
||||
E_SUBSCRIBE_EXACT(unmount_requested, [this](const unmount_requested &) {
|
||||
std::thread([this]() { this->shutdown(); }).detach();
|
||||
});
|
||||
}
|
||||
|
@ -62,12 +62,12 @@ console_consumer::console_consumer(event_level level) {
|
||||
|
||||
set_level(level);
|
||||
|
||||
E_SUBSCRIBE2_ALL(process_event2);
|
||||
E_SUBSCRIBE2_EXACT(event_level_changed,
|
||||
E_SUBSCRIBE_ALL(process_event2);
|
||||
E_SUBSCRIBE_EXACT(event_level_changed,
|
||||
[](auto &&event) { set_level(event.level); });
|
||||
}
|
||||
|
||||
console_consumer::~console_consumer() { E_CONSUMER2_RELEASE(); }
|
||||
console_consumer::~console_consumer() { E_CONSUMER_RELEASE(); }
|
||||
|
||||
void console_consumer::process_event2(const i_event &evt) {
|
||||
switch (evt.get_event_level()) {
|
||||
|
@ -66,12 +66,12 @@ logging_consumer::logging_consumer(event_level level,
|
||||
|
||||
set_level(level);
|
||||
|
||||
E_SUBSCRIBE2_ALL(process_event2);
|
||||
E_SUBSCRIBE2_EXACT(event_level_changed,
|
||||
E_SUBSCRIBE_ALL(process_event2);
|
||||
E_SUBSCRIBE_EXACT(event_level_changed,
|
||||
[](auto &&event) { set_level(event.level); });
|
||||
}
|
||||
|
||||
logging_consumer::~logging_consumer() { E_CONSUMER2_RELEASE(); }
|
||||
logging_consumer::~logging_consumer() { E_CONSUMER_RELEASE(); }
|
||||
|
||||
void logging_consumer::process_event2(const i_event &evt) {
|
||||
switch (evt.get_event_level()) {
|
||||
|
@ -58,7 +58,7 @@ file_manager::file_manager(app_config &config, i_provider &provider)
|
||||
return;
|
||||
}
|
||||
|
||||
E_SUBSCRIBE2_EXACT(file_upload_completed,
|
||||
E_SUBSCRIBE_EXACT(file_upload_completed,
|
||||
[this](auto &&event) { this->upload_completed(event); });
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ file_manager::~file_manager() {
|
||||
stop();
|
||||
mgr_db_.reset();
|
||||
|
||||
E_CONSUMER2_RELEASE();
|
||||
E_CONSUMER_RELEASE();
|
||||
}
|
||||
|
||||
void file_manager::close(std::uint64_t handle) {
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
namespace repertory {
|
||||
class event_capture final {
|
||||
E_CONSUMER2();
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
explicit event_capture(
|
||||
@ -37,13 +37,13 @@ public:
|
||||
std::vector<std::string_view> non_fired_event_names = {})
|
||||
: event_names_(std::move(event_names)),
|
||||
non_fired_event_names_(std::move(non_fired_event_names)) {
|
||||
E_SUBSCRIBE2_ALL(process_event);
|
||||
E_SUBSCRIBE_ALL(process_event);
|
||||
}
|
||||
|
||||
~event_capture() {
|
||||
wait_for_empty();
|
||||
|
||||
E_CONSUMER2_RELEASE();
|
||||
E_CONSUMER_RELEASE();
|
||||
|
||||
EXPECT_TRUE(event_names_.empty());
|
||||
for (const auto &event_name : event_names_) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user