Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding multitask feature #2353

Merged
merged 18 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion build/cmake/terrame/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ source_group("Source Files\\observer\\types\\udpsender" FILES ${TERRAME_OBSERVER
source_group("Header Files\\observer\\types\\udpsender" FILES ${TERRAME_OBSERVER_UDP_SENDER_HDR_FILES})
source_group("UI Files\\observer\\types\\udpsender" FILES ${TERRAME_OBSERVER_UDP_SENDER_UI_FILES})

#terrame/src/hpa
file(GLOB TERRAME_HPA_SRC_FILES ${TERRAME_ABSOLUTE_ROOT_DIR}/src/hpa/*.cpp)
file(GLOB TERRAME_HPA_HDR_FILES ${TERRAME_ABSOLUTE_ROOT_DIR}/src/hpa/*.h)
source_group("Source Files\\hpa" FILES ${TERRAME_HPA_SRC_FILES})
source_group("Header Files\\hpa" FILES ${TERRAME_HPA_HDR_FILES})

if(APPLE)
find_library(_COREFOUNDATION_LIBRARY NAMES CoreFoundation PATHS "/")

Expand Down Expand Up @@ -292,7 +298,8 @@ set(TERRAME_FILES ${TERRAME_CORE_SRC_FILES} ${TERRAME_CORE_HDR_FILES}
${TERRAME_OBSERVER_TYPES_CHART_PLOT_SRC_FILES} ${TERRAME_OBSERVER_TYPES_CHART_PLOT_HDR_FILES}
${TERRAME_OBSERVER_TYPES_STATE_MACHINE_SRC_FILES} ${TERRAME_OBSERVER_TYPES_STATE_MACHINE_HDR_FILES}
${TERRAME_OBSERVER_UDP_SENDER_SRC_FILES} ${TERRAME_OBSERVER_UDP_SENDER_HDR_FILES} ${TERRAME_OBSERVER_UDP_SENDER_UI_FILES}
${TERRAME_GEN_HDR_FILES}
${TERRAME_HPA_SRC_FILES} ${TERRAME_HPA_HDR_FILES}
${TERRAME_GEN_HDR_FILES}
${TERRAME_OBSERVER_QRC_FILES} ${TERRAME_OBSERVER_QRC_FILES_ADD}
${TERRAME_APP_ICON})

Expand Down
6 changes: 0 additions & 6 deletions src/core/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ of this software and its documentation.
#include <sstream>
#include <stdio.h>

#if defined(TME_WIN32)
#include <iostream>
#else
//#include <iostream.h>
#endif

using namespace std;

typedef string ModelID;
Expand Down
17 changes: 17 additions & 0 deletions src/core/registryObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,5 +396,22 @@ Luna<luaEnvironment>::RegType luaEnvironment::methods[] =
{0, 0}
};

//****************************** HPA ****************************************//

// Tiago - alterei as linhas baixo para tornar o HPA um lightuserdata que 'e imune ao garbage collector de Lua
const char HPA::className[] = "HPA";

Luna<HPA>::RegType HPA::methods[] =
{
method(HPA, joinall),
method(HPA, join),
method(HPA, parallel),
method(HPA, acquire),
method(HPA, release),
method(HPA, np),
method(HPA, HPATests),
{0, 0}
};

#endif // REGISTRY_OBJECT_H

20 changes: 20 additions & 0 deletions src/core/terrameLua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ extern "C"
#include "luna.h"
#include "LuaBindingDelegate.h"

#include "hpa/hpa.h"

QApplication* app;

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -165,6 +167,7 @@ void registerClasses()
Luna<luaLogFile>::getInstance()->setup(L);
Luna<luaTcpSender>::getInstance()->setup(L);
Luna<luaUdpSender>::getInstance()->setup(L);
Luna<HPA>::getInstance()->setup(L);
}

int cpp_runcommand(lua_State *L)
Expand Down Expand Up @@ -339,6 +342,16 @@ int cpp_closeAllWidgets(lua_State* L)
return 0;
}

int cpp_hpa_run(lua_State* L)
{
std::string script = lua_tostring(L, -1);
HPA *HPAFlow = new HPA(script, L);
HPAFlow->execute();
delete HPAFlow;

return 0;
}

extern ExecutionModes execModes;

int main(int argc, char *argv[])
Expand Down Expand Up @@ -457,6 +470,9 @@ int main(int argc, char *argv[])
lua_pushcfunction(L, cpp_closeAllWidgets);
lua_setglobal(L, "cpp_closeAllWidgets");

lua_pushcfunction(L, cpp_hpa_run);
lua_setglobal(L, "cpp_hpa_run");

// Execute the lua files
if (argc < 2)
{
Expand All @@ -481,6 +497,10 @@ int main(int argc, char *argv[])
argument++;
}

//HPA *HPAFlow = new HPA("hpa_model_test.lua", L);
//HPAFlow->execute();
//delete HPAFlow;

lua_call(L, 1, 0);
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/terrameLua5_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,7 @@ luaCell * findCell(luaCellularSpace*, CellIndex&);
#include "luaTcpSender.h"
#include "luaUdpSender.h"

#include "hpa/hpa.h"

#endif // TERRAME_LUA_5_1_H

87 changes: 87 additions & 0 deletions src/hpa/bagOfTasks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/************************************************************************************
TerraME - a software platform for multiple scale spatially-explicit dynamic modeling.
Copyright (C) 2001-2017 INPE and TerraLAB/UFOP -- www.terrame.org

This code is part of the TerraME framework.
This framework is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

You should have received a copy of the GNU Lesser General Public
License along with this library.

The authors reassure the license terms regarding the warranties.
They specifically disclaim any warranties, including, but not limited to,
the implied warranties of merchantability and fitness for a particular purpose.
The framework provided hereunder is on an "as is" basis, and the authors have no
obligation to provide maintenance, support, updates, enhancements, or modifications.
In no event shall INPE and TerraLAB / UFOP be held liable to any party for direct,
indirect, special, incidental, or consequential damages arising out of the use
of this software and its documentation.
*************************************************************************************/

#ifndef BAG_OF_TASKS_H
#define BAG_OF_TASKS_H

extern "C" {
#include <lua.h>
}

#include <string>
#include <QMutexLocker>
#include <list>
#include "paramsTask.h"

using namespace std;

static list<ParamTask> BAG;

static QMutex LOCK_BAG;

static int bagOfTask(list<ParamTask> *bag_, ParamTask *firtTask) {
LOCK_BAG.lock();
//neste caso sai um resultado para ser tratado no run (preciso refatorar aqui)
if(bag_->empty())
{
LOCK_BAG.unlock();
return 0;
}
else
{
firtTask = &bag_->front();
bag_->pop_front();
}
LOCK_BAG.unlock();
return 1;
}

//para obter quantidade de tasks agurdando execucao
static int bagSize(list<ParamTask> *bag_){
int nTasks;
LOCK_BAG.lock();
nTasks = bag_->size();
LOCK_BAG.unlock();
return nTasks;
}

static void bagInsertion(list<ParamTask> *bag_, string toExec, string nameFunc, vector<string> params, vector<string> returns, lua_State* storeVals){
LOCK_BAG.lock();

ParamTask toIncludeBagP;
toIncludeBagP.setCallTask(toExec);
toIncludeBagP.setNameTask(nameFunc);
toIncludeBagP.setSetParam(params);
toIncludeBagP.setSetRet(returns);

if(params.size() == 0)
lua_close(storeVals);
else
toIncludeBagP.set_State(storeVals);

bag_->push_back(toIncludeBagP);

LOCK_BAG.unlock();
}

#endif
Loading