Theron  6.00.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
template<typename ObjectType >
bool Theron::Framework::SetFallbackHandler ( ObjectType *const  actor,
void(ObjectType::*)(const void *const data, const uint32_t size, const Address from)  handler 
)
inline

Sets the fallback message handler executed for unhandled messages.

This method sets a 'blind' default handler which, when executed, is passed the unknown message as blind data. The blind data consists of the memory block containing the message, identified by a void pointer and a size.

The fallback handler registered with the framework is run:

  • when a message is sent by an actor within this framework to an address at which no entity is currently registered.
  • when a message is sent using the Send method of this framework to an address at which no entity is currently registered.
  • when a message is delivered to an actor within this framework in which neither a handler for that message type nor a default handler are registered, with the result that the message goes unhandled.

The handler function registered by this method overload is passed the unhandled message as 'blind' data represented by a void pointer and a message size in bytes. Handlers registered using this method must expose a handler method that accepts a void pointer identifying the message contents, a size indicating the size of the message data, and a 'from' address.

A user-defined handler may be able to inspect the contents of the message and take appropriate action, such as reporting the contents of an unexpected message to help with debugging.

class Handler
{
public:
inline void Handle(const void *const data, const Theron::uint32_t size, const Theron::Address from)
{
printf("Caught undelivered or unhandled message of size %d sent from address '%d'\n", size, from.AsInteger());
}
};
Handler handler;
framework.SetFallbackHandler(&handler, &Handler::Handle);

Users can call this method to replace the default fallback handler with their own implementation, for example for more sophisticated error reporting or logging.

Passing 0 to this method clears any previously set fallback handler, or the default fallback handler if no user-defined handler has previously been set.

Note
There are two variants of SetFallbackHandler, accepting fallback handlers with different function signatures. Handlers set using this method accept the unhandled message as 'blind' data (ie. a void pointer and a size in bytes), whereas handlers set using the other method accept only the 'from' address. Registering either kind of fallback handler replaces any previously set handler of the other kind.
Template Parameters
ObjectTypeThe type of the handler object which owns the handler function.
Parameters
actorPointer to the handler object on which the handler function is a member function.
handlerMember function pointer identifying the fallback handler function.