GemaLib
The GeMA library
Loading...
Searching...
No Matches
gmSimulation.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_SIMULATION_H_
25#define _GEMA_SIMULATION_H_
26
27#include "gmConfig.h"
28#include <gmLog.h>
29
30#include <QString>
31#include <QObject>
32#include <QMutex>
33
36class GmPluginLoader;
37class GmPath;
38class GmThreadManager;
39class GmTaskManager;
40
41class GmCommServer;
42
43class LuaEnv;
44struct lua_State;
45
53
54
58class GM_API_EXPORT GmSimulation : public QObject
59{
60 Q_OBJECT
61
62public:
65
68 {
69 QUIET_LOG_MODE = 0x00001,
70 VERBOSE_LOG_MODE = 0x00002,
71 NOCONSOLE_LOG_MODE = 0x00004,
72 REGRESSION_LOG_MODE = 0x00008,
73 MEMORY_LOG_MODE = 0x00010,
74 NOMEMORY_LOG_MODE = 0x00020,
75 TIME_LOG_MODE = 0x00040,
76 NOTIME_LOG_MODE = 0x00080,
77 SERVER_LOG_MODE = 0x00100,
78 NOSERVER_LOG_MODE = 0x00200,
79 PLUGININFO_LOG_MODE = 0x00400,
80 BLASVERSION_LOG_MODE= 0x00800,
81 NO_TRACK_MODE = 0x01000,
82 NS_SP_TRACK_MODE = 0x02000,
83 NS_DP_TRACK_MODE = 0x04000,
84 DS_SP_TRACK_MODE = 0x08000,
85 DS_DP_TRACK_MODE = 0x10000,
86 };
87
96
97 bool initLibrary(QString configFile, QString logFile, int logMode,
98 QString logPath, QString inputPath, QString outputPath,
99 ServerMode serverMode, unsigned localServerPort,
100 QString serverAddrFile, bool rsrcFiles);
101
102 bool initSimulation(QString simulationFile, const QMap<QString, QString>& globalVars,
103 int timeout = -1, lua_State* state = NULL);
104
105 bool initEmptySimulation();
106
107 GmSimulationResult run();
108
112 void clear() { setData(NULL); }
113
114 void printInfo();
115
117 const GmLogCategory& logger() { return _logger; }
118
120 LuaEnv* env() { return _env; }
121
123 GmSimulationData* data() const { return _simulationData; }
124
125 GmPluginLoader* pluginLoader() const;
126
128 const GmPath* paths() const { return _paths; }
129 GmPath* paths() { return _paths; }
130
131signals:
140 void sectionParsed(QString section, LuaTable& data);
141
142private slots:
143 void cancelRequested();
144
145private:
146 bool setConfigFile(QString configFile, QString logFile, int logMode,
147 ServerMode serverMode, unsigned localServerPort, QString serverAddrFile);
148
149 bool setSimulationFile(QString file, const QMap<QString, QString>& globalVars, lua_State* state);
150
151 bool setupLogging (LuaEnv& env, QString logFile, int logMode);
152 bool setupMonitorServer(LuaEnv& env, ServerMode serverMode, unsigned localServerPort, bool logToServer, QString serverAddrFile);
153 bool setupUnitManager (LuaEnv& env);
154 bool setupProgressLevelConfiguration(LuaEnv& env, int trackMode);
155 bool loadConfigValueTables(LuaEnv& env);
156
157 void setData(GmSimulationData* data);
158 void clearDataOnError(bool abort);
159
160 void printPluginVersions(GmLogCategory& logger);
161
165 QVariantMap _configConstants;
166 QVariantMap _configOptions;
168
170
171 GmCommServer* _monitorServer;
173
178
186
188};
189
190#endif
191
Basic class for defining a GeMA physical Simulation, containing references to the model definition,...
Definition gmSimulation.h:59
bool _externalState
Are we using an external Lua environment provided in initSimulation() ?
Definition gmSimulation.h:183
GmLogCategory _logger
Basic logger object for the library.
Definition gmSimulation.h:169
void sectionParsed(QString section, LuaTable &data)
Signal emmited whenever a model section has been parsed from the Lua file.
const GmLogCategory & logger()
Returns the basic logger for the GeMA library.
Definition gmSimulation.h:117
GmSimulationData * _simulationData
Object storing the complete Simulation information.
Definition gmSimulation.h:162
GmSimulationData * data() const
Returns a reference to the simulation data.
Definition gmSimulation.h:123
const GmPath * paths() const
Returns the object storing information for path macro susbstitution.
Definition gmSimulation.h:128
QList< LuaEnv * > _workerEnvList
A list with Lua environments for worker threads.
Definition gmSimulation.h:187
bool _rsrcFiles
If set to true, the config file and the model file are allowed to be resource files.
Definition gmSimulation.h:167
GmCommServer * _monitorServer
The monitor server. Will be NULL if monitoring is not enabled.
Definition gmSimulation.h:171
bool _loadCompleted
A flag set to true when the model loading has finished successfully. Also protected by _envMutex.
Definition gmSimulation.h:185
LuaEnv * env()
Returns the simulation environment.
Definition gmSimulation.h:120
void clear()
Clears the current simulation environment, preparing the object for a new simulation: new calls to in...
Definition gmSimulation.h:112
QVariantMap _configConstants
The set of constants defined on the config file.
Definition gmSimulation.h:165
GmPath * _paths
Object storing the set of important simulation paths for macro translation.
Definition gmSimulation.h:164
LogModes
Predefined Log modes & Progress track levels. Can be ored together.
Definition gmSimulation.h:68
bool _redirectPrint
Should we redirect Lua print() calls to the logger?
Definition gmSimulation.h:184
LuaEnv * _env
Lua environment used to read the Simulation. Reused during the execution step as it contains function...
Definition gmSimulation.h:182
ServerMode
Server initialization modes.
Definition gmSimulation.h:90
@ LOCAL_SERVER_MODE
The monitor server will be turned on, listening for connections on the local host.
Definition gmSimulation.h:94
@ CONFIG_SERVER_MODE
The monitor server will be turned on or off depending on the config file.
Definition gmSimulation.h:91
@ ENABLE_SERVER_MODE
The monitor server will be turned on.
Definition gmSimulation.h:92
@ DISABLE_SERVER_MODE
The monitor server will be turned off.
Definition gmSimulation.h:93
QMutex _envMutex
The mutex used to control the possible data race during the creation of the Lua environments and poss...
Definition gmSimulation.h:177
GmSimulationLoader * _simulationLoader
Simulation loader.
Definition gmSimulation.h:163
bool _monitorRuleTesting
Should we enable monitor rule testing?
Definition gmSimulation.h:172
QVariantMap _configOptions
The set of options defined on the config file.
Definition gmSimulation.h:166
Auxiliary class responsible for loading simulation information from a Lua File.
Definition gmSimulationLoader.h:44
Declaration of useful configuration definitions.
GmSimulationResult
Enumeration describing the result of a simulation.
Definition gmSimulation.h:48
@ GM_RESULT_CANCELED
The simulation was cancelled by user request.
Definition gmSimulation.h:50
@ GM_RESULT_ABORTED
The simulation was aborted by a run time error.
Definition gmSimulation.h:51
@ GM_RESULT_OK
The simulation completed successfully.
Definition gmSimulation.h:49