ngscopeclient v0.3
Loading...
Searching...
No Matches
FlowGraphNode.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
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
36#ifndef FlowGraphNode_h
37#define FlowGraphNode_h
38
40class WaveformBase;
42class InputDescriptor;
43class InputConstraint;
44
45#include "FilterParameter.h"
46#include "Waveform.h"
47#include "Stream.h"
48#include "SerializableObject.h"
49#include "log.h"
50
51
59{
60public:
61 FlowGraphNodeMessage(Severity severity, const std::string& title, const std::string& msg)
62 : m_severity(severity), m_title(title), m_message(msg) {}
63 Severity GetSeverity() const { return m_severity; }
64 const std::string& GetTitle() const {return m_title; }
65 const std::string& GetMessage() const {return m_message; }
66private:
67 Severity m_severity;
69 std::string m_title;
71 std::string m_message;
72};
73
81{
82public:
84 virtual ~FlowGraphNode();
85
86 void DetachInputs();
87
88 //Inputs
89public:
90 size_t GetInputCount();
91 std::string GetInputName(size_t i);
92
93 void SetInput(size_t i, StreamDescriptor stream, bool force = false);
94 void SetInput(const std::string& name, StreamDescriptor stream, bool force = false);
95 virtual bool ValidateChannel(size_t i, StreamDescriptor stream);
96
98
100 std::shared_ptr<InputConstraint> GetInputConstraints(size_t i);
101
102protected:
103 virtual void OnInputChanged(size_t i);
104
105 //Parameters
106public:
107 FilterParameter& GetParameter(std::string s);
108
110 typedef std::map<std::string, FilterParameter> ParameterMapType;
111
119 bool HasParameter(std::string s)
120 { return (m_parameters.find(s) != m_parameters.end()); }
121
123 ParameterMapType::iterator GetParamBegin()
124 { return m_parameters.begin(); }
125
127 ParameterMapType::iterator GetParamEnd()
128 { return m_parameters.end(); }
129
132 { return m_parameters.size(); }
133
139 virtual YAML::Node SerializeConfiguration(IDTable& table);
140
144 virtual void LoadParameters(const YAML::Node& node, IDTable& table);
145 virtual void LoadInputs(const YAML::Node& node, IDTable& table);
146
147 bool IsDownstreamOf(std::set<FlowGraphNode*> nodes);
148
150 // Tail call optimization etc
151
152 enum class ExecutionCapabilities
153 {
154 //Nothing special
155 None = 0,
156
157 //Node does not call begin() on the command buffer, executor must do that for us
158 CommandBufferAppend = 1,
159
160 //Node does not call SubmitAndBlock() on the command buffer, executor must do that for us
161 CommandBufferTailCall = 2,
162
163 //Node has essentially zero CPU-side compute, refresh just enqueues stuff
164 VulkanOnly = 4,
165
166 //Node supports dynamic shader generation
167 DynamicShader = 8
168 };
169
172 { return (uint32_t) ExecutionCapabilities::None; }
173
175 // Filter evaluation
176
177 virtual void Refresh(vk::raii::CommandBuffer& cmdBuf, std::shared_ptr<QueueHandle> queue) =0;
178
180 // Error detection and reporting
181public:
182
184 bool HasMessages() const
185 { return not m_messages.empty(); }
186
188 const std::vector<FlowGraphNodeMessage>& GetMessages() const
189 { return m_messages; }
190
191 const FlowGraphNodeMessage* GetMostSevereMessage() const;
192
193 //Input handling helpers
194protected:
195
201 WaveformBase* GetInputWaveform(size_t i); //implementation in FlowGraphNode_inlines.h
202
206
210
214
218
220 //SparseDigitalBusWaveform* GetSparseDigitalBusInputWaveform(size_t i)
221 //{ return dynamic_cast<SparseDigitalBusWaveform*>(GetInputWaveform(i)); }
222
223 virtual void CreateInput(const std::string& name);
224
225 //Helper for creating a stream with constraints
226 template<class T, class... Args>
227 void CreateInput(const std::string& name, Args&&... args);
228
229 std::string GetInputDisplayName(size_t i);
230
231public:
232 //Sink management (used for special stuff that doesn't call SetInput directly)
233 void AddSink(size_t stream, FlowGraphNode* node)
234 { m_sinks[stream].emplace(node); }
235
236 void RemoveSink(size_t stream, FlowGraphNode* node)
237 { m_sinks[stream].erase(node); }
238
239 const std::set<FlowGraphNode*>& GetSinks(size_t stream)
240 { return m_sinks[stream]; }
241
242protected:
243
247 std::vector< std::shared_ptr<InputDescriptor> > m_inputs;
248
254 std::vector< std::set<FlowGraphNode*> > m_sinks;
255
256 //Parameters
257 ParameterMapType m_parameters;
258
259public:
260
261 sigc::signal<void()> signal_parametersChanged()
262 { return m_parametersChangedSignal; }
263
264 sigc::signal<void()> signal_inputsChanged()
265 { return m_inputsChangedSignal; }
266
267protected:
268
271 { m_messages.clear(); }
272
275 { m_messages.push_back(msg); }
276
278 void AddMessage(Severity severity, const std::string& title, const std::string& message)
280
282 void AddErrorMessage(const std::string& err)
283 { AddErrorMessage("Unknown", std::string("• ") + err); }
284
290 void AddErrorMessage(const std::string& title, const std::string& err)
292
295
298
299 //@brief All the messages the Node accumulates
300 std::vector<FlowGraphNodeMessage> m_messages;
301};
302
303#endif
Declaration of FilterParameter.
Declaration of SerializableObject.
Declaration of Stream.
Declaration of WaveformBase, SparseWaveformBase, UniformWaveformBase.
Definition AcceleratorBuffer.h:204
A parameter to a filter.
Definition FilterParameter.h:86
A Message to the user from a node in the signal flow graph.
Definition FlowGraphNode.h:59
Abstract base class for a node in the signal flow graph.
Definition FlowGraphNode.h:81
virtual void CreateInput(const std::string &name)
Gets the digital bus waveform attached to the specified input.
std::shared_ptr< InputConstraint > GetInputConstraints(size_t i)
Get the constraints on one of our inputs.
Definition FlowGraphNode.cpp:255
StreamDescriptor GetInput(size_t i)
Gets the descriptor for one of our inputs.
Definition FlowGraphNode.cpp:241
bool HasParameter(std::string s)
Checks if we have a parameter with a given name.
Definition FlowGraphNode.h:119
ParameterMapType::iterator GetParamEnd()
Returns an iterator to the end of our parameter map.
Definition FlowGraphNode.h:127
ParameterMapType::iterator GetParamBegin()
Returns an iterator to the beginning of our parameter map.
Definition FlowGraphNode.h:123
virtual YAML::Node SerializeConfiguration(IDTable &table)
Serializes this trigger's configuration to a YAML string.
Definition FlowGraphNode.cpp:335
virtual uint32_t GetExecutionCapabilitiesMask()
Returns a bitmask of ExecutionCapabilities fields.
Definition FlowGraphNode.h:171
sigc::signal< void()> m_parametersChangedSignal
Signal emitted when the set of parameters changes.
Definition FlowGraphNode.h:294
void AddMessage(Severity severity, const std::string &title, const std::string &message)
Attach a new message to the node.
Definition FlowGraphNode.h:278
size_t GetInputCount()
Get the number of input ports.
Definition FlowGraphNode_inlines.h:72
const std::vector< FlowGraphNodeMessage > & GetMessages() const
Walking through any messages.
Definition FlowGraphNode.h:188
SparseAnalogWaveform * GetSparseAnalogInputWaveform(size_t i)
Gets the analog waveform attached to the specified input.
Definition FlowGraphNode.h:204
size_t GetParamCount()
Returns the number of parameter we have.
Definition FlowGraphNode.h:131
SparseDigitalWaveform * GetSparseDigitalInputWaveform(size_t i)
Gets the digital waveform attached to the specified input.
Definition FlowGraphNode.h:212
std::string GetInputDisplayName(size_t i)
Gets the display name for one of our inputs.
Definition FlowGraphNode.cpp:271
WaveformBase * GetInputWaveform(size_t i)
Gets the waveform attached to the specified input.
Definition FlowGraphNode_inlines.h:51
bool IsDownstreamOf(std::set< FlowGraphNode * > nodes)
Determines if this node is downstream of any of the specified other nodes.
Definition FlowGraphNode.cpp:316
sigc::signal< void()> m_inputsChangedSignal
Signal emitted when the set of inputs changes.
Definition FlowGraphNode.h:297
std::map< std::string, FilterParameter > ParameterMapType
Short name for a map of strings to parameters.
Definition FlowGraphNode.h:110
std::vector< std::shared_ptr< InputDescriptor > > m_inputs
Input ports.
Definition FlowGraphNode.h:247
bool HasInput(StreamDescriptor desc)
Checks if the given stream is connected to at least one of our inputs.
Definition FlowGraphNode.cpp:113
UniformAnalogWaveform * GetUniformAnalogInputWaveform(size_t i)
Gets the analog waveform attached to the specified input.
Definition FlowGraphNode.h:208
void AddErrorMessage(const std::string &err)
Add a new error message.
Definition FlowGraphNode.h:282
void ClearMessages()
Remove any messages left over from the last graph refresh.
Definition FlowGraphNode.h:270
virtual void OnInputChanged(size_t i)
Called when a new input is connected to the node.
Definition FlowGraphNode.cpp:106
void SetInput(size_t i, StreamDescriptor stream, bool force=false)
Connects a stream to the input of this node.
Definition FlowGraphNode.cpp:131
bool HasMessages() const
Checks if this graph has any messages.
Definition FlowGraphNode.h:184
std::vector< std::set< FlowGraphNode * > > m_sinks
The nodes (if any) that each of our streams drives.
Definition FlowGraphNode.h:254
void AddMessage(const FlowGraphNodeMessage &msg)
Attach a new message to the node.
Definition FlowGraphNode.h:274
UniformDigitalWaveform * GetUniformDigitalInputWaveform(size_t i)
Gets the digital waveform attached to the specified input.
Definition FlowGraphNode.h:216
virtual bool ValidateChannel(size_t i, StreamDescriptor stream)
Check if a stream is allowed to be connected to the given input.
Definition FlowGraphNode.cpp:293
void DetachInputs()
Disconnects all inputs from the node without releasing them.
Definition FlowGraphNode.cpp:67
virtual void LoadParameters(const YAML::Node &node, IDTable &table)
Load configuration from a save file.
Definition FlowGraphNode.cpp:368
void AddErrorMessage(const std::string &title, const std::string &err)
Add a new error message with a title.
Definition FlowGraphNode.h:290
Bidirectional table mapping integer IDs in scopesession files to object pointers.
Definition IDTable.h:49
Base class for constraints on inputs.
Definition InputConstraint.h:51
Base class for filter graph inputs.
Definition StreamDescriptor.h:110
A single channel on an oscilloscope.
Definition OscilloscopeChannel.h:49
Definition SerializableObject.h:40
A waveform sampled at irregular intervals.
Definition Waveform.h:514
Descriptor for a single stream coming off a channel.
Definition StreamDescriptor.h:47
A waveform sampled at uniform intervals.
Definition Waveform.h:404
Base class for all Waveform specializations.
Definition Waveform.h:59
Severity
Severity of a logging message.
Definition log.h:61
@ ERROR
Something went very wrong, an operation may be aborted or state may be confused.
Main logging framework header.