changeset 169:603991c63ff6

...
author Chris Cannam
date Mon, 25 Sep 2006 20:32:44 +0000
parents 04baa690f90d
children b23eea68357e
files base/StorageAdviser.h system/System.cpp
diffstat 2 files changed, 30 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/base/StorageAdviser.h	Mon Sep 25 13:44:05 2006 +0000
+++ b/base/StorageAdviser.h	Mon Sep 25 20:32:44 2006 +0000
@@ -39,9 +39,17 @@
         UseAsMuchAsYouLike = 8
     };
 
-    // may throw InsufficientDiscSpace exception if it looks like
-    // minimumSize won't fit on the disc
+    // May throw InsufficientDiscSpace exception if it looks like
+    // minimumSize won't fit on the disc.  
 
+    /**
+     * Recommend where to store some data, given certain storage and
+     * recall criteria.  The minimum size is the approximate amount of
+     * data in bytes that will be stored if the recommendation is to
+     * ConserveSpace; the maximum size is approximately the amount
+     * that will be used if UseAsMuchAsYouLike is returned.
+     **!!! sizes should be longer types
+     */
     static Recommendation recommend(Criteria criteria,
                                     int minimumSize,
                                     int maximumSize);
--- a/system/System.cpp	Mon Sep 25 13:44:05 2006 +0000
+++ b/system/System.cpp	Mon Sep 25 20:32:44 2006 +0000
@@ -15,8 +15,6 @@
 
 #include "System.h"
 
-#include <QFile>
-#include <QTextStream>
 #include <QStringList>
 #include <QString>
 
@@ -79,28 +77,28 @@
 int
 GetRealMemoryMBAvailable()
 {
-    // ugh
-    QFile meminfo("/proc/meminfo");
-    if (meminfo.open(QFile::ReadOnly)) {
-        std::cerr << "opened meminfo" << std::endl;
-        QTextStream in(&meminfo);
-        while (!in.atEnd()) {
-            QString line = in.readLine(256);
-            std::cerr << "read: \"" << line.toStdString() << "\"" << std::endl;
-            if (line.startsWith("MemFree:")) {
-                QStringList elements = line.split(' ', QString::SkipEmptyParts);
-                QString unit = "kB";
-                if (elements.size() > 2) unit = elements[2];
-                int size = elements[1].toInt();
-                std::cerr << "have size \"" << size << "\", unit \""
-                          << unit.toStdString() << "\"" << std::endl;
-                if (unit.toLower() == "gb") return size * 1024;
-                if (unit.toLower() == "mb") return size;
-                if (unit.toLower() == "kb") return size / 1024;
-                return size / 1048576;
-            }
+    FILE *meminfo = fopen("/proc/meminfo", "r");
+    if (!meminfo) return -1;
+
+    char buf[256];
+    while (!feof(meminfo)) {
+        fgets(buf, 256, meminfo);
+        if (strncmp(buf, "MemFree:", 8)) {
+            fclose(meminfo);
+            QString line = QString(buf).trimmed();
+            QStringList elements = line.split(' ', QString::SkipEmptyParts);
+            QString unit = "kB";
+            if (elements.size() > 2) unit = elements[2];
+            int size = elements[1].toInt();
+//            std::cerr << "have size \"" << size << "\", unit \""
+//                      << unit.toStdString() << "\"" << std::endl;
+            if (unit.toLower() == "gb") return size * 1024;
+            if (unit.toLower() == "mb") return size;
+            if (unit.toLower() == "kb") return size / 1024;
+            return size / 1048576;
         }
     }
+    fclose(meminfo);
     return -1;
 }