X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=zypp%2FCallback.h;h=99037f2e8aff5f41cfe46bd33b95cb474eddcee9;hb=HEAD;hp=b3eb516f2b71c79af0e3ca02768156e49e6be75b;hpb=8a20984c410ec7051149370274a760885c6452ad;p=platform%2Fupstream%2Flibzypp.git diff --git a/zypp/Callback.h b/zypp/Callback.h index b3eb516..634d22e 100644 --- a/zypp/Callback.h +++ b/zypp/Callback.h @@ -12,7 +12,8 @@ #ifndef ZYPP_CALLBACK_H #define ZYPP_CALLBACK_H -#include "zypp/base/NonCopyable.h" +#include +#include /////////////////////////////////////////////////////////////////// namespace zypp @@ -31,7 +32,7 @@ namespace zypp * \par The task report structure (SENDER SIDE). * * A default constructible struct derived from callback::ReportBase. - * It \b must \b not conatin any data, just virtual methods. + * It \b must \b not contain any data, just virtual methods. * * These are the functions the sender invokes, and which will be forwarded * to some receiver. If no receiver is present, the defined default @@ -57,7 +58,7 @@ namespace zypp * * \par Sending a Task report (SENDER SIDE). * - * Simply create a callback::SendReport<_Report>, where _Report + * Simply create a callback::SendReport, where TReport * is your task report structure. Invoke the callback functions * as needed. That's it. * @@ -120,33 +121,55 @@ namespace zypp * a Callback light). * \li \c disconnect Disconnect this ReceiveReport in case it is * connected. If not connected nothing happens. - * \li \c connected Test wheter this ReceiveReport is currently + * \li \c connected Test whether this ReceiveReport is currently * connected. * \li \c whoIsConnected Return a 'ReceiveReport*' to the currently * connected ReceiveReport, or \c NULL if none is connected. * - */ + * \par Passing Userdata via Callbacks + * + * For typesafe passing of user data via callbacks \see \ref UserData. + * + * ReportBase provides a generic \ref callback::ReportBase:report method + * which can be used to communicate by encoding everything in its \a UserData + * argument. + * + * Convenient sending can be achieved by installing non-virtual methods + * in the TReport class, which encode the arguments in UserData and send + * them via ReportBase::report(). + * + * Convenient receiving can be achieved by installing virtual methods in + * the TReport class, which can be simply overloaded by the receiver. Downside + * of this is that adding virtual methods breaks binary compatibility. + */ namespace callback { ///////////////////////////////////////////////////////////////// /** */ struct ReportBase { + typedef callback::UserData UserData; + typedef UserData::ContentType ContentType; + + /** The most generic way of sending/receiving data. */ + virtual void report( const UserData & userData_r = UserData() ) + {} + virtual ~ReportBase() {} }; /** */ - template - class DistributeReport; + template + struct DistributeReport; /** */ - template - struct ReceiveReport : public _Report + template + struct ReceiveReport : public TReport { - typedef _Report ReportType; - typedef ReceiveReport<_Report> Receiver; - typedef DistributeReport<_Report> Distributor; + typedef TReport ReportType; + typedef ReceiveReport Receiver; + typedef DistributeReport Distributor; virtual ~ReceiveReport() { disconnect(); } @@ -170,13 +193,13 @@ namespace zypp }; /** */ - template + template struct DistributeReport { public: - typedef _Report ReportType; - typedef ReceiveReport<_Report> Receiver; - typedef DistributeReport<_Report> Distributor; + typedef TReport ReportType; + typedef ReceiveReport Receiver; + typedef DistributeReport Distributor; static DistributeReport & instance() { @@ -209,12 +232,12 @@ namespace zypp }; /** */ - template + template struct SendReport : private zypp::base::NonCopyable { - typedef _Report ReportType; - typedef ReceiveReport<_Report> Receiver; - typedef DistributeReport<_Report> Distributor; + typedef TReport ReportType; + typedef ReceiveReport Receiver; + typedef DistributeReport Distributor; SendReport() { Distributor::instance()->reportbegin(); } @@ -222,6 +245,12 @@ namespace zypp ~SendReport() { Distributor::instance()->reportend(); } + static Receiver * whoIsConnected() + { return Distributor::instance().getReceiver(); } + + static bool connected() + { return whoIsConnected(); } + Distributor & operator->() { return Distributor::instance(); } }; @@ -251,12 +280,12 @@ namespace zypp * ...// r receiving the report * \endcode */ - template + template struct TempConnect { - typedef _Report ReportType; - typedef ReceiveReport<_Report> Receiver; - typedef DistributeReport<_Report> Distributor; + typedef TReport ReportType; + typedef ReceiveReport Receiver; + typedef DistributeReport Distributor; TempConnect() : _oldRec( Distributor::instance().getReceiver() )