29 if (criteria &
SpeedCritical) labels.push_back(
"SpeedCritical");
33 if (labels.empty())
return "None";
34 else return labels.join(
"+");
41 if (recommendation &
UseMemory) labels.push_back(
"UseMemory");
42 if (recommendation &
PreferMemory) labels.push_back(
"PreferMemory");
43 if (recommendation &
PreferDisc) labels.push_back(
"PreferDisc");
44 if (recommendation &
UseDisc) labels.push_back(
"UseDisc");
45 if (recommendation &
ConserveSpace) labels.push_back(
"ConserveSpace");
47 if (labels.empty())
return "None";
48 else return labels.join(
"+");
55 if (status ==
Marginal)
return "Marginal";
71 SVDEBUG <<
"StorageAdviser::recommend: criteria " << criteria
73 <<
", minimumSize " << minimumSize
74 <<
", maximumSize " << maximumSize << endl;
77 SVDEBUG <<
"StorageAdviser::recommend: Returning fixed recommendation " 86 }
catch (
const std::exception &e) {
87 SVDEBUG <<
"StorageAdviser::recommend: ERROR: Failed to get temporary directory path: " << e.what() << endl;
89 SVDEBUG <<
"StorageAdviser: returning fallback " << r
94 ssize_t memoryFree, memoryTotal;
97 SVDEBUG <<
"StorageAdviser: disc space: " << discFree
98 <<
"M, memory free: " << memoryFree
99 <<
"M, memory total: " << memoryTotal <<
"M" << endl;
108 if (
sizeof(
void *) < 8) {
109 if (memoryTotal > 4096) {
110 ssize_t excess = memoryTotal - 4096;
111 if (memoryFree > excess) {
112 memoryFree -= excess;
116 SVDEBUG <<
"StorageAdviser: more real memory found than we " 117 <<
"can address in a 32-bit process, reducing free " 118 <<
"estimate to " << memoryFree <<
"M accordingly" << endl;
124 SVDEBUG <<
"StorageAdviser: min requested: " << minimumSize
125 <<
"K, max requested: " << maximumSize <<
"K" << endl;
129 }
else if (discFree > 0) {
135 }
else if (memoryFree > 0) {
147 ssize_t minmb = ssize_t(minimumSize / 1024 + 1);
148 ssize_t maxmb = ssize_t(maximumSize / 1024 + 1);
150 if (memoryFree == -1) memoryStatus =
Unknown;
151 else if (memoryFree < memoryTotal / 3 && memoryFree < 512) memoryStatus =
Insufficient;
152 else if (minmb > (memoryFree * 3) / 4) memoryStatus =
Insufficient;
153 else if (maxmb > (memoryFree * 3) / 4) memoryStatus =
Marginal;
154 else if (minmb > (memoryFree / 3)) memoryStatus =
Marginal;
155 else if (memoryTotal == -1 ||
156 minmb > (memoryTotal / 10)) memoryStatus =
Marginal;
159 if (discFree == -1) discStatus =
Unknown;
160 else if (minmb > (discFree * 3) / 4) discStatus =
Insufficient;
161 else if (maxmb > (discFree / 4)) discStatus =
Marginal;
162 else if (minmb > (discFree / 10)) discStatus =
Marginal;
165 SVDEBUG <<
"StorageAdviser: memory status: " << memoryStatus
167 <<
", disc status " << discStatus
188 }
else if (memoryStatus ==
Marginal) {
209 }
else if (discStatus ==
Marginal) {
211 }
else if (discStatus ==
Unknown) {
241 SVDEBUG <<
"StorageAdviser: returning recommendation " << recommendation
void GetRealMemoryMBAvailable(ssize_t &available, ssize_t &total)
ssize_t GetDiscSpaceMBAvailable(const char *path)
static Recommendation recommend(Criteria criteria, size_t minimumSize, size_t maximumSize)
Recommend where to store some data, given certain storage and recall criteria.
QString getPath()
Create the root temporary directory if necessary, and return its path.
static QString criteriaToString(int)
static Recommendation m_baseRecommendation
static TempDirectory * getInstance()
static void notifyPlannedAllocation(AllocationArea area, size_t size)
Specify that we are planning to use a given amount of storage (in kilobytes), but haven't allocated i...
static void notifyDoneAllocation(AllocationArea area, size_t size)
Specify that we have now allocated, or abandoned the allocation of, the given amount (in kilobytes) o...
static void setFixedRecommendation(Recommendation recommendation)
Force all subsequent recommendations to use the (perhaps partial) specification given here...
static size_t m_discPlanned
static size_t m_memoryPlanned
static QString recommendationToString(int)
static QString storageStatusToString(StorageStatus)