camnet.h

Go to the documentation of this file.
00001 // $Id: camnet.h 751 2006-03-31 15:43:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 
00100 #ifndef _CAMNET_H_
00101 #define _CAMNET_H_
00102 
00103 
00104 
00105 #include <wininet.h>
00106 #include <urlmon.h>
00107 #include <winsock.h>
00108 #include <afxtempl.h>
00109 #include <sys/types.h>
00110 #include <sys/stat.h>
00111 #include <string.h>
00112 #include "stl.h"
00113 //#include "webster.h"
00114 
00115 
00116 
00117 #define DOWNLOAD_HANDLE                 INT32
00118 #define MAX_HANDLE                              1000
00119 #define DOWNLOAD_ERROR                      1
00120 #define SIZEOFKILOBYTE  1024
00121 
00122 #define NOTIFICATION_QUEUE_SIZE         3   // this value is very experimental
00123 
00124 // Downloadable file types
00125 enum FileType {TYPE_HTML = 0, TYPE_CLIPART, TYPE_FONT, TYPE_BITMAP, TYPE_TEXTURE, TYPE_COLOUR, 
00126         TYPE_FILL, TYPE_THUMBNAIL, TYPE_CATALOG, TYPE_SUPPORT};
00127 
00128 // Connection types
00129 enum ConnectionType {CONNECTION_SLOWMODEM = 0, CONNECTION_FASTMODEM, CONNECTION_X2, CONNECTION_ISDN};
00130 
00131 
00132 
00133 typedef struct tagDOWNLOADINFO
00134 {
00135     String_256 strURL;          // URL we're downloading from
00136     String_256 strLocalFile;    // Path of file we're downloading to
00137     INT32 nFileType;                // File type
00138     INT32 nPriority;                // Priority
00139     BOOL bHasProgressDlg;       // Flag indicating whether we should display a progress dialog
00140     String_256 strDescription;  // ID of description string - only used if we have a progress dialog
00141     HWND hwndNotifyWindow;      // Window handle for status notifications
00142     INT32 lNotifyToken;         // Unique token for status notifications
00143 } DOWNLOADINFO, *LPDOWNLOADINFO;
00144 
00145 
00146 
00147 
00148 
00149 
00150 /********************************************************************************************
00151 
00152 >   class AsynchDownload: public CCObject
00153 
00154     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
00155     Created:    11/12/96
00156     Purpose:    Asynchronous download class - downloads a url to a local file using HTTP
00157                     Used by the download manager.
00158     SeeAlso:    InternetManager 
00159 
00160 ********************************************************************************************/
00161 
00162 
00163 class AsynchDownload : public CCObject
00164 {
00165     CC_DECLARE_DYNAMIC(AsynchDownload)
00166 
00167 public:
00168     // Possible priority values 
00169     enum Priority {PRIORITY_NORMAL = 1, PRIORITY_HIGH};
00170     // Possible download states
00171     enum State {STATE_ERROR = 0, STATE_PENDING, STATE_SUCCEEDED, STATE_ABORTED, STATE_FAILED};
00172 
00174     // Construction/Destruction
00176     
00177     AsynchDownload(DOWNLOAD_HANDLE hDownload, LPDOWNLOADINFO pDownloadInfo); 
00178     
00179     ~AsynchDownload();
00180     
00182     // Attributes
00184 
00185     // Returns the download's handle (unique INT32 identifier)
00186     inline const DOWNLOAD_HANDLE GetHandle() {return m_Handle;}
00187     
00188     // Returns the URL of the file to download
00189     inline const String_256& GetTargetURL() {return m_strTargetURL;}
00190 
00191     // Returns filename of local copy of the remote file 
00192     inline const String_256& GetLocalFileName() {return m_strLocalFilePath;}
00193 
00194     // Returns the file description as displayed in the progress dialog 
00195     inline const String_256& GetFileDescription() {return m_strDescription;}
00196 
00197     // Returns the URL of the file to download
00198     inline const HWND& GetNotifyHWND() {return m_hwndNotifyWindow;}
00199 
00200     // Returns the URL of the file to download
00201     inline const INT32& GetNotifyToken() {return m_lNotifyToken;}
00202 
00203     // Returns filename of temporary cache file
00204     inline const String_256& GetCacheFileName() {return m_strCacheFileName;}
00205 
00206     // Returns size of remote file (this is the size reported by the HTTP server - not 100% reliable)
00207     inline const UINT32 GetRemoteFileSize() {return m_ulFileSize;} 
00208 
00209     // Returns bytes downloaded so far - can be used to monitor the progress of the download 
00210     inline const UINT32 GetBytesDownloaded() {return m_ulDownloaded;}
00211 
00212     // Returns the percentage downloaded so far - can be used as an alternative to the above 
00213     inline const INT32 GetPercentageDownloaded() {return m_nPercentageDownloaded;}
00214 
00216     // Operations
00218     
00219     // Cancel this download
00220     HRESULT AbortDownload();
00221 
00222     // Start this download
00223     inline HRESULT StartDownload() {return DoBind();}
00224 
00225     // Returns TRUE in case of success, FALSE otherwise
00226     inline BOOL HasSucceeded() { return m_bSuccess;}
00227 
00228     // Returns TRUE if this download was cancelled by the user rather than succeed or failed by itself
00229     inline BOOL WasAborted() { return m_bAbort;}
00230 
00231     // Get the priority assigned to this download
00232     inline INT32 GetFileType() { return m_nFileType;} 
00233 
00234     // Get the priority assigned to this download
00235     inline Priority GetPriority() { return m_Priority;} 
00236 
00237     // Safe way to free memory and resources alocated to this object - the delete operator should never be used 
00238     // for this purpose as it may lead to access violations
00239     void Release();
00240 
00241     // Returns the instance count of downloads with a given priority
00242     inline static INT32 GetInstanceCount(Priority priority) {return (priority == PRIORITY_NORMAL) ? m_nNormalPriorityInstanceCount : m_nHighPriorityInstanceCount;}
00243 
00244 
00245 
00247     // Implementation
00249 
00250 protected:
00251     
00252     DOWNLOAD_HANDLE m_Handle; // Handle of download
00253     String_256 m_strTargetURL; // URL we're downloading from
00254     String_256 m_strLocalFilePath; // Path of file we're downloading to
00255     BOOL m_bHasProgressDlg; // Flag indicating whether we should display a progress dialog while downloading
00256     String_256 m_strDescription; // ID of description string - only used if we have a progress dialog
00257     BOOL m_bAbort; // Flag signaling that the download was terminated at user's request
00258     BOOL m_bSuccess; // Flag indicating that the download has succeeded
00259     UINT32 m_ulFileSize;    // Size of file as reported by the server - note that some older servers will report 0
00260     UINT32 m_ulDownloaded; // Bytes downloaded so far
00261     INT32 m_nPercentageDownloaded; // Percentage downloaded so far
00262     String_256 m_strCacheFileName; // Path of cache file used by wininet.dll
00263     IMoniker* m_pMoniker; // pointer to URL moniker
00264     IBindCtx* m_pBindContext; // Pointer to bind context
00265     Priority m_Priority; // Download priority (either PRIORITY_NORMAL or PRIORITY_HIGH)
00266     HWND m_hwndNotifyWindow;        // Window handle for status notifications
00267     INT32 m_lNotifyToken;           // Unique token for status notifications
00268     INT32 m_nFileType; // File type 
00269     INT32 m_nAttempts; // Attempts made to download the file 
00270     static INT32 m_nNormalPriorityInstanceCount; // Normal priority downloads instance count
00271     static INT32 m_nHighPriorityInstanceCount; // High priority downloads instance count
00272     // Starts the binding operation which downloads the file to local storage
00273     // (See MS Internet SDK docs for more information)
00274     HRESULT DoBind(); 
00275     // Deallocate resources when binding is over 
00276     void Cleanup();
00277     // Re-attempt a failed download
00278     HRESULT Retry();
00279     // Nested callback class controlling the download operation
00280     // This is the "heart" of  the class
00281     class AsynchBindStatusCallback : public IBindStatusCallback, public IAuthenticate
00282     {
00283       public:
00284 
00285         // data members
00286         DWORD           m_dwRef; // reference count
00287         AsynchDownload* m_pDownload; // pointer to the owner of this callback 
00288         IBinding*       m_pBinding; // pointer to the actual binding operation
00289         HWND m_hProgressDlg; // progress dialog handle
00290         UINT32 m_nIconID; // ID of icon currently used by the progress dialog
00291         // Handle of normal priority progress dialog. There is a single progress dialog for all n.p. downloads 
00292         // (high priority downloads have individual progress dialogs, i.e. each connection has its own)
00293         static HWND m_hNormalPriorityProgressDlg;
00294         static UINT32 m_nNormalPriorityIconID; // ID of icon currently used by the normal priority progress dialog
00295         static HICON m_hiconProgress;
00296 
00297         // Lookup table for callback objects mapping progress dialog handles to the callback
00298         // pointers they belong to. This is necessary as all progress dialogs share the same 
00299         // procedure and we may have several of them running simultaneously
00300         static CTypedPtrMap<CMapPtrToPtr, HWND, AsynchBindStatusCallback*> m_CallbackTable; 
00301 
00302   
00303           // constructors/destructors
00304         AsynchBindStatusCallback(AsynchDownload* pDownload);
00305         ~AsynchBindStatusCallback();
00306           
00307         // Standard IUnknown methods
00309         // Returns S_OK if the interface is supported, E_NOTIMPL otherwise 
00310         HRESULT _stdcall    QueryInterface(REFIID riid,void ** ppv);
00311         // Increment reference count
00312         inline UINT32 _stdcall    AddRef()    { return m_dwRef++; }
00313         // Decrement reference count; delete object if the reference count reaches 0
00314         inline UINT32 _stdcall    Release()   { if (--m_dwRef == 0) { delete this; return 0; } return m_dwRef; }
00315 
00316         // IBindStatusCallback methods - the ones we're not interested in will simply return E_NOTIMPL
00318         // Called on start binding, allows us to retrieve the IBinding* pointer
00319         HRESULT _stdcall    OnStartBinding(DWORD dwReserved, IBinding* pbinding);
00320         // Not used
00321         inline HRESULT _stdcall    GetPriority(INT32* pnPriority) {return E_NOTIMPL;}
00322         // Not used
00323         inline HRESULT _stdcall    OnLowResource(DWORD dwReserved) {return E_NOTIMPL;}
00324         // Called when the state of the download changes (connection established/failed, new data has arrived, etc)
00325         // Also allows us to cancel the download by returning E_ABORT
00326         HRESULT _stdcall    OnProgress(UINT32 ulProgress, UINT32 ulProgressMax, UINT32 ulStateCode,
00327                             LPCWSTR pwzStateText);
00328         // Called on stop binding - hrResult will be non-zero if an error occured
00329         HRESULT _stdcall    OnStopBinding(HRESULT hrResult, LPCWSTR szError);
00330         // Called just before the binding is started - allows us to request that the binding be asynchronous by setting 
00331         // the necessary flags in pgrfBINDF
00332         HRESULT _stdcall    GetBindInfo(DWORD* pgrfBINDF, BINDINFO* pbindinfo);
00333         // Not used
00334         HRESULT _stdcall    OnDataAvailable(DWORD grfBSCF, DWORD dwSize, FORMATETC *pfmtetc,
00335                             STGMEDIUM* pstgmed);
00336         // Not used
00337         inline HRESULT _stdcall    OnObjectAvailable(REFIID riid, IUnknown* punk) {return E_NOTIMPL;}
00338 
00339         // IAuthenticate methods
00341         STDMETHODIMP        Authenticate(HWND *phwnd, LPWSTR *pszUserName, LPWSTR *pszPassword);
00342 
00343         // Progress dialog functions
00345         // Create a modeless progress dialog box and attach it to this callback 
00346         BOOL AttachProgressDlg();
00347         // Detach the callback from its progress dialog and destroy it
00348         void DetachProgressDlg();
00349         // Dialog procedure for the progress dialog
00350         static BOOL CALLBACK DialogProc(HWND hwndDlg, UINT32 message, WPARAM wParam, LPARAM lParam);
00351     };
00352     AsynchBindStatusCallback* m_pCallback;
00353 
00354     friend class AsynchBindStatusCallback;
00355     friend class InternetManager;
00356 };
00357 
00358 
00359 /********************************************************************************************
00360 
00361 >   class DownloadQueue : public CCObject
00362 
00363     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
00364     Created:    4/12/96
00365     Purpose:    InternetManager support class. Represents a queue of asynchronous downloads,
00366                     which are executed in sequence one at a time
00367 
00368 ********************************************************************************************/
00369 
00370 class DownloadQueue : public CCObject
00371 {
00372     // Give my name in memory dumps
00373     CC_DECLARE_MEMDUMP(DownloadQueue);
00374 
00375 public:
00376     enum QueueType {FIFO = 0, LIFO}; // valid queue types
00377     // Construction / destruction
00378     DownloadQueue() {m_enType = FIFO;}
00379     ~DownloadQueue();
00380     // Add another download object to the queue
00381     BOOL Queue(AsynchDownload* pDownload);
00382     // Set the queue type "on the fly". The queue may behave like a LIFO or a FIFO depending on the type of files in the queue
00383     inline void SetType(QueueType enNewType) { m_enType = enNewType;}
00384     // Retrieve the current type
00385     inline QueueType GetType() { return m_enType;}
00386     // Test for empty
00387     BOOL IsEmpty() { return m_List.IsEmpty();}
00388     // Remove a download object from the queue 
00389     BOOL Remove(AsynchDownload* pDownload);
00390     // Flush the queue
00391     void Flush();
00392     // Get a pointer to a download object in the queue knowing its file name
00393     AsynchDownload* FindDownload(const String_256& strFileName);
00394     // Get a pointer to a download object in the queue knowing download handle
00395     AsynchDownload* FindDownload(DOWNLOAD_HANDLE hDownload);
00396     // Get a pointer to the next download in the queue and remove it from the queue 
00397     AsynchDownload* GetNextDownload();
00398 
00399 protected:
00400     // The actual MFC container object 
00401      CTypedPtrList<CPtrList, AsynchDownload*> m_List;
00402      QueueType m_enType;
00403 };
00404 
00405 
00406 /********************************************************************************************
00407 
00408 >   struct CacheEntry
00409 
00410     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
00411     Created:    16/06/97
00412     Purpose:    DownloadCache support structure. Encapsulates an entry into the
00413                         cache file table
00414 
00415 ********************************************************************************************/
00416 
00417 struct CacheEntry
00418 {
00419     // <----DISCARD FIRST---------------------------------------------------------------------------------------------DISCARD LAST---------------->
00420     enum Priority {PRIORITY_OTHER = 0, PRIORITY_FONT_FILE,  PRIORITY_CLIPART_FILE,  PRIORITY_FILL_FILE,
00421         PRIORITY_CLIPART_THUMBNAIL, PRIORITY_FONT_THUMBNAIL, PRIORITY_FILL_THUMBNAIL, 
00422         PRIORITY_OLD_CATALOG_FILE, PRIORITY_CURRENT_CATALOG_FILE};
00423     struct _tstat m_FileStat;
00424     TCHAR szFilePath[_MAX_PATH];
00425     BOOL m_bIsValid;
00426     Priority m_nPriority;
00427     CacheEntry() {memset(szFilePath, 0x00, sizeof(szFilePath)); m_bIsValid = FALSE;}
00428     CacheEntry(const String_256& strPath); 
00429     inline BOOL IsValid() {return m_bIsValid;}
00430     inline INT32 Size() const {return m_FileStat.st_size;}
00431     inline INT32 GetPriority() const {return m_nPriority;}
00432     inline BOOL IsFolder() {return m_bIsValid ? m_FileStat.st_mode & _S_IFDIR : FALSE;}
00433     inline BOOL IsFile() {return m_bIsValid ? m_FileStat.st_mode &  _S_IFREG : FALSE;}
00434     BOOL operator !=(const CacheEntry& entry) { return _tcsicmp(szFilePath, entry.szFilePath);} 
00435 };  
00436 
00437 /********************************************************************************************
00438 
00439 >   struct CacheRemovalAlgorithm
00440 
00441     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
00442     Created:    16/06/97
00443     Purpose:    DownloadCache support structure. Implements the cache removal
00444                         algorithm. When the cache fills up, files with lower priority will
00445                         be discarded first (see CacheEntry::Priority); for files of equal
00446                         priority we compare the time stamps.
00447 
00448 ********************************************************************************************/
00449 
00450 struct CacheRemovalAlgorithm : public STL::binary_function<CacheEntry, CacheEntry, BOOL> 
00451 {
00452     inline BOOL operator()(const CacheEntry& first, const CacheEntry& second) const 
00453     {
00454         INT32 nFirstEntryPriority = first.GetPriority(), nSecondEntryPriority = second.GetPriority();
00455         if (nFirstEntryPriority > nSecondEntryPriority)
00456             return TRUE;
00457         else if (nFirstEntryPriority < nSecondEntryPriority)
00458             return FALSE;
00459         else // entries are of the same priority, use time stamps
00460             return first.m_FileStat.st_ctime >= second.m_FileStat.st_ctime ? TRUE : FALSE;
00461     }
00462 };
00463 
00464 
00465 
00466 /********************************************************************************************
00467 
00468 >   DownloadCache
00469 
00470     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
00471     Created:    15/06/97
00472     Purpose:    Implements the file cache used by the InternetManager
00473     Comment: The interface is static so it can be accessed from anywhere
00474                     in the program with the scope resolution operator ::    
00475 
00476 ********************************************************************************************/
00477 
00478 
00479 
00480 class DownloadCache : public CCObject
00481 {
00482     // Give my name in memory dumps
00483     CC_DECLARE_MEMDUMP(DownloadCache);
00484 public:
00485     // Set the size (in bytes) of the cache. By default the cache size is 5000 Kb
00486     static BOOL SetSize(UINT32 lSize);
00487     // Returns the cache size 
00488     inline static UINT32 GetSize() {return m_lMaxSize;}
00489     // Returns percentage of cache space actually used
00490     inline static INT32 GetUsage() {return m_lMaxSize ? 100 * m_lCurrentSize/m_lMaxSize : 0;}
00491     // Set the cache root directory (currently a subdirectory called /Cache in the app's directory)
00492     static BOOL SetPath(const String_256& strCachePath);
00493     // Empty the cache - note that the cache directory structure and catalog files WILL NOT be removed
00494     static void Flush();
00495     // Delete a file from the cache
00496     static INT32 RemoveFile(const TCHAR* szFilePath);
00497     // Rename a file in the cache
00498     static INT32 RenameFile(const TCHAR* szOldName, const TCHAR* szNewName);
00499     // Add a file to the cache
00500     static void InsertFile(const TCHAR* szFilePath);
00501     // Update cache information by scanning it - n.b. this can be SLOW
00502     static void Refresh();
00503     // Returns TRUE if the given path points to a file/folder in the cache
00504     static BOOL IsCachePath(const TCHAR* szPath);
00505     static class CacheMonitor
00506     {
00507     public:
00508         enum EVENTS {EVENT_DEACTIVATE = 0, EVENT_CHANGE};
00509         CacheMonitor();
00510         ~CacheMonitor();
00511         BOOL Activate(String_256& strCachePath);
00512         BOOL Deactivate();
00513         inline void IgnoreEvents(INT32 nEvents) {m_nIgnoreCount += nEvents;}  
00514     private:
00515         static HANDLE rgEvents[2];
00516         static CRITICAL_SECTION m_CacheDataCriticalSection;
00517         static volatile INT32 m_nIgnoreCount;
00518         HANDLE m_hMonitorThread;
00519         unsigned m_dwMonitorThreadID;
00520         static void OnCacheEvent();
00521         static unsigned __stdcall Monitor(LPVOID lpParam);
00522         friend class DownloadCache;
00523     } m_CacheMonitor;
00524 
00525 private:
00526     static UINT32 m_lMaxSize;
00527     static UINT32 m_lCurrentSize;
00528     static String_256 m_strCachePath;
00529     static INT32 m_nInstanceCount;
00530     static STL::priority_queue< CacheEntry, STL::vector<CacheEntry>, CacheRemovalAlgorithm> m_CacheData;
00531     static STL::priority_queue< CacheEntry, STL::vector<CacheEntry>, CacheRemovalAlgorithm> m_TemporaryCacheData;
00532     inline static void RemoveEntry(CacheEntry& entry)
00533     {
00534         while (!m_TemporaryCacheData.empty()) 
00535             m_TemporaryCacheData.pop();
00536         while (!m_CacheData.empty()) 
00537         {
00538             if (entry != m_CacheData.top()) 
00539                 m_TemporaryCacheData.push(m_CacheData.top());
00540             m_CacheData.pop();
00541         }
00542         m_CacheData = m_TemporaryCacheData;
00543     }
00544 #ifdef _DEBUG
00545     static void AssertCacheDataValid()
00546     {
00547         UINT32 lRealCacheSize = 0;
00548         while (!m_TemporaryCacheData.empty()) 
00549             m_TemporaryCacheData.pop();
00550         while (!m_CacheData.empty()) 
00551         {
00552             lRealCacheSize += m_CacheData.top().Size();
00553             m_TemporaryCacheData.push(m_CacheData.top());
00554             m_CacheData.pop();
00555         }
00556         m_CacheData = m_TemporaryCacheData;
00557         ERROR3IF(lRealCacheSize != m_lCurrentSize, "WARNING: Download cache data not valid");
00558     }
00559 #endif
00560     static BOOL Traverse(const String_256& strPath, BOOL bFlush = FALSE);
00561     
00562     friend class InternetManager;
00563     friend class LibraryGallery;
00564     friend class LibClipartSGallery;
00565 };
00566 
00567 
00568 
00569 
00570 
00571 
00572 
00573 
00574 
00575 /********************************************************************************************
00576 
00577 >   class InternetManager : public CCObject
00578 
00579     Author:     Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
00580     Created:    4/12/96
00581     Purpose:    Webster connection/download manager.
00582                     It is responsible for schedulling downloads for execution according to the priority declared by the client on registration,
00583                     ensuring that no more than a preset number of connections are open at any one time (important for
00584                     users with limited bandwidth), and otherwise keeping track of their fate.
00585                     The sheduling sheme is as follows:
00586                     - downloads with AsynchDownload::PRIORITY_NORMAL will be executed one at a time, as long as there are
00587                         no high priority downloads queued up and the maximum number of connections is not exceeded. They all
00588                         share the same progress dlg, which is hidden when there are no downloads scheduled
00589                     - downloads with AsynchDownload::PRIORITY_HIGH will be executed simultaneously, up to the maximum no
00590                         of connections. Each download gets its own progress dlg.
00591 
00592                     In the present system thumbnail downloads should be registered with PRIORITY_NORMAL, clipart and catalog files 
00593                     should use PRIORITY_HIGH. Maybe types should be used instead of priorities, things might be a bit clearer if TYPE_THUMB
00594                     and TYPE_CLIPART - for instance - were used instead of priorities. However, this is supposed to be a general purpose class
00595                     not limited to downloading clipart.
00596     Comment: The interface is static so it can be accessed from anywhere in the program with the scope resolution operator ::   
00597 
00598 ********************************************************************************************/
00599 
00600 class InternetManager : public CCObject
00601 {
00602     // Give my name in memory dumps
00603     CC_DECLARE_MEMDUMP(InternetManager);
00604 
00605 public:
00606     // Initialization/release
00607     static void Initialize();
00608     static void OnExitInstance();
00609     // Public interface
00611     // Try to connect to the Internet. Returns FALSE if no connection could be started, in which case no Internet-related functions should be called 
00612     inline static BOOL AttemptConnection() { return (InternetAttemptConnect(NULL) == ERROR_SUCCESS);}
00613     // Called by a client object to register a download - returns a non-zero handle if successful, 0 otherwise
00614     static DOWNLOAD_HANDLE RegisterDownload(LPDOWNLOADINFO pDownloadInfo);
00615     // Unregister a previously registered download - called if the file is not required anymore, for instance if the client object
00616     // is about to be destroyed. If the download has already started it will be aborted and deleted as soon as possible - otherwise
00617     // it will simply be removed from its queue and deleted.
00618     static BOOL UnregisterDownload(DOWNLOAD_HANDLE hDownload);
00619     // Returns the state of a download based on its handle 
00620     static AsynchDownload::State GetDownloadState(DOWNLOAD_HANDLE handle);
00621     // Cancel all downloads and flush the queues
00622     static void CancelAllDownloads();
00623     // Stops downloading as soon as possible - downloads already in progress will be allowed to complete
00624     inline static void Suspend() {m_bIsSuspended = TRUE;}
00625     // Resumes downloading after a call to Suspend()
00626     static void Resume();
00627     // Return the percentage downloaded on a specific handle
00628     static INT32 GetPercentageDownloaded(DOWNLOAD_HANDLE hDownload);
00629     // Tests for suspended state
00630     inline static BOOL IsSuspended() {return m_bIsSuspended;}
00631     // Sets the type of connections we use
00632     static void SetConnectionType(ConnectionType type);
00633     // Gets the type of connections we use
00634     static ConnectionType GetConnectionType();
00635 //  // Gets a SERVENT pointer to the currently set proxy server 
00636     static bool GetProxyServer(SERVENT* pProxyEntry, bool* pbProxyEnabled);
00637 //  // Returns TRUE if there are any pending downloads
00638     inline static BOOL HasDownloadsPending() {return (BOOL) (AsynchDownload::m_nNormalPriorityInstanceCount + AsynchDownload::m_nHighPriorityInstanceCount);}
00639     
00640 private:
00641     // Implementation
00643     static DOWNLOAD_HANDLE m_NextHandle; // next free download handle
00644     static BOOL m_bIsSuspended;
00645     static INT32 rgConnections[4];
00646     static INT32 nMaxConnections; // maximum no. of symultaneous connections/downloads (default is 32)
00647     static CTypedPtrArray<CPtrArray, AsynchDownload*> m_CurrentDownloads; // array of currently executing downloads
00648     static String_256 strTempFileURL; // URL of  the temporary file used by the last download process
00649     static DownloadQueue m_NormalPriorityQueue; // normal queue
00650     static DownloadQueue m_HighPriorityQueue; // fast-track queue
00651     static AsynchDownload::State m_StateTable[MAX_HANDLE]; // table of download states - used to keep track of their progress
00652     // Callback function called when the object pointed to by pDownload has completed downloading
00653     static void OnDownloadComplete(AsynchDownload* pDownload);
00654     // Returns the number of current connections with the given priority
00655     static INT32 GetOpenConnections(AsynchDownload::Priority priority);
00656     // Returns a pointer to an AsynchDownload object given a local filename the object is downloading to
00657     static AsynchDownload* GetPendingDownload(const String_256& strFileName);
00658     // Returns a pointer to an AsynchDownload object given a download handle
00659     static AsynchDownload* GetPendingDownload(DOWNLOAD_HANDLE handle);
00660     static AsynchDownload* GetDownload(DOWNLOAD_HANDLE handle);
00661     // Returns the current normal priority download, if any
00662     static AsynchDownload* GetCurrentNormalPriorityDownload();
00663     friend class AsynchDownload;
00664     friend class AsynchDownload::AsynchBindStatusCallback;
00665     friend class DownloadQueue;
00666     static void SetState(DOWNLOAD_HANDLE hDownload, AsynchDownload::State state);
00667 
00668 public:
00669     // preferences
00670     static UINT32 g_ConnectionType;
00671     static UINT32 g_CacheSize;
00672 };
00673 
00674 #endif
00675 
00676 
00677 

Generated on Sat Nov 10 03:48:10 2007 for Camelot by  doxygen 1.4.4