From 155c7a8d1cc50f719704635c733f2ec0a9364af1 Mon Sep 17 00:00:00 2001 From: andreas Date: Tue, 24 Oct 2023 15:10:13 +0200 Subject: [PATCH] add error example, improve debug messages --- lib/exampletask/GwExampleTask.cpp | 17 +++++++++++++++++ lib/usercode/GwUserCode.cpp | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/exampletask/GwExampleTask.cpp b/lib/exampletask/GwExampleTask.cpp index f50e3b6..164761a 100644 --- a/lib/exampletask/GwExampleTask.cpp +++ b/lib/exampletask/GwExampleTask.cpp @@ -7,6 +7,20 @@ #include "GWConfig.h" #include +/** + * INVALID!!! - the next interface declaration will not work + * as it is not in the correct header file + * it is just included here to show you how errors + * could be created. + * if you call the apiSetExampleNotWorkingIf method + * it will always return false +*/ +class ExampleNotWorkingIf: public GwApi::TaskInterfaces::Base{ + public: + int someValue=99; +}; +DECLARE_TASKIF(exampleTask,ExampleNotWorkingIf); + /** * an init function that ist being called before other initializations from the core */ @@ -103,6 +117,9 @@ void exampleTask(GwApi *api){ int apiResult=0; ExampleTaskIf e1=apiGetExampleTaskIf(api,apiResult); LOG_DEBUG(GwLog::LOG,"exampleIf before rs=%d,v=%d,s=%s",apiResult,e1.count,e1.someValue.c_str()); + ExampleNotWorkingIf nw1; + bool nwrs=apiSetExampleNotWorkingIf(api,nw1); + LOG_DEBUG(GwLog::LOG,"exampleNotWorking update returned %d",(int)nwrs); while(true){ delay(1000); /* diff --git a/lib/usercode/GwUserCode.cpp b/lib/usercode/GwUserCode.cpp index 4f12b03..0c4bef9 100644 --- a/lib/usercode/GwUserCode.cpp +++ b/lib/usercode/GwUserCode.cpp @@ -107,15 +107,15 @@ class TaskInterfacesStorage{ GWSYNCHRONIZED(&lock); auto it=registrations().find(name); if (it == registrations().end()){ - LOG_DEBUG(GwLog::ERROR,"invalid set %s not known",name.c_str()); + LOG_DEBUG(GwLog::ERROR,"TaskInterfaces: invalid set %s not known",name.c_str()); return false; } if (it->second.file != file){ - LOG_DEBUG(GwLog::ERROR,"invalid set %s wrong file, expected %s , got %s",name.c_str(),it->second.file.c_str(),file.c_str()); + LOG_DEBUG(GwLog::ERROR,"TaskInterfaces: invalid set %s wrong file, expected %s , got %s",name.c_str(),it->second.file.c_str(),file.c_str()); return false; } if (it->second.task != task){ - LOG_DEBUG(GwLog::ERROR,"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);