mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-14 06:23:07 +01:00
directly use SemaphoreHandle_t as pointer
This commit is contained in:
@@ -75,7 +75,7 @@ class TaskInterfacesStorage{
|
||||
lock=xSemaphoreCreateMutex();
|
||||
}
|
||||
bool set(const String &name, GwApi::TaskInterfaces::Ptr v){
|
||||
GWSYNCHRONIZED(&lock);
|
||||
GWSYNCHRONIZED(lock);
|
||||
auto vit=values.find(name);
|
||||
if (vit != values.end()){
|
||||
vit->second.updates++;
|
||||
@@ -90,7 +90,7 @@ class TaskInterfacesStorage{
|
||||
return true;
|
||||
}
|
||||
GwApi::TaskInterfaces::Ptr get(const String &name, int &result){
|
||||
GWSYNCHRONIZED(&lock);
|
||||
GWSYNCHRONIZED(lock);
|
||||
auto it = values.find(name);
|
||||
if (it == values.end())
|
||||
{
|
||||
@@ -102,7 +102,7 @@ class TaskInterfacesStorage{
|
||||
}
|
||||
|
||||
bool update(const String &name, std::function<GwApi::TaskInterfaces::Ptr(GwApi::TaskInterfaces::Ptr)>f){
|
||||
GWSYNCHRONIZED(&lock);
|
||||
GWSYNCHRONIZED(lock);
|
||||
auto vit=values.find(name);
|
||||
bool rt=false;
|
||||
int mode=0;
|
||||
@@ -160,7 +160,7 @@ class TaskApi : public GwApiInternal
|
||||
{
|
||||
GwApiInternal *api=nullptr;
|
||||
int sourceId;
|
||||
SemaphoreHandle_t *mainLock;
|
||||
SemaphoreHandle_t mainLock;
|
||||
SemaphoreHandle_t localLock;
|
||||
std::map<int,GwCounter<String>> counter;
|
||||
std::map<String,GwApi::HandlerFunction> webHandlers;
|
||||
@@ -172,7 +172,7 @@ class TaskApi : public GwApiInternal
|
||||
public:
|
||||
TaskApi(GwApiInternal *api,
|
||||
int sourceId,
|
||||
SemaphoreHandle_t *mainLock,
|
||||
SemaphoreHandle_t mainLock,
|
||||
const String &name,
|
||||
TaskInterfacesStorage *s,
|
||||
bool init=false)
|
||||
@@ -236,14 +236,14 @@ public:
|
||||
vSemaphoreDelete(localLock);
|
||||
};
|
||||
virtual void fillStatus(GwJsonDocument &status){
|
||||
GWSYNCHRONIZED(&localLock);
|
||||
GWSYNCHRONIZED(localLock);
|
||||
if (! counterUsed) return;
|
||||
for (auto it=counter.begin();it != counter.end();it++){
|
||||
it->second.toJson(status);
|
||||
}
|
||||
};
|
||||
virtual int getJsonSize(){
|
||||
GWSYNCHRONIZED(&localLock);
|
||||
GWSYNCHRONIZED(localLock);
|
||||
if (! counterUsed) return 0;
|
||||
int rt=0;
|
||||
for (auto it=counter.begin();it != counter.end();it++){
|
||||
@@ -252,7 +252,7 @@ public:
|
||||
return rt;
|
||||
};
|
||||
virtual void increment(int idx,const String &name,bool failed=false){
|
||||
GWSYNCHRONIZED(&localLock);
|
||||
GWSYNCHRONIZED(localLock);
|
||||
counterUsed=true;
|
||||
auto it=counter.find(idx);
|
||||
if (it == counter.end()) return;
|
||||
@@ -260,18 +260,18 @@ public:
|
||||
else (it->second.add(name));
|
||||
};
|
||||
virtual void reset(int idx){
|
||||
GWSYNCHRONIZED(&localLock);
|
||||
GWSYNCHRONIZED(localLock);
|
||||
counterUsed=true;
|
||||
auto it=counter.find(idx);
|
||||
if (it == counter.end()) return;
|
||||
it->second.reset();
|
||||
};
|
||||
virtual void remove(int idx){
|
||||
GWSYNCHRONIZED(&localLock);
|
||||
GWSYNCHRONIZED(localLock);
|
||||
counter.erase(idx);
|
||||
}
|
||||
virtual int addCounter(const String &name){
|
||||
GWSYNCHRONIZED(&localLock);
|
||||
GWSYNCHRONIZED(localLock);
|
||||
counterUsed=true;
|
||||
counterIdx++;
|
||||
//avoid the need for an empty counter constructor
|
||||
@@ -289,7 +289,7 @@ public:
|
||||
return api->addXdrMapping(def);
|
||||
}
|
||||
virtual void registerRequestHandler(const String &url,HandlerFunction handler){
|
||||
GWSYNCHRONIZED(&localLock);
|
||||
GWSYNCHRONIZED(localLock);
|
||||
webHandlers[url]=handler;
|
||||
}
|
||||
virtual void addCapability(const String &name, const String &value){
|
||||
@@ -316,7 +316,7 @@ public:
|
||||
{
|
||||
GwApi::HandlerFunction handler;
|
||||
{
|
||||
GWSYNCHRONIZED(&localLock);
|
||||
GWSYNCHRONIZED(localLock);
|
||||
auto it = webHandlers.find(url);
|
||||
if (it == webHandlers.end())
|
||||
{
|
||||
@@ -345,10 +345,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
GwUserCode::GwUserCode(GwApiInternal *api,SemaphoreHandle_t *mainLock){
|
||||
GwUserCode::GwUserCode(GwApiInternal *api){
|
||||
this->logger=api->getLogger();
|
||||
this->api=api;
|
||||
this->mainLock=mainLock;
|
||||
this->taskData=new TaskInterfacesStorage(this->logger);
|
||||
}
|
||||
GwUserCode::~GwUserCode(){
|
||||
|
||||
@@ -41,13 +41,14 @@ class TaskInterfacesStorage;
|
||||
class GwUserCode{
|
||||
GwLog *logger;
|
||||
GwApiInternal *api;
|
||||
SemaphoreHandle_t *mainLock;
|
||||
SemaphoreHandle_t mainLock=nullptr;
|
||||
TaskInterfacesStorage *taskData;
|
||||
void startAddOnTask(GwApiInternal *api,GwUserTask *task,int sourceId,String name);
|
||||
public:
|
||||
~GwUserCode();
|
||||
typedef std::map<String,String> Capabilities;
|
||||
GwUserCode(GwApiInternal *api, SemaphoreHandle_t *mainLock);
|
||||
GwUserCode(GwApiInternal *api);
|
||||
void begin(SemaphoreHandle_t mainLock){this->mainLock=mainLock;}
|
||||
void startUserTasks(int baseId);
|
||||
void startInitTasks(int baseId);
|
||||
void startAddonTask(String name,TaskFunction_t task, int id);
|
||||
|
||||
Reference in New Issue
Block a user