Skip to content

Commit

Permalink
propagate threadData from main.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Feb 1, 2018
1 parent eeba7bb commit f476a5d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
13 changes: 11 additions & 2 deletions OMShell/OMShellGUI/main.cpp
Expand Up @@ -51,6 +51,12 @@
#include "omcinteractiveenvironment.h"
#include <stdio.h>

#define GC_THREADS

extern "C" {
#include "meta/meta_modelica.h"
}

#define CONSUME_CHAR(value,res,i) \
if (value.at(i) == '\\') { \
i++; \
Expand Down Expand Up @@ -89,10 +95,11 @@ QString unparse(QString value)
int main(int argc, char *argv[])
{
MMC_INIT();
MMC_TRY_TOP()

QApplication app(argc, argv);

IAEX::OmcInteractiveEnvironment *env = IAEX::OmcInteractiveEnvironment::getInstance();
IAEX::OmcInteractiveEnvironment *env = IAEX::OmcInteractiveEnvironment::getInstance(threadData);
env->evalExpression("getInstallationDirectoryPath()");
QString dir = unparse(env->getResult()) + "/share/omshell/nls";
QString locale = QString("OMShell_") + QLocale::system().name();
Expand All @@ -111,12 +118,14 @@ int main(int argc, char *argv[])
QString cdRes = env->getResult();
cdRes.remove("\"");
if (0 != tmpDir.compare(cdRes)) {
QMessageBox::critical( 0, "OpenModelica Error", QString("Could not create or cd to temp-dir\nCommand:\n %1\nReturned:\n %2").arg(tmpDir).arg(cdRes));
QMessageBox::critical( 0, "OpenModelica Error", QString("Could not create or cd to temp-dir\nCommand:\n %1\nReturned:\n %2").arg(cdCmd).arg(cdRes));
exit(1);
}

OMS oms;
oms.show();

return app.exec();

MMC_CATCH_TOP();
}
16 changes: 8 additions & 8 deletions OMShell/OMShellGUI/omcinteractiveenvironment.cpp
Expand Up @@ -62,6 +62,7 @@ void (*omc_terminate)(FILE_INFO info,const char *msg,...) = omc_terminate_functi
void (*omc_throw)(threadData_t*) __attribute__ ((noreturn)) = omc_throw_function;
int omc_Main_handleCommand(void *threadData, void *imsg, void **omsg);
void* omc_Main_init(void *threadData, void *args);
void omc_System_initGarbageCollector(void *threadData);
#ifdef WIN32
void omc_Main_setWindowsPaths(threadData_t *threadData, void* _inOMHome);
#endif
Expand All @@ -70,11 +71,11 @@ void omc_Main_setWindowsPaths(threadData_t *threadData, void* _inOMHome);
namespace IAEX
{
OmcInteractiveEnvironment* OmcInteractiveEnvironment::selfInstance = NULL;
OmcInteractiveEnvironment* OmcInteractiveEnvironment::getInstance()
OmcInteractiveEnvironment* OmcInteractiveEnvironment::getInstance(threadData_t *threadData)
{
if (selfInstance == NULL)
{
selfInstance = new OmcInteractiveEnvironment();
selfInstance = new OmcInteractiveEnvironment(threadData);
}
return selfInstance;
}
Expand All @@ -83,7 +84,7 @@ namespace IAEX
*
* \brief Implements evaluation for modelica code.
*/
OmcInteractiveEnvironment::OmcInteractiveEnvironment():result_(""),error_("")
OmcInteractiveEnvironment::OmcInteractiveEnvironment(threadData_t *threadData):threadData_(threadData),result_(""),error_("")
{
// set the language by reading the OMEdit settings file.
QSettings settings(QSettings::IniFormat, QSettings::UserScope, "openmodelica", "omedit");
Expand All @@ -92,14 +93,13 @@ namespace IAEX
void *args = mmc_mk_nil();
QString locale = "+locale=" + settingsLocale.name();
args = mmc_mk_cons(mmc_mk_scon(locale.toStdString().c_str()), args);
// initialize threadData
threadData_t *threadData = (threadData_t *) GC_malloc_uncollectable(sizeof(threadData_t));
// initialize garbage collector
omc_System_initGarbageCollector(NULL);
MMC_TRY_TOP_INTERNAL()
omc_Main_init(threadData, args);
threadData->plotClassPointer = 0;
threadData->plotCB = 0;
MMC_CATCH_TOP()
threadData_ = threadData;
threadData_->plotClassPointer = 0;
threadData_->plotCB = 0;
// set the +d=initialization flag default.
evalExpression(QString("setCommandLineOptions(\"+d=initialization\")"));
#ifdef WIN32
Expand Down
4 changes: 2 additions & 2 deletions OMShell/OMShellGUI/omcinteractiveenvironment.h
Expand Up @@ -42,13 +42,13 @@ namespace IAEX
class OmcInteractiveEnvironment
{
private:
OmcInteractiveEnvironment();
OmcInteractiveEnvironment(threadData_t *threadData);
virtual ~OmcInteractiveEnvironment();

public:
threadData_t *threadData_;

static OmcInteractiveEnvironment* getInstance();
static OmcInteractiveEnvironment* getInstance(threadData_t *threadData = 0);
virtual QString getResult();
virtual QString getError();
virtual int getErrorLevel();
Expand Down

0 comments on commit f476a5d

Please sign in to comment.