Progress on Packets

Hi guys,

I did some work tonight on the new Packet abstraction and BitTorrent packets. As Anders suggested, I used QSharedData and QSharedDataPointer for reference counting of the private data instead of using QBasicAtomic directly. This resulted in a simpler Packet class.

I also extended the previous implementation so that the derived classes derive their private data classes from their parent’s. This trick is used Qt (QHttpHeader for example). The idea is that the class which is lowest in the inheritance tree creates the private data object and passes the pointer to its parent in the ctor initialization list. Since the private data class is derived form the private data class of the parent (and its parent and so on), then this object contains all the private data. The root of the inheritance tree initializes the QSharedDataPointer member d_ptr with the pointer to the private data object. To get this pointer casted correctly (and possibly detached), the macro Q_SD should be used (suggestions for a better name, or against using the prefix Q_?). In the very beginning of a const function that needs access to the private data we should write Q_SD (const Data); and for non-const functions we write Q_SD (Data); The macro expands to a declaration of an auto pointer to the casted private data. In case of a non-const pointer, the shared data is copied.

You need to write the macro Q_DECLARE_SHARED_DATA in the private section of the classes. It adds two help functions needed by the Q_SD macro. I took the corresponding macros from qglobal.h:1648-1659 (Qt 4.1.4) and modified them for our needs. At least to my knowledge no macros are provided in Qt that facilitate the use of QSharedData derived classes in polymorphic hierarchies. Any suggestions for improvements?

I was wondering whether to declare the members of Packet::Data as private or public. Declaring them as private and declaring friend Packet; will give access Packet access to its private data members, but not to Packet’s derived classes. I think that would be better. What do you guys think?

The attached patch shows only the changes done from my previous patch. You can pull all current changes from my public BitTorrent this way:

bzr branch http://bzr.calitko.org/developers/peter/calitko-BitTorrent -r 69

I’d like to provide each active developer their own public repository but I have not done the necessary setup yet. If anybody can recommend me a good tutorial for setting up WebDAV, for which I’ll need to upgrade to Apache 2 on Debian Sarge, I’ll be thankful. I should check whether WebDAV support for bzr is built in or a separate plugin installation is required. Another possibility would be to wait that more progress is done on bzr SmartServer and use it.

Regards,

Peter

Attached Files:

Would you like to post a relpy?


This post starts a thread.
No follow-ups yet.