fixup Fix to build with libxml 2.12.x (fixes #505)
[platform/upstream/libzypp.git] / zypp / Callback.h
index b3eb516..634d22e 100644 (file)
@@ -12,7 +12,8 @@
 #ifndef ZYPP_CALLBACK_H
 #define ZYPP_CALLBACK_H
 
-#include "zypp/base/NonCopyable.h"
+#include <zypp/base/NonCopyable.h>
+#include <zypp/UserData.h>
 
 ///////////////////////////////////////////////////////////////////
 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<TReport>, 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 _Report>
-      class DistributeReport;
+    template<class TReport>
+      struct DistributeReport;
 
     /**  */
-    template<class _Report>
-      struct ReceiveReport : public _Report
+    template<class TReport>
+      struct ReceiveReport : public TReport
       {
-       typedef _Report                   ReportType;
-       typedef ReceiveReport<_Report>    Receiver;
-        typedef DistributeReport<_Report> Distributor;
+       typedef TReport                   ReportType;
+       typedef ReceiveReport<TReport>    Receiver;
+        typedef DistributeReport<TReport> Distributor;
 
         virtual ~ReceiveReport()
         { disconnect(); }
@@ -170,13 +193,13 @@ namespace zypp
       };
 
     /**  */
-    template<class _Report>
+    template<class TReport>
       struct DistributeReport
       {
        public:
-       typedef _Report                   ReportType;
-       typedef ReceiveReport<_Report>    Receiver;
-       typedef DistributeReport<_Report> Distributor;
+       typedef TReport                   ReportType;
+       typedef ReceiveReport<TReport>    Receiver;
+       typedef DistributeReport<TReport> Distributor;
 
          static DistributeReport & instance()
          {
@@ -209,12 +232,12 @@ namespace zypp
       };
 
     /**  */
-    template<class _Report>
+    template<class TReport>
       struct SendReport : private zypp::base::NonCopyable
       {
-       typedef _Report                   ReportType;
-        typedef ReceiveReport<_Report>    Receiver;
-        typedef DistributeReport<_Report> Distributor;
+       typedef TReport                   ReportType;
+        typedef ReceiveReport<TReport>    Receiver;
+        typedef DistributeReport<TReport> 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<class _Report>
+    template<class TReport>
       struct TempConnect
       {
-       typedef _Report                   ReportType;
-        typedef ReceiveReport<_Report>    Receiver;
-        typedef DistributeReport<_Report> Distributor;
+       typedef TReport                   ReportType;
+        typedef ReceiveReport<TReport>    Receiver;
+        typedef DistributeReport<TReport> Distributor;
 
         TempConnect()
         : _oldRec( Distributor::instance().getReceiver() )