C++ Message map/decoding pattern?

Discussion in 'C++' started by Scott Fraysia, Jun 3, 2004.

  1. 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.
    Scott Fraysia, Jun 3, 2004
    #1
    1. Advertising

  2. Scott Fraysia

    Phlip Guest

    Scott Fraysia wrote:

    > 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/.

    --
    Phlip
    http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
    Phlip, Jun 3, 2004
    #2
    1. Advertising

  3. Have you considered chain-of-responsibility pattern ?

    "Scott Fraysia" <> wrote in message
    news:...
    > 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.
    Dave Townsend, Jun 3, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    17
    Views:
    1,849
    Chris Uppal
    Nov 16, 2005
  2. sunny
    Replies:
    1
    Views:
    451
    Salt_Peter
    Dec 7, 2006
  3. Pallav singh
    Replies:
    0
    Views:
    345
    Pallav singh
    Jan 22, 2012
  4. Pallav singh
    Replies:
    0
    Views:
    391
    Pallav singh
    Jan 22, 2012
  5. Pallav singh
    Replies:
    1
    Views:
    443
    Peter Remmers
    Jan 22, 2012
Loading...

Share This Page