Alexei Frolov | 22ee114 | 2022-02-03 13:59:01 -0800 | [diff] [blame] | 1 | // Copyright 2022 The Pigweed Authors |
Alexei Frolov | f93cb26 | 2021-07-14 16:05:15 -0700 | [diff] [blame] | 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 4 | // use this file except in compliance with the License. You may obtain a copy of |
| 5 | // the License at |
| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | // License for the specific language governing permissions and limitations under |
| 13 | // the License. |
| 14 | |
| 15 | #include "pw_transfer/transfer.h" |
| 16 | |
| 17 | #include "pw_assert/check.h" |
| 18 | #include "pw_log/log.h" |
| 19 | #include "pw_status/try.h" |
Alexei Frolov | d71f4f6 | 2021-11-04 14:58:54 -0700 | [diff] [blame] | 20 | #include "pw_transfer/internal/chunk.h" |
Alexei Frolov | f93cb26 | 2021-07-14 16:05:15 -0700 | [diff] [blame] | 21 | |
| 22 | namespace pw::transfer { |
Alexei Frolov | f93cb26 | 2021-07-14 16:05:15 -0700 | [diff] [blame] | 23 | |
Wyatt Hepler | 6a3c063 | 2021-09-30 14:40:23 -0700 | [diff] [blame] | 24 | void TransferService::HandleChunk(ConstByteSpan message, |
Wyatt Hepler | e6209d9 | 2021-10-01 08:24:33 -0700 | [diff] [blame] | 25 | internal::TransferType type) { |
Wyatt Hepler | 6a3c063 | 2021-09-30 14:40:23 -0700 | [diff] [blame] | 26 | internal::Chunk chunk; |
Wyatt Hepler | 6a3c063 | 2021-09-30 14:40:23 -0700 | [diff] [blame] | 27 | if (Status status = internal::DecodeChunk(message, chunk); !status.ok()) { |
Alexei Frolov | 22ee114 | 2022-02-03 13:59:01 -0800 | [diff] [blame] | 28 | PW_LOG_ERROR("Failed to decode transfer chunk: %d", status.code()); |
Alexei Frolov | f93cb26 | 2021-07-14 16:05:15 -0700 | [diff] [blame] | 29 | return; |
| 30 | } |
| 31 | |
Alexei Frolov | 22ee114 | 2022-02-03 13:59:01 -0800 | [diff] [blame] | 32 | if (chunk.IsInitialChunk()) { |
| 33 | // TODO(frolv): Right now, transfer ID and handler ID are the same thing. |
| 34 | // The transfer ID should be made into a unique session ID instead. |
| 35 | thread_.StartServerTransfer(type, |
| 36 | chunk.transfer_id, |
| 37 | chunk.transfer_id, |
| 38 | max_parameters_, |
| 39 | chunk_timeout_, |
| 40 | max_retries_); |
Alexei Frolov | f93cb26 | 2021-07-14 16:05:15 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Alexei Frolov | 22ee114 | 2022-02-03 13:59:01 -0800 | [diff] [blame] | 43 | thread_.ProcessServerChunk(message); |
Alexei Frolov | 563946f | 2021-08-05 18:58:48 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Alexei Frolov | f93cb26 | 2021-07-14 16:05:15 -0700 | [diff] [blame] | 46 | } // namespace pw::transfer |