Class interaction question

A

Angus

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?=

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

Joe Greer

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
 
J

Jorgen Grahn

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top