refactor event system
This commit is contained in:
@ -27,39 +27,6 @@
|
||||
|
||||
namespace repertory {
|
||||
// clang-format off
|
||||
E_SIMPLE2(download_restored, info,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, dest_path, dest, E_FROM_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_restore_failed, error,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, dest_path, dest, E_FROM_STRING,
|
||||
std::string, error, err, E_FROM_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_resume_add_failed, error,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, dest_path, dest, E_FROM_STRING,
|
||||
std::string, error, err, E_FROM_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_resume_added, debug,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, dest_path, dest, E_FROM_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE2(download_resume_removed, debug,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, dest_path, dest, E_FROM_STRING
|
||||
);
|
||||
|
||||
E_SIMPLE3(download_type_selected, debug,
|
||||
std::string, api_path, ap, E_FROM_STRING,
|
||||
std::string, source, src, E_FROM_STRING,
|
||||
download_type, download_type, type, E_FROM_DOWNLOAD_TYPE
|
||||
);
|
||||
|
||||
E_SIMPLE1(item_timeout, trace,
|
||||
std::string, api_path, ap, E_FROM_STRING
|
||||
);
|
||||
|
@ -0,0 +1,80 @@
|
||||
/*
|
||||
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_DOWNLOAD_RESTORE_FAILED_HPP_
|
||||
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESTORE_FAILED_HPP_
|
||||
|
||||
#include "events/i_event.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
struct download_restore_failed final : public i_event {
|
||||
download_restore_failed() = default;
|
||||
download_restore_failed(std::string api_path_, std::string dest_path_,
|
||||
std::string error_, std::string_view function_name_)
|
||||
: api_path(std::move(api_path_)),
|
||||
dest_path(std::move(dest_path_)),
|
||||
error(std::move(error_)),
|
||||
function_name(std::string(function_name_)) {}
|
||||
|
||||
static constexpr const std::string_view name{"download_restore_failed"};
|
||||
|
||||
std::string api_path;
|
||||
std::string dest_path;
|
||||
std::string error;
|
||||
std::string function_name;
|
||||
|
||||
[[nodiscard]] auto get_event_level() const -> event_level override {
|
||||
return event_level::error;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_name() const -> std::string_view override {
|
||||
return name;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_single_line() const -> std::string override {
|
||||
return fmt::format("{}|func|{}|ap|{}|dp|{}|error|{}", name, function_name,
|
||||
api_path, dest_path, error);
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
template <> struct adl_serializer<repertory::download_restore_failed> {
|
||||
static void to_json(json &data,
|
||||
const repertory::download_restore_failed &value) {
|
||||
data["api_path"] = value.api_path;
|
||||
data["dest_path"] = value.dest_path;
|
||||
data["error"] = value.error;
|
||||
data["function_name"] = value.function_name;
|
||||
}
|
||||
|
||||
static void from_json(const json &data,
|
||||
repertory::download_restore_failed &value) {
|
||||
data.at("api_path").get_to<std::string>(value.api_path);
|
||||
data.at("dest_path").get_to<std::string>(value.dest_path);
|
||||
data.at("error").get_to<std::string>(value.error);
|
||||
data.at("function_name").get_to<std::string>(value.function_name);
|
||||
}
|
||||
};
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESTORE_FAILED_HPP_
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
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_DOWNLOAD_RESTORED_HPP_
|
||||
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESTORED_HPP_
|
||||
|
||||
#include "events/i_event.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
struct download_restored final : public i_event {
|
||||
download_restored() = default;
|
||||
download_restored(std::string api_path_, std::string dest_path_,
|
||||
std::string_view function_name_)
|
||||
: api_path(std::move(api_path_)),
|
||||
dest_path(std::move(dest_path_)),
|
||||
function_name(std::string(function_name_)) {}
|
||||
|
||||
static constexpr const std::string_view name{"download_restored"};
|
||||
|
||||
std::string api_path;
|
||||
std::string dest_path;
|
||||
std::string function_name;
|
||||
|
||||
[[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|{}|ap|{}|dp|{}", name, function_name, api_path,
|
||||
dest_path);
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
template <> struct adl_serializer<repertory::download_restored> {
|
||||
static void to_json(json &data, const repertory::download_restored &value) {
|
||||
data["api_path"] = value.api_path;
|
||||
data["dest_path"] = value.dest_path;
|
||||
data["function_name"] = value.function_name;
|
||||
}
|
||||
|
||||
static void from_json(const json &data, repertory::download_restored &value) {
|
||||
data.at("api_path").get_to<std::string>(value.api_path);
|
||||
data.at("dest_path").get_to<std::string>(value.dest_path);
|
||||
data.at("function_name").get_to<std::string>(value.function_name);
|
||||
}
|
||||
};
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESTORED_HPP_
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
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_DOWNLOAD_RESUME_ADD_FAILED_HPP_
|
||||
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_ADD_FAILED_HPP_
|
||||
|
||||
#include "events/i_event.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
struct download_resume_add_failed final : public i_event {
|
||||
download_resume_add_failed() = default;
|
||||
download_resume_add_failed(std::string api_path_, std::string dest_path_,
|
||||
std::string error_,
|
||||
std::string_view function_name_)
|
||||
: api_path(std::move(api_path_)),
|
||||
dest_path(std::move(dest_path_)),
|
||||
error(std::move(error_)),
|
||||
function_name(std::string(function_name_)) {}
|
||||
|
||||
static constexpr const std::string_view name{"download_resume_add_failed"};
|
||||
|
||||
std::string api_path;
|
||||
std::string dest_path;
|
||||
std::string error;
|
||||
std::string function_name;
|
||||
|
||||
[[nodiscard]] auto get_event_level() const -> event_level override {
|
||||
return event_level::error;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_name() const -> std::string_view override {
|
||||
return name;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_single_line() const -> std::string override {
|
||||
return fmt::format("{}|func|{}|ap|{}|dp|{}|error|{}", name, function_name,
|
||||
api_path, dest_path, error);
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
template <> struct adl_serializer<repertory::download_resume_add_failed> {
|
||||
static void to_json(json &data,
|
||||
const repertory::download_resume_add_failed &value) {
|
||||
data["api_path"] = value.api_path;
|
||||
data["dest_path"] = value.dest_path;
|
||||
data["error"] = value.error;
|
||||
data["function_name"] = value.function_name;
|
||||
}
|
||||
|
||||
static void from_json(const json &data,
|
||||
repertory::download_resume_add_failed &value) {
|
||||
data.at("api_path").get_to<std::string>(value.api_path);
|
||||
data.at("dest_path").get_to<std::string>(value.dest_path);
|
||||
data.at("error").get_to<std::string>(value.error);
|
||||
data.at("function_name").get_to<std::string>(value.function_name);
|
||||
}
|
||||
};
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_ADD_FAILED_HPP_
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
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_DOWNLOAD_RESUME_ADDED_HPP_
|
||||
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_ADDED_HPP_
|
||||
|
||||
#include "events/i_event.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
struct download_resume_added final : public i_event {
|
||||
download_resume_added() = default;
|
||||
download_resume_added(std::string api_path_, std::string dest_path_,
|
||||
std::string_view function_name_)
|
||||
: api_path(std::move(api_path_)),
|
||||
dest_path(std::move(dest_path_)),
|
||||
function_name(std::string(function_name_)) {}
|
||||
|
||||
static constexpr const std::string_view name{"download_resume_added"};
|
||||
|
||||
std::string api_path;
|
||||
std::string dest_path;
|
||||
std::string function_name;
|
||||
|
||||
[[nodiscard]] auto get_event_level() const -> event_level override {
|
||||
return event_level::debug;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_name() const -> std::string_view override {
|
||||
return name;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_single_line() const -> std::string override {
|
||||
return fmt::format("{}|func|{}|ap|{}|dp|{}", name, function_name, api_path,
|
||||
dest_path);
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
template <> struct adl_serializer<repertory::download_resume_added> {
|
||||
static void to_json(json &data,
|
||||
const repertory::download_resume_added &value) {
|
||||
data["api_path"] = value.api_path;
|
||||
data["dest_path"] = value.dest_path;
|
||||
data["function_name"] = value.function_name;
|
||||
}
|
||||
|
||||
static void from_json(const json &data,
|
||||
repertory::download_resume_added &value) {
|
||||
data.at("api_path").get_to<std::string>(value.api_path);
|
||||
data.at("dest_path").get_to<std::string>(value.dest_path);
|
||||
data.at("function_name").get_to<std::string>(value.function_name);
|
||||
}
|
||||
};
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_ADDED_HPP_
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
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_DOWNLOAD_RESUME_REMOVED_HPP_
|
||||
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_REMOVED_HPP_
|
||||
|
||||
#include "events/i_event.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
struct download_resume_removed final : public i_event {
|
||||
download_resume_removed() = default;
|
||||
download_resume_removed(std::string api_path_, std::string dest_path_,
|
||||
std::string_view function_name_)
|
||||
: api_path(std::move(api_path_)),
|
||||
dest_path(std::move(dest_path_)),
|
||||
function_name(std::string(function_name_)) {}
|
||||
|
||||
static constexpr const std::string_view name{"download_resume_removed"};
|
||||
|
||||
std::string api_path;
|
||||
std::string dest_path;
|
||||
std::string function_name;
|
||||
|
||||
[[nodiscard]] auto get_event_level() const -> event_level override {
|
||||
return event_level::debug;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_name() const -> std::string_view override {
|
||||
return name;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_single_line() const -> std::string override {
|
||||
return fmt::format("{}|func|{}|ap|{}|dp|{}", name, function_name, api_path,
|
||||
dest_path);
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
template <> struct adl_serializer<repertory::download_resume_removed> {
|
||||
static void to_json(json &data,
|
||||
const repertory::download_resume_removed &value) {
|
||||
data["api_path"] = value.api_path;
|
||||
data["dest_path"] = value.dest_path;
|
||||
data["function_name"] = value.function_name;
|
||||
}
|
||||
|
||||
static void from_json(const json &data,
|
||||
repertory::download_resume_removed &value) {
|
||||
data.at("api_path").get_to<std::string>(value.api_path);
|
||||
data.at("dest_path").get_to<std::string>(value.dest_path);
|
||||
data.at("function_name").get_to<std::string>(value.function_name);
|
||||
}
|
||||
};
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_RESUME_REMOVED_HPP_
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
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_DOWNLOAD_TYPE_SELECTED_HPP_
|
||||
#define REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_TYPE_SELECTED_HPP_
|
||||
|
||||
#include "events/i_event.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
struct download_type_selected final : public i_event {
|
||||
download_type_selected() = default;
|
||||
download_type_selected(std::string api_path_, std::string dest_path_,
|
||||
std::string_view function_name_, download_type type_)
|
||||
: api_path(std::move(api_path_)),
|
||||
dest_path(std::move(dest_path_)),
|
||||
function_name(std::string(function_name_)),
|
||||
type(type_) {}
|
||||
|
||||
static constexpr const std::string_view name{"download_type_selected"};
|
||||
|
||||
std::string api_path;
|
||||
std::string dest_path;
|
||||
std::string function_name;
|
||||
download_type type{};
|
||||
|
||||
[[nodiscard]] auto get_event_level() const -> event_level override {
|
||||
return event_level::debug;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_name() const -> std::string_view override {
|
||||
return name;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_single_line() const -> std::string override {
|
||||
return fmt::format("{}|func|{}|ap|{}|dp|{}|type|{}", name, function_name,
|
||||
api_path, dest_path, download_type_to_string(type));
|
||||
}
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
NLOHMANN_JSON_NAMESPACE_BEGIN
|
||||
template <> struct adl_serializer<repertory::download_type_selected> {
|
||||
static void to_json(json &data,
|
||||
const repertory::download_type_selected &value) {
|
||||
data["api_path"] = value.api_path;
|
||||
data["dest_path"] = value.dest_path;
|
||||
data["function_name"] = value.function_name;
|
||||
data["type"] = repertory::download_type_to_string(value.type);
|
||||
}
|
||||
|
||||
static void from_json(const json &data,
|
||||
repertory::download_type_selected &value) {
|
||||
data.at("api_path").get_to<std::string>(value.api_path);
|
||||
data.at("dest_path").get_to<std::string>(value.dest_path);
|
||||
data.at("function_name").get_to<std::string>(value.function_name);
|
||||
value.type = repertory::download_type_from_string(
|
||||
data.at("type").get<std::string>());
|
||||
}
|
||||
};
|
||||
NLOHMANN_JSON_NAMESPACE_END
|
||||
|
||||
#endif // REPERTORY_INCLUDE_EVENTS_TYPES_DOWNLOAD_TYPE_SELECTED_HPP_
|
@ -23,6 +23,12 @@
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "db/file_mgr_db.hpp"
|
||||
#include "events/types/download_restore_failed.hpp"
|
||||
#include "events/types/download_restored.hpp"
|
||||
#include "events/types/download_resume_add_failed.hpp"
|
||||
#include "events/types/download_resume_added.hpp"
|
||||
#include "events/types/download_resume_removed.hpp"
|
||||
#include "events/types/download_type_selected.hpp"
|
||||
#include "events/types/file_upload_failed.hpp"
|
||||
#include "events/types/file_upload_not_found.hpp"
|
||||
#include "events/types/file_upload_queued.hpp"
|
||||
@ -394,10 +400,11 @@ auto file_manager::open(const std::string &api_path, bool directory,
|
||||
return open(api_path, directory, ofd, handle, file, nullptr);
|
||||
}
|
||||
|
||||
auto file_manager::open(
|
||||
const std::string &api_path, bool directory, const open_file_data &ofd,
|
||||
std::uint64_t &handle, std::shared_ptr<i_open_file> &file,
|
||||
std::shared_ptr<i_closeable_open_file> closeable_file) -> api_error {
|
||||
auto file_manager::open(const std::string &api_path, bool directory,
|
||||
const open_file_data &ofd, std::uint64_t &handle,
|
||||
std::shared_ptr<i_open_file> &file,
|
||||
std::shared_ptr<i_closeable_open_file> closeable_file)
|
||||
-> api_error {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
const auto create_and_add_handle =
|
||||
@ -497,7 +504,7 @@ auto file_manager::open(
|
||||
: preferred_type);
|
||||
if (not directory) {
|
||||
event_system::instance().raise<download_type_selected>(
|
||||
fsi.api_path, fsi.source_path, type);
|
||||
fsi.api_path, fsi.source_path, function_name, type);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
@ -596,6 +603,8 @@ void file_manager::remove_resume(const std::string &api_path,
|
||||
|
||||
void file_manager::remove_resume(const std::string &api_path,
|
||||
const std::string &source_path, bool no_lock) {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
if (provider_.is_read_only()) {
|
||||
return;
|
||||
}
|
||||
@ -606,8 +615,8 @@ void file_manager::remove_resume(const std::string &api_path,
|
||||
}
|
||||
|
||||
if (mgr_db_->remove_resume(api_path)) {
|
||||
event_system::instance().raise<download_resume_removed>(api_path,
|
||||
source_path);
|
||||
event_system::instance().raise<download_resume_removed>(
|
||||
api_path, source_path, function_name);
|
||||
}
|
||||
|
||||
if (not no_lock) {
|
||||
@ -769,8 +778,8 @@ auto file_manager::rename_directory(const std::string &from_api_path,
|
||||
}
|
||||
|
||||
auto file_manager::rename_file(const std::string &from_api_path,
|
||||
const std::string &to_api_path,
|
||||
bool overwrite) -> api_error {
|
||||
const std::string &to_api_path, bool overwrite)
|
||||
-> api_error {
|
||||
if (not provider_.is_rename_supported()) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
@ -876,15 +885,18 @@ void file_manager::start() {
|
||||
if (res != api_error::success) {
|
||||
event_system::instance().raise<download_restore_failed>(
|
||||
entry.api_path, entry.source_path,
|
||||
"failed to get filesystem item|" + api_error_to_string(res));
|
||||
fmt::format("failed to get filesystem item|{}",
|
||||
api_error_to_string(res)),
|
||||
function_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entry.source_path != fsi.source_path) {
|
||||
event_system::instance().raise<download_restore_failed>(
|
||||
fsi.api_path, fsi.source_path,
|
||||
"source path mismatch|expected|" + entry.source_path + "|actual|" +
|
||||
fsi.source_path);
|
||||
fmt::format("source path mismatch|expected|{}|actual|{}",
|
||||
entry.source_path, fsi.source_path),
|
||||
function_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -892,8 +904,9 @@ void file_manager::start() {
|
||||
if (not opt_size.has_value()) {
|
||||
event_system::instance().raise<download_restore_failed>(
|
||||
fsi.api_path, fsi.source_path,
|
||||
"failed to get file size: " +
|
||||
std::to_string(utils::get_last_error_code()));
|
||||
fmt::format("failed to get file size|{}",
|
||||
utils::get_last_error_code()),
|
||||
function_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -901,8 +914,9 @@ void file_manager::start() {
|
||||
if (file_size != fsi.size) {
|
||||
event_system::instance().raise<download_restore_failed>(
|
||||
fsi.api_path, fsi.source_path,
|
||||
"file size mismatch|expected|" + std::to_string(fsi.size) +
|
||||
"|actual|" + std::to_string(file_size));
|
||||
fmt::format("file size mismatch|expected|{}|actual|{}", fsi.size,
|
||||
file_size),
|
||||
function_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -913,8 +927,8 @@ void file_manager::start() {
|
||||
: 0U,
|
||||
fsi, provider_, entry.read_state, *this);
|
||||
open_file_lookup_[entry.api_path] = closeable_file;
|
||||
event_system::instance().raise<download_restored>(fsi.api_path,
|
||||
fsi.source_path);
|
||||
event_system::instance().raise<download_restored>(
|
||||
fsi.api_path, fsi.source_path, function_name);
|
||||
} catch (const std::exception &ex) {
|
||||
utils::error::raise_error(function_name, ex, "query error");
|
||||
}
|
||||
@ -972,6 +986,8 @@ void file_manager::stop() {
|
||||
}
|
||||
|
||||
void file_manager::store_resume(const i_open_file &file) {
|
||||
REPERTORY_USES_FUNCTION_NAME();
|
||||
|
||||
if (provider_.is_read_only()) {
|
||||
return;
|
||||
}
|
||||
@ -983,12 +999,13 @@ void file_manager::store_resume(const i_open_file &file) {
|
||||
file.get_source_path(),
|
||||
})) {
|
||||
event_system::instance().raise<download_resume_added>(
|
||||
file.get_api_path(), file.get_source_path());
|
||||
file.get_api_path(), file.get_source_path(), function_name);
|
||||
return;
|
||||
}
|
||||
|
||||
event_system::instance().raise<download_resume_add_failed>(
|
||||
file.get_api_path(), file.get_source_path(), "failed to store resume");
|
||||
file.get_api_path(), file.get_source_path(), "failed to store resume",
|
||||
function_name);
|
||||
}
|
||||
|
||||
void file_manager::swap_renamed_items(std::string from_api_path,
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "test_common.hpp"
|
||||
|
||||
#include "app_config.hpp"
|
||||
#include "events/types/download_restored.hpp"
|
||||
#include "events/types/download_resume_added.hpp"
|
||||
#include "events/types/file_upload_completed.hpp"
|
||||
#include "events/types/filesystem_item_closed.hpp"
|
||||
#include "events/types/filesystem_item_handle_closed.hpp"
|
||||
@ -413,7 +415,7 @@ TEST_F(file_manager_test,
|
||||
{utils::create_uuid_string()});
|
||||
|
||||
event_consumer consumer(
|
||||
"download_resume_added", [&source_path](const i_event &evt) {
|
||||
download_resume_added::name, [&source_path](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const download_resume_added &>(evt);
|
||||
EXPECT_STREQ("/test_write_partial_download.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
@ -421,7 +423,7 @@ TEST_F(file_manager_test,
|
||||
evt2.get_dest_path().get<std::string>().c_str());
|
||||
});
|
||||
|
||||
event_capture capture({"download_resume_added"},
|
||||
event_capture capture({download_resume_added::name},
|
||||
{
|
||||
file_upload_completed::name,
|
||||
file_upload_queued::name,
|
||||
@ -512,7 +514,7 @@ TEST_F(file_manager_test,
|
||||
mgr.stop();
|
||||
capture.wait_for_empty();
|
||||
|
||||
event_capture ec2({"download_restored", "download_resume_added"},
|
||||
event_capture ec2({download_restored::name, download_resume_added::name},
|
||||
{
|
||||
file_upload_completed::name,
|
||||
file_upload_queued::name,
|
||||
@ -536,13 +538,14 @@ TEST_F(file_manager_test,
|
||||
|
||||
mgr.start();
|
||||
|
||||
event_consumer es2("download_restored", [&source_path](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const download_restored &>(evt);
|
||||
EXPECT_STREQ("/test_write_partial_download.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_dest_path().get<std::string>().c_str());
|
||||
});
|
||||
event_consumer es2(
|
||||
download_restored::name, [&source_path](const i_event &evt) {
|
||||
const auto &evt2 = dynamic_cast<const download_restored &>(evt);
|
||||
EXPECT_STREQ("/test_write_partial_download.txt",
|
||||
evt2.get_api_path().get<std::string>().c_str());
|
||||
EXPECT_STREQ(source_path.c_str(),
|
||||
evt2.get_dest_path().get<std::string>().c_str());
|
||||
});
|
||||
|
||||
EXPECT_EQ(std::size_t(1u), mgr.get_open_file_count());
|
||||
EXPECT_EQ(std::size_t(0u), mgr.get_open_handle_count());
|
||||
@ -1425,7 +1428,7 @@ TEST_F(file_manager_test, can_remove_file) {
|
||||
TEST_F(file_manager_test, can_queue_and_remove_upload) {
|
||||
event_capture capture({
|
||||
file_upload_queued::name,
|
||||
"download_resume_removed",
|
||||
download_resume_removed::name,
|
||||
});
|
||||
|
||||
EXPECT_CALL(mp, is_read_only()).WillRepeatedly(Return(false));
|
||||
|
Reference in New Issue
Block a user