C++ Message map/decoding pattern?

S

Scott Fraysia

The product I am working on will employ a messaging scheme to
communicate between components. This therefore requires that a message
'mapping' mechanism be implemented to identify and decode messages and
delegate the processing of each message to the appropriate handler.

I have seen how, for instance, MFC uses a set of macros to construct a
'message map', but I would prefer that macros were not used. On first
glance I was thinking along the lines of a member-function
template/functor.

In effect, I'm looking for an extensible OO/Pattern based way of
constructing a mapping of various message 'triggers' to handlers, such
as:

if (message is of type 'a')
call handler for messages of type 'a'
else if (message is from component 'b')
call handler for messages from component 'b'
else if (message contains data of type 'c'
call handler for messages containing data of type 'c'

etc

I was hoping not to have to call each and every handler, as there is
likely to be 100s of components, so calling all handlers for all
components when a message is 'broadcast' would likely become rather
inefficient.

Any ideas on books/pattern references ?

I havent seen any of the GOF patterns matching this really, but then,
I could be mistaken.

Scott.
 
P

Phlip

Scott said:
The product I am working on will employ a messaging scheme to
communicate between components. This therefore requires that a message
'mapping' mechanism be implemented to identify and decode messages and
delegate the processing of each message to the appropriate handler.

I have seen how, for instance, MFC uses a set of macros to construct a
'message map', but I would prefer that macros were not used. On first
glance I was thinking along the lines of a member-function
template/functor.

In effect, I'm looking for an extensible OO/Pattern based way of
constructing a mapping of various message 'triggers' to handlers, such
as:

if (message is of type 'a')
call handler for messages of type 'a'
else if (message is from component 'b')
call handler for messages from component 'b'
else if (message contains data of type 'c'
call handler for messages containing data of type 'c'

Read the Prototype and two Factory Patterns from the book /Design Patterns/.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,052
Latest member
KetoBeez

Latest Threads

Top