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 860a012 commit 9f05bfe
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
10 changes: 6 additions & 4 deletions OMNotebook/OMNotebookGUI/cellapplication.cpp
Expand Up @@ -49,8 +49,6 @@

#include <cstdlib>

#include "omc_config.h"

namespace IAEX
{
/*!
Expand Down Expand Up @@ -111,7 +109,7 @@ namespace IAEX
}
};

CellApplication::CellApplication( int &argc, char *argv[] )
CellApplication::CellApplication(int &argc, char *argv[], threadData_t *threadData)
: QObject()
{
app_ = new MyApp(argc, argv, this);
Expand Down Expand Up @@ -151,6 +149,11 @@ namespace IAEX
/* Force C-style doubles */
setlocale(LC_NUMERIC, "C");

/* Don't move this line
* Is importat for threadData initialization
*/
OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance(threadData);

// 2006-04-10 AF, use environment variable to find xml files
QString openmodelica = OmcInteractiveEnvironment::OpenModelicaHome();

Expand All @@ -161,7 +164,6 @@ namespace IAEX
}

// Avoid cluttering the whole disk with omc temp-files
OmcInteractiveEnvironment *env = OmcInteractiveEnvironment::getInstance();
env->evalExpression("setCommandLineOptions(\"+d=shortOutput\")");
QString cmdLine = env->getResult();
//cout << "Set shortOutput flag: " << cmdLine.toStdString() << std::endl;
Expand Down
8 changes: 7 additions & 1 deletion OMNotebook/OMNotebookGUI/cellapplication.h
Expand Up @@ -59,14 +59,20 @@
#include "documentview.h"
#include "xmlnodename.h"

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

namespace IAEX
{

class CellApplication : public QObject, public Application
{
Q_OBJECT
public:
CellApplication(int &argc, char *argv[]);
CellApplication(int &argc, char *argv[], threadData_t *threadData);
virtual ~CellApplication();

virtual CommandCenter *commandCenter();
Expand Down
14 changes: 7 additions & 7 deletions OMNotebook/OMNotebookGUI/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 @@ -72,11 +73,11 @@ using namespace std;
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 @@ -85,7 +86,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 @@ -94,14 +95,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);
MMC_CATCH_TOP()
threadData_ = threadData;
threadData_->plotClassPointer = 0;
threadData_->plotCB = 0;
MMC_CATCH_TOP()
// set the +d=initialization flag default.
evalExpression(QString("setCommandLineOptions(\"+d=initialization\")"));
#ifdef WIN32
Expand Down
4 changes: 2 additions & 2 deletions OMNotebook/OMNotebookGUI/omcinteractiveenvironment.h
Expand Up @@ -43,13 +43,13 @@ namespace IAEX
class OmcInteractiveEnvironment : public InputCellDelegate
{
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
10 changes: 9 additions & 1 deletion OMNotebook/OMNotebookGUI/qtapp.cpp
Expand Up @@ -60,7 +60,12 @@
#include <sys/time.h>
#endif

#define GC_THREADS

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

#include <locale.h>

using namespace std;
Expand All @@ -81,10 +86,11 @@ int main(int argc, char *argv[])
#endif

MMC_INIT();
MMC_TRY_TOP()

try
{
CellApplication a(argc, argv);
CellApplication a(argc, argv, threadData);
return a.exec();
}
catch(exception &e)
Expand All @@ -95,5 +101,7 @@ int main(int argc, char *argv[])
}

return 0;

MMC_CATCH_TOP();
}

0 comments on commit 9f05bfe

Please sign in to comment.