GemaLuaCoreLib
The GeMA Lua Core library
gmLuaTask.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 _GEMALUA_TASK_H_
25 #define _GEMALUA_TASK_H_
26 
27 #include "gmLuaEnv.h"
28 #include <gmTaskManager.h>
29 
30 struct lua_State;
31 
36 class GML_API_EXPORT GmLuaTask : public GmThreadTask
37 {
38 public:
39  GmLuaTask(const QString& fname, const QVariant& taskPars,
40  const QVariantList& extraPars, const GmLogCategory& logger);
41 
42  virtual GmThreadTaskResult run(const GmThread* thread);
43 
44 private:
45  const QString& _fname;
47  const QVariantList& _extraPars;
49 };
50 
55 class GML_API_EXPORT GmLuaNodeTask
56 {
57 public:
58  GmLuaNodeTask(const QString& fname, const QVariantList& extraPars, const GmLogCategory& logger);
59 
60  GmThreadTaskResult operator()(GmNodeTaskDataSet* dataSet, const GmThread* thread);
61 
62 private:
63  static int iteratorClosure (lua_State* L);
64  static int iteratorFunction(lua_State* L);
65 
66  const QString& _fname;
67  const QVariantList& _extraPars;
69 };
70 
75 class GML_API_EXPORT GmLuaCellTask
76 {
77 public:
78  GmLuaCellTask(const QString& fname, const QVariantList& extraPars, const GmLogCategory& logger);
79 
80  GmThreadTaskResult operator()(GmCellTaskDataSet* dataSet, const GmThread* thread);
81 
82 private:
83  static int iteratorClosure(lua_State* L);
84  static int iteratorFunction(lua_State* L);
85 
86  const QString& _fname;
87  const QVariantList& _extraPars;
89 };
90 
91 
93 namespace GmLuaTaskUtils
94 {
95  bool pushParameter(LuaEnv* env, const QVariant& v);
96  bool setInTable(LuaTable& t, const QVariant& index, const QVariant& v);
97 
98  GmThreadTaskResult callLuaTaskFunction(void* dataSet, const GmThread* thread, const QString& luaName,
99  const QVariantList& extraPars, const GmLogCategory& logger,
100  bool loggerIsUpvalue, int (*iteratorClosure)(lua_State*),
101  const char* fname);
102 
103  // Template is decalred in the cpp and specialized for its 2 possible T types (Node and Cell Partition strategy)
104  template <class T> void parseExecOptions(LuaEnv* env, int stackPos, T(*str2Strat)(QString), T defStrategy,
105  const char* fname, int* ntasks, int* nworkers, T* strategy,
106  QVector<int>& taskAffinity);
107 }
108 
109 
110 #endif
const QVariantList & _extraPars
The set of extra parameters, common to all tasks.
Definition: gmLuaTask.h:87
A Thread task that is responsible for calling a Lua function that gets as parameters a single paramet...
Definition: gmLuaTask.h:36
const GmLogCategory & _logger
A logger for error messages.
Definition: gmLuaTask.h:68
const QVariantList & _extraPars
The set of extra parameters, common to all tasks.
Definition: gmLuaTask.h:67
GmThreadTaskResult
bool pushParameter(LuaEnv *env, const QVariant &v)
Pushes v on the stack.
Definition: gmLuaTask.cpp:286
void parseExecOptions(LuaEnv *env, int stackPos, T(*str2Strat)(QString), T defStrategy, const char *fname, int *ntasks, int *nworkers, T *strategy, QVector< int > &taskAffinity)
Parses the contents of the options Lua table at stackPos, using the function str2Strat() function to ...
Definition: gmLuaTask.cpp:485
A task function object responsible for calling a Lua function that gets as parameters an iterator for...
Definition: gmLuaTask.h:75
Declaration of the function used to prepare an environment with the core Lua functions.
const QString & _fname
The name of the function to be called.
Definition: gmLuaTask.h:86
const GmLogCategory & _logger
A logger for error messages.
Definition: gmLuaTask.h:48
const QVariantList & _extraPars
The set of extra parameters, common to all tasks.
Definition: gmLuaTask.h:47
virtual GmThreadTaskResult run(const GmThread *thread)=0
bool setInTable(LuaTable &t, const QVariant &index, const QVariant &v)
Aux function used by pushParameter() to set a field in a table (integer or string) to the value v,...
Definition: gmLuaTask.cpp:346
const GmLogCategory & _logger
A logger for error messages.
Definition: gmLuaTask.h:88
const QString & _fname
The name of the function to be called.
Definition: gmLuaTask.h:45
const QString & _fname
The name of the function to be called.
Definition: gmLuaTask.h:66
A task function object responsible for calling a Lua function that gets as parameters an iterator for...
Definition: gmLuaTask.h:55
GmThreadTaskResult callLuaTaskFunction(void *dataSet, const GmThread *thread, const QString &luaName, const QVariantList &extraPars, const GmLogCategory &logger, bool loggerIsUpvalue, int(*iteratorClosure)(lua_State *), const char *fname)
Aux function used by the GmLuaXxxTask classes to call a Lua function sending as parameters an iterato...
Definition: gmLuaTask.cpp:410
const QVariant & _taskPars
The set of task parameters.
Definition: gmLuaTask.h:46
Aux functions used by several of the task classes.
Definition: gmLuaTask.h:93