mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 09:58:03 +02:00
OpenCL: JSON format support
This commit is contained in:
@@ -49,14 +49,17 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result)
|
||||
if(ffStrStartsWithIgnCase(version, "OpenCL "))
|
||||
versionPretty = version + strlen("OpenCL ");
|
||||
ffStrbufSetS(&result->version, versionPretty);
|
||||
ffStrbufTrim(&result->version, ' ');
|
||||
|
||||
ffStrbufEnsureFree(&result->device, 128);
|
||||
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_NAME, result->device.allocated, result->device.chars, NULL);
|
||||
ffStrbufRecalculateLength(&result->device);
|
||||
ffStrbufTrim(&result->device, ' ');
|
||||
|
||||
ffStrbufEnsureFree(&result->vendor, 32);
|
||||
data->ffclGetDeviceInfo(deviceID, CL_DEVICE_VENDOR, result->vendor.allocated, result->vendor.chars, NULL);
|
||||
ffStrbufRecalculateLength(&result->vendor);
|
||||
ffStrbufTrim(&result->vendor, ' ');
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ void ffPrintOpenCL(FFOpenCLOptions* options)
|
||||
|
||||
void ffInitOpenCLOptions(FFOpenCLOptions* options)
|
||||
{
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENCL_MODULE_NAME, ffParseOpenCLCommandOptions, ffParseOpenCLJsonObject, ffPrintOpenCL, NULL);
|
||||
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENCL_MODULE_NAME, ffParseOpenCLCommandOptions, ffParseOpenCLJsonObject, ffPrintOpenCL, ffGenerateOpenCLJson);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
@@ -76,3 +76,29 @@ void ffParseOpenCLJsonObject(FFOpenCLOptions* options, yyjson_val* module)
|
||||
ffPrintError(FF_OPENCL_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
void ffGenerateOpenCLJson(FF_MAYBE_UNUSED FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
{
|
||||
FFOpenCLResult opencl;
|
||||
ffStrbufInit(&opencl.version);
|
||||
ffStrbufInit(&opencl.device);
|
||||
ffStrbufInit(&opencl.vendor);
|
||||
|
||||
const char* error = ffDetectOpenCL(&opencl);
|
||||
|
||||
if(error != NULL)
|
||||
{
|
||||
yyjson_mut_obj_add_str(doc, module, "error", error);
|
||||
}
|
||||
else
|
||||
{
|
||||
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "version", &opencl.version);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "device", &opencl.device);
|
||||
yyjson_mut_obj_add_strbuf(doc, obj, "vendor", &opencl.vendor);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&opencl.version);
|
||||
ffStrbufDestroy(&opencl.device);
|
||||
ffStrbufDestroy(&opencl.vendor);
|
||||
}
|
||||
|
||||
@@ -9,3 +9,4 @@ void ffInitOpenCLOptions(FFOpenCLOptions* options);
|
||||
bool ffParseOpenCLCommandOptions(FFOpenCLOptions* options, const char* key, const char* value);
|
||||
void ffDestroyOpenCLOptions(FFOpenCLOptions* options);
|
||||
void ffParseOpenCLJsonObject(FFOpenCLOptions* options, yyjson_val* module);
|
||||
void ffGenerateOpenCLJson(FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
|
||||
|
||||
Reference in New Issue
Block a user