Methods for caching generic data

This commit is contained in:
Linus Dierheimer
2022-06-20 16:35:15 +02:00
parent 8fa09ca093
commit af0c72aa61
9 changed files with 50 additions and 25 deletions
+7 -7
View File
@@ -23,7 +23,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//type must exist and be "Battery"
ffStrbufAppendS(dir, "/type");
ffGetFileBuffer(dir->chars, &testBatteryBuffer);
ffReadFileBuffer(dir->chars, &testBatteryBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Battery") != 0)
@@ -34,7 +34,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//scope may not exist or must not be "Device"
ffStrbufAppendS(dir, "/scope");
ffGetFileBuffer(dir->chars, &testBatteryBuffer);
ffReadFileBuffer(dir->chars, &testBatteryBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Device") == 0)
@@ -49,7 +49,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
//capacity must exist and be not empty
ffStrbufInit(&result->capacity);
ffStrbufAppendS(dir, "/capacity");
ffGetFileBuffer(dir->chars, &result->capacity);
ffReadFileBuffer(dir->chars, &result->capacity);
ffStrbufSubstrBefore(dir, dirLength);
if(result->capacity.length == 0)
@@ -63,22 +63,22 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
ffStrbufInit(&result->manufacturer);
ffStrbufAppendS(dir, "/manufacturer");
ffGetFileBuffer(dir->chars, &result->manufacturer);
ffReadFileBuffer(dir->chars, &result->manufacturer);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->modelName);
ffStrbufAppendS(dir, "/model_name");
ffGetFileBuffer(dir->chars, &result->modelName);
ffReadFileBuffer(dir->chars, &result->modelName);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->technology);
ffStrbufAppendS(dir, "/technology");
ffGetFileBuffer(dir->chars, &result->technology);
ffReadFileBuffer(dir->chars, &result->technology);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->status);
ffStrbufAppendS(dir, "/status");
ffGetFileBuffer(dir->chars, &result->status);
ffReadFileBuffer(dir->chars, &result->status);
ffStrbufSubstrBefore(dir, dirLength);
}
+2 -2
View File
@@ -10,9 +10,9 @@ static double getGhz(const char* policyFile, const char* cpuFile)
FFstrbuf content;
ffStrbufInit(&content);
ffGetFileBuffer(policyFile, &content);
ffReadFileBuffer(policyFile, &content);
if(content.length == 0)
ffGetFileBuffer(cpuFile, &content);
ffReadFileBuffer(cpuFile, &content);
double herz = ffStrbufToDouble(&content);
+4 -4
View File
@@ -39,10 +39,10 @@ static bool hostValueSet(FFstrbuf* value)
static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
{
ffGetFileBuffer(devicesPath, buffer);
ffReadFileBuffer(devicesPath, buffer);
if(buffer->length == 0)
ffGetFileBuffer(classPath, buffer);
ffReadFileBuffer(classPath, buffer);
}
#endif
@@ -67,10 +67,10 @@ void ffPrintHost(FFinstance* instance)
getHostValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &product_name);
if(product_name.length == 0)
ffGetFileBuffer("/sys/firmware/devicetree/base/model", &product_name);
ffReadFileBuffer("/sys/firmware/devicetree/base/model", &product_name);
if(product_name.length == 0)
ffGetFileBuffer("/tmp/sysinfo/model", &product_name);
ffReadFileBuffer("/tmp/sysinfo/model", &product_name);
if(ffStrbufStartsWithS(&product_name, "Standard PC"))
{