mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 19:30:03 +02:00
changed API for setting network parameter to remove memory leak, fixed lock issues in streaming print outs to gui
This commit is contained in:
parent
47e5504203
commit
2ec1e08081
@ -17,6 +17,7 @@
|
||||
#include <QString>
|
||||
#include <QCustomEvent>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
@ -47,6 +48,7 @@ class qDebugStream : public basic_streambuf<char> {
|
||||
|
||||
public:
|
||||
qDebugStream(ostream &stream, QWidget* w) : m_stream(stream), log_window(w) {
|
||||
mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
m_old_buf = stream.rdbuf();
|
||||
stream.rdbuf(this);
|
||||
}
|
||||
@ -55,8 +57,11 @@ public:
|
||||
|
||||
~qDebugStream(){
|
||||
// output anything that is left
|
||||
if (!m_string.empty())
|
||||
if (!m_string.empty()) {
|
||||
pthread_mutex_lock(&mutex);
|
||||
QApplication::postEvent(log_window, new qStreamEvent(m_string.c_str()));
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
m_stream.rdbuf(m_old_buf);
|
||||
}
|
||||
|
||||
@ -65,8 +70,10 @@ public:
|
||||
protected:
|
||||
virtual int_type overflow(int_type v){
|
||||
if (v == '\n'){
|
||||
pthread_mutex_lock(&mutex);
|
||||
QApplication::postEvent(log_window, new qStreamEvent(m_string.c_str()));
|
||||
m_string.erase(m_string.begin(), m_string.end());
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
else
|
||||
m_string += v;
|
||||
@ -76,7 +83,9 @@ protected:
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
virtual streamsize xsputn(const char *p, streamsize n) {
|
||||
pthread_mutex_lock(&mutex);
|
||||
m_string.append(p, p + n);
|
||||
|
||||
//changed from uint because of 64 bit
|
||||
int pos = 0;
|
||||
|
||||
@ -88,12 +97,14 @@ protected:
|
||||
m_string.erase(m_string.begin(), m_string.begin() + pos + 1);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return n;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
pthread_mutex_t mutex;
|
||||
ostream &m_stream;
|
||||
streambuf *m_old_buf;
|
||||
string m_string;
|
||||
|
@ -153,14 +153,14 @@ void qTabAdvanced::SetupWidgetWindow(){
|
||||
spinControlPort->setValue(det->getControlPort());
|
||||
spinStopPort->setValue(det->getStopPort());
|
||||
spinTCPPort->setValue(det->getReceiverPort());
|
||||
spinUDPPort->setValue(atoi(det->getReceiverUDPPort()));
|
||||
spinUDPPort->setValue(atoi(det->getReceiverUDPPort().c_str()));
|
||||
|
||||
cout << "Getting network information" << endl;
|
||||
dispIP->setText(det->getDetectorIP());
|
||||
dispMAC->setText(det->getDetectorMAC());
|
||||
dispRxrHostname->setText(det->getReceiver());
|
||||
dispUDPIP->setText(det->getReceiverUDPIP());
|
||||
dispUDPMAC->setText(det->getReceiverUDPMAC());
|
||||
dispIP->setText(det->getDetectorIP().c_str());
|
||||
dispMAC->setText(det->getDetectorMAC().c_str());
|
||||
dispRxrHostname->setText(det->getReceiver().c_str());
|
||||
dispUDPIP->setText(det->getReceiverUDPIP().c_str());
|
||||
dispUDPMAC->setText(det->getReceiverUDPMAC().c_str());
|
||||
|
||||
|
||||
//check if its online and set it to red if offline
|
||||
@ -785,10 +785,10 @@ void qTabAdvanced::SetNetworkParameters(){
|
||||
disconnect(dispUDPIP, SIGNAL(editingFinished()), this, SLOT(SetNetworkParameters()));
|
||||
disconnect(dispUDPMAC, SIGNAL(editingFinished()), this, SLOT(SetNetworkParameters()));
|
||||
|
||||
dispIP->setText(QString(det->setDetectorIP(dispIP->text().toAscii().constData())));
|
||||
dispMAC->setText(QString(det->setDetectorMAC(dispMAC->text().toAscii().constData())));
|
||||
dispUDPIP->setText(QString(det->setReceiverUDPIP(dispUDPIP->text().toAscii().constData())));
|
||||
dispUDPMAC->setText(QString(det->setReceiverUDPMAC(dispUDPMAC->text().toAscii().constData())));
|
||||
dispIP->setText(QString(det->setDetectorIP(dispIP->text().toAscii().constData()).c_str()));
|
||||
dispMAC->setText(QString(det->setDetectorMAC(dispMAC->text().toAscii().constData()).c_str()));
|
||||
dispUDPIP->setText(QString(det->setReceiverUDPIP(dispUDPIP->text().toAscii().constData()).c_str()));
|
||||
dispUDPMAC->setText(QString(det->setReceiverUDPMAC(dispUDPMAC->text().toAscii().constData()).c_str()));
|
||||
qDefs::checkErrorMessage(det,"qTabAdvanced::SetNetworkParameters");
|
||||
|
||||
connect(dispIP, SIGNAL(editingFinished()), this, SLOT(SetNetworkParameters()));
|
||||
@ -806,7 +806,7 @@ void qTabAdvanced::SetReceiver(){
|
||||
cout << "Setting Receiver" << endl;
|
||||
#endif
|
||||
string outdir = myDet->getFilePath();
|
||||
dispRxrHostname->setText(QString(det->setReceiver(dispRxrHostname->text().toAscii().constData())));
|
||||
dispRxrHostname->setText(QString(det->setReceiver(dispRxrHostname->text().toAscii().constData()).c_str()));
|
||||
qDefs::checkErrorMessage(det,"qTabAdvanced::SetReceiver");
|
||||
det->setFilePath(outdir);
|
||||
qDefs::checkErrorMessage(det,"qTabAdvanced::SetReceiver");
|
||||
@ -1059,13 +1059,13 @@ void qTabAdvanced::SetDetector(int index){
|
||||
spinControlPort->setValue(det->getControlPort());
|
||||
spinStopPort->setValue(det->getStopPort());
|
||||
spinTCPPort->setValue(det->getReceiverPort());
|
||||
spinUDPPort->setValue(atoi(det->getReceiverUDPPort()));
|
||||
spinUDPPort->setValue(atoi(det->getReceiverUDPPort().c_str()));
|
||||
|
||||
dispIP->setText(det->getDetectorIP());
|
||||
dispMAC->setText(det->getDetectorMAC());
|
||||
dispRxrHostname->setText(det->getReceiver());
|
||||
dispUDPIP->setText(det->getReceiverUDPIP());
|
||||
dispUDPMAC->setText(det->getReceiverUDPMAC());
|
||||
dispIP->setText(det->getDetectorIP().c_str());
|
||||
dispMAC->setText(det->getDetectorMAC().c_str());
|
||||
dispRxrHostname->setText(det->getReceiver().c_str());
|
||||
dispUDPIP->setText(det->getReceiverUDPIP().c_str());
|
||||
dispUDPMAC->setText(det->getReceiverUDPMAC().c_str());
|
||||
|
||||
|
||||
//check if its online and set it to red if offline
|
||||
@ -1262,20 +1262,20 @@ void qTabAdvanced::Refresh(){
|
||||
disconnect(dispUDPMAC, SIGNAL(editingFinished()), this, SLOT(SetNetworkParameters()));
|
||||
disconnect(btnRxr, SIGNAL(clicked()), this, SLOT(SetReceiver()));
|
||||
|
||||
dispIP->setText(det->getDetectorIP());
|
||||
dispMAC->setText(det->getDetectorMAC());
|
||||
dispIP->setText(det->getDetectorIP().c_str());
|
||||
dispMAC->setText(det->getDetectorMAC().c_str());
|
||||
|
||||
//so that updated status
|
||||
if(det->setReceiverOnline()==slsDetectorDefs::ONLINE_FLAG)
|
||||
det->checkReceiverOnline();
|
||||
comboRxrOnline->setCurrentIndex(det->setReceiverOnline());
|
||||
|
||||
dispRxrHostname->setText(det->getReceiver());
|
||||
dispRxrHostname->setText(det->getReceiver().c_str());
|
||||
spinTCPPort->setValue(det->getReceiverPort());
|
||||
spinUDPPort->setValue(atoi(det->getReceiverUDPPort()));
|
||||
spinUDPPort->setValue(atoi(det->getReceiverUDPPort().c_str()));
|
||||
|
||||
dispUDPIP->setText(det->getReceiverUDPIP());
|
||||
dispUDPMAC->setText(det->getReceiverUDPMAC());
|
||||
dispUDPIP->setText(det->getReceiverUDPIP().c_str());
|
||||
dispUDPMAC->setText(det->getReceiverUDPMAC().c_str());
|
||||
|
||||
//connect
|
||||
connect(spinTCPPort, SIGNAL(valueChanged(int)), this, SLOT(SetRxrTCPPort(int)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user