blob: 142ecb364128ae4b1eccdc95d14d4929755af803 [file] [log] [blame]
Alexei Frolov22ee1142022-02-03 13:59:01 -08001// Copyright 2022 The Pigweed Authors
Alexei Frolovf93cb262021-07-14 16:05:15 -07002//
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 Frolovd71f4f62021-11-04 14:58:54 -070020#include "pw_transfer/internal/chunk.h"
Alexei Frolovf93cb262021-07-14 16:05:15 -070021
22namespace pw::transfer {
Alexei Frolovf93cb262021-07-14 16:05:15 -070023
Wyatt Hepler6a3c0632021-09-30 14:40:23 -070024void TransferService::HandleChunk(ConstByteSpan message,
Wyatt Heplere6209d92021-10-01 08:24:33 -070025 internal::TransferType type) {
Wyatt Hepler6a3c0632021-09-30 14:40:23 -070026 internal::Chunk chunk;
Wyatt Hepler6a3c0632021-09-30 14:40:23 -070027 if (Status status = internal::DecodeChunk(message, chunk); !status.ok()) {
Alexei Frolov22ee1142022-02-03 13:59:01 -080028 PW_LOG_ERROR("Failed to decode transfer chunk: %d", status.code());
Alexei Frolovf93cb262021-07-14 16:05:15 -070029 return;
30 }
31
Alexei Frolov22ee1142022-02-03 13:59:01 -080032 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 Frolovf93cb262021-07-14 16:05:15 -070041 }
42
Alexei Frolov22ee1142022-02-03 13:59:01 -080043 thread_.ProcessServerChunk(message);
Alexei Frolov563946f2021-08-05 18:58:48 -070044}
45
Alexei Frolovf93cb262021-07-14 16:05:15 -070046} // namespace pw::transfer