Skip to content

Commit

Permalink
made some updates on OMS communication with OMC.
Browse files Browse the repository at this point in the history
// Anders Fernström

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2071 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x05andfe committed Feb 2, 2006
1 parent 1fe3c6f commit 7c32f99
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 19 deletions.
1 change: 1 addition & 0 deletions OMS/inputcelldelegate.h
Expand Up @@ -70,6 +70,7 @@ namespace IAEX
public:
virtual QString getResult() = 0;
virtual void evalExpression(QString &expr) = 0;
virtual void closeConnection() = 0; // Added 2006-02-02 AF
};

}
Expand Down
18 changes: 7 additions & 11 deletions OMS/omc_communicator.cpp
Expand Up @@ -169,6 +169,8 @@ bool OmcCommunicator::isConnected() const
*/
void OmcCommunicator::closeConnection()
{
// 2006-02-02 AF, added this code:
omc_ = 0;
}


Expand All @@ -183,7 +185,10 @@ QString OmcCommunicator::callOmc(const QString& fnCall)
{
if (!omc_) {
//throw OmcError(fnCall);
cerr << "OmcError(" << fnCall.toStdString() << ")" << endl;

// 2006-02-02 AF, Added throw exception
string msg = string("OMC-ERROR in function call: ") + fnCall.toStdString();
throw exception( msg.c_str() );
}

QString returnString;
Expand All @@ -196,16 +201,7 @@ QString OmcCommunicator::callOmc(const QString& fnCall)
{
if( fnCall != "quit()" && fnCall != "quit();" )
{
int result(QMessageBox::critical(0, tr("Communication Error"),
tr("<NOBR><B>The Modelica kernel is not responding.</B>"), tr("Try Again"), tr("Abort")));
qApp->processEvents();
if (result == 1) {
QMessageBox::critical(0, tr("Communication Error"),
tr("<NOBR><B>Connection to the Modelica kernel lost.</B><BR><BR>The editor has to be restarted.", "Quit"));
qApp->processEvents();
//throw OmcConnectionLost();
cerr << "OmcConnectionLost()" << endl;
}
throw exception("NOT RESPONDING");
}
else
break;
Expand Down
15 changes: 14 additions & 1 deletion OMS/omcinteractiveenvironment.cpp
Expand Up @@ -80,6 +80,19 @@ namespace IAEX

void OmcInteractiveEnvironment::evalExpression(QString &expr)
{
result_ = comm_.callOmc(expr);
// 2006-02-02 AF, Added try-catch
try
{
result_ = comm_.callOmc(expr);
}
catch( exception &e )
{
throw e;
}
}

void OmcInteractiveEnvironment::closeConnection()
{
comm_.closeConnection();
}
}
1 change: 1 addition & 0 deletions OMS/omcinteractiveenvironment.h
Expand Up @@ -63,6 +63,7 @@ namespace IAEX

virtual QString getResult();
virtual void evalExpression(QString &expr);
virtual void closeConnection(); // Added 2006-02-02 AF
private:
OmcCommunicator &comm_;
QString result_;
Expand Down
66 changes: 60 additions & 6 deletions OMS/oms.cpp
Expand Up @@ -613,7 +613,18 @@ void OMS::returnPressed()
// send command to OMC
if( delegate_ )
{
delegate_->evalExpression( commandText );
// 2006-02-02 AF, Added try-catch
try
{
delegate_->evalExpression( commandText );
}
catch( exception &e )
{
exceptionInEval(e);
return;
}

// get result
QString res = delegate_->getResult();

if( res.isEmpty() )
Expand All @@ -622,12 +633,20 @@ void OMS::returnPressed()
cursor_.insertText( "\n" + res + "\n" );

// get Error text
delegate_->evalExpression( QString("getErrorString()") );
try
{
delegate_->evalExpression( QString("getErrorString()") );
}
catch( exception &e )
{
exceptionInEval(e);
return;
}
QString error = delegate_->getResult();
if( error.size() > 2 )
{
QTextCursor errorCursor = moshError_->textCursor();
errorCursor.insertText( error.mid( 1, error.size() - 3 ) + "\n" );
errorCursor.insertText( error.mid( 0, error.size() - 1 ) + "\n" );
}
}
else
Expand All @@ -640,6 +659,38 @@ void OMS::returnPressed()
addCommandLine();
}

void OMS::exceptionInEval(exception &e)
{
if( string(e.what()) == string("NOT RESPONDING") )
{
int result = QMessageBox::critical( 0, tr("Communication Error"),
tr("<B>OMC is not responding. Do you want to restart OMC?</B>"),
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::No );

if( result == QMessageBox::No )
{
exit();
}
else
{
delegate_->closeConnection();
delete delegate_;
delegate_ = 0;
if( startServer() )
{
prevCommand();
returnPressed();
}
}
}
else
{
QMessageBox::critical( 0, tr("Communication with OMC error"),
e.what() );
}
}

void OMS::insertNewline()
{
cursor_ = moshEdit_->textCursor();
Expand Down Expand Up @@ -915,15 +966,16 @@ void OMS::print()
// TODO: Implement print
}

void OMS::startServer()
bool OMS::startServer()
{
bool omcNowStarted = false;

if( delegate_ == 0 )
{

bool omcNowStarted = false;
try
{
delegate_ = new IAEX::OmcInteractiveEnvironment();
omcNowStarted = true;
}
catch( exception &e )
{
Expand Down Expand Up @@ -976,6 +1028,8 @@ void OMS::startServer()
if( omcNowStarted )
delegate_ = new IAEX::OmcInteractiveEnvironment();
}

return omcNowStarted;
}

void OMS::stopServer()
Expand Down
3 changes: 2 additions & 1 deletion OMS/oms.h
Expand Up @@ -105,7 +105,7 @@ public slots:
void viewStatusbar();
void aboutOMS();
void print();
void startServer();
bool startServer();
void stopServer();
void clear();

Expand All @@ -115,6 +115,7 @@ public slots:
void createAction();
void createMenu();
void createToolbar();
void exceptionInEval(exception &e);
void addCommandLine();
void selectCommandLine();
QStringList getFunctionNames(QString);
Expand Down

0 comments on commit 7c32f99

Please sign in to comment.