mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4683 clang-format on all files in ApplicationCode
This commit is contained in:
@@ -3,17 +3,17 @@
|
||||
// Copyright (C) 2011- Statoil ASA
|
||||
// Copyright (C) 2013- Ceetron Solutions AS
|
||||
// Copyright (C) 2011-2012 Ceetron AS
|
||||
//
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -25,10 +25,10 @@
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "RimCase.h"
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimCase.h"
|
||||
|
||||
#include "RiuMainWindow.h"
|
||||
#include "RiuViewer.h"
|
||||
@@ -44,27 +44,26 @@
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaSocketServer::RiaSocketServer(QObject* parent)
|
||||
: QObject(parent),
|
||||
m_tcpServer(nullptr),
|
||||
m_currentClient(nullptr),
|
||||
m_currentCommandSize(0),
|
||||
m_currentCommand(nullptr),
|
||||
m_currentCaseId(-1)
|
||||
RiaSocketServer::RiaSocketServer( QObject* parent )
|
||||
: QObject( parent )
|
||||
, m_tcpServer( nullptr )
|
||||
, m_currentClient( nullptr )
|
||||
, m_currentCommandSize( 0 )
|
||||
, m_currentCommand( nullptr )
|
||||
, m_currentCaseId( -1 )
|
||||
{
|
||||
// TCP server setup
|
||||
|
||||
m_tcpServer = new QTcpServer(this);
|
||||
m_tcpServer = new QTcpServer( this );
|
||||
|
||||
m_nextPendingConnectionTimer = new QTimer(this);
|
||||
m_nextPendingConnectionTimer->setInterval(100);
|
||||
m_nextPendingConnectionTimer->setSingleShot(true);
|
||||
m_nextPendingConnectionTimer = new QTimer( this );
|
||||
m_nextPendingConnectionTimer->setInterval( 100 );
|
||||
m_nextPendingConnectionTimer->setSingleShot( true );
|
||||
|
||||
if (!m_tcpServer->listen(QHostAddress::LocalHost, 40001))
|
||||
if ( !m_tcpServer->listen( QHostAddress::LocalHost, 40001 ) )
|
||||
{
|
||||
QString txt;
|
||||
txt = "This instance of ResInsight could not start the Socket Server enabling octave to get and set data.\n "
|
||||
@@ -72,15 +71,15 @@ RiaSocketServer::RiaSocketServer(QObject* parent)
|
||||
"Octave can only communicate with one ResInsight process at a time, so the Octave\n"
|
||||
"communication in this ResInsight instance will be disabled.\n"
|
||||
"\n" +
|
||||
tr("The error from the socket system is: %1.").arg(m_tcpServer->errorString());
|
||||
tr( "The error from the socket system is: %1." ).arg( m_tcpServer->errorString() );
|
||||
|
||||
RiaLogging::error(txt);
|
||||
RiaLogging::error( txt );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_nextPendingConnectionTimer, SIGNAL(timeout()), this, SLOT(slotNewClientConnection()));
|
||||
connect(m_tcpServer, SIGNAL(newConnection()), this, SLOT(slotNewClientConnection()));
|
||||
connect( m_nextPendingConnectionTimer, SIGNAL( timeout() ), this, SLOT( slotNewClientConnection() ) );
|
||||
connect( m_tcpServer, SIGNAL( newConnection() ), this, SLOT( slotNewClientConnection() ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -88,7 +87,7 @@ RiaSocketServer::RiaSocketServer(QObject* parent)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiaSocketServer::~RiaSocketServer()
|
||||
{
|
||||
assert (m_currentCommand == nullptr);
|
||||
assert( m_currentCommand == nullptr );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -96,8 +95,10 @@ RiaSocketServer::~RiaSocketServer()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
unsigned short RiaSocketServer::serverPort()
|
||||
{
|
||||
if (m_tcpServer) return m_tcpServer->serverPort();
|
||||
else return 0;
|
||||
if ( m_tcpServer )
|
||||
return m_tcpServer->serverPort();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -105,27 +106,27 @@ unsigned short RiaSocketServer::serverPort()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSocketServer::slotNewClientConnection()
|
||||
{
|
||||
// If we are currently handling a connection, just ignore the new one until the current one is disconnected.
|
||||
// If we are currently handling a connection, just ignore the new one until the current one is disconnected.
|
||||
|
||||
if (m_currentClient && (m_currentClient->state() != QAbstractSocket::UnconnectedState) )
|
||||
if ( m_currentClient && ( m_currentClient->state() != QAbstractSocket::UnconnectedState ) )
|
||||
{
|
||||
//PMonLog("Starting Timer");
|
||||
// PMonLog("Starting Timer");
|
||||
m_nextPendingConnectionTimer->start(); // Reset and start again
|
||||
return;
|
||||
}
|
||||
|
||||
// Read pending data from socket
|
||||
|
||||
if (m_currentClient && m_currentCommand)
|
||||
if ( m_currentClient && m_currentCommand )
|
||||
{
|
||||
bool isFinshed = m_currentCommand->interpretMore(this, m_currentClient);
|
||||
bool isFinshed = m_currentCommand->interpretMore( this, m_currentClient );
|
||||
|
||||
if (!isFinshed)
|
||||
if ( !isFinshed )
|
||||
{
|
||||
QString txt;
|
||||
txt = "ResInsight SocketServer : The command did not finish up correctly at the presence of a new one.";
|
||||
|
||||
RiaLogging::error(txt);
|
||||
|
||||
RiaLogging::error( txt );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,32 +136,32 @@ void RiaSocketServer::slotNewClientConnection()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Find the requested reservoir by caseId
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEclipseCase* RiaSocketServer::findReservoir(int caseId)
|
||||
RimEclipseCase* RiaSocketServer::findReservoir( int caseId )
|
||||
{
|
||||
int currCaseId = caseId;
|
||||
if (caseId < 0)
|
||||
if ( caseId < 0 )
|
||||
{
|
||||
currCaseId = this->currentCaseId();
|
||||
}
|
||||
|
||||
if (currCaseId < 0)
|
||||
if ( currCaseId < 0 )
|
||||
{
|
||||
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>(RiaApplication::instance()->activeReservoirView());
|
||||
if (eclipseView)
|
||||
RimEclipseView* eclipseView = dynamic_cast<RimEclipseView*>( RiaApplication::instance()->activeReservoirView() );
|
||||
if ( eclipseView )
|
||||
{
|
||||
return eclipseView->eclipseCase();
|
||||
}
|
||||
|
||||
// If the active mdi window is different from an Eclipse view, search through available mdi windows to find the last activated
|
||||
// Eclipse view. The sub windows are returned with the most recent activated window at the back.
|
||||
QList<QMdiSubWindow*> subWindows = RiuMainWindow::instance()->subWindowList(QMdiArea::ActivationHistoryOrder);
|
||||
for (int i = subWindows.size() - 1; i > -1; i--)
|
||||
// If the active mdi window is different from an Eclipse view, search through available mdi windows to find the
|
||||
// last activated Eclipse view. The sub windows are returned with the most recent activated window at the back.
|
||||
QList<QMdiSubWindow*> subWindows = RiuMainWindow::instance()->subWindowList( QMdiArea::ActivationHistoryOrder );
|
||||
for ( int i = subWindows.size() - 1; i > -1; i-- )
|
||||
{
|
||||
RiuViewer* viewer = subWindows[i]->widget()->findChild<RiuViewer*>();
|
||||
if (viewer)
|
||||
if ( viewer )
|
||||
{
|
||||
RimEclipseView* riv = dynamic_cast<RimEclipseView*>(viewer->ownerReservoirView());
|
||||
if (riv)
|
||||
RimEclipseView* riv = dynamic_cast<RimEclipseView*>( viewer->ownerReservoirView() );
|
||||
if ( riv )
|
||||
{
|
||||
return riv->eclipseCase();
|
||||
}
|
||||
@@ -169,17 +170,17 @@ RimEclipseCase* RiaSocketServer::findReservoir(int caseId)
|
||||
}
|
||||
else
|
||||
{
|
||||
RimProject* project = RiaApplication::instance()->project();
|
||||
if (!project) return nullptr;
|
||||
RimProject* project = RiaApplication::instance()->project();
|
||||
if ( !project ) return nullptr;
|
||||
|
||||
std::vector<RimCase*> cases;
|
||||
project->allCases(cases);
|
||||
project->allCases( cases );
|
||||
|
||||
for (size_t i = 0; i < cases.size(); i++)
|
||||
for ( size_t i = 0; i < cases.size(); i++ )
|
||||
{
|
||||
if (cases[i]->caseId == currCaseId)
|
||||
if ( cases[i]->caseId == currCaseId )
|
||||
{
|
||||
return dynamic_cast<RimEclipseCase*>(cases[i]);
|
||||
return dynamic_cast<RimEclipseCase*>( cases[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,73 +195,73 @@ RimEclipseCase* RiaSocketServer::findReservoir(int caseId)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaSocketServer::readCommandFromOctave()
|
||||
{
|
||||
QDataStream socketStream(m_currentClient);
|
||||
socketStream.setVersion(riOctavePlugin::qtDataStreamVersion);
|
||||
QDataStream socketStream( m_currentClient );
|
||||
socketStream.setVersion( riOctavePlugin::qtDataStreamVersion );
|
||||
|
||||
// If we have not read the currentCommandSize
|
||||
// read the size of the command if all the data is available
|
||||
|
||||
if (m_currentCommandSize == 0)
|
||||
if ( m_currentCommandSize == 0 )
|
||||
{
|
||||
if (m_currentClient->bytesAvailable() < (int)sizeof(qint64)) return false;
|
||||
if ( m_currentClient->bytesAvailable() < (int)sizeof( qint64 ) ) return false;
|
||||
|
||||
socketStream >> m_currentCommandSize;
|
||||
}
|
||||
|
||||
// Check if the complete command is available, return and whait for readyRead() if not
|
||||
if (m_currentClient->bytesAvailable() < m_currentCommandSize) return false;
|
||||
if ( m_currentClient->bytesAvailable() < m_currentCommandSize ) return false;
|
||||
|
||||
// Now we can read the command name
|
||||
|
||||
QByteArray command = m_currentClient->read( m_currentCommandSize);
|
||||
QTextStream commandStream(command);
|
||||
QByteArray command = m_currentClient->read( m_currentCommandSize );
|
||||
QTextStream commandStream( command );
|
||||
|
||||
QList<QByteArray> args;
|
||||
while (!commandStream.atEnd())
|
||||
while ( !commandStream.atEnd() )
|
||||
{
|
||||
QByteArray arg;
|
||||
commandStream >> arg;
|
||||
args.push_back(arg);
|
||||
args.push_back( arg );
|
||||
}
|
||||
|
||||
CVF_ASSERT(args.size() > 0);
|
||||
CVF_ASSERT( args.size() > 0 );
|
||||
|
||||
// Create the actual RiaSocketCommand object that will interpret the socket data
|
||||
|
||||
m_currentCommand = RiaSocketCommandFactory::instance()->create(args[0]);
|
||||
m_currentCommand = RiaSocketCommandFactory::instance()->create( args[0] );
|
||||
|
||||
if (m_currentCommand)
|
||||
if ( m_currentCommand )
|
||||
{
|
||||
bool finished = m_currentCommand->interpretCommand(this, args, socketStream);
|
||||
bool finished = m_currentCommand->interpretCommand( this, args, socketStream );
|
||||
return finished;
|
||||
}
|
||||
else
|
||||
{
|
||||
QString txt;
|
||||
txt = QString("ResInsight SocketServer: Unknown command: %1").arg(args[0].data());
|
||||
txt = QString( "ResInsight SocketServer: Unknown command: %1" ).arg( args[0].data() );
|
||||
|
||||
RiaLogging::error(txt);
|
||||
RiaLogging::error( txt );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSocketServer::slotCurrentClientDisconnected()
|
||||
{
|
||||
if (m_currentCommand)
|
||||
if ( m_currentCommand )
|
||||
{
|
||||
// Make sure we read what can be read.
|
||||
bool isFinished = m_currentCommand->interpretMore(this, m_currentClient);
|
||||
bool isFinished = m_currentCommand->interpretMore( this, m_currentClient );
|
||||
|
||||
if (!isFinished)
|
||||
if ( !isFinished )
|
||||
{
|
||||
QString txt;
|
||||
txt = QString("ResInsight SocketServer: The command was interrupted and did not finish because the connection to octave disconnected.");
|
||||
txt = QString( "ResInsight SocketServer: The command was interrupted and did not finish because the "
|
||||
"connection to octave disconnected." );
|
||||
|
||||
RiaLogging::error(txt);
|
||||
RiaLogging::error( txt );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,11 +273,11 @@ void RiaSocketServer::slotCurrentClientDisconnected()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSocketServer::slotReadyRead()
|
||||
{
|
||||
if (m_currentCommand)
|
||||
if ( m_currentCommand )
|
||||
{
|
||||
bool isFinished = m_currentCommand->interpretMore(this, m_currentClient);
|
||||
bool isFinished = m_currentCommand->interpretMore( this, m_currentClient );
|
||||
|
||||
if (isFinished)
|
||||
if ( isFinished )
|
||||
{
|
||||
handleNextPendingConnection();
|
||||
}
|
||||
@@ -284,7 +285,7 @@ void RiaSocketServer::slotReadyRead()
|
||||
else
|
||||
{
|
||||
bool isFinished = readCommandFromOctave();
|
||||
if (isFinished)
|
||||
if ( isFinished )
|
||||
{
|
||||
handleNextPendingConnection();
|
||||
}
|
||||
@@ -292,15 +293,15 @@ void RiaSocketServer::slotReadyRead()
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSocketServer::setCurrentCaseId(int caseId)
|
||||
void RiaSocketServer::setCurrentCaseId( int caseId )
|
||||
{
|
||||
m_currentCaseId = caseId;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
int RiaSocketServer::currentCaseId() const
|
||||
{
|
||||
@@ -310,9 +311,9 @@ int RiaSocketServer::currentCaseId() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSocketServer::showErrorMessage(const QString& message) const
|
||||
void RiaSocketServer::showErrorMessage( const QString& message ) const
|
||||
{
|
||||
RiaLogging::error(message);
|
||||
RiaLogging::error( message );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -320,63 +321,62 @@ void RiaSocketServer::showErrorMessage(const QString& message) const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSocketServer::terminateCurrentConnection()
|
||||
{
|
||||
if (m_currentClient)
|
||||
if ( m_currentClient )
|
||||
{
|
||||
m_currentClient->disconnect(SIGNAL(disconnected()));
|
||||
m_currentClient->disconnect(SIGNAL(readyRead()));
|
||||
m_currentClient->disconnect( SIGNAL( disconnected() ) );
|
||||
m_currentClient->disconnect( SIGNAL( readyRead() ) );
|
||||
m_currentClient->deleteLater();
|
||||
m_currentClient = nullptr;
|
||||
}
|
||||
|
||||
// Clean up more state:
|
||||
|
||||
if (m_currentCommand)
|
||||
if ( m_currentCommand )
|
||||
{
|
||||
delete m_currentCommand;
|
||||
m_currentCommand = nullptr;
|
||||
}
|
||||
|
||||
m_currentCommandSize = 0;
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaSocketServer::handleNextPendingConnection()
|
||||
{
|
||||
if (m_currentClient && (m_currentClient->state() != QAbstractSocket::UnconnectedState) )
|
||||
if ( m_currentClient && ( m_currentClient->state() != QAbstractSocket::UnconnectedState ) )
|
||||
{
|
||||
//PMonLog("Starting Timer");
|
||||
// PMonLog("Starting Timer");
|
||||
m_nextPendingConnectionTimer->start(); // Reset and start again
|
||||
return;
|
||||
}
|
||||
|
||||
// Stop timer
|
||||
if (m_nextPendingConnectionTimer->isActive())
|
||||
{
|
||||
//PMonLog("Stopping Timer");
|
||||
if ( m_nextPendingConnectionTimer->isActive() )
|
||||
{
|
||||
// PMonLog("Stopping Timer");
|
||||
m_nextPendingConnectionTimer->stop();
|
||||
}
|
||||
|
||||
terminateCurrentConnection();
|
||||
|
||||
QTcpSocket* clientToHandle = m_tcpServer->nextPendingConnection();
|
||||
if (clientToHandle)
|
||||
if ( clientToHandle )
|
||||
{
|
||||
CVF_ASSERT(m_currentClient == nullptr);
|
||||
CVF_ASSERT(m_currentCommand == nullptr);
|
||||
CVF_ASSERT( m_currentClient == nullptr );
|
||||
CVF_ASSERT( m_currentCommand == nullptr );
|
||||
|
||||
m_currentClient = clientToHandle;
|
||||
m_currentClient = clientToHandle;
|
||||
m_currentCommandSize = 0;
|
||||
|
||||
connect(m_currentClient, SIGNAL(disconnected()), this, SLOT(slotCurrentClientDisconnected()));
|
||||
connect(m_currentClient, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
|
||||
connect( m_currentClient, SIGNAL( disconnected() ), this, SLOT( slotCurrentClientDisconnected() ) );
|
||||
connect( m_currentClient, SIGNAL( readyRead() ), this, SLOT( slotReadyRead() ) );
|
||||
|
||||
if (m_currentClient->bytesAvailable())
|
||||
if ( m_currentClient->bytesAvailable() )
|
||||
{
|
||||
bool isFinished = this->readCommandFromOctave();
|
||||
if (isFinished)
|
||||
if ( isFinished )
|
||||
{
|
||||
// Call ourselves recursively until there are none left, or until it can not be processed in one go.
|
||||
this->handleNextPendingConnection();
|
||||
@@ -384,4 +384,3 @@ void RiaSocketServer::handleNextPendingConnection()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user