ngscopeclient 0.1-dev+51fbda87c
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
41class Session;
42
47{
48public:
49 RowData()
50 : m_height(0)
51 , m_totalHeight(0)
52 , m_stamp(0, 0)
53 , m_packet(nullptr)
54 , m_marker(TimePoint(0,0), 0, "")
55 {}
56
58 : m_height(0)
59 , m_totalHeight(0)
60 , m_stamp(t)
61 , m_packet(p)
62 , m_marker(t, 0, "")
63 {}
64
66 : m_height(0)
67 , m_totalHeight(0)
68 , m_stamp(t)
69 , m_packet(nullptr)
70 , m_marker(m)
71 {}
72
74 double m_height;
75
78
81
84
87};
88
90
92{
93public:
94 ProtocolDisplayFilterClause(std::string str, size_t& i);
97
99
100 bool Validate(std::vector<std::string> headers);
101
102 std::string Evaluate(const Packet* pack);
103
104 static std::string EatSpaces(std::string str);
105
106 enum
107 {
108 TYPE_DATA,
109 TYPE_IDENTIFIER,
110 TYPE_STRING,
111 TYPE_REAL,
112 TYPE_INT,
113 TYPE_EXPRESSION,
114 TYPE_ERROR
115 } m_type;
116
117 std::string m_identifier;
118 std::string m_string;
119 float m_real;
120 long m_long;
121 ProtocolDisplayFilter* m_expression;
122 bool m_invert;
123};
124
126{
127public:
128 ProtocolDisplayFilter(std::string str, size_t& i);
130 ProtocolDisplayFilter& operator=(const ProtocolDisplayFilter&) =delete;
131 virtual ~ProtocolDisplayFilter();
132
133 static void EatSpaces(std::string str, size_t& i);
134
135 bool Validate(std::vector<std::string> headers, bool nakedLiteralOK = false);
136
137 bool Match(const Packet* pack);
138 std::string Evaluate(const Packet* pack);
139
140protected:
141 std::vector<ProtocolDisplayFilterClause*> m_clauses;
142 std::vector<std::string> m_operators;
143};
144
149{
150public:
151 PacketManager(PacketDecoder* pd, Session& session);
152 virtual ~PacketManager();
153
154 void Update();
155 void RemoveHistoryFrom(TimePoint timestamp);
156
157 std::recursive_mutex& GetMutex()
158 { return m_mutex; }
159
160 const std::map<TimePoint, std::vector<Packet*> >& GetPackets()
161 { return m_packets; }
162
163 const std::vector<Packet*>& GetChildPackets(Packet* pack)
164 { return m_childPackets[pack]; }
165
166 const std::map<TimePoint, std::vector<Packet*> >& GetFilteredPackets()
167 { return m_filteredPackets; }
168
169 const std::vector<Packet*>& GetFilteredChildPackets(Packet* pack)
170 { return m_filteredChildPackets[pack]; }
171
175 void SetDisplayFilter(std::shared_ptr<ProtocolDisplayFilter> filter)
176 {
177 m_filterExpression = filter;
179 }
180
181 void FilterPackets();
182
183 bool IsChildOpen(Packet* pack)
184 { return m_lastChildOpen[pack]; }
185
186 void SetChildOpen(Packet* pack, bool open)
187 { m_lastChildOpen[pack] = open; }
188
189 std::vector<RowData>& GetRows()
190 { return m_rows; }
191
192 void OnMarkerChanged();
193
194protected:
195 void RemoveChildHistoryFrom(Packet* pack);
196
199
201 std::recursive_mutex m_mutex;
202
205
207 std::map<TimePoint, std::vector<Packet*> > m_packets;
208
210 std::map<Packet*, std::vector<Packet*> > m_childPackets;
211
213 std::map<TimePoint, std::vector<Packet*> > m_filteredPackets;
214
216 std::map<Packet*, std::vector<Packet*> > m_filteredChildPackets;
217
220
222 std::shared_ptr<ProtocolDisplayFilter> m_filterExpression;
223
225 void RefreshRows();
226
228 std::vector<RowData> m_rows;
229
231 std::map<Packet*, bool> m_lastChildOpen;
232};
233
234#endif
Declaration of Marker.
Data for a marker.
Definition: Marker.h:84
Definition: PacketDecoder.h:85
Keeps track of packetized data history from a single protocol analyzer filter.
Definition: PacketManager.h:149
PacketDecoder * m_filter
The filter we're managing.
Definition: PacketManager.h:204
std::map< Packet *, bool > m_lastChildOpen
Map of packets to child-open flags from last frame.
Definition: PacketManager.h:231
void RefreshRows()
Update the list of rows being displayed.
Definition: PacketManager.cpp:68
void Update()
Handle newly arrived waveform data (may be a change to parameters or a freshly arrived waveform)
Definition: PacketManager.cpp:169
void FilterPackets()
Run the filter expression against the packets.
Definition: PacketManager.cpp:253
Session & m_session
Parent session object.
Definition: PacketManager.h:198
void SetDisplayFilter(std::shared_ptr< ProtocolDisplayFilter > filter)
Sets the current filter expression.
Definition: PacketManager.h:175
std::map< Packet *, std::vector< Packet * > > m_childPackets
Merged child packets.
Definition: PacketManager.h:210
std::recursive_mutex m_mutex
Mutex controlling access to m_packets.
Definition: PacketManager.h:201
std::map< TimePoint, std::vector< Packet * > > m_packets
Our saved packet data.
Definition: PacketManager.h:207
std::shared_ptr< ProtocolDisplayFilter > m_filterExpression
Current filter expression.
Definition: PacketManager.h:222
void RemoveHistoryFrom(TimePoint timestamp)
Removes all history from the specified timestamp.
Definition: PacketManager.cpp:311
std::map< Packet *, std::vector< Packet * > > m_filteredChildPackets
Subset of m_filteredChildPackets that passed the current filter expression.
Definition: PacketManager.h:216
std::map< TimePoint, std::vector< Packet * > > m_filteredPackets
Subset of m_packets that passed the current filter expression.
Definition: PacketManager.h:213
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:228
WaveformCacheKey m_cachekey
Cache key for the current waveform.
Definition: PacketManager.h:219
Definition: PacketDecoder.h:40
Definition: PacketManager.h:92
static std::string EatSpaces(std::string str)
Returns a copy of the input string with spaces removed.
Definition: PacketManager.cpp:621
Definition: PacketManager.h:126
Context data for a single row (used for culling)
Definition: PacketManager.h:47
Marker m_marker
The marker in this row (ignored if m_packet is valid)
Definition: PacketManager.h:86
TimePoint m_stamp
Timestamp of the waveform this packet came from.
Definition: PacketManager.h:80
double m_height
Height of this row.
Definition: PacketManager.h:74
Packet * m_packet
The packet in this row (null if m_marker is valid)
Definition: PacketManager.h:83
double m_totalHeight
Total height of the entire list up to this point.
Definition: PacketManager.h:77
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