Plugins refactoring: handleReceived return enumeration ProcessMessage

Use `ProcessMessage::CONTINUE` to allows other modules to process a message.
Use `ProcessMessage::STOP` to stop further message processing.
This commit is contained in:
Vladislav Osmanov
2021-09-23 04:42:09 +03:00
parent b182819aff
commit debae67ae7
13 changed files with 39 additions and 27 deletions

View File

@@ -143,7 +143,7 @@ ExternalNotificationPlugin::ExternalNotificationPlugin()
#endif
}
bool ExternalNotificationPlugin::handleReceived(const MeshPacket &mp)
ProcessMessage ExternalNotificationPlugin::handleReceived(const MeshPacket &mp)
{
#ifndef NO_ESP32
@@ -176,5 +176,5 @@ bool ExternalNotificationPlugin::handleReceived(const MeshPacket &mp)
#endif
return false; // Very important to never return TRUE here. TRUE means we handled the packet and we will stop letting other plugins see it
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
}

View File

@@ -24,9 +24,9 @@ class ExternalNotificationPlugin : public SinglePortPlugin, private concurrency:
/** Called to handle a particular incoming message
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it
*/
virtual bool handleReceived(const MeshPacket &mp);
virtual ProcessMessage handleReceived(const MeshPacket &mp);
virtual int32_t runOnce();
};

View File

@@ -157,7 +157,7 @@ void SerialPluginRadio::sendPayload(NodeNum dest, bool wantReplies)
service.sendToMesh(p);
}
bool SerialPluginRadio::handleReceived(const MeshPacket &mp)
ProcessMessage SerialPluginRadio::handleReceived(const MeshPacket &mp)
{
#ifndef NO_ESP32
@@ -207,5 +207,5 @@ bool SerialPluginRadio::handleReceived(const MeshPacket &mp)
#endif
return true; // Let others look at this message also if they want
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
}

View File

@@ -45,9 +45,9 @@ class SerialPluginRadio : public SinglePortPlugin
/** Called to handle a particular incoming message
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it
*/
virtual bool handleReceived(const MeshPacket &mp);
virtual ProcessMessage handleReceived(const MeshPacket &mp);
};
extern SerialPluginRadio *serialPluginRadio;

View File

@@ -5,7 +5,7 @@
TextMessagePlugin *textMessagePlugin;
bool TextMessagePlugin::handleReceived(const MeshPacket &mp)
ProcessMessage TextMessagePlugin::handleReceived(const MeshPacket &mp)
{
auto &p = mp.decoded;
DEBUG_MSG("Received text msg from=0x%0x, id=0x%x, msg=%.*s\n", mp.from, mp.id, p.payload.size, p.payload.bytes);
@@ -18,5 +18,5 @@ bool TextMessagePlugin::handleReceived(const MeshPacket &mp)
powerFSM.trigger(EVENT_RECEIVED_TEXT_MSG);
notifyObservers(&mp);
return false; // Let others look at this message also if they want
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
}

View File

@@ -17,9 +17,9 @@ class TextMessagePlugin : public SinglePortPlugin, public Observable<const MeshP
/** Called to handle a particular incoming message
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it
*/
virtual bool handleReceived(const MeshPacket &mp);
virtual ProcessMessage handleReceived(const MeshPacket &mp);
};
extern TextMessagePlugin *textMessagePlugin;

View File

@@ -123,7 +123,7 @@ void RangeTestPluginRadio::sendPayload(NodeNum dest, bool wantReplies)
powerFSM.trigger(EVENT_CONTACT_FROM_PHONE);
}
bool RangeTestPluginRadio::handleReceived(const MeshPacket &mp)
ProcessMessage RangeTestPluginRadio::handleReceived(const MeshPacket &mp)
{
#ifndef NO_ESP32
@@ -181,7 +181,7 @@ bool RangeTestPluginRadio::handleReceived(const MeshPacket &mp)
#endif
return true; // Let others look at this message also if they want
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
}
/// Ported from my old java code, returns distance in meters along the globe

View File

@@ -50,9 +50,9 @@ class RangeTestPluginRadio : public SinglePortPlugin
/** Called to handle a particular incoming message
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it
*/
virtual bool handleReceived(const MeshPacket &mp);
virtual ProcessMessage handleReceived(const MeshPacket &mp);
};
extern RangeTestPluginRadio *rangeTestPluginRadio;

View File

@@ -191,7 +191,7 @@ void StoreForwardPlugin::sendPayloadWelcome(NodeNum dest, bool wantReplies)
service.sendToMesh(p);
}
bool StoreForwardPlugin::handleReceived(const MeshPacket &mp)
ProcessMessage StoreForwardPlugin::handleReceived(const MeshPacket &mp)
{
#ifndef NO_ESP32
if (radioConfig.preferences.store_forward_plugin_enabled) {
@@ -217,7 +217,7 @@ bool StoreForwardPlugin::handleReceived(const MeshPacket &mp)
#endif
return true; // Let others look at this message also if they want
return ProcessMessage::CONTINUE; // Let others look at this message also if they want
}
StoreForwardPlugin::StoreForwardPlugin()

View File

@@ -51,9 +51,9 @@ class StoreForwardPlugin : public SinglePortPlugin, private concurrency::OSThrea
/** Called to handle a particular incoming message
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
@return ProcessMessage::STOP if you've guaranteed you've handled this message and no other handlers should be considered for it
*/
virtual bool handleReceived(const MeshPacket &mp);
virtual ProcessMessage handleReceived(const MeshPacket &mp);
};
extern StoreForwardPlugin *storeForwardPlugin;