38 #ifdef DEBUG_STORAGE_ADVISER 39 SVDEBUG <<
"StorageAdviser::recommend: Criteria " << criteria
40 <<
", minimumSize " << minimumSize
41 <<
", maximumSize " << maximumSize << endl;
51 }
catch (std::exception e) {
52 cerr <<
"StorageAdviser::recommend: ERROR: Failed to get temporary directory path: " << e.what() << endl;
56 int memoryFree, memoryTotal;
61 }
else if (discFree > 0) {
67 }
else if (memoryFree > 0) {
71 #ifdef DEBUG_STORAGE_ADVISER 72 cerr <<
"Disc space: " << discFree <<
", memory free: " << memoryFree <<
", memory total: " << memoryTotal <<
", min " << minimumSize <<
", max " << maximumSize << endl;
87 StorageStatus memoryStatus = Unknown;
88 StorageStatus discStatus = Unknown;
90 int minmb = minimumSize / 1024 + 1;
91 int maxmb = maximumSize / 1024 + 1;
93 if (memoryFree == -1) memoryStatus = Unknown;
94 else if (memoryFree < memoryTotal / 3) memoryStatus = Insufficient;
95 else if (minmb > (memoryFree * 3) / 4) memoryStatus = Insufficient;
96 else if (maxmb > (memoryFree * 3) / 4) memoryStatus = Marginal;
97 else if (minmb > (memoryFree / 3)) memoryStatus = Marginal;
98 else if (memoryTotal == -1 ||
99 minmb > (memoryTotal / 10)) memoryStatus = Marginal;
100 else memoryStatus = Sufficient;
102 if (discFree == -1) discStatus = Unknown;
103 else if (minmb > (discFree * 3) / 4) discStatus = Insufficient;
104 else if (maxmb > (discFree / 4)) discStatus = Marginal;
105 else if (minmb > (discFree / 10)) discStatus = Marginal;
106 else discStatus = Sufficient;
108 #ifdef DEBUG_STORAGE_ADVISER 109 cerr <<
"Memory status: " << memoryStatus <<
", disc status " 110 << discStatus << endl;
115 if (memoryStatus == Insufficient || memoryStatus == Unknown) {
119 if (discStatus == Insufficient && minmb > discFree) {
123 if (discStatus == Insufficient || discStatus == Marginal) {
131 }
else if (memoryStatus == Marginal) {
140 if (discStatus != Insufficient) {
150 if (discStatus == Insufficient) {
152 }
else if (discStatus == Marginal) {
154 }
else if (discStatus == Unknown) {
163 if (discStatus == Insufficient) {
165 }
else if (discStatus != Sufficient) {
static void notifyPlannedAllocation(AllocationArea area, int size)
Specify that we are planning to use a given amount of storage (in kilobytes), but haven't allocated i...
static long m_memoryPlanned
QString getPath()
Create the root temporary directory if necessary, and return its path.
static long m_discPlanned
int GetDiscSpaceMBAvailable(const char *path)
static Recommendation m_baseRecommendation
static TempDirectory * getInstance()
static void notifyDoneAllocation(AllocationArea area, int size)
Specify that we have now allocated, or abandoned the allocation of, the given amount (in kilobytes) o...
void GetRealMemoryMBAvailable(int &available, int &total)
static Recommendation recommend(Criteria criteria, int minimumSize, int maximumSize)
Recommend where to store some data, given certain storage and recall criteria.
static void setFixedRecommendation(Recommendation recommendation)
Force all subsequent recommendations to use the (perhaps partial) specification given here.