Remove duplicate CVoiceVatlib object.

Move the one in Client into its own thread instead

refs #226
This commit is contained in:
Roland Winklmeier
2014-05-02 14:06:45 +02:00
parent 132adc28b5
commit 732b6f5ae7
3 changed files with 13 additions and 14 deletions

View File

@@ -19,6 +19,9 @@ Client::Client(QObject *parent) :
QObject(parent), QObject(parent),
m_voice(new BlackCore::CVoiceVatlib()) m_voice(new BlackCore::CVoiceVatlib())
{ {
m_voice->moveToThread(&m_threadVoice);
m_threadVoice.start();
using namespace BlackCore; using namespace BlackCore;
connect(m_voice, &IVoice::squelchTestFinished, this, &Client::onSquelchTestFinished); connect(m_voice, &IVoice::squelchTestFinished, this, &Client::onSquelchTestFinished);
connect(m_voice, &IVoice::micTestFinished, this, &Client::onMicTestFinished); connect(m_voice, &IVoice::micTestFinished, this, &Client::onMicTestFinished);
@@ -91,6 +94,9 @@ void Client::echo(QTextStream &line)
void Client::exit(QTextStream &) void Client::exit(QTextStream &)
{ {
qDebug() << "Shutting down...";
m_threadVoice.quit();
m_threadVoice.wait(5000);
emit quit(); emit quit();
} }

View File

@@ -11,6 +11,7 @@
#include <QObject> #include <QObject>
#include <functional> #include <functional>
#include <QMap> #include <QMap>
#include <QThread>
class Client : public QObject class Client : public QObject
{ {
@@ -18,6 +19,7 @@ class Client : public QObject
public: public:
Client(QObject *parent = nullptr); Client(QObject *parent = nullptr);
~Client() { if(m_voice) m_voice->deleteLater(); }
signals: signals:
void quit(); void quit();
@@ -56,6 +58,7 @@ private slots:
private: private:
QMap<QString, std::function<void(QTextStream &)>> m_commands; QMap<QString, std::function<void(QTextStream &)>> m_commands;
BlackCore::IVoice *m_voice; BlackCore::IVoice *m_voice;
QThread m_threadVoice;
}; };

View File

@@ -12,7 +12,7 @@
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include <QThread>
using namespace BlackMisc::Audio; using namespace BlackMisc::Audio;
@@ -22,20 +22,10 @@ int main(int argc, char *argv[])
Client client(&app); Client client(&app);
BlackMisc::registerMetadata(); BlackMisc::registerMetadata();
BlackCore::registerMetadata(); BlackCore::registerMetadata();
BlackCore::IVoice *m_voice = new BlackCore::CVoiceVatlib();
QThread m_voiceThread;
m_voice->moveToThread(&m_voiceThread);
m_voiceThread.start();
LineReader reader; LineReader reader;
QObject::connect(&reader, SIGNAL(command(const QString &)), &client, SLOT(command(const QString &))); QObject::connect(&reader, SIGNAL(command(const QString &)), &client, SLOT(command(const QString &)), Qt::QueuedConnection);
QObject::connect(&client, &Client::quit, [&] () QObject::connect(&client, SIGNAL(quit()), &reader, SLOT(terminate()));
{ QObject::connect(&client, SIGNAL(quit()), &app, SLOT(quit()));
qDebug() << "Shutting down...";
reader.terminate();
m_voiceThread.quit();
m_voiceThread.wait(5000);
qApp->quit();
});
reader.start(); reader.start();
app.exec(); app.exec();