diff options
author | Christian Daniel <cd@maintech.de> | 2013-11-16 23:14:30 +0100 |
---|---|---|
committer | Christian Daniel <cd@maintech.de> | 2013-11-16 23:14:30 +0100 |
commit | eeb7a07683c3a9b84304748f609019046cc696e3 (patch) | |
tree | 1b3291634144d7a9945354cb2d5dda1a78c0b10b | |
parent | ba220b717a1ce135ccc756d1382b4bb38ee50f47 (diff) |
switch to new message mechanism without registration-voodoo
-rw-r--r-- | include-gpl/dsp/dspcommands.h | 98 | ||||
-rw-r--r-- | include/util/message.h | 49 | ||||
-rw-r--r-- | plugins/channel/nfm/nfmdemod.cpp | 6 | ||||
-rw-r--r-- | plugins/channel/nfm/nfmdemod.h | 6 | ||||
-rw-r--r-- | plugins/channel/tcpsrc/tcpsrc.cpp | 12 | ||||
-rw-r--r-- | plugins/channel/tcpsrc/tcpsrc.h | 18 | ||||
-rw-r--r-- | plugins/channel/tcpsrc/tcpsrcgui.cpp | 6 | ||||
-rw-r--r-- | plugins/samplesource/osmosdr/osmosdrinput.cpp | 4 | ||||
-rw-r--r-- | plugins/samplesource/osmosdr/osmosdrinput.h | 6 | ||||
-rw-r--r-- | plugins/samplesource/rtlsdr/rtlsdrgui.cpp | 2 | ||||
-rw-r--r-- | plugins/samplesource/rtlsdr/rtlsdrinput.cpp | 6 | ||||
-rw-r--r-- | plugins/samplesource/rtlsdr/rtlsdrinput.h | 12 | ||||
-rw-r--r-- | sdrbase/dsp/channelizer.cpp | 4 | ||||
-rw-r--r-- | sdrbase/dsp/dspcommands.cpp | 34 | ||||
-rw-r--r-- | sdrbase/dsp/dspengine.cpp | 30 | ||||
-rw-r--r-- | sdrbase/dsp/scopevis.cpp | 4 | ||||
-rw-r--r-- | sdrbase/dsp/spectrumvis.cpp | 2 | ||||
-rw-r--r-- | sdrbase/dsp/threadedsamplesink.cpp | 2 | ||||
-rw-r--r-- | sdrbase/mainwindow.cpp | 7 | ||||
-rw-r--r-- | sdrbase/plugin/pluginmanager.cpp | 4 | ||||
-rw-r--r-- | sdrbase/util/message.cpp | 84 |
21 files changed, 178 insertions, 218 deletions
diff --git a/include-gpl/dsp/dspcommands.h b/include-gpl/dsp/dspcommands.h index 0fa61d9..58663fe 100644 --- a/include-gpl/dsp/dspcommands.h +++ b/include-gpl/dsp/dspcommands.h @@ -11,39 +11,25 @@ class SampleSink; class AudioFifo; class SDRANGELOVE_API DSPPing : public Message { -public: - static MessageRegistrator ID; - - DSPPing() : Message(ID()) { } + MESSAGE_CLASS_DECLARATION }; class SDRANGELOVE_API DSPExit : public Message { -public: - static MessageRegistrator ID; - - DSPExit() : Message(ID()) { } + MESSAGE_CLASS_DECLARATION }; class SDRANGELOVE_API DSPAcquisitionStart : public Message { -public: - static MessageRegistrator ID; - - DSPAcquisitionStart() : Message(ID()) { } + MESSAGE_CLASS_DECLARATION }; class SDRANGELOVE_API DSPAcquisitionStop : public Message { -public: - static MessageRegistrator ID; - - DSPAcquisitionStop() : Message(ID()) { } + MESSAGE_CLASS_DECLARATION }; class SDRANGELOVE_API DSPGetDeviceDescription : public Message { -public: - static MessageRegistrator ID; - - DSPGetDeviceDescription() : Message(ID()) { } + MESSAGE_CLASS_DECLARATION +public: void setDeviceDescription(const QString& text) { m_deviceDescription = text; } const QString& getDeviceDescription() const { return m_deviceDescription; } @@ -52,11 +38,9 @@ private: }; class SDRANGELOVE_API DSPGetErrorMessage : public Message { -public: - static MessageRegistrator ID; - - DSPGetErrorMessage() : Message(ID()) { } + MESSAGE_CLASS_DECLARATION +public: void setErrorMessage(const QString& text) { m_errorMessage = text; } const QString& getErrorMessage() const { return m_errorMessage; } @@ -65,10 +49,10 @@ private: }; class SDRANGELOVE_API DSPSetSource : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION - DSPSetSource(SampleSource* sampleSource) : Message(ID()), m_sampleSource(sampleSource) { } +public: + DSPSetSource(SampleSource* sampleSource) : Message(), m_sampleSource(sampleSource) { } SampleSource* getSampleSource() const { return m_sampleSource; } @@ -77,10 +61,10 @@ private: }; class SDRANGELOVE_API DSPAddSink : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION - DSPAddSink(SampleSink* sampleSink) : Message(ID()), m_sampleSink(sampleSink) { } +public: + DSPAddSink(SampleSink* sampleSink) : Message(), m_sampleSink(sampleSink) { } SampleSink* getSampleSink() const { return m_sampleSink; } @@ -89,10 +73,10 @@ private: }; class SDRANGELOVE_API DSPRemoveSink : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION - DSPRemoveSink(SampleSink* sampleSink) : Message(ID()), m_sampleSink(sampleSink) { } +public: + DSPRemoveSink(SampleSink* sampleSink) : Message(), m_sampleSink(sampleSink) { } SampleSink* getSampleSink() const { return m_sampleSink; } @@ -101,10 +85,10 @@ private: }; class SDRANGELOVE_API DSPAddAudioSource : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION - DSPAddAudioSource(AudioFifo* audioFifo) : Message(ID()), m_audioFifo(audioFifo) { } +public: + DSPAddAudioSource(AudioFifo* audioFifo) : Message(), m_audioFifo(audioFifo) { } AudioFifo* getAudioFifo() const { return m_audioFifo; } @@ -113,10 +97,10 @@ private: }; class SDRANGELOVE_API DSPRemoveAudioSource : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION - DSPRemoveAudioSource(AudioFifo* audioFifo) : Message(ID()), m_audioFifo(audioFifo) { } +public: + DSPRemoveAudioSource(AudioFifo* audioFifo) : Message(), m_audioFifo(audioFifo) { } AudioFifo* getAudioFifo() const { return m_audioFifo; } @@ -125,9 +109,9 @@ private: }; class SDRANGELOVE_API DSPConfigureSpectrumVis : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION +public: int getFFTSize() const { return m_fftSize; } int getOverlapPercent() const { return m_overlapPercent; } FFTWindow::Function getWindow() const { return m_window; } @@ -143,7 +127,7 @@ private: FFTWindow::Function m_window; DSPConfigureSpectrumVis(int fftSize, int overlapPercent, FFTWindow::Function window) : - Message(ID()), + Message(), m_fftSize(fftSize), m_overlapPercent(overlapPercent), m_window(window) @@ -151,9 +135,9 @@ private: }; class SDRANGELOVE_API DSPConfigureCorrection : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION +public: bool getDCOffsetCorrection() const { return m_dcOffsetCorrection; } bool getIQImbalanceCorrection() const { return m_iqImbalanceCorrection; } @@ -167,16 +151,16 @@ private: bool m_iqImbalanceCorrection; DSPConfigureCorrection(bool dcOffsetCorrection, bool iqImbalanceCorrection) : - Message(ID()), + Message(), m_dcOffsetCorrection(dcOffsetCorrection), m_iqImbalanceCorrection(iqImbalanceCorrection) { } }; class SDRANGELOVE_API DSPEngineReport : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION +public: int getSampleRate() const { return m_sampleRate; } quint64 getCenterFrequency() const { return m_centerFrequency; } @@ -190,16 +174,16 @@ private: quint64 m_centerFrequency; DSPEngineReport(int sampleRate, quint64 centerFrequency) : - Message(ID()), + Message(), m_sampleRate(sampleRate), m_centerFrequency(centerFrequency) { } }; class SDRANGELOVE_API DSPConfigureScopeVis : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION +public: int getTriggerChannel() const { return m_triggerChannel; } Real getTriggerLevelHigh() const { return m_triggerLevelHigh; } Real getTriggerLevelLow() const { return m_triggerLevelLow; } @@ -215,7 +199,7 @@ private: Real m_triggerLevelLow; DSPConfigureScopeVis(int triggerChannel, Real triggerLevelHigh, Real triggerLevelLow) : - Message(ID()), + Message(), m_triggerChannel(triggerChannel), m_triggerLevelHigh(triggerLevelHigh), m_triggerLevelLow(triggerLevelLow) @@ -223,9 +207,9 @@ private: }; class SDRANGELOVE_API DSPSignalNotification : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION +public: int getSampleRate() const { return m_sampleRate; } qint64 getFrequencyOffset() const { return m_frequencyOffset; } @@ -239,16 +223,16 @@ private: qint64 m_frequencyOffset; DSPSignalNotification(int samplerate, qint64 frequencyOffset) : - Message(ID()), + Message(), m_sampleRate(samplerate), m_frequencyOffset(frequencyOffset) { } }; class SDRANGELOVE_API DSPConfigureChannelizer : public Message { -public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION +public: int getSampleRate() const { return m_sampleRate; } int getCenterFrequency() const { return m_centerFrequency; } @@ -262,7 +246,7 @@ private: int m_centerFrequency; DSPConfigureChannelizer(int sampleRate, int centerFrequency) : - Message(ID()), + Message(), m_sampleRate(sampleRate), m_centerFrequency(centerFrequency) { } diff --git a/include/util/message.h b/include/util/message.h index 95e89ef..29dadae 100644 --- a/include/util/message.h +++ b/include/util/message.h @@ -1,43 +1,33 @@ #ifndef INCLUDE_MESSAGE_H #define INCLUDE_MESSAGE_H +#include <stdlib.h> #include <QAtomicInt> -#include <QStringList> #include "util/export.h" class MessageQueue; class QWaitCondition; class QMutex; -class SDRANGELOVE_API MessageRegistrator { -public: - MessageRegistrator(const char* name); - int operator()() const { return m_registeredID; } - - const char* name() const; - -private: - int m_registeredID; -}; - class SDRANGELOVE_API Message { public: + Message(); virtual ~Message(); + virtual const char* getIdentifier() const; + virtual bool matchIdentifier(const char* identifier) const; + static bool match(Message* message); + + void* getDestination() const { return m_destination; } + void submit(MessageQueue* queue, void* destination = NULL); int execute(MessageQueue* queue, void* destination = NULL); void completed(int result = 0); - int id() const { return m_id; } - const char* name() const; - void* destination() const { return m_destination; } - protected: - Message(int id); - - // adressing - int m_id; + // addressing + static const char* m_identifier; void* m_destination; // stuff for synchronous messages @@ -46,6 +36,25 @@ protected: QMutex* m_mutex; QAtomicInt m_complete; int m_result; + + void prepareSync(); }; +#define MESSAGE_CLASS_DECLARATION \ + public: \ + const char* getIdentifier() const; \ + bool matchIdentifier(const char* identifier) const; \ + static bool match(Message* message); \ + protected: \ + static const char* m_identifier; \ + private: + +#define MESSAGE_CLASS_DEFINITION(Name, BaseClass) \ + const char* Name::m_identifier = #Name; \ + const char* Name::getIdentifier() const { return m_identifier; } \ + bool Name::matchIdentifier(const char* identifier) const {\ + return (m_identifier == identifier) ? true : BaseClass::matchIdentifier(identifier); \ + } \ + bool Name::match(Message* message) { return message->matchIdentifier(m_identifier); } + #endif // INCLUDE_MESSAGE_H diff --git a/plugins/channel/nfm/nfmdemod.cpp b/plugins/channel/nfm/nfmdemod.cpp index 843a6aa..359bf09 100644 --- a/plugins/channel/nfm/nfmdemod.cpp +++ b/plugins/channel/nfm/nfmdemod.cpp @@ -21,7 +21,7 @@ #include "audio/audiooutput.h" #include "dsp/dspcommands.h" -MessageRegistrator NFMDemod::MsgConfigureNFMDemod::ID("MsgConfigureNFMDemod"); +MESSAGE_CLASS_DEFINITION(NFMDemod::MsgConfigureNFMDemod, Message) NFMDemod::NFMDemod(AudioFifo* audioFifo, SampleSink* sampleSink) : m_sampleSink(sampleSink), @@ -119,7 +119,7 @@ void NFMDemod::stop() bool NFMDemod::handleMessage(Message* cmd) { - if(cmd->id() == DSPSignalNotification::ID()) { + if(DSPSignalNotification::match(cmd)) { DSPSignalNotification* signal = (DSPSignalNotification*)cmd; qDebug("%d samples/sec, %lld Hz offset", signal->getSampleRate(), signal->getFrequencyOffset()); m_sampleRate = signal->getSampleRate(); @@ -129,7 +129,7 @@ bool NFMDemod::handleMessage(Message* cmd) m_squelchState = 0; cmd->completed(); return true; - } else if(cmd->id() == MsgConfigureNFMDemod::ID()) { + } else if(MsgConfigureNFMDemod::match(cmd)) { MsgConfigureNFMDemod* cfg = (MsgConfigureNFMDemod*)cmd; m_rfBandwidth = cfg->getRFBandwidth(); m_interpolator.create(16, m_sampleRate, m_rfBandwidth / 2.1); diff --git a/plugins/channel/nfm/nfmdemod.h b/plugins/channel/nfm/nfmdemod.h index 4826f33..a312abb 100644 --- a/plugins/channel/nfm/nfmdemod.h +++ b/plugins/channel/nfm/nfmdemod.h @@ -43,9 +43,9 @@ public: private: class MsgConfigureNFMDemod : public Message { - public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION + public: Real getRFBandwidth() const { return m_rfBandwidth; } Real getAFBandwidth() const { return m_afBandwidth; } Real getVolume() const { return m_volume; } @@ -63,7 +63,7 @@ private: Real m_squelch; MsgConfigureNFMDemod(Real rfBandwidth, Real afBandwidth, Real volume, Real squelch) : - Message(ID()), + Message(), m_rfBandwidth(rfBandwidth), m_afBandwidth(afBandwidth), m_volume(volume), diff --git a/plugins/channel/tcpsrc/tcpsrc.cpp b/plugins/channel/tcpsrc/tcpsrc.cpp index 02a55d2..9cfee43 100644 --- a/plugins/channel/tcpsrc/tcpsrc.cpp +++ b/plugins/channel/tcpsrc/tcpsrc.cpp @@ -5,9 +5,9 @@ #include "tcpsrcgui.h" #include "dsp/dspcommands.h" -MessageRegistrator TCPSrc::MsgTCPSrcConfigure::ID("MsgTCPSrcConfigure"); -MessageRegistrator TCPSrc::MsgTCPSrcConnection::ID("MsgTCPSrcConnection"); -MessageRegistrator TCPSrc::MsgTCPSrcSpectrum::ID("MsgTCPSrcSpectrum"); +MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConfigure, Message) +MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcConnection, Message) +MESSAGE_CLASS_DEFINITION(TCPSrc::MsgTCPSrcSpectrum, Message) TCPSrc::TCPSrc(MessageQueue* uiMessageQueue, TCPSrcGUI* tcpSrcGUI, SampleSink* spectrum) { @@ -97,7 +97,7 @@ void TCPSrc::stop() bool TCPSrc::handleMessage(Message* cmd) { - if(cmd->id() == DSPSignalNotification::ID()) { + if(DSPSignalNotification::match(cmd)) { DSPSignalNotification* signal = (DSPSignalNotification*)cmd; qDebug("%d samples/sec, %lld Hz offset", signal->getSampleRate(), signal->getFrequencyOffset()); m_inputSampleRate = signal->getSampleRate(); @@ -106,7 +106,7 @@ bool TCPSrc::handleMessage(Message* cmd) m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate; cmd->completed(); return true; - } else if(cmd->id() == MsgTCPSrcConfigure::ID()) { + } else if(DSPSignalNotification::match(cmd)) { MsgTCPSrcConfigure* cfg = (MsgTCPSrcConfigure*)cmd; m_sampleFormat = cfg->getSampleFormat(); m_outputSampleRate = cfg->getOutputSampleRate(); @@ -121,7 +121,7 @@ bool TCPSrc::handleMessage(Message* cmd) m_sampleDistanceRemain = m_inputSampleRate / m_outputSampleRate; cmd->completed(); return true; - } else if(cmd->id() == MsgTCPSrcSpectrum::ID()) { + } else if(MsgTCPSrcSpectrum::match(cmd)) { MsgTCPSrcSpectrum* spc = (MsgTCPSrcSpectrum*)cmd; m_spectrumEnabled = spc->getEnabled(); cmd->completed(); diff --git a/plugins/channel/tcpsrc/tcpsrc.h b/plugins/channel/tcpsrc/tcpsrc.h index a8270ff..012a4df 100644 --- a/plugins/channel/tcpsrc/tcpsrc.h +++ b/plugins/channel/tcpsrc/tcpsrc.h @@ -32,9 +32,9 @@ public: bool handleMessage(Message* cmd); class MsgTCPSrcConnection : public Message { - public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION + public: bool getConnect() const { return m_connect; } quint32 getID() const { return m_id; } const QHostAddress& getPeerAddress() const { return m_peerAddress; } @@ -52,7 +52,7 @@ public: int m_peerPort; MsgTCPSrcConnection(bool connect, quint32 id, const QHostAddress& peerAddress, int peerPort) : - Message(ID()), + Message(), m_connect(connect), m_id(id), m_peerAddress(peerAddress), @@ -62,9 +62,9 @@ public: protected: class MsgTCPSrcConfigure : public Message { - public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION + public: SampleFormat getSampleFormat() const { return m_sampleFormat; } Real getOutputSampleRate() const { return m_outputSampleRate; } Real getRFBandwidth() const { return m_rfBandwidth; } @@ -82,7 +82,7 @@ protected: int m_tcpPort; MsgTCPSrcConfigure(SampleFormat sampleFormat, Real outputSampleRate, Real rfBandwidth, int tcpPort) : - Message(ID()), + Message(), m_sampleFormat(sampleFormat), m_outputSampleRate(outputSampleRate), m_rfBandwidth(rfBandwidth), @@ -90,9 +90,9 @@ protected: { } }; class MsgTCPSrcSpectrum : public Message { - public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION + public: bool getEnabled() const { return m_enabled; } static MsgTCPSrcSpectrum* create(bool enabled) @@ -104,7 +104,7 @@ protected: bool m_enabled; MsgTCPSrcSpectrum(bool enabled) : - Message(ID()), + Message(), m_enabled(enabled) { } }; diff --git a/plugins/channel/tcpsrc/tcpsrcgui.cpp b/plugins/channel/tcpsrc/tcpsrcgui.cpp index 5e8f13d..a7dcab2 100644 --- a/plugins/channel/tcpsrc/tcpsrcgui.cpp +++ b/plugins/channel/tcpsrc/tcpsrcgui.cpp @@ -98,11 +98,11 @@ bool TCPSrcGUI::deserialize(const QByteArray& data) bool TCPSrcGUI::handleMessage(Message* message) { - if(message->id() == TCPSrc::MsgTCPSrcConnection::ID()) { + if(TCPSrc::MsgTCPSrcConnection::match(message)) { TCPSrc::MsgTCPSrcConnection* con = (TCPSrc::MsgTCPSrcConnection*)message; if(con->getConnect()) - addConnection(con->id(), con->getPeerAddress(), con->getPeerPort()); - else delConnection(con->id()); + addConnection(con->getID(), con->getPeerAddress(), con->getPeerPort()); + else delConnection(con->getID()); message->completed(); return true; } else { diff --git a/plugins/samplesource/osmosdr/osmosdrinput.cpp b/plugins/samplesource/osmosdr/osmosdrinput.cpp index 8e724cf..989eb09 100644 --- a/plugins/samplesource/osmosdr/osmosdrinput.cpp +++ b/plugins/samplesource/osmosdr/osmosdrinput.cpp @@ -22,7 +22,7 @@ #include "osmosdrgui.h" #include "util/simpleserializer.h" -MessageRegistrator OsmoSDRInput::MsgConfigureOsmoSDR::ID("MsgConfigureOsmoSDR"); +MESSAGE_CLASS_DEFINITION(OsmoSDRInput::MsgConfigureOsmoSDR, Message) OsmoSDRInput::Settings::Settings() : m_swapIQ(false), @@ -331,7 +331,7 @@ quint64 OsmoSDRInput::getCenterFrequency() const bool OsmoSDRInput::handleMessage(Message* message) { - if(message->id() == MsgConfigureOsmoSDR::ID()) { + if(MsgConfigureOsmoSDR::match(message)) { MsgConfigureOsmoSDR* conf = (MsgConfigureOsmoSDR*)message; if(!applySettings(conf->getGeneralSettings(), conf->getSettings(), false)) qDebug("OsmoSDR config error"); diff --git a/plugins/samplesource/osmosdr/osmosdrinput.h b/plugins/samplesource/osmosdr/osmosdrinput.h index 9cea94d..dd832ca 100644 --- a/plugins/samplesource/osmosdr/osmosdrinput.h +++ b/plugins/samplesource/osmosdr/osmosdrinput.h @@ -52,9 +52,9 @@ public: }; class MsgConfigureOsmoSDR : public Message { - public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION + public: const GeneralSettings& getGeneralSettings() const { return m_generalSettings; } const Settings& getSettings() const { return m_settings; } @@ -68,7 +68,7 @@ public: Settings m_settings; MsgConfigureOsmoSDR(const GeneralSettings& generalSettings, const Settings& settings) : - Message(ID()), + Message(), m_generalSettings(generalSettings), m_settings(settings) { } diff --git a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp index c7024e2..5706565 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrgui.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrgui.cpp @@ -82,7 +82,7 @@ bool RTLSDRGui::deserialize(const QByteArray& data) bool RTLSDRGui::handleMessage(Message* message) { - if(message->id() == RTLSDRInput::MsgReportRTLSDR::ID()) { + if(RTLSDRInput::MsgReportRTLSDR::match(message)) { m_gains = ((RTLSDRInput::MsgReportRTLSDR*)message)->getGains(); displaySettings(); message->completed(); diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp index 655d8d7..a5d1d95 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.cpp +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.cpp @@ -22,8 +22,8 @@ #include "rtlsdrgui.h" #include "util/simpleserializer.h" -MessageRegistrator RTLSDRInput::MsgConfigureRTLSDR::ID("MsgConfigureRTLSDR"); -MessageRegistrator RTLSDRInput::MsgReportRTLSDR::ID("MsgReportRTLSDR"); +MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgConfigureRTLSDR, Message) +MESSAGE_CLASS_DEFINITION(RTLSDRInput::MsgReportRTLSDR, Message) RTLSDRInput::Settings::Settings() : m_gain(0), @@ -192,7 +192,7 @@ quint64 RTLSDRInput::getCenterFrequency() const bool RTLSDRInput::handleMessage(Message* message) { - if(message->id() == MsgConfigureRTLSDR::ID()) { + if(MsgConfigureRTLSDR::match(message)) { MsgConfigureRTLSDR* conf = (MsgConfigureRTLSDR*)message; if(!applySettings(conf->getGeneralSettings(), conf->getSettings(), false)) qDebug("RTLSDR config error"); diff --git a/plugins/samplesource/rtlsdr/rtlsdrinput.h b/plugins/samplesource/rtlsdr/rtlsdrinput.h index a92702e..d171af1 100644 --- a/plugins/samplesource/rtlsdr/rtlsdrinput.h +++ b/plugins/samplesource/rtlsdr/rtlsdrinput.h @@ -37,9 +37,9 @@ public: }; class MsgConfigureRTLSDR : public Message { - public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION + public: const GeneralSettings& getGeneralSettings() const { return m_generalSettings; } const Settings& getSettings() const { return m_settings; } @@ -53,16 +53,16 @@ public: Settings m_settings; MsgConfigureRTLSDR(const GeneralSettings& generalSettings, const Settings& settings) : - Message(ID()), + Message(), m_generalSettings(generalSettings), m_settings(settings) { } }; class MsgReportRTLSDR : public Message { - public: - static MessageRegistrator ID; + MESSAGE_CLASS_DECLARATION + public: const std::vector<int>& getGains() const { return m_gains; } static MsgReportRTLSDR* create(const std::vector<int>& gains) @@ -74,7 +74,7 @@ public: std::vector<int> m_gains; MsgReportRTLSDR(const std::vector<int>& gains) : - Message(ID()), + Message(), m_gains(gains) { } }; diff --git a/sdrbase/dsp/channelizer.cpp b/sdrbase/dsp/channelizer.cpp index d64eb02..2028a0f 100644 --- a/sdrbase/dsp/channelizer.cpp +++ b/sdrbase/dsp/channelizer.cpp @@ -57,7 +57,7 @@ void Channelizer::stop() bool Channelizer::handleMessage(Message* cmd) { - if(cmd->id() == DSPSignalNotification::ID()) { + if(DSPSignalNotification::match(cmd)) { DSPSignalNotification* signal = (DSPSignalNotification*)cmd; m_inputSampleRate = signal->getSampleRate(); applyConfiguration(); @@ -68,7 +68,7 @@ bool Channelizer::handleMessage(Message* cmd) signal->completed(); } return true; - } else if(cmd->id() == DSPConfigureChannelizer::ID()) { + } else if(DSPConfigureChannelizer::match(cmd)) { DSPConfigureChannelizer* chan = (DSPConfigureChannelizer*)cmd; m_requestedOutputSampleRate = chan->getSampleRate(); m_requestedCenterFrequency = chan->getCenterFrequency(); diff --git a/sdrbase/dsp/dspcommands.cpp b/sdrbase/dsp/dspcommands.cpp index 55dade9..21bdddc 100644 --- a/sdrbase/dsp/dspcommands.cpp +++ b/sdrbase/dsp/dspcommands.cpp @@ -1,19 +1,19 @@ #include "dsp/dspcommands.h" -MessageRegistrator DSPPing::ID("DSPPing"); -MessageRegistrator DSPExit::ID("DSPExit"); -MessageRegistrator DSPAcquisitionStart::ID("DSPAcquisitionStart"); -MessageRegistrator DSPAcquisitionStop::ID("DSPAcquisitionStop"); -MessageRegistrator DSPGetDeviceDescription::ID("DSPGetDeviceDescription"); -MessageRegistrator DSPGetErrorMessage::ID("DSPGetErrorMessage"); -MessageRegistrator DSPSetSource::ID("DSPSetSource"); -MessageRegistrator DSPAddSink::ID("DSPAddSink"); -MessageRegistrator DSPAddAudioSource::ID("DSPAddAudioSource"); -MessageRegistrator DSPRemoveAudioSource::ID("DSPRemoveAudioSource"); -MessageRegistrator DSPRemoveSink::ID("DSPRemoveSink"); -MessageRegistrator DSPConfigureSpectrumVis::ID("DSPConfigureSpectrumVis"); -MessageRegistrator DSPConfigureCorrection::ID("DSPConfigureCorrection"); -MessageRegistrator DSPEngineReport::ID("DSPEngineReport"); -MessageRegistrator DSPConfigureScopeVis::ID("DSPConfigureScopeVis"); -MessageRegistrator DSPSignalNotification::ID("DSPSignalNotification"); -MessageRegistrator DSPConfigureChannelizer::ID("DSPConfigureChannelizer"); +MESSAGE_CLASS_DEFINITION(DSPPing, Message) +MESSAGE_CLASS_DEFINITION(DSPExit, Message) +MESSAGE_CLASS_DEFINITION(DSPAcquisitionStart, Message) +MESSAGE_CLASS_DEFINITION(DSPAcquisitionStop, Message) +MESSAGE_CLASS_DEFINITION(DSPGetDeviceDescription, Message) +MESSAGE_CLASS_DEFINITION(DSPGetErrorMessage, Message) +MESSAGE_CLASS_DEFINITION(DSPSetSource, Message) +MESSAGE_CLASS_DEFINITION(DSPAddSink, Message) +MESSAGE_CLASS_DEFINITION(DSPRemoveSink, Message) +MESSAGE_CLASS_DEFINITION(DSPAddAudioSource, Message) +MESSAGE_CLASS_DEFINITION(DSPRemoveAudioSource, Message) +MESSAGE_CLASS_DEFINITION(DSPConfigureSpectrumVis, Message) +MESSAGE_CLASS_DEFINITION(DSPConfigureCorrection, Message) +MESSAGE_CLASS_DEFINITION(DSPEngineReport, Message) +MESSAGE_CLASS_DEFINITION(DSPConfigureScopeVis, Message) +MESSAGE_CLASS_DEFINITION(DSPSignalNotification, Message) +MESSAGE_CLASS_DEFINITION(DSPConfigureChannelizer, Message) diff --git a/sdrbase/dsp/dspengine.cpp b/sdrbase/dsp/dspengine.cpp index e196601..369403f 100644 --- a/sdrbase/dsp/dspengine.cpp +++ b/sdrbase/dsp/dspengine.cpp @@ -421,7 +421,7 @@ void DSPEngine::generateReport() bool DSPEngine::distributeMessage(Message* message) { if(m_sampleSource != NULL) { - if((message->destination() == NULL) || (message->destination() == m_sampleSource)) { + if((message->getDestination() == NULL) || (message->getDestination() == m_sampleSource)) { if(m_sampleSource->handleMessage(message)) { generateReport(); return true; @@ -429,7 +429,7 @@ bool DSPEngine::distributeMessage(Message* message) } } for(SampleSinks::const_iterator it = m_sampleSinks.begin(); it != m_sampleSinks.end(); it++) { - if((message->destination() == NULL) || (message->destination() == *it)) { + if((message->getDestination() == NULL) || (message->getDestination() == *it)) { if((*it)->handleMessage(message)) return true; } @@ -447,33 +447,33 @@ void DSPEngine::handleMessages() { Message* message; while((message = m_messageQueue.accept()) != NULL) { - qDebug("Message: %d: %s", message->id(), message->name()); + qDebug("Message: %s", message->getIdentifier()); - if(message->id() == DSPPing::ID()) { + if(DSPPing::match(message)) { message->completed(m_state); - } else if(message->id() == DSPExit::ID()) { + } else if(DSPExit::match(message)) { gotoIdle(); m_state = StNotStarted; exit(); message->completed(m_state); - } else if(message->id() == DSPAcquisitionStart::ID()) { + } else if(DSPAcquisitionStart::match(message)) { m_state = gotoIdle(); if(m_state == StIdle) m_state = gotoRunning(); message->completed(m_state); - } else if(message->id() == DSPAcquisitionStop::ID()) { + } else if(DSPAcquisitionStop::match(message)) { m_state = gotoIdle(); message->completed(m_state); - } else if(message->id() == DSPGetDeviceDescription::ID()) { + } else if(DSPGetDeviceDescription::match(message)) { ((DSPGetDeviceDescription*)message)->setDeviceDescription(m_deviceDescription); message->completed(); - } else if(message->id() == DSPGetErrorMessage::ID()) { + } else if(DSPGetErrorMessage::match(message)) { ((DSPGetErrorMessage*)message)->setErrorMessage(m_errorMessage); message->completed(); - } else if(message->id() == DSPSetSource::ID()) { + } else if(DSPSetSource::match(message)) { handleSetSource(((DSPSetSource*)message)->getSampleSource()); message->completed(); - } else if(message->id() == DSPAddSink::ID()) { + } else if(DSPAddSink::match(message)) { SampleSink* sink = ((DSPAddSink*)message)->getSampleSink(); if(m_state == StRunning) { DSPSignalNotification* signal = DSPSignalNotification::create(m_sampleRate, 0); @@ -482,19 +482,19 @@ void DSPEngine::handleMessages() } m_sampleSinks.push_back(sink); message->completed(); - } else if(message->id() == DSPRemoveSink::ID()) { + } else if(DSPRemoveSink::match(message)) { SampleSink* sink = ((DSPAddSink*)message)->getSampleSink(); if(m_state == StRunning) sink->stop(); m_sampleSinks.remove(sink); message->completed(); - } else if(message->id() == DSPAddAudioSource::ID()) { + } else if(DSPAddAudioSource::match(message)) { m_audioOutput.addFifo(((DSPAddAudioSource*)message)->getAudioFifo()); message->completed(); - } else if(message->id() == DSPRemoveAudioSource::ID()) { + } else if(DSPRemoveAudioSource::match(message)) { m_audioOutput.removeFifo(((DSPAddAudioSource*)message)->getAudioFifo()); message->completed(); - } else if(message->id() == DSPConfigureCorrection::ID()) { + } else if(DSPConfigureCorrection::match(message)) { DSPConfigureCorrection* conf = (DSPConfigureCorrection*)message; m_iqImbalanceCorrection = conf->getIQImbalanceCorrection(); if(m_dcOffsetCorrection != conf->getDCOffsetCorrection()) { diff --git a/sdrbase/dsp/scopevis.cpp b/sdrbase/dsp/scopevis.cpp index 70adf8b..0dc8e23 100644 --- a/sdrbase/dsp/scopevis.cpp +++ b/sdrbase/dsp/scopevis.cpp @@ -122,12 +122,12 @@ void ScopeVis::stop() bool ScopeVis::handleMessage(Message* message) { - if(message->id() == DSPSignalNotification::ID()) { + if(DSPSignalNotification::match(message)) { DSPSignalNotification* signal = (DSPSignalNotification*)message; m_sampleRate = signal->getSampleRate(); message->completed(); return true; - } else if(message->id() == DSPConfigureScopeVis::ID()) { + } else if(DSPConfigureScopeVis::match(message)) { DSPConfigureScopeVis* conf = (DSPConfigureScopeVis*)message; m_triggerState = Untriggered; m_triggerChannel = (TriggerChannel)conf->getTriggerChannel(); diff --git a/sdrbase/dsp/spectrumvis.cpp b/sdrbase/dsp/spectrumvis.cpp index e09cca5..01c7dbe 100644 --- a/sdrbase/dsp/spectrumvis.cpp +++ b/sdrbase/dsp/spectrumvis.cpp @@ -94,7 +94,7 @@ void SpectrumVis::stop() bool SpectrumVis::handleMessage(Message* message) { - if(message->id() == DSPConfigureSpectrumVis::ID()) { + if(DSPConfigureSpectrumVis::match(message)) { DSPConfigureSpectrumVis* conf = (DSPConfigureSpectrumVis*)message; handleConfigure(conf->getFFTSize(), conf->getOverlapPercent(), conf->getWindow()); message->completed(); diff --git a/sdrbase/dsp/threadedsamplesink.cpp b/sdrbase/dsp/threadedsamplesink.cpp index 15fb277..ad157b9 100644 --- a/sdrbase/dsp/threadedsamplesink.cpp +++ b/sdrbase/dsp/threadedsamplesink.cpp @@ -88,7 +88,7 @@ void ThreadedSampleSink::handleMessages() { Message* message; while((message = m_messageQueue.accept()) != NULL) { - qDebug("CMD: %s", message->name()); + qDebug("CMD: %s", message->getIdentifier()); if(m_sampleSink != NULL) { if(!m_sampleSink->handleMessage(message)) message->completed(); diff --git a/sdrbase/mainwindow.cpp b/sdrbase/mainwindow.cpp index 2b2ddd2..815f30b 100644 --- a/sdrbase/mainwindow.cpp +++ b/sdrbase/mainwindow.cpp @@ -306,8 +306,8 @@ void MainWindow::handleMessages() { Message* message; while((message = m_messageQueue->accept()) != NULL) { - qDebug("Message: %d: %s", message->id(), message->name()); - if(message->id() == DSPEngineReport::ID()) { + qDebug("Message: %s", message->getIdentifier()); + if(DSPEngineReport::match(message)) { DSPEngineReport* rep = (DSPEngineReport*)message; m_sampleRate = rep->getSampleRate(); m_centerFrequency = rep->getCenterFrequency(); @@ -490,7 +490,8 @@ void MainWindow::on_action_Oscilloscope_triggered() QDockWidget* dock = new QDockWidget(tr("Signalscope"), this); dock->setObjectName(QString::fromUtf8("scopeDock")); - m_scopeWindow = new ScopeWindow(m_dspEngine); + m_scopeWindow = new ScopeWindow(); + m_scopeWindow->setDSPEngine(m_dspEngine); connect(m_scopeWindow, SIGNAL(destroyed()), this, SLOT(scopeWindowDestroyed())); m_scopeWindow->setSampleRate(m_sampleRate); dock->setWidget(m_scopeWindow); diff --git a/sdrbase/plugin/pluginmanager.cpp b/sdrbase/plugin/pluginmanager.cpp index b2aeb6e..3338c01 100644 --- a/sdrbase/plugin/pluginmanager.cpp +++ b/sdrbase/plugin/pluginmanager.cpp @@ -153,14 +153,14 @@ void PluginManager::freeAll() bool PluginManager::handleMessage(Message* message) { if(m_sampleSourceInstance != NULL) { - if((message->destination() == NULL) || (message->destination() == m_sampleSourceInstance)) { + if((message->getDestination() == NULL) || (message->getDestination() == m_sampleSourceInstance)) { if(m_sampleSourceInstance->handleMessage(message)) return true; } } for(ChannelInstanceRegistrations::iterator it = m_channelInstanceRegistrations.begin(); it != m_channelInstanceRegistrations.end(); ++it) { - if((message->destination() == NULL) || (message->destination() == it->m_gui)) { + if((message->getDestination() == NULL) || (message->getDestination() == it->m_gui)) { if(it->m_gui->handleMessage(message)) return true; } diff --git a/sdrbase/util/message.cpp b/sdrbase/util/message.cpp index df45080..8431ca7 100644 --- a/sdrbase/util/message.cpp +++ b/sdrbase/util/message.cpp @@ -1,53 +1,17 @@ -#include <vector> #include <QWaitCondition> #include <QMutex> #include "util/message.h" #include "util/messagequeue.h" -#include "util/spinlock.h" -class Registry { -public: - static Registry* getInstance() - { - SpinlockHolder spinlockHolder(&m_registryLock); - if(m_instance != NULL) { - return m_instance; - } else { - m_instance = new Registry; - return m_instance; - } - } - - int registerMessage(const char* name) - { - SpinlockHolder spinlockHolder(&m_registryLock); - m_registry.push_back(name); - return m_registry.size() - 1; - } - - const char* name(int id) const - { - return m_registry[id]; - } +const char* Message::m_identifier = "Message"; -private: - static Registry* m_instance; - static Spinlock m_registryLock; - std::vector<const char*> m_registry; - - Registry() : - m_registry() - { } -}; - -Registry* Registry::m_instance = NULL; -Spinlock Registry::m_registryLock; - -MessageRegistrator::MessageRegistrator(const char* name) +Message::Message() : + m_destination(NULL), + m_synchronous(false), + m_waitCondition(NULL), + m_mutex(NULL), + m_complete(0) { - Registry* registry = Registry::getInstance(); - m_registeredID = registry->registerMessage(name); - qDebug("%s registered as %d", name, m_registeredID); } Message::~Message() @@ -58,6 +22,21 @@ Message::~Message() delete m_mutex; } +const char* Message::getIdentifier() const +{ + return m_identifier; +} + +bool Message::matchIdentifier(const char* identifier) const +{ + return m_identifier == identifier; +} + +bool Message::match(Message* message) +{ + return message->matchIdentifier(m_identifier); +} + void Message::submit(MessageQueue* queue, void* destination) { m_destination = destination; @@ -79,7 +58,7 @@ int Message::execute(MessageQueue* queue, void* destination) m_complete.testAndSetAcquire(0, 1); queue->submit(this); while(!m_complete.testAndSetAcquire(0, 1)) - m_waitCondition->wait(m_mutex, 100); + ((QWaitCondition*)m_waitCondition)->wait(m_mutex, 100); m_complete = 0; int result = m_result; m_mutex->unlock(); @@ -91,23 +70,10 @@ void Message::completed(int result) if(m_synchronous) { m_result = result; m_complete = 0; + if(m_waitCondition == NULL) + qFatal("wait condition is NULL"); m_waitCondition->wakeAll(); } else { delete this; } } - -const char* Message::name() const -{ - return Registry::getInstance()->name(m_id); -} - -Message::Message(int id) : - m_id(id), - m_destination(NULL), - m_synchronous(false), - m_waitCondition(NULL), - m_mutex(NULL), - m_complete(0) -{ -} |