added claiming for task interface
This commit is contained in:
parent
a6c1511298
commit
c03e54601c
|
@ -61,6 +61,7 @@ class GwApi{
|
||||||
protected:
|
protected:
|
||||||
virtual bool iset(const String &file, const String &name, Ptr v) = 0;
|
virtual bool iset(const String &file, const String &name, Ptr v) = 0;
|
||||||
virtual Ptr iget(const String &name, int &result) = 0;
|
virtual Ptr iget(const String &name, int &result) = 0;
|
||||||
|
virtual bool iclaim(const String &name, const String &task)=0;
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool set(const T &v){
|
bool set(const T &v){
|
||||||
|
@ -71,6 +72,10 @@ class GwApi{
|
||||||
res=-1;
|
res=-1;
|
||||||
return T();
|
return T();
|
||||||
}
|
}
|
||||||
|
template <typename T>
|
||||||
|
bool claim(const String &task){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class Status{
|
class Status{
|
||||||
public:
|
public:
|
||||||
|
@ -248,7 +253,12 @@ class GwApi{
|
||||||
}\
|
}\
|
||||||
type *tp=(type*)ptr.get(); \
|
type *tp=(type*)ptr.get(); \
|
||||||
return type(*tp); \
|
return type(*tp); \
|
||||||
}
|
}\
|
||||||
|
template<> \
|
||||||
|
inline bool GwApi::TaskInterfaces::claim<type>(const String &task) {\
|
||||||
|
return iclaim(#type,task);\
|
||||||
|
}\
|
||||||
|
|
||||||
#ifndef DECLARE_TASKIF
|
#ifndef DECLARE_TASKIF
|
||||||
#define DECLARE_TASKIF(type) DECLARE_TASKIF_IMPL(type)
|
#define DECLARE_TASKIF(type) DECLARE_TASKIF_IMPL(type)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -111,3 +111,13 @@ void handleButtons(GwApi *api){
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initButtons(GwApi *api){
|
||||||
|
#ifndef GWBUTTON_PIN
|
||||||
|
api->getLogger()->logDebug(GwLog::LOG,"no buttons defined, no button task");
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
const String taskname("buttonTask");
|
||||||
|
api->addUserTask(handleButtons,taskname);
|
||||||
|
api->taskInterfaces()->claim<IButtonTask>(taskname);
|
||||||
|
}
|
|
@ -2,6 +2,6 @@
|
||||||
#define _GWBUTTONTASK_H
|
#define _GWBUTTONTASK_H
|
||||||
#include "GwApi.h"
|
#include "GwApi.h"
|
||||||
//task function
|
//task function
|
||||||
void handleButtons(GwApi *param);
|
void initButtons(GwApi *param);
|
||||||
DECLARE_USERTASK(handleButtons);
|
DECLARE_INITFUNCTION(initButtons);
|
||||||
#endif
|
#endif
|
|
@ -124,6 +124,7 @@ class TaskInterfacesStorage{
|
||||||
}
|
}
|
||||||
if (it->second.task != task){
|
if (it->second.task != task){
|
||||||
LOG_DEBUG(GwLog::ERROR,"TaskInterfaces: invalid set %s wrong task, expected %s , got %s",name.c_str(),it->second.task.c_str(),task.c_str());
|
LOG_DEBUG(GwLog::ERROR,"TaskInterfaces: invalid set %s wrong task, expected %s , got %s",name.c_str(),it->second.task.c_str(),task.c_str());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
auto vit=values.find(name);
|
auto vit=values.find(name);
|
||||||
if (vit != values.end()){
|
if (vit != values.end()){
|
||||||
|
@ -150,15 +151,32 @@ class TaskInterfacesStorage{
|
||||||
class TaskInterfacesImpl : public GwApi::TaskInterfaces{
|
class TaskInterfacesImpl : public GwApi::TaskInterfaces{
|
||||||
String task;
|
String task;
|
||||||
TaskInterfacesStorage *storage;
|
TaskInterfacesStorage *storage;
|
||||||
|
GwLog *logger;
|
||||||
|
bool isInit=false;
|
||||||
public:
|
public:
|
||||||
TaskInterfacesImpl(const String &n,TaskInterfacesStorage *s):
|
TaskInterfacesImpl(const String &n,TaskInterfacesStorage *s, GwLog *l,bool i):
|
||||||
task(n),storage(s){}
|
task(n),storage(s),isInit(i),logger(l){}
|
||||||
virtual bool iset(const String &file, const String &name, Ptr v){
|
virtual bool iset(const String &file, const String &name, Ptr v){
|
||||||
return storage->set(file,name,task,v);
|
return storage->set(file,name,task,v);
|
||||||
}
|
}
|
||||||
virtual Ptr iget(const String &name, int &result){
|
virtual Ptr iget(const String &name, int &result){
|
||||||
return storage->get(name,result);
|
return storage->get(name,result);
|
||||||
}
|
}
|
||||||
|
virtual bool iclaim(const String &name, const String &task){
|
||||||
|
if (! isInit) return false;
|
||||||
|
auto it=registrations().find(name);
|
||||||
|
if (it == registrations().end()){
|
||||||
|
LOG_DEBUG(GwLog::ERROR,"unable to claim interface %s for task %s, not registered",name.c_str(),task.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!it->second.task.isEmpty()){
|
||||||
|
LOG_DEBUG(GwLog::ERROR,"unable to claim interface %s for task %s, already claimed by %s",name.c_str(),task.c_str(),it->second.task.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
it->second.task=task;
|
||||||
|
LOG_DEBUG(GwLog::LOG,"claimed interface %s for task %s",name.c_str(),task.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,7 +205,7 @@ public:
|
||||||
this->mainLock=mainLock;
|
this->mainLock=mainLock;
|
||||||
this->name=name;
|
this->name=name;
|
||||||
localLock=xSemaphoreCreateMutex();
|
localLock=xSemaphoreCreateMutex();
|
||||||
interfaces=new TaskInterfacesImpl(name,s);
|
interfaces=new TaskInterfacesImpl(name,s,api->getLogger(),init);
|
||||||
isInit=init;
|
isInit=init;
|
||||||
}
|
}
|
||||||
virtual GwRequestQueue *getQueue()
|
virtual GwRequestQueue *getQueue()
|
||||||
|
|
Loading…
Reference in New Issue