Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f46b289240ca
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 946189e19c65
Choose a head ref
  • 1 commit
  • 6 files changed
  • 1 contributor

Commits on Sep 13, 2020

  1. Refactoring: moved a bunch of common functionality from Filter class …

    …to new FlowGraphNode class
    azonenberg committed Sep 13, 2020
    Copy the full SHA
    946189e View commit details
Showing with 344 additions and 233 deletions.
  1. +1 −0 scopehal/CMakeLists.txt
  2. +0 −128 scopehal/Filter.cpp
  3. +4 −105 scopehal/Filter.h
  4. +176 −0 scopehal/FlowGraphNode.cpp
  5. +162 −0 scopehal/FlowGraphNode.h
  6. +1 −0 scopehal/scopehal.h
1 change: 1 addition & 0 deletions scopehal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ set(SCOPEHAL_SOURCES

Filter.cpp
FilterParameter.cpp
FlowGraphNode.cpp
PacketDecoder.cpp
Statistic.cpp
)
128 changes: 0 additions & 128 deletions scopehal/Filter.cpp
Original file line number Diff line number Diff line change
@@ -53,16 +53,7 @@ Gdk::Color Filter::m_standardColors[STANDARD_COLOR_COUNT] =
Gdk::Color("#404040") //COLOR_IDLE
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// StreamDescriptor

string StreamDescriptor::GetName()
{
string name = m_channel->m_displayname;
if(m_channel->GetStreamCount() > 1)
name += string(".") + m_channel->GetStreamName(m_stream);
return name;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction
@@ -115,125 +106,6 @@ bool Filter::IsOverlay()
return true;
}

FilterParameter& Filter::GetParameter(string s)
{
if(m_parameters.find(s) == m_parameters.end())
LogError("Invalid parameter name\n");

return m_parameters[s];
}

size_t Filter::GetInputCount()
{
return m_signalNames.size();
}

string Filter::GetInputName(size_t i)
{
if(i < m_signalNames.size())
return m_signalNames[i];
else
{
LogError("Invalid channel index\n");
return "";
}
}

/**
@brief Connects a stream to the input of this filter
@param i Index of the input port to connect
@param stream Input data stream
@param force Forcibly connect this stream without checking to make sure it's the right type.
Should only be set true by by Filter::LoadInputs() or in similar specialized situations.
*/
void Filter::SetInput(size_t i, StreamDescriptor stream, bool force)
{
if(i < m_signalNames.size())
{
if(stream.m_channel == NULL) //NULL is always legal
{
m_inputs[i] = StreamDescriptor(NULL, 0);
return;
}

//If forcing, don't validate the channel
if(!force)
{
if(!ValidateChannel(i, stream))
{
LogError("Invalid channel for input %zu of %s\n", i, m_displayname.c_str());
m_inputs[i] = StreamDescriptor(NULL, 0);
return;
}
}

//Deref whatever was there (if anything)
if(m_inputs[i].m_channel != NULL)
m_inputs[i].m_channel->Release();

//All good, we can save the new input
m_inputs[i] = stream;
stream.m_channel->AddRef();
}
else
{
LogError("Invalid channel index\n");
}
}

/**
@brief Connects a stream to the input of this filter
@param name Name of the input port to connect
@param stream Input data stream
@param force Forcibly connect this stream without checking to make sure it's the right type.
Should only be set true by by Filter::LoadInputs() or in similar specialized situations.
*/
void Filter::SetInput(string name, StreamDescriptor stream, bool force)
{
//Find the channel
for(size_t i=0; i<m_signalNames.size(); i++)
{
if(m_signalNames[i] == name)
{
SetInput(i, stream, force);
return;
}
}

//Not found
LogError("Invalid channel name\n");
}

/**
@brief Gets the descriptor for one of our inputs
*/
StreamDescriptor Filter::GetInput(size_t i)
{
if(i < m_signalNames.size())
return m_inputs[i];
else
{
LogError("Invalid channel index\n");
return StreamDescriptor(NULL, 0);
}
}

