From: Andreas V. <li...@br...> - 2008-08-18 20:30:21
|
Am Sun, 17 Aug 2008 15:34:49 +0200 schrieb P. Durante: > On Sun, Aug 17, 2008 at 11:21 AM, Christopher Lang > <chr...@ac...> wrote: > > > > Paolo, > > > > a question on your code: > > > > what is that "private" stuff all about? For example in class > > "Connection" you are using this: > > > > class DXXAPI Connection > > ... > > 59 struct Private; > > 60 > > 61 typedef std::list<Private*> PrivatePList; > > 62 > > 63 Connection( Private* ); > > > > Could you provide a little bit of rationale about this? It somehow > > confuses me. Is this simply a "private" dbus connection for example > > "app to app" connection? Or is this some (to me unknown) technique > > to produce c++ quasi private members in the "public" section? > > > > many thanks > > > > Chris > > > > > > it's not a private connection, it's the "private data" of that > particular class, objects and messages have private data too > > it's the typical pimpl pattern > > http://en.wikipedia.org/wiki/Pimpl > > and it serves two purposes: > > -copying semantics- > DBus::Connection objects (and any object implementing the same idiom) > can be copied and all copies will refer to the same, internal, libdbus > connection, reference counting is greatly simplified (look at the copy > constructor in connection.cpp) > > -isolation- > the public interface of the library (that is, the files under > include/) does not depend on libdbus, <dbus/dbus.h> is ONLY EVER > included from implementation files (under src/) Thanks for your explanations. I never used that design pattern. But it sounds interesting. I'll implement some samples the next days to get deeper into this design principle. As I understood it we could maybe solve that pthread runtime problem with the Pimpl design. In eventloop.h is this: class DXXAPI DefaultMutex { public: DefaultMutex(); ~DefaultMutex(); void lock(); void unlock(); private: #if defined HAVE_PTHREAD_H pthread_mutex_t _mutex; #elif defined HAVE_WIN32 //TODO: use a critical section #endif }; This was the reason for the private config header. Because if you compile dbus-c++ with HAVE_PTHREAD_H and then the app without you'll get a silent crash. Wouldn't a Pimpl implementation help here to avoid the private config header? regards Andreas |