Connecting Tech Pros Worldwide Forums | Help | Site Map

Class interaction question

Angus
Guest
 
Posts: n/a
#1: Aug 22 '07
I am designing an FTP server and with FTP commands are dispatched on
one port and the actual data transmission on another.

So I thought I would have a CFTPControl class for handlng the commands
and a CFTPData class for the actual data transmission.

But CFTPControl needs to know when the data transmission has
completed. What is the best way to handle this interaction between
the classes?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
 
Posts: n/a
#2: Aug 22 '07

re: Class interaction question


On 2007-08-22 18:03, Angus wrote:
Quote:
I am designing an FTP server and with FTP commands are dispatched on
one port and the actual data transmission on another.
>
So I thought I would have a CFTPControl class for handlng the commands
and a CFTPData class for the actual data transmission.
>
But CFTPControl needs to know when the data transmission has
completed. What is the best way to handle this interaction between
the classes?
I think your biggest problem is the assumption that you should use those
classes. The FTP protocol is best modelled by a state machine, figure
out how to do that and you have a good start. Since you are building a
server you probably want to handle more than one connection and each
connection needs to implement the state machine, so perhaps the class
you should be designing is the Connection class.

--
Erik Wikström
Joe Greer
Guest
 
Posts: n/a
#3: Aug 22 '07

re: Class interaction question


Angus <anguscomber@gmail.comwrote in news:1187798603.500722.26020
@m37g2000prh.googlegroups.com:
Quote:
I am designing an FTP server and with FTP commands are dispatched on
one port and the actual data transmission on another.
>
So I thought I would have a CFTPControl class for handlng the commands
and a CFTPData class for the actual data transmission.
>
But CFTPControl needs to know when the data transmission has
completed. What is the best way to handle this interaction between
the classes?
>
It seems like the Observer pattern is a natural fit.

class CFTPData;

class IDataReport
{
public:
virtual void OnDataDone(CFTPData *) = 0;
virtual ~IDataReport() {}
};

class CFTPData
{
IDataReport * m_pObserver;
public:
void RegisterObserver(IDataReport * pObserver)
{ m_pObserver = pObserver; }

void Process()
{ /* Do stuff */ if (m_pObserver) m_pObserver->OnDataDone(this); }
};

class CFTPControl : private IDataReport
{
public:
void Observe(CFTPData * pSubject)
{ pSubject->RegisterObserver(this); }

private:
void OnDataDone(CFTPData * pSubject)
{ /* wheee the data is done */ }
};

I don't know that you strictly need the pointer to the subject, but I
have yet to use the Observer pattern where knowing which object was
notifying you wasn't important in some fashion. Obviously, the single
pointer can be a vector of pointers if you are going to allow more than
one observer. The functionality in the Observe() method can be done
anyplace you have a pointer to the subject, so don't take the above too
literally.

joe
Jorgen Grahn
Guest
 
Posts: n/a
#4: Aug 25 '07

re: Class interaction question


On Wed, 22 Aug 2007 16:19:12 GMT, Erik Wikström <Erik-wikstrom@telia.comwrote:
Quote:
On 2007-08-22 18:03, Angus wrote:
Quote:
>I am designing an FTP server and with FTP commands are dispatched on
>one port and the actual data transmission on another.
>>
>So I thought I would have a CFTPControl class for handlng the commands
>and a CFTPData class for the actual data transmission.
>>
>But CFTPControl needs to know when the data transmission has
>completed. What is the best way to handle this interaction between
>the classes?
>
I think your biggest problem is the assumption that you should use those
classes. The FTP protocol is best modelled by a state machine, figure
out how to do that and you have a good start.
Yes. The only thing I know about the FTP protocol is that it is more
complex than I think. Hell, it's even hard to find all the relevant
RFCs!

The original poster should make sure he knows more than "there are two
different sockets" before he starts looking for classes -- or he'll
risk having to tear down his design and start from scratch when he,
belatedly, discovers one of the many odd corner cases.

(I just echoed what you said but in many more words, didn't I?)

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyndns.org R'lyeh wgah'nagl fhtagn!
Closed Thread