[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

design problem - message translator

forums_mp

10/12/2008 2:59:00 AM


Facing a design problem here and I'm not sure how to solve this. The
system consists of bi-directional communication between a subject
communicating with two (at least for now ) listeners. Message
translation needs to occur during communication. Each message
between subject and listener contains 30 words where each word is
16bits in size. The first word in each message is a header.

Communication between Subject and Listeners can be described as
follows: Subject sends an ST1 message to Listeners.

Listeners 1 will extract the words from an ST1 message that is
important to Listener 1 and in doing so build an LR1 and LR2
message. LR1 and LR2 are messages Listener 1 understands. In other
words, Words 4,5,8 and 10 from an ST1 message gets copied into an LR1
message. Words 2,5,9,15,17 and 21 from an ST1 message gets copied
into an LR2 message.

Listeners 2 will extract the words from an ST1 message that is
important to Listener 2 and in doing so build an LR3 and LR4
message. LR3 and LR4 are messages Listener 2 understands. In other
words, Words 2,4,22,24,26 and 28 from an ST1 message gets copied into
an LR3 message. Words 12,17,19,20,22, and 27 from an ST1 message
gets copied into an LR4 message.

In my current design each Listener gets an ST1 message and this is
quickly becoming a maintenance nightmare. I'd like to place a message
handler/translator in the middle. The message translators job is to
translate an ST1 message into the appropriate format the Listener
understands. The translator will then give the Listener an LR1,LR2
(Listener1) or LR3,LR4(Listener2) message. I believe that a generic
solution exists that will accomplish the goal of the translator but
I'm not sure how to do this. I'm not sure how to structure the
translator and in doing so exploit C++ template facilities to
accomplish my objective.


Any help appreciated. Thanks in advance.


2 Answers

Sam

10/12/2008 3:27:00 AM

0

forums_mp@hotmail.com writes:

> [ long winded description ]
>
> understands. The translator will then give the Listener an LR1,LR2
> (Listener1) or LR3,LR4(Listener2) message. I believe that a generic
> solution exists that will accomplish the goal of the translator but
> I'm not sure how to do this. I'm not sure how to structure the
> translator and in doing so exploit C++ template facilities to
> accomplish my objective.

I see no reason for an overcomplicated solution. As I understand it, you
only need a generic superclass that retrieves an arbitrary elements from an
array, whose indexes are specified by a subclass. Then, you define the
appropriate subclasses for each one of your LRn messages.

Problem solved.


James Kanze

10/12/2008 9:48:00 AM

0

On Oct 12, 4:58 am, forums...@hotmail.com wrote:
> Facing a design problem here and I'm not sure how to solve
> this.   The system consists of bi-directional communication
> between a subject communicating with two (at least for now )
> listeners.    Message translation needs to occur during
> communication.   Each message between subject and listener
> contains 30 words where each word is 16bits in size.  The
> first word in each message is a header.

> Communication between Subject and Listeners can be described
> as follows:  Subject sends an ST1 message to Listeners.

> Listeners 1 will extract the words from an ST1 message that is
> important to Listener 1 and in doing so build an LR1 and LR2
> message.   LR1 and LR2 are messages Listener 1 understands.  
> In other words,  Words 4,5,8 and 10 from an ST1 message gets
> copied into an LR1 message.   Words 2,5,9,15,17 and 21 from an
> ST1 message gets copied into an LR2 message.

> Listeners 2 will extract the words from an ST1 message that is
> important to Listener 2 and in doing so build an LR3 and LR4
> message.   LR3 and LR4 are messages Listener 2 understands.  
> In other words,  Words 2,4,22,24,26 and 28 from an ST1 message
> gets copied into an LR3 message.   Words 12,17,19,20,22, and
> 27 from an ST1 message gets copied into an LR4 message.

> In my current design each Listener gets an ST1 message and
> this is quickly becoming a maintenance nightmare.  I'd like to
> place a message handler/translator in the middle.  The message
> translators job is to translate an ST1 message into the
> appropriate format the Listener understands.  The translator
> will then give the Listener an LR1,LR2 (Listener1) or
> LR3,LR4(Listener2) message.    I believe that a generic
> solution exists that will accomplish the goal of the
> translator but I'm not sure how to do this.   I'm not sure how
> to structure the translator and in doing so exploit C++
> template facilities to accomplish my objective.

This sounds more or less like you want the adapter pattern,
although I'm not too sure why only accessing a subset of the
information in a given message is becoming a maintenance
nightmare.

--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34