| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2026, Stefan Meislinger | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/tech/copymachines.hpp" | ||
| 30 | |||
| 31 | namespace gate | ||
| 32 | { | ||
| 33 | namespace tech | ||
| 34 | { | ||
| 35 | |||
| 36 | 2 | StreamCopier::StreamCopier(Stream& input, Stream& output) | |
| 37 | 2 | : input_stream(input), output_stream(output) | |
| 38 | { | ||
| 39 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_stream_copier_init(&this->config, this); |
| 40 | 2 | this->config.callback = &StreamCopier::callback; | |
| 41 | 2 | Mem::clear(this->result); | |
| 42 | 2 | } | |
| 43 | 4 | StreamCopier::~StreamCopier() noexcept | |
| 44 | { | ||
| 45 | 4 | } | |
| 46 | |||
| 47 | 1 | uint64_t StreamCopier::getReadOffset() const | |
| 48 | { | ||
| 49 | 1 | return this->config.read_offset; | |
| 50 | } | ||
| 51 | 1 | uint64_t StreamCopier::getWriteOffset() const | |
| 52 | { | ||
| 53 | 1 | return this->config.write_offset; | |
| 54 | } | ||
| 55 | 1 | size_t StreamCopier::getBlockSize() const | |
| 56 | { | ||
| 57 | 1 | return this->config.block_size; | |
| 58 | } | ||
| 59 | 1 | uint64_t StreamCopier::getCopyLimit() const | |
| 60 | { | ||
| 61 | 1 | return this->config.copy_limit; | |
| 62 | } | ||
| 63 | 1 | bool_t StreamCopier::getContinueOnReadErrors() const | |
| 64 | { | ||
| 65 | 1 | return this->config.continue_on_read_errors; | |
| 66 | } | ||
| 67 | 1 | bool_t StreamCopier::getContinueOnWriteErrors() const | |
| 68 | { | ||
| 69 | 1 | return this->config.continue_on_write_errors; | |
| 70 | } | ||
| 71 | |||
| 72 | 2 | void StreamCopier::setReadOffset(uint64_t readOffset) | |
| 73 | { | ||
| 74 | 2 | this->config.read_offset = readOffset; | |
| 75 | 2 | } | |
| 76 | 2 | void StreamCopier::setWriteOffset(uint64_t writeOffset) | |
| 77 | { | ||
| 78 | 2 | this->config.write_offset = writeOffset; | |
| 79 | 2 | } | |
| 80 | 2 | void StreamCopier::setBlockSize(size_t blockSize) | |
| 81 | { | ||
| 82 | 2 | this->config.block_size = blockSize; | |
| 83 | 2 | } | |
| 84 | 2 | void StreamCopier::setCopyLimit(uint64_t copyLimit) | |
| 85 | { | ||
| 86 | 2 | this->config.copy_limit = copyLimit; | |
| 87 | 2 | } | |
| 88 | 2 | void StreamCopier::setContinueOnReadErrors(bool_t enabled) | |
| 89 | { | ||
| 90 | 2 | this->config.continue_on_read_errors = enabled; | |
| 91 | 2 | } | |
| 92 | 2 | void StreamCopier::setContinueOnWriteErrors(bool_t enabled) | |
| 93 | { | ||
| 94 | 2 | this->config.continue_on_write_errors = enabled; | |
| 95 | 2 | } | |
| 96 | 2 | StreamCopier::FinalResult StreamCopier::getFinalResult() const | |
| 97 | { | ||
| 98 | 2 | return this->result; | |
| 99 | } | ||
| 100 | |||
| 101 | |||
| 102 | 2 | void StreamCopier::run() | |
| 103 | { | ||
| 104 | 2 | result_t res = gate_stream_copier_run(&this->config, this->input_stream.c_impl(), this->output_stream.c_impl(), &this->result); | |
| 105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_EXCEPTION(res); |
| 106 | 2 | } | |
| 107 | 1 | void StreamCopier::cancel() | |
| 108 | { | ||
| 109 | 1 | result_t res = gate_stream_copier_cancel(&this->config); | |
| 110 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 111 | 1 | } | |
| 112 | |||
| 113 | |||
| 114 | 31 | void StreamCopier::onProgress(uint64_t bytesCopied, uint64_t available) | |
| 115 | { | ||
| 116 | GATE_UNUSED_ARG(bytesCopied); | ||
| 117 | GATE_UNUSED_ARG(available); | ||
| 118 | 31 | } | |
| 119 | 2 | void StreamCopier::onCompleted(uint64_t bytesCopied) | |
| 120 | { | ||
| 121 | GATE_UNUSED_ARG(bytesCopied); | ||
| 122 | 2 | } | |
| 123 | ✗ | void StreamCopier::onInputError(result_t errorCode, uint64_t inputPosition, size_t affectedLength, char const* errorMessage) | |
| 124 | { | ||
| 125 | GATE_UNUSED_ARG(errorCode); | ||
| 126 | GATE_UNUSED_ARG(inputPosition); | ||
| 127 | GATE_UNUSED_ARG(affectedLength); | ||
| 128 | GATE_UNUSED_ARG(errorMessage); | ||
| 129 | ✗ | } | |
| 130 | ✗ | void StreamCopier::onOutputError(result_t errorCode, uint64_t outputPosition, size_t affectedLength, char const* errorMessage) | |
| 131 | { | ||
| 132 | GATE_UNUSED_ARG(errorCode); | ||
| 133 | GATE_UNUSED_ARG(outputPosition); | ||
| 134 | GATE_UNUSED_ARG(affectedLength); | ||
| 135 | GATE_UNUSED_ARG(errorMessage); | ||
| 136 | ✗ | } | |
| 137 | |||
| 138 | 33 | void StreamCopier::callback(int status, gate_uint64_t position, gate_uint64_t total_bytes_copied, | |
| 139 | gate_result_t result, char const* message, | ||
| 140 | gate_stream_copier_config_t const* config) | ||
| 141 | { | ||
| 142 | 33 | StreamCopier* copier = static_cast<StreamCopier*>(config->user_param); | |
| 143 |
1/2✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 | if (copier) |
| 144 | { | ||
| 145 |
6/19✓ Branch 0 taken 31 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 24 times.
✓ Branch 8 taken 31 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
|
33 | GATEXX_TRY_IGNORE({ |
| 146 | switch (status) | ||
| 147 | { | ||
| 148 | case GATE_STREAM_COPIER_STATUS_PROGRESS: | ||
| 149 | { | ||
| 150 | uint64_t available = 0; | ||
| 151 | if (config->total_available > (gate_int64_t)total_bytes_copied) | ||
| 152 | { | ||
| 153 | available = (gate_uint64_t)(config->total_available - (gate_int64_t)total_bytes_copied); | ||
| 154 | } | ||
| 155 | copier->onProgress(total_bytes_copied, available); | ||
| 156 | break; | ||
| 157 | } | ||
| 158 | case GATE_STREAM_COPIER_STATUS_COMPLETED: | ||
| 159 | { | ||
| 160 | copier->onCompleted(total_bytes_copied); | ||
| 161 | break; | ||
| 162 | } | ||
| 163 | case GATE_STREAM_COPIER_STATUS_INPUTERROR: | ||
| 164 | { | ||
| 165 | copier->onInputError(result, position, config ? config->block_size : 0, message); | ||
| 166 | break; | ||
| 167 | } | ||
| 168 | case GATE_STREAM_COPIER_STATUS_OUTPUTERROR: | ||
| 169 | { | ||
| 170 | copier->onOutputError(result, position, config ? config->block_size : 0, message); | ||
| 171 | break; | ||
| 172 | } | ||
| 173 | } | ||
| 174 | }); | ||
| 175 | } | ||
| 176 | 33 | } | |
| 177 | |||
| 178 | } // end of namespace tech | ||
| 179 | } // end of namespace gate | ||
| 180 |