ngscopeclient v0.3
Loading...
Searching...
No Matches
PacketManager.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* ngscopeclient *
4* *
5* Copyright (c) 2012-2026 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
66 RowData(TimePoint t, const Marker& m)
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(const std::string& str, size_t& i);
101
103
104 bool Validate(const std::vector<std::string>& headers);
105
106 std::string Evaluate(const Packet* pack);
107
108 static std::string EatSpaces(const 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(const std::string& str, size_t& i);
134 ProtocolDisplayFilter& operator=(const ProtocolDisplayFilter&) =delete;
135 virtual ~ProtocolDisplayFilter();
136
137 static void EatSpaces(const std::string& str, size_t& i);
138
139 bool Validate(const 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:
156 virtual ~PacketManager();
157
158 void Update();
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 {
172 if(m_filterExpression == nullptr)
173 return m_packets;
174 else
175 return m_filteredPackets;
176 }
177
178 const std::map<Packet*, std::vector<Packet*> >& GetFilteredChildPackets()
179 {
180 if(m_filterExpression == nullptr)
181 return m_childPackets;
182 else
184 }
185
186 const std::vector<Packet*>& GetFilteredChildPackets(Packet* pack)
187 {
188 if(m_filterExpression == nullptr)
189 return m_childPackets[pack];
190 else
192 }
193
197 void SetDisplayFilter(std::shared_ptr<ProtocolDisplayFilter> filter)
198 {
201 }
202
203 void FilterPackets();
204
205 bool IsChildOpen(Packet* pack)
206 { return m_lastChildOpen[pack]; }
207
208 void SetChildOpen(Packet* pack, bool open)
210
211 std::vector<RowData>& GetRows()
212 {
214 return m_rows;
215 }
216
217 void OnMarkerChanged();
218
223 {
224 std::lock_guard<std::recursive_mutex> lock(m_mutex);
226 {
227 LogTrace("Refreshing rows for %s due to pending changes\n", m_filter->GetDisplayName().c_str());
228 RefreshRows();
229 }
230 }
231
232protected:
233 void RemoveChildHistoryFrom(Packet* pack);
234
237
239 std::recursive_mutex m_mutex;
240
243
245 std::map<TimePoint, std::vector<Packet*> > m_packets;
246
248 std::map<Packet*, std::vector<Packet*> > m_childPackets;
249
251 std::map<TimePoint, std::vector<Packet*> > m_filteredPackets;
252
254 std::map<Packet*, std::vector<Packet*> > m_filteredChildPackets;
255
258
260 std::shared_ptr<ProtocolDisplayFilter> m_filterExpression;
261
263 void RefreshRows();
264
266 std::vector<RowData> m_rows;
267
269 std::map<Packet*, bool> m_lastChildOpen;
270
273};
274
275#endif
Declaration of Marker.
Declaration of TextureManager.
Definition AcceleratorBuffer.h:204
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:88
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:242
std::map< Packet *, bool > m_lastChildOpen
Map of packets to child-open flags from last frame.
Definition PacketManager.h:269
void RefreshRows()
Update the list of rows being displayed.
Definition PacketManager.cpp:74
void Update()
Handle newly arrived waveform data (may be a change to parameters or a freshly arrived waveform)
Definition PacketManager.cpp:217
void RefreshIfPending()
Refresh the list of pending packets.
Definition PacketManager.h:222
void FilterPackets()
Run the filter expression against the packets.
Definition PacketManager.cpp:305
Session & m_session
Parent session object.
Definition PacketManager.h:236
void SetDisplayFilter(std::shared_ptr< ProtocolDisplayFilter > filter)
Sets the current filter expression.
Definition PacketManager.h:197
std::map< Packet *, std::vector< Packet * > > m_childPackets
Merged child packets.
Definition PacketManager.h:248
std::recursive_mutex m_mutex
Mutex controlling access to m_packets.
Definition PacketManager.h:239
std::map< TimePoint, std::vector< Packet * > > m_packets
Our saved packet data.
Definition PacketManager.h:245
std::shared_ptr< ProtocolDisplayFilter > m_filterExpression
Current filter expression.
Definition PacketManager.h:260
bool m_refreshPending
True if we have a refresh pending before we can render (i.e. pending deletion or similar)
Definition PacketManager.h:272
void RemoveHistoryFrom(TimePoint timestamp)
Removes all history from the specified timestamp.
Definition PacketManager.cpp:362
std::map< Packet *, std::vector< Packet * > > m_filteredChildPackets
Subset of m_filteredChildPackets that passed the current filter expression.
Definition PacketManager.h:254
std::map< TimePoint, std::vector< Packet * > > m_filteredPackets
Subset of m_packets that passed the current filter expression.
Definition PacketManager.h:251
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:266
WaveformCacheKey m_cachekey
Cache key for the current waveform.
Definition PacketManager.h:257
Definition PacketDecoder.h:40
Definition PacketManager.h:96
static std::string EatSpaces(const std::string &str)
Returns a copy of the input string with spaces removed.
Definition PacketManager.cpp:680
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:126
A timestamp, measured in seconds + femtoseconds.
Definition Marker.h:42
Describes a particular revision of a waveform.
Definition Filter.h:62