added claiming for task interface
This commit is contained in:
parent
a6c1511298
commit
c03e54601c
|
@ -61,6 +61,7 @@ class GwApi{
|
|||
protected:
|
||||
virtual bool iset(const String &file, const String &name, Ptr v) = 0;
|
||||
virtual Ptr iget(const String &name, int &result) = 0;
|
||||
virtual bool iclaim(const String &name, const String &task)=0;
|
||||
public:
|
||||
template <typename T>
|
||||
bool set(const T &v){
|
||||
|
@ -71,6 +72,10 @@ class GwApi{
|
|||
res=-1;
|
||||
return T();
|
||||
}
|
||||
template <typename T>
|
||||
bool claim(const String &task){
|
||||
return false;
|
||||
}
|
||||
};
|
||||
class Status{
|
||||
public:
|
||||
|
@ -248,7 +253,12 @@ class GwApi{
|
|||
}\
|
||||
type *tp=(type*)ptr.get(); \
|
||||
return type(*tp); \
|
||||
}
|
||||
}\
|
||||
template<> \
|
||||
inline bool GwApi::TaskInterfaces::claim<type>(const String &task) {\
|
||||
return iclaim(#type,task);\
|
||||
}\
|
||||
|
||||
#ifndef DECLARE_TASKIF
|
||||
#define DECLARE_TASKIF(type) DECLARE_TASKIF_IMPL(type)
|
||||
#endif
|
||||
|
|
|
@ -110,4 +110,14 @@ void handleButtons(GwApi *api){
|
|||
}
|
||||
vTaskDelete(NULL);
|
||||
#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
|
||||
#include "GwApi.h"
|
||||
//task function
|
||||
void handleButtons(GwApi *param);
|
||||
DECLARE_USERTASK(handleButtons);
|
||||
void initButtons(GwApi *param);
|
||||
DECLARE_INITFUNCTION(initButtons);
|
||||
#endif
|
|
@ -124,6 +124,7 @@ class TaskInterfacesStorage{
|
|||
}
|
||||
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());
|
||||
return false;
|
||||
}
|
||||
auto vit=values.find(name);
|
||||
if (vit != values.end()){
|
||||
|
@ -150,15 +151,32 @@ class TaskInterfacesStorage{
|
|||
class TaskInterfacesImpl : public GwApi::TaskInterfaces{
|
||||
String task;
|
||||
TaskInterfacesStorage *storage;
|
||||
GwLog *logger;
|
||||
bool isInit=false;
|
||||
public:
|
||||
TaskInterfacesImpl(const String &n,TaskInterfacesStorage *s):
|
||||
task(n),storage(s){}
|
||||
TaskInterfacesImpl(const String &n,TaskInterfacesStorage *s, GwLog *l,bool i):
|
||||
task(n),storage(s),isInit(i),logger(l){}
|
||||
virtual bool iset(const String &file, const String &name, Ptr v){
|
||||
return storage->set(file,name,task,v);
|
||||
}
|
||||
virtual Ptr iget(const String &name, int &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->name=name;
|
||||
localLock=xSemaphoreCreateMutex();
|
||||
interfaces=new TaskInterfacesImpl(name,s);
|
||||
interfaces=new TaskInterfacesImpl(name,s,api->getLogger(),init);
|
||||
isInit=init;
|
||||
}
|
||||
virtual GwRequestQueue *getQueue()
|
||||
|
|
Loading…
Reference in New Issue