[Aptitude-svn-commit] r4066 - in branches/aptitude-0.3/aptitude: .
src
Daniel Burrows
dburrows at costa.debian.org
Fri Sep 9 22:11:04 UTC 2005
Author: dburrows
Date: Fri Sep 9 22:11:01 2005
New Revision: 4066
Modified:
branches/aptitude-0.3/aptitude/ChangeLog
branches/aptitude-0.3/aptitude/src/download_thread.cc
branches/aptitude-0.3/aptitude/src/download_thread.h
Log:
Directly invoke the continuation-passing methods of download_manager from the background thread.
Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog (original)
+++ branches/aptitude-0.3/aptitude/ChangeLog Fri Sep 9 22:11:01 2005
@@ -1,5 +1,10 @@
2005-09-09 Daniel Burrows <dburrows at debian.org>
+ * src/download_thread.cc, src/download_thread.h:
+
+ Directly invoke the continuation-passing methods of
+ download_manager from the background thread.
+
* src/download_manager.cc, src/download_manager.h, src/download_list.h, src/generic/acqprogress.cc, src/generic/acqprogress.h:
Write basic support for continuation-passing in the download
Modified: branches/aptitude-0.3/aptitude/src/download_thread.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download_thread.cc (original)
+++ branches/aptitude-0.3/aptitude/src/download_thread.cc Fri Sep 9 22:11:01 2005
@@ -19,6 +19,8 @@
#include "download_thread.h"
+#include "download_manager.h"
+
#include <vscreen/vscreen.h>
#include <sigc++/bind.h>
@@ -63,46 +65,63 @@
}
};
-/** Run the given function call in the foreground and return its value. */
-template<typename RVal>
+/** Run the given method call in the foreground and return its value. */
+template<typename C, typename RVal>
static
-RVal do_foreground_execute(pkgAcquireStatus *acq,
- RVal (pkgAcquireStatus::* fun) ())
+RVal do_foreground_execute(C *inst,
+ RVal (C::* fun) ())
{
threads::box<RVal> return_box;
- vscreen_post_event(new background_execute<RVal>(sigc::mem_fun(acq, fun),
+ vscreen_post_event(new background_execute<RVal>(sigc::mem_fun(inst, fun),
return_box));
return return_box.take();
}
-/** Run the given function call in the foreground and return its value. */
-template<typename RVal, typename Arg0>
+/** Run the given method call in the foreground and return its value. */
+template<typename C, typename RVal, typename Arg0>
static
-RVal do_foreground_execute(pkgAcquireStatus *acq,
+RVal do_foreground_execute(C *inst,
Arg0 arg0,
- RVal (pkgAcquireStatus::* fun) (Arg0))
+ RVal (C::* fun) (Arg0))
{
threads::box<RVal> return_box;
- vscreen_post_event(new background_execute<RVal>(bind(sigc::mem_fun(acq, fun), arg0),
+ vscreen_post_event(new background_execute<RVal>(bind(sigc::mem_fun(inst, fun), arg0),
+ return_box));
+
+ return return_box.take();
+}
+
+/** Run the given method call in the foreground and return its value. */
+template<typename C, typename RVal, typename Arg0, typename Arg1>
+static
+RVal do_foreground_execute(C *inst,
+ Arg0 arg0,
+ Arg1 arg1,
+ RVal (C::* fun) (Arg0, Arg1))
+{
+ threads::box<RVal> return_box;
+
+ vscreen_post_event(new background_execute<RVal>(bind(sigc::mem_fun(inst, fun), arg0, arg1),
return_box));
return return_box.take();
}
/** Run the given function call in the foreground and return its value. */
-template<typename RVal, typename Arg0, typename Arg1>
+template<typename C, typename RVal, typename Arg0, typename Arg1, typename Arg2>
static
-RVal do_foreground_execute(pkgAcquireStatus *acq,
+RVal do_foreground_execute(C *inst,
Arg0 arg0,
Arg1 arg1,
- RVal (pkgAcquireStatus::* fun) (Arg0, Arg1))
+ Arg2 arg2,
+ RVal (C::* fun) (Arg0, Arg1, Arg2))
{
threads::box<RVal> return_box;
- vscreen_post_event(new background_execute<RVal>(bind(sigc::mem_fun(acq, fun), arg0, arg1),
+ vscreen_post_event(new background_execute<RVal>(bind(sigc::mem_fun(inst, fun), arg0, arg1, arg2),
return_box));
return return_box.take();
@@ -111,47 +130,75 @@
void background_status::Fetched(unsigned long Size,
unsigned long ResumePoint)
{
- do_foreground_execute(real_status, Size, ResumePoint, &pkgAcquireStatus::Fetched);
+ do_foreground_execute(real_status, Size, ResumePoint,
+ &download_manager::Fetched);
}
bool background_status::MediaChange(std::string Media, std::string Drive)
{
- return do_foreground_execute(real_status, Media, Drive, &pkgAcquireStatus::MediaChange);
+ threads::box<bool> return_box;
+
+ do_foreground_execute<download_manager,
+ void, const std::string &, const std::string &,
+ const sigc::slot1<void, bool> &> (real_status, Media, Drive,
+ sigc::mem_fun(return_box,
+ &threads::box<bool>::put),
+ &download_manager::MediaChange);
+
+ return return_box.take();
}
void background_status::IMSHit(pkgAcquire::ItemDesc &item)
{
- do_foreground_execute<void, pkgAcquire::ItemDesc &>(real_status, item, &pkgAcquireStatus::IMSHit);
+ do_foreground_execute<download_manager, void, pkgAcquire::ItemDesc &>(real_status, item, &download_manager::IMSHit);
}
void background_status::Fetch(pkgAcquire::ItemDesc &item)
{
- do_foreground_execute<void, pkgAcquire::ItemDesc &>(real_status, item, &pkgAcquireStatus::Fetch);
+ do_foreground_execute<download_manager, void, pkgAcquire::ItemDesc &>(real_status, item, &download_manager::Fetch);
}
void background_status::Done(pkgAcquire::ItemDesc &item)
{
- do_foreground_execute<void, pkgAcquire::ItemDesc &>(real_status, item, &pkgAcquireStatus::Done);
+ do_foreground_execute<download_manager, void, pkgAcquire::ItemDesc &>(real_status, item, &download_manager::Done);
}
void background_status::Fail(pkgAcquire::ItemDesc &item)
{
- do_foreground_execute<void, pkgAcquire::ItemDesc &>(real_status, item, &pkgAcquireStatus::Fail);
+ do_foreground_execute<download_manager, void, pkgAcquire::ItemDesc &>(real_status, item, &download_manager::Fail);
}
bool background_status::Pulse(pkgAcquire *Owner)
{
- return do_foreground_execute(real_status, Owner, &pkgAcquireStatus::Pulse);
+ threads::box<bool> return_box;
+
+ do_foreground_execute<download_manager, void,
+ pkgAcquire *,
+ const sigc::slot1<void, bool> &>(real_status, Owner,
+ sigc::mem_fun(&return_box,
+ &threads::box<bool>::put),
+ &download_manager::Pulse);
+
+ return return_box.take();
}
void background_status::Start()
{
- do_foreground_execute(real_status, &pkgAcquireStatus::Start);
+ do_foreground_execute(real_status, &download_manager::Start);
}
void background_status::Stop()
{
- do_foreground_execute(real_status, &pkgAcquireStatus::Stop);
+ threads::box<void> return_box;
+
+ do_foreground_execute<download_manager,
+ void,
+ const sigc::slot0<void> &>(real_status,
+ sigc::mem_fun(&return_box,
+ &threads::box<void>::put),
+ &download_manager::Stop);
+
+ return_box.take();
}
class download_thread_complete_event : public vscreen_event
Modified: branches/aptitude-0.3/aptitude/src/download_thread.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/download_thread.h (original)
+++ branches/aptitude-0.3/aptitude/src/download_thread.h Fri Sep 9 22:11:01 2005
@@ -27,6 +27,8 @@
#include <sigc++/slot.h>
+class download_manager;
+
/** A proxy status object that posts messages to the main thread.
* Each message "blocks" the download until the user deals with it,
* just as if it was running in the main thread (I'm not sure
@@ -37,7 +39,7 @@
*/
class background_status : public pkgAcquireStatus
{
- pkgAcquireStatus *real_status;
+ download_manager *real_status;
public:
void Fetched(unsigned long Size, unsigned long ResumePoint);
bool MediaChange(std::string Media, std::string Drive);
@@ -50,7 +52,7 @@
void Stop();
void Complete();
- background_status(pkgAcquireStatus *_real_status)
+ background_status(download_manager *_real_status)
:real_status(_real_status)
{
}
More information about the Aptitude-svn-commit
mailing list