GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tech/cxx_copymachines.cpp
Date: 2025-09-14 13:10:38
Exec Total Coverage
Lines: 0 74 0.0%
Functions: 0 21 0.0%
Branches: 0 25 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, 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 StreamCopier::StreamCopier(Stream& input, Stream& output)
37 : input_stream(input), output_stream(output)
38 {
39 gate_stream_copier_init(&this->config, this);
40 this->config.callback = &StreamCopier::callback;
41 Mem::clear(this->result);
42 }
43 StreamCopier::~StreamCopier() noexcept
44 {
45
46 }
47
48 uint64_t StreamCopier::getReadOffset() const
49 {
50 return this->config.read_offset;
51 }
52 uint64_t StreamCopier::getWriteOffset() const
53 {
54 return this->config.write_offset;
55 }
56 size_t StreamCopier::getBlockSize() const
57 {
58 return this->config.block_size;
59 }
60 uint64_t StreamCopier::getCopyLimit() const
61 {
62 return this->config.copy_limit;
63 }
64 bool_t StreamCopier::getContinueOnReadErrors() const
65 {
66 return this->config.continue_on_read_errors;
67 }
68 bool_t StreamCopier::getContinueOnWriteErrors() const
69 {
70 return this->config.continue_on_write_errors;
71 }
72
73 void StreamCopier::setReadOffset(uint64_t readOffset)
74 {
75 this->config.read_offset = readOffset;
76 }
77 void StreamCopier::setWriteOffset(uint64_t writeOffset)
78 {
79 this->config.write_offset = writeOffset;
80 }
81 void StreamCopier::setBlockSize(size_t blockSize)
82 {
83 this->config.block_size = blockSize;
84 }
85 void StreamCopier::setCopyLimit(uint64_t copyLimit)
86 {
87 this->config.copy_limit = copyLimit;
88 }
89 void StreamCopier::setContinueOnReadErrors(bool_t enabled)
90 {
91 this->config.continue_on_read_errors = enabled;
92 }
93 void StreamCopier::setContinueOnWriteErrors(bool_t enabled)
94 {
95 this->config.continue_on_write_errors = enabled;
96 }
97
98
99
100 void StreamCopier::run()
101 {
102 gate_stream_copier_run(&this->config, this->input_stream.c_impl(), this->output_stream.c_impl(), &this->result);
103 }
104 void StreamCopier::cancel()
105 {
106 result_t res = gate_stream_copier_cancel(&this->config);
107 GATEXX_CHECK_EXCEPTION(res);
108 }
109
110
111 void StreamCopier::onProgress(uint64_t bytesCopied, uint64_t available)
112 {
113 GATE_UNUSED_ARG(bytesCopied);
114 GATE_UNUSED_ARG(available);
115 }
116 void StreamCopier::onCompleted(uint64_t bytesCopied)
117 {
118 GATE_UNUSED_ARG(bytesCopied);
119 }
120 void StreamCopier::onInputError(result_t errorCode, uint64_t inputPosition, size_t affectedLength, char const* errorMessage)
121 {
122 GATE_UNUSED_ARG(errorCode);
123 GATE_UNUSED_ARG(inputPosition);
124 GATE_UNUSED_ARG(affectedLength);
125 GATE_UNUSED_ARG(errorMessage);
126 }
127 void StreamCopier::onOutputError(result_t errorCode, uint64_t outputPosition, size_t affectedLength, char const* errorMessage)
128 {
129 GATE_UNUSED_ARG(errorCode);
130 GATE_UNUSED_ARG(outputPosition);
131 GATE_UNUSED_ARG(affectedLength);
132 GATE_UNUSED_ARG(errorMessage);
133 }
134
135 void StreamCopier::callback(int status, gate_uint64_t position, gate_uint64_t total_bytes_copied,
136 gate_result_t result, char const* message,
137 gate_stream_copier_config_t const* config)
138 {
139 StreamCopier* copier = static_cast<StreamCopier*>(config->user_param);
140 if (copier)
141 {
142 try
143 {
144 switch (status)
145 {
146 case GATE_STREAM_COPIER_STATUS_PROGRESS:
147 {
148 uint64_t available = 0;
149 if (config->total_available > (gate_int64_t)total_bytes_copied)
150 {
151 available = (gate_uint64_t)(config->total_available - (gate_int64_t)total_bytes_copied);
152 }
153 copier->onProgress(total_bytes_copied, available);
154 break;
155 }
156
157 case GATE_STREAM_COPIER_STATUS_COMPLETED:
158 {
159 copier->onCompleted(total_bytes_copied);
160 break;
161 }
162 case GATE_STREAM_COPIER_STATUS_INPUTERROR:
163 {
164 copier->onInputError(result, position, config ? config->block_size : 0, message);
165 break;
166 }
167 case GATE_STREAM_COPIER_STATUS_OUTPUTERROR:
168 {
169 copier->onOutputError(result, position, config ? config->block_size : 0, message);
170 break;
171 }
172 }
173 }
174 catch (...)
175 {
176 }
177 }
178 }
179
180 } // end of namespace tech
181 } // end of namespace gate
182