1 // Copyright (C) 2013 James Turner - zakalawe@mac.com 2 // 3 // This library is free software; you can redistribute it and/or 4 // modify it under the terms of the GNU Library General Public 5 // License as published by the Free Software Foundation; either 6 // version 2 of the License, or (at your option) any later version. 7 // 8 // This library is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 // Library General Public License for more details. 12 // 13 // You should have received a copy of the GNU General Public License 14 // along with this program; if not, write to the Free Software 15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 // 17 18 #ifndef SG_PACKAGE_DELEGATE_HXX 19 #define SG_PACKAGE_DELEGATE_HXX 20 21 #include <string> 22 #include <simgear/misc/stdint.hxx> 23 #include <simgear/structure/SGSharedPtr.hxx> 24 25 namespace simgear 26 { 27 28 namespace pkg 29 { 30 31 class Install; 32 class Catalog; 33 class Package; 34 35 typedef SGSharedPtr<Catalog> CatalogRef; 36 typedef SGSharedPtr<Install> InstallRef; 37 typedef SGSharedPtr<Package> PackageRef; 38 39 /** 40 * package delegate is the mechanism to discover progress / completion / 41 * errors in packaging steps asynchronously. 42 */ 43 class Delegate 44 { 45 public: 46 typedef enum { 47 STATUS_SUCCESS = 0, 48 FAIL_UNKNOWN = 1, 49 STATUS_IN_PROGRESS, ///< downloading/installation in progress 50 FAIL_CHECKSUM, ///< package MD5 verificstion failed 51 FAIL_DOWNLOAD, ///< network issue 52 FAIL_EXTRACT, ///< package archive failed to extract cleanly 53 FAIL_FILESYSTEM, ///< unknown filesystem error occurred 54 FAIL_VERSION, ///< version check mismatch 55 FAIL_NOT_FOUND, ///< package URL returned a 404 56 FAIL_HTTP_FORBIDDEN, ///< URL returned a 403. Marked specially to catch rate-limiting 57 FAIL_VALIDATION, ///< catalog or package failed to validate 58 STATUS_REFRESHED, 59 USER_CANCELLED, 60 USER_DISABLED 61 } StatusCode; 62 63 ~Delegate()64 virtual ~Delegate() { } 65 66 67 /** 68 * emitted when a catalog refesh completes, either success or failure 69 * If catalog is null, this means /all/ catalogs have been refreshed 70 */ 71 virtual void catalogRefreshed(CatalogRef, StatusCode aReason) = 0; 72 73 virtual void startInstall(InstallRef aInstall) = 0; 74 virtual void installProgress(InstallRef aInstall, unsigned int aBytes, unsigned int aTotal) = 0; 75 virtual void finishInstall(InstallRef aInstall, StatusCode aReason) = 0; 76 finishUninstall(const PackageRef & aPackage)77 virtual void finishUninstall(const PackageRef& aPackage) {}; 78 79 /** 80 * Notification when catalogs/packages are added or removed 81 */ availablePackagesChanged()82 virtual void availablePackagesChanged() {} 83 84 /** 85 * More general purpose notification when install is queued / cancelled / started 86 * stopped. Reason value is only in certain cases. 87 */ 88 virtual void installStatusChanged(InstallRef aInstall, StatusCode aReason); 89 90 virtual void dataForThumbnail(const std::string& aThumbnailUrl, 91 size_t lenth, const uint8_t* bytes); 92 }; 93 94 } // of namespace pkg 95 96 } // of namespace simgear 97 98 #endif // of SG_PACKAGE_DELEGATE_HXX 99