Hi,
sorry for the late reply, it seems I've opened a whole can of worms
with this small issue and I'm afraid to incur into a lot of
refactoring overhead just to handle a single corner case (who else
would ever need to handle multiple presentations?).
My current solution has apparently been deemed by Tanguy too 'low
level', so I need a new plan, but I also don't want to touch the
existing code wherever possible, here's the idea:
class PContactList
{
public:
PContactList( CContactList & cContactList )
: _cContactList(cContactList)
{}
CContactList & getCContactList() const
{
return _cContactList;
}
/* convert pure virtual functions into events, this:
* - allows multiple presentations to receive them
* - is consistent with the *Event naming convention
* - is completely compatible with the existing code
*/
Event<void (const std::string & contactId)> contactAddedEvent;
// and so on for the others...
};
class PFactory
{
public:
static Event<void (PContactList & pContactList)>
pContactListCreatedEvent;
// and so on ...
PContactList* createPContactList(CContactList & cContactList);
// ad nauseam ...
};
PContactList* PFactory::createPContactList(CContactList & cContactList)
{
PContactList* pContactList = new PContactList(cContactList);
pContactListCreatedEvent(*pContactList);
return pContactList;
}
class DBusFactory : public PFactory
{
public:
DBusFactory()
{
PFactory::pContactListCreatedEvent
+=
boost::bind(&DBusFactory::pContactListCreatedEventHandler, this, _1);
}
void pContactListCreatedEventHandler(PContactList & pContactList)
{
_dbusContactList = new DBusContactList(pContactList);
}
};
class QtFactory : public PFactory
{
//same as above
};
class DBusContactList : public DBus::ObjectAdaptor
{
public:
DBusContactList(PContactList & pContactList)
{
//other initialization
_pContactList.contactAddedEvent += boost::bind(...);
//bind other signals, if needed
}
void contactAddedEventHandler(const std::string & contactId)
{
// do stuff
}
};
which should work without changing the control layer at all, there's a
problem with postEvent/processEvents however, but I'll be happy to
leave the event handling to the qt part, is this going to have any
side effects?
not shown above, but when the control layer calls 'delete
pContactList' another event is needed to correctly free
DBusContactList and QtContactList.
(as an unrelated side note, the more I look at the code, the more I
think the model layer is a rendundant abstraction, it seems much
simpler to directly use ImWrapper/SipWrapper (which already are
abstractions themselves) and let the control layer do the aggregation,
please please please get rid of it :-)
P.D.
_______________________________________________
Wengophone-devel mailing list
[email protected]
http://dev.openwengo.com/mailman/listinfo/wengophone-devel