]> git.mxchange.org Git - simgear.git/blobdiff - simgear/package/Root.hxx
HTTP request cancellation
[simgear.git] / simgear / package / Root.hxx
index 176651091e98429e44f5777b886f16266653539c..69ac4804cbfa57d91db16051d2e51b850abfd45c 100644 (file)
@@ -24,6 +24,9 @@
 #include <simgear/misc/sg_path.hxx>
 #include <simgear/package/Delegate.hxx>
 
+#include <simgear/structure/SGReferenced.hxx>
+#include <simgear/structure/SGSharedPtr.hxx>
+
 class SGPropertyNode;
 
 namespace simgear
@@ -41,11 +44,15 @@ namespace pkg
 class Package;
 class Catalog;
 class Install;
+  
+typedef SGSharedPtr<Package> PackageRef;
+typedef SGSharedPtr<Catalog> CatalogRef;
+typedef SGSharedPtr<Install> InstallRef;
+  
+typedef std::vector<PackageRef> PackageList;
+typedef std::vector<CatalogRef> CatalogList;
 
-typedef std::vector<Package*> PackageList;
-typedef std::vector<Catalog*> CatalogList;
-
-class Root
+class Root : public SGReferenced
 {
 public:
     Root(const SGPath& aPath, const std::string& aVersion);
@@ -55,8 +62,10 @@ public:
     
     void setLocale(const std::string& aLocale);
         
-    void setDelegate(Delegate* aDelegate);
-        
+    void addDelegate(Delegate* aDelegate);
+    
+    void removeDelegate(Delegate* aDelegate);
+    
     std::string getLocale() const;
     
     CatalogList catalogs() const;
@@ -72,19 +81,35 @@ public:
      * set yet.
      */
     void makeHTTPRequest(HTTP::Request* req);
+
+    /**
+     * Cancel an HTTP request.
+     */
+    void cancelHTTPRequest(HTTP::Request* req, const std::string& reason);
     
     /**
-     * the version string of the root. Catalogs must match this version,
+     * The catalog XML/property version in use. This is used to make incomaptible
+     * changes to the package/catalog syntax
+     */
+    int catalogVersion() const;
+
+    /**
+     * the version string of the application. Catalogs must match this version,
      * or they will be ignored / rejected.
      */
-    std::string catalogVersion() const;
-    
+    std::string applicationVersion() const;
+
     /**
      * refresh catalogs which are more than the maximum age (24 hours by default)
      * set force to true, to download all catalogs regardless of age.
      */
     void refresh(bool aForce = false);
 
+    /**
+     *
+     */
+    PackageList allPackages() const;
+    
     /**
      * retrieve packages matching a filter.
      * filter consists of required / minimum values, AND-ed together.
@@ -97,30 +122,50 @@ public:
      */ 
     PackageList packagesNeedingUpdate() const;
      
-    Package* getPackageById(const std::string& aId) const;
+    PackageRef getPackageById(const std::string& aId) const;
+    
+    CatalogRef getCatalogById(const std::string& aId) const;
     
-    Catalog* getCatalogById(const std::string& aId) const;
+    void scheduleToUpdate(InstallRef aInstall);
+    
+    /**
+     * remove a catalog. Will uninstall all packages originating
+     * from the catalog too.
+     */
+    bool removeCatalogById(const std::string& aId);
+    
+    /**
+     * request thumbnail data from the cache / network
+     */
+    void requestThumbnailData(const std::string& aUrl);
     
-    void scheduleToUpdate(Install* aInstall);
+    bool isInstallQueued(InstallRef aInstall) const;
 private:
     friend class Install;
     friend class Catalog;    
+    friend class Package;
     
-
-    void catalogRefreshBegin(Catalog* aCat);
-    void catalogRefreshComplete(Catalog* aCat, Delegate::FailureCode aReason);
+    InstallRef existingInstallForPackage(PackageRef p) const;
+    
+    void catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason);
         
-    void startNext(Install* aCurrent);
+    void startNext(InstallRef aCurrent);
     
-    void startInstall(Install* aInstall);
-    void installProgress(Install* aInstall, unsigned int aBytes, unsigned int aTotal);
-    void finishInstall(Install* aInstall);    
-    void failedInstall(Install* aInstall, Delegate::FailureCode aReason);
-
+    void startInstall(InstallRef aInstall);
+    void installProgress(InstallRef aInstall, unsigned int aBytes, unsigned int aTotal);
+    void finishInstall(InstallRef aInstall, Delegate::StatusCode aReason);
+    void cancelDownload(InstallRef aInstall);
+    
+    void registerInstall(InstallRef ins);
+    void unregisterInstall(InstallRef ins);
+    
+    class ThumbnailDownloader;
     class RootPrivate;
     std::auto_ptr<RootPrivate> d;
 };
-    
+  
+typedef SGSharedPtr<Root> RootRef;
+  
 } // of namespace pkg
 
 } // of namespace simgear