OSDN Git Service

Support group affiliation with component package granularity.
[mingw/mingw-get.git] / src / pkginet.h
1 #ifndef PKGINET_H
2 /*
3  * pkginet.h
4  *
5  * $Id$
6  *
7  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8  * Copyright (C) 2009, 2010, 2011, 2012, MinGW.org Project
9  *
10  *
11  * Public declaration of the download metering class, and support
12  * functions provided by the internet download agent.
13  *
14  *
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.
20  *
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.
27  *
28  */
29 #define PKGINET_H  1
30
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:
35  */
36 #define INTERNET_RETRY_ATTEMPTS     5
37
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
42  *
43  *   INTERNET_RETRY_INTERVAL * INTERNET_DELAY_FACTOR  milliseconds
44  *
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.
49  */
50 #define INTERNET_DELAY_FACTOR       2
51 #define INTERNET_RETRY_INTERVAL  1000
52
53 class pkgDownloadMeter
54 {
55   /* Abstract base class, from which facilities for monitoring the
56    * progress of file downloads may be derived.
57    */
58   public:
59     /* Hooks for use in the implementation of the GUI download
60      * monitoring dialogue; in a CLI context, these effectively
61      * become no-ops.
62      */
63     static pkgDownloadMeter *UseGUI(){ return primary; }
64     static inline void SpinWait( int, const char * = NULL );
65     virtual void ResetGUI( const char *, unsigned long ){}
66
67     /* The working method to refresh the download progress display;
68      * each derived class MUST furnish an implementation for this.
69      */
70     virtual int Update( unsigned long ) = 0;
71
72   protected:
73     /* Reference pointer to the primary instance of the download
74      * meter in the GUI; always set to NULL, in a CLI context.
75      */
76     static pkgDownloadMeter *primary;
77
78     /* Handler which may be invoked by the SpinWait() hook.
79      */
80     virtual void SpinWaitAction( int, const char * ){}
81
82     /* Storage for the expected size of the active download...
83      */
84     unsigned long content_length;
85
86     /* ...and a method to format it for human readable display.
87      */
88     int SizeFormat( char *, unsigned long );
89 };
90
91 /* Entry point for the worker thread associated with the download
92  * monitoring dialogue, in the GUI context.
93  */
94 EXTERN_C void pkgInvokeDownload( void * );
95
96 #endif /* PKGINET_H: $RCSfile$: end of file */