Tuesday, 3 February 2009

Time for GaduProtocol

Unfortunately it is impossible to do full ULE to ContactList transition without making some changes in Gadu-Gadu protocol implementation. Code responsible for exporting/importing list of contacts depends on old classes. So I had a look into gadu_protocol module and...

And I started refactoring it a bit. I know I've done it about year ago, but now I see that it was not well done: files and classes are too large. Some method also. Yesterday three classes were moved to their own files. Next step require removing all references to old UserStatus (and GaduUserStatus classes) and replacing it with the brand-new Status class.

But what was wrong with UserStatus? It does tasks that only Protocol class should have: it has slots, signals (for informing it was changed). Both protocol classes and Kadu main class conencted to it. The code flow:
  • Kadu: protocol->writeableStatus().setStatus(newStatus)
  • Status: emit goOnline("description")
  • Protocol: slot iWantGoOnline("description")
  • Protocol: communication with server
  • Protocol: CurrentStatus->setStatus(newStatus)
  • CurrentStatus emit goOnline("description")
  • Kadu: wentOnline("description")
Many unnecessary slots/signals. The right way to do it:
  • Kadu: protocol->setStatus(newStatus)
  • Protocol: communication with server
  • Protocol: emit statusChanged(newStatus)
We need the statusChanged signal, because the status setting can be asynchronous.

So the Status class is now very lightweight and does just what it should do - stores 2 pieces of data. Protocol and Kadu classes lost lot of signals and slots. And logic is much simpler ;)

After I sort out the Status class I'll look if splitting GaduProtocol into smaller classes (like GaduConnection) makes sense - I just like small classes ;)

No comments:

Post a Comment