mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4416 First implementation of gRPC-based Python interface
First implementation with Asynchronous gRPC server, a few services and some client python code.
This commit is contained in:
@@ -1292,6 +1292,36 @@ cvf::Font* RiaApplication::defaultWellLabelFont()
|
||||
return m_defaultWellLabelFont.p();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaApplication::initializeGrpcServer(const cvf::ProgramOptions& progOpt)
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
if (!m_preferences->enableGrpcServer()) return false;
|
||||
|
||||
int defaultPortNumber = m_preferences->defaultGrpcPortNumber();
|
||||
bool fixedPort = false;
|
||||
if (cvf::Option o = progOpt.option("grpcserver"))
|
||||
{
|
||||
if (o.valueCount() == 1)
|
||||
{
|
||||
defaultPortNumber = o.value(0).toInt(defaultPortNumber);
|
||||
fixedPort = true;
|
||||
}
|
||||
}
|
||||
int portNumber = defaultPortNumber;
|
||||
if (!fixedPort)
|
||||
{
|
||||
portNumber = RiaGrpcServer::findAvailablePortNumber(defaultPortNumber);
|
||||
}
|
||||
m_grpcServer.reset(new RiaGrpcServer(portNumber));
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "RiaDefines.h"
|
||||
#ifdef ENABLE_GRPC
|
||||
#include "RiaGrpcServer.h"
|
||||
#endif
|
||||
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
@@ -93,7 +96,7 @@ public:
|
||||
EXIT_COMPLETED,
|
||||
EXIT_WITH_ERROR
|
||||
};
|
||||
|
||||
|
||||
public:
|
||||
static RiaApplication* instance();
|
||||
RiaApplication();
|
||||
@@ -171,6 +174,8 @@ public:
|
||||
cvf::Font* defaultAnnotationFont();
|
||||
cvf::Font* defaultWellLabelFont();
|
||||
|
||||
bool initializeGrpcServer(const cvf::ProgramOptions& progOpt);
|
||||
|
||||
// Public implementation specific overrides
|
||||
virtual void initialize();
|
||||
virtual ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) = 0;
|
||||
@@ -178,8 +183,7 @@ public:
|
||||
virtual void addToRecentFiles(const QString& fileName) {}
|
||||
virtual void showInformationMessage(const QString& infoText) = 0;
|
||||
virtual void showErrorMessage(const QString& errMsg) = 0;
|
||||
virtual void cleanupBeforeProgramExit() {}
|
||||
|
||||
virtual void launchGrpcServer() = 0;
|
||||
protected:
|
||||
// Protected implementation specific overrides
|
||||
virtual void invokeProcessEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents) = 0;
|
||||
@@ -203,11 +207,14 @@ protected:
|
||||
RiaSocketServer* m_socketServer;
|
||||
caf::UiProcess* m_workerProcess;
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
std::unique_ptr<RiaGrpcServer> m_grpcServer;
|
||||
#endif
|
||||
|
||||
// Execute for all settings
|
||||
std::list<int> m_currentCaseIds;
|
||||
QString m_currentProgram;
|
||||
QStringList m_currentArguments;
|
||||
|
||||
RiaPreferences* m_preferences;
|
||||
|
||||
std::map<QString, QString> m_fileDialogDefaultDirectories;
|
||||
|
||||
@@ -339,6 +339,16 @@ void RiaConsoleApplication::showErrorMessage(const QString& errMsg)
|
||||
RiaLogging::error(errMsg);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaConsoleApplication::launchGrpcServer()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
m_grpcServer->run();
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -41,7 +41,7 @@ public:
|
||||
ApplicationStatus handleArguments(cvf::ProgramOptions* progOpt) override;
|
||||
void showInformationMessage(const QString& text) override;
|
||||
void showErrorMessage(const QString& errMsg) override;
|
||||
|
||||
void launchGrpcServer() override;
|
||||
protected:
|
||||
// Protected implementation specific overrides
|
||||
void invokeProcessEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents) override;
|
||||
|
||||
@@ -170,6 +170,15 @@ namespace RiaDefines
|
||||
ImportFileType obtainFileTypeFromFileName(const QString& fileName);
|
||||
QString defaultDirectoryLabel(ImportFileType fileTypes);
|
||||
|
||||
enum CaseType
|
||||
{
|
||||
ECLIPSE_RESULT_CASE = 1,
|
||||
ECLIPSE_INPUT_CASE = 2,
|
||||
ECLIPSE_STAT_CASE = 3,
|
||||
ECLIPSE_SOURCE_CASE = 4,
|
||||
GEOMECH_ODB_CASE = 5
|
||||
};
|
||||
|
||||
enum FontSettingType
|
||||
{
|
||||
SCENE_FONT,
|
||||
|
||||
@@ -178,13 +178,11 @@ RiaGuiApplication::RiaGuiApplication(int& argc, char** argv)
|
||||
, m_mainWindow(nullptr)
|
||||
, m_mainPlotWindow(nullptr)
|
||||
{
|
||||
// For idle processing
|
||||
// m_idleTimerStarted = false;
|
||||
installEventFilter(this);
|
||||
|
||||
setWindowIcon(QIcon(":/AppLogo48x48.png"));
|
||||
|
||||
m_recentFileActionProvider = std::unique_ptr<RiuRecentFileActionProvider>(new RiuRecentFileActionProvider);
|
||||
|
||||
connect(this, SIGNAL(aboutToQuit()), this, SLOT(onProgramExit()));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -571,8 +569,8 @@ void RiaGuiApplication::initialize()
|
||||
|
||||
RiaLogging::setLoggerInstance(new RiuMessagePanelLogger(m_mainWindow->messagePanel()));
|
||||
RiaLogging::loggerInstance()->setLevel(RI_LL_DEBUG);
|
||||
|
||||
m_socketServer = new RiaSocketServer(this);
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1231,6 +1229,19 @@ void RiaGuiApplication::showErrorMessage(const QString& errMsg)
|
||||
errDialog.showMessage(errMsg);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::launchGrpcServer()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
m_grpcServer->runInThread();
|
||||
m_idleTimer = new QTimer(this);
|
||||
connect(m_idleTimer, SIGNAL(timeout()), this, SLOT(runIdleProcessing()));
|
||||
m_idleTimer->start(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1367,10 +1378,14 @@ void RiaGuiApplication::onProjectClosed()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::cleanupBeforeProgramExit()
|
||||
void RiaGuiApplication::onProgramExit()
|
||||
{
|
||||
closeAllWindows();
|
||||
invokeProcessEvents();
|
||||
#ifdef ENABLE_GRPC
|
||||
if (m_grpcServer)
|
||||
{
|
||||
m_grpcServer->quit();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1575,6 +1590,27 @@ void RiaGuiApplication::applyGuiPreferences(const RiaPreferences* oldPreferences
|
||||
caf::PdmUiItem::enableExtraDebugText(m_preferences->appendFieldKeywordToToolTipText());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::updateGrpcServer()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
bool isGrpcRunning = m_grpcServer != nullptr && m_grpcServer->isRunning();
|
||||
bool shouldItBeRunning = m_preferences->enableGrpcServer();
|
||||
if (isGrpcRunning && !shouldItBeRunning)
|
||||
{
|
||||
m_grpcServer->quit();
|
||||
}
|
||||
else if (!isGrpcRunning && shouldItBeRunning)
|
||||
{
|
||||
int portNumber = RiaGrpcServer::findAvailablePortNumber(m_preferences->defaultGrpcPortNumber());
|
||||
m_grpcServer.reset(new RiaGrpcServer(portNumber));
|
||||
m_grpcServer->runInThread();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1637,6 +1673,19 @@ void RiaGuiApplication::slotWorkerProcessFinished(int exitCode, QProcess::ExitSt
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaGuiApplication::runIdleProcessing()
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
if (!caf::ProgressInfoStatic::isRunning())
|
||||
{
|
||||
m_grpcServer->processOneRequest();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMutex>
|
||||
#include <QPointer>
|
||||
#include <QProcess>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
@@ -121,6 +123,7 @@ public:
|
||||
|
||||
static void clearAllSelections();
|
||||
void applyGuiPreferences(const RiaPreferences* oldPreferences = nullptr);
|
||||
void updateGrpcServer();
|
||||
|
||||
// Public RiaApplication overrides
|
||||
void initialize() override;
|
||||
@@ -129,7 +132,7 @@ public:
|
||||
void addToRecentFiles(const QString& fileName) override;
|
||||
void showInformationMessage(const QString& text) override;
|
||||
void showErrorMessage(const QString& errMsg) override;
|
||||
void cleanupBeforeProgramExit() override;
|
||||
void launchGrpcServer() override;
|
||||
protected:
|
||||
// Protected RiaApplication overrides
|
||||
void invokeProcessEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents) override;
|
||||
@@ -142,7 +145,7 @@ protected:
|
||||
void startMonitoringWorkProgress(caf::UiProcess* uiProcess) override;
|
||||
void stopMonitoringWorkProgress() override;
|
||||
|
||||
private:
|
||||
private:
|
||||
void setWindowCaptionFromAppState();
|
||||
|
||||
void createMainWindow();
|
||||
@@ -159,11 +162,16 @@ private:
|
||||
|
||||
private slots:
|
||||
void slotWorkerProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
void runIdleProcessing();
|
||||
void onProgramExit();
|
||||
|
||||
private:
|
||||
RiuMainWindow* m_mainWindow;
|
||||
RiuPlotMainWindow* m_mainPlotWindow;
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
QPointer<QTimer> m_idleTimer;
|
||||
#endif
|
||||
|
||||
std::unique_ptr<RiuRecentFileActionProvider> m_recentFileActionProvider;
|
||||
|
||||
std::unique_ptr<RiuMdiMaximizeWindowGuard> m_maximizeWindowGuard;
|
||||
|
||||
@@ -41,11 +41,11 @@ int main(int argc, char *argv[])
|
||||
RiaLogging::loggerInstance()->setLevel(RI_LL_DEBUG);
|
||||
|
||||
std::unique_ptr<RiaApplication> app (createApplication(argc, argv));
|
||||
app->initialize();
|
||||
|
||||
cvf::ProgramOptions progOpt;
|
||||
bool result = RiaArgumentParser::parseArguments(&progOpt);
|
||||
|
||||
bool result = RiaArgumentParser::parseArguments(&progOpt);
|
||||
app->initialize();
|
||||
|
||||
if (!result)
|
||||
{
|
||||
@@ -60,7 +60,6 @@ int main(int argc, char *argv[])
|
||||
app->showErrorMessage(RiaApplication::commandLineParameterHelp() +
|
||||
cvfqt::Utils::toQString(usageText) +
|
||||
unknownOptionsText.join("\n"));
|
||||
app->cleanupBeforeProgramExit();
|
||||
if (dynamic_cast<RiaGuiApplication*>(app.get()) == nullptr)
|
||||
{
|
||||
return 1;
|
||||
@@ -84,6 +83,10 @@ int main(int argc, char *argv[])
|
||||
int exitCode = 0;
|
||||
try
|
||||
{
|
||||
if (app->initializeGrpcServer(progOpt))
|
||||
{
|
||||
app->launchGrpcServer();
|
||||
}
|
||||
exitCode = QCoreApplication::instance()->exec();
|
||||
}
|
||||
catch (std::exception& exep )
|
||||
|
||||
@@ -51,6 +51,9 @@ RiaPreferences::RiaPreferences(void)
|
||||
{
|
||||
CAF_PDM_InitField(&navigationPolicy, "navigationPolicy", caf::AppEnum<RiaGuiApplication::RINavigationPolicy>(RiaGuiApplication::NAVIGATION_POLICY_RMS), "Navigation Mode", "", "", "");
|
||||
|
||||
CAF_PDM_InitField(&enableGrpcServer, "enableGrpcServer", true, "Enable gRPC script server", "", "Remote Procedure Call Scripting Engine", "");
|
||||
CAF_PDM_InitField(&defaultGrpcPortNumber, "defaultGrpcPort", 50051, "Default gRPC port", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&scriptDirectories, "scriptDirectory", "Shared Script Folder(s)", "", "", "");
|
||||
scriptDirectories.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName());
|
||||
|
||||
@@ -129,7 +132,7 @@ RiaPreferences::RiaPreferences(void)
|
||||
|
||||
m_tabNames << "General";
|
||||
m_tabNames << "Eclipse";
|
||||
m_tabNames << "Octave";
|
||||
m_tabNames << "Scripting";
|
||||
if (RiaApplication::enableDevelopmentFeatures())
|
||||
{
|
||||
m_tabNames << "System";
|
||||
@@ -245,6 +248,12 @@ void RiaPreferences::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering&
|
||||
}
|
||||
else if (uiConfigName == m_tabNames[2])
|
||||
{
|
||||
#ifdef ENABLE_GRPC
|
||||
caf::PdmUiGroup* grpcGroup = uiOrdering.addNewGroup("gRPC Server");
|
||||
grpcGroup->add(&enableGrpcServer);
|
||||
grpcGroup->add(&defaultGrpcPortNumber);
|
||||
#endif
|
||||
|
||||
caf::PdmUiGroup* octaveGroup = uiOrdering.addNewGroup("Octave");
|
||||
octaveGroup->add(&octaveExecutable);
|
||||
octaveGroup->add(&octaveShowHeaderInfoWhenExecutingScripts);
|
||||
|
||||
@@ -68,6 +68,9 @@ public:
|
||||
public: // Pdm Fields
|
||||
caf::PdmField<caf::AppEnum< RiaGuiApplication::RINavigationPolicy > > navigationPolicy;
|
||||
|
||||
caf::PdmField<bool> enableGrpcServer;
|
||||
caf::PdmField<int> defaultGrpcPortNumber;
|
||||
|
||||
caf::PdmField<QString> scriptDirectories;
|
||||
caf::PdmField<QString> scriptEditorExecutable;
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
bool RiaArgumentParser::parseArguments(cvf::ProgramOptions* progOpt)
|
||||
{
|
||||
CVF_ASSERT(progOpt);
|
||||
progOpt->registerOption("grpcserver", "[<portnumber>]", "Run as a GRPC server. Default port is 50051", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
progOpt->registerOption("console", "", "Run as a console application without Graphics");
|
||||
progOpt->registerOption("last", "", "Open last used project.");
|
||||
progOpt->registerOption("project", "<filename>", "Open project file <filename>.", cvf::ProgramOptions::SINGLE_VALUE);
|
||||
|
||||
Reference in New Issue
Block a user