OSDN Git Service

Adapt internet download agent for use by setup tool.
[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 class pkgDownloadMeter
32 {
33   /* Abstract base class, from which facilities for monitoring the
34    * progress of file downloads may be derived.
35    */
36   public:
37     /* Hooks for use in the implementation of the GUI download
38      * monitoring dialogue; in a CLI context, these effectively
39      * become no-ops.
40      */
41     static pkgDownloadMeter *UseGUI(){ return primary; }
42     static inline void SpinWait( int, const char * = NULL );
43     virtual void ResetGUI( const char *, unsigned long ){}
44
45     /* The working method to refresh the download progress display;
46      * each derived class MUST furnish an implementation for this.
47      */
48     virtual int Update( unsigned long ) = 0;
49
50   protected:
51     /* Reference pointer to the primary instance of the download
52      * meter in the GUI; always set to NULL, in a CLI context.
53      */
54     static pkgDownloadMeter *primary;
55
56     /* Handler which may be invoked by the SpinWait() hook.
57      */
58     virtual void SpinWaitAction( int, const char * ){}
59
60     /* Storage for the expected size of the active download...
61      */
62     unsigned long content_length;
63
64     /* ...and a method to format it for human readable display.
65      */
66     int SizeFormat( char *, unsigned long );
67 };
68
69 /* Entry point for the worker thread associated with the download
70  * monitoring dialogue, in the GUI context.
71  */
72 EXTERN_C void pkgInvokeDownload( void * );
73
74 #endif /* PKGINET_H: $RCSfile$: end of file */