move want_replies into new plugin system

This commit is contained in:
Kevin Hester
2020-12-05 11:15:06 +08:00
parent 91b99bd584
commit 3e0dc44210
8 changed files with 44 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
#include "MeshPlugin.h"
#include "NodeDB.h"
#include <assert.h>
std::vector<MeshPlugin *> *MeshPlugin::plugins;
@@ -27,6 +28,11 @@ void MeshPlugin::callPlugins(const MeshPacket &mp)
auto &pi = **i;
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())
pi.sendResponse(mp.from);
DEBUG_MSG("Plugin %s handled=%d\n", pi.name, handled);
if (handled)
break;

View File

@@ -47,4 +47,10 @@ class MeshPlugin
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
*/
virtual bool handleReceived(const MeshPacket &mp) { return false; }
/** Messages can be received that have the want_response bit set. If set, this callback will be invoked
* so that subclasses can (optionally) send a response back to the original sender. Implementing this method
* is optional
*/
virtual void sendResponse(NodeNum to) {}
};

View File

@@ -96,9 +96,6 @@ int MeshService::handleFromRadio(const MeshPacket *mp)
MeshPacket *copied = packetPool.allocCopy(*mp);
assert(toPhoneQueue.enqueue(copied, 0)); // FIXME, instead of failing for full queue, delete the oldest mssages
if (mp->decoded.want_response)
sendNetworkPing(mp->from);
return 0;
}