ngscopeclient v0.1
PacketManager.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
35#ifndef PacketManager_h
36#define PacketManager_h
37
38#include "../../lib/scopehal/PacketDecoder.h"
39#include "Marker.h"
40#include "TextureManager.h"
41
42class Session;
43
48{
49public:
50 RowData()
51 : m_height(0)
52 , m_totalHeight(0)
53 , m_stamp(0, 0)
54 , m_packet(nullptr)
55 , m_marker(TimePoint(0,0), 0, "")
56 {}
57
59 : m_height(0)
60 , m_totalHeight(0)
61 , m_stamp(t)
62 , m_packet(p)
63 , m_marker(t, 0, "")
64 {}
65
67 : m_height(0)
68 , m_totalHeight(0)
69 , m_stamp(t)
70 , m_packet(nullptr)
71 , m_marker(m)
72 {}
73
75 double m_height;
76
79
82
85
88
90 std::shared_ptr<Texture> m_texture;
91};
92
94
96{
97public:
98 ProtocolDisplayFilterClause(std::string str, size_t& i);
101
103
104 bool Validate(std::vector<std::string> headers);
105
106 std::string Evaluate(const Packet* pack);
107
108 static std::string EatSpaces(std::string str);
109
110 enum
111 {
112 TYPE_DATA,
113 TYPE_IDENTIFIER,
114 TYPE_STRING,
115 TYPE_REAL,
116 TYPE_INT,
117 TYPE_EXPRESSION,
118 TYPE_ERROR
119 } m_type;
120
121 std::string m_identifier;
122 std::string m_string;
123 float m_real;
124 long m_long;
125 ProtocolDisplayFilter* m_expression;
126 bool m_invert;
127};
128
130{
131public:
132 ProtocolDisplayFilter(std::string str, size_t& i);
134 ProtocolDisplayFilter& operator=(const ProtocolDisplayFilter&) =delete;
135 virtual ~ProtocolDisplayFilter();
136
137 static void EatSpaces(std::string str, size_t& i);
138
139 bool Validate(std::vector<std::string> headers, bool nakedLiteralOK = false);
140
141 bool Match(const Packet* pack);
142 std::string Evaluate(const Packet* pack);
143
144protected:
145 std::vector<ProtocolDisplayFilterClause*> m_clauses;
146 std::vector<std::string> m_operators;
147};
148
153{
154public:
155 PacketManager(PacketDecoder* pd, Session& session);
156 virtual ~PacketManager();
157
158 void Update();
159 void RemoveHistoryFrom(TimePoint timestamp);
160
161 std::recursive_mutex& GetMutex()
162 { return m_mutex; }
163
164 const std::map<TimePoint, std::vector<Packet*> >& GetPackets()
165 { return m_packets; }
166
167 const std::vector<Packet*>& GetChildPackets(Packet* pack)
168 { return m_childPackets[pack]; }
169
170 const std::map<TimePoint, std::vector<Packet*> >& GetFilteredPackets()
171 { return m_filteredPackets; }
172
173 const std::vector<Packet*>& GetFilteredChildPackets(Packet* pack)
174 { return m_filteredChildPackets[pack]; }
175
179 void SetDisplayFilter(std::shared_ptr<ProtocolDisplayFilter> filter)
180 {
181 m_filterExpression = filter;
183 }
184
185 void FilterPackets();
186
187 bool IsChildOpen(Packet* pack)
188 { return m_lastChildOpen[pack]; }
189
190 void SetChildOpen(Packet* pack, bool open)
191 { m_lastChildOpen[pack] = open; }
192
193 std::vector<RowData>& GetRows()
194 {
196 return m_rows;
197 }
198
199 void OnMarkerChanged();
200
205 {
206 std::lock_guard<std::recursive_mutex> lock(m_mutex);
208 {
209 LogTrace("Refreshing rows for %s due to pending changes\n", m_filter->GetDisplayName().c_str());
210 RefreshRows();
211 }
212 }
213
214protected:
215 void RemoveChildHistoryFrom(Packet* pack);
216
219
221 std::recursive_mutex m_mutex;
222
225
227 std::map<TimePoint, std::vector<Packet*> > m_packets;
228
230 std::map<Packet*, std::vector<Packet*> > m_childPackets;
231
233 std::map<TimePoint, std::vector<Packet*> > m_filteredPackets;
234
236 std::map<Packet*, std::vector<Packet*> > m_filteredChildPackets;
237
240
242 std::shared_ptr<ProtocolDisplayFilter> m_filterExpression;
243
245 void RefreshRows();
246
248 std::vector<RowData> m_rows;
249
251 std::map<Packet*, bool> m_lastChildOpen;
252
255};
256
257#endif
Declaration of Marker.
Declaration of TextureManager.
Data for a marker.
Definition: Marker.h:85
virtual std::string GetDisplayName() override
Gets the human-readable nickname for this channel, as displayed in the GUI.
Definition: OscilloscopeChannel.cpp:261
Definition: PacketDecoder.h:85
Keeps track of packetized data history from a single protocol analyzer filter.
Definition: PacketManager.h:153
PacketDecoder * m_filter
The filter we're managing.
Definition: PacketManager.h:224
std::map< Packet *, bool > m_lastChildOpen
Map of packets to child-open flags from last frame.
Definition: PacketManager.h:251
void RefreshRows()
Update the list of rows being displayed.
Definition: PacketManager.cpp:71
void Update()
Handle newly arrived waveform data (may be a change to parameters or a freshly arrived waveform)
Definition: PacketManager.cpp:186
void RefreshIfPending()
Refresh the list of pending packets.
Definition: PacketManager.h:204
void FilterPackets()
Run the filter expression against the packets.
Definition: PacketManager.cpp:270
Session & m_session
Parent session object.
Definition: PacketManager.h:218
void SetDisplayFilter(std::shared_ptr< ProtocolDisplayFilter > filter)
Sets the current filter expression.
Definition: PacketManager.h:179
std::map< Packet *, std::vector< Packet * > > m_childPackets
Merged child packets.
Definition: PacketManager.h:230
std::recursive_mutex m_mutex
Mutex controlling access to m_packets.
Definition: PacketManager.h:221
std::map< TimePoint, std::vector< Packet * > > m_packets
Our saved packet data.
Definition: PacketManager.h:227
std::shared_ptr< ProtocolDisplayFilter > m_filterExpression
Current filter expression.
Definition: PacketManager.h:242
bool m_refreshPending
True if we have a refresh pending before we can render (i.e. pending deletion or similar)
Definition: PacketManager.h:254
void RemoveHistoryFrom(TimePoint timestamp)
Removes all history from the specified timestamp.
Definition: PacketManager.cpp:328
std::map< Packet *, std::vector< Packet * > > m_filteredChildPackets
Subset of m_filteredChildPackets that passed the current filter expression.
Definition: PacketManager.h:236
std::map< TimePoint, std::vector< Packet * > > m_filteredPackets
Subset of m_packets that passed the current filter expression.
Definition: PacketManager.h:233
std::vector< RowData > m_rows
The set of rows that are to be displayed, based on current tree expansion and filter state.
Definition: PacketManager.h:248
WaveformCacheKey m_cachekey
Cache key for the current waveform.
Definition: PacketManager.h:239
Definition: PacketDecoder.h:40
Definition: PacketManager.h:96
static std::string EatSpaces(std::string str)
Returns a copy of the input string with spaces removed.
Definition: PacketManager.cpp:640
Definition: PacketManager.h:130
Context data for a single row (used for culling)
Definition: PacketManager.h:48
Marker m_marker
The marker in this row (ignored if m_packet is valid)
Definition: PacketManager.h:87
TimePoint m_stamp
Timestamp of the waveform this packet came from.
Definition: PacketManager.h:81
double m_height
Height of this row.
Definition: PacketManager.h:75
std::shared_ptr< Texture > m_texture
Texture containing the scanline image for this row (only valid if m_packet is a VideoScanlinePacket)
Definition: PacketManager.h:90
Packet * m_packet
The packet in this row (null if m_marker is valid)
Definition: PacketManager.h:84
double m_totalHeight
Total height of the entire list up to this point.
Definition: PacketManager.h:78
A Session stores all of the instrument configuration and other state the user has open.
Definition: Session.h:95
A timestamp, measured in seconds + femtoseconds.
Definition: Marker.h:42
Describes a particular revision of a waveform.
Definition: Filter.h:52