make plugin reply handling simpler

This commit is contained in:
Kevin Hester
2020-12-13 12:57:37 +08:00
parent ad8bcba5ef
commit ee8f4de5ab
5 changed files with 29 additions and 15 deletions

View File

@@ -5,6 +5,8 @@
std::vector<MeshPlugin *> *MeshPlugin::plugins;
const MeshPacket *MeshPlugin::currentRequest;
MeshPlugin::MeshPlugin(const char *_name) : name(_name)
{
// Can't trust static initalizer order, so we check each time
@@ -27,11 +29,13 @@ void MeshPlugin::callPlugins(const MeshPacket &mp)
// DEBUG_MSG("In call plugins\n");
for (auto i = plugins->begin(); i != plugins->end(); ++i) {
auto &pi = **i;
pi.currentRequest = &mp;
if (pi.wantPortnum(mp.decoded.data.portnum)) {
bool handled = pi.handleReceived(mp);
// Possibly send replies (unless we are handling a locally generated message)
if (mp.decoded.want_response && mp.from != nodeDB.getNodeNum())
// Possibly send replies
if (mp.decoded.want_response)
pi.sendResponse(mp);
DEBUG_MSG("Plugin %s handled=%d\n", pi.name, handled);
@@ -41,6 +45,7 @@ void MeshPlugin::callPlugins(const MeshPacket &mp)
else {
DEBUG_MSG("Plugin %s not interested\n", pi.name);
}
pi.currentRequest = NULL;
}
}