Boost logo

Boost :

From: simon meiklejohn (simon_at_[hidden])
Date: 2005-12-12 14:41:23


Hi Chris,

Almost all my use cases for a network lib involve a lot of
fan-out - ie branching based on the contents of a
message, which gets implemented as client code deriving
from an interface class such as

struct ISomeCustomMessageSet
{
    virtual void Custom1( Custom1Msg& msg );
    virtual void Custom2( Custom2Msg& msg);
    virtual void Custom3( Custom3Msg& mgs);
    ... etc
};

Now assuming i've written some code using asio that
sits on the network receiving and parseing the relevant
message i might connect to that component as follows

// class that wants the messages
class MessageRecipient : public ISomeCustomMessageSet
{
public:
    void Custom1( CustomMessage1& msg ) { /* do useful work */ }
    etc
};

class MessageListenerOnAsio // listens and parses
{
    void Register( ISomeCustomMessageSet* registered) { registered_ =
registered; }
    .. listening/receiving using asio

    {
        // at some point need to call back into the registered_ interface
        registered_->Custom1( a_msg );
    }
}

main()
{
    // pseudo code
    MessageRecipient recipient;
    boost::asio::demuxer demux;
    MessageListenerOnAsio listener(demux );
    listener.register( &recipient );
    demux.run();
}

All well and good, but what if i want to use the dispatcher concept
for the callbacks. i.e. i'd like to be able to do the equivalent of

    boost::asio::some_dispatcher_class listener_dispatch;
    listener.register( listener_dispatch.wrap( recipient ) );

I know that's not correct asio - but what's a recommended way to
achieve this without wrapping each method of the interface.

Cheers

Simon


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk