refactor event system
This commit is contained in:
@ -29,18 +29,18 @@
|
||||
namespace repertory {
|
||||
struct drive_mount_failed final : public i_event {
|
||||
drive_mount_failed() = default;
|
||||
drive_mount_failed(std::string_view function_name_,
|
||||
std::string mount_location_, NTSTATUS status_)
|
||||
: function_name(std::string(function_name_)),
|
||||
mount_location(std::move(mount_location_)),
|
||||
status(status_) {}
|
||||
drive_mount_failed(NTSTATUS error_, std::string_view function_name_,
|
||||
std::string mount_location_)
|
||||
: error(error_),
|
||||
function_name(std::string(function_name_)),
|
||||
mount_location(std::move(mount_location_)) {}
|
||||
|
||||
static constexpr const event_level level{event_level::error};
|
||||
static constexpr const std::string_view name{"drive_mount_failed"};
|
||||
|
||||
NTSTATUS error{};
|
||||
std::string function_name;
|
||||
std::string mount_location;
|
||||
NTSTATUS status{};
|
||||
|
||||
[[nodiscard]] auto get_event_level() const -> event_level override {
|
||||
return level;
|
||||
@ -52,7 +52,7 @@ struct drive_mount_failed final : public i_event {
|
||||
|
||||
[[nodiscard]] auto get_single_line() const -> std::string override {
|
||||
return fmt::format("{}|func|{}|location|{}|status|{}", name, function_name,
|
||||
mount_location, status);
|
||||
mount_location, error);
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
@ -60,16 +60,16 @@ struct drive_mount_failed final : public i_event {
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
template <> struct adl_serializer<repertory::drive_mount_failed> {
|
||||
static void to_json(json &data, const repertory::drive_mount_failed &value) {
|
||||
data["error"] = value.error;
|
||||
data["function_name"] = value.function_name;
|
||||
data["mount_location"] = value.mount_location;
|
||||
data["status"] = value.status;
|
||||
}
|
||||
|
||||
static void from_json(const json &data,
|
||||
repertory::drive_mount_failed &value) {
|
||||
data.at("error").get_to<NTSTATUS>(value.error);
|
||||
data.at("function_name").get_to<std::string>(value.function_name);
|
||||
data.at("mount_location").get_to<std::string>(value.mount_location);
|
||||
data.at("status").get_to<NTSTATUS>(value.status);
|
||||
}
|
||||
};
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
@ -68,7 +68,7 @@ template <> struct adl_serializer<repertory::remote_server_event> {
|
||||
static void from_json(const json &data,
|
||||
repertory::remote_server_event &value) {
|
||||
data.at("api_path").get_to<std::string>(value.api_path);
|
||||
data.at("error").get_to<NTSTATUS>(value.error);
|
||||
data.at("error").get_to<repertory::packet::error_type>(value.error);
|
||||
data.at("function_name").get_to<std::string>(value.function_name);
|
||||
}
|
||||
};
|
||||
|
@ -77,8 +77,8 @@ auto remote_winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS {
|
||||
}
|
||||
|
||||
if (ret != STATUS_SUCCESS) {
|
||||
event_system::instance().raise<drive_mount_failed>(function_name,
|
||||
mount_location, ret);
|
||||
event_system::instance().raise<drive_mount_failed>(ret, function_name,
|
||||
mount_location);
|
||||
if (not lock_.set_mount_state(false, "", -1)) {
|
||||
utils::error::raise_error(function_name, "failed to set mount state");
|
||||
}
|
||||
@ -129,8 +129,8 @@ auto remote_winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
|
||||
UINT32 granted_access, UINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR /*descriptor*/,
|
||||
UINT64 allocation_size, PVOID * /*file_node*/,
|
||||
PVOID *file_desc,
|
||||
OpenFileInfo *ofi) -> NTSTATUS {
|
||||
PVOID *file_desc, OpenFileInfo *ofi)
|
||||
-> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
std::string normalized_name;
|
||||
BOOLEAN exists = 0;
|
||||
@ -164,9 +164,10 @@ auto remote_winfsp_drive::GetFileInfo(PVOID /*file_node*/, PVOID file_desc,
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto remote_winfsp_drive::GetSecurityByName(
|
||||
PWSTR file_name, PUINT32 attributes, PSECURITY_DESCRIPTOR descriptor,
|
||||
SIZE_T *descriptor_size) -> NTSTATUS {
|
||||
auto remote_winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes,
|
||||
PSECURITY_DESCRIPTOR descriptor,
|
||||
SIZE_T *descriptor_size)
|
||||
-> NTSTATUS {
|
||||
std::wstring string_descriptor;
|
||||
std::uint64_t sds = (descriptor_size == nullptr) ? 0 : *descriptor_size;
|
||||
auto ret = remote_instance_->winfsp_get_security_by_name(
|
||||
@ -262,7 +263,7 @@ auto remote_winfsp_drive::mount(const std::vector<std::string> &drive_args)
|
||||
auto ret = winfsp_service(lock_, *this, parsed_drive_args, config_).Run();
|
||||
|
||||
event_system::instance().raise<drive_mount_result>(function_name, "",
|
||||
std::to_string(ret));
|
||||
std::to_string(ret));
|
||||
event_system::instance().stop();
|
||||
c.reset();
|
||||
return static_cast<int>(ret);
|
||||
@ -286,8 +287,8 @@ auto remote_winfsp_drive::Mounted(PVOID host) -> NTSTATUS {
|
||||
|
||||
auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
|
||||
UINT32 granted_access, PVOID * /*file_node*/,
|
||||
PVOID *file_desc,
|
||||
OpenFileInfo *ofi) -> NTSTATUS {
|
||||
PVOID *file_desc, OpenFileInfo *ofi)
|
||||
-> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
std::string normalize_name;
|
||||
auto ret =
|
||||
@ -307,8 +308,8 @@ auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
|
||||
auto remote_winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
|
||||
UINT32 attributes,
|
||||
BOOLEAN replace_attributes,
|
||||
UINT64 allocation_size,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
UINT64 allocation_size, FileInfo *file_info)
|
||||
-> NTSTATUS {
|
||||
remote::file_info info{};
|
||||
auto ret = remote_instance_->winfsp_overwrite(
|
||||
file_desc, attributes, replace_attributes, allocation_size, &info);
|
||||
@ -425,8 +426,8 @@ auto remote_winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
|
||||
UINT32 attributes, UINT64 creation_time,
|
||||
UINT64 last_access_time,
|
||||
UINT64 last_write_time,
|
||||
UINT64 change_time,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
UINT64 change_time, FileInfo *file_info)
|
||||
-> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
auto ret = remote_instance_->winfsp_set_basic_info(
|
||||
file_desc, attributes, creation_time, last_access_time, last_write_time,
|
||||
@ -478,8 +479,8 @@ VOID remote_winfsp_drive::Unmounted(PVOID host) {
|
||||
auto remote_winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc,
|
||||
PVOID buffer, UINT64 offset, ULONG length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PULONG bytes_transferred,
|
||||
FileInfo *file_info) -> NTSTATUS {
|
||||
PULONG bytes_transferred, FileInfo *file_info)
|
||||
-> NTSTATUS {
|
||||
remote::file_info fi{};
|
||||
auto ret = remote_instance_->winfsp_write(
|
||||
file_desc, buffer, offset, length, write_to_end, constrained_io,
|
||||
|
@ -127,8 +127,8 @@ auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/)
|
||||
utils::error::raise_error(function_name, ret, "failed to set mount state");
|
||||
}
|
||||
|
||||
event_system::instance().raise<drive_mount_failed>(function_name,
|
||||
mount_location, ret);
|
||||
event_system::instance().raise<drive_mount_failed>(ret, function_name,
|
||||
mount_location);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user