• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 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_persistent_ram/flat_file_system_entry.h"
17 #include "pw_system/config.h"
18 #include "pw_system/transfer_handlers.h"
19 
20 namespace pw::system {
21 
22 class FileManager {
23  public:
24   // Each transfer handler ID corresponds 1:1 with a transfer handler and
25   // filesystem element pair.  The ID must be unique and increment from 0 to
26   // ensure no gaps in the FileManager handler & filesystem arrays.
27   // NOTE: the enumerators should never have values defined, to ensure they
28   // increment from zero and kNumFileSystemEntries is correct
29   enum TransferHandlerId : uint32_t {
30 #if PW_SYSTEM_ENABLE_TRACE_SERVICE
31     kTraceTransferHandlerId,
32 #endif
33     kNumFileSystemEntries
34   };
35 
36   FileManager();
37 
GetTransferHandlers()38   std::array<transfer::Handler*, kNumFileSystemEntries>& GetTransferHandlers() {
39     return transfer_handlers_;
40   }
41   std::array<file::FlatFileSystemService::Entry*, kNumFileSystemEntries>&
GetFileSystemEntries()42   GetFileSystemEntries() {
43     return file_system_entries_;
44   }
45 
46  private:
47 #if PW_SYSTEM_ENABLE_TRACE_SERVICE
48   TracePersistentBufferTransfer trace_data_handler_;
49   persistent_ram::FlatFileSystemPersistentBufferEntry<
50       PW_TRACE_BUFFER_SIZE_BYTES>
51       trace_data_filesystem_entry_;
52 #endif
53 
54   std::array<transfer::Handler*, kNumFileSystemEntries> transfer_handlers_;
55   std::array<file::FlatFileSystemService::Entry*, kNumFileSystemEntries>
56       file_system_entries_;
57 };
58 
59 FileManager& GetFileManager();
60 
61 }  // namespace pw::system
62