You are here:
Message filters

The most basic way of receiving messages is polling the rcm::Endpoint object using rcm::Endpoint::getPendingMessage. Sometimes however, this method is not convenient.

Another possible method is to insert a message filter into the endpoint reception processing. The idea is that each message goes through a chain of message filters. Each filter executes is's message matching function, that can do something with the message. In particular, the filter can remove the message from the filtering chain, causing it to be "swallowed".

Defining message filters

A message filter is an object of a class, that realizes the rcm::MessageFilter interface, by defining a custom message filtering procedure - rcm::MessageFilter::filterProc. This procedure will be used to processed each incoming message that goes through the filter. In case the filter processes the message and should remove it from further processing this method should return true, otherwise false return value will mean that the message was not "caught" by this filter.

The following example illustrates the message filtering concept:

#include "rcmpp.h"
class MyFilter : public rcm::MessageFilter
virtual bool filterProc(rcm::Message& message) {
if (message.getSrcShortAddress() == 1) {
return true;
return false;
int rcmpp_message_filter_example(const char* portName)
int result = 0;
MyFilter filter;
try {
// construct the connection object
rcm::Connection rcm(portName);
// set UID
// configure networking
rcm.configureNode(RCM_DEVICE_TYPE_COORDINATOR, 0x1122334455667788, RCM_ADDRESSING_SCHEME_STATIC, 0);
// register endpoint 1
rcm::Endpoint& ep1 = rcm.registerEndpoint(1);
// insert filter
// start networking
if (rcm.startNetworking()) {
// delay
// leave the network
// remove filter
catch(rcm::exception &e) {
result = 100;
catch(std::exception &e) {
result = 101;
catch (...) {
result = 102;
return result;
Go to Top