Chris@334: Chris@168: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@168: Chris@168: /* Chris@168: Sonic Visualiser Chris@168: An audio file viewer and annotation editor. Chris@168: Centre for Digital Music, Queen Mary, University of London. Chris@202: This file copyright 2006 QMUL. Chris@168: Chris@168: This program is free software; you can redistribute it and/or Chris@168: modify it under the terms of the GNU General Public License as Chris@168: published by the Free Software Foundation; either version 2 of the Chris@168: License, or (at your option) any later version. See the file Chris@168: COPYING included with this distribution for more information. Chris@168: */ Chris@168: Chris@1276: #ifndef SV_STORAGE_ADVISER_H Chris@1276: #define SV_STORAGE_ADVISER_H Chris@168: Chris@1038: #include Chris@1038: Chris@1276: #include Chris@1276: Chris@168: /** Chris@168: * A utility class designed to help decide whether to store cache data Chris@168: * (for example FFT outputs) in memory or on disk in the TempDirectory. Chris@170: * This is basically a compendium of simple rules of thumb. Chris@168: */ Chris@168: Chris@168: class StorageAdviser Chris@168: { Chris@168: public: Chris@168: // pass to recommend() zero or more of these OR'd together Chris@168: enum Criteria { Chris@170: NoCriteria = 0, Chris@170: SpeedCritical = 1, Chris@170: PrecisionCritical = 2, Chris@170: LongRetentionLikely = 4, Chris@170: FrequentLookupLikely = 8 Chris@168: }; Chris@168: Chris@168: // recommend() returns one or two of these OR'd together Chris@168: enum Recommendation { Chris@170: NoRecommendation = 0, Chris@170: UseMemory = 1, // Disc is strongly contraindicated Chris@170: PreferMemory = 2, // Either would do; memory probably better Chris@170: PreferDisc = 4, // Either would do; disc probably better Chris@170: UseDisc = 8, // Probably won't fit in memory Chris@170: ConserveSpace = 16,// Whatever you choose, keep it compact Chris@170: UseAsMuchAsYouLike = 32 // Take my advice and there'll be space for all Chris@168: }; Chris@168: Chris@169: /** Chris@169: * Recommend where to store some data, given certain storage and Chris@169: * recall criteria. The minimum size is the approximate amount of Chris@170: * data in kilobytes that will be stored if the recommendation is Chris@170: * to ConserveSpace; the maximum size is approximately the amount Chris@169: * that will be used if UseAsMuchAsYouLike is returned. Chris@170: * Chris@170: * May throw InsufficientDiscSpace exception if there appears to Chris@170: * be nowhere the minimum amount of data can be stored. Chris@169: */ Chris@168: static Recommendation recommend(Criteria criteria, Chris@1038: size_t minimumSize, Chris@1038: size_t maximumSize); Chris@205: Chris@205: enum AllocationArea { Chris@205: MemoryAllocation, Chris@205: DiscAllocation Chris@205: }; Chris@205: Chris@205: /** Chris@205: * Specify that we are planning to use a given amount of storage Chris@205: * (in kilobytes), but haven't allocated it yet. Chris@205: */ Chris@1038: static void notifyPlannedAllocation(AllocationArea area, size_t size); Chris@205: Chris@205: /** Chris@205: * Specify that we have now allocated, or abandoned the allocation Chris@205: * of, the given amount (in kilobytes) of a storage area that was Chris@205: * previously notified using notifyPlannedAllocation. Chris@205: */ Chris@1038: static void notifyDoneAllocation(AllocationArea area, size_t size); Chris@205: Chris@411: /** Chris@411: * Force all subsequent recommendations to use the (perhaps Chris@411: * partial) specification given here. If NoRecommendation given Chris@411: * here, this will reset to the default free behaviour. Chris@411: */ Chris@411: static void setFixedRecommendation(Recommendation recommendation); Chris@411: Chris@205: private: Chris@1038: static size_t m_discPlanned; Chris@1038: static size_t m_memoryPlanned; Chris@411: static Recommendation m_baseRecommendation; Chris@1276: Chris@1276: enum StorageStatus { Chris@1276: Unknown, Chris@1276: Insufficient, Chris@1276: Marginal, Chris@1276: Sufficient Chris@1276: }; Chris@1276: Chris@1276: static QString criteriaToString(int); Chris@1276: static QString recommendationToString(int); Chris@1276: static QString storageStatusToString(StorageStatus); Chris@168: }; Chris@168: Chris@168: #endif Chris@168: