F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Clist.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Clist.hpp
3 // \brief CFDP circular list header file
4 //
5 // This file is a port of CFDP circular list 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_clist.h (CFDP circular list data structure 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_CLIST_HPP
33 #define CFDP_CLIST_HPP
34 
35 #include <Fw/Types/BasicTypes.hpp>
36 #include <cstddef>
37 
38 namespace Svc {
39 namespace Ccsds {
40 namespace Cfdp {
41 
48 };
49 
52 
55 
60  return (stat == CLIST_TRAVERSE_CONTINUE);
61 }
62 
66 struct CListNode {
67  struct CListNode* next;
68  struct CListNode* prev;
69 };
70 
78 template <typename Container, typename Member>
79 constexpr Container* container_of_cpp(Member* member_ptr, Member Container::* member) {
80  // reinterpret_cast: Required for intrusive list node-to-parent pointer arithmetic (container_of idiom)
81  return reinterpret_cast<Container*>(reinterpret_cast<U8*>(member_ptr) -
82  reinterpret_cast<std::ptrdiff_t>(&(reinterpret_cast<Container*>(0)->*member)));
83 }
84 
96 
104 
105 /************************************************************************/
110 void CfdpCListInitNode(CListNode* node);
111 
112 /************************************************************************/
118 void CfdpCListInsertFront(CListNode** head, CListNode* node);
119 
120 /************************************************************************/
126 void CfdpCListInsertBack(CListNode** head, CListNode* node);
127 
128 /************************************************************************/
134 void CfdpCListRemove(CListNode** head, CListNode* node);
135 
136 /************************************************************************/
145 
146 /************************************************************************/
153 void CfdpCListInsertAfter(CListNode** head, CListNode* start, CListNode* after);
154 
155 /************************************************************************/
165 void CfdpCListTraverse(CListNode* start, CListFunc fn, void* context);
166 
167 /************************************************************************/
176 void CfdpCListTraverseR(CListNode* end, CListFunc fn, void* context);
177 
178 } // namespace Cfdp
179 } // namespace Ccsds
180 } // namespace Svc
181 
182 #endif /* !CFDP_CLIST_HPP */
struct CListNode * prev
Pointer to previous node.
Definition: Clist.hpp:68
CListTraverseStatus
Traverse status for circular list operations.
Definition: Clist.hpp:45
void CfdpCListInsertAfter(CListNode **head, CListNode *start, CListNode *after)
Insert the given node into the last after the given start node.
Definition: Clist.cpp:125
constexpr U8 CFDP_CLIST_EXIT
Constant indicating to stop traversal.
Definition: Clist.hpp:54
Continue traversing the list.
Definition: Clist.hpp:46
CListTraverseStatus(*)(CListNode *, void *) CListTraverseCallback
Callback type for list traversal.
Definition: Clist.hpp:103
struct CListNode * next
Pointer to next node.
Definition: Clist.hpp:67
Stop traversing the list.
Definition: Clist.hpp:47
void CfdpCListInsertFront(CListNode **head, CListNode *node)
Insert the given node into the front of a list.
Definition: Clist.cpp:48
CListTraverseStatus(*)(CListNode *, void *) CListFunc
Callback function type for use with CfdpCListTraverse()
Definition: Clist.hpp:95
void CfdpCListTraverse(CListNode *start, CListFunc fn, void *context)
Traverse the entire list, calling the given function on all nodes.
Definition: Clist.cpp:139
CListNode * CfdpCListPop(CListNode **head)
Remove the first node from a list and return it.
Definition: Clist.cpp:89
void CfdpCListInsertBack(CListNode **head, CListNode *node)
Insert the given node into the back of a list.
Definition: Clist.cpp:69
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
constexpr U8 CFDP_CLIST_CONT
Constant indicating to continue traversal.
Definition: Clist.hpp:51
static bool CfdpCListTraverseStatusIsContinue(CListTraverseStatus stat)
Definition: Clist.hpp:59
constexpr Container * container_of_cpp(Member *member_ptr, Member Container::*member)
Obtains a pointer to the parent structure.
Definition: Clist.hpp:79
void CfdpCListRemove(CListNode **head, CListNode *node)
Remove the given node from the list.
Definition: Clist.cpp:102
C++ header for working with basic fprime types.
Circular linked list node structure.
Definition: Clist.hpp:66
RateGroupDivider component implementation.
void CfdpCListTraverseR(CListNode *end, CListFunc fn, void *context)
Reverse list traversal, starting from end, calling given function on all nodes.
Definition: Clist.cpp:173
void CfdpCListInitNode(CListNode *node)
Initialize a clist node.
Definition: Clist.cpp:43