/**
@brief Gets the display name for one of our inputs.
This includes the stream name iff the input comes from a multi-stream source.
*/
string Filter::GetInputDisplayName(size_t i)
{
auto in = m_inputs[i];
if(in.m_channel->GetStreamCount() > 1)
return in.m_channel->m_displayname + "." + in.m_channel->GetStreamName(in.m_stream);
else
return in.m_channel->m_displayname;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Refreshing

109 changes: 4 additions & 105 deletions scopehal/Filter.h
Original file line number Diff line number Diff line change
@@ -37,52 +37,13 @@
#define Filter_h

#include "OscilloscopeChannel.h"
#include "FlowGraphNode.h"

/**
@brief Descriptor for a single stream coming off a channel
@brief Abstract base class for all filters and protocol decoders
*/
class StreamDescriptor
{
public:
StreamDescriptor()
: m_channel(NULL)
, m_stream(0)
{}

StreamDescriptor(OscilloscopeChannel* channel, size_t stream)
: m_channel(channel)
, m_stream(stream)
{}

std::string GetName();

OscilloscopeChannel* m_channel;
size_t m_stream;

WaveformBase* GetData()
{ return m_channel->GetData(m_stream); }

bool operator==(const StreamDescriptor& rhs) const
{ return (m_channel == rhs.m_channel) && (m_stream == rhs.m_stream); }

bool operator!=(const StreamDescriptor& rhs) const
{ return (m_channel != rhs.m_channel) || (m_stream != rhs.m_stream); }

bool operator<(const StreamDescriptor& rhs) const
{
if(m_channel < rhs.m_channel)
return true;
if( (m_channel == rhs.m_channel) && (m_stream < rhs.m_stream) )
return true;

return false;
}
};

/**
@brief Abstract base class for all protocol decoders
*/
class Filter : public OscilloscopeChannel
class Filter : public OscilloscopeChannel
, public FlowGraphNode
{
public:

@@ -125,23 +86,6 @@ class Filter : public OscilloscopeChannel

virtual void SetDefaultName() =0;

//Channels
size_t GetInputCount();
std::string GetInputName(size_t i);
void SetInput(size_t i, StreamDescriptor stream, bool force = false);
void SetInput(std::string name, StreamDescriptor stream, bool force = false);

StreamDescriptor GetInput(size_t i);

virtual bool ValidateChannel(size_t i, StreamDescriptor stream) =0;

FilterParameter& GetParameter(std::string s);
typedef std::map<std::string, FilterParameter> ParameterMapType;
ParameterMapType::iterator GetParamBegin()
{ return m_parameters.begin(); }
ParameterMapType::iterator GetParamEnd()
{ return m_parameters.end(); }

Category GetCategory()
{ return m_category; }

@@ -199,15 +143,6 @@ class Filter : public OscilloscopeChannel

protected:

///Names of signals we take as input
std::vector<std::string> m_signalNames;

//Parameters
ParameterMapType m_parameters;

///The channel (if any) connected to each of our inputs
std::vector<StreamDescriptor> m_inputs;

///Group used for the display menu
Category m_category;

@@ -234,42 +169,6 @@ class Filter : public OscilloscopeChannel
i ++;
}

/**
@brief Gets the waveform attached to the specified input.
This function is safe to call on a NULL input and will return NULL in that case.
*/
WaveformBase* GetInputWaveform(size_t i)
{
auto chan = m_inputs[i].m_channel;
if(chan == NULL)
return NULL;
return chan->GetData(m_inputs[i].m_stream);
}

///Gets the analog waveform attached to the specified input
AnalogWaveform* GetAnalogInputWaveform(size_t i)
{ return dynamic_cast<AnalogWaveform*>(GetInputWaveform(i)); }

///Gets the digital waveform attached to the specified input
DigitalWaveform* GetDigitalInputWaveform(size_t i)
{ return dynamic_cast<DigitalWaveform*>(GetInputWaveform(i)); }

///Gets the digital bus waveform attached to the specified input
DigitalBusWaveform* GetDigitalBusInputWaveform(size_t i)
{ return dynamic_cast<DigitalBusWaveform*>(GetInputWaveform(i)); }

/**
@brief Creates and names an input signal
*/
void CreateInput(std::string name)
{
m_signalNames.push_back(name);
m_inputs.push_back(StreamDescriptor(NULL, 0));
}

std::string GetInputDisplayName(size_t i);

public:
//Text formatting for CHANNEL_TYPE_COMPLEX decodes
virtual Gdk::Color GetColor(int i);
Loading