refactor
This commit is contained in:
@ -64,10 +64,10 @@ private:
|
|||||||
stop_type stop_requested_{false};
|
stop_type stop_requested_{false};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
auto download_chunk(std::size_t chunk, bool skip_active) -> api_error;
|
|
||||||
|
|
||||||
void background_reader_thread();
|
void background_reader_thread();
|
||||||
|
|
||||||
|
auto download_chunk(std::size_t chunk, bool skip_active) -> api_error;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] auto is_download_complete() const -> bool override {
|
[[nodiscard]] auto is_download_complete() const -> bool override {
|
||||||
return false;
|
return false;
|
||||||
@ -78,24 +78,10 @@ public:
|
|||||||
|
|
||||||
void forward(std::size_t count);
|
void forward(std::size_t count);
|
||||||
|
|
||||||
[[nodiscard]] auto get_current_chunk() const -> std::size_t {
|
|
||||||
return ring_pos_;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_first_chunk() const -> std::size_t {
|
|
||||||
return ring_begin_;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_last_chunk() const -> std::size_t { return ring_end_; }
|
|
||||||
|
|
||||||
[[nodiscard]] auto get_read_state() const -> boost::dynamic_bitset<> override;
|
[[nodiscard]] auto get_read_state() const -> boost::dynamic_bitset<> override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_read_state(std::size_t chunk) const -> bool override;
|
[[nodiscard]] auto get_read_state(std::size_t chunk) const -> bool override;
|
||||||
|
|
||||||
[[nodiscard]] auto get_total_chunks() const -> std::size_t {
|
|
||||||
return total_chunks_;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] auto is_complete() const -> bool override { return true; }
|
[[nodiscard]] auto is_complete() const -> bool override { return true; }
|
||||||
|
|
||||||
[[nodiscard]] auto is_write_supported() const -> bool override {
|
[[nodiscard]] auto is_write_supported() const -> bool override {
|
||||||
@ -122,11 +108,11 @@ public:
|
|||||||
|
|
||||||
void reverse(std::size_t count);
|
void reverse(std::size_t count);
|
||||||
|
|
||||||
void set(std::size_t first_chunk, std::size_t current_chunk);
|
|
||||||
|
|
||||||
void set_api_path(const std::string &api_path) override;
|
void set_api_path(const std::string &api_path) override;
|
||||||
|
|
||||||
[[nodiscard]] auto write(std::uint64_t, const data_buffer &, std::size_t &)
|
[[nodiscard]] auto write(std::uint64_t /* write_offset */,
|
||||||
|
const data_buffer & /* data */,
|
||||||
|
std::size_t & /* bytes_written */)
|
||||||
-> api_error override {
|
-> api_error override {
|
||||||
return api_error::not_supported;
|
return api_error::not_supported;
|
||||||
}
|
}
|
||||||
|
@ -65,10 +65,10 @@ private:
|
|||||||
stop_type stop_requested_{false};
|
stop_type stop_requested_{false};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
auto download_chunk(std::size_t chunk, bool skip_active) -> api_error;
|
|
||||||
|
|
||||||
void background_reader_thread();
|
void background_reader_thread();
|
||||||
|
|
||||||
|
auto download_chunk(std::size_t chunk, bool skip_active) -> api_error;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] auto is_download_complete() const -> bool override {
|
[[nodiscard]] auto is_download_complete() const -> bool override {
|
||||||
return false;
|
return false;
|
||||||
@ -110,7 +110,8 @@ public:
|
|||||||
[[nodiscard]] auto native_operation(native_operation_callback callback)
|
[[nodiscard]] auto native_operation(native_operation_callback callback)
|
||||||
-> api_error override;
|
-> api_error override;
|
||||||
|
|
||||||
[[nodiscard]] auto native_operation(std::uint64_t, native_operation_callback)
|
[[nodiscard]] auto native_operation(std::uint64_t /* new_file_size */,
|
||||||
|
native_operation_callback /* callback */)
|
||||||
-> api_error override {
|
-> api_error override {
|
||||||
return api_error::not_supported;
|
return api_error::not_supported;
|
||||||
}
|
}
|
||||||
@ -128,7 +129,9 @@ public:
|
|||||||
|
|
||||||
void set_api_path(const std::string &api_path) override;
|
void set_api_path(const std::string &api_path) override;
|
||||||
|
|
||||||
[[nodiscard]] auto write(std::uint64_t, const data_buffer &, std::size_t &)
|
[[nodiscard]] auto write(std::uint64_t /* write_offset */,
|
||||||
|
const data_buffer & /* data */,
|
||||||
|
std::size_t & /* bytes_written */)
|
||||||
-> api_error override {
|
-> api_error override {
|
||||||
return api_error::not_supported;
|
return api_error::not_supported;
|
||||||
}
|
}
|
||||||
|
@ -312,30 +312,6 @@ auto direct_open_file::read(std::size_t read_size, std::uint64_t read_offset,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void direct_open_file::set(std::size_t first_chunk,
|
|
||||||
std::size_t current_chunk) {
|
|
||||||
mutex_lock chunk_lock(chunk_mtx_);
|
|
||||||
if (first_chunk >= total_chunks_) {
|
|
||||||
chunk_notify_.notify_all();
|
|
||||||
throw std::runtime_error("first chunk must be less than total chunks");
|
|
||||||
}
|
|
||||||
|
|
||||||
ring_begin_ = first_chunk;
|
|
||||||
ring_end_ =
|
|
||||||
std::min(total_chunks_ - 1U, ring_begin_ + ring_state_.size() - 1U);
|
|
||||||
|
|
||||||
if (current_chunk > ring_end_) {
|
|
||||||
chunk_notify_.notify_all();
|
|
||||||
throw std::runtime_error(
|
|
||||||
"current chunk must be less than or equal to last chunk");
|
|
||||||
}
|
|
||||||
|
|
||||||
ring_pos_ = current_chunk;
|
|
||||||
ring_state_.set(0U, ring_state_.size(), false);
|
|
||||||
|
|
||||||
chunk_notify_.notify_all();
|
|
||||||
}
|
|
||||||
|
|
||||||
void direct_open_file::set_api_path(const std::string &api_path) {
|
void direct_open_file::set_api_path(const std::string &api_path) {
|
||||||
mutex_lock chunk_lock(chunk_mtx_);
|
mutex_lock chunk_lock(chunk_mtx_);
|
||||||
open_file_base::set_api_path(api_path);
|
open_file_base::set_api_path(api_path);
|
||||||
|
Reference in New Issue
Block a user