refactor stop
This commit is contained in:
@ -44,10 +44,9 @@ private:
|
||||
api_item_added_callback api_item_added_;
|
||||
std::unique_ptr<meta_db> db3_;
|
||||
i_file_manager *fm_{};
|
||||
std::atomic<bool> stop_requested_{false};
|
||||
|
||||
private:
|
||||
void remove_deleted_files();
|
||||
void remove_deleted_files(const stop_type &stop_requested);
|
||||
|
||||
protected:
|
||||
[[nodiscard]] static auto
|
||||
|
@ -77,74 +77,68 @@ private:
|
||||
const encrypt_config &cfg,
|
||||
std::string &api_path) const -> bool;
|
||||
|
||||
void remove_deleted_files();
|
||||
void remove_deleted_files(const stop_type &stop_requested);
|
||||
|
||||
public:
|
||||
[[nodiscard]] auto create_directory(const std::string &api_path,
|
||||
api_meta_map &meta) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
create_directory_clone_source_meta(const std::string & /*source_api_path*/,
|
||||
const std::string & /*api_path*/)
|
||||
-> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto create_file(const std::string & /*api_path*/,
|
||||
api_meta_map & /*meta*/)
|
||||
-> api_error override {
|
||||
[[nodiscard]] auto create_directory_clone_source_meta(
|
||||
const std::string & /*source_api_path*/,
|
||||
const std::string & /*api_path*/) -> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_api_path_from_source(const std::string & /*source_path*/,
|
||||
std::string & /*api_path*/) const
|
||||
-> api_error override;
|
||||
create_file(const std::string & /*api_path*/,
|
||||
api_meta_map & /*meta*/) -> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto get_api_path_from_source(
|
||||
const std::string & /*source_path*/,
|
||||
std::string & /*api_path*/) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_directory_item_count(const std::string &api_path) const
|
||||
-> std::uint64_t override;
|
||||
|
||||
[[nodiscard]] auto get_directory_items(const std::string &api_path,
|
||||
directory_item_list &list) const
|
||||
-> api_error override;
|
||||
[[nodiscard]] auto
|
||||
get_directory_items(const std::string &api_path,
|
||||
directory_item_list &list) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_file(const std::string &api_path, api_file &file) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_file_list(api_file_list &list,
|
||||
std::string &marker) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_file_size(const std::string &api_path,
|
||||
std::uint64_t &file_size) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_filesystem_item(const std::string &api_path,
|
||||
bool directory,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_filesystem_item_and_file(const std::string &api_path,
|
||||
api_file &file,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error override;
|
||||
[[nodiscard]] auto get_file(const std::string &api_path,
|
||||
api_file &file) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_filesystem_item_from_source_path(const std::string &source_path,
|
||||
filesystem_item &fsi) const
|
||||
-> api_error override;
|
||||
get_file_list(api_file_list &list,
|
||||
std::string &marker) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_pinned_files() const
|
||||
-> std::vector<std::string> override;
|
||||
[[nodiscard]] auto
|
||||
get_file_size(const std::string &api_path,
|
||||
std::uint64_t &file_size) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const
|
||||
-> api_error override;
|
||||
[[nodiscard]] auto
|
||||
get_filesystem_item(const std::string &api_path, bool directory,
|
||||
filesystem_item &fsi) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
std::string &value) const
|
||||
-> api_error override;
|
||||
[[nodiscard]] auto get_filesystem_item_and_file(
|
||||
const std::string &api_path, api_file &file,
|
||||
filesystem_item &fsi) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_filesystem_item_from_source_path(
|
||||
const std::string &source_path,
|
||||
filesystem_item &fsi) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_pinned_files() const -> std::vector<std::string> override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_item_meta(const std::string &api_path,
|
||||
api_meta_map &meta) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto
|
||||
get_item_meta(const std::string &api_path, const std::string &key,
|
||||
std::string &value) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto get_total_drive_space() const -> std::uint64_t override;
|
||||
|
||||
@ -159,11 +153,11 @@ public:
|
||||
[[nodiscard]] auto is_directory(const std::string &api_path,
|
||||
bool &exists) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto is_file(const std::string &api_path, bool &exists) const
|
||||
-> api_error override;
|
||||
[[nodiscard]] auto is_file(const std::string &api_path,
|
||||
bool &exists) const -> api_error override;
|
||||
|
||||
[[nodiscard]] auto is_file_writeable(const std::string &api_path) const
|
||||
-> bool override;
|
||||
[[nodiscard]] auto
|
||||
is_file_writeable(const std::string &api_path) const -> bool override;
|
||||
|
||||
[[nodiscard]] auto is_online() const -> bool override;
|
||||
|
||||
@ -173,44 +167,42 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto read_file_bytes(const std::string &api_path,
|
||||
std::size_t size, std::uint64_t offset,
|
||||
data_buffer &data,
|
||||
stop_type &stop_requested)
|
||||
-> api_error override;
|
||||
[[nodiscard]] auto
|
||||
read_file_bytes(const std::string &api_path, std::size_t size,
|
||||
std::uint64_t offset, data_buffer &data,
|
||||
stop_type &stop_requested) -> api_error override;
|
||||
|
||||
[[nodiscard]] auto remove_directory(const std::string & /*api_path*/)
|
||||
-> api_error override {
|
||||
[[nodiscard]] auto
|
||||
remove_directory(const std::string & /*api_path*/) -> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto remove_file(const std::string & /*api_path*/)
|
||||
-> api_error override {
|
||||
[[nodiscard]] auto
|
||||
remove_file(const std::string & /*api_path*/) -> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto remove_item_meta(const std::string & /*api_path*/,
|
||||
const std::string & /*key*/)
|
||||
-> api_error override {
|
||||
[[nodiscard]] auto
|
||||
remove_item_meta(const std::string & /*api_path*/,
|
||||
const std::string & /*key*/) -> api_error override {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto rename_file(const std::string & /*from_api_path*/,
|
||||
const std::string & /*to_api_path*/)
|
||||
-> api_error override {
|
||||
[[nodiscard]] auto
|
||||
rename_file(const std::string & /*from_api_path*/,
|
||||
const std::string & /*to_api_path*/) -> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto set_item_meta(const std::string & /*api_path*/,
|
||||
const std::string & /*key*/,
|
||||
const std::string & /*value*/)
|
||||
-> api_error override {
|
||||
[[nodiscard]] auto
|
||||
set_item_meta(const std::string & /*api_path*/, const std::string & /*key*/,
|
||||
const std::string & /*value*/) -> api_error override {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
[[nodiscard]] auto set_item_meta(const std::string & /*api_path*/,
|
||||
const api_meta_map & /*meta*/)
|
||||
-> api_error override {
|
||||
[[nodiscard]] auto
|
||||
set_item_meta(const std::string & /*api_path*/,
|
||||
const api_meta_map & /*meta*/) -> api_error override {
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
@ -219,10 +211,10 @@ public:
|
||||
|
||||
void stop() override;
|
||||
|
||||
[[nodiscard]] auto upload_file(const std::string & /*api_path*/,
|
||||
const std::string & /*source_path*/,
|
||||
stop_type & /*stop_requested*/)
|
||||
-> api_error override {
|
||||
[[nodiscard]] auto
|
||||
upload_file(const std::string & /*api_path*/,
|
||||
const std::string & /*source_path*/,
|
||||
stop_type & /*stop_requested*/) -> api_error override {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
};
|
||||
|
@ -37,7 +37,7 @@ public:
|
||||
struct polling_item {
|
||||
std::string name;
|
||||
frequency freq;
|
||||
std::function<void()> action;
|
||||
std::function<void(const stop_type &stop_requested)> action;
|
||||
};
|
||||
|
||||
public:
|
||||
@ -58,7 +58,7 @@ public:
|
||||
static auto instance() -> polling & { return instance_; }
|
||||
|
||||
private:
|
||||
app_config *config_ = nullptr;
|
||||
app_config *config_{nullptr};
|
||||
std::unique_ptr<std::thread> high_frequency_thread_;
|
||||
std::unordered_map<std::string, polling_item> items_;
|
||||
std::unique_ptr<std::thread> low_frequency_thread_;
|
||||
@ -66,7 +66,7 @@ private:
|
||||
std::condition_variable notify_;
|
||||
std::unique_ptr<std::thread> second_frequency_thread_;
|
||||
std::mutex start_stop_mutex_;
|
||||
stop_type stop_requested_ = false;
|
||||
stop_type stop_requested_{false};
|
||||
|
||||
private:
|
||||
void frequency_thread(std::function<std::uint32_t()> get_frequency_seconds,
|
||||
|
Reference in New Issue
Block a user