diff --git a/docs/manual.html b/docs/manual.html index e7a1a1726..81a527c79 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -2884,7 +2884,48 @@ struct fastresume_rejected_alert: torrent_alert

dispatcher

-

TODO: describe the dispatcher mechanism

+

The handle_alert class is defined in <libtorrent/alert.hpp>.

+

Examples usage:

+
+struct my_handler
+{
+        void operator()(portmap_error_alert const& a)
+        {
+                std::cout << "Portmapper: " << a.msg << std::endl;
+        }
+
+        void operator()(tracker_warning_alert const& a)
+        {
+                std::cout << "Tracker warning: " << a.msg << std::endl;
+        }
+
+        void operator()(torrent_finished_alert const& a)
+        {
+                // write fast resume data
+                // ...
+
+                std::cout << a.handle.get_torrent_info().name() << "completed"
+                        << std::endl;
+        }
+};
+
+
+std::auto_ptr<alert> a;
+a = ses.pop_alert();
+my_handler h;
+while (a.get())
+{
+        handle_alert<portmap_error_alert
+                , tracker_warning_alert
+                , torrent_finished_alert
+        >::handle_alert(h, a);
+        a = ses.pop_alert();
+}
+
+

In this example 3 alert types are used. You can use any number of template +parameters to select between more types. If the number of types are more than +15, you can define TORRENT_MAX_ALERT_TYPES to a greater number before +including <libtorrent/alert.hpp>.

diff --git a/docs/manual.rst b/docs/manual.rst index 285a29b60..c0af0d39b 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -2974,8 +2974,50 @@ resume file was rejected. It is generated at severity level ``warning``. dispatcher ---------- -*TODO: describe the dispatcher mechanism* +The ``handle_alert`` class is defined in ````. +Examples usage:: + + struct my_handler + { + void operator()(portmap_error_alert const& a) + { + std::cout << "Portmapper: " << a.msg << std::endl; + } + + void operator()(tracker_warning_alert const& a) + { + std::cout << "Tracker warning: " << a.msg << std::endl; + } + + void operator()(torrent_finished_alert const& a) + { + // write fast resume data + // ... + + std::cout << a.handle.get_torrent_info().name() << "completed" + << std::endl; + } + }; + +:: + + std::auto_ptr a; + a = ses.pop_alert(); + my_handler h; + while (a.get()) + { + handle_alert::handle_alert(h, a); + a = ses.pop_alert(); + } + +In this example 3 alert types are used. You can use any number of template +parameters to select between more types. If the number of types are more than +15, you can define ``TORRENT_MAX_ALERT_TYPES`` to a greater number before +including ````. exceptions