Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > design problem, a general message passing class

Reply
Thread Tools

design problem, a general message passing class

 
 
Ethan
Guest
Posts: n/a
 
      06-18-2009
the problem is to hide transport layer (tcp, raw ip, tibco, etc ) from
applications

I am thinking of to have a transceiver interface (abstract class),
which shall define some operations and callbacks.
The interface shall be sufficient for common communication task over
networks. different implementations, e.g. TcpTransceiver will be
derived from this interface.

user apps will only need to know this interface, completely separate
itself from the underlying technology.

I have little experience on this, I am looking for inputs on how the
interface should look like
I can think of some virtual functions, such as

sendMsg,
initConnection,
connectTo,

callbacks that users have to implement, such as onAccept, onConnect,
onReceive etc.
anything else?

also, it's nice to be able to support unicast and multicast
transparently too.

any idea? thanks!!

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

 
Reply With Quote
 
 
 
 
AnonMail2005@gmail.com
Guest
Posts: n/a
 
      06-18-2009
On Jun 17, 10:36 pm, Ethan <ethan.li...@gmail.com> wrote:
> the problem is to hide transport layer (tcp, raw ip, tibco, etc ) from
> applications
>
> I am thinking of to have a transceiver interface (abstract class),
> which shall define some operations and callbacks.
> The interface shall be sufficient for common communication task over
> networks. different implementations, e.g. TcpTransceiver will be
> derived from this interface.
>
> user apps will only need to know this interface, completely separate
> itself from the underlying technology.
>
> I have little experience on this, I am looking for inputs on how the
> interface should look like
> I can think of some virtual functions, such as
>
> sendMsg,
> initConnection,
> connectTo,
>
> callbacks that users have to implement, such as onAccept, onConnect,
> onReceive etc.
> anything else?
>
> also, it's nice to be able to support unicast and multicast
> transparently too.
>
> any idea? thanks!!
>
> --


Check out asio in boost. It probably has most of what you need. And
I believe it's extensible so you can add commercial "transports" like
tibco.

HTH


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

 
Reply With Quote
 
 
 
 
Maxim Yegorushkin
Guest
Posts: n/a
 
      06-18-2009
Ethan wrote:
> the problem is to hide transport layer (tcp, raw ip, tibco, etc ) from
> applications
>
> I am thinking of to have a transceiver interface (abstract class),
> which shall define some operations and callbacks.
> The interface shall be sufficient for common communication task over
> networks. different implementations, e.g. TcpTransceiver will be
> derived from this interface.
>
> user apps will only need to know this interface, completely separate
> itself from the underlying technology.
>
> I have little experience on this, I am looking for inputs on how the
> interface should look like
> I can think of some virtual functions, such as
>
> sendMsg,
> initConnection,
> connectTo,
>
> callbacks that users have to implement, such as onAccept, onConnect,
> onReceive etc.
> anything else?
>
> also, it's nice to be able to support unicast and multicast
> transparently too.


You can achieve this quite easily using design based on interfaces and message
passing. In this particular case Bridge design pattern is what you need. Example:

struct MsgX { ... };
struct MsgY { ... };

struct Connection
{
struct Callback
{
virtual void connected(Connection*) = 0;
virtual void receive(MsgX) = 0;
virtual void receive(MsgY) = 0;
virtual void disconnected(Connection*, int err) = 0;

protected: // no polymorphic destruction required
~Callback() {}
};

virtual void send(MsgX) = 0;
virtual void send(MsgY) = 0;
virtual ~Connection() = 0;
};

std::auto_ptr<Connection> createTcpConnection(Connection::Callback* callback,
char const* host_port);
std::auto_ptr<Connection> createWhateverConnection(Connection::Callback*
callback, ...);

In this design Connection interface represents a connection. Factory functions
createTcpConnection() and createWhateverConnection() create an instance of a
(hidden) class which implements Connection interface. Normally, these factory
functions along with particular classes that implement Connection interface are
implemented by a shared library. That shared library only exposes the factory
functions.

Interface Connection::Callback is implemented by an application that uses
Connection. An application creates an object of a class that implements
Connection::Callback interface and passes the pointer to that object to one of
the Connection factory functions.

This way you achieve good decoupling between connection and its user
implementations, which is the essence of Bridge design pattern.

For simplicity, the server/acceptor interface and factory functions are not
shown here, but they would use the same design pattern.

--
Max



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

 
Reply With Quote
 
Tony
Guest
Posts: n/a
 
      06-19-2009
Ethan wrote:
> the problem is to hide transport layer (tcp, raw ip, tibco, etc ) from
> applications
>
> I am thinking of to have a transceiver interface (abstract class),
> which shall define some operations and callbacks.
> The interface shall be sufficient for common communication task over
> networks. different implementations, e.g. TcpTransceiver will be
> derived from this interface.
>
> user apps will only need to know this interface, completely separate
> itself from the underlying technology.
>
> I have little experience on this, I am looking for inputs on how the
> interface should look like
> I can think of some virtual functions, such as
>
> sendMsg,
> initConnection,
> connectTo,
>
> callbacks that users have to implement, such as onAccept, onConnect,
> onReceive etc.
> anything else?
>
> also, it's nice to be able to support unicast and multicast
> transparently too.
>
> any idea? thanks!!


Maybe this will help:

http://www.cs.wustl.edu/~schmidt/ACE.html

or maybe this:

http://qpid.apache.org/


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Explicitly "Matrix" class, or general "Transform" class? Mike Oliver C++ 0 02-01-2011 11:11 PM
General....very general.... no important for u forever hi Python 0 03-18-2009 08:21 AM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
General Design Question classic versus asp.net methodology needin4mation@gmail.com ASP .Net 3 07-25-2005 03:24 PM
General Question about java parameters / OOP good design techniques antoine Java 7 03-03-2005 05:01 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57