• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The Pigweed Authors
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 #pragma once
15 
16 #include "pw_assert/assert.h"
17 #include "pw_containers/intrusive_list.h"
18 #include "pw_result/result.h"
19 #include "pw_rpc/raw/server_reader_writer.h"
20 #include "pw_transfer/handler.h"
21 #include "pw_transfer/internal/context.h"
22 
23 namespace pw::transfer::internal {
24 
25 // Transfer context for use within the transfer service (server-side). Stores a
26 // pointer to a transfer handler when active to stream the transfer data.
27 class ServerContext final : public Context {
28  public:
ServerContext()29   constexpr ServerContext() : handler_(nullptr) {}
30 
31   // Sets the handler. The handler isn't set by Context::Initialize() since
32   // ClientContexts don't track it.
set_handler(Handler & handler)33   void set_handler(Handler& handler) { handler_ = &handler; }
34 
35  private:
36   // Ends the transfer with the given status, calling the handler's Finalize
37   // method. No chunks are sent.
38   //
39   // Returns DATA_LOSS if the finalize call fails.
40   //
41   // Precondition: Transfer context is active.
42   Status FinalCleanup(Status status) override;
43 
44   Handler* handler_;
45 };
46 
47 }  // namespace pw::transfer::internal
48