WSF
WsfCommQueue.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef WSFCOMMQUEUE_HPP
13#define WSFCOMMQUEUE_HPP
14
15#include "wsf_export.h"
16
17#include <limits>
18#include <list>
19#include <memory>
20#include <vector>
21
22#include "UtCloneablePtr.hpp"
23#include "WsfCommMessage.hpp"
24
25namespace wsf
26{
27namespace comm
28{
29
37{
38public:
40 enum class QueueType : size_t
41 {
42 cFIFO, // First-in-first-out
43 cLIFO, // Last-in-last-out
44 cPRIORITY // Assigned priority queue
45 };
46
47 class Entry
48 {
49 public:
51 enum class EntryStatus : size_t
52 {
53 cQUEUED, // Initial push to queue. No other action taken.
54 cPROCESSED, // Popped. Awaiting feedback. Ignored during subsequent pops.
55 cREPROCESSED // A special status similar to cPROCESSED. For datalink layer usage,
56 // indicates a message is scheduled for retransmission, but not eligible
57 // for typical queue processing.
58 };
59
60 Entry() = default;
61 virtual ~Entry() = default;
62 Entry(const Entry& aSrc) = default;
63
64 bool operator==(const Entry& aRhs) const;
65 Entry& operator=(const Entry& aRhs) = default;
66
67 double GetQueueTime() const { return mQueueTime; }
68 void SetQueueTime(double aSimTime) { mQueueTime = aSimTime; }
69 Message* GetMessage() const { return mMessage.get(); }
70 void SetMessage(Message* aMessagePtr);
71 EntryStatus GetStatus() const { return mStatus; }
72 void SetStatus(EntryStatus aStatus) { mStatus = aStatus; }
73
74 size_t GetCounter() const { return mCounter; }
75 void SetCounter(size_t aCount) { mCounter = aCount; }
76 void IncrementCounter() { ++mCounter; }
77 void DecrementCounter() { --mCounter; }
78 void ResetCounter() { mCounter = 0; }
79
80 private:
81 double mQueueTime{0.0};
82 ut::CloneablePtr<Message> mMessage{nullptr};
83 size_t mCounter{0};
84 EntryStatus mStatus{EntryStatus::cQUEUED};
85 };
86
87 Queue() = default;
88 virtual ~Queue() = default;
89
90 bool Push(const Entry& aEntry);
91
96 void Pop();
97
100 const Entry& Top() const;
101
102 const Entry* Peek(const Message::Identifier& aIdentifier) const;
103 Entry* Peek(const Message::Identifier& aIdentifier);
104
106 size_t Size() const { return mQueue.size(); }
107
110 size_t SizeActiveEntries() const;
111
113 bool Empty() const { return mQueue.empty(); }
114
117 bool EmptyActiveEntries() const;
118
119 QueueType GetQueueType() const { return mQueueType; }
120 void SetQueueType(QueueType aType) { mQueueType = aType; }
121
123
124 size_t GetLimit() const { return mLimit; }
125 void SetLimit(size_t aLimit) { mLimit = aLimit; }
127
128 std::vector<Entry> Remove(double aTime);
129
133
134
137 bool EntryProcessed(const Message::Identifier& aIdentifier);
138
142 bool EntryReprocessed(double aSimTime, const Message::Identifier& aIdentifier);
143
146 bool EntryDropped(const Message::Identifier& aIdentifier);
148
149private:
150 QueueType mQueueType{QueueType::cFIFO};
151 size_t mLimit{std::numeric_limits<size_t>::max()};
152 std::list<Entry> mQueue{};
153};
154
155} // namespace comm
156} // namespace wsf
157
158#endif
bool operator==(int aId, const WsfStringInt &aRhs)
Equal relational operator for the case of an integer on the LHS and a StringId on the RHS.
Definition WsfStringId.hpp:69
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Definition WsfCommMessage.hpp:95
Definition WsfCommMessage.hpp:51
Definition WsfCommQueue.hpp:48
void SetCounter(size_t aCount)
Definition WsfCommQueue.hpp:75
virtual ~Entry()=default
void SetQueueTime(double aSimTime)
Definition WsfCommQueue.hpp:68
double GetQueueTime() const
Definition WsfCommQueue.hpp:67
Message * GetMessage() const
Definition WsfCommQueue.hpp:69
size_t GetCounter() const
Definition WsfCommQueue.hpp:74
Entry & operator=(const Entry &aRhs)=default
EntryStatus GetStatus() const
Definition WsfCommQueue.hpp:71
void DecrementCounter()
Definition WsfCommQueue.hpp:77
EntryStatus
Entry States.
Definition WsfCommQueue.hpp:52
void SetStatus(EntryStatus aStatus)
Definition WsfCommQueue.hpp:72
Entry(const Entry &aSrc)=default
void ResetCounter()
Definition WsfCommQueue.hpp:78
void IncrementCounter()
Definition WsfCommQueue.hpp:76
virtual ~Queue()=default
void Pop()
Definition WsfCommQueue.cpp:63
const Entry & Top() const
Definition WsfCommQueue.cpp:127
size_t GetLimit() const
Limits apply to all entries, regardless of status.
Definition WsfCommQueue.hpp:124
QueueType
Queue Types.
Definition WsfCommQueue.hpp:41
void SetLimit(size_t aLimit)
Definition WsfCommQueue.hpp:125
const Entry * Peek(const Message::Identifier &aIdentifier) const
Definition WsfCommQueue.cpp:191
QueueType GetQueueType() const
Definition WsfCommQueue.hpp:119
size_t Size() const
The number of entries, regardless of status.
Definition WsfCommQueue.hpp:106
bool Empty() const
If the queue is empty, regardless of entry status.
Definition WsfCommQueue.hpp:113
bool Push(const Entry &aEntry)
Definition WsfCommQueue.cpp:40
void SetQueueType(QueueType aType)
Definition WsfCommQueue.hpp:120
Definition WsfComm.cpp:34
Function definitions for those who need run-time access to the version.
Definition WsfComm.cpp:32
Copyrights Multiple, All Rights Reserved