intermediate: running sensor tasks inits after all user init tasks
This commit is contained in:
parent
f75f8033d1
commit
1ab70aca8b
|
@ -240,7 +240,10 @@ static void checkDef(T... args){};
|
|||
#define DECLARE_USERTASK_PARAM(task,...)
|
||||
#endif
|
||||
#ifndef DECLARE_INITFUNCTION
|
||||
#define DECLARE_INITFUNCTION(task)
|
||||
#define DECLARE_INITFUNCTION(task,...)
|
||||
#endif
|
||||
#ifndef DECLARE_INITFUNCTION_ORDER
|
||||
#define DECLARE_INITFUNCTION_ORDER(task,...)
|
||||
#endif
|
||||
#ifndef DECLARE_CAPABILITY
|
||||
#define DECLARE_CAPABILITY(name,value)
|
||||
|
@ -322,5 +325,8 @@ class ConfiguredSensors : public GwApi::TaskInterfaces::Base{
|
|||
};
|
||||
DECLARE_TASKIF(ConfiguredSensors);
|
||||
|
||||
//order for late init functions
|
||||
//all user tasks should have lower orders (default: 0)
|
||||
#define GWLATEORDER 9999
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
#include "GwApi.h"
|
||||
#include "GwSensor.h"
|
||||
void initIicTask(GwApi *api);
|
||||
DECLARE_INITFUNCTION(initIicTask);
|
||||
DECLARE_INITFUNCTION_ORDER(initIicTask,GWLATEORDER);
|
||||
#endif
|
|
@ -16,5 +16,5 @@
|
|||
#define _GWSPITASK_H
|
||||
#include "GwApi.h"
|
||||
void initSpiTask(GwApi *api);
|
||||
DECLARE_INITFUNCTION(initSpiTask);
|
||||
DECLARE_INITFUNCTION_ORDER(initSpiTask,GWLATEORDER);
|
||||
#endif
|
|
@ -1,6 +1,7 @@
|
|||
#define DECLARE_USERTASK(task) GwUserTaskDef __##task##__(task,#task);
|
||||
#define DECLARE_USERTASK_PARAM(task,...) GwUserTaskDef __##task##__(task,#task,__VA_ARGS__);
|
||||
#define DECLARE_INITFUNCTION(task) GwInitTask __Init##task##__(task,#task);
|
||||
#define DECLARE_INITFUNCTION_ORDER(task,order) GwInitTask __Init##task##__(task,#task,order);
|
||||
#define DECLARE_CAPABILITY(name,value) GwUserCapability __CAP##name##__(#name,#value);
|
||||
#define DECLARE_STRING_CAPABILITY(name,value) GwUserCapability __CAP##name##__(#name,value);
|
||||
#define DECLARE_TASKIF(type) \
|
||||
|
@ -43,8 +44,8 @@ class GwInitTask{
|
|||
GwInitTask(TaskFunction_t task, String name){
|
||||
initTasks.push_back(GwUserTask(name,task));
|
||||
}
|
||||
GwInitTask(GwUserTaskFunction task, String name){
|
||||
initTasks.push_back(GwUserTask(name,task));
|
||||
GwInitTask(GwUserTaskFunction task, String name,int order=0){
|
||||
initTasks.push_back(GwUserTask(name,task,GwUserTask::DEFAULT_STACKSIZE,order));
|
||||
}
|
||||
};
|
||||
class GwUserCapability{
|
||||
|
@ -341,7 +342,6 @@ public:
|
|||
sensors->sensors.add(sensor);
|
||||
return true;
|
||||
});
|
||||
api->getLogger()->logDebug(GwLog::LOG,"adding sensor %s returns %d",sensor->prefix.c_str(),(int)rt);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -378,6 +378,9 @@ void GwUserCode::startUserTasks(int baseId){
|
|||
}
|
||||
}
|
||||
void GwUserCode::startInitTasks(int baseId){
|
||||
std::sort(initTasks.begin(),initTasks.end(),[](const GwUserTask &a, const GwUserTask &b){
|
||||
return a.order < b.order;
|
||||
});
|
||||
LOG_DEBUG(GwLog::DEBUG,"starting %d user init tasks",initTasks.size());
|
||||
for (auto it=initTasks.begin();it != initTasks.end();it++){
|
||||
LOG_DEBUG(GwLog::LOG,"starting user init task %s with id %d",it->name.c_str(),baseId);
|
||||
|
|
|
@ -15,22 +15,25 @@ class GwApiInternal : public GwApi{
|
|||
};
|
||||
class GwUserTask{
|
||||
public:
|
||||
static const int DEFAULT_STACKSIZE=2000;
|
||||
String name;
|
||||
TaskFunction_t task=NULL;
|
||||
GwUserTaskFunction usertask=NULL;
|
||||
bool isUserTask=false;
|
||||
GwApiInternal *api=NULL;
|
||||
int stackSize=2000;
|
||||
GwUserTask(String name,TaskFunction_t task,int stackSize=2000){
|
||||
int order=0;
|
||||
GwUserTask(String name,TaskFunction_t task,int stackSize=DEFAULT_STACKSIZE){
|
||||
this->name=name;
|
||||
this->task=task;
|
||||
this->stackSize=stackSize;
|
||||
}
|
||||
GwUserTask(String name, GwUserTaskFunction task,int stackSize=2000){
|
||||
GwUserTask(String name, GwUserTaskFunction task,int stackSize=DEFAULT_STACKSIZE, int order=0){
|
||||
this->name=name;
|
||||
this->usertask=task;
|
||||
this->isUserTask=true;
|
||||
this->stackSize=stackSize;
|
||||
this->order=order;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue