diff options
author | Daniel_Burrows@alumni.brown.edu <Daniel_Burrows@alumni.brown.edu> | 2010-07-03 18:48:03 -0700 |
---|---|---|
committer | Daniel Burrows <Daniel Burrows Daniel_Burrows@alumni.brown.edu> | 2010-07-03 23:49:21 -0700 |
commit | b2aa333c7b9af41a0aa0122d9d976a4dee2be6ba (patch) | |
tree | 0055c766ede64ead4adca121d9f7ab02ee7254a2 | |
parent | 3fe709bebbfdb81c5354cf6e30c6762390569918 (diff) | |
download | aptitude-b2aa333c7b9af41a0aa0122d9d976a4dee2be6ba.tar.gz |
Move the throttle object to src/generic/util.
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/cmdline/Makefile.am | 2 | ||||
-rw-r--r-- | src/cmdline/SConscript | 2 | ||||
-rw-r--r-- | src/cmdline/cmdline_search.cc | 11 | ||||
-rw-r--r-- | src/cmdline/cmdline_search_progress.cc | 10 | ||||
-rw-r--r-- | src/cmdline/cmdline_search_progress.h | 9 | ||||
-rw-r--r-- | src/cmdline/cmdline_versions.cc | 11 | ||||
-rw-r--r-- | src/generic/util/Makefile.am | 4 | ||||
-rw-r--r-- | src/generic/util/SConscript | 4 | ||||
-rw-r--r-- | src/generic/util/mocks/Makefile.am | 1 | ||||
-rw-r--r-- | src/generic/util/mocks/SConscript | 3 | ||||
-rw-r--r-- | src/generic/util/mocks/throttle.h (renamed from src/cmdline/mocks/cmdline_progress_throttle.h) | 16 | ||||
-rw-r--r-- | src/generic/util/throttle.cc (renamed from src/cmdline/cmdline_progress_throttle.cc) | 28 | ||||
-rw-r--r-- | src/generic/util/throttle.h (renamed from src/cmdline/cmdline_progress_throttle.h) | 31 | ||||
-rw-r--r-- | tests/SConscript | 2 | ||||
-rw-r--r-- | tests/test_cmdline_search_progress.cc | 24 |
16 files changed, 91 insertions, 68 deletions
diff --git a/configure.ac b/configure.ac index a2910189..17908562 100644 --- a/configure.ac +++ b/configure.ac @@ -831,6 +831,7 @@ AC_CONFIG_FILES([ src/generic/apt/matching/Makefile src/generic/problemresolver/Makefile src/generic/util/Makefile + src/generic/util/mocks/Makefile src/generic/views/Makefile src/generic/views/mocks/Makefile src/mine/Makefile diff --git a/src/cmdline/Makefile.am b/src/cmdline/Makefile.am index 2f4a6966..4e5ca07b 100644 --- a/src/cmdline/Makefile.am +++ b/src/cmdline/Makefile.am @@ -34,8 +34,6 @@ libcmdline_a_SOURCES=\ cmdline_progress.h \ cmdline_progress_display.cc \ cmdline_progress_display.h \ - cmdline_progress_throttle.cc \ - cmdline_progress_throttle.h \ cmdline_prompt.cc \ cmdline_prompt.h \ cmdline_resolver.cc \ diff --git a/src/cmdline/SConscript b/src/cmdline/SConscript index 92db69d3..b87f9f79 100644 --- a/src/cmdline/SConscript +++ b/src/cmdline/SConscript @@ -28,8 +28,6 @@ src_filenames = [ 'cmdline_progress.h', 'cmdline_progress_display.cc', 'cmdline_progress_display.h', - 'cmdline_progress_throttle.cc', - 'cmdline_progress_throttle.h', 'cmdline_prompt.cc', 'cmdline_prompt.h', 'cmdline_resolver.cc', diff --git a/src/cmdline/cmdline_search.cc b/src/cmdline/cmdline_search.cc index 0104ae20..49349340 100644 --- a/src/cmdline/cmdline_search.cc +++ b/src/cmdline/cmdline_search.cc @@ -24,7 +24,6 @@ #include "cmdline_common.h" #include "cmdline_progress_display.h" -#include "cmdline_progress_throttle.h" #include "cmdline_search_progress.h" #include "cmdline_util.h" #include "terminal.h" @@ -43,6 +42,7 @@ #include <generic/apt/matching/pattern.h> #include <generic/apt/matching/serialize.h> #include <generic/util/progress_info.h> +#include <generic/util/throttle.h> #include <generic/views/progress.h> #include <cwidget/config/column_definition.h> @@ -63,18 +63,19 @@ using namespace std; namespace cw = cwidget; using aptitude::Loggers; -using aptitude::cmdline::create_progress_throttle; +using aptitude::cmdline::create_search_progress; using aptitude::cmdline::create_terminal; using aptitude::cmdline::create_terminal_locale; using aptitude::cmdline::make_text_progress; -using aptitude::cmdline::progress_throttle; using aptitude::cmdline::terminal; using aptitude::cmdline::terminal_locale; using aptitude::matching::serialize_pattern; +using aptitude::util::create_throttle; using aptitude::util::progress_info; using aptitude::util::progress_type_bar; using aptitude::util::progress_type_none; using aptitude::util::progress_type_pulse; +using aptitude::util::throttle; using aptitude::views::progress; using boost::format; using boost::shared_ptr; @@ -100,8 +101,8 @@ namespace const shared_ptr<progress> search_progress_display = create_progress_display(term, term_locale); - const shared_ptr<progress_throttle> search_progress_throttle = - create_progress_throttle(); + const shared_ptr<throttle> search_progress_throttle = + create_throttle(); results_list output; ref_ptr<search_cache> search_info(search_cache::create()); diff --git a/src/cmdline/cmdline_search_progress.cc b/src/cmdline/cmdline_search_progress.cc index 5f5eb3e6..e7fc5da0 100644 --- a/src/cmdline/cmdline_search_progress.cc +++ b/src/cmdline/cmdline_search_progress.cc @@ -22,9 +22,9 @@ #include "cmdline_search_progress.h" #include "cmdline_progress_display.h" -#include "cmdline_progress_throttle.h" #include <generic/util/progress_info.h> +#include <generic/util/throttle.h> #include <generic/views/progress.h> @@ -42,6 +42,8 @@ using boost::make_shared; using boost::shared_ptr; using cwidget::util::ref_ptr; +namespace util = aptitude::util; + namespace aptitude { namespace cmdline @@ -51,12 +53,12 @@ namespace aptitude class search_progress : public views::progress { shared_ptr<views::progress> display; - shared_ptr<progress_throttle> throttle; + shared_ptr<util::throttle> throttle; std::string pattern; public: search_progress(const shared_ptr<views::progress> &_display, - const shared_ptr<progress_throttle> &_throttle, + const shared_ptr<util::throttle> &_throttle, const std::string &_pattern) : display(_display), throttle(_throttle), @@ -112,7 +114,7 @@ namespace aptitude shared_ptr<views::progress> create_search_progress(const std::string &pattern, const shared_ptr<views::progress> &display, - const shared_ptr<progress_throttle> &throttle) + const shared_ptr<util::throttle> &throttle) { return make_shared<search_progress>(display, throttle, diff --git a/src/cmdline/cmdline_search_progress.h b/src/cmdline/cmdline_search_progress.h index 9cf6ef96..3131d04d 100644 --- a/src/cmdline/cmdline_search_progress.h +++ b/src/cmdline/cmdline_search_progress.h @@ -29,10 +29,13 @@ namespace aptitude class progress; } - namespace cmdline + namespace util { - class progress_throttle; + class throttle; + } + namespace cmdline + { /** \brief Create a progress-display object specialized for * showing the progress of a search. * @@ -47,7 +50,7 @@ namespace aptitude boost::shared_ptr<views::progress> create_search_progress(const std::string &pattern, const boost::shared_ptr<views::progress> &display, - const boost::shared_ptr<progress_throttle> &throttle); + const boost::shared_ptr<util::throttle> &throttle); } } diff --git a/src/cmdline/cmdline_versions.cc b/src/cmdline/cmdline_versions.cc index 38ff54b9..46351328 100644 --- a/src/cmdline/cmdline_versions.cc +++ b/src/cmdline/cmdline_versions.cc @@ -22,7 +22,6 @@ #include "cmdline_versions.h" #include "cmdline_progress_display.h" -#include "cmdline_progress_throttle.h" #include "cmdline_search_progress.h" #include "cmdline_util.h" #include "terminal.h" @@ -35,6 +34,7 @@ #include <generic/apt/matching/pattern.h> #include <generic/apt/matching/serialize.h> #include <generic/util/progress_info.h> +#include <generic/util/throttle.h> #include <generic/views/progress.h> @@ -57,19 +57,20 @@ namespace cw = cwidget; namespace m = aptitude::matching; using aptitude::cmdline::create_progress_display; -using aptitude::cmdline::create_progress_throttle; +using aptitude::cmdline::create_search_progress; using aptitude::cmdline::create_terminal; using aptitude::cmdline::create_terminal_locale; using aptitude::cmdline::lessthan_1st; using aptitude::cmdline::package_results_lt; -using aptitude::cmdline::progress_throttle; using aptitude::cmdline::search_result_column_parameters; using aptitude::cmdline::terminal; using aptitude::cmdline::terminal_locale; using aptitude::cmdline::version_results_eq; using aptitude::cmdline::version_results_lt; using aptitude::matching::serialize_pattern; +using aptitude::util::create_throttle; using aptitude::util::progress_info; +using aptitude::util::throttle; using aptitude::views::progress; using boost::shared_ptr; @@ -257,8 +258,8 @@ namespace const shared_ptr<progress> search_progress_display = create_progress_display(term, term_locale); - const shared_ptr<progress_throttle> search_progress_throttle = - create_progress_throttle(); + const shared_ptr<throttle> search_progress_throttle = + create_throttle(); results_list output; cw::util::ref_ptr<m::search_cache> search_info(m::search_cache::create()); diff --git a/src/generic/util/Makefile.am b/src/generic/util/Makefile.am index c754e805..6652afc5 100644 --- a/src/generic/util/Makefile.am +++ b/src/generic/util/Makefile.am @@ -4,6 +4,8 @@ localedir = $(datadir)/locale INCLUDES = -I$(top_builddir) -I$(srcdir) -I$(top_srcdir) -I$(top_srcdir)/src DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ +SUBDIRS = mocks + noinst_LIBRARIES = libgeneric-util.a libgeneric_util_a_SOURCES = \ compare3.h \ @@ -40,6 +42,8 @@ libgeneric_util_a_SOURCES = \ sqlite.h \ temp.cc \ temp.h \ + throttle.cc \ + throttle.h \ undo.cc \ undo.h \ util.cc \ diff --git a/src/generic/util/SConscript b/src/generic/util/SConscript index fe9eeaf5..0615eac0 100644 --- a/src/generic/util/SConscript +++ b/src/generic/util/SConscript @@ -34,6 +34,8 @@ srcs = map(File, [ 'sqlite.h', 'temp.cc', 'temp.h', + 'throttle.cc', + 'throttle.h', 'undo.cc', 'undo.h', 'util.cc', @@ -42,4 +44,6 @@ srcs = map(File, [ programs_env.Dist('Makefile.am', 'SConscript') +SConscript(dirs = [ 'mocks' ]) + Return('srcs') diff --git a/src/generic/util/mocks/Makefile.am b/src/generic/util/mocks/Makefile.am new file mode 100644 index 00000000..6b88c48d --- /dev/null +++ b/src/generic/util/mocks/Makefile.am @@ -0,0 +1 @@ +EXTRA_DIST = throttle.h
\ No newline at end of file diff --git a/src/generic/util/mocks/SConscript b/src/generic/util/mocks/SConscript new file mode 100644 index 00000000..025e0f15 --- /dev/null +++ b/src/generic/util/mocks/SConscript @@ -0,0 +1,3 @@ +Import('programs_env') + +programs_env.Dist('throttle.h') diff --git a/src/cmdline/mocks/cmdline_progress_throttle.h b/src/generic/util/mocks/throttle.h index 19c9d1a5..0e852f6e 100644 --- a/src/cmdline/mocks/cmdline_progress_throttle.h +++ b/src/generic/util/mocks/throttle.h @@ -1,4 +1,4 @@ -/** \file cmdline_progress_throttle.h */ // -*-c++-*- +/** \file throttle.h */ // -*-c++-*- // Copyright (C) 2010 Daniel Burrows @@ -18,23 +18,23 @@ // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. -#ifndef CMDLINE_PROGRESS_THROTTLE -#define CMDLINE_PROGRESS_THROTTLE +#ifndef APTITUDE_UTIL_MOCKS_THROTTLE_H +#define APTITUDE_UTIL_MOCKS_THROTTLE_H // Local includes: -#include <cmdline/cmdline_progress_throttle.h> +#include <generic/util/throttle.h> // System includes: #include <gmock/gmock.h> namespace aptitude { - namespace cmdline + namespace util { namespace mocks { - /** \brief Mock implementation of cmdline::progress_throttle. */ - class progress_throttle : public aptitude::cmdline::progress_throttle + /** \brief Mock implementation of aptitude::util::throttle. */ + class throttle : public aptitude::util::throttle { public: MOCK_METHOD0(update_required, bool()); @@ -44,4 +44,4 @@ namespace aptitude } } -#endif // CMDLINE_PROGRESS_THROTTLE +#endif // APTITUDE_UTIL_MOCKS_THROTTLE_H diff --git a/src/cmdline/cmdline_progress_throttle.cc b/src/generic/util/throttle.cc index 9773e4ed..9697df36 100644 --- a/src/cmdline/cmdline_progress_throttle.cc +++ b/src/generic/util/throttle.cc @@ -1,6 +1,6 @@ -/** \file cmdline_progress_throttle.cc */ // -*-c++-*- +/** \file throttle.cc */ // -*-c++-*- -#include "cmdline_progress_throttle.h" +#include "throttle.h" // Local includes: #include <loggers.h> @@ -22,11 +22,11 @@ using logging::LoggerPtr; namespace aptitude { - namespace cmdline + namespace util { namespace { - class progress_throttle_impl : public progress_throttle + class throttle_impl : public throttle { boost::optional<struct timeval> last_update; @@ -41,9 +41,9 @@ namespace aptitude void write_time_error(int errnum); public: - progress_throttle_impl(); + throttle_impl(); - /** \return \b true if the progress display should be updated. */ + /** \return \b true if the timer has expired. */ bool update_required(); /** \brief Reset the timer that controls when the display is @@ -52,9 +52,9 @@ namespace aptitude void reset_timer(); }; - const double progress_throttle_impl::update_interval; + const double throttle_impl::update_interval; - void progress_throttle_impl::write_time_error(int errnum) + void throttle_impl::write_time_error(int errnum) { if(!wrote_time_error) { @@ -65,13 +65,13 @@ namespace aptitude } } - progress_throttle_impl::progress_throttle_impl() + throttle_impl::throttle_impl() : logger(Loggers::getAptitudeCmdlineThrottle()), wrote_time_error(false) { } - bool progress_throttle_impl::update_required() + bool throttle_impl::update_required() { if(!last_update) return true; @@ -99,7 +99,7 @@ namespace aptitude } } - void progress_throttle_impl::reset_timer() + void throttle_impl::reset_timer() { LOG_TRACE(logger, "Resetting the update timer."); @@ -111,13 +111,13 @@ namespace aptitude } } - progress_throttle::~progress_throttle() + throttle::~throttle() { } - shared_ptr<progress_throttle> create_progress_throttle() + shared_ptr<throttle> create_throttle() { - return make_shared<progress_throttle_impl>(); + return make_shared<throttle_impl>(); } } } diff --git a/src/cmdline/cmdline_progress_throttle.h b/src/generic/util/throttle.h index fbbb9f22..5535b8a2 100644 --- a/src/cmdline/cmdline_progress_throttle.h +++ b/src/generic/util/throttle.h @@ -1,4 +1,4 @@ -/** \file cmdline_progress_throttle.h */ // -*-c++-*- +/** \file throttle.h */ // -*-c++-*- // Copyright (C) 2010 Daniel Burrows // @@ -17,25 +17,28 @@ // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. -#ifndef CMDLINE_PROGRESS_THROTTLE_H -#define CMDLINE_PROGRESS_THROTTLE_H +#ifndef APTITUDE_UTIL_THROTTLE_H +#define APTITUDE_UTIL_THROTTLE_H // System includes: #include <boost/shared_ptr.hpp> namespace aptitude { - namespace cmdline + namespace util { - /** \brief Used to check whether enough time has passed that a - * progress display should be updated. + /** \brief Used to ensure that an expensive operation (such as + * updating a progress indicator) doesn't run too often. + * + * To test code that uses this class, use the mock that's + * available in mocks/. */ - class progress_throttle + class throttle { public: - virtual ~progress_throttle() = 0; + virtual ~throttle() = 0; - /** \return \b true if the progress display should be updated. */ + /** \return \b true if the timer has expired. */ virtual bool update_required() = 0; /** \brief Reset the timer that controls when the display is @@ -44,9 +47,13 @@ namespace aptitude virtual void reset_timer() = 0; }; - /** \brief Create a progress_throttle object. */ - boost::shared_ptr<progress_throttle> create_progress_throttle(); + /** \brief Create a throttle object. + * + * \todo This should take an argument giving the update interval + * in seconds. + */ + boost::shared_ptr<throttle> create_throttle(); } } -#endif // CMDLINE_PROGRESS_THROTTLE_H +#endif // APTITUDE_UTIL_THROTTLE_H diff --git a/tests/SConscript b/tests/SConscript index 4744196b..06fd8b54 100644 --- a/tests/SConscript +++ b/tests/SConscript @@ -104,7 +104,6 @@ gtest_test_sources = [ gtest_test_extra_deps = [ '../src/cmdline/cmdline_download_progress_display.o', '../src/cmdline/cmdline_progress_display.o', - '../src/cmdline/cmdline_progress_throttle.o', '../src/cmdline/cmdline_search_progress.o', '../src/cmdline/mocks/teletype.o', '../src/cmdline/mocks/terminal.o', @@ -113,6 +112,7 @@ gtest_test_extra_deps = [ '../src/generic/apt/globals.o', '../src/generic/util/logging.o', '../src/generic/util/progress_info.o', + '../src/generic/util/throttle.o', '../src/generic/util/util.o', '../src/generic/views/download_progress.o', '../src/generic/views/progress.o', diff --git a/tests/test_cmdline_search_progress.cc b/tests/test_cmdline_search_progress.cc index 0679033e..e245e690 100644 --- a/tests/test_cmdline_search_progress.cc +++ b/tests/test_cmdline_search_progress.cc @@ -22,9 +22,9 @@ // Local includes: #include <cmdline/cmdline_search_progress.h> -#include <cmdline/mocks/cmdline_progress_throttle.h> #include <generic/util/progress_info.h> +#include <generic/util/mocks/throttle.h> #include <generic/views/mocks/progress.h> // System includes: @@ -48,7 +48,7 @@ using testing::_; namespace mocks { - using namespace aptitude::cmdline::mocks; + using namespace aptitude::util::mocks; using namespace aptitude::views::mocks; } @@ -59,7 +59,7 @@ namespace struct CmdlineSearchProgressTest : public Test { const shared_ptr<mocks::progress> progress; - const shared_ptr<mocks::progress_throttle> progress_throttle; + const shared_ptr<mocks::throttle> throttle; /** \brief The search pattern string used to create the search * progress object. @@ -69,11 +69,11 @@ namespace CmdlineSearchProgressTest() : progress(make_shared<mocks::progress>()), - progress_throttle(make_shared<mocks::progress_throttle>()), + throttle(make_shared<mocks::throttle>()), search_pattern("?name(aptitude)"), search_progress(create_search_progress(search_pattern, progress, - progress_throttle)) + throttle)) { } @@ -95,19 +95,19 @@ namespace void never_throttle() { - EXPECT_CALL(*progress_throttle, update_required()) + EXPECT_CALL(*throttle, update_required()) .WillRepeatedly(Return(true)); - EXPECT_CALL(*progress_throttle, reset_timer()) + EXPECT_CALL(*throttle, reset_timer()) .Times(AnyNumber()); } void always_throttle() { - EXPECT_CALL(*progress_throttle, update_required()) + EXPECT_CALL(*throttle, update_required()) .WillRepeatedly(Return(false)); // No call to reset_timer() expected since it's throttled -- // calling it would, in fact, be wrong. - EXPECT_CALL(*progress_throttle, reset_timer()) + EXPECT_CALL(*throttle, reset_timer()) .Times(0); } }; @@ -159,7 +159,7 @@ TEST_F(CmdlineSearchProgressTest, ThrottledProgressNone) // Check that a second set_progress() call goes through, since // throttling is no longer enabled: - Mock::VerifyAndClearExpectations(progress_throttle.get()); + Mock::VerifyAndClearExpectations(throttle.get()); Mock::VerifyAndClearExpectations(progress.get()); never_throttle(); @@ -184,7 +184,7 @@ TEST_F(CmdlineSearchProgressTest, ThrottledProgressPulse) // Check that a second set_progress() call goes through, since // throttling is no longer enabled: - Mock::VerifyAndClearExpectations(progress_throttle.get()); + Mock::VerifyAndClearExpectations(throttle.get()); Mock::VerifyAndClearExpectations(progress.get()); never_throttle(); @@ -211,7 +211,7 @@ TEST_F(CmdlineSearchProgressTest, ThrottledProgressBar) // Check that a second set_progress() call goes through, since // throttling is no longer enabled: - Mock::VerifyAndClearExpectations(progress_throttle.get()); + Mock::VerifyAndClearExpectations(throttle.get()); Mock::VerifyAndClearExpectations(progress.get()); never_throttle(); |