Changeset d5f420a in OpenModelica


Ignore:
Timestamp:
2017-10-19T11:15:41+02:00 (7 years ago)
Author:
Adeel Asghar <adeel.asghar@…>
Branches:
Added-citation-metadata, maintenance/v1.14, maintenance/v1.15, maintenance/v1.16, maintenance/v1.17, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
d60db4d4
Parents:
dbc50ee
git-author:
Adeel Asghar <adeel.asghar@…> (07/06/17 12:21:44)
git-committer:
Adeel Asghar <adeel.asghar@…> (10/19/17 11:15:41)
Message:

Removed the unnecessary SimulationServerCheckThread class.
Do not create unnecessary QTcpSocket objects.

Location:
OMEdit/OMEditGUI/Simulation
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • OMEdit/OMEditGUI/Simulation/OpcUaClient.cpp

    rdbc50ee rd5f420a  
    3131  UA_StatusCode returnValue = UA_Client_connect(mpClient, UA_ClientConnectionTCP, endPoint.c_str());
    3232
     33  qDebug() << returnValue;
    3334  if (returnValue != UA_STATUSCODE_GOOD) {
    3435    UA_Client_disconnect(mpClient);
  • OMEdit/OMEditGUI/Simulation/SimulationDialog.cpp

    rdbc50ee rd5f420a  
    11131113    // embedded server port
    11141114    if (mpInteractiveSimulationPortNumberTextBox->text().isEmpty()) {
    1115       // look for an available port
    1116       QTcpSocket *pSocket = new QTcpSocket();
    11171115      qint16 port = 4841;
    1118       // find a port not previously used by another opc ua server
    1119       pSocket->connectToHost(QHostAddress::LocalHost, port);
    1120       while (pSocket->waitForConnected(10)) {
    1121         port++;
    1122         pSocket->abort();
    1123         pSocket->connectToHost(QHostAddress::LocalHost, port);
    1124       }
    11251116      simulationOptions.setInteractiveSimulationPortNumber(port);
    11261117      simulationFlags.append(QString("-embeddedServerPort=").append(QString::number(port)));
     
    16401631                                                          Helper::scriptingKind, Helper::errorLevel));
    16411632  }
    1642 }
    1643 
    1644 /*!
    1645  * \brief SimulationDialog::embeddedServerError
    1646  * \param simulationOptions
    1647  * Handles what should be done if the OPC UA client is unable to bind to the server \n
    1648  * over the selected port. \n
    1649  */
    1650 void SimulationDialog::embeddedServerError(QString error)
    1651 {
    1652   // make the user aware of the problem
    1653   QMessageBox::critical(this, QString("%1 - %2").arg(Helper::applicationName, Helper::information),
    1654                            "Embedded simulation server: " + error, Helper::ok);
    16551633}
    16561634
  • OMEdit/OMEditGUI/Simulation/SimulationDialog.h

    rdbc50ee rd5f420a  
    232232  void simulationProcessFinished(SimulationOptions simulationOptions, QDateTime resultFileLastModifiedDateTime);
    233233  void simulationProcessRunning(SimulationOptions simulationOptions);
    234   void embeddedServerError(QString error);
    235234public slots:
    236235  void numberOfIntervalsRadioToggled(bool toggle);
  • OMEdit/OMEditGUI/Simulation/SimulationOutputWidget.cpp

    rdbc50ee rd5f420a  
    352352  connect(mpSimulationProcessThread, SIGNAL(sendSimulationStarted()), SLOT(simulationProcessStarted()));
    353353  connect(mpSimulationProcessThread, SIGNAL(sendEmbeddedServerReady()), SLOT(embeddedServerReady()));
    354   connect(mpSimulationProcessThread, SIGNAL(sendEmbeddedServerError(QString)), SLOT(embeddedServerError(QString)));
    355354  connect(mpSimulationProcessThread, SIGNAL(sendSimulationOutput(QString,StringHandler::SimulationMessageType,bool)),
    356355          SLOT(writeSimulationOutput(QString,StringHandler::SimulationMessageType,bool)));
     
    579578
    580579/*!
    581  * \brief SimulationOutputWidget::embeddedServerReady
    582  * Slot activated when SimulationProcessThread sendembeddedServerError signal is raised.\n
    583  * The provided port is unbound and can be used for communication between the client and remote.
    584  */
    585 void SimulationOutputWidget::embeddedServerError(QString error)
    586 {
    587   MainWindow::instance()->getSimulationDialog()->embeddedServerError(error);
    588 }
    589 
    590 /*!
    591580 * \brief SimulationOutputWidget::writeSimulationOutput
    592581 * Slot activated when SimulationProcessThread sendSimulationOutput signal is raised.\n
  • OMEdit/OMEditGUI/Simulation/SimulationOutputWidget.h

    rdbc50ee rd5f420a  
    119119  void simulationProcessStarted();
    120120  void embeddedServerReady();
    121   void embeddedServerError(QString error);
    122121  void writeSimulationOutput(QString output, StringHandler::SimulationMessageType type, bool textFormat);
    123122  void simulationProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
  • OMEdit/OMEditGUI/Simulation/SimulationProcessThread.cpp

    rdbc50ee rd5f420a  
    3636
    3737#include <QDir>
    38 #include <QTcpSocket>
    3938
    4039SimulationProcessThread::SimulationProcessThread(SimulationOutputWidget *pSimulationOutputWidget)
     
    236235
    237236  if (mpSimulationOutputWidget->getSimulationOptions().isInteractiveSimulation()) {
    238     // make sure that the embedded server is ready to be connected to
    239     int port = mpSimulationOutputWidget->getSimulationOptions().getInteractiveSimulationPortNumber();
    240     SimulationServerCheckThread *pEmbeddedServerCheckThread = new SimulationServerCheckThread(port);
    241     connect(pEmbeddedServerCheckThread, SIGNAL(sendEmbeddedServerReady()), this, SLOT(embeddedServerReady()));
    242     connect(pEmbeddedServerCheckThread, SIGNAL(sendEmbeddedServerError(QString)), this, SLOT(embeddedServerError(QString)));
    243     connect(pEmbeddedServerCheckThread, SIGNAL(finished()), pEmbeddedServerCheckThread, SLOT(deleteLater()));
    244     pEmbeddedServerCheckThread->start();
    245   }
    246 }
    247 
    248 /*!
    249  * \brief SimulationServerCheckThread::run
    250  * Raises the sendEmbeddedServerReady signal when the OPC UA server is ready to be connectd to. \n
    251  */
    252 void SimulationServerCheckThread::run()
    253 {
    254   QTcpSocket *pTcpSocket = new QTcpSocket;
    255   while (pTcpSocket->state() != QAbstractSocket::ConnectedState) {
    256     pTcpSocket->connectToHost(QHostAddress::LocalHost, mPort);
    257     msleep(10);
    258     if (pTcpSocket->waitForConnected()) {
    259       emit sendEmbeddedServerReady();
    260     }
    261   }
    262   // make the user aware of known socket errors
    263   if (pTcpSocket->error() && pTcpSocket->error() != QAbstractSocket::UnknownSocketError) {
    264     emit sendEmbeddedServerError(pTcpSocket->errorString());
    265   }
    266 }
    267 
    268 void SimulationProcessThread::embeddedServerReady()
    269 {
    270   emit sendEmbeddedServerReady();
    271 }
    272 
    273 void SimulationProcessThread::embeddedServerError(QString error)
    274 {
    275   // if, somehow, the client is unable to bind to the server over the specified port
    276   emit sendEmbeddedServerError(error);
     237    emit sendEmbeddedServerReady();
     238  }
    277239}
    278240
  • OMEdit/OMEditGUI/Simulation/SimulationProcessThread.h

    rdbc50ee rd5f420a  
    7878  void simulationProcessError(QProcess::ProcessError error);
    7979  void simulationProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
    80   void embeddedServerReady();
    81   void embeddedServerError(QString error);
    8280signals:
    8381  void sendCompilationStarted();
     
    8684  void sendSimulationStarted();
    8785  void sendEmbeddedServerReady();
    88   void sendEmbeddedServerError(QString);
    8986  void sendEstablishConnectionRunning();
    9087  void sendSimulationOutput(QString, StringHandler::SimulationMessageType type, bool);
     
    9289};
    9390
    94 class SimulationServerCheckThread : public QThread
    95 {
    96   Q_OBJECT
    97 public:
    98   SimulationServerCheckThread(int port)
    99     : mPort(port) {}
    100   ~SimulationServerCheckThread(){}
    101   virtual void run();
    102 private:
    103   int mPort;
    104 signals:
    105   void sendEmbeddedServerReady();
    106   void sendEmbeddedServerError(QString);
    107 };
    108 
    10991#endif // SIMULATIONPROCESSTHREAD_H
Note: See TracChangeset for help on using the changeset viewer.