7 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8 * Copyright (C) 2009, 2010, 2011, 2012, MinGW.org Project
11 * Public declaration of the download metering class, and support
12 * functions provided by the internet download agent.
15 * This is free software. Permission is granted to copy, modify and
16 * redistribute this software, under the provisions of the GNU General
17 * Public License, Version 3, (or, at your option, any later version),
18 * as published by the Free Software Foundation; see the file COPYING
19 * for licensing details.
21 * Note, in particular, that this software is provided "as is", in the
22 * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
23 * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
24 * PARTICULAR PURPOSE. Under no circumstances will the author, or the
25 * MinGW Project, accept liability for any damages, however caused,
26 * arising from the use of this software.
31 /* profile.xml may specify the maximum number of retries which will
32 * be permitted, for each configured repository, when any attempt to
33 * establish a download connection fails. In the event that this is
34 * not specified in profile.xml, the following default will apply:
36 #define INTERNET_RETRY_ATTEMPTS 5
38 /* In the default case, when profile.xml doesn't stipulate options,
39 * specify the interval, in milliseconds, to wait between successive
40 * retries to open any one URL. The first attempt for each individual
41 * URL is immediate; if it fails, the first retry is scheduled after
43 * INTERNET_RETRY_INTERVAL * INTERNET_DELAY_FACTOR milliseconds
45 * In the event that further retries are necessary, they are scheduled
46 * at geometrically incrementing intervals, by multiplying the interval
47 * from the preceding attempt by INTERNET_DELAY_FACTOR, prior to each
48 * successive connection attempt.
50 #define INTERNET_DELAY_FACTOR 2
51 #define INTERNET_RETRY_INTERVAL 1000
53 class pkgDownloadMeter
55 /* Abstract base class, from which facilities for monitoring the
56 * progress of file downloads may be derived.
59 /* Hooks for use in the implementation of the GUI download
60 * monitoring dialogue; in a CLI context, these effectively
63 static pkgDownloadMeter *UseGUI(){ return primary; }
64 static inline void SpinWait( int, const char * = NULL );
65 virtual void ResetGUI( const char *, unsigned long ){}
67 /* The working method to refresh the download progress display;
68 * each derived class MUST furnish an implementation for this.
70 virtual int Update( unsigned long ) = 0;
73 /* Reference pointer to the primary instance of the download
74 * meter in the GUI; always set to NULL, in a CLI context.
76 static pkgDownloadMeter *primary;
78 /* Handler which may be invoked by the SpinWait() hook.
80 virtual void SpinWaitAction( int, const char * ){}
82 /* Storage for the expected size of the active download...
84 unsigned long content_length;
86 /* ...and a method to format it for human readable display.
88 int SizeFormat( char *, unsigned long );
91 /* Entry point for the worker thread associated with the download
92 * monitoring dialogue, in the GUI context.
94 EXTERN_C void pkgInvokeDownload( void * );
96 #endif /* PKGINET_H: $RCSfile$: end of file */