📄 progressbar.hh
字号:
// -*- mode: c++; c-basic-offset: 4 -*-#ifndef CLICK_PROGRESSBAR_HH#define CLICK_PROGRESSBAR_HH#include <click/element.hh>#include <click/timer.hh>CLICK_DECLSclass Handler;/*=cProgressBar(POSHANDLER [, SIZEHANDLER, I<KEYWORDS>])=s debuggingprints a progress bar to standard error=ioNone=dReads progress information from handlers, and displays an ASCII-art progressbar on standard error, indicating how much progress has been made and how muchremains to go.POSHANDLER and SIZEHANDLER are read handlers. Each of them should return anonnegative real number. POSHANDLER is checked each time the progress bardisplays; SIZEHANDLER is checked just once, the first time the progress barcomes up. Intuitively, POSHANDLER represents the "position"; the process iscomplete when its value equals the "size" returned by SIZEHANDLER. You maygive multiple position and/or size handlers, as a space-separated list; theirvalues are added together.Keyword arguments are:=over 8=item FIXED_SIZENonnegative real number. Used as the size when SIZEHANDLER is not supplied.Default is no fixed size.=item BANNERString. Print this string before the progress bar. For example, this might bea section of some filename. Default is empty.=item UPDATETime in seconds (millisecond precision). The progress bar updates itself withthis frequency. Default is 1/4 second.=item ACTIVEBoolean. The progress bar will not initially display itself if this is false.Default is true.=item DELAYTime in seconds (millisecond precision). Don't print a progress bar until atleast DELAY seconds have passed. Use this to avoid trivial progress bars (thatis, progress bars that immediately go to 100%). Default is no delay.=item CHECK_STDOUTBoolean. If true, and the standard output is connected to a terminal, then donot print a progress bar. Default is false.=backOnly available in user-level processes.=eThis ProgressBar shows how far into the file FromDump has gotten: fd :: FromDump(~/largedump.gz) -> ... ProgressBar(fd.filepos, fd.filesize);Here are some example progress bars. The first form occurs when the file sizeis known; the second, when it is not known. 74% |************** | 23315KB 00:01 ETA | *** | 5184KB --:-- ETA=nCode based on the progress bar in the OpenSSH project's B<scp> program, whoseauthors are listed as Timo Rinne, Tatu Ylonen, Theo de Raadt, and AaronCampbell.=h mark_stopped write-onlyWhen written, the progress bar changes to indicate that the transfer hasstopped, possibly prematurely.=h mark_done write-onlyWhen written, the progress bar changes to indicate that the transfer hassuccessfully completed.=h pos read-onlyReturns the progress bar's current position.=h size read/writeReturns or sets the progress bar's size value, which is used to compute howclose the process is to completion.=h active read/writeReturns or sets the ACTIVE setting, a Boolean value. An inactive progress barwill not redraw itself.=h banner read/writeReturns or sets the BANNER string.=h poshandler read/writeReturns or sets the read handlers used to read the position, as aspace-separated list.=h sizehandler read/writeReturns or sets the read handlers used to read the size, as a space-separatedlist.=h reset write-onlyWhen written, resets the progress bar to its initial state: the size is readagain, for example. Also sets ACTIVE to true.=aFromDump */class ProgressBar : public Element { public: ProgressBar(); ~ProgressBar(); const char *class_name() const { return "ProgressBar"; } int configure(Vector<String> &, ErrorHandler *); int initialize(ErrorHandler *); void cleanup(CleanupStage); void add_handlers(); void run_timer(); void complete(bool is_full); private: enum { ST_FIRST, ST_MIDDLE, ST_DONE, ST_FIRSTDONE, ST_DEAD }; bool _have_size; int _status; double _size; double _last_pos; Timestamp _start_time; Timestamp _stall_time; Timestamp _last_time; Timestamp _delay_time; String _banner; Timer _timer; uint32_t _interval; uint32_t _delay_ms; bool _active; Vector<Element*> _es; Vector<const Handler*> _hs; int _first_pos_h; bool get_value(int first, int last, double *); static String read_handler(Element *, void *); static int write_handler(const String &, Element *, void *, ErrorHandler*); };CLICK_ENDDECLS#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -