F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Chunk.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Chunk.hpp
3 // \brief CFDP chunks (spare gap tracking) header file
4 //
5 // This file is a port of CFDP chunk/gap tracking from the following files
6 // from the NASA Core Flight System (cFS) CFDP (CF) Application, version 3.0.0,
7 // adapted for use within the F-Prime (F') framework:
8 // - cf_chunks.h (CFDP chunk and gap tracking definitions)
9 //
10 // ======================================================================
11 //
12 // NASA Docket No. GSC-18,447-1
13 //
14 // Copyright (c) 2019 United States Government as represented by the
15 // Administrator of the National Aeronautics and Space Administration.
16 // All Rights Reserved.
17 //
18 // Licensed under the Apache License, Version 2.0 (the "License"); you may
19 // not use this file except in compliance with the License. You may obtain
20 // a copy of the License at
21 //
22 // http://www.apache.org/licenses/LICENSE-2.0
23 //
24 // Unless required by applicable law or agreed to in writing, software
25 // distributed under the License is distributed on an "AS IS" BASIS,
26 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 // See the License for the specific language governing permissions and
28 // limitations under the License.
29 //
30 // ======================================================================
31 
32 #ifndef CFDP_CHUNK_HPP
33 #define CFDP_CHUNK_HPP
34 
35 #include <Fw/FPrimeBasicTypes.hpp>
36 
39 
40 namespace Svc {
41 namespace Ccsds {
42 namespace Cfdp {
43 
44 using ChunkIdx = U16;
45 
49 struct Chunk {
52 };
53 
61 static inline FileSize CfdpChunkMax(FileSize a, FileSize b) {
62  if (a > b) {
63  return a;
64  } else {
65  return b;
66  }
67 }
68 
75 using GapComputeCallback = void (*)(const Chunk* chunk, void* opaque);
76 
91  public:
92  // ----------------------------------------------------------------------
93  // Construction and Destruction
94  // ----------------------------------------------------------------------
95 
104  CfdpChunkList(ChunkIdx maxChunks, Chunk* chunkMem);
105 
106  // ----------------------------------------------------------------------
107  // Public Interface
108  // ----------------------------------------------------------------------
109 
120  void add(FileSize offset, FileSize size);
121 
129  void reset();
130 
140  const Chunk* getFirstChunk() const;
141 
153  void removeFromFirst(FileSize size);
154 
170  U32 computeGaps(ChunkIdx maxGaps, FileSize total, FileSize start, GapComputeCallback callback, void* opaque) const;
171 
176  ChunkIdx getCount() const { return m_count; }
177 
182  ChunkIdx getMaxChunks() const { return m_maxChunks; }
183 
184  private:
185  // ----------------------------------------------------------------------
186  // Private Implementation
187  // ----------------------------------------------------------------------
188 
198  void insertChunk(ChunkIdx index, const Chunk* chunk);
199 
207  void eraseChunk(ChunkIdx index);
208 
218  void eraseRange(ChunkIdx start, ChunkIdx end);
219 
228  ChunkIdx findInsertPosition(const Chunk* chunk);
229 
239  bool combineNext(ChunkIdx i, const Chunk* chunk);
240 
250  bool combinePrevious(ChunkIdx i, const Chunk* chunk);
251 
260  void insert(ChunkIdx i, const Chunk* chunk);
261 
269  ChunkIdx findSmallestSize() const;
270 
271  private:
272  // ----------------------------------------------------------------------
273  // Private Member Variables
274  // ----------------------------------------------------------------------
275 
276  ChunkIdx m_count;
277  ChunkIdx m_maxChunks;
278  Chunk* m_chunks;
279 };
280 
281 } // namespace Cfdp
282 } // namespace Ccsds
283 } // namespace Svc
284 
285 #endif /* !CFDP_CHUNK_HPP */
void removeFromFirst(FileSize size)
Remove a specified size from the first chunk.
Definition: Chunk.cpp:79
void reset()
Reset the chunk list to empty state.
Definition: Chunk.cpp:58
C++ class encapsulation of CFDP chunk list operations.
Definition: Chunk.hpp:90
FileSize size
The size of the chunk.
Definition: Chunk.hpp:51
void add(FileSize offset, FileSize size)
Add a chunk (file segment) to the list.
Definition: Chunk.cpp:63
FileSize offset
The start offset of the chunk within the file.
Definition: Chunk.hpp:50
U32 FileSize
File size and offset type.
void(*)(const Chunk *chunk, void *opaque) GapComputeCallback
Callback type for gap computation.
Definition: Chunk.hpp:75
CfdpChunkList(ChunkIdx maxChunks, Chunk *chunkMem)
Constructor - initializes chunk list with pre-allocated memory.
Definition: Chunk.cpp:51
RateGroupDivider component implementation.
ChunkIdx getMaxChunks() const
Get the maximum number of chunks this list can hold.
Definition: Chunk.hpp:182
const Chunk * getFirstChunk() const
Get the first chunk in the list.
Definition: Chunk.cpp:75
static FileSize CfdpChunkMax(FileSize a, FileSize b)
Selects the larger of the two passed-in offsets.
Definition: Chunk.hpp:61
ChunkIdx getCount() const
Get the current number of chunks in the list.
Definition: Chunk.hpp:176
U32 computeGaps(ChunkIdx maxGaps, FileSize total, FileSize start, GapComputeCallback callback, void *opaque) const
Compute gaps between chunks and invoke callback for each.
Definition: Chunk.cpp:94
Pairs an offset with a size to identify a specific piece of a file.
Definition: Chunk.hpp:49