From d15a977431a9bc7ca2d00f6a6d90865ad44180ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 17 Oct 2023 23:46:38 +0800 Subject: [PATCH 001/100] Logo (Builtin): add Black Mesa Fix #586 --- src/logo/ascii/blackmesa.txt | 20 ++++++++++++++++++++ src/logo/builtin.c | 10 ++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/logo/ascii/blackmesa.txt diff --git a/src/logo/ascii/blackmesa.txt b/src/logo/ascii/blackmesa.txt new file mode 100644 index 000000000..bc7e979d2 --- /dev/null +++ b/src/logo/ascii/blackmesa.txt @@ -0,0 +1,20 @@ + .-;+$$XHHHHHHX$$+;- + ,:X@@X%/;=----=:\%X@@X:, + =$$@@%=. .=+H@X: + -XMX: =XMX= + /@@: =H@+ + %@X. .$$@$$ + +@X, $$@% +/@@, .@@\ +%@% +@$$ +H@: :@H +H@: :HHHHHHHHHHHHHHHHHHX, =@H +%@% ;@M@@@@@@@@@@@@@@@@@H- +@$$ +=@@, :@@@@@@@@@@@@@@@@@@@@@= .@@: + =@X :@@@@@@@@@@@@@@@@@@@@@@:%@% + $$@$$, ;@@@@@@@@@@@@@@@@@M@@@@@@$$ + +@@HHHHHHH@@@@@@@@@@@@@@@@@@@@@@@ + =X@@@@@@@@@@@@@@@@@@@@@@@@@@@X= + :$$@@@@@@@@@@@@@@@@@@M@@@@$$: + \$$@@@@@@@@@@@@@@@@@@X/- + .-;+$$XXHHHHHX$$+;-. diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 9e475ecdc..edfb803df 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -574,6 +574,16 @@ static const FFlogo B[] = { .colorKeys = FF_COLOR_FG_LIGHT_RED, .colorTitle = FF_COLOR_FG_RED, }, + // BlackMesa + { + .names = {"BlackMesa", "black-mesa"}, + .lines = FASTFETCH_DATATEXT_LOGO_BLACKMESA, + .colors = { + FF_COLOR_FG_BLACK, + }, + .colorKeys = FF_COLOR_FG_BLACK, + .colorTitle = FF_COLOR_FG_WHITE, + }, // BlackPanther { .names = {"BlackPanther"}, From f61794ea7093ea50889a5d8d4a0f7b6568f2ca4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 18 Oct 2023 10:52:29 +0800 Subject: [PATCH 002/100] GPU (Windows): better GPU memory and type detection --- src/detection/gpu/gpu_windows.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 67211b76c..01d88e8c3 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -12,9 +12,11 @@ static int isGpuNameEqual(const FFGPUResult* gpu, const FFstrbuf* name) const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus) { DISPLAY_DEVICEW displayDevice = { .cb = sizeof(displayDevice) }; - wchar_t regKey[MAX_PATH] = L"SYSTEM\\CurrentControlSet\\Control\\Video\\{"; - const uint32_t regKeyPrefixLength = (uint32_t) wcslen(regKey); - const uint32_t deviceKeyPrefixLength = strlen("\\Registry\\Machine\\") + regKeyPrefixLength; + wchar_t regDirectxKey[MAX_PATH] = L"SOFTWARE\\Microsoft\\DirectX\\{"; + const uint32_t regDirectxKeyPrefixLength = (uint32_t) wcslen(regDirectxKey); + wchar_t regControlVideoKey[MAX_PATH] = L"SYSTEM\\CurrentControlSet\\Control\\Video\\{"; + const uint32_t regControlVideoKeyPrefixLength = (uint32_t) wcslen(regControlVideoKey); + const uint32_t deviceKeyPrefixLength = strlen("\\Registry\\Machine\\") + regControlVideoKeyPrefixLength; for (DWORD i = 0; EnumDisplayDevicesW(NULL, i, &displayDevice, 0); ++i) { @@ -43,9 +45,9 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* if (deviceKeyLength == 100 && displayDevice.DeviceKey[deviceKeyPrefixLength - 1] == '{') { - wmemcpy(regKey + regKeyPrefixLength, displayDevice.DeviceKey + deviceKeyPrefixLength, 100 - regKeyPrefixLength + 1); + wmemcpy(regControlVideoKey + regControlVideoKeyPrefixLength, displayDevice.DeviceKey + deviceKeyPrefixLength, strlen("00000000-0000-0000-0000-000000000000}\\0000")); FF_HKEY_AUTO_DESTROY hKey = NULL; - if (!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regKey, &hKey, NULL)) continue; + if (!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regControlVideoKey, &hKey, NULL)) continue; ffRegReadStrbuf(hKey, L"DriverVersion", &gpu->driver, NULL); ffRegReadStrbuf(hKey, L"ProviderName", &gpu->vendor, NULL); @@ -57,13 +59,29 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* else if(ffStrbufContainS(&gpu->vendor, "NVIDIA")) ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA); - if (!ffRegReadUint64(hKey, L"HardwareInformation.qwMemorySize", &gpu->dedicated.total, NULL)) + wmemcpy(regDirectxKey + regDirectxKeyPrefixLength, displayDevice.DeviceKey + deviceKeyPrefixLength, strlen("00000000-0000-0000-0000-000000000000}")); + FF_HKEY_AUTO_DESTROY hDirectxKey = NULL; + if (ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regDirectxKey, &hDirectxKey, NULL)) + { + uint64_t dedicatedVideoMemory = 0; + if(ffRegReadUint64(hDirectxKey, L"DedicatedVideoMemory", &dedicatedVideoMemory, NULL)) + gpu->type = dedicatedVideoMemory >= 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; + + uint64_t dedicatedSystemMemory, sharedSystemMemory; + if(ffRegReadUint64(hDirectxKey, L"DedicatedSystemMemory", &dedicatedSystemMemory, NULL) && + ffRegReadUint64(hDirectxKey, L"SharedSystemMemory", &sharedSystemMemory, NULL)) + { + gpu->dedicated.total = dedicatedVideoMemory + dedicatedSystemMemory; + gpu->shared.total = sharedSystemMemory; + } + } + else if (!ffRegReadUint64(hKey, L"HardwareInformation.qwMemorySize", &gpu->dedicated.total, NULL)) { uint32_t vmem = 0; if (ffRegReadUint(hKey, L"HardwareInformation.MemorySize", &vmem, NULL)) gpu->dedicated.total = vmem; + gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; } - gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; } } From debb5d8ad1a0ec227eb3347ecb54d5b19ed4fc98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 21 Oct 2023 12:10:12 +0800 Subject: [PATCH 003/100] Display: don't print display type twice --- src/modules/display/display.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/modules/display/display.c b/src/modules/display/display.c index c52bf42a6..02869ee41 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -49,9 +49,8 @@ void ffPrintDisplay(FFDisplayOptions* options) ffStrbufClear(&key); if(options->moduleArgs.key.length == 0) { - const char* subkey = result->name.length ? result->name.chars : displayType; - if (subkey) - ffStrbufAppendF(&key, "%s (%s)", FF_DISPLAY_MODULE_NAME, subkey); + if (result->name.length) + ffStrbufAppendF(&key, "%s (%s)", FF_DISPLAY_MODULE_NAME, result->name.chars); else if (moduleIndex > 0) ffStrbufAppendF(&key, "%s (%d)", FF_DISPLAY_MODULE_NAME, moduleIndex); else From e2fe94d4e494da7e7042e900e6c0e78e5634d8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 21 Oct 2023 15:44:38 +0800 Subject: [PATCH 004/100] DisplayServer (Android): tidy --- src/detection/displayserver/displayserver_android.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/displayserver/displayserver_android.c b/src/detection/displayserver/displayserver_android.c index d1e342503..f60c315f4 100644 --- a/src/detection/displayserver/displayserver_android.c +++ b/src/detection/displayserver/displayserver_android.c @@ -75,7 +75,7 @@ static bool detectWithGetprop(FFDisplayServerResult* ds) { // Only for MiUI FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); - ; + if (ffSettingsGetAndroidProperty("persist.sys.miui_resolution", &buffer) && ffStrbufContainC(&buffer, ',')) { From 3f4d4c8eea942fa7a61234bbd7e97d512a9dc5b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 21 Oct 2023 17:36:13 +0800 Subject: [PATCH 005/100] GPU: add more vendors --- src/detection/gpu/gpu.c | 9 +++++++++ src/detection/gpu/gpu.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/detection/gpu/gpu.c b/src/detection/gpu/gpu.c index 9300b2484..32fb5a3e9 100644 --- a/src/detection/gpu/gpu.c +++ b/src/detection/gpu/gpu.c @@ -6,6 +6,9 @@ const char* FF_GPU_VENDOR_NAME_APPLE = "Apple"; const char* FF_GPU_VENDOR_NAME_AMD = "AMD"; const char* FF_GPU_VENDOR_NAME_INTEL = "Intel"; const char* FF_GPU_VENDOR_NAME_NVIDIA = "NVIDIA"; +const char* FF_GPU_VENDOR_NAME_VMWARE = "VMware"; +const char* FF_GPU_VENDOR_NAME_PARALLEL = "Parallel"; +const char* FF_GPU_VENDOR_NAME_MICROSOFT = "Microsoft"; static inline bool arrayContains(const unsigned arr[], unsigned vendorId, unsigned length) { @@ -27,6 +30,12 @@ const char* ffGetGPUVendorString(unsigned vendorId) return FF_GPU_VENDOR_NAME_INTEL; else if(arrayContains((const unsigned[]) {0x0955, 0x10de, 0x12d2}, vendorId, 3)) return FF_GPU_VENDOR_NAME_NVIDIA; + else if(arrayContains((const unsigned[]) {0x15ad}, vendorId, 1)) + return FF_GPU_VENDOR_NAME_VMWARE; + else if(arrayContains((const unsigned[]) {0x1ab8}, vendorId, 1)) + return FF_GPU_VENDOR_NAME_PARALLEL; + else if(arrayContains((const unsigned[]) {0x1414}, vendorId, 1)) + return FF_GPU_VENDOR_NAME_MICROSOFT; return NULL; } diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index c0f5dfaa8..8398a826f 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -13,6 +13,9 @@ extern const char* FF_GPU_VENDOR_NAME_APPLE; extern const char* FF_GPU_VENDOR_NAME_AMD; extern const char* FF_GPU_VENDOR_NAME_INTEL; extern const char* FF_GPU_VENDOR_NAME_NVIDIA; +extern const char* FF_GPU_VENDOR_NAME_VMWARE; +extern const char* FF_GPU_VENDOR_NAME_PARALLEL; +extern const char* FF_GPU_VENDOR_NAME_MICROSOFT; typedef struct FFGPUMemory { From 40d6d0b7b5e3b6623fbfb54623f539b0a015503a Mon Sep 17 00:00:00 2001 From: matoro Date: Sun, 22 Oct 2023 23:09:43 -0400 Subject: [PATCH 006/100] CPU (Linux): quirks for MIPS platforms (#590) CPU name is in "cpu model" field on MIPS. Also, /proc/cpuinfo contains an "isa" field, but rather than being a single string like RISC-V it is instead a space-separated list of every ISA flavor that the chip is compatible with. Since these are mostly incremental, just make the cpuISA value set to the last one. Before: ``` $ fastfetch --structure "cpu" --logo none CPU: mips1 mips2 mips3 mips4 mips5 mips32r1 mips32r2 mips64r1 mips64r2 (16) ``` After: ``` $ fastfetch --structure "cpu" --logo none CPU: Cavium Octeon II V0.10 mips64r2 (16) ``` --- src/detection/cpu/cpu_linux.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/detection/cpu/cpu_linux.c b/src/detection/cpu/cpu_linux.c index 1241ef889..9acae0aa8 100644 --- a/src/detection/cpu/cpu_linux.c +++ b/src/detection/cpu/cpu_linux.c @@ -47,7 +47,8 @@ static const char* parseCpuInfo(FFCPUResult* cpu, FFstrbuf* physicalCoresBuffer, ffParsePropLine(line, "isa :", cpuIsa) || ffParsePropLine(line, "uarch :", cpuUarch) || (cpu->name.length == 0 && ffParsePropLine(line, "Hardware :", &cpu->name)) || //For Android devices - (cpu->name.length == 0 && ffParsePropLine(line, "cpu :", &cpu->name)) //For POWER + (cpu->name.length == 0 && ffParsePropLine(line, "cpu :", &cpu->name)) || //For POWER + (cpu->name.length == 0 && ffParsePropLine(line, "cpu model :", &cpu->name)) //For MIPS ); } @@ -115,6 +116,10 @@ static void parseIsa(FFstrbuf* cpuIsa) } // The final ISA output of the above example is "rv64gch". } + if(ffStrbufStartsWithS(cpuIsa, "mips")) + { + ffStrbufSubstrAfterLastC(cpuIsa, ' '); + } } const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu) From e7938216ba5d4855c80b0aa107e63c97d304b770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 23 Oct 2023 10:14:22 +0800 Subject: [PATCH 007/100] Global: `:%s/ffGenerate\w+Json/$0Result/g` --- src/modules/battery/battery.c | 4 ++-- src/modules/battery/battery.h | 2 +- src/modules/bios/bios.c | 4 ++-- src/modules/bios/bios.h | 2 +- src/modules/bluetooth/bluetooth.c | 4 ++-- src/modules/bluetooth/bluetooth.h | 2 +- src/modules/board/board.c | 4 ++-- src/modules/board/board.h | 2 +- src/modules/brightness/brightness.c | 4 ++-- src/modules/brightness/brightness.h | 2 +- src/modules/chassis/chassis.c | 4 ++-- src/modules/chassis/chassis.h | 2 +- src/modules/command/command.c | 4 ++-- src/modules/command/command.h | 2 +- src/modules/cpu/cpu.c | 4 ++-- src/modules/cpu/cpu.h | 2 +- src/modules/cpuusage/cpuusage.c | 4 ++-- src/modules/cpuusage/cpuusage.h | 2 +- src/modules/cursor/cursor.c | 4 ++-- src/modules/cursor/cursor.h | 2 +- src/modules/datetime/datetime.c | 4 ++-- src/modules/datetime/datetime.h | 2 +- src/modules/de/de.c | 4 ++-- src/modules/de/de.h | 2 +- src/modules/disk/disk.c | 4 ++-- src/modules/disk/disk.h | 2 +- src/modules/diskio/diskio.c | 4 ++-- src/modules/diskio/diskio.h | 2 +- src/modules/display/display.c | 4 ++-- src/modules/display/display.h | 2 +- src/modules/font/font.c | 4 ++-- src/modules/font/font.h | 2 +- src/modules/gamepad/gamepad.c | 4 ++-- src/modules/gamepad/gamepad.h | 2 +- src/modules/gpu/gpu.c | 4 ++-- src/modules/gpu/gpu.h | 2 +- src/modules/host/host.c | 4 ++-- src/modules/host/host.h | 2 +- src/modules/icons/icons.c | 4 ++-- src/modules/icons/icons.h | 2 +- src/modules/kernel/kernel.c | 4 ++-- src/modules/kernel/kernel.h | 2 +- src/modules/lm/lm.c | 4 ++-- src/modules/lm/lm.h | 2 +- src/modules/locale/locale.c | 4 ++-- src/modules/locale/locale.h | 2 +- src/modules/localip/localip.c | 4 ++-- src/modules/localip/localip.h | 2 +- src/modules/media/media.c | 4 ++-- src/modules/media/media.h | 2 +- src/modules/memory/memory.c | 4 ++-- src/modules/memory/memory.h | 2 +- src/modules/monitor/monitor.c | 4 ++-- src/modules/monitor/monitor.h | 2 +- src/modules/netio/netio.c | 4 ++-- src/modules/netio/netio.h | 2 +- src/modules/opencl/opencl.c | 4 ++-- src/modules/opencl/opencl.h | 2 +- src/modules/opengl/opengl.c | 4 ++-- src/modules/opengl/opengl.h | 2 +- src/modules/os/os.c | 4 ++-- src/modules/os/os.h | 2 +- src/modules/packages/packages.c | 4 ++-- src/modules/packages/packages.h | 2 +- src/modules/player/player.c | 4 ++-- src/modules/player/player.h | 2 +- src/modules/poweradapter/poweradapter.c | 4 ++-- src/modules/poweradapter/poweradapter.h | 2 +- src/modules/processes/processes.c | 4 ++-- src/modules/processes/processes.h | 2 +- src/modules/publicip/publicip.c | 4 ++-- src/modules/publicip/publicip.h | 2 +- src/modules/shell/shell.c | 4 ++-- src/modules/shell/shell.h | 2 +- src/modules/sound/sound.c | 4 ++-- src/modules/sound/sound.h | 2 +- src/modules/swap/swap.c | 4 ++-- src/modules/swap/swap.h | 2 +- src/modules/terminal/terminal.c | 4 ++-- src/modules/terminal/terminal.h | 2 +- src/modules/terminalfont/terminalfont.c | 4 ++-- src/modules/terminalfont/terminalfont.h | 2 +- src/modules/terminalsize/terminalsize.c | 4 ++-- src/modules/terminalsize/terminalsize.h | 2 +- src/modules/theme/theme.c | 4 ++-- src/modules/theme/theme.h | 2 +- src/modules/title/title.c | 4 ++-- src/modules/title/title.h | 2 +- src/modules/uptime/uptime.c | 4 ++-- src/modules/uptime/uptime.h | 2 +- src/modules/users/users.c | 4 ++-- src/modules/users/users.h | 2 +- src/modules/version/version.c | 4 ++-- src/modules/version/version.h | 2 +- src/modules/vulkan/vulkan.c | 4 ++-- src/modules/vulkan/vulkan.h | 2 +- src/modules/wallpaper/wallpaper.c | 4 ++-- src/modules/wallpaper/wallpaper.h | 2 +- src/modules/weather/weather.c | 4 ++-- src/modules/weather/weather.h | 2 +- src/modules/wifi/wifi.c | 4 ++-- src/modules/wifi/wifi.h | 2 +- src/modules/wm/wm.c | 4 ++-- src/modules/wm/wm.h | 2 +- src/modules/wmtheme/wmtheme.c | 4 ++-- src/modules/wmtheme/wmtheme.h | 2 +- 106 files changed, 159 insertions(+), 159 deletions(-) diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index 67ca2eed0..d3a42c4de 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -103,7 +103,7 @@ void ffPrintBattery(FFBatteryOptions* options) void ffInitBatteryOptions(FFBatteryOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BATTERY_MODULE_NAME, ffParseBatteryCommandOptions, ffParseBatteryJsonObject, ffPrintBattery, ffGenerateBatteryJson, ffPrintBatteryHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BATTERY_MODULE_NAME, ffParseBatteryCommandOptions, ffParseBatteryJsonObject, ffPrintBattery, ffGenerateBatteryJsonResult, ffPrintBatteryHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; @@ -176,7 +176,7 @@ void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module) } } -void ffGenerateBatteryJson(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBatteryResult)); diff --git a/src/modules/battery/battery.h b/src/modules/battery/battery.h index d50ad8bae..9cedbf56b 100644 --- a/src/modules/battery/battery.h +++ b/src/modules/battery/battery.h @@ -10,5 +10,5 @@ void ffInitBatteryOptions(FFBatteryOptions* options); bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, const char* value); void ffDestroyBatteryOptions(FFBatteryOptions* options); void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module); -void ffGenerateBatteryJson(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintBatteryHelpFormat(void); diff --git a/src/modules/bios/bios.c b/src/modules/bios/bios.c index 6658cfac6..f77fdaa89 100644 --- a/src/modules/bios/bios.c +++ b/src/modules/bios/bios.c @@ -55,7 +55,7 @@ exit: void ffInitBiosOptions(FFBiosOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BIOS_MODULE_NAME, ffParseBiosCommandOptions, ffParseBiosJsonObject, ffPrintBios, ffGenerateBiosJson, ffPrintBiosHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BIOS_MODULE_NAME, ffParseBiosCommandOptions, ffParseBiosJsonObject, ffPrintBios, ffGenerateBiosJsonResult, ffPrintBiosHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -91,7 +91,7 @@ void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module) } } -void ffGenerateBiosJson(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateBiosJsonResult(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFBiosResult bios; ffStrbufInit(&bios.date); diff --git a/src/modules/bios/bios.h b/src/modules/bios/bios.h index db7ab3704..cb11bac4f 100644 --- a/src/modules/bios/bios.h +++ b/src/modules/bios/bios.h @@ -9,5 +9,5 @@ void ffInitBiosOptions(FFBiosOptions* options); bool ffParseBiosCommandOptions(FFBiosOptions* options, const char* key, const char* value); void ffDestroyBiosOptions(FFBiosOptions* options); void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module); -void ffGenerateBiosJson(FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateBiosJsonResult(FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintBiosHelpFormat(void); diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index 6ddfb173c..53cc7acbf 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -75,7 +75,7 @@ void ffPrintBluetooth(FFBluetoothOptions* options) void ffInitBluetoothOptions(FFBluetoothOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BLUETOOTH_MODULE_NAME, ffParseBluetoothCommandOptions, ffParseBluetoothJsonObject, ffPrintBluetooth, ffGenerateBluetoothJson, ffPrintBluetoothHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BLUETOOTH_MODULE_NAME, ffParseBluetoothCommandOptions, ffParseBluetoothJsonObject, ffPrintBluetooth, ffGenerateBluetoothJsonResult, ffPrintBluetoothHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); options->showDisconnected = false; } @@ -124,7 +124,7 @@ void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module) } } -void ffGenerateBluetoothJson(FF_MAYBE_UNUSED FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateBluetoothJsonResult(FF_MAYBE_UNUSED FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBluetoothResult)); diff --git a/src/modules/bluetooth/bluetooth.h b/src/modules/bluetooth/bluetooth.h index dbccd1410..2156eedb9 100644 --- a/src/modules/bluetooth/bluetooth.h +++ b/src/modules/bluetooth/bluetooth.h @@ -9,5 +9,5 @@ void ffInitBluetoothOptions(FFBluetoothOptions* options); bool ffParseBluetoothCommandOptions(FFBluetoothOptions* options, const char* key, const char* value); void ffDestroyBluetoothOptions(FFBluetoothOptions* options); void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module); -void ffGenerateBluetoothJson(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintBluetoothHelpFormat(void); diff --git a/src/modules/board/board.c b/src/modules/board/board.c index 7dde50d89..34052cb42 100644 --- a/src/modules/board/board.c +++ b/src/modules/board/board.c @@ -51,7 +51,7 @@ exit: void ffInitBoardOptions(FFBoardOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BOARD_MODULE_NAME, ffParseBoardCommandOptions, ffParseBoardJsonObject, ffPrintBoard, ffGenerateBoardJson, ffPrintBoardHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BOARD_MODULE_NAME, ffParseBoardCommandOptions, ffParseBoardJsonObject, ffPrintBoard, ffGenerateBoardJsonResult, ffPrintBoardHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -87,7 +87,7 @@ void ffParseBoardJsonObject(FFBoardOptions* options, yyjson_val* module) } } -void ffGenerateBoardJson(FF_MAYBE_UNUSED FFBoardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateBoardJsonResult(FF_MAYBE_UNUSED FFBoardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFBoardResult board; ffStrbufInit(&board.name); diff --git a/src/modules/board/board.h b/src/modules/board/board.h index f1a8e46e8..6beaf3a6d 100644 --- a/src/modules/board/board.h +++ b/src/modules/board/board.h @@ -9,5 +9,5 @@ void ffInitBoardOptions(FFBoardOptions* options); bool ffParseBoardCommandOptions(FFBoardOptions* options, const char* key, const char* value); void ffDestroyBoardOptions(FFBoardOptions* options); void ffParseBoardJsonObject(FFBoardOptions* options, yyjson_val* module); -void ffGenerateBoardJson(FFBoardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateBoardJsonResult(FFBoardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintBoardHelpFormat(void); diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index eaedf10a9..e17c3d5e3 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -86,7 +86,7 @@ void ffPrintBrightness(FFBrightnessOptions* options) void ffInitBrightnessOptions(FFBrightnessOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BRIGHTNESS_MODULE_NAME, ffParseBrightnessCommandOptions, ffParseBrightnessJsonObject, ffPrintBrightness, ffGenerateBrightnessJson, ffPrintBrightnessHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BRIGHTNESS_MODULE_NAME, ffParseBrightnessCommandOptions, ffParseBrightnessJsonObject, ffPrintBrightness, ffGenerateBrightnessJsonResult, ffPrintBrightnessHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); options->ddcciSleep = 10; @@ -136,7 +136,7 @@ void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* modul } } -void ffGenerateBrightnessJson(FF_MAYBE_UNUSED FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFBrightnessResult)); diff --git a/src/modules/brightness/brightness.h b/src/modules/brightness/brightness.h index 453a4532c..1cda43f89 100644 --- a/src/modules/brightness/brightness.h +++ b/src/modules/brightness/brightness.h @@ -9,5 +9,5 @@ void ffInitBrightnessOptions(FFBrightnessOptions* options); bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* key, const char* value); void ffDestroyBrightnessOptions(FFBrightnessOptions* options); void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* module); -void ffGenerateBrightnessJson(FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateBrightnessJsonResult(FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintBrightnessHelpFormat(void); diff --git a/src/modules/chassis/chassis.c b/src/modules/chassis/chassis.c index fc915a200..d4e5a6078 100644 --- a/src/modules/chassis/chassis.c +++ b/src/modules/chassis/chassis.c @@ -52,7 +52,7 @@ exit: void ffInitChassisOptions(FFChassisOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CHASSIS_MODULE_NAME, ffParseChassisCommandOptions, ffParseChassisJsonObject, ffPrintChassis, ffGenerateChassisJson, ffPrintChassisHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CHASSIS_MODULE_NAME, ffParseChassisCommandOptions, ffParseChassisJsonObject, ffPrintChassis, ffGenerateChassisJsonResult, ffPrintChassisHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -88,7 +88,7 @@ void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module) } } -void ffGenerateChassisJson(FF_MAYBE_UNUSED FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFChassisResult result; ffStrbufInit(&result.type); diff --git a/src/modules/chassis/chassis.h b/src/modules/chassis/chassis.h index f0d810d16..290e101b0 100644 --- a/src/modules/chassis/chassis.h +++ b/src/modules/chassis/chassis.h @@ -9,5 +9,5 @@ void ffInitChassisOptions(FFChassisOptions* options); bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, const char* value); void ffDestroyChassisOptions(FFChassisOptions* options); void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module); -void ffGenerateChassisJson(FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateChassisJsonResult(FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintChassisHelpFormat(void); diff --git a/src/modules/command/command.c b/src/modules/command/command.c index 5273e74ca..397e99304 100644 --- a/src/modules/command/command.c +++ b/src/modules/command/command.c @@ -47,7 +47,7 @@ void ffPrintCommand(FFCommandOptions* options) void ffInitCommandOptions(FFCommandOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COMMAND_MODULE_NAME, ffParseCommandCommandOptions, ffParseCommandJsonObject, ffPrintCommand, ffGenerateCommandJson, ffPrintCommandHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COMMAND_MODULE_NAME, ffParseCommandCommandOptions, ffParseCommandJsonObject, ffPrintCommand, ffGenerateCommandJsonResult, ffPrintCommandHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInitStatic(&options->shell, @@ -119,7 +119,7 @@ void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module) } } -void ffGenerateCommandJson(FF_MAYBE_UNUSED FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateCommandJsonResult(FF_MAYBE_UNUSED FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); const char* error = ffProcessAppendStdOut(&result, (char* const[]){ diff --git a/src/modules/command/command.h b/src/modules/command/command.h index 932b1b8c3..a9fa22867 100644 --- a/src/modules/command/command.h +++ b/src/modules/command/command.h @@ -9,5 +9,5 @@ void ffInitCommandOptions(FFCommandOptions* options); bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, const char* value); void ffDestroyCommandOptions(FFCommandOptions* options); void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module); -void ffGenerateCommandJson(FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateCommandJsonResult(FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintCommandHelpFormat(void); diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index 133bebec9..702ff14e6 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -79,7 +79,7 @@ void ffPrintCPU(FFCPUOptions* options) void ffInitCPUOptions(FFCPUOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPU_MODULE_NAME, ffParseCPUCommandOptions, ffParseCPUJsonObject, ffPrintCPU, ffGenerateCPUJson, ffPrintCPUHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPU_MODULE_NAME, ffParseCPUCommandOptions, ffParseCPUJsonObject, ffPrintCPU, ffGenerateCPUJsonResult, ffPrintCPUHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; options->freqNdigits = 2; @@ -141,7 +141,7 @@ void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module) } } -void ffGenerateCPUJson(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFCPUResult cpu; cpu.temperature = FF_CPU_TEMP_UNSET; diff --git a/src/modules/cpu/cpu.h b/src/modules/cpu/cpu.h index dac736276..3daf94d65 100644 --- a/src/modules/cpu/cpu.h +++ b/src/modules/cpu/cpu.h @@ -9,5 +9,5 @@ void ffInitCPUOptions(FFCPUOptions* options); bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char* value); void ffDestroyCPUOptions(FFCPUOptions* options); void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module); -void ffGenerateCPUJson(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintCPUHelpFormat(void); diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index c5cd12345..9fa1e824c 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -87,7 +87,7 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) void ffInitCPUUsageOptions(FFCPUUsageOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPUUSAGE_MODULE_NAME, ffParseCPUUsageCommandOptions, ffParseCPUUsageJsonObject, ffPrintCPUUsage, ffGenerateCPUUsageJson, ffPrintCPUUsageHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPUUSAGE_MODULE_NAME, ffParseCPUUsageCommandOptions, ffParseCPUUsageJsonObject, ffPrintCPUUsage, ffGenerateCPUUsageJsonResult, ffPrintCPUUsageHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -135,7 +135,7 @@ void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module) } } -void ffGenerateCPUUsageJson(FF_MAYBE_UNUSED FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateCPUUsageJsonResult(FF_MAYBE_UNUSED FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY percentages = ffListCreate(sizeof(double)); const char* error = ffGetCpuUsageResult(&percentages); diff --git a/src/modules/cpuusage/cpuusage.h b/src/modules/cpuusage/cpuusage.h index 51af8bb22..52c567ee2 100644 --- a/src/modules/cpuusage/cpuusage.h +++ b/src/modules/cpuusage/cpuusage.h @@ -11,5 +11,5 @@ void ffInitCPUUsageOptions(FFCPUUsageOptions* options); bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key, const char* value); void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options); void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module); -void ffGenerateCPUUsageJson(FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateCPUUsageJsonResult(FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintCPUUsageHelpFormat(void); diff --git a/src/modules/cursor/cursor.c b/src/modules/cursor/cursor.c index 2de69177d..28fec9da8 100644 --- a/src/modules/cursor/cursor.c +++ b/src/modules/cursor/cursor.c @@ -52,7 +52,7 @@ void ffPrintCursor(FFCursorOptions* options) void ffInitCursorOptions(FFCursorOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CURSOR_MODULE_NAME, ffParseCursorCommandOptions, ffParseCursorJsonObject, ffPrintCursor, ffGenerateCursorJson, ffPrintCursorHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CURSOR_MODULE_NAME, ffParseCursorCommandOptions, ffParseCursorJsonObject, ffPrintCursor, ffGenerateCursorJsonResult, ffPrintCursorHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -88,7 +88,7 @@ void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module) } } -void ffGenerateCursorJson(FF_MAYBE_UNUSED FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateCursorJsonResult(FF_MAYBE_UNUSED FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFCursorResult result; ffStrbufInit(&result.error); diff --git a/src/modules/cursor/cursor.h b/src/modules/cursor/cursor.h index 44dff4909..36b712dfa 100644 --- a/src/modules/cursor/cursor.h +++ b/src/modules/cursor/cursor.h @@ -9,5 +9,5 @@ void ffInitCursorOptions(FFCursorOptions* options); bool ffParseCursorCommandOptions(FFCursorOptions* options, const char* key, const char* value); void ffDestroyCursorOptions(FFCursorOptions* options); void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module); -void ffGenerateCursorJson(FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateCursorJsonResult(FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintCursorHelpFormat(void); diff --git a/src/modules/datetime/datetime.c b/src/modules/datetime/datetime.c index 50cad80f9..ad0987c71 100644 --- a/src/modules/datetime/datetime.c +++ b/src/modules/datetime/datetime.c @@ -143,7 +143,7 @@ void ffPrintDateTime(FFDateTimeOptions* options) void ffInitDateTimeOptions(FFDateTimeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DATETIME_MODULE_NAME, ffParseDateTimeCommandOptions, ffParseDateTimeJsonObject, ffPrintDateTime, ffGenerateDateTimeJson, ffPrintDateTimeHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DATETIME_MODULE_NAME, ffParseDateTimeCommandOptions, ffParseDateTimeJsonObject, ffPrintDateTime, ffGenerateDateTimeJsonResult, ffPrintDateTimeHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -179,7 +179,7 @@ void ffParseDateTimeJsonObject(FFDateTimeOptions* options, yyjson_val* module) } } -void ffGenerateDateTimeJson(FF_MAYBE_UNUSED FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateDateTimeJsonResult(FF_MAYBE_UNUSED FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { yyjson_mut_obj_add_uint(doc, module, "result", ffTimeGetNow()); } diff --git a/src/modules/datetime/datetime.h b/src/modules/datetime/datetime.h index ef1f91dcb..6356fd408 100644 --- a/src/modules/datetime/datetime.h +++ b/src/modules/datetime/datetime.h @@ -9,5 +9,5 @@ void ffInitDateTimeOptions(FFDateTimeOptions* options); bool ffParseDateTimeCommandOptions(FFDateTimeOptions* options, const char* key, const char* value); void ffDestroyDateTimeOptions(FFDateTimeOptions* options); void ffParseDateTimeJsonObject(FFDateTimeOptions* options, yyjson_val* module); -void ffGenerateDateTimeJson(FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateDateTimeJsonResult(FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintDateTimeHelpFormat(void); diff --git a/src/modules/de/de.c b/src/modules/de/de.c index 0ea30ca01..a14204cce 100644 --- a/src/modules/de/de.c +++ b/src/modules/de/de.c @@ -42,7 +42,7 @@ void ffPrintDE(FFDEOptions* options) void ffInitDEOptions(FFDEOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DE_MODULE_NAME, ffParseDECommandOptions, ffParseDEJsonObject, ffPrintDE, ffGenerateDEJson, ffPrintDEHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DE_MODULE_NAME, ffParseDECommandOptions, ffParseDEJsonObject, ffPrintDE, ffGenerateDEJsonResult, ffPrintDEHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -78,7 +78,7 @@ void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module) } } -void ffGenerateDEJson(FF_MAYBE_UNUSED FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateDEJsonResult(FF_MAYBE_UNUSED FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFDisplayServerResult* result = ffConnectDisplayServer(); diff --git a/src/modules/de/de.h b/src/modules/de/de.h index 6b1ea4778..c33143319 100644 --- a/src/modules/de/de.h +++ b/src/modules/de/de.h @@ -9,5 +9,5 @@ void ffInitDEOptions(FFDEOptions* options); bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* value); void ffDestroyDEOptions(FFDEOptions* options); void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module); -void ffGenerateDEJson(FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateDEJsonResult(FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintDEHelpFormat(void); diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 1e789d433..874b26c2a 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -204,7 +204,7 @@ void ffPrintDisk(FFDiskOptions* options) void ffInitDiskOptions(FFDiskOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISK_MODULE_NAME, ffParseDiskCommandOptions, ffParseDiskJsonObject, ffPrintDisk, ffGenerateDiskJson, ffPrintDiskHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISK_MODULE_NAME, ffParseDiskCommandOptions, ffParseDiskJsonObject, ffPrintDisk, ffGenerateDiskJsonResult, ffPrintDiskHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->folders); @@ -373,7 +373,7 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module) } } -void ffGenerateDiskJson(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY disks = ffListCreate(sizeof (FFDisk)); const char* error = ffDetectDisks(options, &disks); diff --git a/src/modules/disk/disk.h b/src/modules/disk/disk.h index a3ee43e18..f28403b15 100644 --- a/src/modules/disk/disk.h +++ b/src/modules/disk/disk.h @@ -9,5 +9,5 @@ void ffInitDiskOptions(FFDiskOptions* options); bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const char* value); void ffDestroyDiskOptions(FFDiskOptions* options); void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module); -void ffGenerateDiskJson(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintDiskHelpFormat(void); diff --git a/src/modules/diskio/diskio.c b/src/modules/diskio/diskio.c index cb7c981dc..205b2abb6 100644 --- a/src/modules/diskio/diskio.c +++ b/src/modules/diskio/diskio.c @@ -114,7 +114,7 @@ void ffPrintDiskIO(FFDiskIOOptions* options) void ffInitDiskIOOptions(FFDiskIOOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISKIO_MODULE_NAME, ffParseDiskIOCommandOptions, ffParseDiskIOJsonObject, ffPrintDiskIO, ffGenerateDiskIOJson, ffPrintDiskIOHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISKIO_MODULE_NAME, ffParseDiskIOCommandOptions, ffParseDiskIOJsonObject, ffPrintDiskIO, ffGenerateDiskIOJsonResult, ffPrintDiskIOHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->namePrefix); @@ -165,7 +165,7 @@ void ffParseDiskIOJsonObject(FFDiskIOOptions* options, yyjson_val* module) } } -void ffGenerateDiskIOJson(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFDiskIOResult)); const char* error = ffDetectDiskIO(&result, options); diff --git a/src/modules/diskio/diskio.h b/src/modules/diskio/diskio.h index ab4502f11..5c048cbfd 100644 --- a/src/modules/diskio/diskio.h +++ b/src/modules/diskio/diskio.h @@ -11,5 +11,5 @@ void ffInitDiskIOOptions(FFDiskIOOptions* options); bool ffParseDiskIOCommandOptions(FFDiskIOOptions* options, const char* key, const char* value); void ffDestroyDiskIOOptions(FFDiskIOOptions* options); void ffParseDiskIOJsonObject(FFDiskIOOptions* options, yyjson_val* module); -void ffGenerateDiskIOJson(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintDiskIOHelpFormat(void); diff --git a/src/modules/display/display.c b/src/modules/display/display.c index 02869ee41..d7b870568 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -111,7 +111,7 @@ void ffPrintDisplay(FFDisplayOptions* options) void ffInitDisplayOptions(FFDisplayOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISPLAY_MODULE_NAME, ffParseDisplayCommandOptions, ffParseDisplayJsonObject, ffPrintDisplay, ffGenerateDisplayJson, ffPrintDisplayHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISPLAY_MODULE_NAME, ffParseDisplayCommandOptions, ffParseDisplayJsonObject, ffPrintDisplay, ffGenerateDisplayJsonResult, ffPrintDisplayHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); options->compactType = FF_DISPLAY_COMPACT_TYPE_NONE; options->preciseRefreshRate = false; @@ -188,7 +188,7 @@ void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module) } } -void ffGenerateDisplayJson(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFDisplayServerResult* dsResult = ffConnectDisplayServer(); diff --git a/src/modules/display/display.h b/src/modules/display/display.h index b01a97ef1..b592afd99 100644 --- a/src/modules/display/display.h +++ b/src/modules/display/display.h @@ -9,5 +9,5 @@ void ffInitDisplayOptions(FFDisplayOptions* options); bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, const char* value); void ffDestroyDisplayOptions(FFDisplayOptions* options); void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module); -void ffGenerateDisplayJson(FFDisplayOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateDisplayJsonResult(FFDisplayOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintDisplayHelpFormat(void); diff --git a/src/modules/font/font.c b/src/modules/font/font.c index c4ea4e62e..93becab47 100644 --- a/src/modules/font/font.c +++ b/src/modules/font/font.c @@ -45,7 +45,7 @@ void ffPrintFont(FFFontOptions* options) void ffInitFontOptions(FFFontOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_FONT_MODULE_NAME, ffParseFontCommandOptions, ffParseFontJsonObject, ffPrintFont, ffGenerateFontJson, ffPrintFontHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_FONT_MODULE_NAME, ffParseFontCommandOptions, ffParseFontJsonObject, ffPrintFont, ffGenerateFontJsonResult, ffPrintFontHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -81,7 +81,7 @@ void ffParseFontJsonObject(FFFontOptions* options, yyjson_val* module) } } -void ffGenerateFontJson(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateFontJsonResult(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFFontResult font; for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i) diff --git a/src/modules/font/font.h b/src/modules/font/font.h index 5d8631a9e..a4239578e 100644 --- a/src/modules/font/font.h +++ b/src/modules/font/font.h @@ -9,5 +9,5 @@ void ffInitFontOptions(FFFontOptions* options); bool ffParseFontCommandOptions(FFFontOptions* options, const char* key, const char* value); void ffDestroyFontOptions(FFFontOptions* options); void ffParseFontJsonObject(FFFontOptions* options, yyjson_val* module); -void ffGenerateFontJson(FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateFontJsonResult(FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintFontHelpFormat(void); diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index b0a5b5043..a6b8a60cd 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -51,7 +51,7 @@ void ffPrintGamepad(FFGamepadOptions* options) void ffInitGamepadOptions(FFGamepadOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GAMEPAD_MODULE_NAME, ffParseGamepadCommandOptions, ffParseGamepadJsonObject, ffPrintGamepad, ffGenerateGamepadJson, ffPrintGamepadHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GAMEPAD_MODULE_NAME, ffParseGamepadCommandOptions, ffParseGamepadJsonObject, ffPrintGamepad, ffGenerateGamepadJsonResult, ffPrintGamepadHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -87,7 +87,7 @@ void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module) } } -void ffGenerateGamepadJson(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFGamepadDevice)); diff --git a/src/modules/gamepad/gamepad.h b/src/modules/gamepad/gamepad.h index ff05a4dbc..cd37d9144 100644 --- a/src/modules/gamepad/gamepad.h +++ b/src/modules/gamepad/gamepad.h @@ -9,5 +9,5 @@ void ffInitGamepadOptions(FFGamepadOptions* options); bool ffParseGamepadCommandOptions(FFGamepadOptions* options, const char* key, const char* value); void ffDestroyGamepadOptions(FFGamepadOptions* options); void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module); -void ffGenerateGamepadJson(FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateGamepadJsonResult(FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintGamepadHelpFormat(void); diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index acc8ab0a7..84412b0a1 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -125,7 +125,7 @@ void ffPrintGPU(FFGPUOptions* options) void ffInitGPUOptions(FFGPUOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GPU_MODULE_NAME, ffParseGPUCommandOptions, ffParseGPUJsonObject, ffPrintGPU, ffGenerateGPUJson, ffPrintGPUHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GPU_MODULE_NAME, ffParseGPUCommandOptions, ffParseGPUJsonObject, ffPrintGPU, ffGenerateGPUJsonResult, ffPrintGPUHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); options->forceVulkan = false; @@ -215,7 +215,7 @@ void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module) } } -void ffGenerateGPUJson(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY gpus = ffListCreate(sizeof (FFGPUResult)); const char* error = ffDetectGPU(options, &gpus); diff --git a/src/modules/gpu/gpu.h b/src/modules/gpu/gpu.h index 0c1d73bb2..575e1bd67 100644 --- a/src/modules/gpu/gpu.h +++ b/src/modules/gpu/gpu.h @@ -9,5 +9,5 @@ void ffInitGPUOptions(FFGPUOptions* options); bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char* value); void ffDestroyGPUOptions(FFGPUOptions* options); void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module); -void ffGenerateGPUJson(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintGPUHelpFormat(void); diff --git a/src/modules/host/host.c b/src/modules/host/host.c index f65f30030..9705351de 100644 --- a/src/modules/host/host.c +++ b/src/modules/host/host.c @@ -67,7 +67,7 @@ exit: void ffInitHostOptions(FFHostOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_HOST_MODULE_NAME, ffParseHostCommandOptions, ffParseHostJsonObject, ffPrintHost, ffGenerateHostJson, ffPrintHostHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_HOST_MODULE_NAME, ffParseHostCommandOptions, ffParseHostJsonObject, ffPrintHost, ffGenerateHostJsonResult, ffPrintHostHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -103,7 +103,7 @@ void ffParseHostJsonObject(FFHostOptions* options, yyjson_val* module) } } -void ffGenerateHostJson(FF_MAYBE_UNUSED FFHostOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateHostJsonResult(FF_MAYBE_UNUSED FFHostOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFHostResult host; ffStrbufInit(&host.productFamily); diff --git a/src/modules/host/host.h b/src/modules/host/host.h index c07789382..3e0aa150e 100644 --- a/src/modules/host/host.h +++ b/src/modules/host/host.h @@ -9,5 +9,5 @@ void ffInitHostOptions(FFHostOptions* options); bool ffParseHostCommandOptions(FFHostOptions* options, const char* key, const char* value); void ffDestroyHostOptions(FFHostOptions* options); void ffParseHostJsonObject(FFHostOptions* options, yyjson_val* module); -void ffGenerateHostJson(FFHostOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateHostJsonResult(FFHostOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintHostHelpFormat(void); diff --git a/src/modules/icons/icons.c b/src/modules/icons/icons.c index 0b16ec141..646df67ea 100644 --- a/src/modules/icons/icons.c +++ b/src/modules/icons/icons.c @@ -32,7 +32,7 @@ void ffPrintIcons(FFIconsOptions* options) void ffInitIconsOptions(FFIconsOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_ICONS_MODULE_NAME, ffParseIconsCommandOptions, ffParseIconsJsonObject, ffPrintIcons, ffGenerateIconsJson, ffPrintIconsHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_ICONS_MODULE_NAME, ffParseIconsCommandOptions, ffParseIconsJsonObject, ffPrintIcons, ffGenerateIconsJsonResult, ffPrintIconsHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -68,7 +68,7 @@ void ffParseIconsJsonObject(FFIconsOptions* options, yyjson_val* module) } } -void ffGenerateIconsJson(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateIconsJsonResult(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY icons = ffStrbufCreate(); const char* error = ffDetectIcons(&icons); diff --git a/src/modules/icons/icons.h b/src/modules/icons/icons.h index f44c0db2d..5c390c577 100644 --- a/src/modules/icons/icons.h +++ b/src/modules/icons/icons.h @@ -9,5 +9,5 @@ void ffInitIconsOptions(FFIconsOptions* options); bool ffParseIconsCommandOptions(FFIconsOptions* options, const char* key, const char* value); void ffDestroyIconsOptions(FFIconsOptions* options); void ffParseIconsJsonObject(FFIconsOptions* options, yyjson_val* module); -void ffGenerateIconsJson(FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateIconsJsonResult(FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintIconsHelpFormat(void); diff --git a/src/modules/kernel/kernel.c b/src/modules/kernel/kernel.c index 56c81b118..bd6acaa37 100644 --- a/src/modules/kernel/kernel.c +++ b/src/modules/kernel/kernel.c @@ -32,7 +32,7 @@ void ffPrintKernel(FFKernelOptions* options) void ffInitKernelOptions(FFKernelOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_KERNEL_MODULE_NAME, ffParseKernelCommandOptions, ffParseKernelJsonObject, ffPrintKernel, ffGenerateKernelJson, ffPrintKernelHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_KERNEL_MODULE_NAME, ffParseKernelCommandOptions, ffParseKernelJsonObject, ffPrintKernel, ffGenerateKernelJsonResult, ffPrintKernelHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -68,7 +68,7 @@ void ffParseKernelJsonObject(FFKernelOptions* options, yyjson_val* module) } } -void ffGenerateKernelJson(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateKernelJsonResult(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, obj, "architecture", &instance.state.platform.systemArchitecture); diff --git a/src/modules/kernel/kernel.h b/src/modules/kernel/kernel.h index 6adbe89ab..523c8caa7 100644 --- a/src/modules/kernel/kernel.h +++ b/src/modules/kernel/kernel.h @@ -9,5 +9,5 @@ void ffInitKernelOptions(FFKernelOptions* options); bool ffParseKernelCommandOptions(FFKernelOptions* options, const char* key, const char* value); void ffDestroyKernelOptions(FFKernelOptions* options); void ffParseKernelJsonObject(FFKernelOptions* options, yyjson_val* module); -void ffGenerateKernelJson(FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateKernelJsonResult(FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintKernelHelpFormat(void); diff --git a/src/modules/lm/lm.c b/src/modules/lm/lm.c index e64a0e8a2..e44279cb4 100644 --- a/src/modules/lm/lm.c +++ b/src/modules/lm/lm.c @@ -51,7 +51,7 @@ void ffPrintLM(FFLMOptions* options) void ffInitLMOptions(FFLMOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LM_MODULE_NAME, ffParseLMCommandOptions, ffParseLMJsonObject, ffPrintLM, ffGenerateLMJson, ffPrintLMHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LM_MODULE_NAME, ffParseLMCommandOptions, ffParseLMJsonObject, ffPrintLM, ffGenerateLMJsonResult, ffPrintLMHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -87,7 +87,7 @@ void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module) } } -void ffGenerateLMJson(FF_MAYBE_UNUSED FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateLMJsonResult(FF_MAYBE_UNUSED FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFLMResult result; ffStrbufInit(&result.service); diff --git a/src/modules/lm/lm.h b/src/modules/lm/lm.h index 4178e1c9f..b234acad8 100644 --- a/src/modules/lm/lm.h +++ b/src/modules/lm/lm.h @@ -9,5 +9,5 @@ void ffInitLMOptions(FFLMOptions* options); bool ffParseLMCommandOptions(FFLMOptions* options, const char* key, const char* value); void ffDestroyLMOptions(FFLMOptions* options); void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module); -void ffGenerateLMJson(FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateLMJsonResult(FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintLMHelpFormat(void); diff --git a/src/modules/locale/locale.c b/src/modules/locale/locale.c index 674e5f6f3..31b03ef0a 100644 --- a/src/modules/locale/locale.c +++ b/src/modules/locale/locale.c @@ -32,7 +32,7 @@ void ffPrintLocale(FFLocaleOptions* options) void ffInitLocaleOptions(FFLocaleOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALE_MODULE_NAME, ffParseLocaleCommandOptions, ffParseLocaleJsonObject, ffPrintLocale, ffGenerateLocaleJson, ffPrintLocaleHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALE_MODULE_NAME, ffParseLocaleCommandOptions, ffParseLocaleJsonObject, ffPrintLocale, ffGenerateLocaleJsonResult, ffPrintLocaleHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -68,7 +68,7 @@ void ffParseLocaleJsonObject(FFLocaleOptions* options, yyjson_val* module) } } -void ffGenerateLocaleJson(FF_MAYBE_UNUSED FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateLocaleJsonResult(FF_MAYBE_UNUSED FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY locale = ffStrbufCreate(); diff --git a/src/modules/locale/locale.h b/src/modules/locale/locale.h index f0031e2bf..451995b82 100644 --- a/src/modules/locale/locale.h +++ b/src/modules/locale/locale.h @@ -9,5 +9,5 @@ void ffInitLocaleOptions(FFLocaleOptions* options); bool ffParseLocaleCommandOptions(FFLocaleOptions* options, const char* key, const char* value); void ffDestroyLocaleOptions(FFLocaleOptions* options); void ffParseLocaleJsonObject(FFLocaleOptions* options, yyjson_val* module); -void ffGenerateLocaleJson(FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateLocaleJsonResult(FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintLocaleHelpFormat(void); diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index 86b8e3a85..fc70f8479 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -133,7 +133,7 @@ void ffPrintLocalIp(FFLocalIpOptions* options) void ffInitLocalIpOptions(FFLocalIpOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALIP_MODULE_NAME, ffParseLocalIpCommandOptions, ffParseLocalIpJsonObject, ffPrintLocalIp, ffGenerateLocalIpJson, ffPrintLocalIpHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALIP_MODULE_NAME, ffParseLocalIpCommandOptions, ffParseLocalIpJsonObject, ffPrintLocalIp, ffGenerateLocalIpJsonResult, ffPrintLocalIpHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); options->showType = FF_LOCALIP_TYPE_IPV4_BIT; @@ -288,7 +288,7 @@ void ffParseLocalIpJsonObject(FFLocalIpOptions* options, yyjson_val* module) } } -void ffGenerateLocalIpJson(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFLocalIpResult)); diff --git a/src/modules/localip/localip.h b/src/modules/localip/localip.h index b78f7df6b..ee07ebdb1 100644 --- a/src/modules/localip/localip.h +++ b/src/modules/localip/localip.h @@ -9,5 +9,5 @@ void ffInitLocalIpOptions(FFLocalIpOptions* options); bool ffParseLocalIpCommandOptions(FFLocalIpOptions* options, const char* key, const char* value); void ffDestroyLocalIpOptions(FFLocalIpOptions* options); void ffParseLocalIpJsonObject(FFLocalIpOptions* options, yyjson_val* module); -void ffGenerateLocalIpJson(FFLocalIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateLocalIpJsonResult(FFLocalIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintLocalIpHelpFormat(void); diff --git a/src/modules/media/media.c b/src/modules/media/media.c index 61a3814a2..472404e4d 100644 --- a/src/modules/media/media.c +++ b/src/modules/media/media.c @@ -107,7 +107,7 @@ void ffPrintMedia(FFMediaOptions* options) void ffInitMediaOptions(FFMediaOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEDIA_MODULE_NAME, ffParseMediaCommandOptions, ffParseMediaJsonObject, ffPrintMedia, ffGenerateMediaJson, ffPrintMediaHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEDIA_MODULE_NAME, ffParseMediaCommandOptions, ffParseMediaJsonObject, ffPrintMedia, ffGenerateMediaJsonResult, ffPrintMediaHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -143,7 +143,7 @@ void ffParseMediaJsonObject(FFMediaOptions* options, yyjson_val* module) } } -void ffGenerateMediaJson(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateMediaJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFMediaResult* media = ffDetectMedia(); diff --git a/src/modules/media/media.h b/src/modules/media/media.h index e9966c180..c0e581bdb 100644 --- a/src/modules/media/media.h +++ b/src/modules/media/media.h @@ -9,5 +9,5 @@ void ffInitMediaOptions(FFMediaOptions* options); bool ffParseMediaCommandOptions(FFMediaOptions* options, const char* key, const char* value); void ffDestroyMediaOptions(FFMediaOptions* options); void ffParseMediaJsonObject(FFMediaOptions* options, yyjson_val* module); -void ffGenerateMediaJson(FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateMediaJsonResult(FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintMediaHelpFormat(void); diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index faea2c7bd..44156a52e 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -68,7 +68,7 @@ void ffPrintMemory(FFMemoryOptions* options) void ffInitMemoryOptions(FFMemoryOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEMORY_MODULE_NAME, ffParseMemoryCommandOptions, ffParseMemoryJsonObject, ffPrintMemory, ffGenerateMemoryJson, ffPrintMemoryHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEMORY_MODULE_NAME, ffParseMemoryCommandOptions, ffParseMemoryJsonObject, ffPrintMemory, ffGenerateMemoryJsonResult, ffPrintMemoryHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -104,7 +104,7 @@ void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module) } } -void ffGenerateMemoryJson(FF_MAYBE_UNUSED FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateMemoryJsonResult(FF_MAYBE_UNUSED FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFMemoryResult storage; const char* error = ffDetectMemory(&storage); diff --git a/src/modules/memory/memory.h b/src/modules/memory/memory.h index 9d86997ef..ffdeb45fa 100644 --- a/src/modules/memory/memory.h +++ b/src/modules/memory/memory.h @@ -9,5 +9,5 @@ void ffInitMemoryOptions(FFMemoryOptions* options); bool ffParseMemoryCommandOptions(FFMemoryOptions* options, const char* key, const char* value); void ffDestroyMemoryOptions(FFMemoryOptions* options); void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module); -void ffGenerateMemoryJson(FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateMemoryJsonResult(FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintMemoryHelpFormat(void); diff --git a/src/modules/monitor/monitor.c b/src/modules/monitor/monitor.c index 271ccc67b..732a4ef4e 100644 --- a/src/modules/monitor/monitor.c +++ b/src/modules/monitor/monitor.c @@ -77,7 +77,7 @@ void ffPrintMonitor(FFMonitorOptions* options) void ffInitMonitorOptions(FFMonitorOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MONITOR_MODULE_NAME, ffParseMonitorCommandOptions, ffParseMonitorJsonObject, ffPrintMonitor, ffGenerateMonitorJson, ffPrintMonitorHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MONITOR_MODULE_NAME, ffParseMonitorCommandOptions, ffParseMonitorJsonObject, ffPrintMonitor, ffGenerateMonitorJsonResult, ffPrintMonitorHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -113,7 +113,7 @@ void ffParseMonitorJsonObject(FFMonitorOptions* options, yyjson_val* module) } } -void ffGenerateMonitorJson(FF_MAYBE_UNUSED FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateMonitorJsonResult(FF_MAYBE_UNUSED FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFMonitorResult)); diff --git a/src/modules/monitor/monitor.h b/src/modules/monitor/monitor.h index 53eccd5b4..3d860df02 100644 --- a/src/modules/monitor/monitor.h +++ b/src/modules/monitor/monitor.h @@ -9,5 +9,5 @@ void ffInitMonitorOptions(FFMonitorOptions* options); bool ffParseMonitorCommandOptions(FFMonitorOptions* options, const char* key, const char* value); void ffDestroyMonitorOptions(FFMonitorOptions* options); void ffParseMonitorJsonObject(FFMonitorOptions* options, yyjson_val* module); -void ffGenerateMonitorJson(FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateMonitorJsonResult(FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintMonitorHelpFormat(void); diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index 3f6410257..490ad93d1 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -101,7 +101,7 @@ void ffPrintNetIO(FFNetIOOptions* options) void ffInitNetIOOptions(FFNetIOOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_NETIO_MODULE_NAME, ffParseNetIOCommandOptions, ffParseNetIOJsonObject, ffPrintNetIO, ffGenerateNetIOJson, ffPrintNetIOHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_NETIO_MODULE_NAME, ffParseNetIOCommandOptions, ffParseNetIOJsonObject, ffPrintNetIO, ffGenerateNetIOJsonResult, ffPrintNetIOHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->namePrefix); @@ -165,7 +165,7 @@ void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module) } } -void ffGenerateNetIOJson(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetIOResult)); const char* error = ffDetectNetIO(&result, options); diff --git a/src/modules/netio/netio.h b/src/modules/netio/netio.h index b8a19169c..aead4d6e0 100644 --- a/src/modules/netio/netio.h +++ b/src/modules/netio/netio.h @@ -11,5 +11,5 @@ void ffInitNetIOOptions(FFNetIOOptions* options); bool ffParseNetIOCommandOptions(FFNetIOOptions* options, const char* key, const char* value); void ffDestroyNetIOOptions(FFNetIOOptions* options); void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module); -void ffGenerateNetIOJson(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintNetIOHelpFormat(void); diff --git a/src/modules/opencl/opencl.c b/src/modules/opencl/opencl.c index 600dc8c7d..b4a2e9a73 100644 --- a/src/modules/opencl/opencl.c +++ b/src/modules/opencl/opencl.c @@ -41,7 +41,7 @@ void ffPrintOpenCL(FFOpenCLOptions* options) void ffInitOpenCLOptions(FFOpenCLOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENCL_MODULE_NAME, ffParseOpenCLCommandOptions, ffParseOpenCLJsonObject, ffPrintOpenCL, ffGenerateOpenCLJson, ffPrintOpenCLHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENCL_MODULE_NAME, ffParseOpenCLCommandOptions, ffParseOpenCLJsonObject, ffPrintOpenCL, ffGenerateOpenCLJsonResult, ffPrintOpenCLHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -77,7 +77,7 @@ void ffParseOpenCLJsonObject(FFOpenCLOptions* options, yyjson_val* module) } } -void ffGenerateOpenCLJson(FF_MAYBE_UNUSED FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateOpenCLJsonResult(FF_MAYBE_UNUSED FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFOpenCLResult opencl; ffStrbufInit(&opencl.version); diff --git a/src/modules/opencl/opencl.h b/src/modules/opencl/opencl.h index 35c480946..5a9bc3573 100644 --- a/src/modules/opencl/opencl.h +++ b/src/modules/opencl/opencl.h @@ -9,5 +9,5 @@ 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); +void ffGenerateOpenCLJsonResult(FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintOpenCLHelpFormat(void); diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index 6a98eb8b7..9c6f949c8 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -44,7 +44,7 @@ void ffPrintOpenGL(FFOpenGLOptions* options) void ffInitOpenGLOptions(FFOpenGLOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENGL_MODULE_NAME, ffParseOpenGLCommandOptions, ffParseOpenGLJsonObject, ffPrintOpenGL, ffGenerateOpenGLJson, ffPrintOpenGLHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENGL_MODULE_NAME, ffParseOpenGLCommandOptions, ffParseOpenGLJsonObject, ffPrintOpenGL, ffGenerateOpenGLJsonResult, ffPrintOpenGLHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); #if defined(__linux__) || defined(__FreeBSD__) @@ -116,7 +116,7 @@ void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module) } } -void ffGenerateOpenGLJson(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFOpenGLResult result; ffStrbufInit(&result.version); diff --git a/src/modules/opengl/opengl.h b/src/modules/opengl/opengl.h index d4f84a895..e94b5b7fb 100644 --- a/src/modules/opengl/opengl.h +++ b/src/modules/opengl/opengl.h @@ -9,5 +9,5 @@ void ffInitOpenGLOptions(FFOpenGLOptions* options); bool ffParseOpenGLCommandOptions(FFOpenGLOptions* options, const char* key, const char* value); void ffDestroyOpenGLOptions(FFOpenGLOptions* options); void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module); -void ffGenerateOpenGLJson(FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateOpenGLJsonResult(FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintOpenGLHelpFormat(void); diff --git a/src/modules/os/os.c b/src/modules/os/os.c index 299e871b3..d969805f6 100644 --- a/src/modules/os/os.c +++ b/src/modules/os/os.c @@ -138,7 +138,7 @@ void ffPrintOS(FFOSOptions* options) void ffInitOSOptions(FFOSOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OS_MODULE_NAME, ffParseOSCommandOptions, ffParseOSJsonObject, ffPrintOS, ffGenerateOSJson, ffPrintOSHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OS_MODULE_NAME, ffParseOSCommandOptions, ffParseOSJsonObject, ffPrintOS, ffGenerateOSJsonResult, ffPrintOSHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -174,7 +174,7 @@ void ffParseOSJsonObject(FFOSOptions* options, yyjson_val* module) } } -void ffGenerateOSJson(FF_MAYBE_UNUSED FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateOSJsonResult(FF_MAYBE_UNUSED FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFOSResult* os = ffDetectOS(); diff --git a/src/modules/os/os.h b/src/modules/os/os.h index 8b16baf4e..db357d70c 100644 --- a/src/modules/os/os.h +++ b/src/modules/os/os.h @@ -9,5 +9,5 @@ void ffInitOSOptions(FFOSOptions* options); bool ffParseOSCommandOptions(FFOSOptions* options, const char* key, const char* value); void ffDestroyOSOptions(FFOSOptions* options); void ffParseOSJsonObject(FFOSOptions* options, yyjson_val* module); -void ffGenerateOSJson(FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateOSJsonResult(FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintOSHelpFormat(void); diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index 253484926..42fdd724f 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -104,7 +104,7 @@ void ffPrintPackages(FFPackagesOptions* options) void ffInitPackagesOptions(FFPackagesOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PACKAGES_MODULE_NAME, ffParsePackagesCommandOptions, ffParsePackagesJsonObject, ffPrintPackages, ffGeneratePackagesJson, ffPrintPackagesHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PACKAGES_MODULE_NAME, ffParsePackagesCommandOptions, ffParsePackagesJsonObject, ffPrintPackages, ffGeneratePackagesJsonResult, ffPrintPackagesHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -140,7 +140,7 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) } } -void ffGeneratePackagesJson(FF_MAYBE_UNUSED FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFPackagesResult counts = {}; ffStrbufInit(&counts.pacmanBranch); diff --git a/src/modules/packages/packages.h b/src/modules/packages/packages.h index 39114a098..426e7fe47 100644 --- a/src/modules/packages/packages.h +++ b/src/modules/packages/packages.h @@ -9,5 +9,5 @@ void ffInitPackagesOptions(FFPackagesOptions* options); bool ffParsePackagesCommandOptions(FFPackagesOptions* options, const char* key, const char* value); void ffDestroyPackagesOptions(FFPackagesOptions* options); void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module); -void ffGeneratePackagesJson(FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGeneratePackagesJsonResult(FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintPackagesHelpFormat(void); diff --git a/src/modules/player/player.c b/src/modules/player/player.c index caba0d847..77898b364 100644 --- a/src/modules/player/player.c +++ b/src/modules/player/player.c @@ -75,7 +75,7 @@ void ffPrintPlayer(FFPlayerOptions* options) void ffInitPlayerOptions(FFPlayerOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PLAYER_MODULE_NAME, ffParsePlayerCommandOptions, ffParsePlayerJsonObject, ffPrintPlayer, ffGeneratePlayerJson, ffPrintPlayerHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PLAYER_MODULE_NAME, ffParsePlayerCommandOptions, ffParsePlayerJsonObject, ffPrintPlayer, ffGeneratePlayerJsonResult, ffPrintPlayerHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -111,7 +111,7 @@ void ffParsePlayerJsonObject(FFPlayerOptions* options, yyjson_val* module) } } -void ffGeneratePlayerJson(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGeneratePlayerJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFMediaResult* media = ffDetectMedia(); diff --git a/src/modules/player/player.h b/src/modules/player/player.h index 11a4fed8e..d2e4ea140 100644 --- a/src/modules/player/player.h +++ b/src/modules/player/player.h @@ -10,5 +10,5 @@ void ffInitPlayerOptions(FFPlayerOptions* options); bool ffParsePlayerCommandOptions(FFPlayerOptions* options, const char* key, const char* value); void ffDestroyPlayerOptions(FFPlayerOptions* options); void ffParsePlayerJsonObject(FFPlayerOptions* options, yyjson_val* module); -void ffGeneratePlayerJson(FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGeneratePlayerJsonResult(FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintPlayerHelpFormat(void); diff --git a/src/modules/poweradapter/poweradapter.c b/src/modules/poweradapter/poweradapter.c index fef71928a..2cd639c42 100644 --- a/src/modules/poweradapter/poweradapter.c +++ b/src/modules/poweradapter/poweradapter.c @@ -62,7 +62,7 @@ void ffPrintPowerAdapter(FFPowerAdapterOptions* options) void ffInitPowerAdapterOptions(FFPowerAdapterOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_POWERADAPTER_MODULE_NAME, ffParsePowerAdapterCommandOptions, ffParsePowerAdapterJsonObject, ffPrintPowerAdapter, ffGeneratePowerAdapterJson, ffPrintPowerAdapterHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_POWERADAPTER_MODULE_NAME, ffParsePowerAdapterCommandOptions, ffParsePowerAdapterJsonObject, ffPrintPowerAdapter, ffGeneratePowerAdapterJsonResult, ffPrintPowerAdapterHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -98,7 +98,7 @@ void ffParsePowerAdapterJsonObject(FFPowerAdapterOptions* options, yyjson_val* m } } -void ffGeneratePowerAdapterJson(FF_MAYBE_UNUSED FFPowerAdapterOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGeneratePowerAdapterJsonResult(FF_MAYBE_UNUSED FFPowerAdapterOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFPowerAdapterResult)); diff --git a/src/modules/poweradapter/poweradapter.h b/src/modules/poweradapter/poweradapter.h index 792409ff2..58b18e601 100644 --- a/src/modules/poweradapter/poweradapter.h +++ b/src/modules/poweradapter/poweradapter.h @@ -9,5 +9,5 @@ void ffInitPowerAdapterOptions(FFPowerAdapterOptions* options); bool ffParsePowerAdapterCommandOptions(FFPowerAdapterOptions* options, const char* key, const char* value); void ffDestroyPowerAdapterOptions(FFPowerAdapterOptions* options); void ffParsePowerAdapterJsonObject(FFPowerAdapterOptions* options, yyjson_val* module); -void ffGeneratePowerAdapterJson(FFPowerAdapterOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGeneratePowerAdapterJsonResult(FFPowerAdapterOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintPowerAdapterHelpFormat(void); diff --git a/src/modules/processes/processes.c b/src/modules/processes/processes.c index ce0497172..e6bda6004 100644 --- a/src/modules/processes/processes.c +++ b/src/modules/processes/processes.c @@ -33,7 +33,7 @@ void ffPrintProcesses(FFProcessesOptions* options) void ffInitProcessesOptions(FFProcessesOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PROCESSES_MODULE_NAME, ffParseProcessesCommandOptions, ffParseProcessesJsonObject, ffPrintProcesses, ffGenerateProcessesJson, ffPrintProcessesHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PROCESSES_MODULE_NAME, ffParseProcessesCommandOptions, ffParseProcessesJsonObject, ffPrintProcesses, ffGenerateProcessesJsonResult, ffPrintProcessesHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -69,7 +69,7 @@ void ffParseProcessesJsonObject(FFProcessesOptions* options, yyjson_val* module) } } -void ffGenerateProcessesJson(FF_MAYBE_UNUSED FFProcessesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateProcessesJsonResult(FF_MAYBE_UNUSED FFProcessesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { uint32_t result; const char* error = ffDetectProcesses(&result); diff --git a/src/modules/processes/processes.h b/src/modules/processes/processes.h index b2d9ac6be..74ae83e45 100644 --- a/src/modules/processes/processes.h +++ b/src/modules/processes/processes.h @@ -9,5 +9,5 @@ void ffInitProcessesOptions(FFProcessesOptions* options); bool ffParseProcessesCommandOptions(FFProcessesOptions* options, const char* key, const char* value); void ffDestroyProcessesOptions(FFProcessesOptions* options); void ffParseProcessesJsonObject(FFProcessesOptions* options, yyjson_val* module); -void ffGenerateProcessesJson(FFProcessesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateProcessesJsonResult(FFProcessesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintProcessesHelpFormat(void); diff --git a/src/modules/publicip/publicip.c b/src/modules/publicip/publicip.c index a6ae2c9eb..a815a9935 100644 --- a/src/modules/publicip/publicip.c +++ b/src/modules/publicip/publicip.c @@ -42,7 +42,7 @@ void ffPrintPublicIp(FFPublicIpOptions* options) void ffInitPublicIpOptions(FFPublicIpOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PUBLICIP_MODULE_NAME, ffParsePublicIpCommandOptions, ffParsePublicIpJsonObject, ffPrintPublicIp, ffGeneratePublicIpJson, ffPrintPublicIpHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PUBLICIP_MODULE_NAME, ffParsePublicIpCommandOptions, ffParsePublicIpJsonObject, ffPrintPublicIp, ffGeneratePublicIpJsonResult, ffPrintPublicIpHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->url); @@ -107,7 +107,7 @@ void ffParsePublicIpJsonObject(FFPublicIpOptions* options, yyjson_val* module) } } -void ffGeneratePublicIpJson(FFPublicIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGeneratePublicIpJsonResult(FFPublicIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFPublicIpResult result; ffStrbufInit(&result.ip); diff --git a/src/modules/publicip/publicip.h b/src/modules/publicip/publicip.h index 69f8752e4..0b8792382 100644 --- a/src/modules/publicip/publicip.h +++ b/src/modules/publicip/publicip.h @@ -11,5 +11,5 @@ void ffInitPublicIpOptions(FFPublicIpOptions* options); bool ffParsePublicIpCommandOptions(FFPublicIpOptions* options, const char* key, const char* value); void ffDestroyPublicIpOptions(FFPublicIpOptions* options); void ffParsePublicIpJsonObject(FFPublicIpOptions* options, yyjson_val* module); -void ffGeneratePublicIpJson(FFPublicIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGeneratePublicIpJsonResult(FFPublicIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintPublicIpHelpFormat(void); diff --git a/src/modules/shell/shell.c b/src/modules/shell/shell.c index 64c074b63..3e63e4523 100644 --- a/src/modules/shell/shell.c +++ b/src/modules/shell/shell.c @@ -44,7 +44,7 @@ void ffPrintShell(FFShellOptions* options) void ffInitShellOptions(FFShellOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SHELL_MODULE_NAME, ffParseShellCommandOptions, ffParseShellJsonObject, ffPrintShell, ffGenerateShellJson, ffPrintShellHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SHELL_MODULE_NAME, ffParseShellCommandOptions, ffParseShellJsonObject, ffPrintShell, ffGenerateShellJsonResult, ffPrintShellHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -80,7 +80,7 @@ void ffParseShellJsonObject(FFShellOptions* options, yyjson_val* module) } } -void ffGenerateShellJson(FF_MAYBE_UNUSED FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateShellJsonResult(FF_MAYBE_UNUSED FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFTerminalShellResult* result = ffDetectTerminalShell(); diff --git a/src/modules/shell/shell.h b/src/modules/shell/shell.h index 961a94cb7..dac01eb7c 100644 --- a/src/modules/shell/shell.h +++ b/src/modules/shell/shell.h @@ -9,5 +9,5 @@ void ffInitShellOptions(FFShellOptions* options); bool ffParseShellCommandOptions(FFShellOptions* options, const char* key, const char* value); void ffDestroyShellOptions(FFShellOptions* options); void ffParseShellJsonObject(FFShellOptions* options, yyjson_val* module); -void ffGenerateShellJson(FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateShellJsonResult(FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintShellHelpFormat(void); diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index cd0ea1ff1..97a6a05ac 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -85,7 +85,7 @@ void ffPrintSound(FFSoundOptions* options) void ffInitSoundOptions(FFSoundOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SOUND_MODULE_NAME, ffParseSoundCommandOptions, ffParseSoundJsonObject, ffPrintSound, ffGenerateSoundJson, ffPrintSoundHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SOUND_MODULE_NAME, ffParseSoundCommandOptions, ffParseSoundJsonObject, ffPrintSound, ffGenerateSoundJsonResult, ffPrintSoundHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); options->soundType = FF_SOUND_TYPE_MAIN; @@ -150,7 +150,7 @@ void ffParseSoundJsonObject(FFSoundOptions* options, yyjson_val* module) } } -void ffGenerateSoundJson(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateSoundJsonResult(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFSoundDevice)); const char* error = ffDetectSound(&result); diff --git a/src/modules/sound/sound.h b/src/modules/sound/sound.h index b7ab196a1..de90d8472 100644 --- a/src/modules/sound/sound.h +++ b/src/modules/sound/sound.h @@ -9,5 +9,5 @@ void ffInitSoundOptions(FFSoundOptions* options); bool ffParseSoundCommandOptions(FFSoundOptions* options, const char* key, const char* value); void ffDestroySoundOptions(FFSoundOptions* options); void ffParseSoundJsonObject(FFSoundOptions* options, yyjson_val* module); -void ffGenerateSoundJson(FFSoundOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateSoundJsonResult(FFSoundOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintSoundHelpFormat(void); diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index 0e207434a..1397ee9fd 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -75,7 +75,7 @@ void ffPrintSwap(FFSwapOptions* options) void ffInitSwapOptions(FFSwapOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SWAP_MODULE_NAME, ffParseSwapCommandOptions, ffParseSwapJsonObject, ffPrintSwap, ffGenerateSwapJson, ffPrintSwapHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SWAP_MODULE_NAME, ffParseSwapCommandOptions, ffParseSwapJsonObject, ffPrintSwap, ffGenerateSwapJsonResult, ffPrintSwapHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -111,7 +111,7 @@ void ffParseSwapJsonObject(FFSwapOptions* options, yyjson_val* module) } } -void ffGenerateSwapJson(FF_MAYBE_UNUSED FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateSwapJsonResult(FF_MAYBE_UNUSED FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFSwapResult storage; const char* error = ffDetectSwap(&storage); diff --git a/src/modules/swap/swap.h b/src/modules/swap/swap.h index 1a6fbc64f..177f503fa 100644 --- a/src/modules/swap/swap.h +++ b/src/modules/swap/swap.h @@ -9,5 +9,5 @@ void ffInitSwapOptions(FFSwapOptions* options); bool ffParseSwapCommandOptions(FFSwapOptions* options, const char* key, const char* value); void ffDestroySwapOptions(FFSwapOptions* options); void ffParseSwapJsonObject(FFSwapOptions* options, yyjson_val* module); -void ffGenerateSwapJson(FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateSwapJsonResult(FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintSwapHelpFormat(void); diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index 6745524fa..73eb004b0 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -42,7 +42,7 @@ void ffPrintTerminal(FFTerminalOptions* options) void ffInitTerminalOptions(FFTerminalOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINAL_MODULE_NAME, ffParseTerminalCommandOptions, ffParseTerminalJsonObject, ffPrintTerminal, ffGenerateTerminalJson, ffPrintTerminalHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINAL_MODULE_NAME, ffParseTerminalCommandOptions, ffParseTerminalJsonObject, ffPrintTerminal, ffGenerateTerminalJsonResult, ffPrintTerminalHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -78,7 +78,7 @@ void ffParseTerminalJsonObject(FFTerminalOptions* options, yyjson_val* module) } } -void ffGenerateTerminalJson(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFTerminalShellResult* result = ffDetectTerminalShell(); diff --git a/src/modules/terminal/terminal.h b/src/modules/terminal/terminal.h index c10e3fba0..0655f86c7 100644 --- a/src/modules/terminal/terminal.h +++ b/src/modules/terminal/terminal.h @@ -9,5 +9,5 @@ void ffInitTerminalOptions(FFTerminalOptions* options); bool ffParseTerminalCommandOptions(FFTerminalOptions* options, const char* key, const char* value); void ffDestroyTerminalOptions(FFTerminalOptions* options); void ffParseTerminalJsonObject(FFTerminalOptions* options, yyjson_val* module); -void ffGenerateTerminalJson(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateTerminalJsonResult(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintTerminalHelpFormat(void); diff --git a/src/modules/terminalfont/terminalfont.c b/src/modules/terminalfont/terminalfont.c index 2353ff869..8bf5f6395 100644 --- a/src/modules/terminalfont/terminalfont.c +++ b/src/modules/terminalfont/terminalfont.c @@ -49,7 +49,7 @@ void ffPrintTerminalFont(FFTerminalFontOptions* options) void ffInitTerminalFontOptions(FFTerminalFontOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALFONT_MODULE_NAME, ffParseTerminalFontCommandOptions, ffParseTerminalFontJsonObject, ffPrintTerminalFont, ffGenerateTerminalFontJson, ffPrintTerminalFontHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALFONT_MODULE_NAME, ffParseTerminalFontCommandOptions, ffParseTerminalFontJsonObject, ffPrintTerminalFont, ffGenerateTerminalFontJsonResult, ffPrintTerminalFontHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -85,7 +85,7 @@ void ffParseTerminalFontJsonObject(FFTerminalFontOptions* options, yyjson_val* m } } -void ffGenerateTerminalFontJson(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateTerminalFontJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFTerminalFontResult result; ffFontInit(&result.font); diff --git a/src/modules/terminalfont/terminalfont.h b/src/modules/terminalfont/terminalfont.h index a117c8289..78f54524a 100644 --- a/src/modules/terminalfont/terminalfont.h +++ b/src/modules/terminalfont/terminalfont.h @@ -9,5 +9,5 @@ void ffInitTerminalFontOptions(FFTerminalFontOptions* options); bool ffParseTerminalFontCommandOptions(FFTerminalFontOptions* options, const char* key, const char* value); void ffDestroyTerminalFontOptions(FFTerminalFontOptions* options); void ffParseTerminalFontJsonObject(FFTerminalFontOptions* options, yyjson_val* module); -void ffGenerateTerminalFontJson(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateTerminalFontJsonResult(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintTerminalFontHelpFormat(void); diff --git a/src/modules/terminalsize/terminalsize.c b/src/modules/terminalsize/terminalsize.c index 8d4f454bd..92ea0b99c 100644 --- a/src/modules/terminalsize/terminalsize.c +++ b/src/modules/terminalsize/terminalsize.c @@ -41,7 +41,7 @@ void ffPrintTerminalSize(FFTerminalSizeOptions* options) void ffInitTerminalSizeOptions(FFTerminalSizeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALSIZE_MODULE_NAME, ffParseTerminalSizeCommandOptions, ffParseTerminalSizeJsonObject, ffPrintTerminalSize, ffGenerateTerminalSizeJson, ffPrintTerminalSizeHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALSIZE_MODULE_NAME, ffParseTerminalSizeCommandOptions, ffParseTerminalSizeJsonObject, ffPrintTerminalSize, ffGenerateTerminalSizeJsonResult, ffPrintTerminalSizeHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -77,7 +77,7 @@ void ffParseTerminalSizeJsonObject(FFTerminalSizeOptions* options, yyjson_val* m } } -void ffGenerateTerminalSizeJson(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateTerminalSizeJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFTerminalSizeResult result; diff --git a/src/modules/terminalsize/terminalsize.h b/src/modules/terminalsize/terminalsize.h index 312ccaf5a..4d1a5c28c 100644 --- a/src/modules/terminalsize/terminalsize.h +++ b/src/modules/terminalsize/terminalsize.h @@ -9,5 +9,5 @@ void ffInitTerminalSizeOptions(FFTerminalSizeOptions* options); bool ffParseTerminalSizeCommandOptions(FFTerminalSizeOptions* options, const char* key, const char* value); void ffDestroyTerminalSizeOptions(FFTerminalSizeOptions* options); void ffParseTerminalSizeJsonObject(FFTerminalSizeOptions* options, yyjson_val* module); -void ffGenerateTerminalSizeJson(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateTerminalSizeJsonResult(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintTerminalSizeHelpFormat(void); diff --git a/src/modules/theme/theme.c b/src/modules/theme/theme.c index 8c0e60af5..d4b7364ad 100644 --- a/src/modules/theme/theme.c +++ b/src/modules/theme/theme.c @@ -32,7 +32,7 @@ void ffPrintTheme(FFThemeOptions* options) void ffInitThemeOptions(FFThemeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_THEME_MODULE_NAME, ffParseThemeCommandOptions, ffParseThemeJsonObject, ffPrintTheme, ffGenerateThemeJson, ffPrintThemeHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_THEME_MODULE_NAME, ffParseThemeCommandOptions, ffParseThemeJsonObject, ffPrintTheme, ffGenerateThemeJsonResult, ffPrintThemeHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -68,7 +68,7 @@ void ffParseThemeJsonObject(FFThemeOptions* options, yyjson_val* module) } } -void ffGenerateThemeJson(FF_MAYBE_UNUSED FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateThemeJsonResult(FF_MAYBE_UNUSED FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY theme = ffStrbufCreate(); const char* error = ffDetectTheme(&theme); diff --git a/src/modules/theme/theme.h b/src/modules/theme/theme.h index cf658de21..ed11cf014 100644 --- a/src/modules/theme/theme.h +++ b/src/modules/theme/theme.h @@ -9,5 +9,5 @@ void ffInitThemeOptions(FFThemeOptions* options); bool ffParseThemeCommandOptions(FFThemeOptions* options, const char* key, const char* value); void ffDestroyThemeOptions(FFThemeOptions* options); void ffParseThemeJsonObject(FFThemeOptions* options, yyjson_val* module); -void ffGenerateThemeJson(FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateThemeJsonResult(FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintThemeHelpFormat(void); diff --git a/src/modules/title/title.c b/src/modules/title/title.c index 2116a9e4b..b0d301a5a 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -71,7 +71,7 @@ void ffPrintTitle(FFTitleOptions* options) void ffInitTitleOptions(FFTitleOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TITLE_MODULE_NAME, ffParseTitleCommandOptions, ffParseTitleJsonObject, ffPrintTitle, ffGenerateTitleJson, ffPrintTitleHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TITLE_MODULE_NAME, ffParseTitleCommandOptions, ffParseTitleJsonObject, ffPrintTitle, ffGenerateTitleJsonResult, ffPrintTitleHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufSetStatic(&options->moduleArgs.key, " "); @@ -163,7 +163,7 @@ void ffParseTitleJsonObject(FFTitleOptions* options, yyjson_val* module) } } -void ffGenerateTitleJson(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, obj, "userName", &instance.state.platform.userName); diff --git a/src/modules/title/title.h b/src/modules/title/title.h index bad3a99c8..059b2dcc7 100644 --- a/src/modules/title/title.h +++ b/src/modules/title/title.h @@ -9,5 +9,5 @@ void ffInitTitleOptions(FFTitleOptions* options); bool ffParseTitleCommandOptions(FFTitleOptions* options, const char* key, const char* value); void ffDestroyTitleOptions(FFTitleOptions* options); void ffParseTitleJsonObject(FFTitleOptions* options, yyjson_val* module); -void ffGenerateTitleJson(FFTitleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateTitleJsonResult(FFTitleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintTitleHelpFormat(void); diff --git a/src/modules/uptime/uptime.c b/src/modules/uptime/uptime.c index d0ed2630d..ba8a031ca 100644 --- a/src/modules/uptime/uptime.c +++ b/src/modules/uptime/uptime.c @@ -91,7 +91,7 @@ void ffPrintUptime(FFUptimeOptions* options) void ffInitUptimeOptions(FFUptimeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_UPTIME_MODULE_NAME, ffParseUptimeCommandOptions, ffParseUptimeJsonObject, ffPrintUptime, ffGenerateUptimeJson, ffPrintUptimeHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_UPTIME_MODULE_NAME, ffParseUptimeCommandOptions, ffParseUptimeJsonObject, ffPrintUptime, ffGenerateUptimeJsonResult, ffPrintUptimeHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -127,7 +127,7 @@ void ffParseUptimeJsonObject(FFUptimeOptions* options, yyjson_val* module) } } -void ffGenerateUptimeJson(FF_MAYBE_UNUSED FFUptimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateUptimeJsonResult(FF_MAYBE_UNUSED FFUptimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFUptimeResult result; const char* error = ffDetectUptime(&result); diff --git a/src/modules/uptime/uptime.h b/src/modules/uptime/uptime.h index 4cd953782..5ce932a49 100644 --- a/src/modules/uptime/uptime.h +++ b/src/modules/uptime/uptime.h @@ -9,5 +9,5 @@ void ffInitUptimeOptions(FFUptimeOptions* options); bool ffParseUptimeCommandOptions(FFUptimeOptions* options, const char* key, const char* value); void ffDestroyUptimeOptions(FFUptimeOptions* options); void ffParseUptimeJsonObject(FFUptimeOptions* options, yyjson_val* module); -void ffGenerateUptimeJson(FFUptimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateUptimeJsonResult(FFUptimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintUptimeHelpFormat(void); diff --git a/src/modules/users/users.c b/src/modules/users/users.c index 3565fbe8a..3235283a6 100644 --- a/src/modules/users/users.c +++ b/src/modules/users/users.c @@ -93,7 +93,7 @@ void ffPrintUsers(FFUsersOptions* options) void ffInitUsersOptions(FFUsersOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_USERS_MODULE_NAME, ffParseUsersCommandOptions, ffParseUsersJsonObject, ffPrintUsers, ffGenerateUsersJson, ffPrintUsersHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_USERS_MODULE_NAME, ffParseUsersCommandOptions, ffParseUsersJsonObject, ffPrintUsers, ffGenerateUsersJsonResult, ffPrintUsersHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); options->compact = false; @@ -143,7 +143,7 @@ void ffParseUsersJsonObject(FFUsersOptions* options, yyjson_val* module) } } -void ffGenerateUsersJson(FF_MAYBE_UNUSED FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateUsersJsonResult(FF_MAYBE_UNUSED FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFUserResult)); diff --git a/src/modules/users/users.h b/src/modules/users/users.h index 71a4449ec..9947d4ce4 100644 --- a/src/modules/users/users.h +++ b/src/modules/users/users.h @@ -9,5 +9,5 @@ void ffInitUsersOptions(FFUsersOptions* options); bool ffParseUsersCommandOptions(FFUsersOptions* options, const char* key, const char* value); void ffDestroyUsersOptions(FFUsersOptions* options); void ffParseUsersJsonObject(FFUsersOptions* options, yyjson_val* module); -void ffGenerateUsersJson(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateUsersJsonResult(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintUsersHelpFormat(void); diff --git a/src/modules/version/version.c b/src/modules/version/version.c index 69911fb10..933ecc46d 100644 --- a/src/modules/version/version.c +++ b/src/modules/version/version.c @@ -47,7 +47,7 @@ void ffPrintVersion(FFVersionOptions* options) void ffInitVersionOptions(FFVersionOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VERSION_MODULE_NAME, ffParseVersionCommandOptions, ffParseVersionJsonObject, ffPrintVersion, ffGenerateVersionJson, ffPrintVersionHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VERSION_MODULE_NAME, ffParseVersionCommandOptions, ffParseVersionJsonObject, ffPrintVersion, ffGenerateVersionJsonResult, ffPrintVersionHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -83,7 +83,7 @@ void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module) } } -void ffGenerateVersionJson(FF_MAYBE_UNUSED FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateVersionJsonResult(FF_MAYBE_UNUSED FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFVersionResult result; ffDetectVersion(&result); diff --git a/src/modules/version/version.h b/src/modules/version/version.h index 3daaccd1c..2881af0d6 100644 --- a/src/modules/version/version.h +++ b/src/modules/version/version.h @@ -9,5 +9,5 @@ void ffInitVersionOptions(FFVersionOptions* options); bool ffParseVersionCommandOptions(FFVersionOptions* options, const char* key, const char* value); void ffDestroyVersionOptions(FFVersionOptions* options); void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module); -void ffGenerateVersionJson(FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateVersionJsonResult(FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintVersionHelpFormat(void); diff --git a/src/modules/vulkan/vulkan.c b/src/modules/vulkan/vulkan.c index 81760efa2..839e52407 100644 --- a/src/modules/vulkan/vulkan.c +++ b/src/modules/vulkan/vulkan.c @@ -46,7 +46,7 @@ void ffPrintVulkan(FFVulkanOptions* options) void ffInitVulkanOptions(FFVulkanOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VULKAN_MODULE_NAME, ffParseVulkanCommandOptions, ffParseVulkanJsonObject, ffPrintVulkan, ffGenerateVulkanJson, ffPrintVulkanHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VULKAN_MODULE_NAME, ffParseVulkanCommandOptions, ffParseVulkanJsonObject, ffPrintVulkan, ffGenerateVulkanJsonResult, ffPrintVulkanHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -82,7 +82,7 @@ void ffParseVulkanJsonObject(FFVulkanOptions* options, yyjson_val* module) } } -void ffGenerateVulkanJson(FF_MAYBE_UNUSED FFVulkanOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateVulkanJsonResult(FF_MAYBE_UNUSED FFVulkanOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFVulkanResult* result = ffDetectVulkan(); diff --git a/src/modules/vulkan/vulkan.h b/src/modules/vulkan/vulkan.h index fad7884bf..9a4954b67 100644 --- a/src/modules/vulkan/vulkan.h +++ b/src/modules/vulkan/vulkan.h @@ -9,5 +9,5 @@ void ffInitVulkanOptions(FFVulkanOptions* options); bool ffParseVulkanCommandOptions(FFVulkanOptions* options, const char* key, const char* value); void ffDestroyVulkanOptions(FFVulkanOptions* options); void ffParseVulkanJsonObject(FFVulkanOptions* options, yyjson_val* module); -void ffGenerateVulkanJson(FFVulkanOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateVulkanJsonResult(FFVulkanOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintVulkanHelpFormat(void); diff --git a/src/modules/wallpaper/wallpaper.c b/src/modules/wallpaper/wallpaper.c index 17213dfc5..dfcfd3466 100644 --- a/src/modules/wallpaper/wallpaper.c +++ b/src/modules/wallpaper/wallpaper.c @@ -44,7 +44,7 @@ void ffPrintWallpaper(FFWallpaperOptions* options) void ffInitWallpaperOptions(FFWallpaperOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperCommandOptions, ffParseWallpaperJsonObject, ffPrintWallpaper, ffGenerateWallpaperJson, ffPrintWallpaperHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperCommandOptions, ffParseWallpaperJsonObject, ffPrintWallpaper, ffGenerateWallpaperJsonResult, ffPrintWallpaperHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -80,7 +80,7 @@ void ffParseWallpaperJsonObject(FFWallpaperOptions* options, yyjson_val* module) } } -void ffGenerateWallpaperJson(FF_MAYBE_UNUSED FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateWallpaperJsonResult(FF_MAYBE_UNUSED FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY fullpath = ffStrbufCreate(); const char* error = ffDetectWallpaper(&fullpath); diff --git a/src/modules/wallpaper/wallpaper.h b/src/modules/wallpaper/wallpaper.h index a811cf515..ec51a9918 100644 --- a/src/modules/wallpaper/wallpaper.h +++ b/src/modules/wallpaper/wallpaper.h @@ -9,5 +9,5 @@ void ffInitWallpaperOptions(FFWallpaperOptions* options); bool ffParseWallpaperCommandOptions(FFWallpaperOptions* options, const char* key, const char* value); void ffDestroyWallpaperOptions(FFWallpaperOptions* options); void ffParseWallpaperJsonObject(FFWallpaperOptions* options, yyjson_val* module); -void ffGenerateWallpaperJson(FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateWallpaperJsonResult(FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintWallpaperHelpFormat(void); diff --git a/src/modules/weather/weather.c b/src/modules/weather/weather.c index 2fdb578d3..fff967a52 100644 --- a/src/modules/weather/weather.c +++ b/src/modules/weather/weather.c @@ -33,7 +33,7 @@ void ffPrintWeather(FFWeatherOptions* options) void ffInitWeatherOptions(FFWeatherOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WEATHER_MODULE_NAME, ffParseWeatherCommandOptions, ffParseWeatherJsonObject, ffPrintWeather, ffGenerateWeatherJson, ffPrintWeatherHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WEATHER_MODULE_NAME, ffParseWeatherCommandOptions, ffParseWeatherJsonObject, ffPrintWeather, ffGenerateWeatherJsonResult, ffPrintWeatherHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->location); @@ -111,7 +111,7 @@ void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module) } } -void ffGenerateWeatherJson(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateWeatherJsonResult(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); const char* error = ffDetectWeather(options, &result); diff --git a/src/modules/weather/weather.h b/src/modules/weather/weather.h index 6fdff6f97..7bb0f1367 100644 --- a/src/modules/weather/weather.h +++ b/src/modules/weather/weather.h @@ -11,5 +11,5 @@ void ffInitWeatherOptions(FFWeatherOptions* options); bool ffParseWeatherCommandOptions(FFWeatherOptions* options, const char* key, const char* value); void ffDestroyWeatherOptions(FFWeatherOptions* options); void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module); -void ffGenerateWeatherJson(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateWeatherJsonResult(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintWeatherHelpFormat(void); diff --git a/src/modules/wifi/wifi.c b/src/modules/wifi/wifi.c index 2268e830e..b7d73497e 100644 --- a/src/modules/wifi/wifi.c +++ b/src/modules/wifi/wifi.c @@ -72,7 +72,7 @@ void ffPrintWifi(FFWifiOptions* options) void ffInitWifiOptions(FFWifiOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WIFI_MODULE_NAME, ffParseWifiCommandOptions, ffParseWifiJsonObject, ffPrintWifi, ffGenerateWifiJson, ffPrintWifiHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WIFI_MODULE_NAME, ffParseWifiCommandOptions, ffParseWifiJsonObject, ffPrintWifi, ffGenerateWifiJsonResult, ffPrintWifiHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -108,7 +108,7 @@ void ffParseWifiJsonObject(FFWifiOptions* options, yyjson_val* module) } } -void ffGenerateWifiJson(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateWifiJsonResult(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFWifiResult)); const char* error = ffDetectWifi(&result); diff --git a/src/modules/wifi/wifi.h b/src/modules/wifi/wifi.h index 96ad12950..88f1c208f 100644 --- a/src/modules/wifi/wifi.h +++ b/src/modules/wifi/wifi.h @@ -9,5 +9,5 @@ void ffInitWifiOptions(FFWifiOptions* options); bool ffParseWifiCommandOptions(FFWifiOptions* options, const char* key, const char* value); void ffDestroyWifiOptions(FFWifiOptions* options); void ffParseWifiJsonObject(FFWifiOptions* options, yyjson_val* module); -void ffGenerateWifiJson(FFWifiOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateWifiJsonResult(FFWifiOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintWifiHelpFormat(void); diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index dcfbf94ec..de232bc95 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -43,7 +43,7 @@ void ffPrintWM(FFWMOptions* options) void ffInitWMOptions(FFWMOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WM_MODULE_NAME, ffParseWMCommandOptions, ffParseWMJsonObject, ffPrintWM, ffGenerateWMJson, ffPrintWMHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WM_MODULE_NAME, ffParseWMCommandOptions, ffParseWMJsonObject, ffPrintWM, ffGenerateWMJsonResult, ffPrintWMHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -79,7 +79,7 @@ void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module) } } -void ffGenerateWMJson(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFDisplayServerResult* result = ffConnectDisplayServer(); diff --git a/src/modules/wm/wm.h b/src/modules/wm/wm.h index 52f927515..3253b6ad1 100644 --- a/src/modules/wm/wm.h +++ b/src/modules/wm/wm.h @@ -9,5 +9,5 @@ void ffInitWMOptions(FFWMOptions* options); bool ffParseWMCommandOptions(FFWMOptions* options, const char* key, const char* value); void ffDestroyWMOptions(FFWMOptions* options); void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module); -void ffGenerateWMJson(FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateWMJsonResult(FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintWMHelpFormat(void); diff --git a/src/modules/wmtheme/wmtheme.c b/src/modules/wmtheme/wmtheme.c index d506d634c..27f194e1e 100644 --- a/src/modules/wmtheme/wmtheme.c +++ b/src/modules/wmtheme/wmtheme.c @@ -32,7 +32,7 @@ void ffPrintWMTheme(FFWMThemeOptions* options) void ffInitWMThemeOptions(FFWMThemeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WMTHEME_MODULE_NAME, ffParseWMThemeCommandOptions, ffParseWMThemeJsonObject, ffPrintWMTheme, ffGenerateWMThemeJson, ffPrintWMthemeHelpFormat); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WMTHEME_MODULE_NAME, ffParseWMThemeCommandOptions, ffParseWMThemeJsonObject, ffPrintWMTheme, ffGenerateWMThemeJsonResult, ffPrintWMthemeHelpFormat); ffOptionInitModuleArg(&options->moduleArgs); } @@ -68,7 +68,7 @@ void ffParseWMThemeJsonObject(FFWMThemeOptions* options, yyjson_val* module) } } -void ffGenerateWMThemeJson(FF_MAYBE_UNUSED FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +void ffGenerateWMThemeJsonResult(FF_MAYBE_UNUSED FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate(); if(!ffDetectWmTheme(&themeOrError)) diff --git a/src/modules/wmtheme/wmtheme.h b/src/modules/wmtheme/wmtheme.h index 0e9dd5b13..187d2f18e 100644 --- a/src/modules/wmtheme/wmtheme.h +++ b/src/modules/wmtheme/wmtheme.h @@ -9,5 +9,5 @@ void ffInitWMThemeOptions(FFWMThemeOptions* options); bool ffParseWMThemeCommandOptions(FFWMThemeOptions* options, const char* key, const char* value); void ffDestroyWMThemeOptions(FFWMThemeOptions* options); void ffParseWMThemeJsonObject(FFWMThemeOptions* options, yyjson_val* module); -void ffGenerateWMThemeJson(FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); +void ffGenerateWMThemeJsonResult(FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); void ffPrintWMthemeHelpFormat(void); From 824ada49b60cb86a7355f5aa96b88a725886a4cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 23 Oct 2023 10:22:21 +0800 Subject: [PATCH 008/100] Global: `:%s/generateJson/generateJsonResult/g` --- src/common/commandoption.c | 4 ++-- src/common/jsonconfig.c | 4 ++-- src/common/option.h | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common/commandoption.c b/src/common/commandoption.c index 7b0402b51..80ddcb923 100644 --- a/src/common/commandoption.c +++ b/src/common/commandoption.c @@ -15,8 +15,8 @@ static inline yyjson_mut_val* genJson(FFModuleBaseInfo* baseInfo) yyjson_mut_val* module = yyjson_mut_arr_add_obj(doc, doc->root); yyjson_mut_obj_add_str(doc, module, "type", baseInfo->name); - if (baseInfo->generateJson) - baseInfo->generateJson(baseInfo, doc, module); + if (baseInfo->generateJsonResult) + baseInfo->generateJsonResult(baseInfo, doc, module); else yyjson_mut_obj_add_str(doc, module, "error", "Unsupported for JSON format"); return module; diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 26dd884d6..09610cd0e 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -77,8 +77,8 @@ static inline yyjson_mut_val* genJson(FFModuleBaseInfo* baseInfo) yyjson_mut_val* module = yyjson_mut_arr_add_obj(doc, doc->root); yyjson_mut_obj_add_str(doc, module, "type", baseInfo->name); - if (baseInfo->generateJson) - baseInfo->generateJson(baseInfo, doc, module); + if (baseInfo->generateJsonResult) + baseInfo->generateJsonResult(baseInfo, doc, module); else yyjson_mut_obj_add_str(doc, module, "error", "Unsupported for JSON format"); return module; diff --git a/src/common/option.h b/src/common/option.h index 47e96585c..3207e576d 100644 --- a/src/common/option.h +++ b/src/common/option.h @@ -17,7 +17,7 @@ typedef struct FFModuleBaseInfo bool (*parseCommandOptions)(void* options, const char* key, const char* value); void (*parseJsonObject)(void* options, struct yyjson_val *module); void (*printModule)(void* options); - void (*generateJson)(void* options, struct yyjson_mut_doc* doc, struct yyjson_mut_val* module); + void (*generateJsonResult)(void* options, struct yyjson_mut_doc* doc, struct yyjson_mut_val* module); void (*printHelpFormat)(void); } FFModuleBaseInfo; @@ -27,7 +27,7 @@ static inline void ffOptionInitModuleBaseInfo( void* parseCommandOptions, // bool (*const parseCommandOptions)(void* options, const char* key, const char* value) void* parseJsonObject, // void (*const parseJsonObject)(void* options, yyjson_val *module) void* printModule, // void (*const printModule)(void* options) - void* generateJson, // void (*const generateJson)(void* options, yyjson_mut_doc* doc, yyjson_mut_val* obj) + void* generateJsonResult, // void (*const generateJsonResult)(void* options, yyjson_mut_doc* doc, yyjson_mut_val* obj) void (*printHelpFormat)(void) ) { @@ -35,7 +35,7 @@ static inline void ffOptionInitModuleBaseInfo( baseInfo->parseCommandOptions = (__typeof__(baseInfo->parseCommandOptions)) parseCommandOptions; baseInfo->parseJsonObject = (__typeof__(baseInfo->parseJsonObject)) parseJsonObject; baseInfo->printModule = (__typeof__(baseInfo->printModule)) printModule; - baseInfo->generateJson = (__typeof__(baseInfo->generateJson)) generateJson; + baseInfo->generateJsonResult = (__typeof__(baseInfo->generateJsonResult)) generateJsonResult; baseInfo->printHelpFormat = printHelpFormat; } From 44632e9bf6a032a9b6a8b313de704de1d4c4f3d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 23 Oct 2023 13:32:18 +0800 Subject: [PATCH 009/100] Global: don't expose internal functions --- src/common/jsonconfig.c | 8 ++--- src/modules/battery/battery.c | 40 ++++++++++----------- src/modules/battery/battery.h | 5 --- src/modules/bios/bios.c | 22 ++++++------ src/modules/bios/bios.h | 4 --- src/modules/bluetooth/bluetooth.c | 24 ++++++------- src/modules/bluetooth/bluetooth.h | 4 --- src/modules/board/board.c | 22 ++++++------ src/modules/board/board.h | 4 --- src/modules/break/break.c | 18 +++++----- src/modules/break/break.h | 2 -- src/modules/brightness/brightness.c | 26 +++++++------- src/modules/brightness/brightness.h | 4 --- src/modules/chassis/chassis.c | 22 ++++++------ src/modules/chassis/chassis.h | 4 --- src/modules/colors/colors.c | 28 +++++++-------- src/modules/colors/colors.h | 2 -- src/modules/command/command.c | 46 ++++++++++++------------- src/modules/command/command.h | 4 --- src/modules/cpu/cpu.c | 26 +++++++------- src/modules/cpu/cpu.h | 4 --- src/modules/cpuusage/cpuusage.c | 22 ++++++------ src/modules/cpuusage/cpuusage.h | 4 --- src/modules/cursor/cursor.c | 22 ++++++------ src/modules/cursor/cursor.h | 4 --- src/modules/custom/custom.c | 24 ++++++------- src/modules/custom/custom.h | 2 -- src/modules/datetime/datetime.c | 22 ++++++------ src/modules/datetime/datetime.h | 4 --- src/modules/de/de.c | 22 ++++++------ src/modules/de/de.h | 4 --- src/modules/disk/disk.c | 30 ++++++++-------- src/modules/disk/disk.h | 4 --- src/modules/diskio/diskio.c | 28 +++++++-------- src/modules/diskio/diskio.h | 4 --- src/modules/display/display.c | 26 +++++++------- src/modules/display/display.h | 4 --- src/modules/font/font.c | 22 ++++++------ src/modules/font/font.h | 4 --- src/modules/gamepad/gamepad.c | 22 ++++++------ src/modules/gamepad/gamepad.h | 4 --- src/modules/gpu/gpu.c | 30 ++++++++-------- src/modules/gpu/gpu.h | 4 --- src/modules/host/host.c | 22 ++++++------ src/modules/host/host.h | 4 --- src/modules/icons/icons.c | 22 ++++++------ src/modules/icons/icons.h | 4 --- src/modules/kernel/kernel.c | 22 ++++++------ src/modules/kernel/kernel.h | 4 --- src/modules/lm/lm.c | 22 ++++++------ src/modules/lm/lm.h | 4 --- src/modules/locale/locale.c | 22 ++++++------ src/modules/locale/locale.h | 4 --- src/modules/localip/localip.c | 32 ++++++++--------- src/modules/localip/localip.h | 4 --- src/modules/media/media.c | 22 ++++++------ src/modules/media/media.h | 4 --- src/modules/memory/memory.c | 22 ++++++------ src/modules/memory/memory.h | 4 --- src/modules/monitor/monitor.c | 22 ++++++------ src/modules/monitor/monitor.h | 4 --- src/modules/netio/netio.c | 30 ++++++++-------- src/modules/netio/netio.h | 4 --- src/modules/opencl/opencl.c | 22 ++++++------ src/modules/opencl/opencl.h | 4 --- src/modules/opengl/opengl.c | 30 ++++++++-------- src/modules/opengl/opengl.h | 4 --- src/modules/os/os.c | 22 ++++++------ src/modules/os/os.h | 4 --- src/modules/packages/packages.c | 22 ++++++------ src/modules/packages/packages.h | 4 --- src/modules/player/player.c | 22 ++++++------ src/modules/player/player.h | 4 --- src/modules/poweradapter/poweradapter.c | 22 ++++++------ src/modules/poweradapter/poweradapter.h | 4 --- src/modules/processes/processes.c | 22 ++++++------ src/modules/processes/processes.h | 4 --- src/modules/publicip/publicip.c | 32 ++++++++--------- src/modules/publicip/publicip.h | 4 --- src/modules/separator/separator.c | 22 ++++++------ src/modules/separator/separator.h | 2 -- src/modules/shell/shell.c | 22 ++++++------ src/modules/shell/shell.h | 4 --- src/modules/sound/sound.c | 26 +++++++------- src/modules/sound/sound.h | 4 --- src/modules/swap/swap.c | 22 ++++++------ src/modules/swap/swap.h | 4 --- src/modules/terminal/terminal.c | 22 ++++++------ src/modules/terminal/terminal.h | 4 --- src/modules/terminalfont/terminalfont.c | 22 ++++++------ src/modules/terminalfont/terminalfont.h | 4 --- src/modules/terminalsize/terminalsize.c | 22 ++++++------ src/modules/terminalsize/terminalsize.h | 4 --- src/modules/theme/theme.c | 22 ++++++------ src/modules/theme/theme.h | 4 --- src/modules/title/title.c | 40 ++++++++++----------- src/modules/title/title.h | 4 --- src/modules/uptime/uptime.c | 22 ++++++------ src/modules/uptime/uptime.h | 4 --- src/modules/users/users.c | 26 +++++++------- src/modules/users/users.h | 4 --- src/modules/version/version.c | 22 ++++++------ src/modules/version/version.h | 4 --- src/modules/vulkan/vulkan.c | 22 ++++++------ src/modules/vulkan/vulkan.h | 4 --- src/modules/wallpaper/wallpaper.c | 22 ++++++------ src/modules/wallpaper/wallpaper.h | 4 --- src/modules/weather/weather.c | 34 +++++++++--------- src/modules/weather/weather.h | 4 --- src/modules/wifi/wifi.c | 22 ++++++------ src/modules/wifi/wifi.h | 4 --- src/modules/wm/wm.c | 22 ++++++------ src/modules/wm/wm.h | 4 --- src/modules/wmtheme/wmtheme.c | 22 ++++++------ src/modules/wmtheme/wmtheme.h | 4 --- 115 files changed, 709 insertions(+), 930 deletions(-) diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 09610cd0e..6e13334d5 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -115,7 +115,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) case 'd': case 'D': { if (ffStrEqualsIgnCase(type, FF_DISKIO_MODULE_NAME)) { - if (module) ffParseDiskIOJsonObject(&cfg->diskIo, module); + if (module) cfg->diskIo.moduleInfo.parseJsonObject(&cfg->diskIo, module); ffPrepareDiskIO(&cfg->diskIo); } break; @@ -123,7 +123,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) case 'n': case 'N': { if (ffStrEqualsIgnCase(type, FF_NETIO_MODULE_NAME)) { - if (module) ffParseNetIOJsonObject(&cfg->netIo, module); + if (module) cfg->netIo.moduleInfo.parseJsonObject(&cfg->netIo, module); ffPrepareNetIO(&cfg->netIo); } break; @@ -131,7 +131,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) case 'p': case 'P': { if (ffStrEqualsIgnCase(type, FF_PUBLICIP_MODULE_NAME)) { - if (module) ffParsePublicIpJsonObject(&cfg->publicIP, module); + if (module) cfg->publicIP.moduleInfo.parseJsonObject(&cfg->publicIP, module); ffPreparePublicIp(&cfg->publicIP); } break; @@ -139,7 +139,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) case 'w': case 'W': { if (ffStrEqualsIgnCase(type, FF_WEATHER_MODULE_NAME)) { - if (module) ffParseWeatherJsonObject(&cfg->weather, module); + if (module) cfg->weather.moduleInfo.parseJsonObject(&cfg->weather, module); ffPrepareWeather(&cfg->weather); } break; diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index d3a42c4de..c48bc389b 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -101,17 +101,6 @@ void ffPrintBattery(FFBatteryOptions* options) } } -void ffInitBatteryOptions(FFBatteryOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BATTERY_MODULE_NAME, ffParseBatteryCommandOptions, ffParseBatteryJsonObject, ffPrintBattery, ffGenerateBatteryJsonResult, ffPrintBatteryHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - options->temp = false; - - #ifdef __linux__ - ffStrbufInit(&options->dir); - #endif -} - bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_BATTERY_MODULE_NAME); @@ -136,15 +125,6 @@ bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, co return false; } -void ffDestroyBatteryOptions(FFBatteryOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); - - #ifdef __linux__ - ffStrbufDestroy(&options->dir); - #endif -} - void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -219,3 +199,23 @@ void ffPrintBatteryHelpFormat(void) "Battery status" }); } + +void ffInitBatteryOptions(FFBatteryOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BATTERY_MODULE_NAME, ffParseBatteryCommandOptions, ffParseBatteryJsonObject, ffPrintBattery, ffGenerateBatteryJsonResult, ffPrintBatteryHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + options->temp = false; + + #ifdef __linux__ + ffStrbufInit(&options->dir); + #endif +} + +void ffDestroyBatteryOptions(FFBatteryOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); + + #ifdef __linux__ + ffStrbufDestroy(&options->dir); + #endif +} diff --git a/src/modules/battery/battery.h b/src/modules/battery/battery.h index 9cedbf56b..60d0f1c89 100644 --- a/src/modules/battery/battery.h +++ b/src/modules/battery/battery.h @@ -5,10 +5,5 @@ #define FF_BATTERY_MODULE_NAME "Battery" void ffPrintBattery(FFBatteryOptions* options); - void ffInitBatteryOptions(FFBatteryOptions* options); -bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, const char* value); void ffDestroyBatteryOptions(FFBatteryOptions* options); -void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module); -void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintBatteryHelpFormat(void); diff --git a/src/modules/bios/bios.c b/src/modules/bios/bios.c index f77fdaa89..68f63e340 100644 --- a/src/modules/bios/bios.c +++ b/src/modules/bios/bios.c @@ -53,12 +53,6 @@ exit: ffStrbufDestroy(&bios.version); } -void ffInitBiosOptions(FFBiosOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BIOS_MODULE_NAME, ffParseBiosCommandOptions, ffParseBiosJsonObject, ffPrintBios, ffGenerateBiosJsonResult, ffPrintBiosHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseBiosCommandOptions(FFBiosOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_BIOS_MODULE_NAME); @@ -69,11 +63,6 @@ bool ffParseBiosCommandOptions(FFBiosOptions* options, const char* key, const ch return false; } -void ffDestroyBiosOptions(FFBiosOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -135,3 +124,14 @@ void ffPrintBiosHelpFormat(void) "bios version" }); } + +void ffInitBiosOptions(FFBiosOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BIOS_MODULE_NAME, ffParseBiosCommandOptions, ffParseBiosJsonObject, ffPrintBios, ffGenerateBiosJsonResult, ffPrintBiosHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyBiosOptions(FFBiosOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/bios/bios.h b/src/modules/bios/bios.h index cb11bac4f..6d99eccfd 100644 --- a/src/modules/bios/bios.h +++ b/src/modules/bios/bios.h @@ -6,8 +6,4 @@ void ffPrintBios(FFBiosOptions* options); void ffInitBiosOptions(FFBiosOptions* options); -bool ffParseBiosCommandOptions(FFBiosOptions* options, const char* key, const char* value); void ffDestroyBiosOptions(FFBiosOptions* options); -void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module); -void ffGenerateBiosJsonResult(FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintBiosHelpFormat(void); diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index 53cc7acbf..ae8e64779 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -73,13 +73,6 @@ void ffPrintBluetooth(FFBluetoothOptions* options) } } -void ffInitBluetoothOptions(FFBluetoothOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BLUETOOTH_MODULE_NAME, ffParseBluetoothCommandOptions, ffParseBluetoothJsonObject, ffPrintBluetooth, ffGenerateBluetoothJsonResult, ffPrintBluetoothHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - options->showDisconnected = false; -} - bool ffParseBluetoothCommandOptions(FFBluetoothOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_BLUETOOTH_MODULE_NAME); @@ -96,11 +89,6 @@ bool ffParseBluetoothCommandOptions(FFBluetoothOptions* options, const char* key return false; } -void ffDestroyBluetoothOptions(FFBluetoothOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -166,3 +154,15 @@ void ffPrintBluetoothHelpFormat(void) "Battery percentage" }); } + +void ffInitBluetoothOptions(FFBluetoothOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BLUETOOTH_MODULE_NAME, ffParseBluetoothCommandOptions, ffParseBluetoothJsonObject, ffPrintBluetooth, ffGenerateBluetoothJsonResult, ffPrintBluetoothHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + options->showDisconnected = false; +} + +void ffDestroyBluetoothOptions(FFBluetoothOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/bluetooth/bluetooth.h b/src/modules/bluetooth/bluetooth.h index 2156eedb9..20c3b6d81 100644 --- a/src/modules/bluetooth/bluetooth.h +++ b/src/modules/bluetooth/bluetooth.h @@ -6,8 +6,4 @@ void ffPrintBluetooth(FFBluetoothOptions* options); void ffInitBluetoothOptions(FFBluetoothOptions* options); -bool ffParseBluetoothCommandOptions(FFBluetoothOptions* options, const char* key, const char* value); void ffDestroyBluetoothOptions(FFBluetoothOptions* options); -void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module); -void ffGenerateBluetoothJsonResult(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintBluetoothHelpFormat(void); diff --git a/src/modules/board/board.c b/src/modules/board/board.c index 34052cb42..e7664eb34 100644 --- a/src/modules/board/board.c +++ b/src/modules/board/board.c @@ -49,12 +49,6 @@ exit: ffStrbufDestroy(&result.version); } -void ffInitBoardOptions(FFBoardOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BOARD_MODULE_NAME, ffParseBoardCommandOptions, ffParseBoardJsonObject, ffPrintBoard, ffGenerateBoardJsonResult, ffPrintBoardHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseBoardCommandOptions(FFBoardOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_BOARD_MODULE_NAME); @@ -65,11 +59,6 @@ bool ffParseBoardCommandOptions(FFBoardOptions* options, const char* key, const return false; } -void ffDestroyBoardOptions(FFBoardOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseBoardJsonObject(FFBoardOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -127,3 +116,14 @@ void ffPrintBoardHelpFormat(void) "board version" }); } + +void ffInitBoardOptions(FFBoardOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BOARD_MODULE_NAME, ffParseBoardCommandOptions, ffParseBoardJsonObject, ffPrintBoard, ffGenerateBoardJsonResult, ffPrintBoardHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyBoardOptions(FFBoardOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/board/board.h b/src/modules/board/board.h index 6beaf3a6d..7fdbffe95 100644 --- a/src/modules/board/board.h +++ b/src/modules/board/board.h @@ -6,8 +6,4 @@ void ffPrintBoard(FFBoardOptions* options); void ffInitBoardOptions(FFBoardOptions* options); -bool ffParseBoardCommandOptions(FFBoardOptions* options, const char* key, const char* value); void ffDestroyBoardOptions(FFBoardOptions* options); -void ffParseBoardJsonObject(FFBoardOptions* options, yyjson_val* module); -void ffGenerateBoardJsonResult(FFBoardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintBoardHelpFormat(void); diff --git a/src/modules/break/break.c b/src/modules/break/break.c index e52e357e6..5ec50ace9 100644 --- a/src/modules/break/break.c +++ b/src/modules/break/break.c @@ -7,22 +7,22 @@ void ffPrintBreak(FF_MAYBE_UNUSED FFBreakOptions* options) putchar('\n'); } -void ffInitBreakOptions(FF_MAYBE_UNUSED FFBreakOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BREAK_MODULE_NAME, ffParseBreakCommandOptions, ffParseBreakJsonObject, ffPrintBreak, NULL, NULL); -} - bool ffParseBreakCommandOptions(FF_MAYBE_UNUSED FFBreakOptions* options, FF_MAYBE_UNUSED const char* key, FF_MAYBE_UNUSED const char* value) { return false; } -void ffDestroyBreakOptions(FF_MAYBE_UNUSED FFBreakOptions* options) -{ -} - void ffParseBreakJsonObject(FF_MAYBE_UNUSED FFBreakOptions* options, FF_MAYBE_UNUSED yyjson_val* module) { ffPrintBreak(options); return; } + +void ffInitBreakOptions(FF_MAYBE_UNUSED FFBreakOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BREAK_MODULE_NAME, ffParseBreakCommandOptions, ffParseBreakJsonObject, ffPrintBreak, NULL, NULL); +} + +void ffDestroyBreakOptions(FF_MAYBE_UNUSED FFBreakOptions* options) +{ +} diff --git a/src/modules/break/break.h b/src/modules/break/break.h index 155548cf6..b651a503e 100644 --- a/src/modules/break/break.h +++ b/src/modules/break/break.h @@ -6,6 +6,4 @@ void ffPrintBreak(FFBreakOptions* options); void ffInitBreakOptions(FFBreakOptions* options); -bool ffParseBreakCommandOptions(FFBreakOptions* options, const char* key, const char* value); void ffDestroyBreakOptions(FFBreakOptions* options); -void ffParseBreakJsonObject(FFBreakOptions* options, yyjson_val* module); diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index e17c3d5e3..b49a04d7e 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -84,14 +84,6 @@ void ffPrintBrightness(FFBrightnessOptions* options) } } -void ffInitBrightnessOptions(FFBrightnessOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BRIGHTNESS_MODULE_NAME, ffParseBrightnessCommandOptions, ffParseBrightnessJsonObject, ffPrintBrightness, ffGenerateBrightnessJsonResult, ffPrintBrightnessHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - options->ddcciSleep = 10; -} - bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_BRIGHTNESS_MODULE_NAME); @@ -108,11 +100,6 @@ bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* k return false; } -void ffDestroyBrightnessOptions(FFBrightnessOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -182,3 +169,16 @@ void ffPrintBrightnessHelpFormat(void) "Current brightness value", }); } + +void ffInitBrightnessOptions(FFBrightnessOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BRIGHTNESS_MODULE_NAME, ffParseBrightnessCommandOptions, ffParseBrightnessJsonObject, ffPrintBrightness, ffGenerateBrightnessJsonResult, ffPrintBrightnessHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + options->ddcciSleep = 10; +} + +void ffDestroyBrightnessOptions(FFBrightnessOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/brightness/brightness.h b/src/modules/brightness/brightness.h index 1cda43f89..36faaf304 100644 --- a/src/modules/brightness/brightness.h +++ b/src/modules/brightness/brightness.h @@ -6,8 +6,4 @@ void ffPrintBrightness(FFBrightnessOptions* options); void ffInitBrightnessOptions(FFBrightnessOptions* options); -bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* key, const char* value); void ffDestroyBrightnessOptions(FFBrightnessOptions* options); -void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* module); -void ffGenerateBrightnessJsonResult(FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintBrightnessHelpFormat(void); diff --git a/src/modules/chassis/chassis.c b/src/modules/chassis/chassis.c index d4e5a6078..c3b953e43 100644 --- a/src/modules/chassis/chassis.c +++ b/src/modules/chassis/chassis.c @@ -50,12 +50,6 @@ exit: ffStrbufDestroy(&result.version); } -void ffInitChassisOptions(FFChassisOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CHASSIS_MODULE_NAME, ffParseChassisCommandOptions, ffParseChassisJsonObject, ffPrintChassis, ffGenerateChassisJsonResult, ffPrintChassisHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_CHASSIS_MODULE_NAME); @@ -66,11 +60,6 @@ bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, co return false; } -void ffDestroyChassisOptions(FFChassisOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -128,3 +117,14 @@ void ffPrintChassisHelpFormat(void) "chassis version" }); } + +void ffInitChassisOptions(FFChassisOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CHASSIS_MODULE_NAME, ffParseChassisCommandOptions, ffParseChassisJsonObject, ffPrintChassis, ffGenerateChassisJsonResult, ffPrintChassisHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyChassisOptions(FFChassisOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/chassis/chassis.h b/src/modules/chassis/chassis.h index 290e101b0..f37358c94 100644 --- a/src/modules/chassis/chassis.h +++ b/src/modules/chassis/chassis.h @@ -6,8 +6,4 @@ void ffPrintChassis(FFChassisOptions* options); void ffInitChassisOptions(FFChassisOptions* options); -bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, const char* value); void ffDestroyChassisOptions(FFChassisOptions* options); -void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module); -void ffGenerateChassisJsonResult(FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintChassisHelpFormat(void); diff --git a/src/modules/colors/colors.c b/src/modules/colors/colors.c index 4ac68d12e..4cbe89df4 100644 --- a/src/modules/colors/colors.c +++ b/src/modules/colors/colors.c @@ -55,15 +55,6 @@ void ffPrintColors(FFColorsOptions* options) puts(FASTFETCH_TEXT_MODIFIER_RESET); } -void ffInitColorsOptions(FFColorsOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COLORS_MODULE_NAME, ffParseColorsCommandOptions, ffParseColorsJsonObject, ffPrintColors, NULL, NULL); - ffOptionInitModuleArg(&options->moduleArgs); - ffStrbufSetStatic(&options->moduleArgs.key, " "); - options->symbol = FF_COLORS_SYMBOL_BLOCK; - options->paddingLeft = 0; -} - bool ffParseColorsCommandOptions(FFColorsOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_COLORS_MODULE_NAME); @@ -94,11 +85,6 @@ bool ffParseColorsCommandOptions(FFColorsOptions* options, const char* key, cons return false; } -void ffDestroyColorsOptions(FF_MAYBE_UNUSED FFColorsOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -140,3 +126,17 @@ void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module) ffPrintErrorString(FF_COLORS_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Unknown JSON key %s", key); } } + +void ffInitColorsOptions(FFColorsOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COLORS_MODULE_NAME, ffParseColorsCommandOptions, ffParseColorsJsonObject, ffPrintColors, NULL, NULL); + ffOptionInitModuleArg(&options->moduleArgs); + ffStrbufSetStatic(&options->moduleArgs.key, " "); + options->symbol = FF_COLORS_SYMBOL_BLOCK; + options->paddingLeft = 0; +} + +void ffDestroyColorsOptions(FF_MAYBE_UNUSED FFColorsOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/colors/colors.h b/src/modules/colors/colors.h index 674bcd817..8520f54b6 100644 --- a/src/modules/colors/colors.h +++ b/src/modules/colors/colors.h @@ -7,5 +7,3 @@ void ffPrintColors(FFColorsOptions* options); void ffInitColorsOptions(FFColorsOptions* options); void ffDestroyColorsOptions(FFColorsOptions* options); -bool ffParseColorsCommandOptions(FFColorsOptions* options, const char* key, const char* value); -void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module); diff --git a/src/modules/command/command.c b/src/modules/command/command.c index 397e99304..d5b86d30e 100644 --- a/src/modules/command/command.c +++ b/src/modules/command/command.c @@ -45,22 +45,6 @@ void ffPrintCommand(FFCommandOptions* options) } } -void ffInitCommandOptions(FFCommandOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COMMAND_MODULE_NAME, ffParseCommandCommandOptions, ffParseCommandJsonObject, ffPrintCommand, ffGenerateCommandJsonResult, ffPrintCommandHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - ffStrbufInitStatic(&options->shell, - #ifdef _WIN32 - "cmd.exe" - #else - "/bin/sh" - #endif - ); - - ffStrbufInit(&options->text); -} - bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_COMMAND_MODULE_NAME); @@ -83,13 +67,6 @@ bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, co return false; } -void ffDestroyCommandOptions(FFCommandOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); - ffStrbufDestroy(&options->shell); - ffStrbufDestroy(&options->text); -} - void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -154,3 +131,26 @@ void ffPrintCommandHelpFormat(void) "Command result" }); } + +void ffInitCommandOptions(FFCommandOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COMMAND_MODULE_NAME, ffParseCommandCommandOptions, ffParseCommandJsonObject, ffPrintCommand, ffGenerateCommandJsonResult, ffPrintCommandHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + ffStrbufInitStatic(&options->shell, + #ifdef _WIN32 + "cmd.exe" + #else + "/bin/sh" + #endif + ); + + ffStrbufInit(&options->text); +} + +void ffDestroyCommandOptions(FFCommandOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); + ffStrbufDestroy(&options->shell); + ffStrbufDestroy(&options->text); +} diff --git a/src/modules/command/command.h b/src/modules/command/command.h index a9fa22867..246412801 100644 --- a/src/modules/command/command.h +++ b/src/modules/command/command.h @@ -6,8 +6,4 @@ void ffPrintCommand(FFCommandOptions* options); void ffInitCommandOptions(FFCommandOptions* options); -bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, const char* value); void ffDestroyCommandOptions(FFCommandOptions* options); -void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module); -void ffGenerateCommandJsonResult(FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintCommandHelpFormat(void); diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index 702ff14e6..0fe0dea42 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -77,14 +77,6 @@ void ffPrintCPU(FFCPUOptions* options) ffStrbufDestroy(&cpu.vendor); } -void ffInitCPUOptions(FFCPUOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPU_MODULE_NAME, ffParseCPUCommandOptions, ffParseCPUJsonObject, ffPrintCPU, ffGenerateCPUJsonResult, ffPrintCPUHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - options->temp = false; - options->freqNdigits = 2; -} - bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_CPU_MODULE_NAME); @@ -107,11 +99,6 @@ bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char return false; } -void ffDestroyCPUOptions(FFCPUOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -195,3 +182,16 @@ void ffPrintCPUHelpFormat(void) "Temperature" }); } + +void ffInitCPUOptions(FFCPUOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPU_MODULE_NAME, ffParseCPUCommandOptions, ffParseCPUJsonObject, ffPrintCPU, ffGenerateCPUJsonResult, ffPrintCPUHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + options->temp = false; + options->freqNdigits = 2; +} + +void ffDestroyCPUOptions(FFCPUOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/cpu/cpu.h b/src/modules/cpu/cpu.h index 3daf94d65..1db4efbf7 100644 --- a/src/modules/cpu/cpu.h +++ b/src/modules/cpu/cpu.h @@ -6,8 +6,4 @@ void ffPrintCPU(FFCPUOptions* options); void ffInitCPUOptions(FFCPUOptions* options); -bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char* value); void ffDestroyCPUOptions(FFCPUOptions* options); -void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module); -void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintCPUHelpFormat(void); diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index 9fa1e824c..69e938af1 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -85,12 +85,6 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) } } -void ffInitCPUUsageOptions(FFCPUUsageOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPUUSAGE_MODULE_NAME, ffParseCPUUsageCommandOptions, ffParseCPUUsageJsonObject, ffPrintCPUUsage, ffGenerateCPUUsageJsonResult, ffPrintCPUUsageHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_CPUUSAGE_MODULE_NAME); @@ -107,11 +101,6 @@ bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key, return false; } -void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -162,3 +151,14 @@ void ffPrintCPUUsageHelpFormat(void) "CPU core index of minimum usage", }); } + +void ffInitCPUUsageOptions(FFCPUUsageOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPUUSAGE_MODULE_NAME, ffParseCPUUsageCommandOptions, ffParseCPUUsageJsonObject, ffPrintCPUUsage, ffGenerateCPUUsageJsonResult, ffPrintCPUUsageHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/cpuusage/cpuusage.h b/src/modules/cpuusage/cpuusage.h index 52c567ee2..bbd74f085 100644 --- a/src/modules/cpuusage/cpuusage.h +++ b/src/modules/cpuusage/cpuusage.h @@ -8,8 +8,4 @@ void ffPrepareCPUUsage(); void ffPrintCPUUsage(FFCPUUsageOptions* options); void ffInitCPUUsageOptions(FFCPUUsageOptions* options); -bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key, const char* value); void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options); -void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module); -void ffGenerateCPUUsageJsonResult(FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintCPUUsageHelpFormat(void); diff --git a/src/modules/cursor/cursor.c b/src/modules/cursor/cursor.c index 28fec9da8..7b4d20171 100644 --- a/src/modules/cursor/cursor.c +++ b/src/modules/cursor/cursor.c @@ -50,12 +50,6 @@ void ffPrintCursor(FFCursorOptions* options) ffStrbufDestroy(&result.size); } -void ffInitCursorOptions(FFCursorOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CURSOR_MODULE_NAME, ffParseCursorCommandOptions, ffParseCursorJsonObject, ffPrintCursor, ffGenerateCursorJsonResult, ffPrintCursorHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseCursorCommandOptions(FFCursorOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_CURSOR_MODULE_NAME); @@ -66,11 +60,6 @@ bool ffParseCursorCommandOptions(FFCursorOptions* options, const char* key, cons return false; } -void ffDestroyCursorOptions(FFCursorOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -119,3 +108,14 @@ void ffPrintCursorHelpFormat(void) "Cursor size" }); } + +void ffInitCursorOptions(FFCursorOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CURSOR_MODULE_NAME, ffParseCursorCommandOptions, ffParseCursorJsonObject, ffPrintCursor, ffGenerateCursorJsonResult, ffPrintCursorHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyCursorOptions(FFCursorOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/cursor/cursor.h b/src/modules/cursor/cursor.h index 36b712dfa..939033682 100644 --- a/src/modules/cursor/cursor.h +++ b/src/modules/cursor/cursor.h @@ -6,8 +6,4 @@ void ffPrintCursor(FFCursorOptions* options); void ffInitCursorOptions(FFCursorOptions* options); -bool ffParseCursorCommandOptions(FFCursorOptions* options, const char* key, const char* value); void ffDestroyCursorOptions(FFCursorOptions* options); -void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module); -void ffGenerateCursorJsonResult(FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintCursorHelpFormat(void); diff --git a/src/modules/custom/custom.c b/src/modules/custom/custom.c index 11104d6c1..baccd127c 100644 --- a/src/modules/custom/custom.c +++ b/src/modules/custom/custom.c @@ -17,13 +17,6 @@ void ffPrintCustom(FFCustomOptions* options) puts(FASTFETCH_TEXT_MODIFIER_RESET); } -void ffInitCustomOptions(FFCustomOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CUSTOM_MODULE_NAME, ffParseCustomCommandOptions, ffParseCustomJsonObject, ffPrintCustom, NULL, NULL); - ffOptionInitModuleArg(&options->moduleArgs); - ffStrbufSetStatic(&options->moduleArgs.key, " "); -} - bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_CUSTOM_MODULE_NAME); @@ -34,11 +27,6 @@ bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, cons return false; } -void ffDestroyCustomOptions(FFCustomOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseCustomJsonObject(FFCustomOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -55,3 +43,15 @@ void ffParseCustomJsonObject(FFCustomOptions* options, yyjson_val* module) ffPrintError(FF_CUSTOM_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } + +void ffInitCustomOptions(FFCustomOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CUSTOM_MODULE_NAME, ffParseCustomCommandOptions, ffParseCustomJsonObject, ffPrintCustom, NULL, NULL); + ffOptionInitModuleArg(&options->moduleArgs); + ffStrbufSetStatic(&options->moduleArgs.key, " "); +} + +void ffDestroyCustomOptions(FFCustomOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/custom/custom.h b/src/modules/custom/custom.h index 4c4c40b5d..172fe9ea3 100644 --- a/src/modules/custom/custom.h +++ b/src/modules/custom/custom.h @@ -6,6 +6,4 @@ void ffPrintCustom(FFCustomOptions* options); void ffInitCustomOptions(FFCustomOptions* options); -bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, const char* value); void ffDestroyCustomOptions(FFCustomOptions* options); -void ffParseCustomJsonObject(FFCustomOptions* options, yyjson_val* module); diff --git a/src/modules/datetime/datetime.c b/src/modules/datetime/datetime.c index ad0987c71..6c4bb29ce 100644 --- a/src/modules/datetime/datetime.c +++ b/src/modules/datetime/datetime.c @@ -141,12 +141,6 @@ void ffPrintDateTime(FFDateTimeOptions* options) puts(buffer); } -void ffInitDateTimeOptions(FFDateTimeOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DATETIME_MODULE_NAME, ffParseDateTimeCommandOptions, ffParseDateTimeJsonObject, ffPrintDateTime, ffGenerateDateTimeJsonResult, ffPrintDateTimeHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseDateTimeCommandOptions(FFDateTimeOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_DATETIME_MODULE_NAME); @@ -157,11 +151,6 @@ bool ffParseDateTimeCommandOptions(FFDateTimeOptions* options, const char* key, return false; } -void ffDestroyDateTimeOptions(FFDateTimeOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseDateTimeJsonObject(FFDateTimeOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -209,3 +198,14 @@ void ffPrintDateTimeHelpFormat(void) "second with leading zero" }); } + +void ffInitDateTimeOptions(FFDateTimeOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DATETIME_MODULE_NAME, ffParseDateTimeCommandOptions, ffParseDateTimeJsonObject, ffPrintDateTime, ffGenerateDateTimeJsonResult, ffPrintDateTimeHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyDateTimeOptions(FFDateTimeOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/datetime/datetime.h b/src/modules/datetime/datetime.h index 6356fd408..b169e73d1 100644 --- a/src/modules/datetime/datetime.h +++ b/src/modules/datetime/datetime.h @@ -6,8 +6,4 @@ void ffPrintDateTime(FFDateTimeOptions* options); void ffInitDateTimeOptions(FFDateTimeOptions* options); -bool ffParseDateTimeCommandOptions(FFDateTimeOptions* options, const char* key, const char* value); void ffDestroyDateTimeOptions(FFDateTimeOptions* options); -void ffParseDateTimeJsonObject(FFDateTimeOptions* options, yyjson_val* module); -void ffGenerateDateTimeJsonResult(FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintDateTimeHelpFormat(void); diff --git a/src/modules/de/de.c b/src/modules/de/de.c index a14204cce..83b361733 100644 --- a/src/modules/de/de.c +++ b/src/modules/de/de.c @@ -40,12 +40,6 @@ void ffPrintDE(FFDEOptions* options) } } -void ffInitDEOptions(FFDEOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DE_MODULE_NAME, ffParseDECommandOptions, ffParseDEJsonObject, ffPrintDE, ffGenerateDEJsonResult, ffPrintDEHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_DE_MODULE_NAME); @@ -56,11 +50,6 @@ bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* return false; } -void ffDestroyDEOptions(FFDEOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -102,3 +91,14 @@ void ffPrintDEHelpFormat(void) "DE version" }); } + +void ffInitDEOptions(FFDEOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DE_MODULE_NAME, ffParseDECommandOptions, ffParseDEJsonObject, ffPrintDE, ffGenerateDEJsonResult, ffPrintDEHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyDEOptions(FFDEOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/de/de.h b/src/modules/de/de.h index c33143319..01cc458aa 100644 --- a/src/modules/de/de.h +++ b/src/modules/de/de.h @@ -6,8 +6,4 @@ void ffPrintDE(FFDEOptions* options); void ffInitDEOptions(FFDEOptions* options); -bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* value); void ffDestroyDEOptions(FFDEOptions* options); -void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module); -void ffGenerateDEJsonResult(FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintDEHelpFormat(void); diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 874b26c2a..0fbcc86b8 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -202,16 +202,6 @@ void ffPrintDisk(FFDiskOptions* options) } } -void ffInitDiskOptions(FFDiskOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISK_MODULE_NAME, ffParseDiskCommandOptions, ffParseDiskJsonObject, ffPrintDisk, ffGenerateDiskJsonResult, ffPrintDiskHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - ffStrbufInit(&options->folders); - options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT; - options->calcType = FF_DISK_CALC_TYPE_FREE; -} - bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_DISK_MODULE_NAME); @@ -291,11 +281,6 @@ bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const ch return false; } -void ffDestroyDiskOptions(FFDiskOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -440,3 +425,18 @@ void ffPrintDiskHelpFormat(void) "Filesystem" }); } + +void ffInitDiskOptions(FFDiskOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISK_MODULE_NAME, ffParseDiskCommandOptions, ffParseDiskJsonObject, ffPrintDisk, ffGenerateDiskJsonResult, ffPrintDiskHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + ffStrbufInit(&options->folders); + options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT; + options->calcType = FF_DISK_CALC_TYPE_FREE; +} + +void ffDestroyDiskOptions(FFDiskOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/disk/disk.h b/src/modules/disk/disk.h index f28403b15..e21531eae 100644 --- a/src/modules/disk/disk.h +++ b/src/modules/disk/disk.h @@ -6,8 +6,4 @@ void ffPrintDisk(FFDiskOptions* options); void ffInitDiskOptions(FFDiskOptions* options); -bool ffParseDiskCommandOptions(FFDiskOptions* options, const char* key, const char* value); void ffDestroyDiskOptions(FFDiskOptions* options); -void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module); -void ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintDiskHelpFormat(void); diff --git a/src/modules/diskio/diskio.c b/src/modules/diskio/diskio.c index 205b2abb6..ef1b72801 100644 --- a/src/modules/diskio/diskio.c +++ b/src/modules/diskio/diskio.c @@ -112,14 +112,6 @@ void ffPrintDiskIO(FFDiskIOOptions* options) } } -void ffInitDiskIOOptions(FFDiskIOOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISKIO_MODULE_NAME, ffParseDiskIOCommandOptions, ffParseDiskIOJsonObject, ffPrintDiskIO, ffGenerateDiskIOJsonResult, ffPrintDiskIOHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - ffStrbufInit(&options->namePrefix); -} - bool ffParseDiskIOCommandOptions(FFDiskIOOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_DISKIO_MODULE_NAME); @@ -136,12 +128,6 @@ bool ffParseDiskIOCommandOptions(FFDiskIOOptions* options, const char* key, cons return false; } -void ffDestroyDiskIOOptions(FFDiskIOOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); - ffStrbufDestroy(&options->namePrefix); -} - void ffParseDiskIOJsonObject(FFDiskIOOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -226,3 +212,17 @@ void ffPrintDiskIOHelpFormat(void) "Number of writes", }); } + +void ffInitDiskIOOptions(FFDiskIOOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISKIO_MODULE_NAME, ffParseDiskIOCommandOptions, ffParseDiskIOJsonObject, ffPrintDiskIO, ffGenerateDiskIOJsonResult, ffPrintDiskIOHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + ffStrbufInit(&options->namePrefix); +} + +void ffDestroyDiskIOOptions(FFDiskIOOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); + ffStrbufDestroy(&options->namePrefix); +} diff --git a/src/modules/diskio/diskio.h b/src/modules/diskio/diskio.h index 5c048cbfd..b3fa27bde 100644 --- a/src/modules/diskio/diskio.h +++ b/src/modules/diskio/diskio.h @@ -8,8 +8,4 @@ void ffPrepareDiskIO(FFDiskIOOptions* options); void ffPrintDiskIO(FFDiskIOOptions* options); void ffInitDiskIOOptions(FFDiskIOOptions* options); -bool ffParseDiskIOCommandOptions(FFDiskIOOptions* options, const char* key, const char* value); void ffDestroyDiskIOOptions(FFDiskIOOptions* options); -void ffParseDiskIOJsonObject(FFDiskIOOptions* options, yyjson_val* module); -void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintDiskIOHelpFormat(void); diff --git a/src/modules/display/display.c b/src/modules/display/display.c index d7b870568..13f83c689 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -109,14 +109,6 @@ void ffPrintDisplay(FFDisplayOptions* options) } } -void ffInitDisplayOptions(FFDisplayOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISPLAY_MODULE_NAME, ffParseDisplayCommandOptions, ffParseDisplayJsonObject, ffPrintDisplay, ffGenerateDisplayJsonResult, ffPrintDisplayHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - options->compactType = FF_DISPLAY_COMPACT_TYPE_NONE; - options->preciseRefreshRate = false; -} - bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_DISPLAY_MODULE_NAME); @@ -144,11 +136,6 @@ bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, co return false; } -void ffDestroyDisplayOptions(FFDisplayOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -238,3 +225,16 @@ void ffPrintDisplayHelpFormat(void) "Screen rotation (in degrees)", }); } + +void ffInitDisplayOptions(FFDisplayOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISPLAY_MODULE_NAME, ffParseDisplayCommandOptions, ffParseDisplayJsonObject, ffPrintDisplay, ffGenerateDisplayJsonResult, ffPrintDisplayHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + options->compactType = FF_DISPLAY_COMPACT_TYPE_NONE; + options->preciseRefreshRate = false; +} + +void ffDestroyDisplayOptions(FFDisplayOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/display/display.h b/src/modules/display/display.h index b592afd99..7479295cf 100644 --- a/src/modules/display/display.h +++ b/src/modules/display/display.h @@ -6,8 +6,4 @@ void ffPrintDisplay(FFDisplayOptions* options); void ffInitDisplayOptions(FFDisplayOptions* options); -bool ffParseDisplayCommandOptions(FFDisplayOptions* options, const char* key, const char* value); void ffDestroyDisplayOptions(FFDisplayOptions* options); -void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module); -void ffGenerateDisplayJsonResult(FFDisplayOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintDisplayHelpFormat(void); diff --git a/src/modules/font/font.c b/src/modules/font/font.c index 93becab47..589a15331 100644 --- a/src/modules/font/font.c +++ b/src/modules/font/font.c @@ -43,12 +43,6 @@ void ffPrintFont(FFFontOptions* options) ffStrbufDestroy(&font.fonts[i]); } -void ffInitFontOptions(FFFontOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_FONT_MODULE_NAME, ffParseFontCommandOptions, ffParseFontJsonObject, ffPrintFont, ffGenerateFontJsonResult, ffPrintFontHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseFontCommandOptions(FFFontOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_FONT_MODULE_NAME); @@ -59,11 +53,6 @@ bool ffParseFontCommandOptions(FFFontOptions* options, const char* key, const ch return false; } -void ffDestroyFontOptions(FFFontOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseFontJsonObject(FFFontOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -117,3 +106,14 @@ void ffPrintFontHelpFormat(void) "Combined fonts" }); } + +void ffInitFontOptions(FFFontOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_FONT_MODULE_NAME, ffParseFontCommandOptions, ffParseFontJsonObject, ffPrintFont, ffGenerateFontJsonResult, ffPrintFontHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyFontOptions(FFFontOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/font/font.h b/src/modules/font/font.h index a4239578e..01d78f0ec 100644 --- a/src/modules/font/font.h +++ b/src/modules/font/font.h @@ -6,8 +6,4 @@ void ffPrintFont(FFFontOptions* options); void ffInitFontOptions(FFFontOptions* options); -bool ffParseFontCommandOptions(FFFontOptions* options, const char* key, const char* value); void ffDestroyFontOptions(FFFontOptions* options); -void ffParseFontJsonObject(FFFontOptions* options, yyjson_val* module); -void ffGenerateFontJsonResult(FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintFontHelpFormat(void); diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index a6b8a60cd..39194b30c 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -49,12 +49,6 @@ void ffPrintGamepad(FFGamepadOptions* options) } } -void ffInitGamepadOptions(FFGamepadOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GAMEPAD_MODULE_NAME, ffParseGamepadCommandOptions, ffParseGamepadJsonObject, ffPrintGamepad, ffGenerateGamepadJsonResult, ffPrintGamepadHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseGamepadCommandOptions(FFGamepadOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_GAMEPAD_MODULE_NAME); @@ -65,11 +59,6 @@ bool ffParseGamepadCommandOptions(FFGamepadOptions* options, const char* key, co return false; } -void ffDestroyGamepadOptions(FFGamepadOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -127,3 +116,14 @@ void ffPrintGamepadHelpFormat(void) "Identifier" }); } + +void ffInitGamepadOptions(FFGamepadOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GAMEPAD_MODULE_NAME, ffParseGamepadCommandOptions, ffParseGamepadJsonObject, ffPrintGamepad, ffGenerateGamepadJsonResult, ffPrintGamepadHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyGamepadOptions(FFGamepadOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/gamepad/gamepad.h b/src/modules/gamepad/gamepad.h index cd37d9144..309edd0a7 100644 --- a/src/modules/gamepad/gamepad.h +++ b/src/modules/gamepad/gamepad.h @@ -6,8 +6,4 @@ void ffPrintGamepad(FFGamepadOptions* options); void ffInitGamepadOptions(FFGamepadOptions* options); -bool ffParseGamepadCommandOptions(FFGamepadOptions* options, const char* key, const char* value); void ffDestroyGamepadOptions(FFGamepadOptions* options); -void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module); -void ffGenerateGamepadJsonResult(FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintGamepadHelpFormat(void); diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 84412b0a1..3189549fa 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -123,16 +123,6 @@ void ffPrintGPU(FFGPUOptions* options) } } -void ffInitGPUOptions(FFGPUOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GPU_MODULE_NAME, ffParseGPUCommandOptions, ffParseGPUJsonObject, ffPrintGPU, ffGenerateGPUJsonResult, ffPrintGPUHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - options->forceVulkan = false; - options->temp = false; - options->hideType = FF_GPU_TYPE_UNKNOWN; -} - bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_GPU_MODULE_NAME); @@ -165,11 +155,6 @@ bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char return false; } -void ffDestroyGPUOptions(FFGPUOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -297,3 +282,18 @@ void ffPrintGPUHelpFormat(void) "GPU used shared memory", }); } + +void ffInitGPUOptions(FFGPUOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GPU_MODULE_NAME, ffParseGPUCommandOptions, ffParseGPUJsonObject, ffPrintGPU, ffGenerateGPUJsonResult, ffPrintGPUHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + options->forceVulkan = false; + options->temp = false; + options->hideType = FF_GPU_TYPE_UNKNOWN; +} + +void ffDestroyGPUOptions(FFGPUOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/gpu/gpu.h b/src/modules/gpu/gpu.h index 575e1bd67..36dbd441d 100644 --- a/src/modules/gpu/gpu.h +++ b/src/modules/gpu/gpu.h @@ -6,8 +6,4 @@ void ffPrintGPU(FFGPUOptions* options); void ffInitGPUOptions(FFGPUOptions* options); -bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char* value); void ffDestroyGPUOptions(FFGPUOptions* options); -void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module); -void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintGPUHelpFormat(void); diff --git a/src/modules/host/host.c b/src/modules/host/host.c index 9705351de..28c5ab5f3 100644 --- a/src/modules/host/host.c +++ b/src/modules/host/host.c @@ -65,12 +65,6 @@ exit: ffStrbufDestroy(&host.sysVendor); } -void ffInitHostOptions(FFHostOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_HOST_MODULE_NAME, ffParseHostCommandOptions, ffParseHostJsonObject, ffPrintHost, ffGenerateHostJsonResult, ffPrintHostHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseHostCommandOptions(FFHostOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_HOST_MODULE_NAME); @@ -81,11 +75,6 @@ bool ffParseHostCommandOptions(FFHostOptions* options, const char* key, const ch return false; } -void ffDestroyHostOptions(FFHostOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseHostJsonObject(FFHostOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -150,3 +139,14 @@ void ffPrintHostHelpFormat(void) "sys vendor" }); } + +void ffInitHostOptions(FFHostOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_HOST_MODULE_NAME, ffParseHostCommandOptions, ffParseHostJsonObject, ffPrintHost, ffGenerateHostJsonResult, ffPrintHostHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyHostOptions(FFHostOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/host/host.h b/src/modules/host/host.h index 3e0aa150e..780849bf2 100644 --- a/src/modules/host/host.h +++ b/src/modules/host/host.h @@ -6,8 +6,4 @@ void ffPrintHost(FFHostOptions* options); void ffInitHostOptions(FFHostOptions* options); -bool ffParseHostCommandOptions(FFHostOptions* options, const char* key, const char* value); void ffDestroyHostOptions(FFHostOptions* options); -void ffParseHostJsonObject(FFHostOptions* options, yyjson_val* module); -void ffGenerateHostJsonResult(FFHostOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintHostHelpFormat(void); diff --git a/src/modules/icons/icons.c b/src/modules/icons/icons.c index 646df67ea..eff569649 100644 --- a/src/modules/icons/icons.c +++ b/src/modules/icons/icons.c @@ -30,12 +30,6 @@ void ffPrintIcons(FFIconsOptions* options) } } -void ffInitIconsOptions(FFIconsOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_ICONS_MODULE_NAME, ffParseIconsCommandOptions, ffParseIconsJsonObject, ffPrintIcons, ffGenerateIconsJsonResult, ffPrintIconsHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseIconsCommandOptions(FFIconsOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_ICONS_MODULE_NAME); @@ -46,11 +40,6 @@ bool ffParseIconsCommandOptions(FFIconsOptions* options, const char* key, const return false; } -void ffDestroyIconsOptions(FFIconsOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseIconsJsonObject(FFIconsOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -88,3 +77,14 @@ void ffPrintIconsHelpFormat(void) "Combined icons" }); } + +void ffInitIconsOptions(FFIconsOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_ICONS_MODULE_NAME, ffParseIconsCommandOptions, ffParseIconsJsonObject, ffPrintIcons, ffGenerateIconsJsonResult, ffPrintIconsHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyIconsOptions(FFIconsOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/icons/icons.h b/src/modules/icons/icons.h index 5c390c577..d31a83a9a 100644 --- a/src/modules/icons/icons.h +++ b/src/modules/icons/icons.h @@ -6,8 +6,4 @@ void ffPrintIcons(FFIconsOptions* options); void ffInitIconsOptions(FFIconsOptions* options); -bool ffParseIconsCommandOptions(FFIconsOptions* options, const char* key, const char* value); void ffDestroyIconsOptions(FFIconsOptions* options); -void ffParseIconsJsonObject(FFIconsOptions* options, yyjson_val* module); -void ffGenerateIconsJsonResult(FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintIconsHelpFormat(void); diff --git a/src/modules/kernel/kernel.c b/src/modules/kernel/kernel.c index bd6acaa37..4fab5cd7d 100644 --- a/src/modules/kernel/kernel.c +++ b/src/modules/kernel/kernel.c @@ -30,12 +30,6 @@ void ffPrintKernel(FFKernelOptions* options) } } -void ffInitKernelOptions(FFKernelOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_KERNEL_MODULE_NAME, ffParseKernelCommandOptions, ffParseKernelJsonObject, ffPrintKernel, ffGenerateKernelJsonResult, ffPrintKernelHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseKernelCommandOptions(FFKernelOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_KERNEL_MODULE_NAME); @@ -46,11 +40,6 @@ bool ffParseKernelCommandOptions(FFKernelOptions* options, const char* key, cons return false; } -void ffDestroyKernelOptions(FFKernelOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseKernelJsonObject(FFKernelOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -86,3 +75,14 @@ void ffPrintKernelHelpFormat(void) "Kernel version" }); } + +void ffInitKernelOptions(FFKernelOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_KERNEL_MODULE_NAME, ffParseKernelCommandOptions, ffParseKernelJsonObject, ffPrintKernel, ffGenerateKernelJsonResult, ffPrintKernelHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyKernelOptions(FFKernelOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/kernel/kernel.h b/src/modules/kernel/kernel.h index 523c8caa7..c1a6be856 100644 --- a/src/modules/kernel/kernel.h +++ b/src/modules/kernel/kernel.h @@ -6,8 +6,4 @@ void ffPrintKernel(FFKernelOptions* options); void ffInitKernelOptions(FFKernelOptions* options); -bool ffParseKernelCommandOptions(FFKernelOptions* options, const char* key, const char* value); void ffDestroyKernelOptions(FFKernelOptions* options); -void ffParseKernelJsonObject(FFKernelOptions* options, yyjson_val* module); -void ffGenerateKernelJsonResult(FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintKernelHelpFormat(void); diff --git a/src/modules/lm/lm.c b/src/modules/lm/lm.c index e44279cb4..95aa56896 100644 --- a/src/modules/lm/lm.c +++ b/src/modules/lm/lm.c @@ -49,12 +49,6 @@ void ffPrintLM(FFLMOptions* options) ffStrbufDestroy(&result.version); } -void ffInitLMOptions(FFLMOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LM_MODULE_NAME, ffParseLMCommandOptions, ffParseLMJsonObject, ffPrintLM, ffGenerateLMJsonResult, ffPrintLMHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseLMCommandOptions(FFLMOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_LM_MODULE_NAME); @@ -65,11 +59,6 @@ bool ffParseLMCommandOptions(FFLMOptions* options, const char* key, const char* return false; } -void ffDestroyLMOptions(FFLMOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -126,3 +115,14 @@ void ffPrintLMHelpFormat(void) "LM version" }); } + +void ffInitLMOptions(FFLMOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LM_MODULE_NAME, ffParseLMCommandOptions, ffParseLMJsonObject, ffPrintLM, ffGenerateLMJsonResult, ffPrintLMHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyLMOptions(FFLMOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/lm/lm.h b/src/modules/lm/lm.h index b234acad8..f6e1569e1 100644 --- a/src/modules/lm/lm.h +++ b/src/modules/lm/lm.h @@ -6,8 +6,4 @@ void ffPrintLM(FFLMOptions* options); void ffInitLMOptions(FFLMOptions* options); -bool ffParseLMCommandOptions(FFLMOptions* options, const char* key, const char* value); void ffDestroyLMOptions(FFLMOptions* options); -void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module); -void ffGenerateLMJsonResult(FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintLMHelpFormat(void); diff --git a/src/modules/locale/locale.c b/src/modules/locale/locale.c index 31b03ef0a..18e4e67a7 100644 --- a/src/modules/locale/locale.c +++ b/src/modules/locale/locale.c @@ -30,12 +30,6 @@ void ffPrintLocale(FFLocaleOptions* options) } } -void ffInitLocaleOptions(FFLocaleOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALE_MODULE_NAME, ffParseLocaleCommandOptions, ffParseLocaleJsonObject, ffPrintLocale, ffGenerateLocaleJsonResult, ffPrintLocaleHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseLocaleCommandOptions(FFLocaleOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_LOCALE_MODULE_NAME); @@ -46,11 +40,6 @@ bool ffParseLocaleCommandOptions(FFLocaleOptions* options, const char* key, cons return false; } -void ffDestroyLocaleOptions(FFLocaleOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseLocaleJsonObject(FFLocaleOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -88,3 +77,14 @@ void ffPrintLocaleHelpFormat(void) "Locale code" }); } + +void ffInitLocaleOptions(FFLocaleOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALE_MODULE_NAME, ffParseLocaleCommandOptions, ffParseLocaleJsonObject, ffPrintLocale, ffGenerateLocaleJsonResult, ffPrintLocaleHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyLocaleOptions(FFLocaleOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/locale/locale.h b/src/modules/locale/locale.h index 451995b82..c1fe3f8f7 100644 --- a/src/modules/locale/locale.h +++ b/src/modules/locale/locale.h @@ -6,8 +6,4 @@ void ffPrintLocale(FFLocaleOptions* options); void ffInitLocaleOptions(FFLocaleOptions* options); -bool ffParseLocaleCommandOptions(FFLocaleOptions* options, const char* key, const char* value); void ffDestroyLocaleOptions(FFLocaleOptions* options); -void ffParseLocaleJsonObject(FFLocaleOptions* options, yyjson_val* module); -void ffGenerateLocaleJsonResult(FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintLocaleHelpFormat(void); diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index fc70f8479..f95b1cfc0 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -131,16 +131,6 @@ void ffPrintLocalIp(FFLocalIpOptions* options) } } -void ffInitLocalIpOptions(FFLocalIpOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALIP_MODULE_NAME, ffParseLocalIpCommandOptions, ffParseLocalIpJsonObject, ffPrintLocalIp, ffGenerateLocalIpJsonResult, ffPrintLocalIpHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - options->showType = FF_LOCALIP_TYPE_IPV4_BIT; - ffStrbufInit(&options->namePrefix); - options->defaultRouteOnly = false; -} - bool ffParseLocalIpCommandOptions(FFLocalIpOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_LOCALIP_MODULE_NAME); @@ -208,12 +198,6 @@ bool ffParseLocalIpCommandOptions(FFLocalIpOptions* options, const char* key, co return false; } -void ffDestroyLocalIpOptions(FFLocalIpOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); - ffStrbufDestroy(&options->namePrefix); -} - void ffParseLocalIpJsonObject(FFLocalIpOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -337,3 +321,19 @@ void ffPrintLocalIpHelpFormat(void) "Is default route" }); } + +void ffInitLocalIpOptions(FFLocalIpOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALIP_MODULE_NAME, ffParseLocalIpCommandOptions, ffParseLocalIpJsonObject, ffPrintLocalIp, ffGenerateLocalIpJsonResult, ffPrintLocalIpHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + options->showType = FF_LOCALIP_TYPE_IPV4_BIT; + ffStrbufInit(&options->namePrefix); + options->defaultRouteOnly = false; +} + +void ffDestroyLocalIpOptions(FFLocalIpOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); + ffStrbufDestroy(&options->namePrefix); +} diff --git a/src/modules/localip/localip.h b/src/modules/localip/localip.h index ee07ebdb1..1ac255979 100644 --- a/src/modules/localip/localip.h +++ b/src/modules/localip/localip.h @@ -6,8 +6,4 @@ void ffPrintLocalIp(FFLocalIpOptions* options); void ffInitLocalIpOptions(FFLocalIpOptions* options); -bool ffParseLocalIpCommandOptions(FFLocalIpOptions* options, const char* key, const char* value); void ffDestroyLocalIpOptions(FFLocalIpOptions* options); -void ffParseLocalIpJsonObject(FFLocalIpOptions* options, yyjson_val* module); -void ffGenerateLocalIpJsonResult(FFLocalIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintLocalIpHelpFormat(void); diff --git a/src/modules/media/media.c b/src/modules/media/media.c index 472404e4d..7769dc4fa 100644 --- a/src/modules/media/media.c +++ b/src/modules/media/media.c @@ -105,12 +105,6 @@ void ffPrintMedia(FFMediaOptions* options) } } -void ffInitMediaOptions(FFMediaOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEDIA_MODULE_NAME, ffParseMediaCommandOptions, ffParseMediaJsonObject, ffPrintMedia, ffGenerateMediaJsonResult, ffPrintMediaHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseMediaCommandOptions(FFMediaOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_MEDIA_MODULE_NAME); @@ -121,11 +115,6 @@ bool ffParseMediaCommandOptions(FFMediaOptions* options, const char* key, const return false; } -void ffDestroyMediaOptions(FFMediaOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseMediaJsonObject(FFMediaOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -170,3 +159,14 @@ void ffPrintMediaHelpFormat(void) "Status", }); } + +void ffInitMediaOptions(FFMediaOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEDIA_MODULE_NAME, ffParseMediaCommandOptions, ffParseMediaJsonObject, ffPrintMedia, ffGenerateMediaJsonResult, ffPrintMediaHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyMediaOptions(FFMediaOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/media/media.h b/src/modules/media/media.h index c0e581bdb..7c010b1fe 100644 --- a/src/modules/media/media.h +++ b/src/modules/media/media.h @@ -6,8 +6,4 @@ void ffPrintMedia(FFMediaOptions* options); void ffInitMediaOptions(FFMediaOptions* options); -bool ffParseMediaCommandOptions(FFMediaOptions* options, const char* key, const char* value); void ffDestroyMediaOptions(FFMediaOptions* options); -void ffParseMediaJsonObject(FFMediaOptions* options, yyjson_val* module); -void ffGenerateMediaJsonResult(FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintMediaHelpFormat(void); diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 44156a52e..018ab2def 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -66,12 +66,6 @@ void ffPrintMemory(FFMemoryOptions* options) } } -void ffInitMemoryOptions(FFMemoryOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEMORY_MODULE_NAME, ffParseMemoryCommandOptions, ffParseMemoryJsonObject, ffPrintMemory, ffGenerateMemoryJsonResult, ffPrintMemoryHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseMemoryCommandOptions(FFMemoryOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_MEMORY_MODULE_NAME); @@ -82,11 +76,6 @@ bool ffParseMemoryCommandOptions(FFMemoryOptions* options, const char* key, cons return false; } -void ffDestroyMemoryOptions(FFMemoryOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -128,3 +117,14 @@ void ffPrintMemoryHelpFormat(void) "Percentage used" }); } + +void ffInitMemoryOptions(FFMemoryOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEMORY_MODULE_NAME, ffParseMemoryCommandOptions, ffParseMemoryJsonObject, ffPrintMemory, ffGenerateMemoryJsonResult, ffPrintMemoryHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyMemoryOptions(FFMemoryOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/memory/memory.h b/src/modules/memory/memory.h index ffdeb45fa..dcef5e50d 100644 --- a/src/modules/memory/memory.h +++ b/src/modules/memory/memory.h @@ -6,8 +6,4 @@ void ffPrintMemory(FFMemoryOptions* options); void ffInitMemoryOptions(FFMemoryOptions* options); -bool ffParseMemoryCommandOptions(FFMemoryOptions* options, const char* key, const char* value); void ffDestroyMemoryOptions(FFMemoryOptions* options); -void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module); -void ffGenerateMemoryJsonResult(FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintMemoryHelpFormat(void); diff --git a/src/modules/monitor/monitor.c b/src/modules/monitor/monitor.c index 732a4ef4e..cd42ddf35 100644 --- a/src/modules/monitor/monitor.c +++ b/src/modules/monitor/monitor.c @@ -75,12 +75,6 @@ void ffPrintMonitor(FFMonitorOptions* options) } } -void ffInitMonitorOptions(FFMonitorOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MONITOR_MODULE_NAME, ffParseMonitorCommandOptions, ffParseMonitorJsonObject, ffPrintMonitor, ffGenerateMonitorJsonResult, ffPrintMonitorHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseMonitorCommandOptions(FFMonitorOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_MONITOR_MODULE_NAME); @@ -91,11 +85,6 @@ bool ffParseMonitorCommandOptions(FFMonitorOptions* options, const char* key, co return false; } -void ffDestroyMonitorOptions(FFMonitorOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseMonitorJsonObject(FFMonitorOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -160,3 +149,14 @@ void ffPrintMonitorHelpFormat(void) "Display physical pixels per inch (PPI)" }); } + +void ffInitMonitorOptions(FFMonitorOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MONITOR_MODULE_NAME, ffParseMonitorCommandOptions, ffParseMonitorJsonObject, ffPrintMonitor, ffGenerateMonitorJsonResult, ffPrintMonitorHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyMonitorOptions(FFMonitorOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/monitor/monitor.h b/src/modules/monitor/monitor.h index 3d860df02..d928c2ffe 100644 --- a/src/modules/monitor/monitor.h +++ b/src/modules/monitor/monitor.h @@ -6,8 +6,4 @@ void ffPrintMonitor(FFMonitorOptions* options); void ffInitMonitorOptions(FFMonitorOptions* options); -bool ffParseMonitorCommandOptions(FFMonitorOptions* options, const char* key, const char* value); void ffDestroyMonitorOptions(FFMonitorOptions* options); -void ffParseMonitorJsonObject(FFMonitorOptions* options, yyjson_val* module); -void ffGenerateMonitorJsonResult(FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintMonitorHelpFormat(void); diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index 490ad93d1..8f76365fd 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -99,15 +99,6 @@ void ffPrintNetIO(FFNetIOOptions* options) } } -void ffInitNetIOOptions(FFNetIOOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_NETIO_MODULE_NAME, ffParseNetIOCommandOptions, ffParseNetIOJsonObject, ffPrintNetIO, ffGenerateNetIOJsonResult, ffPrintNetIOHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - ffStrbufInit(&options->namePrefix); - options->defaultRouteOnly = false; -} - bool ffParseNetIOCommandOptions(FFNetIOOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_NETIO_MODULE_NAME); @@ -130,12 +121,6 @@ bool ffParseNetIOCommandOptions(FFNetIOOptions* options, const char* key, const return false; } -void ffDestroyNetIOOptions(FFNetIOOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); - ffStrbufDestroy(&options->namePrefix); -} - void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -215,3 +200,18 @@ void ffPrintNetIOHelpFormat(void) "Number of packets dropped when sending per second", }); } + +void ffInitNetIOOptions(FFNetIOOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_NETIO_MODULE_NAME, ffParseNetIOCommandOptions, ffParseNetIOJsonObject, ffPrintNetIO, ffGenerateNetIOJsonResult, ffPrintNetIOHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + ffStrbufInit(&options->namePrefix); + options->defaultRouteOnly = false; +} + +void ffDestroyNetIOOptions(FFNetIOOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); + ffStrbufDestroy(&options->namePrefix); +} diff --git a/src/modules/netio/netio.h b/src/modules/netio/netio.h index aead4d6e0..5b94e4bf2 100644 --- a/src/modules/netio/netio.h +++ b/src/modules/netio/netio.h @@ -8,8 +8,4 @@ void ffPrepareNetIO(FFNetIOOptions* options); void ffPrintNetIO(FFNetIOOptions* options); void ffInitNetIOOptions(FFNetIOOptions* options); -bool ffParseNetIOCommandOptions(FFNetIOOptions* options, const char* key, const char* value); void ffDestroyNetIOOptions(FFNetIOOptions* options); -void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module); -void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintNetIOHelpFormat(void); diff --git a/src/modules/opencl/opencl.c b/src/modules/opencl/opencl.c index b4a2e9a73..fd9015cb3 100644 --- a/src/modules/opencl/opencl.c +++ b/src/modules/opencl/opencl.c @@ -39,12 +39,6 @@ void ffPrintOpenCL(FFOpenCLOptions* options) ffStrbufDestroy(&opencl.vendor); } -void ffInitOpenCLOptions(FFOpenCLOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENCL_MODULE_NAME, ffParseOpenCLCommandOptions, ffParseOpenCLJsonObject, ffPrintOpenCL, ffGenerateOpenCLJsonResult, ffPrintOpenCLHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseOpenCLCommandOptions(FFOpenCLOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_OPENCL_MODULE_NAME); @@ -55,11 +49,6 @@ bool ffParseOpenCLCommandOptions(FFOpenCLOptions* options, const char* key, cons return false; } -void ffDestroyOpenCLOptions(FFOpenCLOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseOpenCLJsonObject(FFOpenCLOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -111,3 +100,14 @@ void ffPrintOpenCLHelpFormat(void) "vendor" }); } + +void ffInitOpenCLOptions(FFOpenCLOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENCL_MODULE_NAME, ffParseOpenCLCommandOptions, ffParseOpenCLJsonObject, ffPrintOpenCL, ffGenerateOpenCLJsonResult, ffPrintOpenCLHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyOpenCLOptions(FFOpenCLOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/opencl/opencl.h b/src/modules/opencl/opencl.h index 5a9bc3573..f378e3f0b 100644 --- a/src/modules/opencl/opencl.h +++ b/src/modules/opencl/opencl.h @@ -6,8 +6,4 @@ void ffPrintOpenCL(FFOpenCLOptions* options); 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 ffGenerateOpenCLJsonResult(FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintOpenCLHelpFormat(void); diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index 9c6f949c8..b579c7526 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -42,16 +42,6 @@ void ffPrintOpenGL(FFOpenGLOptions* options) ffStrbufDestroy(&result.slv); } -void ffInitOpenGLOptions(FFOpenGLOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENGL_MODULE_NAME, ffParseOpenGLCommandOptions, ffParseOpenGLJsonObject, ffPrintOpenGL, ffGenerateOpenGLJsonResult, ffPrintOpenGLHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - #if defined(__linux__) || defined(__FreeBSD__) - options->library = FF_OPENGL_LIBRARY_AUTO; - #endif -} - bool ffParseOpenGLCommandOptions(FFOpenGLOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_OPENGL_MODULE_NAME); @@ -75,11 +65,6 @@ bool ffParseOpenGLCommandOptions(FFOpenGLOptions* options, const char* key, cons return false; } -void ffDestroyOpenGLOptions(FFOpenGLOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -153,3 +138,18 @@ void ffPrintOpenGLHelpFormat(void) "shading language version" }); } + +void ffInitOpenGLOptions(FFOpenGLOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENGL_MODULE_NAME, ffParseOpenGLCommandOptions, ffParseOpenGLJsonObject, ffPrintOpenGL, ffGenerateOpenGLJsonResult, ffPrintOpenGLHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + #if defined(__linux__) || defined(__FreeBSD__) + options->library = FF_OPENGL_LIBRARY_AUTO; + #endif +} + +void ffDestroyOpenGLOptions(FFOpenGLOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/opengl/opengl.h b/src/modules/opengl/opengl.h index e94b5b7fb..0f9d34735 100644 --- a/src/modules/opengl/opengl.h +++ b/src/modules/opengl/opengl.h @@ -6,8 +6,4 @@ void ffPrintOpenGL(FFOpenGLOptions* options); void ffInitOpenGLOptions(FFOpenGLOptions* options); -bool ffParseOpenGLCommandOptions(FFOpenGLOptions* options, const char* key, const char* value); void ffDestroyOpenGLOptions(FFOpenGLOptions* options); -void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module); -void ffGenerateOpenGLJsonResult(FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintOpenGLHelpFormat(void); diff --git a/src/modules/os/os.c b/src/modules/os/os.c index d969805f6..037c769ca 100644 --- a/src/modules/os/os.c +++ b/src/modules/os/os.c @@ -136,12 +136,6 @@ void ffPrintOS(FFOSOptions* options) } } -void ffInitOSOptions(FFOSOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OS_MODULE_NAME, ffParseOSCommandOptions, ffParseOSJsonObject, ffPrintOS, ffGenerateOSJsonResult, ffPrintOSHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseOSCommandOptions(FFOSOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_OS_MODULE_NAME); @@ -152,11 +146,6 @@ bool ffParseOSCommandOptions(FFOSOptions* options, const char* key, const char* return false; } -void ffDestroyOSOptions(FFOSOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseOSJsonObject(FFOSOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -214,3 +203,14 @@ void ffPrintOSHelpFormat(void) "Architecture of the OS" }); } + +void ffInitOSOptions(FFOSOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OS_MODULE_NAME, ffParseOSCommandOptions, ffParseOSJsonObject, ffPrintOS, ffGenerateOSJsonResult, ffPrintOSHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyOSOptions(FFOSOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/os/os.h b/src/modules/os/os.h index db357d70c..ff2aa787d 100644 --- a/src/modules/os/os.h +++ b/src/modules/os/os.h @@ -6,8 +6,4 @@ void ffPrintOS(FFOSOptions* options); void ffInitOSOptions(FFOSOptions* options); -bool ffParseOSCommandOptions(FFOSOptions* options, const char* key, const char* value); void ffDestroyOSOptions(FFOSOptions* options); -void ffParseOSJsonObject(FFOSOptions* options, yyjson_val* module); -void ffGenerateOSJsonResult(FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintOSHelpFormat(void); diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index 42fdd724f..be900d904 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -102,12 +102,6 @@ void ffPrintPackages(FFPackagesOptions* options) ffStrbufDestroy(&counts.pacmanBranch); } -void ffInitPackagesOptions(FFPackagesOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PACKAGES_MODULE_NAME, ffParsePackagesCommandOptions, ffParsePackagesJsonObject, ffPrintPackages, ffGeneratePackagesJsonResult, ffPrintPackagesHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParsePackagesCommandOptions(FFPackagesOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_PACKAGES_MODULE_NAME); @@ -118,11 +112,6 @@ bool ffParsePackagesCommandOptions(FFPackagesOptions* options, const char* key, return false; } -void ffDestroyPackagesOptions(FFPackagesOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -214,3 +203,14 @@ void ffPrintPackagesHelpFormat(void) "Number of opkg packages" }); } + +void ffInitPackagesOptions(FFPackagesOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PACKAGES_MODULE_NAME, ffParsePackagesCommandOptions, ffParsePackagesJsonObject, ffPrintPackages, ffGeneratePackagesJsonResult, ffPrintPackagesHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyPackagesOptions(FFPackagesOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/packages/packages.h b/src/modules/packages/packages.h index 426e7fe47..97b8b4c91 100644 --- a/src/modules/packages/packages.h +++ b/src/modules/packages/packages.h @@ -6,8 +6,4 @@ void ffPrintPackages(FFPackagesOptions* options); void ffInitPackagesOptions(FFPackagesOptions* options); -bool ffParsePackagesCommandOptions(FFPackagesOptions* options, const char* key, const char* value); void ffDestroyPackagesOptions(FFPackagesOptions* options); -void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module); -void ffGeneratePackagesJsonResult(FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintPackagesHelpFormat(void); diff --git a/src/modules/player/player.c b/src/modules/player/player.c index 77898b364..ff0860f63 100644 --- a/src/modules/player/player.c +++ b/src/modules/player/player.c @@ -73,12 +73,6 @@ void ffPrintPlayer(FFPlayerOptions* options) } } -void ffInitPlayerOptions(FFPlayerOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PLAYER_MODULE_NAME, ffParsePlayerCommandOptions, ffParsePlayerJsonObject, ffPrintPlayer, ffGeneratePlayerJsonResult, ffPrintPlayerHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParsePlayerCommandOptions(FFPlayerOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_PLAYER_MODULE_NAME); @@ -89,11 +83,6 @@ bool ffParsePlayerCommandOptions(FFPlayerOptions* options, const char* key, cons return false; } -void ffDestroyPlayerOptions(FFPlayerOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParsePlayerJsonObject(FFPlayerOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -136,3 +125,14 @@ void ffPrintPlayerHelpFormat(void) "URL name" }); } + +void ffInitPlayerOptions(FFPlayerOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PLAYER_MODULE_NAME, ffParsePlayerCommandOptions, ffParsePlayerJsonObject, ffPrintPlayer, ffGeneratePlayerJsonResult, ffPrintPlayerHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyPlayerOptions(FFPlayerOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/player/player.h b/src/modules/player/player.h index d2e4ea140..3912a3fe3 100644 --- a/src/modules/player/player.h +++ b/src/modules/player/player.h @@ -7,8 +7,4 @@ void ffPrintPlayer(FFPlayerOptions* options); void ffInitPlayerOptions(FFPlayerOptions* options); -bool ffParsePlayerCommandOptions(FFPlayerOptions* options, const char* key, const char* value); void ffDestroyPlayerOptions(FFPlayerOptions* options); -void ffParsePlayerJsonObject(FFPlayerOptions* options, yyjson_val* module); -void ffGeneratePlayerJsonResult(FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintPlayerHelpFormat(void); diff --git a/src/modules/poweradapter/poweradapter.c b/src/modules/poweradapter/poweradapter.c index 2cd639c42..626861b22 100644 --- a/src/modules/poweradapter/poweradapter.c +++ b/src/modules/poweradapter/poweradapter.c @@ -60,12 +60,6 @@ void ffPrintPowerAdapter(FFPowerAdapterOptions* options) } } -void ffInitPowerAdapterOptions(FFPowerAdapterOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_POWERADAPTER_MODULE_NAME, ffParsePowerAdapterCommandOptions, ffParsePowerAdapterJsonObject, ffPrintPowerAdapter, ffGeneratePowerAdapterJsonResult, ffPrintPowerAdapterHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParsePowerAdapterCommandOptions(FFPowerAdapterOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_POWERADAPTER_MODULE_NAME); @@ -76,11 +70,6 @@ bool ffParsePowerAdapterCommandOptions(FFPowerAdapterOptions* options, const cha return false; } -void ffDestroyPowerAdapterOptions(FFPowerAdapterOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParsePowerAdapterJsonObject(FFPowerAdapterOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -137,3 +126,14 @@ void ffPrintPowerAdapterHelpFormat(void) "PowerAdapter description" }); } + +void ffInitPowerAdapterOptions(FFPowerAdapterOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_POWERADAPTER_MODULE_NAME, ffParsePowerAdapterCommandOptions, ffParsePowerAdapterJsonObject, ffPrintPowerAdapter, ffGeneratePowerAdapterJsonResult, ffPrintPowerAdapterHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyPowerAdapterOptions(FFPowerAdapterOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/poweradapter/poweradapter.h b/src/modules/poweradapter/poweradapter.h index 58b18e601..315c6e749 100644 --- a/src/modules/poweradapter/poweradapter.h +++ b/src/modules/poweradapter/poweradapter.h @@ -6,8 +6,4 @@ void ffPrintPowerAdapter(FFPowerAdapterOptions* options); void ffInitPowerAdapterOptions(FFPowerAdapterOptions* options); -bool ffParsePowerAdapterCommandOptions(FFPowerAdapterOptions* options, const char* key, const char* value); void ffDestroyPowerAdapterOptions(FFPowerAdapterOptions* options); -void ffParsePowerAdapterJsonObject(FFPowerAdapterOptions* options, yyjson_val* module); -void ffGeneratePowerAdapterJsonResult(FFPowerAdapterOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintPowerAdapterHelpFormat(void); diff --git a/src/modules/processes/processes.c b/src/modules/processes/processes.c index e6bda6004..ea9517234 100644 --- a/src/modules/processes/processes.c +++ b/src/modules/processes/processes.c @@ -31,12 +31,6 @@ void ffPrintProcesses(FFProcessesOptions* options) } } -void ffInitProcessesOptions(FFProcessesOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PROCESSES_MODULE_NAME, ffParseProcessesCommandOptions, ffParseProcessesJsonObject, ffPrintProcesses, ffGenerateProcessesJsonResult, ffPrintProcessesHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseProcessesCommandOptions(FFProcessesOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_PROCESSES_MODULE_NAME); @@ -47,11 +41,6 @@ bool ffParseProcessesCommandOptions(FFProcessesOptions* options, const char* key return false; } -void ffDestroyProcessesOptions(FFProcessesOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseProcessesJsonObject(FFProcessesOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -89,3 +78,14 @@ void ffPrintProcessesHelpFormat(void) "Count" }); } + +void ffInitProcessesOptions(FFProcessesOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PROCESSES_MODULE_NAME, ffParseProcessesCommandOptions, ffParseProcessesJsonObject, ffPrintProcesses, ffGenerateProcessesJsonResult, ffPrintProcessesHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyProcessesOptions(FFProcessesOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/processes/processes.h b/src/modules/processes/processes.h index 74ae83e45..d2159ca0e 100644 --- a/src/modules/processes/processes.h +++ b/src/modules/processes/processes.h @@ -6,8 +6,4 @@ void ffPrintProcesses(FFProcessesOptions* options); void ffInitProcessesOptions(FFProcessesOptions* options); -bool ffParseProcessesCommandOptions(FFProcessesOptions* options, const char* key, const char* value); void ffDestroyProcessesOptions(FFProcessesOptions* options); -void ffParseProcessesJsonObject(FFProcessesOptions* options, yyjson_val* module); -void ffGenerateProcessesJsonResult(FFProcessesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintProcessesHelpFormat(void); diff --git a/src/modules/publicip/publicip.c b/src/modules/publicip/publicip.c index a815a9935..7a469536e 100644 --- a/src/modules/publicip/publicip.c +++ b/src/modules/publicip/publicip.c @@ -40,15 +40,6 @@ void ffPrintPublicIp(FFPublicIpOptions* options) ffStrbufDestroy(&result.location); } -void ffInitPublicIpOptions(FFPublicIpOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PUBLICIP_MODULE_NAME, ffParsePublicIpCommandOptions, ffParsePublicIpJsonObject, ffPrintPublicIp, ffGeneratePublicIpJsonResult, ffPrintPublicIpHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - ffStrbufInit(&options->url); - options->timeout = 0; -} - bool ffParsePublicIpCommandOptions(FFPublicIpOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_PUBLICIP_MODULE_NAME); @@ -71,13 +62,6 @@ bool ffParsePublicIpCommandOptions(FFPublicIpOptions* options, const char* key, return false; } -void ffDestroyPublicIpOptions(FFPublicIpOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); - - ffStrbufDestroy(&options->url); -} - void ffParsePublicIpJsonObject(FFPublicIpOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -135,3 +119,19 @@ void ffPrintPublicIpHelpFormat(void) "Location" }); } + +void ffInitPublicIpOptions(FFPublicIpOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PUBLICIP_MODULE_NAME, ffParsePublicIpCommandOptions, ffParsePublicIpJsonObject, ffPrintPublicIp, ffGeneratePublicIpJsonResult, ffPrintPublicIpHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + ffStrbufInit(&options->url); + options->timeout = 0; +} + +void ffDestroyPublicIpOptions(FFPublicIpOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); + + ffStrbufDestroy(&options->url); +} diff --git a/src/modules/publicip/publicip.h b/src/modules/publicip/publicip.h index 0b8792382..e54bab809 100644 --- a/src/modules/publicip/publicip.h +++ b/src/modules/publicip/publicip.h @@ -8,8 +8,4 @@ void ffPreparePublicIp(FFPublicIpOptions* options); void ffPrintPublicIp(FFPublicIpOptions* options); void ffInitPublicIpOptions(FFPublicIpOptions* options); -bool ffParsePublicIpCommandOptions(FFPublicIpOptions* options, const char* key, const char* value); void ffDestroyPublicIpOptions(FFPublicIpOptions* options); -void ffParsePublicIpJsonObject(FFPublicIpOptions* options, yyjson_val* module); -void ffGeneratePublicIpJsonResult(FFPublicIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintPublicIpHelpFormat(void); diff --git a/src/modules/separator/separator.c b/src/modules/separator/separator.c index 75cd4eea7..5d0c87e6d 100644 --- a/src/modules/separator/separator.c +++ b/src/modules/separator/separator.c @@ -75,12 +75,6 @@ void ffPrintSeparator(FFSeparatorOptions* options) putchar('\n'); } -void ffInitSeparatorOptions(FFSeparatorOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SEPARATOR_MODULE_NAME, ffParseSeparatorCommandOptions, ffParseSeparatorJsonObject, ffPrintSeparator, NULL, NULL); - ffStrbufInit(&options->string); -} - bool ffParseSeparatorCommandOptions(FFSeparatorOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_SEPARATOR_MODULE_NAME); @@ -95,11 +89,6 @@ bool ffParseSeparatorCommandOptions(FFSeparatorOptions* options, const char* key return false; } -void ffDestroySeparatorOptions(FFSeparatorOptions* options) -{ - ffStrbufDestroy(&options->string); -} - void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -119,3 +108,14 @@ void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module) ffPrintErrorString(FF_SEPARATOR_MODULE_NAME, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "Unknown JSON key %s", key); } } + +void ffInitSeparatorOptions(FFSeparatorOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SEPARATOR_MODULE_NAME, ffParseSeparatorCommandOptions, ffParseSeparatorJsonObject, ffPrintSeparator, NULL, NULL); + ffStrbufInit(&options->string); +} + +void ffDestroySeparatorOptions(FFSeparatorOptions* options) +{ + ffStrbufDestroy(&options->string); +} diff --git a/src/modules/separator/separator.h b/src/modules/separator/separator.h index a5dc91285..bca935521 100644 --- a/src/modules/separator/separator.h +++ b/src/modules/separator/separator.h @@ -6,6 +6,4 @@ void ffPrintSeparator(FFSeparatorOptions* options); void ffInitSeparatorOptions(FFSeparatorOptions* options); -bool ffParseSeparatorCommandOptions(FFSeparatorOptions* options, const char* key, const char* value); void ffDestroySeparatorOptions(FFSeparatorOptions* options); -void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module); diff --git a/src/modules/shell/shell.c b/src/modules/shell/shell.c index 3e63e4523..a74a0eb6e 100644 --- a/src/modules/shell/shell.c +++ b/src/modules/shell/shell.c @@ -42,12 +42,6 @@ void ffPrintShell(FFShellOptions* options) } } -void ffInitShellOptions(FFShellOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SHELL_MODULE_NAME, ffParseShellCommandOptions, ffParseShellJsonObject, ffPrintShell, ffGenerateShellJsonResult, ffPrintShellHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseShellCommandOptions(FFShellOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_SHELL_MODULE_NAME); @@ -58,11 +52,6 @@ bool ffParseShellCommandOptions(FFShellOptions* options, const char* key, const return false; } -void ffDestroyShellOptions(FFShellOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseShellJsonObject(FFShellOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -109,3 +98,14 @@ void ffPrintShellHelpFormat(void) "Shell pretty name" }); } + +void ffInitShellOptions(FFShellOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SHELL_MODULE_NAME, ffParseShellCommandOptions, ffParseShellJsonObject, ffPrintShell, ffGenerateShellJsonResult, ffPrintShellHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyShellOptions(FFShellOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/shell/shell.h b/src/modules/shell/shell.h index dac01eb7c..01f9f17de 100644 --- a/src/modules/shell/shell.h +++ b/src/modules/shell/shell.h @@ -6,8 +6,4 @@ void ffPrintShell(FFShellOptions* options); void ffInitShellOptions(FFShellOptions* options); -bool ffParseShellCommandOptions(FFShellOptions* options, const char* key, const char* value); void ffDestroyShellOptions(FFShellOptions* options); -void ffParseShellJsonObject(FFShellOptions* options, yyjson_val* module); -void ffGenerateShellJsonResult(FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintShellHelpFormat(void); diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 97a6a05ac..2c00a388f 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -83,14 +83,6 @@ void ffPrintSound(FFSoundOptions* options) } -void ffInitSoundOptions(FFSoundOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SOUND_MODULE_NAME, ffParseSoundCommandOptions, ffParseSoundJsonObject, ffPrintSound, ffGenerateSoundJsonResult, ffPrintSoundHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - options->soundType = FF_SOUND_TYPE_MAIN; -} - bool ffParseSoundCommandOptions(FFSoundOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_SOUND_MODULE_NAME); @@ -112,11 +104,6 @@ bool ffParseSoundCommandOptions(FFSoundOptions* options, const char* key, const return false; } -void ffDestroySoundOptions(FFSoundOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseSoundJsonObject(FFSoundOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -199,3 +186,16 @@ void ffPrintSoundHelpFormat(void) "Identifier" }); } + +void ffInitSoundOptions(FFSoundOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SOUND_MODULE_NAME, ffParseSoundCommandOptions, ffParseSoundJsonObject, ffPrintSound, ffGenerateSoundJsonResult, ffPrintSoundHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + options->soundType = FF_SOUND_TYPE_MAIN; +} + +void ffDestroySoundOptions(FFSoundOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/sound/sound.h b/src/modules/sound/sound.h index de90d8472..35c3f2a7b 100644 --- a/src/modules/sound/sound.h +++ b/src/modules/sound/sound.h @@ -6,8 +6,4 @@ void ffPrintSound(FFSoundOptions* options); void ffInitSoundOptions(FFSoundOptions* options); -bool ffParseSoundCommandOptions(FFSoundOptions* options, const char* key, const char* value); void ffDestroySoundOptions(FFSoundOptions* options); -void ffParseSoundJsonObject(FFSoundOptions* options, yyjson_val* module); -void ffGenerateSoundJsonResult(FFSoundOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintSoundHelpFormat(void); diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index 1397ee9fd..d0c3d080a 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -73,12 +73,6 @@ void ffPrintSwap(FFSwapOptions* options) } } -void ffInitSwapOptions(FFSwapOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SWAP_MODULE_NAME, ffParseSwapCommandOptions, ffParseSwapJsonObject, ffPrintSwap, ffGenerateSwapJsonResult, ffPrintSwapHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseSwapCommandOptions(FFSwapOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_SWAP_MODULE_NAME); @@ -89,11 +83,6 @@ bool ffParseSwapCommandOptions(FFSwapOptions* options, const char* key, const ch return false; } -void ffDestroySwapOptions(FFSwapOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseSwapJsonObject(FFSwapOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -135,3 +124,14 @@ void ffPrintSwapHelpFormat(void) "Percentage used" }); } + +void ffInitSwapOptions(FFSwapOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SWAP_MODULE_NAME, ffParseSwapCommandOptions, ffParseSwapJsonObject, ffPrintSwap, ffGenerateSwapJsonResult, ffPrintSwapHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroySwapOptions(FFSwapOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/swap/swap.h b/src/modules/swap/swap.h index 177f503fa..b44ae4df3 100644 --- a/src/modules/swap/swap.h +++ b/src/modules/swap/swap.h @@ -6,8 +6,4 @@ void ffPrintSwap(FFSwapOptions* options); void ffInitSwapOptions(FFSwapOptions* options); -bool ffParseSwapCommandOptions(FFSwapOptions* options, const char* key, const char* value); void ffDestroySwapOptions(FFSwapOptions* options); -void ffParseSwapJsonObject(FFSwapOptions* options, yyjson_val* module); -void ffGenerateSwapJsonResult(FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintSwapHelpFormat(void); diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index 73eb004b0..6cb379575 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -40,12 +40,6 @@ void ffPrintTerminal(FFTerminalOptions* options) } } -void ffInitTerminalOptions(FFTerminalOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINAL_MODULE_NAME, ffParseTerminalCommandOptions, ffParseTerminalJsonObject, ffPrintTerminal, ffGenerateTerminalJsonResult, ffPrintTerminalHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseTerminalCommandOptions(FFTerminalOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_TERMINAL_MODULE_NAME); @@ -56,11 +50,6 @@ bool ffParseTerminalCommandOptions(FFTerminalOptions* options, const char* key, return false; } -void ffDestroyTerminalOptions(FFTerminalOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseTerminalJsonObject(FFTerminalOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -108,3 +97,14 @@ void ffPrintTerminalHelpFormat(void) "Terminal version" }); } + +void ffInitTerminalOptions(FFTerminalOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINAL_MODULE_NAME, ffParseTerminalCommandOptions, ffParseTerminalJsonObject, ffPrintTerminal, ffGenerateTerminalJsonResult, ffPrintTerminalHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyTerminalOptions(FFTerminalOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/terminal/terminal.h b/src/modules/terminal/terminal.h index 0655f86c7..9e1bbf75e 100644 --- a/src/modules/terminal/terminal.h +++ b/src/modules/terminal/terminal.h @@ -6,8 +6,4 @@ void ffPrintTerminal(FFTerminalOptions* options); void ffInitTerminalOptions(FFTerminalOptions* options); -bool ffParseTerminalCommandOptions(FFTerminalOptions* options, const char* key, const char* value); void ffDestroyTerminalOptions(FFTerminalOptions* options); -void ffParseTerminalJsonObject(FFTerminalOptions* options, yyjson_val* module); -void ffGenerateTerminalJsonResult(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintTerminalHelpFormat(void); diff --git a/src/modules/terminalfont/terminalfont.c b/src/modules/terminalfont/terminalfont.c index 8bf5f6395..a1be63293 100644 --- a/src/modules/terminalfont/terminalfont.c +++ b/src/modules/terminalfont/terminalfont.c @@ -47,12 +47,6 @@ void ffPrintTerminalFont(FFTerminalFontOptions* options) ffFontDestroy(&terminalFont.fallback); } -void ffInitTerminalFontOptions(FFTerminalFontOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALFONT_MODULE_NAME, ffParseTerminalFontCommandOptions, ffParseTerminalFontJsonObject, ffPrintTerminalFont, ffGenerateTerminalFontJsonResult, ffPrintTerminalFontHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseTerminalFontCommandOptions(FFTerminalFontOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_TERMINALFONT_MODULE_NAME); @@ -63,11 +57,6 @@ bool ffParseTerminalFontCommandOptions(FFTerminalFontOptions* options, const cha return false; } -void ffDestroyTerminalFontOptions(FFTerminalFontOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseTerminalFontJsonObject(FFTerminalFontOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -134,3 +123,14 @@ void ffPrintTerminalFontHelpFormat(void) "Terminal font styles" }); } + +void ffInitTerminalFontOptions(FFTerminalFontOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALFONT_MODULE_NAME, ffParseTerminalFontCommandOptions, ffParseTerminalFontJsonObject, ffPrintTerminalFont, ffGenerateTerminalFontJsonResult, ffPrintTerminalFontHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyTerminalFontOptions(FFTerminalFontOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/terminalfont/terminalfont.h b/src/modules/terminalfont/terminalfont.h index 78f54524a..01eee0802 100644 --- a/src/modules/terminalfont/terminalfont.h +++ b/src/modules/terminalfont/terminalfont.h @@ -6,8 +6,4 @@ void ffPrintTerminalFont(FFTerminalFontOptions* options); void ffInitTerminalFontOptions(FFTerminalFontOptions* options); -bool ffParseTerminalFontCommandOptions(FFTerminalFontOptions* options, const char* key, const char* value); void ffDestroyTerminalFontOptions(FFTerminalFontOptions* options); -void ffParseTerminalFontJsonObject(FFTerminalFontOptions* options, yyjson_val* module); -void ffGenerateTerminalFontJsonResult(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintTerminalFontHelpFormat(void); diff --git a/src/modules/terminalsize/terminalsize.c b/src/modules/terminalsize/terminalsize.c index 92ea0b99c..3d94d09c4 100644 --- a/src/modules/terminalsize/terminalsize.c +++ b/src/modules/terminalsize/terminalsize.c @@ -39,12 +39,6 @@ void ffPrintTerminalSize(FFTerminalSizeOptions* options) } } -void ffInitTerminalSizeOptions(FFTerminalSizeOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALSIZE_MODULE_NAME, ffParseTerminalSizeCommandOptions, ffParseTerminalSizeJsonObject, ffPrintTerminalSize, ffGenerateTerminalSizeJsonResult, ffPrintTerminalSizeHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseTerminalSizeCommandOptions(FFTerminalSizeOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_TERMINALSIZE_MODULE_NAME); @@ -55,11 +49,6 @@ bool ffParseTerminalSizeCommandOptions(FFTerminalSizeOptions* options, const cha return false; } -void ffDestroyTerminalSizeOptions(FFTerminalSizeOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseTerminalSizeJsonObject(FFTerminalSizeOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -103,3 +92,14 @@ void ffPrintTerminalSizeHelpFormat(void) "Terminal height (in pixels)" }); } + +void ffInitTerminalSizeOptions(FFTerminalSizeOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALSIZE_MODULE_NAME, ffParseTerminalSizeCommandOptions, ffParseTerminalSizeJsonObject, ffPrintTerminalSize, ffGenerateTerminalSizeJsonResult, ffPrintTerminalSizeHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyTerminalSizeOptions(FFTerminalSizeOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/terminalsize/terminalsize.h b/src/modules/terminalsize/terminalsize.h index 4d1a5c28c..e88f8b6c7 100644 --- a/src/modules/terminalsize/terminalsize.h +++ b/src/modules/terminalsize/terminalsize.h @@ -6,8 +6,4 @@ void ffPrintTerminalSize(FFTerminalSizeOptions* options); void ffInitTerminalSizeOptions(FFTerminalSizeOptions* options); -bool ffParseTerminalSizeCommandOptions(FFTerminalSizeOptions* options, const char* key, const char* value); void ffDestroyTerminalSizeOptions(FFTerminalSizeOptions* options); -void ffParseTerminalSizeJsonObject(FFTerminalSizeOptions* options, yyjson_val* module); -void ffGenerateTerminalSizeJsonResult(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintTerminalSizeHelpFormat(void); diff --git a/src/modules/theme/theme.c b/src/modules/theme/theme.c index d4b7364ad..2f373d0ae 100644 --- a/src/modules/theme/theme.c +++ b/src/modules/theme/theme.c @@ -30,12 +30,6 @@ void ffPrintTheme(FFThemeOptions* options) } } -void ffInitThemeOptions(FFThemeOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_THEME_MODULE_NAME, ffParseThemeCommandOptions, ffParseThemeJsonObject, ffPrintTheme, ffGenerateThemeJsonResult, ffPrintThemeHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseThemeCommandOptions(FFThemeOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_THEME_MODULE_NAME); @@ -46,11 +40,6 @@ bool ffParseThemeCommandOptions(FFThemeOptions* options, const char* key, const return false; } -void ffDestroyThemeOptions(FFThemeOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseThemeJsonObject(FFThemeOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -88,3 +77,14 @@ void ffPrintThemeHelpFormat(void) "Combined themes" }); } + +void ffInitThemeOptions(FFThemeOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_THEME_MODULE_NAME, ffParseThemeCommandOptions, ffParseThemeJsonObject, ffPrintTheme, ffGenerateThemeJsonResult, ffPrintThemeHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyThemeOptions(FFThemeOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/theme/theme.h b/src/modules/theme/theme.h index ed11cf014..6ead202bf 100644 --- a/src/modules/theme/theme.h +++ b/src/modules/theme/theme.h @@ -6,8 +6,4 @@ void ffPrintTheme(FFThemeOptions* options); void ffInitThemeOptions(FFThemeOptions* options); -bool ffParseThemeCommandOptions(FFThemeOptions* options, const char* key, const char* value); void ffDestroyThemeOptions(FFThemeOptions* options); -void ffParseThemeJsonObject(FFThemeOptions* options, yyjson_val* module); -void ffGenerateThemeJsonResult(FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintThemeHelpFormat(void); diff --git a/src/modules/title/title.c b/src/modules/title/title.c index b0d301a5a..d1283be27 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -69,18 +69,6 @@ void ffPrintTitle(FFTitleOptions* options) } } -void ffInitTitleOptions(FFTitleOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TITLE_MODULE_NAME, ffParseTitleCommandOptions, ffParseTitleJsonObject, ffPrintTitle, ffGenerateTitleJsonResult, ffPrintTitleHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - ffStrbufSetStatic(&options->moduleArgs.key, " "); - - options->fqdn = false; - ffStrbufInit(&options->colorUser); - ffStrbufInit(&options->colorAt); - ffStrbufInit(&options->colorHost); -} - bool ffParseTitleCommandOptions(FFTitleOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_TITLE_MODULE_NAME); @@ -115,14 +103,6 @@ bool ffParseTitleCommandOptions(FFTitleOptions* options, const char* key, const return false; } -void ffDestroyTitleOptions(FFTitleOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); - ffStrbufDestroy(&options->colorUser); - ffStrbufDestroy(&options->colorAt); - ffStrbufDestroy(&options->colorHost); -} - void ffParseTitleJsonObject(FFTitleOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -186,3 +166,23 @@ void ffPrintTitleHelpFormat(void) "Host name (colored)" }); } + +void ffInitTitleOptions(FFTitleOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TITLE_MODULE_NAME, ffParseTitleCommandOptions, ffParseTitleJsonObject, ffPrintTitle, ffGenerateTitleJsonResult, ffPrintTitleHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + ffStrbufSetStatic(&options->moduleArgs.key, " "); + + options->fqdn = false; + ffStrbufInit(&options->colorUser); + ffStrbufInit(&options->colorAt); + ffStrbufInit(&options->colorHost); +} + +void ffDestroyTitleOptions(FFTitleOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); + ffStrbufDestroy(&options->colorUser); + ffStrbufDestroy(&options->colorAt); + ffStrbufDestroy(&options->colorHost); +} diff --git a/src/modules/title/title.h b/src/modules/title/title.h index 059b2dcc7..83ddfa9b5 100644 --- a/src/modules/title/title.h +++ b/src/modules/title/title.h @@ -6,8 +6,4 @@ void ffPrintTitle(FFTitleOptions* options); void ffInitTitleOptions(FFTitleOptions* options); -bool ffParseTitleCommandOptions(FFTitleOptions* options, const char* key, const char* value); void ffDestroyTitleOptions(FFTitleOptions* options); -void ffParseTitleJsonObject(FFTitleOptions* options, yyjson_val* module); -void ffGenerateTitleJsonResult(FFTitleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintTitleHelpFormat(void); diff --git a/src/modules/uptime/uptime.c b/src/modules/uptime/uptime.c index ba8a031ca..dbef0de67 100644 --- a/src/modules/uptime/uptime.c +++ b/src/modules/uptime/uptime.c @@ -89,12 +89,6 @@ void ffPrintUptime(FFUptimeOptions* options) } } -void ffInitUptimeOptions(FFUptimeOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_UPTIME_MODULE_NAME, ffParseUptimeCommandOptions, ffParseUptimeJsonObject, ffPrintUptime, ffGenerateUptimeJsonResult, ffPrintUptimeHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseUptimeCommandOptions(FFUptimeOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_UPTIME_MODULE_NAME); @@ -105,11 +99,6 @@ bool ffParseUptimeCommandOptions(FFUptimeOptions* options, const char* key, cons return false; } -void ffDestroyUptimeOptions(FFUptimeOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseUptimeJsonObject(FFUptimeOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -152,3 +141,14 @@ void ffPrintUptimeHelpFormat(void) "Seconds" }); } + +void ffInitUptimeOptions(FFUptimeOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_UPTIME_MODULE_NAME, ffParseUptimeCommandOptions, ffParseUptimeJsonObject, ffPrintUptime, ffGenerateUptimeJsonResult, ffPrintUptimeHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyUptimeOptions(FFUptimeOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/uptime/uptime.h b/src/modules/uptime/uptime.h index 5ce932a49..17b6c1bc6 100644 --- a/src/modules/uptime/uptime.h +++ b/src/modules/uptime/uptime.h @@ -6,8 +6,4 @@ void ffPrintUptime(FFUptimeOptions* options); void ffInitUptimeOptions(FFUptimeOptions* options); -bool ffParseUptimeCommandOptions(FFUptimeOptions* options, const char* key, const char* value); void ffDestroyUptimeOptions(FFUptimeOptions* options); -void ffParseUptimeJsonObject(FFUptimeOptions* options, yyjson_val* module); -void ffGenerateUptimeJsonResult(FFUptimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintUptimeHelpFormat(void); diff --git a/src/modules/users/users.c b/src/modules/users/users.c index 3235283a6..8df069fb4 100644 --- a/src/modules/users/users.c +++ b/src/modules/users/users.c @@ -91,14 +91,6 @@ void ffPrintUsers(FFUsersOptions* options) } } -void ffInitUsersOptions(FFUsersOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_USERS_MODULE_NAME, ffParseUsersCommandOptions, ffParseUsersJsonObject, ffPrintUsers, ffGenerateUsersJsonResult, ffPrintUsersHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - options->compact = false; -} - bool ffParseUsersCommandOptions(FFUsersOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_USERS_MODULE_NAME); @@ -115,11 +107,6 @@ bool ffParseUsersCommandOptions(FFUsersOptions* options, const char* key, const return false; } -void ffDestroyUsersOptions(FFUsersOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseUsersJsonObject(FFUsersOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -186,3 +173,16 @@ void ffPrintUsersHelpFormat(void) "Login Time" }); } + +void ffInitUsersOptions(FFUsersOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_USERS_MODULE_NAME, ffParseUsersCommandOptions, ffParseUsersJsonObject, ffPrintUsers, ffGenerateUsersJsonResult, ffPrintUsersHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + options->compact = false; +} + +void ffDestroyUsersOptions(FFUsersOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/users/users.h b/src/modules/users/users.h index 9947d4ce4..81d3dd3f5 100644 --- a/src/modules/users/users.h +++ b/src/modules/users/users.h @@ -6,8 +6,4 @@ void ffPrintUsers(FFUsersOptions* options); void ffInitUsersOptions(FFUsersOptions* options); -bool ffParseUsersCommandOptions(FFUsersOptions* options, const char* key, const char* value); void ffDestroyUsersOptions(FFUsersOptions* options); -void ffParseUsersJsonObject(FFUsersOptions* options, yyjson_val* module); -void ffGenerateUsersJsonResult(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintUsersHelpFormat(void); diff --git a/src/modules/version/version.c b/src/modules/version/version.c index 933ecc46d..860a56079 100644 --- a/src/modules/version/version.c +++ b/src/modules/version/version.c @@ -45,12 +45,6 @@ void ffPrintVersion(FFVersionOptions* options) } } -void ffInitVersionOptions(FFVersionOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VERSION_MODULE_NAME, ffParseVersionCommandOptions, ffParseVersionJsonObject, ffPrintVersion, ffGenerateVersionJsonResult, ffPrintVersionHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseVersionCommandOptions(FFVersionOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_VERSION_MODULE_NAME); @@ -61,11 +55,6 @@ bool ffParseVersionCommandOptions(FFVersionOptions* options, const char* key, co return false; } -void ffDestroyVersionOptions(FFVersionOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -129,3 +118,14 @@ void ffPrintVersionHelpFormat(void) "Libc used" }); } + +void ffInitVersionOptions(FFVersionOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VERSION_MODULE_NAME, ffParseVersionCommandOptions, ffParseVersionJsonObject, ffPrintVersion, ffGenerateVersionJsonResult, ffPrintVersionHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyVersionOptions(FFVersionOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/version/version.h b/src/modules/version/version.h index 2881af0d6..1cab28d94 100644 --- a/src/modules/version/version.h +++ b/src/modules/version/version.h @@ -6,8 +6,4 @@ void ffPrintVersion(FFVersionOptions* options); void ffInitVersionOptions(FFVersionOptions* options); -bool ffParseVersionCommandOptions(FFVersionOptions* options, const char* key, const char* value); void ffDestroyVersionOptions(FFVersionOptions* options); -void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module); -void ffGenerateVersionJsonResult(FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintVersionHelpFormat(void); diff --git a/src/modules/vulkan/vulkan.c b/src/modules/vulkan/vulkan.c index 839e52407..5fa1bca9c 100644 --- a/src/modules/vulkan/vulkan.c +++ b/src/modules/vulkan/vulkan.c @@ -44,12 +44,6 @@ void ffPrintVulkan(FFVulkanOptions* options) } } -void ffInitVulkanOptions(FFVulkanOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VULKAN_MODULE_NAME, ffParseVulkanCommandOptions, ffParseVulkanJsonObject, ffPrintVulkan, ffGenerateVulkanJsonResult, ffPrintVulkanHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseVulkanCommandOptions(FFVulkanOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_VULKAN_MODULE_NAME); @@ -60,11 +54,6 @@ bool ffParseVulkanCommandOptions(FFVulkanOptions* options, const char* key, cons return false; } -void ffDestroyVulkanOptions(FFVulkanOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseVulkanJsonObject(FFVulkanOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -145,3 +134,14 @@ void ffPrintVulkanHelpFormat(void) "Conformance version" }); } + +void ffInitVulkanOptions(FFVulkanOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VULKAN_MODULE_NAME, ffParseVulkanCommandOptions, ffParseVulkanJsonObject, ffPrintVulkan, ffGenerateVulkanJsonResult, ffPrintVulkanHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyVulkanOptions(FFVulkanOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/vulkan/vulkan.h b/src/modules/vulkan/vulkan.h index 9a4954b67..397c42093 100644 --- a/src/modules/vulkan/vulkan.h +++ b/src/modules/vulkan/vulkan.h @@ -6,8 +6,4 @@ void ffPrintVulkan(FFVulkanOptions* options); void ffInitVulkanOptions(FFVulkanOptions* options); -bool ffParseVulkanCommandOptions(FFVulkanOptions* options, const char* key, const char* value); void ffDestroyVulkanOptions(FFVulkanOptions* options); -void ffParseVulkanJsonObject(FFVulkanOptions* options, yyjson_val* module); -void ffGenerateVulkanJsonResult(FFVulkanOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintVulkanHelpFormat(void); diff --git a/src/modules/wallpaper/wallpaper.c b/src/modules/wallpaper/wallpaper.c index dfcfd3466..c5c7de2cb 100644 --- a/src/modules/wallpaper/wallpaper.c +++ b/src/modules/wallpaper/wallpaper.c @@ -42,12 +42,6 @@ void ffPrintWallpaper(FFWallpaperOptions* options) } } -void ffInitWallpaperOptions(FFWallpaperOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperCommandOptions, ffParseWallpaperJsonObject, ffPrintWallpaper, ffGenerateWallpaperJsonResult, ffPrintWallpaperHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseWallpaperCommandOptions(FFWallpaperOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_WALLPAPER_MODULE_NAME); @@ -58,11 +52,6 @@ bool ffParseWallpaperCommandOptions(FFWallpaperOptions* options, const char* key return false; } -void ffDestroyWallpaperOptions(FFWallpaperOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseWallpaperJsonObject(FFWallpaperOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -98,3 +87,14 @@ void ffPrintWallpaperHelpFormat(void) "Wallpaper image file" }); } + +void ffInitWallpaperOptions(FFWallpaperOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperCommandOptions, ffParseWallpaperJsonObject, ffPrintWallpaper, ffGenerateWallpaperJsonResult, ffPrintWallpaperHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyWallpaperOptions(FFWallpaperOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/wallpaper/wallpaper.h b/src/modules/wallpaper/wallpaper.h index ec51a9918..a2c804ae3 100644 --- a/src/modules/wallpaper/wallpaper.h +++ b/src/modules/wallpaper/wallpaper.h @@ -6,8 +6,4 @@ void ffPrintWallpaper(FFWallpaperOptions* options); void ffInitWallpaperOptions(FFWallpaperOptions* options); -bool ffParseWallpaperCommandOptions(FFWallpaperOptions* options, const char* key, const char* value); void ffDestroyWallpaperOptions(FFWallpaperOptions* options); -void ffParseWallpaperJsonObject(FFWallpaperOptions* options, yyjson_val* module); -void ffGenerateWallpaperJsonResult(FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintWallpaperHelpFormat(void); diff --git a/src/modules/weather/weather.c b/src/modules/weather/weather.c index fff967a52..47c5f1bc8 100644 --- a/src/modules/weather/weather.c +++ b/src/modules/weather/weather.c @@ -31,16 +31,6 @@ void ffPrintWeather(FFWeatherOptions* options) } } -void ffInitWeatherOptions(FFWeatherOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WEATHER_MODULE_NAME, ffParseWeatherCommandOptions, ffParseWeatherJsonObject, ffPrintWeather, ffGenerateWeatherJsonResult, ffPrintWeatherHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); - - ffStrbufInit(&options->location); - ffStrbufInitStatic(&options->outputFormat, "%t+-+%C+(%l)"); - options->timeout = 0; -} - bool ffParseWeatherCommandOptions(FFWeatherOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_WEATHER_MODULE_NAME); @@ -69,13 +59,6 @@ bool ffParseWeatherCommandOptions(FFWeatherOptions* options, const char* key, co return false; } -void ffDestroyWeatherOptions(FFWeatherOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); - - ffStrbufDestroy(&options->outputFormat); -} - void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -131,3 +114,20 @@ void ffPrintWeatherHelpFormat(void) "Weather result" }); } + +void ffInitWeatherOptions(FFWeatherOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WEATHER_MODULE_NAME, ffParseWeatherCommandOptions, ffParseWeatherJsonObject, ffPrintWeather, ffGenerateWeatherJsonResult, ffPrintWeatherHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); + + ffStrbufInit(&options->location); + ffStrbufInitStatic(&options->outputFormat, "%t+-+%C+(%l)"); + options->timeout = 0; +} + +void ffDestroyWeatherOptions(FFWeatherOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); + + ffStrbufDestroy(&options->outputFormat); +} diff --git a/src/modules/weather/weather.h b/src/modules/weather/weather.h index 7bb0f1367..1ec2f02a2 100644 --- a/src/modules/weather/weather.h +++ b/src/modules/weather/weather.h @@ -8,8 +8,4 @@ void ffPrepareWeather(FFWeatherOptions* options); void ffPrintWeather(FFWeatherOptions* options); void ffInitWeatherOptions(FFWeatherOptions* options); -bool ffParseWeatherCommandOptions(FFWeatherOptions* options, const char* key, const char* value); void ffDestroyWeatherOptions(FFWeatherOptions* options); -void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module); -void ffGenerateWeatherJsonResult(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintWeatherHelpFormat(void); diff --git a/src/modules/wifi/wifi.c b/src/modules/wifi/wifi.c index b7d73497e..766eac1ec 100644 --- a/src/modules/wifi/wifi.c +++ b/src/modules/wifi/wifi.c @@ -70,12 +70,6 @@ void ffPrintWifi(FFWifiOptions* options) } } -void ffInitWifiOptions(FFWifiOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WIFI_MODULE_NAME, ffParseWifiCommandOptions, ffParseWifiJsonObject, ffPrintWifi, ffGenerateWifiJsonResult, ffPrintWifiHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseWifiCommandOptions(FFWifiOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_WIFI_MODULE_NAME); @@ -86,11 +80,6 @@ bool ffParseWifiCommandOptions(FFWifiOptions* options, const char* key, const ch return false; } -void ffDestroyWifiOptions(FFWifiOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseWifiJsonObject(FFWifiOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -169,3 +158,14 @@ void ffPrintWifiHelpFormat(void) "Connection Security algorithm" }); } + +void ffInitWifiOptions(FFWifiOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WIFI_MODULE_NAME, ffParseWifiCommandOptions, ffParseWifiJsonObject, ffPrintWifi, ffGenerateWifiJsonResult, ffPrintWifiHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyWifiOptions(FFWifiOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/wifi/wifi.h b/src/modules/wifi/wifi.h index 88f1c208f..bd23565d3 100644 --- a/src/modules/wifi/wifi.h +++ b/src/modules/wifi/wifi.h @@ -6,8 +6,4 @@ void ffPrintWifi(FFWifiOptions* options); void ffInitWifiOptions(FFWifiOptions* options); -bool ffParseWifiCommandOptions(FFWifiOptions* options, const char* key, const char* value); void ffDestroyWifiOptions(FFWifiOptions* options); -void ffParseWifiJsonObject(FFWifiOptions* options, yyjson_val* module); -void ffGenerateWifiJsonResult(FFWifiOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintWifiHelpFormat(void); diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index de232bc95..973eabac7 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -41,12 +41,6 @@ void ffPrintWM(FFWMOptions* options) } } -void ffInitWMOptions(FFWMOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WM_MODULE_NAME, ffParseWMCommandOptions, ffParseWMJsonObject, ffPrintWM, ffGenerateWMJsonResult, ffPrintWMHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseWMCommandOptions(FFWMOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_WM_MODULE_NAME); @@ -57,11 +51,6 @@ bool ffParseWMCommandOptions(FFWMOptions* options, const char* key, const char* return false; } -void ffDestroyWMOptions(FFWMOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -102,3 +91,14 @@ void ffPrintWMHelpFormat(void) "WM protocol name" }); } + +void ffInitWMOptions(FFWMOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WM_MODULE_NAME, ffParseWMCommandOptions, ffParseWMJsonObject, ffPrintWM, ffGenerateWMJsonResult, ffPrintWMHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyWMOptions(FFWMOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/wm/wm.h b/src/modules/wm/wm.h index 3253b6ad1..93edec8b4 100644 --- a/src/modules/wm/wm.h +++ b/src/modules/wm/wm.h @@ -6,8 +6,4 @@ void ffPrintWM(FFWMOptions* options); void ffInitWMOptions(FFWMOptions* options); -bool ffParseWMCommandOptions(FFWMOptions* options, const char* key, const char* value); void ffDestroyWMOptions(FFWMOptions* options); -void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module); -void ffGenerateWMJsonResult(FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintWMHelpFormat(void); diff --git a/src/modules/wmtheme/wmtheme.c b/src/modules/wmtheme/wmtheme.c index 27f194e1e..f47260aed 100644 --- a/src/modules/wmtheme/wmtheme.c +++ b/src/modules/wmtheme/wmtheme.c @@ -30,12 +30,6 @@ void ffPrintWMTheme(FFWMThemeOptions* options) } } -void ffInitWMThemeOptions(FFWMThemeOptions* options) -{ - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WMTHEME_MODULE_NAME, ffParseWMThemeCommandOptions, ffParseWMThemeJsonObject, ffPrintWMTheme, ffGenerateWMThemeJsonResult, ffPrintWMthemeHelpFormat); - ffOptionInitModuleArg(&options->moduleArgs); -} - bool ffParseWMThemeCommandOptions(FFWMThemeOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_WMTHEME_MODULE_NAME); @@ -46,11 +40,6 @@ bool ffParseWMThemeCommandOptions(FFWMThemeOptions* options, const char* key, co return false; } -void ffDestroyWMThemeOptions(FFWMThemeOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - void ffParseWMThemeJsonObject(FFWMThemeOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -86,3 +75,14 @@ void ffPrintWMthemeHelpFormat(void) "WM theme" }); } + +void ffInitWMThemeOptions(FFWMThemeOptions* options) +{ + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WMTHEME_MODULE_NAME, ffParseWMThemeCommandOptions, ffParseWMThemeJsonObject, ffPrintWMTheme, ffGenerateWMThemeJsonResult, ffPrintWMthemeHelpFormat); + ffOptionInitModuleArg(&options->moduleArgs); +} + +void ffDestroyWMThemeOptions(FFWMThemeOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} diff --git a/src/modules/wmtheme/wmtheme.h b/src/modules/wmtheme/wmtheme.h index 187d2f18e..9a2a24982 100644 --- a/src/modules/wmtheme/wmtheme.h +++ b/src/modules/wmtheme/wmtheme.h @@ -6,8 +6,4 @@ void ffPrintWMTheme(FFWMThemeOptions* options); void ffInitWMThemeOptions(FFWMThemeOptions* options); -bool ffParseWMThemeCommandOptions(FFWMThemeOptions* options, const char* key, const char* value); void ffDestroyWMThemeOptions(FFWMThemeOptions* options); -void ffParseWMThemeJsonObject(FFWMThemeOptions* options, yyjson_val* module); -void ffGenerateWMThemeJsonResult(FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module); -void ffPrintWMthemeHelpFormat(void); From ec87790e4fa03c229b763ca2aba8000f33e97741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 23 Oct 2023 13:39:07 +0800 Subject: [PATCH 010/100] Global: init support for JSON config file migration (WIP) --- src/common/commandoption.c | 39 +++++++++-- src/common/commandoption.h | 1 + src/common/init.c | 1 + src/common/jsonconfig.c | 12 ++++ src/common/jsonconfig.h | 1 + src/common/option.h | 5 +- src/fastfetch.c | 89 ++++++++++++++++--------- src/fastfetch.h | 1 + src/modules/battery/battery.c | 27 +++++++- src/modules/bios/bios.c | 19 +++++- src/modules/bluetooth/bluetooth.c | 11 ++- src/modules/board/board.c | 11 ++- src/modules/break/break.c | 11 ++- src/modules/brightness/brightness.c | 11 ++- src/modules/chassis/chassis.c | 11 ++- src/modules/colors/colors.c | 11 ++- src/modules/command/command.c | 11 ++- src/modules/cpu/cpu.c | 11 ++- src/modules/cpuusage/cpuusage.c | 11 ++- src/modules/cursor/cursor.c | 11 ++- src/modules/custom/custom.c | 19 +++++- src/modules/datetime/datetime.c | 11 ++- src/modules/de/de.c | 11 ++- src/modules/disk/disk.c | 11 ++- src/modules/diskio/diskio.c | 11 ++- src/modules/display/display.c | 11 ++- src/modules/font/font.c | 11 ++- src/modules/gamepad/gamepad.c | 11 ++- src/modules/gpu/gpu.c | 11 ++- src/modules/host/host.c | 11 ++- src/modules/icons/icons.c | 11 ++- src/modules/kernel/kernel.c | 11 ++- src/modules/lm/lm.c | 11 ++- src/modules/locale/locale.c | 11 ++- src/modules/localip/localip.c | 11 ++- src/modules/media/media.c | 11 ++- src/modules/memory/memory.c | 11 ++- src/modules/monitor/monitor.c | 11 ++- src/modules/netio/netio.c | 11 ++- src/modules/opencl/opencl.c | 11 ++- src/modules/opengl/opengl.c | 11 ++- src/modules/os/os.c | 11 ++- src/modules/packages/packages.c | 11 ++- src/modules/player/player.c | 11 ++- src/modules/poweradapter/poweradapter.c | 11 ++- src/modules/processes/processes.c | 11 ++- src/modules/publicip/publicip.c | 11 ++- src/modules/separator/separator.c | 11 ++- src/modules/shell/shell.c | 11 ++- src/modules/sound/sound.c | 11 ++- src/modules/swap/swap.c | 11 ++- src/modules/terminal/terminal.c | 11 ++- src/modules/terminalfont/terminalfont.c | 11 ++- src/modules/terminalsize/terminalsize.c | 11 ++- src/modules/theme/theme.c | 11 ++- src/modules/title/title.c | 11 ++- src/modules/uptime/uptime.c | 11 ++- src/modules/users/users.c | 11 ++- src/modules/version/version.c | 11 ++- src/modules/vulkan/vulkan.c | 11 ++- src/modules/wallpaper/wallpaper.c | 11 ++- src/modules/weather/weather.c | 11 ++- src/modules/wifi/wifi.c | 11 ++- src/modules/wm/wm.c | 11 ++- src/modules/wmtheme/wmtheme.c | 11 ++- 65 files changed, 716 insertions(+), 92 deletions(-) diff --git a/src/common/commandoption.c b/src/common/commandoption.c index 80ddcb923..727292fa2 100644 --- a/src/common/commandoption.c +++ b/src/common/commandoption.c @@ -1,6 +1,7 @@ #include "commandoption.h" #include "common/printing.h" #include "common/time.h" +#include "common/jsonconfig.h" #include "fastfetch_datatext.h" #include "modules/modules.h" #include "util/stringUtils.h" @@ -8,7 +9,27 @@ #include #include -static inline yyjson_mut_val* genJson(FFModuleBaseInfo* baseInfo) +static inline yyjson_mut_val* genJsonConfig(FFModuleBaseInfo* baseInfo) +{ + yyjson_mut_doc* doc = instance.state.migrateConfigDoc; + if (__builtin_expect(!doc, true)) return NULL; + + yyjson_mut_val* modules = yyjson_mut_obj_get(doc->root, "modules"); + if (!modules) + modules = yyjson_mut_obj_add_arr(doc, doc->root, "modules"); + + yyjson_mut_val* module = yyjson_mut_arr_add_obj(doc, modules); + FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateS(baseInfo->name); + ffStrbufLowerCase(&type); + yyjson_mut_obj_add_strbuf(doc, module, "type", &type); + + if (baseInfo->generateJsonConfig) + baseInfo->generateJsonConfig(baseInfo, doc, module); + + return module; +} + +static inline yyjson_mut_val* genJsonResult(FFModuleBaseInfo* baseInfo) { yyjson_mut_doc* doc = instance.state.resultDoc; if (__builtin_expect(!doc, true)) return NULL; @@ -31,7 +52,7 @@ bool ffParseModuleCommand(const char* type) FFModuleBaseInfo* baseInfo = *modules; if (ffStrEqualsIgnCase(type, baseInfo->name)) { - if (!genJson(baseInfo)) + if (!genJsonConfig(baseInfo) && !genJsonResult(baseInfo)) baseInfo->printModule(baseInfo); return true; } @@ -88,7 +109,7 @@ static void parseStructureCommand(const char* line, FFlist* customValues) if (customValue->printKey) ffStrbufAppend(&options.moduleArgs.key, &customValue->key); ffStrbufAppend(&options.moduleArgs.outputFormat, &customValue->value); - ffPrintCustom(&options); + if (!genJsonConfig((FFModuleBaseInfo*) &options)) ffPrintCustom(&options); return; } } @@ -135,9 +156,19 @@ void ffPrintCommandOption(FFdata* data) } #if defined(_WIN32) - if (!instance.config.noBuffer) fflush(stdout); + if (!resultDoc && !instance.config.noBuffer) fflush(stdout); #endif startIndex = colonIndex + 1; } } + +void ffMigrateCommandOptionToJsonc(FFdata* data) +{ + //If we don't have a custom structure, use the default one + if(data->structure.length == 0) + ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); + instance.config.stat = false; + ffPrintCommandOption(data); + yyjson_mut_write_fp(stdout, instance.state.migrateConfigDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); +} diff --git a/src/common/commandoption.h b/src/common/commandoption.h index c938fe2a8..1c9ed9721 100644 --- a/src/common/commandoption.h +++ b/src/common/commandoption.h @@ -24,5 +24,6 @@ bool ffParseModuleCommand(const char* type); bool ffParseModuleOptions(const char* key, const char* value); void ffPrepareCommandOption(FFdata* data); void ffPrintCommandOption(FFdata* data); +void ffMigrateCommandOptionToJsonc(FFdata* data); #endif diff --git a/src/common/init.c b/src/common/init.c index eab996eaa..bfabc8129 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -381,6 +381,7 @@ static void destroyState(void) ffPlatformDestroy(&instance.state.platform); yyjson_doc_free(instance.state.configDoc); yyjson_mut_doc_free(instance.state.resultDoc); + yyjson_mut_doc_free(instance.state.migrateConfigDoc); } void ffDestroyInstance(void) diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 6e13334d5..0c1fdc1e5 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -35,6 +35,18 @@ bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs* return false; } +void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs) +{ + if (!ffStrbufEqual(&defaultModuleArgs->key, &moduleArgs->key)) + yyjson_mut_obj_add_strbuf(doc, module, "key", &moduleArgs->key); + if (!ffStrbufEqual(&defaultModuleArgs->outputFormat, &moduleArgs->outputFormat)) + yyjson_mut_obj_add_strbuf(doc, module, "format", &moduleArgs->outputFormat); + if (!ffStrbufEqual(&defaultModuleArgs->keyColor, &moduleArgs->keyColor)) + yyjson_mut_obj_add_strbuf(doc, module, "keyColor", &moduleArgs->keyColor); + if (moduleArgs->keyWidth != defaultModuleArgs->keyWidth) + yyjson_mut_obj_add_uint(doc, module, "keyWidth", moduleArgs->keyWidth); +} + const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]) { if (yyjson_is_int(val)) diff --git a/src/common/jsonconfig.h b/src/common/jsonconfig.h index afb0fd865..b7824cdd0 100644 --- a/src/common/jsonconfig.h +++ b/src/common/jsonconfig.h @@ -8,6 +8,7 @@ void ffPrintJsonConfig(bool prepare); const char* ffParseGeneralJsonConfig(void); const char* ffParseDisplayJsonConfig(void); const char* ffParseLibraryJsonConfig(void); +void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs); yyjson_api_inline bool yyjson_mut_obj_add_strbuf(yyjson_mut_doc *doc, yyjson_mut_val *obj, diff --git a/src/common/option.h b/src/common/option.h index 3207e576d..401f7a33b 100644 --- a/src/common/option.h +++ b/src/common/option.h @@ -19,6 +19,7 @@ typedef struct FFModuleBaseInfo void (*printModule)(void* options); void (*generateJsonResult)(void* options, struct yyjson_mut_doc* doc, struct yyjson_mut_val* module); void (*printHelpFormat)(void); + void (*generateJsonConfig)(void* options, struct yyjson_mut_doc* doc, struct yyjson_mut_val* obj); } FFModuleBaseInfo; static inline void ffOptionInitModuleBaseInfo( @@ -28,7 +29,8 @@ static inline void ffOptionInitModuleBaseInfo( void* parseJsonObject, // void (*const parseJsonObject)(void* options, yyjson_val *module) void* printModule, // void (*const printModule)(void* options) void* generateJsonResult, // void (*const generateJsonResult)(void* options, yyjson_mut_doc* doc, yyjson_mut_val* obj) - void (*printHelpFormat)(void) + void (*printHelpFormat)(void), + void* generateJsonConfig // void (*const generateJsonConfig)(void* options, yyjson_mut_doc* doc, yyjson_mut_val* obj) ) { baseInfo->name = name; @@ -37,6 +39,7 @@ static inline void ffOptionInitModuleBaseInfo( baseInfo->printModule = (__typeof__(baseInfo->printModule)) printModule; baseInfo->generateJsonResult = (__typeof__(baseInfo->generateJsonResult)) generateJsonResult; baseInfo->printHelpFormat = printHelpFormat; + baseInfo->generateJsonConfig = (__typeof__(baseInfo->generateJsonConfig)) generateJsonConfig; } typedef struct FFModuleArgs diff --git a/src/fastfetch.c b/src/fastfetch.c index 2268822b0..48b5431ca 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -481,6 +481,26 @@ static void parseOption(FFdata* data, const char* key, const char* value) generateConfigFile(false, value); else if(ffStrEqualsIgnCase(key, "--gen-config-force")) generateConfigFile(true, value); + else if (ffStrEqualsIgnCase(key, "--migrate-config")) + { + yyjson_mut_doc_free(instance.state.migrateConfigDoc); + + if (ffOptionParseBoolean(value)) + { + if (instance.state.configDoc) + { + fputs("Error: existing jsonc config file detected. Exiting\n", stderr); + exit(477); + } + + yyjson_mut_doc* doc = instance.state.migrateConfigDoc = yyjson_mut_doc_new(NULL); + yyjson_mut_val* root = yyjson_mut_obj(doc); + yyjson_mut_doc_set_root(doc, root); + yyjson_mut_obj_add_str(doc, root, "$schema", "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json"); + } + else + instance.state.migrateConfigDoc = NULL; + } else if(ffStrEqualsIgnCase(key, "--thread") || ffStrEqualsIgnCase(key, "--multithreading")) instance.config.multithreading = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--stat")) @@ -719,20 +739,22 @@ error: static void parseConfigFiles(FFdata* data) { - for(uint32_t i = instance.state.platform.configDirs.length; i > 0; --i) + if (__builtin_expect(!instance.state.migrateConfigDoc, true)) { - FFstrbuf* dir = ffListGet(&instance.state.platform.configDirs, i - 1); - uint32_t dirLength = dir->length; + for (uint32_t i = instance.state.platform.configDirs.length; i > 0; --i) + { + FFstrbuf* dir = ffListGet(&instance.state.platform.configDirs, i - 1); + uint32_t dirLength = dir->length; - ffStrbufAppendS(dir, "fastfetch/config.jsonc"); - bool success = parseJsoncFile(dir->chars); - ffStrbufSubstrBefore(dir, dirLength); - if (success) return; + ffStrbufAppendS(dir, "fastfetch/config.jsonc"); + bool success = parseJsoncFile(dir->chars); + ffStrbufSubstrBefore(dir, dirLength); + if (success) return; + } } - - for(uint32_t i = instance.state.platform.configDirs.length; i > 0; --i) + for (uint32_t i = instance.state.platform.configDirs.length; i > 0; --i) { - if(!data->loadUserConfig) + if (!data->loadUserConfig) return; FFstrbuf* dir = ffListGet(&instance.state.platform.configDirs, i - 1); @@ -773,20 +795,8 @@ static void parseArguments(FFdata* data, int argc, const char** argv) } } -int main(int argc, const char** argv) +static void ffRun(FFdata* data) { - ffInitInstance(); - - //Data stores things only needed for the configuration of fastfetch - FFdata data; - ffStrbufInit(&data.structure); - ffListInit(&data.customValues, sizeof(FFCustomValue)); - data.loadUserConfig = true; - - if(!getenv("NO_CONFIG")) - parseConfigFiles(&data); - parseArguments(&data, argc, argv); - if (instance.state.configDoc) { const char* error = NULL; @@ -803,12 +813,12 @@ int main(int argc, const char** argv) } } - const bool useJsonConfig = data.structure.length == 0 && instance.state.configDoc; + const bool useJsonConfig = data->structure.length == 0 && instance.state.configDoc; - if(useJsonConfig) + if (useJsonConfig) ffPrintJsonConfig(true /* prepare */); else - ffPrepareCommandOption(&data); + ffPrepareCommandOption(data); ffStart(); @@ -819,14 +829,33 @@ int main(int argc, const char** argv) if (useJsonConfig) ffPrintJsonConfig(false); else - ffPrintCommandOption(&data); + ffPrintCommandOption(data); if (instance.state.resultDoc) - { yyjson_mut_write_fp(stdout, instance.state.resultDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); - } + else + ffFinish(); +} - ffFinish(); +int main(int argc, const char** argv) +{ + ffInitInstance(); + + //Data stores things only needed for the configuration of fastfetch + FFdata data = { + .structure = ffStrbufCreate(), + .customValues = ffListCreate(sizeof(FFCustomValue)), + .loadUserConfig = true, + }; + + if(!getenv("NO_CONFIG")) + parseConfigFiles(&data); + parseArguments(&data, argc, argv); + + if (__builtin_expect(!instance.state.migrateConfigDoc, true)) + ffRun(&data); + else + ffMigrateCommandOptionToJsonc(&data); // Migrate ffStrbufDestroy(&data.structure); FF_LIST_FOR_EACH(FFCustomValue, customValue, data.customValues) diff --git a/src/fastfetch.h b/src/fastfetch.h index cbb307a15..54fc39407 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -176,6 +176,7 @@ typedef struct FFstate FFPlatform platform; yyjson_doc* configDoc; yyjson_mut_doc* resultDoc; + yyjson_mut_doc* migrateConfigDoc; } FFstate; typedef struct FFinstance diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index c48bc389b..ad09a31c7 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -156,6 +156,22 @@ void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module) } } +void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyBatteryOptions))) FFBatteryOptions defaultOptions; + ffInitBatteryOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + #ifdef __linux__ + if (!ffStrbufEquals(&defaultOptions.dir, &options->dir)) + yyjson_mut_obj_add_strbuf(doc, module, "dir", &options->dir); + #endif + + if (options->temp != defaultOptions.temp) + yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); +} + void ffGenerateBatteryJsonResult(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBatteryResult)); @@ -202,7 +218,16 @@ void ffPrintBatteryHelpFormat(void) void ffInitBatteryOptions(FFBatteryOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BATTERY_MODULE_NAME, ffParseBatteryCommandOptions, ffParseBatteryJsonObject, ffPrintBattery, ffGenerateBatteryJsonResult, ffPrintBatteryHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_BATTERY_MODULE_NAME, + ffParseBatteryCommandOptions, + ffParseBatteryJsonObject, + ffPrintBattery, + ffGenerateBatteryJsonResult, + ffPrintBatteryHelpFormat, + ffGenerateBatteryJsonConfig + ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; diff --git a/src/modules/bios/bios.c b/src/modules/bios/bios.c index 68f63e340..e9b7e3a2b 100644 --- a/src/modules/bios/bios.c +++ b/src/modules/bios/bios.c @@ -80,6 +80,14 @@ void ffParseBiosJsonObject(FFBiosOptions* options, yyjson_val* module) } } +void ffGenerateBiosJsonConfig(FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyBiosOptions))) FFBiosOptions defaultOptions; + ffInitBiosOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateBiosJsonResult(FF_MAYBE_UNUSED FFBiosOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFBiosResult bios; @@ -127,7 +135,16 @@ void ffPrintBiosHelpFormat(void) void ffInitBiosOptions(FFBiosOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BIOS_MODULE_NAME, ffParseBiosCommandOptions, ffParseBiosJsonObject, ffPrintBios, ffGenerateBiosJsonResult, ffPrintBiosHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_BIOS_MODULE_NAME, + ffParseBiosCommandOptions, + ffParseBiosJsonObject, + ffPrintBios, + ffGenerateBiosJsonResult, + ffPrintBiosHelpFormat, + ffGenerateBiosJsonConfig + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index ae8e64779..3439796cc 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -157,7 +157,16 @@ void ffPrintBluetoothHelpFormat(void) void ffInitBluetoothOptions(FFBluetoothOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BLUETOOTH_MODULE_NAME, ffParseBluetoothCommandOptions, ffParseBluetoothJsonObject, ffPrintBluetooth, ffGenerateBluetoothJsonResult, ffPrintBluetoothHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_BLUETOOTH_MODULE_NAME, + ffParseBluetoothCommandOptions, + ffParseBluetoothJsonObject, + ffPrintBluetooth, + ffGenerateBluetoothJsonResult, + ffPrintBluetoothHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); options->showDisconnected = false; } diff --git a/src/modules/board/board.c b/src/modules/board/board.c index e7664eb34..5f6f633b8 100644 --- a/src/modules/board/board.c +++ b/src/modules/board/board.c @@ -119,7 +119,16 @@ void ffPrintBoardHelpFormat(void) void ffInitBoardOptions(FFBoardOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BOARD_MODULE_NAME, ffParseBoardCommandOptions, ffParseBoardJsonObject, ffPrintBoard, ffGenerateBoardJsonResult, ffPrintBoardHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_BOARD_MODULE_NAME, + ffParseBoardCommandOptions, + ffParseBoardJsonObject, + ffPrintBoard, + ffGenerateBoardJsonResult, + ffPrintBoardHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/break/break.c b/src/modules/break/break.c index 5ec50ace9..cdd8ba2c9 100644 --- a/src/modules/break/break.c +++ b/src/modules/break/break.c @@ -20,7 +20,16 @@ void ffParseBreakJsonObject(FF_MAYBE_UNUSED FFBreakOptions* options, FF_MAYBE_UN void ffInitBreakOptions(FF_MAYBE_UNUSED FFBreakOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BREAK_MODULE_NAME, ffParseBreakCommandOptions, ffParseBreakJsonObject, ffPrintBreak, NULL, NULL); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_BREAK_MODULE_NAME, + ffParseBreakCommandOptions, + ffParseBreakJsonObject, + ffPrintBreak, + NULL, + NULL, + NULL + ); } void ffDestroyBreakOptions(FF_MAYBE_UNUSED FFBreakOptions* options) diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index b49a04d7e..fde35952e 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -172,7 +172,16 @@ void ffPrintBrightnessHelpFormat(void) void ffInitBrightnessOptions(FFBrightnessOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_BRIGHTNESS_MODULE_NAME, ffParseBrightnessCommandOptions, ffParseBrightnessJsonObject, ffPrintBrightness, ffGenerateBrightnessJsonResult, ffPrintBrightnessHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_BRIGHTNESS_MODULE_NAME, + ffParseBrightnessCommandOptions, + ffParseBrightnessJsonObject, + ffPrintBrightness, + ffGenerateBrightnessJsonResult, + ffPrintBrightnessHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); options->ddcciSleep = 10; diff --git a/src/modules/chassis/chassis.c b/src/modules/chassis/chassis.c index c3b953e43..816059f67 100644 --- a/src/modules/chassis/chassis.c +++ b/src/modules/chassis/chassis.c @@ -120,7 +120,16 @@ void ffPrintChassisHelpFormat(void) void ffInitChassisOptions(FFChassisOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CHASSIS_MODULE_NAME, ffParseChassisCommandOptions, ffParseChassisJsonObject, ffPrintChassis, ffGenerateChassisJsonResult, ffPrintChassisHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_CHASSIS_MODULE_NAME, + ffParseChassisCommandOptions, + ffParseChassisJsonObject, + ffPrintChassis, + ffGenerateChassisJsonResult, + ffPrintChassisHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/colors/colors.c b/src/modules/colors/colors.c index 4cbe89df4..f33e9c682 100644 --- a/src/modules/colors/colors.c +++ b/src/modules/colors/colors.c @@ -129,7 +129,16 @@ void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module) void ffInitColorsOptions(FFColorsOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COLORS_MODULE_NAME, ffParseColorsCommandOptions, ffParseColorsJsonObject, ffPrintColors, NULL, NULL); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_COLORS_MODULE_NAME, + ffParseColorsCommandOptions, + ffParseColorsJsonObject, + ffPrintColors, + NULL, + NULL, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufSetStatic(&options->moduleArgs.key, " "); options->symbol = FF_COLORS_SYMBOL_BLOCK; diff --git a/src/modules/command/command.c b/src/modules/command/command.c index d5b86d30e..59114dacd 100644 --- a/src/modules/command/command.c +++ b/src/modules/command/command.c @@ -134,7 +134,16 @@ void ffPrintCommandHelpFormat(void) void ffInitCommandOptions(FFCommandOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_COMMAND_MODULE_NAME, ffParseCommandCommandOptions, ffParseCommandJsonObject, ffPrintCommand, ffGenerateCommandJsonResult, ffPrintCommandHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_COMMAND_MODULE_NAME, + ffParseCommandCommandOptions, + ffParseCommandJsonObject, + ffPrintCommand, + ffGenerateCommandJsonResult, + ffPrintCommandHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInitStatic(&options->shell, diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index 0fe0dea42..fab9d77fa 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -185,7 +185,16 @@ void ffPrintCPUHelpFormat(void) void ffInitCPUOptions(FFCPUOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPU_MODULE_NAME, ffParseCPUCommandOptions, ffParseCPUJsonObject, ffPrintCPU, ffGenerateCPUJsonResult, ffPrintCPUHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_CPU_MODULE_NAME, + ffParseCPUCommandOptions, + ffParseCPUJsonObject, + ffPrintCPU, + ffGenerateCPUJsonResult, + ffPrintCPUHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; options->freqNdigits = 2; diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index 69e938af1..7a2418850 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -154,7 +154,16 @@ void ffPrintCPUUsageHelpFormat(void) void ffInitCPUUsageOptions(FFCPUUsageOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CPUUSAGE_MODULE_NAME, ffParseCPUUsageCommandOptions, ffParseCPUUsageJsonObject, ffPrintCPUUsage, ffGenerateCPUUsageJsonResult, ffPrintCPUUsageHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_CPUUSAGE_MODULE_NAME, + ffParseCPUUsageCommandOptions, + ffParseCPUUsageJsonObject, + ffPrintCPUUsage, + ffGenerateCPUUsageJsonResult, + ffPrintCPUUsageHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/cursor/cursor.c b/src/modules/cursor/cursor.c index 7b4d20171..4f6dfd3e1 100644 --- a/src/modules/cursor/cursor.c +++ b/src/modules/cursor/cursor.c @@ -111,7 +111,16 @@ void ffPrintCursorHelpFormat(void) void ffInitCursorOptions(FFCursorOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CURSOR_MODULE_NAME, ffParseCursorCommandOptions, ffParseCursorJsonObject, ffPrintCursor, ffGenerateCursorJsonResult, ffPrintCursorHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_CURSOR_MODULE_NAME, + ffParseCursorCommandOptions, + ffParseCursorJsonObject, + ffPrintCursor, + ffGenerateCursorJsonResult, + ffPrintCursorHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/custom/custom.c b/src/modules/custom/custom.c index baccd127c..4aed00daf 100644 --- a/src/modules/custom/custom.c +++ b/src/modules/custom/custom.c @@ -27,6 +27,14 @@ bool ffParseCustomCommandOptions(FFCustomOptions* options, const char* key, cons return false; } +void ffGenerateCustomJsonConfig(FFCustomOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyCustomOptions))) FFCustomOptions defaultOptions; + ffInitCustomOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffParseCustomJsonObject(FFCustomOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -46,7 +54,16 @@ void ffParseCustomJsonObject(FFCustomOptions* options, yyjson_val* module) void ffInitCustomOptions(FFCustomOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_CUSTOM_MODULE_NAME, ffParseCustomCommandOptions, ffParseCustomJsonObject, ffPrintCustom, NULL, NULL); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_CUSTOM_MODULE_NAME, + ffParseCustomCommandOptions, + ffParseCustomJsonObject, + ffPrintCustom, + NULL, + NULL, + ffGenerateCustomJsonConfig + ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufSetStatic(&options->moduleArgs.key, " "); } diff --git a/src/modules/datetime/datetime.c b/src/modules/datetime/datetime.c index 6c4bb29ce..08b9f356f 100644 --- a/src/modules/datetime/datetime.c +++ b/src/modules/datetime/datetime.c @@ -201,7 +201,16 @@ void ffPrintDateTimeHelpFormat(void) void ffInitDateTimeOptions(FFDateTimeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DATETIME_MODULE_NAME, ffParseDateTimeCommandOptions, ffParseDateTimeJsonObject, ffPrintDateTime, ffGenerateDateTimeJsonResult, ffPrintDateTimeHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_DATETIME_MODULE_NAME, + ffParseDateTimeCommandOptions, + ffParseDateTimeJsonObject, + ffPrintDateTime, + ffGenerateDateTimeJsonResult, + ffPrintDateTimeHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/de/de.c b/src/modules/de/de.c index 83b361733..4c804ebc7 100644 --- a/src/modules/de/de.c +++ b/src/modules/de/de.c @@ -94,7 +94,16 @@ void ffPrintDEHelpFormat(void) void ffInitDEOptions(FFDEOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DE_MODULE_NAME, ffParseDECommandOptions, ffParseDEJsonObject, ffPrintDE, ffGenerateDEJsonResult, ffPrintDEHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_DE_MODULE_NAME, + ffParseDECommandOptions, + ffParseDEJsonObject, + ffPrintDE, + ffGenerateDEJsonResult, + ffPrintDEHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 0fbcc86b8..0bd94e0d0 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -428,7 +428,16 @@ void ffPrintDiskHelpFormat(void) void ffInitDiskOptions(FFDiskOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISK_MODULE_NAME, ffParseDiskCommandOptions, ffParseDiskJsonObject, ffPrintDisk, ffGenerateDiskJsonResult, ffPrintDiskHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_DISK_MODULE_NAME, + ffParseDiskCommandOptions, + ffParseDiskJsonObject, + ffPrintDisk, + ffGenerateDiskJsonResult, + ffPrintDiskHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->folders); diff --git a/src/modules/diskio/diskio.c b/src/modules/diskio/diskio.c index ef1b72801..c54d16e69 100644 --- a/src/modules/diskio/diskio.c +++ b/src/modules/diskio/diskio.c @@ -215,7 +215,16 @@ void ffPrintDiskIOHelpFormat(void) void ffInitDiskIOOptions(FFDiskIOOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISKIO_MODULE_NAME, ffParseDiskIOCommandOptions, ffParseDiskIOJsonObject, ffPrintDiskIO, ffGenerateDiskIOJsonResult, ffPrintDiskIOHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_DISKIO_MODULE_NAME, + ffParseDiskIOCommandOptions, + ffParseDiskIOJsonObject, + ffPrintDiskIO, + ffGenerateDiskIOJsonResult, + ffPrintDiskIOHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->namePrefix); diff --git a/src/modules/display/display.c b/src/modules/display/display.c index 13f83c689..56b858ccd 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -228,7 +228,16 @@ void ffPrintDisplayHelpFormat(void) void ffInitDisplayOptions(FFDisplayOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_DISPLAY_MODULE_NAME, ffParseDisplayCommandOptions, ffParseDisplayJsonObject, ffPrintDisplay, ffGenerateDisplayJsonResult, ffPrintDisplayHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_DISPLAY_MODULE_NAME, + ffParseDisplayCommandOptions, + ffParseDisplayJsonObject, + ffPrintDisplay, + ffGenerateDisplayJsonResult, + ffPrintDisplayHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); options->compactType = FF_DISPLAY_COMPACT_TYPE_NONE; options->preciseRefreshRate = false; diff --git a/src/modules/font/font.c b/src/modules/font/font.c index 589a15331..aa8432987 100644 --- a/src/modules/font/font.c +++ b/src/modules/font/font.c @@ -109,7 +109,16 @@ void ffPrintFontHelpFormat(void) void ffInitFontOptions(FFFontOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_FONT_MODULE_NAME, ffParseFontCommandOptions, ffParseFontJsonObject, ffPrintFont, ffGenerateFontJsonResult, ffPrintFontHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_FONT_MODULE_NAME, + ffParseFontCommandOptions, + ffParseFontJsonObject, + ffPrintFont, + ffGenerateFontJsonResult, + ffPrintFontHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index 39194b30c..7db46fee8 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -119,7 +119,16 @@ void ffPrintGamepadHelpFormat(void) void ffInitGamepadOptions(FFGamepadOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GAMEPAD_MODULE_NAME, ffParseGamepadCommandOptions, ffParseGamepadJsonObject, ffPrintGamepad, ffGenerateGamepadJsonResult, ffPrintGamepadHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_GAMEPAD_MODULE_NAME, + ffParseGamepadCommandOptions, + ffParseGamepadJsonObject, + ffPrintGamepad, + ffGenerateGamepadJsonResult, + ffPrintGamepadHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 3189549fa..e73267609 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -285,7 +285,16 @@ void ffPrintGPUHelpFormat(void) void ffInitGPUOptions(FFGPUOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_GPU_MODULE_NAME, ffParseGPUCommandOptions, ffParseGPUJsonObject, ffPrintGPU, ffGenerateGPUJsonResult, ffPrintGPUHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_GPU_MODULE_NAME, + ffParseGPUCommandOptions, + ffParseGPUJsonObject, + ffPrintGPU, + ffGenerateGPUJsonResult, + ffPrintGPUHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); options->forceVulkan = false; diff --git a/src/modules/host/host.c b/src/modules/host/host.c index 28c5ab5f3..a3740e773 100644 --- a/src/modules/host/host.c +++ b/src/modules/host/host.c @@ -142,7 +142,16 @@ void ffPrintHostHelpFormat(void) void ffInitHostOptions(FFHostOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_HOST_MODULE_NAME, ffParseHostCommandOptions, ffParseHostJsonObject, ffPrintHost, ffGenerateHostJsonResult, ffPrintHostHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_HOST_MODULE_NAME, + ffParseHostCommandOptions, + ffParseHostJsonObject, + ffPrintHost, + ffGenerateHostJsonResult, + ffPrintHostHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/icons/icons.c b/src/modules/icons/icons.c index eff569649..02a8c9899 100644 --- a/src/modules/icons/icons.c +++ b/src/modules/icons/icons.c @@ -80,7 +80,16 @@ void ffPrintIconsHelpFormat(void) void ffInitIconsOptions(FFIconsOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_ICONS_MODULE_NAME, ffParseIconsCommandOptions, ffParseIconsJsonObject, ffPrintIcons, ffGenerateIconsJsonResult, ffPrintIconsHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_ICONS_MODULE_NAME, + ffParseIconsCommandOptions, + ffParseIconsJsonObject, + ffPrintIcons, + ffGenerateIconsJsonResult, + ffPrintIconsHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/kernel/kernel.c b/src/modules/kernel/kernel.c index 4fab5cd7d..cf3838107 100644 --- a/src/modules/kernel/kernel.c +++ b/src/modules/kernel/kernel.c @@ -78,7 +78,16 @@ void ffPrintKernelHelpFormat(void) void ffInitKernelOptions(FFKernelOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_KERNEL_MODULE_NAME, ffParseKernelCommandOptions, ffParseKernelJsonObject, ffPrintKernel, ffGenerateKernelJsonResult, ffPrintKernelHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_KERNEL_MODULE_NAME, + ffParseKernelCommandOptions, + ffParseKernelJsonObject, + ffPrintKernel, + ffGenerateKernelJsonResult, + ffPrintKernelHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/lm/lm.c b/src/modules/lm/lm.c index 95aa56896..61f3573ec 100644 --- a/src/modules/lm/lm.c +++ b/src/modules/lm/lm.c @@ -118,7 +118,16 @@ void ffPrintLMHelpFormat(void) void ffInitLMOptions(FFLMOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LM_MODULE_NAME, ffParseLMCommandOptions, ffParseLMJsonObject, ffPrintLM, ffGenerateLMJsonResult, ffPrintLMHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_LM_MODULE_NAME, + ffParseLMCommandOptions, + ffParseLMJsonObject, + ffPrintLM, + ffGenerateLMJsonResult, + ffPrintLMHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/locale/locale.c b/src/modules/locale/locale.c index 18e4e67a7..ec28ee864 100644 --- a/src/modules/locale/locale.c +++ b/src/modules/locale/locale.c @@ -80,7 +80,16 @@ void ffPrintLocaleHelpFormat(void) void ffInitLocaleOptions(FFLocaleOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALE_MODULE_NAME, ffParseLocaleCommandOptions, ffParseLocaleJsonObject, ffPrintLocale, ffGenerateLocaleJsonResult, ffPrintLocaleHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_LOCALE_MODULE_NAME, + ffParseLocaleCommandOptions, + ffParseLocaleJsonObject, + ffPrintLocale, + ffGenerateLocaleJsonResult, + ffPrintLocaleHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index f95b1cfc0..8d5877a14 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -324,7 +324,16 @@ void ffPrintLocalIpHelpFormat(void) void ffInitLocalIpOptions(FFLocalIpOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_LOCALIP_MODULE_NAME, ffParseLocalIpCommandOptions, ffParseLocalIpJsonObject, ffPrintLocalIp, ffGenerateLocalIpJsonResult, ffPrintLocalIpHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_LOCALIP_MODULE_NAME, + ffParseLocalIpCommandOptions, + ffParseLocalIpJsonObject, + ffPrintLocalIp, + ffGenerateLocalIpJsonResult, + ffPrintLocalIpHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); options->showType = FF_LOCALIP_TYPE_IPV4_BIT; diff --git a/src/modules/media/media.c b/src/modules/media/media.c index 7769dc4fa..d9472afc4 100644 --- a/src/modules/media/media.c +++ b/src/modules/media/media.c @@ -162,7 +162,16 @@ void ffPrintMediaHelpFormat(void) void ffInitMediaOptions(FFMediaOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEDIA_MODULE_NAME, ffParseMediaCommandOptions, ffParseMediaJsonObject, ffPrintMedia, ffGenerateMediaJsonResult, ffPrintMediaHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_MEDIA_MODULE_NAME, + ffParseMediaCommandOptions, + ffParseMediaJsonObject, + ffPrintMedia, + ffGenerateMediaJsonResult, + ffPrintMediaHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 018ab2def..3e727ca98 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -120,7 +120,16 @@ void ffPrintMemoryHelpFormat(void) void ffInitMemoryOptions(FFMemoryOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MEMORY_MODULE_NAME, ffParseMemoryCommandOptions, ffParseMemoryJsonObject, ffPrintMemory, ffGenerateMemoryJsonResult, ffPrintMemoryHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_MEMORY_MODULE_NAME, + ffParseMemoryCommandOptions, + ffParseMemoryJsonObject, + ffPrintMemory, + ffGenerateMemoryJsonResult, + ffPrintMemoryHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/monitor/monitor.c b/src/modules/monitor/monitor.c index cd42ddf35..99ee0da98 100644 --- a/src/modules/monitor/monitor.c +++ b/src/modules/monitor/monitor.c @@ -152,7 +152,16 @@ void ffPrintMonitorHelpFormat(void) void ffInitMonitorOptions(FFMonitorOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_MONITOR_MODULE_NAME, ffParseMonitorCommandOptions, ffParseMonitorJsonObject, ffPrintMonitor, ffGenerateMonitorJsonResult, ffPrintMonitorHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_MONITOR_MODULE_NAME, + ffParseMonitorCommandOptions, + ffParseMonitorJsonObject, + ffPrintMonitor, + ffGenerateMonitorJsonResult, + ffPrintMonitorHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index 8f76365fd..8428bbbf0 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -203,7 +203,16 @@ void ffPrintNetIOHelpFormat(void) void ffInitNetIOOptions(FFNetIOOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_NETIO_MODULE_NAME, ffParseNetIOCommandOptions, ffParseNetIOJsonObject, ffPrintNetIO, ffGenerateNetIOJsonResult, ffPrintNetIOHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_NETIO_MODULE_NAME, + ffParseNetIOCommandOptions, + ffParseNetIOJsonObject, + ffPrintNetIO, + ffGenerateNetIOJsonResult, + ffPrintNetIOHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->namePrefix); diff --git a/src/modules/opencl/opencl.c b/src/modules/opencl/opencl.c index fd9015cb3..951a42d5c 100644 --- a/src/modules/opencl/opencl.c +++ b/src/modules/opencl/opencl.c @@ -103,7 +103,16 @@ void ffPrintOpenCLHelpFormat(void) void ffInitOpenCLOptions(FFOpenCLOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENCL_MODULE_NAME, ffParseOpenCLCommandOptions, ffParseOpenCLJsonObject, ffPrintOpenCL, ffGenerateOpenCLJsonResult, ffPrintOpenCLHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_OPENCL_MODULE_NAME, + ffParseOpenCLCommandOptions, + ffParseOpenCLJsonObject, + ffPrintOpenCL, + ffGenerateOpenCLJsonResult, + ffPrintOpenCLHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index b579c7526..fbf819c90 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -141,7 +141,16 @@ void ffPrintOpenGLHelpFormat(void) void ffInitOpenGLOptions(FFOpenGLOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OPENGL_MODULE_NAME, ffParseOpenGLCommandOptions, ffParseOpenGLJsonObject, ffPrintOpenGL, ffGenerateOpenGLJsonResult, ffPrintOpenGLHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_OPENGL_MODULE_NAME, + ffParseOpenGLCommandOptions, + ffParseOpenGLJsonObject, + ffPrintOpenGL, + ffGenerateOpenGLJsonResult, + ffPrintOpenGLHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); #if defined(__linux__) || defined(__FreeBSD__) diff --git a/src/modules/os/os.c b/src/modules/os/os.c index 037c769ca..408fa8f86 100644 --- a/src/modules/os/os.c +++ b/src/modules/os/os.c @@ -206,7 +206,16 @@ void ffPrintOSHelpFormat(void) void ffInitOSOptions(FFOSOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_OS_MODULE_NAME, ffParseOSCommandOptions, ffParseOSJsonObject, ffPrintOS, ffGenerateOSJsonResult, ffPrintOSHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_OS_MODULE_NAME, + ffParseOSCommandOptions, + ffParseOSJsonObject, + ffPrintOS, + ffGenerateOSJsonResult, + ffPrintOSHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index be900d904..a795a02c5 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -206,7 +206,16 @@ void ffPrintPackagesHelpFormat(void) void ffInitPackagesOptions(FFPackagesOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PACKAGES_MODULE_NAME, ffParsePackagesCommandOptions, ffParsePackagesJsonObject, ffPrintPackages, ffGeneratePackagesJsonResult, ffPrintPackagesHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_PACKAGES_MODULE_NAME, + ffParsePackagesCommandOptions, + ffParsePackagesJsonObject, + ffPrintPackages, + ffGeneratePackagesJsonResult, + ffPrintPackagesHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/player/player.c b/src/modules/player/player.c index ff0860f63..8d90c2c18 100644 --- a/src/modules/player/player.c +++ b/src/modules/player/player.c @@ -128,7 +128,16 @@ void ffPrintPlayerHelpFormat(void) void ffInitPlayerOptions(FFPlayerOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PLAYER_MODULE_NAME, ffParsePlayerCommandOptions, ffParsePlayerJsonObject, ffPrintPlayer, ffGeneratePlayerJsonResult, ffPrintPlayerHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_PLAYER_MODULE_NAME, + ffParsePlayerCommandOptions, + ffParsePlayerJsonObject, + ffPrintPlayer, + ffGeneratePlayerJsonResult, + ffPrintPlayerHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/poweradapter/poweradapter.c b/src/modules/poweradapter/poweradapter.c index 626861b22..6ae9ab738 100644 --- a/src/modules/poweradapter/poweradapter.c +++ b/src/modules/poweradapter/poweradapter.c @@ -129,7 +129,16 @@ void ffPrintPowerAdapterHelpFormat(void) void ffInitPowerAdapterOptions(FFPowerAdapterOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_POWERADAPTER_MODULE_NAME, ffParsePowerAdapterCommandOptions, ffParsePowerAdapterJsonObject, ffPrintPowerAdapter, ffGeneratePowerAdapterJsonResult, ffPrintPowerAdapterHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_POWERADAPTER_MODULE_NAME, + ffParsePowerAdapterCommandOptions, + ffParsePowerAdapterJsonObject, + ffPrintPowerAdapter, + ffGeneratePowerAdapterJsonResult, + ffPrintPowerAdapterHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/processes/processes.c b/src/modules/processes/processes.c index ea9517234..05a28ba02 100644 --- a/src/modules/processes/processes.c +++ b/src/modules/processes/processes.c @@ -81,7 +81,16 @@ void ffPrintProcessesHelpFormat(void) void ffInitProcessesOptions(FFProcessesOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PROCESSES_MODULE_NAME, ffParseProcessesCommandOptions, ffParseProcessesJsonObject, ffPrintProcesses, ffGenerateProcessesJsonResult, ffPrintProcessesHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_PROCESSES_MODULE_NAME, + ffParseProcessesCommandOptions, + ffParseProcessesJsonObject, + ffPrintProcesses, + ffGenerateProcessesJsonResult, + ffPrintProcessesHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/publicip/publicip.c b/src/modules/publicip/publicip.c index 7a469536e..9a83a01fa 100644 --- a/src/modules/publicip/publicip.c +++ b/src/modules/publicip/publicip.c @@ -122,7 +122,16 @@ void ffPrintPublicIpHelpFormat(void) void ffInitPublicIpOptions(FFPublicIpOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_PUBLICIP_MODULE_NAME, ffParsePublicIpCommandOptions, ffParsePublicIpJsonObject, ffPrintPublicIp, ffGeneratePublicIpJsonResult, ffPrintPublicIpHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_PUBLICIP_MODULE_NAME, + ffParsePublicIpCommandOptions, + ffParsePublicIpJsonObject, + ffPrintPublicIp, + ffGeneratePublicIpJsonResult, + ffPrintPublicIpHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->url); diff --git a/src/modules/separator/separator.c b/src/modules/separator/separator.c index 5d0c87e6d..2c71c01f4 100644 --- a/src/modules/separator/separator.c +++ b/src/modules/separator/separator.c @@ -111,7 +111,16 @@ void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module) void ffInitSeparatorOptions(FFSeparatorOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SEPARATOR_MODULE_NAME, ffParseSeparatorCommandOptions, ffParseSeparatorJsonObject, ffPrintSeparator, NULL, NULL); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_SEPARATOR_MODULE_NAME, + ffParseSeparatorCommandOptions, + ffParseSeparatorJsonObject, + ffPrintSeparator, + NULL, + NULL, + NULL + ); ffStrbufInit(&options->string); } diff --git a/src/modules/shell/shell.c b/src/modules/shell/shell.c index a74a0eb6e..5a7b237d0 100644 --- a/src/modules/shell/shell.c +++ b/src/modules/shell/shell.c @@ -101,7 +101,16 @@ void ffPrintShellHelpFormat(void) void ffInitShellOptions(FFShellOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SHELL_MODULE_NAME, ffParseShellCommandOptions, ffParseShellJsonObject, ffPrintShell, ffGenerateShellJsonResult, ffPrintShellHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_SHELL_MODULE_NAME, + ffParseShellCommandOptions, + ffParseShellJsonObject, + ffPrintShell, + ffGenerateShellJsonResult, + ffPrintShellHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 2c00a388f..235cdb220 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -189,7 +189,16 @@ void ffPrintSoundHelpFormat(void) void ffInitSoundOptions(FFSoundOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SOUND_MODULE_NAME, ffParseSoundCommandOptions, ffParseSoundJsonObject, ffPrintSound, ffGenerateSoundJsonResult, ffPrintSoundHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_SOUND_MODULE_NAME, + ffParseSoundCommandOptions, + ffParseSoundJsonObject, + ffPrintSound, + ffGenerateSoundJsonResult, + ffPrintSoundHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); options->soundType = FF_SOUND_TYPE_MAIN; diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index d0c3d080a..96e092a86 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -127,7 +127,16 @@ void ffPrintSwapHelpFormat(void) void ffInitSwapOptions(FFSwapOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_SWAP_MODULE_NAME, ffParseSwapCommandOptions, ffParseSwapJsonObject, ffPrintSwap, ffGenerateSwapJsonResult, ffPrintSwapHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_SWAP_MODULE_NAME, + ffParseSwapCommandOptions, + ffParseSwapJsonObject, + ffPrintSwap, + ffGenerateSwapJsonResult, + ffPrintSwapHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index 6cb379575..d157cec38 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -100,7 +100,16 @@ void ffPrintTerminalHelpFormat(void) void ffInitTerminalOptions(FFTerminalOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINAL_MODULE_NAME, ffParseTerminalCommandOptions, ffParseTerminalJsonObject, ffPrintTerminal, ffGenerateTerminalJsonResult, ffPrintTerminalHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_TERMINAL_MODULE_NAME, + ffParseTerminalCommandOptions, + ffParseTerminalJsonObject, + ffPrintTerminal, + ffGenerateTerminalJsonResult, + ffPrintTerminalHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/terminalfont/terminalfont.c b/src/modules/terminalfont/terminalfont.c index a1be63293..b4719274f 100644 --- a/src/modules/terminalfont/terminalfont.c +++ b/src/modules/terminalfont/terminalfont.c @@ -126,7 +126,16 @@ void ffPrintTerminalFontHelpFormat(void) void ffInitTerminalFontOptions(FFTerminalFontOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALFONT_MODULE_NAME, ffParseTerminalFontCommandOptions, ffParseTerminalFontJsonObject, ffPrintTerminalFont, ffGenerateTerminalFontJsonResult, ffPrintTerminalFontHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_TERMINALFONT_MODULE_NAME, + ffParseTerminalFontCommandOptions, + ffParseTerminalFontJsonObject, + ffPrintTerminalFont, + ffGenerateTerminalFontJsonResult, + ffPrintTerminalFontHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/terminalsize/terminalsize.c b/src/modules/terminalsize/terminalsize.c index 3d94d09c4..432912ac4 100644 --- a/src/modules/terminalsize/terminalsize.c +++ b/src/modules/terminalsize/terminalsize.c @@ -95,7 +95,16 @@ void ffPrintTerminalSizeHelpFormat(void) void ffInitTerminalSizeOptions(FFTerminalSizeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TERMINALSIZE_MODULE_NAME, ffParseTerminalSizeCommandOptions, ffParseTerminalSizeJsonObject, ffPrintTerminalSize, ffGenerateTerminalSizeJsonResult, ffPrintTerminalSizeHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_TERMINALSIZE_MODULE_NAME, + ffParseTerminalSizeCommandOptions, + ffParseTerminalSizeJsonObject, + ffPrintTerminalSize, + ffGenerateTerminalSizeJsonResult, + ffPrintTerminalSizeHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/theme/theme.c b/src/modules/theme/theme.c index 2f373d0ae..40b50c0b0 100644 --- a/src/modules/theme/theme.c +++ b/src/modules/theme/theme.c @@ -80,7 +80,16 @@ void ffPrintThemeHelpFormat(void) void ffInitThemeOptions(FFThemeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_THEME_MODULE_NAME, ffParseThemeCommandOptions, ffParseThemeJsonObject, ffPrintTheme, ffGenerateThemeJsonResult, ffPrintThemeHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_THEME_MODULE_NAME, + ffParseThemeCommandOptions, + ffParseThemeJsonObject, + ffPrintTheme, + ffGenerateThemeJsonResult, + ffPrintThemeHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/title/title.c b/src/modules/title/title.c index d1283be27..5757c4a48 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -169,7 +169,16 @@ void ffPrintTitleHelpFormat(void) void ffInitTitleOptions(FFTitleOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_TITLE_MODULE_NAME, ffParseTitleCommandOptions, ffParseTitleJsonObject, ffPrintTitle, ffGenerateTitleJsonResult, ffPrintTitleHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_TITLE_MODULE_NAME, + ffParseTitleCommandOptions, + ffParseTitleJsonObject, + ffPrintTitle, + ffGenerateTitleJsonResult, + ffPrintTitleHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufSetStatic(&options->moduleArgs.key, " "); diff --git a/src/modules/uptime/uptime.c b/src/modules/uptime/uptime.c index dbef0de67..432c2c3a0 100644 --- a/src/modules/uptime/uptime.c +++ b/src/modules/uptime/uptime.c @@ -144,7 +144,16 @@ void ffPrintUptimeHelpFormat(void) void ffInitUptimeOptions(FFUptimeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_UPTIME_MODULE_NAME, ffParseUptimeCommandOptions, ffParseUptimeJsonObject, ffPrintUptime, ffGenerateUptimeJsonResult, ffPrintUptimeHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_UPTIME_MODULE_NAME, + ffParseUptimeCommandOptions, + ffParseUptimeJsonObject, + ffPrintUptime, + ffGenerateUptimeJsonResult, + ffPrintUptimeHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/users/users.c b/src/modules/users/users.c index 8df069fb4..9a53c43e6 100644 --- a/src/modules/users/users.c +++ b/src/modules/users/users.c @@ -176,7 +176,16 @@ void ffPrintUsersHelpFormat(void) void ffInitUsersOptions(FFUsersOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_USERS_MODULE_NAME, ffParseUsersCommandOptions, ffParseUsersJsonObject, ffPrintUsers, ffGenerateUsersJsonResult, ffPrintUsersHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_USERS_MODULE_NAME, + ffParseUsersCommandOptions, + ffParseUsersJsonObject, + ffPrintUsers, + ffGenerateUsersJsonResult, + ffPrintUsersHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); options->compact = false; diff --git a/src/modules/version/version.c b/src/modules/version/version.c index 860a56079..0fce05a4f 100644 --- a/src/modules/version/version.c +++ b/src/modules/version/version.c @@ -121,7 +121,16 @@ void ffPrintVersionHelpFormat(void) void ffInitVersionOptions(FFVersionOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VERSION_MODULE_NAME, ffParseVersionCommandOptions, ffParseVersionJsonObject, ffPrintVersion, ffGenerateVersionJsonResult, ffPrintVersionHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_VERSION_MODULE_NAME, + ffParseVersionCommandOptions, + ffParseVersionJsonObject, + ffPrintVersion, + ffGenerateVersionJsonResult, + ffPrintVersionHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/vulkan/vulkan.c b/src/modules/vulkan/vulkan.c index 5fa1bca9c..78f1a892e 100644 --- a/src/modules/vulkan/vulkan.c +++ b/src/modules/vulkan/vulkan.c @@ -137,7 +137,16 @@ void ffPrintVulkanHelpFormat(void) void ffInitVulkanOptions(FFVulkanOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_VULKAN_MODULE_NAME, ffParseVulkanCommandOptions, ffParseVulkanJsonObject, ffPrintVulkan, ffGenerateVulkanJsonResult, ffPrintVulkanHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_VULKAN_MODULE_NAME, + ffParseVulkanCommandOptions, + ffParseVulkanJsonObject, + ffPrintVulkan, + ffGenerateVulkanJsonResult, + ffPrintVulkanHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/wallpaper/wallpaper.c b/src/modules/wallpaper/wallpaper.c index c5c7de2cb..720daa428 100644 --- a/src/modules/wallpaper/wallpaper.c +++ b/src/modules/wallpaper/wallpaper.c @@ -90,7 +90,16 @@ void ffPrintWallpaperHelpFormat(void) void ffInitWallpaperOptions(FFWallpaperOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperCommandOptions, ffParseWallpaperJsonObject, ffPrintWallpaper, ffGenerateWallpaperJsonResult, ffPrintWallpaperHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_WALLPAPER_MODULE_NAME, + ffParseWallpaperCommandOptions, + ffParseWallpaperJsonObject, + ffPrintWallpaper, + ffGenerateWallpaperJsonResult, + ffPrintWallpaperHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/weather/weather.c b/src/modules/weather/weather.c index 47c5f1bc8..42e2d4d5b 100644 --- a/src/modules/weather/weather.c +++ b/src/modules/weather/weather.c @@ -117,7 +117,16 @@ void ffPrintWeatherHelpFormat(void) void ffInitWeatherOptions(FFWeatherOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WEATHER_MODULE_NAME, ffParseWeatherCommandOptions, ffParseWeatherJsonObject, ffPrintWeather, ffGenerateWeatherJsonResult, ffPrintWeatherHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_WEATHER_MODULE_NAME, + ffParseWeatherCommandOptions, + ffParseWeatherJsonObject, + ffPrintWeather, + ffGenerateWeatherJsonResult, + ffPrintWeatherHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->location); diff --git a/src/modules/wifi/wifi.c b/src/modules/wifi/wifi.c index 766eac1ec..8ca221c61 100644 --- a/src/modules/wifi/wifi.c +++ b/src/modules/wifi/wifi.c @@ -161,7 +161,16 @@ void ffPrintWifiHelpFormat(void) void ffInitWifiOptions(FFWifiOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WIFI_MODULE_NAME, ffParseWifiCommandOptions, ffParseWifiJsonObject, ffPrintWifi, ffGenerateWifiJsonResult, ffPrintWifiHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_WIFI_MODULE_NAME, + ffParseWifiCommandOptions, + ffParseWifiJsonObject, + ffPrintWifi, + ffGenerateWifiJsonResult, + ffPrintWifiHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index 973eabac7..15005b788 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -94,7 +94,16 @@ void ffPrintWMHelpFormat(void) void ffInitWMOptions(FFWMOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WM_MODULE_NAME, ffParseWMCommandOptions, ffParseWMJsonObject, ffPrintWM, ffGenerateWMJsonResult, ffPrintWMHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_WM_MODULE_NAME, + ffParseWMCommandOptions, + ffParseWMJsonObject, + ffPrintWM, + ffGenerateWMJsonResult, + ffPrintWMHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/wmtheme/wmtheme.c b/src/modules/wmtheme/wmtheme.c index f47260aed..f3b8c3177 100644 --- a/src/modules/wmtheme/wmtheme.c +++ b/src/modules/wmtheme/wmtheme.c @@ -78,7 +78,16 @@ void ffPrintWMthemeHelpFormat(void) void ffInitWMThemeOptions(FFWMThemeOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WMTHEME_MODULE_NAME, ffParseWMThemeCommandOptions, ffParseWMThemeJsonObject, ffPrintWMTheme, ffGenerateWMThemeJsonResult, ffPrintWMthemeHelpFormat); + ffOptionInitModuleBaseInfo( + &options->moduleInfo, + FF_WMTHEME_MODULE_NAME, + ffParseWMThemeCommandOptions, + ffParseWMThemeJsonObject, + ffPrintWMTheme, + ffGenerateWMThemeJsonResult, + ffPrintWMthemeHelpFormat, + NULL + ); ffOptionInitModuleArg(&options->moduleArgs); } From a7621a73012edc983829c5c6f0a5b5771c82c916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 23 Oct 2023 16:33:25 +0800 Subject: [PATCH 011/100] Break: remove redundant code --- src/modules/break/break.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/modules/break/break.c b/src/modules/break/break.c index cdd8ba2c9..a9588dffc 100644 --- a/src/modules/break/break.c +++ b/src/modules/break/break.c @@ -14,8 +14,6 @@ bool ffParseBreakCommandOptions(FF_MAYBE_UNUSED FFBreakOptions* options, FF_MAYB void ffParseBreakJsonObject(FF_MAYBE_UNUSED FFBreakOptions* options, FF_MAYBE_UNUSED yyjson_val* module) { - ffPrintBreak(options); - return; } void ffInitBreakOptions(FF_MAYBE_UNUSED FFBreakOptions* options) From be2af8aeaf41d390f850dfb5ed2e225f354e0eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 23 Oct 2023 16:34:33 +0800 Subject: [PATCH 012/100] Migration: support `bluetooth` and `board` --- src/modules/bluetooth/bluetooth.c | 13 ++++++++++++- src/modules/board/board.c | 10 +++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index 3439796cc..344d8e181 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -112,6 +112,17 @@ void ffParseBluetoothJsonObject(FFBluetoothOptions* options, yyjson_val* module) } } +void ffGenerateBluetoothJsonConfig(FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyBluetoothOptions))) FFBluetoothOptions defaultOptions; + ffInitBluetoothOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (options->showDisconnected != defaultOptions.showDisconnected) + yyjson_mut_obj_add_bool(doc, module, "showDisconnected", options->showDisconnected); +} + void ffGenerateBluetoothJsonResult(FF_MAYBE_UNUSED FFBluetoothOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFBluetoothResult)); @@ -165,7 +176,7 @@ void ffInitBluetoothOptions(FFBluetoothOptions* options) ffPrintBluetooth, ffGenerateBluetoothJsonResult, ffPrintBluetoothHelpFormat, - NULL + ffGenerateBluetoothJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); options->showDisconnected = false; diff --git a/src/modules/board/board.c b/src/modules/board/board.c index 5f6f633b8..414793abf 100644 --- a/src/modules/board/board.c +++ b/src/modules/board/board.c @@ -76,6 +76,14 @@ void ffParseBoardJsonObject(FFBoardOptions* options, yyjson_val* module) } } +void ffGenerateBoardJsonConfig(FFBoardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyBoardOptions))) FFBoardOptions defaultOptions; + ffInitBoardOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateBoardJsonResult(FF_MAYBE_UNUSED FFBoardOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFBoardResult board; @@ -127,7 +135,7 @@ void ffInitBoardOptions(FFBoardOptions* options) ffPrintBoard, ffGenerateBoardJsonResult, ffPrintBoardHelpFormat, - NULL + ffGenerateBoardJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } From 48d2dbad34b9f1eeeac5bc8be7420414d35c65d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 23 Oct 2023 18:42:40 +0800 Subject: [PATCH 013/100] Battery (Linux): fix build --- src/modules/battery/battery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index ad09a31c7..6a503cdc0 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -164,7 +164,7 @@ void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc, ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); #ifdef __linux__ - if (!ffStrbufEquals(&defaultOptions.dir, &options->dir)) + if (!ffStrbufEqual(&defaultOptions.dir, &options->dir)) yyjson_mut_obj_add_strbuf(doc, module, "dir", &options->dir); #endif From fc0db8c291a640f6ddbc7057a4a0cee4ff67d755 Mon Sep 17 00:00:00 2001 From: matoro Date: Mon, 23 Oct 2023 11:37:37 -0400 Subject: [PATCH 014/100] Host (Linux): devicetree path for OBP hosts (#591) At least SPARC devices have their model name in this devicetree node and do not have a "model" node. Possibly also POWER Macs, do not have one to test though. --- src/detection/host/host_linux.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/detection/host/host_linux.c b/src/detection/host/host_linux.c index 674d93b5e..269904eaf 100644 --- a/src/detection/host/host_linux.c +++ b/src/detection/host/host_linux.c @@ -28,6 +28,10 @@ static void getHostProductName(FFstrbuf* name) if(ffIsSmbiosValueSet(name)) return; + ffReadFileBuffer("/sys/firmware/devicetree/base/banner-name", name); + if(ffIsSmbiosValueSet(name)) + return; + //does a clear before the read ffReadFileBuffer("/tmp/sysinfo/model", name); if(ffIsSmbiosValueSet(name)) From 281af9c86fefc99ae11e2b9b52e84f8491f02082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 23 Oct 2023 22:20:28 +0800 Subject: [PATCH 015/100] Terminal (Linux): better support for tmux --- src/detection/terminalshell/terminalshell.h | 1 + .../terminalshell/terminalshell_linux.c | 17 +++++++++++++-- .../terminalshell/terminalshell_windows.c | 2 ++ src/modules/terminal/terminal.c | 21 ++++++++++++++----- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/detection/terminalshell/terminalshell.h b/src/detection/terminalshell/terminalshell.h index 41e31700f..5e9113d71 100644 --- a/src/detection/terminalshell/terminalshell.h +++ b/src/detection/terminalshell/terminalshell.h @@ -20,6 +20,7 @@ typedef struct FFTerminalShellResult const char* terminalExeName; //pointer to a char in terminalExe FFstrbuf terminalVersion; uint32_t terminalPid; + FFstrbuf terminalPlugins; } FFTerminalShellResult; const FFTerminalShellResult* ffDetectTerminalShell(); diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 810fe90bc..37ec1e87f 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -176,6 +176,18 @@ static void getTerminalShell(FFTerminalShellResult* result, pid_t pid) return; } + if (ffStrStartsWith(name, "tmux: ")) + { + if (result->terminalPlugins.length) + ffStrbufAppendS(&result->terminalPlugins, ", "); + ffStrbufAppendS(&result->terminalPlugins, "tmux "); + ffStrbufAppendS(&result->terminalPlugins, getenv("TERM_PROGRAM_VERSION")); + ffStrbufTrimRight(&result->terminalPlugins, ' '); + + getTerminalShell(result, ppid); + return; + } + #ifdef __APPLE__ // https://github.com/fastfetch-cli/fastfetch/discussions/501 if (ffStrEndsWith(name, " (figterm)")) @@ -236,8 +248,7 @@ static void getTerminalFromEnv(FFTerminalShellResult* result) //Termux if(!ffStrSet(term) && ( getenv("TERMUX_VERSION") != NULL || - getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL || - getenv("TMUX_TMPDIR") != NULL + getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL )) term = "com.termux"; #endif @@ -332,6 +343,8 @@ const FFTerminalShellResult* ffDetectTerminalShell() const uint32_t exePathLen = 260; #endif + ffStrbufInit(&result.terminalPlugins); + ffStrbufInit(&result.shellProcessName); ffStrbufInitA(&result.shellExe, exePathLen); result.shellExeName = result.shellExe.chars; diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index ebc062b33..ee0f287ba 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -366,6 +366,8 @@ const FFTerminalShellResult* ffDetectTerminalShell(void) } init = true; + ffStrbufInit(&result.terminalPlugins); + ffStrbufInit(&result.shellProcessName); ffStrbufInitA(&result.shellExe, 128); result.shellExeName = ""; diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index d157cec38..5f508263e 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -6,7 +6,7 @@ #include -#define FF_TERMINAL_NUM_FORMAT_ARGS 6 +#define FF_TERMINAL_NUM_FORMAT_ARGS 7 void ffPrintTerminal(FFTerminalOptions* options) { @@ -22,10 +22,18 @@ void ffPrintTerminal(FFTerminalOptions* options) { ffPrintLogoAndKey(FF_TERMINAL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); + ffStrbufWriteTo(&result->terminalPrettyName, stdout); + if(result->terminalVersion.length) - printf("%s %s\n", result->terminalPrettyName.chars, result->terminalVersion.chars); - else - ffStrbufPutTo(&result->terminalPrettyName, stdout); + { + putchar(' '); + ffStrbufWriteTo(&result->terminalVersion, stdout); + } + + if(result->terminalPlugins.length) + printf(" (with %s)", result->terminalPlugins.chars); + + putchar('\n'); } else { @@ -36,6 +44,7 @@ void ffPrintTerminal(FFTerminalOptions* options) {FF_FORMAT_ARG_TYPE_UINT, &result->terminalPid}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalPrettyName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalVersion}, + {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalPlugins}, }); } } @@ -84,6 +93,7 @@ void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yy yyjson_mut_obj_add_uint(doc, obj, "pid", result->terminalPid); yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->terminalPrettyName); yyjson_mut_obj_add_strbuf(doc, obj, "version", &result->terminalVersion); + yyjson_mut_obj_add_strbuf(doc, obj, "plugins", &result->terminalPlugins); } void ffPrintTerminalHelpFormat(void) @@ -94,7 +104,8 @@ void ffPrintTerminalHelpFormat(void) "Terminal exe name", "Terminal pid", "Terminal pretty name", - "Terminal version" + "Terminal version", + "Terminal plugins (e.g. tmux)" }); } From 40e2787d94dd691a601fb884ec6256b9ac945cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 24 Oct 2023 10:09:43 +0800 Subject: [PATCH 016/100] Revert "Terminal (Linux): better support for tmux" This reverts commit 281af9c86fefc99ae11e2b9b52e84f8491f02082. --- src/detection/terminalshell/terminalshell.h | 1 - .../terminalshell/terminalshell_linux.c | 17 ++------------- .../terminalshell/terminalshell_windows.c | 2 -- src/modules/terminal/terminal.c | 21 +++++-------------- 4 files changed, 7 insertions(+), 34 deletions(-) diff --git a/src/detection/terminalshell/terminalshell.h b/src/detection/terminalshell/terminalshell.h index 5e9113d71..41e31700f 100644 --- a/src/detection/terminalshell/terminalshell.h +++ b/src/detection/terminalshell/terminalshell.h @@ -20,7 +20,6 @@ typedef struct FFTerminalShellResult const char* terminalExeName; //pointer to a char in terminalExe FFstrbuf terminalVersion; uint32_t terminalPid; - FFstrbuf terminalPlugins; } FFTerminalShellResult; const FFTerminalShellResult* ffDetectTerminalShell(); diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 37ec1e87f..810fe90bc 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -176,18 +176,6 @@ static void getTerminalShell(FFTerminalShellResult* result, pid_t pid) return; } - if (ffStrStartsWith(name, "tmux: ")) - { - if (result->terminalPlugins.length) - ffStrbufAppendS(&result->terminalPlugins, ", "); - ffStrbufAppendS(&result->terminalPlugins, "tmux "); - ffStrbufAppendS(&result->terminalPlugins, getenv("TERM_PROGRAM_VERSION")); - ffStrbufTrimRight(&result->terminalPlugins, ' '); - - getTerminalShell(result, ppid); - return; - } - #ifdef __APPLE__ // https://github.com/fastfetch-cli/fastfetch/discussions/501 if (ffStrEndsWith(name, " (figterm)")) @@ -248,7 +236,8 @@ static void getTerminalFromEnv(FFTerminalShellResult* result) //Termux if(!ffStrSet(term) && ( getenv("TERMUX_VERSION") != NULL || - getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL + getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL || + getenv("TMUX_TMPDIR") != NULL )) term = "com.termux"; #endif @@ -343,8 +332,6 @@ const FFTerminalShellResult* ffDetectTerminalShell() const uint32_t exePathLen = 260; #endif - ffStrbufInit(&result.terminalPlugins); - ffStrbufInit(&result.shellProcessName); ffStrbufInitA(&result.shellExe, exePathLen); result.shellExeName = result.shellExe.chars; diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index ee0f287ba..ebc062b33 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -366,8 +366,6 @@ const FFTerminalShellResult* ffDetectTerminalShell(void) } init = true; - ffStrbufInit(&result.terminalPlugins); - ffStrbufInit(&result.shellProcessName); ffStrbufInitA(&result.shellExe, 128); result.shellExeName = ""; diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index 5f508263e..d157cec38 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -6,7 +6,7 @@ #include -#define FF_TERMINAL_NUM_FORMAT_ARGS 7 +#define FF_TERMINAL_NUM_FORMAT_ARGS 6 void ffPrintTerminal(FFTerminalOptions* options) { @@ -22,18 +22,10 @@ void ffPrintTerminal(FFTerminalOptions* options) { ffPrintLogoAndKey(FF_TERMINAL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); - ffStrbufWriteTo(&result->terminalPrettyName, stdout); - if(result->terminalVersion.length) - { - putchar(' '); - ffStrbufWriteTo(&result->terminalVersion, stdout); - } - - if(result->terminalPlugins.length) - printf(" (with %s)", result->terminalPlugins.chars); - - putchar('\n'); + printf("%s %s\n", result->terminalPrettyName.chars, result->terminalVersion.chars); + else + ffStrbufPutTo(&result->terminalPrettyName, stdout); } else { @@ -44,7 +36,6 @@ void ffPrintTerminal(FFTerminalOptions* options) {FF_FORMAT_ARG_TYPE_UINT, &result->terminalPid}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalPrettyName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalVersion}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalPlugins}, }); } } @@ -93,7 +84,6 @@ void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yy yyjson_mut_obj_add_uint(doc, obj, "pid", result->terminalPid); yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->terminalPrettyName); yyjson_mut_obj_add_strbuf(doc, obj, "version", &result->terminalVersion); - yyjson_mut_obj_add_strbuf(doc, obj, "plugins", &result->terminalPlugins); } void ffPrintTerminalHelpFormat(void) @@ -104,8 +94,7 @@ void ffPrintTerminalHelpFormat(void) "Terminal exe name", "Terminal pid", "Terminal pretty name", - "Terminal version", - "Terminal plugins (e.g. tmux)" + "Terminal version" }); } From 533231825c0e28062bfcdd4b24b90fdb27f809d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 24 Oct 2023 10:14:08 +0800 Subject: [PATCH 017/100] Terminal (Linux): detect `tmux: server` as tmux --- src/detection/terminalshell/terminalshell_linux.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 810fe90bc..7b72f8618 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -236,8 +236,7 @@ static void getTerminalFromEnv(FFTerminalShellResult* result) //Termux if(!ffStrSet(term) && ( getenv("TERMUX_VERSION") != NULL || - getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL || - getenv("TMUX_TMPDIR") != NULL + getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL )) term = "com.termux"; #endif @@ -373,9 +372,10 @@ const FFTerminalShellResult* ffDetectTerminalShell() result.terminalExeName + 1); } - if(ffStrbufEqualS(&result.terminalProcessName, "wezterm-gui")) ffStrbufInitStatic(&result.terminalPrettyName, "WezTerm"); + if(ffStrbufStartsWithS(&result.terminalProcessName, "tmux:")) + ffStrbufInitStatic(&result.terminalPrettyName, "tmux"); #if defined(__ANDROID__) From f4a263df01db151a6a7a5eebd2713c90a94b1cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 24 Oct 2023 14:41:29 +0800 Subject: [PATCH 018/100] Migration: finish modules support --- src/modules/brightness/brightness.c | 13 +++++++++- src/modules/chassis/chassis.c | 10 +++++++- src/modules/colors/colors.c | 26 ++++++++++++++++++- src/modules/command/command.c | 16 +++++++++++- src/modules/cpu/cpu.c | 20 ++++++++++++--- src/modules/cpuusage/cpuusage.c | 13 +++++++++- src/modules/cursor/cursor.c | 10 +++++++- src/modules/datetime/datetime.c | 10 +++++++- src/modules/de/de.c | 10 +++++++- src/modules/disk/disk.c | 34 ++++++++++++++++++++++++- src/modules/diskio/diskio.c | 13 +++++++++- src/modules/display/display.c | 29 ++++++++++++++++++++- src/modules/font/font.c | 10 +++++++- src/modules/gamepad/gamepad.c | 10 +++++++- src/modules/gpu/gpu.c | 32 ++++++++++++++++++++++- src/modules/host/host.c | 10 +++++++- src/modules/icons/icons.c | 10 +++++++- src/modules/kernel/kernel.c | 10 +++++++- src/modules/lm/lm.c | 10 +++++++- src/modules/locale/locale.c | 10 +++++++- src/modules/localip/localip.c | 34 ++++++++++++++++++++++++- src/modules/media/media.c | 10 +++++++- src/modules/memory/memory.c | 10 +++++++- src/modules/monitor/monitor.c | 10 +++++++- src/modules/netio/netio.c | 16 +++++++++++- src/modules/opencl/opencl.c | 10 +++++++- src/modules/opengl/opengl.c | 15 ++++++++++- src/modules/os/os.c | 10 +++++++- src/modules/packages/packages.c | 10 +++++++- src/modules/player/player.c | 10 +++++++- src/modules/poweradapter/poweradapter.c | 10 +++++++- src/modules/processes/processes.c | 10 +++++++- src/modules/publicip/publicip.c | 13 +++++++++- src/modules/separator/separator.c | 11 +++++++- src/modules/shell/shell.c | 10 +++++++- src/modules/sound/sound.c | 27 ++++++++++++++++++-- src/modules/swap/swap.c | 10 +++++++- src/modules/terminal/terminal.c | 10 +++++++- src/modules/terminalfont/terminalfont.c | 10 +++++++- src/modules/terminalsize/terminalsize.c | 10 +++++++- src/modules/theme/theme.c | 10 +++++++- src/modules/title/title.c | 27 +++++++++++++++++++- src/modules/uptime/uptime.c | 10 +++++++- src/modules/users/users.c | 13 +++++++++- src/modules/version/version.c | 10 +++++++- src/modules/vulkan/vulkan.c | 10 +++++++- src/modules/wallpaper/wallpaper.c | 10 +++++++- src/modules/weather/weather.c | 19 +++++++++++++- src/modules/wifi/wifi.c | 10 +++++++- src/modules/wm/wm.c | 10 +++++++- src/modules/wmtheme/wmtheme.c | 10 +++++++- 51 files changed, 647 insertions(+), 54 deletions(-) diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index fde35952e..df676f893 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -123,6 +123,17 @@ void ffParseBrightnessJsonObject(FFBrightnessOptions* options, yyjson_val* modul } } +void ffGenerateBrightnessJsonConfig(FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyBrightnessOptions))) FFBrightnessOptions defaultOptions; + ffInitBrightnessOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (defaultOptions.ddcciSleep != options->ddcciSleep) + yyjson_mut_obj_add_uint(doc, module, "ddcciSleep", options->ddcciSleep); +} + void ffGenerateBrightnessJsonResult(FF_MAYBE_UNUSED FFBrightnessOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFBrightnessResult)); @@ -180,7 +191,7 @@ void ffInitBrightnessOptions(FFBrightnessOptions* options) ffPrintBrightness, ffGenerateBrightnessJsonResult, ffPrintBrightnessHelpFormat, - NULL + ffGenerateBrightnessJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/chassis/chassis.c b/src/modules/chassis/chassis.c index 816059f67..bd1b0c208 100644 --- a/src/modules/chassis/chassis.c +++ b/src/modules/chassis/chassis.c @@ -77,6 +77,14 @@ void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module) } } +void ffGenerateChassisJsonConfig(FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyChassisOptions))) FFChassisOptions defaultOptions; + ffInitChassisOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFChassisResult result; @@ -128,7 +136,7 @@ void ffInitChassisOptions(FFChassisOptions* options) ffPrintChassis, ffGenerateChassisJsonResult, ffPrintChassisHelpFormat, - NULL + ffGenerateChassisJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/colors/colors.c b/src/modules/colors/colors.c index f33e9c682..9d6e65867 100644 --- a/src/modules/colors/colors.c +++ b/src/modules/colors/colors.c @@ -127,6 +127,30 @@ void ffParseColorsJsonObject(FFColorsOptions* options, yyjson_val* module) } } +void ffGenerateColorsJsonConfig(FFColorsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyColorsOptions))) FFColorsOptions defaultOptions; + ffInitColorsOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (defaultOptions.symbol != options->symbol) + { + switch (options->symbol) + { + case FF_COLORS_SYMBOL_CIRCLE: yyjson_mut_obj_add_str(doc, module, "symbol", "circle"); break; + case FF_COLORS_SYMBOL_DIAMOND: yyjson_mut_obj_add_str(doc, module, "symbol", "diamond"); break; + case FF_COLORS_SYMBOL_TRIANGLE: yyjson_mut_obj_add_str(doc, module, "symbol", "triangle"); break; + case FF_COLORS_SYMBOL_SQUARE: yyjson_mut_obj_add_str(doc, module, "symbol", "square"); break; + case FF_COLORS_SYMBOL_STAR: yyjson_mut_obj_add_str(doc, module, "symbol", "star"); break; + default: yyjson_mut_obj_add_str(doc, module, "symbol", "block"); break; + } + } + + if (defaultOptions.paddingLeft != options->paddingLeft) + yyjson_mut_obj_add_uint(doc, module, "paddingLeft", options->paddingLeft); +} + void ffInitColorsOptions(FFColorsOptions* options) { ffOptionInitModuleBaseInfo( @@ -137,7 +161,7 @@ void ffInitColorsOptions(FFColorsOptions* options) ffPrintColors, NULL, NULL, - NULL + ffGenerateColorsJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufSetStatic(&options->moduleArgs.key, " "); diff --git a/src/modules/command/command.c b/src/modules/command/command.c index 59114dacd..7f25c6ff8 100644 --- a/src/modules/command/command.c +++ b/src/modules/command/command.c @@ -96,6 +96,20 @@ void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module) } } +void ffGenerateCommandJsonConfig(FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyCommandOptions))) FFCommandOptions defaultOptions; + ffInitCommandOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (!ffStrbufEqual(&defaultOptions.shell, &options->shell)) + yyjson_mut_obj_add_strbuf(doc, module, "shell", &options->shell); + + if (!ffStrbufEqual(&defaultOptions.text, &options->text)) + yyjson_mut_obj_add_strbuf(doc, module, "text", &options->text); +} + void ffGenerateCommandJsonResult(FF_MAYBE_UNUSED FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); @@ -142,7 +156,7 @@ void ffInitCommandOptions(FFCommandOptions* options) ffPrintCommand, ffGenerateCommandJsonResult, ffPrintCommandHelpFormat, - NULL + ffGenerateCommandJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/cpu/cpu.c b/src/modules/cpu/cpu.c index fab9d77fa..4d41d4e0c 100644 --- a/src/modules/cpu/cpu.c +++ b/src/modules/cpu/cpu.c @@ -77,7 +77,7 @@ void ffPrintCPU(FFCPUOptions* options) ffStrbufDestroy(&cpu.vendor); } -bool ffParseCPUCommandOptions(FFCPUOptions* options, const char* key, const char* value) +bool ffParseCPUCPUOptions(FFCPUOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_CPU_MODULE_NAME); if (!subKey) return false; @@ -128,6 +128,20 @@ void ffParseCPUJsonObject(FFCPUOptions* options, yyjson_val* module) } } +void ffGenerateCPUJsonConfig(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyCPUOptions))) FFCPUOptions defaultOptions; + ffInitCPUOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (defaultOptions.temp != options->temp) + yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); + + if (defaultOptions.freqNdigits != options->freqNdigits) + yyjson_mut_obj_add_uint(doc, module, "freqNdigits", options->freqNdigits); +} + void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFCPUResult cpu; @@ -188,12 +202,12 @@ void ffInitCPUOptions(FFCPUOptions* options) ffOptionInitModuleBaseInfo( &options->moduleInfo, FF_CPU_MODULE_NAME, - ffParseCPUCommandOptions, + ffParseCPUCPUOptions, ffParseCPUJsonObject, ffPrintCPU, ffGenerateCPUJsonResult, ffPrintCPUHelpFormat, - NULL + ffGenerateCPUJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); options->temp = false; diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index 7a2418850..7583e30e3 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -124,6 +124,17 @@ void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module) } } +void ffGenerateCPUUsageJsonConfig(FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyCPUUsageOptions))) FFCPUUsageOptions defaultOptions; + ffInitCPUUsageOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (options->separate != defaultOptions.separate) + yyjson_mut_obj_add_bool(doc, module, "separate", options->separate); +} + void ffGenerateCPUUsageJsonResult(FF_MAYBE_UNUSED FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY percentages = ffListCreate(sizeof(double)); @@ -162,7 +173,7 @@ void ffInitCPUUsageOptions(FFCPUUsageOptions* options) ffPrintCPUUsage, ffGenerateCPUUsageJsonResult, ffPrintCPUUsageHelpFormat, - NULL + ffGenerateCPUUsageJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/cursor/cursor.c b/src/modules/cursor/cursor.c index 4f6dfd3e1..5e10f2bcd 100644 --- a/src/modules/cursor/cursor.c +++ b/src/modules/cursor/cursor.c @@ -77,6 +77,14 @@ void ffParseCursorJsonObject(FFCursorOptions* options, yyjson_val* module) } } +void ffGenerateCursorJsonConfig(FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyCursorOptions))) FFCursorOptions defaultOptions; + ffInitCursorOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateCursorJsonResult(FF_MAYBE_UNUSED FFCursorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFCursorResult result; @@ -119,7 +127,7 @@ void ffInitCursorOptions(FFCursorOptions* options) ffPrintCursor, ffGenerateCursorJsonResult, ffPrintCursorHelpFormat, - NULL + ffGenerateCursorJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/datetime/datetime.c b/src/modules/datetime/datetime.c index 08b9f356f..445f17088 100644 --- a/src/modules/datetime/datetime.c +++ b/src/modules/datetime/datetime.c @@ -168,6 +168,14 @@ void ffParseDateTimeJsonObject(FFDateTimeOptions* options, yyjson_val* module) } } +void ffGenerateDateTimeJsonConfig(FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyDateTimeOptions))) FFDateTimeOptions defaultOptions; + ffInitDateTimeOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateDateTimeJsonResult(FF_MAYBE_UNUSED FFDateTimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { yyjson_mut_obj_add_uint(doc, module, "result", ffTimeGetNow()); @@ -209,7 +217,7 @@ void ffInitDateTimeOptions(FFDateTimeOptions* options) ffPrintDateTime, ffGenerateDateTimeJsonResult, ffPrintDateTimeHelpFormat, - NULL + ffGenerateDateTimeJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/de/de.c b/src/modules/de/de.c index 4c804ebc7..ace665bf8 100644 --- a/src/modules/de/de.c +++ b/src/modules/de/de.c @@ -67,6 +67,14 @@ void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module) } } +void ffGenerateDEJsonConfig(FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyDEOptions))) FFDEOptions defaultOptions; + ffInitDEOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateDEJsonResult(FF_MAYBE_UNUSED FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFDisplayServerResult* result = ffConnectDisplayServer(); @@ -102,7 +110,7 @@ void ffInitDEOptions(FFDEOptions* options) ffPrintDE, ffGenerateDEJsonResult, ffPrintDEHelpFormat, - NULL + ffGenerateDEJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 0bd94e0d0..1a1f4b2d8 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -358,6 +358,38 @@ void ffParseDiskJsonObject(FFDiskOptions* options, yyjson_val* module) } } +void ffGenerateDiskJsonConfig(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyDiskOptions))) FFDiskOptions defaultOptions; + ffInitDiskOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (defaultOptions.showTypes != options->showTypes) + { + if (options->showTypes & FF_DISK_VOLUME_TYPE_EXTERNAL_BIT) + yyjson_mut_obj_add_bool(doc, module, "showExternal", true); + + if (options->showTypes & FF_DISK_VOLUME_TYPE_HIDDEN_BIT) + yyjson_mut_obj_add_bool(doc, module, "showHidden", true); + + if (options->showTypes & FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT) + yyjson_mut_obj_add_bool(doc, module, "showSubvolumes", true); + + if (options->showTypes & FF_DISK_VOLUME_TYPE_READONLY_BIT) + yyjson_mut_obj_add_bool(doc, module, "showReadOnly", true); + + if (options->showTypes & FF_DISK_VOLUME_TYPE_UNKNOWN_BIT) + yyjson_mut_obj_add_bool(doc, module, "showUnknown", true); + } + + if (!ffStrbufEqual(&options->folders, &defaultOptions.folders)) + yyjson_mut_obj_add_strbuf(doc, module, "folders", &options->folders); + + if (defaultOptions.calcType != options->calcType) + yyjson_mut_obj_add_bool(doc, module, "useAvailable", options->calcType == FF_DISK_CALC_TYPE_AVAILABLE); +} + void ffGenerateDiskJsonResult(FFDiskOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY disks = ffListCreate(sizeof (FFDisk)); @@ -436,7 +468,7 @@ void ffInitDiskOptions(FFDiskOptions* options) ffPrintDisk, ffGenerateDiskJsonResult, ffPrintDiskHelpFormat, - NULL + ffGenerateDiskJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/diskio/diskio.c b/src/modules/diskio/diskio.c index c54d16e69..585819b5a 100644 --- a/src/modules/diskio/diskio.c +++ b/src/modules/diskio/diskio.c @@ -151,6 +151,17 @@ void ffParseDiskIOJsonObject(FFDiskIOOptions* options, yyjson_val* module) } } +void ffGenerateDiskIOJsonConfig(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyDiskIOOptions))) FFDiskIOOptions defaultOptions; + ffInitDiskIOOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (!ffStrbufEqual(&options->namePrefix, &defaultOptions.namePrefix)) + yyjson_mut_obj_add_strbuf(doc, module, "namePrefix", &options->namePrefix); +} + void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFDiskIOResult)); @@ -223,7 +234,7 @@ void ffInitDiskIOOptions(FFDiskIOOptions* options) ffPrintDiskIO, ffGenerateDiskIOJsonResult, ffPrintDiskIOHelpFormat, - NULL + ffGenerateDiskIOJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/display/display.c b/src/modules/display/display.c index 56b858ccd..472ff01af 100644 --- a/src/modules/display/display.c +++ b/src/modules/display/display.c @@ -175,6 +175,33 @@ void ffParseDisplayJsonObject(FFDisplayOptions* options, yyjson_val* module) } } +void ffGenerateDisplayJsonConfig(FFDisplayOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyDisplayOptions))) FFDisplayOptions defaultOptions; + ffInitDisplayOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (options->compactType != defaultOptions.compactType) + { + switch (options->compactType) + { + case FF_DISPLAY_COMPACT_TYPE_NONE: + yyjson_mut_obj_add_str(doc, module, "compactType", "none"); + break; + case FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT: + yyjson_mut_obj_add_str(doc, module, "compactType", "original"); + break; + case FF_DISPLAY_COMPACT_TYPE_SCALED_BIT: + yyjson_mut_obj_add_str(doc, module, "compactType", "scaled"); + break; + } + } + + if (options->preciseRefreshRate != defaultOptions.preciseRefreshRate) + yyjson_mut_obj_add_bool(doc, module, "preciseRefreshRate", options->preciseRefreshRate); +} + void ffGenerateDisplayJsonResult(FF_MAYBE_UNUSED FFDisplayOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFDisplayServerResult* dsResult = ffConnectDisplayServer(); @@ -236,7 +263,7 @@ void ffInitDisplayOptions(FFDisplayOptions* options) ffPrintDisplay, ffGenerateDisplayJsonResult, ffPrintDisplayHelpFormat, - NULL + ffGenerateDisplayJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); options->compactType = FF_DISPLAY_COMPACT_TYPE_NONE; diff --git a/src/modules/font/font.c b/src/modules/font/font.c index aa8432987..98c8646e6 100644 --- a/src/modules/font/font.c +++ b/src/modules/font/font.c @@ -70,6 +70,14 @@ void ffParseFontJsonObject(FFFontOptions* options, yyjson_val* module) } } +void ffGenerateFontJsonConfig(FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyFontOptions))) FFFontOptions defaultOptions; + ffInitFontOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateFontJsonResult(FF_MAYBE_UNUSED FFFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFFontResult font; @@ -117,7 +125,7 @@ void ffInitFontOptions(FFFontOptions* options) ffPrintFont, ffGenerateFontJsonResult, ffPrintFontHelpFormat, - NULL + ffGenerateFontJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index 7db46fee8..05c02c6ba 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -76,6 +76,14 @@ void ffParseGamepadJsonObject(FFGamepadOptions* options, yyjson_val* module) } } +void ffGenerateGamepadJsonConfig(FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyGamepadOptions))) FFGamepadOptions defaultOptions; + ffInitGamepadOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateGamepadJsonResult(FF_MAYBE_UNUSED FFGamepadOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFGamepadDevice)); @@ -127,7 +135,7 @@ void ffInitGamepadOptions(FFGamepadOptions* options) ffPrintGamepad, ffGenerateGamepadJsonResult, ffPrintGamepadHelpFormat, - NULL + ffGenerateGamepadJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index e73267609..2a48e463d 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -200,6 +200,36 @@ void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module) } } +void ffGenerateGPUJsonConfig(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyGPUOptions))) FFGPUOptions defaultOptions; + ffInitGPUOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (options->forceVulkan != defaultOptions.forceVulkan) + yyjson_mut_obj_add_bool(doc, module, "forceVulkan", options->forceVulkan); + + if (options->temp != defaultOptions.temp) + yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); + + if (options->hideType != defaultOptions.hideType) + { + switch (options->hideType) + { + case FF_GPU_TYPE_UNKNOWN: + yyjson_mut_obj_add_str(doc, module, "hideType", "none"); + break; + case FF_GPU_TYPE_INTEGRATED: + yyjson_mut_obj_add_str(doc, module, "hideType", "intergrated"); + break; + case FF_GPU_TYPE_DISCRETE: + yyjson_mut_obj_add_str(doc, module, "hideType", "discrete"); + break; + } + } +} + void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY gpus = ffListCreate(sizeof (FFGPUResult)); @@ -293,7 +323,7 @@ void ffInitGPUOptions(FFGPUOptions* options) ffPrintGPU, ffGenerateGPUJsonResult, ffPrintGPUHelpFormat, - NULL + ffGenerateGPUJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/host/host.c b/src/modules/host/host.c index a3740e773..182954de1 100644 --- a/src/modules/host/host.c +++ b/src/modules/host/host.c @@ -92,6 +92,14 @@ void ffParseHostJsonObject(FFHostOptions* options, yyjson_val* module) } } +void ffGenerateHostJsonConfig(FFHostOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyHostOptions))) FFHostOptions defaultOptions; + ffInitHostOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateHostJsonResult(FF_MAYBE_UNUSED FFHostOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFHostResult host; @@ -150,7 +158,7 @@ void ffInitHostOptions(FFHostOptions* options) ffPrintHost, ffGenerateHostJsonResult, ffPrintHostHelpFormat, - NULL + ffGenerateHostJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/icons/icons.c b/src/modules/icons/icons.c index 02a8c9899..adfd336f9 100644 --- a/src/modules/icons/icons.c +++ b/src/modules/icons/icons.c @@ -57,6 +57,14 @@ void ffParseIconsJsonObject(FFIconsOptions* options, yyjson_val* module) } } +void ffGenerateIconsJsonConfig(FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyIconsOptions))) FFIconsOptions defaultOptions; + ffInitIconsOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateIconsJsonResult(FF_MAYBE_UNUSED FFIconsOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY icons = ffStrbufCreate(); @@ -88,7 +96,7 @@ void ffInitIconsOptions(FFIconsOptions* options) ffPrintIcons, ffGenerateIconsJsonResult, ffPrintIconsHelpFormat, - NULL + ffGenerateIconsJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/kernel/kernel.c b/src/modules/kernel/kernel.c index cf3838107..24600576f 100644 --- a/src/modules/kernel/kernel.c +++ b/src/modules/kernel/kernel.c @@ -57,6 +57,14 @@ void ffParseKernelJsonObject(FFKernelOptions* options, yyjson_val* module) } } +void ffGenerateKernelJsonConfig(FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyKernelOptions))) FFKernelOptions defaultOptions; + ffInitKernelOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateKernelJsonResult(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); @@ -86,7 +94,7 @@ void ffInitKernelOptions(FFKernelOptions* options) ffPrintKernel, ffGenerateKernelJsonResult, ffPrintKernelHelpFormat, - NULL + ffGenerateKernelJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/lm/lm.c b/src/modules/lm/lm.c index 61f3573ec..082591f3d 100644 --- a/src/modules/lm/lm.c +++ b/src/modules/lm/lm.c @@ -76,6 +76,14 @@ void ffParseLMJsonObject(FFLMOptions* options, yyjson_val* module) } } +void ffGenerateLMJsonConfig(FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyLMOptions))) FFLMOptions defaultOptions; + ffInitLMOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateLMJsonResult(FF_MAYBE_UNUSED FFLMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFLMResult result; @@ -126,7 +134,7 @@ void ffInitLMOptions(FFLMOptions* options) ffPrintLM, ffGenerateLMJsonResult, ffPrintLMHelpFormat, - NULL + ffGenerateLMJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/locale/locale.c b/src/modules/locale/locale.c index ec28ee864..8d6980434 100644 --- a/src/modules/locale/locale.c +++ b/src/modules/locale/locale.c @@ -57,6 +57,14 @@ void ffParseLocaleJsonObject(FFLocaleOptions* options, yyjson_val* module) } } +void ffGenerateLocaleJsonConfig(FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyLocaleOptions))) FFLocaleOptions defaultOptions; + ffInitLocaleOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateLocaleJsonResult(FF_MAYBE_UNUSED FFLocaleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY locale = ffStrbufCreate(); @@ -88,7 +96,7 @@ void ffInitLocaleOptions(FFLocaleOptions* options) ffPrintLocale, ffGenerateLocaleJsonResult, ffPrintLocaleHelpFormat, - NULL + ffGenerateLocaleJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index 8d5877a14..9f17891fc 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -272,6 +272,38 @@ void ffParseLocalIpJsonObject(FFLocalIpOptions* options, yyjson_val* module) } } +void ffGenerateLocalIpJsonConfig(FFLocalIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyLocalIpOptions))) FFLocalIpOptions defaultOptions; + ffInitLocalIpOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (defaultOptions.showType != options->showType) + { + if (options->showType & FF_LOCALIP_TYPE_IPV4_BIT) + yyjson_mut_obj_add_bool(doc, module, "showIpv4", true); + + if (options->showType & FF_LOCALIP_TYPE_IPV6_BIT) + yyjson_mut_obj_add_bool(doc, module, "showIpv6", true); + + if (options->showType & FF_LOCALIP_TYPE_MAC_BIT) + yyjson_mut_obj_add_bool(doc, module, "showMac", true); + + if (options->showType & FF_LOCALIP_TYPE_LOOP_BIT) + yyjson_mut_obj_add_bool(doc, module, "showLoop", true); + + if (options->showType & FF_LOCALIP_TYPE_COMPACT_BIT) + yyjson_mut_obj_add_bool(doc, module, "compact", true); + } + + if (!ffStrbufEqual(&options->namePrefix, &defaultOptions.namePrefix)) + yyjson_mut_obj_add_strbuf(doc, module, "namePrefix", &options->namePrefix); + + if (options->defaultRouteOnly != defaultOptions.defaultRouteOnly) + yyjson_mut_obj_add_bool(doc, module, "defaultRouteOnly", options->defaultRouteOnly); +} + void ffGenerateLocalIpJsonResult(FF_MAYBE_UNUSED FFLocalIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFLocalIpResult)); @@ -332,7 +364,7 @@ void ffInitLocalIpOptions(FFLocalIpOptions* options) ffPrintLocalIp, ffGenerateLocalIpJsonResult, ffPrintLocalIpHelpFormat, - NULL + ffGenerateLocalIpJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/media/media.c b/src/modules/media/media.c index d9472afc4..ebdc43e2f 100644 --- a/src/modules/media/media.c +++ b/src/modules/media/media.c @@ -132,6 +132,14 @@ void ffParseMediaJsonObject(FFMediaOptions* options, yyjson_val* module) } } +void ffGenerateMediaJsonConfig(FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyMediaOptions))) FFMediaOptions defaultOptions; + ffInitMediaOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateMediaJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFMediaResult* media = ffDetectMedia(); @@ -170,7 +178,7 @@ void ffInitMediaOptions(FFMediaOptions* options) ffPrintMedia, ffGenerateMediaJsonResult, ffPrintMediaHelpFormat, - NULL + ffGenerateMediaJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 3e727ca98..12d8b1717 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -93,6 +93,14 @@ void ffParseMemoryJsonObject(FFMemoryOptions* options, yyjson_val* module) } } +void ffGenerateMemoryJsonConfig(FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyMemoryOptions))) FFMemoryOptions defaultOptions; + ffInitMemoryOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateMemoryJsonResult(FF_MAYBE_UNUSED FFMemoryOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFMemoryResult storage; @@ -128,7 +136,7 @@ void ffInitMemoryOptions(FFMemoryOptions* options) ffPrintMemory, ffGenerateMemoryJsonResult, ffPrintMemoryHelpFormat, - NULL + ffGenerateMemoryJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/monitor/monitor.c b/src/modules/monitor/monitor.c index 99ee0da98..a53d4a029 100644 --- a/src/modules/monitor/monitor.c +++ b/src/modules/monitor/monitor.c @@ -102,6 +102,14 @@ void ffParseMonitorJsonObject(FFMonitorOptions* options, yyjson_val* module) } } +void ffGenerateMonitorJsonConfig(FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyMonitorOptions))) FFMonitorOptions defaultOptions; + ffInitMonitorOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateMonitorJsonResult(FF_MAYBE_UNUSED FFMonitorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFMonitorResult)); @@ -160,7 +168,7 @@ void ffInitMonitorOptions(FFMonitorOptions* options) ffPrintMonitor, ffGenerateMonitorJsonResult, ffPrintMonitorHelpFormat, - NULL + ffGenerateMonitorJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index 8428bbbf0..9542cb021 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -150,6 +150,20 @@ void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module) } } +void ffGenerateNetIOJsonConfig(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyNetIOOptions))) FFNetIOOptions defaultOptions; + ffInitNetIOOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (!ffStrbufEqual(&options->namePrefix, &defaultOptions.namePrefix)) + yyjson_mut_obj_add_strbuf(doc, module, "namePrefix", &options->namePrefix); + + if (options->defaultRouteOnly != defaultOptions.defaultRouteOnly) + yyjson_mut_obj_add_bool(doc, module, "defaultRouteOnly", options->defaultRouteOnly); +} + void ffGenerateNetIOJsonResult(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetIOResult)); @@ -211,7 +225,7 @@ void ffInitNetIOOptions(FFNetIOOptions* options) ffPrintNetIO, ffGenerateNetIOJsonResult, ffPrintNetIOHelpFormat, - NULL + ffGenerateNetIOJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/opencl/opencl.c b/src/modules/opencl/opencl.c index 951a42d5c..dcd0b7e84 100644 --- a/src/modules/opencl/opencl.c +++ b/src/modules/opencl/opencl.c @@ -66,6 +66,14 @@ void ffParseOpenCLJsonObject(FFOpenCLOptions* options, yyjson_val* module) } } +void ffGenerateOpenCLJsonConfig(FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyOpenCLOptions))) FFOpenCLOptions defaultOptions; + ffInitOpenCLOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateOpenCLJsonResult(FF_MAYBE_UNUSED FFOpenCLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFOpenCLResult opencl; @@ -111,7 +119,7 @@ void ffInitOpenCLOptions(FFOpenCLOptions* options) ffPrintOpenCL, ffGenerateOpenCLJsonResult, ffPrintOpenCLHelpFormat, - NULL + ffGenerateOpenCLJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index fbf819c90..efec8be63 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -101,6 +101,19 @@ void ffParseOpenGLJsonObject(FFOpenGLOptions* options, yyjson_val* module) } } +void ffGenerateOpenGLJsonConfig(FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyOpenGLOptions))) FFOpenGLOptions defaultOptions; + ffInitOpenGLOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + #if defined(__linux__) || defined(__FreeBSD__) + if (!ffStrbufEqual(&options->library, &defaultOptions.library)) + yyjson_mut_obj_add_strbuf(doc, module, "library", &options->library); + #endif +} + void ffGenerateOpenGLJsonResult(FF_MAYBE_UNUSED FFOpenGLOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFOpenGLResult result; @@ -149,7 +162,7 @@ void ffInitOpenGLOptions(FFOpenGLOptions* options) ffPrintOpenGL, ffGenerateOpenGLJsonResult, ffPrintOpenGLHelpFormat, - NULL + ffGenerateOpenGLJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/os/os.c b/src/modules/os/os.c index 408fa8f86..a88be7e39 100644 --- a/src/modules/os/os.c +++ b/src/modules/os/os.c @@ -163,6 +163,14 @@ void ffParseOSJsonObject(FFOSOptions* options, yyjson_val* module) } } +void ffGenerateOSJsonConfig(FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyOSOptions))) FFOSOptions defaultOptions; + ffInitOSOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateOSJsonResult(FF_MAYBE_UNUSED FFOSOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFOSResult* os = ffDetectOS(); @@ -214,7 +222,7 @@ void ffInitOSOptions(FFOSOptions* options) ffPrintOS, ffGenerateOSJsonResult, ffPrintOSHelpFormat, - NULL + ffGenerateOSJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index a795a02c5..0e3202f41 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -129,6 +129,14 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) } } +void ffGeneratePackagesJsonConfig(FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyPackagesOptions))) FFPackagesOptions defaultOptions; + ffInitPackagesOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFPackagesResult counts = {}; @@ -214,7 +222,7 @@ void ffInitPackagesOptions(FFPackagesOptions* options) ffPrintPackages, ffGeneratePackagesJsonResult, ffPrintPackagesHelpFormat, - NULL + ffGeneratePackagesJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/player/player.c b/src/modules/player/player.c index 8d90c2c18..7f8dd8fdc 100644 --- a/src/modules/player/player.c +++ b/src/modules/player/player.c @@ -100,6 +100,14 @@ void ffParsePlayerJsonObject(FFPlayerOptions* options, yyjson_val* module) } } +void ffGeneratePlayerJsonConfig(FFPlayerOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyPlayerOptions))) FFPlayerOptions defaultOptions; + ffInitPlayerOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGeneratePlayerJsonResult(FF_MAYBE_UNUSED FFMediaOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFMediaResult* media = ffDetectMedia(); @@ -136,7 +144,7 @@ void ffInitPlayerOptions(FFPlayerOptions* options) ffPrintPlayer, ffGeneratePlayerJsonResult, ffPrintPlayerHelpFormat, - NULL + ffGeneratePlayerJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/poweradapter/poweradapter.c b/src/modules/poweradapter/poweradapter.c index 6ae9ab738..64a58d2bb 100644 --- a/src/modules/poweradapter/poweradapter.c +++ b/src/modules/poweradapter/poweradapter.c @@ -70,6 +70,14 @@ bool ffParsePowerAdapterCommandOptions(FFPowerAdapterOptions* options, const cha return false; } +void ffGeneratePowerAdapterJsonConfig(FFPowerAdapterOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyPowerAdapterOptions))) FFPowerAdapterOptions defaultOptions; + ffInitPowerAdapterOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffParsePowerAdapterJsonObject(FFPowerAdapterOptions* options, yyjson_val* module) { yyjson_val *key_, *val; @@ -137,7 +145,7 @@ void ffInitPowerAdapterOptions(FFPowerAdapterOptions* options) ffPrintPowerAdapter, ffGeneratePowerAdapterJsonResult, ffPrintPowerAdapterHelpFormat, - NULL + ffGeneratePowerAdapterJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/processes/processes.c b/src/modules/processes/processes.c index 05a28ba02..7fe18163b 100644 --- a/src/modules/processes/processes.c +++ b/src/modules/processes/processes.c @@ -58,6 +58,14 @@ void ffParseProcessesJsonObject(FFProcessesOptions* options, yyjson_val* module) } } +void ffGenerateProcessesJsonConfig(FFProcessesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyProcessesOptions))) FFProcessesOptions defaultOptions; + ffInitProcessesOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateProcessesJsonResult(FF_MAYBE_UNUSED FFProcessesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { uint32_t result; @@ -89,7 +97,7 @@ void ffInitProcessesOptions(FFProcessesOptions* options) ffPrintProcesses, ffGenerateProcessesJsonResult, ffPrintProcessesHelpFormat, - NULL + ffGenerateProcessesJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/publicip/publicip.c b/src/modules/publicip/publicip.c index 9a83a01fa..3e00a5929 100644 --- a/src/modules/publicip/publicip.c +++ b/src/modules/publicip/publicip.c @@ -91,6 +91,17 @@ void ffParsePublicIpJsonObject(FFPublicIpOptions* options, yyjson_val* module) } } +void ffGeneratePublicIpJsonConfig(FFPublicIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyPublicIpOptions))) FFPublicIpOptions defaultOptions; + ffInitPublicIpOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (!ffStrbufEqual(&options->url, &defaultOptions.url)) + yyjson_mut_obj_add_strbuf(doc, module, "url", &options->url); +} + void ffGeneratePublicIpJsonResult(FFPublicIpOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFPublicIpResult result; @@ -130,7 +141,7 @@ void ffInitPublicIpOptions(FFPublicIpOptions* options) ffPrintPublicIp, ffGeneratePublicIpJsonResult, ffPrintPublicIpHelpFormat, - NULL + ffGeneratePublicIpJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/separator/separator.c b/src/modules/separator/separator.c index 2c71c01f4..1bcc8b192 100644 --- a/src/modules/separator/separator.c +++ b/src/modules/separator/separator.c @@ -109,6 +109,15 @@ void ffParseSeparatorJsonObject(FFSeparatorOptions* options, yyjson_val* module) } } +void ffGenerateSeparatorJsonConfig(FFSeparatorOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroySeparatorOptions))) FFSeparatorOptions defaultOptions; + ffInitSeparatorOptions(&defaultOptions); + + if (!ffStrbufEqual(&options->string, &defaultOptions.string)) + yyjson_mut_obj_add_strbuf(doc, module, "string", &options->string); +} + void ffInitSeparatorOptions(FFSeparatorOptions* options) { ffOptionInitModuleBaseInfo( @@ -119,7 +128,7 @@ void ffInitSeparatorOptions(FFSeparatorOptions* options) ffPrintSeparator, NULL, NULL, - NULL + ffGenerateSeparatorJsonConfig ); ffStrbufInit(&options->string); } diff --git a/src/modules/shell/shell.c b/src/modules/shell/shell.c index 5a7b237d0..9094cc889 100644 --- a/src/modules/shell/shell.c +++ b/src/modules/shell/shell.c @@ -69,6 +69,14 @@ void ffParseShellJsonObject(FFShellOptions* options, yyjson_val* module) } } +void ffGenerateShellJsonConfig(FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyShellOptions))) FFShellOptions defaultOptions; + ffInitShellOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateShellJsonResult(FF_MAYBE_UNUSED FFShellOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFTerminalShellResult* result = ffDetectTerminalShell(); @@ -109,7 +117,7 @@ void ffInitShellOptions(FFShellOptions* options) ffPrintShell, ffGenerateShellJsonResult, ffPrintShellHelpFormat, - NULL + ffGenerateShellJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 235cdb220..78b77ef67 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -82,7 +82,6 @@ void ffPrintSound(FFSoundOptions* options) } } - bool ffParseSoundCommandOptions(FFSoundOptions* options, const char* key, const char* value) { const char* subKey = ffOptionTestPrefix(key, FF_SOUND_MODULE_NAME); @@ -137,6 +136,30 @@ void ffParseSoundJsonObject(FFSoundOptions* options, yyjson_val* module) } } +void ffGenerateSoundJsonConfig(FFSoundOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroySoundOptions))) FFSoundOptions defaultOptions; + ffInitSoundOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (defaultOptions.soundType != options->soundType) + { + switch (options->soundType) + { + case FF_SOUND_TYPE_MAIN: + yyjson_mut_obj_add_str(doc, module, "soundType", "main"); + break; + case FF_SOUND_TYPE_ACTIVE: + yyjson_mut_obj_add_str(doc, module, "soundType", "active"); + break; + case FF_SOUND_TYPE_ALL: + yyjson_mut_obj_add_str(doc, module, "soundType", "all"); + break; + } + } +} + void ffGenerateSoundJsonResult(FF_MAYBE_UNUSED FFSoundOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFSoundDevice)); @@ -197,7 +220,7 @@ void ffInitSoundOptions(FFSoundOptions* options) ffPrintSound, ffGenerateSoundJsonResult, ffPrintSoundHelpFormat, - NULL + ffGenerateSoundJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index 96e092a86..392002f10 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -100,6 +100,14 @@ void ffParseSwapJsonObject(FFSwapOptions* options, yyjson_val* module) } } +void ffGenerateSwapJsonConfig(FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroySwapOptions))) FFSwapOptions defaultOptions; + ffInitSwapOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateSwapJsonResult(FF_MAYBE_UNUSED FFSwapOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFSwapResult storage; @@ -135,7 +143,7 @@ void ffInitSwapOptions(FFSwapOptions* options) ffPrintSwap, ffGenerateSwapJsonResult, ffPrintSwapHelpFormat, - NULL + ffGenerateSwapJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/terminal/terminal.c b/src/modules/terminal/terminal.c index d157cec38..ac32c7901 100644 --- a/src/modules/terminal/terminal.c +++ b/src/modules/terminal/terminal.c @@ -67,6 +67,14 @@ void ffParseTerminalJsonObject(FFTerminalOptions* options, yyjson_val* module) } } +void ffGenerateTerminalJsonConfig(FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyTerminalOptions))) FFTerminalOptions defaultOptions; + ffInitTerminalOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateTerminalJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFTerminalShellResult* result = ffDetectTerminalShell(); @@ -108,7 +116,7 @@ void ffInitTerminalOptions(FFTerminalOptions* options) ffPrintTerminal, ffGenerateTerminalJsonResult, ffPrintTerminalHelpFormat, - NULL + ffGenerateTerminalJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/terminalfont/terminalfont.c b/src/modules/terminalfont/terminalfont.c index b4719274f..353e67845 100644 --- a/src/modules/terminalfont/terminalfont.c +++ b/src/modules/terminalfont/terminalfont.c @@ -74,6 +74,14 @@ void ffParseTerminalFontJsonObject(FFTerminalFontOptions* options, yyjson_val* m } } +void ffGenerateTerminalFontJsonConfig(FFTerminalFontOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyTerminalFontOptions))) FFTerminalFontOptions defaultOptions; + ffInitTerminalFontOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateTerminalFontJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFTerminalFontResult result; @@ -134,7 +142,7 @@ void ffInitTerminalFontOptions(FFTerminalFontOptions* options) ffPrintTerminalFont, ffGenerateTerminalFontJsonResult, ffPrintTerminalFontHelpFormat, - NULL + ffGenerateTerminalFontJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/terminalsize/terminalsize.c b/src/modules/terminalsize/terminalsize.c index 432912ac4..120c908dc 100644 --- a/src/modules/terminalsize/terminalsize.c +++ b/src/modules/terminalsize/terminalsize.c @@ -66,6 +66,14 @@ void ffParseTerminalSizeJsonObject(FFTerminalSizeOptions* options, yyjson_val* m } } +void ffGenerateTerminalSizeJsonConfig(FFTerminalSizeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyTerminalSizeOptions))) FFTerminalSizeOptions defaultOptions; + ffInitTerminalSizeOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateTerminalSizeJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFTerminalSizeResult result; @@ -103,7 +111,7 @@ void ffInitTerminalSizeOptions(FFTerminalSizeOptions* options) ffPrintTerminalSize, ffGenerateTerminalSizeJsonResult, ffPrintTerminalSizeHelpFormat, - NULL + ffGenerateTerminalSizeJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/theme/theme.c b/src/modules/theme/theme.c index 40b50c0b0..888fa552c 100644 --- a/src/modules/theme/theme.c +++ b/src/modules/theme/theme.c @@ -57,6 +57,14 @@ void ffParseThemeJsonObject(FFThemeOptions* options, yyjson_val* module) } } +void ffGenerateThemeJsonConfig(FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyThemeOptions))) FFThemeOptions defaultOptions; + ffInitThemeOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateThemeJsonResult(FF_MAYBE_UNUSED FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY theme = ffStrbufCreate(); @@ -88,7 +96,7 @@ void ffInitThemeOptions(FFThemeOptions* options) ffPrintTheme, ffGenerateThemeJsonResult, ffPrintThemeHelpFormat, - NULL + ffGenerateThemeJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/title/title.c b/src/modules/title/title.c index 5757c4a48..fc37c3bc8 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -143,6 +143,31 @@ void ffParseTitleJsonObject(FFTitleOptions* options, yyjson_val* module) } } +void ffGenerateTitleJsonConfig(FFTitleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyTitleOptions))) FFTitleOptions defaultOptions; + ffInitTitleOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (defaultOptions.fqdn != options->fqdn) + yyjson_mut_obj_add_bool(doc, module, "fqdn", options->fqdn); + + yyjson_mut_val* color = yyjson_mut_obj(doc); + + if (!ffStrbufEqual(&options->colorUser, &defaultOptions.colorUser)) + yyjson_mut_obj_add_strbuf(doc, color, "user", &options->colorUser); + + if (!ffStrbufEqual(&options->colorAt, &defaultOptions.colorAt)) + yyjson_mut_obj_add_strbuf(doc, color, "at", &options->colorAt); + + if (!ffStrbufEqual(&options->colorHost, &defaultOptions.colorHost)) + yyjson_mut_obj_add_strbuf(doc, color, "host", &options->colorHost); + + if (yyjson_mut_obj_size(color)) + yyjson_mut_obj_add_val(doc, module, "color", color); +} + void ffGenerateTitleJsonResult(FF_MAYBE_UNUSED FFTitleOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); @@ -177,7 +202,7 @@ void ffInitTitleOptions(FFTitleOptions* options) ffPrintTitle, ffGenerateTitleJsonResult, ffPrintTitleHelpFormat, - NULL + ffGenerateTitleJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); ffStrbufSetStatic(&options->moduleArgs.key, " "); diff --git a/src/modules/uptime/uptime.c b/src/modules/uptime/uptime.c index 432c2c3a0..cd7fd0f5e 100644 --- a/src/modules/uptime/uptime.c +++ b/src/modules/uptime/uptime.c @@ -116,6 +116,14 @@ void ffParseUptimeJsonObject(FFUptimeOptions* options, yyjson_val* module) } } +void ffGenerateUptimeJsonConfig(FFUptimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyUptimeOptions))) FFUptimeOptions defaultOptions; + ffInitUptimeOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateUptimeJsonResult(FF_MAYBE_UNUSED FFUptimeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFUptimeResult result; @@ -152,7 +160,7 @@ void ffInitUptimeOptions(FFUptimeOptions* options) ffPrintUptime, ffGenerateUptimeJsonResult, ffPrintUptimeHelpFormat, - NULL + ffGenerateUptimeJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/users/users.c b/src/modules/users/users.c index 9a53c43e6..59fd43f62 100644 --- a/src/modules/users/users.c +++ b/src/modules/users/users.c @@ -130,6 +130,17 @@ void ffParseUsersJsonObject(FFUsersOptions* options, yyjson_val* module) } } +void ffGenerateUsersJsonConfig(FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyUsersOptions))) FFUsersOptions defaultOptions; + ffInitUsersOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (options->compact != defaultOptions.compact) + yyjson_mut_obj_add_bool(doc, module, "compact", options->compact); +} + void ffGenerateUsersJsonResult(FF_MAYBE_UNUSED FFUsersOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY results = ffListCreate(sizeof(FFUserResult)); @@ -184,7 +195,7 @@ void ffInitUsersOptions(FFUsersOptions* options) ffPrintUsers, ffGenerateUsersJsonResult, ffPrintUsersHelpFormat, - NULL + ffGenerateUsersJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/version/version.c b/src/modules/version/version.c index 0fce05a4f..9b50b6e95 100644 --- a/src/modules/version/version.c +++ b/src/modules/version/version.c @@ -72,6 +72,14 @@ void ffParseVersionJsonObject(FFVersionOptions* options, yyjson_val* module) } } +void ffGenerateVersionJsonConfig(FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyVersionOptions))) FFVersionOptions defaultOptions; + ffInitVersionOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateVersionJsonResult(FF_MAYBE_UNUSED FFVersionOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FFVersionResult result; @@ -129,7 +137,7 @@ void ffInitVersionOptions(FFVersionOptions* options) ffPrintVersion, ffGenerateVersionJsonResult, ffPrintVersionHelpFormat, - NULL + ffGenerateVersionJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/vulkan/vulkan.c b/src/modules/vulkan/vulkan.c index 78f1a892e..eb47e0f5a 100644 --- a/src/modules/vulkan/vulkan.c +++ b/src/modules/vulkan/vulkan.c @@ -71,6 +71,14 @@ void ffParseVulkanJsonObject(FFVulkanOptions* options, yyjson_val* module) } } +void ffGenerateVulkanJsonConfig(FFVulkanOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyVulkanOptions))) FFVulkanOptions defaultOptions; + ffInitVulkanOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateVulkanJsonResult(FF_MAYBE_UNUSED FFVulkanOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFVulkanResult* result = ffDetectVulkan(); @@ -145,7 +153,7 @@ void ffInitVulkanOptions(FFVulkanOptions* options) ffPrintVulkan, ffGenerateVulkanJsonResult, ffPrintVulkanHelpFormat, - NULL + ffGenerateVulkanJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/wallpaper/wallpaper.c b/src/modules/wallpaper/wallpaper.c index 720daa428..7fe1a9a5c 100644 --- a/src/modules/wallpaper/wallpaper.c +++ b/src/modules/wallpaper/wallpaper.c @@ -69,6 +69,14 @@ void ffParseWallpaperJsonObject(FFWallpaperOptions* options, yyjson_val* module) } } +void ffGenerateWallpaperJsonConfig(FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyWallpaperOptions))) FFWallpaperOptions defaultOptions; + ffInitWallpaperOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateWallpaperJsonResult(FF_MAYBE_UNUSED FFWallpaperOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY fullpath = ffStrbufCreate(); @@ -98,7 +106,7 @@ void ffInitWallpaperOptions(FFWallpaperOptions* options) ffPrintWallpaper, ffGenerateWallpaperJsonResult, ffPrintWallpaperHelpFormat, - NULL + ffGenerateWallpaperJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/weather/weather.c b/src/modules/weather/weather.c index 42e2d4d5b..f4135c80b 100644 --- a/src/modules/weather/weather.c +++ b/src/modules/weather/weather.c @@ -94,6 +94,23 @@ void ffParseWeatherJsonObject(FFWeatherOptions* options, yyjson_val* module) } } +void ffGenerateWeatherJsonConfig(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyWeatherOptions))) FFWeatherOptions defaultOptions; + ffInitWeatherOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (!ffStrbufEqual(&options->location, &defaultOptions.location)) + yyjson_mut_obj_add_strbuf(doc, module, "location", &options->location); + + if (!ffStrbufEqual(&options->outputFormat, &defaultOptions.outputFormat)) + yyjson_mut_obj_add_strbuf(doc, module, "outputFormat", &options->outputFormat); + + if (options->timeout != defaultOptions.timeout) + yyjson_mut_obj_add_uint(doc, module, "timeout", options->timeout); +} + void ffGenerateWeatherJsonResult(FFWeatherOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); @@ -125,7 +142,7 @@ void ffInitWeatherOptions(FFWeatherOptions* options) ffPrintWeather, ffGenerateWeatherJsonResult, ffPrintWeatherHelpFormat, - NULL + ffGenerateWeatherJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); diff --git a/src/modules/wifi/wifi.c b/src/modules/wifi/wifi.c index 8ca221c61..152fe86ee 100644 --- a/src/modules/wifi/wifi.c +++ b/src/modules/wifi/wifi.c @@ -97,6 +97,14 @@ void ffParseWifiJsonObject(FFWifiOptions* options, yyjson_val* module) } } +void ffGenerateWifiJsonConfig(FFWifiOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyWifiOptions))) FFWifiOptions defaultOptions; + ffInitWifiOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateWifiJsonResult(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFWifiResult)); @@ -169,7 +177,7 @@ void ffInitWifiOptions(FFWifiOptions* options) ffPrintWifi, ffGenerateWifiJsonResult, ffPrintWifiHelpFormat, - NULL + ffGenerateWifiJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index 15005b788..374e981f6 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -68,6 +68,14 @@ void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module) } } +void ffGenerateWMJsonConfig(FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyWMOptions))) FFWMOptions defaultOptions; + ffInitWMOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { const FFDisplayServerResult* result = ffConnectDisplayServer(); @@ -102,7 +110,7 @@ void ffInitWMOptions(FFWMOptions* options) ffPrintWM, ffGenerateWMJsonResult, ffPrintWMHelpFormat, - NULL + ffGenerateWMJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } diff --git a/src/modules/wmtheme/wmtheme.c b/src/modules/wmtheme/wmtheme.c index f3b8c3177..1cedd28e5 100644 --- a/src/modules/wmtheme/wmtheme.c +++ b/src/modules/wmtheme/wmtheme.c @@ -57,6 +57,14 @@ void ffParseWMThemeJsonObject(FFWMThemeOptions* options, yyjson_val* module) } } +void ffGenerateWMThemeJsonConfig(FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + __attribute__((__cleanup__(ffDestroyWMThemeOptions))) FFWMThemeOptions defaultOptions; + ffInitWMThemeOptions(&defaultOptions); + + ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); +} + void ffGenerateWMThemeJsonResult(FF_MAYBE_UNUSED FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate(); @@ -86,7 +94,7 @@ void ffInitWMThemeOptions(FFWMThemeOptions* options) ffPrintWMTheme, ffGenerateWMThemeJsonResult, ffPrintWMthemeHelpFormat, - NULL + ffGenerateWMThemeJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); } From 94119d1674aed582bfe12aad45b2d2748a360f31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 24 Oct 2023 15:17:27 +0800 Subject: [PATCH 019/100] OpenGL (Linux): fix build --- src/modules/opengl/opengl.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/modules/opengl/opengl.c b/src/modules/opengl/opengl.c index efec8be63..5f159cbc5 100644 --- a/src/modules/opengl/opengl.c +++ b/src/modules/opengl/opengl.c @@ -109,8 +109,24 @@ void ffGenerateOpenGLJsonConfig(FFOpenGLOptions* options, yyjson_mut_doc* doc, y ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); #if defined(__linux__) || defined(__FreeBSD__) - if (!ffStrbufEqual(&options->library, &defaultOptions.library)) - yyjson_mut_obj_add_strbuf(doc, module, "library", &options->library); + if (options->library != defaultOptions.library) + { + switch (options->library) + { + case FF_OPENGL_LIBRARY_AUTO: + yyjson_mut_obj_add_str(doc, module, "library", "auto"); + break; + case FF_OPENGL_LIBRARY_EGL: + yyjson_mut_obj_add_str(doc, module, "library", "egl"); + break; + case FF_OPENGL_LIBRARY_GLX: + yyjson_mut_obj_add_str(doc, module, "library", "glx"); + break; + case FF_OPENGL_LIBRARY_OSMESA: + yyjson_mut_obj_add_str(doc, module, "library", "osmesa"); + break; + } + } #endif } From bf1d1cbac5dbb737aa3306020dc466a9b16aeb3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 24 Oct 2023 15:47:53 +0800 Subject: [PATCH 020/100] Terminal: support urxvt version detection --- src/detection/terminalshell/terminalshell.c | 23 +++++++++++++++++++ .../terminalshell/terminalshell_linux.c | 5 ++++ 2 files changed, 28 insertions(+) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index 822812882..99224718e 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -284,6 +284,22 @@ FF_MAYBE_UNUSED static bool getTerminalVersionXterm(FFstrbuf* exe, FFstrbuf* ver return version->length > 0; } +FF_MAYBE_UNUSED static bool getTerminalVersionUrxvt(FF_MAYBE_UNUSED FFstrbuf* exe, FFstrbuf* version) +{ + if(ffProcessAppendStdErr(version, (char* const[]){ + "urxvt", // Don't use exe because of urxvtd + "-invalid", + NULL + })) return false; + + //urxvt: "invalid": unknown or malformed option. + //rxvt-unicode (urxvt) v9.31 - released: 2023-01-02 + ffStrbufSubstrAfterFirstS(version, "(urxvt) v"); + ffStrbufSubstrBeforeFirstC(version, ' '); + + return version->length > 0; +} + static bool getTerminalVersionContour(FFstrbuf* exe, FFstrbuf* version) { const char* env = getenv("TERMINAL_VERSION_STRING"); @@ -371,6 +387,13 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe if(ffStrbufIgnCaseEqualS(processName, "xterm")) return getTerminalVersionXterm(exe, version); + if(ffStrbufIgnCaseEqualS(processName, "urxvt") || + ffStrbufIgnCaseEqualS(processName, "urxvtd") || + ffStrbufIgnCaseEqualS(processName, "rxvt") || + ffStrbufIgnCaseEqualS(processName, "rxvt-unicode") + ) + return getTerminalVersionUrxvt(exe, version); + #endif #ifdef _WIN32 diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 7b72f8618..38d83e800 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -388,6 +388,11 @@ const FFTerminalShellResult* ffDetectTerminalShell() ffStrbufInitStatic(&result.terminalPrettyName, "GNOME Terminal"); else if(ffStrbufStartsWithS(&result.terminalProcessName, "kgx")) ffStrbufInitStatic(&result.terminalPrettyName, "GNOME Console"); + else if(ffStrbufEqualS(&result.terminalProcessName, "urxvt") || + ffStrbufEqualS(&result.terminalProcessName, "urxvtd") || + ffStrbufEqualS(&result.terminalProcessName, "rxvt") + ) + ffStrbufInitStatic(&result.terminalPrettyName, "rxvt-unicode"); #elif defined(__APPLE__) From 504f1533c2f74b909c95037fa0d54bbf80dc5f11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 24 Oct 2023 15:57:40 +0800 Subject: [PATCH 021/100] Terminal: support st version detection --- src/detection/terminalshell/terminalshell.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index 99224718e..60bff0490 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -300,6 +300,20 @@ FF_MAYBE_UNUSED static bool getTerminalVersionUrxvt(FF_MAYBE_UNUSED FFstrbuf* ex return version->length > 0; } +FF_MAYBE_UNUSED static bool getTerminalVersionSt(FF_MAYBE_UNUSED FFstrbuf* exe, FFstrbuf* version) +{ + if(ffProcessAppendStdErr(version, (char* const[]){ + exe->chars, + "-v", + NULL + })) return false; + + //st 0.9 + ffStrbufSubstrAfterFirstC(version, ' '); + + return version->length > 0; +} + static bool getTerminalVersionContour(FFstrbuf* exe, FFstrbuf* version) { const char* env = getenv("TERMINAL_VERSION_STRING"); @@ -387,6 +401,9 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe if(ffStrbufIgnCaseEqualS(processName, "xterm")) return getTerminalVersionXterm(exe, version); + if(ffStrbufIgnCaseEqualS(processName, "st")) + return getTerminalVersionSt(exe, version); + if(ffStrbufIgnCaseEqualS(processName, "urxvt") || ffStrbufIgnCaseEqualS(processName, "urxvtd") || ffStrbufIgnCaseEqualS(processName, "rxvt") || From 11d03ad59ea9e0895a5f7f97cb9cf0891873e291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 24 Oct 2023 16:45:04 +0800 Subject: [PATCH 022/100] TerminalFont: support st --- README.md | 2 +- .../terminalfont/terminalfont_linux.c | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 26ccceda9..63c44c693 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Budgie, Cinnamon, Gnome, KDE Plasma, LXQt, Mate, XFCE4 ##### Terminal fonts ``` -Alacritty, Apple Terminal, ConEmu, Deepin Terminal, foot, Gnome Console, Gnome Terminal, iTerm2, Kitty, Konsole, LXTerminal, MATE Terminal, mintty, QTerminal, Tabby, Terminator, Termux, Tilix, TTY, Warp, WezTerm, Windows Terminal, XFCE4 Terminal, Yakuake +Alacritty, Apple Terminal, ConEmu, Deepin Terminal, foot, Gnome Console, Gnome Terminal, iTerm2, Kitty, Konsole, LXTerminal, MATE Terminal, mintty, QTerminal, st, Tabby, Terminator, Termux, Tilix, TTY, Warp, WezTerm, Windows Terminal, XFCE4 Terminal, Yakuake ``` ## Building diff --git a/src/detection/terminalfont/terminalfont_linux.c b/src/detection/terminalfont/terminalfont_linux.c index c9f1b3421..71299af6a 100644 --- a/src/detection/terminalfont/terminalfont_linux.c +++ b/src/detection/terminalfont/terminalfont_linux.c @@ -2,6 +2,7 @@ #include "common/settings.h" #include "common/properties.h" #include "common/parsing.h" +#include "common/io/io.h" #include "detection/terminalshell/terminalshell.h" #include "detection/displayserver/displayserver.h" #include "util/mallocHelper.h" @@ -250,6 +251,38 @@ static void detectXterm(FFTerminalFontResult* terminalFont) ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars); } +static void detectSt(FFTerminalFontResult* terminalFont, uint32_t pid) +{ + FF_STRBUF_AUTO_DESTROY size = ffStrbufCreateF("/proc/%u/cmdline", pid); + FF_STRBUF_AUTO_DESTROY font = ffStrbufCreate(); + if (!ffAppendFileBuffer(size.chars, &font)) + { + ffStrbufAppendF(&terminalFont->error, "Failed to open %s", size.chars); + return; + } + + const char* p = memmem(font.chars, font.length, "\0-f", sizeof("\0-f")); // find parameter of `-f` + if (!p) + { + ffStrbufAppendF(&terminalFont->error, "st was not executed with `-f` parameter"); + return; + } + + ffStrbufSubstrAfter(&font, (uint32_t) (p + (sizeof("\0-f") - 1) - font.chars)); + ffStrbufRecalculateLength(&font); + + // `monospace:size=15` || `monospace` || `:size=15` + uint32_t index = ffStrbufFirstIndexS(&font, ":size="); + if (index != font.length) + { + ffStrbufSetS(&size, font.chars + index + strlen(":size=")); + ffStrbufSubstrBefore(&font, index); + } + else + ffStrbufClear(&size); + ffFontInitValues(&terminalFont->font, font.chars, size.chars); +} + void ffDetectTerminalFontPlatform(const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont) { if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "konsole")) @@ -276,4 +309,6 @@ void ffDetectTerminalFontPlatform(const FFTerminalShellResult* terminalShell, FF detectQTerminal(terminalFont); else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "xterm")) detectXterm(terminalFont); + else if(ffStrbufIgnCaseEqualS(&terminalShell->terminalProcessName, "st")) + detectSt(terminalFont, terminalShell->terminalPid); } From 3303f4e1ce9be3ca2c693de5fefb38f125d431c7 Mon Sep 17 00:00:00 2001 From: westpain Date: Tue, 24 Oct 2023 16:15:56 +0300 Subject: [PATCH 023/100] Add cycledream logo (#595) --- src/logo/ascii/cycledream.txt | 21 +++++++++++++++++++++ src/logo/builtin.c | 10 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/logo/ascii/cycledream.txt diff --git a/src/logo/ascii/cycledream.txt b/src/logo/ascii/cycledream.txt new file mode 100644 index 000000000..2f613eaa4 --- /dev/null +++ b/src/logo/ascii/cycledream.txt @@ -0,0 +1,21 @@ + .:ox00000kdc, + ;; 'cdO. dxl,. + 00 'oO' 0x; + 00ko ,Oc + x00Okxx lO' + .x, .0c + ;c .O00' :: '0: + . O0000. o0. +.0c ,,;;:clO00000Olc:;;,, .0l +x0 ;00000000000000000c 00 +00 0000000000000. 0O +x0. ... 00000000000. ... '0: +.0c ,00000000000o .o + o0. O000; '0000 + 0k .0 O O' + lO. ''..... + .0o d000 + Oo' ,dO O0 + ;Oo;. .;oO, 00 + xkdocc:ccodko + ;k0k, diff --git a/src/logo/builtin.c b/src/logo/builtin.c index edfb803df..2873f3552 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -1044,6 +1044,16 @@ static const FFlogo C[] = { .colorKeys = FF_COLOR_FG_BLUE, .colorTitle = FF_COLOR_FG_CYAN, }, + // cycledream + { + .names = {"cycledream"}, + .lines = FASTFETCH_DATATEXT_LOGO_CYCLEDREAM, + .colors = { + FF_COLOR_FG_MAGENTA, + }, + .colorKeys = FF_COLOR_FG_MAGENTA, + .colorTitle = FF_COLOR_FG_MAGENTA, + }, // LAST {}, }; From 22080d36b07b01b7792e4519b6f5ec47537958f5 Mon Sep 17 00:00:00 2001 From: Martin Valba Date: Tue, 24 Oct 2023 17:23:33 +0300 Subject: [PATCH 024/100] Add Evolinx distro banner (#596) * Add Evolinx banner * Removed accidental local bad save --- src/logo/ascii/evolinx.txt | 10 ++++++++++ src/logo/builtin.c | 10 ++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/logo/ascii/evolinx.txt diff --git a/src/logo/ascii/evolinx.txt b/src/logo/ascii/evolinx.txt new file mode 100644 index 000000000..9eec96f56 --- /dev/null +++ b/src/logo/ascii/evolinx.txt @@ -0,0 +1,10 @@ +#-----------------------------------------------------------------------# +|#SSSSSSSS\*SS\****SS\**SSSSSS\**SS\*******SSSSSS\*SS\***SS\*SS\***SS\*#| +|#SS**_____|SS*|***SS*|SS**__SS\*SS*|******\_SS**_|SSS\**SS*|SS*|**SS*|#| +|#SS*|******SS*|***SS*|SS*/**SS*|SS*|********SS*|**SSSS\*SS*|\SS\*SS**|#| +|#SSSSS\****\SS\**SS**|SS*|**SS*|SS*|********SS*|**SS*SS\SS*|*\SSSS**/*#| +|#SS**__|****\SS\SS**/*SS*|**SS*|SS*|********SS*|**SS*\SSSS*|*SS**SS<**#| +|#SS*|********\SSS**/**SS*|**SS*|SS*|********SS*|**SS*|\SSS*|SS**/\SS\*#| +|#SSSSSSSS\****\S**/****SSSSSS**|SSSSSSSS\*SSSSSS\*SS*|*\SS*|SS*/**SS*|#| +|#\________|****\_/*****\______/*\________|\______|\__|**\__|\__|**\__|#| +#-----------------------------------------------------------------------# diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 2873f3552..67b41f763 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -1340,6 +1340,16 @@ static const FFlogo E[] = { .colorKeys = FF_COLOR_FG_BLUE, .colorTitle = FF_COLOR_FG_WHITE, }, + // evolinx + { + .names = {"Evolinx"}, + .lines = FASTFETCH_DATATEXT_LOGO_EVOLINX, + .colors = { + FF_COLOR_FG_BLUE, + }, + .colorKeys = FF_COLOR_FG_BLUE, + .colorTitle = FF_COLOR_FG_BLUE, + }, // EvolutionOS { .names = {"EvolutionOS"}, From fa02217ff4f5958f53b6733878d011db3334d143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 25 Oct 2023 09:03:44 +0800 Subject: [PATCH 025/100] Doc: update changelog --- CHANGELOG.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cd3246ca..4c58a2ac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +# 2.2.0 + +Features: +* Quirks for MIPS platforms (CPU, Linux) +* Use devicetree path for OBP hosts (Host, Linux) +* Detect `tmux: server` as tmux (Terminal, Linux) +* Support urxvt version detection (Terminal, Linux) +* Support st version detection (Terminal, Linux) +* Support st terminal font detection (TerminalFont, Linux) + +Bugfixes: +* Better GPU memory and type detection (GPU, Windows) +* Don't print display type twice (Display) + +Logos: +* Add Black Mesa +* Add cycledream +* Add Evolinx + # 2.1.2 Bugfixes: From 4e018dbf26072dc8c51ae4ad75c6918b6cf275a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 25 Oct 2023 09:13:04 +0800 Subject: [PATCH 026/100] JsonConfig: code refactor --- src/common/jsonconfig.c | 12 +++--------- src/common/jsonconfig.h | 6 +++--- src/fastfetch.c | 8 ++++---- src/logo/logo.h | 2 +- src/logo/option.c | 4 +--- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 0c1fdc1e5..e07fd5f85 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -227,10 +227,8 @@ static const char* printJsonConfig(bool prepare) return NULL; } -const char* ffParseGeneralJsonConfig(void) +const char* ffParseGeneralJsonConfig(FFconfig* config) { - FFconfig* config = &instance.config; - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); assert(root); @@ -282,10 +280,8 @@ const char* ffParseGeneralJsonConfig(void) return NULL; } -const char* ffParseDisplayJsonConfig(void) +const char* ffParseDisplayJsonConfig(FFconfig* config) { - FFconfig* config = &instance.config; - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); assert(root); @@ -416,10 +412,8 @@ const char* ffParseDisplayJsonConfig(void) return NULL; } -const char* ffParseLibraryJsonConfig(void) +const char* ffParseLibraryJsonConfig(FFconfig* config) { - FFconfig* config = &instance.config; - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); assert(root); diff --git a/src/common/jsonconfig.h b/src/common/jsonconfig.h index b7824cdd0..f7546f174 100644 --- a/src/common/jsonconfig.h +++ b/src/common/jsonconfig.h @@ -5,9 +5,9 @@ bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs* moduleArgs); const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]); void ffPrintJsonConfig(bool prepare); -const char* ffParseGeneralJsonConfig(void); -const char* ffParseDisplayJsonConfig(void); -const char* ffParseLibraryJsonConfig(void); +const char* ffParseGeneralJsonConfig(FFconfig* config); +const char* ffParseDisplayJsonConfig(FFconfig* config); +const char* ffParseLibraryJsonConfig(FFconfig* config); void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs); yyjson_api_inline bool yyjson_mut_obj_add_strbuf(yyjson_mut_doc *doc, diff --git a/src/fastfetch.c b/src/fastfetch.c index 48b5431ca..8be5c1a56 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -802,10 +802,10 @@ static void ffRun(FFdata* data) const char* error = NULL; if ( - (error = ffParseLogoJsonConfig()) || - (error = ffParseGeneralJsonConfig()) || - (error = ffParseDisplayJsonConfig()) || - (error = ffParseLibraryJsonConfig()) || + (error = ffParseLogoJsonConfig(&instance.config.logo)) || + (error = ffParseGeneralJsonConfig(&instance.config)) || + (error = ffParseDisplayJsonConfig(&instance.config)) || + (error = ffParseLibraryJsonConfig(&instance.config)) || false ) { fputs(error, stderr); diff --git a/src/logo/logo.h b/src/logo/logo.h index 62e884143..6b80449ba 100644 --- a/src/logo/logo.h +++ b/src/logo/logo.h @@ -36,6 +36,6 @@ bool ffLogoPrintImageIfExists(FFLogoType type, bool printError); void ffInitLogoOptions(FFLogoOptions* options); bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value); void ffDestroyLogoOptions(FFLogoOptions* options); -const char* ffParseLogoJsonConfig(); +const char* ffParseLogoJsonConfig(FFLogoOptions* options); #endif diff --git a/src/logo/option.c b/src/logo/option.c index 32114de22..f24d8ed4d 100644 --- a/src/logo/option.c +++ b/src/logo/option.c @@ -211,10 +211,8 @@ void ffDestroyLogoOptions(FFLogoOptions* options) ffStrbufDestroy(&options->colors[i]); } -const char* ffParseLogoJsonConfig(void) +const char* ffParseLogoJsonConfig(FFLogoOptions* options) { - FFLogoOptions* options = &instance.config.logo; - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); assert(root); From f50368a949d7f0a309e6c04a0f821fb03a4258e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 25 Oct 2023 10:18:07 +0800 Subject: [PATCH 027/100] Migration: support logo --- src/fastfetch.c | 12 +++- src/logo/logo.h | 1 + src/logo/option.c | 143 +++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 152 insertions(+), 4 deletions(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index 8be5c1a56..4a531e87e 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -795,7 +795,7 @@ static void parseArguments(FFdata* data, int argc, const char** argv) } } -static void ffRun(FFdata* data) +static void run(FFdata* data) { if (instance.state.configDoc) { @@ -837,6 +837,12 @@ static void ffRun(FFdata* data) ffFinish(); } +static void migrateConfig(FFdata* data) +{ + ffGenerateLogoJsonConfig(&instance.config.logo, instance.state.migrateConfigDoc); + ffMigrateCommandOptionToJsonc(data); +} + int main(int argc, const char** argv) { ffInitInstance(); @@ -853,9 +859,9 @@ int main(int argc, const char** argv) parseArguments(&data, argc, argv); if (__builtin_expect(!instance.state.migrateConfigDoc, true)) - ffRun(&data); + run(&data); else - ffMigrateCommandOptionToJsonc(&data); // Migrate + migrateConfig(&data); ffStrbufDestroy(&data.structure); FF_LIST_FOR_EACH(FFCustomValue, customValue, data.customValues) diff --git a/src/logo/logo.h b/src/logo/logo.h index 6b80449ba..0ff7e37bd 100644 --- a/src/logo/logo.h +++ b/src/logo/logo.h @@ -37,5 +37,6 @@ void ffInitLogoOptions(FFLogoOptions* options); bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value); void ffDestroyLogoOptions(FFLogoOptions* options); const char* ffParseLogoJsonConfig(FFLogoOptions* options); +void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc); #endif diff --git a/src/logo/option.c b/src/logo/option.c index f24d8ed4d..3bd9ebccb 100644 --- a/src/logo/option.c +++ b/src/logo/option.c @@ -286,7 +286,7 @@ const char* ffParseLogoJsonConfig(FFLogoOptions* options) { const char* keyc = yyjson_get_str(key_c); uint32_t index = (uint32_t) strtoul(keyc, NULL, 10); - if (index < 1 || index > 9) + if (index < 1 || index > FASTFETCH_LOGO_MAX_COLORS) return "Keys of property 'color' must be a number between 1 to 9"; ffOptionParseColor(yyjson_get_str(valc), &options->colors[index - 1]); @@ -417,3 +417,144 @@ const char* ffParseLogoJsonConfig(FFLogoOptions* options) return NULL; } + +void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc) +{ + __attribute__((__cleanup__(ffDestroyLogoOptions))) FFLogoOptions defaultOptions; + ffInitLogoOptions(&defaultOptions); + + yyjson_mut_val* obj = yyjson_mut_obj(doc); + + if (options->type != defaultOptions.type) + { + switch (options->type) + { + case FF_LOGO_TYPE_NONE: + yyjson_mut_obj_add_null(doc, doc->root, "logo"); + return; + case FF_LOGO_TYPE_BUILTIN: + yyjson_mut_obj_add_str(doc, obj, "type", "builtin"); + break; + case FF_LOGO_TYPE_SMALL: + yyjson_mut_obj_add_str(doc, obj, "type", "small"); + break; + case FF_LOGO_TYPE_FILE: + yyjson_mut_obj_add_str(doc, obj, "type", "file"); + break; + case FF_LOGO_TYPE_FILE_RAW: + yyjson_mut_obj_add_str(doc, obj, "type", "file-raw"); + break; + case FF_LOGO_TYPE_DATA: + yyjson_mut_obj_add_str(doc, obj, "type", "data"); + break; + case FF_LOGO_TYPE_DATA_RAW: + yyjson_mut_obj_add_str(doc, obj, "type", "data-raw"); + break; + case FF_LOGO_TYPE_IMAGE_SIXEL: + yyjson_mut_obj_add_str(doc, obj, "type", "sixel"); + break; + case FF_LOGO_TYPE_IMAGE_KITTY: + yyjson_mut_obj_add_str(doc, obj, "type", "kitty"); + break; + case FF_LOGO_TYPE_IMAGE_ITERM: + yyjson_mut_obj_add_str(doc, obj, "type", "iterm"); + break; + case FF_LOGO_TYPE_IMAGE_CHAFA: + yyjson_mut_obj_add_str(doc, obj, "type", "chafa"); + break; + case FF_LOGO_TYPE_IMAGE_RAW: + yyjson_mut_obj_add_str(doc, obj, "type", "raw"); + break; + default: + yyjson_mut_obj_add_str(doc, obj, "type", "auto"); + break; + } + } + + if (!ffStrbufEqual(&options->source, &defaultOptions.source)) + yyjson_mut_obj_add_str(doc, obj, "source", options->source.chars); + + { + yyjson_mut_val* color = yyjson_mut_arr(doc); + for (int i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++) + { + if (!ffStrbufEqual(&options->colors[i], &defaultOptions.colors[i])) + yyjson_mut_arr_add_strbuf(doc, color, &options->colors[i]); + } + if (yyjson_mut_arr_size(color) > 0) + yyjson_mut_obj_add_val(doc, obj, "color", color); + } + + if (options->width != defaultOptions.width) + yyjson_mut_obj_add_uint(doc, obj, "width", options->width); + + if (options->height != defaultOptions.height) + yyjson_mut_obj_add_uint(doc, obj, "height", options->height); + + { + yyjson_mut_val* padding = yyjson_mut_obj(doc); + if (options->paddingTop != defaultOptions.paddingTop) + yyjson_mut_obj_add_uint(doc, padding, "top", options->paddingTop); + if (options->paddingLeft != defaultOptions.paddingLeft) + yyjson_mut_obj_add_uint(doc, padding, "left", options->paddingLeft); + if (options->paddingRight != defaultOptions.paddingRight) + yyjson_mut_obj_add_uint(doc, padding, "right", options->paddingRight); + + if (yyjson_mut_obj_size(padding) > 0) + yyjson_mut_obj_add_val(doc, obj, "padding", padding); + } + + if (options->printRemaining != defaultOptions.printRemaining) + yyjson_mut_obj_add_bool(doc, obj, "printRemaining", options->printRemaining); + + if (options->preserveAspectRadio != defaultOptions.preserveAspectRadio) + yyjson_mut_obj_add_bool(doc, obj, "preserveAspectRadio", options->preserveAspectRadio); + + if (options->recache != defaultOptions.recache) + yyjson_mut_obj_add_bool(doc, obj, "recache", options->recache); + + if (options->separate != defaultOptions.separate) + yyjson_mut_obj_add_bool(doc, obj, "separate", options->separate); + + { + yyjson_mut_val* chafa = yyjson_mut_obj(doc); + if (options->chafaFgOnly != defaultOptions.chafaFgOnly) + yyjson_mut_obj_add_bool(doc, chafa, "fgOnly", options->chafaFgOnly); + if (!ffStrbufEqual(&options->chafaSymbols, &defaultOptions.chafaSymbols)) + yyjson_mut_obj_add_strbuf(doc, chafa, "symbols", &options->chafaSymbols); + if (options->chafaCanvasMode != defaultOptions.chafaCanvasMode && options->chafaCanvasMode <= 7) + { + yyjson_mut_obj_add_str(doc, chafa, "canvasMode", ((const char* []) { + "TRUECOLOR", + "INDEXED_256", + "INDEXED_240", + "INDEXED_16", + "FGBG_BGFG", + "FGBG", + "INDEXED_8", + "INDEXED_16_8", + })[options->chafaCanvasMode]); + } + if (options->chafaColorSpace != defaultOptions.chafaColorSpace && options->chafaColorSpace <= 1) + { + yyjson_mut_obj_add_str(doc, chafa, "colorSpace", ((const char* []) { + "RGB", + "DIN99D", + })[options->chafaColorSpace]); + } + if (options->chafaDitherMode != defaultOptions.chafaDitherMode && options->chafaDitherMode <= 2) + { + yyjson_mut_obj_add_str(doc, chafa, "ditherMode", ((const char* []) { + "NONE", + "ORDERED", + "DIFFUSION", + })[options->chafaDitherMode]); + } + + if (yyjson_mut_obj_size(chafa) > 0) + yyjson_mut_obj_add_val(doc, obj, "chafa", chafa); + } + + if (yyjson_mut_obj_size(obj) > 0) + yyjson_mut_obj_add_val(doc, doc->root, "logo", obj); +} From 04c3a4ccf7477dbc30e0bf2bbf32a93f18156112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 25 Oct 2023 10:44:34 +0800 Subject: [PATCH 028/100] Logo: move logo options related code to a new folder --- CMakeLists.txt | 2 +- src/common/jsonconfig.c | 4 +- src/fastfetch.h | 2 +- src/logo/logo.h | 7 - src/options/logo.c | 560 ++++++++++++++++++++++++++++++++++++++++ src/options/logo.h | 52 ++++ 6 files changed, 616 insertions(+), 11 deletions(-) create mode 100644 src/options/logo.c create mode 100644 src/options/logo.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f883df03d..0239cdbc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,7 +297,6 @@ set(LIBFASTFETCH_SRC src/logo/image/im7.c src/logo/image/image.c src/logo/logo.c - src/logo/option.c src/modules/battery/battery.c src/modules/bios/bios.c src/modules/bluetooth/bluetooth.c @@ -355,6 +354,7 @@ set(LIBFASTFETCH_SRC src/modules/wifi/wifi.c src/modules/wm/wm.c src/modules/wmtheme/wmtheme.c + src/options/logo.c src/util/edidHelper.c src/util/FFlist.c src/util/FFstrbuf.c diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index e07fd5f85..f4ef9bc75 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -82,7 +82,7 @@ const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair p return "Invalid enum value type; must be a string or integer"; } -static inline yyjson_mut_val* genJson(FFModuleBaseInfo* baseInfo) +static inline yyjson_mut_val* genJsonResult(FFModuleBaseInfo* baseInfo) { yyjson_mut_doc* doc = instance.state.resultDoc; if (__builtin_expect(!doc, true)) return NULL; @@ -106,7 +106,7 @@ static bool parseModuleJsonObject(const char* type, yyjson_val* jsonVal) if (ffStrEqualsIgnCase(type, baseInfo->name)) { if (jsonVal) baseInfo->parseJsonObject(baseInfo, jsonVal); - if (!genJson(baseInfo)) + if (!genJsonResult(baseInfo)) baseInfo->printModule(baseInfo); return true; } diff --git a/src/fastfetch.h b/src/fastfetch.h index 54fc39407..76ed4181c 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -24,7 +24,7 @@ #include "util/unused.h" #include "modules/options.h" -#include "logo/option.h" +#include "options/logo.h" typedef enum FFBinaryPrefixType { diff --git a/src/logo/logo.h b/src/logo/logo.h index 0ff7e37bd..bbdcdbe38 100644 --- a/src/logo/logo.h +++ b/src/logo/logo.h @@ -32,11 +32,4 @@ extern const FFlogo ffLogoUnknown; //image/image.c bool ffLogoPrintImageIfExists(FFLogoType type, bool printError); -//option.c -void ffInitLogoOptions(FFLogoOptions* options); -bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value); -void ffDestroyLogoOptions(FFLogoOptions* options); -const char* ffParseLogoJsonConfig(FFLogoOptions* options); -void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc); - #endif diff --git a/src/options/logo.c b/src/options/logo.c new file mode 100644 index 000000000..3bd9ebccb --- /dev/null +++ b/src/options/logo.c @@ -0,0 +1,560 @@ +#include "logo/logo.h" + +#include "common/jsonconfig.h" +#include "util/stringUtils.h" + +void ffInitLogoOptions(FFLogoOptions* options) +{ + ffStrbufInit(&options->source); + options->type = FF_LOGO_TYPE_AUTO; + for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i) + ffStrbufInit(&options->colors[i]); + options->width = 0; + options->height = 0; //preserve aspect ratio + options->paddingTop = 0; + options->paddingLeft = 0; + options->paddingRight = 4; + options->printRemaining = true; + options->preserveAspectRadio = false; + options->recache = false; + options->separate = false; + + options->chafaFgOnly = false; + ffStrbufInitStatic(&options->chafaSymbols, "block+border+space-wide-inverted"); // Chafa default + options->chafaCanvasMode = UINT32_MAX; + options->chafaColorSpace = UINT32_MAX; + options->chafaDitherMode = UINT32_MAX; +} + +bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value) +{ + if (strcasecmp(key, "-l") == 0) + goto logoType; + + const char* subKey = ffOptionTestPrefix(key, "logo"); + if(subKey) + { + if (subKey[0] == '\0') + { +logoType: + if(value == NULL) + { + fprintf(stderr, "Error: usage: %s \n", key); + exit(477); + } + //this is usually wanted when disabling logo + if(strcasecmp(value, "none") == 0) + { + options->paddingTop = 0; + options->paddingRight = 0; + options->paddingLeft = 0; + options->type = FF_LOGO_TYPE_NONE; + } + else if(strcasecmp(value, "small") == 0) + { + options->type = FF_LOGO_TYPE_SMALL; + } + else + ffOptionParseString(key, value, &options->source); + } + else if(strcasecmp(subKey, "type") == 0) + { + options->type = (FFLogoType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { + { "auto", FF_LOGO_TYPE_AUTO }, + { "builtin", FF_LOGO_TYPE_BUILTIN }, + { "small", FF_LOGO_TYPE_SMALL }, + { "file", FF_LOGO_TYPE_FILE }, + { "file-raw", FF_LOGO_TYPE_FILE_RAW }, + { "data", FF_LOGO_TYPE_DATA }, + { "data-raw", FF_LOGO_TYPE_DATA_RAW }, + { "sixel", FF_LOGO_TYPE_IMAGE_SIXEL }, + { "kitty", FF_LOGO_TYPE_IMAGE_KITTY }, + { "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT }, + { "iterm", FF_LOGO_TYPE_IMAGE_ITERM }, + { "chafa", FF_LOGO_TYPE_IMAGE_CHAFA }, + { "raw", FF_LOGO_TYPE_IMAGE_RAW }, + { "none", FF_LOGO_TYPE_NONE }, + {}, + }); + } + else if(ffStrStartsWithIgnCase(subKey, "color-") && subKey[6] != '\0' && subKey[7] == '\0') // matches "--logo-color-*" + { + //Map the number to an array index, so that '1' -> 0, '2' -> 1, etc. + int index = (int)subKey[6] - '0' - 1; + + //Match only --logo-color-[1-9] + if(index < 0 || index >= FASTFETCH_LOGO_MAX_COLORS) + { + fprintf(stderr, "Error: invalid --color-[1-9] index: %c\n", key[13]); + exit(472); + } + if(value == NULL) + { + fprintf(stderr, "Error: usage: %s \n", key); + exit(477); + } + ffOptionParseColor(value, &options->colors[index]); + } + else if(strcasecmp(subKey, "width") == 0) + options->width = ffOptionParseUInt32(key, value); + else if(strcasecmp(subKey, "height") == 0) + options->height = ffOptionParseUInt32(key, value); + else if(strcasecmp(subKey, "padding") == 0) + { + uint32_t padding = ffOptionParseUInt32(key, value); + options->paddingLeft = padding; + options->paddingRight = padding; + } + else if(strcasecmp(subKey, "padding-top") == 0) + options->paddingTop = ffOptionParseUInt32(key, value); + else if(strcasecmp(subKey, "padding-left") == 0) + options->paddingLeft = ffOptionParseUInt32(key, value); + else if(strcasecmp(subKey, "padding-right") == 0) + options->paddingRight = ffOptionParseUInt32(key, value); + else if(strcasecmp(subKey, "print-remaining") == 0) + options->printRemaining = ffOptionParseBoolean(value); + else if(strcasecmp(subKey, "preserve-aspect-radio") == 0) + options->preserveAspectRadio = ffOptionParseBoolean(value); + else if(strcasecmp(subKey, "recache") == 0) + options->recache = ffOptionParseBoolean(value); + else if(strcasecmp(subKey, "separate") == 0) + options->separate = ffOptionParseBoolean(value); + else + return false; + } + else if((subKey = ffOptionTestPrefix(key, "file"))) + { + if(subKey[0] == '\0') + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_FILE; + } + else if(strcasecmp(subKey, "raw") == 0) + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_FILE_RAW; + } + else + return false; + } + else if((subKey = ffOptionTestPrefix(key, "data"))) + { + if(subKey[0] == '\0') + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_DATA; + } + else if(strcasecmp(subKey, "raw") == 0) + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_DATA_RAW; + } + else + return false; + } + else if(strcasecmp(key, "--sixel") == 0) + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_IMAGE_SIXEL; + } + else if(strcasecmp(key, "--kitty") == 0) + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_IMAGE_KITTY; + } + else if(strcasecmp(key, "--kitty-direct") == 0) + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_IMAGE_KITTY_DIRECT; + } + else if(strcasecmp(key, "--iterm") == 0) + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_IMAGE_ITERM; + } + else if(strcasecmp(key, "--raw") == 0) + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_IMAGE_RAW; + } + else if((subKey = ffOptionTestPrefix(key, "chafa"))) + { + if(subKey[0] == '\0') + { + ffOptionParseString(key, value, &options->source); + options->type = FF_LOGO_TYPE_IMAGE_CHAFA; + } + else if(strcasecmp(subKey, "fg-only") == 0) + options->chafaFgOnly = ffOptionParseBoolean(value); + else if(strcasecmp(subKey, "symbols") == 0) + ffOptionParseString(key, value, &options->chafaSymbols); + else if(strcasecmp(subKey, "canvas-mode") == 0) + options->chafaCanvasMode = ffOptionParseUInt32(key, value); + else if(strcasecmp(subKey, "color-space") == 0) + options->chafaColorSpace = ffOptionParseUInt32(key, value); + else if(strcasecmp(subKey, "dither-mode") == 0) + options->chafaDitherMode = ffOptionParseUInt32(key, value); + else + return false; + } + else + return false; + + return true; +} + +void ffDestroyLogoOptions(FFLogoOptions* options) +{ + ffStrbufDestroy(&options->source); + ffStrbufDestroy(&options->chafaSymbols); + for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i) + ffStrbufDestroy(&options->colors[i]); +} + +const char* ffParseLogoJsonConfig(FFLogoOptions* options) +{ + yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); + assert(root); + + if (!yyjson_is_obj(root)) + return "Invalid JSON config format. Root value must be an object"; + + yyjson_val* object = yyjson_obj_get(root, "logo"); + if (!object) return NULL; + if (yyjson_is_null(object)) + { + options->type = FF_LOGO_TYPE_NONE; + options->paddingTop = 0; + options->paddingRight = 0; + options->paddingLeft = 0; + return NULL; + } + + if (yyjson_is_str(object)) + { + const char* value = yyjson_get_str(object); + ffStrbufSetS(&options->source, value); + return NULL; + } + + if (!yyjson_is_obj(object)) return "Property 'logo' must be an object"; + + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(object, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + + if (strcasecmp(key, "type") == 0) + { + int value; + const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { + { "auto", FF_LOGO_TYPE_AUTO }, + { "builtin", FF_LOGO_TYPE_BUILTIN }, + { "small", FF_LOGO_TYPE_SMALL }, + { "file", FF_LOGO_TYPE_FILE }, + { "file-raw", FF_LOGO_TYPE_FILE_RAW }, + { "data", FF_LOGO_TYPE_DATA }, + { "data-raw", FF_LOGO_TYPE_DATA_RAW }, + { "sixel", FF_LOGO_TYPE_IMAGE_SIXEL }, + { "kitty", FF_LOGO_TYPE_IMAGE_KITTY }, + { "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT }, + { "iterm", FF_LOGO_TYPE_IMAGE_ITERM }, + { "chafa", FF_LOGO_TYPE_IMAGE_CHAFA }, + { "raw", FF_LOGO_TYPE_IMAGE_RAW }, + { "none", FF_LOGO_TYPE_NONE }, + {}, + }); + + if (error) return error; + options->type = (FFLogoType) value; + continue; + } + else if (strcasecmp(key, "source") == 0) + { + ffStrbufSetS(&options->source, yyjson_get_str(val)); + continue; + } + else if (strcasecmp(key, "color") == 0) + { + if (!yyjson_is_obj(val)) + return "Property 'color' must be an object"; + + yyjson_val *key_c, *valc; + size_t idxc, maxc; + yyjson_obj_foreach(val, idxc, maxc, key_c, valc) + { + const char* keyc = yyjson_get_str(key_c); + uint32_t index = (uint32_t) strtoul(keyc, NULL, 10); + if (index < 1 || index > FASTFETCH_LOGO_MAX_COLORS) + return "Keys of property 'color' must be a number between 1 to 9"; + + ffOptionParseColor(yyjson_get_str(valc), &options->colors[index - 1]); + } + continue; + } + else if (strcasecmp(key, "width") == 0) + { + uint32_t value = (uint32_t) yyjson_get_uint(val); + if (value == 0) + return "Logo width must be a possitive integer"; + options->width = value; + continue; + } + else if (strcasecmp(key, "height") == 0) + { + uint32_t value = (uint32_t) yyjson_get_uint(val); + if (value == 0) + return "Logo height must be a possitive integer"; + options->height = value; + continue; + } + else if (strcasecmp(key, "padding") == 0) + { + if (!yyjson_is_obj(val)) + return "Logo padding must be an object"; + + #define FF_PARSE_PADDING_POSITON(pos, paddingPos) \ + yyjson_val* pos = yyjson_obj_get(val, #pos); \ + if (pos) \ + { \ + if (!yyjson_is_uint(pos)) \ + return "Logo padding values must be possitive integers"; \ + options->paddingPos = (uint32_t) yyjson_get_uint(pos); \ + } + FF_PARSE_PADDING_POSITON(left, paddingLeft); + FF_PARSE_PADDING_POSITON(top, paddingTop); + FF_PARSE_PADDING_POSITON(right, paddingRight); + #undef FF_PARSE_PADDING_POSITON + continue; + } + else if (strcasecmp(key, "printRemaining") == 0) + { + options->printRemaining = yyjson_get_bool(val); + continue; + } + else if (strcasecmp(key, "preserveAspectRadio") == 0) + { + options->preserveAspectRadio = yyjson_get_bool(val); + continue; + } + else if (strcasecmp(key, "recache") == 0) + { + options->recache = yyjson_get_bool(val); + continue; + } + else if (strcasecmp(key, "separate") == 0) + { + options->separate = yyjson_get_bool(val); + continue; + } + else if (strcasecmp(key, "chafa") == 0) + { + if (!yyjson_is_obj(val)) + return "Chafa config must be an object"; + + yyjson_val* fgOnly = yyjson_obj_get(val, "fgOnly"); + if (fgOnly) + options->chafaFgOnly = yyjson_get_bool(fgOnly); + + yyjson_val* symbols = yyjson_obj_get(val, "symbols"); + if (symbols) + ffStrbufAppendS(&options->chafaSymbols, yyjson_get_str(symbols)); + + yyjson_val* canvasMode = yyjson_obj_get(val, "canvasMode"); + if (canvasMode) + { + int value; + const char* error = ffJsonConfigParseEnum(canvasMode, &value, (FFKeyValuePair[]) { + { "TRUECOLOR", 0 }, + { "INDEXED_256", 1 }, + { "INDEXED_240", 2 }, + { "INDEXED_16", 3 }, + { "FGBG_BGFG", 4 }, + { "FGBG", 5 }, + { "INDEXED_8", 6 }, + { "INDEXED_16_8", 7 }, + {}, + }); + + if (error) return error; + options->chafaCanvasMode = (uint32_t) value; + } + + yyjson_val* colorSpace = yyjson_obj_get(val, "colorSpace"); + if (colorSpace) + { + int value; + const char* error = ffJsonConfigParseEnum(colorSpace, &value, (FFKeyValuePair[]) { + { "RGB", 0 }, + { "DIN99D", 1 }, + {}, + }); + + if (error) return error; + options->chafaColorSpace = (uint32_t) value; + } + + yyjson_val* ditherMode = yyjson_obj_get(val, "ditherMode"); + if (ditherMode) + { + int value; + const char* error = ffJsonConfigParseEnum(ditherMode, &value, (FFKeyValuePair[]) { + { "NONE", 0 }, + { "ORDERED", 1 }, + { "DIFFUSION", 2 }, + {}, + }); + + if (error) return error; + options->chafaDitherMode = (uint32_t) value; + } + continue; + } + else + return "Unknown logo key"; + } + + return NULL; +} + +void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc) +{ + __attribute__((__cleanup__(ffDestroyLogoOptions))) FFLogoOptions defaultOptions; + ffInitLogoOptions(&defaultOptions); + + yyjson_mut_val* obj = yyjson_mut_obj(doc); + + if (options->type != defaultOptions.type) + { + switch (options->type) + { + case FF_LOGO_TYPE_NONE: + yyjson_mut_obj_add_null(doc, doc->root, "logo"); + return; + case FF_LOGO_TYPE_BUILTIN: + yyjson_mut_obj_add_str(doc, obj, "type", "builtin"); + break; + case FF_LOGO_TYPE_SMALL: + yyjson_mut_obj_add_str(doc, obj, "type", "small"); + break; + case FF_LOGO_TYPE_FILE: + yyjson_mut_obj_add_str(doc, obj, "type", "file"); + break; + case FF_LOGO_TYPE_FILE_RAW: + yyjson_mut_obj_add_str(doc, obj, "type", "file-raw"); + break; + case FF_LOGO_TYPE_DATA: + yyjson_mut_obj_add_str(doc, obj, "type", "data"); + break; + case FF_LOGO_TYPE_DATA_RAW: + yyjson_mut_obj_add_str(doc, obj, "type", "data-raw"); + break; + case FF_LOGO_TYPE_IMAGE_SIXEL: + yyjson_mut_obj_add_str(doc, obj, "type", "sixel"); + break; + case FF_LOGO_TYPE_IMAGE_KITTY: + yyjson_mut_obj_add_str(doc, obj, "type", "kitty"); + break; + case FF_LOGO_TYPE_IMAGE_ITERM: + yyjson_mut_obj_add_str(doc, obj, "type", "iterm"); + break; + case FF_LOGO_TYPE_IMAGE_CHAFA: + yyjson_mut_obj_add_str(doc, obj, "type", "chafa"); + break; + case FF_LOGO_TYPE_IMAGE_RAW: + yyjson_mut_obj_add_str(doc, obj, "type", "raw"); + break; + default: + yyjson_mut_obj_add_str(doc, obj, "type", "auto"); + break; + } + } + + if (!ffStrbufEqual(&options->source, &defaultOptions.source)) + yyjson_mut_obj_add_str(doc, obj, "source", options->source.chars); + + { + yyjson_mut_val* color = yyjson_mut_arr(doc); + for (int i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++) + { + if (!ffStrbufEqual(&options->colors[i], &defaultOptions.colors[i])) + yyjson_mut_arr_add_strbuf(doc, color, &options->colors[i]); + } + if (yyjson_mut_arr_size(color) > 0) + yyjson_mut_obj_add_val(doc, obj, "color", color); + } + + if (options->width != defaultOptions.width) + yyjson_mut_obj_add_uint(doc, obj, "width", options->width); + + if (options->height != defaultOptions.height) + yyjson_mut_obj_add_uint(doc, obj, "height", options->height); + + { + yyjson_mut_val* padding = yyjson_mut_obj(doc); + if (options->paddingTop != defaultOptions.paddingTop) + yyjson_mut_obj_add_uint(doc, padding, "top", options->paddingTop); + if (options->paddingLeft != defaultOptions.paddingLeft) + yyjson_mut_obj_add_uint(doc, padding, "left", options->paddingLeft); + if (options->paddingRight != defaultOptions.paddingRight) + yyjson_mut_obj_add_uint(doc, padding, "right", options->paddingRight); + + if (yyjson_mut_obj_size(padding) > 0) + yyjson_mut_obj_add_val(doc, obj, "padding", padding); + } + + if (options->printRemaining != defaultOptions.printRemaining) + yyjson_mut_obj_add_bool(doc, obj, "printRemaining", options->printRemaining); + + if (options->preserveAspectRadio != defaultOptions.preserveAspectRadio) + yyjson_mut_obj_add_bool(doc, obj, "preserveAspectRadio", options->preserveAspectRadio); + + if (options->recache != defaultOptions.recache) + yyjson_mut_obj_add_bool(doc, obj, "recache", options->recache); + + if (options->separate != defaultOptions.separate) + yyjson_mut_obj_add_bool(doc, obj, "separate", options->separate); + + { + yyjson_mut_val* chafa = yyjson_mut_obj(doc); + if (options->chafaFgOnly != defaultOptions.chafaFgOnly) + yyjson_mut_obj_add_bool(doc, chafa, "fgOnly", options->chafaFgOnly); + if (!ffStrbufEqual(&options->chafaSymbols, &defaultOptions.chafaSymbols)) + yyjson_mut_obj_add_strbuf(doc, chafa, "symbols", &options->chafaSymbols); + if (options->chafaCanvasMode != defaultOptions.chafaCanvasMode && options->chafaCanvasMode <= 7) + { + yyjson_mut_obj_add_str(doc, chafa, "canvasMode", ((const char* []) { + "TRUECOLOR", + "INDEXED_256", + "INDEXED_240", + "INDEXED_16", + "FGBG_BGFG", + "FGBG", + "INDEXED_8", + "INDEXED_16_8", + })[options->chafaCanvasMode]); + } + if (options->chafaColorSpace != defaultOptions.chafaColorSpace && options->chafaColorSpace <= 1) + { + yyjson_mut_obj_add_str(doc, chafa, "colorSpace", ((const char* []) { + "RGB", + "DIN99D", + })[options->chafaColorSpace]); + } + if (options->chafaDitherMode != defaultOptions.chafaDitherMode && options->chafaDitherMode <= 2) + { + yyjson_mut_obj_add_str(doc, chafa, "ditherMode", ((const char* []) { + "NONE", + "ORDERED", + "DIFFUSION", + })[options->chafaDitherMode]); + } + + if (yyjson_mut_obj_size(chafa) > 0) + yyjson_mut_obj_add_val(doc, obj, "chafa", chafa); + } + + if (yyjson_mut_obj_size(obj) > 0) + yyjson_mut_obj_add_val(doc, doc->root, "logo", obj); +} diff --git a/src/options/logo.h b/src/options/logo.h new file mode 100644 index 000000000..98d0d4bb8 --- /dev/null +++ b/src/options/logo.h @@ -0,0 +1,52 @@ +#pragma once + +#include "util/FFstrbuf.h" + +#define FASTFETCH_LOGO_MAX_NAMES 9 +#define FASTFETCH_LOGO_MAX_COLORS 9 //two digits would make parsing much more complicated (index 1 - 9) + +typedef enum FFLogoType +{ + FF_LOGO_TYPE_AUTO, //if something is given, first try builtin, then file. Otherwise detect logo + FF_LOGO_TYPE_BUILTIN, //builtin ascii art + FF_LOGO_TYPE_SMALL, //builtin ascii art, small version + FF_LOGO_TYPE_FILE, //text file, printed with color code replacement + FF_LOGO_TYPE_FILE_RAW, //text file, printed as is + FF_LOGO_TYPE_DATA, //text data, printed with color code replacement + FF_LOGO_TYPE_DATA_RAW, //text data, printed as is + FF_LOGO_TYPE_IMAGE_SIXEL, //image file, printed as sixel codes. + FF_LOGO_TYPE_IMAGE_KITTY, //image file, printed as kitty graphics protocol + FF_LOGO_TYPE_IMAGE_KITTY_DIRECT, //image file, tell the terminal emulator to read image data from the specified file (Supported by kitty and wezterm) + FF_LOGO_TYPE_IMAGE_ITERM, //image file, printed as iterm graphics protocol + FF_LOGO_TYPE_IMAGE_CHAFA, //image file, printed as ascii art using libchafa + FF_LOGO_TYPE_IMAGE_RAW, //image file, printed as raw binary string + FF_LOGO_TYPE_NONE, //--logo none +} FFLogoType; + +typedef struct FFLogoOptions +{ + FFstrbuf source; + FFLogoType type; + FFstrbuf colors[FASTFETCH_LOGO_MAX_COLORS]; + uint32_t width; + uint32_t height; + uint32_t paddingTop; + uint32_t paddingLeft; + uint32_t paddingRight; + bool printRemaining; + bool preserveAspectRadio; + bool recache; + bool separate; + + bool chafaFgOnly; + FFstrbuf chafaSymbols; + uint32_t chafaCanvasMode; + uint32_t chafaColorSpace; + uint32_t chafaDitherMode; +} FFLogoOptions; + +void ffInitLogoOptions(FFLogoOptions* options); +bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value); +void ffDestroyLogoOptions(FFLogoOptions* options); +const char* ffParseLogoJsonConfig(FFLogoOptions* options); +void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc); From bed1b4cf0f952e6e5963242911352cef43f8c9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 25 Oct 2023 13:39:13 +0800 Subject: [PATCH 029/100] Global: move general options to a new separate folder --- CHANGELOG.md | 3 + CMakeLists.txt | 1 + doc/json_schema.json | 20 +- src/common/commandoption.c | 2 +- src/common/init.c | 20 +- src/common/jsonconfig.c | 62 +- src/common/jsonconfig.h | 1 - src/common/processing_linux.c | 2 +- src/common/processing_windows.c | 2 +- src/detection/battery/battery_windows.c | 2 +- src/detection/chassis/chassis_windows.cpp | 2 +- .../displayserver/displayserver_apple.c | 2 +- .../displayserver/linux/displayserver_linux.c | 2 +- src/detection/displayserver/linux/wmde.c | 8 +- src/detection/media/media_linux.c | 4 +- src/detection/os/os_linux.c | 6 +- src/detection/packages/packages_windows.c | 2 +- src/detection/terminalfont/terminalfont.c | 2 +- src/detection/vulkan/vulkan.c | 2 +- src/fastfetch.c | 53 +- src/fastfetch.h | 19 +- src/logo/option.c | 560 ------------------ src/logo/option.h | 46 -- src/options/general.c | 98 +++ src/options/general.h | 25 + src/options/logo.c | 8 +- src/options/logo.h | 2 +- src/util/windows/wmi.hpp | 2 +- 28 files changed, 195 insertions(+), 763 deletions(-) delete mode 100644 src/logo/option.c delete mode 100644 src/logo/option.h create mode 100644 src/options/general.c create mode 100644 src/options/general.h diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c58a2ac0..9db77642c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # 2.2.0 +Changes: +* `--pipe` and `--stat` are moved from `general` options to `display` options. This affects cjson configuration. + Features: * Quirks for MIPS platforms (CPU, Linux) * Use devicetree path for OBP hosts (Host, Linux) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0239cdbc0..243172947 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -355,6 +355,7 @@ set(LIBFASTFETCH_SRC src/modules/wm/wm.c src/modules/wmtheme/wmtheme.c src/options/logo.c + src/options/general.c src/util/edidHelper.c src/util/FFlist.c src/util/FFstrbuf.c diff --git a/doc/json_schema.json b/doc/json_schema.json index e309dee87..b099900da 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -242,21 +242,11 @@ "title": "Alias of multithreading", "default": true }, - "stat": { - "type": "boolean", - "title": "Show time usage (in ms) for individual modules", - "default": false - }, "escapeBedrock": { "type": "boolean", "title": "On Bedrock Linux, whether to escape the bedrock jail", "default": true }, - "pipe": { - "type": "boolean", - "title": "Whether to enable pipe mode (disable logo and all escape sequences)", - "default": false - }, "playerName": { "type": "string", "title": "The name of the player to use for module Media and Player. Linux only" @@ -287,6 +277,16 @@ "title": "Configure how things to be displayed", "type": "object", "properties": { + "stat": { + "type": "boolean", + "title": "Show time usage (in ms) for individual modules", + "default": false + }, + "pipe": { + "type": "boolean", + "title": "Whether to enable pipe mode (disable logo and all escape sequences)", + "default": false + }, "showErrors": { "type": "boolean", "title": "Print occurring errors to the console. False to ignore errored modules", diff --git a/src/common/commandoption.c b/src/common/commandoption.c index 727292fa2..ab3ac56da 100644 --- a/src/common/commandoption.c +++ b/src/common/commandoption.c @@ -87,7 +87,7 @@ void ffPrepareCommandOption(FFdata* data) if(ffStrbufContainIgnCaseS(&data->structure, FF_NETIO_MODULE_NAME)) ffPrepareNetIO(&instance.config.netIo); - if(instance.config.multithreading) + if(instance.config.general.multithreading) { if(ffStrbufContainIgnCaseS(&data->structure, FF_PUBLICIP_MODULE_NAME)) ffPreparePublicIp(&instance.config.publicIP); diff --git a/src/common/init.c b/src/common/init.c index bfabc8129..84efec1db 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -33,23 +33,14 @@ static void initState(FFstate* state) static void defaultConfig(void) { ffInitLogoOptions(&instance.config.logo); + ffInitGeneralOptions(&instance.config.general); ffStrbufInit(&instance.config.colorKeys); ffStrbufInit(&instance.config.colorTitle); instance.config.brightColor = true; ffStrbufInitStatic(&instance.config.keyValueSeparator, ": "); - instance.config.processingTimeout = 1000; - - #if defined(__linux__) || defined(__FreeBSD__) - ffStrbufInit(&instance.config.playerName); - ffStrbufInit(&instance.config.osFile); - instance.config.dsForceDrm = false; - #elif defined(_WIN32) - instance.config.wmiTimeout = 5000; - #endif instance.config.showErrors = false; - instance.config.allowSlowOperations = false; instance.config.pipe = !isatty(STDOUT_FILENO); #ifdef NDEBUG @@ -60,12 +51,10 @@ static void defaultConfig(void) instance.config.hideCursor = false; #endif - instance.config.escapeBedrock = true; instance.config.binaryPrefixType = FF_BINARY_PREFIX_TYPE_IEC; instance.config.sizeNdigits = 2; instance.config.sizeMaxPrefix = UINT8_MAX; instance.config.temperatureUnit = FF_TEMPERATURE_UNIT_CELSIUS; - instance.config.multithreading = true; instance.config.stat = false; instance.config.noBuffer = false; instance.config.keyWidth = 0; @@ -233,7 +222,7 @@ static void exitSignalHandler(int signal) void ffStart(void) { #ifdef FF_START_DETECTION_THREADS - if(instance.config.multithreading) + if(instance.config.general.multithreading) startDetectionThreads(); #endif @@ -287,11 +276,6 @@ static void destroyConfig(void) ffStrbufDestroy(&instance.config.barCharElapsed); ffStrbufDestroy(&instance.config.barCharTotal); - #if defined(__linux__) || defined(__FreeBSD__) - ffStrbufDestroy(&instance.config.playerName); - ffStrbufDestroy(&instance.config.osFile); - #endif - ffDestroyBatteryOptions(&instance.config.battery); ffDestroyBiosOptions(&instance.config.bios); ffDestroyBluetoothOptions(&instance.config.bluetooth); diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index f4ef9bc75..f3f240fef 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -227,59 +227,6 @@ static const char* printJsonConfig(bool prepare) return NULL; } -const char* ffParseGeneralJsonConfig(FFconfig* config) -{ - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); - assert(root); - - if (!yyjson_is_obj(root)) - return "Invalid JSON config format. Root value must be an object"; - - yyjson_val* object = yyjson_obj_get(root, "general"); - if (!object) return NULL; - if (!yyjson_is_obj(object)) return "Property 'general' must be an object"; - - yyjson_val *key_, *val; - size_t idx, max; - yyjson_obj_foreach(object, idx, max, key_, val) - { - const char* key = yyjson_get_str(key_); - - if (ffStrEqualsIgnCase(key, "allowSlowOperations")) - config->allowSlowOperations = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "thread") || ffStrEqualsIgnCase(key, "multithreading")) - config->multithreading = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "stat")) - { - if ((config->stat = yyjson_get_bool(val))) - config->showErrors = true; - } - else if (ffStrEqualsIgnCase(key, "escapeBedrock")) - config->escapeBedrock = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "pipe")) - config->pipe = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "processingTimeout")) - config->processingTimeout = (int32_t) yyjson_get_int(val); - - #if defined(__linux__) || defined(__FreeBSD__) - else if (ffStrEqualsIgnCase(key, "playerName")) - ffStrbufSetS(&config->playerName, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "osFile")) - ffStrbufSetS(&config->osFile, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "dsForceDrm")) - config->dsForceDrm = yyjson_get_bool(val); - #elif defined(_WIN32) - else if (ffStrEqualsIgnCase(key, "wmiTimeout")) - config->wmiTimeout = (int32_t) yyjson_get_int(val); - #endif - - else - return "Unknown general property"; - } - - return NULL; -} - const char* ffParseDisplayJsonConfig(FFconfig* config) { yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); @@ -298,7 +245,14 @@ const char* ffParseDisplayJsonConfig(FFconfig* config) { const char* key = yyjson_get_str(key_); - if (ffStrEqualsIgnCase(key, "showErrors")) + if (ffStrEqualsIgnCase(key, "stat")) + { + if ((config->stat = yyjson_get_bool(val))) + config->showErrors = true; + } + else if (ffStrEqualsIgnCase(key, "pipe")) + config->pipe = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "showErrors")) config->showErrors = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "disableLinewrap")) config->disableLinewrap = yyjson_get_bool(val); diff --git a/src/common/jsonconfig.h b/src/common/jsonconfig.h index f7546f174..6103d7337 100644 --- a/src/common/jsonconfig.h +++ b/src/common/jsonconfig.h @@ -5,7 +5,6 @@ bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs* moduleArgs); const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]); void ffPrintJsonConfig(bool prepare); -const char* ffParseGeneralJsonConfig(FFconfig* config); const char* ffParseDisplayJsonConfig(FFconfig* config); const char* ffParseLibraryJsonConfig(FFconfig* config); void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs); diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index 84bc79cec..b96a2ff85 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -48,7 +48,7 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use int FF_AUTO_CLOSE_FD childPipeFd = pipes[0]; - int timeout = instance.config.processingTimeout; + int timeout = instance.config.general.processingTimeout; if (timeout >= 0) fcntl(childPipeFd, F_SETFL, fcntl(childPipeFd, F_GETFL) | O_NONBLOCK); diff --git a/src/common/processing_windows.c b/src/common/processing_windows.c index 6355a3a1f..5f44d5210 100644 --- a/src/common/processing_windows.c +++ b/src/common/processing_windows.c @@ -8,7 +8,7 @@ enum { FF_PIPE_BUFSIZ = 4096 }; const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool useStdErr) { - int timeout = instance.config.processingTimeout; + int timeout = instance.config.general.processingTimeout; FF_AUTO_CLOSE_FD HANDLE hChildPipeRead = CreateNamedPipeW( L"\\\\.\\pipe\\LOCAL\\", diff --git a/src/detection/battery/battery_windows.c b/src/detection/battery/battery_windows.c index 056bfd06a..e75baccbc 100644 --- a/src/detection/battery/battery_windows.c +++ b/src/detection/battery/battery_windows.c @@ -32,7 +32,7 @@ static inline void wrapSetupDiDestroyDeviceInfoList(HDEVINFO* hdev) const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) { - if(instance.config.allowSlowOperations) + if(instance.config.general.allowSlowOperations) { //https://learn.microsoft.com/en-us/windows/win32/power/enumerating-battery-devices HDEVINFO hdev __attribute__((__cleanup__(wrapSetupDiDestroyDeviceInfoList))) = diff --git a/src/detection/chassis/chassis_windows.cpp b/src/detection/chassis/chassis_windows.cpp index 2332c5b31..05fe63ad1 100644 --- a/src/detection/chassis/chassis_windows.cpp +++ b/src/detection/chassis/chassis_windows.cpp @@ -67,7 +67,7 @@ FF_MAYBE_UNUSED static const char* detectWithWmi(FFChassisResult* result) extern "C" const char* ffDetectChassis(FFChassisResult* result) { - if (instance.config.allowSlowOperations) + if (instance.config.general.allowSlowOperations) return detectWithWmi(result); return detectWithRegistry(result); } diff --git a/src/detection/displayserver/displayserver_apple.c b/src/detection/displayserver/displayserver_apple.c index dfd2fe77f..1bc386c52 100644 --- a/src/detection/displayserver/displayserver_apple.c +++ b/src/detection/displayserver/displayserver_apple.c @@ -116,7 +116,7 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) } ffStrbufInit(&ds->wmProtocolName); - if(instance.config.allowSlowOperations) + if(instance.config.general.allowSlowOperations) { FF_STRBUF_AUTO_DESTROY name; ffStrbufInit(&name); diff --git a/src/detection/displayserver/linux/displayserver_linux.c b/src/detection/displayserver/linux/displayserver_linux.c index 3c93d29c0..3de10d9dc 100644 --- a/src/detection/displayserver/linux/displayserver_linux.c +++ b/src/detection/displayserver/linux/displayserver_linux.c @@ -88,7 +88,7 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) ffStrbufInit(&ds->deVersion); ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4); - if (!instance.config.dsForceDrm) + if (!instance.config.general.dsForceDrm) { //We try wayland as our prefered display server, as it supports the most features. //This method can't detect the name of our WM / DE diff --git a/src/detection/displayserver/linux/wmde.c b/src/detection/displayserver/linux/wmde.c index b34c429f2..8829f2352 100644 --- a/src/detection/displayserver/linux/wmde.c +++ b/src/detection/displayserver/linux/wmde.c @@ -154,7 +154,7 @@ static void getKDE(FFDisplayServerResult* result) if(result->deVersion.length == 0) ffParsePropFileData("wayland-sessions/plasmawayland5.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion); - if(result->deVersion.length == 0 && instance.config.allowSlowOperations) + if(result->deVersion.length == 0 && instance.config.general.allowSlowOperations) { if (ffProcessAppendStdOut(&result->deVersion, (char* const[]){ "plasmashell", @@ -214,7 +214,7 @@ static void getMate(FFDisplayServerResult* result) ffParseSemver(&result->deVersion, &major, &minor, µ); - if(result->deVersion.length == 0 && instance.config.allowSlowOperations) + if(result->deVersion.length == 0 && instance.config.general.allowSlowOperations) { ffProcessAppendStdOut(&result->deVersion, (char* const[]){ "mate-session", @@ -250,7 +250,7 @@ static void getXFCE4(FFDisplayServerResult* result) } #endif - if(result->deVersion.length == 0 && instance.config.allowSlowOperations) + if(result->deVersion.length == 0 && instance.config.general.allowSlowOperations) { //This is somewhat slow ffProcessAppendStdOut(&result->deVersion, (char* const[]){ @@ -276,7 +276,7 @@ static void getLXQt(FFDisplayServerResult* result) if(result->deVersion.length == 0) ffParsePropFileData("cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", &result->deVersion); - if(result->deVersion.length == 0 && instance.config.allowSlowOperations) + if(result->deVersion.length == 0 && instance.config.general.allowSlowOperations) { //This is really, really, really slow. Thank you, LXQt developers ffProcessAppendStdOut(&result->deVersion, (char* const[]){ diff --git a/src/detection/media/media_linux.c b/src/detection/media/media_linux.c index 2552fdab2..35830f1b9 100644 --- a/src/detection/media/media_linux.c +++ b/src/detection/media/media_linux.c @@ -161,8 +161,8 @@ static const char* getMedia(FFMediaResult* result) // FIXME: This is shared for both player and media module. // However it uses an option in one specific module - if(instance.config.playerName.length > 0) - getCustomBus(&data, &instance.config.playerName, result); + if(instance.config.general.playerName.length > 0) + getCustomBus(&data, &instance.config.general.playerName, result); else getBestBus(&data, result); diff --git a/src/detection/os/os_linux.c b/src/detection/os/os_linux.c index 1b99c174c..346b2937a 100644 --- a/src/detection/os/os_linux.c +++ b/src/detection/os/os_linux.c @@ -133,13 +133,13 @@ static void getDebianVersion(FFOSResult* result) static void detectOS(FFOSResult* os) { - if(instance.config.osFile.length > 0) + if(instance.config.general.osFile.length > 0) { - parseFile(instance.config.osFile.chars, os); + parseFile(instance.config.general.osFile.chars, os); return; } - if(instance.config.escapeBedrock && parseFile(FASTFETCH_TARGET_DIR_ROOT"/bedrock"FASTFETCH_TARGET_DIR_ETC"/bedrock-release", os)) + if(instance.config.general.escapeBedrock && parseFile(FASTFETCH_TARGET_DIR_ROOT"/bedrock"FASTFETCH_TARGET_DIR_ETC"/bedrock-release", os)) { if(os->id.length == 0) ffStrbufAppendS(&os->id, "bedrock"); diff --git a/src/detection/packages/packages_windows.c b/src/detection/packages/packages_windows.c index bfd6a4c79..e5b591361 100644 --- a/src/detection/packages/packages_windows.c +++ b/src/detection/packages/packages_windows.c @@ -110,6 +110,6 @@ void ffDetectPackagesImpl(FFPackagesResult* result) detectScoop(result); detectChoco(result); detectPacman(result); - if (instance.config.allowSlowOperations) + if (instance.config.general.allowSlowOperations) detectWinget(result); } diff --git a/src/detection/terminalfont/terminalfont.c b/src/detection/terminalfont/terminalfont.c index 1ebca55d9..cf5366f5b 100644 --- a/src/detection/terminalfont/terminalfont.c +++ b/src/detection/terminalfont/terminalfont.c @@ -247,7 +247,7 @@ FF_MAYBE_UNUSED static bool detectKitty(const FFstrbuf* exe, FFTerminalFontResul {"font_size ", &fontSize}, }; - if(instance.config.allowSlowOperations) + if(instance.config.general.allowSlowOperations) { FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate(); if(!ffProcessAppendStdOut(&buf, (char* const[]){ diff --git a/src/detection/vulkan/vulkan.c b/src/detection/vulkan/vulkan.c index 88d687c8e..0516e1bbc 100644 --- a/src/detection/vulkan/vulkan.c +++ b/src/detection/vulkan/vulkan.c @@ -119,7 +119,7 @@ static const char* detectVulkan(FFVulkanResult* result) PFN_vkGetPhysicalDeviceMemoryProperties ffvkGetPhysicalDeviceMemoryProperties = NULL; PFN_vkGetPhysicalDeviceMemoryProperties2 ffvkGetPhysicalDeviceMemoryProperties2 = - instance.config.allowSlowOperations ? (PFN_vkGetPhysicalDeviceMemoryProperties2) ffvkGetInstanceProcAddr(vkInstance, "vkGetPhysicalDeviceMemoryProperties2") : NULL; // 1.1 + instance.config.general.allowSlowOperations ? (PFN_vkGetPhysicalDeviceMemoryProperties2) ffvkGetInstanceProcAddr(vkInstance, "vkGetPhysicalDeviceMemoryProperties2") : NULL; // 1.1 if(!ffvkGetPhysicalDeviceMemoryProperties2) ffvkGetPhysicalDeviceMemoryProperties = (PFN_vkGetPhysicalDeviceMemoryProperties) ffvkGetInstanceProcAddr(vkInstance, "vkGetPhysicalDeviceMemoryProperties"); diff --git a/src/fastfetch.c b/src/fastfetch.c index 4a531e87e..5a34305eb 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -471,9 +471,9 @@ static void parseOption(FFdata* data, const char* key, const char* value) customValue->printKey = key[5] == '\0'; } - /////////////////// - //General options// - /////////////////// + //////////// + //Switches// + //////////// else if(ffStrEqualsIgnCase(key, "-c") || ffStrEqualsIgnCase(key, "--load-config") || ffStrEqualsIgnCase(key, "--config")) optionParseConfigFile(data, key, value); @@ -501,23 +501,8 @@ static void parseOption(FFdata* data, const char* key, const char* value) else instance.state.migrateConfigDoc = NULL; } - else if(ffStrEqualsIgnCase(key, "--thread") || ffStrEqualsIgnCase(key, "--multithreading")) - instance.config.multithreading = ffOptionParseBoolean(value); - else if(ffStrEqualsIgnCase(key, "--stat")) - { - if((instance.config.stat = ffOptionParseBoolean(value))) - instance.config.showErrors = true; - } - else if(ffStrEqualsIgnCase(key, "--allow-slow-operations")) - instance.config.allowSlowOperations = ffOptionParseBoolean(value); - else if(ffStrEqualsIgnCase(key, "--escape-bedrock")) - instance.config.escapeBedrock = ffOptionParseBoolean(value); - else if(ffStrEqualsIgnCase(key, "--pipe")) - instance.config.pipe = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--load-user-config")) data->loadUserConfig = ffOptionParseBoolean(value); - else if(ffStrEqualsIgnCase(key, "--processing-timeout")) - instance.config.processingTimeout = ffOptionParseInt32(key, value); else if(ffStrEqualsIgnCase(key, "--format")) { switch (ffOptionParseEnum(key, value, (FFKeyValuePair[]) { @@ -543,17 +528,11 @@ static void parseOption(FFdata* data, const char* key, const char* value) } } - #if defined(__linux__) || defined(__FreeBSD__) - else if(ffStrEqualsIgnCase(key, "--player-name")) - ffOptionParseString(key, value, &instance.config.playerName); - else if (ffStrEqualsIgnCase(key, "--os-file")) - ffOptionParseString(key, value, &instance.config.osFile); - else if(ffStrEqualsIgnCase(key, "--ds-force-drm")) - instance.config.dsForceDrm = ffOptionParseBoolean(value); - #elif defined(_WIN32) - else if (ffStrEqualsIgnCase(key, "--wmi-timeout")) - instance.config.wmiTimeout = ffOptionParseInt32(key, value); - #endif + /////////////////// + //General options// + /////////////////// + + else if(ffParseGeneralCommandOptions(&instance.config.general, key, value)) {} //////////////// //Logo options// @@ -565,6 +544,13 @@ static void parseOption(FFdata* data, const char* key, const char* value) //Display options// /////////////////// + else if(ffStrEqualsIgnCase(key, "--stat")) + { + if((instance.config.stat = ffOptionParseBoolean(value))) + instance.config.showErrors = true; + } + else if(ffStrEqualsIgnCase(key, "--pipe")) + instance.config.pipe = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--show-errors")) instance.config.showErrors = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--disable-linewrap")) @@ -801,9 +787,14 @@ static void run(FFdata* data) { const char* error = NULL; + yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); + if (!yyjson_is_obj(root)) + error = "Invalid JSON config format. Root value must be an object"; + if ( - (error = ffParseLogoJsonConfig(&instance.config.logo)) || - (error = ffParseGeneralJsonConfig(&instance.config)) || + error || + (error = ffParseLogoJsonConfig(&instance.config.logo, root)) || + (error = ffParseGeneralJsonConfig(&instance.config.general, root)) || (error = ffParseDisplayJsonConfig(&instance.config)) || (error = ffParseLibraryJsonConfig(&instance.config)) || false diff --git a/src/fastfetch.h b/src/fastfetch.h index 76ed4181c..eaef3b803 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -25,6 +25,7 @@ #include "modules/options.h" #include "options/logo.h" +#include "options/general.h" typedef enum FFBinaryPrefixType { @@ -43,6 +44,7 @@ typedef enum FFTemperatureUnit typedef struct FFconfig { FFLogoOptions logo; + FFGeneralOptions general; //If one of those is empty, ffLogoPrint will set them FFstrbuf colorKeys; @@ -52,11 +54,11 @@ typedef struct FFconfig FFstrbuf keyValueSeparator; + bool stat; + bool pipe; //disables logo and all escape sequences bool showErrors; - bool allowSlowOperations; bool disableLinewrap; bool hideCursor; - bool escapeBedrock; FFBinaryPrefixType binaryPrefixType; uint8_t sizeNdigits; uint8_t sizeMaxPrefix; @@ -67,22 +69,9 @@ typedef struct FFconfig bool barBorder; uint8_t percentType; uint8_t percentNdigits; - bool pipe; //disables logo and all escape sequences - bool multithreading; - bool stat; bool noBuffer; - int32_t processingTimeout; uint32_t keyWidth; - // Module options that cannot be put in module option structure - #if defined(__linux__) || defined(__FreeBSD__) - FFstrbuf playerName; - FFstrbuf osFile; - bool dsForceDrm; - #elif defined(_WIN32) - int32_t wmiTimeout; - #endif - FFBatteryOptions battery; FFBiosOptions bios; FFBluetoothOptions bluetooth; diff --git a/src/logo/option.c b/src/logo/option.c deleted file mode 100644 index 3bd9ebccb..000000000 --- a/src/logo/option.c +++ /dev/null @@ -1,560 +0,0 @@ -#include "logo/logo.h" - -#include "common/jsonconfig.h" -#include "util/stringUtils.h" - -void ffInitLogoOptions(FFLogoOptions* options) -{ - ffStrbufInit(&options->source); - options->type = FF_LOGO_TYPE_AUTO; - for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i) - ffStrbufInit(&options->colors[i]); - options->width = 0; - options->height = 0; //preserve aspect ratio - options->paddingTop = 0; - options->paddingLeft = 0; - options->paddingRight = 4; - options->printRemaining = true; - options->preserveAspectRadio = false; - options->recache = false; - options->separate = false; - - options->chafaFgOnly = false; - ffStrbufInitStatic(&options->chafaSymbols, "block+border+space-wide-inverted"); // Chafa default - options->chafaCanvasMode = UINT32_MAX; - options->chafaColorSpace = UINT32_MAX; - options->chafaDitherMode = UINT32_MAX; -} - -bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value) -{ - if (strcasecmp(key, "-l") == 0) - goto logoType; - - const char* subKey = ffOptionTestPrefix(key, "logo"); - if(subKey) - { - if (subKey[0] == '\0') - { -logoType: - if(value == NULL) - { - fprintf(stderr, "Error: usage: %s \n", key); - exit(477); - } - //this is usually wanted when disabling logo - if(strcasecmp(value, "none") == 0) - { - options->paddingTop = 0; - options->paddingRight = 0; - options->paddingLeft = 0; - options->type = FF_LOGO_TYPE_NONE; - } - else if(strcasecmp(value, "small") == 0) - { - options->type = FF_LOGO_TYPE_SMALL; - } - else - ffOptionParseString(key, value, &options->source); - } - else if(strcasecmp(subKey, "type") == 0) - { - options->type = (FFLogoType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { - { "auto", FF_LOGO_TYPE_AUTO }, - { "builtin", FF_LOGO_TYPE_BUILTIN }, - { "small", FF_LOGO_TYPE_SMALL }, - { "file", FF_LOGO_TYPE_FILE }, - { "file-raw", FF_LOGO_TYPE_FILE_RAW }, - { "data", FF_LOGO_TYPE_DATA }, - { "data-raw", FF_LOGO_TYPE_DATA_RAW }, - { "sixel", FF_LOGO_TYPE_IMAGE_SIXEL }, - { "kitty", FF_LOGO_TYPE_IMAGE_KITTY }, - { "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT }, - { "iterm", FF_LOGO_TYPE_IMAGE_ITERM }, - { "chafa", FF_LOGO_TYPE_IMAGE_CHAFA }, - { "raw", FF_LOGO_TYPE_IMAGE_RAW }, - { "none", FF_LOGO_TYPE_NONE }, - {}, - }); - } - else if(ffStrStartsWithIgnCase(subKey, "color-") && subKey[6] != '\0' && subKey[7] == '\0') // matches "--logo-color-*" - { - //Map the number to an array index, so that '1' -> 0, '2' -> 1, etc. - int index = (int)subKey[6] - '0' - 1; - - //Match only --logo-color-[1-9] - if(index < 0 || index >= FASTFETCH_LOGO_MAX_COLORS) - { - fprintf(stderr, "Error: invalid --color-[1-9] index: %c\n", key[13]); - exit(472); - } - if(value == NULL) - { - fprintf(stderr, "Error: usage: %s \n", key); - exit(477); - } - ffOptionParseColor(value, &options->colors[index]); - } - else if(strcasecmp(subKey, "width") == 0) - options->width = ffOptionParseUInt32(key, value); - else if(strcasecmp(subKey, "height") == 0) - options->height = ffOptionParseUInt32(key, value); - else if(strcasecmp(subKey, "padding") == 0) - { - uint32_t padding = ffOptionParseUInt32(key, value); - options->paddingLeft = padding; - options->paddingRight = padding; - } - else if(strcasecmp(subKey, "padding-top") == 0) - options->paddingTop = ffOptionParseUInt32(key, value); - else if(strcasecmp(subKey, "padding-left") == 0) - options->paddingLeft = ffOptionParseUInt32(key, value); - else if(strcasecmp(subKey, "padding-right") == 0) - options->paddingRight = ffOptionParseUInt32(key, value); - else if(strcasecmp(subKey, "print-remaining") == 0) - options->printRemaining = ffOptionParseBoolean(value); - else if(strcasecmp(subKey, "preserve-aspect-radio") == 0) - options->preserveAspectRadio = ffOptionParseBoolean(value); - else if(strcasecmp(subKey, "recache") == 0) - options->recache = ffOptionParseBoolean(value); - else if(strcasecmp(subKey, "separate") == 0) - options->separate = ffOptionParseBoolean(value); - else - return false; - } - else if((subKey = ffOptionTestPrefix(key, "file"))) - { - if(subKey[0] == '\0') - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_FILE; - } - else if(strcasecmp(subKey, "raw") == 0) - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_FILE_RAW; - } - else - return false; - } - else if((subKey = ffOptionTestPrefix(key, "data"))) - { - if(subKey[0] == '\0') - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_DATA; - } - else if(strcasecmp(subKey, "raw") == 0) - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_DATA_RAW; - } - else - return false; - } - else if(strcasecmp(key, "--sixel") == 0) - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_IMAGE_SIXEL; - } - else if(strcasecmp(key, "--kitty") == 0) - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_IMAGE_KITTY; - } - else if(strcasecmp(key, "--kitty-direct") == 0) - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_IMAGE_KITTY_DIRECT; - } - else if(strcasecmp(key, "--iterm") == 0) - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_IMAGE_ITERM; - } - else if(strcasecmp(key, "--raw") == 0) - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_IMAGE_RAW; - } - else if((subKey = ffOptionTestPrefix(key, "chafa"))) - { - if(subKey[0] == '\0') - { - ffOptionParseString(key, value, &options->source); - options->type = FF_LOGO_TYPE_IMAGE_CHAFA; - } - else if(strcasecmp(subKey, "fg-only") == 0) - options->chafaFgOnly = ffOptionParseBoolean(value); - else if(strcasecmp(subKey, "symbols") == 0) - ffOptionParseString(key, value, &options->chafaSymbols); - else if(strcasecmp(subKey, "canvas-mode") == 0) - options->chafaCanvasMode = ffOptionParseUInt32(key, value); - else if(strcasecmp(subKey, "color-space") == 0) - options->chafaColorSpace = ffOptionParseUInt32(key, value); - else if(strcasecmp(subKey, "dither-mode") == 0) - options->chafaDitherMode = ffOptionParseUInt32(key, value); - else - return false; - } - else - return false; - - return true; -} - -void ffDestroyLogoOptions(FFLogoOptions* options) -{ - ffStrbufDestroy(&options->source); - ffStrbufDestroy(&options->chafaSymbols); - for(uint8_t i = 0; i < (uint8_t) FASTFETCH_LOGO_MAX_COLORS; ++i) - ffStrbufDestroy(&options->colors[i]); -} - -const char* ffParseLogoJsonConfig(FFLogoOptions* options) -{ - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); - assert(root); - - if (!yyjson_is_obj(root)) - return "Invalid JSON config format. Root value must be an object"; - - yyjson_val* object = yyjson_obj_get(root, "logo"); - if (!object) return NULL; - if (yyjson_is_null(object)) - { - options->type = FF_LOGO_TYPE_NONE; - options->paddingTop = 0; - options->paddingRight = 0; - options->paddingLeft = 0; - return NULL; - } - - if (yyjson_is_str(object)) - { - const char* value = yyjson_get_str(object); - ffStrbufSetS(&options->source, value); - return NULL; - } - - if (!yyjson_is_obj(object)) return "Property 'logo' must be an object"; - - yyjson_val *key_, *val; - size_t idx, max; - yyjson_obj_foreach(object, idx, max, key_, val) - { - const char* key = yyjson_get_str(key_); - - if (strcasecmp(key, "type") == 0) - { - int value; - const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { - { "auto", FF_LOGO_TYPE_AUTO }, - { "builtin", FF_LOGO_TYPE_BUILTIN }, - { "small", FF_LOGO_TYPE_SMALL }, - { "file", FF_LOGO_TYPE_FILE }, - { "file-raw", FF_LOGO_TYPE_FILE_RAW }, - { "data", FF_LOGO_TYPE_DATA }, - { "data-raw", FF_LOGO_TYPE_DATA_RAW }, - { "sixel", FF_LOGO_TYPE_IMAGE_SIXEL }, - { "kitty", FF_LOGO_TYPE_IMAGE_KITTY }, - { "kitty-direct", FF_LOGO_TYPE_IMAGE_KITTY_DIRECT }, - { "iterm", FF_LOGO_TYPE_IMAGE_ITERM }, - { "chafa", FF_LOGO_TYPE_IMAGE_CHAFA }, - { "raw", FF_LOGO_TYPE_IMAGE_RAW }, - { "none", FF_LOGO_TYPE_NONE }, - {}, - }); - - if (error) return error; - options->type = (FFLogoType) value; - continue; - } - else if (strcasecmp(key, "source") == 0) - { - ffStrbufSetS(&options->source, yyjson_get_str(val)); - continue; - } - else if (strcasecmp(key, "color") == 0) - { - if (!yyjson_is_obj(val)) - return "Property 'color' must be an object"; - - yyjson_val *key_c, *valc; - size_t idxc, maxc; - yyjson_obj_foreach(val, idxc, maxc, key_c, valc) - { - const char* keyc = yyjson_get_str(key_c); - uint32_t index = (uint32_t) strtoul(keyc, NULL, 10); - if (index < 1 || index > FASTFETCH_LOGO_MAX_COLORS) - return "Keys of property 'color' must be a number between 1 to 9"; - - ffOptionParseColor(yyjson_get_str(valc), &options->colors[index - 1]); - } - continue; - } - else if (strcasecmp(key, "width") == 0) - { - uint32_t value = (uint32_t) yyjson_get_uint(val); - if (value == 0) - return "Logo width must be a possitive integer"; - options->width = value; - continue; - } - else if (strcasecmp(key, "height") == 0) - { - uint32_t value = (uint32_t) yyjson_get_uint(val); - if (value == 0) - return "Logo height must be a possitive integer"; - options->height = value; - continue; - } - else if (strcasecmp(key, "padding") == 0) - { - if (!yyjson_is_obj(val)) - return "Logo padding must be an object"; - - #define FF_PARSE_PADDING_POSITON(pos, paddingPos) \ - yyjson_val* pos = yyjson_obj_get(val, #pos); \ - if (pos) \ - { \ - if (!yyjson_is_uint(pos)) \ - return "Logo padding values must be possitive integers"; \ - options->paddingPos = (uint32_t) yyjson_get_uint(pos); \ - } - FF_PARSE_PADDING_POSITON(left, paddingLeft); - FF_PARSE_PADDING_POSITON(top, paddingTop); - FF_PARSE_PADDING_POSITON(right, paddingRight); - #undef FF_PARSE_PADDING_POSITON - continue; - } - else if (strcasecmp(key, "printRemaining") == 0) - { - options->printRemaining = yyjson_get_bool(val); - continue; - } - else if (strcasecmp(key, "preserveAspectRadio") == 0) - { - options->preserveAspectRadio = yyjson_get_bool(val); - continue; - } - else if (strcasecmp(key, "recache") == 0) - { - options->recache = yyjson_get_bool(val); - continue; - } - else if (strcasecmp(key, "separate") == 0) - { - options->separate = yyjson_get_bool(val); - continue; - } - else if (strcasecmp(key, "chafa") == 0) - { - if (!yyjson_is_obj(val)) - return "Chafa config must be an object"; - - yyjson_val* fgOnly = yyjson_obj_get(val, "fgOnly"); - if (fgOnly) - options->chafaFgOnly = yyjson_get_bool(fgOnly); - - yyjson_val* symbols = yyjson_obj_get(val, "symbols"); - if (symbols) - ffStrbufAppendS(&options->chafaSymbols, yyjson_get_str(symbols)); - - yyjson_val* canvasMode = yyjson_obj_get(val, "canvasMode"); - if (canvasMode) - { - int value; - const char* error = ffJsonConfigParseEnum(canvasMode, &value, (FFKeyValuePair[]) { - { "TRUECOLOR", 0 }, - { "INDEXED_256", 1 }, - { "INDEXED_240", 2 }, - { "INDEXED_16", 3 }, - { "FGBG_BGFG", 4 }, - { "FGBG", 5 }, - { "INDEXED_8", 6 }, - { "INDEXED_16_8", 7 }, - {}, - }); - - if (error) return error; - options->chafaCanvasMode = (uint32_t) value; - } - - yyjson_val* colorSpace = yyjson_obj_get(val, "colorSpace"); - if (colorSpace) - { - int value; - const char* error = ffJsonConfigParseEnum(colorSpace, &value, (FFKeyValuePair[]) { - { "RGB", 0 }, - { "DIN99D", 1 }, - {}, - }); - - if (error) return error; - options->chafaColorSpace = (uint32_t) value; - } - - yyjson_val* ditherMode = yyjson_obj_get(val, "ditherMode"); - if (ditherMode) - { - int value; - const char* error = ffJsonConfigParseEnum(ditherMode, &value, (FFKeyValuePair[]) { - { "NONE", 0 }, - { "ORDERED", 1 }, - { "DIFFUSION", 2 }, - {}, - }); - - if (error) return error; - options->chafaDitherMode = (uint32_t) value; - } - continue; - } - else - return "Unknown logo key"; - } - - return NULL; -} - -void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc) -{ - __attribute__((__cleanup__(ffDestroyLogoOptions))) FFLogoOptions defaultOptions; - ffInitLogoOptions(&defaultOptions); - - yyjson_mut_val* obj = yyjson_mut_obj(doc); - - if (options->type != defaultOptions.type) - { - switch (options->type) - { - case FF_LOGO_TYPE_NONE: - yyjson_mut_obj_add_null(doc, doc->root, "logo"); - return; - case FF_LOGO_TYPE_BUILTIN: - yyjson_mut_obj_add_str(doc, obj, "type", "builtin"); - break; - case FF_LOGO_TYPE_SMALL: - yyjson_mut_obj_add_str(doc, obj, "type", "small"); - break; - case FF_LOGO_TYPE_FILE: - yyjson_mut_obj_add_str(doc, obj, "type", "file"); - break; - case FF_LOGO_TYPE_FILE_RAW: - yyjson_mut_obj_add_str(doc, obj, "type", "file-raw"); - break; - case FF_LOGO_TYPE_DATA: - yyjson_mut_obj_add_str(doc, obj, "type", "data"); - break; - case FF_LOGO_TYPE_DATA_RAW: - yyjson_mut_obj_add_str(doc, obj, "type", "data-raw"); - break; - case FF_LOGO_TYPE_IMAGE_SIXEL: - yyjson_mut_obj_add_str(doc, obj, "type", "sixel"); - break; - case FF_LOGO_TYPE_IMAGE_KITTY: - yyjson_mut_obj_add_str(doc, obj, "type", "kitty"); - break; - case FF_LOGO_TYPE_IMAGE_ITERM: - yyjson_mut_obj_add_str(doc, obj, "type", "iterm"); - break; - case FF_LOGO_TYPE_IMAGE_CHAFA: - yyjson_mut_obj_add_str(doc, obj, "type", "chafa"); - break; - case FF_LOGO_TYPE_IMAGE_RAW: - yyjson_mut_obj_add_str(doc, obj, "type", "raw"); - break; - default: - yyjson_mut_obj_add_str(doc, obj, "type", "auto"); - break; - } - } - - if (!ffStrbufEqual(&options->source, &defaultOptions.source)) - yyjson_mut_obj_add_str(doc, obj, "source", options->source.chars); - - { - yyjson_mut_val* color = yyjson_mut_arr(doc); - for (int i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++) - { - if (!ffStrbufEqual(&options->colors[i], &defaultOptions.colors[i])) - yyjson_mut_arr_add_strbuf(doc, color, &options->colors[i]); - } - if (yyjson_mut_arr_size(color) > 0) - yyjson_mut_obj_add_val(doc, obj, "color", color); - } - - if (options->width != defaultOptions.width) - yyjson_mut_obj_add_uint(doc, obj, "width", options->width); - - if (options->height != defaultOptions.height) - yyjson_mut_obj_add_uint(doc, obj, "height", options->height); - - { - yyjson_mut_val* padding = yyjson_mut_obj(doc); - if (options->paddingTop != defaultOptions.paddingTop) - yyjson_mut_obj_add_uint(doc, padding, "top", options->paddingTop); - if (options->paddingLeft != defaultOptions.paddingLeft) - yyjson_mut_obj_add_uint(doc, padding, "left", options->paddingLeft); - if (options->paddingRight != defaultOptions.paddingRight) - yyjson_mut_obj_add_uint(doc, padding, "right", options->paddingRight); - - if (yyjson_mut_obj_size(padding) > 0) - yyjson_mut_obj_add_val(doc, obj, "padding", padding); - } - - if (options->printRemaining != defaultOptions.printRemaining) - yyjson_mut_obj_add_bool(doc, obj, "printRemaining", options->printRemaining); - - if (options->preserveAspectRadio != defaultOptions.preserveAspectRadio) - yyjson_mut_obj_add_bool(doc, obj, "preserveAspectRadio", options->preserveAspectRadio); - - if (options->recache != defaultOptions.recache) - yyjson_mut_obj_add_bool(doc, obj, "recache", options->recache); - - if (options->separate != defaultOptions.separate) - yyjson_mut_obj_add_bool(doc, obj, "separate", options->separate); - - { - yyjson_mut_val* chafa = yyjson_mut_obj(doc); - if (options->chafaFgOnly != defaultOptions.chafaFgOnly) - yyjson_mut_obj_add_bool(doc, chafa, "fgOnly", options->chafaFgOnly); - if (!ffStrbufEqual(&options->chafaSymbols, &defaultOptions.chafaSymbols)) - yyjson_mut_obj_add_strbuf(doc, chafa, "symbols", &options->chafaSymbols); - if (options->chafaCanvasMode != defaultOptions.chafaCanvasMode && options->chafaCanvasMode <= 7) - { - yyjson_mut_obj_add_str(doc, chafa, "canvasMode", ((const char* []) { - "TRUECOLOR", - "INDEXED_256", - "INDEXED_240", - "INDEXED_16", - "FGBG_BGFG", - "FGBG", - "INDEXED_8", - "INDEXED_16_8", - })[options->chafaCanvasMode]); - } - if (options->chafaColorSpace != defaultOptions.chafaColorSpace && options->chafaColorSpace <= 1) - { - yyjson_mut_obj_add_str(doc, chafa, "colorSpace", ((const char* []) { - "RGB", - "DIN99D", - })[options->chafaColorSpace]); - } - if (options->chafaDitherMode != defaultOptions.chafaDitherMode && options->chafaDitherMode <= 2) - { - yyjson_mut_obj_add_str(doc, chafa, "ditherMode", ((const char* []) { - "NONE", - "ORDERED", - "DIFFUSION", - })[options->chafaDitherMode]); - } - - if (yyjson_mut_obj_size(chafa) > 0) - yyjson_mut_obj_add_val(doc, obj, "chafa", chafa); - } - - if (yyjson_mut_obj_size(obj) > 0) - yyjson_mut_obj_add_val(doc, doc->root, "logo", obj); -} diff --git a/src/logo/option.h b/src/logo/option.h deleted file mode 100644 index 9273e2a3f..000000000 --- a/src/logo/option.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include "util/FFstrbuf.h" - -#define FASTFETCH_LOGO_MAX_NAMES 9 -#define FASTFETCH_LOGO_MAX_COLORS 9 //two digits would make parsing much more complicated (index 1 - 9) - -typedef enum FFLogoType -{ - FF_LOGO_TYPE_AUTO, //if something is given, first try builtin, then file. Otherwise detect logo - FF_LOGO_TYPE_BUILTIN, //builtin ascii art - FF_LOGO_TYPE_SMALL, //builtin ascii art, small version - FF_LOGO_TYPE_FILE, //text file, printed with color code replacement - FF_LOGO_TYPE_FILE_RAW, //text file, printed as is - FF_LOGO_TYPE_DATA, //text data, printed with color code replacement - FF_LOGO_TYPE_DATA_RAW, //text data, printed as is - FF_LOGO_TYPE_IMAGE_SIXEL, //image file, printed as sixel codes. - FF_LOGO_TYPE_IMAGE_KITTY, //image file, printed as kitty graphics protocol - FF_LOGO_TYPE_IMAGE_KITTY_DIRECT, //image file, tell the terminal emulator to read image data from the specified file (Supported by kitty and wezterm) - FF_LOGO_TYPE_IMAGE_ITERM, //image file, printed as iterm graphics protocol - FF_LOGO_TYPE_IMAGE_CHAFA, //image file, printed as ascii art using libchafa - FF_LOGO_TYPE_IMAGE_RAW, //image file, printed as raw binary string - FF_LOGO_TYPE_NONE, //--logo none -} FFLogoType; - -typedef struct FFLogoOptions -{ - FFstrbuf source; - FFLogoType type; - FFstrbuf colors[FASTFETCH_LOGO_MAX_COLORS]; - uint32_t width; - uint32_t height; - uint32_t paddingTop; - uint32_t paddingLeft; - uint32_t paddingRight; - bool printRemaining; - bool preserveAspectRadio; - bool recache; - bool separate; - - bool chafaFgOnly; - FFstrbuf chafaSymbols; - uint32_t chafaCanvasMode; - uint32_t chafaColorSpace; - uint32_t chafaDitherMode; -} FFLogoOptions; diff --git a/src/options/general.c b/src/options/general.c new file mode 100644 index 000000000..ac5d4f451 --- /dev/null +++ b/src/options/general.c @@ -0,0 +1,98 @@ +#include "fastfetch.h" +#include "util/stringUtils.h" +#include "options/general.h" + +#include + +const char* ffParseGeneralJsonConfig(FFGeneralOptions* options, yyjson_val* root) +{ + yyjson_val* object = yyjson_obj_get(root, "general"); + if (!object) return NULL; + if (!yyjson_is_obj(object)) return "Property 'general' must be an object"; + + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(object, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + + if (ffStrEqualsIgnCase(key, "allowSlowOperations")) + options->allowSlowOperations = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "thread") || ffStrEqualsIgnCase(key, "multithreading")) + options->multithreading = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "processingTimeout")) + options->processingTimeout = (int32_t) yyjson_get_int(val); + + #if defined(__linux__) || defined(__FreeBSD__) + else if (ffStrEqualsIgnCase(key, "escapeBedrock")) + options->escapeBedrock = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "playerName")) + ffStrbufSetS(&options->playerName, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "osFile")) + ffStrbufSetS(&options->osFile, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "dsForceDrm")) + options->dsForceDrm = yyjson_get_bool(val); + #elif defined(_WIN32) + else if (ffStrEqualsIgnCase(key, "wmiTimeout")) + options->wmiTimeout = (int32_t) yyjson_get_int(val); + #endif + + else + return "Unknown general property"; + } + + return NULL; +} + +bool ffParseGeneralCommandOptions(FFGeneralOptions* options, const char* key, const char* value) +{ + if(ffStrEqualsIgnCase(key, "--allow-slow-operations")) + options->allowSlowOperations = ffOptionParseBoolean(value); + else if(ffStrEqualsIgnCase(key, "--thread") || ffStrEqualsIgnCase(key, "--multithreading")) + options->multithreading = ffOptionParseBoolean(value); + else if(ffStrEqualsIgnCase(key, "--processing-timeout")) + options->processingTimeout = ffOptionParseInt32(key, value); + + #if defined(__linux__) || defined(__FreeBSD__) + else if(ffStrEqualsIgnCase(key, "--escape-bedrock")) + options->escapeBedrock = ffOptionParseBoolean(value); + else if(ffStrEqualsIgnCase(key, "--player-name")) + ffOptionParseString(key, value, &options->playerName); + else if (ffStrEqualsIgnCase(key, "--os-file")) + ffOptionParseString(key, value, &options->osFile); + else if(ffStrEqualsIgnCase(key, "--ds-force-drm")) + options->dsForceDrm = ffOptionParseBoolean(value); + #elif defined(_WIN32) + else if (ffStrEqualsIgnCase(key, "--wmi-timeout")) + options->wmiTimeout = ffOptionParseInt32(key, value); + #endif + + else + return false; + + return true; +} + +void ffInitGeneralOptions(FFGeneralOptions* options) +{ + options->processingTimeout = 1000; + options->allowSlowOperations = false; + options->multithreading = true; + + #if defined(__linux__) || defined(__FreeBSD__) + options->escapeBedrock = true; + ffStrbufInit(&options->playerName); + ffStrbufInit(&options->osFile); + options->dsForceDrm = false; + #elif defined(_WIN32) + options->wmiTimeout = 5000; + #endif +} + +void ffDestroyGeneralOptions(FF_MAYBE_UNUSED FFGeneralOptions* options) +{ + #if defined(__linux__) || defined(__FreeBSD__) + ffStrbufDestroy(&options->playerName); + ffStrbufDestroy(&options->osFile); + #endif +} diff --git a/src/options/general.h b/src/options/general.h new file mode 100644 index 000000000..d84e55bad --- /dev/null +++ b/src/options/general.h @@ -0,0 +1,25 @@ +#pragma once + +#include "util/FFstrbuf.h" + +typedef struct FFGeneralOptions +{ + bool allowSlowOperations; + bool multithreading; + int32_t processingTimeout; + + // Module options that cannot be put in module option structure + #if defined(__linux__) || defined(__FreeBSD__) + FFstrbuf playerName; + FFstrbuf osFile; + bool escapeBedrock; + bool dsForceDrm; + #elif defined(_WIN32) + int32_t wmiTimeout; + #endif +} FFGeneralOptions; + +const char* ffParseGeneralJsonConfig(FFGeneralOptions* options, yyjson_val* root); +bool ffParseGeneralCommandOptions(FFGeneralOptions* options, const char* key, const char* value); +void ffInitGeneralOptions(FFGeneralOptions* options); +void ffDestroyGeneralOptions(FFGeneralOptions* options); diff --git a/src/options/logo.c b/src/options/logo.c index 3bd9ebccb..12854b662 100644 --- a/src/options/logo.c +++ b/src/options/logo.c @@ -211,14 +211,8 @@ void ffDestroyLogoOptions(FFLogoOptions* options) ffStrbufDestroy(&options->colors[i]); } -const char* ffParseLogoJsonConfig(FFLogoOptions* options) +const char* ffParseLogoJsonConfig(FFLogoOptions* options, yyjson_val* root) { - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); - assert(root); - - if (!yyjson_is_obj(root)) - return "Invalid JSON config format. Root value must be an object"; - yyjson_val* object = yyjson_obj_get(root, "logo"); if (!object) return NULL; if (yyjson_is_null(object)) diff --git a/src/options/logo.h b/src/options/logo.h index 98d0d4bb8..5bc0ef614 100644 --- a/src/options/logo.h +++ b/src/options/logo.h @@ -48,5 +48,5 @@ typedef struct FFLogoOptions void ffInitLogoOptions(FFLogoOptions* options); bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value); void ffDestroyLogoOptions(FFLogoOptions* options); -const char* ffParseLogoJsonConfig(FFLogoOptions* options); +const char* ffParseLogoJsonConfig(FFLogoOptions* options, yyjson_val* root); void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc); diff --git a/src/util/windows/wmi.hpp b/src/util/windows/wmi.hpp index f9719a664..5e8d57a32 100644 --- a/src/util/windows/wmi.hpp +++ b/src/util/windows/wmi.hpp @@ -162,7 +162,7 @@ struct FFWmiRecord if(!pEnumerator) return; ULONG ret; - bool ok = SUCCEEDED(pEnumerator->Next(instance.config.wmiTimeout, 1, &obj, &ret)) && ret; + bool ok = SUCCEEDED(pEnumerator->Next(instance.config.general.wmiTimeout, 1, &obj, &ret)) && ret; if(!ok) obj = nullptr; } FFWmiRecord(const FFWmiRecord&) = delete; From 8a939e981c0ed0c72b64f3ba81790140daedc2e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 25 Oct 2023 14:37:48 +0800 Subject: [PATCH 030/100] Options (General): symbol renaming to prevent from possible naming conflicts --- src/common/init.c | 2 +- src/fastfetch.c | 4 ++-- src/fastfetch.h | 2 +- src/options/general.c | 8 ++++---- src/options/general.h | 12 ++++++------ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/common/init.c b/src/common/init.c index 84efec1db..9d375993f 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -33,7 +33,7 @@ static void initState(FFstate* state) static void defaultConfig(void) { ffInitLogoOptions(&instance.config.logo); - ffInitGeneralOptions(&instance.config.general); + ffOptionsInitGeneral(&instance.config.general); ffStrbufInit(&instance.config.colorKeys); ffStrbufInit(&instance.config.colorTitle); diff --git a/src/fastfetch.c b/src/fastfetch.c index 5a34305eb..c396d27c3 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -532,7 +532,7 @@ static void parseOption(FFdata* data, const char* key, const char* value) //General options// /////////////////// - else if(ffParseGeneralCommandOptions(&instance.config.general, key, value)) {} + else if(ffOptionsParseGeneralCommandLine(&instance.config.general, key, value)) {} //////////////// //Logo options// @@ -794,7 +794,7 @@ static void run(FFdata* data) if ( error || (error = ffParseLogoJsonConfig(&instance.config.logo, root)) || - (error = ffParseGeneralJsonConfig(&instance.config.general, root)) || + (error = ffOptionsParseGeneralJsonConfig(&instance.config.general, root)) || (error = ffParseDisplayJsonConfig(&instance.config)) || (error = ffParseLibraryJsonConfig(&instance.config)) || false diff --git a/src/fastfetch.h b/src/fastfetch.h index eaef3b803..701f9fe01 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -44,7 +44,7 @@ typedef enum FFTemperatureUnit typedef struct FFconfig { FFLogoOptions logo; - FFGeneralOptions general; + FFOptionsGeneral general; //If one of those is empty, ffLogoPrint will set them FFstrbuf colorKeys; diff --git a/src/options/general.c b/src/options/general.c index ac5d4f451..459db3eda 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -4,7 +4,7 @@ #include -const char* ffParseGeneralJsonConfig(FFGeneralOptions* options, yyjson_val* root) +const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_val* root) { yyjson_val* object = yyjson_obj_get(root, "general"); if (!object) return NULL; @@ -44,7 +44,7 @@ const char* ffParseGeneralJsonConfig(FFGeneralOptions* options, yyjson_val* root return NULL; } -bool ffParseGeneralCommandOptions(FFGeneralOptions* options, const char* key, const char* value) +bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key, const char* value) { if(ffStrEqualsIgnCase(key, "--allow-slow-operations")) options->allowSlowOperations = ffOptionParseBoolean(value); @@ -73,7 +73,7 @@ bool ffParseGeneralCommandOptions(FFGeneralOptions* options, const char* key, co return true; } -void ffInitGeneralOptions(FFGeneralOptions* options) +void ffOptionsInitGeneral(FFOptionsGeneral* options) { options->processingTimeout = 1000; options->allowSlowOperations = false; @@ -89,7 +89,7 @@ void ffInitGeneralOptions(FFGeneralOptions* options) #endif } -void ffDestroyGeneralOptions(FF_MAYBE_UNUSED FFGeneralOptions* options) +void ffOptionsDestroyGeneral(FF_MAYBE_UNUSED FFOptionsGeneral* options) { #if defined(__linux__) || defined(__FreeBSD__) ffStrbufDestroy(&options->playerName); diff --git a/src/options/general.h b/src/options/general.h index d84e55bad..d9e976245 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -2,7 +2,7 @@ #include "util/FFstrbuf.h" -typedef struct FFGeneralOptions +typedef struct FFOptionsGeneral { bool allowSlowOperations; bool multithreading; @@ -17,9 +17,9 @@ typedef struct FFGeneralOptions #elif defined(_WIN32) int32_t wmiTimeout; #endif -} FFGeneralOptions; +} FFOptionsGeneral; -const char* ffParseGeneralJsonConfig(FFGeneralOptions* options, yyjson_val* root); -bool ffParseGeneralCommandOptions(FFGeneralOptions* options, const char* key, const char* value); -void ffInitGeneralOptions(FFGeneralOptions* options); -void ffDestroyGeneralOptions(FFGeneralOptions* options); +const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_val* root); +bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key, const char* value); +void ffOptionsInitGeneral(FFOptionsGeneral* options); +void ffOptionsDestroyGeneral(FFOptionsGeneral* options); From ca37206a49fca670098965cda5c37d23df4ad460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 25 Oct 2023 14:43:46 +0800 Subject: [PATCH 031/100] Options (Logo): renaming symbols --- src/common/init.c | 5 +++-- src/fastfetch.c | 6 +++--- src/fastfetch.h | 2 +- src/logo/image/image.c | 6 +++--- src/logo/logo.c | 18 +++++++++--------- src/options/logo.c | 14 +++++++------- src/options/logo.h | 14 +++++++------- 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/common/init.c b/src/common/init.c index 9d375993f..e6ddba717 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -32,7 +32,7 @@ static void initState(FFstate* state) static void defaultConfig(void) { - ffInitLogoOptions(&instance.config.logo); + ffOptionsInitLogo(&instance.config.logo); ffOptionsInitGeneral(&instance.config.general); ffStrbufInit(&instance.config.colorKeys); @@ -268,7 +268,8 @@ void ffFinish(void) static void destroyConfig(void) { - ffDestroyLogoOptions(&instance.config.logo); + ffOptionsDestroyLogo(&instance.config.logo); + ffOptionsDestroyGeneral(&instance.config.general); ffStrbufDestroy(&instance.config.colorKeys); ffStrbufDestroy(&instance.config.colorTitle); diff --git a/src/fastfetch.c b/src/fastfetch.c index c396d27c3..548eb382f 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -538,7 +538,7 @@ static void parseOption(FFdata* data, const char* key, const char* value) //Logo options// //////////////// - else if(ffParseLogoCommandOptions(&instance.config.logo, key, value)) {} + else if(ffOptionsParseLogoCommandLine(&instance.config.logo, key, value)) {} /////////////////// //Display options// @@ -793,7 +793,7 @@ static void run(FFdata* data) if ( error || - (error = ffParseLogoJsonConfig(&instance.config.logo, root)) || + (error = ffOptionsParseLogoJsonConfig(&instance.config.logo, root)) || (error = ffOptionsParseGeneralJsonConfig(&instance.config.general, root)) || (error = ffParseDisplayJsonConfig(&instance.config)) || (error = ffParseLibraryJsonConfig(&instance.config)) || @@ -830,7 +830,7 @@ static void run(FFdata* data) static void migrateConfig(FFdata* data) { - ffGenerateLogoJsonConfig(&instance.config.logo, instance.state.migrateConfigDoc); + ffOptionsGenerateLogoJsonConfig(&instance.config.logo, instance.state.migrateConfigDoc); ffMigrateCommandOptionToJsonc(data); } diff --git a/src/fastfetch.h b/src/fastfetch.h index 701f9fe01..f741bf2fd 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -43,7 +43,7 @@ typedef enum FFTemperatureUnit typedef struct FFconfig { - FFLogoOptions logo; + FFOptionsLogo logo; FFOptionsGeneral general; //If one of those is empty, ffLogoPrint will set them diff --git a/src/logo/image/image.c b/src/logo/image/image.c index 953d12f8d..8756fcca9 100644 --- a/src/logo/image/image.c +++ b/src/logo/image/image.c @@ -37,7 +37,7 @@ static FFstrbuf base64Encode(const FFstrbuf* in) static bool printImageIterm(void) { - const FFLogoOptions* options = &instance.config.logo; + const FFOptionsLogo* options = &instance.config.logo; FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate(); if(!ffAppendFileBuffer(options->source.chars, &buf)) { @@ -118,7 +118,7 @@ static bool printImageIterm(void) static bool printImageKittyDirect(void) { - const FFLogoOptions* options = &instance.config.logo; + const FFOptionsLogo* options = &instance.config.logo; FF_STRBUF_AUTO_DESTROY base64 = base64Encode(&options->source); if (!options->width || !options->height) @@ -296,7 +296,7 @@ static void writeCacheUint32(FFLogoRequestData* requestData, uint32_t value, con static void printImagePixels(FFLogoRequestData* requestData, const FFstrbuf* result, const char* cacheFileName) { - const FFLogoOptions* options = &instance.config.logo; + const FFOptionsLogo* options = &instance.config.logo; //Calculate character dimensions instance.state.logoWidth = requestData->logoCharacterWidth + options->paddingLeft + options->paddingRight; instance.state.logoHeight = requestData->logoCharacterHeight + options->paddingTop - 1; diff --git a/src/logo/logo.c b/src/logo/logo.c index e03ba7221..582343fb7 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -18,7 +18,7 @@ typedef enum FFLogoSize static void ffLogoPrintCharsRaw(const char* data, size_t length) { - FFLogoOptions* options = &instance.config.logo; + FFOptionsLogo* options = &instance.config.logo; FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate(); if (!options->width || !options->height) @@ -55,7 +55,7 @@ static void ffLogoPrintCharsRaw(const char* data, size_t length) void ffLogoPrintChars(const char* data, bool doColorReplacement) { - FFLogoOptions* options = &instance.config.logo; + FFOptionsLogo* options = &instance.config.logo; uint32_t currentlineLength = 0; @@ -301,7 +301,7 @@ static void logoPrintStruct(const FFlogo* logo) { logoApplyColors(logo); - FFLogoOptions* options = &instance.config.logo; + FFOptionsLogo* options = &instance.config.logo; const char* const* colors = logo->colors; for(int i = 0; *colors != NULL && i < FASTFETCH_LOGO_MAX_COLORS; i++, colors++) @@ -344,7 +344,7 @@ static inline void logoPrintDetected(FFLogoSize size) static bool logoPrintData(bool doColorReplacement) { - FFLogoOptions* options = &instance.config.logo; + FFOptionsLogo* options = &instance.config.logo; if(options->source.length == 0) return false; @@ -355,7 +355,7 @@ static bool logoPrintData(bool doColorReplacement) static void updateLogoPath(void) { - FFLogoOptions* options = &instance.config.logo; + FFOptionsLogo* options = &instance.config.logo; if(ffPathExists(options->source.chars, FF_PATHTYPE_FILE)) return; @@ -384,7 +384,7 @@ static void updateLogoPath(void) static bool logoPrintFileIfExists(bool doColorReplacement, bool raw) { - FFLogoOptions* options = &instance.config.logo; + FFOptionsLogo* options = &instance.config.logo; FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate(); @@ -417,7 +417,7 @@ static bool logoPrintImageIfExists(FFLogoType logo, bool printError) static bool logoTryKnownType(void) { - FFLogoOptions* options = &instance.config.logo; + FFOptionsLogo* options = &instance.config.logo; if(options->type == FF_LOGO_TYPE_NONE) { @@ -469,7 +469,7 @@ void ffLogoPrint(void) return; } - const FFLogoOptions* options = &instance.config.logo; + const FFOptionsLogo* options = &instance.config.logo; if (options->type == FF_LOGO_TYPE_NONE) { @@ -535,7 +535,7 @@ void ffLogoPrintRemaining(void) void ffLogoBuiltinPrint(void) { - FFLogoOptions* options = &instance.config.logo; + FFOptionsLogo* options = &instance.config.logo; for(uint8_t ch = 0; ch < 26; ++ch) { diff --git a/src/options/logo.c b/src/options/logo.c index 12854b662..ae3210768 100644 --- a/src/options/logo.c +++ b/src/options/logo.c @@ -3,7 +3,7 @@ #include "common/jsonconfig.h" #include "util/stringUtils.h" -void ffInitLogoOptions(FFLogoOptions* options) +void ffOptionsInitLogo(FFOptionsLogo* options) { ffStrbufInit(&options->source); options->type = FF_LOGO_TYPE_AUTO; @@ -26,7 +26,7 @@ void ffInitLogoOptions(FFLogoOptions* options) options->chafaDitherMode = UINT32_MAX; } -bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value) +bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, const char* value) { if (strcasecmp(key, "-l") == 0) goto logoType; @@ -203,7 +203,7 @@ logoType: return true; } -void ffDestroyLogoOptions(FFLogoOptions* options) +void ffOptionsDestroyLogo(FFOptionsLogo* options) { ffStrbufDestroy(&options->source); ffStrbufDestroy(&options->chafaSymbols); @@ -211,7 +211,7 @@ void ffDestroyLogoOptions(FFLogoOptions* options) ffStrbufDestroy(&options->colors[i]); } -const char* ffParseLogoJsonConfig(FFLogoOptions* options, yyjson_val* root) +const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* root) { yyjson_val* object = yyjson_obj_get(root, "logo"); if (!object) return NULL; @@ -412,10 +412,10 @@ const char* ffParseLogoJsonConfig(FFLogoOptions* options, yyjson_val* root) return NULL; } -void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc) +void ffOptionsGenerateLogoJsonConfig(FFOptionsLogo* options, yyjson_mut_doc* doc) { - __attribute__((__cleanup__(ffDestroyLogoOptions))) FFLogoOptions defaultOptions; - ffInitLogoOptions(&defaultOptions); + __attribute__((__cleanup__(ffOptionsDestroyLogo))) FFOptionsLogo defaultOptions; + ffOptionsInitLogo(&defaultOptions); yyjson_mut_val* obj = yyjson_mut_obj(doc); diff --git a/src/options/logo.h b/src/options/logo.h index 5bc0ef614..dd370471e 100644 --- a/src/options/logo.h +++ b/src/options/logo.h @@ -23,7 +23,7 @@ typedef enum FFLogoType FF_LOGO_TYPE_NONE, //--logo none } FFLogoType; -typedef struct FFLogoOptions +typedef struct FFOptionsLogo { FFstrbuf source; FFLogoType type; @@ -43,10 +43,10 @@ typedef struct FFLogoOptions uint32_t chafaCanvasMode; uint32_t chafaColorSpace; uint32_t chafaDitherMode; -} FFLogoOptions; +} FFOptionsLogo; -void ffInitLogoOptions(FFLogoOptions* options); -bool ffParseLogoCommandOptions(FFLogoOptions* options, const char* key, const char* value); -void ffDestroyLogoOptions(FFLogoOptions* options); -const char* ffParseLogoJsonConfig(FFLogoOptions* options, yyjson_val* root); -void ffGenerateLogoJsonConfig(FFLogoOptions* options, yyjson_mut_doc* doc); +void ffOptionsInitLogo(FFOptionsLogo* options); +bool ffOptionsParseLogoCommandLine(FFOptionsLogo* options, const char* key, const char* value); +void ffOptionsDestroyLogo(FFOptionsLogo* options); +const char* ffOptionsParseLogoJsonConfig(FFOptionsLogo* options, yyjson_val* root); +void ffOptionsGenerateLogoJsonConfig(FFOptionsLogo* options, yyjson_mut_doc* doc); From 3c5b0024141d20beb9f5296311991f9194c6268a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 25 Oct 2023 15:38:46 +0800 Subject: [PATCH 032/100] Options (Modules): split code --- CMakeLists.txt | 1 + src/common/commandoption.c | 9 ++- src/common/init.c | 120 +---------------------------- src/common/jsonconfig.c | 16 ++-- src/common/modules.c | 114 +++++++++++++-------------- src/fastfetch.h | 61 +-------------- src/flashfetch.c | 101 ++++++++++++------------ src/modules/separator/separator.c | 2 +- src/options/modules.c | 124 ++++++++++++++++++++++++++++++ src/options/modules.h | 67 ++++++++++++++++ 10 files changed, 318 insertions(+), 297 deletions(-) create mode 100644 src/options/modules.c create mode 100644 src/options/modules.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 243172947..c48b06813 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,6 +354,7 @@ set(LIBFASTFETCH_SRC src/modules/wifi/wifi.c src/modules/wm/wm.c src/modules/wmtheme/wmtheme.c + src/options/modules.c src/options/logo.c src/options/general.c src/util/edidHelper.c diff --git a/src/common/commandoption.c b/src/common/commandoption.c index ab3ac56da..507393dc3 100644 --- a/src/common/commandoption.c +++ b/src/common/commandoption.c @@ -74,6 +74,7 @@ bool ffParseModuleOptions(const char* key, const char* value) void ffPrepareCommandOption(FFdata* data) { + FFOptionsModules* const options = &instance.config.modules; //If we don't have a custom structure, use the default one if(data->structure.length == 0) ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); @@ -82,18 +83,18 @@ void ffPrepareCommandOption(FFdata* data) ffPrepareCPUUsage(); if(ffStrbufContainIgnCaseS(&data->structure, FF_DISKIO_MODULE_NAME)) - ffPrepareDiskIO(&instance.config.diskIo); + ffPrepareDiskIO(&options->diskIo); if(ffStrbufContainIgnCaseS(&data->structure, FF_NETIO_MODULE_NAME)) - ffPrepareNetIO(&instance.config.netIo); + ffPrepareNetIO(&options->netIo); if(instance.config.general.multithreading) { if(ffStrbufContainIgnCaseS(&data->structure, FF_PUBLICIP_MODULE_NAME)) - ffPreparePublicIp(&instance.config.publicIP); + ffPreparePublicIp(&options->publicIP); if(ffStrbufContainIgnCaseS(&data->structure, FF_WEATHER_MODULE_NAME)) - ffPrepareWeather(&instance.config.weather); + ffPrepareWeather(&options->weather); } } diff --git a/src/common/init.c b/src/common/init.c index e6ddba717..25e01d748 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -15,8 +15,6 @@ #include #endif -#include "modules/modules.h" - FFinstance instance; // Global singleton static void initState(FFstate* state) @@ -34,6 +32,7 @@ static void defaultConfig(void) { ffOptionsInitLogo(&instance.config.logo); ffOptionsInitGeneral(&instance.config.general); + ffOptionsInitModules(&instance.config.modules); ffStrbufInit(&instance.config.colorKeys); ffStrbufInit(&instance.config.colorTitle); @@ -66,64 +65,6 @@ static void defaultConfig(void) instance.config.percentType = 1; instance.config.percentNdigits = 0; - ffInitBatteryOptions(&instance.config.battery); - ffInitBiosOptions(&instance.config.bios); - ffInitBluetoothOptions(&instance.config.bluetooth); - ffInitBoardOptions(&instance.config.board); - ffInitBreakOptions(&instance.config.break_); - ffInitBrightnessOptions(&instance.config.brightness); - ffInitCPUOptions(&instance.config.cpu); - ffInitCPUUsageOptions(&instance.config.cpuUsage); - ffInitChassisOptions(&instance.config.chassis); - ffInitColorsOptions(&instance.config.colors); - ffInitCommandOptions(&instance.config.command); - ffInitCursorOptions(&instance.config.cursor); - ffInitCustomOptions(&instance.config.custom); - ffInitDEOptions(&instance.config.de); - ffInitDateTimeOptions(&instance.config.dateTime); - ffInitDiskOptions(&instance.config.disk); - ffInitDiskIOOptions(&instance.config.diskIo); - ffInitDisplayOptions(&instance.config.display); - ffInitFontOptions(&instance.config.font); - ffInitGPUOptions(&instance.config.gpu); - ffInitGamepadOptions(&instance.config.gamepad); - ffInitHostOptions(&instance.config.host); - ffInitIconsOptions(&instance.config.icons); - ffInitKernelOptions(&instance.config.kernel); - ffInitLMOptions(&instance.config.lm); - ffInitLocalIpOptions(&instance.config.localIP); - ffInitLocaleOptions(&instance.config.locale); - ffInitMediaOptions(&instance.config.media); - ffInitMemoryOptions(&instance.config.memory); - ffInitMonitorOptions(&instance.config.monitor); - ffInitNetIOOptions(&instance.config.netIo); - ffInitOSOptions(&instance.config.os); - ffInitOpenCLOptions(&instance.config.openCL); - ffInitOpenGLOptions(&instance.config.openGL); - ffInitPackagesOptions(&instance.config.packages); - ffInitPlayerOptions(&instance.config.player); - ffInitPowerAdapterOptions(&instance.config.powerAdapter); - ffInitProcessesOptions(&instance.config.processes); - ffInitPublicIpOptions(&instance.config.publicIP); - ffInitSeparatorOptions(&instance.config.separator); - ffInitShellOptions(&instance.config.shell); - ffInitSoundOptions(&instance.config.sound); - ffInitSwapOptions(&instance.config.swap); - ffInitTerminalFontOptions(&instance.config.terminalFont); - ffInitTerminalOptions(&instance.config.terminal); - ffInitTerminalSizeOptions(&instance.config.terminalSize); - ffInitThemeOptions(&instance.config.theme); - ffInitTitleOptions(&instance.config.title); - ffInitUptimeOptions(&instance.config.uptime); - ffInitUsersOptions(&instance.config.users); - ffInitVersionOptions(&instance.config.version); - ffInitVulkanOptions(&instance.config.vulkan); - ffInitWMOptions(&instance.config.wm); - ffInitWMThemeOptions(&instance.config.wmTheme); - ffInitWallpaperOptions(&instance.config.wallpaper); - ffInitWeatherOptions(&instance.config.weather); - ffInitWifiOptions(&instance.config.wifi); - ffStrbufInit(&instance.config.libPCI); ffStrbufInit(&instance.config.libVulkan); ffStrbufInit(&instance.config.libWayland); @@ -270,6 +211,7 @@ static void destroyConfig(void) { ffOptionsDestroyLogo(&instance.config.logo); ffOptionsDestroyGeneral(&instance.config.general); + ffOptionsDestroyModules(&instance.config.modules); ffStrbufDestroy(&instance.config.colorKeys); ffStrbufDestroy(&instance.config.colorTitle); @@ -277,64 +219,6 @@ static void destroyConfig(void) ffStrbufDestroy(&instance.config.barCharElapsed); ffStrbufDestroy(&instance.config.barCharTotal); - ffDestroyBatteryOptions(&instance.config.battery); - ffDestroyBiosOptions(&instance.config.bios); - ffDestroyBluetoothOptions(&instance.config.bluetooth); - ffDestroyBoardOptions(&instance.config.board); - ffDestroyBreakOptions(&instance.config.break_); - ffDestroyBrightnessOptions(&instance.config.brightness); - ffDestroyCPUOptions(&instance.config.cpu); - ffDestroyCPUUsageOptions(&instance.config.cpuUsage); - ffDestroyChassisOptions(&instance.config.chassis); - ffDestroyColorsOptions(&instance.config.colors); - ffDestroyCommandOptions(&instance.config.command); - ffDestroyCursorOptions(&instance.config.cursor); - ffDestroyCustomOptions(&instance.config.custom); - ffDestroyDEOptions(&instance.config.de); - ffDestroyDateTimeOptions(&instance.config.dateTime); - ffDestroyDiskOptions(&instance.config.disk); - ffDestroyDiskIOOptions(&instance.config.diskIo); - ffDestroyDisplayOptions(&instance.config.display); - ffDestroyFontOptions(&instance.config.font); - ffDestroyGPUOptions(&instance.config.gpu); - ffDestroyGamepadOptions(&instance.config.gamepad); - ffDestroyHostOptions(&instance.config.host); - ffDestroyIconsOptions(&instance.config.icons); - ffDestroyKernelOptions(&instance.config.kernel); - ffDestroyLMOptions(&instance.config.lm); - ffDestroyLocalIpOptions(&instance.config.localIP); - ffDestroyLocaleOptions(&instance.config.locale); - ffDestroyMediaOptions(&instance.config.media); - ffDestroyMemoryOptions(&instance.config.memory); - ffDestroyMonitorOptions(&instance.config.monitor); - ffDestroyNetIOOptions(&instance.config.netIo); - ffDestroyOSOptions(&instance.config.os); - ffDestroyOpenCLOptions(&instance.config.openCL); - ffDestroyOpenGLOptions(&instance.config.openGL); - ffDestroyPackagesOptions(&instance.config.packages); - ffDestroyPlayerOptions(&instance.config.player); - ffDestroyPowerAdapterOptions(&instance.config.powerAdapter); - ffDestroyProcessesOptions(&instance.config.processes); - ffDestroyPublicIpOptions(&instance.config.publicIP); - ffDestroySeparatorOptions(&instance.config.separator); - ffDestroyShellOptions(&instance.config.shell); - ffDestroySoundOptions(&instance.config.sound); - ffDestroySwapOptions(&instance.config.swap); - ffDestroyTerminalFontOptions(&instance.config.terminalFont); - ffDestroyTerminalOptions(&instance.config.terminal); - ffDestroyTerminalSizeOptions(&instance.config.terminalSize); - ffDestroyThemeOptions(&instance.config.theme); - ffDestroyTitleOptions(&instance.config.title); - ffDestroyUptimeOptions(&instance.config.uptime); - ffDestroyUsersOptions(&instance.config.users); - ffDestroyVersionOptions(&instance.config.version); - ffDestroyVulkanOptions(&instance.config.vulkan); - ffDestroyWMOptions(&instance.config.wm); - ffDestroyWMThemeOptions(&instance.config.wmTheme); - ffDestroyWallpaperOptions(&instance.config.wallpaper); - ffDestroyWeatherOptions(&instance.config.weather); - ffDestroyWifiOptions(&instance.config.wifi); - ffStrbufDestroy(&instance.config.libPCI); ffStrbufDestroy(&instance.config.libVulkan); ffStrbufDestroy(&instance.config.libWayland); diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index f3f240fef..384751370 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -127,32 +127,32 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) case 'd': case 'D': { if (ffStrEqualsIgnCase(type, FF_DISKIO_MODULE_NAME)) { - if (module) cfg->diskIo.moduleInfo.parseJsonObject(&cfg->diskIo, module); - ffPrepareDiskIO(&cfg->diskIo); + if (module) cfg->modules.diskIo.moduleInfo.parseJsonObject(&cfg->modules.diskIo, module); + ffPrepareDiskIO(&cfg->modules.diskIo); } break; } case 'n': case 'N': { if (ffStrEqualsIgnCase(type, FF_NETIO_MODULE_NAME)) { - if (module) cfg->netIo.moduleInfo.parseJsonObject(&cfg->netIo, module); - ffPrepareNetIO(&cfg->netIo); + if (module) cfg->modules.netIo.moduleInfo.parseJsonObject(&cfg->modules.netIo, module); + ffPrepareNetIO(&cfg->modules.netIo); } break; } case 'p': case 'P': { if (ffStrEqualsIgnCase(type, FF_PUBLICIP_MODULE_NAME)) { - if (module) cfg->publicIP.moduleInfo.parseJsonObject(&cfg->publicIP, module); - ffPreparePublicIp(&cfg->publicIP); + if (module) cfg->modules.publicIP.moduleInfo.parseJsonObject(&cfg->modules.publicIP, module); + ffPreparePublicIp(&cfg->modules.publicIP); } break; } case 'w': case 'W': { if (ffStrEqualsIgnCase(type, FF_WEATHER_MODULE_NAME)) { - if (module) cfg->weather.moduleInfo.parseJsonObject(&cfg->weather, module); - ffPrepareWeather(&cfg->weather); + if (module) cfg->modules.weather.moduleInfo.parseJsonObject(&cfg->modules.weather, module); + ffPrepareWeather(&cfg->modules.weather); } break; } diff --git a/src/common/modules.c b/src/common/modules.c index 216470144..a065bc625 100644 --- a/src/common/modules.c +++ b/src/common/modules.c @@ -5,32 +5,32 @@ static FFModuleBaseInfo* A[] = { }; static FFModuleBaseInfo* B[] = { - (void*) &instance.config.battery, - (void*) &instance.config.bios, - (void*) &instance.config.bluetooth, - (void*) &instance.config.board, - (void*) &instance.config.break_, - (void*) &instance.config.brightness, + (void*) &instance.config.modules.battery, + (void*) &instance.config.modules.bios, + (void*) &instance.config.modules.bluetooth, + (void*) &instance.config.modules.board, + (void*) &instance.config.modules.break_, + (void*) &instance.config.modules.brightness, NULL, }; static FFModuleBaseInfo* C[] = { - (void*) &instance.config.chassis, - (void*) &instance.config.command, - (void*) &instance.config.colors, - (void*) &instance.config.cpu, - (void*) &instance.config.cpuUsage, - (void*) &instance.config.cursor, - (void*) &instance.config.custom, + (void*) &instance.config.modules.chassis, + (void*) &instance.config.modules.command, + (void*) &instance.config.modules.colors, + (void*) &instance.config.modules.cpu, + (void*) &instance.config.modules.cpuUsage, + (void*) &instance.config.modules.cursor, + (void*) &instance.config.modules.custom, NULL, }; static FFModuleBaseInfo* D[] = { - (void*) &instance.config.dateTime, - (void*) &instance.config.de, - (void*) &instance.config.display, - (void*) &instance.config.disk, - (void*) &instance.config.diskIo, + (void*) &instance.config.modules.dateTime, + (void*) &instance.config.modules.de, + (void*) &instance.config.modules.display, + (void*) &instance.config.modules.disk, + (void*) &instance.config.modules.diskIo, NULL, }; @@ -39,23 +39,23 @@ static FFModuleBaseInfo* E[] = { }; static FFModuleBaseInfo* F[] = { - (void*) &instance.config.font, + (void*) &instance.config.modules.font, NULL, }; static FFModuleBaseInfo* G[] = { - (void*) &instance.config.gamepad, - (void*) &instance.config.gpu, + (void*) &instance.config.modules.gamepad, + (void*) &instance.config.modules.gpu, NULL, }; static FFModuleBaseInfo* H[] = { - (void*) &instance.config.host, + (void*) &instance.config.modules.host, NULL, }; static FFModuleBaseInfo* I[] = { - (void*) &instance.config.icons, + (void*) &instance.config.modules.icons, NULL, }; @@ -64,42 +64,42 @@ static FFModuleBaseInfo* J[] = { }; static FFModuleBaseInfo* K[] = { - (void*) &instance.config.kernel, + (void*) &instance.config.modules.kernel, NULL, }; static FFModuleBaseInfo* L[] = { - (void*) &instance.config.lm, - (void*) &instance.config.locale, - (void*) &instance.config.localIP, + (void*) &instance.config.modules.lm, + (void*) &instance.config.modules.locale, + (void*) &instance.config.modules.localIP, NULL, }; static FFModuleBaseInfo* M[] = { - (void*) &instance.config.media, - (void*) &instance.config.memory, - (void*) &instance.config.monitor, + (void*) &instance.config.modules.media, + (void*) &instance.config.modules.memory, + (void*) &instance.config.modules.monitor, NULL, }; static FFModuleBaseInfo* N[] = { - (void*) &instance.config.netIo, + (void*) &instance.config.modules.netIo, NULL, }; static FFModuleBaseInfo* O[] = { - (void*) &instance.config.openCL, - (void*) &instance.config.openGL, - (void*) &instance.config.os, + (void*) &instance.config.modules.openCL, + (void*) &instance.config.modules.openGL, + (void*) &instance.config.modules.os, NULL, }; static FFModuleBaseInfo* P[] = { - (void*) &instance.config.packages, - (void*) &instance.config.player, - (void*) &instance.config.powerAdapter, - (void*) &instance.config.processes, - (void*) &instance.config.publicIP, + (void*) &instance.config.modules.packages, + (void*) &instance.config.modules.player, + (void*) &instance.config.modules.powerAdapter, + (void*) &instance.config.modules.processes, + (void*) &instance.config.modules.publicIP, NULL, }; @@ -112,40 +112,40 @@ static FFModuleBaseInfo* R[] = { }; static FFModuleBaseInfo* S[] = { - (void*) &instance.config.separator, - (void*) &instance.config.shell, - (void*) &instance.config.sound, - (void*) &instance.config.swap, + (void*) &instance.config.modules.separator, + (void*) &instance.config.modules.shell, + (void*) &instance.config.modules.sound, + (void*) &instance.config.modules.swap, NULL, }; static FFModuleBaseInfo* T[] = { - (void*) &instance.config.terminal, - (void*) &instance.config.terminalFont, - (void*) &instance.config.terminalSize, - (void*) &instance.config.title, - (void*) &instance.config.theme, + (void*) &instance.config.modules.terminal, + (void*) &instance.config.modules.terminalFont, + (void*) &instance.config.modules.terminalSize, + (void*) &instance.config.modules.title, + (void*) &instance.config.modules.theme, NULL, }; static FFModuleBaseInfo* U[] = { - (void*) &instance.config.uptime, - (void*) &instance.config.users, + (void*) &instance.config.modules.uptime, + (void*) &instance.config.modules.users, NULL, }; static FFModuleBaseInfo* V[] = { - (void*) &instance.config.version, - (void*) &instance.config.vulkan, + (void*) &instance.config.modules.version, + (void*) &instance.config.modules.vulkan, NULL, }; static FFModuleBaseInfo* W[] = { - (void*) &instance.config.wallpaper, - (void*) &instance.config.weather, - (void*) &instance.config.wm, - (void*) &instance.config.wifi, - (void*) &instance.config.wmTheme, + (void*) &instance.config.modules.wallpaper, + (void*) &instance.config.modules.weather, + (void*) &instance.config.modules.wm, + (void*) &instance.config.modules.wifi, + (void*) &instance.config.modules.wmTheme, NULL, }; diff --git a/src/fastfetch.h b/src/fastfetch.h index f741bf2fd..e957adf75 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -23,7 +23,7 @@ #include "util/platform/FFPlatform.h" #include "util/unused.h" -#include "modules/options.h" +#include "options/modules.h" #include "options/logo.h" #include "options/general.h" @@ -45,6 +45,7 @@ typedef struct FFconfig { FFOptionsLogo logo; FFOptionsGeneral general; + FFOptionsModules modules; //If one of those is empty, ffLogoPrint will set them FFstrbuf colorKeys; @@ -72,64 +73,6 @@ typedef struct FFconfig bool noBuffer; uint32_t keyWidth; - FFBatteryOptions battery; - FFBiosOptions bios; - FFBluetoothOptions bluetooth; - FFBoardOptions board; - FFBreakOptions break_; - FFBrightnessOptions brightness; - FFCPUOptions cpu; - FFCPUUsageOptions cpuUsage; - FFChassisOptions chassis; - FFColorsOptions colors; - FFCommandOptions command; - FFCursorOptions cursor; - FFCustomOptions custom; - FFDEOptions de; - FFDateTimeOptions dateTime; - FFDiskOptions disk; - FFDiskIOOptions diskIo; - FFDisplayOptions display; - FFFontOptions font; - FFGPUOptions gpu; - FFGamepadOptions gamepad; - FFHostOptions host; - FFIconsOptions icons; - FFKernelOptions kernel; - FFLMOptions lm; - FFLocalIpOptions localIP; - FFLocaleOptions locale; - FFMediaOptions media; - FFMemoryOptions memory; - FFMonitorOptions monitor; - FFNetIOOptions netIo; - FFOSOptions os; - FFOpenCLOptions openCL; - FFOpenGLOptions openGL; - FFPackagesOptions packages; - FFPlayerOptions player; - FFPowerAdapterOptions powerAdapter; - FFProcessesOptions processes; - FFPublicIpOptions publicIP; - FFSeparatorOptions separator; - FFShellOptions shell; - FFSoundOptions sound; - FFSwapOptions swap; - FFTerminalFontOptions terminalFont; - FFTerminalOptions terminal; - FFTerminalSizeOptions terminalSize; - FFThemeOptions theme; - FFTitleOptions title; - FFUptimeOptions uptime; - FFUsersOptions users; - FFVersionOptions version; - FFVulkanOptions vulkan; - FFWMOptions wm; - FFWMThemeOptions wmTheme; - FFWallpaperOptions wallpaper; - FFWeatherOptions weather; - FFWifiOptions wifi; - FFstrbuf libPCI; FFstrbuf libVulkan; FFstrbuf libWayland; diff --git a/src/flashfetch.c b/src/flashfetch.c index 355238ac4..72e93cf56 100644 --- a/src/flashfetch.c +++ b/src/flashfetch.c @@ -7,63 +7,64 @@ int main(void) ffInitInstance(); //This also applys default configuration to instance.config //Modify instance.config here + FFOptionsModules* const options = &instance.config.modules; // ffPrepareCPUUsage(); - // ffPreparePublicIp(&instance.config.publicIP); - // ffPrepareWeather(&instance.config.weather); + // ffPreparePublicIp(&options->publicIP); + // ffPrepareWeather(&options->weather); //Does things like starting detection threads, disabling line wrap, etc ffStart(); //Printing - ffPrintTitle(&instance.config.title); - ffPrintSeparator(&instance.config.separator); - ffPrintOS(&instance.config.os); - ffPrintHost(&instance.config.host); - //ffPrintBios(&instance.config.bios); - //ffPrintBoard(&instance.config.board); - //ffPrintChassis(&instance.config.chassis); - ffPrintKernel(&instance.config.kernel); - //ffPrintProcesses(&instance.config.processes); - ffPrintUptime(&instance.config.uptime); - ffPrintPackages(&instance.config.packages); - ffPrintShell(&instance.config.shell); - ffPrintDisplay(&instance.config.display); - // ffPrintBrightness(&instance.config.brightness); - ffPrintDE(&instance.config.de); - ffPrintWM(&instance.config.wm); - ffPrintWMTheme(&instance.config.wmTheme); - ffPrintTheme(&instance.config.theme); - ffPrintIcons(&instance.config.icons); - ffPrintFont(&instance.config.font); - ffPrintCursor(&instance.config.cursor); - ffPrintTerminal(&instance.config.terminal); - ffPrintTerminalFont(&instance.config.terminalFont); - ffPrintCPU(&instance.config.cpu); - ffPrintGPU(&instance.config.gpu); - ffPrintMemory(&instance.config.memory); - ffPrintSwap(&instance.config.swap); - ffPrintDisk(&instance.config.disk); - ffPrintBattery(&instance.config.battery); - ffPrintPowerAdapter(&instance.config.powerAdapter); - //ffPrintPlayer(&instance.config.player); - //ffPrintMedia(&instance.config.media); - //ffPrintLocalIp(&instance.config.localIp); - //ffPrintPublicIp(&instance.config.publicIp); - //ffPrintWifi(&instance.config.wifi); - //ffPrintCPUUsage(&instance.config.cpuUsage); - ffPrintLocale(&instance.config.locale); - //ffPrintDateTime(&instance.config.dateTime); - //ffPrintVulkan(&instance.config.vulkan); - //ffPrintOpenGL(&instance.config.openGL); - //ffPrintOpenCL(&instance.config.openCL); - //ffPrintUsers(&instance.config.users); - //ffPrintWeather(&instance.config.weather); - //ffPrintBluetooth(&instance.config.bluetooth); - //ffPrintSound(&instance.config.sound); - //ffPrintGamepad(&instance.config.gamepad); - ffPrintBreak(&instance.config.break_); - ffPrintColors(&instance.config.colors); + ffPrintTitle(&options->title); + ffPrintSeparator(&options->separator); + ffPrintOS(&options->os); + ffPrintHost(&options->host); + //ffPrintBios(&options->bios); + //ffPrintBoard(&options->board); + //ffPrintChassis(&options->chassis); + ffPrintKernel(&options->kernel); + //ffPrintProcesses(&options->processes); + ffPrintUptime(&options->uptime); + ffPrintPackages(&options->packages); + ffPrintShell(&options->shell); + ffPrintDisplay(&options->display); + // ffPrintBrightness(&options->brightness); + ffPrintDE(&options->de); + ffPrintWM(&options->wm); + ffPrintWMTheme(&options->wmTheme); + ffPrintTheme(&options->theme); + ffPrintIcons(&options->icons); + ffPrintFont(&options->font); + ffPrintCursor(&options->cursor); + ffPrintTerminal(&options->terminal); + ffPrintTerminalFont(&options->terminalFont); + ffPrintCPU(&options->cpu); + ffPrintGPU(&options->gpu); + ffPrintMemory(&options->memory); + ffPrintSwap(&options->swap); + ffPrintDisk(&options->disk); + ffPrintBattery(&options->battery); + ffPrintPowerAdapter(&options->powerAdapter); + //ffPrintPlayer(&options->player); + //ffPrintMedia(&options->media); + //ffPrintLocalIp(&options->localIp); + //ffPrintPublicIp(&options->publicIp); + //ffPrintWifi(&options->wifi); + //ffPrintCPUUsage(&options->cpuUsage); + ffPrintLocale(&options->locale); + //ffPrintDateTime(&options->dateTime); + //ffPrintVulkan(&options->vulkan); + //ffPrintOpenGL(&options->openGL); + //ffPrintOpenCL(&options->openCL); + //ffPrintUsers(&options->users); + //ffPrintWeather(&options->weather); + //ffPrintBluetooth(&options->bluetooth); + //ffPrintSound(&options->sound); + //ffPrintGamepad(&options->gamepad); + ffPrintBreak(&options->break_); + ffPrintColors(&options->colors); ffFinish(); ffDestroyInstance(); diff --git a/src/modules/separator/separator.c b/src/modules/separator/separator.c index 1bcc8b192..56a245fac 100644 --- a/src/modules/separator/separator.c +++ b/src/modules/separator/separator.c @@ -21,7 +21,7 @@ static inline uint32_t getWcsWidth(const FFstrbuf* mbstr, wchar_t* wstr, mbstate void ffPrintSeparator(FFSeparatorOptions* options) { mbstate_t state = {}; - bool fqdn = instance.config.title.fqdn; + bool fqdn = instance.config.modules.title.fqdn; const FFPlatform* platform = &instance.state.platform; FF_AUTO_FREE wchar_t* wstr = malloc((max( diff --git a/src/options/modules.c b/src/options/modules.c new file mode 100644 index 000000000..2047abdde --- /dev/null +++ b/src/options/modules.c @@ -0,0 +1,124 @@ +#include "fastfetch.h" +#include "modules/modules.h" + +void ffOptionsInitModules(FFOptionsModules* options) +{ + ffInitBatteryOptions(&options->battery); + ffInitBiosOptions(&options->bios); + ffInitBluetoothOptions(&options->bluetooth); + ffInitBoardOptions(&options->board); + ffInitBreakOptions(&options->break_); + ffInitBrightnessOptions(&options->brightness); + ffInitCPUOptions(&options->cpu); + ffInitCPUUsageOptions(&options->cpuUsage); + ffInitChassisOptions(&options->chassis); + ffInitColorsOptions(&options->colors); + ffInitCommandOptions(&options->command); + ffInitCursorOptions(&options->cursor); + ffInitCustomOptions(&options->custom); + ffInitDEOptions(&options->de); + ffInitDateTimeOptions(&options->dateTime); + ffInitDiskOptions(&options->disk); + ffInitDiskIOOptions(&options->diskIo); + ffInitDisplayOptions(&options->display); + ffInitFontOptions(&options->font); + ffInitGPUOptions(&options->gpu); + ffInitGamepadOptions(&options->gamepad); + ffInitHostOptions(&options->host); + ffInitIconsOptions(&options->icons); + ffInitKernelOptions(&options->kernel); + ffInitLMOptions(&options->lm); + ffInitLocalIpOptions(&options->localIP); + ffInitLocaleOptions(&options->locale); + ffInitMediaOptions(&options->media); + ffInitMemoryOptions(&options->memory); + ffInitMonitorOptions(&options->monitor); + ffInitNetIOOptions(&options->netIo); + ffInitOSOptions(&options->os); + ffInitOpenCLOptions(&options->openCL); + ffInitOpenGLOptions(&options->openGL); + ffInitPackagesOptions(&options->packages); + ffInitPlayerOptions(&options->player); + ffInitPowerAdapterOptions(&options->powerAdapter); + ffInitProcessesOptions(&options->processes); + ffInitPublicIpOptions(&options->publicIP); + ffInitSeparatorOptions(&options->separator); + ffInitShellOptions(&options->shell); + ffInitSoundOptions(&options->sound); + ffInitSwapOptions(&options->swap); + ffInitTerminalFontOptions(&options->terminalFont); + ffInitTerminalOptions(&options->terminal); + ffInitTerminalSizeOptions(&options->terminalSize); + ffInitThemeOptions(&options->theme); + ffInitTitleOptions(&options->title); + ffInitUptimeOptions(&options->uptime); + ffInitUsersOptions(&options->users); + ffInitVersionOptions(&options->version); + ffInitVulkanOptions(&options->vulkan); + ffInitWMOptions(&options->wm); + ffInitWMThemeOptions(&options->wmTheme); + ffInitWallpaperOptions(&options->wallpaper); + ffInitWeatherOptions(&options->weather); + ffInitWifiOptions(&options->wifi); +} + +void ffOptionsDestroyModules(FFOptionsModules* options) +{ + ffDestroyBatteryOptions(&options->battery); + ffDestroyBiosOptions(&options->bios); + ffDestroyBluetoothOptions(&options->bluetooth); + ffDestroyBoardOptions(&options->board); + ffDestroyBreakOptions(&options->break_); + ffDestroyBrightnessOptions(&options->brightness); + ffDestroyCPUOptions(&options->cpu); + ffDestroyCPUUsageOptions(&options->cpuUsage); + ffDestroyChassisOptions(&options->chassis); + ffDestroyColorsOptions(&options->colors); + ffDestroyCommandOptions(&options->command); + ffDestroyCursorOptions(&options->cursor); + ffDestroyCustomOptions(&options->custom); + ffDestroyDEOptions(&options->de); + ffDestroyDateTimeOptions(&options->dateTime); + ffDestroyDiskOptions(&options->disk); + ffDestroyDiskIOOptions(&options->diskIo); + ffDestroyDisplayOptions(&options->display); + ffDestroyFontOptions(&options->font); + ffDestroyGPUOptions(&options->gpu); + ffDestroyGamepadOptions(&options->gamepad); + ffDestroyHostOptions(&options->host); + ffDestroyIconsOptions(&options->icons); + ffDestroyKernelOptions(&options->kernel); + ffDestroyLMOptions(&options->lm); + ffDestroyLocalIpOptions(&options->localIP); + ffDestroyLocaleOptions(&options->locale); + ffDestroyMediaOptions(&options->media); + ffDestroyMemoryOptions(&options->memory); + ffDestroyMonitorOptions(&options->monitor); + ffDestroyNetIOOptions(&options->netIo); + ffDestroyOSOptions(&options->os); + ffDestroyOpenCLOptions(&options->openCL); + ffDestroyOpenGLOptions(&options->openGL); + ffDestroyPackagesOptions(&options->packages); + ffDestroyPlayerOptions(&options->player); + ffDestroyPowerAdapterOptions(&options->powerAdapter); + ffDestroyProcessesOptions(&options->processes); + ffDestroyPublicIpOptions(&options->publicIP); + ffDestroySeparatorOptions(&options->separator); + ffDestroyShellOptions(&options->shell); + ffDestroySoundOptions(&options->sound); + ffDestroySwapOptions(&options->swap); + ffDestroyTerminalFontOptions(&options->terminalFont); + ffDestroyTerminalOptions(&options->terminal); + ffDestroyTerminalSizeOptions(&options->terminalSize); + ffDestroyThemeOptions(&options->theme); + ffDestroyTitleOptions(&options->title); + ffDestroyUptimeOptions(&options->uptime); + ffDestroyUsersOptions(&options->users); + ffDestroyVersionOptions(&options->version); + ffDestroyVulkanOptions(&options->vulkan); + ffDestroyWMOptions(&options->wm); + ffDestroyWMThemeOptions(&options->wmTheme); + ffDestroyWallpaperOptions(&options->wallpaper); + ffDestroyWeatherOptions(&options->weather); + ffDestroyWifiOptions(&options->wifi); +} diff --git a/src/options/modules.h b/src/options/modules.h new file mode 100644 index 000000000..66b4203c6 --- /dev/null +++ b/src/options/modules.h @@ -0,0 +1,67 @@ +#pragma once + +#include "modules/options.h" + +typedef struct FFOptionsModules +{ + FFBatteryOptions battery; + FFBiosOptions bios; + FFBluetoothOptions bluetooth; + FFBoardOptions board; + FFBreakOptions break_; + FFBrightnessOptions brightness; + FFCPUOptions cpu; + FFCPUUsageOptions cpuUsage; + FFChassisOptions chassis; + FFColorsOptions colors; + FFCommandOptions command; + FFCursorOptions cursor; + FFCustomOptions custom; + FFDEOptions de; + FFDateTimeOptions dateTime; + FFDiskOptions disk; + FFDiskIOOptions diskIo; + FFDisplayOptions display; + FFFontOptions font; + FFGPUOptions gpu; + FFGamepadOptions gamepad; + FFHostOptions host; + FFIconsOptions icons; + FFKernelOptions kernel; + FFLMOptions lm; + FFLocalIpOptions localIP; + FFLocaleOptions locale; + FFMediaOptions media; + FFMemoryOptions memory; + FFMonitorOptions monitor; + FFNetIOOptions netIo; + FFOSOptions os; + FFOpenCLOptions openCL; + FFOpenGLOptions openGL; + FFPackagesOptions packages; + FFPlayerOptions player; + FFPowerAdapterOptions powerAdapter; + FFProcessesOptions processes; + FFPublicIpOptions publicIP; + FFSeparatorOptions separator; + FFShellOptions shell; + FFSoundOptions sound; + FFSwapOptions swap; + FFTerminalFontOptions terminalFont; + FFTerminalOptions terminal; + FFTerminalSizeOptions terminalSize; + FFThemeOptions theme; + FFTitleOptions title; + FFUptimeOptions uptime; + FFUsersOptions users; + FFVersionOptions version; + FFVulkanOptions vulkan; + FFWMOptions wm; + FFWMThemeOptions wmTheme; + FFWallpaperOptions wallpaper; + FFWeatherOptions weather; + FFWifiOptions wifi; +} FFOptionsModules; + +void ffOptionsInitModules(FFOptionsModules* options); +void ffOptionsDestroyModules(FFOptionsModules* options); From 2c49dcceaff9c0cc863c7108d42051bd1dee39ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 25 Oct 2023 16:24:24 +0800 Subject: [PATCH 033/100] Options (Library): split code --- CMakeLists.txt | 1 + src/common/dbus.c | 2 +- src/common/init.c | 50 +---- src/common/jsonconfig.c | 73 ------- src/common/jsonconfig.h | 1 - src/common/settings.c | 8 +- src/detection/brightness/brightness_linux.c | 2 +- src/detection/displayserver/linux/wayland.c | 2 +- src/detection/displayserver/linux/xcb.c | 4 +- src/detection/displayserver/linux/xlib.c | 4 +- src/detection/gpu/gpu_linux.c | 2 +- src/detection/lm/lm_linux.c | 2 +- src/detection/opencl/opencl.c | 2 +- src/detection/opengl/opengl_linux.c | 6 +- src/detection/packages/packages_linux.c | 2 +- src/detection/sound/sound_linux.c | 2 +- .../terminalfont/terminalfont_android.c | 2 +- src/detection/vulkan/vulkan.c | 2 +- src/detection/wallpaper/wallpaper_apple.c | 2 +- src/detection/wifi/wifi_linux.c | 2 +- src/fastfetch.c | 58 +----- src/fastfetch.h | 26 +-- src/logo/image/im6.c | 2 +- src/logo/image/im7.c | 2 +- src/logo/image/image.c | 4 +- src/options/library.c | 188 ++++++++++++++++++ src/options/library.h | 36 ++++ 27 files changed, 258 insertions(+), 229 deletions(-) create mode 100644 src/options/library.c create mode 100644 src/options/library.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c48b06813..76aaf7612 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -357,6 +357,7 @@ set(LIBFASTFETCH_SRC src/options/modules.c src/options/logo.c src/options/general.c + src/options/library.c src/util/edidHelper.c src/util/FFlist.c src/util/FFstrbuf.c diff --git a/src/common/dbus.c b/src/common/dbus.c index 968358a8d..05f66e402 100644 --- a/src/common/dbus.c +++ b/src/common/dbus.c @@ -7,7 +7,7 @@ static bool loadLibSymbols(FFDBusLibrary* lib) { - FF_LIBRARY_LOAD(dbus, &instance.config.libDBus, false, "libdbus-1" FF_LIBRARY_EXTENSION, 4); + FF_LIBRARY_LOAD(dbus, &instance.config.library.libDBus, false, "libdbus-1" FF_LIBRARY_EXTENSION, 4); FF_LIBRARY_LOAD_SYMBOL_PTR(dbus, lib, dbus_bus_get, false) FF_LIBRARY_LOAD_SYMBOL_PTR(dbus, lib, dbus_message_new_method_call, false) FF_LIBRARY_LOAD_SYMBOL_PTR(dbus, lib, dbus_message_iter_init, false) diff --git a/src/common/init.c b/src/common/init.c index 25e01d748..35e363a6c 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -65,30 +65,7 @@ static void defaultConfig(void) instance.config.percentType = 1; instance.config.percentNdigits = 0; - ffStrbufInit(&instance.config.libPCI); - ffStrbufInit(&instance.config.libVulkan); - ffStrbufInit(&instance.config.libWayland); - ffStrbufInit(&instance.config.libXcbRandr); - ffStrbufInit(&instance.config.libXcb); - ffStrbufInit(&instance.config.libXrandr); - ffStrbufInit(&instance.config.libX11); - ffStrbufInit(&instance.config.libGIO); - ffStrbufInit(&instance.config.libDConf); - ffStrbufInit(&instance.config.libDBus); - ffStrbufInit(&instance.config.libXFConf); - ffStrbufInit(&instance.config.libSQLite3); - ffStrbufInit(&instance.config.librpm); - ffStrbufInit(&instance.config.libImageMagick); - ffStrbufInit(&instance.config.libZ); - ffStrbufInit(&instance.config.libChafa); - ffStrbufInit(&instance.config.libEGL); - ffStrbufInit(&instance.config.libGLX); - ffStrbufInit(&instance.config.libOSMesa); - ffStrbufInit(&instance.config.libOpenCL); - ffStrbufInit(&instance.config.libfreetype); - ffStrbufInit(&instance.config.libPulse); - ffStrbufInit(&instance.config.libnm); - ffStrbufInit(&instance.config.libDdcutil); + ffOptionsInitLibrary(&instance.config.library); } void ffInitInstance(void) @@ -219,30 +196,7 @@ static void destroyConfig(void) ffStrbufDestroy(&instance.config.barCharElapsed); ffStrbufDestroy(&instance.config.barCharTotal); - ffStrbufDestroy(&instance.config.libPCI); - ffStrbufDestroy(&instance.config.libVulkan); - ffStrbufDestroy(&instance.config.libWayland); - ffStrbufDestroy(&instance.config.libXcbRandr); - ffStrbufDestroy(&instance.config.libXcb); - ffStrbufDestroy(&instance.config.libXrandr); - ffStrbufDestroy(&instance.config.libX11); - ffStrbufDestroy(&instance.config.libGIO); - ffStrbufDestroy(&instance.config.libDConf); - ffStrbufDestroy(&instance.config.libDBus); - ffStrbufDestroy(&instance.config.libXFConf); - ffStrbufDestroy(&instance.config.libSQLite3); - ffStrbufDestroy(&instance.config.librpm); - ffStrbufDestroy(&instance.config.libImageMagick); - ffStrbufDestroy(&instance.config.libZ); - ffStrbufDestroy(&instance.config.libChafa); - ffStrbufDestroy(&instance.config.libEGL); - ffStrbufDestroy(&instance.config.libGLX); - ffStrbufDestroy(&instance.config.libOSMesa); - ffStrbufDestroy(&instance.config.libOpenCL); - ffStrbufDestroy(&instance.config.libfreetype); - ffStrbufDestroy(&instance.config.libPulse); - ffStrbufDestroy(&instance.config.libnm); - ffStrbufDestroy(&instance.config.libDdcutil); + ffOptionsDestroyLibrary(&instance.config.library); } static void destroyState(void) diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 384751370..5a890ba22 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -366,79 +366,6 @@ const char* ffParseDisplayJsonConfig(FFconfig* config) return NULL; } -const char* ffParseLibraryJsonConfig(FFconfig* config) -{ - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); - assert(root); - - if (!yyjson_is_obj(root)) - return "Invalid JSON config format. Root value must be an object"; - - yyjson_val* object = yyjson_obj_get(root, "library"); - if (!object) return NULL; - if (!yyjson_is_obj(object)) return "Property 'library' must be an object"; - - yyjson_val *key_, *val; - size_t idx, max; - yyjson_obj_foreach(object, idx, max, key_, val) - { - const char* key = yyjson_get_str(key_); - - if (ffStrEqualsIgnCase(key, "pci")) - ffStrbufSetS(&config->libPCI, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "vulkan")) - ffStrbufSetS(&config->libVulkan, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "freetype")) - ffStrbufSetS(&config->libfreetype, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "wayland")) - ffStrbufSetS(&config->libWayland, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "xcbRandr")) - ffStrbufSetS(&config->libXcbRandr, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "xcb")) - ffStrbufSetS(&config->libXcb, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "Xrandr")) - ffStrbufSetS(&config->libXrandr, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "X11")) - ffStrbufSetS(&config->libX11, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "gio")) - ffStrbufSetS(&config->libGIO, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "DConf")) - ffStrbufSetS(&config->libDConf, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "dbus")) - ffStrbufSetS(&config->libDBus, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "XFConf")) - ffStrbufSetS(&config->libXFConf, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "sqlite") || ffStrEqualsIgnCase(key, "sqlite3")) - ffStrbufSetS(&config->libSQLite3, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "rpm")) - ffStrbufSetS(&config->librpm, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "imagemagick")) - ffStrbufSetS(&config->libImageMagick, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "z")) - ffStrbufSetS(&config->libZ, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "chafa")) - ffStrbufSetS(&config->libChafa, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "egl")) - ffStrbufSetS(&config->libEGL, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "glx")) - ffStrbufSetS(&config->libGLX, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "osmesa")) - ffStrbufSetS(&config->libOSMesa, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "opencl")) - ffStrbufSetS(&config->libOpenCL, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "pulse")) - ffStrbufSetS(&config->libPulse, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "nm")) - ffStrbufSetS(&config->libnm, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "ddcutil")) - ffStrbufSetS(&config->libDdcutil, yyjson_get_str(val)); - else - return "Unknown library property"; - } - - return NULL; -} - void ffPrintJsonConfig(bool prepare) { const char* error = printJsonConfig(prepare); diff --git a/src/common/jsonconfig.h b/src/common/jsonconfig.h index 6103d7337..2ca3fc950 100644 --- a/src/common/jsonconfig.h +++ b/src/common/jsonconfig.h @@ -6,7 +6,6 @@ bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs* const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]); void ffPrintJsonConfig(bool prepare); const char* ffParseDisplayJsonConfig(FFconfig* config); -const char* ffParseLibraryJsonConfig(FFconfig* config); void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs); yyjson_api_inline bool yyjson_mut_obj_add_strbuf(yyjson_mut_doc *doc, diff --git a/src/common/settings.c b/src/common/settings.c index dda3fe62d..0e1dbeb29 100644 --- a/src/common/settings.c +++ b/src/common/settings.c @@ -99,7 +99,7 @@ typedef struct GSettingsData static const GSettingsData* getGSettingsData(void) { - FF_LIBRARY_DATA_LOAD_INIT(GSettingsData, instance.config.libGIO, "libgio-2.0" FF_LIBRARY_EXTENSION, 1); + FF_LIBRARY_DATA_LOAD_INIT(GSettingsData, instance.config.library.libGIO, "libgio-2.0" FF_LIBRARY_EXTENSION, 1); FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_schema_source_lookup) FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_schema_has_key) @@ -172,7 +172,7 @@ typedef struct DConfData static const DConfData* getDConfData(void) { - FF_LIBRARY_DATA_LOAD_INIT(DConfData, instance.config.libDConf, "libdconf" FF_LIBRARY_EXTENSION, 2); + FF_LIBRARY_DATA_LOAD_INIT(DConfData, instance.config.library.libDConf, "libdconf" FF_LIBRARY_EXTENSION, 2); FF_LIBRARY_DATA_LOAD_SYMBOL(dconf_client_read_full) FF_LIBRARY_DATA_LOAD_SYMBOL(dconf_client_new) @@ -243,7 +243,7 @@ typedef struct XFConfData static const XFConfData* getXFConfData(void) { - FF_LIBRARY_DATA_LOAD_INIT(XFConfData, instance.config.libXFConf, "libxfconf-0" FF_LIBRARY_EXTENSION, 4); + FF_LIBRARY_DATA_LOAD_INIT(XFConfData, instance.config.library.libXFConf, "libxfconf-0" FF_LIBRARY_EXTENSION, 4); FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_get) FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_has_property) @@ -305,7 +305,7 @@ typedef struct SQLiteData static const SQLiteData* getSQLiteData(void) { - FF_LIBRARY_DATA_LOAD_INIT(SQLiteData, instance.config.libSQLite3, "libsqlite3" FF_LIBRARY_EXTENSION, 1); + FF_LIBRARY_DATA_LOAD_INIT(SQLiteData, instance.config.library.libSQLite3, "libsqlite3" FF_LIBRARY_EXTENSION, 1); FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_open_v2) FF_LIBRARY_DATA_LOAD_SYMBOL(sqlite3_prepare_v2) diff --git a/src/detection/brightness/brightness_linux.c b/src/detection/brightness/brightness_linux.c index 9b354c0f2..ff3843c06 100644 --- a/src/detection/brightness/brightness_linux.c +++ b/src/detection/brightness/brightness_linux.c @@ -100,7 +100,7 @@ double ddca_set_default_sleep_multiplier(double multiplier); // ddcutil 1.4 static const char* detectWithDdcci(FFBrightnessOptions* options, FFlist* result) { - FF_LIBRARY_LOAD(libddcutil, &instance.config.libDdcutil, "dlopen ddcutil failed", "libddcutil" FF_LIBRARY_EXTENSION, 5); + FF_LIBRARY_LOAD(libddcutil, &instance.config.library.libDdcutil, "dlopen ddcutil failed", "libddcutil" FF_LIBRARY_EXTENSION, 5); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libddcutil, ddca_get_display_info_list2) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libddcutil, ddca_open_display2) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libddcutil, ddca_get_any_vcp_value_using_explicit_type) diff --git a/src/detection/displayserver/linux/wayland.c b/src/detection/displayserver/linux/wayland.c index 06d7c7f75..e9bfca341 100644 --- a/src/detection/displayserver/linux/wayland.c +++ b/src/detection/displayserver/linux/wayland.c @@ -276,7 +276,7 @@ static void waylandGlobalAddListener(void* data, struct wl_registry* registry, u bool detectWayland(FFDisplayServerResult* result) { - FF_LIBRARY_LOAD(wayland, &instance.config.libWayland, false, "libwayland-client" FF_LIBRARY_EXTENSION, 1) + FF_LIBRARY_LOAD(wayland, &instance.config.library.libWayland, false, "libwayland-client" FF_LIBRARY_EXTENSION, 1) FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect, false) FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_get_fd, false) diff --git a/src/detection/displayserver/linux/xcb.c b/src/detection/displayserver/linux/xcb.c index d968bfbad..4a5240837 100644 --- a/src/detection/displayserver/linux/xcb.c +++ b/src/detection/displayserver/linux/xcb.c @@ -100,7 +100,7 @@ static void xcbDetectWMfromEWMH(XcbPropertyData* data, xcb_connection_t* connect void ffdsConnectXcb(FFDisplayServerResult* result) { - FF_LIBRARY_LOAD(xcb, &instance.config.libXcb, , "libxcb" FF_LIBRARY_EXTENSION, 2) + FF_LIBRARY_LOAD(xcb, &instance.config.library.libXcb, , "libxcb" FF_LIBRARY_EXTENSION, 2) FF_LIBRARY_LOAD_SYMBOL(xcb, xcb_connect,) FF_LIBRARY_LOAD_SYMBOL(xcb, xcb_get_setup,) FF_LIBRARY_LOAD_SYMBOL(xcb, xcb_setup_roots_iterator,) @@ -429,7 +429,7 @@ static void xcbRandrHandleScreen(XcbRandrData* data, xcb_screen_t* screen) void ffdsConnectXcbRandr(FFDisplayServerResult* result) { - FF_LIBRARY_LOAD(xcbRandr, &instance.config.libXcbRandr, , "libxcb-randr" FF_LIBRARY_EXTENSION, 1) + FF_LIBRARY_LOAD(xcbRandr, &instance.config.library.libXcbRandr, , "libxcb-randr" FF_LIBRARY_EXTENSION, 1) FF_LIBRARY_LOAD_SYMBOL(xcbRandr, xcb_connect,) FF_LIBRARY_LOAD_SYMBOL(xcbRandr, xcb_get_setup,) FF_LIBRARY_LOAD_SYMBOL(xcbRandr, xcb_setup_roots_iterator,) diff --git a/src/detection/displayserver/linux/xlib.c b/src/detection/displayserver/linux/xlib.c index 4c9333d88..6c52a4393 100644 --- a/src/detection/displayserver/linux/xlib.c +++ b/src/detection/displayserver/linux/xlib.c @@ -60,7 +60,7 @@ static void x11DetectWMFromEWMH(X11PropertyData* data, Display* display, FFDispl void ffdsConnectXlib(FFDisplayServerResult* result) { - FF_LIBRARY_LOAD(x11, &instance.config.libX11, , "libX11" FF_LIBRARY_EXTENSION, 7, "libX11-xcb" FF_LIBRARY_EXTENSION, 2) + FF_LIBRARY_LOAD(x11, &instance.config.library.libX11, , "libX11" FF_LIBRARY_EXTENSION, 7, "libX11-xcb" FF_LIBRARY_EXTENSION, 2) FF_LIBRARY_LOAD_SYMBOL(x11, XOpenDisplay,) FF_LIBRARY_LOAD_SYMBOL(x11, XCloseDisplay,) @@ -338,7 +338,7 @@ static void xrandrHandleScreen(XrandrData* data, Screen* screen) void ffdsConnectXrandr(FFDisplayServerResult* result) { - FF_LIBRARY_LOAD(xrandr, &instance.config.libXrandr, , "libXrandr" FF_LIBRARY_EXTENSION, 3) + FF_LIBRARY_LOAD(xrandr, &instance.config.library.libXrandr, , "libXrandr" FF_LIBRARY_EXTENSION, 3) FF_LIBRARY_LOAD_SYMBOL(xrandr, XOpenDisplay,) FF_LIBRARY_LOAD_SYMBOL(xrandr, XCloseDisplay,) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 72a653008..9951699c3 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -270,7 +270,7 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus) { PCIData pci; - FF_LIBRARY_LOAD(libpci, &instance.config.libPCI, "dlopen libpci.so failed", "libpci" FF_LIBRARY_EXTENSION, 4); + FF_LIBRARY_LOAD(libpci, &instance.config.library.libPCI, "dlopen libpci.so failed", "libpci" FF_LIBRARY_EXTENSION, 4); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libpci, pci_alloc); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libpci, pci_init); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libpci, pci_scan_bus); diff --git a/src/detection/lm/lm_linux.c b/src/detection/lm/lm_linux.c index 6416c80a7..0fb4fdba5 100644 --- a/src/detection/lm/lm_linux.c +++ b/src/detection/lm/lm_linux.c @@ -55,7 +55,7 @@ static const char* getSshdVersion(FFstrbuf* version) static const char* getSddmVersion(FFstrbuf* version) { - FF_LIBRARY_LOAD(zlib, &instance.config.libZ, "dlopen libz failed", "libz" FF_LIBRARY_EXTENSION, 2) + FF_LIBRARY_LOAD(zlib, &instance.config.library.libZ, "dlopen libz failed", "libz" FF_LIBRARY_EXTENSION, 2) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzopen); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzread); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzerror); diff --git a/src/detection/opencl/opencl.c b/src/detection/opencl/opencl.c index 0526de2e2..3402c9311 100644 --- a/src/detection/opencl/opencl.c +++ b/src/detection/opencl/opencl.c @@ -72,7 +72,7 @@ const char* ffDetectOpenCL(FFOpenCLResult* result) OpenCLData data; - FF_LIBRARY_LOAD(opencl, &instance.config.libOpenCL, "dlopen libOpenCL"FF_LIBRARY_EXTENSION" failed", + FF_LIBRARY_LOAD(opencl, &instance.config.library.libOpenCL, "dlopen libOpenCL"FF_LIBRARY_EXTENSION" failed", #ifdef _WIN32 "OpenCL"FF_LIBRARY_EXTENSION, -1, #endif diff --git a/src/detection/opengl/opengl_linux.c b/src/detection/opengl/opengl_linux.c index 8ea44355d..8ce29e7a2 100644 --- a/src/detection/opengl/opengl_linux.c +++ b/src/detection/opengl/opengl_linux.c @@ -122,7 +122,7 @@ static const char* eglPrint(FFOpenGLResult* result) { EGLData eglData; - FF_LIBRARY_LOAD(egl, &instance.config.libEGL, "dlopen egl failed", "libEGL" FF_LIBRARY_EXTENSION, 1); + FF_LIBRARY_LOAD(egl, &instance.config.library.libEGL, "dlopen egl failed", "libEGL" FF_LIBRARY_EXTENSION, 1); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetProcAddress); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglGetDisplay); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(egl, eglData, eglInitialize); @@ -239,7 +239,7 @@ static const char* glxPrint(FFOpenGLResult* result) { GLXData data; - FF_LIBRARY_LOAD(glx, &instance.config.libGLX, "dlopen glx failed", "libGLX" FF_LIBRARY_EXTENSION, 1); + FF_LIBRARY_LOAD(glx, &instance.config.library.libGLX, "dlopen glx failed", "libGLX" FF_LIBRARY_EXTENSION, 1); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXGetProcAddress); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, XOpenDisplay); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(glx, data, glXChooseVisual); @@ -303,7 +303,7 @@ static const char* osMesaPrint(FFOpenGLResult* result) { OSMesaData data; - FF_LIBRARY_LOAD(osmesa, &instance.config.libOSMesa, "dlopen osmesa failed", "libOSMesa" FF_LIBRARY_EXTENSION, 8); + FF_LIBRARY_LOAD(osmesa, &instance.config.library.libOSMesa, "dlopen osmesa failed", "libOSMesa" FF_LIBRARY_EXTENSION, 8); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(osmesa, data, OSMesaGetProcAddress); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(osmesa, data, OSMesaCreateContext); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(osmesa, data, OSMesaMakeCurrent); diff --git a/src/detection/packages/packages_linux.c b/src/detection/packages/packages_linux.c index 93a756012..332fd3de0 100644 --- a/src/detection/packages/packages_linux.c +++ b/src/detection/packages/packages_linux.c @@ -226,7 +226,7 @@ static uint32_t getFlatpak(FFstrbuf* baseDir, const char* dirname) static uint32_t getRpmFromLibrpm(void) { - FF_LIBRARY_LOAD(rpm, &instance.config.librpm, 0, "librpm" FF_LIBRARY_EXTENSION, 12) + FF_LIBRARY_LOAD(rpm, &instance.config.library.librpm, 0, "librpm" FF_LIBRARY_EXTENSION, 12) FF_LIBRARY_LOAD_SYMBOL(rpm, rpmReadConfigFiles, 0) FF_LIBRARY_LOAD_SYMBOL(rpm, rpmtsCreate, 0) FF_LIBRARY_LOAD_SYMBOL(rpm, rpmtsInitIterator, 0) diff --git a/src/detection/sound/sound_linux.c b/src/detection/sound/sound_linux.c index 8f14ab49e..f42ea3a79 100644 --- a/src/detection/sound/sound_linux.c +++ b/src/detection/sound/sound_linux.c @@ -38,7 +38,7 @@ static void paServerInfoCallback(pa_context *c, const pa_server_info *i, void *u static const char* detectSound(FFlist* devices) { - FF_LIBRARY_LOAD(pulse, &instance.config.libPulse, "Failed to load libpulse" FF_LIBRARY_EXTENSION, "libpulse" FF_LIBRARY_EXTENSION, 0) + FF_LIBRARY_LOAD(pulse, &instance.config.library.libPulse, "Failed to load libpulse" FF_LIBRARY_EXTENSION, "libpulse" FF_LIBRARY_EXTENSION, 0) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pulse, pa_mainloop_new) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pulse, pa_mainloop_get_api) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(pulse, pa_mainloop_iterate) diff --git a/src/detection/terminalfont/terminalfont_android.c b/src/detection/terminalfont/terminalfont_android.c index bced44147..72a67fb0a 100644 --- a/src/detection/terminalfont/terminalfont_android.c +++ b/src/detection/terminalfont/terminalfont_android.c @@ -15,7 +15,7 @@ const char* detectTermux(FFTerminalFontResult* terminalFont) { #ifdef FF_HAVE_FREETYPE - FF_LIBRARY_LOAD(freetype, &instance.config.libfreetype, "dlopen libfreetype"FF_LIBRARY_EXTENSION " failed", "libfreetype"FF_LIBRARY_EXTENSION, 2) + FF_LIBRARY_LOAD(freetype, &instance.config.library.libfreetype, "dlopen libfreetype"FF_LIBRARY_EXTENSION " failed", "libfreetype"FF_LIBRARY_EXTENSION, 2) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_Init_FreeType); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_New_Face); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_Done_Face); diff --git a/src/detection/vulkan/vulkan.c b/src/detection/vulkan/vulkan.c index 0516e1bbc..dd337e8d2 100644 --- a/src/detection/vulkan/vulkan.c +++ b/src/detection/vulkan/vulkan.c @@ -40,7 +40,7 @@ static void applyDriverName(VkPhysicalDeviceDriverProperties* properties, FFstrb static const char* detectVulkan(FFVulkanResult* result) { - FF_LIBRARY_LOAD(vulkan, &instance.config.libVulkan, "dlopen libvulkan"FF_LIBRARY_EXTENSION " failed", + FF_LIBRARY_LOAD(vulkan, &instance.config.library.libVulkan, "dlopen libvulkan"FF_LIBRARY_EXTENSION " failed", #ifdef __APPLE__ "libMoltenVK"FF_LIBRARY_EXTENSION, -1 #elif defined(_WIN32) diff --git a/src/detection/wallpaper/wallpaper_apple.c b/src/detection/wallpaper/wallpaper_apple.c index 4ec131417..87691abb4 100644 --- a/src/detection/wallpaper/wallpaper_apple.c +++ b/src/detection/wallpaper/wallpaper_apple.c @@ -24,7 +24,7 @@ const char* ffDetectWallpaper(FFstrbuf* result) #endif if (!ffOsascript("tell application \"Finder\" to get POSIX path of (get desktop picture as alias)", result)) - return "ffOsascript() failed"; + return "ffOsascript(get desktop picture) failed"; return NULL; } diff --git a/src/detection/wifi/wifi_linux.c b/src/detection/wifi/wifi_linux.c index 9a75d587e..9a5c957b9 100644 --- a/src/detection/wifi/wifi_linux.c +++ b/src/detection/wifi/wifi_linux.c @@ -22,7 +22,7 @@ static const char* detectWifiWithLibnm(FFlist* result) { - FF_LIBRARY_LOAD(nm, &instance.config.libnm, "dlopen libnm failed", "libnm" FF_LIBRARY_EXTENSION, 0); + FF_LIBRARY_LOAD(nm, &instance.config.library.libnm, "dlopen libnm failed", "libnm" FF_LIBRARY_EXTENSION, 0); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(nm, nm_client_new); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(nm, nm_client_get_devices); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(nm, nm_device_get_iface); diff --git a/src/fastfetch.c b/src/fastfetch.c index 548eb382f..4a1cd470e 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -649,61 +649,7 @@ static void parseOption(FFdata* data, const char* key, const char* value) /////////////////// //Library options// /////////////////// - - else if(ffStrStartsWithIgnCase(key, "--lib-")) - { - const char* subkey = key + strlen("--lib-"); - if(ffStrEqualsIgnCase(subkey, "PCI")) - ffOptionParseString(key, value, &instance.config.libPCI); - else if(ffStrEqualsIgnCase(subkey, "vulkan")) - ffOptionParseString(key, value, &instance.config.libVulkan); - else if(ffStrEqualsIgnCase(subkey, "freetype")) - ffOptionParseString(key, value, &instance.config.libfreetype); - else if(ffStrEqualsIgnCase(subkey, "wayland")) - ffOptionParseString(key, value, &instance.config.libWayland); - else if(ffStrEqualsIgnCase(subkey, "xcb-randr")) - ffOptionParseString(key, value, &instance.config.libXcbRandr); - else if(ffStrEqualsIgnCase(subkey, "xcb")) - ffOptionParseString(key, value, &instance.config.libXcb); - else if(ffStrEqualsIgnCase(subkey, "Xrandr")) - ffOptionParseString(key, value, &instance.config.libXrandr); - else if(ffStrEqualsIgnCase(subkey, "X11")) - ffOptionParseString(key, value, &instance.config.libX11); - else if(ffStrEqualsIgnCase(subkey, "gio")) - ffOptionParseString(key, value, &instance.config.libGIO); - else if(ffStrEqualsIgnCase(subkey, "DConf")) - ffOptionParseString(key, value, &instance.config.libDConf); - else if(ffStrEqualsIgnCase(subkey, "dbus")) - ffOptionParseString(key, value, &instance.config.libDBus); - else if(ffStrEqualsIgnCase(subkey, "XFConf")) - ffOptionParseString(key, value, &instance.config.libXFConf); - else if(ffStrEqualsIgnCase(subkey, "sqlite") || ffStrEqualsIgnCase(subkey, "sqlite3")) - ffOptionParseString(key, value, &instance.config.libSQLite3); - else if(ffStrEqualsIgnCase(subkey, "rpm")) - ffOptionParseString(key, value, &instance.config.librpm); - else if(ffStrEqualsIgnCase(subkey, "imagemagick")) - ffOptionParseString(key, value, &instance.config.libImageMagick); - else if(ffStrEqualsIgnCase(subkey, "z")) - ffOptionParseString(key, value, &instance.config.libZ); - else if(ffStrEqualsIgnCase(subkey, "chafa")) - ffOptionParseString(key, value, &instance.config.libChafa); - else if(ffStrEqualsIgnCase(subkey, "egl")) - ffOptionParseString(key, value, &instance.config.libEGL); - else if(ffStrEqualsIgnCase(subkey, "glx")) - ffOptionParseString(key, value, &instance.config.libGLX); - else if(ffStrEqualsIgnCase(subkey, "osmesa")) - ffOptionParseString(key, value, &instance.config.libOSMesa); - else if(ffStrEqualsIgnCase(subkey, "opencl")) - ffOptionParseString(key, value, &instance.config.libOpenCL); - else if(ffStrEqualsIgnCase(subkey, "pulse")) - ffOptionParseString(key, value, &instance.config.libPulse); - else if(ffStrEqualsIgnCase(subkey, "nm")) - ffOptionParseString(key, value, &instance.config.libnm); - else if(ffStrEqualsIgnCase(subkey, "ddcutil")) - ffOptionParseString(key, value, &instance.config.libDdcutil); - else - goto error; - } + else if(ffOptionsParseLibraryCommandLine(&instance.config.library, key, value)) {} /////////////////////// //Module args options// @@ -796,7 +742,7 @@ static void run(FFdata* data) (error = ffOptionsParseLogoJsonConfig(&instance.config.logo, root)) || (error = ffOptionsParseGeneralJsonConfig(&instance.config.general, root)) || (error = ffParseDisplayJsonConfig(&instance.config)) || - (error = ffParseLibraryJsonConfig(&instance.config)) || + (error = ffOptionsParseLibraryJsonConfig(&instance.config.library, root)) || false ) { fputs(error, stderr); diff --git a/src/fastfetch.h b/src/fastfetch.h index e957adf75..7be79ab60 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -26,6 +26,7 @@ #include "options/modules.h" #include "options/logo.h" #include "options/general.h" +#include "options/library.h" typedef enum FFBinaryPrefixType { @@ -73,30 +74,7 @@ typedef struct FFconfig bool noBuffer; uint32_t keyWidth; - FFstrbuf libPCI; - FFstrbuf libVulkan; - FFstrbuf libWayland; - FFstrbuf libXcbRandr; - FFstrbuf libXcb; - FFstrbuf libXrandr; - FFstrbuf libX11; - FFstrbuf libGIO; - FFstrbuf libDConf; - FFstrbuf libDBus; - FFstrbuf libXFConf; - FFstrbuf libSQLite3; - FFstrbuf librpm; - FFstrbuf libImageMagick; - FFstrbuf libZ; - FFstrbuf libChafa; - FFstrbuf libEGL; - FFstrbuf libGLX; - FFstrbuf libOSMesa; - FFstrbuf libOpenCL; - FFstrbuf libfreetype; - FFstrbuf libPulse; - FFstrbuf libnm; - FFstrbuf libDdcutil; + FFOptionsLibrary library; } FFconfig; typedef struct FFstate diff --git a/src/logo/image/im6.c b/src/logo/image/im6.c index c9a1e56a4..a8820f53b 100644 --- a/src/logo/image/im6.c +++ b/src/logo/image/im6.c @@ -14,7 +14,7 @@ static void* logoResize(const void* image, size_t width, size_t height, void* ex FFLogoImageResult ffLogoPrintImageIM6(FFLogoRequestData* requestData) { - FF_LIBRARY_LOAD(imageMagick, &instance.config.libImageMagick, FF_LOGO_IMAGE_RESULT_INIT_ERROR, "libMagickCore-6.Q16HDRI" FF_LIBRARY_EXTENSION, 8, "libMagickCore-6.Q16" FF_LIBRARY_EXTENSION, 8) + FF_LIBRARY_LOAD(imageMagick, &instance.config.library.libImageMagick, FF_LOGO_IMAGE_RESULT_INIT_ERROR, "libMagickCore-6.Q16HDRI" FF_LIBRARY_EXTENSION, 8, "libMagickCore-6.Q16" FF_LIBRARY_EXTENSION, 8) FF_LIBRARY_LOAD_SYMBOL_ADDRESS(imageMagick, ffResizeImage, ResizeImage, FF_LOGO_IMAGE_RESULT_INIT_ERROR); return ffLogoPrintImageImpl(requestData, &(FFIMData) { diff --git a/src/logo/image/im7.c b/src/logo/image/im7.c index 394e124df..03229aacb 100644 --- a/src/logo/image/im7.c +++ b/src/logo/image/im7.c @@ -14,7 +14,7 @@ static void* logoResize(const void* image, size_t width, size_t height, void* ex FFLogoImageResult ffLogoPrintImageIM7(FFLogoRequestData* requestData) { - FF_LIBRARY_LOAD(imageMagick, &instance.config.libImageMagick, FF_LOGO_IMAGE_RESULT_INIT_ERROR, + FF_LIBRARY_LOAD(imageMagick, &instance.config.library.libImageMagick, FF_LOGO_IMAGE_RESULT_INIT_ERROR, "libMagickCore-7.Q16HDRI" FF_LIBRARY_EXTENSION, 11, "libMagickCore-7.Q16" FF_LIBRARY_EXTENSION, 11, "libMagickCore-7.Q16HDRI-10" FF_LIBRARY_EXTENSION, -1 // Required for Windows diff --git a/src/logo/image/image.c b/src/logo/image/image.c index 8756fcca9..6164585f5 100644 --- a/src/logo/image/image.c +++ b/src/logo/image/image.c @@ -222,7 +222,7 @@ static inline char* realpath(const char* restrict file_name, char* restrict reso static bool compressBlob(void** blob, size_t* length) { - FF_LIBRARY_LOAD(zlib, &instance.config.libZ, false, "libz" FF_LIBRARY_EXTENSION, 2) + FF_LIBRARY_LOAD(zlib, &instance.config.library.libZ, false, "libz" FF_LIBRARY_EXTENSION, 2) FF_LIBRARY_LOAD_SYMBOL(zlib, compressBound, false) FF_LIBRARY_LOAD_SYMBOL(zlib, compress2, false) @@ -398,7 +398,7 @@ static bool printImageKitty(FFLogoRequestData* requestData, const ImageData* ima #include static bool printImageChafa(FFLogoRequestData* requestData, const ImageData* imageData) { - FF_LIBRARY_LOAD(chafa, &instance.config.libChafa, false, + FF_LIBRARY_LOAD(chafa, &instance.config.library.libChafa, false, "libchafa" FF_LIBRARY_EXTENSION, 1, "libchafa-0" FF_LIBRARY_EXTENSION, -1 // Required for Windows ) diff --git a/src/options/library.c b/src/options/library.c new file mode 100644 index 000000000..5020891f1 --- /dev/null +++ b/src/options/library.c @@ -0,0 +1,188 @@ +#include "fastfetch.h" +#include "options/library.h" +#include "util/stringUtils.h" + +const char* ffOptionsParseLibraryJsonConfig(FFOptionsLibrary* options, yyjson_val* root) +{ + yyjson_val* object = yyjson_obj_get(root, "library"); + if (!object) return NULL; + if (!yyjson_is_obj(object)) return "Property 'library' must be an object"; + + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(object, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + + if (ffStrEqualsIgnCase(key, "pci")) + ffStrbufSetS(&options->libPCI, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "vulkan")) + ffStrbufSetS(&options->libVulkan, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "freetype")) + ffStrbufSetS(&options->libfreetype, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "wayland")) + ffStrbufSetS(&options->libWayland, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "xcbRandr")) + ffStrbufSetS(&options->libXcbRandr, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "xcb")) + ffStrbufSetS(&options->libXcb, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "Xrandr")) + ffStrbufSetS(&options->libXrandr, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "X11")) + ffStrbufSetS(&options->libX11, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "gio")) + ffStrbufSetS(&options->libGIO, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "DConf")) + ffStrbufSetS(&options->libDConf, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "dbus")) + ffStrbufSetS(&options->libDBus, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "XFConf")) + ffStrbufSetS(&options->libXFConf, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "sqlite") || ffStrEqualsIgnCase(key, "sqlite3")) + ffStrbufSetS(&options->libSQLite3, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "rpm")) + ffStrbufSetS(&options->librpm, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "imagemagick")) + ffStrbufSetS(&options->libImageMagick, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "z")) + ffStrbufSetS(&options->libZ, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "chafa")) + ffStrbufSetS(&options->libChafa, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "egl")) + ffStrbufSetS(&options->libEGL, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "glx")) + ffStrbufSetS(&options->libGLX, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "osmesa")) + ffStrbufSetS(&options->libOSMesa, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "opencl")) + ffStrbufSetS(&options->libOpenCL, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "pulse")) + ffStrbufSetS(&options->libPulse, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "nm")) + ffStrbufSetS(&options->libnm, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "ddcutil")) + ffStrbufSetS(&options->libDdcutil, yyjson_get_str(val)); + else + return "Unknown library property"; + } + + return NULL; +} + +bool ffOptionsParseLibraryCommandLine(FFOptionsLibrary* options, const char* key, const char* value) +{ + if(ffStrStartsWithIgnCase(key, "--lib-")) + { + const char* subkey = key + strlen("--lib-"); + if(ffStrEqualsIgnCase(subkey, "PCI")) + ffOptionParseString(key, value, &options->libPCI); + else if(ffStrEqualsIgnCase(subkey, "vulkan")) + ffOptionParseString(key, value, &options->libVulkan); + else if(ffStrEqualsIgnCase(subkey, "freetype")) + ffOptionParseString(key, value, &options->libfreetype); + else if(ffStrEqualsIgnCase(subkey, "wayland")) + ffOptionParseString(key, value, &options->libWayland); + else if(ffStrEqualsIgnCase(subkey, "xcb-randr")) + ffOptionParseString(key, value, &options->libXcbRandr); + else if(ffStrEqualsIgnCase(subkey, "xcb")) + ffOptionParseString(key, value, &options->libXcb); + else if(ffStrEqualsIgnCase(subkey, "Xrandr")) + ffOptionParseString(key, value, &options->libXrandr); + else if(ffStrEqualsIgnCase(subkey, "X11")) + ffOptionParseString(key, value, &options->libX11); + else if(ffStrEqualsIgnCase(subkey, "gio")) + ffOptionParseString(key, value, &options->libGIO); + else if(ffStrEqualsIgnCase(subkey, "DConf")) + ffOptionParseString(key, value, &options->libDConf); + else if(ffStrEqualsIgnCase(subkey, "dbus")) + ffOptionParseString(key, value, &options->libDBus); + else if(ffStrEqualsIgnCase(subkey, "XFConf")) + ffOptionParseString(key, value, &options->libXFConf); + else if(ffStrEqualsIgnCase(subkey, "sqlite") || ffStrEqualsIgnCase(subkey, "sqlite3")) + ffOptionParseString(key, value, &options->libSQLite3); + else if(ffStrEqualsIgnCase(subkey, "rpm")) + ffOptionParseString(key, value, &options->librpm); + else if(ffStrEqualsIgnCase(subkey, "imagemagick")) + ffOptionParseString(key, value, &options->libImageMagick); + else if(ffStrEqualsIgnCase(subkey, "z")) + ffOptionParseString(key, value, &options->libZ); + else if(ffStrEqualsIgnCase(subkey, "chafa")) + ffOptionParseString(key, value, &options->libChafa); + else if(ffStrEqualsIgnCase(subkey, "egl")) + ffOptionParseString(key, value, &options->libEGL); + else if(ffStrEqualsIgnCase(subkey, "glx")) + ffOptionParseString(key, value, &options->libGLX); + else if(ffStrEqualsIgnCase(subkey, "osmesa")) + ffOptionParseString(key, value, &options->libOSMesa); + else if(ffStrEqualsIgnCase(subkey, "opencl")) + ffOptionParseString(key, value, &options->libOpenCL); + else if(ffStrEqualsIgnCase(subkey, "pulse")) + ffOptionParseString(key, value, &options->libPulse); + else if(ffStrEqualsIgnCase(subkey, "nm")) + ffOptionParseString(key, value, &options->libnm); + else if(ffStrEqualsIgnCase(subkey, "ddcutil")) + ffOptionParseString(key, value, &options->libDdcutil); + else + return false; + } + else + return false; + + return true; +} + +void ffOptionsInitLibrary(FFOptionsLibrary* options) +{ + ffStrbufInit(&options->libPCI); + ffStrbufInit(&options->libVulkan); + ffStrbufInit(&options->libWayland); + ffStrbufInit(&options->libXcbRandr); + ffStrbufInit(&options->libXcb); + ffStrbufInit(&options->libXrandr); + ffStrbufInit(&options->libX11); + ffStrbufInit(&options->libGIO); + ffStrbufInit(&options->libDConf); + ffStrbufInit(&options->libDBus); + ffStrbufInit(&options->libXFConf); + ffStrbufInit(&options->libSQLite3); + ffStrbufInit(&options->librpm); + ffStrbufInit(&options->libImageMagick); + ffStrbufInit(&options->libZ); + ffStrbufInit(&options->libChafa); + ffStrbufInit(&options->libEGL); + ffStrbufInit(&options->libGLX); + ffStrbufInit(&options->libOSMesa); + ffStrbufInit(&options->libOpenCL); + ffStrbufInit(&options->libfreetype); + ffStrbufInit(&options->libPulse); + ffStrbufInit(&options->libnm); + ffStrbufInit(&options->libDdcutil); +} + +void ffOptionsDestroyLibrary(FFOptionsLibrary* options) +{ + ffStrbufDestroy(&options->libPCI); + ffStrbufDestroy(&options->libVulkan); + ffStrbufDestroy(&options->libWayland); + ffStrbufDestroy(&options->libXcbRandr); + ffStrbufDestroy(&options->libXcb); + ffStrbufDestroy(&options->libXrandr); + ffStrbufDestroy(&options->libX11); + ffStrbufDestroy(&options->libGIO); + ffStrbufDestroy(&options->libDConf); + ffStrbufDestroy(&options->libDBus); + ffStrbufDestroy(&options->libXFConf); + ffStrbufDestroy(&options->libSQLite3); + ffStrbufDestroy(&options->librpm); + ffStrbufDestroy(&options->libImageMagick); + ffStrbufDestroy(&options->libZ); + ffStrbufDestroy(&options->libChafa); + ffStrbufDestroy(&options->libEGL); + ffStrbufDestroy(&options->libGLX); + ffStrbufDestroy(&options->libOSMesa); + ffStrbufDestroy(&options->libOpenCL); + ffStrbufDestroy(&options->libfreetype); + ffStrbufDestroy(&options->libPulse); + ffStrbufDestroy(&options->libnm); + ffStrbufDestroy(&options->libDdcutil); +} diff --git a/src/options/library.h b/src/options/library.h new file mode 100644 index 000000000..6cfde64a7 --- /dev/null +++ b/src/options/library.h @@ -0,0 +1,36 @@ +#pragma once + +#include "util/FFstrbuf.h" + +typedef struct FFOptionsLibrary +{ + FFstrbuf libPCI; + FFstrbuf libVulkan; + FFstrbuf libWayland; + FFstrbuf libXcbRandr; + FFstrbuf libXcb; + FFstrbuf libXrandr; + FFstrbuf libX11; + FFstrbuf libGIO; + FFstrbuf libDConf; + FFstrbuf libDBus; + FFstrbuf libXFConf; + FFstrbuf libSQLite3; + FFstrbuf librpm; + FFstrbuf libImageMagick; + FFstrbuf libZ; + FFstrbuf libChafa; + FFstrbuf libEGL; + FFstrbuf libGLX; + FFstrbuf libOSMesa; + FFstrbuf libOpenCL; + FFstrbuf libfreetype; + FFstrbuf libPulse; + FFstrbuf libnm; + FFstrbuf libDdcutil; +} FFOptionsLibrary; + +const char* ffOptionsParseLibraryJsonConfig(FFOptionsLibrary* options, yyjson_val* root); +bool ffOptionsParseLibraryCommandLine(FFOptionsLibrary* options, const char* key, const char* value); +void ffOptionsInitLibrary(FFOptionsLibrary* options); +void ffOptionsDestroyLibrary(FFOptionsLibrary* options); From bd898e4006cfef46155b0ee0fd2920e50b37f46c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 09:50:51 +0800 Subject: [PATCH 034/100] Wifi (macOS): additional fix of Sonoma compatibility --- src/detection/wifi/wifi_apple.m | 78 +++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/src/detection/wifi/wifi_apple.m b/src/detection/wifi/wifi_apple.m index 68a86808b..188e0b29f 100644 --- a/src/detection/wifi/wifi_apple.m +++ b/src/detection/wifi/wifi_apple.m @@ -24,11 +24,11 @@ const char* ffDetectWifi(FFlist* result) item->conn.txRate = 0.0/0.0; ffStrbufAppendS(&item->inf.description, inf.interfaceName.UTF8String); - ffStrbufAppendS(&item->inf.status, inf.powerOn ? "Power On" : "Power Off"); + ffStrbufSetStatic(&item->inf.status, inf.powerOn ? "Power On" : "Power Off"); if(!inf.powerOn) continue; - ffStrbufAppendS(&item->conn.status, inf.serviceActive ? "Active" : "Inactive"); + ffStrbufSetStatic(&item->conn.status, inf.serviceActive ? "Active" : "Inactive"); if(!inf.serviceActive) continue; @@ -52,28 +52,28 @@ const char* ffDetectWifi(FFlist* result) switch(inf.activePHYMode) { case kCWPHYModeNone: - ffStrbufAppendS(&item->conn.protocol, "none"); + ffStrbufSetStatic(&item->conn.protocol, "none"); break; case kCWPHYMode11a: - ffStrbufAppendS(&item->conn.protocol, "802.11a"); + ffStrbufSetStatic(&item->conn.protocol, "802.11a"); break; case kCWPHYMode11b: - ffStrbufAppendS(&item->conn.protocol, "802.11b"); + ffStrbufSetStatic(&item->conn.protocol, "802.11b"); break; case kCWPHYMode11g: - ffStrbufAppendS(&item->conn.protocol, "802.11g"); + ffStrbufSetStatic(&item->conn.protocol, "802.11g"); break; case kCWPHYMode11n: - ffStrbufAppendS(&item->conn.protocol, "802.11n (Wi-Fi 4)"); + ffStrbufSetStatic(&item->conn.protocol, "802.11n (Wi-Fi 4)"); break; case kCWPHYMode11ac: - ffStrbufAppendS(&item->conn.protocol, "802.11ac (Wi-Fi 5)"); + ffStrbufSetStatic(&item->conn.protocol, "802.11ac (Wi-Fi 5)"); break; case 6 /*kCWPHYMode11ax*/: - ffStrbufAppendS(&item->conn.protocol, "802.11ax (Wi-Fi 6)"); + ffStrbufSetStatic(&item->conn.protocol, "802.11ax (Wi-Fi 6)"); break; case 7 /*kCWPHYMode11be?*/: - ffStrbufAppendS(&item->conn.protocol, "802.11be (Wi-Fi 7)"); + ffStrbufSetStatic(&item->conn.protocol, "802.11be (Wi-Fi 7)"); break; default: ffStrbufAppendF(&item->conn.protocol, "Unknown (%ld)", inf.activePHYMode); @@ -85,55 +85,79 @@ const char* ffDetectWifi(FFlist* result) switch(inf.security) { case kCWSecurityNone: - ffStrbufAppendS(&item->conn.security, "Insecure"); + ffStrbufSetStatic(&item->conn.security, "Insecure"); break; case kCWSecurityWEP: - ffStrbufAppendS(&item->conn.security, "WEP"); + ffStrbufSetStatic(&item->conn.security, "WEP"); break; case kCWSecurityWPAPersonal: - ffStrbufAppendS(&item->conn.security, "WPA Personal"); + ffStrbufSetStatic(&item->conn.security, "WPA Personal"); break; case kCWSecurityWPAPersonalMixed: - ffStrbufAppendS(&item->conn.security, "WPA Persional Mixed"); + ffStrbufSetStatic(&item->conn.security, "WPA Persional Mixed"); break; case kCWSecurityWPA2Personal: - ffStrbufAppendS(&item->conn.security, "WPA2 Personal"); + ffStrbufSetStatic(&item->conn.security, "WPA2 Personal"); break; case kCWSecurityPersonal: - ffStrbufAppendS(&item->conn.security, "Personal"); + ffStrbufSetStatic(&item->conn.security, "Personal"); break; case kCWSecurityDynamicWEP: - ffStrbufAppendS(&item->conn.security, "Dynamic WEP"); + ffStrbufSetStatic(&item->conn.security, "Dynamic WEP"); break; case kCWSecurityWPAEnterprise: - ffStrbufAppendS(&item->conn.security, "WPA Enterprise"); + ffStrbufSetStatic(&item->conn.security, "WPA Enterprise"); break; case kCWSecurityWPAEnterpriseMixed: - ffStrbufAppendS(&item->conn.security, "WPA Enterprise Mixed"); + ffStrbufSetStatic(&item->conn.security, "WPA Enterprise Mixed"); break; case kCWSecurityWPA2Enterprise: - ffStrbufAppendS(&item->conn.security, "WPA2 Enterprise"); + ffStrbufSetStatic(&item->conn.security, "WPA2 Enterprise"); break; case kCWSecurityEnterprise: - ffStrbufAppendS(&item->conn.security, "Enterprise"); + ffStrbufSetStatic(&item->conn.security, "Enterprise"); break; case kCWSecurityWPA3Personal: - ffStrbufAppendS(&item->conn.security, "WPA3 Personal"); + ffStrbufSetStatic(&item->conn.security, "WPA3 Personal"); break; case kCWSecurityWPA3Enterprise: - ffStrbufAppendS(&item->conn.security, "WPA3 Enterprise"); + ffStrbufSetStatic(&item->conn.security, "WPA3 Enterprise"); break; case kCWSecurityWPA3Transition: - ffStrbufAppendS(&item->conn.security, "WPA3 Transition"); + ffStrbufSetStatic(&item->conn.security, "WPA3 Transition"); break; case 14 /*kCWSecurityOWE*/: - ffStrbufAppendS(&item->conn.security, "OWE"); + ffStrbufSetStatic(&item->conn.security, "OWE"); break; case 15 /*kCWSecurityOWETransition*/: - ffStrbufAppendS(&item->conn.security, "OWE Transition"); + ffStrbufSetStatic(&item->conn.security, "OWE Transition"); break; case kCWSecurityUnknown: - // Ignore + // Sonoma... + { + if (!ffProcessAppendStdOut(&item->conn.security, (char* []) { + "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport", + "-I", + NULL + })) + { + { + uint32_t ssidIndex = ffStrbufFirstIndexS(&item->conn.security, " SSID: "); + if (ssidIndex == item->conn.security.length) break; + ssidIndex += (uint32_t) strlen(" SSID: "); + uint32_t ssidEndIndex = ffStrbufNextIndexC(&item->conn.security, ssidIndex, '\n'); + if (item->conn.ssid.length != ssidEndIndex - ssidIndex) break; + } + + uint32_t linkAuthIndex = ffStrbufFirstIndexS(&item->conn.security, " link auth: "); + if (linkAuthIndex == item->conn.security.length) break; + linkAuthIndex += (uint32_t) strlen(" link auth: "); + uint32_t linkAuthEndIndex = ffStrbufNextIndexC(&item->conn.security, linkAuthIndex, '\n'); + ffStrbufSubstrBefore(&item->conn.security, linkAuthEndIndex); + ffStrbufSubstrAfter(&item->conn.security, linkAuthIndex - 1); + ffStrbufUpperCase(&item->conn.security); + } + } break; default: ffStrbufAppendF(&item->conn.security, "Unknown (%ld)", inf.security); From 399e2235d4bd463a45bbbd1bc212a27beb389454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 10:26:15 +0800 Subject: [PATCH 035/100] Options (Display): split code --- CMakeLists.txt | 1 + src/common/bar.c | 44 ++-- src/common/commandoption.c | 10 +- src/common/init.c | 51 +---- src/common/jsonconfig.c | 147 +------------- src/common/jsonconfig.h | 1 - src/common/parsing.c | 8 +- src/common/printing.c | 22 +- src/fastfetch.c | 149 ++------------ src/fastfetch.h | 43 +--- src/logo/logo.c | 12 +- src/modules/battery/battery.c | 6 +- src/modules/brightness/brightness.c | 4 +- src/modules/colors/colors.c | 2 +- src/modules/cpuusage/cpuusage.c | 4 +- src/modules/disk/disk.c | 10 +- src/modules/memory/memory.c | 6 +- src/modules/swap/swap.c | 10 +- src/modules/title/title.c | 12 +- src/options/display.c | 298 ++++++++++++++++++++++++++++ src/options/display.h | 51 +++++ 21 files changed, 452 insertions(+), 439 deletions(-) create mode 100644 src/options/display.c create mode 100644 src/options/display.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 76aaf7612..67bab51bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,6 +354,7 @@ set(LIBFASTFETCH_SRC src/modules/wifi/wifi.c src/modules/wm/wm.c src/modules/wmtheme/wmtheme.c + src/options/display.c src/options/modules.c src/options/logo.c src/options/general.c diff --git a/src/common/bar.c b/src/common/bar.c index e250188d7..4bd6e76ba 100644 --- a/src/common/bar.c +++ b/src/common/bar.c @@ -6,15 +6,17 @@ void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t { assert(green <= 100 && yellow <= 100 && red <= 100); - uint32_t blocksPercent = (uint32_t) (percent / 100.0 * instance.config.barWidth + 0.5); - uint32_t blocksGreen = (uint32_t) (green / 100.0 * instance.config.barWidth + 0.5); - uint32_t blocksYellow = (uint32_t) (yellow / 100.0 * instance.config.barWidth + 0.5); - uint32_t blocksRed = (uint32_t) (red / 100.0 * instance.config.barWidth + 0.5); - assert(blocksPercent <= instance.config.barWidth); + const FFOptionsDisplay* options = &instance.config.display; - if(instance.config.barBorder) + uint32_t blocksPercent = (uint32_t) (percent / 100.0 * options->barWidth + 0.5); + uint32_t blocksGreen = (uint32_t) (green / 100.0 * options->barWidth + 0.5); + uint32_t blocksYellow = (uint32_t) (yellow / 100.0 * options->barWidth + 0.5); + uint32_t blocksRed = (uint32_t) (red / 100.0 * options->barWidth + 0.5); + assert(blocksPercent <= options->barWidth); + + if(options->barBorder) { - if(!instance.config.pipe) + if(!options->pipe) ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m[ "); else ffStrbufAppendS(buffer, "[ "); @@ -22,7 +24,7 @@ void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t for (uint32_t i = 0; i < blocksPercent; ++i) { - if(!instance.config.pipe) + if(!options->pipe) { if (i == blocksGreen) ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_GREEN "m"); @@ -31,26 +33,26 @@ void ffAppendPercentBar(FFstrbuf* buffer, double percent, uint8_t green, uint8_t else if (i == blocksRed) ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m"); } - ffStrbufAppend(buffer, &instance.config.barCharElapsed); + ffStrbufAppend(buffer, &options->barCharElapsed); } - if (blocksPercent < instance.config.barWidth) + if (blocksPercent < options->barWidth) { - if(!instance.config.pipe) + if(!options->pipe) ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m"); - for (uint32_t i = blocksPercent; i < instance.config.barWidth; ++i) - ffStrbufAppend(buffer, &instance.config.barCharTotal); + for (uint32_t i = blocksPercent; i < options->barWidth; ++i) + ffStrbufAppend(buffer, &options->barCharTotal); } - if(instance.config.barBorder) + if(options->barBorder) { - if(!instance.config.pipe) + if(!options->pipe) ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_WHITE "m ]"); else ffStrbufAppendS(buffer, " ]"); } - if(!instance.config.pipe) + if(!options->pipe) ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); } @@ -67,12 +69,14 @@ void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t { assert(green <= 100 && yellow <= 100); - bool colored = !!(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_COLOR_BIT); + const FFOptionsDisplay* options = &instance.config.display; + + bool colored = !!(options->percentType & FF_PERCENTAGE_TYPE_NUM_COLOR_BIT); if (parentheses) ffStrbufAppendC(buffer, '('); - if (colored && !instance.config.pipe) + if (colored && !options->pipe) { if(green < yellow) { @@ -93,9 +97,9 @@ void ffAppendPercentNum(FFstrbuf* buffer, double percent, uint8_t green, uint8_t ffStrbufAppendS(buffer, "\e[" FF_COLOR_FG_LIGHT_RED "m"); } } - ffStrbufAppendF(buffer, "%.*f%%", instance.config.percentNdigits, percent); + ffStrbufAppendF(buffer, "%.*f%%", options->percentNdigits, percent); - if (colored && !instance.config.pipe) + if (colored && !options->pipe) { ffStrbufAppendS(buffer, FASTFETCH_TEXT_MODIFIER_RESET); } diff --git a/src/common/commandoption.c b/src/common/commandoption.c index 507393dc3..262675cba 100644 --- a/src/common/commandoption.c +++ b/src/common/commandoption.c @@ -131,12 +131,12 @@ void ffPrintCommandOption(FFdata* data) data->structure.chars[colonIndex] = '\0'; uint64_t ms = 0; - if(instance.config.stat) + if(instance.config.display.stat) ms = ffTimeGetTick(); parseStructureCommand(data->structure.chars + startIndex, &data->customValues); - if(instance.config.stat) + if(instance.config.display.stat) { ms = ffTimeGetTick() - ms; @@ -149,7 +149,7 @@ void ffPrintCommandOption(FFdata* data) { char str[32]; int len = snprintf(str, sizeof str, "%" PRIu64 "ms", ms); - if(instance.config.pipe) + if(instance.config.display.pipe) puts(str); else printf("\033[s\033[1A\033[9999999C\033[%dD%s\033[u", len, str); // Save; Up 1; Right 9999999; Left ; Print ; Load @@ -157,7 +157,7 @@ void ffPrintCommandOption(FFdata* data) } #if defined(_WIN32) - if (!resultDoc && !instance.config.noBuffer) fflush(stdout); + if (!resultDoc && !instance.config.display.noBuffer) fflush(stdout); #endif startIndex = colonIndex + 1; @@ -169,7 +169,7 @@ void ffMigrateCommandOptionToJsonc(FFdata* data) //If we don't have a custom structure, use the default one if(data->structure.length == 0) ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); - instance.config.stat = false; + instance.config.display.stat = false; ffPrintCommandOption(data); yyjson_mut_write_fp(stdout, instance.state.migrateConfigDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); } diff --git a/src/common/init.c b/src/common/init.c index 35e363a6c..8c5d4c7a2 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -33,38 +33,7 @@ static void defaultConfig(void) ffOptionsInitLogo(&instance.config.logo); ffOptionsInitGeneral(&instance.config.general); ffOptionsInitModules(&instance.config.modules); - - ffStrbufInit(&instance.config.colorKeys); - ffStrbufInit(&instance.config.colorTitle); - instance.config.brightColor = true; - ffStrbufInitStatic(&instance.config.keyValueSeparator, ": "); - - instance.config.showErrors = false; - instance.config.pipe = !isatty(STDOUT_FILENO); - - #ifdef NDEBUG - instance.config.disableLinewrap = !instance.config.pipe; - instance.config.hideCursor = !instance.config.pipe; - #else - instance.config.disableLinewrap = false; - instance.config.hideCursor = false; - #endif - - instance.config.binaryPrefixType = FF_BINARY_PREFIX_TYPE_IEC; - instance.config.sizeNdigits = 2; - instance.config.sizeMaxPrefix = UINT8_MAX; - instance.config.temperatureUnit = FF_TEMPERATURE_UNIT_CELSIUS; - instance.config.stat = false; - instance.config.noBuffer = false; - instance.config.keyWidth = 0; - - ffStrbufInitStatic(&instance.config.barCharElapsed, "â– "); - ffStrbufInitStatic(&instance.config.barCharTotal, "-"); - instance.config.barWidth = 10; - instance.config.barBorder = true; - instance.config.percentType = 1; - instance.config.percentNdigits = 0; - + ffOptionsInitDisplay(&instance.config.display); ffOptionsInitLibrary(&instance.config.library); } @@ -144,11 +113,11 @@ void ffStart(void) startDetectionThreads(); #endif - ffDisableLinewrap = instance.config.disableLinewrap && !instance.config.pipe && !instance.state.resultDoc; - ffHideCursor = instance.config.hideCursor && !instance.config.pipe && !instance.state.resultDoc; + ffDisableLinewrap = instance.config.display.disableLinewrap && !instance.config.display.pipe && !instance.state.resultDoc; + ffHideCursor = instance.config.display.hideCursor && !instance.config.display.pipe && !instance.state.resultDoc; #ifdef _WIN32 - setvbuf(stdout, NULL, _IOFBF, instance.config.noBuffer ? 0 : 4096); + setvbuf(stdout, NULL, _IOFBF, instance.config.display.noBuffer ? 0 : 4096); SetConsoleCtrlHandler(consoleHandler, TRUE); HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE); DWORD mode = 0; @@ -156,7 +125,7 @@ void ffStart(void) SetConsoleMode(hStdout, mode | ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING); SetConsoleOutputCP(CP_UTF8); #else - if (instance.config.noBuffer) setvbuf(stdout, NULL, _IONBF, 0); + if (instance.config.display.noBuffer) setvbuf(stdout, NULL, _IONBF, 0); struct sigaction action = { .sa_handler = exitSignalHandler }; sigaction(SIGINT, &action, NULL); sigaction(SIGTERM, &action, NULL); @@ -164,7 +133,7 @@ void ffStart(void) #endif //reset everything to default before we start printing - if(!instance.config.pipe && !instance.state.resultDoc) + if(!instance.config.display.pipe && !instance.state.resultDoc) fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); if(ffHideCursor) @@ -189,13 +158,7 @@ static void destroyConfig(void) ffOptionsDestroyLogo(&instance.config.logo); ffOptionsDestroyGeneral(&instance.config.general); ffOptionsDestroyModules(&instance.config.modules); - - ffStrbufDestroy(&instance.config.colorKeys); - ffStrbufDestroy(&instance.config.colorTitle); - ffStrbufDestroy(&instance.config.keyValueSeparator); - ffStrbufDestroy(&instance.config.barCharElapsed); - ffStrbufDestroy(&instance.config.barCharTotal); - + ffOptionsDestroyDisplay(&instance.config.display); ffOptionsDestroyLibrary(&instance.config.library); } diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 5a890ba22..1b32ed8b4 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -178,7 +178,7 @@ static const char* printJsonConfig(bool prepare) yyjson_arr_foreach(modules, idx, max, item) { uint64_t ms = 0; - if(!prepare && instance.config.stat) + if(!prepare && instance.config.display.stat) ms = ffTimeGetTick(); yyjson_val* module = item; @@ -200,7 +200,7 @@ static const char* printJsonConfig(bool prepare) else if(!parseModuleJsonObject(type, module)) return "Unknown module type"; - if(!prepare && instance.config.stat) + if(!prepare && instance.config.display.stat) { ms = ffTimeGetTick() - ms; if (resultDoc) @@ -212,7 +212,7 @@ static const char* printJsonConfig(bool prepare) { char str[32]; int len = snprintf(str, sizeof str, "%" PRIu64 "ms", ms); - if(instance.config.pipe) + if(instance.config.display.pipe) puts(str); else printf("\033[s\033[1A\033[9999999C\033[%dD%s\033[u", len, str); // Save; Up 1; Right 9999999; Left ; Print ; Load @@ -220,152 +220,13 @@ static const char* printJsonConfig(bool prepare) } #if defined(_WIN32) - if (!instance.config.noBuffer && !resultDoc) fflush(stdout); + if (!instance.config.display.noBuffer && !resultDoc) fflush(stdout); #endif } return NULL; } -const char* ffParseDisplayJsonConfig(FFconfig* config) -{ - yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); - assert(root); - - if (!yyjson_is_obj(root)) - return "Invalid JSON config format. Root value must be an object"; - - yyjson_val* object = yyjson_obj_get(root, "display"); - if (!object) return NULL; - if (!yyjson_is_obj(object)) return "Property 'display' must be an object"; - - yyjson_val *key_, *val; - size_t idx, max; - yyjson_obj_foreach(object, idx, max, key_, val) - { - const char* key = yyjson_get_str(key_); - - if (ffStrEqualsIgnCase(key, "stat")) - { - if ((config->stat = yyjson_get_bool(val))) - config->showErrors = true; - } - else if (ffStrEqualsIgnCase(key, "pipe")) - config->pipe = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "showErrors")) - config->showErrors = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "disableLinewrap")) - config->disableLinewrap = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "hideCursor")) - config->hideCursor = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "separator")) - ffStrbufSetS(&config->keyValueSeparator, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "color")) - { - if (yyjson_is_str(val)) - { - ffOptionParseColor(yyjson_get_str(val), &config->colorKeys); - ffStrbufSet(&config->colorTitle, &config->colorKeys); - } - else if (yyjson_is_obj(val)) - { - const char* colorKeys = yyjson_get_str(yyjson_obj_get(val, "keys")); - if (colorKeys) - ffOptionParseColor(colorKeys, &config->colorKeys); - const char* colorTitle = yyjson_get_str(yyjson_obj_get(val, "title")); - if (colorTitle) - ffOptionParseColor(colorTitle, &config->colorTitle); - } - else - return "display.color must be either a string or an object"; - } - else if (ffStrEqualsIgnCase(key, "brightColor")) - config->brightColor = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "binaryPrefix")) - { - int value; - const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { - { "iec", FF_BINARY_PREFIX_TYPE_IEC }, - { "si", FF_BINARY_PREFIX_TYPE_SI }, - { "jedec", FF_BINARY_PREFIX_TYPE_JEDEC }, - {}, - }); - if (error) return error; - config->binaryPrefixType = (FFBinaryPrefixType) value; - } - else if (ffStrEqualsIgnCase(key, "sizeNdigits")) - config->sizeNdigits = (uint8_t) yyjson_get_uint(val); - else if (ffStrEqualsIgnCase(key, "sizeMaxPrefix")) - { - int value; - const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { - { "B", 0 }, - { "kB", 1 }, - { "MB", 2 }, - { "GB", 3 }, - { "TB", 4 }, - { "PB", 5 }, - { "EB", 6 }, - { "ZB", 7 }, - { "YB", 8 }, - {} - }); - if (error) return error; - config->sizeMaxPrefix = (uint8_t) value; - } - else if (ffStrEqualsIgnCase(key, "temperatureUnit")) - { - int value; - const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { - { "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS }, - { "C", FF_TEMPERATURE_UNIT_CELSIUS }, - { "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT }, - { "F", FF_TEMPERATURE_UNIT_FAHRENHEIT }, - { "KELVIN", FF_TEMPERATURE_UNIT_KELVIN }, - { "K", FF_TEMPERATURE_UNIT_KELVIN }, - {}, - }); - if (error) return error; - config->temperatureUnit = (FFTemperatureUnit) value; - } - else if (ffStrEqualsIgnCase(key, "percentType")) - config->percentType = (uint8_t) yyjson_get_uint(val); - else if (ffStrEqualsIgnCase(key, "percentNdigits")) - config->percentNdigits = (uint8_t) yyjson_get_uint(val); - else if (ffStrEqualsIgnCase(key, "bar")) - { - if (yyjson_is_obj(val)) - { - const char* charElapsed = yyjson_get_str(yyjson_obj_get(val, "charElapsed")); - if (charElapsed) - ffStrbufSetS(&config->barCharElapsed, charElapsed); - - const char* charTotal = yyjson_get_str(yyjson_obj_get(val, "charTotal")); - if (charTotal) - ffStrbufSetS(&config->barCharTotal, charTotal); - - yyjson_val* border = yyjson_obj_get(val, "border"); - if (border) - config->barBorder = yyjson_get_bool(border); - - yyjson_val* width = yyjson_obj_get(val, "width"); - if (width) - config->barWidth = (uint8_t) yyjson_get_uint(width); - } - else - return "display.bar must be an object"; - } - else if (ffStrEqualsIgnCase(key, "noBuffer")) - config->noBuffer = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "keyWidth")) - config->keyWidth = (uint32_t) yyjson_get_uint(val); - else - return "Unknown display property"; - } - - return NULL; -} - void ffPrintJsonConfig(bool prepare) { const char* error = printJsonConfig(prepare); diff --git a/src/common/jsonconfig.h b/src/common/jsonconfig.h index 2ca3fc950..08f522c5c 100644 --- a/src/common/jsonconfig.h +++ b/src/common/jsonconfig.h @@ -5,7 +5,6 @@ bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs* moduleArgs); const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]); void ffPrintJsonConfig(bool prepare); -const char* ffParseDisplayJsonConfig(FFconfig* config); void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs); yyjson_api_inline bool yyjson_mut_obj_add_strbuf(yyjson_mut_doc *doc, diff --git a/src/common/parsing.c b/src/common/parsing.c index 55a2780fe..5f5b18d04 100644 --- a/src/common/parsing.c +++ b/src/common/parsing.c @@ -65,7 +65,7 @@ static void parseSize(FFstrbuf* result, uint64_t bytes, uint32_t base, const cha double size = (double) bytes; uint8_t counter = 0; - while(size >= base && counter < instance.config.sizeMaxPrefix && prefixes[counter + 1]) + while(size >= base && counter < instance.config.display.sizeMaxPrefix && prefixes[counter + 1]) { size /= base; counter++; @@ -74,12 +74,12 @@ static void parseSize(FFstrbuf* result, uint64_t bytes, uint32_t base, const cha if(counter == 0) ffStrbufAppendF(result, "%"PRIu64" %s", bytes, prefixes[0]); else - ffStrbufAppendF(result, "%.*f %s", instance.config.sizeNdigits, size, prefixes[counter]); + ffStrbufAppendF(result, "%.*f %s", instance.config.display.sizeNdigits, size, prefixes[counter]); } void ffParseSize(uint64_t bytes, FFstrbuf* result) { - switch (instance.config.binaryPrefixType) + switch (instance.config.display.binaryPrefixType) { case FF_BINARY_PREFIX_TYPE_IEC: parseSize(result, bytes, 1024, (const char*[]) {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", NULL}); @@ -98,7 +98,7 @@ void ffParseSize(uint64_t bytes, FFstrbuf* result) void ffParseTemperature(double celsius, FFstrbuf* buffer) { - switch (instance.config.temperatureUnit) + switch (instance.config.display.temperatureUnit) { case FF_TEMPERATURE_UNIT_CELSIUS: ffStrbufAppendF(buffer, "%.1f°C", celsius); diff --git a/src/common/printing.c b/src/common/printing.c index b5a32175b..21df19cb3 100644 --- a/src/common/printing.c +++ b/src/common/printing.c @@ -14,16 +14,16 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu if(moduleArgs && ffStrbufEqualS(&moduleArgs->key, " ")) return; - if(!instance.config.pipe) + if(!instance.config.display.pipe) { fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); - if (instance.config.brightColor) + if (instance.config.display.brightColor) fputs(FASTFETCH_TEXT_MODIFIER_BOLT, stdout); if(moduleArgs && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR) && moduleArgs->keyColor.length > 0) ffPrintColor(&moduleArgs->keyColor); else - ffPrintColor(&instance.config.colorKeys); + ffPrintColor(&instance.config.display.colorKeys); } //NULL check is required for modules with custom keys, e.g. disk with the folder path @@ -43,18 +43,18 @@ void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModu ffStrbufWriteTo(&key, stdout); } - if(!instance.config.pipe) + if(!instance.config.display.pipe) fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); - ffStrbufWriteTo(&instance.config.keyValueSeparator, stdout); + ffStrbufWriteTo(&instance.config.display.keyValueSeparator, stdout); - if(!instance.config.pipe) + if(!instance.config.display.pipe) fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); - if (!instance.config.pipe && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH)) + if (!instance.config.display.pipe && !(printType & FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH)) { - uint32_t keyWidth = moduleArgs && moduleArgs->keyWidth > 0 ? moduleArgs->keyWidth : instance.config.keyWidth; + uint32_t keyWidth = moduleArgs && moduleArgs->keyWidth > 0 ? moduleArgs->keyWidth : instance.config.display.keyWidth; if (keyWidth > 0) printf("\e[%uG", (unsigned) (keyWidth + instance.state.logoWidth)); } @@ -77,17 +77,17 @@ void ffPrintFormatString(const char* moduleName, uint8_t moduleIndex, const FFMo static void printError(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType, const char* message, va_list arguments) { - if(!instance.config.showErrors) + if(!instance.config.display.showErrors) return; ffPrintLogoAndKey(moduleName, moduleIndex, moduleArgs, printType); - if(!instance.config.pipe) + if(!instance.config.display.pipe) fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout); vprintf(message, arguments); - if(!instance.config.pipe) + if(!instance.config.display.pipe) fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); putchar('\n'); diff --git a/src/fastfetch.c b/src/fastfetch.c index 4a1cd470e..234d58e81 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -332,16 +332,6 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val exit(414); } -static inline void optionCheckString(const char* key, const char* value, FFstrbuf* buffer) -{ - if(value == NULL) - { - fprintf(stderr, "Error: usage: %s \n", key); - exit(477); - } - ffStrbufEnsureFree(buffer, 63); //This is not needed, as ffStrbufSetS will resize capacity if needed, but giving a higher start should improve performance -} - static void printVersion() { FFVersionResult result = {}; @@ -527,135 +517,20 @@ static void parseOption(FFdata* data, const char* key, const char* value) break; } } - - /////////////////// - //General options// - /////////////////// - - else if(ffOptionsParseGeneralCommandLine(&instance.config.general, key, value)) {} - - //////////////// - //Logo options// - //////////////// - - else if(ffOptionsParseLogoCommandLine(&instance.config.logo, key, value)) {} - - /////////////////// - //Display options// - /////////////////// - - else if(ffStrEqualsIgnCase(key, "--stat")) - { - if((instance.config.stat = ffOptionParseBoolean(value))) - instance.config.showErrors = true; - } - else if(ffStrEqualsIgnCase(key, "--pipe")) - instance.config.pipe = ffOptionParseBoolean(value); - else if(ffStrEqualsIgnCase(key, "--show-errors")) - instance.config.showErrors = ffOptionParseBoolean(value); - else if(ffStrEqualsIgnCase(key, "--disable-linewrap")) - instance.config.disableLinewrap = ffOptionParseBoolean(value); - else if(ffStrEqualsIgnCase(key, "--hide-cursor")) - instance.config.hideCursor = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "-s") || ffStrEqualsIgnCase(key, "--structure")) ffOptionParseString(key, value, &data->structure); - else if(ffStrEqualsIgnCase(key, "--separator")) - ffOptionParseString(key, value, &instance.config.keyValueSeparator); - else if(ffStrEqualsIgnCase(key, "--color")) - { - optionCheckString(key, value, &instance.config.colorKeys); - ffOptionParseColor(value, &instance.config.colorKeys); - ffStrbufSet(&instance.config.colorTitle, &instance.config.colorKeys); - } - else if(ffStrStartsWithIgnCase(key, "--color-")) - { - const char* subkey = key + strlen("--color-"); - if(ffStrEqualsIgnCase(subkey, "keys")) - { - optionCheckString(key, value, &instance.config.colorKeys); - ffOptionParseColor(value, &instance.config.colorKeys); - } - else if(ffStrEqualsIgnCase(subkey, "title")) - { - optionCheckString(key, value, &instance.config.colorTitle); - ffOptionParseColor(value, &instance.config.colorTitle); - } - else - goto error; - } - else if(ffStrEqualsIgnCase(key, "--key-width")) - instance.config.keyWidth = ffOptionParseUInt32(key, value); - else if(ffStrEqualsIgnCase(key, "--bright-color")) - instance.config.brightColor = ffOptionParseBoolean(value); - else if(ffStrEqualsIgnCase(key, "--binary-prefix")) - { - instance.config.binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { - { "iec", FF_BINARY_PREFIX_TYPE_IEC }, - { "si", FF_BINARY_PREFIX_TYPE_SI }, - { "jedec", FF_BINARY_PREFIX_TYPE_JEDEC }, - {} - }); - } - else if(ffStrEqualsIgnCase(key, "--size-ndigits")) - instance.config.sizeNdigits = (uint8_t) ffOptionParseUInt32(key, value); - else if(ffStrEqualsIgnCase(key, "--size-max-prefix")) - { - instance.config.sizeMaxPrefix = (uint8_t) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { - { "B", 0 }, - { "kB", 1 }, - { "MB", 2 }, - { "GB", 3 }, - { "TB", 4 }, - { "PB", 5 }, - { "EB", 6 }, - { "ZB", 7 }, - { "YB", 8 }, - {} - }); - } - else if(ffStrEqualsIgnCase(key, "--temperature-unit")) - { - instance.config.temperatureUnit = (FFTemperatureUnit) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { - { "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS }, - { "C", FF_TEMPERATURE_UNIT_CELSIUS }, - { "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT }, - { "F", FF_TEMPERATURE_UNIT_FAHRENHEIT }, - { "KELVIN", FF_TEMPERATURE_UNIT_KELVIN }, - { "K", FF_TEMPERATURE_UNIT_KELVIN }, - {}, - }); - } - else if(ffStrEqualsIgnCase(key, "--percent-type")) - instance.config.percentType = (uint8_t) ffOptionParseUInt32(key, value); - else if(ffStrEqualsIgnCase(key, "--percent-ndigits")) - instance.config.percentNdigits = (uint8_t) ffOptionParseUInt32(key, value); - else if(ffStrEqualsIgnCase(key, "--no-buffer")) - instance.config.noBuffer = ffOptionParseBoolean(value); - else if(ffStrStartsWithIgnCase(key, "--bar-")) - { - const char* subkey = key + strlen("--bar-"); - if(ffStrEqualsIgnCase(subkey, "char-elapsed")) - ffOptionParseString(key, value, &instance.config.barCharElapsed); - else if(ffStrEqualsIgnCase(subkey, "char-total")) - ffOptionParseString(key, value, &instance.config.barCharTotal); - else if(ffStrEqualsIgnCase(subkey, "width")) - instance.config.barWidth = (uint8_t) ffOptionParseUInt32(key, value); - else if(ffStrEqualsIgnCase(subkey, "border")) - instance.config.barBorder = ffOptionParseBoolean(value); - else - goto error; - } - /////////////////// - //Library options// - /////////////////// - else if(ffOptionsParseLibraryCommandLine(&instance.config.library, key, value)) {} + /////////// + //Options// + /////////// - /////////////////////// - //Module args options// - /////////////////////// - - else if(ffParseModuleOptions(key, value)) {} + else if( + ffOptionsParseGeneralCommandLine(&instance.config.general, key, value) || + ffOptionsParseLogoCommandLine(&instance.config.logo, key, value) || + ffOptionsParseDisplayCommandLine(&instance.config.display, key, value) || + ffOptionsParseLibraryCommandLine(&instance.config.library, key, value) || + ffParseModuleOptions(key, value) + ) {} ////////////////// //Unknown option// @@ -741,7 +616,7 @@ static void run(FFdata* data) error || (error = ffOptionsParseLogoJsonConfig(&instance.config.logo, root)) || (error = ffOptionsParseGeneralJsonConfig(&instance.config.general, root)) || - (error = ffParseDisplayJsonConfig(&instance.config)) || + (error = ffOptionsParseDisplayJsonConfig(&instance.config.display, root)) || (error = ffOptionsParseLibraryJsonConfig(&instance.config.library, root)) || false ) { @@ -760,7 +635,7 @@ static void run(FFdata* data) ffStart(); #if defined(_WIN32) - if (!instance.config.noBuffer) fflush(stdout); + if (!instance.config.display.noBuffer) fflush(stdout); #endif if (useJsonConfig) diff --git a/src/fastfetch.h b/src/fastfetch.h index 7be79ab60..e97e6c7bc 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -25,55 +25,16 @@ #include "options/modules.h" #include "options/logo.h" +#include "options/display.h" #include "options/general.h" #include "options/library.h" -typedef enum FFBinaryPrefixType -{ - FF_BINARY_PREFIX_TYPE_IEC, // 1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard) - FF_BINARY_PREFIX_TYPE_SI, // 1000 Bytes = 1 KB, 1000 KB = 1 MB, ... - FF_BINARY_PREFIX_TYPE_JEDEC, // 1024 Bytes = 1 kB, 1024 K = 1 MB, ... -} FFBinaryPrefixType; - -typedef enum FFTemperatureUnit -{ - FF_TEMPERATURE_UNIT_CELSIUS, - FF_TEMPERATURE_UNIT_FAHRENHEIT, - FF_TEMPERATURE_UNIT_KELVIN, -} FFTemperatureUnit; - typedef struct FFconfig { FFOptionsLogo logo; + FFOptionsDisplay display; FFOptionsGeneral general; FFOptionsModules modules; - - //If one of those is empty, ffLogoPrint will set them - FFstrbuf colorKeys; - FFstrbuf colorTitle; - - bool brightColor; - - FFstrbuf keyValueSeparator; - - bool stat; - bool pipe; //disables logo and all escape sequences - bool showErrors; - bool disableLinewrap; - bool hideCursor; - FFBinaryPrefixType binaryPrefixType; - uint8_t sizeNdigits; - uint8_t sizeMaxPrefix; - FFTemperatureUnit temperatureUnit; - FFstrbuf barCharElapsed; - FFstrbuf barCharTotal; - uint8_t barWidth; - bool barBorder; - uint8_t percentType; - uint8_t percentNdigits; - bool noBuffer; - uint32_t keyWidth; - FFOptionsLibrary library; } FFconfig; diff --git a/src/logo/logo.c b/src/logo/logo.c index 582343fb7..7c4205a40 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -61,7 +61,7 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement) FF_STRBUF_AUTO_DESTROY result = ffStrbufCreateA(2048); - if (instance.config.brightColor) + if (instance.config.display.brightColor) ffStrbufAppendS(&result, FASTFETCH_TEXT_MODIFIER_BOLT); ffStrbufAppendNC(&result, options->paddingTop, '\n'); @@ -212,11 +212,11 @@ void ffLogoPrintChars(const char* data, bool doColorReplacement) static void logoApplyColors(const FFlogo* logo) { - if(instance.config.colorTitle.length == 0) - ffStrbufAppendS(&instance.config.colorTitle, logo->colorTitle ? logo->colorTitle : logo->colors[0]); + if(instance.config.display.colorTitle.length == 0) + ffStrbufAppendS(&instance.config.display.colorTitle, logo->colorTitle ? logo->colorTitle : logo->colors[0]); - if(instance.config.colorKeys.length == 0) - ffStrbufAppendS(&instance.config.colorKeys, logo->colorKeys ? logo->colorKeys : logo->colors[1]); + if(instance.config.display.colorKeys.length == 0) + ffStrbufAppendS(&instance.config.display.colorKeys, logo->colorKeys ? logo->colorKeys : logo->colors[1]); } static bool logoHasName(const FFlogo* logo, const FFstrbuf* name, bool small) @@ -462,7 +462,7 @@ void ffLogoPrint(void) //In pipe mode, we don't have a logo or padding. //We also don't need to set main color, because it won't be printed anyway. //So we can return quickly here. - if(instance.config.pipe || instance.state.resultDoc) + if(instance.config.display.pipe || instance.state.resultDoc) { instance.state.logoHeight = 0; instance.state.logoWidth = 0; diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index 6a503cdc0..7318289fd 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -16,13 +16,13 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); bool showStatus = - !(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) && + !(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT) && result->status.length > 0 && ffStrbufIgnCaseCompS(&result->status, "Unknown") != 0; if(result->capacity >= 0) { - if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { if(result->capacity <= 20) ffAppendPercentBar(&str, result->capacity, 100, 100, 0); @@ -32,7 +32,7 @@ static void printBattery(FFBatteryOptions* options, FFBatteryResult* result, uin ffAppendPercentBar(&str, result->capacity, 0, 100, 100); } - if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) { if(str.length > 0) ffStrbufAppendC(&str, ' '); diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index df676f893..4bcabec82 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -50,12 +50,12 @@ void ffPrintBrightness(FFBrightnessOptions* options) FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY); - if (instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) + if (instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { ffAppendPercentBar(&str, percent, 0, 100, 100); } - if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) { if(str.length > 0) ffStrbufAppendC(&str, ' '); diff --git a/src/modules/colors/colors.c b/src/modules/colors/colors.c index 9d6e65867..239e2ec8b 100644 --- a/src/modules/colors/colors.c +++ b/src/modules/colors/colors.c @@ -6,7 +6,7 @@ void ffPrintColors(FFColorsOptions* options) { - if(instance.config.pipe) + if(instance.config.display.pipe) return; ffPrintLogoAndKey(FF_COLORS_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index 7583e30e3..7a059b1d5 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -47,9 +47,9 @@ void ffPrintCPUUsage(FFCPUUsageOptions* options) FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); if (!options->separate) { - if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) ffAppendPercentBar(&str, avgValue, 0, 50, 80); - if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) { if(str.length > 0) ffStrbufAppendC(&str, ' '); diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 1a1f4b2d8..b465d4845 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -15,7 +15,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) if(options->moduleArgs.key.length == 0) { - if(instance.config.pipe) + if(instance.config.display.pipe) ffStrbufAppendF(&key, "%s (%s)", FF_DISK_MODULE_NAME, disk->mountpoint.chars); else { @@ -57,16 +57,16 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) if(disk->bytesTotal > 0) { - if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { ffAppendPercentBar(&str, bytesPercentage, 0, 50, 80); ffStrbufAppendC(&str, ' '); } - if(!(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) + if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars); - if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) { ffAppendPercentNum(&str, bytesPercentage, 50, 80, str.length > 0); ffStrbufAppendC(&str, ' '); @@ -75,7 +75,7 @@ static void printDisk(FFDiskOptions* options, const FFDisk* disk) else ffStrbufAppendS(&str, "Unknown "); - if(!(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) + if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) { if(disk->filesystem.length) ffStrbufAppendF(&str, "- %s ", disk->filesystem.chars); diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 12d8b1717..c3c00cbe6 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -38,16 +38,16 @@ void ffPrintMemory(FFMemoryOptions* options) { FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); - if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { ffAppendPercentBar(&str, percentage, 0, 50, 80); ffStrbufAppendC(&str, ' '); } - if(!(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) + if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars); - if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) ffAppendPercentNum(&str, percentage, 50, 80, str.length > 0); ffStrbufTrimRight(&str, ' '); diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index 392002f10..25f9cf6a3 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -35,26 +35,26 @@ void ffPrintSwap(FFSwapOptions* options) FF_STRBUF_AUTO_DESTROY str = ffStrbufCreate(); if (storage.bytesTotal == 0) { - if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { ffAppendPercentBar(&str, 0, 0, 50, 80); ffStrbufAppendC(&str, ' '); } - if(!(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) + if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) ffStrbufAppendS(&str, "Disabled"); } else { - if(instance.config.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_BAR_BIT) { ffAppendPercentBar(&str, percentage, 0, 50, 80); ffStrbufAppendC(&str, ' '); } - if(!(instance.config.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) + if(!(instance.config.display.percentType & FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT)) ffStrbufAppendF(&str, "%s / %s ", usedPretty.chars, totalPretty.chars); - if(instance.config.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) + if(instance.config.display.percentType & FF_PERCENTAGE_TYPE_NUM_BIT) ffAppendPercentNum(&str, percentage, 50, 80, str.length > 0); } diff --git a/src/modules/title/title.c b/src/modules/title/title.c index fc37c3bc8..daad8413f 100644 --- a/src/modules/title/title.c +++ b/src/modules/title/title.c @@ -8,19 +8,19 @@ static void appendText(FFstrbuf* output, const FFstrbuf* text, const FFstrbuf* color) { - if (!instance.config.pipe) + if (!instance.config.display.pipe) { - if (instance.config.brightColor) + if (instance.config.display.brightColor) ffStrbufAppendS(output, FASTFETCH_TEXT_MODIFIER_BOLT); if (color->length > 0) ffStrbufAppendF(output, "\e[%sm", color->chars); - else if (instance.config.colorTitle.length > 0) - ffStrbufAppendF(output, "\e[%sm", instance.config.colorTitle.chars); + else if (instance.config.display.colorTitle.length > 0) + ffStrbufAppendF(output, "\e[%sm", instance.config.display.colorTitle.chars); } ffStrbufAppend(output, text); - if(!instance.config.pipe) + if(!instance.config.display.pipe) ffStrbufAppendS(output, FASTFETCH_TEXT_MODIFIER_RESET); } @@ -37,7 +37,7 @@ void ffPrintTitle(FFTitleOptions* options) appendText(&hostNameColored, &hostName, &options->colorHost); FF_STRBUF_AUTO_DESTROY atColored = ffStrbufCreate(); - if (!instance.config.pipe && options->colorAt.length > 0) + if (!instance.config.display.pipe && options->colorAt.length > 0) { ffStrbufAppendF(&atColored, "\e[%sm", options->colorAt.chars); ffStrbufAppendC(&atColored, '@'); diff --git a/src/options/display.c b/src/options/display.c new file mode 100644 index 000000000..5386d8b5c --- /dev/null +++ b/src/options/display.c @@ -0,0 +1,298 @@ +#include "fastfetch.h" +#include "common/jsonconfig.h" +#include "util/stringUtils.h" +#include "options/display.h" + +#include + +const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_val* root) +{ + yyjson_val* object = yyjson_obj_get(root, "display"); + if (!object) return NULL; + if (!yyjson_is_obj(object)) return "Property 'display' must be an object"; + + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(object, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + + if (ffStrEqualsIgnCase(key, "stat")) + { + if ((options->stat = yyjson_get_bool(val))) + options->showErrors = true; + } + else if (ffStrEqualsIgnCase(key, "pipe")) + options->pipe = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "showErrors")) + options->showErrors = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "disableLinewrap")) + options->disableLinewrap = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "hideCursor")) + options->hideCursor = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "separator")) + ffStrbufSetS(&options->keyValueSeparator, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "color")) + { + if (yyjson_is_str(val)) + { + ffOptionParseColor(yyjson_get_str(val), &options->colorKeys); + ffStrbufSet(&options->colorTitle, &options->colorKeys); + } + else if (yyjson_is_obj(val)) + { + const char* colorKeys = yyjson_get_str(yyjson_obj_get(val, "keys")); + if (colorKeys) + ffOptionParseColor(colorKeys, &options->colorKeys); + const char* colorTitle = yyjson_get_str(yyjson_obj_get(val, "title")); + if (colorTitle) + ffOptionParseColor(colorTitle, &options->colorTitle); + } + else + return "display.color must be either a string or an object"; + } + else if (ffStrEqualsIgnCase(key, "brightColor")) + options->brightColor = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "binaryPrefix")) + { + int value; + const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { + { "iec", FF_BINARY_PREFIX_TYPE_IEC }, + { "si", FF_BINARY_PREFIX_TYPE_SI }, + { "jedec", FF_BINARY_PREFIX_TYPE_JEDEC }, + {}, + }); + if (error) return error; + options->binaryPrefixType = (FFBinaryPrefixType) value; + } + else if (ffStrEqualsIgnCase(key, "sizeNdigits")) + options->sizeNdigits = (uint8_t) yyjson_get_uint(val); + else if (ffStrEqualsIgnCase(key, "sizeMaxPrefix")) + { + int value; + const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { + { "B", 0 }, + { "kB", 1 }, + { "MB", 2 }, + { "GB", 3 }, + { "TB", 4 }, + { "PB", 5 }, + { "EB", 6 }, + { "ZB", 7 }, + { "YB", 8 }, + {} + }); + if (error) return error; + options->sizeMaxPrefix = (uint8_t) value; + } + else if (ffStrEqualsIgnCase(key, "temperatureUnit")) + { + int value; + const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { + { "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS }, + { "C", FF_TEMPERATURE_UNIT_CELSIUS }, + { "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT }, + { "F", FF_TEMPERATURE_UNIT_FAHRENHEIT }, + { "KELVIN", FF_TEMPERATURE_UNIT_KELVIN }, + { "K", FF_TEMPERATURE_UNIT_KELVIN }, + {}, + }); + if (error) return error; + options->temperatureUnit = (FFTemperatureUnit) value; + } + else if (ffStrEqualsIgnCase(key, "percentType")) + options->percentType = (uint8_t) yyjson_get_uint(val); + else if (ffStrEqualsIgnCase(key, "percentNdigits")) + options->percentNdigits = (uint8_t) yyjson_get_uint(val); + else if (ffStrEqualsIgnCase(key, "bar")) + { + if (yyjson_is_obj(val)) + { + const char* charElapsed = yyjson_get_str(yyjson_obj_get(val, "charElapsed")); + if (charElapsed) + ffStrbufSetS(&options->barCharElapsed, charElapsed); + + const char* charTotal = yyjson_get_str(yyjson_obj_get(val, "charTotal")); + if (charTotal) + ffStrbufSetS(&options->barCharTotal, charTotal); + + yyjson_val* border = yyjson_obj_get(val, "border"); + if (border) + options->barBorder = yyjson_get_bool(border); + + yyjson_val* width = yyjson_obj_get(val, "width"); + if (width) + options->barWidth = (uint8_t) yyjson_get_uint(width); + } + else + return "display.bar must be an object"; + } + else if (ffStrEqualsIgnCase(key, "noBuffer")) + options->noBuffer = yyjson_get_bool(val); + else if (ffStrEqualsIgnCase(key, "keyWidth")) + options->keyWidth = (uint32_t) yyjson_get_uint(val); + else + return "Unknown display property"; + } + + return NULL; +} + +static inline void optionCheckString(const char* key, const char* value, FFstrbuf* buffer) +{ + if(value == NULL) + { + fprintf(stderr, "Error: usage: %s \n", key); + exit(477); + } + ffStrbufEnsureFree(buffer, 63); //This is not needed, as ffStrbufSetS will resize capacity if needed, but giving a higher start should improve performance +} + +bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key, const char* value) +{ + if(ffStrEqualsIgnCase(key, "--stat")) + { + if((options->stat = ffOptionParseBoolean(value))) + options->showErrors = true; + } + else if(ffStrEqualsIgnCase(key, "--pipe")) + options->pipe = ffOptionParseBoolean(value); + else if(ffStrEqualsIgnCase(key, "--show-errors")) + options->showErrors = ffOptionParseBoolean(value); + else if(ffStrEqualsIgnCase(key, "--disable-linewrap")) + options->disableLinewrap = ffOptionParseBoolean(value); + else if(ffStrEqualsIgnCase(key, "--hide-cursor")) + options->hideCursor = ffOptionParseBoolean(value); + else if(ffStrEqualsIgnCase(key, "--separator")) + ffOptionParseString(key, value, &options->keyValueSeparator); + else if(ffStrEqualsIgnCase(key, "--color")) + { + optionCheckString(key, value, &options->colorKeys); + ffOptionParseColor(value, &options->colorKeys); + ffStrbufSet(&options->colorTitle, &options->colorKeys); + } + else if(ffStrStartsWithIgnCase(key, "--color-")) + { + const char* subkey = key + strlen("--color-"); + if(ffStrEqualsIgnCase(subkey, "keys")) + { + optionCheckString(key, value, &options->colorKeys); + ffOptionParseColor(value, &options->colorKeys); + } + else if(ffStrEqualsIgnCase(subkey, "title")) + { + optionCheckString(key, value, &options->colorTitle); + ffOptionParseColor(value, &options->colorTitle); + } + else + return false; + } + else if(ffStrEqualsIgnCase(key, "--key-width")) + options->keyWidth = ffOptionParseUInt32(key, value); + else if(ffStrEqualsIgnCase(key, "--bright-color")) + options->brightColor = ffOptionParseBoolean(value); + else if(ffStrEqualsIgnCase(key, "--binary-prefix")) + { + options->binaryPrefixType = (FFBinaryPrefixType) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { + { "iec", FF_BINARY_PREFIX_TYPE_IEC }, + { "si", FF_BINARY_PREFIX_TYPE_SI }, + { "jedec", FF_BINARY_PREFIX_TYPE_JEDEC }, + {} + }); + } + else if(ffStrEqualsIgnCase(key, "--size-ndigits")) + options->sizeNdigits = (uint8_t) ffOptionParseUInt32(key, value); + else if(ffStrEqualsIgnCase(key, "--size-max-prefix")) + { + options->sizeMaxPrefix = (uint8_t) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { + { "B", 0 }, + { "kB", 1 }, + { "MB", 2 }, + { "GB", 3 }, + { "TB", 4 }, + { "PB", 5 }, + { "EB", 6 }, + { "ZB", 7 }, + { "YB", 8 }, + {} + }); + } + else if(ffStrEqualsIgnCase(key, "--temperature-unit")) + { + options->temperatureUnit = (FFTemperatureUnit) ffOptionParseEnum(key, value, (FFKeyValuePair[]) { + { "CELSIUS", FF_TEMPERATURE_UNIT_CELSIUS }, + { "C", FF_TEMPERATURE_UNIT_CELSIUS }, + { "FAHRENHEIT", FF_TEMPERATURE_UNIT_FAHRENHEIT }, + { "F", FF_TEMPERATURE_UNIT_FAHRENHEIT }, + { "KELVIN", FF_TEMPERATURE_UNIT_KELVIN }, + { "K", FF_TEMPERATURE_UNIT_KELVIN }, + {}, + }); + } + else if(ffStrEqualsIgnCase(key, "--percent-type")) + options->percentType = (uint8_t) ffOptionParseUInt32(key, value); + else if(ffStrEqualsIgnCase(key, "--percent-ndigits")) + options->percentNdigits = (uint8_t) ffOptionParseUInt32(key, value); + else if(ffStrEqualsIgnCase(key, "--no-buffer")) + options->noBuffer = ffOptionParseBoolean(value); + else if(ffStrStartsWithIgnCase(key, "--bar-")) + { + const char* subkey = key + strlen("--bar-"); + if(ffStrEqualsIgnCase(subkey, "char-elapsed")) + ffOptionParseString(key, value, &options->barCharElapsed); + else if(ffStrEqualsIgnCase(subkey, "char-total")) + ffOptionParseString(key, value, &options->barCharTotal); + else if(ffStrEqualsIgnCase(subkey, "width")) + options->barWidth = (uint8_t) ffOptionParseUInt32(key, value); + else if(ffStrEqualsIgnCase(subkey, "border")) + options->barBorder = ffOptionParseBoolean(value); + else + return false; + } + else + return false; + return true; +} + +void ffOptionsInitDisplay(FFOptionsDisplay* options) +{ + ffStrbufInit(&options->colorKeys); + ffStrbufInit(&options->colorTitle); + options->brightColor = true; + ffStrbufInitStatic(&options->keyValueSeparator, ": "); + + options->showErrors = false; + options->pipe = !isatty(STDOUT_FILENO); + + #ifdef NDEBUG + options->disableLinewrap = !options->pipe; + options->hideCursor = !options->pipe; + #else + options->disableLinewrap = false; + options->hideCursor = false; + #endif + + options->binaryPrefixType = FF_BINARY_PREFIX_TYPE_IEC; + options->sizeNdigits = 2; + options->sizeMaxPrefix = UINT8_MAX; + options->temperatureUnit = FF_TEMPERATURE_UNIT_CELSIUS; + options->stat = false; + options->noBuffer = false; + options->keyWidth = 0; + + ffStrbufInitStatic(&options->barCharElapsed, "â– "); + ffStrbufInitStatic(&options->barCharTotal, "-"); + options->barWidth = 10; + options->barBorder = true; + options->percentType = 1; + options->percentNdigits = 0; +} + +void ffOptionsDestroyDisplay(FFOptionsDisplay* options) +{ + ffStrbufDestroy(&options->colorKeys); + ffStrbufDestroy(&options->colorTitle); + ffStrbufDestroy(&options->keyValueSeparator); + ffStrbufDestroy(&options->barCharElapsed); + ffStrbufDestroy(&options->barCharTotal); +} diff --git a/src/options/display.h b/src/options/display.h new file mode 100644 index 000000000..9bc9aee2b --- /dev/null +++ b/src/options/display.h @@ -0,0 +1,51 @@ +#pragma once + +#include "util/FFstrbuf.h" + +typedef enum FFBinaryPrefixType +{ + FF_BINARY_PREFIX_TYPE_IEC, // 1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard) + FF_BINARY_PREFIX_TYPE_SI, // 1000 Bytes = 1 KB, 1000 KB = 1 MB, ... + FF_BINARY_PREFIX_TYPE_JEDEC, // 1024 Bytes = 1 kB, 1024 K = 1 MB, ... +} FFBinaryPrefixType; + +typedef enum FFTemperatureUnit +{ + FF_TEMPERATURE_UNIT_CELSIUS, + FF_TEMPERATURE_UNIT_FAHRENHEIT, + FF_TEMPERATURE_UNIT_KELVIN, +} FFTemperatureUnit; + +typedef struct FFOptionsDisplay +{ + //If one of those is empty, ffLogoPrint will set them + FFstrbuf colorKeys; + FFstrbuf colorTitle; + + bool brightColor; + + FFstrbuf keyValueSeparator; + + bool stat; + bool pipe; //disables logo and all escape sequences + bool showErrors; + bool disableLinewrap; + bool hideCursor; + FFBinaryPrefixType binaryPrefixType; + uint8_t sizeNdigits; + uint8_t sizeMaxPrefix; + FFTemperatureUnit temperatureUnit; + FFstrbuf barCharElapsed; + FFstrbuf barCharTotal; + uint8_t barWidth; + bool barBorder; + uint8_t percentType; + uint8_t percentNdigits; + bool noBuffer; + uint32_t keyWidth; +} FFOptionsDisplay; + +const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_val* root); +bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key, const char* value); +void ffOptionsInitDisplay(FFOptionsDisplay* options); +void ffOptionsDestroyDisplay(FFOptionsDisplay* options); From 6c82686283b5cabda06b90c073083475919f7821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 11:02:08 +0800 Subject: [PATCH 036/100] Migration (Display): support display options --- doc/json_schema.json | 21 +++++-- src/fastfetch.c | 1 + src/options/display.c | 125 ++++++++++++++++++++++++++++++++++++++++++ src/options/display.h | 1 + 4 files changed, 142 insertions(+), 6 deletions(-) diff --git a/doc/json_schema.json b/doc/json_schema.json index b099900da..ddb007448 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -344,10 +344,19 @@ "binaryPrefix": { "type": "string", "title": "Set the binary prefix to used when printing bytes", - "enum": [ - "iec", - "si", - "jedec" + "oneOf": [ + { + "const": "iec", + "description": "1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard)" + }, + { + "const": "si", + "description": "1000 Bytes = 1 KB, 1000 KB = 1 MB, ..." + }, + { + "const": "jedec", + "description": "1024 Bytes = 1 kB, 1024 K = 1 MB, ..." + } ] }, "sizeNdigits": { @@ -602,10 +611,10 @@ "oneOf": [ { "title": "Break", - "description": "Print a empty line", "properties": { "type": { - "const": "break" + "const": "break", + "description": "Print a empty line" } }, "additionalProperties": false diff --git a/src/fastfetch.c b/src/fastfetch.c index 234d58e81..6524bfc5b 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -652,6 +652,7 @@ static void run(FFdata* data) static void migrateConfig(FFdata* data) { ffOptionsGenerateLogoJsonConfig(&instance.config.logo, instance.state.migrateConfigDoc); + ffOptionsGenerateDisplayJsonConfig(&instance.config.display, instance.state.migrateConfigDoc); ffMigrateCommandOptionToJsonc(data); } diff --git a/src/options/display.c b/src/options/display.c index 5386d8b5c..6391bc87f 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -296,3 +296,128 @@ void ffOptionsDestroyDisplay(FFOptionsDisplay* options) ffStrbufDestroy(&options->barCharElapsed); ffStrbufDestroy(&options->barCharTotal); } + +void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_doc* doc) +{ + __attribute__((__cleanup__(ffOptionsDestroyDisplay))) FFOptionsDisplay defaultOptions; + ffOptionsInitDisplay(&defaultOptions); + + yyjson_mut_val* obj = yyjson_mut_obj(doc); + + if (options->stat != defaultOptions.stat) + yyjson_mut_obj_add_bool(doc, obj, "stat", options->stat); + + if (options->pipe != defaultOptions.pipe) + yyjson_mut_obj_add_bool(doc, obj, "pipe", options->pipe); + + if (options->showErrors != defaultOptions.showErrors) + yyjson_mut_obj_add_bool(doc, obj, "showErrors", options->showErrors); + + if (options->disableLinewrap != defaultOptions.disableLinewrap) + yyjson_mut_obj_add_bool(doc, obj, "disableLinewrap", options->disableLinewrap); + + if (options->hideCursor != defaultOptions.hideCursor) + yyjson_mut_obj_add_bool(doc, obj, "hideCursor", options->hideCursor); + + if (!ffStrbufEqual(&options->keyValueSeparator, &defaultOptions.keyValueSeparator)) + yyjson_mut_obj_add_strbuf(doc, obj, "separator", &options->keyValueSeparator); + + { + yyjson_mut_val* color = yyjson_mut_obj(doc); + if (!ffStrbufEqual(&options->colorKeys, &defaultOptions.colorKeys)) + yyjson_mut_obj_add_strbuf(doc, color, "keys", &options->colorKeys); + if (!ffStrbufEqual(&options->colorTitle, &defaultOptions.colorTitle)) + yyjson_mut_obj_add_strbuf(doc, color, "title", &options->colorTitle); + if (yyjson_mut_obj_size(color) > 0) + { + if (yyjson_mut_obj_size(color) == 2 && ffStrbufEqual(&options->colorKeys, &options->colorTitle)) + yyjson_mut_obj_add_strbuf(doc, obj, "color", &options->colorKeys); + else + yyjson_mut_obj_add_val(doc, obj, "color", color); + } + } + + if (options->brightColor != defaultOptions.brightColor) + yyjson_mut_obj_add_bool(doc, obj, "brightColor", options->brightColor); + + if (options->binaryPrefixType != defaultOptions.binaryPrefixType) + { + switch (options->binaryPrefixType) + { + case FF_BINARY_PREFIX_TYPE_IEC: + yyjson_mut_obj_add_str(doc, obj, "binaryPrefix", "iec"); + break; + case FF_BINARY_PREFIX_TYPE_SI: + yyjson_mut_obj_add_str(doc, obj, "binaryPrefix", "si"); + break; + case FF_BINARY_PREFIX_TYPE_JEDEC: + yyjson_mut_obj_add_str(doc, obj, "binaryPrefix", "jedec"); + break; + + } + } + + if (options->sizeNdigits != defaultOptions.sizeNdigits) + yyjson_mut_obj_add_uint(doc, obj, "sizeNdigits", options->sizeNdigits); + + if (options->sizeMaxPrefix != defaultOptions.sizeMaxPrefix && options->sizeMaxPrefix <= 8) + { + yyjson_mut_obj_add_str(doc, obj, "sizeMaxPrefix", ((const char* []) { + "B", + "kB", + "MB", + "GB", + "TB", + "PB", + "EB", + "ZB", + "YB", + })[options->sizeMaxPrefix]); + } + + if (options->temperatureUnit != defaultOptions.temperatureUnit) + { + switch (options->temperatureUnit) + { + case FF_TEMPERATURE_UNIT_CELSIUS: + yyjson_mut_obj_add_str(doc, obj, "temperatureUnit", "C"); + break; + case FF_TEMPERATURE_UNIT_FAHRENHEIT: + yyjson_mut_obj_add_str(doc, obj, "temperatureUnit", "F"); + break; + case FF_TEMPERATURE_UNIT_KELVIN: + yyjson_mut_obj_add_str(doc, obj, "temperatureUnit", "K"); + break; + } + } + + if (options->percentType != defaultOptions.percentType) + yyjson_mut_obj_add_uint(doc, obj, "percentType", options->percentType); + + if (options->percentNdigits != defaultOptions.percentNdigits) + yyjson_mut_obj_add_uint(doc, obj, "percentNdigits", options->percentNdigits); + + { + yyjson_mut_val* bar = yyjson_mut_obj(doc); + if (!ffStrbufEqual(&options->barCharElapsed, &defaultOptions.barCharElapsed)) + yyjson_mut_obj_add_strbuf(doc, bar, "charElapsed", &options->barCharElapsed); + if (!ffStrbufEqual(&options->barCharTotal, &defaultOptions.barCharTotal)) + yyjson_mut_obj_add_strbuf(doc, bar, "charTotal", &options->barCharTotal); + if (options->barBorder != defaultOptions.barBorder) + yyjson_mut_obj_add_bool(doc, bar, "border", options->barBorder); + if (options->barWidth != defaultOptions.barWidth) + yyjson_mut_obj_add_uint(doc, bar, "width", options->barWidth); + + if (yyjson_mut_obj_size(bar) > 0) + yyjson_mut_obj_add_val(doc, obj, "bar", bar); + } + + if (options->noBuffer != defaultOptions.noBuffer) + yyjson_mut_obj_add_bool(doc, obj, "noBuffer", options->noBuffer); + + if (options->keyWidth != defaultOptions.keyWidth) + yyjson_mut_obj_add_uint(doc, obj, "keyWidth", options->keyWidth); + + if (yyjson_mut_obj_size(obj) > 0) + yyjson_mut_obj_add_val(doc, doc->root, "display", obj); +} diff --git a/src/options/display.h b/src/options/display.h index 9bc9aee2b..4591734c5 100644 --- a/src/options/display.h +++ b/src/options/display.h @@ -49,3 +49,4 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va bool ffOptionsParseDisplayCommandLine(FFOptionsDisplay* options, const char* key, const char* value); void ffOptionsInitDisplay(FFOptionsDisplay* options); void ffOptionsDestroyDisplay(FFOptionsDisplay* options); +void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_doc* doc); From d00b301904eccedf682414a0fe2913b99670fc01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 11:11:08 +0800 Subject: [PATCH 037/100] Migration (General): support general options --- src/fastfetch.c | 1 + src/options/general.c | 44 ++++++++++++++++++++++++++++++++++++++++++- src/options/general.h | 1 + 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index 6524bfc5b..9ba0b6782 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -653,6 +653,7 @@ static void migrateConfig(FFdata* data) { ffOptionsGenerateLogoJsonConfig(&instance.config.logo, instance.state.migrateConfigDoc); ffOptionsGenerateDisplayJsonConfig(&instance.config.display, instance.state.migrateConfigDoc); + ffOptionsGenerateGeneralJsonConfig(&instance.config.general, instance.state.migrateConfigDoc); ffMigrateCommandOptionToJsonc(data); } diff --git a/src/options/general.c b/src/options/general.c index 459db3eda..c95062887 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -1,6 +1,7 @@ #include "fastfetch.h" -#include "util/stringUtils.h" +#include "common/jsonconfig.h" #include "options/general.h" +#include "util/stringUtils.h" #include @@ -96,3 +97,44 @@ void ffOptionsDestroyGeneral(FF_MAYBE_UNUSED FFOptionsGeneral* options) ffStrbufDestroy(&options->osFile); #endif } + +void ffOptionsGenerateGeneralJsonConfig(FFOptionsGeneral* options, yyjson_mut_doc* doc) +{ + __attribute__((__cleanup__(ffOptionsDestroyGeneral))) FFOptionsGeneral defaultOptions; + ffOptionsInitGeneral(&defaultOptions); + + yyjson_mut_val* obj = yyjson_mut_obj(doc); + + if (options->allowSlowOperations != defaultOptions.allowSlowOperations) + yyjson_mut_obj_add_bool(doc, obj, "allowSlowOperations", options->allowSlowOperations); + + if (options->multithreading != defaultOptions.multithreading) + yyjson_mut_obj_add_bool(doc, obj, "thread", options->multithreading); + + if (options->processingTimeout != defaultOptions.processingTimeout) + yyjson_mut_obj_add_int(doc, obj, "processingTimeout", options->processingTimeout); + + #if defined(__linux__) || defined(__FreeBSD__) + + if (options->escapeBedrock != defaultOptions.escapeBedrock) + yyjson_mut_obj_add_bool(doc, obj, "escapeBedrock", options->escapeBedrock); + + if (!ffStrbufEqual(&options->playerName, &defaultOptions.playerName)) + yyjson_mut_obj_add_strbuf(doc, obj, "playerName", &options->playerName); + + if (!ffStrbufEqual(&options->osFile, &defaultOptions.osFile)) + yyjson_mut_obj_add_strbuf(doc, obj, "osFile", &options->osFile); + + if (options->dsForceDrm != defaultOptions.dsForceDrm) + yyjson_mut_obj_add_bool(doc, obj, "dsForceDrm", options->dsForceDrm); + + #elif defined(_WIN32) + + if (options->wmiTimeout != defaultOptions.wmiTimeout) + yyjson_mut_obj_add_int(doc, obj, "wmiTimeout", options->wmiTimeout); + + #endif + + if (yyjson_mut_obj_size(obj) > 0) + yyjson_mut_obj_add_val(doc, doc->root, "general", obj); +} diff --git a/src/options/general.h b/src/options/general.h index d9e976245..cb57719d2 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -23,3 +23,4 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key, const char* value); void ffOptionsInitGeneral(FFOptionsGeneral* options); void ffOptionsDestroyGeneral(FFOptionsGeneral* options); +void ffOptionsGenerateGeneralJsonConfig(FFOptionsGeneral* options, yyjson_mut_doc* doc); From 3236ef075d22016b303c0b6cd3951fc8f4307454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 11:20:34 +0800 Subject: [PATCH 038/100] Migration (Library): support library options --- src/fastfetch.c | 1 + src/options/library.c | 85 ++++++++++++++++++++++++++++++++++++++++++- src/options/library.h | 1 + 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index 9ba0b6782..bf617e4e7 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -654,6 +654,7 @@ static void migrateConfig(FFdata* data) ffOptionsGenerateLogoJsonConfig(&instance.config.logo, instance.state.migrateConfigDoc); ffOptionsGenerateDisplayJsonConfig(&instance.config.display, instance.state.migrateConfigDoc); ffOptionsGenerateGeneralJsonConfig(&instance.config.general, instance.state.migrateConfigDoc); + ffOptionsGenerateLibraryJsonConfig(&instance.config.library, instance.state.migrateConfigDoc); ffMigrateCommandOptionToJsonc(data); } diff --git a/src/options/library.c b/src/options/library.c index 5020891f1..327d50a0b 100644 --- a/src/options/library.c +++ b/src/options/library.c @@ -1,5 +1,6 @@ #include "fastfetch.h" -#include "options/library.h" +#include "common/jsonconfig.h" +#include "options/general.h" #include "util/stringUtils.h" const char* ffOptionsParseLibraryJsonConfig(FFOptionsLibrary* options, yyjson_val* root) @@ -82,7 +83,7 @@ bool ffOptionsParseLibraryCommandLine(FFOptionsLibrary* options, const char* key ffOptionParseString(key, value, &options->libfreetype); else if(ffStrEqualsIgnCase(subkey, "wayland")) ffOptionParseString(key, value, &options->libWayland); - else if(ffStrEqualsIgnCase(subkey, "xcb-randr")) + else if(ffStrEqualsIgnCase(subkey, "xcbRandr")) ffOptionParseString(key, value, &options->libXcbRandr); else if(ffStrEqualsIgnCase(subkey, "xcb")) ffOptionParseString(key, value, &options->libXcb); @@ -186,3 +187,83 @@ void ffOptionsDestroyLibrary(FFOptionsLibrary* options) ffStrbufDestroy(&options->libnm); ffStrbufDestroy(&options->libDdcutil); } + +void ffOptionsGenerateLibraryJsonConfig(FFOptionsLibrary* options, yyjson_mut_doc* doc) +{ + __attribute__((__cleanup__(ffOptionsDestroyLibrary))) FFOptionsLibrary defaultOptions; + ffOptionsInitLibrary(&defaultOptions); + + yyjson_mut_val* obj = yyjson_mut_obj(doc); + + if (!ffStrbufEqual(&options->libPCI, &defaultOptions.libPCI)) + yyjson_mut_obj_add_strbuf(doc, obj, "PCI", &options->libPCI); + + if (!ffStrbufEqual(&options->libVulkan, &defaultOptions.libVulkan)) + yyjson_mut_obj_add_strbuf(doc, obj, "vulkan", &options->libVulkan); + + if (!ffStrbufEqual(&options->libWayland, &defaultOptions.libWayland)) + yyjson_mut_obj_add_strbuf(doc, obj, "wayland", &options->libWayland); + + if (!ffStrbufEqual(&options->libXcbRandr, &defaultOptions.libXcbRandr)) + yyjson_mut_obj_add_strbuf(doc, obj, "xcbRandr", &options->libXcbRandr); + + if (!ffStrbufEqual(&options->libXcb, &defaultOptions.libXcb)) + yyjson_mut_obj_add_strbuf(doc, obj, "xcb", &options->libXcb); + + if (!ffStrbufEqual(&options->libXrandr, &defaultOptions.libXrandr)) + yyjson_mut_obj_add_strbuf(doc, obj, "Xrandr", &options->libXrandr); + + if (!ffStrbufEqual(&options->libX11, &defaultOptions.libX11)) + yyjson_mut_obj_add_strbuf(doc, obj, "X11", &options->libX11); + + if (!ffStrbufEqual(&options->libGIO, &defaultOptions.libGIO)) + yyjson_mut_obj_add_strbuf(doc, obj, "gio", &options->libGIO); + + if (!ffStrbufEqual(&options->libDConf, &defaultOptions.libDConf)) + yyjson_mut_obj_add_strbuf(doc, obj, "DConf", &options->libDConf); + + if (!ffStrbufEqual(&options->libDBus, &defaultOptions.libDBus)) + yyjson_mut_obj_add_strbuf(doc, obj, "dbus", &options->libDBus); + + if (!ffStrbufEqual(&options->libXFConf, &defaultOptions.libXFConf)) + yyjson_mut_obj_add_strbuf(doc, obj, "XFConf", &options->libXFConf); + + if (!ffStrbufEqual(&options->libSQLite3, &defaultOptions.libSQLite3)) + yyjson_mut_obj_add_strbuf(doc, obj, "sqlite", &options->libSQLite3); + + if (!ffStrbufEqual(&options->librpm, &defaultOptions.librpm)) + yyjson_mut_obj_add_strbuf(doc, obj, "rpm", &options->librpm); + + if (!ffStrbufEqual(&options->libImageMagick, &defaultOptions.libImageMagick)) + yyjson_mut_obj_add_strbuf(doc, obj, "ImageMagick", &options->libImageMagick); + + if (!ffStrbufEqual(&options->libZ, &defaultOptions.libZ)) + yyjson_mut_obj_add_strbuf(doc, obj, "z", &options->libZ); + + if (!ffStrbufEqual(&options->libChafa, &defaultOptions.libChafa)) + yyjson_mut_obj_add_strbuf(doc, obj, "chafa", &options->libChafa); + + if (!ffStrbufEqual(&options->libEGL, &defaultOptions.libEGL)) + yyjson_mut_obj_add_strbuf(doc, obj, "egl", &options->libEGL); + + if (!ffStrbufEqual(&options->libGLX, &defaultOptions.libGLX)) + yyjson_mut_obj_add_strbuf(doc, obj, "glx", &options->libGLX); + + if (!ffStrbufEqual(&options->libOSMesa, &defaultOptions.libOSMesa)) + yyjson_mut_obj_add_strbuf(doc, obj, "OSMesa", &options->libOSMesa); + + if (!ffStrbufEqual(&options->libOpenCL, &defaultOptions.libOpenCL)) + yyjson_mut_obj_add_strbuf(doc, obj, "OpenCL", &options->libOpenCL); + + if (!ffStrbufEqual(&options->libPulse, &defaultOptions.libPulse)) + yyjson_mut_obj_add_strbuf(doc, obj, "pulse", &options->libPulse); + + if (!ffStrbufEqual(&options->libnm, &defaultOptions.libnm)) + yyjson_mut_obj_add_strbuf(doc, obj, "nm", &options->libnm); + + if (!ffStrbufEqual(&options->libDdcutil, &defaultOptions.libDdcutil)) + yyjson_mut_obj_add_strbuf(doc, obj, "ddcutil", &options->libDdcutil); + + if (yyjson_mut_obj_size(obj) > 0) + yyjson_mut_obj_add_val(doc, doc->root, "library", obj); +} diff --git a/src/options/library.h b/src/options/library.h index 6cfde64a7..1b4b5fd12 100644 --- a/src/options/library.h +++ b/src/options/library.h @@ -34,3 +34,4 @@ const char* ffOptionsParseLibraryJsonConfig(FFOptionsLibrary* options, yyjson_va bool ffOptionsParseLibraryCommandLine(FFOptionsLibrary* options, const char* key, const char* value); void ffOptionsInitLibrary(FFOptionsLibrary* options); void ffOptionsDestroyLibrary(FFOptionsLibrary* options); +void ffOptionsGenerateLibraryJsonConfig(FFOptionsLibrary* options, yyjson_mut_doc* doc); From 23def0a1c7684498e4ee6dd03d7b259fcd729d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 11:33:04 +0800 Subject: [PATCH 039/100] Options (Library): add definitions only when used on the platform --- src/options/library.c | 128 ++++++++++++++++++++++++------------------ src/options/library.h | 15 +++-- 2 files changed, 81 insertions(+), 62 deletions(-) diff --git a/src/options/library.c b/src/options/library.c index 327d50a0b..1708d3148 100644 --- a/src/options/library.c +++ b/src/options/library.c @@ -15,10 +15,22 @@ const char* ffOptionsParseLibraryJsonConfig(FFOptionsLibrary* options, yyjson_va { const char* key = yyjson_get_str(key_); - if (ffStrEqualsIgnCase(key, "pci")) - ffStrbufSetS(&options->libPCI, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "vulkan")) + if (ffStrEqualsIgnCase(key, "vulkan")) ffStrbufSetS(&options->libVulkan, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "opencl")) + ffStrbufSetS(&options->libOpenCL, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "sqlite") || ffStrEqualsIgnCase(key, "sqlite3")) + ffStrbufSetS(&options->libSQLite3, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "imagemagick")) + ffStrbufSetS(&options->libImageMagick, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "chafa")) + ffStrbufSetS(&options->libChafa, yyjson_get_str(val)); + else if (ffStrEqualsIgnCase(key, "z")) + ffStrbufSetS(&options->libZ, yyjson_get_str(val)); + +#if defined(__linux__) || defined(__FreeBSD__) + else if (ffStrEqualsIgnCase(key, "pci")) + ffStrbufSetS(&options->libPCI, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "freetype")) ffStrbufSetS(&options->libfreetype, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "wayland")) @@ -39,30 +51,22 @@ const char* ffOptionsParseLibraryJsonConfig(FFOptionsLibrary* options, yyjson_va ffStrbufSetS(&options->libDBus, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "XFConf")) ffStrbufSetS(&options->libXFConf, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "sqlite") || ffStrEqualsIgnCase(key, "sqlite3")) - ffStrbufSetS(&options->libSQLite3, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "rpm")) ffStrbufSetS(&options->librpm, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "imagemagick")) - ffStrbufSetS(&options->libImageMagick, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "z")) - ffStrbufSetS(&options->libZ, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "chafa")) - ffStrbufSetS(&options->libChafa, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "egl")) ffStrbufSetS(&options->libEGL, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "glx")) ffStrbufSetS(&options->libGLX, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "osmesa")) ffStrbufSetS(&options->libOSMesa, yyjson_get_str(val)); - else if (ffStrEqualsIgnCase(key, "opencl")) - ffStrbufSetS(&options->libOpenCL, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "pulse")) ffStrbufSetS(&options->libPulse, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "nm")) ffStrbufSetS(&options->libnm, yyjson_get_str(val)); else if (ffStrEqualsIgnCase(key, "ddcutil")) ffStrbufSetS(&options->libDdcutil, yyjson_get_str(val)); +#endif + else return "Unknown library property"; } @@ -75,10 +79,22 @@ bool ffOptionsParseLibraryCommandLine(FFOptionsLibrary* options, const char* key if(ffStrStartsWithIgnCase(key, "--lib-")) { const char* subkey = key + strlen("--lib-"); - if(ffStrEqualsIgnCase(subkey, "PCI")) - ffOptionParseString(key, value, &options->libPCI); - else if(ffStrEqualsIgnCase(subkey, "vulkan")) + if(ffStrEqualsIgnCase(subkey, "vulkan")) ffOptionParseString(key, value, &options->libVulkan); + else if(ffStrEqualsIgnCase(subkey, "opencl")) + ffOptionParseString(key, value, &options->libOpenCL); + else if(ffStrEqualsIgnCase(subkey, "sqlite") || ffStrEqualsIgnCase(subkey, "sqlite3")) + ffOptionParseString(key, value, &options->libSQLite3); + else if(ffStrEqualsIgnCase(subkey, "imagemagick")) + ffOptionParseString(key, value, &options->libImageMagick); + else if(ffStrEqualsIgnCase(subkey, "chafa")) + ffOptionParseString(key, value, &options->libChafa); + else if(ffStrEqualsIgnCase(subkey, "z")) + ffOptionParseString(key, value, &options->libZ); + +#if defined(__linux__) || defined(__FreeBSD__) + else if(ffStrEqualsIgnCase(subkey, "PCI")) + ffOptionParseString(key, value, &options->libPCI); else if(ffStrEqualsIgnCase(subkey, "freetype")) ffOptionParseString(key, value, &options->libfreetype); else if(ffStrEqualsIgnCase(subkey, "wayland")) @@ -99,30 +115,22 @@ bool ffOptionsParseLibraryCommandLine(FFOptionsLibrary* options, const char* key ffOptionParseString(key, value, &options->libDBus); else if(ffStrEqualsIgnCase(subkey, "XFConf")) ffOptionParseString(key, value, &options->libXFConf); - else if(ffStrEqualsIgnCase(subkey, "sqlite") || ffStrEqualsIgnCase(subkey, "sqlite3")) - ffOptionParseString(key, value, &options->libSQLite3); else if(ffStrEqualsIgnCase(subkey, "rpm")) ffOptionParseString(key, value, &options->librpm); - else if(ffStrEqualsIgnCase(subkey, "imagemagick")) - ffOptionParseString(key, value, &options->libImageMagick); - else if(ffStrEqualsIgnCase(subkey, "z")) - ffOptionParseString(key, value, &options->libZ); - else if(ffStrEqualsIgnCase(subkey, "chafa")) - ffOptionParseString(key, value, &options->libChafa); else if(ffStrEqualsIgnCase(subkey, "egl")) ffOptionParseString(key, value, &options->libEGL); else if(ffStrEqualsIgnCase(subkey, "glx")) ffOptionParseString(key, value, &options->libGLX); else if(ffStrEqualsIgnCase(subkey, "osmesa")) ffOptionParseString(key, value, &options->libOSMesa); - else if(ffStrEqualsIgnCase(subkey, "opencl")) - ffOptionParseString(key, value, &options->libOpenCL); else if(ffStrEqualsIgnCase(subkey, "pulse")) ffOptionParseString(key, value, &options->libPulse); else if(ffStrEqualsIgnCase(subkey, "nm")) ffOptionParseString(key, value, &options->libnm); else if(ffStrEqualsIgnCase(subkey, "ddcutil")) ffOptionParseString(key, value, &options->libDdcutil); +#endif + else return false; } @@ -134,8 +142,15 @@ bool ffOptionsParseLibraryCommandLine(FFOptionsLibrary* options, const char* key void ffOptionsInitLibrary(FFOptionsLibrary* options) { - ffStrbufInit(&options->libPCI); ffStrbufInit(&options->libVulkan); + ffStrbufInit(&options->libOpenCL); + ffStrbufInit(&options->libSQLite3); + ffStrbufInit(&options->libImageMagick); + ffStrbufInit(&options->libChafa); + ffStrbufInit(&options->libZ); + +#if defined(__linux__) || defined(__FreeBSD__) + ffStrbufInit(&options->libPCI); ffStrbufInit(&options->libWayland); ffStrbufInit(&options->libXcbRandr); ffStrbufInit(&options->libXcb); @@ -145,25 +160,28 @@ void ffOptionsInitLibrary(FFOptionsLibrary* options) ffStrbufInit(&options->libDConf); ffStrbufInit(&options->libDBus); ffStrbufInit(&options->libXFConf); - ffStrbufInit(&options->libSQLite3); ffStrbufInit(&options->librpm); - ffStrbufInit(&options->libImageMagick); - ffStrbufInit(&options->libZ); - ffStrbufInit(&options->libChafa); ffStrbufInit(&options->libEGL); ffStrbufInit(&options->libGLX); ffStrbufInit(&options->libOSMesa); - ffStrbufInit(&options->libOpenCL); ffStrbufInit(&options->libfreetype); ffStrbufInit(&options->libPulse); ffStrbufInit(&options->libnm); ffStrbufInit(&options->libDdcutil); +#endif } void ffOptionsDestroyLibrary(FFOptionsLibrary* options) { - ffStrbufDestroy(&options->libPCI); ffStrbufDestroy(&options->libVulkan); + ffStrbufDestroy(&options->libOpenCL); + ffStrbufDestroy(&options->libSQLite3); + ffStrbufDestroy(&options->libImageMagick); + ffStrbufDestroy(&options->libChafa); + ffStrbufDestroy(&options->libZ); + +#if defined(__linux__) || defined(__FreeBSD__) + ffStrbufDestroy(&options->libPCI); ffStrbufDestroy(&options->libWayland); ffStrbufDestroy(&options->libXcbRandr); ffStrbufDestroy(&options->libXcb); @@ -173,19 +191,15 @@ void ffOptionsDestroyLibrary(FFOptionsLibrary* options) ffStrbufDestroy(&options->libDConf); ffStrbufDestroy(&options->libDBus); ffStrbufDestroy(&options->libXFConf); - ffStrbufDestroy(&options->libSQLite3); ffStrbufDestroy(&options->librpm); - ffStrbufDestroy(&options->libImageMagick); - ffStrbufDestroy(&options->libZ); - ffStrbufDestroy(&options->libChafa); ffStrbufDestroy(&options->libEGL); ffStrbufDestroy(&options->libGLX); ffStrbufDestroy(&options->libOSMesa); - ffStrbufDestroy(&options->libOpenCL); ffStrbufDestroy(&options->libfreetype); ffStrbufDestroy(&options->libPulse); ffStrbufDestroy(&options->libnm); ffStrbufDestroy(&options->libDdcutil); +#endif } void ffOptionsGenerateLibraryJsonConfig(FFOptionsLibrary* options, yyjson_mut_doc* doc) @@ -195,12 +209,28 @@ void ffOptionsGenerateLibraryJsonConfig(FFOptionsLibrary* options, yyjson_mut_do yyjson_mut_val* obj = yyjson_mut_obj(doc); - if (!ffStrbufEqual(&options->libPCI, &defaultOptions.libPCI)) - yyjson_mut_obj_add_strbuf(doc, obj, "PCI", &options->libPCI); - if (!ffStrbufEqual(&options->libVulkan, &defaultOptions.libVulkan)) yyjson_mut_obj_add_strbuf(doc, obj, "vulkan", &options->libVulkan); + if (!ffStrbufEqual(&options->libOpenCL, &defaultOptions.libOpenCL)) + yyjson_mut_obj_add_strbuf(doc, obj, "OpenCL", &options->libOpenCL); + + if (!ffStrbufEqual(&options->libSQLite3, &defaultOptions.libSQLite3)) + yyjson_mut_obj_add_strbuf(doc, obj, "sqlite", &options->libSQLite3); + + if (!ffStrbufEqual(&options->libImageMagick, &defaultOptions.libImageMagick)) + yyjson_mut_obj_add_strbuf(doc, obj, "ImageMagick", &options->libImageMagick); + + if (!ffStrbufEqual(&options->libChafa, &defaultOptions.libChafa)) + yyjson_mut_obj_add_strbuf(doc, obj, "chafa", &options->libChafa); + + if (!ffStrbufEqual(&options->libZ, &defaultOptions.libZ)) + yyjson_mut_obj_add_strbuf(doc, obj, "z", &options->libZ); + +#if defined(__linux__) || defined(__FreeBSD__) + if (!ffStrbufEqual(&options->libPCI, &defaultOptions.libPCI)) + yyjson_mut_obj_add_strbuf(doc, obj, "PCI", &options->libPCI); + if (!ffStrbufEqual(&options->libWayland, &defaultOptions.libWayland)) yyjson_mut_obj_add_strbuf(doc, obj, "wayland", &options->libWayland); @@ -228,21 +258,9 @@ void ffOptionsGenerateLibraryJsonConfig(FFOptionsLibrary* options, yyjson_mut_do if (!ffStrbufEqual(&options->libXFConf, &defaultOptions.libXFConf)) yyjson_mut_obj_add_strbuf(doc, obj, "XFConf", &options->libXFConf); - if (!ffStrbufEqual(&options->libSQLite3, &defaultOptions.libSQLite3)) - yyjson_mut_obj_add_strbuf(doc, obj, "sqlite", &options->libSQLite3); - if (!ffStrbufEqual(&options->librpm, &defaultOptions.librpm)) yyjson_mut_obj_add_strbuf(doc, obj, "rpm", &options->librpm); - if (!ffStrbufEqual(&options->libImageMagick, &defaultOptions.libImageMagick)) - yyjson_mut_obj_add_strbuf(doc, obj, "ImageMagick", &options->libImageMagick); - - if (!ffStrbufEqual(&options->libZ, &defaultOptions.libZ)) - yyjson_mut_obj_add_strbuf(doc, obj, "z", &options->libZ); - - if (!ffStrbufEqual(&options->libChafa, &defaultOptions.libChafa)) - yyjson_mut_obj_add_strbuf(doc, obj, "chafa", &options->libChafa); - if (!ffStrbufEqual(&options->libEGL, &defaultOptions.libEGL)) yyjson_mut_obj_add_strbuf(doc, obj, "egl", &options->libEGL); @@ -252,9 +270,6 @@ void ffOptionsGenerateLibraryJsonConfig(FFOptionsLibrary* options, yyjson_mut_do if (!ffStrbufEqual(&options->libOSMesa, &defaultOptions.libOSMesa)) yyjson_mut_obj_add_strbuf(doc, obj, "OSMesa", &options->libOSMesa); - if (!ffStrbufEqual(&options->libOpenCL, &defaultOptions.libOpenCL)) - yyjson_mut_obj_add_strbuf(doc, obj, "OpenCL", &options->libOpenCL); - if (!ffStrbufEqual(&options->libPulse, &defaultOptions.libPulse)) yyjson_mut_obj_add_strbuf(doc, obj, "pulse", &options->libPulse); @@ -263,6 +278,7 @@ void ffOptionsGenerateLibraryJsonConfig(FFOptionsLibrary* options, yyjson_mut_do if (!ffStrbufEqual(&options->libDdcutil, &defaultOptions.libDdcutil)) yyjson_mut_obj_add_strbuf(doc, obj, "ddcutil", &options->libDdcutil); +#endif if (yyjson_mut_obj_size(obj) > 0) yyjson_mut_obj_add_val(doc, doc->root, "library", obj); diff --git a/src/options/library.h b/src/options/library.h index 1b4b5fd12..02bf17794 100644 --- a/src/options/library.h +++ b/src/options/library.h @@ -4,8 +4,15 @@ typedef struct FFOptionsLibrary { - FFstrbuf libPCI; FFstrbuf libVulkan; + FFstrbuf libOpenCL; + FFstrbuf libSQLite3; + FFstrbuf libImageMagick; + FFstrbuf libChafa; + FFstrbuf libZ; + +#if defined(__linux__) || defined(__FreeBSD__) + FFstrbuf libPCI; FFstrbuf libWayland; FFstrbuf libXcbRandr; FFstrbuf libXcb; @@ -15,19 +22,15 @@ typedef struct FFOptionsLibrary FFstrbuf libDConf; FFstrbuf libDBus; FFstrbuf libXFConf; - FFstrbuf libSQLite3; FFstrbuf librpm; - FFstrbuf libImageMagick; - FFstrbuf libZ; - FFstrbuf libChafa; FFstrbuf libEGL; FFstrbuf libGLX; FFstrbuf libOSMesa; - FFstrbuf libOpenCL; FFstrbuf libfreetype; FFstrbuf libPulse; FFstrbuf libnm; FFstrbuf libDdcutil; +#endif } FFOptionsLibrary; const char* ffOptionsParseLibraryJsonConfig(FFOptionsLibrary* options, yyjson_val* root); From 6a0df7ae499e6582bcd2f9b1616dcc8449123cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 14:06:47 +0800 Subject: [PATCH 040/100] Migration: simplify json result --- src/common/commandoption.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/common/commandoption.c b/src/common/commandoption.c index 262675cba..c68ae3b6f 100644 --- a/src/common/commandoption.c +++ b/src/common/commandoption.c @@ -18,14 +18,21 @@ static inline yyjson_mut_val* genJsonConfig(FFModuleBaseInfo* baseInfo) if (!modules) modules = yyjson_mut_obj_add_arr(doc, doc->root, "modules"); - yyjson_mut_val* module = yyjson_mut_arr_add_obj(doc, modules); - FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateS(baseInfo->name); - ffStrbufLowerCase(&type); - yyjson_mut_obj_add_strbuf(doc, module, "type", &type); - + yyjson_mut_val* module = yyjson_mut_obj(doc); if (baseInfo->generateJsonConfig) baseInfo->generateJsonConfig(baseInfo, doc, module); + FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateS(baseInfo->name); + ffStrbufLowerCase(&type); + + if (yyjson_mut_obj_size(module) > 0) + { + yyjson_mut_obj_add_strbuf(doc, module, "type", &type); + yyjson_mut_arr_add_val(modules, module); + } + else + yyjson_mut_arr_add_strbuf(doc, modules, &type); + return module; } From 72d138f8c41159400c5eceab1b268afc4cf0d5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 14:28:47 +0800 Subject: [PATCH 041/100] Migration (Modules): only generate objects when necessary --- src/common/commandoption.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/common/commandoption.c b/src/common/commandoption.c index c68ae3b6f..4d5df49e3 100644 --- a/src/common/commandoption.c +++ b/src/common/commandoption.c @@ -19,17 +19,15 @@ static inline yyjson_mut_val* genJsonConfig(FFModuleBaseInfo* baseInfo) modules = yyjson_mut_obj_add_arr(doc, doc->root, "modules"); yyjson_mut_val* module = yyjson_mut_obj(doc); + FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateS(baseInfo->name); + ffStrbufLowerCase(&type); + yyjson_mut_obj_add_strbuf(doc, module, "type", &type); + if (baseInfo->generateJsonConfig) baseInfo->generateJsonConfig(baseInfo, doc, module); - FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateS(baseInfo->name); - ffStrbufLowerCase(&type); - - if (yyjson_mut_obj_size(module) > 0) - { - yyjson_mut_obj_add_strbuf(doc, module, "type", &type); + if (yyjson_mut_obj_size(module) > 1) yyjson_mut_arr_add_val(modules, module); - } else yyjson_mut_arr_add_strbuf(doc, modules, &type); From f45654620fef755ac147457283a8b463d3124ea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 15:39:28 +0800 Subject: [PATCH 042/100] Global: code refactor --- src/common/commandoption.c | 148 +++++++++++++++++++------------------ src/common/commandoption.h | 5 +- src/common/jsonconfig.c | 41 +++++----- src/common/jsonconfig.h | 2 +- src/fastfetch.c | 9 ++- 5 files changed, 107 insertions(+), 98 deletions(-) diff --git a/src/common/commandoption.c b/src/common/commandoption.c index 4d5df49e3..21ecf9582 100644 --- a/src/common/commandoption.c +++ b/src/common/commandoption.c @@ -9,62 +9,6 @@ #include #include -static inline yyjson_mut_val* genJsonConfig(FFModuleBaseInfo* baseInfo) -{ - yyjson_mut_doc* doc = instance.state.migrateConfigDoc; - if (__builtin_expect(!doc, true)) return NULL; - - yyjson_mut_val* modules = yyjson_mut_obj_get(doc->root, "modules"); - if (!modules) - modules = yyjson_mut_obj_add_arr(doc, doc->root, "modules"); - - yyjson_mut_val* module = yyjson_mut_obj(doc); - FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateS(baseInfo->name); - ffStrbufLowerCase(&type); - yyjson_mut_obj_add_strbuf(doc, module, "type", &type); - - if (baseInfo->generateJsonConfig) - baseInfo->generateJsonConfig(baseInfo, doc, module); - - if (yyjson_mut_obj_size(module) > 1) - yyjson_mut_arr_add_val(modules, module); - else - yyjson_mut_arr_add_strbuf(doc, modules, &type); - - return module; -} - -static inline yyjson_mut_val* genJsonResult(FFModuleBaseInfo* baseInfo) -{ - yyjson_mut_doc* doc = instance.state.resultDoc; - if (__builtin_expect(!doc, true)) return NULL; - - yyjson_mut_val* module = yyjson_mut_arr_add_obj(doc, doc->root); - yyjson_mut_obj_add_str(doc, module, "type", baseInfo->name); - if (baseInfo->generateJsonResult) - baseInfo->generateJsonResult(baseInfo, doc, module); - else - yyjson_mut_obj_add_str(doc, module, "error", "Unsupported for JSON format"); - return module; -} - -bool ffParseModuleCommand(const char* type) -{ - if(!isalpha(type[0])) return false; - - for (FFModuleBaseInfo** modules = ffModuleInfos[toupper(type[0]) - 'A']; *modules; ++modules) - { - FFModuleBaseInfo* baseInfo = *modules; - if (ffStrEqualsIgnCase(type, baseInfo->name)) - { - if (!genJsonConfig(baseInfo) && !genJsonResult(baseInfo)) - baseInfo->printModule(baseInfo); - return true; - } - } - return false; -} - bool ffParseModuleOptions(const char* key, const char* value) { if (!ffStrStartsWith(key, "--") || !isalpha(key[2])) return false; @@ -103,7 +47,42 @@ void ffPrepareCommandOption(FFdata* data) } } -static void parseStructureCommand(const char* line, FFlist* customValues) +static void genJsonConfig(FFModuleBaseInfo* baseInfo, yyjson_mut_doc* doc) +{ + yyjson_mut_val* modules = yyjson_mut_obj_get(doc->root, "modules"); + if (!modules) + modules = yyjson_mut_obj_add_arr(doc, doc->root, "modules"); + + yyjson_mut_val* module = yyjson_mut_obj(doc); + FF_STRBUF_AUTO_DESTROY type = ffStrbufCreateS(baseInfo->name); + ffStrbufLowerCase(&type); + yyjson_mut_obj_add_strbuf(doc, module, "type", &type); + + if (baseInfo->generateJsonConfig) + baseInfo->generateJsonConfig(baseInfo, doc, module); + + if (yyjson_mut_obj_size(module) > 1) + yyjson_mut_arr_add_val(modules, module); + else + yyjson_mut_arr_add_strbuf(doc, modules, &type); +} + +static void genJsonResult(FFModuleBaseInfo* baseInfo, yyjson_mut_doc* doc) +{ + yyjson_mut_val* module = yyjson_mut_arr_add_obj(doc, doc->root); + yyjson_mut_obj_add_str(doc, module, "type", baseInfo->name); + if (baseInfo->generateJsonResult) + baseInfo->generateJsonResult(baseInfo, doc, module); + else + yyjson_mut_obj_add_str(doc, module, "error", "Unsupported for JSON format"); +} + +static void parseStructureCommand( + const char* line, + FFlist* customValues, + void (*fn)(FFModuleBaseInfo *baseInfo, yyjson_mut_doc* jsonDoc), + yyjson_mut_doc* jsonDoc +) { // handle `--set` and `--set-keyless` FF_LIST_FOR_EACH(FFCustomValue, customValue, *customValues) @@ -115,19 +94,35 @@ static void parseStructureCommand(const char* line, FFlist* customValues) if (customValue->printKey) ffStrbufAppend(&options.moduleArgs.key, &customValue->key); ffStrbufAppend(&options.moduleArgs.outputFormat, &customValue->value); - if (!genJsonConfig((FFModuleBaseInfo*) &options)) ffPrintCustom(&options); + if (__builtin_expect(jsonDoc != NULL, false)) + fn((FFModuleBaseInfo*) &options, jsonDoc); + else + ffPrintCustom(&options); return; } } - if(!ffParseModuleCommand(line)) - ffPrintErrorString(line, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, ""); + if(isalpha(line[0])) + { + for (FFModuleBaseInfo** modules = ffModuleInfos[toupper(line[0]) - 'A']; *modules; ++modules) + { + FFModuleBaseInfo* baseInfo = *modules; + if (ffStrEqualsIgnCase(line, baseInfo->name)) + { + if (__builtin_expect(jsonDoc != NULL, false)) + fn(baseInfo, jsonDoc); + else + baseInfo->printModule(baseInfo); + return; + } + } + } + + ffPrintErrorString(line, 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, ""); } -void ffPrintCommandOption(FFdata* data) +void ffPrintCommandOption(FFdata* data, yyjson_mut_doc* jsonDoc) { - yyjson_mut_doc* resultDoc = instance.state.resultDoc; - //Parse the structure and call the modules uint32_t startIndex = 0; while (startIndex < data->structure.length) @@ -139,16 +134,16 @@ void ffPrintCommandOption(FFdata* data) if(instance.config.display.stat) ms = ffTimeGetTick(); - parseStructureCommand(data->structure.chars + startIndex, &data->customValues); + parseStructureCommand(data->structure.chars + startIndex, &data->customValues, genJsonResult, jsonDoc); if(instance.config.display.stat) { ms = ffTimeGetTick() - ms; - if (resultDoc) + if (jsonDoc) { - yyjson_mut_val* moduleJson = yyjson_mut_arr_get_last(resultDoc->root); - yyjson_mut_obj_add_uint(resultDoc, moduleJson, "stat", ms); + yyjson_mut_val* moduleJson = yyjson_mut_arr_get_last(jsonDoc->root); + yyjson_mut_obj_add_uint(jsonDoc, moduleJson, "stat", ms); } else { @@ -162,19 +157,28 @@ void ffPrintCommandOption(FFdata* data) } #if defined(_WIN32) - if (!resultDoc && !instance.config.display.noBuffer) fflush(stdout); + if (!jsonDoc && !instance.config.display.noBuffer) fflush(stdout); #endif startIndex = colonIndex + 1; } } -void ffMigrateCommandOptionToJsonc(FFdata* data) +void ffMigrateCommandOptionToJsonc(FFdata* data, yyjson_mut_doc* jsonDoc) { //If we don't have a custom structure, use the default one if(data->structure.length == 0) ffStrbufAppendS(&data->structure, FASTFETCH_DATATEXT_STRUCTURE); - instance.config.display.stat = false; - ffPrintCommandOption(data); - yyjson_mut_write_fp(stdout, instance.state.migrateConfigDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); + + //Parse the structure and call the modules + uint32_t startIndex = 0; + while (startIndex < data->structure.length) + { + uint32_t colonIndex = ffStrbufNextIndexC(&data->structure, startIndex, ':'); + data->structure.chars[colonIndex] = '\0'; + + parseStructureCommand(data->structure.chars + startIndex, &data->customValues, genJsonConfig, jsonDoc); + + startIndex = colonIndex + 1; + } } diff --git a/src/common/commandoption.h b/src/common/commandoption.h index 1c9ed9721..c20d0f81f 100644 --- a/src/common/commandoption.h +++ b/src/common/commandoption.h @@ -20,10 +20,9 @@ typedef struct FFdata bool loadUserConfig; } FFdata; -bool ffParseModuleCommand(const char* type); bool ffParseModuleOptions(const char* key, const char* value); void ffPrepareCommandOption(FFdata* data); -void ffPrintCommandOption(FFdata* data); -void ffMigrateCommandOptionToJsonc(FFdata* data); +void ffPrintCommandOption(FFdata* data, yyjson_mut_doc* jsonDoc); +void ffMigrateCommandOptionToJsonc(FFdata* data, yyjson_mut_doc* jsonDoc); #endif diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 1b32ed8b4..f0d20da25 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -82,21 +82,17 @@ const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair p return "Invalid enum value type; must be a string or integer"; } -static inline yyjson_mut_val* genJsonResult(FFModuleBaseInfo* baseInfo) +static inline void genJsonResult(FFModuleBaseInfo* baseInfo, yyjson_mut_doc* doc) { - yyjson_mut_doc* doc = instance.state.resultDoc; - if (__builtin_expect(!doc, true)) return NULL; - yyjson_mut_val* module = yyjson_mut_arr_add_obj(doc, doc->root); yyjson_mut_obj_add_str(doc, module, "type", baseInfo->name); if (baseInfo->generateJsonResult) baseInfo->generateJsonResult(baseInfo, doc, module); else yyjson_mut_obj_add_str(doc, module, "error", "Unsupported for JSON format"); - return module; } -static bool parseModuleJsonObject(const char* type, yyjson_val* jsonVal) +static bool parseModuleJsonObject(const char* type, yyjson_val* jsonVal, yyjson_mut_doc* jsonDoc) { if(!isalpha(type[0])) return false; @@ -106,7 +102,9 @@ static bool parseModuleJsonObject(const char* type, yyjson_val* jsonVal) if (ffStrEqualsIgnCase(type, baseInfo->name)) { if (jsonVal) baseInfo->parseJsonObject(baseInfo, jsonVal); - if (!genJsonResult(baseInfo)) + if (__builtin_expect(jsonDoc != NULL, false)) + genJsonResult(baseInfo, jsonDoc); + else baseInfo->printModule(baseInfo); return true; } @@ -159,7 +157,7 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module) } } -static const char* printJsonConfig(bool prepare) +static const char* printJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc) { yyjson_val* const root = yyjson_doc_get_root(instance.state.configDoc); assert(root); @@ -171,8 +169,6 @@ static const char* printJsonConfig(bool prepare) if (!modules) return NULL; if (!yyjson_is_arr(modules)) return "Property 'modules' must be an array of strings or objects"; - yyjson_mut_doc* resultDoc = instance.state.resultDoc; - yyjson_val* item; size_t idx, max; yyjson_arr_foreach(modules, idx, max, item) @@ -197,16 +193,16 @@ static const char* printJsonConfig(bool prepare) if(prepare) prepareModuleJsonObject(type, module); - else if(!parseModuleJsonObject(type, module)) + else if(!parseModuleJsonObject(type, module, jsonDoc)) return "Unknown module type"; if(!prepare && instance.config.display.stat) { ms = ffTimeGetTick() - ms; - if (resultDoc) + if (jsonDoc) { - yyjson_mut_val* moduleJson = yyjson_mut_arr_get_last(resultDoc->root); - yyjson_mut_obj_add_uint(resultDoc, moduleJson, "stat", ms); + yyjson_mut_val* moduleJson = yyjson_mut_arr_get_last(jsonDoc->root); + yyjson_mut_obj_add_uint(jsonDoc, moduleJson, "stat", ms); } else { @@ -220,16 +216,25 @@ static const char* printJsonConfig(bool prepare) } #if defined(_WIN32) - if (!instance.config.display.noBuffer && !resultDoc) fflush(stdout); + if (!instance.config.display.noBuffer && !jsonDoc) fflush(stdout); #endif } return NULL; } -void ffPrintJsonConfig(bool prepare) +void ffPrintJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc) { - const char* error = printJsonConfig(prepare); + const char* error = printJsonConfig(prepare, jsonDoc); if (error) - ffPrintErrorString("JsonConfig", 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "%s", error); + { + if (jsonDoc) + { + yyjson_mut_val* obj = yyjson_mut_obj(jsonDoc); + yyjson_mut_obj_add_str(jsonDoc, obj, "error", error); + yyjson_mut_doc_set_root(jsonDoc, obj); + } + else + ffPrintErrorString("JsonConfig", 0, NULL, FF_PRINT_TYPE_NO_CUSTOM_KEY, "%s", error); + } } diff --git a/src/common/jsonconfig.h b/src/common/jsonconfig.h index 08f522c5c..917beadf2 100644 --- a/src/common/jsonconfig.h +++ b/src/common/jsonconfig.h @@ -4,7 +4,7 @@ bool ffJsonConfigParseModuleArgs(const char* key, yyjson_val* val, FFModuleArgs* moduleArgs); const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair pairs[]); -void ffPrintJsonConfig(bool prepare); +void ffPrintJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc); void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs); yyjson_api_inline bool yyjson_mut_obj_add_strbuf(yyjson_mut_doc *doc, diff --git a/src/fastfetch.c b/src/fastfetch.c index bf617e4e7..ef7ad5590 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -628,7 +628,7 @@ static void run(FFdata* data) const bool useJsonConfig = data->structure.length == 0 && instance.state.configDoc; if (useJsonConfig) - ffPrintJsonConfig(true /* prepare */); + ffPrintJsonConfig(true /* prepare */, instance.state.resultDoc); else ffPrepareCommandOption(data); @@ -639,9 +639,9 @@ static void run(FFdata* data) #endif if (useJsonConfig) - ffPrintJsonConfig(false); + ffPrintJsonConfig(false, instance.state.resultDoc); else - ffPrintCommandOption(data); + ffPrintCommandOption(data, instance.state.resultDoc); if (instance.state.resultDoc) yyjson_mut_write_fp(stdout, instance.state.resultDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); @@ -655,7 +655,8 @@ static void migrateConfig(FFdata* data) ffOptionsGenerateDisplayJsonConfig(&instance.config.display, instance.state.migrateConfigDoc); ffOptionsGenerateGeneralJsonConfig(&instance.config.general, instance.state.migrateConfigDoc); ffOptionsGenerateLibraryJsonConfig(&instance.config.library, instance.state.migrateConfigDoc); - ffMigrateCommandOptionToJsonc(data); + ffMigrateCommandOptionToJsonc(data, instance.state.migrateConfigDoc); + yyjson_mut_write_fp(stdout, instance.state.migrateConfigDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); } int main(int argc, const char** argv) From 8bdd410e9711cca06bbd82f26ebc2647c18dd8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 16:22:05 +0800 Subject: [PATCH 043/100] Migration: support specifying config file path --- CHANGELOG.md | 4 ++++ src/common/init.c | 2 +- src/fastfetch.c | 61 +++++++++++++++++++++++++++++------------------ src/fastfetch.h | 2 +- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9db77642c..a62003508 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # 2.2.0 +This release introduces a new option `--migrate-config`, which migrates old flag based config file to new JSONC format + Changes: * `--pipe` and `--stat` are moved from `general` options to `display` options. This affects cjson configuration. +* With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in the future Features: * Quirks for MIPS platforms (CPU, Linux) @@ -10,6 +13,7 @@ Features: * Support urxvt version detection (Terminal, Linux) * Support st version detection (Terminal, Linux) * Support st terminal font detection (TerminalFont, Linux) +* Add option `--migrate-config ` Bugfixes: * Better GPU memory and type detection (GPU, Windows) diff --git a/src/common/init.c b/src/common/init.c index 8c5d4c7a2..2fc032a27 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -167,7 +167,7 @@ static void destroyState(void) ffPlatformDestroy(&instance.state.platform); yyjson_doc_free(instance.state.configDoc); yyjson_mut_doc_free(instance.state.resultDoc); - yyjson_mut_doc_free(instance.state.migrateConfigDoc); + ffStrbufDestroy(&instance.state.migrateConfigPath); } void ffDestroyInstance(void) diff --git a/src/fastfetch.c b/src/fastfetch.c index ef7ad5590..9c43dc978 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -473,23 +473,19 @@ static void parseOption(FFdata* data, const char* key, const char* value) generateConfigFile(true, value); else if (ffStrEqualsIgnCase(key, "--migrate-config")) { - yyjson_mut_doc_free(instance.state.migrateConfigDoc); - - if (ffOptionParseBoolean(value)) + if (instance.state.configDoc) { - if (instance.state.configDoc) - { - fputs("Error: existing jsonc config file detected. Exiting\n", stderr); - exit(477); - } + fputs("Error: existing jsonc config file detected. Aborting\n", stderr); + exit(477); + } - yyjson_mut_doc* doc = instance.state.migrateConfigDoc = yyjson_mut_doc_new(NULL); - yyjson_mut_val* root = yyjson_mut_obj(doc); - yyjson_mut_doc_set_root(doc, root); - yyjson_mut_obj_add_str(doc, root, "$schema", "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json"); + if (!value) + { + ffStrbufSet(&instance.state.migrateConfigPath, (FFstrbuf*) ffListGet(&instance.state.platform.configDirs, 0)); + ffStrbufAppendS(&instance.state.migrateConfigPath, "fastfetch/config.jsonc"); } else - instance.state.migrateConfigDoc = NULL; + ffStrbufSetS(&instance.state.migrateConfigPath, value); } else if(ffStrEqualsIgnCase(key, "--load-user-config")) data->loadUserConfig = ffOptionParseBoolean(value); @@ -546,7 +542,7 @@ error: static void parseConfigFiles(FFdata* data) { - if (__builtin_expect(!instance.state.migrateConfigDoc, true)) + if (__builtin_expect(instance.state.migrateConfigPath.length == 0, true)) { for (uint32_t i = instance.state.platform.configDirs.length; i > 0; --i) { @@ -649,14 +645,33 @@ static void run(FFdata* data) ffFinish(); } -static void migrateConfig(FFdata* data) +static void migrateConfig(FFdata* data, const FFstrbuf* filename) { - ffOptionsGenerateLogoJsonConfig(&instance.config.logo, instance.state.migrateConfigDoc); - ffOptionsGenerateDisplayJsonConfig(&instance.config.display, instance.state.migrateConfigDoc); - ffOptionsGenerateGeneralJsonConfig(&instance.config.general, instance.state.migrateConfigDoc); - ffOptionsGenerateLibraryJsonConfig(&instance.config.library, instance.state.migrateConfigDoc); - ffMigrateCommandOptionToJsonc(data, instance.state.migrateConfigDoc); - yyjson_mut_write_fp(stdout, instance.state.migrateConfigDoc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); + yyjson_mut_doc* doc = yyjson_mut_doc_new(NULL); + yyjson_mut_val* root = yyjson_mut_obj(doc); + yyjson_mut_doc_set_root(doc, root); + yyjson_mut_obj_add_str(doc, root, "$schema", "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json"); + + ffOptionsGenerateLogoJsonConfig(&instance.config.logo, doc); + ffOptionsGenerateDisplayJsonConfig(&instance.config.display, doc); + ffOptionsGenerateGeneralJsonConfig(&instance.config.general, doc); + ffOptionsGenerateLibraryJsonConfig(&instance.config.library, doc); + ffMigrateCommandOptionToJsonc(data, doc); + + if (ffStrbufEqualS(filename, "-")) + yyjson_mut_write_fp(stdout, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL); + else + { + if (yyjson_mut_write_file(filename->chars, doc, YYJSON_WRITE_INF_AND_NAN_AS_NULL | YYJSON_WRITE_PRETTY_TWO_SPACES, NULL, NULL)) + printf("The migrated config file has been written in `%s`\nYou may remove the old config file if everything works fine\n", filename->chars); + else + { + printf("Error: failed to write file in `%s`\n", filename->chars); + exit(1); + } + } + + yyjson_mut_doc_free(doc); } int main(int argc, const char** argv) @@ -674,10 +689,10 @@ int main(int argc, const char** argv) parseConfigFiles(&data); parseArguments(&data, argc, argv); - if (__builtin_expect(!instance.state.migrateConfigDoc, true)) + if (__builtin_expect(instance.state.migrateConfigPath.length == 0, true)) run(&data); else - migrateConfig(&data); + migrateConfig(&data, &instance.state.migrateConfigPath); ffStrbufDestroy(&data.structure); FF_LIST_FOR_EACH(FFCustomValue, customValue, data.customValues) diff --git a/src/fastfetch.h b/src/fastfetch.h index e97e6c7bc..502a48d40 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -47,7 +47,7 @@ typedef struct FFstate FFPlatform platform; yyjson_doc* configDoc; yyjson_mut_doc* resultDoc; - yyjson_mut_doc* migrateConfigDoc; + FFstrbuf migrateConfigPath; } FFstate; typedef struct FFinstance From e707cf8464ef045d0d17728b5523b5f69c9abca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 16:34:38 +0800 Subject: [PATCH 044/100] Migration: deprecate `--gen-config conf` --- CHANGELOG.md | 3 ++- README.md | 2 ++ src/data/help.txt | 4 ++-- src/fastfetch.c | 18 ++++++++++++------ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a62003508..cf518c70c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ This release introduces a new option `--migrate-config`, which migrates old flag Changes: * `--pipe` and `--stat` are moved from `general` options to `display` options. This affects cjson configuration. -* With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in the future +* With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version) +* Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version) Features: * Quirks for MIPS platforms (CPU, Linux) diff --git a/README.md b/README.md index 63c44c693..da2e4443c 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ There are [screenshots on different platforms](https://github.com/fastfetch-cli/ With customization and speed being two competing goals, this project actually builds two executables: + + * The main one is `fastfetch`, which can be very greatly configured via flags. These flags can be made persistent by modifying `$XDG_CONFIG_HOME/fastfetch/config.conf`. Use `fastfetch --gen-config conf` to generate one. To view the available options, run `fastfetch --help`. * The second executable is called `flashfetch`, which is configured at compile time to eliminate any possible overhead. Configuration of it can be very easily done in [`src/flashfetch.c`](src/flashfetch.c). diff --git a/src/data/help.txt b/src/data/help.txt index a83a81b8e..af8e2ba62 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -14,8 +14,8 @@ Informative options: --print-config-system: Print the default system config --print-config-user: Print the default user config --print-structure: Print the default structure - --gen-config : Generate a sample config file in the default path. Param `type` can be `jsonc` or `conf` - --gen-config-force : Generate a sample config file in the default path. Overwrite the existing one + --gen-config : Generate a sample config file in the default path. Param `type` can be `jsonc` or deprecated `conf` + --gen-config-force : Generate a sample config file in the default path. Overwrite the existing one General options: --load-config : Load a config file or preset (+) diff --git a/src/fastfetch.c b/src/fastfetch.c index 9c43dc978..f42537aee 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -236,18 +236,24 @@ static bool parseConfigFile(FFdata* data, const char* path) static void generateConfigFile(bool force, const char* type) { + if (!type) + { + fputs("Error: the config type (`jsonc` or `conf`) must be specified\n", stderr); + exit(1); + } + FFstrbuf* filename = (FFstrbuf*) ffListGet(&instance.state.platform.configDirs, 0); // Paths generated in `init.c/initConfigDirs` end with `/` - bool isJsonc = false; - if (type) + bool isJsonc = ffStrEqualsIgnCase(type, "jsonc"); + if (!isJsonc) { - if (ffStrEqualsIgnCase(type, "jsonc")) - isJsonc = true; - else if (!ffStrEqualsIgnCase(type, "conf")) + if (!ffStrEqualsIgnCase(type, "conf")) { - fputs("config type can only be `jsonc` or `conf`\n", stderr); + fputs("Error: config type can only be `jsonc` or `conf`\n", stderr); exit(1); } + else + fputs("Warning: support of flag based config type `conf` is deprecated, and may be removed in the future\n", stderr); } ffStrbufAppendS(filename, isJsonc ? "fastfetch/config.jsonc" : "fastfetch/config.conf"); From cd5e14a834fd1a435e68bef12b7e055b546fa327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 23:27:40 +0800 Subject: [PATCH 045/100] LM (Linux): tidy --- src/detection/lm/lm_linux.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/detection/lm/lm_linux.c b/src/detection/lm/lm_linux.c index 0fb4fdba5..c91fdf477 100644 --- a/src/detection/lm/lm_linux.c +++ b/src/detection/lm/lm_linux.c @@ -56,12 +56,12 @@ static const char* getSshdVersion(FFstrbuf* version) static const char* getSddmVersion(FFstrbuf* version) { FF_LIBRARY_LOAD(zlib, &instance.config.library.libZ, "dlopen libz failed", "libz" FF_LIBRARY_EXTENSION, 2) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzopen); - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzread); - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzerror); - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gztell); - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzrewind); - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzclose); + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzopen) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzread) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzerror) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gztell) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzrewind) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(zlib, gzclose) gzFile file = ffgzopen("/usr/share/man/man1/sddm.1.gz", "rb"); if (file == Z_NULL) From 59a9209621594bd74715a77f6c4e92c785d1df49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 26 Oct 2023 23:28:43 +0800 Subject: [PATCH 046/100] GPU: support Nvidia GPU temp detection --- CHANGELOG.md | 1 + CMakeLists.txt | 3 + src/3rdparty/nvml/nvml.h | 5684 ++++++++++++++++++++++++++++ src/3rdparty/nvml/repo.json | 6 + src/detection/gpu/gpu_linux.c | 12 +- src/detection/gpu/gpu_windows.c | 14 +- src/detection/temps/temps_nvidia.c | 73 + src/detection/temps/temps_nvidia.h | 5 + 8 files changed, 5791 insertions(+), 7 deletions(-) create mode 100644 src/3rdparty/nvml/nvml.h create mode 100644 src/3rdparty/nvml/repo.json create mode 100644 src/detection/temps/temps_nvidia.c create mode 100644 src/detection/temps/temps_nvidia.h diff --git a/CHANGELOG.md b/CHANGELOG.md index cf518c70c..ac2742f03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Features: * Support st version detection (Terminal, Linux) * Support st terminal font detection (TerminalFont, Linux) * Add option `--migrate-config ` +* Support Nvidia GPU temp detection via nvml (GPU) Bugfixes: * Better GPU memory and type detection (GPU, Windows) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67bab51bf..a32376948 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -412,6 +412,7 @@ if(LINUX) src/detection/sound/sound_linux.c src/detection/swap/swap_linux.c src/detection/temps/temps_linux.c + src/detection/temps/temps_nvidia.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c src/detection/terminalsize/terminalsize_linux.c @@ -518,6 +519,7 @@ elseif(BSD) src/detection/sound/sound_linux.c src/detection/swap/swap_bsd.c src/detection/temps/temps_bsd.c + src/detection/temps/temps_nvidia.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c src/detection/terminalsize/terminalsize_linux.c @@ -622,6 +624,7 @@ elseif(WIN32) src/detection/terminalshell/terminalshell_windows.c src/detection/terminalsize/terminalsize_windows.c src/detection/temps/temps_windows.cpp + src/detection/temps/temps_nvidia.c src/detection/theme/theme_nosupport.c src/detection/uptime/uptime_windows.c src/detection/users/users_windows.c diff --git a/src/3rdparty/nvml/nvml.h b/src/3rdparty/nvml/nvml.h new file mode 100644 index 000000000..53bced8df --- /dev/null +++ b/src/3rdparty/nvml/nvml.h @@ -0,0 +1,5684 @@ +/* + * Copyright 1993-2017 NVIDIA Corporation. All rights reserved. + * + * NOTICE TO USER: + * + * This source code is subject to NVIDIA ownership rights under U.S. and + * international Copyright laws. Users and possessors of this source code + * are hereby granted a nonexclusive, royalty-free license to use this code + * in individual and commercial software. + * + * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE + * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR + * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. + * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE + * OR PERFORMANCE OF THIS SOURCE CODE. + * + * U.S. Government End Users. This source code is a "commercial item" as + * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of + * "commercial computer software" and "commercial computer software + * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) + * and is provided to the U.S. Government only as a commercial end item. + * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through + * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the + * source code with only those rights set forth herein. + * + * Any use of this source code in individual and commercial software must + * include, in the user documentation and internal comments to the code, + * the above Disclaimer and U.S. Government End Users Notice. + */ + +/* +NVML API Reference + +The NVIDIA Management Library (NVML) is a C-based programmatic interface for monitoring and +managing various states within NVIDIA Tesla &tm; GPUs. It is intended to be a platform for building +3rd party applications, and is also the underlying library for the NVIDIA-supported nvidia-smi +tool. NVML is thread-safe so it is safe to make simultaneous NVML calls from multiple threads. + +API Documentation + +Supported platforms: +- Windows: Windows Server 2008 R2 64bit, Windows Server 2012 R2 64bit, Windows 7 64bit, Windows 8 64bit, Windows 10 64bit +- Linux: 32-bit and 64-bit +- Hypervisors: Windows Server 2008R2/2012 Hyper-V 64bit, Citrix XenServer 6.2 SP1+, VMware ESX 5.1/5.5 + +Supported products: +- Full Support + - All Tesla products, starting with the Fermi architecture + - All Quadro products, starting with the Fermi architecture + - All GRID products, starting with the Kepler architecture + - Selected GeForce Titan products +- Limited Support + - All Geforce products, starting with the Fermi architecture + +The NVML library can be found at \%ProgramW6432\%\\"NVIDIA Corporation"\\NVSMI\\ on Windows. It is +not be added to the system path by default. To dynamically link to NVML, add this path to the PATH +environmental variable. To dynamically load NVML, call LoadLibrary with this path. + +On Linux the NVML library will be found on the standard library path. For 64 bit Linux, both the 32 bit +and 64 bit NVML libraries will be installed. + +Online documentation for this library is available at http://docs.nvidia.com/deploy/nvml-api/index.html +*/ + +#ifndef __nvml_nvml_h__ +#define __nvml_nvml_h__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * On Windows, set up methods for DLL export + * define NVML_STATIC_IMPORT when using nvml_loader library + */ +#if defined _WINDOWS + #if !defined NVML_STATIC_IMPORT + #if defined NVML_LIB_EXPORT + #define DECLDIR __declspec(dllexport) + #else + #define DECLDIR __declspec(dllimport) + #endif + #else + #define DECLDIR + #endif +#else + #define DECLDIR +#endif + +/** + * NVML API versioning support + */ +#define NVML_API_VERSION 9 +#define NVML_API_VERSION_STR "9" +#define nvmlInit nvmlInit_v2 +#define nvmlDeviceGetPciInfo nvmlDeviceGetPciInfo_v3 +#define nvmlDeviceGetCount nvmlDeviceGetCount_v2 +#define nvmlDeviceGetHandleByIndex nvmlDeviceGetHandleByIndex_v2 +#define nvmlDeviceGetHandleByPciBusId nvmlDeviceGetHandleByPciBusId_v2 +#define nvmlDeviceGetNvLinkRemotePciInfo nvmlDeviceGetNvLinkRemotePciInfo_v2 + +/***************************************************************************************************/ +/** @defgroup nvmlDeviceStructs Device Structs + * @{ + */ +/***************************************************************************************************/ + +/** + * Special constant that some fields take when they are not available. + * Used when only part of the struct is not available. + * + * Each structure explicitly states when to check for this value. + */ +#define NVML_VALUE_NOT_AVAILABLE (-1) + +typedef struct nvmlDevice_st* nvmlDevice_t; + +/** + * Buffer size guaranteed to be large enough for pci bus id + */ +#define NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE 32 + +/** + * Buffer size guaranteed to be large enough for pci bus id for ::busIdLegacy + */ +#define NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE 16 + +/** + * PCI information about a GPU device. + */ +typedef struct nvmlPciInfo_st +{ + char busIdLegacy[NVML_DEVICE_PCI_BUS_ID_BUFFER_V2_SIZE]; //!< The legacy tuple domain:bus:device.function PCI identifier (& NULL terminator) + unsigned int domain; //!< The PCI domain on which the device's bus resides, 0 to 0xffffffff + unsigned int bus; //!< The bus on which the device resides, 0 to 0xff + unsigned int device; //!< The device's id on the bus, 0 to 31 + unsigned int pciDeviceId; //!< The combined 16-bit device id and 16-bit vendor id + + // Added in NVML 2.285 API + unsigned int pciSubSystemId; //!< The 32-bit Sub System Device ID + + char busId[NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE]; //!< The tuple domain:bus:device.function PCI identifier (& NULL terminator) +} nvmlPciInfo_t; + +/** + * Detailed ECC error counts for a device. + * + * @deprecated Different GPU families can have different memory error counters + * See \ref nvmlDeviceGetMemoryErrorCounter + */ +typedef struct nvmlEccErrorCounts_st +{ + unsigned long long l1Cache; //!< L1 cache errors + unsigned long long l2Cache; //!< L2 cache errors + unsigned long long deviceMemory; //!< Device memory errors + unsigned long long registerFile; //!< Register file errors +} nvmlEccErrorCounts_t; + +/** + * Utilization information for a device. + * Each sample period may be between 1 second and 1/6 second, depending on the product being queried. + */ +typedef struct nvmlUtilization_st +{ + unsigned int gpu; //!< Percent of time over the past sample period during which one or more kernels was executing on the GPU + unsigned int memory; //!< Percent of time over the past sample period during which global (device) memory was being read or written +} nvmlUtilization_t; + +/** + * Memory allocation information for a device. + */ +typedef struct nvmlMemory_st +{ + unsigned long long total; //!< Total installed FB memory (in bytes) + unsigned long long free; //!< Unallocated FB memory (in bytes) + unsigned long long used; //!< Allocated FB memory (in bytes). Note that the driver/GPU always sets aside a small amount of memory for bookkeeping +} nvmlMemory_t; + +/** + * BAR1 Memory allocation Information for a device + */ +typedef struct nvmlBAR1Memory_st +{ + unsigned long long bar1Total; //!< Total BAR1 Memory (in bytes) + unsigned long long bar1Free; //!< Unallocated BAR1 Memory (in bytes) + unsigned long long bar1Used; //!< Allocated Used Memory (in bytes) +}nvmlBAR1Memory_t; + +/** + * Information about running compute processes on the GPU + */ +typedef struct nvmlProcessInfo_st +{ + unsigned int pid; //!< Process ID + unsigned long long usedGpuMemory; //!< Amount of used GPU memory in bytes. + //! Under WDDM, \ref NVML_VALUE_NOT_AVAILABLE is always reported + //! because Windows KMD manages all the memory and not the NVIDIA driver +} nvmlProcessInfo_t; + +/** + * Enum to represent type of bridge chip + */ +typedef enum nvmlBridgeChipType_enum +{ + NVML_BRIDGE_CHIP_PLX = 0, + NVML_BRIDGE_CHIP_BRO4 = 1 +}nvmlBridgeChipType_t; + +/** + * Maximum number of NvLink links supported + */ +#define NVML_NVLINK_MAX_LINKS 6 + +/** + * Enum to represent the NvLink utilization counter packet units + */ +typedef enum nvmlNvLinkUtilizationCountUnits_enum +{ + NVML_NVLINK_COUNTER_UNIT_CYCLES = 0, // count by cycles + NVML_NVLINK_COUNTER_UNIT_PACKETS = 1, // count by packets + NVML_NVLINK_COUNTER_UNIT_BYTES = 2, // count by bytes + + // this must be last + NVML_NVLINK_COUNTER_UNIT_COUNT +} nvmlNvLinkUtilizationCountUnits_t; + +/** + * Enum to represent the NvLink utilization counter packet types to count + * ** this is ONLY applicable with the units as packets or bytes + * ** as specified in \a nvmlNvLinkUtilizationCountUnits_t + * ** all packet filter descriptions are target GPU centric + * ** these can be "OR'd" together + */ +typedef enum nvmlNvLinkUtilizationCountPktTypes_enum +{ + NVML_NVLINK_COUNTER_PKTFILTER_NOP = 0x1, // no operation packets + NVML_NVLINK_COUNTER_PKTFILTER_READ = 0x2, // read packets + NVML_NVLINK_COUNTER_PKTFILTER_WRITE = 0x4, // write packets + NVML_NVLINK_COUNTER_PKTFILTER_RATOM = 0x8, // reduction atomic requests + NVML_NVLINK_COUNTER_PKTFILTER_NRATOM = 0x10, // non-reduction atomic requests + NVML_NVLINK_COUNTER_PKTFILTER_FLUSH = 0x20, // flush requests + NVML_NVLINK_COUNTER_PKTFILTER_RESPDATA = 0x40, // responses with data + NVML_NVLINK_COUNTER_PKTFILTER_RESPNODATA = 0x80, // responses without data + NVML_NVLINK_COUNTER_PKTFILTER_ALL = 0xFF // all packets +} nvmlNvLinkUtilizationCountPktTypes_t; + +/** + * Struct to define the NVLINK counter controls + */ +typedef struct nvmlNvLinkUtilizationControl_st +{ + nvmlNvLinkUtilizationCountUnits_t units; + nvmlNvLinkUtilizationCountPktTypes_t pktfilter; +} nvmlNvLinkUtilizationControl_t; + +/** + * Enum to represent NvLink queryable capabilities + */ +typedef enum nvmlNvLinkCapability_enum +{ + NVML_NVLINK_CAP_P2P_SUPPORTED = 0, // P2P over NVLink is supported + NVML_NVLINK_CAP_SYSMEM_ACCESS = 1, // Access to system memory is supported + NVML_NVLINK_CAP_P2P_ATOMICS = 2, // P2P atomics are supported + NVML_NVLINK_CAP_SYSMEM_ATOMICS= 3, // System memory atomics are supported + NVML_NVLINK_CAP_SLI_BRIDGE = 4, // SLI is supported over this link + NVML_NVLINK_CAP_VALID = 5, // Link is supported on this device + // should be last + NVML_NVLINK_CAP_COUNT +} nvmlNvLinkCapability_t; + +/** + * Enum to represent NvLink queryable error counters + */ +typedef enum nvmlNvLinkErrorCounter_enum +{ + NVML_NVLINK_ERROR_DL_REPLAY = 0, // Data link transmit replay error counter + NVML_NVLINK_ERROR_DL_RECOVERY = 1, // Data link transmit recovery error counter + NVML_NVLINK_ERROR_DL_CRC_FLIT = 2, // Data link receive flow control digit CRC error counter + NVML_NVLINK_ERROR_DL_CRC_DATA = 3, // Data link receive data CRC error counter + + // this must be last + NVML_NVLINK_ERROR_COUNT +} nvmlNvLinkErrorCounter_t; + +/** + * Represents level relationships within a system between two GPUs + * The enums are spaced to allow for future relationships + */ +typedef enum nvmlGpuLevel_enum +{ + NVML_TOPOLOGY_INTERNAL = 0, // e.g. Tesla K80 + NVML_TOPOLOGY_SINGLE = 10, // all devices that only need traverse a single PCIe switch + NVML_TOPOLOGY_MULTIPLE = 20, // all devices that need not traverse a host bridge + NVML_TOPOLOGY_HOSTBRIDGE = 30, // all devices that are connected to the same host bridge + NVML_TOPOLOGY_NODE = 40, // all devices that are connected to the same NUMA node but possibly multiple host bridges + NVML_TOPOLOGY_SYSTEM = 50, // all devices in the system + + // there is purposefully no COUNT here because of the need for spacing above +} nvmlGpuTopologyLevel_t; + +/* Compatibility for CPU->NODE renaming */ +#define NVML_TOPOLOGY_CPU NVML_TOPOLOGY_NODE + +/* P2P Capability Index Status*/ +typedef enum nvmlGpuP2PStatus_enum +{ + NVML_P2P_STATUS_OK = 0, + NVML_P2P_STATUS_CHIPSET_NOT_SUPPORED, + NVML_P2P_STATUS_GPU_NOT_SUPPORTED, + NVML_P2P_STATUS_IOH_TOPOLOGY_NOT_SUPPORTED, + NVML_P2P_STATUS_DISABLED_BY_REGKEY, + NVML_P2P_STATUS_NOT_SUPPORTED, + NVML_P2P_STATUS_UNKNOWN + +} nvmlGpuP2PStatus_t; + +/* P2P Capability Index*/ +typedef enum nvmlGpuP2PCapsIndex_enum +{ + NVML_P2P_CAPS_INDEX_READ = 0, + NVML_P2P_CAPS_INDEX_WRITE, + NVML_P2P_CAPS_INDEX_NVLINK, + NVML_P2P_CAPS_INDEX_ATOMICS, + NVML_P2P_CAPS_INDEX_PROP, + NVML_P2P_CAPS_INDEX_UNKNOWN +}nvmlGpuP2PCapsIndex_t; + +/** + * Maximum limit on Physical Bridges per Board + */ +#define NVML_MAX_PHYSICAL_BRIDGE (128) + +/** + * Information about the Bridge Chip Firmware + */ +typedef struct nvmlBridgeChipInfo_st +{ + nvmlBridgeChipType_t type; //!< Type of Bridge Chip + unsigned int fwVersion; //!< Firmware Version. 0=Version is unavailable +}nvmlBridgeChipInfo_t; + +/** + * This structure stores the complete Hierarchy of the Bridge Chip within the board. The immediate + * bridge is stored at index 0 of bridgeInfoList, parent to immediate bridge is at index 1 and so forth. + */ +typedef struct nvmlBridgeChipHierarchy_st +{ + unsigned char bridgeCount; //!< Number of Bridge Chips on the Board + nvmlBridgeChipInfo_t bridgeChipInfo[NVML_MAX_PHYSICAL_BRIDGE]; //!< Hierarchy of Bridge Chips on the board +}nvmlBridgeChipHierarchy_t; + +/** + * Represents Type of Sampling Event + */ +typedef enum nvmlSamplingType_enum +{ + NVML_TOTAL_POWER_SAMPLES = 0, //!< To represent total power drawn by GPU + NVML_GPU_UTILIZATION_SAMPLES = 1, //!< To represent percent of time during which one or more kernels was executing on the GPU + NVML_MEMORY_UTILIZATION_SAMPLES = 2, //!< To represent percent of time during which global (device) memory was being read or written + NVML_ENC_UTILIZATION_SAMPLES = 3, //!< To represent percent of time during which NVENC remains busy + NVML_DEC_UTILIZATION_SAMPLES = 4, //!< To represent percent of time during which NVDEC remains busy + NVML_PROCESSOR_CLK_SAMPLES = 5, //!< To represent processor clock samples + NVML_MEMORY_CLK_SAMPLES = 6, //!< To represent memory clock samples + + // Keep this last + NVML_SAMPLINGTYPE_COUNT +}nvmlSamplingType_t; + +/** + * Represents the queryable PCIe utilization counters + */ +typedef enum nvmlPcieUtilCounter_enum +{ + NVML_PCIE_UTIL_TX_BYTES = 0, // 1KB granularity + NVML_PCIE_UTIL_RX_BYTES = 1, // 1KB granularity + + // Keep this last + NVML_PCIE_UTIL_COUNT +} nvmlPcieUtilCounter_t; + +/** + * Represents the type for sample value returned + */ +typedef enum nvmlValueType_enum +{ + NVML_VALUE_TYPE_DOUBLE = 0, + NVML_VALUE_TYPE_UNSIGNED_INT = 1, + NVML_VALUE_TYPE_UNSIGNED_LONG = 2, + NVML_VALUE_TYPE_UNSIGNED_LONG_LONG = 3, + NVML_VALUE_TYPE_SIGNED_LONG_LONG = 4, + + // Keep this last + NVML_VALUE_TYPE_COUNT +}nvmlValueType_t; + + +/** + * Union to represent different types of Value + */ +typedef union nvmlValue_st +{ + double dVal; //!< If the value is double + unsigned int uiVal; //!< If the value is unsigned int + unsigned long ulVal; //!< If the value is unsigned long + unsigned long long ullVal; //!< If the value is unsigned long long + signed long long sllVal; //!< If the value is signed long long +}nvmlValue_t; + +/** + * Information for Sample + */ +typedef struct nvmlSample_st +{ + unsigned long long timeStamp; //!< CPU Timestamp in microseconds + nvmlValue_t sampleValue; //!< Sample Value +}nvmlSample_t; + +/** + * Represents type of perf policy for which violation times can be queried + */ +typedef enum nvmlPerfPolicyType_enum +{ + NVML_PERF_POLICY_POWER = 0, //!< How long did power violations cause the GPU to be below application clocks + NVML_PERF_POLICY_THERMAL = 1, //!< How long did thermal violations cause the GPU to be below application clocks + NVML_PERF_POLICY_SYNC_BOOST = 2, //!< How long did sync boost cause the GPU to be below application clocks + NVML_PERF_POLICY_BOARD_LIMIT = 3, //!< How long did the board limit cause the GPU to be below application clocks + NVML_PERF_POLICY_LOW_UTILIZATION = 4, //!< How long did low utilization cause the GPU to be below application clocks + NVML_PERF_POLICY_RELIABILITY = 5, //!< How long did the board reliability limit cause the GPU to be below application clocks + + NVML_PERF_POLICY_TOTAL_APP_CLOCKS = 10, //!< Total time the GPU was held below application clocks by any limiter (0 - 5 above) + NVML_PERF_POLICY_TOTAL_BASE_CLOCKS = 11, //!< Total time the GPU was held below base clocks + + // Keep this last + NVML_PERF_POLICY_COUNT +}nvmlPerfPolicyType_t; + +/** + * Struct to hold perf policy violation status data + */ +typedef struct nvmlViolationTime_st +{ + unsigned long long referenceTime; //!< referenceTime represents CPU timestamp in microseconds + unsigned long long violationTime; //!< violationTime in Nanoseconds +}nvmlViolationTime_t; + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlDeviceEnumvs Device Enums + * @{ + */ +/***************************************************************************************************/ + +/** + * Generic enable/disable enum. + */ +typedef enum nvmlEnableState_enum +{ + NVML_FEATURE_DISABLED = 0, //!< Feature disabled + NVML_FEATURE_ENABLED = 1 //!< Feature enabled +} nvmlEnableState_t; + +//! Generic flag used to specify the default behavior of some functions. See description of particular functions for details. +#define nvmlFlagDefault 0x00 +//! Generic flag used to force some behavior. See description of particular functions for details. +#define nvmlFlagForce 0x01 + +/** + * * The Brand of the GPU + * */ +typedef enum nvmlBrandType_enum +{ + NVML_BRAND_UNKNOWN = 0, + NVML_BRAND_QUADRO = 1, + NVML_BRAND_TESLA = 2, + NVML_BRAND_NVS = 3, + NVML_BRAND_GRID = 4, + NVML_BRAND_GEFORCE = 5, + + // Keep this last + NVML_BRAND_COUNT +} nvmlBrandType_t; + +/** + * Temperature thresholds. + */ +typedef enum nvmlTemperatureThresholds_enum +{ + NVML_TEMPERATURE_THRESHOLD_SHUTDOWN = 0, // Temperature at which the GPU will shut down + // for HW protection + NVML_TEMPERATURE_THRESHOLD_SLOWDOWN = 1, // Temperature at which the GPU will begin HW slowdown + NVML_TEMPERATURE_THRESHOLD_MEM_MAX = 2, // Memory Temperature at which the GPU will begin SW slowdown + NVML_TEMPERATURE_THRESHOLD_GPU_MAX = 3, // GPU Temperature at which the GPU can be throttled below base clock + // Keep this last + NVML_TEMPERATURE_THRESHOLD_COUNT +} nvmlTemperatureThresholds_t; + +/** + * Temperature sensors. + */ +typedef enum nvmlTemperatureSensors_enum +{ + NVML_TEMPERATURE_GPU = 0, //!< Temperature sensor for the GPU die + + // Keep this last + NVML_TEMPERATURE_COUNT +} nvmlTemperatureSensors_t; + +/** + * Compute mode. + * + * NVML_COMPUTEMODE_EXCLUSIVE_PROCESS was added in CUDA 4.0. + * Earlier CUDA versions supported a single exclusive mode, + * which is equivalent to NVML_COMPUTEMODE_EXCLUSIVE_THREAD in CUDA 4.0 and beyond. + */ +typedef enum nvmlComputeMode_enum +{ + NVML_COMPUTEMODE_DEFAULT = 0, //!< Default compute mode -- multiple contexts per device + NVML_COMPUTEMODE_EXCLUSIVE_THREAD = 1, //!< Support Removed + NVML_COMPUTEMODE_PROHIBITED = 2, //!< Compute-prohibited mode -- no contexts per device + NVML_COMPUTEMODE_EXCLUSIVE_PROCESS = 3, //!< Compute-exclusive-process mode -- only one context per device, usable from multiple threads at a time + + // Keep this last + NVML_COMPUTEMODE_COUNT +} nvmlComputeMode_t; + +/** + * ECC bit types. + * + * @deprecated See \ref nvmlMemoryErrorType_t for a more flexible type + */ +#define nvmlEccBitType_t nvmlMemoryErrorType_t + +/** + * Single bit ECC errors + * + * @deprecated Mapped to \ref NVML_MEMORY_ERROR_TYPE_CORRECTED + */ +#define NVML_SINGLE_BIT_ECC NVML_MEMORY_ERROR_TYPE_CORRECTED + +/** + * Double bit ECC errors + * + * @deprecated Mapped to \ref NVML_MEMORY_ERROR_TYPE_UNCORRECTED + */ +#define NVML_DOUBLE_BIT_ECC NVML_MEMORY_ERROR_TYPE_UNCORRECTED + +/** + * Memory error types + */ +typedef enum nvmlMemoryErrorType_enum +{ + /** + * A memory error that was corrected + * + * For ECC errors, these are single bit errors + * For Texture memory, these are errors fixed by resend + */ + NVML_MEMORY_ERROR_TYPE_CORRECTED = 0, + /** + * A memory error that was not corrected + * + * For ECC errors, these are double bit errors + * For Texture memory, these are errors where the resend fails + */ + NVML_MEMORY_ERROR_TYPE_UNCORRECTED = 1, + + + // Keep this last + NVML_MEMORY_ERROR_TYPE_COUNT //!< Count of memory error types + +} nvmlMemoryErrorType_t; + +/** + * ECC counter types. + * + * Note: Volatile counts are reset each time the driver loads. On Windows this is once per boot. On Linux this can be more frequent. + * On Linux the driver unloads when no active clients exist. If persistence mode is enabled or there is always a driver + * client active (e.g. X11), then Linux also sees per-boot behavior. If not, volatile counts are reset each time a compute app + * is run. + */ +typedef enum nvmlEccCounterType_enum +{ + NVML_VOLATILE_ECC = 0, //!< Volatile counts are reset each time the driver loads. + NVML_AGGREGATE_ECC = 1, //!< Aggregate counts persist across reboots (i.e. for the lifetime of the device) + + // Keep this last + NVML_ECC_COUNTER_TYPE_COUNT //!< Count of memory counter types +} nvmlEccCounterType_t; + +/** + * Clock types. + * + * All speeds are in Mhz. + */ +typedef enum nvmlClockType_enum +{ + NVML_CLOCK_GRAPHICS = 0, //!< Graphics clock domain + NVML_CLOCK_SM = 1, //!< SM clock domain + NVML_CLOCK_MEM = 2, //!< Memory clock domain + NVML_CLOCK_VIDEO = 3, //!< Video encoder/decoder clock domain + + // Keep this last + NVML_CLOCK_COUNT //usedGpuMemory is not supported + + + unsigned long long time; //!< Amount of time in ms during which the compute context was active. The time is reported as 0 if + //!< the process is not terminated + + unsigned long long startTime; //!< CPU Timestamp in usec representing start time for the process + + unsigned int isRunning; //!< Flag to represent if the process is running (1 for running, 0 for terminated) + + unsigned int reserved[5]; //!< Reserved for future use +} nvmlAccountingStats_t; + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlVgpuConstants Vgpu Constants + * @{ + */ +/***************************************************************************************************/ + +/** + * Buffer size guaranteed to be large enough for \ref nvmlVgpuTypeGetLicense + */ +#define NVML_GRID_LICENSE_BUFFER_SIZE 128 + +#define NVML_VGPU_NAME_BUFFER_SIZE 64 + +#define NVML_MAX_VGPU_TYPES_PER_PGPU 17 + +#define NVML_MAX_VGPU_INSTANCES_PER_PGPU 24 + +#define NVML_GRID_LICENSE_FEATURE_MAX_COUNT 3 + +#define NVML_GRID_LICENSE_INFO_MAX_LENGTH 128 + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlVgpuEnum Vgpu Enum + * @{ + */ +/***************************************************************************************************/ + +/*! + * Types of VM identifiers + */ +typedef enum nvmlVgpuVmIdType { + NVML_VGPU_VM_ID_DOMAIN_ID = 0, //!< VM ID represents DOMAIN ID + NVML_VGPU_VM_ID_UUID = 1, //!< VM ID represents UUID +} nvmlVgpuVmIdType_t; + +// vGPU GUEST info state. +typedef enum nvmlVgpuGuestInfoState_enum +{ + NVML_VGPU_INSTANCE_GUEST_INFO_STATE_UNINITIALIZED = 0, //= 0 and < \a unitCount + * @param unit Reference in which to return the unit handle + * + * @return + * - \ref NVML_SUCCESS if \a unit has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a index is invalid or \a unit is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlUnitGetHandleByIndex(unsigned int index, nvmlUnit_t *unit); + +/** + * Retrieves the static information associated with a unit. + * + * For S-class products. + * + * See \ref nvmlUnitInfo_t for details on available unit info. + * + * @param unit The identifier of the target unit + * @param info Reference in which to return the unit information + * + * @return + * - \ref NVML_SUCCESS if \a info has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit is invalid or \a info is NULL + */ +nvmlReturn_t DECLDIR nvmlUnitGetUnitInfo(nvmlUnit_t unit, nvmlUnitInfo_t *info); + +/** + * Retrieves the LED state associated with this unit. + * + * For S-class products. + * + * See \ref nvmlLedState_t for details on allowed states. + * + * @param unit The identifier of the target unit + * @param state Reference in which to return the current LED state + * + * @return + * - \ref NVML_SUCCESS if \a state has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit is invalid or \a state is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this is not an S-class product + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlUnitSetLedState() + */ +nvmlReturn_t DECLDIR nvmlUnitGetLedState(nvmlUnit_t unit, nvmlLedState_t *state); + +/** + * Retrieves the PSU stats for the unit. + * + * For S-class products. + * + * See \ref nvmlPSUInfo_t for details on available PSU info. + * + * @param unit The identifier of the target unit + * @param psu Reference in which to return the PSU information + * + * @return + * - \ref NVML_SUCCESS if \a psu has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit is invalid or \a psu is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this is not an S-class product + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlUnitGetPsuInfo(nvmlUnit_t unit, nvmlPSUInfo_t *psu); + +/** + * Retrieves the temperature readings for the unit, in degrees C. + * + * For S-class products. + * + * Depending on the product, readings may be available for intake (type=0), + * exhaust (type=1) and board (type=2). + * + * @param unit The identifier of the target unit + * @param type The type of reading to take + * @param temp Reference in which to return the intake temperature + * + * @return + * - \ref NVML_SUCCESS if \a temp has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit or \a type is invalid or \a temp is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this is not an S-class product + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlUnitGetTemperature(nvmlUnit_t unit, unsigned int type, unsigned int *temp); + +/** + * Retrieves the fan speed readings for the unit. + * + * For S-class products. + * + * See \ref nvmlUnitFanSpeeds_t for details on available fan speed info. + * + * @param unit The identifier of the target unit + * @param fanSpeeds Reference in which to return the fan speed information + * + * @return + * - \ref NVML_SUCCESS if \a fanSpeeds has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit is invalid or \a fanSpeeds is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this is not an S-class product + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlUnitGetFanSpeedInfo(nvmlUnit_t unit, nvmlUnitFanSpeeds_t *fanSpeeds); + +/** + * Retrieves the set of GPU devices that are attached to the specified unit. + * + * For S-class products. + * + * The \a deviceCount argument is expected to be set to the size of the input \a devices array. + * + * @param unit The identifier of the target unit + * @param deviceCount Reference in which to provide the \a devices array size, and + * to return the number of attached GPU devices + * @param devices Reference in which to return the references to the attached GPU devices + * + * @return + * - \ref NVML_SUCCESS if \a deviceCount and \a devices have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a deviceCount indicates that the \a devices array is too small + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit is invalid, either of \a deviceCount or \a devices is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlUnitGetDevices(nvmlUnit_t unit, unsigned int *deviceCount, nvmlDevice_t *devices); + +/** + * Retrieves the IDs and firmware versions for any Host Interface Cards (HICs) in the system. + * + * For S-class products. + * + * The \a hwbcCount argument is expected to be set to the size of the input \a hwbcEntries array. + * The HIC must be connected to an S-class system for it to be reported by this function. + * + * @param hwbcCount Size of hwbcEntries array + * @param hwbcEntries Array holding information about hwbc + * + * @return + * - \ref NVML_SUCCESS if \a hwbcCount and \a hwbcEntries have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if either \a hwbcCount or \a hwbcEntries is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a hwbcCount indicates that the \a hwbcEntries array is too small + */ +nvmlReturn_t DECLDIR nvmlSystemGetHicVersion(unsigned int *hwbcCount, nvmlHwbcEntry_t *hwbcEntries); +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlDeviceQueries Device Queries + * This chapter describes that queries that NVML can perform against each device. + * In each case the device is identified with an nvmlDevice_t handle. This handle is obtained by + * calling one of \ref nvmlDeviceGetHandleByIndex(), \ref nvmlDeviceGetHandleBySerial(), + * \ref nvmlDeviceGetHandleByPciBusId(). or \ref nvmlDeviceGetHandleByUUID(). + * @{ + */ +/***************************************************************************************************/ + + /** + * Retrieves the number of compute devices in the system. A compute device is a single GPU. + * + * For all products. + * + * Note: New nvmlDeviceGetCount_v2 (default in NVML 5.319) returns count of all devices in the system + * even if nvmlDeviceGetHandleByIndex_v2 returns NVML_ERROR_NO_PERMISSION for such device. + * Update your code to handle this error, or use NVML 4.304 or older nvml header file. + * For backward binary compatibility reasons _v1 version of the API is still present in the shared + * library. + * Old _v1 version of nvmlDeviceGetCount doesn't count devices that NVML has no permission to talk to. + * + * @param deviceCount Reference in which to return the number of accessible devices + * + * @return + * - \ref NVML_SUCCESS if \a deviceCount has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a deviceCount is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCount(unsigned int *deviceCount); + +/** + * Acquire the handle for a particular device, based on its index. + * + * For all products. + * + * Valid indices are derived from the \a accessibleDevices count returned by + * \ref nvmlDeviceGetCount(). For example, if \a accessibleDevices is 2 the valid indices + * are 0 and 1, corresponding to GPU 0 and GPU 1. + * + * The order in which NVML enumerates devices has no guarantees of consistency between reboots. For that reason it + * is recommended that devices be looked up by their PCI ids or UUID. See + * \ref nvmlDeviceGetHandleByUUID() and \ref nvmlDeviceGetHandleByPciBusId(). + * + * Note: The NVML index may not correlate with other APIs, such as the CUDA device index. + * + * Starting from NVML 5, this API causes NVML to initialize the target GPU + * NVML may initialize additional GPUs if: + * - The target GPU is an SLI slave + * + * Note: New nvmlDeviceGetCount_v2 (default in NVML 5.319) returns count of all devices in the system + * even if nvmlDeviceGetHandleByIndex_v2 returns NVML_ERROR_NO_PERMISSION for such device. + * Update your code to handle this error, or use NVML 4.304 or older nvml header file. + * For backward binary compatibility reasons _v1 version of the API is still present in the shared + * library. + * Old _v1 version of nvmlDeviceGetCount doesn't count devices that NVML has no permission to talk to. + * + * This means that nvmlDeviceGetHandleByIndex_v2 and _v1 can return different devices for the same index. + * If you don't touch macros that map old (_v1) versions to _v2 versions at the top of the file you don't + * need to worry about that. + * + * @param index The index of the target GPU, >= 0 and < \a accessibleDevices + * @param device Reference in which to return the device handle + * + * @return + * - \ref NVML_SUCCESS if \a device has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a index is invalid or \a device is NULL + * - \ref NVML_ERROR_INSUFFICIENT_POWER if any attached devices have improperly attached external power cables + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to talk to this device + * - \ref NVML_ERROR_IRQ_ISSUE if NVIDIA kernel detected an interrupt issue with the attached GPUs + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetIndex + * @see nvmlDeviceGetCount + */ +nvmlReturn_t DECLDIR nvmlDeviceGetHandleByIndex(unsigned int index, nvmlDevice_t *device); + +/** + * Acquire the handle for a particular device, based on its board serial number. + * + * For Fermi &tm; or newer fully supported devices. + * + * This number corresponds to the value printed directly on the board, and to the value returned by + * \ref nvmlDeviceGetSerial(). + * + * @deprecated Since more than one GPU can exist on a single board this function is deprecated in favor + * of \ref nvmlDeviceGetHandleByUUID. + * For dual GPU boards this function will return NVML_ERROR_INVALID_ARGUMENT. + * + * Starting from NVML 5, this API causes NVML to initialize the target GPU + * NVML may initialize additional GPUs as it searches for the target GPU + * + * @param serial The board serial number of the target GPU + * @param device Reference in which to return the device handle + * + * @return + * - \ref NVML_SUCCESS if \a device has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a serial is invalid, \a device is NULL or more than one + * device has the same serial (dual GPU boards) + * - \ref NVML_ERROR_NOT_FOUND if \a serial does not match a valid device on the system + * - \ref NVML_ERROR_INSUFFICIENT_POWER if any attached devices have improperly attached external power cables + * - \ref NVML_ERROR_IRQ_ISSUE if NVIDIA kernel detected an interrupt issue with the attached GPUs + * - \ref NVML_ERROR_GPU_IS_LOST if any GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetSerial + * @see nvmlDeviceGetHandleByUUID + */ +nvmlReturn_t DECLDIR nvmlDeviceGetHandleBySerial(const char *serial, nvmlDevice_t *device); + +/** + * Acquire the handle for a particular device, based on its globally unique immutable UUID associated with each device. + * + * For all products. + * + * @param uuid The UUID of the target GPU + * @param device Reference in which to return the device handle + * + * Starting from NVML 5, this API causes NVML to initialize the target GPU + * NVML may initialize additional GPUs as it searches for the target GPU + * + * @return + * - \ref NVML_SUCCESS if \a device has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a uuid is invalid or \a device is null + * - \ref NVML_ERROR_NOT_FOUND if \a uuid does not match a valid device on the system + * - \ref NVML_ERROR_INSUFFICIENT_POWER if any attached devices have improperly attached external power cables + * - \ref NVML_ERROR_IRQ_ISSUE if NVIDIA kernel detected an interrupt issue with the attached GPUs + * - \ref NVML_ERROR_GPU_IS_LOST if any GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetUUID + */ +nvmlReturn_t DECLDIR nvmlDeviceGetHandleByUUID(const char *uuid, nvmlDevice_t *device); + +/** + * Acquire the handle for a particular device, based on its PCI bus id. + * + * For all products. + * + * This value corresponds to the nvmlPciInfo_t::busId returned by \ref nvmlDeviceGetPciInfo(). + * + * Starting from NVML 5, this API causes NVML to initialize the target GPU + * NVML may initialize additional GPUs if: + * - The target GPU is an SLI slave + * + * \note NVML 4.304 and older version of nvmlDeviceGetHandleByPciBusId"_v1" returns NVML_ERROR_NOT_FOUND + * instead of NVML_ERROR_NO_PERMISSION. + * + * @param pciBusId The PCI bus id of the target GPU + * @param device Reference in which to return the device handle + * + * @return + * - \ref NVML_SUCCESS if \a device has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pciBusId is invalid or \a device is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a pciBusId does not match a valid device on the system + * - \ref NVML_ERROR_INSUFFICIENT_POWER if the attached device has improperly attached external power cables + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to talk to this device + * - \ref NVML_ERROR_IRQ_ISSUE if NVIDIA kernel detected an interrupt issue with the attached GPUs + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetHandleByPciBusId(const char *pciBusId, nvmlDevice_t *device); + +/** + * Retrieves the name of this device. + * + * For all products. + * + * The name is an alphanumeric string that denotes a particular product, e.g. Tesla &tm; C2070. It will not + * exceed 64 characters in length (including the NULL terminator). See \ref + * nvmlConstants::NVML_DEVICE_NAME_BUFFER_SIZE. + * + * @param device The identifier of the target device + * @param name Reference in which to return the product name + * @param length The maximum allowed length of the string returned in \a name + * + * @return + * - \ref NVML_SUCCESS if \a name has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a name is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetName(nvmlDevice_t device, char *name, unsigned int length); + +/** + * Retrieves the brand of this device. + * + * For all products. + * + * The type is a member of \ref nvmlBrandType_t defined above. + * + * @param device The identifier of the target device + * @param type Reference in which to return the product brand type + * + * @return + * - \ref NVML_SUCCESS if \a name has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a type is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetBrand(nvmlDevice_t device, nvmlBrandType_t *type); + +/** + * Retrieves the NVML index of this device. + * + * For all products. + * + * Valid indices are derived from the \a accessibleDevices count returned by + * \ref nvmlDeviceGetCount(). For example, if \a accessibleDevices is 2 the valid indices + * are 0 and 1, corresponding to GPU 0 and GPU 1. + * + * The order in which NVML enumerates devices has no guarantees of consistency between reboots. For that reason it + * is recommended that devices be looked up by their PCI ids or GPU UUID. See + * \ref nvmlDeviceGetHandleByPciBusId() and \ref nvmlDeviceGetHandleByUUID(). + * + * Note: The NVML index may not correlate with other APIs, such as the CUDA device index. + * + * @param device The identifier of the target device + * @param index Reference in which to return the NVML index of the device + * + * @return + * - \ref NVML_SUCCESS if \a index has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a index is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetHandleByIndex() + * @see nvmlDeviceGetCount() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetIndex(nvmlDevice_t device, unsigned int *index); + +/** + * Retrieves the globally unique board serial number associated with this device's board. + * + * For all products with an inforom. + * + * The serial number is an alphanumeric string that will not exceed 30 characters (including the NULL terminator). + * This number matches the serial number tag that is physically attached to the board. See \ref + * nvmlConstants::NVML_DEVICE_SERIAL_BUFFER_SIZE. + * + * @param device The identifier of the target device + * @param serial Reference in which to return the board/module serial number + * @param length The maximum allowed length of the string returned in \a serial + * + * @return + * - \ref NVML_SUCCESS if \a serial has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a serial is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSerial(nvmlDevice_t device, char *serial, unsigned int length); + +/** + * Retrieves an array of unsigned ints (sized to cpuSetSize) of bitmasks with the ideal CPU affinity for the device + * For example, if processors 0, 1, 32, and 33 are ideal for the device and cpuSetSize == 2, + * result[0] = 0x3, result[1] = 0x3 + * + * For Kepler &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device The identifier of the target device + * @param cpuSetSize The size of the cpuSet array that is safe to access + * @param cpuSet Array reference in which to return a bitmask of CPUs, 64 CPUs per + * unsigned long on 64-bit machines, 32 on 32-bit machines + * + * @return + * - \ref NVML_SUCCESS if \a cpuAffinity has been filled + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, cpuSetSize == 0, or cpuSet is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCpuAffinity(nvmlDevice_t device, unsigned int cpuSetSize, unsigned long *cpuSet); + +/** + * Sets the ideal affinity for the calling thread and device using the guidelines + * given in nvmlDeviceGetCpuAffinity(). Note, this is a change as of version 8.0. + * Older versions set the affinity for a calling process and all children. + * Currently supports up to 64 processors. + * + * For Kepler &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device The identifier of the target device + * + * @return + * - \ref NVML_SUCCESS if the calling process has been successfully bound + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetCpuAffinity(nvmlDevice_t device); + +/** + * Clear all affinity bindings for the calling thread. Note, this is a change as of version + * 8.0 as older versions cleared the affinity for a calling process and all children. + * + * For Kepler &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device The identifier of the target device + * + * @return + * - \ref NVML_SUCCESS if the calling process has been successfully unbound + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceClearCpuAffinity(nvmlDevice_t device); + +/** + * Retrieve the common ancestor for two devices + * For all products. + * Supported on Linux only. + * + * @param device1 The identifier of the first device + * @param device2 The identifier of the second device + * @param pathInfo A \ref nvmlGpuTopologyLevel_t that gives the path type + * + * @return + * - \ref NVML_SUCCESS if \a pathInfo has been set + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device1, or \a device2 is invalid, or \a pathInfo is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device or OS does not support this feature + * - \ref NVML_ERROR_UNKNOWN an error has occurred in underlying topology discovery + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTopologyCommonAncestor(nvmlDevice_t device1, nvmlDevice_t device2, nvmlGpuTopologyLevel_t *pathInfo); + +/** + * Retrieve the set of GPUs that are nearest to a given device at a specific interconnectivity level + * For all products. + * Supported on Linux only. + * + * @param device The identifier of the first device + * @param level The \ref nvmlGpuTopologyLevel_t level to search for other GPUs + * @param count When zero, is set to the number of matching GPUs such that \a deviceArray + * can be malloc'd. When non-zero, \a deviceArray will be filled with \a count + * number of device handles. + * @param deviceArray An array of device handles for GPUs found at \a level + * + * @return + * - \ref NVML_SUCCESS if \a deviceArray or \a count (if initially zero) has been set + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a level, or \a count is invalid, or \a deviceArray is NULL with a non-zero \a count + * - \ref NVML_ERROR_NOT_SUPPORTED if the device or OS does not support this feature + * - \ref NVML_ERROR_UNKNOWN an error has occurred in underlying topology discovery + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTopologyNearestGpus(nvmlDevice_t device, nvmlGpuTopologyLevel_t level, unsigned int *count, nvmlDevice_t *deviceArray); + +/** + * Retrieve the set of GPUs that have a CPU affinity with the given CPU number + * For all products. + * Supported on Linux only. + * + * @param cpuNumber The CPU number + * @param count When zero, is set to the number of matching GPUs such that \a deviceArray + * can be malloc'd. When non-zero, \a deviceArray will be filled with \a count + * number of device handles. + * @param deviceArray An array of device handles for GPUs found with affinity to \a cpuNumber + * + * @return + * - \ref NVML_SUCCESS if \a deviceArray or \a count (if initially zero) has been set + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a cpuNumber, or \a count is invalid, or \a deviceArray is NULL with a non-zero \a count + * - \ref NVML_ERROR_NOT_SUPPORTED if the device or OS does not support this feature + * - \ref NVML_ERROR_UNKNOWN an error has occurred in underlying topology discovery + */ +nvmlReturn_t DECLDIR nvmlSystemGetTopologyGpuSet(unsigned int cpuNumber, unsigned int *count, nvmlDevice_t *deviceArray); + +/** + * Retrieve the status for a given p2p capability index between a given pair of GPU + * + * @param device1 The first device + * @param device2 The second device + * @param p2pIndex p2p Capability Index being looked for between \a device1 and \a device2 + * @param p2pStatus Reference in which to return the status of the \a p2pIndex + * between \a device1 and \a device2 + * @return + * - \ref NVML_SUCCESS if \a p2pStatus has been populated + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device1 or \a device2 or \a p2pIndex is invalid or \a p2pStatus is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetP2PStatus(nvmlDevice_t device1, nvmlDevice_t device2, nvmlGpuP2PCapsIndex_t p2pIndex,nvmlGpuP2PStatus_t *p2pStatus); + +/** + * Retrieves the globally unique immutable UUID associated with this device, as a 5 part hexadecimal string, + * that augments the immutable, board serial identifier. + * + * For all products. + * + * The UUID is a globally unique identifier. It is the only available identifier for pre-Fermi-architecture products. + * It does NOT correspond to any identifier printed on the board. It will not exceed 80 characters in length + * (including the NULL terminator). See \ref nvmlConstants::NVML_DEVICE_UUID_BUFFER_SIZE. + * + * @param device The identifier of the target device + * @param uuid Reference in which to return the GPU UUID + * @param length The maximum allowed length of the string returned in \a uuid + * + * @return + * - \ref NVML_SUCCESS if \a uuid has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a uuid is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetUUID(nvmlDevice_t device, char *uuid, unsigned int length); + +/** + * Retrieves minor number for the device. The minor number for the device is such that the Nvidia device node file for + * each GPU will have the form /dev/nvidia[minor number]. + * + * For all products. + * Supported only for Linux + * + * @param device The identifier of the target device + * @param minorNumber Reference in which to return the minor number for the device + * @return + * - \ref NVML_SUCCESS if the minor number is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a minorNumber is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMinorNumber(nvmlDevice_t device, unsigned int *minorNumber); + +/** + * Retrieves the the device board part number which is programmed into the board's InfoROM + * + * For all products. + * + * @param device Identifier of the target device + * @param partNumber Reference to the buffer to return + * @param length Length of the buffer reference + * + * @return + * - \ref NVML_SUCCESS if \a partNumber has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_NOT_SUPPORTED if the needed VBIOS fields have not been filled + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a serial is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetBoardPartNumber(nvmlDevice_t device, char* partNumber, unsigned int length); + +/** + * Retrieves the version information for the device's infoROM object. + * + * For all products with an inforom. + * + * Fermi and higher parts have non-volatile on-board memory for persisting device info, such as aggregate + * ECC counts. The version of the data structures in this memory may change from time to time. It will not + * exceed 16 characters in length (including the NULL terminator). + * See \ref nvmlConstants::NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE. + * + * See \ref nvmlInforomObject_t for details on the available infoROM objects. + * + * @param device The identifier of the target device + * @param object The target infoROM object + * @param version Reference in which to return the infoROM version + * @param length The maximum allowed length of the string returned in \a version + * + * @return + * - \ref NVML_SUCCESS if \a version has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a version is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have an infoROM + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetInforomImageVersion + */ +nvmlReturn_t DECLDIR nvmlDeviceGetInforomVersion(nvmlDevice_t device, nvmlInforomObject_t object, char *version, unsigned int length); + +/** + * Retrieves the global infoROM image version + * + * For all products with an inforom. + * + * Image version just like VBIOS version uniquely describes the exact version of the infoROM flashed on the board + * in contrast to infoROM object version which is only an indicator of supported features. + * Version string will not exceed 16 characters in length (including the NULL terminator). + * See \ref nvmlConstants::NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE. + * + * @param device The identifier of the target device + * @param version Reference in which to return the infoROM image version + * @param length The maximum allowed length of the string returned in \a version + * + * @return + * - \ref NVML_SUCCESS if \a version has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a version is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have an infoROM + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetInforomVersion + */ +nvmlReturn_t DECLDIR nvmlDeviceGetInforomImageVersion(nvmlDevice_t device, char *version, unsigned int length); + +/** + * Retrieves the checksum of the configuration stored in the device's infoROM. + * + * For all products with an inforom. + * + * Can be used to make sure that two GPUs have the exact same configuration. + * Current checksum takes into account configuration stored in PWR and ECC infoROM objects. + * Checksum can change between driver releases or when user changes configuration (e.g. disable/enable ECC) + * + * @param device The identifier of the target device + * @param checksum Reference in which to return the infoROM configuration checksum + * + * @return + * - \ref NVML_SUCCESS if \a checksum has been set + * - \ref NVML_ERROR_CORRUPTED_INFOROM if the device's checksum couldn't be retrieved due to infoROM corruption + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a checksum is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetInforomConfigurationChecksum(nvmlDevice_t device, unsigned int *checksum); + +/** + * Reads the infoROM from the flash and verifies the checksums. + * + * For all products with an inforom. + * + * @param device The identifier of the target device + * + * @return + * - \ref NVML_SUCCESS if infoROM is not corrupted + * - \ref NVML_ERROR_CORRUPTED_INFOROM if the device's infoROM is corrupted + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceValidateInforom(nvmlDevice_t device); + +/** + * Retrieves the display mode for the device. + * + * For all products. + * + * This method indicates whether a physical display (e.g. monitor) is currently connected to + * any of the device's connectors. + * + * See \ref nvmlEnableState_t for details on allowed modes. + * + * @param device The identifier of the target device + * @param display Reference in which to return the display mode + * + * @return + * - \ref NVML_SUCCESS if \a display has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a display is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDisplayMode(nvmlDevice_t device, nvmlEnableState_t *display); + +/** + * Retrieves the display active state for the device. + * + * For all products. + * + * This method indicates whether a display is initialized on the device. + * For example whether X Server is attached to this device and has allocated memory for the screen. + * + * Display can be active even when no monitor is physically attached. + * + * See \ref nvmlEnableState_t for details on allowed modes. + * + * @param device The identifier of the target device + * @param isActive Reference in which to return the display active state + * + * @return + * - \ref NVML_SUCCESS if \a isActive has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a isActive is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDisplayActive(nvmlDevice_t device, nvmlEnableState_t *isActive); + +/** + * Retrieves the persistence mode associated with this device. + * + * For all products. + * For Linux only. + * + * When driver persistence mode is enabled the driver software state is not torn down when the last + * client disconnects. By default this feature is disabled. + * + * See \ref nvmlEnableState_t for details on allowed modes. + * + * @param device The identifier of the target device + * @param mode Reference in which to return the current driver persistence mode + * + * @return + * - \ref NVML_SUCCESS if \a mode has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetPersistenceMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPersistenceMode(nvmlDevice_t device, nvmlEnableState_t *mode); + +/** + * Retrieves the PCI attributes of this device. + * + * For all products. + * + * See \ref nvmlPciInfo_t for details on the available PCI info. + * + * @param device The identifier of the target device + * @param pci Reference in which to return the PCI info + * + * @return + * - \ref NVML_SUCCESS if \a pci has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pci is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPciInfo(nvmlDevice_t device, nvmlPciInfo_t *pci); + +/** + * Retrieves the maximum PCIe link generation possible with this device and system + * + * I.E. for a generation 2 PCIe device attached to a generation 1 PCIe bus the max link generation this function will + * report is generation 1. + * + * For Fermi &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param maxLinkGen Reference in which to return the max PCIe link generation + * + * @return + * - \ref NVML_SUCCESS if \a maxLinkGen has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a maxLinkGen is null + * - \ref NVML_ERROR_NOT_SUPPORTED if PCIe link information is not available + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMaxPcieLinkGeneration(nvmlDevice_t device, unsigned int *maxLinkGen); + +/** + * Retrieves the maximum PCIe link width possible with this device and system + * + * I.E. for a device with a 16x PCIe bus width attached to a 8x PCIe system bus this function will report + * a max link width of 8. + * + * For Fermi &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param maxLinkWidth Reference in which to return the max PCIe link generation + * + * @return + * - \ref NVML_SUCCESS if \a maxLinkWidth has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a maxLinkWidth is null + * - \ref NVML_ERROR_NOT_SUPPORTED if PCIe link information is not available + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMaxPcieLinkWidth(nvmlDevice_t device, unsigned int *maxLinkWidth); + +/** + * Retrieves the current PCIe link generation + * + * For Fermi &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param currLinkGen Reference in which to return the current PCIe link generation + * + * @return + * - \ref NVML_SUCCESS if \a currLinkGen has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a currLinkGen is null + * - \ref NVML_ERROR_NOT_SUPPORTED if PCIe link information is not available + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCurrPcieLinkGeneration(nvmlDevice_t device, unsigned int *currLinkGen); + +/** + * Retrieves the current PCIe link width + * + * For Fermi &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param currLinkWidth Reference in which to return the current PCIe link generation + * + * @return + * - \ref NVML_SUCCESS if \a currLinkWidth has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a currLinkWidth is null + * - \ref NVML_ERROR_NOT_SUPPORTED if PCIe link information is not available + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCurrPcieLinkWidth(nvmlDevice_t device, unsigned int *currLinkWidth); + +/** + * Retrieve PCIe utilization information. + * This function is querying a byte counter over a 20ms interval and thus is the + * PCIe throughput over that interval. + * + * For Maxwell &tm; or newer fully supported devices. + * + * This method is not supported in virtual machines running virtual GPU (vGPU). + * + * @param device The identifier of the target device + * @param counter The specific counter that should be queried \ref nvmlPcieUtilCounter_t + * @param value Reference in which to return throughput in KB/s + * + * @return + * - \ref NVML_SUCCESS if \a value has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a counter is invalid, or \a value is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPcieThroughput(nvmlDevice_t device, nvmlPcieUtilCounter_t counter, unsigned int *value); + +/** + * Retrieve the PCIe replay counter. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param value Reference in which to return the counter's value + * + * @return + * - \ref NVML_SUCCESS if \a value and \a rollover have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a value or \a rollover are NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPcieReplayCounter(nvmlDevice_t device, unsigned int *value); + +/** + * Retrieves the current clock speeds for the device. + * + * For Fermi &tm; or newer fully supported devices. + * + * See \ref nvmlClockType_t for details on available clock information. + * + * @param device The identifier of the target device + * @param type Identify which clock domain to query + * @param clock Reference in which to return the clock speed in MHz + * + * @return + * - \ref NVML_SUCCESS if \a clock has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clock is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device cannot report the specified clock + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetClockInfo(nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock); + +/** + * Retrieves the maximum clock speeds for the device. + * + * For Fermi &tm; or newer fully supported devices. + * + * See \ref nvmlClockType_t for details on available clock information. + * + * \note On GPUs from Fermi family current P0 clocks (reported by \ref nvmlDeviceGetClockInfo) can differ from max clocks + * by few MHz. + * + * @param device The identifier of the target device + * @param type Identify which clock domain to query + * @param clock Reference in which to return the clock speed in MHz + * + * @return + * - \ref NVML_SUCCESS if \a clock has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clock is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device cannot report the specified clock + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMaxClockInfo(nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock); + +/** + * Retrieves the current setting of a clock that applications will use unless an overspec situation occurs. + * Can be changed using \ref nvmlDeviceSetApplicationsClocks. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param clockType Identify which clock domain to query + * @param clockMHz Reference in which to return the clock in MHz + * + * @return + * - \ref NVML_SUCCESS if \a clockMHz has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clockMHz is NULL or \a clockType is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetApplicationsClock(nvmlDevice_t device, nvmlClockType_t clockType, unsigned int *clockMHz); + +/** + * Retrieves the default applications clock that GPU boots with or + * defaults to after \ref nvmlDeviceResetApplicationsClocks call. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param clockType Identify which clock domain to query + * @param clockMHz Reference in which to return the default clock in MHz + * + * @return + * - \ref NVML_SUCCESS if \a clockMHz has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clockMHz is NULL or \a clockType is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * \see nvmlDeviceGetApplicationsClock + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDefaultApplicationsClock(nvmlDevice_t device, nvmlClockType_t clockType, unsigned int *clockMHz); + +/** + * Resets the application clock to the default value + * + * This is the applications clock that will be used after system reboot or driver reload. + * Default value is constant, but the current value an be changed using \ref nvmlDeviceSetApplicationsClocks. + * + * On Pascal and newer hardware, if clocks were previously locked with \ref nvmlDeviceSetApplicationsClocks, + * this call will unlock clocks. This returns clocks their default behavior ofautomatically boosting above + * base clocks as thermal limits allow. + * + * @see nvmlDeviceGetApplicationsClock + * @see nvmlDeviceSetApplicationsClocks + * + * For Fermi &tm; or newer non-GeForce fully supported devices and Maxwell or newer GeForce devices. + * + * @param device The identifier of the target device + * + * @return + * - \ref NVML_SUCCESS if new settings were successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceResetApplicationsClocks(nvmlDevice_t device); + +/** + * Retrieves the clock speed for the clock specified by the clock type and clock ID. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param clockType Identify which clock domain to query + * @param clockId Identify which clock in the domain to query + * @param clockMHz Reference in which to return the clock in MHz + * + * @return + * - \ref NVML_SUCCESS if \a clockMHz has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clockMHz is NULL or \a clockType is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetClock(nvmlDevice_t device, nvmlClockType_t clockType, nvmlClockId_t clockId, unsigned int *clockMHz); + +/** + * Retrieves the customer defined maximum boost clock speed specified by the given clock type. + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param clockType Identify which clock domain to query + * @param clockMHz Reference in which to return the clock in MHz + * + * @return + * - \ref NVML_SUCCESS if \a clockMHz has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clockMHz is NULL or \a clockType is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device or the \a clockType on this device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMaxCustomerBoostClock(nvmlDevice_t device, nvmlClockType_t clockType, unsigned int *clockMHz); + +/** + * Retrieves the list of possible memory clocks that can be used as an argument for \ref nvmlDeviceSetApplicationsClocks. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param count Reference in which to provide the \a clocksMHz array size, and + * to return the number of elements + * @param clocksMHz Reference in which to return the clock in MHz + * + * @return + * - \ref NVML_SUCCESS if \a count and \a clocksMHz have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a count is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a count is too small (\a count is set to the number of + * required elements) + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetApplicationsClocks + * @see nvmlDeviceGetSupportedGraphicsClocks + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSupportedMemoryClocks(nvmlDevice_t device, unsigned int *count, unsigned int *clocksMHz); + +/** + * Retrieves the list of possible graphics clocks that can be used as an argument for \ref nvmlDeviceSetApplicationsClocks. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param memoryClockMHz Memory clock for which to return possible graphics clocks + * @param count Reference in which to provide the \a clocksMHz array size, and + * to return the number of elements + * @param clocksMHz Reference in which to return the clocks in MHz + * + * @return + * - \ref NVML_SUCCESS if \a count and \a clocksMHz have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_NOT_FOUND if the specified \a memoryClockMHz is not a supported frequency + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clock is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a count is too small + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetApplicationsClocks + * @see nvmlDeviceGetSupportedMemoryClocks + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSupportedGraphicsClocks(nvmlDevice_t device, unsigned int memoryClockMHz, unsigned int *count, unsigned int *clocksMHz); + +/** + * Retrieve the current state of Auto Boosted clocks on a device and store it in \a isEnabled + * + * For Kepler &tm; or newer fully supported devices. + * + * Auto Boosted clocks are enabled by default on some hardware, allowing the GPU to run at higher clock rates + * to maximize performance as thermal limits allow. + * + * On Pascal and newer hardware, Auto Aoosted clocks are controlled through application clocks. + * Use \ref nvmlDeviceSetApplicationsClocks and \ref nvmlDeviceResetApplicationsClocks to control Auto Boost + * behavior. + * + * @param device The identifier of the target device + * @param isEnabled Where to store the current state of Auto Boosted clocks of the target device + * @param defaultIsEnabled Where to store the default Auto Boosted clocks behavior of the target device that the device will + * revert to when no applications are using the GPU + * + * @return + * - \ref NVML_SUCCESS If \a isEnabled has been been set with the Auto Boosted clocks state of \a device + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a isEnabled is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support Auto Boosted clocks + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAutoBoostedClocksEnabled(nvmlDevice_t device, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled); + +/** + * Try to set the current state of Auto Boosted clocks on a device. + * + * For Kepler &tm; or newer fully supported devices. + * + * Auto Boosted clocks are enabled by default on some hardware, allowing the GPU to run at higher clock rates + * to maximize performance as thermal limits allow. Auto Boosted clocks should be disabled if fixed clock + * rates are desired. + * + * Non-root users may use this API by default but can be restricted by root from using this API by calling + * \ref nvmlDeviceSetAPIRestriction with apiType=NVML_RESTRICTED_API_SET_AUTO_BOOSTED_CLOCKS. + * Note: Persistence Mode is required to modify current Auto Boost settings, therefore, it must be enabled. + * + * On Pascal and newer hardware, Auto Boosted clocks are controlled through application clocks. + * Use \ref nvmlDeviceSetApplicationsClocks and \ref nvmlDeviceResetApplicationsClocks to control Auto Boost + * behavior. + * + * @param device The identifier of the target device + * @param enabled What state to try to set Auto Boosted clocks of the target device to + * + * @return + * - \ref NVML_SUCCESS If the Auto Boosted clocks were successfully set to the state specified by \a enabled + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support Auto Boosted clocks + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + */ +nvmlReturn_t DECLDIR nvmlDeviceSetAutoBoostedClocksEnabled(nvmlDevice_t device, nvmlEnableState_t enabled); + +/** + * Try to set the default state of Auto Boosted clocks on a device. This is the default state that Auto Boosted clocks will + * return to when no compute running processes (e.g. CUDA application which have an active context) are running + * + * For Kepler &tm; or newer non-GeForce fully supported devices and Maxwell or newer GeForce devices. + * Requires root/admin permissions. + * + * Auto Boosted clocks are enabled by default on some hardware, allowing the GPU to run at higher clock rates + * to maximize performance as thermal limits allow. Auto Boosted clocks should be disabled if fixed clock + * rates are desired. + * + * On Pascal and newer hardware, Auto Boosted clocks are controlled through application clocks. + * Use \ref nvmlDeviceSetApplicationsClocks and \ref nvmlDeviceResetApplicationsClocks to control Auto Boost + * behavior. + * + * @param device The identifier of the target device + * @param enabled What state to try to set default Auto Boosted clocks of the target device to + * @param flags Flags that change the default behavior. Currently Unused. + * + * @return + * - \ref NVML_SUCCESS If the Auto Boosted clock's default state was successfully set to the state specified by \a enabled + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_NO_PERMISSION If the calling user does not have permission to change Auto Boosted clock's default state. + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support Auto Boosted clocks + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + */ +nvmlReturn_t DECLDIR nvmlDeviceSetDefaultAutoBoostedClocksEnabled(nvmlDevice_t device, nvmlEnableState_t enabled, unsigned int flags); + + +/** + * Retrieves the intended operating speed of the device's fan. + * + * Note: The reported speed is the intended fan speed. If the fan is physically blocked and unable to spin, the + * output will not match the actual fan speed. + * + * For all discrete products with dedicated fans. + * + * The fan speed is expressed as a percent of the maximum, i.e. full speed is 100%. + * + * @param device The identifier of the target device + * @param speed Reference in which to return the fan speed percentage + * + * @return + * - \ref NVML_SUCCESS if \a speed has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a speed is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have a fan + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetFanSpeed(nvmlDevice_t device, unsigned int *speed); + +/** + * Retrieves the current temperature readings for the device, in degrees C. + * + * For all products. + * + * See \ref nvmlTemperatureSensors_t for details on available temperature sensors. + * + * @param device The identifier of the target device + * @param sensorType Flag that indicates which sensor reading to retrieve + * @param temp Reference in which to return the temperature reading + * + * @return + * - \ref NVML_SUCCESS if \a temp has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a sensorType is invalid or \a temp is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have the specified sensor + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTemperature(nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp); + +/** + * Retrieves the temperature threshold for the GPU with the specified threshold type in degrees C. + * + * For Kepler &tm; or newer fully supported devices. + * + * See \ref nvmlTemperatureThresholds_t for details on available temperature thresholds. + * + * @param device The identifier of the target device + * @param thresholdType The type of threshold value queried + * @param temp Reference in which to return the temperature reading + * @return + * - \ref NVML_SUCCESS if \a temp has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a thresholdType is invalid or \a temp is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have a temperature sensor or is unsupported + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTemperatureThreshold(nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp); + +/** + * Retrieves the current performance state for the device. + * + * For Fermi &tm; or newer fully supported devices. + * + * See \ref nvmlPstates_t for details on allowed performance states. + * + * @param device The identifier of the target device + * @param pState Reference in which to return the performance state reading + * + * @return + * - \ref NVML_SUCCESS if \a pState has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pState is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPerformanceState(nvmlDevice_t device, nvmlPstates_t *pState); + +/** + * Retrieves current clocks throttling reasons. + * + * For all fully supported products. + * + * \note More than one bit can be enabled at the same time. Multiple reasons can be affecting clocks at once. + * + * @param device The identifier of the target device + * @param clocksThrottleReasons Reference in which to return bitmask of active clocks throttle + * reasons + * + * @return + * - \ref NVML_SUCCESS if \a clocksThrottleReasons has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clocksThrottleReasons is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlClocksThrottleReasons + * @see nvmlDeviceGetSupportedClocksThrottleReasons + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCurrentClocksThrottleReasons(nvmlDevice_t device, unsigned long long *clocksThrottleReasons); + +/** + * Retrieves bitmask of supported clocks throttle reasons that can be returned by + * \ref nvmlDeviceGetCurrentClocksThrottleReasons + * + * For all fully supported products. + * + * This method is not supported in virtual machines running virtual GPU (vGPU). + * + * @param device The identifier of the target device + * @param supportedClocksThrottleReasons Reference in which to return bitmask of supported + * clocks throttle reasons + * + * @return + * - \ref NVML_SUCCESS if \a supportedClocksThrottleReasons has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a supportedClocksThrottleReasons is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlClocksThrottleReasons + * @see nvmlDeviceGetCurrentClocksThrottleReasons + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSupportedClocksThrottleReasons(nvmlDevice_t device, unsigned long long *supportedClocksThrottleReasons); + +/** + * Deprecated: Use \ref nvmlDeviceGetPerformanceState. This function exposes an incorrect generalization. + * + * Retrieve the current performance state for the device. + * + * For Fermi &tm; or newer fully supported devices. + * + * See \ref nvmlPstates_t for details on allowed performance states. + * + * @param device The identifier of the target device + * @param pState Reference in which to return the performance state reading + * + * @return + * - \ref NVML_SUCCESS if \a pState has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pState is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerState(nvmlDevice_t device, nvmlPstates_t *pState); + +/** + * This API has been deprecated. + * + * Retrieves the power management mode associated with this device. + * + * For products from the Fermi family. + * - Requires \a NVML_INFOROM_POWER version 3.0 or higher. + * + * For from the Kepler or newer families. + * - Does not require \a NVML_INFOROM_POWER object. + * + * This flag indicates whether any power management algorithm is currently active on the device. An + * enabled state does not necessarily mean the device is being actively throttled -- only that + * that the driver will do so if the appropriate conditions are met. + * + * See \ref nvmlEnableState_t for details on allowed modes. + * + * @param device The identifier of the target device + * @param mode Reference in which to return the current power management mode + * + * @return + * - \ref NVML_SUCCESS if \a mode has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementMode(nvmlDevice_t device, nvmlEnableState_t *mode); + +/** + * Retrieves the power management limit associated with this device. + * + * For Fermi &tm; or newer fully supported devices. + * + * The power limit defines the upper boundary for the card's power draw. If + * the card's total power draw reaches this limit the power management algorithm kicks in. + * + * This reading is only available if power management mode is supported. + * See \ref nvmlDeviceGetPowerManagementMode. + * + * @param device The identifier of the target device + * @param limit Reference in which to return the power management limit in milliwatts + * + * @return + * - \ref NVML_SUCCESS if \a limit has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a limit is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementLimit(nvmlDevice_t device, unsigned int *limit); + +/** + * Retrieves information about possible values of power management limits on this device. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param minLimit Reference in which to return the minimum power management limit in milliwatts + * @param maxLimit Reference in which to return the maximum power management limit in milliwatts + * + * @return + * - \ref NVML_SUCCESS if \a minLimit and \a maxLimit have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a minLimit or \a maxLimit is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetPowerManagementLimit + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementLimitConstraints(nvmlDevice_t device, unsigned int *minLimit, unsigned int *maxLimit); + +/** + * Retrieves default power management limit on this device, in milliwatts. + * Default power management limit is a power management limit that the device boots with. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param defaultLimit Reference in which to return the default power management limit in milliwatts + * + * @return + * - \ref NVML_SUCCESS if \a defaultLimit has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a defaultLimit is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementDefaultLimit(nvmlDevice_t device, unsigned int *defaultLimit); + +/** + * Retrieves power usage for this GPU in milliwatts and its associated circuitry (e.g. memory) + * + * For Fermi &tm; or newer fully supported devices. + * + * On Fermi and Kepler GPUs the reading is accurate to within +/- 5% of current power draw. + * + * It is only available if power management mode is supported. See \ref nvmlDeviceGetPowerManagementMode. + * + * @param device The identifier of the target device + * @param power Reference in which to return the power usage information + * + * @return + * - \ref NVML_SUCCESS if \a power has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a power is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support power readings + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerUsage(nvmlDevice_t device, unsigned int *power); + +/** + * Retrieves total energy consumption for this GPU in millijoules (mJ) since the driver was last reloaded + * + * For newer than Pascal &tm; fully supported devices. + * + * @param device The identifier of the target device + * @param energy Reference in which to return the energy consumption information + * + * @return + * - \ref NVML_SUCCESS if \a energy has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a energy is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support energy readings + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTotalEnergyConsumption(nvmlDevice_t device, unsigned long long *energy); + +/** + * Get the effective power limit that the driver enforces after taking into account all limiters + * + * Note: This can be different from the \ref nvmlDeviceGetPowerManagementLimit if other limits are set elsewhere + * This includes the out of band power limit interface + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The device to communicate with + * @param limit Reference in which to return the power management limit in milliwatts + * + * @return + * - \ref NVML_SUCCESS if \a limit has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a limit is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEnforcedPowerLimit(nvmlDevice_t device, unsigned int *limit); + +/** + * Retrieves the current GOM and pending GOM (the one that GPU will switch to after reboot). + * + * For GK110 M-class and X-class Tesla &tm; products from the Kepler family. + * Modes \ref NVML_GOM_LOW_DP and \ref NVML_GOM_ALL_ON are supported on fully supported GeForce products. + * Not supported on Quadro ® and Tesla &tm; C-class products. + * + * @param device The identifier of the target device + * @param current Reference in which to return the current GOM + * @param pending Reference in which to return the pending GOM + * + * @return + * - \ref NVML_SUCCESS if \a mode has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a current or \a pending is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlGpuOperationMode_t + * @see nvmlDeviceSetGpuOperationMode + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuOperationMode(nvmlDevice_t device, nvmlGpuOperationMode_t *current, nvmlGpuOperationMode_t *pending); + +/** + * Retrieves the amount of used, free and total memory available on the device, in bytes. + * + * For all products. + * + * Enabling ECC reduces the amount of total available memory, due to the extra required parity bits. + * Under WDDM most device memory is allocated and managed on startup by Windows. + * + * Under Linux and Windows TCC, the reported amount of used memory is equal to the sum of memory allocated + * by all active channels on the device. + * + * See \ref nvmlMemory_t for details on available memory info. + * + * @param device The identifier of the target device + * @param memory Reference in which to return the memory information + * + * @return + * - \ref NVML_SUCCESS if \a memory has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a memory is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMemoryInfo(nvmlDevice_t device, nvmlMemory_t *memory); + +/** + * Retrieves the current compute mode for the device. + * + * For all products. + * + * See \ref nvmlComputeMode_t for details on allowed compute modes. + * + * @param device The identifier of the target device + * @param mode Reference in which to return the current compute mode + * + * @return + * - \ref NVML_SUCCESS if \a mode has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetComputeMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetComputeMode(nvmlDevice_t device, nvmlComputeMode_t *mode); + +/** + * Retrieves the CUDA compute capability of the device. + * + * For all products. + * + * Returns the major and minor compute capability version numbers of the + * device. The major and minor versions are equivalent to the + * CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR and + * CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR attributes that would be + * returned by CUDA's cuDeviceGetAttribute(). + * + * @param device The identifier of the target device + * @param major Reference in which to return the major CUDA compute capability + * @param minor Reference in which to return the minor CUDA compute capability + * + * @return + * - \ref NVML_SUCCESS if \a major and \a minor have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a major or \a minor are NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCudaComputeCapability(nvmlDevice_t device, int *major, int *minor); + +/** + * Retrieves the current and pending ECC modes for the device. + * + * For Fermi &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher. + * + * Changing ECC modes requires a reboot. The "pending" ECC mode refers to the target mode following + * the next reboot. + * + * See \ref nvmlEnableState_t for details on allowed modes. + * + * @param device The identifier of the target device + * @param current Reference in which to return the current ECC mode + * @param pending Reference in which to return the pending ECC mode + * + * @return + * - \ref NVML_SUCCESS if \a current and \a pending have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or either \a current or \a pending is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetEccMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEccMode(nvmlDevice_t device, nvmlEnableState_t *current, nvmlEnableState_t *pending); + +/** + * Retrieves the device boardId from 0-N. + * Devices with the same boardId indicate GPUs connected to the same PLX. Use in conjunction with + * \ref nvmlDeviceGetMultiGpuBoard() to decide if they are on the same board as well. + * The boardId returned is a unique ID for the current configuration. Uniqueness and ordering across + * reboots and system configurations is not guaranteed (i.e. if a Tesla K40c returns 0x100 and + * the two GPUs on a Tesla K10 in the same system returns 0x200 it is not guaranteed they will + * always return those values but they will always be different from each other). + * + * + * For Fermi &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param boardId Reference in which to return the device's board ID + * + * @return + * - \ref NVML_SUCCESS if \a boardId has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a boardId is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetBoardId(nvmlDevice_t device, unsigned int *boardId); + +/** + * Retrieves whether the device is on a Multi-GPU Board + * Devices that are on multi-GPU boards will set \a multiGpuBool to a non-zero value. + * + * For Fermi &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param multiGpuBool Reference in which to return a zero or non-zero value + * to indicate whether the device is on a multi GPU board + * + * @return + * - \ref NVML_SUCCESS if \a multiGpuBool has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a multiGpuBool is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMultiGpuBoard(nvmlDevice_t device, unsigned int *multiGpuBool); + +/** + * Retrieves the total ECC error counts for the device. + * + * For Fermi &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher. + * Requires ECC Mode to be enabled. + * + * The total error count is the sum of errors across each of the separate memory systems, i.e. the total set of + * errors across the entire device. + * + * See \ref nvmlMemoryErrorType_t for a description of available error types.\n + * See \ref nvmlEccCounterType_t for a description of available counter types. + * + * @param device The identifier of the target device + * @param errorType Flag that specifies the type of the errors. + * @param counterType Flag that specifies the counter-type of the errors. + * @param eccCounts Reference in which to return the specified ECC errors + * + * @return + * - \ref NVML_SUCCESS if \a eccCounts has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a errorType or \a counterType is invalid, or \a eccCounts is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceClearEccErrorCounts() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTotalEccErrors(nvmlDevice_t device, nvmlMemoryErrorType_t errorType, nvmlEccCounterType_t counterType, unsigned long long *eccCounts); + +/** + * Retrieves the detailed ECC error counts for the device. + * + * @deprecated This API supports only a fixed set of ECC error locations + * On different GPU architectures different locations are supported + * See \ref nvmlDeviceGetMemoryErrorCounter + * + * For Fermi &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 2.0 or higher to report aggregate location-based ECC counts. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher to report all other ECC counts. + * Requires ECC Mode to be enabled. + * + * Detailed errors provide separate ECC counts for specific parts of the memory system. + * + * Reports zero for unsupported ECC error counters when a subset of ECC error counters are supported. + * + * See \ref nvmlMemoryErrorType_t for a description of available bit types.\n + * See \ref nvmlEccCounterType_t for a description of available counter types.\n + * See \ref nvmlEccErrorCounts_t for a description of provided detailed ECC counts. + * + * @param device The identifier of the target device + * @param errorType Flag that specifies the type of the errors. + * @param counterType Flag that specifies the counter-type of the errors. + * @param eccCounts Reference in which to return the specified ECC errors + * + * @return + * - \ref NVML_SUCCESS if \a eccCounts has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a errorType or \a counterType is invalid, or \a eccCounts is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceClearEccErrorCounts() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDetailedEccErrors(nvmlDevice_t device, nvmlMemoryErrorType_t errorType, nvmlEccCounterType_t counterType, nvmlEccErrorCounts_t *eccCounts); + +/** + * Retrieves the requested memory error counter for the device. + * + * For Fermi &tm; or newer fully supported devices. + * Requires \a NVML_INFOROM_ECC version 2.0 or higher to report aggregate location-based memory error counts. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher to report all other memory error counts. + * + * Only applicable to devices with ECC. + * + * Requires ECC Mode to be enabled. + * + * See \ref nvmlMemoryErrorType_t for a description of available memory error types.\n + * See \ref nvmlEccCounterType_t for a description of available counter types.\n + * See \ref nvmlMemoryLocation_t for a description of available counter locations.\n + * + * @param device The identifier of the target device + * @param errorType Flag that specifies the type of error. + * @param counterType Flag that specifies the counter-type of the errors. + * @param locationType Specifies the location of the counter. + * @param count Reference in which to return the ECC counter + * + * @return + * - \ref NVML_SUCCESS if \a count has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a bitTyp,e \a counterType or \a locationType is + * invalid, or \a count is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support ECC error reporting in the specified memory + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMemoryErrorCounter(nvmlDevice_t device, nvmlMemoryErrorType_t errorType, + nvmlEccCounterType_t counterType, + nvmlMemoryLocation_t locationType, unsigned long long *count); + +/** + * Retrieves the current utilization rates for the device's major subsystems. + * + * For Fermi &tm; or newer fully supported devices. + * + * See \ref nvmlUtilization_t for details on available utilization rates. + * + * \note During driver initialization when ECC is enabled one can see high GPU and Memory Utilization readings. + * This is caused by ECC Memory Scrubbing mechanism that is performed during driver initialization. + * + * @param device The identifier of the target device + * @param utilization Reference in which to return the utilization information + * + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a utilization is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetUtilizationRates(nvmlDevice_t device, nvmlUtilization_t *utilization); + +/** + * Retrieves the current utilization and sampling size in microseconds for the Encoder + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param utilization Reference to an unsigned int for encoder utilization info + * @param samplingPeriodUs Reference to an unsigned int for the sampling period in US + * + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEncoderUtilization(nvmlDevice_t device, unsigned int *utilization, unsigned int *samplingPeriodUs); + +/** + * Retrieves the current capacity of the device's encoder, in macroblocks per second. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param encoderQueryType Type of encoder to query + * @param encoderCapacity Reference to an unsigned int for the encoder capacity + * + * @return + * - \ref NVML_SUCCESS if \a encoderCapacity is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a encoderCapacity is NULL, or \a device or \a encoderQueryType + * are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if device does not support the encoder specified in \a encodeQueryType + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEncoderCapacity (nvmlDevice_t device, nvmlEncoderType_t encoderQueryType, unsigned int *encoderCapacity); + +/** + * Retrieves the current encoder statistics for a given device. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param sessionCount Reference to an unsigned int for count of active encoder sessions + * @param averageFps Reference to an unsigned int for trailing average FPS of all active sessions + * @param averageLatency Reference to an unsigned int for encode latency in microseconds + * + * @return + * - \ref NVML_SUCCESS if \a sessionCount, \a averageFps and \a averageLatency is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount, or \a device or \a averageFps, + * or \a averageLatency is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEncoderStats (nvmlDevice_t device, unsigned int *sessionCount, + unsigned int *averageFps, unsigned int *averageLatency); + +/** + * Retrieves information about active encoder sessions on a target device. + * + * An array of active encoder sessions is returned in the caller-supplied buffer pointed at by \a sessionInfos. The + * array elememt count is passed in \a sessionCount, and \a sessionCount is used to return the number of sessions + * written to the buffer. + * + * If the supplied buffer is not large enough to accommodate the active session array, the function returns + * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlEncoderSessionInfo_t array required in \a sessionCount. + * To query the number of active encoder sessions, call this function with *sessionCount = 0. The code will return + * NVML_SUCCESS with number of active encoder sessions updated in *sessionCount. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param sessionCount Reference to caller supplied array size, and returns the number of sessions. + * @param sessionInfos Reference in which to return the session information + * + * @return + * - \ref NVML_SUCCESS if \a sessionInfos is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a sessionCount is too small, array element count is returned in \a sessionCount + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount is NULL. + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEncoderSessions(nvmlDevice_t device, unsigned int *sessionCount, nvmlEncoderSessionInfo_t *sessionInfos); + +/** + * Retrieves the current utilization and sampling size in microseconds for the Decoder + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param utilization Reference to an unsigned int for decoder utilization info + * @param samplingPeriodUs Reference to an unsigned int for the sampling period in US + * + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDecoderUtilization(nvmlDevice_t device, unsigned int *utilization, unsigned int *samplingPeriodUs); + +/** + * Retrieves the current and pending driver model for the device. + * + * For Fermi &tm; or newer fully supported devices. + * For windows only. + * + * On Windows platforms the device driver can run in either WDDM or WDM (TCC) mode. If a display is attached + * to the device it must run in WDDM mode. TCC mode is preferred if a display is not attached. + * + * See \ref nvmlDriverModel_t for details on available driver models. + * + * @param device The identifier of the target device + * @param current Reference in which to return the current driver model + * @param pending Reference in which to return the pending driver model + * + * @return + * - \ref NVML_SUCCESS if either \a current and/or \a pending have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or both \a current and \a pending are NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the platform is not windows + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetDriverModel() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDriverModel(nvmlDevice_t device, nvmlDriverModel_t *current, nvmlDriverModel_t *pending); + +/** + * Get VBIOS version of the device. + * + * For all products. + * + * The VBIOS version may change from time to time. It will not exceed 32 characters in length + * (including the NULL terminator). See \ref nvmlConstants::NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE. + * + * @param device The identifier of the target device + * @param version Reference to which to return the VBIOS version + * @param length The maximum allowed length of the string returned in \a version + * + * @return + * - \ref NVML_SUCCESS if \a version has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a version is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetVbiosVersion(nvmlDevice_t device, char *version, unsigned int length); + +/** + * Get Bridge Chip Information for all the bridge chips on the board. + * + * For all fully supported products. + * Only applicable to multi-GPU products. + * + * @param device The identifier of the target device + * @param bridgeHierarchy Reference to the returned bridge chip Hierarchy + * + * @return + * - \ref NVML_SUCCESS if bridge chip exists + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a bridgeInfo is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if bridge chip not supported on the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetBridgeChipInfo(nvmlDevice_t device, nvmlBridgeChipHierarchy_t *bridgeHierarchy); + +/** + * Get information about processes with a compute context on a device + * + * For Fermi &tm; or newer fully supported devices. + * + * This function returns information only about compute running processes (e.g. CUDA application which have + * active context). Any graphics applications (e.g. using OpenGL, DirectX) won't be listed by this function. + * + * To query the current number of running compute processes, call this function with *infoCount = 0. The + * return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if none are running. For this call + * \a infos is allowed to be NULL. + * + * The usedGpuMemory field returned is all of the memory used by the application. + * + * Keep in mind that information returned by this call is dynamic and the number of elements might change in + * time. Allocate more space for \a infos table in case new compute processes are spawned. + * + * @param device The identifier of the target device + * @param infoCount Reference in which to provide the \a infos array size, and + * to return the number of returned elements + * @param infos Reference in which to return the process information + * + * @return + * - \ref NVML_SUCCESS if \a infoCount and \a infos have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a infoCount indicates that the \a infos array is too small + * \a infoCount will contain minimal amount of space necessary for + * the call to complete + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, either of \a infoCount or \a infos is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see \ref nvmlSystemGetProcessName + */ +nvmlReturn_t DECLDIR nvmlDeviceGetComputeRunningProcesses(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_t *infos); + +/** + * Get information about processes with a graphics context on a device + * + * For Kepler &tm; or newer fully supported devices. + * + * This function returns information only about graphics based processes + * (eg. applications using OpenGL, DirectX) + * + * To query the current number of running graphics processes, call this function with *infoCount = 0. The + * return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if none are running. For this call + * \a infos is allowed to be NULL. + * + * The usedGpuMemory field returned is all of the memory used by the application. + * + * Keep in mind that information returned by this call is dynamic and the number of elements might change in + * time. Allocate more space for \a infos table in case new graphics processes are spawned. + * + * @param device The identifier of the target device + * @param infoCount Reference in which to provide the \a infos array size, and + * to return the number of returned elements + * @param infos Reference in which to return the process information + * + * @return + * - \ref NVML_SUCCESS if \a infoCount and \a infos have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a infoCount indicates that the \a infos array is too small + * \a infoCount will contain minimal amount of space necessary for + * the call to complete + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, either of \a infoCount or \a infos is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see \ref nvmlSystemGetProcessName + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGraphicsRunningProcesses(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_t *infos); + +/** + * Check if the GPU devices are on the same physical board. + * + * For all fully supported products. + * + * @param device1 The first GPU device + * @param device2 The second GPU device + * @param onSameBoard Reference in which to return the status. + * Non-zero indicates that the GPUs are on the same board. + * + * @return + * - \ref NVML_SUCCESS if \a onSameBoard has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a dev1 or \a dev2 are invalid or \a onSameBoard is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this check is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the either GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceOnSameBoard(nvmlDevice_t device1, nvmlDevice_t device2, int *onSameBoard); + +/** + * Retrieves the root/admin permissions on the target API. See \a nvmlRestrictedAPI_t for the list of supported APIs. + * If an API is restricted only root users can call that API. See \a nvmlDeviceSetAPIRestriction to change current permissions. + * + * For all fully supported products. + * + * @param device The identifier of the target device + * @param apiType Target API type for this operation + * @param isRestricted Reference in which to return the current restriction + * NVML_FEATURE_ENABLED indicates that the API is root-only + * NVML_FEATURE_DISABLED indicates that the API is accessible to all users + * + * @return + * - \ref NVML_SUCCESS if \a isRestricted has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a apiType incorrect or \a isRestricted is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device or the device does not support + * the feature that is being queried (E.G. Enabling/disabling Auto Boosted clocks is + * not supported by the device) + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlRestrictedAPI_t + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAPIRestriction(nvmlDevice_t device, nvmlRestrictedAPI_t apiType, nvmlEnableState_t *isRestricted); + +/** + * Gets recent samples for the GPU. + * + * For Kepler &tm; or newer fully supported devices. + * + * Based on type, this method can be used to fetch the power, utilization or clock samples maintained in the buffer by + * the driver. + * + * Power, Utilization and Clock samples are returned as type "unsigned int" for the union nvmlValue_t. + * + * To get the size of samples that user needs to allocate, the method is invoked with samples set to NULL. + * The returned samplesCount will provide the number of samples that can be queried. The user needs to + * allocate the buffer with size as samplesCount * sizeof(nvmlSample_t). + * + * lastSeenTimeStamp represents CPU timestamp in microseconds. Set it to 0 to fetch all the samples maintained by the + * underlying buffer. Set lastSeenTimeStamp to one of the timeStamps retrieved from the date of the previous query + * to get more recent samples. + * + * This method fetches the number of entries which can be accommodated in the provided samples array, and the + * reference samplesCount is updated to indicate how many samples were actually retrieved. The advantage of using this + * method for samples in contrast to polling via existing methods is to get get higher frequency data at lower polling cost. + * + * @param device The identifier for the target device + * @param type Type of sampling event + * @param lastSeenTimeStamp Return only samples with timestamp greater than lastSeenTimeStamp. + * @param sampleValType Output parameter to represent the type of sample value as described in nvmlSampleVal_t + * @param sampleCount Reference to provide the number of elements which can be queried in samples array + * @param samples Reference in which samples are returned + + * @return + * - \ref NVML_SUCCESS if samples are successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a samplesCount is NULL or + * reference to \a sampleCount is 0 for non null \a samples + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_FOUND if sample entries are not found + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSamples(nvmlDevice_t device, nvmlSamplingType_t type, unsigned long long lastSeenTimeStamp, + nvmlValueType_t *sampleValType, unsigned int *sampleCount, nvmlSample_t *samples); + +/** + * Gets Total, Available and Used size of BAR1 memory. + * + * BAR1 is used to map the FB (device memory) so that it can be directly accessed by the CPU or by 3rd party + * devices (peer-to-peer on the PCIE bus). + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param bar1Memory Reference in which BAR1 memory + * information is returned. + * + * @return + * - \ref NVML_SUCCESS if BAR1 memory is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a bar1Memory is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetBAR1MemoryInfo(nvmlDevice_t device, nvmlBAR1Memory_t *bar1Memory); + + +/** + * Gets the duration of time during which the device was throttled (lower than requested clocks) due to power + * or thermal constraints. + * + * The method is important to users who are tying to understand if their GPUs throttle at any point during their applications. The + * difference in violation times at two different reference times gives the indication of GPU throttling event. + * + * Violation for thermal capping is not supported at this time. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param perfPolicyType Represents Performance policy which can trigger GPU throttling + * @param violTime Reference to which violation time related information is returned + * + * + * @return + * - \ref NVML_SUCCESS if violation time is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a perfPolicyType is invalid, or \a violTime is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetViolationStatus(nvmlDevice_t device, nvmlPerfPolicyType_t perfPolicyType, nvmlViolationTime_t *violTime); + +/** + * @} + */ + +/** @addtogroup nvmlAccountingStats + * @{ + */ + +/** + * Queries the state of per process accounting mode. + * + * For Kepler &tm; or newer fully supported devices. + * + * See \ref nvmlDeviceGetAccountingStats for more details. + * See \ref nvmlDeviceSetAccountingMode + * + * @param device The identifier of the target device + * @param mode Reference in which to return the current accounting mode + * + * @return + * - \ref NVML_SUCCESS if the mode has been successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode are NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAccountingMode(nvmlDevice_t device, nvmlEnableState_t *mode); + +/** + * Queries process's accounting stats. + * + * For Kepler &tm; or newer fully supported devices. + * + * Accounting stats capture GPU utilization and other statistics across the lifetime of a process. + * Accounting stats can be queried during life time of the process and after its termination. + * The time field in \ref nvmlAccountingStats_t is reported as 0 during the lifetime of the process and + * updated to actual running time after its termination. + * Accounting stats are kept in a circular buffer, newly created processes overwrite information about old + * processes. + * + * See \ref nvmlAccountingStats_t for description of each returned metric. + * List of processes that can be queried can be retrieved from \ref nvmlDeviceGetAccountingPids. + * + * @note Accounting Mode needs to be on. See \ref nvmlDeviceGetAccountingMode. + * @note Only compute and graphics applications stats can be queried. Monitoring applications stats can't be + * queried since they don't contribute to GPU utilization. + * @note In case of pid collision stats of only the latest process (that terminated last) will be reported + * + * @warning On Kepler devices per process statistics are accurate only if there's one process running on a GPU. + * + * @param device The identifier of the target device + * @param pid Process Id of the target process to query stats for + * @param stats Reference in which to return the process's accounting stats + * + * @return + * - \ref NVML_SUCCESS if stats have been successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a stats are NULL + * - \ref NVML_ERROR_NOT_FOUND if process stats were not found + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature or accounting mode is disabled + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetAccountingBufferSize + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAccountingStats(nvmlDevice_t device, unsigned int pid, nvmlAccountingStats_t *stats); + +/** + * Queries list of processes that can be queried for accounting stats. The list of processes returned + * can be in running or terminated state. + * + * For Kepler &tm; or newer fully supported devices. + * + * To just query the number of processes ready to be queried, call this function with *count = 0 and + * pids=NULL. The return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if list is empty. + * + * For more details see \ref nvmlDeviceGetAccountingStats. + * + * @note In case of PID collision some processes might not be accessible before the circular buffer is full. + * + * @param device The identifier of the target device + * @param count Reference in which to provide the \a pids array size, and + * to return the number of elements ready to be queried + * @param pids Reference in which to return list of process ids + * + * @return + * - \ref NVML_SUCCESS if pids were successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a count is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature or accounting mode is disabled + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a count is too small (\a count is set to + * expected value) + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetAccountingBufferSize + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAccountingPids(nvmlDevice_t device, unsigned int *count, unsigned int *pids); + +/** + * Returns the number of processes that the circular buffer with accounting pids can hold. + * + * For Kepler &tm; or newer fully supported devices. + * + * This is the maximum number of processes that accounting information will be stored for before information + * about oldest processes will get overwritten by information about new processes. + * + * @param device The identifier of the target device + * @param bufferSize Reference in which to provide the size (in number of elements) + * of the circular buffer for accounting stats. + * + * @return + * - \ref NVML_SUCCESS if buffer size was successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a bufferSize is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature or accounting mode is disabled + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetAccountingStats + * @see nvmlDeviceGetAccountingPids + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAccountingBufferSize(nvmlDevice_t device, unsigned int *bufferSize); + +/** @} */ + +/** @addtogroup nvmlDeviceQueries + * @{ + */ + +/** + * Returns the list of retired pages by source, including pages that are pending retirement + * The address information provided from this API is the hardware address of the page that was retired. Note + * that this does not match the virtual address used in CUDA, but will match the address information in XID 63 + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param cause Filter page addresses by cause of retirement + * @param pageCount Reference in which to provide the \a addresses buffer size, and + * to return the number of retired pages that match \a cause + * Set to 0 to query the size without allocating an \a addresses buffer + * @param addresses Buffer to write the page addresses into + * + * @return + * - \ref NVML_SUCCESS if \a pageCount was populated and \a addresses was filled + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a pageCount indicates the buffer is not large enough to store all the + * matching page addresses. \a pageCount is set to the needed size. + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a pageCount is NULL, \a cause is invalid, or + * \a addresses is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetRetiredPages(nvmlDevice_t device, nvmlPageRetirementCause_t cause, + unsigned int *pageCount, unsigned long long *addresses); + +/** + * Check if any pages are pending retirement and need a reboot to fully retire. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param isPending Reference in which to return the pending status + * + * @return + * - \ref NVML_SUCCESS if \a isPending was populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a isPending is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetRetiredPagesPendingStatus(nvmlDevice_t device, nvmlEnableState_t *isPending); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlUnitCommands Unit Commands + * This chapter describes NVML operations that change the state of the unit. For S-class products. + * Each of these requires root/admin access. Non-admin users will see an NVML_ERROR_NO_PERMISSION + * error code when invoking any of these methods. + * @{ + */ +/***************************************************************************************************/ + +/** + * Set the LED state for the unit. The LED can be either green (0) or amber (1). + * + * For S-class products. + * Requires root/admin permissions. + * + * This operation takes effect immediately. + * + * + * Current S-Class products don't provide unique LEDs for each unit. As such, both front + * and back LEDs will be toggled in unison regardless of which unit is specified with this command. + * + * See \ref nvmlLedColor_t for available colors. + * + * @param unit The identifier of the target unit + * @param color The target LED color + * + * @return + * - \ref NVML_SUCCESS if the LED color has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit or \a color is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this is not an S-class product + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlUnitGetLedState() + */ +nvmlReturn_t DECLDIR nvmlUnitSetLedState(nvmlUnit_t unit, nvmlLedColor_t color); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlDeviceCommands Device Commands + * This chapter describes NVML operations that change the state of the device. + * Each of these requires root/admin access. Non-admin users will see an NVML_ERROR_NO_PERMISSION + * error code when invoking any of these methods. + * @{ + */ +/***************************************************************************************************/ + +/** + * Set the persistence mode for the device. + * + * For all products. + * For Linux only. + * Requires root/admin permissions. + * + * The persistence mode determines whether the GPU driver software is torn down after the last client + * exits. + * + * This operation takes effect immediately. It is not persistent across reboots. After each reboot the + * persistence mode is reset to "Disabled". + * + * See \ref nvmlEnableState_t for available modes. + * + * @param device The identifier of the target device + * @param mode The target persistence mode + * + * @return + * - \ref NVML_SUCCESS if the persistence mode was set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetPersistenceMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceSetPersistenceMode(nvmlDevice_t device, nvmlEnableState_t mode); + +/** + * Set the compute mode for the device. + * + * For all products. + * Requires root/admin permissions. + * + * The compute mode determines whether a GPU can be used for compute operations and whether it can + * be shared across contexts. + * + * This operation takes effect immediately. Under Linux it is not persistent across reboots and + * always resets to "Default". Under windows it is persistent. + * + * Under windows compute mode may only be set to DEFAULT when running in WDDM + * + * See \ref nvmlComputeMode_t for details on available compute modes. + * + * @param device The identifier of the target device + * @param mode The target compute mode + * + * @return + * - \ref NVML_SUCCESS if the compute mode was set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetComputeMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceSetComputeMode(nvmlDevice_t device, nvmlComputeMode_t mode); + +/** + * Set the ECC mode for the device. + * + * For Kepler &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher. + * Requires root/admin permissions. + * + * The ECC mode determines whether the GPU enables its ECC support. + * + * This operation takes effect after the next reboot. + * + * See \ref nvmlEnableState_t for details on available modes. + * + * @param device The identifier of the target device + * @param ecc The target ECC mode + * + * @return + * - \ref NVML_SUCCESS if the ECC mode was set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a ecc is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetEccMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceSetEccMode(nvmlDevice_t device, nvmlEnableState_t ecc); + +/** + * Clear the ECC error and other memory error counts for the device. + * + * For Kepler &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 2.0 or higher to clear aggregate location-based ECC counts. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher to clear all other ECC counts. + * Requires root/admin permissions. + * Requires ECC Mode to be enabled. + * + * Sets all of the specified ECC counters to 0, including both detailed and total counts. + * + * This operation takes effect immediately. + * + * See \ref nvmlMemoryErrorType_t for details on available counter types. + * + * @param device The identifier of the target device + * @param counterType Flag that indicates which type of errors should be cleared. + * + * @return + * - \ref NVML_SUCCESS if the error counts were cleared + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a counterType is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see + * - nvmlDeviceGetDetailedEccErrors() + * - nvmlDeviceGetTotalEccErrors() + */ +nvmlReturn_t DECLDIR nvmlDeviceClearEccErrorCounts(nvmlDevice_t device, nvmlEccCounterType_t counterType); + +/** + * Set the driver model for the device. + * + * For Fermi &tm; or newer fully supported devices. + * For windows only. + * Requires root/admin permissions. + * + * On Windows platforms the device driver can run in either WDDM or WDM (TCC) mode. If a display is attached + * to the device it must run in WDDM mode. + * + * It is possible to force the change to WDM (TCC) while the display is still attached with a force flag (nvmlFlagForce). + * This should only be done if the host is subsequently powered down and the display is detached from the device + * before the next reboot. + * + * This operation takes effect after the next reboot. + * + * Windows driver model may only be set to WDDM when running in DEFAULT compute mode. + * + * Change driver model to WDDM is not supported when GPU doesn't support graphics acceleration or + * will not support it after reboot. See \ref nvmlDeviceSetGpuOperationMode. + * + * See \ref nvmlDriverModel_t for details on available driver models. + * See \ref nvmlFlagDefault and \ref nvmlFlagForce + * + * @param device The identifier of the target device + * @param driverModel The target driver model + * @param flags Flags that change the default behavior + * + * @return + * - \ref NVML_SUCCESS if the driver model has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a driverModel is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the platform is not windows or the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetDriverModel() + */ +nvmlReturn_t DECLDIR nvmlDeviceSetDriverModel(nvmlDevice_t device, nvmlDriverModel_t driverModel, unsigned int flags); + +/** + * Set clocks that applications will lock to. + * + * Sets the clocks that compute and graphics applications will be running at. + * e.g. CUDA driver requests these clocks during context creation which means this property + * defines clocks at which CUDA applications will be running unless some overspec event + * occurs (e.g. over power, over thermal or external HW brake). + * + * Can be used as a setting to request constant performance. + * + * On Pascal and newer hardware, this will automatically disable automatic boosting of clocks. + * + * On K80 and newer Kepler and Maxwell GPUs, users desiring fixed performance should also call + * \ref nvmlDeviceSetAutoBoostedClocksEnabled to prevent clocks from automatically boosting + * above the clock value being set. + * + * For Kepler &tm; or newer non-GeForce fully supported devices and Maxwell or newer GeForce devices. + * Requires root/admin permissions. + * + * See \ref nvmlDeviceGetSupportedMemoryClocks and \ref nvmlDeviceGetSupportedGraphicsClocks + * for details on how to list available clocks combinations. + * + * After system reboot or driver reload applications clocks go back to their default value. + * See \ref nvmlDeviceResetApplicationsClocks. + * + * @param device The identifier of the target device + * @param memClockMHz Requested memory clock in MHz + * @param graphicsClockMHz Requested graphics clock in MHz + * + * @return + * - \ref NVML_SUCCESS if new settings were successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a memClockMHz and \a graphicsClockMHz + * is not a valid clock combination + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetApplicationsClocks(nvmlDevice_t device, unsigned int memClockMHz, unsigned int graphicsClockMHz); + +/** + * Set new power limit of this device. + * + * For Kepler &tm; or newer fully supported devices. + * Requires root/admin permissions. + * + * See \ref nvmlDeviceGetPowerManagementLimitConstraints to check the allowed ranges of values. + * + * \note Limit is not persistent across reboots or driver unloads. + * Enable persistent mode to prevent driver from unloading when no application is using the device. + * + * @param device The identifier of the target device + * @param limit Power management limit in milliwatts to set + * + * @return + * - \ref NVML_SUCCESS if \a limit has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a defaultLimit is out of range + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetPowerManagementLimitConstraints + * @see nvmlDeviceGetPowerManagementDefaultLimit + */ +nvmlReturn_t DECLDIR nvmlDeviceSetPowerManagementLimit(nvmlDevice_t device, unsigned int limit); + +/** + * Sets new GOM. See \a nvmlGpuOperationMode_t for details. + * + * For GK110 M-class and X-class Tesla &tm; products from the Kepler family. + * Modes \ref NVML_GOM_LOW_DP and \ref NVML_GOM_ALL_ON are supported on fully supported GeForce products. + * Not supported on Quadro ® and Tesla &tm; C-class products. + * Requires root/admin permissions. + * + * Changing GOMs requires a reboot. + * The reboot requirement might be removed in the future. + * + * Compute only GOMs don't support graphics acceleration. Under windows switching to these GOMs when + * pending driver model is WDDM is not supported. See \ref nvmlDeviceSetDriverModel. + * + * @param device The identifier of the target device + * @param mode Target GOM + * + * @return + * - \ref NVML_SUCCESS if \a mode has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode incorrect + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support GOM or specific mode + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlGpuOperationMode_t + * @see nvmlDeviceGetGpuOperationMode + */ +nvmlReturn_t DECLDIR nvmlDeviceSetGpuOperationMode(nvmlDevice_t device, nvmlGpuOperationMode_t mode); + +/** + * Changes the root/admin restructions on certain APIs. See \a nvmlRestrictedAPI_t for the list of supported APIs. + * This method can be used by a root/admin user to give non-root/admin access to certain otherwise-restricted APIs. + * The new setting lasts for the lifetime of the NVIDIA driver; it is not persistent. See \a nvmlDeviceGetAPIRestriction + * to query the current restriction settings. + * + * For Kepler &tm; or newer fully supported devices. + * Requires root/admin permissions. + * + * @param device The identifier of the target device + * @param apiType Target API type for this operation + * @param isRestricted The target restriction + * + * @return + * - \ref NVML_SUCCESS if \a isRestricted has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a apiType incorrect + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support changing API restrictions or the device does not support + * the feature that api restrictions are being set for (E.G. Enabling/disabling auto + * boosted clocks is not supported by the device) + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlRestrictedAPI_t + */ +nvmlReturn_t DECLDIR nvmlDeviceSetAPIRestriction(nvmlDevice_t device, nvmlRestrictedAPI_t apiType, nvmlEnableState_t isRestricted); + +/** + * @} + */ + +/** @addtogroup nvmlAccountingStats + * @{ + */ + +/** + * Enables or disables per process accounting. + * + * For Kepler &tm; or newer fully supported devices. + * Requires root/admin permissions. + * + * @note This setting is not persistent and will default to disabled after driver unloads. + * Enable persistence mode to be sure the setting doesn't switch off to disabled. + * + * @note Enabling accounting mode has no negative impact on the GPU performance. + * + * @note Disabling accounting clears all accounting pids information. + * + * See \ref nvmlDeviceGetAccountingMode + * See \ref nvmlDeviceGetAccountingStats + * See \ref nvmlDeviceClearAccountingPids + * + * @param device The identifier of the target device + * @param mode The target accounting mode + * + * @return + * - \ref NVML_SUCCESS if the new mode has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a mode are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetAccountingMode(nvmlDevice_t device, nvmlEnableState_t mode); + +/** + * Clears accounting information about all processes that have already terminated. + * + * For Kepler &tm; or newer fully supported devices. + * Requires root/admin permissions. + * + * See \ref nvmlDeviceGetAccountingMode + * See \ref nvmlDeviceGetAccountingStats + * See \ref nvmlDeviceSetAccountingMode + * + * @param device The identifier of the target device + * + * @return + * - \ref NVML_SUCCESS if accounting information has been cleared + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceClearAccountingPids(nvmlDevice_t device); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup NvLink NvLink Methods + * This chapter describes methods that NVML can perform on NVLINK enabled devices. + * @{ + */ +/***************************************************************************************************/ + +/** + * Retrieves the state of the device's NvLink for the link specified + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param link Specifies the NvLink link to be queried + * @param isActive \a nvmlEnableState_t where NVML_FEATURE_ENABLED indicates that + * the link is active and NVML_FEATURE_DISABLED indicates it + * is inactive + * + * @return + * - \ref NVML_SUCCESS if \a isActive has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a link is invalid or \a isActive is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkState(nvmlDevice_t device, unsigned int link, nvmlEnableState_t *isActive); + +/** + * Retrieves the version of the device's NvLink for the link specified + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param link Specifies the NvLink link to be queried + * @param version Requested NvLink version + * + * @return + * - \ref NVML_SUCCESS if \a version has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a link is invalid or \a version is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkVersion(nvmlDevice_t device, unsigned int link, unsigned int *version); + +/** + * Retrieves the requested capability from the device's NvLink for the link specified + * Please refer to the \a nvmlNvLinkCapability_t structure for the specific caps that can be queried + * The return value should be treated as a boolean. + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param link Specifies the NvLink link to be queried + * @param capability Specifies the \a nvmlNvLinkCapability_t to be queried + * @param capResult A boolean for the queried capability indicating that feature is available + * + * @return + * - \ref NVML_SUCCESS if \a capResult has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a link, or \a capability is invalid or \a capResult is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkCapability(nvmlDevice_t device, unsigned int link, + nvmlNvLinkCapability_t capability, unsigned int *capResult); + +/** + * Retrieves the PCI information for the remote node on a NvLink link + * Note: pciSubSystemId is not filled in this function and is indeterminate + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param link Specifies the NvLink link to be queried + * @param pci \a nvmlPciInfo_t of the remote node for the specified link + * + * @return + * - \ref NVML_SUCCESS if \a pci has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a link is invalid or \a pci is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkRemotePciInfo(nvmlDevice_t device, unsigned int link, nvmlPciInfo_t *pci); + +/** + * Retrieves the specified error counter value + * Please refer to \a nvmlNvLinkErrorCounter_t for error counters that are available + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param link Specifies the NvLink link to be queried + * @param counter Specifies the NvLink counter to be queried + * @param counterValue Returned counter value + * + * @return + * - \ref NVML_SUCCESS if \a counter has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a link, or \a counter is invalid or \a counterValue is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkErrorCounter(nvmlDevice_t device, unsigned int link, + nvmlNvLinkErrorCounter_t counter, unsigned long long *counterValue); + +/** + * Resets all error counters to zero + * Please refer to \a nvmlNvLinkErrorCounter_t for the list of error counters that are reset + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param link Specifies the NvLink link to be queried + * + * @return + * - \ref NVML_SUCCESS if the reset is successful + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a link is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceResetNvLinkErrorCounters(nvmlDevice_t device, unsigned int link); + +/** + * Set the NVLINK utilization counter control information for the specified counter, 0 or 1. + * Please refer to \a nvmlNvLinkUtilizationControl_t for the structure definition. Performs a reset + * of the counters if the reset parameter is non-zero. + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param counter Specifies the counter that should be set (0 or 1). + * @param link Specifies the NvLink link to be queried + * @param control A reference to the \a nvmlNvLinkUtilizationControl_t to set + * @param reset Resets the counters on set if non-zero + * + * @return + * - \ref NVML_SUCCESS if the control has been set successfully + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a counter, \a link, or \a control is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetNvLinkUtilizationControl(nvmlDevice_t device, unsigned int link, unsigned int counter, + nvmlNvLinkUtilizationControl_t *control, unsigned int reset); + +/** + * Get the NVLINK utilization counter control information for the specified counter, 0 or 1. + * Please refer to \a nvmlNvLinkUtilizationControl_t for the structure definition + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param counter Specifies the counter that should be set (0 or 1). + * @param link Specifies the NvLink link to be queried + * @param control A reference to the \a nvmlNvLinkUtilizationControl_t to place information + * + * @return + * - \ref NVML_SUCCESS if the control has been set successfully + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a counter, \a link, or \a control is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkUtilizationControl(nvmlDevice_t device, unsigned int link, unsigned int counter, + nvmlNvLinkUtilizationControl_t *control); + + +/** + * Retrieve the NVLINK utilization counter based on the current control for a specified counter. + * In general it is good practice to use \a nvmlDeviceSetNvLinkUtilizationControl + * before reading the utilization counters as they have no default state + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param link Specifies the NvLink link to be queried + * @param counter Specifies the counter that should be read (0 or 1). + * @param rxcounter Receive counter return value + * @param txcounter Transmit counter return value + * + * @return + * - \ref NVML_SUCCESS if \a rxcounter and \a txcounter have been successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a counter, or \a link is invalid or \a rxcounter or \a txcounter are NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkUtilizationCounter(nvmlDevice_t device, unsigned int link, unsigned int counter, + unsigned long long *rxcounter, unsigned long long *txcounter); + +/** + * Freeze the NVLINK utilization counters + * Both the receive and transmit counters are operated on by this function + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param link Specifies the NvLink link to be queried + * @param counter Specifies the counter that should be frozen (0 or 1). + * @param freeze NVML_FEATURE_ENABLED = freeze the receive and transmit counters + * NVML_FEATURE_DISABLED = unfreeze the receive and transmit counters + * + * @return + * - \ref NVML_SUCCESS if counters were successfully frozen or unfrozen + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a link, \a counter, or \a freeze is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceFreezeNvLinkUtilizationCounter (nvmlDevice_t device, unsigned int link, + unsigned int counter, nvmlEnableState_t freeze); + +/** + * Reset the NVLINK utilization counters + * Both the receive and transmit counters are operated on by this function + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param link Specifies the NvLink link to be reset + * @param counter Specifies the counter that should be reset (0 or 1) + * + * @return + * - \ref NVML_SUCCESS if counters were successfully reset + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a link, or \a counter is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceResetNvLinkUtilizationCounter (nvmlDevice_t device, unsigned int link, unsigned int counter); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlEvents Event Handling Methods + * This chapter describes methods that NVML can perform against each device to register and wait for + * some event to occur. + * @{ + */ +/***************************************************************************************************/ + +/** + * Create an empty set of events. + * Event set should be freed by \ref nvmlEventSetFree + * + * For Fermi &tm; or newer fully supported devices. + * @param set Reference in which to return the event handle + * + * @return + * - \ref NVML_SUCCESS if the event has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a set is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlEventSetFree + */ +nvmlReturn_t DECLDIR nvmlEventSetCreate(nvmlEventSet_t *set); + +/** + * Starts recording of events on a specified devices and add the events to specified \ref nvmlEventSet_t + * + * For Fermi &tm; or newer fully supported devices. + * Ecc events are available only on ECC enabled devices (see \ref nvmlDeviceGetTotalEccErrors) + * Power capping events are available only on Power Management enabled devices (see \ref nvmlDeviceGetPowerManagementMode) + * + * For Linux only. + * + * \b IMPORTANT: Operations on \a set are not thread safe + * + * This call starts recording of events on specific device. + * All events that occurred before this call are not recorded. + * Checking if some event occurred can be done with \ref nvmlEventSetWait + * + * If function reports NVML_ERROR_UNKNOWN, event set is in undefined state and should be freed. + * If function reports NVML_ERROR_NOT_SUPPORTED, event set can still be used. None of the requested eventTypes + * are registered in that case. + * + * @param device The identifier of the target device + * @param eventTypes Bitmask of \ref nvmlEventType to record + * @param set Set to which add new event types + * + * @return + * - \ref NVML_SUCCESS if the event has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a eventTypes is invalid or \a set is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the platform does not support this feature or some of requested event types + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlEventType + * @see nvmlDeviceGetSupportedEventTypes + * @see nvmlEventSetWait + * @see nvmlEventSetFree + */ +nvmlReturn_t DECLDIR nvmlDeviceRegisterEvents(nvmlDevice_t device, unsigned long long eventTypes, nvmlEventSet_t set); + +/** + * Returns information about events supported on device + * + * For Fermi &tm; or newer fully supported devices. + * + * Events are not supported on Windows. So this function returns an empty mask in \a eventTypes on Windows. + * + * @param device The identifier of the target device + * @param eventTypes Reference in which to return bitmask of supported events + * + * @return + * - \ref NVML_SUCCESS if the eventTypes has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a eventType is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlEventType + * @see nvmlDeviceRegisterEvents + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSupportedEventTypes(nvmlDevice_t device, unsigned long long *eventTypes); + +/** + * Waits on events and delivers events + * + * For Fermi &tm; or newer fully supported devices. + * + * If some events are ready to be delivered at the time of the call, function returns immediately. + * If there are no events ready to be delivered, function sleeps till event arrives + * but not longer than specified timeout. This function in certain conditions can return before + * specified timeout passes (e.g. when interrupt arrives) + * + * In case of xid error, the function returns the most recent xid error type seen by the system. If there are multiple + * xid errors generated before nvmlEventSetWait is invoked then the last seen xid error type is returned for all + * xid error events. + * + * @param set Reference to set of events to wait on + * @param data Reference in which to return event data + * @param timeoutms Maximum amount of wait time in milliseconds for registered event + * + * @return + * - \ref NVML_SUCCESS if the data has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a data is NULL + * - \ref NVML_ERROR_TIMEOUT if no event arrived in specified timeout or interrupt arrived + * - \ref NVML_ERROR_GPU_IS_LOST if a GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlEventType + * @see nvmlDeviceRegisterEvents + */ +nvmlReturn_t DECLDIR nvmlEventSetWait(nvmlEventSet_t set, nvmlEventData_t * data, unsigned int timeoutms); + +/** + * Releases events in the set + * + * For Fermi &tm; or newer fully supported devices. + * + * @param set Reference to events to be released + * + * @return + * - \ref NVML_SUCCESS if the event has been successfully released + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceRegisterEvents + */ +nvmlReturn_t DECLDIR nvmlEventSetFree(nvmlEventSet_t set); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlZPI Drain states + * This chapter describes methods that NVML can perform against each device to control their drain state + * and recognition by NVML and NVIDIA kernel driver. These methods can be used with out-of-band tools to + * power on/off GPUs, enable robust reset scenarios, etc. + * @{ + */ +/***************************************************************************************************/ + +/** + * Modify the drain state of a GPU. This method forces a GPU to no longer accept new incoming requests. + * Any new NVML process will no longer see this GPU. Persistence mode for this GPU must be turned off before + * this call is made. + * Must be called as administrator. + * For Linux only. + * + * For Pascal &tm; or newer fully supported devices. + * Some Kepler devices supported. + * + * @param pciInfo The PCI address of the GPU drain state to be modified + * @param newState The drain state that should be entered, see \ref nvmlEnableState_t + * + * @return + * - \ref NVML_SUCCESS if counters were successfully reset + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a nvmlIndex or \a newState is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the calling process has insufficient permissions to perform operation + * - \ref NVML_ERROR_IN_USE if the device has persistence mode turned on + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceModifyDrainState (nvmlPciInfo_t *pciInfo, nvmlEnableState_t newState); + +/** + * Query the drain state of a GPU. This method is used to check if a GPU is in a currently draining + * state. + * For Linux only. + * + * For Pascal &tm; or newer fully supported devices. + * Some Kepler devices supported. + * + * @param pciInfo The PCI address of the GPU drain state to be queried + * @param currentState The current drain state for this GPU, see \ref nvmlEnableState_t + * + * @return + * - \ref NVML_SUCCESS if counters were successfully reset + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a nvmlIndex or \a currentState is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceQueryDrainState (nvmlPciInfo_t *pciInfo, nvmlEnableState_t *currentState); + +/** + * This method will remove the specified GPU from the view of both NVML and the NVIDIA kernel driver + * as long as no other processes are attached. If other processes are attached, this call will return + * NVML_ERROR_IN_USE and the GPU will be returned to its original "draining" state. Note: the + * only situation where a process can still be attached after nvmlDeviceModifyDrainState() is called + * to initiate the draining state is if that process was using, and is still using, a GPU before the + * call was made. Also note, persistence mode counts as an attachment to the GPU thus it must be disabled + * prior to this call. + * + * For long-running NVML processes please note that this will change the enumeration of current GPUs. + * For example, if there are four GPUs present and GPU1 is removed, the new enumeration will be 0-2. + * Also, device handles after the removed GPU will not be valid and must be re-established. + * Must be run as administrator. + * For Linux only. + * + * For Pascal &tm; or newer fully supported devices. + * Some Kepler devices supported. + * + * @param pciInfo The PCI address of the GPU to be removed + * + * @return + * - \ref NVML_SUCCESS if counters were successfully reset + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a nvmlIndex is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_IN_USE if the device is still in use and cannot be removed + */ +nvmlReturn_t DECLDIR nvmlDeviceRemoveGpu (nvmlPciInfo_t *pciInfo); + +/** + * Request the OS and the NVIDIA kernel driver to rediscover a portion of the PCI subsystem looking for GPUs that + * were previously removed. The portion of the PCI tree can be narrowed by specifying a domain, bus, and device. + * If all are zeroes then the entire PCI tree will be searched. Please note that for long-running NVML processes + * the enumeration will change based on how many GPUs are discovered and where they are inserted in bus order. + * + * In addition, all newly discovered GPUs will be initialized and their ECC scrubbed which may take several seconds + * per GPU. Also, all device handles are no longer guaranteed to be valid post discovery. + * + * Must be run as administrator. + * For Linux only. + * + * For Pascal &tm; or newer fully supported devices. + * Some Kepler devices supported. + * + * @param pciInfo The PCI tree to be searched. Only the domain, bus, and device + * fields are used in this call. + * + * @return + * - \ref NVML_SUCCESS if counters were successfully reset + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pciInfo is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the operating system does not support this feature + * - \ref NVML_ERROR_OPERATING_SYSTEM if the operating system is denying this feature + * - \ref NVML_ERROR_NO_PERMISSION if the calling process has insufficient permissions to perform operation + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceDiscoverGpus (nvmlPciInfo_t *pciInfo); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlFieldValueQueries Field Value Queries + * This chapter describes NVML operations that are associated with retrieving Field Values from NVML + * @{ + */ +/***************************************************************************************************/ + +/** + * Request values for a list of fields for a device. This API allows multiple fields to be queried at once. + * If any of the underlying fieldIds are populated by the same driver call, the results for those field IDs + * will be populated from a single call rather than making a driver call for each fieldId. + * + * @param device The device handle of the GPU to request field values for + * @param valuesCount Number of entries in values that should be retrieved + * @param values Array of \a valuesCount structures to hold field values. + * Each value's fieldId must be populated prior to this call + * + * @return + * - \ref NVML_SUCCESS if any values in \a values were populated. Note that you must + * check the nvmlReturn field of each value for each individual + * status + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a values is NULL + */ +nvmlReturn_t DECLDIR nvmlDeviceGetFieldValues(nvmlDevice_t device, int valuesCount, nvmlFieldValue_t *values); + + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlGridQueries Grid Queries + * This chapter describes NVML operations that are associated with NVIDIA GRID products. + * @{ + */ +/***************************************************************************************************/ + +/** + * This method is used to get the virtualization mode corresponding to the GPU. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device Identifier of the target device + * @param pVirtualMode Reference to virtualization mode. One of NVML_GPU_VIRTUALIZATION_? + * + * @return + * - \ref NVML_SUCCESS if \a pVirtualMode is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pVirtualMode is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetVirtualizationMode(nvmlDevice_t device, nvmlGpuVirtualizationMode_t *pVirtualMode); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlGridCommands Grid Commands + * This chapter describes NVML operations that are associated with NVIDIA GRID products. + * @{ + */ +/***************************************************************************************************/ + +/** + * This method is used to set the virtualization mode corresponding to the GPU. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device Identifier of the target device + * @param virtualMode virtualization mode. One of NVML_GPU_VIRTUALIZATION_? + * + * @return + * - \ref NVML_SUCCESS if \a pVirtualMode is set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pVirtualMode is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_SUPPORTED if setting of virtualization mode is not supported. + * - \ref NVML_ERROR_NO_PERMISSION if setting of virtualization mode is not allowed for this client. + */ +nvmlReturn_t DECLDIR nvmlDeviceSetVirtualizationMode(nvmlDevice_t device, nvmlGpuVirtualizationMode_t virtualMode); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlVgpu vGPU Management + * @{ + * + * Set of APIs supporting GRID vGPU + */ +/***************************************************************************************************/ + +/** + * Retrieve the supported vGPU types on a physical GPU (device). + * + * An array of supported vGPU types for the physical GPU indicated by \a device is returned in the caller-supplied buffer + * pointed at by \a vgpuTypeIds. The element count of nvmlVgpuTypeId_t array is passed in \a vgpuCount, and \a vgpuCount + * is used to return the number of vGPU types written to the buffer. + * + * If the supplied buffer is not large enough to accommodate the vGPU type array, the function returns + * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlVgpuTypeId_t array required in \a vgpuCount. + * To query the number of vGPU types supported for the GPU, call this function with *vgpuCount = 0. + * The code will return NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if no vGPU types are supported. + * + * @param device The identifier of the target device + * @param vgpuCount Pointer to caller-supplied array size, and returns number of vGPU types + * @param vgpuTypeIds Pointer to caller-supplied array in which to return list of vGPU types + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_INSUFFICIENT_SIZE \a vgpuTypeIds buffer is too small, array element count is returned in \a vgpuCount + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuCount is NULL or \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if vGPU is not supported by the device + * - \ref NVML_ERROR_VGPU_ECC_NOT_SUPPORTED if ECC is enabled on the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSupportedVgpus(nvmlDevice_t device, unsigned int *vgpuCount, nvmlVgpuTypeId_t *vgpuTypeIds); + +/** + * Retrieve the currently creatable vGPU types on a physical GPU (device). + * + * An array of creatable vGPU types for the physical GPU indicated by \a device is returned in the caller-supplied buffer + * pointed at by \a vgpuTypeIds. The element count of nvmlVgpuTypeId_t array is passed in \a vgpuCount, and \a vgpuCount + * is used to return the number of vGPU types written to the buffer. + * + * The creatable vGPU types for a device may differ over time, as there may be restrictions on what type of vGPU types + * can concurrently run on a device. For example, if only one vGPU type is allowed at a time on a device, then the creatable + * list will be restricted to whatever vGPU type is already running on the device. + * + * If the supplied buffer is not large enough to accommodate the vGPU type array, the function returns + * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlVgpuTypeId_t array required in \a vgpuCount. + * To query the number of vGPU types createable for the GPU, call this function with *vgpuCount = 0. + * The code will return NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if no vGPU types are creatable. + * + * @param device The identifier of the target device + * @param vgpuCount Pointer to caller-supplied array size, and returns number of vGPU types + * @param vgpuTypeIds Pointer to caller-supplied array in which to return list of vGPU types + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_INSUFFICIENT_SIZE \a vgpuTypeIds buffer is too small, array element count is returned in \a vgpuCount + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuCount is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if vGPU is not supported by the device + * - \ref NVML_ERROR_VGPU_ECC_NOT_SUPPORTED if ECC is enabled on the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCreatableVgpus(nvmlDevice_t device, unsigned int *vgpuCount, nvmlVgpuTypeId_t *vgpuTypeIds); + +/** + * Retrieve the class of a vGPU type. It will not exceed 64 characters in length (including the NUL terminator). + * See \ref nvmlConstants::NVML_DEVICE_NAME_BUFFER_SIZE. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param vgpuTypeClass Pointer to string array to return class in + * @param size Size of string + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a vgpuTypeClass is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a size is too small + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetClass(nvmlVgpuTypeId_t vgpuTypeId, char *vgpuTypeClass, unsigned int *size); + +/** + * Retrieve the vGPU type name. + * + * The name is an alphanumeric string that denotes a particular vGPU, e.g. GRID M60-2Q. It will not + * exceed 64 characters in length (including the NUL terminator). See \ref + * nvmlConstants::NVML_DEVICE_NAME_BUFFER_SIZE. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param vgpuTypeName Pointer to buffer to return name + * @param size Size of buffer + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a name is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a size is too small + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetName(nvmlVgpuTypeId_t vgpuTypeId, char *vgpuTypeName, unsigned int *size); + +/** + * Retrieve the device ID of a vGPU type. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param deviceID Device ID and vendor ID of the device contained in single 32 bit value + * @param subsystemID Subsystem ID and subsystem vendor ID of the device contained in single 32 bit value + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a deviceId or \a subsystemID are NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetDeviceID(nvmlVgpuTypeId_t vgpuTypeId, unsigned long long *deviceID, unsigned long long *subsystemID); + +/** + * Retrieve the vGPU framebuffer size in bytes. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param fbSize Pointer to framebuffer size in bytes + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a fbSize is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetFramebufferSize(nvmlVgpuTypeId_t vgpuTypeId, unsigned long long *fbSize); + +/** + * Retrieve count of vGPU's supported display heads. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param numDisplayHeads Pointer to number of display heads + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a numDisplayHeads is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetNumDisplayHeads(nvmlVgpuTypeId_t vgpuTypeId, unsigned int *numDisplayHeads); + +/** + * Retrieve vGPU display head's maximum supported resolution. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param displayIndex Zero-based index of display head + * @param xdim Pointer to maximum number of pixels in X dimension + * @param ydim Pointer to maximum number of pixels in Y dimension + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a xdim or \a ydim are NULL, or \a displayIndex + * is out of range. + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetResolution(nvmlVgpuTypeId_t vgpuTypeId, unsigned int displayIndex, unsigned int *xdim, unsigned int *ydim); + +/** + * Retrieve license requirements for a vGPU type + * + * The license type and version required to run the specified vGPU type is returned as an alphanumeric string, in the form + * ",", for example "GRID-Virtual-PC,2.0". If a vGPU is runnable with* more than one type of license, + * the licenses are delimited by a semicolon, for example "GRID-Virtual-PC,2.0;GRID-Virtual-WS,2.0;GRID-Virtual-WS-Ext,2.0". + * + * The total length of the returned string will not exceed 128 characters, including the NUL terminator. + * See \ref nvmlVgpuConstants::NVML_GRID_LICENSE_BUFFER_SIZE. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param vgpuTypeLicenseString Pointer to buffer to return license info + * @param size Size of \a vgpuTypeLicenseString buffer + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a vgpuTypeLicenseString is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a size is too small + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetLicense(nvmlVgpuTypeId_t vgpuTypeId, char *vgpuTypeLicenseString, unsigned int size); + +/** + * Retrieve the static frame rate limit value of the vGPU type + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param frameRateLimit Reference to return the frame rate limit value + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_NOT_SUPPORTED if frame rate limiter is turned off for the vGPU type + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a frameRateLimit is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetFrameRateLimit(nvmlVgpuTypeId_t vgpuTypeId, unsigned int *frameRateLimit); + +/** + * Retrieve the maximum number of vGPU instances creatable on a device for given vGPU type + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param vgpuTypeId Handle to vGPU type + * @param vgpuInstanceCount Pointer to get the max number of vGPU instances + * that can be created on a deicve for given vgpuTypeId + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid or is not supported on target device, + * or \a vgpuInstanceCount is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetMaxInstances(nvmlDevice_t device, nvmlVgpuTypeId_t vgpuTypeId, unsigned int *vgpuInstanceCount); + +/** + * Retrieve the active vGPU instances on a device. + * + * An array of active vGPU instances is returned in the caller-supplied buffer pointed at by \a vgpuInstances. The + * array elememt count is passed in \a vgpuCount, and \a vgpuCount is used to return the number of vGPU instances + * written to the buffer. + * + * If the supplied buffer is not large enough to accommodate the vGPU instance array, the function returns + * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlVgpuInstance_t array required in \a vgpuCount. + * To query the number of active vGPU instances, call this function with *vgpuCount = 0. The code will return + * NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if no vGPU Types are supported. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param vgpuCount Pointer which passes in the array size as well as get + * back the number of types + * @param vgpuInstances Pointer to array in which to return list of vGPU instances + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a vgpuCount is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a size is too small + * - \ref NVML_ERROR_NOT_SUPPORTED if vGPU is not supported by the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetActiveVgpus(nvmlDevice_t device, unsigned int *vgpuCount, nvmlVgpuInstance_t *vgpuInstances); + +/** + * Retrieve the VM ID associated with a vGPU instance. + * + * The VM ID is returned as a string, not exceeding 80 characters in length (including the NUL terminator). + * See \ref nvmlConstants::NVML_DEVICE_UUID_BUFFER_SIZE. + * + * The format of the VM ID varies by platform, and is indicated by the type identifier returned in \a vmIdType. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param vmId Pointer to caller-supplied buffer to hold VM ID + * @param size Size of buffer in bytes + * @param vmIdType Pointer to hold VM ID type + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a vmId or \a vmIdType are NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a size is too small + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetVmID(nvmlVgpuInstance_t vgpuInstance, char *vmId, unsigned int size, nvmlVgpuVmIdType_t *vmIdType); + +/** + * Retrieve the UUID of a vGPU instance. + * + * The UUID is a globally unique identifier associated with the vGPU, and is returned as a 5-part hexadecimal string, + * not exceeding 80 characters in length (including the NULL terminator). + * See \ref nvmlConstants::NVML_DEVICE_UUID_BUFFER_SIZE. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param uuid Pointer to caller-supplied buffer to hold vGPU UUID + * @param size Size of buffer in bytes + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a uuid is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a size is too small + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetUUID(nvmlVgpuInstance_t vgpuInstance, char *uuid, unsigned int size); + +/** + * Retrieve the NVIDIA driver version installed in the VM associated with a vGPU. + * + * The version is returned as an alphanumeric string in the caller-supplied buffer \a version. The length of the version + * string will not exceed 80 characters in length (including the NUL terminator). + * See \ref nvmlConstants::NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE. + * + * nvmlVgpuInstanceGetVmDriverVersion() may be called at any time for a vGPU instance. The guest VM driver version is + * returned as "Unknown" if no NVIDIA driver is installed in the VM, or the VM has not yet booted to the point where the + * NVIDIA driver is loaded and initialized. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param version Caller-supplied buffer to return driver version string + * @param length Size of \a version buffer + * + * @return + * - \ref NVML_SUCCESS if \a version has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetVmDriverVersion(nvmlVgpuInstance_t vgpuInstance, char* version, unsigned int length); + +/** + * Retrieve the framebuffer usage in bytes. + * + * Framebuffer usage is the amont of vGPU framebuffer memory that is currently in use by the VM. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuInstance The identifier of the target instance + * @param fbUsage Pointer to framebuffer usage in bytes + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a fbUsage is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetFbUsage(nvmlVgpuInstance_t vgpuInstance, unsigned long long *fbUsage); + +/** + * Retrieve the current licensing state of the vGPU instance. + * + * If the vGPU is currently licensed, \a licensed is set to 1, otherwise it is set to 0. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param licensed Reference to return the licensing status + * + * @return + * - \ref NVML_SUCCESS if \a licensed has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a licensed is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetLicenseStatus(nvmlVgpuInstance_t vgpuInstance, unsigned int *licensed); + +/** + * Retrieve the vGPU type of a vGPU instance. + * + * Returns the vGPU type ID of vgpu assigned to the vGPU instance. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param vgpuTypeId Reference to return the vgpuTypeId + * + * @return + * - \ref NVML_SUCCESS if \a vgpuTypeId has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a vgpuTypeId is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetType(nvmlVgpuInstance_t vgpuInstance, nvmlVgpuTypeId_t *vgpuTypeId); + +/** + * Retrieve the frame rate limit set for the vGPU instance. + * + * Returns the value of the frame rate limit set for the vGPU instance + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param frameRateLimit Reference to return the frame rate limit + * + * @return + * - \ref NVML_SUCCESS if \a frameRateLimit has been set + * - \ref NVML_ERROR_NOT_SUPPORTED if frame rate limiter is turned off for the vGPU type + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a frameRateLimit is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetFrameRateLimit(nvmlVgpuInstance_t vgpuInstance, unsigned int *frameRateLimit); + +/** + * Retrieve the encoder Capacity of a vGPU instance, in macroblocks per second. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param encoderCapacity Reference to an unsigned int for the encoder capacity + * + * @return + * - \ref NVML_SUCCESS if \a encoderCapacity has been retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a encoderQueryType is invalid + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEncoderCapacity(nvmlVgpuInstance_t vgpuInstance, unsigned int *encoderCapacity); + +/** + * Set the encoder Capacity of a vGPU instance, in macroblocks per second. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param encoderCapacity Unsigned int for the encoder capacity value + * + * @return + * - \ref NVML_SUCCESS if \a encoderCapacity has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceSetEncoderCapacity(nvmlVgpuInstance_t vgpuInstance, unsigned int encoderCapacity); + +/** + * Retrieves current utilization for vGPUs on a physical GPU (device). + * + * For Kepler &tm; or newer fully supported devices. + * + * Reads recent utilization of GPU SM (3D/Compute), framebuffer, video encoder, and video decoder for vGPU instances running + * on a device. Utilization values are returned as an array of utilization sample structures in the caller-supplied buffer + * pointed at by \a utilizationSamples. One utilization sample structure is returned per vGPU instance, and includes the + * CPU timestamp at which the samples were recorded. Individual utilization values are returned as "unsigned int" values + * in nvmlValue_t unions. The function sets the caller-supplied \a sampleValType to NVML_VALUE_TYPE_UNSIGNED_INT to + * indicate the returned value type. + * + * To read utilization values, first determine the size of buffer required to hold the samples by invoking the function with + * \a utilizationSamples set to NULL. The function will return NVML_ERROR_INSUFFICIENT_SIZE, with the current vGPU instance + * count in \a vgpuInstanceSamplesCount, or NVML_SUCCESS if the current vGPU instance count is zero. The caller should allocate + * a buffer of size vgpuInstanceSamplesCount * sizeof(nvmlVgpuInstanceUtilizationSample_t). Invoke the function again with + * the allocated buffer passed in \a utilizationSamples, and \a vgpuInstanceSamplesCount set to the number of entries the + * buffer is sized for. + * + * On successful return, the function updates \a vgpuInstanceSampleCount with the number of vGPU utilization sample + * structures that were actually written. This may differ from a previously read value as vGPU instances are created or + * destroyed. + * + * lastSeenTimeStamp represents the CPU timestamp in microseconds at which utilization samples were last read. Set it to 0 + * to read utilization based on all the samples maintained by the driver's internal sample buffer. Set lastSeenTimeStamp + * to a timeStamp retrieved from a previous query to read utilization since the previous query. + * + * @param device The identifier for the target device + * @param lastSeenTimeStamp Return only samples with timestamp greater than lastSeenTimeStamp. + * @param sampleValType Pointer to caller-supplied buffer to hold the type of returned sample values + * @param vgpuInstanceSamplesCount Pointer to caller-supplied array size, and returns number of vGPU instances + * @param utilizationSamples Pointer to caller-supplied buffer in which vGPU utilization samples are returned + + * @return + * - \ref NVML_SUCCESS if utilization samples are successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a vgpuInstanceSamplesCount or \a sampleValType is + * NULL, or a sample count of 0 is passed with a non-NULL \a utilizationSamples + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if supplied \a vgpuInstanceSamplesCount is too small to return samples for all + * vGPU instances currently executing on the device + * - \ref NVML_ERROR_NOT_SUPPORTED if vGPU is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_FOUND if sample entries are not found + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetVgpuUtilization(nvmlDevice_t device, unsigned long long lastSeenTimeStamp, + nvmlValueType_t *sampleValType, unsigned int *vgpuInstanceSamplesCount, + nvmlVgpuInstanceUtilizationSample_t *utilizationSamples); + +/** + * Retrieves current utilization for processes running on vGPUs on a physical GPU (device). + * + * For Maxwell &tm; or newer fully supported devices. + * + * Reads recent utilization of GPU SM (3D/Compute), framebuffer, video encoder, and video decoder for processes running on + * vGPU instances active on a device. Utilization values are returned as an array of utilization sample structures in the + * caller-supplied buffer pointed at by \a utilizationSamples. One utilization sample structure is returned per process running + * on vGPU instances, that had some non-zero utilization during the last sample period. It includes the CPU timestamp at which + * the samples were recorded. Individual utilization values are returned as "unsigned int" values. + * + * To read utilization values, first determine the size of buffer required to hold the samples by invoking the function with + * \a utilizationSamples set to NULL. The function will return NVML_ERROR_INSUFFICIENT_SIZE, with the current vGPU instance + * count in \a vgpuProcessSamplesCount. The caller should allocate a buffer of size + * vgpuProcessSamplesCount * sizeof(nvmlVgpuProcessUtilizationSample_t). Invoke the function again with + * the allocated buffer passed in \a utilizationSamples, and \a vgpuProcessSamplesCount set to the number of entries the + * buffer is sized for. + * + * On successful return, the function updates \a vgpuSubProcessSampleCount with the number of vGPU sub process utilization sample + * structures that were actually written. This may differ from a previously read value depending on the number of processes that are active + * in any given sample period. + * + * lastSeenTimeStamp represents the CPU timestamp in microseconds at which utilization samples were last read. Set it to 0 + * to read utilization based on all the samples maintained by the driver's internal sample buffer. Set lastSeenTimeStamp + * to a timeStamp retrieved from a previous query to read utilization since the previous query. + * + * @param device The identifier for the target device + * @param lastSeenTimeStamp Return only samples with timestamp greater than lastSeenTimeStamp. + * @param vgpuProcessSamplesCount Pointer to caller-supplied array size, and returns number of processes running on vGPU instances + * @param utilizationSamples Pointer to caller-supplied buffer in which vGPU sub process utilization samples are returned + + * @return + * - \ref NVML_SUCCESS if utilization samples are successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a vgpuProcessSamplesCount or a sample count of 0 is + * passed with a non-NULL \a utilizationSamples + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if supplied \a vgpuProcessSamplesCount is too small to return samples for all + * vGPU instances currently executing on the device + * - \ref NVML_ERROR_NOT_SUPPORTED if vGPU is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_FOUND if sample entries are not found + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetVgpuProcessUtilization(nvmlDevice_t device, unsigned long long lastSeenTimeStamp, + unsigned int *vgpuProcessSamplesCount, + nvmlVgpuProcessUtilizationSample_t *utilizationSamples); +/** + * Retrieve the GRID licensable features. + * + * Identifies whether the system supports GRID Software Licensing. If it does, return the list of licensable feature(s) + * and their current license status. + * + * @param device Identifier of the target device + * @param pGridLicensableFeatures Pointer to structure in which GRID licensable features are returned + * + * @return + * - \ref NVML_SUCCESS if licensable features are successfully retrieved + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pGridLicensableFeatures is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGridLicensableFeatures(nvmlDevice_t device, nvmlGridLicensableFeatures_t *pGridLicensableFeatures); + +/** + * Retrieves the current encoder statistics of a vGPU Instance + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param sessionCount Reference to an unsigned int for count of active encoder sessions + * @param averageFps Reference to an unsigned int for trailing average FPS of all active sessions + * @param averageLatency Reference to an unsigned int for encode latency in microseconds + * + * @return + * - \ref NVML_SUCCESS if \a sessionCount, \a averageFps and \a averageLatency is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount , or \a averageFps or \a averageLatency is NULL + * or \a vgpuInstance is invalid. + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEncoderStats(nvmlVgpuInstance_t vgpuInstance, unsigned int *sessionCount, + unsigned int *averageFps, unsigned int *averageLatency); + +/** + * Retrieves information about all active encoder sessions on a vGPU Instance. + * + * An array of active encoder sessions is returned in the caller-supplied buffer pointed at by \a sessionInfo. The + * array elememt count is passed in \a sessionCount, and \a sessionCount is used to return the number of sessions + * written to the buffer. + * + * If the supplied buffer is not large enough to accommodate the active session array, the function returns + * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlEncoderSessionInfo_t array required in \a sessionCount. + * To query the number of active encoder sessions, call this function with *sessionCount = 0. The code will return + * NVML_SUCCESS with number of active encoder sessions updated in *sessionCount. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param sessionCount Reference to caller supplied array size, and returns + * the number of sessions. + * @param sessionInfo Reference to caller supplied array in which the list + * of session information us returned. + * + * @return + * - \ref NVML_SUCCESS if \a sessionInfo is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a sessionCount is too small, array element count is + returned in \a sessionCount + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount is NULL or \a vgpuInstance is invalid.. + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEncoderSessions(nvmlVgpuInstance_t vgpuInstance, unsigned int *sessionCount, nvmlEncoderSessionInfo_t *sessionInfo); + +/** + * Retrieves the current utilization and process ID + * + * For Maxwell &tm; or newer fully supported devices. + * + * Reads recent utilization of GPU SM (3D/Compute), framebuffer, video encoder, and video decoder for processes running. + * Utilization values are returned as an array of utilization sample structures in the caller-supplied buffer pointed at + * by \a utilization. One utilization sample structure is returned per process running, that had some non-zero utilization + * during the last sample period. It includes the CPU timestamp at which the samples were recorded. Individual utilization values + * are returned as "unsigned int" values. + * + * To read utilization values, first determine the size of buffer required to hold the samples by invoking the function with + * \a utilization set to NULL. The caller should allocate a buffer of size + * processSamplesCount * sizeof(nvmlProcessUtilizationSample_t). Invoke the function again with the allocated buffer passed + * in \a utilization, and \a processSamplesCount set to the number of entries the buffer is sized for. + * + * On successful return, the function updates \a processSamplesCount with the number of process utilization sample + * structures that were actually written. This may differ from a previously read value as instances are created or + * destroyed. + * + * lastSeenTimeStamp represents the CPU timestamp in microseconds at which utilization samples were last read. Set it to 0 + * to read utilization based on all the samples maintained by the driver's internal sample buffer. Set lastSeenTimeStamp + * to a timeStamp retrieved from a previous query to read utilization since the previous query. + * + * @param device The identifier of the target device + * @param utilization Pointer to caller-supplied buffer in which guest process utilization samples are returned + * @param processSamplesCount Pointer to caller-supplied array size, and returns number of processes running + * @param lastSeenTimeStamp Return only samples with timestamp greater than lastSeenTimeStamp. + + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetProcessUtilization(nvmlDevice_t device, nvmlProcessUtilizationSample_t *utilization, + unsigned int *processSamplesCount, unsigned long long lastSeenTimeStamp); + +/** @} */ + +/** + * NVML API versioning support + */ +#if defined(__NVML_API_VERSION_INTERNAL) +#undef nvmlDeviceGetNvLinkRemotePciInfo +#undef nvmlDeviceGetPciInfo +#undef nvmlDeviceGetCount +#undef nvmlDeviceGetHandleByIndex +#undef nvmlDeviceGetHandleByPciBusId +#undef nvmlInit +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/3rdparty/nvml/repo.json b/src/3rdparty/nvml/repo.json new file mode 100644 index 000000000..8612ffb39 --- /dev/null +++ b/src/3rdparty/nvml/repo.json @@ -0,0 +1,6 @@ +{ + "home": "https://developer.nvidia.com/gpu-deployment-kit", + "license": "Embed in source", + "version": "v9", + "author": "NVIDIA Corporation" +} diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 9951699c3..fc891fc27 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -1,5 +1,6 @@ #include "detection/gpu/gpu.h" #include "detection/vulkan/vulkan.h" +#include "detection/temps/temps_nvidia.h" #ifdef FF_HAVE_LIBPCI #include "common/library.h" @@ -35,7 +36,7 @@ typedef struct PCIData static void pciDetectVendorName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* device) { - ffStrbufAppendS(&gpu->vendor, ffGetGPUVendorString(device->vendor_id)); + ffStrbufSetStatic(&gpu->vendor, ffGetGPUVendorString(device->vendor_id)); if(gpu->vendor.length > 0) return; @@ -45,11 +46,11 @@ static void pciDetectVendorName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* ffStrbufRecalculateLength(&gpu->vendor); if(ffStrbufContainS(&gpu->vendor, "AMD") || ffStrbufContainS(&gpu->vendor, "ATI")) - ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD); + ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD); else if(ffStrbufContainS(&gpu->vendor, "Intel")) - ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL); + ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL); else if(ffStrbufContainS(&gpu->vendor, "NVIDIA")) - ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA); + ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA); } static void drmDetectDeviceName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* device) @@ -240,6 +241,9 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* if(options->temp) pciDetectTemp(gpu, device); #endif + + if (gpu->temperature != gpu->temperature && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) + ffDetectNvidiaGpuTemp(&gpu->temperature, device->device_id); } jmp_buf pciInitJmpBuf; diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 01d88e8c3..80ed6fd91 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -1,4 +1,5 @@ #include "gpu.h" +#include "detection/temps/temps_nvidia.h" #include "util/windows/unicode.h" #include "util/windows/registry.h" @@ -53,11 +54,11 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* ffRegReadStrbuf(hKey, L"ProviderName", &gpu->vendor, NULL); if(ffStrbufContainS(&gpu->vendor, "AMD") || ffStrbufContainS(&gpu->vendor, "ATI")) - ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD); + ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD); else if(ffStrbufContainS(&gpu->vendor, "Intel")) - ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL); + ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL); else if(ffStrbufContainS(&gpu->vendor, "NVIDIA")) - ffStrbufSetS(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA); + ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA); wmemcpy(regDirectxKey + regDirectxKeyPrefixLength, displayDevice.DeviceKey + deviceKeyPrefixLength, strlen("00000000-0000-0000-0000-000000000000}")); FF_HKEY_AUTO_DESTROY hDirectxKey = NULL; @@ -74,6 +75,13 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->dedicated.total = dedicatedVideoMemory + dedicatedSystemMemory; gpu->shared.total = sharedSystemMemory; } + + if (options->temp && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) + { + uint32_t deviceId; + if(ffRegReadUint(hDirectxKey, L"DeviceId", &deviceId, NULL)) + ffDetectNvidiaGpuTemp(&gpu->temperature, deviceId); + } } else if (!ffRegReadUint64(hKey, L"HardwareInformation.qwMemorySize", &gpu->dedicated.total, NULL)) { diff --git a/src/detection/temps/temps_nvidia.c b/src/detection/temps/temps_nvidia.c new file mode 100644 index 000000000..90f241d1a --- /dev/null +++ b/src/detection/temps/temps_nvidia.c @@ -0,0 +1,73 @@ +#include "temps_nvidia.h" + +#include "3rdparty/nvml/nvml.h" +#include "common/library.h" + +struct FFNvmlData { + FF_LIBRARY_SYMBOL(nvmlDeviceGetCount_v2) + FF_LIBRARY_SYMBOL(nvmlDeviceGetHandleByIndex_v2) + FF_LIBRARY_SYMBOL(nvmlDeviceGetPciInfo_v3) + FF_LIBRARY_SYMBOL(nvmlDeviceGetTemperature) + + bool inited; +} nvmlData; + +const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId) +{ + if (!nvmlData.inited) + { + nvmlData.inited = true; + FF_LIBRARY_LOAD(libnvml, NULL, "dlopen nvml failed", +#ifdef _WIN32 + "nvml" +#else + "libnvidia-ml" +#endif + FF_LIBRARY_EXTENSION, -1 + ); + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlInit_v2) + FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlShutdown) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetCount_v2) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetHandleByIndex_v2) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetPciInfo_v3) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetTemperature) + + if (ffnvmlInit_v2() != NVML_SUCCESS) + { + nvmlData.ffnvmlDeviceGetTemperature = NULL; + return "nvmlInit_v2() failed"; + } + atexit((void*) ffnvmlShutdown); + libnvml = NULL; // don't close nvml + } + + if (nvmlData.ffnvmlDeviceGetTemperature == NULL) + return "loading nvml library failed"; + + uint32_t count; + if (nvmlData.ffnvmlDeviceGetCount_v2(&count) != NVML_SUCCESS) + return "nvmlDeviceGetCount_v2() failed"; + + for (uint32_t i = 0; i < count; i++) + { + nvmlDevice_t device; + if (nvmlData.ffnvmlDeviceGetHandleByIndex_v2(i, &device) != NVML_SUCCESS) + continue; + + nvmlPciInfo_t pciInfo; + if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_SUCCESS) + continue; + + if (pciInfo.pciDeviceId >> 16 != deviceId) + continue; + + uint32_t value; + if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) != NVML_SUCCESS) + return "nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) failed"; + + *temp = value; + return NULL; + } + + return "Device not found"; +} diff --git a/src/detection/temps/temps_nvidia.h b/src/detection/temps/temps_nvidia.h new file mode 100644 index 000000000..1b79d2522 --- /dev/null +++ b/src/detection/temps/temps_nvidia.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId); From 155e4a5b8025ae13d93e3cf5f10659a13f96f44c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 27 Oct 2023 00:00:48 +0800 Subject: [PATCH 047/100] Doc: update doc for `--migrate-config` --- src/data/help.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/data/help.txt b/src/data/help.txt index af8e2ba62..719a46c67 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -16,6 +16,7 @@ Informative options: --print-structure: Print the default structure --gen-config : Generate a sample config file in the default path. Param `type` can be `jsonc` or deprecated `conf` --gen-config-force : Generate a sample config file in the default path. Overwrite the existing one + --migrate-config : Migrate old flag based config file to new JSONC format. Optional param `path` is the file path that new file should be write to General options: --load-config : Load a config file or preset (+) From 04409f438123a0a28e29805a2a690ffad1e28cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 27 Oct 2023 11:50:55 +0800 Subject: [PATCH 048/100] Wifi (macOS): better (or worse) support of security detection --- CHANGELOG.md | 2 + CMakeLists.txt | 1 + README.md | 3 +- src/detection/wifi/wifi_apple.m | 91 +++++++++++++++++++++------------ src/modules/wifi/wifi.c | 5 +- 5 files changed, 66 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac2742f03..cd686e92b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,10 +16,12 @@ Features: * Support st terminal font detection (TerminalFont, Linux) * Add option `--migrate-config ` * Support Nvidia GPU temp detection via nvml (GPU) +* Try supporting Wifi authentication type detection in macOS Sonoma. Please file a feature request if you get `to be supported (num)` with result of `/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep auth` (Wifi, macOS) Bugfixes: * Better GPU memory and type detection (GPU, Windows) * Don't print display type twice (Display) +* Detect BSSID instead of Wifi MAC address to align with other platforms (Wifi, macOS) Logos: * Add Black Mesa diff --git a/CMakeLists.txt b/CMakeLists.txt index a32376948..5d9e36098 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -877,6 +877,7 @@ elseif(APPLE) PRIVATE "-weak_framework CoreDisplay" PRIVATE "-weak_framework DisplayServices -F /System/Library/PrivateFrameworks" PRIVATE "-weak_framework MediaRemote -F /System/Library/PrivateFrameworks" + PRIVATE "-weak_framework IO80211 -F /System/Library/PrivateFrameworks" ) elseif(WIN32) target_compile_definitions(libfastfetch PRIVATE -D_WIN32_WINNT=0x0601) diff --git a/README.md b/README.md index da2e4443c..308ad4900 100644 --- a/README.md +++ b/README.md @@ -76,9 +76,10 @@ The following libraries are used if present at runtime: * [`DirectX-Headers`](https://github.com/microsoft/DirectX-Headers): Used for GPU detection in WSL ### macOS - + * [`MediaRemote`](https://iphonedev.wiki/index.php/MediaRemote.framework): Need for Media detection. It's a private framework provided by newer macOS system. * [`DisplayServices`](https://developer.apple.com/forums/thread/666383#663154022): Need for screen brightness detection. It's a private framework provided by newer macOS system. +* [`IO80211`](https://code.google.com/archive/p/iphone-wireless/wikis): Need for Wifi detection on Sonoma (and maybe later). It's a private framework provided by newer macOS system. * [`MoltenVK`](https://github.com/KhronosGroup/MoltenVK): Vulkan driver for macOS. [`molten-vk`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/molten-vk.rb) * [`libmagickcore` (ImageMagick)](https://www.imagemagick.org/): Images in terminal using sixel graphics protocol. [`imagemagick`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/imagemagick.rb) * [`libchafa`](https://github.com/hpjansson/chafa): Image output as ascii art. [`chafa`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/chafa.rb) diff --git a/src/detection/wifi/wifi_apple.m b/src/detection/wifi/wifi_apple.m index 188e0b29f..0281f4440 100644 --- a/src/detection/wifi/wifi_apple.m +++ b/src/detection/wifi/wifi_apple.m @@ -3,6 +3,27 @@ #import +struct Apple80211; // https://code.google.com/archive/p/iphone-wireless/wikis/Apple80211.wiki + +// 0 is sucessful; < 0 is failure +int Apple80211Open(struct Apple80211 **handle) __attribute__((weak_import)); +int Apple80211BindToInterface(struct Apple80211 *handle, CFStringRef interface) __attribute__((weak_import)); +int Apple80211GetInfoCopy(struct Apple80211 *handle, CFDictionaryRef *info) __attribute__((weak_import)); +int Apple80211Close(struct Apple80211 *handle) __attribute__((weak_import)); + +static NSDictionary* getWifiInfoByApple80211(NSString* ifName) +{ + if (!Apple80211Open || !Apple80211BindToInterface || !Apple80211GetInfoCopy || !Apple80211Close) return NULL; + + struct Apple80211* handle = NULL; + if (Apple80211Open(&handle) < 0) return NULL; + if (Apple80211BindToInterface(handle, (CFStringRef)ifName) < 0) return NULL; + CFDictionaryRef result; + if (Apple80211GetInfoCopy(handle, &result) < 0) return NULL; + Apple80211Close(handle); + return CFBridgingRelease(result); +} + const char* ffDetectWifi(FFlist* result) { NSArray* interfaces = CWWiFiClient.sharedWiFiClient.interfaces; @@ -28,27 +49,24 @@ const char* ffDetectWifi(FFlist* result) if(!inf.powerOn) continue; - ffStrbufSetStatic(&item->conn.status, inf.serviceActive ? "Active" : "Inactive"); + ffStrbufSetStatic(&item->conn.status, inf.interfaceMode != kCWInterfaceModeNone ? "Active" : "Inactive"); if(!inf.serviceActive) continue; - if (inf.ssid) + NSDictionary* apple = NULL; + + if (inf.ssid) // https://developer.apple.com/forums/thread/732431 ffStrbufAppendS(&item->conn.ssid, inf.ssid.UTF8String); - else if (!ffProcessAppendStdOut(&item->conn.ssid, (char* []) { - "/usr/sbin/networksetup", - "-getairportnetwork", - item->inf.description.chars, - NULL - }) && item->conn.ssid.length > 0) - { - uint32_t index = ffStrbufFirstIndexC(&item->conn.ssid, ':'); - if (index < item->conn.ssid.length) - ffStrbufSubstrAfter(&item->conn.ssid, index + 1); - } + else if (apple || (apple = getWifiInfoByApple80211(inf.interfaceName))) + ffStrbufAppendS(&item->conn.ssid, [[apple valueForKey:@"SSID_STR"] UTF8String]); else ffStrbufSetStatic(&item->conn.ssid, ""); // https://developer.apple.com/forums/thread/732431 - ffStrbufAppendS(&item->conn.macAddress, inf.hardwareAddress.UTF8String); + if (inf.bssid) + ffStrbufAppendS(&item->conn.macAddress, inf.bssid.UTF8String); + else if (apple || (apple = getWifiInfoByApple80211(inf.interfaceName))) + ffStrbufAppendS(&item->conn.macAddress, [[apple valueForKey:@"BSSID"] UTF8String]); + switch(inf.activePHYMode) { case kCWPHYModeNone: @@ -134,28 +152,35 @@ const char* ffDetectWifi(FFlist* result) break; case kCWSecurityUnknown: // Sonoma... + if (apple || (apple = getWifiInfoByApple80211(inf.interfaceName))) { - if (!ffProcessAppendStdOut(&item->conn.security, (char* []) { - "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport", - "-I", - NULL - })) + NSDictionary* authType = [apple valueForKey:@"AUTH_TYPE"]; + if (authType) { - { - uint32_t ssidIndex = ffStrbufFirstIndexS(&item->conn.security, " SSID: "); - if (ssidIndex == item->conn.security.length) break; - ssidIndex += (uint32_t) strlen(" SSID: "); - uint32_t ssidEndIndex = ffStrbufNextIndexC(&item->conn.security, ssidIndex, '\n'); - if (item->conn.ssid.length != ssidEndIndex - ssidIndex) break; - } + if ([[authType valueForKey:@"AUTH_LOWER"] intValue] != 1) break; // APPLE80211_AUTH_TYPE_UNICAST? - uint32_t linkAuthIndex = ffStrbufFirstIndexS(&item->conn.security, " link auth: "); - if (linkAuthIndex == item->conn.security.length) break; - linkAuthIndex += (uint32_t) strlen(" link auth: "); - uint32_t linkAuthEndIndex = ffStrbufNextIndexC(&item->conn.security, linkAuthIndex, '\n'); - ffStrbufSubstrBefore(&item->conn.security, linkAuthEndIndex); - ffStrbufSubstrAfter(&item->conn.security, linkAuthIndex - 1); - ffStrbufUpperCase(&item->conn.security); + NSNumber* authUpper = [authType valueForKey:@"AUTH_UPPER"]; + if (!authUpper) + ffStrbufSetStatic(&item->conn.security, "Insecure"); + else + { + int authUpperValue = [authUpper intValue]; + switch (authUpperValue) + { + case 4096: + ffStrbufSetStatic(&item->conn.security, "WPA3-SAE"); + break; + case 8: + ffStrbufSetStatic(&item->conn.security, "WPA2-PSK"); + break; + case 4: + ffStrbufSetStatic(&item->conn.security, "WPA2"); + break; + default: // TODO: support more auth types + ffStrbufAppendF(&item->conn.security, "To be supported (%d)", authUpperValue); + break; + } + } } } break; diff --git a/src/modules/wifi/wifi.c b/src/modules/wifi/wifi.c index 152fe86ee..25617d677 100644 --- a/src/modules/wifi/wifi.c +++ b/src/modules/wifi/wifi.c @@ -132,8 +132,9 @@ void ffGenerateWifiJsonResult(FF_MAYBE_UNUSED FFWifiOptions* options, yyjson_mut yyjson_mut_val* conn = yyjson_mut_obj_add_obj(doc, obj, "conn"); yyjson_mut_obj_add_strbuf(doc, conn, "status", &wifi->conn.status); yyjson_mut_obj_add_strbuf(doc, conn, "ssid", &wifi->conn.ssid); - yyjson_mut_obj_add_strbuf(doc, conn, "macAddress", &wifi->conn.macAddress); + yyjson_mut_obj_add_strbuf(doc, conn, "bssid", &wifi->conn.macAddress); yyjson_mut_obj_add_strbuf(doc, conn, "protocol", &wifi->conn.protocol); + yyjson_mut_obj_add_strbuf(doc, conn, "security", &wifi->conn.security); yyjson_mut_obj_add_real(doc, conn, "signalQuality", wifi->conn.signalQuality); yyjson_mut_obj_add_real(doc, conn, "rxRate", wifi->conn.rxRate); yyjson_mut_obj_add_real(doc, conn, "txRate", wifi->conn.txRate); @@ -158,7 +159,7 @@ void ffPrintWifiHelpFormat(void) "Interface status", "Connection status", "Connection SSID", - "Connection mac address", + "Connection BSSID", "Connection protocol", "Connection signal quality (percentage)", "Connection RX rate", From df245f32ec7b87b3ca0c25fae1c219d7931da1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 27 Oct 2023 11:52:14 +0800 Subject: [PATCH 049/100] FFlist: add `FF_LIST_GET` this macro can be safer to use than `ffListGet` because it detects wrong type convertion --- src/util/FFlist.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util/FFlist.h b/src/util/FFlist.h index 276a65e13..0f71b1bff 100644 --- a/src/util/FFlist.h +++ b/src/util/FFlist.h @@ -103,4 +103,11 @@ static inline void ffListClear(FFlist* list) #define FF_LIST_AUTO_DESTROY FFlist __attribute__((__cleanup__(ffListDestroy))) +#define FF_LIST_GET(itemType, listVar, index) \ + ({ \ + assert(sizeof(itemType) == (listVar).elementSize); \ + assert((listVar).capacity > (index)); \ + (itemType*)(listVar).data + (index); \ + }) + #endif From cda4c62e9ed1b7d06860bb26de4d18af298f07ad Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 27 Oct 2023 16:59:10 +0800 Subject: [PATCH 050/100] macOS: fix building on old macOS version --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d9e36098..0f7fab9b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -875,9 +875,11 @@ elseif(APPLE) PRIVATE "-framework OpenCL" PRIVATE "-framework SystemConfiguration" PRIVATE "-weak_framework CoreDisplay" - PRIVATE "-weak_framework DisplayServices -F /System/Library/PrivateFrameworks" - PRIVATE "-weak_framework MediaRemote -F /System/Library/PrivateFrameworks" - PRIVATE "-weak_framework IO80211 -F /System/Library/PrivateFrameworks" + + PRIVATE "-F /System/Library/PrivateFrameworks" + PRIVATE "-weak_framework DisplayServices" + PRIVATE "-weak_framework MediaRemote" + PRIVATE "-weak_framework Apple80211" ) elseif(WIN32) target_compile_definitions(libfastfetch PRIVATE -D_WIN32_WINNT=0x0601) From 130d5a5202332b57b7d3f2e7528eb6c0da66f29d Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 27 Oct 2023 17:35:28 +0800 Subject: [PATCH 051/100] Sound (macOS): fix no sound devices detected error on old macOS version --- src/detection/sound/sound_apple.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/detection/sound/sound_apple.c b/src/detection/sound/sound_apple.c index 1d1962164..22ecec2ac 100644 --- a/src/detection/sound/sound_apple.c +++ b/src/detection/sound/sound_apple.c @@ -49,14 +49,23 @@ const char* ffDetectSound(FFlist* devices /* List of FFSoundDevice */) }, 0, NULL, &dataSize) == kAudioHardwareNoError && dataSize > 0) continue; - uint32_t connected; - dataSize = sizeof(connected); + uint32_t dataSource; + dataSize = sizeof(dataSource); if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ - kAudioDevicePropertyJackIsConnected, + kAudioDevicePropertyDataSource, kAudioObjectPropertyScopeOutput, kAudioObjectPropertyElementMain - }, 0, NULL, &dataSize, &connected) == kAudioHardwareNoError) - if (!connected) continue; + }, 0, NULL, &dataSize, &dataSource) == kAudioHardwareNoError && dataSource == 'hdpn') + { + uint32_t connected; + dataSize = sizeof(connected); + if(AudioObjectGetPropertyData(deviceId, &(AudioObjectPropertyAddress){ + kAudioDevicePropertyJackIsConnected, + kAudioObjectPropertyScopeOutput, + kAudioObjectPropertyElementMain + }, 0, NULL, &dataSize, &connected) == kAudioHardwareNoError) + if (!connected) continue; + } FFSoundDevice* device = (FFSoundDevice*) ffListAdd(devices); device->main = deviceId == mainDeviceId; From dd3109cd89ebc350236c54db92c2c1ef7d86a843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 27 Oct 2023 21:05:03 +0800 Subject: [PATCH 052/100] GPU: better nvidia GPU temp detection --- src/3rdparty/nvml/nvml.h | 9023 +++++++++++++++++++++------- src/3rdparty/nvml/repo.json | 4 +- src/detection/gpu/gpu_linux.c | 6 +- src/detection/gpu/gpu_windows.c | 16 +- src/detection/temps/temps_nvidia.c | 55 +- src/detection/temps/temps_nvidia.h | 2 +- 6 files changed, 6901 insertions(+), 2205 deletions(-) diff --git a/src/3rdparty/nvml/nvml.h b/src/3rdparty/nvml/nvml.h index 53bced8df..191d41da5 100644 --- a/src/3rdparty/nvml/nvml.h +++ b/src/3rdparty/nvml/nvml.h @@ -1,42 +1,42 @@ /* - * Copyright 1993-2017 NVIDIA Corporation. All rights reserved. + * Copyright 1993-2023 NVIDIA Corporation. All rights reserved. * - * NOTICE TO USER: + * NOTICE TO USER: * - * This source code is subject to NVIDIA ownership rights under U.S. and - * international Copyright laws. Users and possessors of this source code - * are hereby granted a nonexclusive, royalty-free license to use this code + * This source code is subject to NVIDIA ownership rights under U.S. and + * international Copyright laws. Users and possessors of this source code + * are hereby granted a nonexclusive, royalty-free license to use this code * in individual and commercial software. * - * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE - * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR - * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH - * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF + * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE + * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR + * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH + * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. - * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, - * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE - * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE - * OR PERFORMANCE OF THIS SOURCE CODE. + * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE + * OR PERFORMANCE OF THIS SOURCE CODE. * - * U.S. Government End Users. This source code is a "commercial item" as - * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of - * "commercial computer software" and "commercial computer software - * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) - * and is provided to the U.S. Government only as a commercial end item. - * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through - * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the - * source code with only those rights set forth herein. + * U.S. Government End Users. This source code is a "commercial item" as + * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of + * "commercial computer software" and "commercial computer software + * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) + * and is provided to the U.S. Government only as a commercial end item. + * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through + * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the + * source code with only those rights set forth herein. * - * Any use of this source code in individual and commercial software must + * Any use of this source code in individual and commercial software must * include, in the user documentation and internal comments to the code, * the above Disclaimer and U.S. Government End Users Notice. */ -/* +/* NVML API Reference -The NVIDIA Management Library (NVML) is a C-based programmatic interface for monitoring and +The NVIDIA Management Library (NVML) is a C-based programmatic interface for monitoring and managing various states within NVIDIA Tesla &tm; GPUs. It is intended to be a platform for building 3rd party applications, and is also the underlying library for the NVIDIA-supported nvidia-smi tool. NVML is thread-safe so it is safe to make simultaneous NVML calls from multiple threads. @@ -52,13 +52,13 @@ Supported products: - Full Support - All Tesla products, starting with the Fermi architecture - All Quadro products, starting with the Fermi architecture - - All GRID products, starting with the Kepler architecture + - All vGPU Software products, starting with the Kepler architecture - Selected GeForce Titan products - Limited Support - All Geforce products, starting with the Fermi architecture The NVML library can be found at \%ProgramW6432\%\\"NVIDIA Corporation"\\NVSMI\\ on Windows. It is -not be added to the system path by default. To dynamically link to NVML, add this path to the PATH +not be added to the system path by default. To dynamically link to NVML, add this path to the PATH environmental variable. To dynamically load NVML, call LoadLibrary with this path. On Linux the NVML library will be found on the standard library path. For 64 bit Linux, both the 32 bit @@ -95,14 +95,37 @@ extern "C" { /** * NVML API versioning support */ -#define NVML_API_VERSION 9 -#define NVML_API_VERSION_STR "9" -#define nvmlInit nvmlInit_v2 -#define nvmlDeviceGetPciInfo nvmlDeviceGetPciInfo_v3 -#define nvmlDeviceGetCount nvmlDeviceGetCount_v2 -#define nvmlDeviceGetHandleByIndex nvmlDeviceGetHandleByIndex_v2 -#define nvmlDeviceGetHandleByPciBusId nvmlDeviceGetHandleByPciBusId_v2 -#define nvmlDeviceGetNvLinkRemotePciInfo nvmlDeviceGetNvLinkRemotePciInfo_v2 +#define NVML_API_VERSION 12 +#define NVML_API_VERSION_STR "12" +/** + * Defining NVML_NO_UNVERSIONED_FUNC_DEFS will disable "auto upgrading" of APIs. + * e.g. the user will have to call nvmlInit_v2 instead of nvmlInit. Enable this + * guard if you need to support older versions of the API + */ +#ifndef NVML_NO_UNVERSIONED_FUNC_DEFS + #define nvmlInit nvmlInit_v2 + #define nvmlDeviceGetPciInfo nvmlDeviceGetPciInfo_v3 + #define nvmlDeviceGetCount nvmlDeviceGetCount_v2 + #define nvmlDeviceGetHandleByIndex nvmlDeviceGetHandleByIndex_v2 + #define nvmlDeviceGetHandleByPciBusId nvmlDeviceGetHandleByPciBusId_v2 + #define nvmlDeviceGetNvLinkRemotePciInfo nvmlDeviceGetNvLinkRemotePciInfo_v2 + #define nvmlDeviceRemoveGpu nvmlDeviceRemoveGpu_v2 + #define nvmlDeviceGetGridLicensableFeatures nvmlDeviceGetGridLicensableFeatures_v4 + #define nvmlEventSetWait nvmlEventSetWait_v2 + #define nvmlDeviceGetAttributes nvmlDeviceGetAttributes_v2 + #define nvmlComputeInstanceGetInfo nvmlComputeInstanceGetInfo_v2 + #define nvmlDeviceGetComputeRunningProcesses nvmlDeviceGetComputeRunningProcesses_v3 + #define nvmlDeviceGetGraphicsRunningProcesses nvmlDeviceGetGraphicsRunningProcesses_v3 + #define nvmlDeviceGetMPSComputeRunningProcesses nvmlDeviceGetMPSComputeRunningProcesses_v3 + #define nvmlBlacklistDeviceInfo_t nvmlExcludedDeviceInfo_t + #define nvmlGetBlacklistDeviceCount nvmlGetExcludedDeviceCount + #define nvmlGetBlacklistDeviceInfoByIndex nvmlGetExcludedDeviceInfoByIndex + #define nvmlDeviceGetGpuInstancePossiblePlacements nvmlDeviceGetGpuInstancePossiblePlacements_v2 + #define nvmlVgpuInstanceGetLicenseInfo nvmlVgpuInstanceGetLicenseInfo_v2 +#endif // #ifndef NVML_NO_UNVERSIONED_FUNC_DEFS + +#define NVML_STRUCT_VERSION(data, ver) (unsigned int)(sizeof(nvml ## data ## _v ## ver ## _t) | \ + (ver << 24U)) /***************************************************************************************************/ /** @defgroup nvmlDeviceStructs Device Structs @@ -147,13 +170,30 @@ typedef struct nvmlPciInfo_st char busId[NVML_DEVICE_PCI_BUS_ID_BUFFER_SIZE]; //!< The tuple domain:bus:device.function PCI identifier (& NULL terminator) } nvmlPciInfo_t; +/** + * PCI format string for ::busIdLegacy + */ +#define NVML_DEVICE_PCI_BUS_ID_LEGACY_FMT "%04X:%02X:%02X.0" + +/** + * PCI format string for ::busId + */ +#define NVML_DEVICE_PCI_BUS_ID_FMT "%08X:%02X:%02X.0" + +/** + * Utility macro for filling the pci bus id format from a nvmlPciInfo_t + */ +#define NVML_DEVICE_PCI_BUS_ID_FMT_ARGS(pciInfo) (pciInfo)->domain, \ + (pciInfo)->bus, \ + (pciInfo)->device + /** * Detailed ECC error counts for a device. * * @deprecated Different GPU families can have different memory error counters * See \ref nvmlDeviceGetMemoryErrorCounter */ -typedef struct nvmlEccErrorCounts_st +typedef struct nvmlEccErrorCounts_st { unsigned long long l1Cache; //!< L1 cache errors unsigned long long l2Cache; //!< L2 cache errors @@ -161,26 +201,44 @@ typedef struct nvmlEccErrorCounts_st unsigned long long registerFile; //!< Register file errors } nvmlEccErrorCounts_t; -/** +/** * Utilization information for a device. * Each sample period may be between 1 second and 1/6 second, depending on the product being queried. */ -typedef struct nvmlUtilization_st +typedef struct nvmlUtilization_st { unsigned int gpu; //!< Percent of time over the past sample period during which one or more kernels was executing on the GPU unsigned int memory; //!< Percent of time over the past sample period during which global (device) memory was being read or written } nvmlUtilization_t; -/** - * Memory allocation information for a device. +/** + * Memory allocation information for a device (v1). + * The total amount is equal to the sum of the amounts of free and used memory. */ -typedef struct nvmlMemory_st +typedef struct nvmlMemory_st { - unsigned long long total; //!< Total installed FB memory (in bytes) - unsigned long long free; //!< Unallocated FB memory (in bytes) - unsigned long long used; //!< Allocated FB memory (in bytes). Note that the driver/GPU always sets aside a small amount of memory for bookkeeping + unsigned long long total; //!< Total physical device memory (in bytes) + unsigned long long free; //!< Unallocated device memory (in bytes) + unsigned long long used; //!< Sum of Reserved and Allocated device memory (in bytes). + //!< Note that the driver/GPU always sets aside a small amount of memory for bookkeeping } nvmlMemory_t; +/** + * Memory allocation information for a device (v2). + * + * Version 2 adds versioning for the struct and the amount of system-reserved memory as an output. + */ +typedef struct nvmlMemory_v2_st +{ + unsigned int version; //!< Structure format version (must be 2) + unsigned long long total; //!< Total physical device memory (in bytes) + unsigned long long reserved; //!< Device memory (in bytes) reserved for system use (driver or firmware) + unsigned long long free; //!< Unallocated device memory (in bytes) + unsigned long long used; //!< Allocated device memory (in bytes). +} nvmlMemory_v2_t; + +#define nvmlMemory_v2 NVML_STRUCT_VERSION(Memory, 2) + /** * BAR1 Memory allocation Information for a device */ @@ -191,16 +249,104 @@ typedef struct nvmlBAR1Memory_st unsigned long long bar1Used; //!< Allocated Used Memory (in bytes) }nvmlBAR1Memory_t; +/** + * Information about running compute processes on the GPU, legacy version + * for older versions of the API. + */ +typedef struct nvmlProcessInfo_v1_st +{ + unsigned int pid; //!< Process ID + unsigned long long usedGpuMemory; //!< Amount of used GPU memory in bytes. + //! Under WDDM, \ref NVML_VALUE_NOT_AVAILABLE is always reported + //! because Windows KMD manages all the memory and not the NVIDIA driver +} nvmlProcessInfo_v1_t; + /** * Information about running compute processes on the GPU */ -typedef struct nvmlProcessInfo_st +typedef struct nvmlProcessInfo_v2_st { - unsigned int pid; //!< Process ID - unsigned long long usedGpuMemory; //!< Amount of used GPU memory in bytes. - //! Under WDDM, \ref NVML_VALUE_NOT_AVAILABLE is always reported - //! because Windows KMD manages all the memory and not the NVIDIA driver -} nvmlProcessInfo_t; + unsigned int pid; //!< Process ID + unsigned long long usedGpuMemory; //!< Amount of used GPU memory in bytes. + //! Under WDDM, \ref NVML_VALUE_NOT_AVAILABLE is always reported + //! because Windows KMD manages all the memory and not the NVIDIA driver + unsigned int gpuInstanceId; //!< If MIG is enabled, stores a valid GPU instance ID. gpuInstanceId is set to + // 0xFFFFFFFF otherwise. + unsigned int computeInstanceId; //!< If MIG is enabled, stores a valid compute instance ID. computeInstanceId is set to + // 0xFFFFFFFF otherwise. +} nvmlProcessInfo_v2_t, nvmlProcessInfo_t; + +/** + * Information about running process on the GPU with protected memory + */ +typedef struct +{ + unsigned int pid; //!< Process ID + unsigned long long usedGpuMemory; //!< Amount of used GPU memory in bytes. + //! Under WDDM, \ref NVML_VALUE_NOT_AVAILABLE is always reported + //! because Windows KMD manages all the memory and not the NVIDIA driver + unsigned int gpuInstanceId; //!< If MIG is enabled, stores a valid GPU instance ID. gpuInstanceId is + // set to 0xFFFFFFFF otherwise. + unsigned int computeInstanceId; //!< If MIG is enabled, stores a valid compute instance ID. computeInstanceId + // is set to 0xFFFFFFFF otherwise. + unsigned long long usedGpuCcProtectedMemory; //!< Amount of used GPU conf compute protected memory in bytes. +} nvmlProcessDetail_v1_t; + +/** + * Information about all running processes on the GPU for the given mode + */ +typedef struct +{ + unsigned int version; //!< Struct version, MUST be nvmlProcessDetailList_v1 + unsigned int mode; //!< Process mode(Compute/Graphics/MPSCompute) + unsigned int numProcArrayEntries; //!< Number of process entries in procArray + nvmlProcessDetail_v1_t *procArray; //!< Process array +} nvmlProcessDetailList_v1_t; + +typedef nvmlProcessDetailList_v1_t nvmlProcessDetailList_t; + +/** + * nvmlProcessDetailList version + */ +#define nvmlProcessDetailList_v1 NVML_STRUCT_VERSION(ProcessDetailList, 1) + +typedef struct nvmlDeviceAttributes_st +{ + unsigned int multiprocessorCount; //!< Streaming Multiprocessor count + unsigned int sharedCopyEngineCount; //!< Shared Copy Engine count + unsigned int sharedDecoderCount; //!< Shared Decoder Engine count + unsigned int sharedEncoderCount; //!< Shared Encoder Engine count + unsigned int sharedJpegCount; //!< Shared JPEG Engine count + unsigned int sharedOfaCount; //!< Shared OFA Engine count + unsigned int gpuInstanceSliceCount; //!< GPU instance slice count + unsigned int computeInstanceSliceCount; //!< Compute instance slice count + unsigned long long memorySizeMB; //!< Device memory size (in MiB) +} nvmlDeviceAttributes_t; + +/** + * C2C Mode information for a device + */ +typedef struct +{ + unsigned int isC2cEnabled; +} nvmlC2cModeInfo_v1_t; + +#define nvmlC2cModeInfo_v1 NVML_STRUCT_VERSION(C2cModeInfo, 1) + +/** + * Possible values that classify the remap availability for each bank. The max + * field will contain the number of banks that have maximum remap availability + * (all reserved rows are available). None means that there are no reserved + * rows available. + */ +typedef struct nvmlRowRemapperHistogramValues_st +{ + unsigned int max; + unsigned int high; + unsigned int partial; + unsigned int low; + unsigned int none; +} nvmlRowRemapperHistogramValues_t; /** * Enum to represent type of bridge chip @@ -208,13 +354,13 @@ typedef struct nvmlProcessInfo_st typedef enum nvmlBridgeChipType_enum { NVML_BRIDGE_CHIP_PLX = 0, - NVML_BRIDGE_CHIP_BRO4 = 1 + NVML_BRIDGE_CHIP_BRO4 = 1 }nvmlBridgeChipType_t; /** - * Maximum number of NvLink links supported + * Maximum number of NvLink links supported */ -#define NVML_NVLINK_MAX_LINKS 6 +#define NVML_NVLINK_MAX_LINKS 18 /** * Enum to represent the NvLink utilization counter packet units @@ -224,7 +370,7 @@ typedef enum nvmlNvLinkUtilizationCountUnits_enum NVML_NVLINK_COUNTER_UNIT_CYCLES = 0, // count by cycles NVML_NVLINK_COUNTER_UNIT_PACKETS = 1, // count by packets NVML_NVLINK_COUNTER_UNIT_BYTES = 2, // count by bytes - + NVML_NVLINK_COUNTER_UNIT_RESERVED = 3, // count reserved for internal use // this must be last NVML_NVLINK_COUNTER_UNIT_COUNT } nvmlNvLinkUtilizationCountUnits_t; @@ -234,7 +380,7 @@ typedef enum nvmlNvLinkUtilizationCountUnits_enum * ** this is ONLY applicable with the units as packets or bytes * ** as specified in \a nvmlNvLinkUtilizationCountUnits_t * ** all packet filter descriptions are target GPU centric - * ** these can be "OR'd" together + * ** these can be "OR'd" together */ typedef enum nvmlNvLinkUtilizationCountPktTypes_enum { @@ -249,7 +395,7 @@ typedef enum nvmlNvLinkUtilizationCountPktTypes_enum NVML_NVLINK_COUNTER_PKTFILTER_ALL = 0xFF // all packets } nvmlNvLinkUtilizationCountPktTypes_t; -/** +/** * Struct to define the NVLINK counter controls */ typedef struct nvmlNvLinkUtilizationControl_st @@ -282,11 +428,23 @@ typedef enum nvmlNvLinkErrorCounter_enum NVML_NVLINK_ERROR_DL_RECOVERY = 1, // Data link transmit recovery error counter NVML_NVLINK_ERROR_DL_CRC_FLIT = 2, // Data link receive flow control digit CRC error counter NVML_NVLINK_ERROR_DL_CRC_DATA = 3, // Data link receive data CRC error counter + NVML_NVLINK_ERROR_DL_ECC_DATA = 4, // Data link receive data ECC error counter // this must be last NVML_NVLINK_ERROR_COUNT } nvmlNvLinkErrorCounter_t; +/** + * Enum to represent NvLink's remote device type + */ +typedef enum nvmlIntNvLinkDeviceType_enum +{ + NVML_NVLINK_DEVICE_TYPE_GPU = 0x00, + NVML_NVLINK_DEVICE_TYPE_IBMNPU = 0x01, + NVML_NVLINK_DEVICE_TYPE_SWITCH = 0x02, + NVML_NVLINK_DEVICE_TYPE_UNKNOWN = 0xFF +} nvmlIntNvLinkDeviceType_t; + /** * Represents level relationships within a system between two GPUs * The enums are spaced to allow for future relationships @@ -298,7 +456,7 @@ typedef enum nvmlGpuLevel_enum NVML_TOPOLOGY_MULTIPLE = 20, // all devices that need not traverse a host bridge NVML_TOPOLOGY_HOSTBRIDGE = 30, // all devices that are connected to the same host bridge NVML_TOPOLOGY_NODE = 40, // all devices that are connected to the same NUMA node but possibly multiple host bridges - NVML_TOPOLOGY_SYSTEM = 50, // all devices in the system + NVML_TOPOLOGY_SYSTEM = 50 // all devices in the system // there is purposefully no COUNT here because of the need for spacing above } nvmlGpuTopologyLevel_t; @@ -311,6 +469,7 @@ typedef enum nvmlGpuP2PStatus_enum { NVML_P2P_STATUS_OK = 0, NVML_P2P_STATUS_CHIPSET_NOT_SUPPORED, + NVML_P2P_STATUS_CHIPSET_NOT_SUPPORTED = NVML_P2P_STATUS_CHIPSET_NOT_SUPPORED, NVML_P2P_STATUS_GPU_NOT_SUPPORTED, NVML_P2P_STATUS_IOH_TOPOLOGY_NOT_SUPPORTED, NVML_P2P_STATUS_DISABLED_BY_REGKEY, @@ -340,12 +499,12 @@ typedef enum nvmlGpuP2PCapsIndex_enum */ typedef struct nvmlBridgeChipInfo_st { - nvmlBridgeChipType_t type; //!< Type of Bridge Chip + nvmlBridgeChipType_t type; //!< Type of Bridge Chip unsigned int fwVersion; //!< Firmware Version. 0=Version is unavailable }nvmlBridgeChipInfo_t; /** - * This structure stores the complete Hierarchy of the Bridge Chip within the board. The immediate + * This structure stores the complete Hierarchy of the Bridge Chip within the board. The immediate * bridge is stored at index 0 of bridgeInfoList, parent to immediate bridge is at index 1 and so forth. */ typedef struct nvmlBridgeChipHierarchy_st @@ -363,12 +522,13 @@ typedef enum nvmlSamplingType_enum NVML_GPU_UTILIZATION_SAMPLES = 1, //!< To represent percent of time during which one or more kernels was executing on the GPU NVML_MEMORY_UTILIZATION_SAMPLES = 2, //!< To represent percent of time during which global (device) memory was being read or written NVML_ENC_UTILIZATION_SAMPLES = 3, //!< To represent percent of time during which NVENC remains busy - NVML_DEC_UTILIZATION_SAMPLES = 4, //!< To represent percent of time during which NVDEC remains busy + NVML_DEC_UTILIZATION_SAMPLES = 4, //!< To represent percent of time during which NVDEC remains busy NVML_PROCESSOR_CLK_SAMPLES = 5, //!< To represent processor clock samples NVML_MEMORY_CLK_SAMPLES = 6, //!< To represent memory clock samples - + NVML_MODULE_POWER_SAMPLES = 7, //!< To represent module power samples for total module starting Grace Hopper + // Keep this last - NVML_SAMPLINGTYPE_COUNT + NVML_SAMPLINGTYPE_COUNT }nvmlSamplingType_t; /** @@ -378,7 +538,7 @@ typedef enum nvmlPcieUtilCounter_enum { NVML_PCIE_UTIL_TX_BYTES = 0, // 1KB granularity NVML_PCIE_UTIL_RX_BYTES = 1, // 1KB granularity - + // Keep this last NVML_PCIE_UTIL_COUNT } nvmlPcieUtilCounter_t; @@ -386,13 +546,14 @@ typedef enum nvmlPcieUtilCounter_enum /** * Represents the type for sample value returned */ -typedef enum nvmlValueType_enum +typedef enum nvmlValueType_enum { NVML_VALUE_TYPE_DOUBLE = 0, NVML_VALUE_TYPE_UNSIGNED_INT = 1, NVML_VALUE_TYPE_UNSIGNED_LONG = 2, NVML_VALUE_TYPE_UNSIGNED_LONG_LONG = 3, NVML_VALUE_TYPE_SIGNED_LONG_LONG = 4, + NVML_VALUE_TYPE_SIGNED_INT = 5, // Keep this last NVML_VALUE_TYPE_COUNT @@ -405,6 +566,7 @@ typedef enum nvmlValueType_enum typedef union nvmlValue_st { double dVal; //!< If the value is double + int siVal; //!< If the value is signed int unsigned int uiVal; //!< If the value is unsigned int unsigned long ulVal; //!< If the value is unsigned long unsigned long long ullVal; //!< If the value is unsigned long long @@ -414,14 +576,14 @@ typedef union nvmlValue_st /** * Information for Sample */ -typedef struct nvmlSample_st +typedef struct nvmlSample_st { unsigned long long timeStamp; //!< CPU Timestamp in microseconds - nvmlValue_t sampleValue; //!< Sample Value + nvmlValue_t sampleValue; //!< Sample Value }nvmlSample_t; /** - * Represents type of perf policy for which violation times can be queried + * Represents type of perf policy for which violation times can be queried */ typedef enum nvmlPerfPolicyType_enum { @@ -448,6 +610,60 @@ typedef struct nvmlViolationTime_st unsigned long long violationTime; //!< violationTime in Nanoseconds }nvmlViolationTime_t; +#define NVML_MAX_THERMAL_SENSORS_PER_GPU 3 + +typedef enum +{ + NVML_THERMAL_TARGET_NONE = 0, + NVML_THERMAL_TARGET_GPU = 1, //!< GPU core temperature requires NvPhysicalGpuHandle + NVML_THERMAL_TARGET_MEMORY = 2, //!< GPU memory temperature requires NvPhysicalGpuHandle + NVML_THERMAL_TARGET_POWER_SUPPLY = 4, //!< GPU power supply temperature requires NvPhysicalGpuHandle + NVML_THERMAL_TARGET_BOARD = 8, //!< GPU board ambient temperature requires NvPhysicalGpuHandle + NVML_THERMAL_TARGET_VCD_BOARD = 9, //!< Visual Computing Device Board temperature requires NvVisualComputingDeviceHandle + NVML_THERMAL_TARGET_VCD_INLET = 10, //!< Visual Computing Device Inlet temperature requires NvVisualComputingDeviceHandle + NVML_THERMAL_TARGET_VCD_OUTLET = 11, //!< Visual Computing Device Outlet temperature requires NvVisualComputingDeviceHandle + + NVML_THERMAL_TARGET_ALL = 15, + NVML_THERMAL_TARGET_UNKNOWN = -1, +} nvmlThermalTarget_t; + +typedef enum +{ + NVML_THERMAL_CONTROLLER_NONE = 0, + NVML_THERMAL_CONTROLLER_GPU_INTERNAL, + NVML_THERMAL_CONTROLLER_ADM1032, + NVML_THERMAL_CONTROLLER_ADT7461, + NVML_THERMAL_CONTROLLER_MAX6649, + NVML_THERMAL_CONTROLLER_MAX1617, + NVML_THERMAL_CONTROLLER_LM99, + NVML_THERMAL_CONTROLLER_LM89, + NVML_THERMAL_CONTROLLER_LM64, + NVML_THERMAL_CONTROLLER_G781, + NVML_THERMAL_CONTROLLER_ADT7473, + NVML_THERMAL_CONTROLLER_SBMAX6649, + NVML_THERMAL_CONTROLLER_VBIOSEVT, + NVML_THERMAL_CONTROLLER_OS, + NVML_THERMAL_CONTROLLER_NVSYSCON_CANOAS, + NVML_THERMAL_CONTROLLER_NVSYSCON_E551, + NVML_THERMAL_CONTROLLER_MAX6649R, + NVML_THERMAL_CONTROLLER_ADT7473S, + NVML_THERMAL_CONTROLLER_UNKNOWN = -1, +} nvmlThermalController_t; + +typedef struct +{ + unsigned int count; + struct + { + nvmlThermalController_t controller; + int defaultMinTemp; + int defaultMaxTemp; + int currentTemp; + nvmlThermalTarget_t target; + } sensor[NVML_MAX_THERMAL_SENSORS_PER_GPU]; + +} nvmlGpuThermalSettings_t; + /** @} */ /***************************************************************************************************/ @@ -456,31 +672,43 @@ typedef struct nvmlViolationTime_st */ /***************************************************************************************************/ -/** - * Generic enable/disable enum. +/** + * Generic enable/disable enum. */ -typedef enum nvmlEnableState_enum +typedef enum nvmlEnableState_enum { - NVML_FEATURE_DISABLED = 0, //!< Feature disabled + NVML_FEATURE_DISABLED = 0, //!< Feature disabled NVML_FEATURE_ENABLED = 1 //!< Feature enabled } nvmlEnableState_t; //! Generic flag used to specify the default behavior of some functions. See description of particular functions for details. -#define nvmlFlagDefault 0x00 +#define nvmlFlagDefault 0x00 //! Generic flag used to force some behavior. See description of particular functions for details. -#define nvmlFlagForce 0x01 +#define nvmlFlagForce 0x01 /** * * The Brand of the GPU * */ typedef enum nvmlBrandType_enum { - NVML_BRAND_UNKNOWN = 0, - NVML_BRAND_QUADRO = 1, - NVML_BRAND_TESLA = 2, - NVML_BRAND_NVS = 3, - NVML_BRAND_GRID = 4, - NVML_BRAND_GEFORCE = 5, + NVML_BRAND_UNKNOWN = 0, + NVML_BRAND_QUADRO = 1, + NVML_BRAND_TESLA = 2, + NVML_BRAND_NVS = 3, + NVML_BRAND_GRID = 4, // Deprecated from API reporting. Keeping definition for backward compatibility. + NVML_BRAND_GEFORCE = 5, + NVML_BRAND_TITAN = 6, + NVML_BRAND_NVIDIA_VAPPS = 7, // NVIDIA Virtual Applications + NVML_BRAND_NVIDIA_VPC = 8, // NVIDIA Virtual PC + NVML_BRAND_NVIDIA_VCS = 9, // NVIDIA Virtual Compute Server + NVML_BRAND_NVIDIA_VWS = 10, // NVIDIA RTX Virtual Workstation + NVML_BRAND_NVIDIA_CLOUD_GAMING = 11, // NVIDIA Cloud Gaming + NVML_BRAND_NVIDIA_VGAMING = NVML_BRAND_NVIDIA_CLOUD_GAMING, // Deprecated from API reporting. Keeping definition for backward compatibility. + NVML_BRAND_QUADRO_RTX = 12, + NVML_BRAND_NVIDIA_RTX = 13, + NVML_BRAND_NVIDIA = 14, + NVML_BRAND_GEFORCE_RTX = 15, // Unused + NVML_BRAND_TITAN_RTX = 16, // Unused // Keep this last NVML_BRAND_COUNT @@ -491,45 +719,94 @@ typedef enum nvmlBrandType_enum */ typedef enum nvmlTemperatureThresholds_enum { - NVML_TEMPERATURE_THRESHOLD_SHUTDOWN = 0, // Temperature at which the GPU will shut down - // for HW protection - NVML_TEMPERATURE_THRESHOLD_SLOWDOWN = 1, // Temperature at which the GPU will begin HW slowdown - NVML_TEMPERATURE_THRESHOLD_MEM_MAX = 2, // Memory Temperature at which the GPU will begin SW slowdown - NVML_TEMPERATURE_THRESHOLD_GPU_MAX = 3, // GPU Temperature at which the GPU can be throttled below base clock + NVML_TEMPERATURE_THRESHOLD_SHUTDOWN = 0, // Temperature at which the GPU will + // shut down for HW protection + NVML_TEMPERATURE_THRESHOLD_SLOWDOWN = 1, // Temperature at which the GPU will + // begin HW slowdown + NVML_TEMPERATURE_THRESHOLD_MEM_MAX = 2, // Memory Temperature at which the GPU will + // begin SW slowdown + NVML_TEMPERATURE_THRESHOLD_GPU_MAX = 3, // GPU Temperature at which the GPU + // can be throttled below base clock + NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_MIN = 4, // Minimum GPU Temperature that can be + // set as acoustic threshold + NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_CURR = 5, // Current temperature that is set as + // acoustic threshold. + NVML_TEMPERATURE_THRESHOLD_ACOUSTIC_MAX = 6, // Maximum GPU temperature that can be + // set as acoustic threshold. // Keep this last NVML_TEMPERATURE_THRESHOLD_COUNT } nvmlTemperatureThresholds_t; -/** - * Temperature sensors. +/** + * Temperature sensors. */ -typedef enum nvmlTemperatureSensors_enum +typedef enum nvmlTemperatureSensors_enum { NVML_TEMPERATURE_GPU = 0, //!< Temperature sensor for the GPU die - + // Keep this last NVML_TEMPERATURE_COUNT } nvmlTemperatureSensors_t; -/** - * Compute mode. +/** + * Compute mode. * * NVML_COMPUTEMODE_EXCLUSIVE_PROCESS was added in CUDA 4.0. - * Earlier CUDA versions supported a single exclusive mode, + * Earlier CUDA versions supported a single exclusive mode, * which is equivalent to NVML_COMPUTEMODE_EXCLUSIVE_THREAD in CUDA 4.0 and beyond. */ -typedef enum nvmlComputeMode_enum +typedef enum nvmlComputeMode_enum { NVML_COMPUTEMODE_DEFAULT = 0, //!< Default compute mode -- multiple contexts per device NVML_COMPUTEMODE_EXCLUSIVE_THREAD = 1, //!< Support Removed NVML_COMPUTEMODE_PROHIBITED = 2, //!< Compute-prohibited mode -- no contexts per device NVML_COMPUTEMODE_EXCLUSIVE_PROCESS = 3, //!< Compute-exclusive-process mode -- only one context per device, usable from multiple threads at a time - + // Keep this last NVML_COMPUTEMODE_COUNT } nvmlComputeMode_t; -/** +/** + * Max Clock Monitors available + */ +#define MAX_CLK_DOMAINS 32 + +/** + * Clock Monitor error types + */ +typedef struct nvmlClkMonFaultInfo_struct { + /** + * The Domain which faulted + */ + unsigned int clkApiDomain; + + /** + * Faults Information + */ + unsigned int clkDomainFaultMask; +} nvmlClkMonFaultInfo_t; + +/** + * Clock Monitor Status + */ +typedef struct nvmlClkMonStatus_status { + /** + * Fault status Indicator + */ + unsigned int bGlobalStatus; + + /** + * Total faulted domain numbers + */ + unsigned int clkMonListSize; + + /** + * The fault Information structure + */ + nvmlClkMonFaultInfo_t clkMonList[MAX_CLK_DOMAINS]; +} nvmlClkMonStatus_t; + +/** * ECC bit types. * * @deprecated See \ref nvmlMemoryErrorType_t for a more flexible type @@ -557,56 +834,56 @@ typedef enum nvmlMemoryErrorType_enum { /** * A memory error that was corrected - * + * * For ECC errors, these are single bit errors * For Texture memory, these are errors fixed by resend */ NVML_MEMORY_ERROR_TYPE_CORRECTED = 0, /** * A memory error that was not corrected - * + * * For ECC errors, these are double bit errors * For Texture memory, these are errors where the resend fails */ NVML_MEMORY_ERROR_TYPE_UNCORRECTED = 1, - - + + // Keep this last NVML_MEMORY_ERROR_TYPE_COUNT //!< Count of memory error types } nvmlMemoryErrorType_t; -/** - * ECC counter types. +/** + * ECC counter types. * * Note: Volatile counts are reset each time the driver loads. On Windows this is once per boot. On Linux this can be more frequent. - * On Linux the driver unloads when no active clients exist. If persistence mode is enabled or there is always a driver + * On Linux the driver unloads when no active clients exist. If persistence mode is enabled or there is always a driver * client active (e.g. X11), then Linux also sees per-boot behavior. If not, volatile counts are reset each time a compute app * is run. */ -typedef enum nvmlEccCounterType_enum +typedef enum nvmlEccCounterType_enum { NVML_VOLATILE_ECC = 0, //!< Volatile counts are reset each time the driver loads. NVML_AGGREGATE_ECC = 1, //!< Aggregate counts persist across reboots (i.e. for the lifetime of the device) - + // Keep this last NVML_ECC_COUNTER_TYPE_COUNT //!< Count of memory counter types } nvmlEccCounterType_t; -/** - * Clock types. - * +/** + * Clock types. + * * All speeds are in Mhz. */ -typedef enum nvmlClockType_enum +typedef enum nvmlClockType_enum { NVML_CLOCK_GRAPHICS = 0, //!< Graphics clock domain NVML_CLOCK_SM = 1, //!< SM clock domain NVML_CLOCK_MEM = 2, //!< Memory clock domain NVML_CLOCK_VIDEO = 3, //!< Video encoder/decoder clock domain - + // Keep this last - NVML_CLOCK_COUNT //usedGpuMemory is not supported - - unsigned long long time; //!< Amount of time in ms during which the compute context was active. The time is reported as 0 if + + unsigned long long time; //!< Amount of time in ms during which the compute context was active. The time is reported as 0 if //!< the process is not terminated - + unsigned long long startTime; //!< CPU Timestamp in usec representing start time for the process - + unsigned int isRunning; //!< Flag to represent if the process is running (1 for running, 0 for terminated) unsigned int reserved[5]; //!< Reserved for future use @@ -1259,145 +2237,24 @@ typedef struct nvmlAccountingStats_st { /** @} */ -/***************************************************************************************************/ -/** @defgroup nvmlVgpuConstants Vgpu Constants - * @{ - */ -/***************************************************************************************************/ - -/** - * Buffer size guaranteed to be large enough for \ref nvmlVgpuTypeGetLicense - */ -#define NVML_GRID_LICENSE_BUFFER_SIZE 128 - -#define NVML_VGPU_NAME_BUFFER_SIZE 64 - -#define NVML_MAX_VGPU_TYPES_PER_PGPU 17 - -#define NVML_MAX_VGPU_INSTANCES_PER_PGPU 24 - -#define NVML_GRID_LICENSE_FEATURE_MAX_COUNT 3 - -#define NVML_GRID_LICENSE_INFO_MAX_LENGTH 128 - -/** @} */ - -/***************************************************************************************************/ -/** @defgroup nvmlVgpuEnum Vgpu Enum - * @{ - */ -/***************************************************************************************************/ - -/*! - * Types of VM identifiers - */ -typedef enum nvmlVgpuVmIdType { - NVML_VGPU_VM_ID_DOMAIN_ID = 0, //!< VM ID represents DOMAIN ID - NVML_VGPU_VM_ID_UUID = 1, //!< VM ID represents UUID -} nvmlVgpuVmIdType_t; - -// vGPU GUEST info state. -typedef enum nvmlVgpuGuestInfoState_enum -{ - NVML_VGPU_INSTANCE_GUEST_INFO_STATE_UNINITIALIZED = 0, //= 0 and < \a unitCount * @param unit Reference in which to return the unit handle - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a unit has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a index is invalid or \a unit is NULL @@ -1699,8 +2841,8 @@ nvmlReturn_t DECLDIR nvmlUnitGetHandleByIndex(unsigned int index, nvmlUnit_t *un * * @param unit The identifier of the target unit * @param info Reference in which to return the unit information - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a info has been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit is invalid or \a info is NULL @@ -1716,14 +2858,14 @@ nvmlReturn_t DECLDIR nvmlUnitGetUnitInfo(nvmlUnit_t unit, nvmlUnitInfo_t *info); * * @param unit The identifier of the target unit * @param state Reference in which to return the current LED state - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a state has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit is invalid or \a state is NULL * - \ref NVML_ERROR_NOT_SUPPORTED if this is not an S-class product * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * + * * @see nvmlUnitSetLedState() */ nvmlReturn_t DECLDIR nvmlUnitGetLedState(nvmlUnit_t unit, nvmlLedState_t *state); @@ -1737,8 +2879,8 @@ nvmlReturn_t DECLDIR nvmlUnitGetLedState(nvmlUnit_t unit, nvmlLedState_t *state) * * @param unit The identifier of the target unit * @param psu Reference in which to return the PSU information - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a psu has been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit is invalid or \a psu is NULL @@ -1752,14 +2894,14 @@ nvmlReturn_t DECLDIR nvmlUnitGetPsuInfo(nvmlUnit_t unit, nvmlPSUInfo_t *psu); * * For S-class products. * - * Depending on the product, readings may be available for intake (type=0), + * Depending on the product, readings may be available for intake (type=0), * exhaust (type=1) and board (type=2). * * @param unit The identifier of the target unit * @param type The type of reading to take * @param temp Reference in which to return the intake temperature - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a temp has been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit or \a type is invalid or \a temp is NULL @@ -1777,8 +2919,8 @@ nvmlReturn_t DECLDIR nvmlUnitGetTemperature(nvmlUnit_t unit, unsigned int type, * * @param unit The identifier of the target unit * @param fanSpeeds Reference in which to return the fan speed information - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a fanSpeeds has been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit is invalid or \a fanSpeeds is NULL @@ -1798,8 +2940,8 @@ nvmlReturn_t DECLDIR nvmlUnitGetFanSpeedInfo(nvmlUnit_t unit, nvmlUnitFanSpeeds_ * @param deviceCount Reference in which to provide the \a devices array size, and * to return the number of attached GPU devices * @param devices Reference in which to return the references to the attached GPU devices - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a deviceCount and \a devices have been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a deviceCount indicates that the \a devices array is too small @@ -1808,39 +2950,21 @@ nvmlReturn_t DECLDIR nvmlUnitGetFanSpeedInfo(nvmlUnit_t unit, nvmlUnitFanSpeeds_ */ nvmlReturn_t DECLDIR nvmlUnitGetDevices(nvmlUnit_t unit, unsigned int *deviceCount, nvmlDevice_t *devices); -/** - * Retrieves the IDs and firmware versions for any Host Interface Cards (HICs) in the system. - * - * For S-class products. - * - * The \a hwbcCount argument is expected to be set to the size of the input \a hwbcEntries array. - * The HIC must be connected to an S-class system for it to be reported by this function. - * - * @param hwbcCount Size of hwbcEntries array - * @param hwbcEntries Array holding information about hwbc - * - * @return - * - \ref NVML_SUCCESS if \a hwbcCount and \a hwbcEntries have been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if either \a hwbcCount or \a hwbcEntries is NULL - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a hwbcCount indicates that the \a hwbcEntries array is too small - */ -nvmlReturn_t DECLDIR nvmlSystemGetHicVersion(unsigned int *hwbcCount, nvmlHwbcEntry_t *hwbcEntries); /** @} */ /***************************************************************************************************/ /** @defgroup nvmlDeviceQueries Device Queries * This chapter describes that queries that NVML can perform against each device. - * In each case the device is identified with an nvmlDevice_t handle. This handle is obtained by - * calling one of \ref nvmlDeviceGetHandleByIndex(), \ref nvmlDeviceGetHandleBySerial(), - * \ref nvmlDeviceGetHandleByPciBusId(). or \ref nvmlDeviceGetHandleByUUID(). + * In each case the device is identified with an nvmlDevice_t handle. This handle is obtained by + * calling one of \ref nvmlDeviceGetHandleByIndex_v2(), \ref nvmlDeviceGetHandleBySerial(), + * \ref nvmlDeviceGetHandleByPciBusId_v2(). or \ref nvmlDeviceGetHandleByUUID(). * @{ */ /***************************************************************************************************/ /** * Retrieves the number of compute devices in the system. A compute device is a single GPU. - * + * * For all products. * * Note: New nvmlDeviceGetCount_v2 (default in NVML 5.319) returns count of all devices in the system @@ -1851,34 +2975,54 @@ nvmlReturn_t DECLDIR nvmlSystemGetHicVersion(unsigned int *hwbcCount, nvmlHwbcEn * Old _v1 version of nvmlDeviceGetCount doesn't count devices that NVML has no permission to talk to. * * @param deviceCount Reference in which to return the number of accessible devices - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a deviceCount has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a deviceCount is NULL * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceGetCount(unsigned int *deviceCount); +nvmlReturn_t DECLDIR nvmlDeviceGetCount_v2(unsigned int *deviceCount); + +/** + * Get attributes (engine counts etc.) for the given NVML device handle. + * + * @note This API currently only supports MIG device handles. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device NVML device handle + * @param attributes Device attributes + * + * @return + * - \ref NVML_SUCCESS if \a device attributes were successfully retrieved + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device handle is invalid + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAttributes_v2(nvmlDevice_t device, nvmlDeviceAttributes_t *attributes); /** * Acquire the handle for a particular device, based on its index. - * + * * For all products. * - * Valid indices are derived from the \a accessibleDevices count returned by - * \ref nvmlDeviceGetCount(). For example, if \a accessibleDevices is 2 the valid indices + * Valid indices are derived from the \a accessibleDevices count returned by + * \ref nvmlDeviceGetCount_v2(). For example, if \a accessibleDevices is 2 the valid indices * are 0 and 1, corresponding to GPU 0 and GPU 1. * * The order in which NVML enumerates devices has no guarantees of consistency between reboots. For that reason it - * is recommended that devices be looked up by their PCI ids or UUID. See - * \ref nvmlDeviceGetHandleByUUID() and \ref nvmlDeviceGetHandleByPciBusId(). + * is recommended that devices be looked up by their PCI ids or UUID. See + * \ref nvmlDeviceGetHandleByUUID() and \ref nvmlDeviceGetHandleByPciBusId_v2(). * * Note: The NVML index may not correlate with other APIs, such as the CUDA device index. * * Starting from NVML 5, this API causes NVML to initialize the target GPU * NVML may initialize additional GPUs if: * - The target GPU is an SLI slave - * + * * Note: New nvmlDeviceGetCount_v2 (default in NVML 5.319) returns count of all devices in the system * even if nvmlDeviceGetHandleByIndex_v2 returns NVML_ERROR_NO_PERMISSION for such device. * Update your code to handle this error, or use NVML 4.304 or older nvml header file. @@ -1892,8 +3036,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetCount(unsigned int *deviceCount); * * @param index The index of the target GPU, >= 0 and < \a accessibleDevices * @param device Reference in which to return the device handle - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a device has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a index is invalid or \a device is NULL @@ -1906,7 +3050,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetCount(unsigned int *deviceCount); * @see nvmlDeviceGetIndex * @see nvmlDeviceGetCount */ -nvmlReturn_t DECLDIR nvmlDeviceGetHandleByIndex(unsigned int index, nvmlDevice_t *device); +nvmlReturn_t DECLDIR nvmlDeviceGetHandleByIndex_v2(unsigned int index, nvmlDevice_t *device); /** * Acquire the handle for a particular device, based on its board serial number. @@ -1916,7 +3060,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetHandleByIndex(unsigned int index, nvmlDevice_t * This number corresponds to the value printed directly on the board, and to the value returned by * \ref nvmlDeviceGetSerial(). * - * @deprecated Since more than one GPU can exist on a single board this function is deprecated in favor + * @deprecated Since more than one GPU can exist on a single board this function is deprecated in favor * of \ref nvmlDeviceGetHandleByUUID. * For dual GPU boards this function will return NVML_ERROR_INVALID_ARGUMENT. * @@ -1925,8 +3069,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetHandleByIndex(unsigned int index, nvmlDevice_t * * @param serial The board serial number of the target GPU * @param device Reference in which to return the device handle - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a device has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a serial is invalid, \a device is NULL or more than one @@ -1947,13 +3091,13 @@ nvmlReturn_t DECLDIR nvmlDeviceGetHandleBySerial(const char *serial, nvmlDevice_ * * For all products. * - * @param uuid The UUID of the target GPU - * @param device Reference in which to return the device handle - * + * @param uuid The UUID of the target GPU or MIG instance + * @param device Reference in which to return the device handle or MIG device handle + * * Starting from NVML 5, this API causes NVML to initialize the target GPU * NVML may initialize additional GPUs as it searches for the target GPU * - * @return + * @return * - \ref NVML_SUCCESS if \a device has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a uuid is invalid or \a device is null @@ -1969,22 +3113,22 @@ nvmlReturn_t DECLDIR nvmlDeviceGetHandleByUUID(const char *uuid, nvmlDevice_t *d /** * Acquire the handle for a particular device, based on its PCI bus id. - * + * * For all products. * - * This value corresponds to the nvmlPciInfo_t::busId returned by \ref nvmlDeviceGetPciInfo(). + * This value corresponds to the nvmlPciInfo_t::busId returned by \ref nvmlDeviceGetPciInfo_v3(). * * Starting from NVML 5, this API causes NVML to initialize the target GPU * NVML may initialize additional GPUs if: * - The target GPU is an SLI slave * - * \note NVML 4.304 and older version of nvmlDeviceGetHandleByPciBusId"_v1" returns NVML_ERROR_NOT_FOUND + * \note NVML 4.304 and older version of nvmlDeviceGetHandleByPciBusId"_v1" returns NVML_ERROR_NOT_FOUND * instead of NVML_ERROR_NO_PERMISSION. * * @param pciBusId The PCI bus id of the target GPU * @param device Reference in which to return the device handle - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a device has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pciBusId is invalid or \a device is NULL @@ -1995,22 +3139,25 @@ nvmlReturn_t DECLDIR nvmlDeviceGetHandleByUUID(const char *uuid, nvmlDevice_t *d * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceGetHandleByPciBusId(const char *pciBusId, nvmlDevice_t *device); +nvmlReturn_t DECLDIR nvmlDeviceGetHandleByPciBusId_v2(const char *pciBusId, nvmlDevice_t *device); /** - * Retrieves the name of this device. - * + * Retrieves the name of this device. + * * For all products. * * The name is an alphanumeric string that denotes a particular product, e.g. Tesla &tm; C2070. It will not - * exceed 64 characters in length (including the NULL terminator). See \ref - * nvmlConstants::NVML_DEVICE_NAME_BUFFER_SIZE. + * exceed 96 characters in length (including the NULL terminator). See \ref + * nvmlConstants::NVML_DEVICE_NAME_V2_BUFFER_SIZE. + * + * When used with MIG device handles the API returns MIG device names which can be used to identify devices + * based on their attributes. * * @param device The identifier of the target device * @param name Reference in which to return the product name * @param length The maximum allowed length of the string returned in \a name - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a name has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a name is NULL @@ -2043,21 +3190,25 @@ nvmlReturn_t DECLDIR nvmlDeviceGetBrand(nvmlDevice_t device, nvmlBrandType_t *ty * Retrieves the NVML index of this device. * * For all products. - * - * Valid indices are derived from the \a accessibleDevices count returned by - * \ref nvmlDeviceGetCount(). For example, if \a accessibleDevices is 2 the valid indices + * + * Valid indices are derived from the \a accessibleDevices count returned by + * \ref nvmlDeviceGetCount_v2(). For example, if \a accessibleDevices is 2 the valid indices * are 0 and 1, corresponding to GPU 0 and GPU 1. * * The order in which NVML enumerates devices has no guarantees of consistency between reboots. For that reason it - * is recommended that devices be looked up by their PCI ids or GPU UUID. See - * \ref nvmlDeviceGetHandleByPciBusId() and \ref nvmlDeviceGetHandleByUUID(). + * is recommended that devices be looked up by their PCI ids or GPU UUID. See + * \ref nvmlDeviceGetHandleByPciBusId_v2() and \ref nvmlDeviceGetHandleByUUID(). + * + * When used with MIG device handles this API returns indices that can be + * passed to \ref nvmlDeviceGetMigDeviceHandleByIndex to retrieve an identical handle. + * MIG device indices are unique within a device. * * Note: The NVML index may not correlate with other APIs, such as the CUDA device index. * * @param device The identifier of the target device * @param index Reference in which to return the NVML index of the device * - * @return + * @return * - \ref NVML_SUCCESS if \a index has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a index is NULL @@ -2081,8 +3232,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetIndex(nvmlDevice_t device, unsigned int *index * @param device The identifier of the target device * @param serial Reference in which to return the board/module serial number * @param length The maximum allowed length of the string returned in \a serial - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a serial has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a serial is NULL @@ -2093,20 +3244,129 @@ nvmlReturn_t DECLDIR nvmlDeviceGetIndex(nvmlDevice_t device, unsigned int *index */ nvmlReturn_t DECLDIR nvmlDeviceGetSerial(nvmlDevice_t device, char *serial, unsigned int length); +/* +* Get a unique identifier for the device module on the baseboard +* +* This API retrieves a unique identifier for each GPU module that exists on a given baseboard. +* For non-baseboard products, this ID would always be 0. +* +* @param device The identifier of the target device +* @param moduleId Unique identifier for the GPU module +* +* @return +* - \ref NVML_SUCCESS if \a moduleId has been successfully retrieved +* - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized +* - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a moduleId is invalid +* - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlDeviceGetModuleId(nvmlDevice_t device, unsigned int *moduleId); + /** - * Retrieves an array of unsigned ints (sized to cpuSetSize) of bitmasks with the ideal CPU affinity for the device + * Retrieves the Device's C2C Mode information + * + * @param device The identifier of the target device + * @param c2cModeInfo Output struct containing the device's C2C Mode info + * + * @return + * - \ref NVML_SUCCESS if \a C2C Mode Infor query is successful + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a serial is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetC2cModeInfoV(nvmlDevice_t device, nvmlC2cModeInfo_v1_t *c2cModeInfo); + +/***************************************************************************************************/ + +/** @defgroup nvmlAffinity CPU and Memory Affinity + * This chapter describes NVML operations that are associated with CPU and memory + * affinity. + * @{ + */ +/***************************************************************************************************/ + +//! Scope of NUMA node for affinity queries +#define NVML_AFFINITY_SCOPE_NODE 0 +//! Scope of processor socket for affinity queries +#define NVML_AFFINITY_SCOPE_SOCKET 1 + +typedef unsigned int nvmlAffinityScope_t; + +/** + * Retrieves an array of unsigned ints (sized to nodeSetSize) of bitmasks with + * the ideal memory affinity within node or socket for the device. + * For example, if NUMA node 0, 1 are ideal within the socket for the device and nodeSetSize == 1, + * result[0] = 0x3 + * + * \note If requested scope is not applicable to the target topology, the API + * will fall back to reporting the memory affinity for the immediate non-I/O + * ancestor of the device. + * + * For Kepler &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device The identifier of the target device + * @param nodeSetSize The size of the nodeSet array that is safe to access + * @param nodeSet Array reference in which to return a bitmask of NODEs, 64 NODEs per + * unsigned long on 64-bit machines, 32 on 32-bit machines + * @param scope Scope that change the default behavior + * + * @return + * - \ref NVML_SUCCESS if \a NUMA node Affinity has been filled + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, nodeSetSize == 0, nodeSet is NULL or scope is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ + +nvmlReturn_t DECLDIR nvmlDeviceGetMemoryAffinity(nvmlDevice_t device, unsigned int nodeSetSize, unsigned long *nodeSet, nvmlAffinityScope_t scope); + +/** + * Retrieves an array of unsigned ints (sized to cpuSetSize) of bitmasks with the + * ideal CPU affinity within node or socket for the device. * For example, if processors 0, 1, 32, and 33 are ideal for the device and cpuSetSize == 2, * result[0] = 0x3, result[1] = 0x3 * + * \note If requested scope is not applicable to the target topology, the API + * will fall back to reporting the CPU affinity for the immediate non-I/O + * ancestor of the device. + * * For Kepler &tm; or newer fully supported devices. * Supported on Linux only. * * @param device The identifier of the target device * @param cpuSetSize The size of the cpuSet array that is safe to access - * @param cpuSet Array reference in which to return a bitmask of CPUs, 64 CPUs per + * @param cpuSet Array reference in which to return a bitmask of CPUs, 64 CPUs per + * unsigned long on 64-bit machines, 32 on 32-bit machines + * @param scope Scope that change the default behavior + * + * @return + * - \ref NVML_SUCCESS if \a cpuAffinity has been filled + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, cpuSetSize == 0, cpuSet is NULL or sope is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ + +nvmlReturn_t DECLDIR nvmlDeviceGetCpuAffinityWithinScope(nvmlDevice_t device, unsigned int cpuSetSize, unsigned long *cpuSet, nvmlAffinityScope_t scope); + +/** + * Retrieves an array of unsigned ints (sized to cpuSetSize) of bitmasks with the ideal CPU affinity for the device + * For example, if processors 0, 1, 32, and 33 are ideal for the device and cpuSetSize == 2, + * result[0] = 0x3, result[1] = 0x3 + * This is equivalent to calling \ref nvmlDeviceGetCpuAffinityWithinScope with \ref NVML_AFFINITY_SCOPE_NODE. + * + * For Kepler &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device The identifier of the target device + * @param cpuSetSize The size of the cpuSet array that is safe to access + * @param cpuSet Array reference in which to return a bitmask of CPUs, 64 CPUs per * unsigned long on 64-bit machines, 32 on 32-bit machines * - * @return + * @return * - \ref NVML_SUCCESS if \a cpuAffinity has been filled * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, cpuSetSize == 0, or cpuSet is NULL @@ -2117,17 +3377,17 @@ nvmlReturn_t DECLDIR nvmlDeviceGetSerial(nvmlDevice_t device, char *serial, unsi nvmlReturn_t DECLDIR nvmlDeviceGetCpuAffinity(nvmlDevice_t device, unsigned int cpuSetSize, unsigned long *cpuSet); /** - * Sets the ideal affinity for the calling thread and device using the guidelines - * given in nvmlDeviceGetCpuAffinity(). Note, this is a change as of version 8.0. + * Sets the ideal affinity for the calling thread and device using the guidelines + * given in nvmlDeviceGetCpuAffinity(). Note, this is a change as of version 8.0. * Older versions set the affinity for a calling process and all children. - * Currently supports up to 64 processors. + * Currently supports up to 1024 processors. * * For Kepler &tm; or newer fully supported devices. * Supported on Linux only. * * @param device The identifier of the target device * - * @return + * @return * - \ref NVML_SUCCESS if the calling process has been successfully bound * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid @@ -2146,7 +3406,7 @@ nvmlReturn_t DECLDIR nvmlDeviceSetCpuAffinity(nvmlDevice_t device); * * @param device The identifier of the target device * - * @return + * @return * - \ref NVML_SUCCESS if the calling process has been successfully unbound * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized @@ -2169,6 +3429,8 @@ nvmlReturn_t DECLDIR nvmlDeviceClearCpuAffinity(nvmlDevice_t device); * - \ref NVML_ERROR_NOT_SUPPORTED if the device or OS does not support this feature * - \ref NVML_ERROR_UNKNOWN an error has occurred in underlying topology discovery */ + +/** @} */ nvmlReturn_t DECLDIR nvmlDeviceGetTopologyCommonAncestor(nvmlDevice_t device1, nvmlDevice_t device2, nvmlGpuTopologyLevel_t *pathInfo); /** @@ -2178,7 +3440,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetTopologyCommonAncestor(nvmlDevice_t device1, n * * @param device The identifier of the first device * @param level The \ref nvmlGpuTopologyLevel_t level to search for other GPUs - * @param count When zero, is set to the number of matching GPUs such that \a deviceArray + * @param count When zero, is set to the number of matching GPUs such that \a deviceArray * can be malloc'd. When non-zero, \a deviceArray will be filled with \a count * number of device handles. * @param deviceArray An array of device handles for GPUs found at \a level @@ -2192,37 +3454,18 @@ nvmlReturn_t DECLDIR nvmlDeviceGetTopologyCommonAncestor(nvmlDevice_t device1, n nvmlReturn_t DECLDIR nvmlDeviceGetTopologyNearestGpus(nvmlDevice_t device, nvmlGpuTopologyLevel_t level, unsigned int *count, nvmlDevice_t *deviceArray); /** - * Retrieve the set of GPUs that have a CPU affinity with the given CPU number - * For all products. - * Supported on Linux only. + * Retrieve the status for a given p2p capability index between a given pair of GPU * - * @param cpuNumber The CPU number - * @param count When zero, is set to the number of matching GPUs such that \a deviceArray - * can be malloc'd. When non-zero, \a deviceArray will be filled with \a count - * number of device handles. - * @param deviceArray An array of device handles for GPUs found with affinity to \a cpuNumber - * - * @return - * - \ref NVML_SUCCESS if \a deviceArray or \a count (if initially zero) has been set - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a cpuNumber, or \a count is invalid, or \a deviceArray is NULL with a non-zero \a count - * - \ref NVML_ERROR_NOT_SUPPORTED if the device or OS does not support this feature - * - \ref NVML_ERROR_UNKNOWN an error has occurred in underlying topology discovery - */ -nvmlReturn_t DECLDIR nvmlSystemGetTopologyGpuSet(unsigned int cpuNumber, unsigned int *count, nvmlDevice_t *deviceArray); - -/** - * Retrieve the status for a given p2p capability index between a given pair of GPU - * - * @param device1 The first device + * @param device1 The first device * @param device2 The second device * @param p2pIndex p2p Capability Index being looked for between \a device1 and \a device2 - * @param p2pStatus Reference in which to return the status of the \a p2pIndex + * @param p2pStatus Reference in which to return the status of the \a p2pIndex * between \a device1 and \a device2 - * @return + * @return * - \ref NVML_SUCCESS if \a p2pStatus has been populated * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device1 or \a device2 or \a p2pIndex is invalid or \a p2pStatus is NULL * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ + */ nvmlReturn_t DECLDIR nvmlDeviceGetP2PStatus(nvmlDevice_t device1, nvmlDevice_t device2, nvmlGpuP2PCapsIndex_t p2pIndex,nvmlGpuP2PStatus_t *p2pStatus); /** @@ -2232,18 +3475,21 @@ nvmlReturn_t DECLDIR nvmlDeviceGetP2PStatus(nvmlDevice_t device1, nvmlDevice_t d * For all products. * * The UUID is a globally unique identifier. It is the only available identifier for pre-Fermi-architecture products. - * It does NOT correspond to any identifier printed on the board. It will not exceed 80 characters in length - * (including the NULL terminator). See \ref nvmlConstants::NVML_DEVICE_UUID_BUFFER_SIZE. + * It does NOT correspond to any identifier printed on the board. It will not exceed 96 characters in length + * (including the NULL terminator). See \ref nvmlConstants::NVML_DEVICE_UUID_V2_BUFFER_SIZE. + * + * When used with MIG device handles the API returns globally unique UUIDs which can be used to identify MIG + * devices across both GPU and MIG devices. UUIDs are immutable for the lifetime of a MIG device. * * @param device The identifier of the target device * @param uuid Reference in which to return the GPU UUID * @param length The maximum allowed length of the string returned in \a uuid - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a uuid has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a uuid is NULL - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error @@ -2251,7 +3497,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetP2PStatus(nvmlDevice_t device1, nvmlDevice_t d nvmlReturn_t DECLDIR nvmlDeviceGetUUID(nvmlDevice_t device, char *uuid, unsigned int length); /** - * Retrieves minor number for the device. The minor number for the device is such that the Nvidia device node file for + * Retrieves minor number for the device. The minor number for the device is such that the Nvidia device node file for * each GPU will have the form /dev/nvidia[minor number]. * * For all products. @@ -2293,7 +3539,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetBoardPartNumber(nvmlDevice_t device, char* par * * For all products with an inforom. * - * Fermi and higher parts have non-volatile on-board memory for persisting device info, such as aggregate + * Fermi and higher parts have non-volatile on-board memory for persisting device info, such as aggregate * ECC counts. The version of the data structures in this memory may change from time to time. It will not * exceed 16 characters in length (including the NULL terminator). * See \ref nvmlConstants::NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE. @@ -2305,11 +3551,11 @@ nvmlReturn_t DECLDIR nvmlDeviceGetBoardPartNumber(nvmlDevice_t device, char* par * @param version Reference in which to return the infoROM version * @param length The maximum allowed length of the string returned in \a version * - * @return + * @return * - \ref NVML_SUCCESS if \a version has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a version is NULL - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have an infoROM * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error @@ -2323,7 +3569,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetInforomVersion(nvmlDevice_t device, nvmlInforo * * For all products with an inforom. * - * Image version just like VBIOS version uniquely describes the exact version of the infoROM flashed on the board + * Image version just like VBIOS version uniquely describes the exact version of the infoROM flashed on the board * in contrast to infoROM object version which is only an indicator of supported features. * Version string will not exceed 16 characters in length (including the NULL terminator). * See \ref nvmlConstants::NVML_DEVICE_INFOROM_VERSION_BUFFER_SIZE. @@ -2332,11 +3578,11 @@ nvmlReturn_t DECLDIR nvmlDeviceGetInforomVersion(nvmlDevice_t device, nvmlInforo * @param version Reference in which to return the infoROM image version * @param length The maximum allowed length of the string returned in \a version * - * @return + * @return * - \ref NVML_SUCCESS if \a version has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a version is NULL - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have an infoROM * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error @@ -2357,14 +3603,14 @@ nvmlReturn_t DECLDIR nvmlDeviceGetInforomImageVersion(nvmlDevice_t device, char * @param device The identifier of the target device * @param checksum Reference in which to return the infoROM configuration checksum * - * @return + * @return * - \ref NVML_SUCCESS if \a checksum has been set * - \ref NVML_ERROR_CORRUPTED_INFOROM if the device's checksum couldn't be retrieved due to infoROM corruption * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a checksum is NULL * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlDeviceGetInforomConfigurationChecksum(nvmlDevice_t device, unsigned int *checksum); @@ -2375,16 +3621,37 @@ nvmlReturn_t DECLDIR nvmlDeviceGetInforomConfigurationChecksum(nvmlDevice_t devi * * @param device The identifier of the target device * - * @return + * @return * - \ref NVML_SUCCESS if infoROM is not corrupted * - \ref NVML_ERROR_CORRUPTED_INFOROM if the device's infoROM is corrupted * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlDeviceValidateInforom(nvmlDevice_t device); +/** + * Retrieves the timestamp and the duration of the last flush of the BBX (blackbox) infoROM object during the current run. + * + * For all products with an inforom. + * + * @param device The identifier of the target device + * @param timestamp The start timestamp of the last BBX Flush + * @param durationUs The duration (us) of the last BBX Flush + * + * @return + * - \ref NVML_SUCCESS if \a timestamp and \a durationUs are successfully retrieved + * - \ref NVML_ERROR_NOT_READY if the BBX object has not been flushed yet + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have an infoROM + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetInforomVersion + */ +nvmlReturn_t DECLDIR nvmlDeviceGetLastBBXFlushTime(nvmlDevice_t device, unsigned long long *timestamp, + unsigned long *durationUs); + /** * Retrieves the display mode for the device. * @@ -2397,8 +3664,8 @@ nvmlReturn_t DECLDIR nvmlDeviceValidateInforom(nvmlDevice_t device); * * @param device The identifier of the target device * @param display Reference in which to return the display mode - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a display has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a display is NULL @@ -2422,8 +3689,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetDisplayMode(nvmlDevice_t device, nvmlEnableSta * * @param device The identifier of the target device * @param isActive Reference in which to return the display active state - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a isActive has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a isActive is NULL @@ -2439,15 +3706,15 @@ nvmlReturn_t DECLDIR nvmlDeviceGetDisplayActive(nvmlDevice_t device, nvmlEnableS * For all products. * For Linux only. * - * When driver persistence mode is enabled the driver software state is not torn down when the last - * client disconnects. By default this feature is disabled. + * When driver persistence mode is enabled the driver software state is not torn down when the last + * client disconnects. By default this feature is disabled. * * See \ref nvmlEnableState_t for details on allowed modes. * * @param device The identifier of the target device * @param mode Reference in which to return the current driver persistence mode - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a mode has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is NULL @@ -2461,35 +3728,35 @@ nvmlReturn_t DECLDIR nvmlDeviceGetPersistenceMode(nvmlDevice_t device, nvmlEnabl /** * Retrieves the PCI attributes of this device. - * + * * For all products. * * See \ref nvmlPciInfo_t for details on the available PCI info. * * @param device The identifier of the target device * @param pci Reference in which to return the PCI info - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a pci has been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pci is NULL * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceGetPciInfo(nvmlDevice_t device, nvmlPciInfo_t *pci); +nvmlReturn_t DECLDIR nvmlDeviceGetPciInfo_v3(nvmlDevice_t device, nvmlPciInfo_t *pci); /** * Retrieves the maximum PCIe link generation possible with this device and system * * I.E. for a generation 2 PCIe device attached to a generation 1 PCIe bus the max link generation this function will * report is generation 1. - * + * * For Fermi &tm; or newer fully supported devices. - * + * * @param device The identifier of the target device * @param maxLinkGen Reference in which to return the max PCIe link generation - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a maxLinkGen has been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a maxLinkGen is null @@ -2499,18 +3766,36 @@ nvmlReturn_t DECLDIR nvmlDeviceGetPciInfo(nvmlDevice_t device, nvmlPciInfo_t *pc */ nvmlReturn_t DECLDIR nvmlDeviceGetMaxPcieLinkGeneration(nvmlDevice_t device, unsigned int *maxLinkGen); +/** + * Retrieves the maximum PCIe link generation supported by this device + * + * For Fermi &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param maxLinkGenDevice Reference in which to return the max PCIe link generation + * + * @return + * - \ref NVML_SUCCESS if \a maxLinkGenDevice has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a maxLinkGenDevice is null + * - \ref NVML_ERROR_NOT_SUPPORTED if PCIe link information is not available + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuMaxPcieLinkGeneration(nvmlDevice_t device, unsigned int *maxLinkGenDevice); + /** * Retrieves the maximum PCIe link width possible with this device and system * * I.E. for a device with a 16x PCIe bus width attached to a 8x PCIe system bus this function will report * a max link width of 8. - * + * * For Fermi &tm; or newer fully supported devices. - * + * * @param device The identifier of the target device * @param maxLinkWidth Reference in which to return the max PCIe link generation - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a maxLinkWidth has been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a maxLinkWidth is null @@ -2522,13 +3807,13 @@ nvmlReturn_t DECLDIR nvmlDeviceGetMaxPcieLinkWidth(nvmlDevice_t device, unsigned /** * Retrieves the current PCIe link generation - * + * * For Fermi &tm; or newer fully supported devices. - * + * * @param device The identifier of the target device * @param currLinkGen Reference in which to return the current PCIe link generation - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a currLinkGen has been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a currLinkGen is null @@ -2540,13 +3825,13 @@ nvmlReturn_t DECLDIR nvmlDeviceGetCurrPcieLinkGeneration(nvmlDevice_t device, un /** * Retrieves the current PCIe link width - * + * * For Fermi &tm; or newer fully supported devices. - * + * * @param device The identifier of the target device * @param currLinkWidth Reference in which to return the current PCIe link generation - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a currLinkWidth has been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a currLinkWidth is null @@ -2558,7 +3843,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetCurrPcieLinkWidth(nvmlDevice_t device, unsigne /** * Retrieve PCIe utilization information. - * This function is querying a byte counter over a 20ms interval and thus is the + * This function is querying a byte counter over a 20ms interval and thus is the * PCIe throughput over that interval. * * For Maxwell &tm; or newer fully supported devices. @@ -2579,7 +3864,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetCurrPcieLinkWidth(nvmlDevice_t device, unsigne */ nvmlReturn_t DECLDIR nvmlDeviceGetPcieThroughput(nvmlDevice_t device, nvmlPcieUtilCounter_t counter, unsigned int *value); -/** +/** * Retrieve the PCIe replay counter. * * For Kepler &tm; or newer fully supported devices. @@ -2588,9 +3873,9 @@ nvmlReturn_t DECLDIR nvmlDeviceGetPcieThroughput(nvmlDevice_t device, nvmlPcieUt * @param value Reference in which to return the counter's value * * @return - * - \ref NVML_SUCCESS if \a value and \a rollover have been set + * - \ref NVML_SUCCESS if \a value has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a value or \a rollover are NULL + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a value is NULL * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error @@ -2607,8 +3892,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetPcieReplayCounter(nvmlDevice_t device, unsigne * @param device The identifier of the target device * @param type Identify which clock domain to query * @param clock Reference in which to return the clock speed in MHz - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a clock has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clock is NULL @@ -2631,8 +3916,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetClockInfo(nvmlDevice_t device, nvmlClockType_t * @param device The identifier of the target device * @param type Identify which clock domain to query * @param clock Reference in which to return the clock speed in MHz - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a clock has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clock is NULL @@ -2642,6 +3927,20 @@ nvmlReturn_t DECLDIR nvmlDeviceGetClockInfo(nvmlDevice_t device, nvmlClockType_t */ nvmlReturn_t DECLDIR nvmlDeviceGetMaxClockInfo(nvmlDevice_t device, nvmlClockType_t type, unsigned int *clock); +/** + * Retrieve the GPCCLK VF offset value + * @param[in] device The identifier of the target device + * @param[out] offset The retrieved GPCCLK VF offset value + * + * @return + * - \ref NVML_SUCCESS if \a offset has been successfully queried + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a offset is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpcClkVfOffset(nvmlDevice_t device, int *offset); + /** * Retrieves the current setting of a clock that applications will use unless an overspec situation occurs. * Can be changed using \ref nvmlDeviceSetApplicationsClocks. @@ -2651,8 +3950,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetMaxClockInfo(nvmlDevice_t device, nvmlClockTyp * @param device The identifier of the target device * @param clockType Identify which clock domain to query * @param clockMHz Reference in which to return the clock in MHz - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a clockMHz has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clockMHz is NULL or \a clockType is invalid @@ -2663,7 +3962,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetMaxClockInfo(nvmlDevice_t device, nvmlClockTyp nvmlReturn_t DECLDIR nvmlDeviceGetApplicationsClock(nvmlDevice_t device, nvmlClockType_t clockType, unsigned int *clockMHz); /** - * Retrieves the default applications clock that GPU boots with or + * Retrieves the default applications clock that GPU boots with or * defaults to after \ref nvmlDeviceResetApplicationsClocks call. * * For Kepler &tm; or newer fully supported devices. @@ -2671,8 +3970,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetApplicationsClock(nvmlDevice_t device, nvmlClo * @param device The identifier of the target device * @param clockType Identify which clock domain to query * @param clockMHz Reference in which to return the default clock in MHz - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a clockMHz has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clockMHz is NULL or \a clockType is invalid @@ -2684,33 +3983,6 @@ nvmlReturn_t DECLDIR nvmlDeviceGetApplicationsClock(nvmlDevice_t device, nvmlClo */ nvmlReturn_t DECLDIR nvmlDeviceGetDefaultApplicationsClock(nvmlDevice_t device, nvmlClockType_t clockType, unsigned int *clockMHz); -/** - * Resets the application clock to the default value - * - * This is the applications clock that will be used after system reboot or driver reload. - * Default value is constant, but the current value an be changed using \ref nvmlDeviceSetApplicationsClocks. - * - * On Pascal and newer hardware, if clocks were previously locked with \ref nvmlDeviceSetApplicationsClocks, - * this call will unlock clocks. This returns clocks their default behavior ofautomatically boosting above - * base clocks as thermal limits allow. - * - * @see nvmlDeviceGetApplicationsClock - * @see nvmlDeviceSetApplicationsClocks - * - * For Fermi &tm; or newer non-GeForce fully supported devices and Maxwell or newer GeForce devices. - * - * @param device The identifier of the target device - * - * @return - * - \ref NVML_SUCCESS if new settings were successfully set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceResetApplicationsClocks(nvmlDevice_t device); - /** * Retrieves the clock speed for the clock specified by the clock type and clock ID. * @@ -2759,9 +4031,9 @@ nvmlReturn_t DECLDIR nvmlDeviceGetMaxCustomerBoostClock(nvmlDevice_t device, nvm * @param count Reference in which to provide the \a clocksMHz array size, and * to return the number of elements * @param clocksMHz Reference in which to return the clock in MHz - * - * @return - * - \ref NVML_SUCCESS if \a count and \a clocksMHz have been populated + * + * @return + * - \ref NVML_SUCCESS if \a count and \a clocksMHz have been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a count is NULL * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature @@ -2785,14 +4057,14 @@ nvmlReturn_t DECLDIR nvmlDeviceGetSupportedMemoryClocks(nvmlDevice_t device, uns * @param count Reference in which to provide the \a clocksMHz array size, and * to return the number of elements * @param clocksMHz Reference in which to return the clocks in MHz - * - * @return - * - \ref NVML_SUCCESS if \a count and \a clocksMHz have been populated + * + * @return + * - \ref NVML_SUCCESS if \a count and \a clocksMHz have been populated * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_NOT_FOUND if the specified \a memoryClockMHz is not a supported frequency * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clock is NULL * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a count is too small + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a count is too small * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error * @@ -2829,6 +4101,2568 @@ nvmlReturn_t DECLDIR nvmlDeviceGetSupportedGraphicsClocks(nvmlDevice_t device, u */ nvmlReturn_t DECLDIR nvmlDeviceGetAutoBoostedClocksEnabled(nvmlDevice_t device, nvmlEnableState_t *isEnabled, nvmlEnableState_t *defaultIsEnabled); +/** + * Retrieves the intended operating speed of the device's fan. + * + * Note: The reported speed is the intended fan speed. If the fan is physically blocked and unable to spin, the + * output will not match the actual fan speed. + * + * For all discrete products with dedicated fans. + * + * The fan speed is expressed as a percentage of the product's maximum noise tolerance fan speed. + * This value may exceed 100% in certain cases. + * + * @param device The identifier of the target device + * @param speed Reference in which to return the fan speed percentage + * + * @return + * - \ref NVML_SUCCESS if \a speed has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a speed is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have a fan + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetFanSpeed(nvmlDevice_t device, unsigned int *speed); + + +/** + * Retrieves the intended operating speed of the device's specified fan. + * + * Note: The reported speed is the intended fan speed. If the fan is physically blocked and unable to spin, the + * output will not match the actual fan speed. + * + * For all discrete products with dedicated fans. + * + * The fan speed is expressed as a percentage of the product's maximum noise tolerance fan speed. + * This value may exceed 100% in certain cases. + * + * @param device The identifier of the target device + * @param fan The index of the target fan, zero indexed. + * @param speed Reference in which to return the fan speed percentage + * + * @return + * - \ref NVML_SUCCESS if \a speed has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a fan is not an acceptable index, or \a speed is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have a fan or is newer than Maxwell + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetFanSpeed_v2(nvmlDevice_t device, unsigned int fan, unsigned int * speed); + +/** + * Retrieves the intended target speed of the device's specified fan. + * + * Normally, the driver dynamically adjusts the fan based on + * the needs of the GPU. But when user set fan speed using nvmlDeviceSetFanSpeed_v2, + * the driver will attempt to make the fan achieve the setting in + * nvmlDeviceSetFanSpeed_v2. The actual current speed of the fan + * is reported in nvmlDeviceGetFanSpeed_v2. + * + * For all discrete products with dedicated fans. + * + * The fan speed is expressed as a percentage of the product's maximum noise tolerance fan speed. + * This value may exceed 100% in certain cases. + * + * @param device The identifier of the target device + * @param fan The index of the target fan, zero indexed. + * @param targetSpeed Reference in which to return the fan speed percentage + * + * @return + * - \ref NVML_SUCCESS if \a speed has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a fan is not an acceptable index, or \a speed is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have a fan or is newer than Maxwell + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTargetFanSpeed(nvmlDevice_t device, unsigned int fan, unsigned int *targetSpeed); + +/** + * Retrieves the min and max fan speed that user can set for the GPU fan. + * + * For all cuda-capable discrete products with fans + * + * @param device The identifier of the target device + * @param minSpeed The minimum speed allowed to set + * @param maxSpeed The maximum speed allowed to set + * + * return + * NVML_SUCCESS if speed has been adjusted + * NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * NVML_ERROR_INVALID_ARGUMENT if device is invalid + * NVML_ERROR_NOT_SUPPORTED if the device does not support this + * (doesn't have fans) + * NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMinMaxFanSpeed(nvmlDevice_t device, unsigned int * minSpeed, + unsigned int * maxSpeed); + +/** + * Gets current fan control policy. + * + * For Maxwell &tm; or newer fully supported devices. + * + * For all cuda-capable discrete products with fans + * + * device The identifier of the target \a device + * policy Reference in which to return the fan control \a policy + * + * return + * NVML_SUCCESS if \a policy has been populated + * NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a policy is null or the \a fan given doesn't reference + * a fan that exists. + * NVML_ERROR_NOT_SUPPORTED if the \a device is older than Maxwell + * NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetFanControlPolicy_v2(nvmlDevice_t device, unsigned int fan, + nvmlFanControlPolicy_t *policy); + +/** + * Retrieves the number of fans on the device. + * + * For all discrete products with dedicated fans. + * + * @param device The identifier of the target device + * @param numFans The number of fans + * + * @return + * - \ref NVML_SUCCESS if \a fan number query was successful + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a numFans is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have a fan + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetNumFans(nvmlDevice_t device, unsigned int *numFans); + +/** + * Retrieves the current temperature readings for the device, in degrees C. + * + * For all products. + * + * See \ref nvmlTemperatureSensors_t for details on available temperature sensors. + * + * @param device The identifier of the target device + * @param sensorType Flag that indicates which sensor reading to retrieve + * @param temp Reference in which to return the temperature reading + * + * @return + * - \ref NVML_SUCCESS if \a temp has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a sensorType is invalid or \a temp is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have the specified sensor + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTemperature(nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp); + +/** + * Retrieves the temperature threshold for the GPU with the specified threshold type in degrees C. + * + * For Kepler &tm; or newer fully supported devices. + * + * See \ref nvmlTemperatureThresholds_t for details on available temperature thresholds. + * + * Note: This API is no longer the preferred interface for retrieving the following temperature thresholds + * on Ada and later architectures: NVML_TEMPERATURE_THRESHOLD_SHUTDOWN, NVML_TEMPERATURE_THRESHOLD_SLOWDOWN, + * NVML_TEMPERATURE_THRESHOLD_MEM_MAX and NVML_TEMPERATURE_THRESHOLD_GPU_MAX. + * + * Support for reading these temperature thresholds for Ada and later architectures would be removed from this + * API in future releases. Please use \ref nvmlDeviceGetFieldValues with NVML_FI_DEV_TEMPERATURE_* fields to retrieve + * temperature thresholds on these architectures. + * + * @param device The identifier of the target device + * @param thresholdType The type of threshold value queried + * @param temp Reference in which to return the temperature reading + * @return + * - \ref NVML_SUCCESS if \a temp has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a thresholdType is invalid or \a temp is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have a temperature sensor or is unsupported + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTemperatureThreshold(nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp); + +/** + * Used to execute a list of thermal system instructions. + * + * @param device The identifier of the target device + * @param sensorIndex The index of the thermal sensor + * @param pThermalSettings Reference in which to return the thermal sensor information + * + * @return + * - \ref NVML_SUCCESS if \a pThermalSettings has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pThermalSettings is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetThermalSettings(nvmlDevice_t device, unsigned int sensorIndex, nvmlGpuThermalSettings_t *pThermalSettings); + +/** + * Retrieves the current performance state for the device. + * + * For Fermi &tm; or newer fully supported devices. + * + * See \ref nvmlPstates_t for details on allowed performance states. + * + * @param device The identifier of the target device + * @param pState Reference in which to return the performance state reading + * + * @return + * - \ref NVML_SUCCESS if \a pState has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pState is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPerformanceState(nvmlDevice_t device, nvmlPstates_t *pState); + +/** + * Retrieves current clocks event reasons. + * + * For all fully supported products. + * + * \note More than one bit can be enabled at the same time. Multiple reasons can be affecting clocks at once. + * + * @param device The identifier of the target device + * @param clocksEventReasons Reference in which to return bitmask of active clocks event + * reasons + * + * @return + * - \ref NVML_SUCCESS if \a clocksEventReasons has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clocksEventReasons is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlClocksEventReasons + * @see nvmlDeviceGetSupportedClocksEventReasons + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCurrentClocksEventReasons(nvmlDevice_t device, unsigned long long *clocksEventReasons); + +/** + * @deprecated Use \ref nvmlDeviceGetCurrentClocksEventReasons instead + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCurrentClocksThrottleReasons(nvmlDevice_t device, unsigned long long *clocksThrottleReasons); + +/** + * Retrieves bitmask of supported clocks event reasons that can be returned by + * \ref nvmlDeviceGetCurrentClocksEventReasons + * + * For all fully supported products. + * + * This method is not supported in virtual machines running virtual GPU (vGPU). + * + * @param device The identifier of the target device + * @param supportedClocksEventReasons Reference in which to return bitmask of supported + * clocks event reasons + * + * @return + * - \ref NVML_SUCCESS if \a supportedClocksEventReasons has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a supportedClocksEventReasons is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlClocksEventReasons + * @see nvmlDeviceGetCurrentClocksEventReasons + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSupportedClocksEventReasons(nvmlDevice_t device, unsigned long long *supportedClocksEventReasons); + +/** + * @deprecated Use \ref nvmlDeviceGetSupportedClocksEventReasons instead + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSupportedClocksThrottleReasons(nvmlDevice_t device, unsigned long long *supportedClocksThrottleReasons); + +/** + * Deprecated: Use \ref nvmlDeviceGetPerformanceState. This function exposes an incorrect generalization. + * + * Retrieve the current performance state for the device. + * + * For Fermi &tm; or newer fully supported devices. + * + * See \ref nvmlPstates_t for details on allowed performance states. + * + * @param device The identifier of the target device + * @param pState Reference in which to return the performance state reading + * + * @return + * - \ref NVML_SUCCESS if \a pState has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pState is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerState(nvmlDevice_t device, nvmlPstates_t *pState); + +/** + * Retrieve performance monitor samples from the associated subdevice. + * + * @param device + * @param pDynamicPstatesInfo + * + * @return + * - \ref NVML_SUCCESS if \a pDynamicPstatesInfo has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pDynamicPstatesInfo is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDynamicPstatesInfo(nvmlDevice_t device, nvmlGpuDynamicPstatesInfo_t *pDynamicPstatesInfo); + +/** + * Retrieve the MemClk (Memory Clock) VF offset value. + * @param[in] device The identifier of the target device + * @param[out] offset The retrieved MemClk VF offset value + * + * @return + * - \ref NVML_SUCCESS if \a offset has been successfully queried + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a offset is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMemClkVfOffset(nvmlDevice_t device, int *offset); + +/** + * Retrieve min and max clocks of some clock domain for a given PState + * + * @param device The identifier of the target device + * @param type Clock domain + * @param pstate PState to query + * @param minClockMHz Reference in which to return min clock frequency + * @param maxClockMHz Reference in which to return max clock frequency + * + * @return + * - \ref NVML_SUCCESS if everything worked + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a type or \a pstate are invalid or both + * \a minClockMHz and \a maxClockMHz are NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMinMaxClockOfPState(nvmlDevice_t device, nvmlClockType_t type, nvmlPstates_t pstate, + unsigned int * minClockMHz, unsigned int * maxClockMHz); + +/** + * Get all supported Performance States (P-States) for the device. + * + * The returned array would contain a contiguous list of valid P-States supported by + * the device. If the number of supported P-States is fewer than the size of the array + * supplied missing elements would contain \a NVML_PSTATE_UNKNOWN. + * + * The number of elements in the returned list will never exceed \a NVML_MAX_GPU_PERF_PSTATES. + * + * @param device The identifier of the target device + * @param pstates Container to return the list of performance states + * supported by device + * @param size Size of the supplied \a pstates array in bytes + * + * @return + * - \ref NVML_SUCCESS if \a pstates array has been retrieved + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if the the container supplied was not large enough to + * hold the resulting list + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a pstates is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support performance state readings + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSupportedPerformanceStates(nvmlDevice_t device, + nvmlPstates_t *pstates, unsigned int size); + +/** + * Retrieve the GPCCLK min max VF offset value. + * @param[in] device The identifier of the target device + * @param[out] minOffset The retrieved GPCCLK VF min offset value + * @param[out] maxOffset The retrieved GPCCLK VF max offset value + * + * @return + * - \ref NVML_SUCCESS if \a offset has been successfully queried + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a offset is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpcClkMinMaxVfOffset(nvmlDevice_t device, + int *minOffset, int *maxOffset); + +/** + * Retrieve the MemClk (Memory Clock) min max VF offset value. + * @param[in] device The identifier of the target device + * @param[out] minOffset The retrieved MemClk VF min offset value + * @param[out] maxOffset The retrieved MemClk VF max offset value + * + * @return + * - \ref NVML_SUCCESS if \a offset has been successfully queried + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a offset is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMemClkMinMaxVfOffset(nvmlDevice_t device, + int *minOffset, int *maxOffset); + +/** + * This API has been deprecated. + * + * Retrieves the power management mode associated with this device. + * + * For products from the Fermi family. + * - Requires \a NVML_INFOROM_POWER version 3.0 or higher. + * + * For from the Kepler or newer families. + * - Does not require \a NVML_INFOROM_POWER object. + * + * This flag indicates whether any power management algorithm is currently active on the device. An + * enabled state does not necessarily mean the device is being actively throttled -- only that + * that the driver will do so if the appropriate conditions are met. + * + * See \ref nvmlEnableState_t for details on allowed modes. + * + * @param device The identifier of the target device + * @param mode Reference in which to return the current power management mode + * + * @return + * - \ref NVML_SUCCESS if \a mode has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementMode(nvmlDevice_t device, nvmlEnableState_t *mode); + +/** + * Retrieves the power management limit associated with this device. + * + * For Fermi &tm; or newer fully supported devices. + * + * The power limit defines the upper boundary for the card's power draw. If + * the card's total power draw reaches this limit the power management algorithm kicks in. + * + * This reading is only available if power management mode is supported. + * See \ref nvmlDeviceGetPowerManagementMode. + * + * @param device The identifier of the target device + * @param limit Reference in which to return the power management limit in milliwatts + * + * @return + * - \ref NVML_SUCCESS if \a limit has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a limit is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementLimit(nvmlDevice_t device, unsigned int *limit); + +/** + * Retrieves information about possible values of power management limits on this device. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param minLimit Reference in which to return the minimum power management limit in milliwatts + * @param maxLimit Reference in which to return the maximum power management limit in milliwatts + * + * @return + * - \ref NVML_SUCCESS if \a minLimit and \a maxLimit have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a minLimit or \a maxLimit is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetPowerManagementLimit + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementLimitConstraints(nvmlDevice_t device, unsigned int *minLimit, unsigned int *maxLimit); + +/** + * Retrieves default power management limit on this device, in milliwatts. + * Default power management limit is a power management limit that the device boots with. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param defaultLimit Reference in which to return the default power management limit in milliwatts + * + * @return + * - \ref NVML_SUCCESS if \a defaultLimit has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a defaultLimit is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementDefaultLimit(nvmlDevice_t device, unsigned int *defaultLimit); + +/** + * Retrieves power usage for this GPU in milliwatts and its associated circuitry (e.g. memory) + * + * For Fermi &tm; or newer fully supported devices. + * + * On Fermi and Kepler GPUs the reading is accurate to within +/- 5% of current power draw. On Ampere + * (except GA100) or newer GPUs, the API returns power averaged over 1 sec interval. On GA100 and + * older architectures, instantaneous power is returned. + * + * See \ref NVML_FI_DEV_POWER_AVERAGE and \ref NVML_FI_DEV_POWER_INSTANT to query specific power + * values. + * + * It is only available if power management mode is supported. See \ref nvmlDeviceGetPowerManagementMode. + * + * @param device The identifier of the target device + * @param power Reference in which to return the power usage information + * + * @return + * - \ref NVML_SUCCESS if \a power has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a power is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support power readings + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerUsage(nvmlDevice_t device, unsigned int *power); + +/** + * Retrieves total energy consumption for this GPU in millijoules (mJ) since the driver was last reloaded + * + * For Volta &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param energy Reference in which to return the energy consumption information + * + * @return + * - \ref NVML_SUCCESS if \a energy has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a energy is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support energy readings + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTotalEnergyConsumption(nvmlDevice_t device, unsigned long long *energy); + +/** + * Get the effective power limit that the driver enforces after taking into account all limiters + * + * Note: This can be different from the \ref nvmlDeviceGetPowerManagementLimit if other limits are set elsewhere + * This includes the out of band power limit interface + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The device to communicate with + * @param limit Reference in which to return the power management limit in milliwatts + * + * @return + * - \ref NVML_SUCCESS if \a limit has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a limit is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEnforcedPowerLimit(nvmlDevice_t device, unsigned int *limit); + +/** + * Retrieves the current GOM and pending GOM (the one that GPU will switch to after reboot). + * + * For GK110 M-class and X-class Tesla &tm; products from the Kepler family. + * Modes \ref NVML_GOM_LOW_DP and \ref NVML_GOM_ALL_ON are supported on fully supported GeForce products. + * Not supported on Quadro ® and Tesla &tm; C-class products. + * + * @param device The identifier of the target device + * @param current Reference in which to return the current GOM + * @param pending Reference in which to return the pending GOM + * + * @return + * - \ref NVML_SUCCESS if \a mode has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a current or \a pending is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlGpuOperationMode_t + * @see nvmlDeviceSetGpuOperationMode + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuOperationMode(nvmlDevice_t device, nvmlGpuOperationMode_t *current, nvmlGpuOperationMode_t *pending); + +/** + * Retrieves the amount of used, free, reserved and total memory available on the device, in bytes. + * The reserved amount is supported on version 2 only. + * + * For all products. + * + * Enabling ECC reduces the amount of total available memory, due to the extra required parity bits. + * Under WDDM most device memory is allocated and managed on startup by Windows. + * + * Under Linux and Windows TCC, the reported amount of used memory is equal to the sum of memory allocated + * by all active channels on the device. + * + * See \ref nvmlMemory_v2_t for details on available memory info. + * + * @note In MIG mode, if device handle is provided, the API returns aggregate + * information, only if the caller has appropriate privileges. Per-instance + * information can be queried by using specific MIG device handles. + * + * @note nvmlDeviceGetMemoryInfo_v2 adds additional memory information. + * + * @note On systems where GPUs are NUMA nodes, the accuracy of FB memory utilization + * provided by this API depends on the memory accounting of the operating system. + * This is because FB memory is managed by the operating system instead of the NVIDIA GPU driver. + * Typically, pages allocated from FB memory are not released even after + * the process terminates to enhance performance. In scenarios where + * the operating system is under memory pressure, it may resort to utilizing FB memory. + * Such actions can result in discrepancies in the accuracy of memory reporting. + * + * @param device The identifier of the target device + * @param memory Reference in which to return the memory information + * + * @return + * - \ref NVML_SUCCESS if \a memory has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a memory is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMemoryInfo(nvmlDevice_t device, nvmlMemory_t *memory); +nvmlReturn_t DECLDIR nvmlDeviceGetMemoryInfo_v2(nvmlDevice_t device, nvmlMemory_v2_t *memory); + +/** + * Retrieves the current compute mode for the device. + * + * For all products. + * + * See \ref nvmlComputeMode_t for details on allowed compute modes. + * + * @param device The identifier of the target device + * @param mode Reference in which to return the current compute mode + * + * @return + * - \ref NVML_SUCCESS if \a mode has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetComputeMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetComputeMode(nvmlDevice_t device, nvmlComputeMode_t *mode); + +/** + * Retrieves the CUDA compute capability of the device. + * + * For all products. + * + * Returns the major and minor compute capability version numbers of the + * device. The major and minor versions are equivalent to the + * CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR and + * CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR attributes that would be + * returned by CUDA's cuDeviceGetAttribute(). + * + * @param device The identifier of the target device + * @param major Reference in which to return the major CUDA compute capability + * @param minor Reference in which to return the minor CUDA compute capability + * + * @return + * - \ref NVML_SUCCESS if \a major and \a minor have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a major or \a minor are NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetCudaComputeCapability(nvmlDevice_t device, int *major, int *minor); + +/** + * Retrieves the current and pending ECC modes for the device. + * + * For Fermi &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher. + * + * Changing ECC modes requires a reboot. The "pending" ECC mode refers to the target mode following + * the next reboot. + * + * See \ref nvmlEnableState_t for details on allowed modes. + * + * @param device The identifier of the target device + * @param current Reference in which to return the current ECC mode + * @param pending Reference in which to return the pending ECC mode + * + * @return + * - \ref NVML_SUCCESS if \a current and \a pending have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or either \a current or \a pending is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetEccMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEccMode(nvmlDevice_t device, nvmlEnableState_t *current, nvmlEnableState_t *pending); + +/** + * Retrieves the default ECC modes for the device. + * + * For Fermi &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher. + * + * See \ref nvmlEnableState_t for details on allowed modes. + * + * @param device The identifier of the target device + * @param defaultMode Reference in which to return the default ECC mode + * + * @return + * - \ref NVML_SUCCESS if \a current and \a pending have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a default is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetEccMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDefaultEccMode(nvmlDevice_t device, nvmlEnableState_t *defaultMode); + +/** + * Retrieves the device boardId from 0-N. + * Devices with the same boardId indicate GPUs connected to the same PLX. Use in conjunction with + * \ref nvmlDeviceGetMultiGpuBoard() to decide if they are on the same board as well. + * The boardId returned is a unique ID for the current configuration. Uniqueness and ordering across + * reboots and system configurations is not guaranteed (i.e. if a Tesla K40c returns 0x100 and + * the two GPUs on a Tesla K10 in the same system returns 0x200 it is not guaranteed they will + * always return those values but they will always be different from each other). + * + * + * For Fermi &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param boardId Reference in which to return the device's board ID + * + * @return + * - \ref NVML_SUCCESS if \a boardId has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a boardId is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetBoardId(nvmlDevice_t device, unsigned int *boardId); + +/** + * Retrieves whether the device is on a Multi-GPU Board + * Devices that are on multi-GPU boards will set \a multiGpuBool to a non-zero value. + * + * For Fermi &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param multiGpuBool Reference in which to return a zero or non-zero value + * to indicate whether the device is on a multi GPU board + * + * @return + * - \ref NVML_SUCCESS if \a multiGpuBool has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a multiGpuBool is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMultiGpuBoard(nvmlDevice_t device, unsigned int *multiGpuBool); + +/** + * Retrieves the total ECC error counts for the device. + * + * For Fermi &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher. + * Requires ECC Mode to be enabled. + * + * The total error count is the sum of errors across each of the separate memory systems, i.e. the total set of + * errors across the entire device. + * + * See \ref nvmlMemoryErrorType_t for a description of available error types.\n + * See \ref nvmlEccCounterType_t for a description of available counter types. + * + * @param device The identifier of the target device + * @param errorType Flag that specifies the type of the errors. + * @param counterType Flag that specifies the counter-type of the errors. + * @param eccCounts Reference in which to return the specified ECC errors + * + * @return + * - \ref NVML_SUCCESS if \a eccCounts has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a errorType or \a counterType is invalid, or \a eccCounts is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceClearEccErrorCounts() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetTotalEccErrors(nvmlDevice_t device, nvmlMemoryErrorType_t errorType, nvmlEccCounterType_t counterType, unsigned long long *eccCounts); + +/** + * Retrieves the detailed ECC error counts for the device. + * + * @deprecated This API supports only a fixed set of ECC error locations + * On different GPU architectures different locations are supported + * See \ref nvmlDeviceGetMemoryErrorCounter + * + * For Fermi &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 2.0 or higher to report aggregate location-based ECC counts. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher to report all other ECC counts. + * Requires ECC Mode to be enabled. + * + * Detailed errors provide separate ECC counts for specific parts of the memory system. + * + * Reports zero for unsupported ECC error counters when a subset of ECC error counters are supported. + * + * See \ref nvmlMemoryErrorType_t for a description of available bit types.\n + * See \ref nvmlEccCounterType_t for a description of available counter types.\n + * See \ref nvmlEccErrorCounts_t for a description of provided detailed ECC counts. + * + * @param device The identifier of the target device + * @param errorType Flag that specifies the type of the errors. + * @param counterType Flag that specifies the counter-type of the errors. + * @param eccCounts Reference in which to return the specified ECC errors + * + * @return + * - \ref NVML_SUCCESS if \a eccCounts has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a errorType or \a counterType is invalid, or \a eccCounts is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceClearEccErrorCounts() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDetailedEccErrors(nvmlDevice_t device, nvmlMemoryErrorType_t errorType, nvmlEccCounterType_t counterType, nvmlEccErrorCounts_t *eccCounts); + +/** + * Retrieves the requested memory error counter for the device. + * + * For Fermi &tm; or newer fully supported devices. + * Requires \a NVML_INFOROM_ECC version 2.0 or higher to report aggregate location-based memory error counts. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher to report all other memory error counts. + * + * Only applicable to devices with ECC. + * + * Requires ECC Mode to be enabled. + * + * @note On MIG-enabled GPUs, per instance information can be queried using specific + * MIG device handles. Per instance information is currently only supported for + * non-DRAM uncorrectable volatile errors. Querying volatile errors using device + * handles is currently not supported. + * + * See \ref nvmlMemoryErrorType_t for a description of available memory error types.\n + * See \ref nvmlEccCounterType_t for a description of available counter types.\n + * See \ref nvmlMemoryLocation_t for a description of available counter locations.\n + * + * @param device The identifier of the target device + * @param errorType Flag that specifies the type of error. + * @param counterType Flag that specifies the counter-type of the errors. + * @param locationType Specifies the location of the counter. + * @param count Reference in which to return the ECC counter + * + * @return + * - \ref NVML_SUCCESS if \a count has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a bitTyp,e \a counterType or \a locationType is + * invalid, or \a count is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support ECC error reporting in the specified memory + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMemoryErrorCounter(nvmlDevice_t device, nvmlMemoryErrorType_t errorType, + nvmlEccCounterType_t counterType, + nvmlMemoryLocation_t locationType, unsigned long long *count); + +/** + * Retrieves the current utilization rates for the device's major subsystems. + * + * For Fermi &tm; or newer fully supported devices. + * + * See \ref nvmlUtilization_t for details on available utilization rates. + * + * \note During driver initialization when ECC is enabled one can see high GPU and Memory Utilization readings. + * This is caused by ECC Memory Scrubbing mechanism that is performed during driver initialization. + * + * @note On MIG-enabled GPUs, querying device utilization rates is not currently supported. + * + * @param device The identifier of the target device + * @param utilization Reference in which to return the utilization information + * + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a utilization is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetUtilizationRates(nvmlDevice_t device, nvmlUtilization_t *utilization); + +/** + * Retrieves the current utilization and sampling size in microseconds for the Encoder + * + * For Kepler &tm; or newer fully supported devices. + * + * @note On MIG-enabled GPUs, querying encoder utilization is not currently supported. + * + * @param device The identifier of the target device + * @param utilization Reference to an unsigned int for encoder utilization info + * @param samplingPeriodUs Reference to an unsigned int for the sampling period in US + * + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEncoderUtilization(nvmlDevice_t device, unsigned int *utilization, unsigned int *samplingPeriodUs); + +/** + * Retrieves the current capacity of the device's encoder, as a percentage of maximum encoder capacity with valid values in the range 0-100. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param encoderQueryType Type of encoder to query + * @param encoderCapacity Reference to an unsigned int for the encoder capacity + * + * @return + * - \ref NVML_SUCCESS if \a encoderCapacity is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a encoderCapacity is NULL, or \a device or \a encoderQueryType + * are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if device does not support the encoder specified in \a encodeQueryType + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEncoderCapacity (nvmlDevice_t device, nvmlEncoderType_t encoderQueryType, unsigned int *encoderCapacity); + +/** + * Retrieves the current encoder statistics for a given device. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param sessionCount Reference to an unsigned int for count of active encoder sessions + * @param averageFps Reference to an unsigned int for trailing average FPS of all active sessions + * @param averageLatency Reference to an unsigned int for encode latency in microseconds + * + * @return + * - \ref NVML_SUCCESS if \a sessionCount, \a averageFps and \a averageLatency is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount, or \a device or \a averageFps, + * or \a averageLatency is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEncoderStats (nvmlDevice_t device, unsigned int *sessionCount, + unsigned int *averageFps, unsigned int *averageLatency); + +/** + * Retrieves information about active encoder sessions on a target device. + * + * An array of active encoder sessions is returned in the caller-supplied buffer pointed at by \a sessionInfos. The + * array element count is passed in \a sessionCount, and \a sessionCount is used to return the number of sessions + * written to the buffer. + * + * If the supplied buffer is not large enough to accommodate the active session array, the function returns + * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlEncoderSessionInfo_t array required in \a sessionCount. + * To query the number of active encoder sessions, call this function with *sessionCount = 0. The code will return + * NVML_SUCCESS with number of active encoder sessions updated in *sessionCount. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param sessionCount Reference to caller supplied array size, and returns the number of sessions. + * @param sessionInfos Reference in which to return the session information + * + * @return + * - \ref NVML_SUCCESS if \a sessionInfos is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a sessionCount is too small, array element count is returned in \a sessionCount + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount is NULL. + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by \a device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetEncoderSessions(nvmlDevice_t device, unsigned int *sessionCount, nvmlEncoderSessionInfo_t *sessionInfos); + +/** + * Retrieves the current utilization and sampling size in microseconds for the Decoder + * + * For Kepler &tm; or newer fully supported devices. + * + * @note On MIG-enabled GPUs, querying decoder utilization is not currently supported. + * + * @param device The identifier of the target device + * @param utilization Reference to an unsigned int for decoder utilization info + * @param samplingPeriodUs Reference to an unsigned int for the sampling period in US + * + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDecoderUtilization(nvmlDevice_t device, unsigned int *utilization, unsigned int *samplingPeriodUs); + +/** + * Retrieves the current utilization and sampling size in microseconds for the JPG + * + * %TURING_OR_NEWER% + * + * @note On MIG-enabled GPUs, querying decoder utilization is not currently supported. + * + * @param device The identifier of the target device + * @param utilization Reference to an unsigned int for jpg utilization info + * @param samplingPeriodUs Reference to an unsigned int for the sampling period in US + * + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetJpgUtilization(nvmlDevice_t device, unsigned int *utilization, unsigned int *samplingPeriodUs); + +/** + * Retrieves the current utilization and sampling size in microseconds for the OFA (Optical Flow Accelerator) + * + * %TURING_OR_NEWER% + * + * @note On MIG-enabled GPUs, querying decoder utilization is not currently supported. + * + * @param device The identifier of the target device + * @param utilization Reference to an unsigned int for ofa utilization info + * @param samplingPeriodUs Reference to an unsigned int for the sampling period in US + * + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetOfaUtilization(nvmlDevice_t device, unsigned int *utilization, unsigned int *samplingPeriodUs); + +/** +* Retrieves the active frame buffer capture sessions statistics for a given device. +* +* For Maxwell &tm; or newer fully supported devices. +* +* @param device The identifier of the target device +* @param fbcStats Reference to nvmlFBCStats_t structure containing NvFBC stats +* +* @return +* - \ref NVML_SUCCESS if \a fbcStats is fetched +* - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized +* - \ref NVML_ERROR_INVALID_ARGUMENT if \a fbcStats is NULL +* - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible +* - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlDeviceGetFBCStats(nvmlDevice_t device, nvmlFBCStats_t *fbcStats); + +/** +* Retrieves information about active frame buffer capture sessions on a target device. +* +* An array of active FBC sessions is returned in the caller-supplied buffer pointed at by \a sessionInfo. The +* array element count is passed in \a sessionCount, and \a sessionCount is used to return the number of sessions +* written to the buffer. +* +* If the supplied buffer is not large enough to accommodate the active session array, the function returns +* NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlFBCSessionInfo_t array required in \a sessionCount. +* To query the number of active FBC sessions, call this function with *sessionCount = 0. The code will return +* NVML_SUCCESS with number of active FBC sessions updated in *sessionCount. +* +* For Maxwell &tm; or newer fully supported devices. +* +* @note hResolution, vResolution, averageFPS and averageLatency data for a FBC session returned in \a sessionInfo may +* be zero if there are no new frames captured since the session started. +* +* @param device The identifier of the target device +* @param sessionCount Reference to caller supplied array size, and returns the number of sessions. +* @param sessionInfo Reference in which to return the session information +* +* @return +* - \ref NVML_SUCCESS if \a sessionInfo is fetched +* - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized +* - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a sessionCount is too small, array element count is returned in \a sessionCount +* - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount is NULL. +* - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible +* - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlDeviceGetFBCSessions(nvmlDevice_t device, unsigned int *sessionCount, nvmlFBCSessionInfo_t *sessionInfo); + +/** + * Retrieves the current and pending driver model for the device. + * + * For Fermi &tm; or newer fully supported devices. + * For windows only. + * + * On Windows platforms the device driver can run in either WDDM or WDM (TCC) mode. If a display is attached + * to the device it must run in WDDM mode. TCC mode is preferred if a display is not attached. + * + * See \ref nvmlDriverModel_t for details on available driver models. + * + * @param device The identifier of the target device + * @param current Reference in which to return the current driver model + * @param pending Reference in which to return the pending driver model + * + * @return + * - \ref NVML_SUCCESS if either \a current and/or \a pending have been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or both \a current and \a pending are NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the platform is not windows + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceSetDriverModel() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDriverModel(nvmlDevice_t device, nvmlDriverModel_t *current, nvmlDriverModel_t *pending); + +/** + * Get VBIOS version of the device. + * + * For all products. + * + * The VBIOS version may change from time to time. It will not exceed 32 characters in length + * (including the NULL terminator). See \ref nvmlConstants::NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE. + * + * @param device The identifier of the target device + * @param version Reference to which to return the VBIOS version + * @param length The maximum allowed length of the string returned in \a version + * + * @return + * - \ref NVML_SUCCESS if \a version has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a version is NULL + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetVbiosVersion(nvmlDevice_t device, char *version, unsigned int length); + +/** + * Get Bridge Chip Information for all the bridge chips on the board. + * + * For all fully supported products. + * Only applicable to multi-GPU products. + * + * @param device The identifier of the target device + * @param bridgeHierarchy Reference to the returned bridge chip Hierarchy + * + * @return + * - \ref NVML_SUCCESS if bridge chip exists + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a bridgeInfo is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if bridge chip not supported on the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetBridgeChipInfo(nvmlDevice_t device, nvmlBridgeChipHierarchy_t *bridgeHierarchy); + +/** + * Get information about processes with a compute context on a device + * + * For Fermi &tm; or newer fully supported devices. + * + * This function returns information only about compute running processes (e.g. CUDA application which have + * active context). Any graphics applications (e.g. using OpenGL, DirectX) won't be listed by this function. + * + * To query the current number of running compute processes, call this function with *infoCount = 0. The + * return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if none are running. For this call + * \a infos is allowed to be NULL. + * + * The usedGpuMemory field returned is all of the memory used by the application. + * + * Keep in mind that information returned by this call is dynamic and the number of elements might change in + * time. Allocate more space for \a infos table in case new compute processes are spawned. + * + * @note In MIG mode, if device handle is provided, the API returns aggregate information, only if + * the caller has appropriate privileges. Per-instance information can be queried by using + * specific MIG device handles. + * Querying per-instance information using MIG device handles is not supported if the device is in vGPU Host virtualization mode. + * + * @param device The device handle or MIG device handle + * @param infoCount Reference in which to provide the \a infos array size, and + * to return the number of returned elements + * @param infos Reference in which to return the process information + * + * @return + * - \ref NVML_SUCCESS if \a infoCount and \a infos have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a infoCount indicates that the \a infos array is too small + * \a infoCount will contain minimal amount of space necessary for + * the call to complete + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, either of \a infoCount or \a infos is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by \a device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see \ref nvmlSystemGetProcessName + */ +nvmlReturn_t DECLDIR nvmlDeviceGetComputeRunningProcesses_v3(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_t *infos); + +/** + * Get information about processes with a graphics context on a device + * + * For Kepler &tm; or newer fully supported devices. + * + * This function returns information only about graphics based processes + * (eg. applications using OpenGL, DirectX) + * + * To query the current number of running graphics processes, call this function with *infoCount = 0. The + * return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if none are running. For this call + * \a infos is allowed to be NULL. + * + * The usedGpuMemory field returned is all of the memory used by the application. + * + * Keep in mind that information returned by this call is dynamic and the number of elements might change in + * time. Allocate more space for \a infos table in case new graphics processes are spawned. + * + * @note In MIG mode, if device handle is provided, the API returns aggregate information, only if + * the caller has appropriate privileges. Per-instance information can be queried by using + * specific MIG device handles. + * Querying per-instance information using MIG device handles is not supported if the device is in vGPU Host virtualization mode. + * + * @param device The device handle or MIG device handle + * @param infoCount Reference in which to provide the \a infos array size, and + * to return the number of returned elements + * @param infos Reference in which to return the process information + * + * @return + * - \ref NVML_SUCCESS if \a infoCount and \a infos have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a infoCount indicates that the \a infos array is too small + * \a infoCount will contain minimal amount of space necessary for + * the call to complete + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, either of \a infoCount or \a infos is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by \a device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see \ref nvmlSystemGetProcessName + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGraphicsRunningProcesses_v3(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_t *infos); + +/** + * Get information about processes with a MPS compute context on a device + * + * For Volta &tm; or newer fully supported devices. + * + * This function returns information only about compute running processes (e.g. CUDA application which have + * active context) utilizing MPS. Any graphics applications (e.g. using OpenGL, DirectX) won't be listed by + * this function. + * + * To query the current number of running compute processes, call this function with *infoCount = 0. The + * return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if none are running. For this call + * \a infos is allowed to be NULL. + * + * The usedGpuMemory field returned is all of the memory used by the application. + * + * Keep in mind that information returned by this call is dynamic and the number of elements might change in + * time. Allocate more space for \a infos table in case new compute processes are spawned. + * + * @note In MIG mode, if device handle is provided, the API returns aggregate information, only if + * the caller has appropriate privileges. Per-instance information can be queried by using + * specific MIG device handles. + * Querying per-instance information using MIG device handles is not supported if the device is in vGPU Host virtualization mode. + * + * @param device The device handle or MIG device handle + * @param infoCount Reference in which to provide the \a infos array size, and + * to return the number of returned elements + * @param infos Reference in which to return the process information + * + * @return + * - \ref NVML_SUCCESS if \a infoCount and \a infos have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a infoCount indicates that the \a infos array is too small + * \a infoCount will contain minimal amount of space necessary for + * the call to complete + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, either of \a infoCount or \a infos is NULL + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by \a device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see \ref nvmlSystemGetProcessName + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMPSComputeRunningProcesses_v3(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_t *infos); + +/** + * Get information about running processes on a device for input context + * + * %HOPPER_OR_NEWER% + * + * This function returns information only about running processes (e.g. CUDA application which have + * active context). + * + * To determine the size of the @ref plist->procArray array to allocate, call the function with + * @ref plist->numProcArrayEntries set to zero and @ref plist->procArray set to NULL. The return + * code will be either NVML_ERROR_INSUFFICIENT_SIZE (if there are valid processes of type + * @ref plist->mode to report on, in which case the @ref plist->numProcArrayEntries field will + * indicate the required number of entries in the array) or NVML_SUCCESS (if no processes of type + * @ref plist->mode exist). + * + * The usedGpuMemory field returned is all of the memory used by the application. + * The usedGpuCcProtectedMemory field returned is all of the protected memory used by the application. + * + * Keep in mind that information returned by this call is dynamic and the number of elements might change in + * time. Allocate more space for \a plist->procArray table in case new processes are spawned. + * + * @note In MIG mode, if device handle is provided, the API returns aggregate information, only if + * the caller has appropriate privileges. Per-instance information can be queried by using + * specific MIG device handles. + * Querying per-instance information using MIG device handles is not supported if the device is in + * vGPU Host virtualization mode. + * Protected memory usage is currently not available in MIG mode and in windows. + * + * @param device The device handle or MIG device handle + * @param plist Reference in which to process detail list + * @param plist->version The api version + * @param plist->mode The process mode + * @param plist->procArray Reference in which to return the process information + * @param plist->numProcArrayEntries Proc array size of returned entries + * + * @return + * - \ref NVML_SUCCESS if \a plist->numprocArrayEntries and \a plist->procArray have been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a plist->numprocArrayEntries indicates that the \a plist->procArray is too small + * \a plist->numprocArrayEntries will contain minimal amount of space necessary for + * the call to complete + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a plist is NULL, \a plist->version is invalid, + * \a plist->mode is invalid, + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by \a device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetRunningProcessDetailList(nvmlDevice_t device, nvmlProcessDetailList_t *plist); + +/** + * Check if the GPU devices are on the same physical board. + * + * For all fully supported products. + * + * @param device1 The first GPU device + * @param device2 The second GPU device + * @param onSameBoard Reference in which to return the status. + * Non-zero indicates that the GPUs are on the same board. + * + * @return + * - \ref NVML_SUCCESS if \a onSameBoard has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a dev1 or \a dev2 are invalid or \a onSameBoard is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this check is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the either GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceOnSameBoard(nvmlDevice_t device1, nvmlDevice_t device2, int *onSameBoard); + +/** + * Retrieves the root/admin permissions on the target API. See \a nvmlRestrictedAPI_t for the list of supported APIs. + * If an API is restricted only root users can call that API. See \a nvmlDeviceSetAPIRestriction to change current permissions. + * + * For all fully supported products. + * + * @param device The identifier of the target device + * @param apiType Target API type for this operation + * @param isRestricted Reference in which to return the current restriction + * NVML_FEATURE_ENABLED indicates that the API is root-only + * NVML_FEATURE_DISABLED indicates that the API is accessible to all users + * + * @return + * - \ref NVML_SUCCESS if \a isRestricted has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a apiType incorrect or \a isRestricted is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device or the device does not support + * the feature that is being queried (E.G. Enabling/disabling Auto Boosted clocks is + * not supported by the device) + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlRestrictedAPI_t + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAPIRestriction(nvmlDevice_t device, nvmlRestrictedAPI_t apiType, nvmlEnableState_t *isRestricted); + +/** + * Gets recent samples for the GPU. + * + * For Kepler &tm; or newer fully supported devices. + * + * Based on type, this method can be used to fetch the power, utilization or clock samples maintained in the buffer by + * the driver. + * + * Power, Utilization and Clock samples are returned as type "unsigned int" for the union nvmlValue_t. + * + * To get the size of samples that user needs to allocate, the method is invoked with samples set to NULL. + * The returned samplesCount will provide the number of samples that can be queried. The user needs to + * allocate the buffer with size as samplesCount * sizeof(nvmlSample_t). + * + * lastSeenTimeStamp represents CPU timestamp in microseconds. Set it to 0 to fetch all the samples maintained by the + * underlying buffer. Set lastSeenTimeStamp to one of the timeStamps retrieved from the date of the previous query + * to get more recent samples. + * + * This method fetches the number of entries which can be accommodated in the provided samples array, and the + * reference samplesCount is updated to indicate how many samples were actually retrieved. The advantage of using this + * method for samples in contrast to polling via existing methods is to get get higher frequency data at lower polling cost. + * + * @note On MIG-enabled GPUs, querying the following sample types, NVML_GPU_UTILIZATION_SAMPLES, NVML_MEMORY_UTILIZATION_SAMPLES + * NVML_ENC_UTILIZATION_SAMPLES and NVML_DEC_UTILIZATION_SAMPLES, is not currently supported. + * + * @param device The identifier for the target device + * @param type Type of sampling event + * @param lastSeenTimeStamp Return only samples with timestamp greater than lastSeenTimeStamp. + * @param sampleValType Output parameter to represent the type of sample value as described in nvmlSampleVal_t + * @param sampleCount Reference to provide the number of elements which can be queried in samples array + * @param samples Reference in which samples are returned + + * @return + * - \ref NVML_SUCCESS if samples are successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a samplesCount is NULL or + * reference to \a sampleCount is 0 for non null \a samples + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_NOT_FOUND if sample entries are not found + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetSamples(nvmlDevice_t device, nvmlSamplingType_t type, unsigned long long lastSeenTimeStamp, + nvmlValueType_t *sampleValType, unsigned int *sampleCount, nvmlSample_t *samples); + +/** + * Gets Total, Available and Used size of BAR1 memory. + * + * BAR1 is used to map the FB (device memory) so that it can be directly accessed by the CPU or by 3rd party + * devices (peer-to-peer on the PCIE bus). + * + * @note In MIG mode, if device handle is provided, the API returns aggregate + * information, only if the caller has appropriate privileges. Per-instance + * information can be queried by using specific MIG device handles. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param bar1Memory Reference in which BAR1 memory + * information is returned. + * + * @return + * - \ref NVML_SUCCESS if BAR1 memory is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a bar1Memory is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetBAR1MemoryInfo(nvmlDevice_t device, nvmlBAR1Memory_t *bar1Memory); + +/** + * Gets the duration of time during which the device was throttled (lower than requested clocks) due to power + * or thermal constraints. + * + * The method is important to users who are tying to understand if their GPUs throttle at any point during their applications. The + * difference in violation times at two different reference times gives the indication of GPU throttling event. + * + * Violation for thermal capping is not supported at this time. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param perfPolicyType Represents Performance policy which can trigger GPU throttling + * @param violTime Reference to which violation time related information is returned + * + * + * @return + * - \ref NVML_SUCCESS if violation time is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a perfPolicyType is invalid, or \a violTime is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetViolationStatus(nvmlDevice_t device, nvmlPerfPolicyType_t perfPolicyType, nvmlViolationTime_t *violTime); + +/** + * Gets the device's interrupt number + * + * @param device The identifier of the target device + * @param irqNum The interrupt number associated with the specified device + * + * @return + * - \ref NVML_SUCCESS if irq number is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a irqNum is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetIrqNum(nvmlDevice_t device, unsigned int *irqNum); + +/** + * Gets the device's core count + * + * @param device The identifier of the target device + * @param numCores The number of cores for the specified device + * + * @return + * - \ref NVML_SUCCESS if Gpu core count is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a numCores is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetNumGpuCores(nvmlDevice_t device, unsigned int *numCores); + +/** + * Gets the devices power source + * + * @param device The identifier of the target device + * @param powerSource The power source of the device + * + * @return + * - \ref NVML_SUCCESS if the current power source was successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a powerSource is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPowerSource(nvmlDevice_t device, nvmlPowerSource_t *powerSource); + +/** + * Gets the device's memory bus width + * + * @param device The identifier of the target device + * @param busWidth The devices's memory bus width + * + * @return + * - \ref NVML_SUCCESS if the memory bus width is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a busWidth is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMemoryBusWidth(nvmlDevice_t device, unsigned int *busWidth); + +/** + * Gets the device's PCIE Max Link speed in MBPS + * + * @param device The identifier of the target device + * @param maxSpeed The devices's PCIE Max Link speed in MBPS + * + * @return + * - \ref NVML_SUCCESS if Pcie Max Link Speed is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a maxSpeed is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPcieLinkMaxSpeed(nvmlDevice_t device, unsigned int *maxSpeed); + +/** + * Gets the device's PCIe Link speed in Mbps + * + * @param device The identifier of the target device + * @param pcieSpeed The devices's PCIe Max Link speed in Mbps + * + * @return + * - \ref NVML_SUCCESS if \a pcieSpeed has been retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pcieSpeed is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support PCIe speed getting + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPcieSpeed(nvmlDevice_t device, unsigned int *pcieSpeed); + +/** + * Gets the device's Adaptive Clock status + * + * @param device The identifier of the target device + * @param adaptiveClockStatus The current adaptive clocking status, either + * @ref NVML_ADAPTIVE_CLOCKING_INFO_STATUS_DISABLED + * or @ref NVML_ADAPTIVE_CLOCKING_INFO_STATUS_ENABLED + * + * @return + * - \ref NVML_SUCCESS if the current adaptive clocking status is successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a adaptiveClockStatus is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAdaptiveClockInfoStatus(nvmlDevice_t device, unsigned int *adaptiveClockStatus); + +/** + * Get the type of the GPU Bus (PCIe, PCI, ...) + * + * @param device The identifier of the target device + * @param type The PCI Bus type + * + * return + * - \ref NVML_SUCCESS if the bus \a type is successfully retreived + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \device is invalid or \type is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetBusType(nvmlDevice_t device, nvmlBusType_t *type); + +/** + * Get fabric information associated with the device. + * + * %HOPPER_OR_NEWER% + * + * On Hopper + NVSwitch systems, GPU is registered with the NVIDIA Fabric Manager + * Upon successful registration, the GPU is added to the NVLink fabric to enable + * peer-to-peer communication. + * This API reports the current state of the GPU in the NVLink fabric + * along with other useful information. + * + * @param device The identifier of the target device + * @param gpuFabricInfo Information about GPU fabric state + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't support gpu fabric + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuFabricInfo(nvmlDevice_t device, nvmlGpuFabricInfo_t *gpuFabricInfo); + +/** + * Get Conf Computing System capabilities. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux, Windows TCC. + * + * @param capabilities System CC capabilities + * + * @return + * - \ref NVML_SUCCESS if \a capabilities were successfully queried + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a capabilities is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + */ +nvmlReturn_t DECLDIR nvmlSystemGetConfComputeCapabilities(nvmlConfComputeSystemCaps_t *capabilities); + +/** + * Get Conf Computing System State. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux, Windows TCC. + * + * @param state System CC State + * + * @return + * - \ref NVML_SUCCESS if \a state were successfully queried + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a state is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + */ +nvmlReturn_t DECLDIR nvmlSystemGetConfComputeState(nvmlConfComputeSystemState_t *state); + +/** + * Get Conf Computing Protected and Unprotected Memory Sizes. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux, Windows TCC. + * + * @param device Device handle + * @param memInfo Protected/Unprotected Memory sizes + * + * @return + * - \ref NVML_SUCCESS if \a memInfo were successfully queried + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a memInfo or \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + */ +nvmlReturn_t DECLDIR nvmlDeviceGetConfComputeMemSizeInfo(nvmlDevice_t device, nvmlConfComputeMemSizeInfo_t *memInfo); + +/** + * Get Conf Computing GPUs ready state. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux, Windows TCC. + * + * @param isAcceptingWork Returns GPU current work accepting state, + * NVML_CC_ACCEPTING_CLIENT_REQUESTS_TRUE or + * NVML_CC_ACCEPTING_CLIENT_REQUESTS_FALSE + * + * return + * - \ref NVML_SUCCESS if \a current GPUs ready state were successfully queried + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a isAcceptingWork is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + */ +nvmlReturn_t DECLDIR nvmlSystemGetConfComputeGpusReadyState(unsigned int *isAcceptingWork); + +/** + * Get Conf Computing protected memory usage. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux, Windows TCC. + * + * @param device The identifier of the target device + * @param memory Reference in which to return the memory information + * + * @return + * - \ref NVML_SUCCESS if \a memory has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a memory is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetConfComputeProtectedMemoryUsage(nvmlDevice_t device, nvmlMemory_t *memory); + +/** + * Get Conf Computing Gpu certificate details. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux, Windows TCC. + * + * @param device The identifier of the target device + * @param gpuCert Reference in which to return the gpu certificate information + * + * @return + * - \ref NVML_SUCCESS if \a gpu certificate info has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a memory is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetConfComputeGpuCertificate(nvmlDevice_t device, + nvmlConfComputeGpuCertificate_t *gpuCert); + +/** + * Get Conf Computing Gpu attestation report. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux, Windows TCC. + * + * @param device The identifier of the target device + * @param gpuAtstReport Reference in which to return the gpu attestation report + * + * @return + * - \ref NVML_SUCCESS if \a gpu attestation report has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a memory is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetConfComputeGpuAttestationReport(nvmlDevice_t device, + nvmlConfComputeGpuAttestationReport_t *gpuAtstReport); + +/** + * Retrieve GSP firmware version. + * + * The caller passes in buffer via \a version and corresponding GSP firmware numbered version + * is returned with the same parameter in string format. + * + * @param device Device handle + * @param version The retrieved GSP firmware version + * + * @return + * - \ref NVML_SUCCESS if GSP firmware version is sucessfully retrieved + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or GSP \a version pointer is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if GSP firmware is not enabled for GPU + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGspFirmwareVersion(nvmlDevice_t device, char *version); + +/** + * Retrieve GSP firmware mode. + * + * The caller passes in integer pointers. GSP firmware enablement and default mode information is returned with + * corresponding parameters. The return value in \a isEnabled and \a defaultMode should be treated as boolean. + * + * @param device Device handle + * @param isEnabled Pointer to specify if GSP firmware is enabled + * @param defaultMode Pointer to specify if GSP firmware is supported by default on \a device + * + * @return + * - \ref NVML_SUCCESS if GSP firmware mode is sucessfully retrieved + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or any of \a isEnabled or \a defaultMode is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGspFirmwareMode(nvmlDevice_t device, unsigned int *isEnabled, unsigned int *defaultMode); + +/** + * @} + */ + +/** @addtogroup nvmlAccountingStats + * @{ + */ + +/** + * Queries the state of per process accounting mode. + * + * For Kepler &tm; or newer fully supported devices. + * + * See \ref nvmlDeviceGetAccountingStats for more details. + * See \ref nvmlDeviceSetAccountingMode + * + * @param device The identifier of the target device + * @param mode Reference in which to return the current accounting mode + * + * @return + * - \ref NVML_SUCCESS if the mode has been successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode are NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAccountingMode(nvmlDevice_t device, nvmlEnableState_t *mode); + +/** + * Queries process's accounting stats. + * + * For Kepler &tm; or newer fully supported devices. + * + * Accounting stats capture GPU utilization and other statistics across the lifetime of a process. + * Accounting stats can be queried during life time of the process and after its termination. + * The time field in \ref nvmlAccountingStats_t is reported as 0 during the lifetime of the process and + * updated to actual running time after its termination. + * Accounting stats are kept in a circular buffer, newly created processes overwrite information about old + * processes. + * + * See \ref nvmlAccountingStats_t for description of each returned metric. + * List of processes that can be queried can be retrieved from \ref nvmlDeviceGetAccountingPids. + * + * @note Accounting Mode needs to be on. See \ref nvmlDeviceGetAccountingMode. + * @note Only compute and graphics applications stats can be queried. Monitoring applications stats can't be + * queried since they don't contribute to GPU utilization. + * @note In case of pid collision stats of only the latest process (that terminated last) will be reported + * + * @warning On Kepler devices per process statistics are accurate only if there's one process running on a GPU. + * + * @param device The identifier of the target device + * @param pid Process Id of the target process to query stats for + * @param stats Reference in which to return the process's accounting stats + * + * @return + * - \ref NVML_SUCCESS if stats have been successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a stats are NULL + * - \ref NVML_ERROR_NOT_FOUND if process stats were not found + * - \ref NVML_ERROR_NOT_SUPPORTED if \a device doesn't support this feature or accounting mode is disabled + * or on vGPU host. + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetAccountingBufferSize + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAccountingStats(nvmlDevice_t device, unsigned int pid, nvmlAccountingStats_t *stats); + +/** + * Queries list of processes that can be queried for accounting stats. The list of processes returned + * can be in running or terminated state. + * + * For Kepler &tm; or newer fully supported devices. + * + * To just query the number of processes ready to be queried, call this function with *count = 0 and + * pids=NULL. The return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if list is empty. + * + * For more details see \ref nvmlDeviceGetAccountingStats. + * + * @note In case of PID collision some processes might not be accessible before the circular buffer is full. + * + * @param device The identifier of the target device + * @param count Reference in which to provide the \a pids array size, and + * to return the number of elements ready to be queried + * @param pids Reference in which to return list of process ids + * + * @return + * - \ref NVML_SUCCESS if pids were successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a count is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if \a device doesn't support this feature or accounting mode is disabled + * or on vGPU host. + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a count is too small (\a count is set to + * expected value) + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetAccountingBufferSize + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAccountingPids(nvmlDevice_t device, unsigned int *count, unsigned int *pids); + +/** + * Returns the number of processes that the circular buffer with accounting pids can hold. + * + * For Kepler &tm; or newer fully supported devices. + * + * This is the maximum number of processes that accounting information will be stored for before information + * about oldest processes will get overwritten by information about new processes. + * + * @param device The identifier of the target device + * @param bufferSize Reference in which to provide the size (in number of elements) + * of the circular buffer for accounting stats. + * + * @return + * - \ref NVML_SUCCESS if buffer size was successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a bufferSize is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature or accounting mode is disabled + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetAccountingStats + * @see nvmlDeviceGetAccountingPids + */ +nvmlReturn_t DECLDIR nvmlDeviceGetAccountingBufferSize(nvmlDevice_t device, unsigned int *bufferSize); + +/** @} */ + +/** @addtogroup nvmlDeviceQueries + * @{ + */ + +/** + * Returns the list of retired pages by source, including pages that are pending retirement + * The address information provided from this API is the hardware address of the page that was retired. Note + * that this does not match the virtual address used in CUDA, but will match the address information in XID 63 + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param cause Filter page addresses by cause of retirement + * @param pageCount Reference in which to provide the \a addresses buffer size, and + * to return the number of retired pages that match \a cause + * Set to 0 to query the size without allocating an \a addresses buffer + * @param addresses Buffer to write the page addresses into + * + * @return + * - \ref NVML_SUCCESS if \a pageCount was populated and \a addresses was filled + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a pageCount indicates the buffer is not large enough to store all the + * matching page addresses. \a pageCount is set to the needed size. + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a pageCount is NULL, \a cause is invalid, or + * \a addresses is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetRetiredPages(nvmlDevice_t device, nvmlPageRetirementCause_t cause, + unsigned int *pageCount, unsigned long long *addresses); + +/** + * Returns the list of retired pages by source, including pages that are pending retirement + * The address information provided from this API is the hardware address of the page that was retired. Note + * that this does not match the virtual address used in CUDA, but will match the address information in XID 63 + * + * \note nvmlDeviceGetRetiredPages_v2 adds an additional timestamps parameter to return the time of each page's + * retirement. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param cause Filter page addresses by cause of retirement + * @param pageCount Reference in which to provide the \a addresses buffer size, and + * to return the number of retired pages that match \a cause + * Set to 0 to query the size without allocating an \a addresses buffer + * @param addresses Buffer to write the page addresses into + * @param timestamps Buffer to write the timestamps of page retirement, additional for _v2 + * + * @return + * - \ref NVML_SUCCESS if \a pageCount was populated and \a addresses was filled + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a pageCount indicates the buffer is not large enough to store all the + * matching page addresses. \a pageCount is set to the needed size. + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a pageCount is NULL, \a cause is invalid, or + * \a addresses is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetRetiredPages_v2(nvmlDevice_t device, nvmlPageRetirementCause_t cause, + unsigned int *pageCount, unsigned long long *addresses, unsigned long long *timestamps); + +/** + * Check if any pages are pending retirement and need a reboot to fully retire. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param isPending Reference in which to return the pending status + * + * @return + * - \ref NVML_SUCCESS if \a isPending was populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a isPending is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetRetiredPagesPendingStatus(nvmlDevice_t device, nvmlEnableState_t *isPending); + +/** + * Get number of remapped rows. The number of rows reported will be based on + * the cause of the remapping. isPending indicates whether or not there are + * pending remappings. A reset will be required to actually remap the row. + * failureOccurred will be set if a row remapping ever failed in the past. A + * pending remapping won't affect future work on the GPU since + * error-containment and dynamic page blacklisting will take care of that. + * + * @note On MIG-enabled GPUs with active instances, querying the number of + * remapped rows is not supported + * + * For Ampere &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param corrRows Reference for number of rows remapped due to correctable errors + * @param uncRows Reference for number of rows remapped due to uncorrectable errors + * @param isPending Reference for whether or not remappings are pending + * @param failureOccurred Reference that is set when a remapping has failed in the past + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a corrRows, \a uncRows, \a isPending or \a failureOccurred is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If MIG is enabled or if the device doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN Unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetRemappedRows(nvmlDevice_t device, unsigned int *corrRows, unsigned int *uncRows, + unsigned int *isPending, unsigned int *failureOccurred); + +/** + * Get the row remapper histogram. Returns the remap availability for each bank + * on the GPU. + * + * @param device Device handle + * @param values Histogram values + * + * @return + * - \ref NVML_SUCCESS On success + * - \ref NVML_ERROR_UNKNOWN On any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetRowRemapperHistogram(nvmlDevice_t device, nvmlRowRemapperHistogramValues_t *values); + +/** + * Get architecture for device + * + * @param device The identifier of the target device + * @param arch Reference where architecture is returned, if call successful. + * Set to NVML_DEVICE_ARCH_* upon success + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device or \a arch (output refererence) are invalid + */ +nvmlReturn_t DECLDIR nvmlDeviceGetArchitecture(nvmlDevice_t device, nvmlDeviceArchitecture_t *arch); + +/** + * Retrieves the frequency monitor fault status for the device. + * + * For Ampere &tm; or newer fully supported devices. + * Requires root user. + * + * See \ref nvmlClkMonStatus_t for details on decoding the status output. + * + * @param device The identifier of the target device + * @param status Reference in which to return the clkmon fault status + * + * @return + * - \ref NVML_SUCCESS if \a status has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a status is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetClkMonStatus() + */ +nvmlReturn_t DECLDIR nvmlDeviceGetClkMonStatus(nvmlDevice_t device, nvmlClkMonStatus_t *status); + +/** + * Retrieves the current utilization and process ID + * + * For Maxwell &tm; or newer fully supported devices. + * + * Reads recent utilization of GPU SM (3D/Compute), framebuffer, video encoder, and video decoder for processes running. + * Utilization values are returned as an array of utilization sample structures in the caller-supplied buffer pointed at + * by \a utilization. One utilization sample structure is returned per process running, that had some non-zero utilization + * during the last sample period. It includes the CPU timestamp at which the samples were recorded. Individual utilization values + * are returned as "unsigned int" values. If no valid sample entries are found since the lastSeenTimeStamp, NVML_ERROR_NOT_FOUND + * is returned. + * + * To read utilization values, first determine the size of buffer required to hold the samples by invoking the function with + * \a utilization set to NULL. The caller should allocate a buffer of size + * processSamplesCount * sizeof(nvmlProcessUtilizationSample_t). Invoke the function again with the allocated buffer passed + * in \a utilization, and \a processSamplesCount set to the number of entries the buffer is sized for. + * + * On successful return, the function updates \a processSamplesCount with the number of process utilization sample + * structures that were actually written. This may differ from a previously read value as instances are created or + * destroyed. + * + * lastSeenTimeStamp represents the CPU timestamp in microseconds at which utilization samples were last read. Set it to 0 + * to read utilization based on all the samples maintained by the driver's internal sample buffer. Set lastSeenTimeStamp + * to a timeStamp retrieved from a previous query to read utilization since the previous query. + * + * @note On MIG-enabled GPUs, querying process utilization is not currently supported. + * + * @param device The identifier of the target device + * @param utilization Pointer to caller-supplied buffer in which guest process utilization samples are returned + * @param processSamplesCount Pointer to caller-supplied array size, and returns number of processes running + * @param lastSeenTimeStamp Return only samples with timestamp greater than lastSeenTimeStamp. + + * @return + * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_NOT_FOUND if sample entries are not found + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetProcessUtilization(nvmlDevice_t device, nvmlProcessUtilizationSample_t *utilization, + unsigned int *processSamplesCount, unsigned long long lastSeenTimeStamp); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlUnitCommands Unit Commands + * This chapter describes NVML operations that change the state of the unit. For S-class products. + * Each of these requires root/admin access. Non-admin users will see an NVML_ERROR_NO_PERMISSION + * error code when invoking any of these methods. + * @{ + */ +/***************************************************************************************************/ + +/** + * Set the LED state for the unit. The LED can be either green (0) or amber (1). + * + * For S-class products. + * Requires root/admin permissions. + * + * This operation takes effect immediately. + * + * + * Current S-Class products don't provide unique LEDs for each unit. As such, both front + * and back LEDs will be toggled in unison regardless of which unit is specified with this command. + * + * See \ref nvmlLedColor_t for available colors. + * + * @param unit The identifier of the target unit + * @param color The target LED color + * + * @return + * - \ref NVML_SUCCESS if the LED color has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit or \a color is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this is not an S-class product + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlUnitGetLedState() + */ +nvmlReturn_t DECLDIR nvmlUnitSetLedState(nvmlUnit_t unit, nvmlLedColor_t color); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlDeviceCommands Device Commands + * This chapter describes NVML operations that change the state of the device. + * Each of these requires root/admin access. Non-admin users will see an NVML_ERROR_NO_PERMISSION + * error code when invoking any of these methods. + * @{ + */ +/***************************************************************************************************/ + +/** + * Set the persistence mode for the device. + * + * For all products. + * For Linux only. + * Requires root/admin permissions. + * + * The persistence mode determines whether the GPU driver software is torn down after the last client + * exits. + * + * This operation takes effect immediately. It is not persistent across reboots. After each reboot the + * persistence mode is reset to "Disabled". + * + * See \ref nvmlEnableState_t for available modes. + * + * After calling this API with mode set to NVML_FEATURE_DISABLED on a device that has its own NUMA + * memory, the given device handle will no longer be valid, and to continue to interact with this + * device, a new handle should be obtained from one of the nvmlDeviceGetHandleBy*() APIs. This + * limitation is currently only applicable to devices that have a coherent NVLink connection to + * system memory. + * + * @param device The identifier of the target device + * @param mode The target persistence mode + * + * @return + * - \ref NVML_SUCCESS if the persistence mode was set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetPersistenceMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceSetPersistenceMode(nvmlDevice_t device, nvmlEnableState_t mode); + +/** + * Set the compute mode for the device. + * + * For all products. + * Requires root/admin permissions. + * + * The compute mode determines whether a GPU can be used for compute operations and whether it can + * be shared across contexts. + * + * This operation takes effect immediately. Under Linux it is not persistent across reboots and + * always resets to "Default". Under windows it is persistent. + * + * Under windows compute mode may only be set to DEFAULT when running in WDDM + * + * @note On MIG-enabled GPUs, compute mode would be set to DEFAULT and changing it is not supported. + * + * See \ref nvmlComputeMode_t for details on available compute modes. + * + * @param device The identifier of the target device + * @param mode The target compute mode + * + * @return + * - \ref NVML_SUCCESS if the compute mode was set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetComputeMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceSetComputeMode(nvmlDevice_t device, nvmlComputeMode_t mode); + +/** + * Set the ECC mode for the device. + * + * For Kepler &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher. + * Requires root/admin permissions. + * + * The ECC mode determines whether the GPU enables its ECC support. + * + * This operation takes effect after the next reboot. + * + * See \ref nvmlEnableState_t for details on available modes. + * + * @param device The identifier of the target device + * @param ecc The target ECC mode + * + * @return + * - \ref NVML_SUCCESS if the ECC mode was set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a ecc is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetEccMode() + */ +nvmlReturn_t DECLDIR nvmlDeviceSetEccMode(nvmlDevice_t device, nvmlEnableState_t ecc); + +/** + * Clear the ECC error and other memory error counts for the device. + * + * For Kepler &tm; or newer fully supported devices. + * Only applicable to devices with ECC. + * Requires \a NVML_INFOROM_ECC version 2.0 or higher to clear aggregate location-based ECC counts. + * Requires \a NVML_INFOROM_ECC version 1.0 or higher to clear all other ECC counts. + * Requires root/admin permissions. + * Requires ECC Mode to be enabled. + * + * Sets all of the specified ECC counters to 0, including both detailed and total counts. + * + * This operation takes effect immediately. + * + * See \ref nvmlMemoryErrorType_t for details on available counter types. + * + * @param device The identifier of the target device + * @param counterType Flag that indicates which type of errors should be cleared. + * + * @return + * - \ref NVML_SUCCESS if the error counts were cleared + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a counterType is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see + * - nvmlDeviceGetDetailedEccErrors() + * - nvmlDeviceGetTotalEccErrors() + */ +nvmlReturn_t DECLDIR nvmlDeviceClearEccErrorCounts(nvmlDevice_t device, nvmlEccCounterType_t counterType); + +/** + * Set the driver model for the device. + * + * For Fermi &tm; or newer fully supported devices. + * For windows only. + * Requires root/admin permissions. + * + * On Windows platforms the device driver can run in either WDDM or WDM (TCC) mode. If a display is attached + * to the device it must run in WDDM mode. + * + * It is possible to force the change to WDM (TCC) while the display is still attached with a force flag (nvmlFlagForce). + * This should only be done if the host is subsequently powered down and the display is detached from the device + * before the next reboot. + * + * This operation takes effect after the next reboot. + * + * Windows driver model may only be set to WDDM when running in DEFAULT compute mode. + * + * Change driver model to WDDM is not supported when GPU doesn't support graphics acceleration or + * will not support it after reboot. See \ref nvmlDeviceSetGpuOperationMode. + * + * See \ref nvmlDriverModel_t for details on available driver models. + * See \ref nvmlFlagDefault and \ref nvmlFlagForce + * + * @param device The identifier of the target device + * @param driverModel The target driver model + * @param flags Flags that change the default behavior + * + * @return + * - \ref NVML_SUCCESS if the driver model has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a driverModel is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the platform is not windows or the device does not support this feature + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlDeviceGetDriverModel() + */ +nvmlReturn_t DECLDIR nvmlDeviceSetDriverModel(nvmlDevice_t device, nvmlDriverModel_t driverModel, unsigned int flags); + +typedef enum nvmlClockLimitId_enum { + NVML_CLOCK_LIMIT_ID_RANGE_START = 0xffffff00, + NVML_CLOCK_LIMIT_ID_TDP, + NVML_CLOCK_LIMIT_ID_UNLIMITED +} nvmlClockLimitId_t; + +/** + * Set clocks that device will lock to. + * + * Sets the clocks that the device will be running at to the value in the range of minGpuClockMHz to maxGpuClockMHz. + * Setting this will supersede application clock values and take effect regardless if a cuda app is running. + * See /ref nvmlDeviceSetApplicationsClocks + * + * Can be used as a setting to request constant performance. + * + * This can be called with a pair of integer clock frequencies in MHz, or a pair of /ref nvmlClockLimitId_t values. + * See the table below for valid combinations of these values. + * + * minGpuClock | maxGpuClock | Effect + * ------------+-------------+-------------------------------------------------- + * tdp | tdp | Lock clock to TDP + * unlimited | tdp | Upper bound is TDP but clock may drift below this + * tdp | unlimited | Lower bound is TDP but clock may boost above this + * unlimited | unlimited | Unlocked (== nvmlDeviceResetGpuLockedClocks) + * + * If one arg takes one of these values, the other must be one of these values as + * well. Mixed numeric and symbolic calls return NVML_ERROR_INVALID_ARGUMENT. + * + * Requires root/admin permissions. + * + * After system reboot or driver reload applications clocks go back to their default value. + * See \ref nvmlDeviceResetGpuLockedClocks. + * + * For Volta &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param minGpuClockMHz Requested minimum gpu clock in MHz + * @param maxGpuClockMHz Requested maximum gpu clock in MHz + * + * @return + * - \ref NVML_SUCCESS if new settings were successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a minGpuClockMHz and \a maxGpuClockMHz + * is not a valid clock combination + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetGpuLockedClocks(nvmlDevice_t device, unsigned int minGpuClockMHz, unsigned int maxGpuClockMHz); + +/** + * Resets the gpu clock to the default value + * + * This is the gpu clock that will be used after system reboot or driver reload. + * Default values are idle clocks, but the current values can be changed using \ref nvmlDeviceSetApplicationsClocks. + * + * @see nvmlDeviceSetGpuLockedClocks + * + * For Volta &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * + * @return + * - \ref NVML_SUCCESS if new settings were successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceResetGpuLockedClocks(nvmlDevice_t device); + +/** + * Set memory clocks that device will lock to. + * + * Sets the device's memory clocks to the value in the range of minMemClockMHz to maxMemClockMHz. + * Setting this will supersede application clock values and take effect regardless of whether a cuda app is running. + * See /ref nvmlDeviceSetApplicationsClocks + * + * Can be used as a setting to request constant performance. + * + * Requires root/admin permissions. + * + * After system reboot or driver reload applications clocks go back to their default value. + * See \ref nvmlDeviceResetMemoryLockedClocks. + * + * For Ampere &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param minMemClockMHz Requested minimum memory clock in MHz + * @param maxMemClockMHz Requested maximum memory clock in MHz + * + * @return + * - \ref NVML_SUCCESS if new settings were successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a minGpuClockMHz and \a maxGpuClockMHz + * is not a valid clock combination + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetMemoryLockedClocks(nvmlDevice_t device, unsigned int minMemClockMHz, unsigned int maxMemClockMHz); + +/** + * Resets the memory clock to the default value + * + * This is the memory clock that will be used after system reboot or driver reload. + * Default values are idle clocks, but the current values can be changed using \ref nvmlDeviceSetApplicationsClocks. + * + * @see nvmlDeviceSetMemoryLockedClocks + * + * For Ampere &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * + * @return + * - \ref NVML_SUCCESS if new settings were successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceResetMemoryLockedClocks(nvmlDevice_t device); + +/** + * Set clocks that applications will lock to. + * + * Sets the clocks that compute and graphics applications will be running at. + * e.g. CUDA driver requests these clocks during context creation which means this property + * defines clocks at which CUDA applications will be running unless some overspec event + * occurs (e.g. over power, over thermal or external HW brake). + * + * Can be used as a setting to request constant performance. + * + * On Pascal and newer hardware, this will automatically disable automatic boosting of clocks. + * + * On K80 and newer Kepler and Maxwell GPUs, users desiring fixed performance should also call + * \ref nvmlDeviceSetAutoBoostedClocksEnabled to prevent clocks from automatically boosting + * above the clock value being set. + * + * For Kepler &tm; or newer non-GeForce fully supported devices and Maxwell or newer GeForce devices. + * Requires root/admin permissions. + * + * See \ref nvmlDeviceGetSupportedMemoryClocks and \ref nvmlDeviceGetSupportedGraphicsClocks + * for details on how to list available clocks combinations. + * + * After system reboot or driver reload applications clocks go back to their default value. + * See \ref nvmlDeviceResetApplicationsClocks. + * + * @param device The identifier of the target device + * @param memClockMHz Requested memory clock in MHz + * @param graphicsClockMHz Requested graphics clock in MHz + * + * @return + * - \ref NVML_SUCCESS if new settings were successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a memClockMHz and \a graphicsClockMHz + * is not a valid clock combination + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetApplicationsClocks(nvmlDevice_t device, unsigned int memClockMHz, unsigned int graphicsClockMHz); + +/** + * Resets the application clock to the default value + * + * This is the applications clock that will be used after system reboot or driver reload. + * Default value is constant, but the current value an be changed using \ref nvmlDeviceSetApplicationsClocks. + * + * On Pascal and newer hardware, if clocks were previously locked with \ref nvmlDeviceSetApplicationsClocks, + * this call will unlock clocks. This returns clocks their default behavior ofautomatically boosting above + * base clocks as thermal limits allow. + * + * @see nvmlDeviceGetApplicationsClock + * @see nvmlDeviceSetApplicationsClocks + * + * For Fermi &tm; or newer non-GeForce fully supported devices and Maxwell or newer GeForce devices. + * + * @param device The identifier of the target device + * + * @return + * - \ref NVML_SUCCESS if new settings were successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceResetApplicationsClocks(nvmlDevice_t device); + /** * Try to set the current state of Auto Boosted clocks on a device. * @@ -2891,61 +6725,57 @@ nvmlReturn_t DECLDIR nvmlDeviceSetAutoBoostedClocksEnabled(nvmlDevice_t device, */ nvmlReturn_t DECLDIR nvmlDeviceSetDefaultAutoBoostedClocksEnabled(nvmlDevice_t device, nvmlEnableState_t enabled, unsigned int flags); - /** - * Retrieves the intended operating speed of the device's fan. + * Sets the speed of the fan control policy to default. * - * Note: The reported speed is the intended fan speed. If the fan is physically blocked and unable to spin, the - * output will not match the actual fan speed. - * - * For all discrete products with dedicated fans. + * For all cuda-capable discrete products with fans * - * The fan speed is expressed as a percent of the maximum, i.e. full speed is 100%. + * @param device The identifier of the target device + * @param fan The index of the fan, starting at zero * - * @param device The identifier of the target device - * @param speed Reference in which to return the fan speed percentage - * - * @return - * - \ref NVML_SUCCESS if \a speed has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a speed is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have a fan - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * return + * NVML_SUCCESS if speed has been adjusted + * NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * NVML_ERROR_INVALID_ARGUMENT if device is invalid + * NVML_ERROR_NOT_SUPPORTED if the device does not support this + * (doesn't have fans) + * NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceGetFanSpeed(nvmlDevice_t device, unsigned int *speed); +nvmlReturn_t DECLDIR nvmlDeviceSetDefaultFanSpeed_v2(nvmlDevice_t device, unsigned int fan); /** - * Retrieves the current temperature readings for the device, in degrees C. - * - * For all products. + * Sets current fan control policy. * - * See \ref nvmlTemperatureSensors_t for details on available temperature sensors. + * For Maxwell &tm; or newer fully supported devices. * - * @param device The identifier of the target device - * @param sensorType Flag that indicates which sensor reading to retrieve - * @param temp Reference in which to return the temperature reading - * - * @return - * - \ref NVML_SUCCESS if \a temp has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a sensorType is invalid or \a temp is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not have the specified sensor - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * Requires privileged user. + * + * For all cuda-capable discrete products with fans + * + * device The identifier of the target \a device + * policy The fan control \a policy to set + * + * return + * NVML_SUCCESS if \a policy has been set + * NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a policy is null or the \a fan given doesn't reference + * a fan that exists. + * NVML_ERROR_NOT_SUPPORTED if the \a device is older than Maxwell + * NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceGetTemperature(nvmlDevice_t device, nvmlTemperatureSensors_t sensorType, unsigned int *temp); +nvmlReturn_t DECLDIR nvmlDeviceSetFanControlPolicy(nvmlDevice_t device, unsigned int fan, + nvmlFanControlPolicy_t policy); /** - * Retrieves the temperature threshold for the GPU with the specified threshold type in degrees C. + * Sets the temperature threshold for the GPU with the specified threshold type in degrees C. * - * For Kepler &tm; or newer fully supported devices. + * For Maxwell &tm; or newer fully supported devices. * * See \ref nvmlTemperatureThresholds_t for details on available temperature thresholds. * * @param device The identifier of the target device - * @param thresholdType The type of threshold value queried - * @param temp Reference in which to return the temperature reading + * @param thresholdType The type of threshold value to be set + * @param temp Reference which hold the value to be set * @return * - \ref NVML_SUCCESS if \a temp has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized @@ -2954,1369 +6784,11 @@ nvmlReturn_t DECLDIR nvmlDeviceGetTemperature(nvmlDevice_t device, nvmlTemperatu * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceGetTemperatureThreshold(nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, unsigned int *temp); - -/** - * Retrieves the current performance state for the device. - * - * For Fermi &tm; or newer fully supported devices. - * - * See \ref nvmlPstates_t for details on allowed performance states. - * - * @param device The identifier of the target device - * @param pState Reference in which to return the performance state reading - * - * @return - * - \ref NVML_SUCCESS if \a pState has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pState is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetPerformanceState(nvmlDevice_t device, nvmlPstates_t *pState); - -/** - * Retrieves current clocks throttling reasons. - * - * For all fully supported products. - * - * \note More than one bit can be enabled at the same time. Multiple reasons can be affecting clocks at once. - * - * @param device The identifier of the target device - * @param clocksThrottleReasons Reference in which to return bitmask of active clocks throttle - * reasons - * - * @return - * - \ref NVML_SUCCESS if \a clocksThrottleReasons has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a clocksThrottleReasons is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlClocksThrottleReasons - * @see nvmlDeviceGetSupportedClocksThrottleReasons - */ -nvmlReturn_t DECLDIR nvmlDeviceGetCurrentClocksThrottleReasons(nvmlDevice_t device, unsigned long long *clocksThrottleReasons); - -/** - * Retrieves bitmask of supported clocks throttle reasons that can be returned by - * \ref nvmlDeviceGetCurrentClocksThrottleReasons - * - * For all fully supported products. - * - * This method is not supported in virtual machines running virtual GPU (vGPU). - * - * @param device The identifier of the target device - * @param supportedClocksThrottleReasons Reference in which to return bitmask of supported - * clocks throttle reasons - * - * @return - * - \ref NVML_SUCCESS if \a supportedClocksThrottleReasons has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a supportedClocksThrottleReasons is NULL - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlClocksThrottleReasons - * @see nvmlDeviceGetCurrentClocksThrottleReasons - */ -nvmlReturn_t DECLDIR nvmlDeviceGetSupportedClocksThrottleReasons(nvmlDevice_t device, unsigned long long *supportedClocksThrottleReasons); - -/** - * Deprecated: Use \ref nvmlDeviceGetPerformanceState. This function exposes an incorrect generalization. - * - * Retrieve the current performance state for the device. - * - * For Fermi &tm; or newer fully supported devices. - * - * See \ref nvmlPstates_t for details on allowed performance states. - * - * @param device The identifier of the target device - * @param pState Reference in which to return the performance state reading - * - * @return - * - \ref NVML_SUCCESS if \a pState has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pState is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetPowerState(nvmlDevice_t device, nvmlPstates_t *pState); - -/** - * This API has been deprecated. - * - * Retrieves the power management mode associated with this device. - * - * For products from the Fermi family. - * - Requires \a NVML_INFOROM_POWER version 3.0 or higher. - * - * For from the Kepler or newer families. - * - Does not require \a NVML_INFOROM_POWER object. - * - * This flag indicates whether any power management algorithm is currently active on the device. An - * enabled state does not necessarily mean the device is being actively throttled -- only that - * that the driver will do so if the appropriate conditions are met. - * - * See \ref nvmlEnableState_t for details on allowed modes. - * - * @param device The identifier of the target device - * @param mode Reference in which to return the current power management mode - * - * @return - * - \ref NVML_SUCCESS if \a mode has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementMode(nvmlDevice_t device, nvmlEnableState_t *mode); - -/** - * Retrieves the power management limit associated with this device. - * - * For Fermi &tm; or newer fully supported devices. - * - * The power limit defines the upper boundary for the card's power draw. If - * the card's total power draw reaches this limit the power management algorithm kicks in. - * - * This reading is only available if power management mode is supported. - * See \ref nvmlDeviceGetPowerManagementMode. - * - * @param device The identifier of the target device - * @param limit Reference in which to return the power management limit in milliwatts - * - * @return - * - \ref NVML_SUCCESS if \a limit has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a limit is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementLimit(nvmlDevice_t device, unsigned int *limit); - -/** - * Retrieves information about possible values of power management limits on this device. - * - * For Kepler &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param minLimit Reference in which to return the minimum power management limit in milliwatts - * @param maxLimit Reference in which to return the maximum power management limit in milliwatts - * - * @return - * - \ref NVML_SUCCESS if \a minLimit and \a maxLimit have been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a minLimit or \a maxLimit is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceSetPowerManagementLimit - */ -nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementLimitConstraints(nvmlDevice_t device, unsigned int *minLimit, unsigned int *maxLimit); - -/** - * Retrieves default power management limit on this device, in milliwatts. - * Default power management limit is a power management limit that the device boots with. - * - * For Kepler &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param defaultLimit Reference in which to return the default power management limit in milliwatts - * - * @return - * - \ref NVML_SUCCESS if \a defaultLimit has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a defaultLimit is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetPowerManagementDefaultLimit(nvmlDevice_t device, unsigned int *defaultLimit); - -/** - * Retrieves power usage for this GPU in milliwatts and its associated circuitry (e.g. memory) - * - * For Fermi &tm; or newer fully supported devices. - * - * On Fermi and Kepler GPUs the reading is accurate to within +/- 5% of current power draw. - * - * It is only available if power management mode is supported. See \ref nvmlDeviceGetPowerManagementMode. - * - * @param device The identifier of the target device - * @param power Reference in which to return the power usage information - * - * @return - * - \ref NVML_SUCCESS if \a power has been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a power is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support power readings - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetPowerUsage(nvmlDevice_t device, unsigned int *power); - -/** - * Retrieves total energy consumption for this GPU in millijoules (mJ) since the driver was last reloaded - * - * For newer than Pascal &tm; fully supported devices. - * - * @param device The identifier of the target device - * @param energy Reference in which to return the energy consumption information - * - * @return - * - \ref NVML_SUCCESS if \a energy has been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a energy is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support energy readings - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetTotalEnergyConsumption(nvmlDevice_t device, unsigned long long *energy); - -/** - * Get the effective power limit that the driver enforces after taking into account all limiters - * - * Note: This can be different from the \ref nvmlDeviceGetPowerManagementLimit if other limits are set elsewhere - * This includes the out of band power limit interface - * - * For Kepler &tm; or newer fully supported devices. - * - * @param device The device to communicate with - * @param limit Reference in which to return the power management limit in milliwatts - * - * @return - * - \ref NVML_SUCCESS if \a limit has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a limit is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetEnforcedPowerLimit(nvmlDevice_t device, unsigned int *limit); - -/** - * Retrieves the current GOM and pending GOM (the one that GPU will switch to after reboot). - * - * For GK110 M-class and X-class Tesla &tm; products from the Kepler family. - * Modes \ref NVML_GOM_LOW_DP and \ref NVML_GOM_ALL_ON are supported on fully supported GeForce products. - * Not supported on Quadro ® and Tesla &tm; C-class products. - * - * @param device The identifier of the target device - * @param current Reference in which to return the current GOM - * @param pending Reference in which to return the pending GOM - * - * @return - * - \ref NVML_SUCCESS if \a mode has been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a current or \a pending is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlGpuOperationMode_t - * @see nvmlDeviceSetGpuOperationMode - */ -nvmlReturn_t DECLDIR nvmlDeviceGetGpuOperationMode(nvmlDevice_t device, nvmlGpuOperationMode_t *current, nvmlGpuOperationMode_t *pending); - -/** - * Retrieves the amount of used, free and total memory available on the device, in bytes. - * - * For all products. - * - * Enabling ECC reduces the amount of total available memory, due to the extra required parity bits. - * Under WDDM most device memory is allocated and managed on startup by Windows. - * - * Under Linux and Windows TCC, the reported amount of used memory is equal to the sum of memory allocated - * by all active channels on the device. - * - * See \ref nvmlMemory_t for details on available memory info. - * - * @param device The identifier of the target device - * @param memory Reference in which to return the memory information - * - * @return - * - \ref NVML_SUCCESS if \a memory has been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a memory is NULL - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetMemoryInfo(nvmlDevice_t device, nvmlMemory_t *memory); - -/** - * Retrieves the current compute mode for the device. - * - * For all products. - * - * See \ref nvmlComputeMode_t for details on allowed compute modes. - * - * @param device The identifier of the target device - * @param mode Reference in which to return the current compute mode - * - * @return - * - \ref NVML_SUCCESS if \a mode has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceSetComputeMode() - */ -nvmlReturn_t DECLDIR nvmlDeviceGetComputeMode(nvmlDevice_t device, nvmlComputeMode_t *mode); - -/** - * Retrieves the CUDA compute capability of the device. - * - * For all products. - * - * Returns the major and minor compute capability version numbers of the - * device. The major and minor versions are equivalent to the - * CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR and - * CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR attributes that would be - * returned by CUDA's cuDeviceGetAttribute(). - * - * @param device The identifier of the target device - * @param major Reference in which to return the major CUDA compute capability - * @param minor Reference in which to return the minor CUDA compute capability - * - * @return - * - \ref NVML_SUCCESS if \a major and \a minor have been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a major or \a minor are NULL - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetCudaComputeCapability(nvmlDevice_t device, int *major, int *minor); - -/** - * Retrieves the current and pending ECC modes for the device. - * - * For Fermi &tm; or newer fully supported devices. - * Only applicable to devices with ECC. - * Requires \a NVML_INFOROM_ECC version 1.0 or higher. - * - * Changing ECC modes requires a reboot. The "pending" ECC mode refers to the target mode following - * the next reboot. - * - * See \ref nvmlEnableState_t for details on allowed modes. - * - * @param device The identifier of the target device - * @param current Reference in which to return the current ECC mode - * @param pending Reference in which to return the pending ECC mode - * - * @return - * - \ref NVML_SUCCESS if \a current and \a pending have been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or either \a current or \a pending is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceSetEccMode() - */ -nvmlReturn_t DECLDIR nvmlDeviceGetEccMode(nvmlDevice_t device, nvmlEnableState_t *current, nvmlEnableState_t *pending); - -/** - * Retrieves the device boardId from 0-N. - * Devices with the same boardId indicate GPUs connected to the same PLX. Use in conjunction with - * \ref nvmlDeviceGetMultiGpuBoard() to decide if they are on the same board as well. - * The boardId returned is a unique ID for the current configuration. Uniqueness and ordering across - * reboots and system configurations is not guaranteed (i.e. if a Tesla K40c returns 0x100 and - * the two GPUs on a Tesla K10 in the same system returns 0x200 it is not guaranteed they will - * always return those values but they will always be different from each other). - * - * - * For Fermi &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param boardId Reference in which to return the device's board ID - * - * @return - * - \ref NVML_SUCCESS if \a boardId has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a boardId is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetBoardId(nvmlDevice_t device, unsigned int *boardId); - -/** - * Retrieves whether the device is on a Multi-GPU Board - * Devices that are on multi-GPU boards will set \a multiGpuBool to a non-zero value. - * - * For Fermi &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param multiGpuBool Reference in which to return a zero or non-zero value - * to indicate whether the device is on a multi GPU board - * - * @return - * - \ref NVML_SUCCESS if \a multiGpuBool has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a multiGpuBool is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetMultiGpuBoard(nvmlDevice_t device, unsigned int *multiGpuBool); - -/** - * Retrieves the total ECC error counts for the device. - * - * For Fermi &tm; or newer fully supported devices. - * Only applicable to devices with ECC. - * Requires \a NVML_INFOROM_ECC version 1.0 or higher. - * Requires ECC Mode to be enabled. - * - * The total error count is the sum of errors across each of the separate memory systems, i.e. the total set of - * errors across the entire device. - * - * See \ref nvmlMemoryErrorType_t for a description of available error types.\n - * See \ref nvmlEccCounterType_t for a description of available counter types. - * - * @param device The identifier of the target device - * @param errorType Flag that specifies the type of the errors. - * @param counterType Flag that specifies the counter-type of the errors. - * @param eccCounts Reference in which to return the specified ECC errors - * - * @return - * - \ref NVML_SUCCESS if \a eccCounts has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a errorType or \a counterType is invalid, or \a eccCounts is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceClearEccErrorCounts() - */ -nvmlReturn_t DECLDIR nvmlDeviceGetTotalEccErrors(nvmlDevice_t device, nvmlMemoryErrorType_t errorType, nvmlEccCounterType_t counterType, unsigned long long *eccCounts); - -/** - * Retrieves the detailed ECC error counts for the device. - * - * @deprecated This API supports only a fixed set of ECC error locations - * On different GPU architectures different locations are supported - * See \ref nvmlDeviceGetMemoryErrorCounter - * - * For Fermi &tm; or newer fully supported devices. - * Only applicable to devices with ECC. - * Requires \a NVML_INFOROM_ECC version 2.0 or higher to report aggregate location-based ECC counts. - * Requires \a NVML_INFOROM_ECC version 1.0 or higher to report all other ECC counts. - * Requires ECC Mode to be enabled. - * - * Detailed errors provide separate ECC counts for specific parts of the memory system. - * - * Reports zero for unsupported ECC error counters when a subset of ECC error counters are supported. - * - * See \ref nvmlMemoryErrorType_t for a description of available bit types.\n - * See \ref nvmlEccCounterType_t for a description of available counter types.\n - * See \ref nvmlEccErrorCounts_t for a description of provided detailed ECC counts. - * - * @param device The identifier of the target device - * @param errorType Flag that specifies the type of the errors. - * @param counterType Flag that specifies the counter-type of the errors. - * @param eccCounts Reference in which to return the specified ECC errors - * - * @return - * - \ref NVML_SUCCESS if \a eccCounts has been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a errorType or \a counterType is invalid, or \a eccCounts is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceClearEccErrorCounts() - */ -nvmlReturn_t DECLDIR nvmlDeviceGetDetailedEccErrors(nvmlDevice_t device, nvmlMemoryErrorType_t errorType, nvmlEccCounterType_t counterType, nvmlEccErrorCounts_t *eccCounts); - -/** - * Retrieves the requested memory error counter for the device. - * - * For Fermi &tm; or newer fully supported devices. - * Requires \a NVML_INFOROM_ECC version 2.0 or higher to report aggregate location-based memory error counts. - * Requires \a NVML_INFOROM_ECC version 1.0 or higher to report all other memory error counts. - * - * Only applicable to devices with ECC. - * - * Requires ECC Mode to be enabled. - * - * See \ref nvmlMemoryErrorType_t for a description of available memory error types.\n - * See \ref nvmlEccCounterType_t for a description of available counter types.\n - * See \ref nvmlMemoryLocation_t for a description of available counter locations.\n - * - * @param device The identifier of the target device - * @param errorType Flag that specifies the type of error. - * @param counterType Flag that specifies the counter-type of the errors. - * @param locationType Specifies the location of the counter. - * @param count Reference in which to return the ECC counter - * - * @return - * - \ref NVML_SUCCESS if \a count has been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a bitTyp,e \a counterType or \a locationType is - * invalid, or \a count is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support ECC error reporting in the specified memory - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetMemoryErrorCounter(nvmlDevice_t device, nvmlMemoryErrorType_t errorType, - nvmlEccCounterType_t counterType, - nvmlMemoryLocation_t locationType, unsigned long long *count); - -/** - * Retrieves the current utilization rates for the device's major subsystems. - * - * For Fermi &tm; or newer fully supported devices. - * - * See \ref nvmlUtilization_t for details on available utilization rates. - * - * \note During driver initialization when ECC is enabled one can see high GPU and Memory Utilization readings. - * This is caused by ECC Memory Scrubbing mechanism that is performed during driver initialization. - * - * @param device The identifier of the target device - * @param utilization Reference in which to return the utilization information - * - * @return - * - \ref NVML_SUCCESS if \a utilization has been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a utilization is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetUtilizationRates(nvmlDevice_t device, nvmlUtilization_t *utilization); - -/** - * Retrieves the current utilization and sampling size in microseconds for the Encoder - * - * For Kepler &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param utilization Reference to an unsigned int for encoder utilization info - * @param samplingPeriodUs Reference to an unsigned int for the sampling period in US - * - * @return - * - \ref NVML_SUCCESS if \a utilization has been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetEncoderUtilization(nvmlDevice_t device, unsigned int *utilization, unsigned int *samplingPeriodUs); - -/** - * Retrieves the current capacity of the device's encoder, in macroblocks per second. - * - * For Maxwell &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param encoderQueryType Type of encoder to query - * @param encoderCapacity Reference to an unsigned int for the encoder capacity - * - * @return - * - \ref NVML_SUCCESS if \a encoderCapacity is fetched - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a encoderCapacity is NULL, or \a device or \a encoderQueryType - * are invalid - * - \ref NVML_ERROR_NOT_SUPPORTED if device does not support the encoder specified in \a encodeQueryType - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetEncoderCapacity (nvmlDevice_t device, nvmlEncoderType_t encoderQueryType, unsigned int *encoderCapacity); - -/** - * Retrieves the current encoder statistics for a given device. - * - * For Maxwell &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param sessionCount Reference to an unsigned int for count of active encoder sessions - * @param averageFps Reference to an unsigned int for trailing average FPS of all active sessions - * @param averageLatency Reference to an unsigned int for encode latency in microseconds - * - * @return - * - \ref NVML_SUCCESS if \a sessionCount, \a averageFps and \a averageLatency is fetched - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount, or \a device or \a averageFps, - * or \a averageLatency is NULL - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetEncoderStats (nvmlDevice_t device, unsigned int *sessionCount, - unsigned int *averageFps, unsigned int *averageLatency); - -/** - * Retrieves information about active encoder sessions on a target device. - * - * An array of active encoder sessions is returned in the caller-supplied buffer pointed at by \a sessionInfos. The - * array elememt count is passed in \a sessionCount, and \a sessionCount is used to return the number of sessions - * written to the buffer. - * - * If the supplied buffer is not large enough to accommodate the active session array, the function returns - * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlEncoderSessionInfo_t array required in \a sessionCount. - * To query the number of active encoder sessions, call this function with *sessionCount = 0. The code will return - * NVML_SUCCESS with number of active encoder sessions updated in *sessionCount. - * - * For Maxwell &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param sessionCount Reference to caller supplied array size, and returns the number of sessions. - * @param sessionInfos Reference in which to return the session information - * - * @return - * - \ref NVML_SUCCESS if \a sessionInfos is fetched - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a sessionCount is too small, array element count is returned in \a sessionCount - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount is NULL. - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetEncoderSessions(nvmlDevice_t device, unsigned int *sessionCount, nvmlEncoderSessionInfo_t *sessionInfos); - -/** - * Retrieves the current utilization and sampling size in microseconds for the Decoder - * - * For Kepler &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param utilization Reference to an unsigned int for decoder utilization info - * @param samplingPeriodUs Reference to an unsigned int for the sampling period in US - * - * @return - * - \ref NVML_SUCCESS if \a utilization has been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetDecoderUtilization(nvmlDevice_t device, unsigned int *utilization, unsigned int *samplingPeriodUs); - -/** - * Retrieves the current and pending driver model for the device. - * - * For Fermi &tm; or newer fully supported devices. - * For windows only. - * - * On Windows platforms the device driver can run in either WDDM or WDM (TCC) mode. If a display is attached - * to the device it must run in WDDM mode. TCC mode is preferred if a display is not attached. - * - * See \ref nvmlDriverModel_t for details on available driver models. - * - * @param device The identifier of the target device - * @param current Reference in which to return the current driver model - * @param pending Reference in which to return the pending driver model - * - * @return - * - \ref NVML_SUCCESS if either \a current and/or \a pending have been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or both \a current and \a pending are NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the platform is not windows - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceSetDriverModel() - */ -nvmlReturn_t DECLDIR nvmlDeviceGetDriverModel(nvmlDevice_t device, nvmlDriverModel_t *current, nvmlDriverModel_t *pending); - -/** - * Get VBIOS version of the device. - * - * For all products. - * - * The VBIOS version may change from time to time. It will not exceed 32 characters in length - * (including the NULL terminator). See \ref nvmlConstants::NVML_DEVICE_VBIOS_VERSION_BUFFER_SIZE. - * - * @param device The identifier of the target device - * @param version Reference to which to return the VBIOS version - * @param length The maximum allowed length of the string returned in \a version - * - * @return - * - \ref NVML_SUCCESS if \a version has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a version is NULL - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetVbiosVersion(nvmlDevice_t device, char *version, unsigned int length); - -/** - * Get Bridge Chip Information for all the bridge chips on the board. - * - * For all fully supported products. - * Only applicable to multi-GPU products. - * - * @param device The identifier of the target device - * @param bridgeHierarchy Reference to the returned bridge chip Hierarchy - * - * @return - * - \ref NVML_SUCCESS if bridge chip exists - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a bridgeInfo is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if bridge chip not supported on the device - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - */ -nvmlReturn_t DECLDIR nvmlDeviceGetBridgeChipInfo(nvmlDevice_t device, nvmlBridgeChipHierarchy_t *bridgeHierarchy); - -/** - * Get information about processes with a compute context on a device - * - * For Fermi &tm; or newer fully supported devices. - * - * This function returns information only about compute running processes (e.g. CUDA application which have - * active context). Any graphics applications (e.g. using OpenGL, DirectX) won't be listed by this function. - * - * To query the current number of running compute processes, call this function with *infoCount = 0. The - * return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if none are running. For this call - * \a infos is allowed to be NULL. - * - * The usedGpuMemory field returned is all of the memory used by the application. - * - * Keep in mind that information returned by this call is dynamic and the number of elements might change in - * time. Allocate more space for \a infos table in case new compute processes are spawned. - * - * @param device The identifier of the target device - * @param infoCount Reference in which to provide the \a infos array size, and - * to return the number of returned elements - * @param infos Reference in which to return the process information - * - * @return - * - \ref NVML_SUCCESS if \a infoCount and \a infos have been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a infoCount indicates that the \a infos array is too small - * \a infoCount will contain minimal amount of space necessary for - * the call to complete - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, either of \a infoCount or \a infos is NULL - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see \ref nvmlSystemGetProcessName - */ -nvmlReturn_t DECLDIR nvmlDeviceGetComputeRunningProcesses(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_t *infos); - -/** - * Get information about processes with a graphics context on a device - * - * For Kepler &tm; or newer fully supported devices. - * - * This function returns information only about graphics based processes - * (eg. applications using OpenGL, DirectX) - * - * To query the current number of running graphics processes, call this function with *infoCount = 0. The - * return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if none are running. For this call - * \a infos is allowed to be NULL. - * - * The usedGpuMemory field returned is all of the memory used by the application. - * - * Keep in mind that information returned by this call is dynamic and the number of elements might change in - * time. Allocate more space for \a infos table in case new graphics processes are spawned. - * - * @param device The identifier of the target device - * @param infoCount Reference in which to provide the \a infos array size, and - * to return the number of returned elements - * @param infos Reference in which to return the process information - * - * @return - * - \ref NVML_SUCCESS if \a infoCount and \a infos have been populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a infoCount indicates that the \a infos array is too small - * \a infoCount will contain minimal amount of space necessary for - * the call to complete - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, either of \a infoCount or \a infos is NULL - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see \ref nvmlSystemGetProcessName - */ -nvmlReturn_t DECLDIR nvmlDeviceGetGraphicsRunningProcesses(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_t *infos); - -/** - * Check if the GPU devices are on the same physical board. - * - * For all fully supported products. - * - * @param device1 The first GPU device - * @param device2 The second GPU device - * @param onSameBoard Reference in which to return the status. - * Non-zero indicates that the GPUs are on the same board. - * - * @return - * - \ref NVML_SUCCESS if \a onSameBoard has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a dev1 or \a dev2 are invalid or \a onSameBoard is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if this check is not supported by the device - * - \ref NVML_ERROR_GPU_IS_LOST if the either GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceOnSameBoard(nvmlDevice_t device1, nvmlDevice_t device2, int *onSameBoard); - -/** - * Retrieves the root/admin permissions on the target API. See \a nvmlRestrictedAPI_t for the list of supported APIs. - * If an API is restricted only root users can call that API. See \a nvmlDeviceSetAPIRestriction to change current permissions. - * - * For all fully supported products. - * - * @param device The identifier of the target device - * @param apiType Target API type for this operation - * @param isRestricted Reference in which to return the current restriction - * NVML_FEATURE_ENABLED indicates that the API is root-only - * NVML_FEATURE_DISABLED indicates that the API is accessible to all users - * - * @return - * - \ref NVML_SUCCESS if \a isRestricted has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a apiType incorrect or \a isRestricted is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device or the device does not support - * the feature that is being queried (E.G. Enabling/disabling Auto Boosted clocks is - * not supported by the device) - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlRestrictedAPI_t - */ -nvmlReturn_t DECLDIR nvmlDeviceGetAPIRestriction(nvmlDevice_t device, nvmlRestrictedAPI_t apiType, nvmlEnableState_t *isRestricted); - -/** - * Gets recent samples for the GPU. - * - * For Kepler &tm; or newer fully supported devices. - * - * Based on type, this method can be used to fetch the power, utilization or clock samples maintained in the buffer by - * the driver. - * - * Power, Utilization and Clock samples are returned as type "unsigned int" for the union nvmlValue_t. - * - * To get the size of samples that user needs to allocate, the method is invoked with samples set to NULL. - * The returned samplesCount will provide the number of samples that can be queried. The user needs to - * allocate the buffer with size as samplesCount * sizeof(nvmlSample_t). - * - * lastSeenTimeStamp represents CPU timestamp in microseconds. Set it to 0 to fetch all the samples maintained by the - * underlying buffer. Set lastSeenTimeStamp to one of the timeStamps retrieved from the date of the previous query - * to get more recent samples. - * - * This method fetches the number of entries which can be accommodated in the provided samples array, and the - * reference samplesCount is updated to indicate how many samples were actually retrieved. The advantage of using this - * method for samples in contrast to polling via existing methods is to get get higher frequency data at lower polling cost. - * - * @param device The identifier for the target device - * @param type Type of sampling event - * @param lastSeenTimeStamp Return only samples with timestamp greater than lastSeenTimeStamp. - * @param sampleValType Output parameter to represent the type of sample value as described in nvmlSampleVal_t - * @param sampleCount Reference to provide the number of elements which can be queried in samples array - * @param samples Reference in which samples are returned - - * @return - * - \ref NVML_SUCCESS if samples are successfully retrieved - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a samplesCount is NULL or - * reference to \a sampleCount is 0 for non null \a samples - * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_NOT_FOUND if sample entries are not found - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetSamples(nvmlDevice_t device, nvmlSamplingType_t type, unsigned long long lastSeenTimeStamp, - nvmlValueType_t *sampleValType, unsigned int *sampleCount, nvmlSample_t *samples); - -/** - * Gets Total, Available and Used size of BAR1 memory. - * - * BAR1 is used to map the FB (device memory) so that it can be directly accessed by the CPU or by 3rd party - * devices (peer-to-peer on the PCIE bus). - * - * For Kepler &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param bar1Memory Reference in which BAR1 memory - * information is returned. - * - * @return - * - \ref NVML_SUCCESS if BAR1 memory is successfully retrieved - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a bar1Memory is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - */ -nvmlReturn_t DECLDIR nvmlDeviceGetBAR1MemoryInfo(nvmlDevice_t device, nvmlBAR1Memory_t *bar1Memory); - - -/** - * Gets the duration of time during which the device was throttled (lower than requested clocks) due to power - * or thermal constraints. - * - * The method is important to users who are tying to understand if their GPUs throttle at any point during their applications. The - * difference in violation times at two different reference times gives the indication of GPU throttling event. - * - * Violation for thermal capping is not supported at this time. - * - * For Kepler &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param perfPolicyType Represents Performance policy which can trigger GPU throttling - * @param violTime Reference to which violation time related information is returned - * - * - * @return - * - \ref NVML_SUCCESS if violation time is successfully retrieved - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a perfPolicyType is invalid, or \a violTime is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - */ -nvmlReturn_t DECLDIR nvmlDeviceGetViolationStatus(nvmlDevice_t device, nvmlPerfPolicyType_t perfPolicyType, nvmlViolationTime_t *violTime); - -/** - * @} - */ - -/** @addtogroup nvmlAccountingStats - * @{ - */ - -/** - * Queries the state of per process accounting mode. - * - * For Kepler &tm; or newer fully supported devices. - * - * See \ref nvmlDeviceGetAccountingStats for more details. - * See \ref nvmlDeviceSetAccountingMode - * - * @param device The identifier of the target device - * @param mode Reference in which to return the current accounting mode - * - * @return - * - \ref NVML_SUCCESS if the mode has been successfully retrieved - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode are NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetAccountingMode(nvmlDevice_t device, nvmlEnableState_t *mode); - -/** - * Queries process's accounting stats. - * - * For Kepler &tm; or newer fully supported devices. - * - * Accounting stats capture GPU utilization and other statistics across the lifetime of a process. - * Accounting stats can be queried during life time of the process and after its termination. - * The time field in \ref nvmlAccountingStats_t is reported as 0 during the lifetime of the process and - * updated to actual running time after its termination. - * Accounting stats are kept in a circular buffer, newly created processes overwrite information about old - * processes. - * - * See \ref nvmlAccountingStats_t for description of each returned metric. - * List of processes that can be queried can be retrieved from \ref nvmlDeviceGetAccountingPids. - * - * @note Accounting Mode needs to be on. See \ref nvmlDeviceGetAccountingMode. - * @note Only compute and graphics applications stats can be queried. Monitoring applications stats can't be - * queried since they don't contribute to GPU utilization. - * @note In case of pid collision stats of only the latest process (that terminated last) will be reported - * - * @warning On Kepler devices per process statistics are accurate only if there's one process running on a GPU. - * - * @param device The identifier of the target device - * @param pid Process Id of the target process to query stats for - * @param stats Reference in which to return the process's accounting stats - * - * @return - * - \ref NVML_SUCCESS if stats have been successfully retrieved - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a stats are NULL - * - \ref NVML_ERROR_NOT_FOUND if process stats were not found - * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature or accounting mode is disabled - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceGetAccountingBufferSize - */ -nvmlReturn_t DECLDIR nvmlDeviceGetAccountingStats(nvmlDevice_t device, unsigned int pid, nvmlAccountingStats_t *stats); - -/** - * Queries list of processes that can be queried for accounting stats. The list of processes returned - * can be in running or terminated state. - * - * For Kepler &tm; or newer fully supported devices. - * - * To just query the number of processes ready to be queried, call this function with *count = 0 and - * pids=NULL. The return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if list is empty. - * - * For more details see \ref nvmlDeviceGetAccountingStats. - * - * @note In case of PID collision some processes might not be accessible before the circular buffer is full. - * - * @param device The identifier of the target device - * @param count Reference in which to provide the \a pids array size, and - * to return the number of elements ready to be queried - * @param pids Reference in which to return list of process ids - * - * @return - * - \ref NVML_SUCCESS if pids were successfully retrieved - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a count is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature or accounting mode is disabled - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a count is too small (\a count is set to - * expected value) - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceGetAccountingBufferSize - */ -nvmlReturn_t DECLDIR nvmlDeviceGetAccountingPids(nvmlDevice_t device, unsigned int *count, unsigned int *pids); - -/** - * Returns the number of processes that the circular buffer with accounting pids can hold. - * - * For Kepler &tm; or newer fully supported devices. - * - * This is the maximum number of processes that accounting information will be stored for before information - * about oldest processes will get overwritten by information about new processes. - * - * @param device The identifier of the target device - * @param bufferSize Reference in which to provide the size (in number of elements) - * of the circular buffer for accounting stats. - * - * @return - * - \ref NVML_SUCCESS if buffer size was successfully retrieved - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a bufferSize is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature or accounting mode is disabled - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceGetAccountingStats - * @see nvmlDeviceGetAccountingPids - */ -nvmlReturn_t DECLDIR nvmlDeviceGetAccountingBufferSize(nvmlDevice_t device, unsigned int *bufferSize); - -/** @} */ - -/** @addtogroup nvmlDeviceQueries - * @{ - */ - -/** - * Returns the list of retired pages by source, including pages that are pending retirement - * The address information provided from this API is the hardware address of the page that was retired. Note - * that this does not match the virtual address used in CUDA, but will match the address information in XID 63 - * - * For Kepler &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param cause Filter page addresses by cause of retirement - * @param pageCount Reference in which to provide the \a addresses buffer size, and - * to return the number of retired pages that match \a cause - * Set to 0 to query the size without allocating an \a addresses buffer - * @param addresses Buffer to write the page addresses into - * - * @return - * - \ref NVML_SUCCESS if \a pageCount was populated and \a addresses was filled - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a pageCount indicates the buffer is not large enough to store all the - * matching page addresses. \a pageCount is set to the needed size. - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a pageCount is NULL, \a cause is invalid, or - * \a addresses is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetRetiredPages(nvmlDevice_t device, nvmlPageRetirementCause_t cause, - unsigned int *pageCount, unsigned long long *addresses); - -/** - * Check if any pages are pending retirement and need a reboot to fully retire. - * - * For Kepler &tm; or newer fully supported devices. - * - * @param device The identifier of the target device - * @param isPending Reference in which to return the pending status - * - * @return - * - \ref NVML_SUCCESS if \a isPending was populated - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a isPending is NULL - * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceGetRetiredPagesPendingStatus(nvmlDevice_t device, nvmlEnableState_t *isPending); - -/** @} */ - -/***************************************************************************************************/ -/** @defgroup nvmlUnitCommands Unit Commands - * This chapter describes NVML operations that change the state of the unit. For S-class products. - * Each of these requires root/admin access. Non-admin users will see an NVML_ERROR_NO_PERMISSION - * error code when invoking any of these methods. - * @{ - */ -/***************************************************************************************************/ - -/** - * Set the LED state for the unit. The LED can be either green (0) or amber (1). - * - * For S-class products. - * Requires root/admin permissions. - * - * This operation takes effect immediately. - * - * - * Current S-Class products don't provide unique LEDs for each unit. As such, both front - * and back LEDs will be toggled in unison regardless of which unit is specified with this command. - * - * See \ref nvmlLedColor_t for available colors. - * - * @param unit The identifier of the target unit - * @param color The target LED color - * - * @return - * - \ref NVML_SUCCESS if the LED color has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a unit or \a color is invalid - * - \ref NVML_ERROR_NOT_SUPPORTED if this is not an S-class product - * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlUnitGetLedState() - */ -nvmlReturn_t DECLDIR nvmlUnitSetLedState(nvmlUnit_t unit, nvmlLedColor_t color); - -/** @} */ - -/***************************************************************************************************/ -/** @defgroup nvmlDeviceCommands Device Commands - * This chapter describes NVML operations that change the state of the device. - * Each of these requires root/admin access. Non-admin users will see an NVML_ERROR_NO_PERMISSION - * error code when invoking any of these methods. - * @{ - */ -/***************************************************************************************************/ - -/** - * Set the persistence mode for the device. - * - * For all products. - * For Linux only. - * Requires root/admin permissions. - * - * The persistence mode determines whether the GPU driver software is torn down after the last client - * exits. - * - * This operation takes effect immediately. It is not persistent across reboots. After each reboot the - * persistence mode is reset to "Disabled". - * - * See \ref nvmlEnableState_t for available modes. - * - * @param device The identifier of the target device - * @param mode The target persistence mode - * - * @return - * - \ref NVML_SUCCESS if the persistence mode was set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is invalid - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceGetPersistenceMode() - */ -nvmlReturn_t DECLDIR nvmlDeviceSetPersistenceMode(nvmlDevice_t device, nvmlEnableState_t mode); - -/** - * Set the compute mode for the device. - * - * For all products. - * Requires root/admin permissions. - * - * The compute mode determines whether a GPU can be used for compute operations and whether it can - * be shared across contexts. - * - * This operation takes effect immediately. Under Linux it is not persistent across reboots and - * always resets to "Default". Under windows it is persistent. - * - * Under windows compute mode may only be set to DEFAULT when running in WDDM - * - * See \ref nvmlComputeMode_t for details on available compute modes. - * - * @param device The identifier of the target device - * @param mode The target compute mode - * - * @return - * - \ref NVML_SUCCESS if the compute mode was set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode is invalid - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceGetComputeMode() - */ -nvmlReturn_t DECLDIR nvmlDeviceSetComputeMode(nvmlDevice_t device, nvmlComputeMode_t mode); - -/** - * Set the ECC mode for the device. - * - * For Kepler &tm; or newer fully supported devices. - * Only applicable to devices with ECC. - * Requires \a NVML_INFOROM_ECC version 1.0 or higher. - * Requires root/admin permissions. - * - * The ECC mode determines whether the GPU enables its ECC support. - * - * This operation takes effect after the next reboot. - * - * See \ref nvmlEnableState_t for details on available modes. - * - * @param device The identifier of the target device - * @param ecc The target ECC mode - * - * @return - * - \ref NVML_SUCCESS if the ECC mode was set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a ecc is invalid - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceGetEccMode() - */ -nvmlReturn_t DECLDIR nvmlDeviceSetEccMode(nvmlDevice_t device, nvmlEnableState_t ecc); - -/** - * Clear the ECC error and other memory error counts for the device. - * - * For Kepler &tm; or newer fully supported devices. - * Only applicable to devices with ECC. - * Requires \a NVML_INFOROM_ECC version 2.0 or higher to clear aggregate location-based ECC counts. - * Requires \a NVML_INFOROM_ECC version 1.0 or higher to clear all other ECC counts. - * Requires root/admin permissions. - * Requires ECC Mode to be enabled. - * - * Sets all of the specified ECC counters to 0, including both detailed and total counts. - * - * This operation takes effect immediately. - * - * See \ref nvmlMemoryErrorType_t for details on available counter types. - * - * @param device The identifier of the target device - * @param counterType Flag that indicates which type of errors should be cleared. - * - * @return - * - \ref NVML_SUCCESS if the error counts were cleared - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a counterType is invalid - * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature - * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see - * - nvmlDeviceGetDetailedEccErrors() - * - nvmlDeviceGetTotalEccErrors() - */ -nvmlReturn_t DECLDIR nvmlDeviceClearEccErrorCounts(nvmlDevice_t device, nvmlEccCounterType_t counterType); - -/** - * Set the driver model for the device. - * - * For Fermi &tm; or newer fully supported devices. - * For windows only. - * Requires root/admin permissions. - * - * On Windows platforms the device driver can run in either WDDM or WDM (TCC) mode. If a display is attached - * to the device it must run in WDDM mode. - * - * It is possible to force the change to WDM (TCC) while the display is still attached with a force flag (nvmlFlagForce). - * This should only be done if the host is subsequently powered down and the display is detached from the device - * before the next reboot. - * - * This operation takes effect after the next reboot. - * - * Windows driver model may only be set to WDDM when running in DEFAULT compute mode. - * - * Change driver model to WDDM is not supported when GPU doesn't support graphics acceleration or - * will not support it after reboot. See \ref nvmlDeviceSetGpuOperationMode. - * - * See \ref nvmlDriverModel_t for details on available driver models. - * See \ref nvmlFlagDefault and \ref nvmlFlagForce - * - * @param device The identifier of the target device - * @param driverModel The target driver model - * @param flags Flags that change the default behavior - * - * @return - * - \ref NVML_SUCCESS if the driver model has been set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a driverModel is invalid - * - \ref NVML_ERROR_NOT_SUPPORTED if the platform is not windows or the device does not support this feature - * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * - * @see nvmlDeviceGetDriverModel() - */ -nvmlReturn_t DECLDIR nvmlDeviceSetDriverModel(nvmlDevice_t device, nvmlDriverModel_t driverModel, unsigned int flags); - -/** - * Set clocks that applications will lock to. - * - * Sets the clocks that compute and graphics applications will be running at. - * e.g. CUDA driver requests these clocks during context creation which means this property - * defines clocks at which CUDA applications will be running unless some overspec event - * occurs (e.g. over power, over thermal or external HW brake). - * - * Can be used as a setting to request constant performance. - * - * On Pascal and newer hardware, this will automatically disable automatic boosting of clocks. - * - * On K80 and newer Kepler and Maxwell GPUs, users desiring fixed performance should also call - * \ref nvmlDeviceSetAutoBoostedClocksEnabled to prevent clocks from automatically boosting - * above the clock value being set. - * - * For Kepler &tm; or newer non-GeForce fully supported devices and Maxwell or newer GeForce devices. - * Requires root/admin permissions. - * - * See \ref nvmlDeviceGetSupportedMemoryClocks and \ref nvmlDeviceGetSupportedGraphicsClocks - * for details on how to list available clocks combinations. - * - * After system reboot or driver reload applications clocks go back to their default value. - * See \ref nvmlDeviceResetApplicationsClocks. - * - * @param device The identifier of the target device - * @param memClockMHz Requested memory clock in MHz - * @param graphicsClockMHz Requested graphics clock in MHz - * - * @return - * - \ref NVML_SUCCESS if new settings were successfully set - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a memClockMHz and \a graphicsClockMHz - * is not a valid clock combination - * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation - * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature - * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlDeviceSetApplicationsClocks(nvmlDevice_t device, unsigned int memClockMHz, unsigned int graphicsClockMHz); +nvmlReturn_t DECLDIR nvmlDeviceSetTemperatureThreshold(nvmlDevice_t device, nvmlTemperatureThresholds_t thresholdType, int *temp); /** * Set new power limit of this device. - * + * * For Kepler &tm; or newer fully supported devices. * Requires root/admin permissions. * @@ -4327,8 +6799,8 @@ nvmlReturn_t DECLDIR nvmlDeviceSetApplicationsClocks(nvmlDevice_t device, unsign * * @param device The identifier of the target device * @param limit Power management limit in milliwatts to set - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a limit has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a defaultLimit is out of range @@ -4348,17 +6820,17 @@ nvmlReturn_t DECLDIR nvmlDeviceSetPowerManagementLimit(nvmlDevice_t device, unsi * Modes \ref NVML_GOM_LOW_DP and \ref NVML_GOM_ALL_ON are supported on fully supported GeForce products. * Not supported on Quadro ® and Tesla &tm; C-class products. * Requires root/admin permissions. - * - * Changing GOMs requires a reboot. + * + * Changing GOMs requires a reboot. * The reboot requirement might be removed in the future. * * Compute only GOMs don't support graphics acceleration. Under windows switching to these GOMs when * pending driver model is WDDM is not supported. See \ref nvmlDeviceSetDriverModel. - * + * * @param device The identifier of the target device * @param mode Target GOM - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a mode has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a mode incorrect @@ -4377,7 +6849,7 @@ nvmlReturn_t DECLDIR nvmlDeviceSetGpuOperationMode(nvmlDevice_t device, nvmlGpuO * This method can be used by a root/admin user to give non-root/admin access to certain otherwise-restricted APIs. * The new setting lasts for the lifetime of the NVIDIA driver; it is not persistent. See \a nvmlDeviceGetAPIRestriction * to query the current restriction settings. - * + * * For Kepler &tm; or newer fully supported devices. * Requires root/admin permissions. * @@ -4390,7 +6862,7 @@ nvmlReturn_t DECLDIR nvmlDeviceSetGpuOperationMode(nvmlDevice_t device, nvmlGpuO * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a apiType incorrect * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support changing API restrictions or the device does not support - * the feature that api restrictions are being set for (E.G. Enabling/disabling auto + * the feature that api restrictions are being set for (E.G. Enabling/disabling auto * boosted clocks is not supported by the device) * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible @@ -4400,10 +6872,98 @@ nvmlReturn_t DECLDIR nvmlDeviceSetGpuOperationMode(nvmlDevice_t device, nvmlGpuO */ nvmlReturn_t DECLDIR nvmlDeviceSetAPIRestriction(nvmlDevice_t device, nvmlRestrictedAPI_t apiType, nvmlEnableState_t isRestricted); +/** + * Sets the speed of a specified fan. + * + * WARNING: This function changes the fan control policy to manual. It means that YOU have to monitor + * the temperature and adjust the fan speed accordingly. + * If you set the fan speed too low you can burn your GPU! + * Use nvmlDeviceSetDefaultFanSpeed_v2 to restore default control policy. + * + * For all cuda-capable discrete products with fans that are Maxwell or Newer. + * + * device The identifier of the target device + * fan The index of the fan, starting at zero + * speed The target speed of the fan [0-100] in % of max speed + * + * return + * NVML_SUCCESS if the fan speed has been set + * NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * NVML_ERROR_INVALID_ARGUMENT if the device is not valid, or the speed is outside acceptable ranges, + * or if the fan index doesn't reference an actual fan. + * NVML_ERROR_NOT_SUPPORTED if the device is older than Maxwell. + * NVML_ERROR_UNKNOWN if there was an unexpected error. + */ +nvmlReturn_t DECLDIR nvmlDeviceSetFanSpeed_v2(nvmlDevice_t device, unsigned int fan, unsigned int speed); + +/** + * Set the GPCCLK VF offset value + * @param[in] device The identifier of the target device + * @param[in] offset The GPCCLK VF offset value to set + * + * @return + * - \ref NVML_SUCCESS if \a offset has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a offset is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetGpcClkVfOffset(nvmlDevice_t device, int offset); + +/** + * Set the MemClk (Memory Clock) VF offset value. It requires elevated privileges. + * @param[in] device The identifier of the target device + * @param[in] offset The MemClk VF offset value to set + * + * @return + * - \ref NVML_SUCCESS if \a offset has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a offset is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature + * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetMemClkVfOffset(nvmlDevice_t device, int offset); + +/** + * Set Conf Computing Unprotected Memory Size. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux, Windows TCC. + * + * @param device Device Handle + * @param sizeKiB Unprotected Memory size to be set in KiB + * + * @return + * - \ref NVML_SUCCESS if \a sizeKiB successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + */ +nvmlReturn_t DECLDIR nvmlDeviceSetConfComputeUnprotectedMemSize(nvmlDevice_t device, unsigned long long sizeKiB); + +/** + * Set Conf Computing GPUs ready state. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux, Windows TCC. + * + * @param isAcceptingWork GPU accepting new work, NVML_CC_ACCEPTING_CLIENT_REQUESTS_TRUE or + * NVML_CC_ACCEPTING_CLIENT_REQUESTS_FALSE + * + * return + * - \ref NVML_SUCCESS if \a current GPUs ready state is successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a isAcceptingWork is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + */ +nvmlReturn_t DECLDIR nvmlSystemSetConfComputeGpusReadyState(unsigned int isAcceptingWork); + /** * @} */ - + /** @addtogroup nvmlAccountingStats * @{ */ @@ -4416,11 +6976,13 @@ nvmlReturn_t DECLDIR nvmlDeviceSetAPIRestriction(nvmlDevice_t device, nvmlRestri * * @note This setting is not persistent and will default to disabled after driver unloads. * Enable persistence mode to be sure the setting doesn't switch off to disabled. - * + * * @note Enabling accounting mode has no negative impact on the GPU performance. * * @note Disabling accounting clears all accounting pids information. * + * @note On MIG-enabled GPUs, accounting mode would be set to DISABLED and changing it is not supported. + * * See \ref nvmlDeviceGetAccountingMode * See \ref nvmlDeviceGetAccountingStats * See \ref nvmlDeviceClearAccountingPids @@ -4428,7 +6990,7 @@ nvmlReturn_t DECLDIR nvmlDeviceSetAPIRestriction(nvmlDevice_t device, nvmlRestri * @param device The identifier of the target device * @param mode The target accounting mode * - * @return + * @return * - \ref NVML_SUCCESS if the new mode has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a mode are invalid @@ -4450,8 +7012,8 @@ nvmlReturn_t DECLDIR nvmlDeviceSetAccountingMode(nvmlDevice_t device, nvmlEnable * * @param device The identifier of the target device * - * @return - * - \ref NVML_SUCCESS if accounting information has been cleared + * @return + * - \ref NVML_SUCCESS if accounting information has been cleared * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device are invalid * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature @@ -4477,10 +7039,10 @@ nvmlReturn_t DECLDIR nvmlDeviceClearAccountingPids(nvmlDevice_t device); * @param device The identifier of the target device * @param link Specifies the NvLink link to be queried * @param isActive \a nvmlEnableState_t where NVML_FEATURE_ENABLED indicates that - * the link is active and NVML_FEATURE_DISABLED indicates it + * the link is active and NVML_FEATURE_DISABLED indicates it * is inactive * - * @return + * @return * - \ref NVML_SUCCESS if \a isActive has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a link is invalid or \a isActive is NULL @@ -4498,7 +7060,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkState(nvmlDevice_t device, unsigned int * @param link Specifies the NvLink link to be queried * @param version Requested NvLink version * - * @return + * @return * - \ref NVML_SUCCESS if \a version has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a link is invalid or \a version is NULL @@ -4519,7 +7081,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkVersion(nvmlDevice_t device, unsigned in * @param capability Specifies the \a nvmlNvLinkCapability_t to be queried * @param capResult A boolean for the queried capability indicating that feature is available * - * @return + * @return * - \ref NVML_SUCCESS if \a capResult has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a link, or \a capability is invalid or \a capResult is NULL @@ -4527,26 +7089,26 @@ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkVersion(nvmlDevice_t device, unsigned in * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkCapability(nvmlDevice_t device, unsigned int link, - nvmlNvLinkCapability_t capability, unsigned int *capResult); + nvmlNvLinkCapability_t capability, unsigned int *capResult); /** - * Retrieves the PCI information for the remote node on a NvLink link + * Retrieves the PCI information for the remote node on a NvLink link * Note: pciSubSystemId is not filled in this function and is indeterminate * * For Pascal &tm; or newer fully supported devices. * * @param device The identifier of the target device * @param link Specifies the NvLink link to be queried - * @param pci \a nvmlPciInfo_t of the remote node for the specified link + * @param pci \a nvmlPciInfo_t of the remote node for the specified link * - * @return + * @return * - \ref NVML_SUCCESS if \a pci has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a link is invalid or \a pci is NULL * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkRemotePciInfo(nvmlDevice_t device, unsigned int link, nvmlPciInfo_t *pci); +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkRemotePciInfo_v2(nvmlDevice_t device, unsigned int link, nvmlPciInfo_t *pci); /** * Retrieves the specified error counter value @@ -4559,7 +7121,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkRemotePciInfo(nvmlDevice_t device, unsig * @param counter Specifies the NvLink counter to be queried * @param counterValue Returned counter value * - * @return + * @return * - \ref NVML_SUCCESS if \a counter has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a link, or \a counter is invalid or \a counterValue is NULL @@ -4578,7 +7140,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkErrorCounter(nvmlDevice_t device, unsign * @param device The identifier of the target device * @param link Specifies the NvLink link to be queried * - * @return + * @return * - \ref NVML_SUCCESS if the reset is successful * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a link is invalid @@ -4588,6 +7150,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkErrorCounter(nvmlDevice_t device, unsign nvmlReturn_t DECLDIR nvmlDeviceResetNvLinkErrorCounters(nvmlDevice_t device, unsigned int link); /** + * Deprecated: Setting utilization counter control is no longer supported. + * * Set the NVLINK utilization counter control information for the specified counter, 0 or 1. * Please refer to \a nvmlNvLinkUtilizationControl_t for the structure definition. Performs a reset * of the counters if the reset parameter is non-zero. @@ -4600,10 +7164,10 @@ nvmlReturn_t DECLDIR nvmlDeviceResetNvLinkErrorCounters(nvmlDevice_t device, uns * @param control A reference to the \a nvmlNvLinkUtilizationControl_t to set * @param reset Resets the counters on set if non-zero * - * @return + * @return * - \ref NVML_SUCCESS if the control has been set successfully * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a counter, \a link, or \a control is invalid + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a counter, \a link, or \a control is invalid * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ @@ -4611,6 +7175,8 @@ nvmlReturn_t DECLDIR nvmlDeviceSetNvLinkUtilizationControl(nvmlDevice_t device, nvmlNvLinkUtilizationControl_t *control, unsigned int reset); /** + * Deprecated: Getting utilization counter control is no longer supported. + * * Get the NVLINK utilization counter control information for the specified counter, 0 or 1. * Please refer to \a nvmlNvLinkUtilizationControl_t for the structure definition * @@ -4621,10 +7187,10 @@ nvmlReturn_t DECLDIR nvmlDeviceSetNvLinkUtilizationControl(nvmlDevice_t device, * @param link Specifies the NvLink link to be queried * @param control A reference to the \a nvmlNvLinkUtilizationControl_t to place information * - * @return + * @return * - \ref NVML_SUCCESS if the control has been set successfully * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a counter, \a link, or \a control is invalid + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a counter, \a link, or \a control is invalid * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ @@ -4633,6 +7199,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkUtilizationControl(nvmlDevice_t device, /** + * Deprecated: Use \ref nvmlDeviceGetFieldValues with NVML_FI_DEV_NVLINK_THROUGHPUT_* as field values instead. + * * Retrieve the NVLINK utilization counter based on the current control for a specified counter. * In general it is good practice to use \a nvmlDeviceSetNvLinkUtilizationControl * before reading the utilization counters as they have no default state @@ -4645,18 +7213,20 @@ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkUtilizationControl(nvmlDevice_t device, * @param rxcounter Receive counter return value * @param txcounter Transmit counter return value * - * @return + * @return * - \ref NVML_SUCCESS if \a rxcounter and \a txcounter have been successfully set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a counter, or \a link is invalid or \a rxcounter or \a txcounter are NULL * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkUtilizationCounter(nvmlDevice_t device, unsigned int link, unsigned int counter, +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkUtilizationCounter(nvmlDevice_t device, unsigned int link, unsigned int counter, unsigned long long *rxcounter, unsigned long long *txcounter); /** - * Freeze the NVLINK utilization counters + * Deprecated: Freezing NVLINK utilization counters is no longer supported. + * + * Freeze the NVLINK utilization counters * Both the receive and transmit counters are operated on by this function * * For Pascal &tm; or newer fully supported devices. @@ -4667,18 +7237,20 @@ nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkUtilizationCounter(nvmlDevice_t device, * @param freeze NVML_FEATURE_ENABLED = freeze the receive and transmit counters * NVML_FEATURE_DISABLED = unfreeze the receive and transmit counters * - * @return + * @return * - \ref NVML_SUCCESS if counters were successfully frozen or unfrozen * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a link, \a counter, or \a freeze is invalid * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceFreezeNvLinkUtilizationCounter (nvmlDevice_t device, unsigned int link, +nvmlReturn_t DECLDIR nvmlDeviceFreezeNvLinkUtilizationCounter (nvmlDevice_t device, unsigned int link, unsigned int counter, nvmlEnableState_t freeze); /** - * Reset the NVLINK utilization counters + * Deprecated: Resetting NVLINK utilization counters is no longer supported. + * + * Reset the NVLINK utilization counters * Both the receive and transmit counters are operated on by this function * * For Pascal &tm; or newer fully supported devices. @@ -4687,7 +7259,7 @@ nvmlReturn_t DECLDIR nvmlDeviceFreezeNvLinkUtilizationCounter (nvmlDevice_t devi * @param link Specifies the NvLink link to be reset * @param counter Specifies the counter that should be reset (0 or 1) * - * @return + * @return * - \ref NVML_SUCCESS if counters were successfully reset * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a link, or \a counter is invalid @@ -4696,11 +7268,30 @@ nvmlReturn_t DECLDIR nvmlDeviceFreezeNvLinkUtilizationCounter (nvmlDevice_t devi */ nvmlReturn_t DECLDIR nvmlDeviceResetNvLinkUtilizationCounter (nvmlDevice_t device, unsigned int link, unsigned int counter); +/** +* Get the NVLink device type of the remote device connected over the given link. +* +* @param device The device handle of the target GPU +* @param link The NVLink link index on the target GPU +* @param pNvLinkDeviceType Pointer in which the output remote device type is returned +* +* @return +* - \ref NVML_SUCCESS if \a pNvLinkDeviceType has been set +* - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized +* - \ref NVML_ERROR_NOT_SUPPORTED if NVLink is not supported +* - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a link is invalid, or +* \a pNvLinkDeviceType is NULL +* - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is +* otherwise inaccessible +* - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkRemoteDeviceType(nvmlDevice_t device, unsigned int link, nvmlIntNvLinkDeviceType_t *pNvLinkDeviceType); + /** @} */ /***************************************************************************************************/ /** @defgroup nvmlEvents Event Handling Methods - * This chapter describes methods that NVML can perform against each device to register and wait for + * This chapter describes methods that NVML can perform against each device to register and wait for * some event to occur. * @{ */ @@ -4712,13 +7303,13 @@ nvmlReturn_t DECLDIR nvmlDeviceResetNvLinkUtilizationCounter (nvmlDevice_t devic * * For Fermi &tm; or newer fully supported devices. * @param set Reference in which to return the event handle - * - * @return + * + * @return * - \ref NVML_SUCCESS if the event has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a set is NULL * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * + * * @see nvmlEventSetFree */ nvmlReturn_t DECLDIR nvmlEventSetCreate(nvmlEventSet_t *set); @@ -4736,7 +7327,7 @@ nvmlReturn_t DECLDIR nvmlEventSetCreate(nvmlEventSet_t *set); * * This call starts recording of events on specific device. * All events that occurred before this call are not recorded. - * Checking if some event occurred can be done with \ref nvmlEventSetWait + * Checking if some event occurred can be done with \ref nvmlEventSetWait_v2 * * If function reports NVML_ERROR_UNKNOWN, event set is in undefined state and should be freed. * If function reports NVML_ERROR_NOT_SUPPORTED, event set can still be used. None of the requested eventTypes @@ -4745,15 +7336,15 @@ nvmlReturn_t DECLDIR nvmlEventSetCreate(nvmlEventSet_t *set); * @param device The identifier of the target device * @param eventTypes Bitmask of \ref nvmlEventType to record * @param set Set to which add new event types - * - * @return + * + * @return * - \ref NVML_SUCCESS if the event has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a eventTypes is invalid or \a set is NULL * - \ref NVML_ERROR_NOT_SUPPORTED if the platform does not support this feature or some of requested event types * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * + * * @see nvmlEventType * @see nvmlDeviceGetSupportedEventTypes * @see nvmlEventSetWait @@ -4770,14 +7361,14 @@ nvmlReturn_t DECLDIR nvmlDeviceRegisterEvents(nvmlDevice_t device, unsigned long * * @param device The identifier of the target device * @param eventTypes Reference in which to return bitmask of supported events - * - * @return + * + * @return * - \ref NVML_SUCCESS if the eventTypes has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a eventType is NULL * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * + * * @see nvmlEventType * @see nvmlDeviceRegisterEvents */ @@ -4789,43 +7380,51 @@ nvmlReturn_t DECLDIR nvmlDeviceGetSupportedEventTypes(nvmlDevice_t device, unsig * For Fermi &tm; or newer fully supported devices. * * If some events are ready to be delivered at the time of the call, function returns immediately. - * If there are no events ready to be delivered, function sleeps till event arrives + * If there are no events ready to be delivered, function sleeps till event arrives * but not longer than specified timeout. This function in certain conditions can return before * specified timeout passes (e.g. when interrupt arrives) - * - * In case of xid error, the function returns the most recent xid error type seen by the system. If there are multiple - * xid errors generated before nvmlEventSetWait is invoked then the last seen xid error type is returned for all - * xid error events. - * + * + * On Windows, in case of xid error, the function returns the most recent xid error type seen by the system. + * If there are multiple xid errors generated before nvmlEventSetWait is invoked then the last seen xid error + * type is returned for all xid error events. + * + * On Linux, every xid error event would return the associated event data and other information if applicable. + * + * In MIG mode, if device handle is provided, the API reports all the events for the available instances, + * only if the caller has appropriate privileges. In absence of required privileges, only the events which + * affect all the instances (i.e. whole device) are reported. + * + * This API does not currently support per-instance event reporting using MIG device handles. + * * @param set Reference to set of events to wait on * @param data Reference in which to return event data * @param timeoutms Maximum amount of wait time in milliseconds for registered event - * - * @return + * + * @return * - \ref NVML_SUCCESS if the data has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a data is NULL * - \ref NVML_ERROR_TIMEOUT if no event arrived in specified timeout or interrupt arrived * - \ref NVML_ERROR_GPU_IS_LOST if a GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * + * * @see nvmlEventType * @see nvmlDeviceRegisterEvents */ -nvmlReturn_t DECLDIR nvmlEventSetWait(nvmlEventSet_t set, nvmlEventData_t * data, unsigned int timeoutms); +nvmlReturn_t DECLDIR nvmlEventSetWait_v2(nvmlEventSet_t set, nvmlEventData_t * data, unsigned int timeoutms); /** * Releases events in the set * * For Fermi &tm; or newer fully supported devices. * - * @param set Reference to events to be released - * - * @return + * @param set Reference to events to be released + * + * @return * - \ref NVML_SUCCESS if the event has been successfully released * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_UNKNOWN on any unexpected error - * + * * @see nvmlDeviceRegisterEvents */ nvmlReturn_t DECLDIR nvmlEventSetFree(nvmlEventSet_t set); @@ -4833,7 +7432,7 @@ nvmlReturn_t DECLDIR nvmlEventSetFree(nvmlEventSet_t set); /** @} */ /***************************************************************************************************/ -/** @defgroup nvmlZPI Drain states +/** @defgroup nvmlZPI Drain states * This chapter describes methods that NVML can perform against each device to control their drain state * and recognition by NVML and NVIDIA kernel driver. These methods can be used with out-of-band tools to * power on/off GPUs, enable robust reset scenarios, etc. @@ -4847,14 +7446,14 @@ nvmlReturn_t DECLDIR nvmlEventSetFree(nvmlEventSet_t set); * this call is made. * Must be called as administrator. * For Linux only. - * + * * For Pascal &tm; or newer fully supported devices. * Some Kepler devices supported. * * @param pciInfo The PCI address of the GPU drain state to be modified * @param newState The drain state that should be entered, see \ref nvmlEnableState_t * - * @return + * @return * - \ref NVML_SUCCESS if counters were successfully reset * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a nvmlIndex or \a newState is invalid @@ -4869,14 +7468,14 @@ nvmlReturn_t DECLDIR nvmlDeviceModifyDrainState (nvmlPciInfo_t *pciInfo, nvmlEna * Query the drain state of a GPU. This method is used to check if a GPU is in a currently draining * state. * For Linux only. - * + * * For Pascal &tm; or newer fully supported devices. * Some Kepler devices supported. * * @param pciInfo The PCI address of the GPU drain state to be queried * @param currentState The current drain state for this GPU, see \ref nvmlEnableState_t * - * @return + * @return * - \ref NVML_SUCCESS if counters were successfully reset * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a nvmlIndex or \a currentState is invalid @@ -4890,20 +7489,23 @@ nvmlReturn_t DECLDIR nvmlDeviceQueryDrainState (nvmlPciInfo_t *pciInfo, nvmlEnab * as long as no other processes are attached. If other processes are attached, this call will return * NVML_ERROR_IN_USE and the GPU will be returned to its original "draining" state. Note: the * only situation where a process can still be attached after nvmlDeviceModifyDrainState() is called - * to initiate the draining state is if that process was using, and is still using, a GPU before the + * to initiate the draining state is if that process was using, and is still using, a GPU before the * call was made. Also note, persistence mode counts as an attachment to the GPU thus it must be disabled * prior to this call. * * For long-running NVML processes please note that this will change the enumeration of current GPUs. * For example, if there are four GPUs present and GPU1 is removed, the new enumeration will be 0-2. * Also, device handles after the removed GPU will not be valid and must be re-established. - * Must be run as administrator. + * Must be run as administrator. * For Linux only. * * For Pascal &tm; or newer fully supported devices. * Some Kepler devices supported. * * @param pciInfo The PCI address of the GPU to be removed + * @param gpuState Whether the GPU is to be removed, from the OS + * see \ref nvmlDetachGpuState_t + * @param linkState Requested upstream PCIe link state, see \ref nvmlPcieLinkState_t * * @return * - \ref NVML_SUCCESS if counters were successfully reset @@ -4912,11 +7514,11 @@ nvmlReturn_t DECLDIR nvmlDeviceQueryDrainState (nvmlPciInfo_t *pciInfo, nvmlEnab * - \ref NVML_ERROR_NOT_SUPPORTED if the device doesn't support this feature * - \ref NVML_ERROR_IN_USE if the device is still in use and cannot be removed */ -nvmlReturn_t DECLDIR nvmlDeviceRemoveGpu (nvmlPciInfo_t *pciInfo); +nvmlReturn_t DECLDIR nvmlDeviceRemoveGpu_v2(nvmlPciInfo_t *pciInfo, nvmlDetachGpuState_t gpuState, nvmlPcieLinkState_t linkState); /** * Request the OS and the NVIDIA kernel driver to rediscover a portion of the PCI subsystem looking for GPUs that - * were previously removed. The portion of the PCI tree can be narrowed by specifying a domain, bus, and device. + * were previously removed. The portion of the PCI tree can be narrowed by specifying a domain, bus, and device. * If all are zeroes then the entire PCI tree will be searched. Please note that for long-running NVML processes * the enumeration will change based on how many GPUs are discovered and where they are inserted in bus order. * @@ -4925,14 +7527,14 @@ nvmlReturn_t DECLDIR nvmlDeviceRemoveGpu (nvmlPciInfo_t *pciInfo); * * Must be run as administrator. * For Linux only. - * + * * For Pascal &tm; or newer fully supported devices. * Some Kepler devices supported. * * @param pciInfo The PCI tree to be searched. Only the domain, bus, and device * fields are used in this call. * - * @return + * @return * - \ref NVML_SUCCESS if counters were successfully reset * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pciInfo is invalid @@ -4970,12 +7572,34 @@ nvmlReturn_t DECLDIR nvmlDeviceDiscoverGpus (nvmlPciInfo_t *pciInfo); */ nvmlReturn_t DECLDIR nvmlDeviceGetFieldValues(nvmlDevice_t device, int valuesCount, nvmlFieldValue_t *values); +/** + * Clear values for a list of fields for a device. This API allows multiple fields to be cleared at once. + * + * @param device The device handle of the GPU to request field values for + * @param valuesCount Number of entries in values that should be cleared + * @param values Array of \a valuesCount structures to hold field values. + * Each value's fieldId must be populated prior to this call + * + * @return + * - \ref NVML_SUCCESS if any values in \a values were cleared. Note that you must + * check the nvmlReturn field of each value for each individual + * status + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a values is NULL + */ +nvmlReturn_t DECLDIR nvmlDeviceClearFieldValues(nvmlDevice_t device, int valuesCount, nvmlFieldValue_t *values); /** @} */ /***************************************************************************************************/ -/** @defgroup nvmlGridQueries Grid Queries - * This chapter describes NVML operations that are associated with NVIDIA GRID products. +/** @defgroup vGPU Enums, Constants and Structs + * @{ + */ +/** @} */ +/***************************************************************************************************/ + +/***************************************************************************************************/ +/** @defgroup nvmlVirtualGpuQueries vGPU APIs + * This chapter describes operations that are associated with NVIDIA vGPU Software products. * @{ */ /***************************************************************************************************/ @@ -4987,8 +7611,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetFieldValues(nvmlDevice_t device, int valuesCou * * @param device Identifier of the target device * @param pVirtualMode Reference to virtualization mode. One of NVML_GPU_VIRTUALIZATION_? - * - * @return + * + * @return * - \ref NVML_SUCCESS if \a pVirtualMode is fetched * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pVirtualMode is NULL @@ -4997,14 +7621,23 @@ nvmlReturn_t DECLDIR nvmlDeviceGetFieldValues(nvmlDevice_t device, int valuesCou */ nvmlReturn_t DECLDIR nvmlDeviceGetVirtualizationMode(nvmlDevice_t device, nvmlGpuVirtualizationMode_t *pVirtualMode); -/** @} */ - -/***************************************************************************************************/ -/** @defgroup nvmlGridCommands Grid Commands - * This chapter describes NVML operations that are associated with NVIDIA GRID products. - * @{ +/** + * Queries if SR-IOV host operation is supported on a vGPU supported device. + * + * Checks whether SR-IOV host capability is supported by the device and the + * driver, and indicates device is in SR-IOV mode if both of these conditions + * are true. + * + * @param device The identifier of the target device + * @param pHostVgpuMode Reference in which to return the current vGPU mode + * + * @return + * - \ref NVML_SUCCESS if device's vGPU mode has been successfully retrieved + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device handle is 0 or \a pVgpuMode is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if \a device doesn't support this feature. + * - \ref NVML_ERROR_UNKNOWN if any unexpected error occurred */ -/***************************************************************************************************/ +nvmlReturn_t DECLDIR nvmlDeviceGetHostVgpuMode(nvmlDevice_t device, nvmlHostVgpuMode_t *pHostVgpuMode); /** * This method is used to set the virtualization mode corresponding to the GPU. @@ -5014,7 +7647,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetVirtualizationMode(nvmlDevice_t device, nvmlGp * @param device Identifier of the target device * @param virtualMode virtualization mode. One of NVML_GPU_VIRTUALIZATION_? * - * @return + * @return * - \ref NVML_SUCCESS if \a pVirtualMode is set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a pVirtualMode is NULL @@ -5024,16 +7657,75 @@ nvmlReturn_t DECLDIR nvmlDeviceGetVirtualizationMode(nvmlDevice_t device, nvmlGp */ nvmlReturn_t DECLDIR nvmlDeviceSetVirtualizationMode(nvmlDevice_t device, nvmlGpuVirtualizationMode_t virtualMode); +/** + * Retrieve the vGPU Software licensable features. + * + * Identifies whether the system supports vGPU Software Licensing. If it does, return the list of licensable feature(s) + * and their current license status. + * + * @param device Identifier of the target device + * @param pGridLicensableFeatures Pointer to structure in which vGPU software licensable features are returned + * + * @return + * - \ref NVML_SUCCESS if licensable features are successfully retrieved + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pGridLicensableFeatures is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGridLicensableFeatures_v4(nvmlDevice_t device, nvmlGridLicensableFeatures_t *pGridLicensableFeatures); + /** @} */ /***************************************************************************************************/ /** @defgroup nvmlVgpu vGPU Management * @{ * - * Set of APIs supporting GRID vGPU + * This chapter describes APIs supporting NVIDIA vGPU. */ /***************************************************************************************************/ +/** + * Retrieve the requested vGPU driver capability. + * + * Refer to the \a nvmlVgpuDriverCapability_t structure for the specific capabilities that can be queried. + * The return value in \a capResult should be treated as a boolean, with a non-zero value indicating that the capability + * is supported. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param capability Specifies the \a nvmlVgpuDriverCapability_t to be queried + * @param capResult A boolean for the queried capability indicating that feature is supported + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a capability is invalid, or \a capResult is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED the API is not supported in current state or \a devices not in vGPU mode + * - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlGetVgpuDriverCapabilities(nvmlVgpuDriverCapability_t capability, unsigned int *capResult); + +/** + * Retrieve the requested vGPU capability for GPU. + * + * Refer to the \a nvmlDeviceVgpuCapability_t structure for the specific capabilities that can be queried. + * The return value in \a capResult reports a non-zero value indicating that the capability + * is supported, and also reports the capability's data based on the queried capability. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param device The identifier of the target device + * @param capability Specifies the \a nvmlDeviceVgpuCapability_t to be queried + * @param capResult Specifies that the queried capability is supported, and also returns capability's data + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a capability is invalid, or \a capResult is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED the API is not supported in current state or \a device not in vGPU mode + * - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlDeviceGetVgpuCapabilities(nvmlDevice_t device, nvmlDeviceVgpuCapability_t capability, unsigned int *capResult); + /** * Retrieve the supported vGPU types on a physical GPU (device). * @@ -5055,8 +7747,7 @@ nvmlReturn_t DECLDIR nvmlDeviceSetVirtualizationMode(nvmlDevice_t device, nvmlGp * - \ref NVML_ERROR_INSUFFICIENT_SIZE \a vgpuTypeIds buffer is too small, array element count is returned in \a vgpuCount * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuCount is NULL or \a device is invalid * - \ref NVML_ERROR_NOT_SUPPORTED if vGPU is not supported by the device - * - \ref NVML_ERROR_VGPU_ECC_NOT_SUPPORTED if ECC is enabled on the device - * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlDeviceGetSupportedVgpus(nvmlDevice_t device, unsigned int *vgpuCount, nvmlVgpuTypeId_t *vgpuTypeIds); @@ -5073,7 +7764,7 @@ nvmlReturn_t DECLDIR nvmlDeviceGetSupportedVgpus(nvmlDevice_t device, unsigned i * * If the supplied buffer is not large enough to accommodate the vGPU type array, the function returns * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlVgpuTypeId_t array required in \a vgpuCount. - * To query the number of vGPU types createable for the GPU, call this function with *vgpuCount = 0. + * To query the number of vGPU types that can be created for the GPU, call this function with *vgpuCount = 0. * The code will return NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if no vGPU types are creatable. * * @param device The identifier of the target device @@ -5085,7 +7776,6 @@ nvmlReturn_t DECLDIR nvmlDeviceGetSupportedVgpus(nvmlDevice_t device, unsigned i * - \ref NVML_ERROR_INSUFFICIENT_SIZE \a vgpuTypeIds buffer is too small, array element count is returned in \a vgpuCount * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuCount is NULL * - \ref NVML_ERROR_NOT_SUPPORTED if vGPU is not supported by the device - * - \ref NVML_ERROR_VGPU_ECC_NOT_SUPPORTED if ECC is enabled on the device * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlDeviceGetCreatableVgpus(nvmlDevice_t device, unsigned int *vgpuCount, nvmlVgpuTypeId_t *vgpuTypeIds); @@ -5129,6 +7819,24 @@ nvmlReturn_t DECLDIR nvmlVgpuTypeGetClass(nvmlVgpuTypeId_t vgpuTypeId, char *vgp */ nvmlReturn_t DECLDIR nvmlVgpuTypeGetName(nvmlVgpuTypeId_t vgpuTypeId, char *vgpuTypeName, unsigned int *size); +/** + * Retrieve the GPU Instance Profile ID for the given vGPU type ID. + * The API will return a valid GPU Instance Profile ID for the MIG capable vGPU types, else INVALID_GPU_INSTANCE_PROFILE_ID is + * returned. + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param gpuInstanceProfileId GPU Instance Profile ID + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_NOT_SUPPORTED if \a device is not in vGPU Host virtualization mode + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a gpuInstanceProfileId is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetGpuInstanceProfileId(nvmlVgpuTypeId_t vgpuTypeId, unsigned int *gpuInstanceProfileId); + /** * Retrieve the device ID of a vGPU type. * @@ -5233,7 +7941,7 @@ nvmlReturn_t DECLDIR nvmlVgpuTypeGetLicense(nvmlVgpuTypeId_t vgpuTypeId, char *v * - \ref NVML_SUCCESS successful completion * - \ref NVML_ERROR_NOT_SUPPORTED if frame rate limiter is turned off for the vGPU type * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, or \a frameRateLimit is NULL + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a frameRateLimit is NULL * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlVgpuTypeGetFrameRateLimit(nvmlVgpuTypeId_t vgpuTypeId, unsigned int *frameRateLimit); @@ -5256,11 +7964,26 @@ nvmlReturn_t DECLDIR nvmlVgpuTypeGetFrameRateLimit(nvmlVgpuTypeId_t vgpuTypeId, */ nvmlReturn_t DECLDIR nvmlVgpuTypeGetMaxInstances(nvmlDevice_t device, nvmlVgpuTypeId_t vgpuTypeId, unsigned int *vgpuInstanceCount); +/** + * Retrieve the maximum number of vGPU instances supported per VM for given vGPU type + * + * For Kepler &tm; or newer fully supported devices. + * + * @param vgpuTypeId Handle to vGPU type + * @param vgpuInstanceCountPerVm Pointer to get the max number of vGPU instances supported per VM for given \a vgpuTypeId + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a vgpuInstanceCountPerVm is NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetMaxInstancesPerVm(nvmlVgpuTypeId_t vgpuTypeId, unsigned int *vgpuInstanceCountPerVm); + /** * Retrieve the active vGPU instances on a device. * * An array of active vGPU instances is returned in the caller-supplied buffer pointed at by \a vgpuInstances. The - * array elememt count is passed in \a vgpuCount, and \a vgpuCount is used to return the number of vGPU instances + * array element count is passed in \a vgpuCount, and \a vgpuCount is used to return the number of vGPU instances * written to the buffer. * * If the supplied buffer is not large enough to accommodate the vGPU instance array, the function returns @@ -5303,7 +8026,8 @@ nvmlReturn_t DECLDIR nvmlDeviceGetActiveVgpus(nvmlDevice_t device, unsigned int * @return * - \ref NVML_SUCCESS successful completion * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a vmId or \a vmIdType are NULL + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vmId or \a vmIdType is NULL, or \a vgpuInstance is 0 + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a size is too small * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ @@ -5325,7 +8049,8 @@ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetVmID(nvmlVgpuInstance_t vgpuInstance, ch * @return * - \ref NVML_SUCCESS successful completion * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a uuid is NULL + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a uuid is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a size is too small * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ @@ -5339,7 +8064,7 @@ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetUUID(nvmlVgpuInstance_t vgpuInstance, ch * See \ref nvmlConstants::NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE. * * nvmlVgpuInstanceGetVmDriverVersion() may be called at any time for a vGPU instance. The guest VM driver version is - * returned as "Unknown" if no NVIDIA driver is installed in the VM, or the VM has not yet booted to the point where the + * returned as "Not Available" if no NVIDIA driver is installed in the VM, or the VM has not yet booted to the point where the * NVIDIA driver is loaded and initialized. * * For Kepler &tm; or newer fully supported devices. @@ -5351,7 +8076,8 @@ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetUUID(nvmlVgpuInstance_t vgpuInstance, ch * @return * - \ref NVML_SUCCESS if \a version has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0 + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ @@ -5370,12 +8096,15 @@ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetVmDriverVersion(nvmlVgpuInstance_t vgpuI * @return * - \ref NVML_SUCCESS successful completion * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a fbUsage is NULL + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a fbUsage is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetFbUsage(nvmlVgpuInstance_t vgpuInstance, unsigned long long *fbUsage); /** + * @deprecated Use \ref nvmlVgpuInstanceGetLicenseInfo_v2. + * * Retrieve the current licensing state of the vGPU instance. * * If the vGPU is currently licensed, \a licensed is set to 1, otherwise it is set to 0. @@ -5388,7 +8117,8 @@ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetFbUsage(nvmlVgpuInstance_t vgpuInstance, * @return * - \ref NVML_SUCCESS if \a licensed has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a licensed is NULL + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a licensed is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetLicenseStatus(nvmlVgpuInstance_t vgpuInstance, unsigned int *licensed); @@ -5406,7 +8136,8 @@ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetLicenseStatus(nvmlVgpuInstance_t vgpuIns * @return * - \ref NVML_SUCCESS if \a vgpuTypeId has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a vgpuTypeId is NULL + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a vgpuTypeId is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetType(nvmlVgpuInstance_t vgpuInstance, nvmlVgpuTypeId_t *vgpuTypeId); @@ -5425,13 +8156,30 @@ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetType(nvmlVgpuInstance_t vgpuInstance, nv * - \ref NVML_SUCCESS if \a frameRateLimit has been set * - \ref NVML_ERROR_NOT_SUPPORTED if frame rate limiter is turned off for the vGPU type * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a frameRateLimit is NULL + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a frameRateLimit is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetFrameRateLimit(nvmlVgpuInstance_t vgpuInstance, unsigned int *frameRateLimit); /** - * Retrieve the encoder Capacity of a vGPU instance, in macroblocks per second. + * Retrieve the current ECC mode of vGPU instance. + * + * @param vgpuInstance The identifier of the target vGPU instance + * @param eccMode Reference in which to return the current ECC mode + * + * @return + * - \ref NVML_SUCCESS if the vgpuInstance's ECC mode has been successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a mode is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system + * - \ref NVML_ERROR_NOT_SUPPORTED if the vGPU doesn't support this feature + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEccMode(nvmlVgpuInstance_t vgpuInstance, nvmlEnableState_t *eccMode); + +/** + * Retrieve the encoder capacity of a vGPU instance, as a percentage of maximum encoder capacity with valid values in the range 0-100. * * For Maxwell &tm; or newer fully supported devices. * @@ -5441,13 +8189,14 @@ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetFrameRateLimit(nvmlVgpuInstance_t vgpuIn * @return * - \ref NVML_SUCCESS if \a encoderCapacity has been retrieved * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid, or \a encoderQueryType is invalid + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a encoderQueryType is invalid + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEncoderCapacity(nvmlVgpuInstance_t vgpuInstance, unsigned int *encoderCapacity); /** - * Set the encoder Capacity of a vGPU instance, in macroblocks per second. + * Set the encoder capacity of a vGPU instance, as a percentage of maximum encoder capacity with valid values in the range 0-100. * * For Maxwell &tm; or newer fully supported devices. * @@ -5457,11 +8206,525 @@ nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEncoderCapacity(nvmlVgpuInstance_t vgpuI * @return * - \ref NVML_SUCCESS if \a encoderCapacity has been set * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a encoderCapacity is out of range of 0-100. + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ nvmlReturn_t DECLDIR nvmlVgpuInstanceSetEncoderCapacity(nvmlVgpuInstance_t vgpuInstance, unsigned int encoderCapacity); +/** + * Retrieves the current encoder statistics of a vGPU Instance + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param sessionCount Reference to an unsigned int for count of active encoder sessions + * @param averageFps Reference to an unsigned int for trailing average FPS of all active sessions + * @param averageLatency Reference to an unsigned int for encode latency in microseconds + * + * @return + * - \ref NVML_SUCCESS if \a sessionCount, \a averageFps and \a averageLatency is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount , or \a averageFps or \a averageLatency is NULL + * or \a vgpuInstance is 0. + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEncoderStats(nvmlVgpuInstance_t vgpuInstance, unsigned int *sessionCount, + unsigned int *averageFps, unsigned int *averageLatency); + +/** + * Retrieves information about all active encoder sessions on a vGPU Instance. + * + * An array of active encoder sessions is returned in the caller-supplied buffer pointed at by \a sessionInfo. The + * array element count is passed in \a sessionCount, and \a sessionCount is used to return the number of sessions + * written to the buffer. + * + * If the supplied buffer is not large enough to accommodate the active session array, the function returns + * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlEncoderSessionInfo_t array required in \a sessionCount. + * To query the number of active encoder sessions, call this function with *sessionCount = 0. The code will return + * NVML_SUCCESS with number of active encoder sessions updated in *sessionCount. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param sessionCount Reference to caller supplied array size, and returns + * the number of sessions. + * @param sessionInfo Reference to caller supplied array in which the list + * of session information us returned. + * + * @return + * - \ref NVML_SUCCESS if \a sessionInfo is fetched + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a sessionCount is too small, array element count is + returned in \a sessionCount + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount is NULL, or \a vgpuInstance is 0. + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEncoderSessions(nvmlVgpuInstance_t vgpuInstance, unsigned int *sessionCount, nvmlEncoderSessionInfo_t *sessionInfo); + +/** +* Retrieves the active frame buffer capture sessions statistics of a vGPU Instance +* +* For Maxwell &tm; or newer fully supported devices. +* +* @param vgpuInstance Identifier of the target vGPU instance +* @param fbcStats Reference to nvmlFBCStats_t structure containing NvFBC stats +* +* @return +* - \ref NVML_SUCCESS if \a fbcStats is fetched +* - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized +* - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a fbcStats is NULL +* - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system +* - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetFBCStats(nvmlVgpuInstance_t vgpuInstance, nvmlFBCStats_t *fbcStats); + +/** +* Retrieves information about active frame buffer capture sessions on a vGPU Instance. +* +* An array of active FBC sessions is returned in the caller-supplied buffer pointed at by \a sessionInfo. The +* array element count is passed in \a sessionCount, and \a sessionCount is used to return the number of sessions +* written to the buffer. +* +* If the supplied buffer is not large enough to accommodate the active session array, the function returns +* NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlFBCSessionInfo_t array required in \a sessionCount. +* To query the number of active FBC sessions, call this function with *sessionCount = 0. The code will return +* NVML_SUCCESS with number of active FBC sessions updated in *sessionCount. +* +* For Maxwell &tm; or newer fully supported devices. +* +* @note hResolution, vResolution, averageFPS and averageLatency data for a FBC session returned in \a sessionInfo may +* be zero if there are no new frames captured since the session started. +* +* @param vgpuInstance Identifier of the target vGPU instance +* @param sessionCount Reference to caller supplied array size, and returns the number of sessions. +* @param sessionInfo Reference in which to return the session information +* +* @return +* - \ref NVML_SUCCESS if \a sessionInfo is fetched +* - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized +* - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a sessionCount is NULL. +* - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system +* - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a sessionCount is too small, array element count is returned in \a sessionCount +* - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetFBCSessions(nvmlVgpuInstance_t vgpuInstance, unsigned int *sessionCount, nvmlFBCSessionInfo_t *sessionInfo); + +/** +* Retrieve the GPU Instance ID for the given vGPU Instance. +* The API will return a valid GPU Instance ID for MIG backed vGPU Instance, else INVALID_GPU_INSTANCE_ID is returned. +* +* For Kepler &tm; or newer fully supported devices. +* +* @param vgpuInstance Identifier of the target vGPU instance +* @param gpuInstanceId GPU Instance ID +* +* @return +* - \ref NVML_SUCCESS successful completion +* - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized +* - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a gpuInstanceId is NULL. +* - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system +* - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetGpuInstanceId(nvmlVgpuInstance_t vgpuInstance, unsigned int *gpuInstanceId); + +/** +* Retrieves the PCI Id of the given vGPU Instance i.e. the PCI Id of the GPU as seen inside the VM. +* +* The vGPU PCI id is returned as "00000000:00:00.0" if NVIDIA driver is not installed on the vGPU instance. +* +* @param vgpuInstance Identifier of the target vGPU instance +* @param vgpuPciId Caller-supplied buffer to return vGPU PCI Id string +* @param length Size of the vgpuPciId buffer +* +* @return +* - \ref NVML_SUCCESS if vGPU PCI Id is sucessfully retrieved +* - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized +* - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a vgpuPciId is NULL +* - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system +* - \ref NVML_ERROR_DRIVER_NOT_LOADED if NVIDIA driver is not running on the vGPU instance +* - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a length is too small, \a length is set to required length +* - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetGpuPciId(nvmlVgpuInstance_t vgpuInstance, char *vgpuPciId, unsigned int *length); + +/** +* Retrieve the requested capability for a given vGPU type. Refer to the \a nvmlVgpuCapability_t structure +* for the specific capabilities that can be queried. The return value in \a capResult should be treated as +* a boolean, with a non-zero value indicating that the capability is supported. +* +* For Maxwell &tm; or newer fully supported devices. +* +* @param vgpuTypeId Handle to vGPU type +* @param capability Specifies the \a nvmlVgpuCapability_t to be queried +* @param capResult A boolean for the queried capability indicating that feature is supported +* +* @return +* - \ref NVML_SUCCESS successful completion +* - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized +* - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuTypeId is invalid, or \a capability is invalid, or \a capResult is NULL +* - \ref NVML_ERROR_UNKNOWN on any unexpected error +*/ +nvmlReturn_t DECLDIR nvmlVgpuTypeGetCapabilities(nvmlVgpuTypeId_t vgpuTypeId, nvmlVgpuCapability_t capability, unsigned int *capResult); + +/** + * Retrieve the MDEV UUID of a vGPU instance. + * + * The MDEV UUID is a globally unique identifier of the mdev device assigned to the VM, and is returned as a 5-part hexadecimal string, + * not exceeding 80 characters in length (including the NULL terminator). + * MDEV UUID is displayed only on KVM platform. + * See \ref nvmlConstants::NVML_DEVICE_UUID_BUFFER_SIZE. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param mdevUuid Pointer to caller-supplied buffer to hold MDEV UUID + * @param size Size of buffer in bytes + * + * @return + * - \ref NVML_SUCCESS successful completion + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_NOT_SUPPORTED on any hypervisor other than KVM + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a mdevUuid is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a size is too small + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetMdevUUID(nvmlVgpuInstance_t vgpuInstance, char *mdevUuid, unsigned int size); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvml vGPU Migration + * This chapter describes operations that are associated with vGPU Migration. + * @{ + */ +/***************************************************************************************************/ + +/** + * Structure representing range of vGPU versions. + */ +typedef struct nvmlVgpuVersion_st +{ + unsigned int minVersion; //!< Minimum vGPU version. + unsigned int maxVersion; //!< Maximum vGPU version. +} nvmlVgpuVersion_t; + +/** + * vGPU metadata structure. + */ +typedef struct nvmlVgpuMetadata_st +{ + unsigned int version; //!< Current version of the structure + unsigned int revision; //!< Current revision of the structure + nvmlVgpuGuestInfoState_t guestInfoState; //!< Current state of Guest-dependent fields + char guestDriverVersion[NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE]; //!< Version of driver installed in guest + char hostDriverVersion[NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE]; //!< Version of driver installed in host + unsigned int reserved[6]; //!< Reserved for internal use + unsigned int vgpuVirtualizationCaps; //!< vGPU virtualization capabilities bitfield + unsigned int guestVgpuVersion; //!< vGPU version of guest driver + unsigned int opaqueDataSize; //!< Size of opaque data field in bytes + char opaqueData[4]; //!< Opaque data +} nvmlVgpuMetadata_t; + +/** + * Physical GPU metadata structure + */ +typedef struct nvmlVgpuPgpuMetadata_st +{ + unsigned int version; //!< Current version of the structure + unsigned int revision; //!< Current revision of the structure + char hostDriverVersion[NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE]; //!< Host driver version + unsigned int pgpuVirtualizationCaps; //!< Pgpu virtualization capabilities bitfield + unsigned int reserved[5]; //!< Reserved for internal use + nvmlVgpuVersion_t hostSupportedVgpuRange; //!< vGPU version range supported by host driver + unsigned int opaqueDataSize; //!< Size of opaque data field in bytes + char opaqueData[4]; //!< Opaque data +} nvmlVgpuPgpuMetadata_t; + +/** + * vGPU VM compatibility codes + */ +typedef enum nvmlVgpuVmCompatibility_enum +{ + NVML_VGPU_VM_COMPATIBILITY_NONE = 0x0, //!< vGPU is not runnable + NVML_VGPU_VM_COMPATIBILITY_COLD = 0x1, //!< vGPU is runnable from a cold / powered-off state (ACPI S5) + NVML_VGPU_VM_COMPATIBILITY_HIBERNATE = 0x2, //!< vGPU is runnable from a hibernated state (ACPI S4) + NVML_VGPU_VM_COMPATIBILITY_SLEEP = 0x4, //!< vGPU is runnable from a sleeped state (ACPI S3) + NVML_VGPU_VM_COMPATIBILITY_LIVE = 0x8 //!< vGPU is runnable from a live/paused (ACPI S0) +} nvmlVgpuVmCompatibility_t; + +/** + * vGPU-pGPU compatibility limit codes + */ +typedef enum nvmlVgpuPgpuCompatibilityLimitCode_enum +{ + NVML_VGPU_COMPATIBILITY_LIMIT_NONE = 0x0, //!< Compatibility is not limited. + NVML_VGPU_COMPATIBILITY_LIMIT_HOST_DRIVER = 0x1, //!< ompatibility is limited by host driver version. + NVML_VGPU_COMPATIBILITY_LIMIT_GUEST_DRIVER = 0x2, //!< Compatibility is limited by guest driver version. + NVML_VGPU_COMPATIBILITY_LIMIT_GPU = 0x4, //!< Compatibility is limited by GPU hardware. + NVML_VGPU_COMPATIBILITY_LIMIT_OTHER = 0x80000000 //!< Compatibility is limited by an undefined factor. +} nvmlVgpuPgpuCompatibilityLimitCode_t; + +/** + * vGPU-pGPU compatibility structure + */ +typedef struct nvmlVgpuPgpuCompatibility_st +{ + nvmlVgpuVmCompatibility_t vgpuVmCompatibility; //!< Compatibility of vGPU VM. See \ref nvmlVgpuVmCompatibility_t + nvmlVgpuPgpuCompatibilityLimitCode_t compatibilityLimitCode; //!< Limiting factor for vGPU-pGPU compatibility. See \ref nvmlVgpuPgpuCompatibilityLimitCode_t +} nvmlVgpuPgpuCompatibility_t; + +/** + * Returns vGPU metadata structure for a running vGPU. The structure contains information about the vGPU and its associated VM + * such as the currently installed NVIDIA guest driver version, together with host driver version and an opaque data section + * containing internal state. + * + * nvmlVgpuInstanceGetMetadata() may be called at any time for a vGPU instance. Some fields in the returned structure are + * dependent on information obtained from the guest VM, which may not yet have reached a state where that information + * is available. The current state of these dependent fields is reflected in the info structure's \ref nvmlVgpuGuestInfoState_t field. + * + * The VMM may choose to read and save the vGPU's VM info as persistent metadata associated with the VM, and provide + * it to Virtual GPU Manager when creating a vGPU for subsequent instances of the VM. + * + * The caller passes in a buffer via \a vgpuMetadata, with the size of the buffer in \a bufferSize. If the vGPU Metadata structure + * is too large to fit in the supplied buffer, the function returns NVML_ERROR_INSUFFICIENT_SIZE with the size needed + * in \a bufferSize. + * + * @param vgpuInstance vGPU instance handle + * @param vgpuMetadata Pointer to caller-supplied buffer into which vGPU metadata is written + * @param bufferSize Size of vgpuMetadata buffer + * + * @return + * - \ref NVML_SUCCESS vGPU metadata structure was successfully returned + * - \ref NVML_ERROR_INSUFFICIENT_SIZE vgpuMetadata buffer is too small, required size is returned in \a bufferSize + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a bufferSize is NULL or \a vgpuInstance is 0; if \a vgpuMetadata is NULL and the value of \a bufferSize is not 0. + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetMetadata(nvmlVgpuInstance_t vgpuInstance, nvmlVgpuMetadata_t *vgpuMetadata, unsigned int *bufferSize); + +/** + * Returns a vGPU metadata structure for the physical GPU indicated by \a device. The structure contains information about + * the GPU and the currently installed NVIDIA host driver version that's controlling it, together with an opaque data section + * containing internal state. + * + * The caller passes in a buffer via \a pgpuMetadata, with the size of the buffer in \a bufferSize. If the \a pgpuMetadata + * structure is too large to fit in the supplied buffer, the function returns NVML_ERROR_INSUFFICIENT_SIZE with the size needed + * in \a bufferSize. + * + * @param device The identifier of the target device + * @param pgpuMetadata Pointer to caller-supplied buffer into which \a pgpuMetadata is written + * @param bufferSize Pointer to size of \a pgpuMetadata buffer + * + * @return + * - \ref NVML_SUCCESS GPU metadata structure was successfully returned + * - \ref NVML_ERROR_INSUFFICIENT_SIZE pgpuMetadata buffer is too small, required size is returned in \a bufferSize + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a bufferSize is NULL or \a device is invalid; if \a pgpuMetadata is NULL and the value of \a bufferSize is not 0. + * - \ref NVML_ERROR_NOT_SUPPORTED vGPU is not supported by the system + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetVgpuMetadata(nvmlDevice_t device, nvmlVgpuPgpuMetadata_t *pgpuMetadata, unsigned int *bufferSize); + +/** + * Takes a vGPU instance metadata structure read from \ref nvmlVgpuInstanceGetMetadata(), and a vGPU metadata structure for a + * physical GPU read from \ref nvmlDeviceGetVgpuMetadata(), and returns compatibility information of the vGPU instance and the + * physical GPU. + * + * The caller passes in a buffer via \a compatibilityInfo, into which a compatibility information structure is written. The + * structure defines the states in which the vGPU / VM may be booted on the physical GPU. If the vGPU / VM compatibility + * with the physical GPU is limited, a limit code indicates the factor limiting compatability. + * (see \ref nvmlVgpuPgpuCompatibilityLimitCode_t for details). + * + * Note: vGPU compatibility does not take into account dynamic capacity conditions that may limit a system's ability to + * boot a given vGPU or associated VM. + * + * @param vgpuMetadata Pointer to caller-supplied vGPU metadata structure + * @param pgpuMetadata Pointer to caller-supplied GPU metadata structure + * @param compatibilityInfo Pointer to caller-supplied buffer to hold compatibility info + * + * @return + * - \ref NVML_SUCCESS vGPU metadata structure was successfully returned + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuMetadata or \a pgpuMetadata or \a bufferSize are NULL + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlGetVgpuCompatibility(nvmlVgpuMetadata_t *vgpuMetadata, nvmlVgpuPgpuMetadata_t *pgpuMetadata, nvmlVgpuPgpuCompatibility_t *compatibilityInfo); + +/** + * Returns the properties of the physical GPU indicated by the device in an ascii-encoded string format. + * + * The caller passes in a buffer via \a pgpuMetadata, with the size of the buffer in \a bufferSize. If the + * string is too large to fit in the supplied buffer, the function returns NVML_ERROR_INSUFFICIENT_SIZE with the size needed + * in \a bufferSize. + * + * @param device The identifier of the target device + * @param pgpuMetadata Pointer to caller-supplied buffer into which \a pgpuMetadata is written + * @param bufferSize Pointer to size of \a pgpuMetadata buffer + * + * @return + * - \ref NVML_SUCCESS GPU metadata structure was successfully returned + * - \ref NVML_ERROR_INSUFFICIENT_SIZE \a pgpuMetadata buffer is too small, required size is returned in \a bufferSize + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a bufferSize is NULL or \a device is invalid; if \a pgpuMetadata is NULL and the value of \a bufferSize is not 0. + * - \ref NVML_ERROR_NOT_SUPPORTED if vGPU is not supported by the system + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetPgpuMetadataString(nvmlDevice_t device, char *pgpuMetadata, unsigned int *bufferSize); + +/** + * Returns the vGPU Software scheduler logs. + * \a pSchedulerLog points to a caller-allocated structure to contain the logs. The number of elements returned will + * never exceed \a NVML_SCHEDULER_SW_MAX_LOG_ENTRIES. + * + * To get the entire logs, call the function atleast 5 times a second. + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target \a device + * @param pSchedulerLog Reference in which \a pSchedulerLog is written + * + * @return + * - \ref NVML_SUCCESS vGPU scheduler logs were successfully obtained + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pSchedulerLog is NULL or \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED The API is not supported in current state or \a device not in vGPU host mode + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetVgpuSchedulerLog(nvmlDevice_t device, nvmlVgpuSchedulerLog_t *pSchedulerLog); + +/** + * Returns the vGPU scheduler state. + * The information returned in \a nvmlVgpuSchedulerGetState_t is not relevant if the BEST EFFORT policy is set. + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target \a device + * @param pSchedulerState Reference in which \a pSchedulerState is returned + * + * @return + * - \ref NVML_SUCCESS vGPU scheduler state is successfully obtained + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pSchedulerState is NULL or \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED The API is not supported in current state or \a device not in vGPU host mode + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetVgpuSchedulerState(nvmlDevice_t device, nvmlVgpuSchedulerGetState_t *pSchedulerState); + +/** + * Returns the vGPU scheduler capabilities. + * The list of supported vGPU schedulers returned in \a nvmlVgpuSchedulerCapabilities_t is from + * the NVML_VGPU_SCHEDULER_POLICY_*. This list enumerates the supported scheduler policies + * if the engine is Graphics type. + * The other values in \a nvmlVgpuSchedulerCapabilities_t are also applicable if the engine is + * Graphics type. For other engine types, it is BEST EFFORT policy. + * If ARR is supported and enabled, scheduling frequency and averaging factor are applicable + * else timeSlice is applicable. + * + * For Pascal &tm; or newer fully supported devices. + * + * @param device The identifier of the target \a device + * @param pCapabilities Reference in which \a pCapabilities is written + * + * @return + * - \ref NVML_SUCCESS vGPU scheduler capabilities were successfully obtained + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pCapabilities is NULL or \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED The API is not supported in current state or \a device not in vGPU host mode + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetVgpuSchedulerCapabilities(nvmlDevice_t device, nvmlVgpuSchedulerCapabilities_t *pCapabilities); + +/** + * Sets the vGPU scheduler state. + * + * For Pascal &tm; or newer fully supported devices. + * + * The scheduler state change won't persist across module load/unload. + * Scheduler state and params will be allowed to set only when no VM is running. + * In \a nvmlVgpuSchedulerSetState_t, IFF enableARRMode is enabled then + * provide avgFactorForARR and frequency as input. If enableARRMode is disabled + * then provide timeslice as input. + * + * @param device The identifier of the target \a device + * @param pSchedulerState vGPU \a pSchedulerState to set + * + * @return + * - \ref NVML_SUCCESS vGPU scheduler state has been successfully set + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pSchedulerState is NULL or \a device is invalid + * - \ref NVML_ERROR_RESET_REQUIRED if setting \a pSchedulerState failed with fatal error, + * reboot is required to overcome from this error. + * - \ref NVML_ERROR_NOT_SUPPORTED The API is not supported in current state or \a device not in vGPU host mode + * or if any vGPU instance currently exists on the \a device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceSetVgpuSchedulerState(nvmlDevice_t device, nvmlVgpuSchedulerSetState_t *pSchedulerState); + +/* + * Virtual GPU (vGPU) version + * + * The NVIDIA vGPU Manager and the guest drivers are tagged with a range of supported vGPU versions. This determines the range of NVIDIA guest driver versions that + * are compatible for vGPU feature support with a given NVIDIA vGPU Manager. For vGPU feature support, the range of supported versions for the NVIDIA vGPU Manager + * and the guest driver must overlap. Otherwise, the guest driver fails to load in the VM. + * + * When the NVIDIA guest driver loads, either when the VM is booted or when the driver is installed or upgraded, a negotiation occurs between the guest driver + * and the NVIDIA vGPU Manager to select the highest mutually compatible vGPU version. The negotiated vGPU version stays the same across VM migration. + */ + +/** + * Query the ranges of supported vGPU versions. + * + * This function gets the linear range of supported vGPU versions that is preset for the NVIDIA vGPU Manager and the range set by an administrator. + * If the preset range has not been overridden by \ref nvmlSetVgpuVersion, both ranges are the same. + * + * The caller passes pointers to the following \ref nvmlVgpuVersion_t structures, into which the NVIDIA vGPU Manager writes the ranges: + * 1. \a supported structure that represents the preset range of vGPU versions supported by the NVIDIA vGPU Manager. + * 2. \a current structure that represents the range of supported vGPU versions set by an administrator. By default, this range is the same as the preset range. + * + * @param supported Pointer to the structure in which the preset range of vGPU versions supported by the NVIDIA vGPU Manager is written + * @param current Pointer to the structure in which the range of supported vGPU versions set by an administrator is written + * + * @return + * - \ref NVML_SUCCESS The vGPU version range structures were successfully obtained. + * - \ref NVML_ERROR_NOT_SUPPORTED The API is not supported. + * - \ref NVML_ERROR_INVALID_ARGUMENT The \a supported parameter or the \a current parameter is NULL. + * - \ref NVML_ERROR_UNKNOWN An error occurred while the data was being fetched. + */ +nvmlReturn_t DECLDIR nvmlGetVgpuVersion(nvmlVgpuVersion_t *supported, nvmlVgpuVersion_t *current); + +/** + * Override the preset range of vGPU versions supported by the NVIDIA vGPU Manager with a range set by an administrator. + * + * This function configures the NVIDIA vGPU Manager with a range of supported vGPU versions set by an administrator. This range must be a subset of the + * preset range that the NVIDIA vGPU Manager supports. The custom range set by an administrator takes precedence over the preset range and is advertised to + * the guest VM for negotiating the vGPU version. See \ref nvmlGetVgpuVersion for details of how to query the preset range of versions supported. + * + * This function takes a pointer to vGPU version range structure \ref nvmlVgpuVersion_t as input to override the preset vGPU version range that the NVIDIA vGPU Manager supports. + * + * After host system reboot or driver reload, the range of supported versions reverts to the range that is preset for the NVIDIA vGPU Manager. + * + * @note 1. The range set by the administrator must be a subset of the preset range that the NVIDIA vGPU Manager supports. Otherwise, an error is returned. + * 2. If the range of supported guest driver versions does not overlap the range set by the administrator, the guest driver fails to load. + * 3. If the range of supported guest driver versions overlaps the range set by the administrator, the guest driver will load with a negotiated + * vGPU version that is the maximum value in the overlapping range. + * 4. No VMs must be running on the host when this function is called. If a VM is running on the host, the call to this function fails. + * + * @param vgpuVersion Pointer to a caller-supplied range of supported vGPU versions. + * + * @return + * - \ref NVML_SUCCESS The preset range of supported vGPU versions was successfully overridden. + * - \ref NVML_ERROR_NOT_SUPPORTED The API is not supported. + * - \ref NVML_ERROR_IN_USE The range was not overridden because a VM is running on the host. + * - \ref NVML_ERROR_INVALID_ARGUMENT The \a vgpuVersion parameter specifies a range that is outside the range supported by the NVIDIA vGPU Manager or if \a vgpuVersion is NULL. + */ +nvmlReturn_t DECLDIR nvmlSetVgpuVersion(nvmlVgpuVersion_t *vgpuVersion); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlUtil vGPU Utilization and Accounting + * This chapter describes operations that are associated with vGPU Utilization and Accounting. + * @{ + */ +/***************************************************************************************************/ + /** * Retrieves current utilization for vGPUs on a physical GPU (device). * @@ -5558,123 +8821,1535 @@ nvmlReturn_t DECLDIR nvmlDeviceGetVgpuProcessUtilization(nvmlDevice_t device, un unsigned int *vgpuProcessSamplesCount, nvmlVgpuProcessUtilizationSample_t *utilizationSamples); /** - * Retrieve the GRID licensable features. + * Queries the state of per process accounting mode on vGPU. * - * Identifies whether the system supports GRID Software Licensing. If it does, return the list of licensable feature(s) - * and their current license status. + * For Maxwell &tm; or newer fully supported devices. * - * @param device Identifier of the target device - * @param pGridLicensableFeatures Pointer to structure in which GRID licensable features are returned + * @param vgpuInstance The identifier of the target vGPU instance + * @param mode Reference in which to return the current accounting mode * * @return - * - \ref NVML_SUCCESS if licensable features are successfully retrieved - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a pGridLicensableFeatures is NULL + * - \ref NVML_SUCCESS if the mode has been successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a mode is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system + * - \ref NVML_ERROR_NOT_SUPPORTED if the vGPU doesn't support this feature + * - \ref NVML_ERROR_DRIVER_NOT_LOADED if NVIDIA driver is not running on the vGPU instance * - \ref NVML_ERROR_UNKNOWN on any unexpected error */ -nvmlReturn_t DECLDIR nvmlDeviceGetGridLicensableFeatures(nvmlDevice_t device, nvmlGridLicensableFeatures_t *pGridLicensableFeatures); +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetAccountingMode(nvmlVgpuInstance_t vgpuInstance, nvmlEnableState_t *mode); /** - * Retrieves the current encoder statistics of a vGPU Instance + * Queries list of processes running on vGPU that can be queried for accounting stats. The list of processes + * returned can be in running or terminated state. * * For Maxwell &tm; or newer fully supported devices. * - * @param vgpuInstance Identifier of the target vGPU instance - * @param sessionCount Reference to an unsigned int for count of active encoder sessions - * @param averageFps Reference to an unsigned int for trailing average FPS of all active sessions - * @param averageLatency Reference to an unsigned int for encode latency in microseconds + * To just query the maximum number of processes that can be queried, call this function with *count = 0 and + * pids=NULL. The return code will be NVML_ERROR_INSUFFICIENT_SIZE, or NVML_SUCCESS if list is empty. + * + * For more details see \ref nvmlVgpuInstanceGetAccountingStats. + * + * @note In case of PID collision some processes might not be accessible before the circular buffer is full. + * + * @param vgpuInstance The identifier of the target vGPU instance + * @param count Reference in which to provide the \a pids array size, and + * to return the number of elements ready to be queried + * @param pids Reference in which to return list of process ids * * @return - * - \ref NVML_SUCCESS if \a sessionCount, \a averageFps and \a averageLatency is fetched - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount , or \a averageFps or \a averageLatency is NULL - * or \a vgpuInstance is invalid. - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEncoderStats(nvmlVgpuInstance_t vgpuInstance, unsigned int *sessionCount, - unsigned int *averageFps, unsigned int *averageLatency); - -/** - * Retrieves information about all active encoder sessions on a vGPU Instance. - * - * An array of active encoder sessions is returned in the caller-supplied buffer pointed at by \a sessionInfo. The - * array elememt count is passed in \a sessionCount, and \a sessionCount is used to return the number of sessions - * written to the buffer. - * - * If the supplied buffer is not large enough to accommodate the active session array, the function returns - * NVML_ERROR_INSUFFICIENT_SIZE, with the element count of nvmlEncoderSessionInfo_t array required in \a sessionCount. - * To query the number of active encoder sessions, call this function with *sessionCount = 0. The code will return - * NVML_SUCCESS with number of active encoder sessions updated in *sessionCount. - * - * For Maxwell &tm; or newer fully supported devices. - * - * @param vgpuInstance Identifier of the target vGPU instance - * @param sessionCount Reference to caller supplied array size, and returns - * the number of sessions. - * @param sessionInfo Reference to caller supplied array in which the list - * of session information us returned. - * - * @return - * - \ref NVML_SUCCESS if \a sessionInfo is fetched - * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a sessionCount is too small, array element count is - returned in \a sessionCount - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a sessionCount is NULL or \a vgpuInstance is invalid.. - * - \ref NVML_ERROR_UNKNOWN on any unexpected error - */ -nvmlReturn_t DECLDIR nvmlVgpuInstanceGetEncoderSessions(nvmlVgpuInstance_t vgpuInstance, unsigned int *sessionCount, nvmlEncoderSessionInfo_t *sessionInfo); - -/** - * Retrieves the current utilization and process ID - * - * For Maxwell &tm; or newer fully supported devices. - * - * Reads recent utilization of GPU SM (3D/Compute), framebuffer, video encoder, and video decoder for processes running. - * Utilization values are returned as an array of utilization sample structures in the caller-supplied buffer pointed at - * by \a utilization. One utilization sample structure is returned per process running, that had some non-zero utilization - * during the last sample period. It includes the CPU timestamp at which the samples were recorded. Individual utilization values - * are returned as "unsigned int" values. - * - * To read utilization values, first determine the size of buffer required to hold the samples by invoking the function with - * \a utilization set to NULL. The caller should allocate a buffer of size - * processSamplesCount * sizeof(nvmlProcessUtilizationSample_t). Invoke the function again with the allocated buffer passed - * in \a utilization, and \a processSamplesCount set to the number of entries the buffer is sized for. - * - * On successful return, the function updates \a processSamplesCount with the number of process utilization sample - * structures that were actually written. This may differ from a previously read value as instances are created or - * destroyed. - * - * lastSeenTimeStamp represents the CPU timestamp in microseconds at which utilization samples were last read. Set it to 0 - * to read utilization based on all the samples maintained by the driver's internal sample buffer. Set lastSeenTimeStamp - * to a timeStamp retrieved from a previous query to read utilization since the previous query. - * - * @param device The identifier of the target device - * @param utilization Pointer to caller-supplied buffer in which guest process utilization samples are returned - * @param processSamplesCount Pointer to caller-supplied array size, and returns number of processes running - * @param lastSeenTimeStamp Return only samples with timestamp greater than lastSeenTimeStamp. - - * @return - * - \ref NVML_SUCCESS if \a utilization has been populated + * - \ref NVML_SUCCESS if pids were successfully retrieved * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized - * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid, \a utilization is NULL, or \a samplingPeriodUs is NULL + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a count is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system + * - \ref NVML_ERROR_NOT_SUPPORTED if the vGPU doesn't support this feature or accounting mode is disabled + * - \ref NVML_ERROR_INSUFFICIENT_SIZE if \a count is too small (\a count is set to expected value) + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see nvmlVgpuInstanceGetAccountingPids + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetAccountingPids(nvmlVgpuInstance_t vgpuInstance, unsigned int *count, unsigned int *pids); + +/** + * Queries process's accounting stats. + * + * For Maxwell &tm; or newer fully supported devices. + * + * Accounting stats capture GPU utilization and other statistics across the lifetime of a process, and + * can be queried during life time of the process or after its termination. + * The time field in \ref nvmlAccountingStats_t is reported as 0 during the lifetime of the process and + * updated to actual running time after its termination. + * Accounting stats are kept in a circular buffer, newly created processes overwrite information about old + * processes. + * + * See \ref nvmlAccountingStats_t for description of each returned metric. + * List of processes that can be queried can be retrieved from \ref nvmlVgpuInstanceGetAccountingPids. + * + * @note Accounting Mode needs to be on. See \ref nvmlVgpuInstanceGetAccountingMode. + * @note Only compute and graphics applications stats can be queried. Monitoring applications stats can't be + * queried since they don't contribute to GPU utilization. + * @note In case of pid collision stats of only the latest process (that terminated last) will be reported + * + * @param vgpuInstance The identifier of the target vGPU instance + * @param pid Process Id of the target process to query stats for + * @param stats Reference in which to return the process's accounting stats + * + * @return + * - \ref NVML_SUCCESS if stats have been successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a stats is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system + * or \a stats is not found + * - \ref NVML_ERROR_NOT_SUPPORTED if the vGPU doesn't support this feature or accounting mode is disabled + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetAccountingStats(nvmlVgpuInstance_t vgpuInstance, unsigned int pid, nvmlAccountingStats_t *stats); + +/** + * Clears accounting information of the vGPU instance that have already terminated. + * + * For Maxwell &tm; or newer fully supported devices. + * Requires root/admin permissions. + * + * @note Accounting Mode needs to be on. See \ref nvmlVgpuInstanceGetAccountingMode. + * @note Only compute and graphics applications stats are reported and can be cleared since monitoring applications + * stats don't contribute to GPU utilization. + * + * @param vgpuInstance The identifier of the target vGPU instance + * + * @return + * - \ref NVML_SUCCESS if accounting information has been cleared + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is invalid + * - \ref NVML_ERROR_NO_PERMISSION if the user doesn't have permission to perform this operation + * - \ref NVML_ERROR_NOT_SUPPORTED if the vGPU doesn't support this feature or accounting mode is disabled + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceClearAccountingPids(nvmlVgpuInstance_t vgpuInstance); + +/** + * Query the license information of the vGPU instance. + * + * For Maxwell &tm; or newer fully supported devices. + * + * @param vgpuInstance Identifier of the target vGPU instance + * @param licenseInfo Pointer to vGPU license information structure + * + * @return + * - \ref NVML_SUCCESS if information is successfully retrieved + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a vgpuInstance is 0, or \a licenseInfo is NULL + * - \ref NVML_ERROR_NOT_FOUND if \a vgpuInstance does not match a valid active vGPU instance on the system + * - \ref NVML_ERROR_DRIVER_NOT_LOADED if NVIDIA driver is not running on the vGPU instance + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetLicenseInfo_v2(nvmlVgpuInstance_t vgpuInstance, nvmlVgpuLicenseInfo_t *licenseInfo); +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlExcludedGpuQueries Excluded GPU Queries + * This chapter describes NVML operations that are associated with excluded GPUs. + * @{ + */ +/***************************************************************************************************/ + +/** + * Excluded GPU device information + **/ +typedef struct nvmlExcludedDeviceInfo_st +{ + nvmlPciInfo_t pciInfo; //!< The PCI information for the excluded GPU + char uuid[NVML_DEVICE_UUID_BUFFER_SIZE]; //!< The ASCII string UUID for the excluded GPU +} nvmlExcludedDeviceInfo_t; + + /** + * Retrieves the number of excluded GPU devices in the system. + * + * For all products. + * + * @param deviceCount Reference in which to return the number of excluded devices + * + * @return + * - \ref NVML_SUCCESS if \a deviceCount has been set + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a deviceCount is NULL + */ +nvmlReturn_t DECLDIR nvmlGetExcludedDeviceCount(unsigned int *deviceCount); + +/** + * Acquire the device information for an excluded GPU device, based on its index. + * + * For all products. + * + * Valid indices are derived from the \a deviceCount returned by + * \ref nvmlGetExcludedDeviceCount(). For example, if \a deviceCount is 2 the valid indices + * are 0 and 1, corresponding to GPU 0 and GPU 1. + * + * @param index The index of the target GPU, >= 0 and < \a deviceCount + * @param info Reference in which to return the device information + * + * @return + * - \ref NVML_SUCCESS if \a device has been set + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a index is invalid or \a info is NULL + * + * @see nvmlGetExcludedDeviceCount + */ +nvmlReturn_t DECLDIR nvmlGetExcludedDeviceInfoByIndex(unsigned int index, nvmlExcludedDeviceInfo_t *info); + +/** @} */ + +/***************************************************************************************************/ +/** @defgroup nvmlMultiInstanceGPU Multi Instance GPU Management + * This chapter describes NVML operations that are associated with Multi Instance GPU management. + * @{ + */ +/***************************************************************************************************/ + +/** + * Disable Multi Instance GPU mode. + */ +#define NVML_DEVICE_MIG_DISABLE 0x0 + +/** + * Enable Multi Instance GPU mode. + */ +#define NVML_DEVICE_MIG_ENABLE 0x1 + +/** + * GPU instance profiles. + * + * These macros should be passed to \ref nvmlDeviceGetGpuInstanceProfileInfo to retrieve the + * detailed information about a GPU instance such as profile ID, engine counts. + */ +#define NVML_GPU_INSTANCE_PROFILE_1_SLICE 0x0 +#define NVML_GPU_INSTANCE_PROFILE_2_SLICE 0x1 +#define NVML_GPU_INSTANCE_PROFILE_3_SLICE 0x2 +#define NVML_GPU_INSTANCE_PROFILE_4_SLICE 0x3 +#define NVML_GPU_INSTANCE_PROFILE_7_SLICE 0x4 +#define NVML_GPU_INSTANCE_PROFILE_8_SLICE 0x5 +#define NVML_GPU_INSTANCE_PROFILE_6_SLICE 0x6 +#define NVML_GPU_INSTANCE_PROFILE_1_SLICE_REV1 0x7 +#define NVML_GPU_INSTANCE_PROFILE_2_SLICE_REV1 0x8 +#define NVML_GPU_INSTANCE_PROFILE_1_SLICE_REV2 0x9 +#define NVML_GPU_INSTANCE_PROFILE_COUNT 0xA + +/** + * MIG GPU instance profile capability. + * + * Bit field values representing MIG profile capabilities + * \ref nvmlGpuInstanceProfileInfo_v3_t.capabilities + */ +#define NVML_GPU_INTSTANCE_PROFILE_CAPS_P2P 0x1 + +/** + * MIG compute instance profile capability. + * + * Bit field values representing MIG profile capabilities + * \ref nvmlComputeInstanceProfileInfo_v3_t.capabilities + */ +/* No capabilities for compute profiles currently exposed */ + +typedef struct nvmlGpuInstancePlacement_st +{ + unsigned int start; //!< Index of first occupied memory slice + unsigned int size; //!< Number of memory slices occupied +} nvmlGpuInstancePlacement_t; + +/** + * GPU instance profile information. + */ +typedef struct nvmlGpuInstanceProfileInfo_st +{ + unsigned int id; //!< Unique profile ID within the device + unsigned int isP2pSupported; //!< Peer-to-Peer support + unsigned int sliceCount; //!< GPU Slice count + unsigned int instanceCount; //!< GPU instance count + unsigned int multiprocessorCount; //!< Streaming Multiprocessor count + unsigned int copyEngineCount; //!< Copy Engine count + unsigned int decoderCount; //!< Decoder Engine count + unsigned int encoderCount; //!< Encoder Engine count + unsigned int jpegCount; //!< JPEG Engine count + unsigned int ofaCount; //!< OFA Engine count + unsigned long long memorySizeMB; //!< Memory size in MBytes +} nvmlGpuInstanceProfileInfo_t; + +/** + * GPU instance profile information (v2). + * + * Version 2 adds the \ref nvmlGpuInstanceProfileInfo_v2_t.version field + * to the start of the structure, and the \ref nvmlGpuInstanceProfileInfo_v2_t.name + * field to the end. This structure is not backwards-compatible with + * \ref nvmlGpuInstanceProfileInfo_t. + */ +typedef struct nvmlGpuInstanceProfileInfo_v2_st +{ + unsigned int version; //!< Structure version identifier (set to \ref nvmlGpuInstanceProfileInfo_v2) + unsigned int id; //!< Unique profile ID within the device + unsigned int isP2pSupported; //!< Peer-to-Peer support + unsigned int sliceCount; //!< GPU Slice count + unsigned int instanceCount; //!< GPU instance count + unsigned int multiprocessorCount; //!< Streaming Multiprocessor count + unsigned int copyEngineCount; //!< Copy Engine count + unsigned int decoderCount; //!< Decoder Engine count + unsigned int encoderCount; //!< Encoder Engine count + unsigned int jpegCount; //!< JPEG Engine count + unsigned int ofaCount; //!< OFA Engine count + unsigned long long memorySizeMB; //!< Memory size in MBytes + char name[NVML_DEVICE_NAME_V2_BUFFER_SIZE]; //!< Profile name +} nvmlGpuInstanceProfileInfo_v2_t; + +/** + * Version identifier value for \ref nvmlGpuInstanceProfileInfo_v2_t.version. + */ +#define nvmlGpuInstanceProfileInfo_v2 NVML_STRUCT_VERSION(GpuInstanceProfileInfo, 2) + +/** + * GPU instance profile information (v3). + * + * Version 3 removes isP2pSupported field and adds the \ref nvmlGpuInstanceProfileInfo_v3_t.capabilities + * field \ref nvmlGpuInstanceProfileInfo_t. + */ +typedef struct nvmlGpuInstanceProfileInfo_v3_st +{ + unsigned int version; //!< Structure version identifier (set to \ref nvmlGpuInstanceProfileInfo_v3) + unsigned int id; //!< Unique profile ID within the device + unsigned int sliceCount; //!< GPU Slice count + unsigned int instanceCount; //!< GPU instance count + unsigned int multiprocessorCount; //!< Streaming Multiprocessor count + unsigned int copyEngineCount; //!< Copy Engine count + unsigned int decoderCount; //!< Decoder Engine count + unsigned int encoderCount; //!< Encoder Engine count + unsigned int jpegCount; //!< JPEG Engine count + unsigned int ofaCount; //!< OFA Engine count + unsigned long long memorySizeMB; //!< Memory size in MBytes + char name[NVML_DEVICE_NAME_V2_BUFFER_SIZE]; //!< Profile name + unsigned int capabilities; //!< Additional capabilities +} nvmlGpuInstanceProfileInfo_v3_t; + +/** + * Version identifier value for \ref nvmlGpuInstanceProfileInfo_v3_t.version. + */ +#define nvmlGpuInstanceProfileInfo_v3 NVML_STRUCT_VERSION(GpuInstanceProfileInfo, 3) + +typedef struct nvmlGpuInstanceInfo_st +{ + nvmlDevice_t device; //!< Parent device + unsigned int id; //!< Unique instance ID within the device + unsigned int profileId; //!< Unique profile ID within the device + nvmlGpuInstancePlacement_t placement; //!< Placement for this instance +} nvmlGpuInstanceInfo_t; + +typedef struct nvmlGpuInstance_st* nvmlGpuInstance_t; + +/** + * Compute instance profiles. + * + * These macros should be passed to \ref nvmlGpuInstanceGetComputeInstanceProfileInfo to retrieve the + * detailed information about a compute instance such as profile ID, engine counts + */ +#define NVML_COMPUTE_INSTANCE_PROFILE_1_SLICE 0x0 +#define NVML_COMPUTE_INSTANCE_PROFILE_2_SLICE 0x1 +#define NVML_COMPUTE_INSTANCE_PROFILE_3_SLICE 0x2 +#define NVML_COMPUTE_INSTANCE_PROFILE_4_SLICE 0x3 +#define NVML_COMPUTE_INSTANCE_PROFILE_7_SLICE 0x4 +#define NVML_COMPUTE_INSTANCE_PROFILE_8_SLICE 0x5 +#define NVML_COMPUTE_INSTANCE_PROFILE_6_SLICE 0x6 +#define NVML_COMPUTE_INSTANCE_PROFILE_1_SLICE_REV1 0x7 +#define NVML_COMPUTE_INSTANCE_PROFILE_COUNT 0x8 + +#define NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_SHARED 0x0 //!< All the engines except multiprocessors would be shared +#define NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_COUNT 0x1 + +typedef struct nvmlComputeInstancePlacement_st +{ + unsigned int start; //!< Index of first occupied compute slice + unsigned int size; //!< Number of compute slices occupied +} nvmlComputeInstancePlacement_t; + +/** + * Compute instance profile information. + */ +typedef struct nvmlComputeInstanceProfileInfo_st +{ + unsigned int id; //!< Unique profile ID within the GPU instance + unsigned int sliceCount; //!< GPU Slice count + unsigned int instanceCount; //!< Compute instance count + unsigned int multiprocessorCount; //!< Streaming Multiprocessor count + unsigned int sharedCopyEngineCount; //!< Shared Copy Engine count + unsigned int sharedDecoderCount; //!< Shared Decoder Engine count + unsigned int sharedEncoderCount; //!< Shared Encoder Engine count + unsigned int sharedJpegCount; //!< Shared JPEG Engine count + unsigned int sharedOfaCount; //!< Shared OFA Engine count +} nvmlComputeInstanceProfileInfo_t; + +/** + * Compute instance profile information (v2). + * + * Version 2 adds the \ref nvmlComputeInstanceProfileInfo_v2_t.version field + * to the start of the structure, and the \ref nvmlComputeInstanceProfileInfo_v2_t.name + * field to the end. This structure is not backwards-compatible with + * \ref nvmlComputeInstanceProfileInfo_t. + */ +typedef struct nvmlComputeInstanceProfileInfo_v2_st +{ + unsigned int version; //!< Structure version identifier (set to \ref nvmlComputeInstanceProfileInfo_v2) + unsigned int id; //!< Unique profile ID within the GPU instance + unsigned int sliceCount; //!< GPU Slice count + unsigned int instanceCount; //!< Compute instance count + unsigned int multiprocessorCount; //!< Streaming Multiprocessor count + unsigned int sharedCopyEngineCount; //!< Shared Copy Engine count + unsigned int sharedDecoderCount; //!< Shared Decoder Engine count + unsigned int sharedEncoderCount; //!< Shared Encoder Engine count + unsigned int sharedJpegCount; //!< Shared JPEG Engine count + unsigned int sharedOfaCount; //!< Shared OFA Engine count + char name[NVML_DEVICE_NAME_V2_BUFFER_SIZE]; //!< Profile name +} nvmlComputeInstanceProfileInfo_v2_t; + +/** + * Version identifier value for \ref nvmlComputeInstanceProfileInfo_v2_t.version. + */ +#define nvmlComputeInstanceProfileInfo_v2 NVML_STRUCT_VERSION(ComputeInstanceProfileInfo, 2) + +/** + * Compute instance profile information (v3). + * + * Version 3 adds the \ref nvmlComputeInstanceProfileInfo_v3_t.capabilities field + * \ref nvmlComputeInstanceProfileInfo_t. + */ +typedef struct nvmlComputeInstanceProfileInfo_v3_st +{ + unsigned int version; //!< Structure version identifier (set to \ref nvmlComputeInstanceProfileInfo_v3) + unsigned int id; //!< Unique profile ID within the GPU instance + unsigned int sliceCount; //!< GPU Slice count + unsigned int instanceCount; //!< Compute instance count + unsigned int multiprocessorCount; //!< Streaming Multiprocessor count + unsigned int sharedCopyEngineCount; //!< Shared Copy Engine count + unsigned int sharedDecoderCount; //!< Shared Decoder Engine count + unsigned int sharedEncoderCount; //!< Shared Encoder Engine count + unsigned int sharedJpegCount; //!< Shared JPEG Engine count + unsigned int sharedOfaCount; //!< Shared OFA Engine count + char name[NVML_DEVICE_NAME_V2_BUFFER_SIZE]; //!< Profile name + unsigned int capabilities; //!< Additional capabilities +} nvmlComputeInstanceProfileInfo_v3_t; + +/** + * Version identifier value for \ref nvmlComputeInstanceProfileInfo_v3_t.version. + */ +#define nvmlComputeInstanceProfileInfo_v3 NVML_STRUCT_VERSION(ComputeInstanceProfileInfo, 3) + +typedef struct nvmlComputeInstanceInfo_st +{ + nvmlDevice_t device; //!< Parent device + nvmlGpuInstance_t gpuInstance; //!< Parent GPU instance + unsigned int id; //!< Unique instance ID within the GPU instance + unsigned int profileId; //!< Unique profile ID within the GPU instance + nvmlComputeInstancePlacement_t placement; //!< Placement for this instance within the GPU instance's compute slice range {0, sliceCount} +} nvmlComputeInstanceInfo_t; + +typedef struct nvmlComputeInstance_st* nvmlComputeInstance_t; + +/** + * Set MIG mode for the device. + * + * For Ampere &tm; or newer fully supported devices. + * Requires root user. + * + * This mode determines whether a GPU instance can be created. + * + * This API may unbind or reset the device to activate the requested mode. Thus, the attributes associated with the + * device, such as minor number, might change. The caller of this API is expected to query such attributes again. + * + * On certain platforms like pass-through virtualization, where reset functionality may not be exposed directly, VM + * reboot is required. \a activationStatus would return \ref NVML_ERROR_RESET_REQUIRED for such cases. + * + * \a activationStatus would return the appropriate error code upon unsuccessful activation. For example, if device + * unbind fails because the device isn't idle, \ref NVML_ERROR_IN_USE would be returned. The caller of this API + * is expected to idle the device and retry setting the \a mode. + * + * @note On Windows, only disabling MIG mode is supported. \a activationStatus would return \ref + * NVML_ERROR_NOT_SUPPORTED as GPU reset is not supported on Windows through this API. + * + * @param device The identifier of the target device + * @param mode The mode to be set, \ref NVML_DEVICE_MIG_DISABLE or + * \ref NVML_DEVICE_MIG_ENABLE + * @param activationStatus The activationStatus status + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device,\a mode or \a activationStatus are invalid + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't support MIG mode + */ +nvmlReturn_t DECLDIR nvmlDeviceSetMigMode(nvmlDevice_t device, unsigned int mode, nvmlReturn_t *activationStatus); + +/** + * Get MIG mode for the device. + * + * For Ampere &tm; or newer fully supported devices. + * + * Changing MIG modes may require device unbind or reset. The "pending" MIG mode refers to the target mode following the + * next activation trigger. + * + * @param device The identifier of the target device + * @param currentMode Returns the current mode, \ref NVML_DEVICE_MIG_DISABLE or + * \ref NVML_DEVICE_MIG_ENABLE + * @param pendingMode Returns the pending mode, \ref NVML_DEVICE_MIG_DISABLE or + * \ref NVML_DEVICE_MIG_ENABLE + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a currentMode or \a pendingMode are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't support MIG mode + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMigMode(nvmlDevice_t device, unsigned int *currentMode, unsigned int *pendingMode); + +/** + * Get GPU instance profile information. + * + * Information provided by this API is immutable throughout the lifetime of a MIG mode. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device The identifier of the target device + * @param profile One of the NVML_GPU_INSTANCE_PROFILE_* + * @param info Returns detailed profile information + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a profile or \a info are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled or \a profile isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuInstanceProfileInfo(nvmlDevice_t device, unsigned int profile, + nvmlGpuInstanceProfileInfo_t *info); + +/** + * Versioned wrapper around \ref nvmlDeviceGetGpuInstanceProfileInfo that accepts a versioned + * \ref nvmlGpuInstanceProfileInfo_v2_t or later output structure. + * + * @note The caller must set the \ref nvmlGpuInstanceProfileInfo_v2_t.version field to the + * appropriate version prior to calling this function. For example: + * \code + * nvmlGpuInstanceProfileInfo_v2_t profileInfo = + * { .version = nvmlGpuInstanceProfileInfo_v2 }; + * nvmlReturn_t result = nvmlDeviceGetGpuInstanceProfileInfoV(device, + * profile, + * &profileInfo); + * \endcode + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device The identifier of the target device + * @param profile One of the NVML_GPU_INSTANCE_PROFILE_* + * @param info Returns detailed profile information + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a profile, \a info, or \a info->version are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled or \a profile isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuInstanceProfileInfoV(nvmlDevice_t device, unsigned int profile, + nvmlGpuInstanceProfileInfo_v2_t *info); + +/** + * Get GPU instance placements. + * + * A placement represents the location of a GPU instance within a device. This API only returns all the possible + * placements for the given profile. + * A created GPU instance occupies memory slices described by its placement. Creation of new GPU instance will + * fail if there is overlap with the already occupied memory slices. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * @param device The identifier of the target device + * @param profileId The GPU instance profile ID. See \ref nvmlDeviceGetGpuInstanceProfileInfo + * @param placements Returns placements allowed for the profile. Can be NULL to discover number + * of allowed placements for this profile. If non-NULL must be large enough + * to accommodate the placements supported by the profile. + * @param count Returns number of allowed placemenets for the profile. + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a profileId or \a count are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled or \a profileId isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuInstancePossiblePlacements_v2(nvmlDevice_t device, unsigned int profileId, + nvmlGpuInstancePlacement_t *placements, + unsigned int *count); + +/** + * Get GPU instance profile capacity. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * @param device The identifier of the target device + * @param profileId The GPU instance profile ID. See \ref nvmlDeviceGetGpuInstanceProfileInfo + * @param count Returns remaining instance count for the profile ID + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a profileId or \a count are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled or \a profileId isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuInstanceRemainingCapacity(nvmlDevice_t device, unsigned int profileId, + unsigned int *count); + +/** + * Create GPU instance. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * If the parent device is unbound, reset or the GPU instance is destroyed explicitly, the GPU instance handle would + * become invalid. The GPU instance must be recreated to acquire a valid handle. + * + * @param device The identifier of the target device + * @param profileId The GPU instance profile ID. See \ref nvmlDeviceGetGpuInstanceProfileInfo + * @param gpuInstance Returns the GPU instance handle + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a profile, \a profileId or \a gpuInstance are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled or in vGPU guest + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + * - \ref NVML_ERROR_INSUFFICIENT_RESOURCES If the requested GPU instance could not be created + */ +nvmlReturn_t DECLDIR nvmlDeviceCreateGpuInstance(nvmlDevice_t device, unsigned int profileId, + nvmlGpuInstance_t *gpuInstance); + +/** + * Create GPU instance with the specified placement. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * If the parent device is unbound, reset or the GPU instance is destroyed explicitly, the GPU instance handle would + * become invalid. The GPU instance must be recreated to acquire a valid handle. + * + * @param device The identifier of the target device + * @param profileId The GPU instance profile ID. See \ref nvmlDeviceGetGpuInstanceProfileInfo + * @param placement The requested placement. See \ref nvmlDeviceGetGpuInstancePossiblePlacements_v2 + * @param gpuInstance Returns the GPU instance handle + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a profile, \a profileId, \a placement or \a gpuInstance + * are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled or in vGPU guest + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + * - \ref NVML_ERROR_INSUFFICIENT_RESOURCES If the requested GPU instance could not be created + */ +nvmlReturn_t DECLDIR nvmlDeviceCreateGpuInstanceWithPlacement(nvmlDevice_t device, unsigned int profileId, + const nvmlGpuInstancePlacement_t *placement, + nvmlGpuInstance_t *gpuInstance); +/** + * Destroy GPU instance. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * @param gpuInstance The GPU instance handle + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a gpuInstance is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled or in vGPU guest + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + * - \ref NVML_ERROR_IN_USE If the GPU instance is in use. This error would be returned if processes + * (e.g. CUDA application) or compute instances are active on the + * GPU instance. + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceDestroy(nvmlGpuInstance_t gpuInstance); + +/** + * Get GPU instances for given profile ID. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * @param device The identifier of the target device + * @param profileId The GPU instance profile ID. See \ref nvmlDeviceGetGpuInstanceProfileInfo + * @param gpuInstances Returns pre-exiting GPU instances, the buffer must be large enough to + * accommodate the instances supported by the profile. + * See \ref nvmlDeviceGetGpuInstanceProfileInfo + * @param count The count of returned GPU instances + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a profileId, \a gpuInstances or \a count are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuInstances(nvmlDevice_t device, unsigned int profileId, + nvmlGpuInstance_t *gpuInstances, unsigned int *count); + +/** + * Get GPU instances for given instance ID. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * @param device The identifier of the target device + * @param id The GPU instance ID + * @param gpuInstance Returns GPU instance + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a id or \a gpuInstance are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + * - \ref NVML_ERROR_NOT_FOUND If the GPU instance is not found. + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuInstanceById(nvmlDevice_t device, unsigned int id, nvmlGpuInstance_t *gpuInstance); + +/** + * Get GPU instance information. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param gpuInstance The GPU instance handle + * @param info Return GPU instance information + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a gpuInstance or \a info are invalid + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceGetInfo(nvmlGpuInstance_t gpuInstance, nvmlGpuInstanceInfo_t *info); + +/** + * Get compute instance profile information. + * + * Information provided by this API is immutable throughout the lifetime of a MIG mode. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param gpuInstance The identifier of the target GPU instance + * @param profile One of the NVML_COMPUTE_INSTANCE_PROFILE_* + * @param engProfile One of the NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_* + * @param info Returns detailed profile information + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a gpuInstance, \a profile, \a engProfile or \a info are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a profile isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceGetComputeInstanceProfileInfo(nvmlGpuInstance_t gpuInstance, unsigned int profile, + unsigned int engProfile, + nvmlComputeInstanceProfileInfo_t *info); + +/** + * Versioned wrapper around \ref nvmlGpuInstanceGetComputeInstanceProfileInfo that accepts a versioned + * \ref nvmlComputeInstanceProfileInfo_v2_t or later output structure. + * + * @note The caller must set the \ref nvmlGpuInstanceProfileInfo_v2_t.version field to the + * appropriate version prior to calling this function. For example: + * \code + * nvmlComputeInstanceProfileInfo_v2_t profileInfo = + * { .version = nvmlComputeInstanceProfileInfo_v2 }; + * nvmlReturn_t result = nvmlGpuInstanceGetComputeInstanceProfileInfoV(gpuInstance, + * profile, + * engProfile, + * &profileInfo); + * \endcode + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param gpuInstance The identifier of the target GPU instance + * @param profile One of the NVML_COMPUTE_INSTANCE_PROFILE_* + * @param engProfile One of the NVML_COMPUTE_INSTANCE_ENGINE_PROFILE_* + * @param info Returns detailed profile information + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a gpuInstance, \a profile, \a engProfile, \a info, or \a info->version are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a profile isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceGetComputeInstanceProfileInfoV(nvmlGpuInstance_t gpuInstance, unsigned int profile, + unsigned int engProfile, + nvmlComputeInstanceProfileInfo_v2_t *info); + +/** + * Get compute instance profile capacity. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * @param gpuInstance The identifier of the target GPU instance + * @param profileId The compute instance profile ID. + * See \ref nvmlGpuInstanceGetComputeInstanceProfileInfo + * @param count Returns remaining instance count for the profile ID + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a gpuInstance, \a profileId or \a availableCount are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a profileId isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceGetComputeInstanceRemainingCapacity(nvmlGpuInstance_t gpuInstance, + unsigned int profileId, unsigned int *count); + +/** + * Get compute instance placements. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * A placement represents the location of a compute instance within a GPU instance. This API only returns all the possible + * placements for the given profile. + * A created compute instance occupies compute slices described by its placement. Creation of new compute instance will + * fail if there is overlap with the already occupied compute slices. + * + * @param gpuInstance The identifier of the target GPU instance + * @param profileId The compute instance profile ID. See \ref nvmlGpuInstanceGetComputeInstanceProfileInfo + * @param placements Returns placements allowed for the profile. Can be NULL to discover number + * of allowed placements for this profile. If non-NULL must be large enough + * to accommodate the placements supported by the profile. + * @param count Returns number of allowed placemenets for the profile. + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a gpuInstance, \a profileId or \a count are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled or \a profileId isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceGetComputeInstancePossiblePlacements(nvmlGpuInstance_t gpuInstance, + unsigned int profileId, + nvmlComputeInstancePlacement_t *placements, + unsigned int *count); + +/** + * Create compute instance. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * If the parent device is unbound, reset or the parent GPU instance is destroyed or the compute instance is destroyed + * explicitly, the compute instance handle would become invalid. The compute instance must be recreated to acquire + * a valid handle. + * + * @param gpuInstance The identifier of the target GPU instance + * @param profileId The compute instance profile ID. + * See \ref nvmlGpuInstanceGetComputeInstanceProfileInfo + * @param computeInstance Returns the compute instance handle + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a gpuInstance, \a profile, \a profileId or \a computeInstance + * are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a profileId isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + * - \ref NVML_ERROR_INSUFFICIENT_RESOURCES If the requested compute instance could not be created + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceCreateComputeInstance(nvmlGpuInstance_t gpuInstance, unsigned int profileId, + nvmlComputeInstance_t *computeInstance); + +/** + * Create compute instance with the specified placement. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * If the parent device is unbound, reset or the parent GPU instance is destroyed or the compute instance is destroyed + * explicitly, the compute instance handle would become invalid. The compute instance must be recreated to acquire + * a valid handle. + * + * @param gpuInstance The identifier of the target GPU instance + * @param profileId The compute instance profile ID. + * See \ref nvmlGpuInstanceGetComputeInstanceProfileInfo + * @param placement The requested placement. See \ref nvmlGpuInstanceGetComputeInstancePossiblePlacements + * @param computeInstance Returns the compute instance handle + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a gpuInstance, \a profile, \a profileId or \a computeInstance + * are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a profileId isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + * - \ref NVML_ERROR_INSUFFICIENT_RESOURCES If the requested compute instance could not be created + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceCreateComputeInstanceWithPlacement(nvmlGpuInstance_t gpuInstance, unsigned int profileId, + const nvmlComputeInstancePlacement_t *placement, + nvmlComputeInstance_t *computeInstance); + +/** + * Destroy compute instance. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * @param computeInstance The compute instance handle + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a computeInstance is invalid + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + * - \ref NVML_ERROR_IN_USE If the compute instance is in use. This error would be returned if + * processes (e.g. CUDA application) are active on the compute instance. + */ +nvmlReturn_t DECLDIR nvmlComputeInstanceDestroy(nvmlComputeInstance_t computeInstance); + +/** + * Get compute instances for given profile ID. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * @param gpuInstance The identifier of the target GPU instance + * @param profileId The compute instance profile ID. + * See \ref nvmlGpuInstanceGetComputeInstanceProfileInfo + * @param computeInstances Returns pre-exiting compute instances, the buffer must be large enough to + * accommodate the instances supported by the profile. + * See \ref nvmlGpuInstanceGetComputeInstanceProfileInfo + * @param count The count of returned compute instances + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a gpuInstance, \a profileId, \a computeInstances or \a count + * are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a profileId isn't supported + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceGetComputeInstances(nvmlGpuInstance_t gpuInstance, unsigned int profileId, + nvmlComputeInstance_t *computeInstances, unsigned int *count); + +/** + * Get compute instance for given instance ID. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * Requires privileged user. + * + * @param gpuInstance The identifier of the target GPU instance + * @param id The compute instance ID + * @param computeInstance Returns compute instance + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a device, \a ID or \a computeInstance are invalid + * - \ref NVML_ERROR_NOT_SUPPORTED If \a device doesn't have MIG mode enabled + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + * - \ref NVML_ERROR_NOT_FOUND If the compute instance is not found. + */ +nvmlReturn_t DECLDIR nvmlGpuInstanceGetComputeInstanceById(nvmlGpuInstance_t gpuInstance, unsigned int id, + nvmlComputeInstance_t *computeInstance); + +/** + * Get compute instance information. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param computeInstance The compute instance handle + * @param info Return compute instance information + * + * @return + * - \ref NVML_SUCCESS Upon success + * - \ref NVML_ERROR_UNINITIALIZED If library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT If \a computeInstance or \a info are invalid + * - \ref NVML_ERROR_NO_PERMISSION If user doesn't have permission to perform the operation + */ +nvmlReturn_t DECLDIR nvmlComputeInstanceGetInfo_v2(nvmlComputeInstance_t computeInstance, nvmlComputeInstanceInfo_t *info); + +/** + * Test if the given handle refers to a MIG device. + * + * A MIG device handle is an NVML abstraction which maps to a MIG compute instance. + * These overloaded references can be used (with some restrictions) interchangeably + * with a GPU device handle to execute queries at a per-compute instance granularity. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device NVML handle to test + * @param isMigDevice True when handle refers to a MIG device + * + * @return + * - \ref NVML_SUCCESS if \a device status was successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device handle or \a isMigDevice reference is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this check is not supported by the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceIsMigDeviceHandle(nvmlDevice_t device, unsigned int *isMigDevice); + +/** + * Get GPU instance ID for the given MIG device handle. + * + * GPU instance IDs are unique per device and remain valid until the GPU instance is destroyed. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device Target MIG device handle + * @param id GPU instance ID + * + * @return + * - \ref NVML_SUCCESS if instance ID was successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a id reference is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetGpuInstanceId(nvmlDevice_t device, unsigned int *id); + +/** + * Get compute instance ID for the given MIG device handle. + * + * Compute instance IDs are unique per GPU instance and remain valid until the compute instance + * is destroyed. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device Target MIG device handle + * @param id Compute instance ID + * + * @return + * - \ref NVML_SUCCESS if instance ID was successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a id reference is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetComputeInstanceId(nvmlDevice_t device, unsigned int *id); + +/** + * Get the maximum number of MIG devices that can exist under a given parent NVML device. + * + * Returns zero if MIG is not supported or enabled. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device Target device handle + * @param count Count of MIG devices + * + * @return + * - \ref NVML_SUCCESS if \a count was successfully retrieved + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device or \a count reference is invalid + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMaxMigDeviceCount(nvmlDevice_t device, unsigned int *count); + +/** + * Get MIG device handle for the given index under its parent NVML device. + * + * If the compute instance is destroyed either explicitly or by destroying, + * resetting or unbinding the parent GPU instance or the GPU device itself + * the MIG device handle would remain invalid and must be requested again + * using this API. Handles may be reused and their properties can change in + * the process. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param device Reference to the parent GPU device handle + * @param index Index of the MIG device + * @param migDevice Reference to the MIG device handle + * + * @return + * - \ref NVML_SUCCESS if \a migDevice handle was successfully created + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device, \a index or \a migDevice reference is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_NOT_FOUND if no valid MIG device was found at \a index + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetMigDeviceHandleByIndex(nvmlDevice_t device, unsigned int index, + nvmlDevice_t *migDevice); + +/** + * Get parent device handle from a MIG device handle. + * + * For Ampere &tm; or newer fully supported devices. + * Supported on Linux only. + * + * @param migDevice MIG device handle + * @param device Device handle + * + * @return + * - \ref NVML_SUCCESS if \a device handle was successfully created + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a migDevice or \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * - \ref NVML_ERROR_UNKNOWN on any unexpected error + */ +nvmlReturn_t DECLDIR nvmlDeviceGetDeviceHandleFromMigDeviceHandle(nvmlDevice_t migDevice, nvmlDevice_t *device); + +/** @} */ // @defgroup nvmlMultiInstanceGPU + + +/***************************************************************************************************/ +/** @defgroup GPM NVML GPM + * @{ + */ +/***************************************************************************************************/ +/** @defgroup nvmlGpmEnums GPM Enums + * @{ + */ +/***************************************************************************************************/ + +/** + * GPM Metric Identifiers + */ +typedef enum +{ + NVML_GPM_METRIC_GRAPHICS_UTIL = 1, //!< Percentage of time any compute/graphics app was active on the GPU. 0.0 - 100.0 + NVML_GPM_METRIC_SM_UTIL = 2, //!< Percentage of SMs that were busy. 0.0 - 100.0 + NVML_GPM_METRIC_SM_OCCUPANCY = 3, //!< Percentage of warps that were active vs theoretical maximum. 0.0 - 100.0 + NVML_GPM_METRIC_INTEGER_UTIL = 4, //!< Percentage of time the GPU's SMs were doing integer operations. 0.0 - 100.0 + NVML_GPM_METRIC_ANY_TENSOR_UTIL = 5, //!< Percentage of time the GPU's SMs were doing ANY tensor operations. 0.0 - 100.0 + NVML_GPM_METRIC_DFMA_TENSOR_UTIL = 6, //!< Percentage of time the GPU's SMs were doing DFMA tensor operations. 0.0 - 100.0 + NVML_GPM_METRIC_HMMA_TENSOR_UTIL = 7, //!< Percentage of time the GPU's SMs were doing HMMA tensor operations. 0.0 - 100.0 + NVML_GPM_METRIC_IMMA_TENSOR_UTIL = 9, //!< Percentage of time the GPU's SMs were doing IMMA tensor operations. 0.0 - 100.0 + NVML_GPM_METRIC_DRAM_BW_UTIL = 10, //!< Percentage of DRAM bw used vs theoretical maximum. 0.0 - 100.0 */ + NVML_GPM_METRIC_FP64_UTIL = 11, //!< Percentage of time the GPU's SMs were doing non-tensor FP64 math. 0.0 - 100.0 + NVML_GPM_METRIC_FP32_UTIL = 12, //!< Percentage of time the GPU's SMs were doing non-tensor FP32 math. 0.0 - 100.0 + NVML_GPM_METRIC_FP16_UTIL = 13, //!< Percentage of time the GPU's SMs were doing non-tensor FP16 math. 0.0 - 100.0 + NVML_GPM_METRIC_PCIE_TX_PER_SEC = 20, //!< PCIe traffic from this GPU in MiB/sec + NVML_GPM_METRIC_PCIE_RX_PER_SEC = 21, //!< PCIe traffic to this GPU in MiB/sec + NVML_GPM_METRIC_NVDEC_0_UTIL = 30, //!< Percent utilization of NVDEC 0. 0.0 - 100.0 + NVML_GPM_METRIC_NVDEC_1_UTIL = 31, //!< Percent utilization of NVDEC 1. 0.0 - 100.0 + NVML_GPM_METRIC_NVDEC_2_UTIL = 32, //!< Percent utilization of NVDEC 2. 0.0 - 100.0 + NVML_GPM_METRIC_NVDEC_3_UTIL = 33, //!< Percent utilization of NVDEC 3. 0.0 - 100.0 + NVML_GPM_METRIC_NVDEC_4_UTIL = 34, //!< Percent utilization of NVDEC 4. 0.0 - 100.0 + NVML_GPM_METRIC_NVDEC_5_UTIL = 35, //!< Percent utilization of NVDEC 5. 0.0 - 100.0 + NVML_GPM_METRIC_NVDEC_6_UTIL = 36, //!< Percent utilization of NVDEC 6. 0.0 - 100.0 + NVML_GPM_METRIC_NVDEC_7_UTIL = 37, //!< Percent utilization of NVDEC 7. 0.0 - 100.0 + NVML_GPM_METRIC_NVJPG_0_UTIL = 40, //!< Percent utilization of NVJPG 0. 0.0 - 100.0 + NVML_GPM_METRIC_NVJPG_1_UTIL = 41, //!< Percent utilization of NVJPG 1. 0.0 - 100.0 + NVML_GPM_METRIC_NVJPG_2_UTIL = 42, //!< Percent utilization of NVJPG 2. 0.0 - 100.0 + NVML_GPM_METRIC_NVJPG_3_UTIL = 43, //!< Percent utilization of NVJPG 3. 0.0 - 100.0 + NVML_GPM_METRIC_NVJPG_4_UTIL = 44, //!< Percent utilization of NVJPG 4. 0.0 - 100.0 + NVML_GPM_METRIC_NVJPG_5_UTIL = 45, //!< Percent utilization of NVJPG 5. 0.0 - 100.0 + NVML_GPM_METRIC_NVJPG_6_UTIL = 46, //!< Percent utilization of NVJPG 6. 0.0 - 100.0 + NVML_GPM_METRIC_NVJPG_7_UTIL = 47, //!< Percent utilization of NVJPG 7. 0.0 - 100.0 + NVML_GPM_METRIC_NVOFA_0_UTIL = 50, //!< Percent utilization of NVOFA 0. 0.0 - 100.0 + NVML_GPM_METRIC_NVLINK_TOTAL_RX_PER_SEC = 60, //!< NvLink read bandwidth for all links in MiB/sec + NVML_GPM_METRIC_NVLINK_TOTAL_TX_PER_SEC = 61, //!< NvLink write bandwidth for all links in MiB/sec + NVML_GPM_METRIC_NVLINK_L0_RX_PER_SEC = 62, //!< NvLink read bandwidth for link 0 in MiB/sec + NVML_GPM_METRIC_NVLINK_L0_TX_PER_SEC = 63, //!< NvLink write bandwidth for link 0 in MiB/sec + NVML_GPM_METRIC_NVLINK_L1_RX_PER_SEC = 64, //!< NvLink read bandwidth for link 1 in MiB/sec + NVML_GPM_METRIC_NVLINK_L1_TX_PER_SEC = 65, //!< NvLink write bandwidth for link 1 in MiB/sec + NVML_GPM_METRIC_NVLINK_L2_RX_PER_SEC = 66, //!< NvLink read bandwidth for link 2 in MiB/sec + NVML_GPM_METRIC_NVLINK_L2_TX_PER_SEC = 67, //!< NvLink write bandwidth for link 2 in MiB/sec + NVML_GPM_METRIC_NVLINK_L3_RX_PER_SEC = 68, //!< NvLink read bandwidth for link 3 in MiB/sec + NVML_GPM_METRIC_NVLINK_L3_TX_PER_SEC = 69, //!< NvLink write bandwidth for link 3 in MiB/sec + NVML_GPM_METRIC_NVLINK_L4_RX_PER_SEC = 70, //!< NvLink read bandwidth for link 4 in MiB/sec + NVML_GPM_METRIC_NVLINK_L4_TX_PER_SEC = 71, //!< NvLink write bandwidth for link 4 in MiB/sec + NVML_GPM_METRIC_NVLINK_L5_RX_PER_SEC = 72, //!< NvLink read bandwidth for link 5 in MiB/sec + NVML_GPM_METRIC_NVLINK_L5_TX_PER_SEC = 73, //!< NvLink write bandwidth for link 5 in MiB/sec + NVML_GPM_METRIC_NVLINK_L6_RX_PER_SEC = 74, //!< NvLink read bandwidth for link 6 in MiB/sec + NVML_GPM_METRIC_NVLINK_L6_TX_PER_SEC = 75, //!< NvLink write bandwidth for link 6 in MiB/sec + NVML_GPM_METRIC_NVLINK_L7_RX_PER_SEC = 76, //!< NvLink read bandwidth for link 7 in MiB/sec + NVML_GPM_METRIC_NVLINK_L7_TX_PER_SEC = 77, //!< NvLink write bandwidth for link 7 in MiB/sec + NVML_GPM_METRIC_NVLINK_L8_RX_PER_SEC = 78, //!< NvLink read bandwidth for link 8 in MiB/sec + NVML_GPM_METRIC_NVLINK_L8_TX_PER_SEC = 79, //!< NvLink write bandwidth for link 8 in MiB/sec + NVML_GPM_METRIC_NVLINK_L9_RX_PER_SEC = 80, //!< NvLink read bandwidth for link 9 in MiB/sec + NVML_GPM_METRIC_NVLINK_L9_TX_PER_SEC = 81, //!< NvLink write bandwidth for link 9 in MiB/sec + NVML_GPM_METRIC_NVLINK_L10_RX_PER_SEC = 82, //!< NvLink read bandwidth for link 10 in MiB/sec + NVML_GPM_METRIC_NVLINK_L10_TX_PER_SEC = 83, //!< NvLink write bandwidth for link 10 in MiB/sec + NVML_GPM_METRIC_NVLINK_L11_RX_PER_SEC = 84, //!< NvLink read bandwidth for link 11 in MiB/sec + NVML_GPM_METRIC_NVLINK_L11_TX_PER_SEC = 85, //!< NvLink write bandwidth for link 11 in MiB/sec + NVML_GPM_METRIC_NVLINK_L12_RX_PER_SEC = 86, //!< NvLink read bandwidth for link 12 in MiB/sec + NVML_GPM_METRIC_NVLINK_L12_TX_PER_SEC = 87, //!< NvLink write bandwidth for link 12 in MiB/sec + NVML_GPM_METRIC_NVLINK_L13_RX_PER_SEC = 88, //!< NvLink read bandwidth for link 13 in MiB/sec + NVML_GPM_METRIC_NVLINK_L13_TX_PER_SEC = 89, //!< NvLink write bandwidth for link 13 in MiB/sec + NVML_GPM_METRIC_NVLINK_L14_RX_PER_SEC = 90, //!< NvLink read bandwidth for link 14 in MiB/sec + NVML_GPM_METRIC_NVLINK_L14_TX_PER_SEC = 91, //!< NvLink write bandwidth for link 14 in MiB/sec + NVML_GPM_METRIC_NVLINK_L15_RX_PER_SEC = 92, //!< NvLink read bandwidth for link 15 in MiB/sec + NVML_GPM_METRIC_NVLINK_L15_TX_PER_SEC = 93, //!< NvLink write bandwidth for link 15 in MiB/sec + NVML_GPM_METRIC_NVLINK_L16_RX_PER_SEC = 94, //!< NvLink read bandwidth for link 16 in MiB/sec + NVML_GPM_METRIC_NVLINK_L16_TX_PER_SEC = 95, //!< NvLink write bandwidth for link 16 in MiB/sec + NVML_GPM_METRIC_NVLINK_L17_RX_PER_SEC = 96, //!< NvLink read bandwidth for link 17 in MiB/sec + NVML_GPM_METRIC_NVLINK_L17_TX_PER_SEC = 97, //!< NvLink write bandwidth for link 17 in MiB/sec + NVML_GPM_METRIC_MAX = 98, //!< Maximum value above +1. Note that changing this should also change NVML_GPM_METRICS_GET_VERSION due to struct size change +} nvmlGpmMetricId_t; + +/** @} */ // @defgroup nvmlGpmEnums + + +/***************************************************************************************************/ +/** @defgroup nvmlGpmStructs GPM Structs + * @{ + */ +/***************************************************************************************************/ + +/** + * Handle to an allocated GPM sample allocated with nvmlGpmSampleAlloc(). Free this with nvmlGpmSampleFree(). + */ +typedef struct nvmlGpmSample_st* nvmlGpmSample_t; + +/** + * GPM metric information. + */ +typedef struct +{ + unsigned int metricId; //!< IN: NVML_GPM_METRIC_? #define of which metric to retrieve + nvmlReturn_t nvmlReturn; //!< OUT: Status of this metric. If this is nonzero, then value is not valid + double value; //!< OUT: Value of this metric. Is only valid if nvmlReturn is 0 (NVML_SUCCESS) + struct + { + char *shortName; + char *longName; + char *unit; + } metricInfo; //!< OUT: Metric name and unit. Those can be NULL if not defined +} nvmlGpmMetric_t; + +/** + * GPM buffer information. + */ +typedef struct +{ + unsigned int version; //!< IN: Set to NVML_GPM_METRICS_GET_VERSION + unsigned int numMetrics; //!< IN: How many metrics to retrieve in metrics[] + nvmlGpmSample_t sample1; //!< IN: Sample buffer + nvmlGpmSample_t sample2; //!< IN: Sample buffer + nvmlGpmMetric_t metrics[NVML_GPM_METRIC_MAX]; //!< IN/OUT: Array of metrics. Set metricId on call. See nvmlReturn and value on return +} nvmlGpmMetricsGet_t; + +#define NVML_GPM_METRICS_GET_VERSION 1 + +/** + * GPM device information. + */ +typedef struct +{ + unsigned int version; //!< IN: Set to NVML_GPM_SUPPORT_VERSION + unsigned int isSupportedDevice; //!< OUT: Indicates device support +} nvmlGpmSupport_t; + +#define NVML_GPM_SUPPORT_VERSION 1 + +/** @} */ // @defgroup nvmlGPMStructs + +/***************************************************************************************************/ +/** @defgroup nvmlGpmFunctions GPM Functions + * @{ + */ +/***************************************************************************************************/ + +/** + * Calculate GPM metrics from two samples. + * + * For Hopper &tm; or newer fully supported devices. + * + * @param metricsGet IN/OUT: populated \a nvmlGpmMetricsGet_t struct + * + * @return + * - \ref NVML_SUCCESS on success + * - Nonzero NVML_ERROR_? enum on error + */ +nvmlReturn_t DECLDIR nvmlGpmMetricsGet(nvmlGpmMetricsGet_t *metricsGet); + + +/** + * Free an allocated sample buffer that was allocated with \ref nvmlGpmSampleAlloc() + * + * For Hopper &tm; or newer fully supported devices. + * + * @param gpmSample Sample to free + * + * @return + * - \ref NVML_SUCCESS on success + * - \ref NVML_ERROR_INVALID_ARGUMENT if an invalid pointer is provided + */ +nvmlReturn_t DECLDIR nvmlGpmSampleFree(nvmlGpmSample_t gpmSample); + + +/** + * Allocate a sample buffer to be used with NVML GPM . You will need to allocate + * at least two of these buffers to use with the NVML GPM feature + * + * For Hopper &tm; or newer fully supported devices. + * + * @param gpmSample Where the allocated sample will be stored + * + * @return + * - \ref NVML_SUCCESS on success + * - \ref NVML_ERROR_INVALID_ARGUMENT if an invalid pointer is provided + * - \ref NVML_ERROR_MEMORY if system memory is insufficient + */ +nvmlReturn_t DECLDIR nvmlGpmSampleAlloc(nvmlGpmSample_t *gpmSample); + +/** + * Read a sample of GPM metrics into the provided \a gpmSample buffer. After + * two samples are gathered, you can call nvmlGpmMetricGet on those samples to + * retrive metrics + * + * For Hopper &tm; or newer fully supported devices. + * + * @param device Device to get samples for + * @param gpmSample Buffer to read samples into + * + * @return + * - \ref NVML_SUCCESS on success + * - Nonzero NVML_ERROR_? enum on error + */ +nvmlReturn_t DECLDIR nvmlGpmSampleGet(nvmlDevice_t device, nvmlGpmSample_t gpmSample); + +/** + * Read a sample of GPM metrics into the provided \a gpmSample buffer for a MIG GPU Instance. + * + * After two samples are gathered, you can call nvmlGpmMetricGet on those + * samples to retrive metrics + * + * For Hopper &tm; or newer fully supported devices. + * + * @param device Device to get samples for + * @param gpuInstanceId MIG GPU Instance ID + * @param gpmSample Buffer to read samples into + * + * @return + * - \ref NVML_SUCCESS on success + * - Nonzero NVML_ERROR_? enum on error + */ +nvmlReturn_t DECLDIR nvmlGpmMigSampleGet(nvmlDevice_t device, unsigned int gpuInstanceId, nvmlGpmSample_t gpmSample); + +/** + * Indicate whether the supplied device supports GPM + * + * @param device NVML device to query for + * @param gpmSupport Structure to indicate GPM support \a nvmlGpmSupport_t. Indicates + * GPM support per system for the supplied device + * + * @return + * - NVML_SUCCESS on success + * - Nonzero NVML_ERROR_? enum if there is an error in processing the query + */ +nvmlReturn_t DECLDIR nvmlGpmQueryDeviceSupport(nvmlDevice_t device, nvmlGpmSupport_t *gpmSupport); + +/* GPM Stream State */ +/** + * Get GPM stream state. + * + * %HOPPER_OR_NEWER% + * Supported on Linux, Windows TCC. + * + * @param device The identifier of the target device + * @param state Returns GPM stream state + * NVML_FEATURE_DISABLED or NVML_FEATURE_ENABLED + * + * @return + * - \ref NVML_SUCCESS if \a current GPM stream state were successfully queried + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a state is NULL + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + */ +nvmlReturn_t DECLDIR nvmlGpmQueryIfStreamingEnabled(nvmlDevice_t device, unsigned int *state); + +/** + * Set GPM stream state. + * + * %HOPPER_OR_NEWER% + * Supported on Linux, Windows TCC. + * + * @param device The identifier of the target device + * @param state GPM stream state, + * NVML_FEATURE_DISABLED or NVML_FEATURE_ENABLED + * + * @return + * - \ref NVML_SUCCESS if \a current GPM stream state is successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + */ +nvmlReturn_t DECLDIR nvmlGpmSetStreamingEnabled(nvmlDevice_t device, unsigned int state); + +/** @} */ // @defgroup nvmlGpmFunctions +/** @} */ // @defgroup GPM + +#define NVML_NVLINK_POWER_STATE_HIGH_SPEED 0x0 +#define NVML_NVLINK_POWER_STATE_LOW 0x1 + +#define NVML_NVLINK_LOW_POWER_THRESHOLD_MIN 0x1 +#define NVML_NVLINK_LOW_POWER_THRESHOLD_MAX 0x1FFF +#define NVML_NVLINK_LOW_POWER_THRESHOLD_RESET 0xFFFFFFFF + +/* Structure containing Low Power parameters */ +typedef struct nvmlNvLinkPowerThres_st +{ + unsigned int lowPwrThreshold; //!< Low power threshold (in units of 100us) +} nvmlNvLinkPowerThres_t; + +/** + * Set NvLink Low Power Threshold for device. + * + * %HOPPER_OR_NEWER% + * + * @param device The identifier of the target device + * @param info Reference to \a nvmlNvLinkPowerThres_t struct + * input parameters + * + * @return + * - \ref NVML_SUCCESS if the \a Threshold is successfully set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a Threshold is not within range + * - \ref NVML_ERROR_NOT_SUPPORTED if this query is not supported by the device + * + **/ +nvmlReturn_t DECLDIR nvmlDeviceSetNvLinkDeviceLowPowerThreshold(nvmlDevice_t device, nvmlNvLinkPowerThres_t *info); + +/** + * Set the global nvlink bandwith mode + * + * @param nvlinkBwMode nvlink bandwidth mode + * @return + * - \ref NVML_SUCCESS on success + * - \ref NVML_ERROR_INVALID_ARGUMENT if an invalid argument is provided + * - \ref NVML_ERROR_IN_USE if P2P object exists + * - \ref NVML_ERROR_NOT_SUPPORTED if GPU is not Hopper or newer architecture. + * - \ref NVML_ERROR_NO_PERMISSION if not root user + */ +nvmlReturn_t DECLDIR nvmlSystemSetNvlinkBwMode(unsigned int nvlinkBwMode); + +/** + * Get the global nvlink bandwith mode + * + * @param nvlinkBwMode reference of nvlink bandwidth mode + * @return + * - \ref NVML_SUCCESS on success + * - \ref NVML_ERROR_INVALID_ARGUMENT if an invalid pointer is provided + * - \ref NVML_ERROR_NOT_SUPPORTED if GPU is not Hopper or newer architecture. + * - \ref NVML_ERROR_NO_PERMISSION if not root user + */ +nvmlReturn_t DECLDIR nvmlSystemGetNvlinkBwMode(unsigned int *nvlinkBwMode); + +/** + * Set new power limit of this device. + * + * For Kepler &tm; or newer fully supported devices. + * Requires root/admin permissions. + * + * See \ref nvmlDeviceGetPowerManagementLimitConstraints to check the allowed ranges of values. + * + * See \ref nvmlPowerValue_v2_t for more information on the struct. + * + * \note Limit is not persistent across reboots or driver unloads. + * Enable persistent mode to prevent driver from unloading when no application is using the device. + * + * This API replaces nvmlDeviceSetPowerManagementLimit. It can be used as a drop-in replacement for the older version. + * + * @param device The identifier of the target device + * @param powerValue Power management limit in milliwatts to set + * + * @return + * - \ref NVML_SUCCESS if \a limit has been set + * - \ref NVML_ERROR_UNINITIALIZED if the library has not been successfully initialized + * - \ref NVML_ERROR_INVALID_ARGUMENT if \a device is invalid or \a powerValue is NULL or contains invalid values * - \ref NVML_ERROR_NOT_SUPPORTED if the device does not support this feature * - \ref NVML_ERROR_GPU_IS_LOST if the target GPU has fallen off the bus or is otherwise inaccessible * - \ref NVML_ERROR_UNKNOWN on any unexpected error + * + * @see NVML_FI_DEV_POWER_AVERAGE + * @see NVML_FI_DEV_POWER_INSTANT + * @see NVML_FI_DEV_POWER_MIN_LIMIT + * @see NVML_FI_DEV_POWER_MAX_LIMIT + * @see NVML_FI_DEV_POWER_CURRENT_LIMIT */ -nvmlReturn_t DECLDIR nvmlDeviceGetProcessUtilization(nvmlDevice_t device, nvmlProcessUtilizationSample_t *utilization, - unsigned int *processSamplesCount, unsigned long long lastSeenTimeStamp); +nvmlReturn_t DECLDIR nvmlDeviceSetPowerManagementLimit_v2(nvmlDevice_t device, nvmlPowerValue_v2_t *powerValue); -/** @} */ /** * NVML API versioning support */ -#if defined(__NVML_API_VERSION_INTERNAL) + +#ifdef NVML_NO_UNVERSIONED_FUNC_DEFS +nvmlReturn_t DECLDIR nvmlInit(void); +nvmlReturn_t DECLDIR nvmlDeviceGetCount(unsigned int *deviceCount); +nvmlReturn_t DECLDIR nvmlDeviceGetHandleByIndex(unsigned int index, nvmlDevice_t *device); +nvmlReturn_t DECLDIR nvmlDeviceGetHandleByPciBusId(const char *pciBusId, nvmlDevice_t *device); +nvmlReturn_t DECLDIR nvmlDeviceGetPciInfo(nvmlDevice_t device, nvmlPciInfo_t *pci); +nvmlReturn_t DECLDIR nvmlDeviceGetPciInfo_v2(nvmlDevice_t device, nvmlPciInfo_t *pci); +nvmlReturn_t DECLDIR nvmlDeviceGetNvLinkRemotePciInfo(nvmlDevice_t device, unsigned int link, nvmlPciInfo_t *pci); +nvmlReturn_t DECLDIR nvmlDeviceGetGridLicensableFeatures(nvmlDevice_t device, nvmlGridLicensableFeatures_t *pGridLicensableFeatures); +nvmlReturn_t DECLDIR nvmlDeviceGetGridLicensableFeatures_v2(nvmlDevice_t device, nvmlGridLicensableFeatures_t *pGridLicensableFeatures); +nvmlReturn_t DECLDIR nvmlDeviceGetGridLicensableFeatures_v3(nvmlDevice_t device, nvmlGridLicensableFeatures_t *pGridLicensableFeatures); +nvmlReturn_t DECLDIR nvmlDeviceRemoveGpu(nvmlPciInfo_t *pciInfo); +nvmlReturn_t DECLDIR nvmlEventSetWait(nvmlEventSet_t set, nvmlEventData_t * data, unsigned int timeoutms); +nvmlReturn_t DECLDIR nvmlDeviceGetAttributes(nvmlDevice_t device, nvmlDeviceAttributes_t *attributes); +nvmlReturn_t DECLDIR nvmlComputeInstanceGetInfo(nvmlComputeInstance_t computeInstance, nvmlComputeInstanceInfo_t *info); +nvmlReturn_t DECLDIR nvmlDeviceGetComputeRunningProcesses(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_v1_t *infos); +nvmlReturn_t DECLDIR nvmlDeviceGetComputeRunningProcesses_v2(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_v2_t *infos); +nvmlReturn_t DECLDIR nvmlDeviceGetGraphicsRunningProcesses(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_v1_t *infos); +nvmlReturn_t DECLDIR nvmlDeviceGetGraphicsRunningProcesses_v2(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_v2_t *infos); +nvmlReturn_t DECLDIR nvmlDeviceGetMPSComputeRunningProcesses(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_v1_t *infos); +nvmlReturn_t DECLDIR nvmlDeviceGetMPSComputeRunningProcesses_v2(nvmlDevice_t device, unsigned int *infoCount, nvmlProcessInfo_v2_t *infos); +nvmlReturn_t DECLDIR nvmlDeviceGetGpuInstancePossiblePlacements(nvmlDevice_t device, unsigned int profileId, nvmlGpuInstancePlacement_t *placements, unsigned int *count); +nvmlReturn_t DECLDIR nvmlVgpuInstanceGetLicenseInfo(nvmlVgpuInstance_t vgpuInstance, nvmlVgpuLicenseInfo_t *licenseInfo); +#endif // #ifdef NVML_NO_UNVERSIONED_FUNC_DEFS + +#if defined(NVML_NO_UNVERSIONED_FUNC_DEFS) +// We don't define APIs to run new versions if this guard is present so there is +// no need to undef +#elif defined(__NVML_API_VERSION_INTERNAL) +#undef nvmlDeviceGetGraphicsRunningProcesses +#undef nvmlDeviceGetComputeRunningProcesses +#undef nvmlDeviceGetMPSComputeRunningProcesses +#undef nvmlDeviceGetAttributes +#undef nvmlComputeInstanceGetInfo +#undef nvmlEventSetWait +#undef nvmlDeviceGetGridLicensableFeatures +#undef nvmlDeviceRemoveGpu #undef nvmlDeviceGetNvLinkRemotePciInfo #undef nvmlDeviceGetPciInfo #undef nvmlDeviceGetCount #undef nvmlDeviceGetHandleByIndex #undef nvmlDeviceGetHandleByPciBusId #undef nvmlInit +#undef nvmlBlacklistDeviceInfo_t +#undef nvmlGetBlacklistDeviceCount +#undef nvmlGetBlacklistDeviceInfoByIndex +#undef nvmlDeviceGetGpuInstancePossiblePlacements +#undef nvmlVgpuInstanceGetLicenseInfo +#undef nvmlDeviceSetPowerManagementLimit + #endif #ifdef __cplusplus diff --git a/src/3rdparty/nvml/repo.json b/src/3rdparty/nvml/repo.json index 8612ffb39..ae0121463 100644 --- a/src/3rdparty/nvml/repo.json +++ b/src/3rdparty/nvml/repo.json @@ -1,6 +1,6 @@ { - "home": "https://developer.nvidia.com/gpu-deployment-kit", + "home": "https://github.com/NVIDIA/nvidia-settings/blob/main/src/nvml.h", "license": "Embed in source", - "version": "v9", + "version": "545.23.06", "author": "NVIDIA Corporation" } diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index fc891fc27..651cc0e42 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -243,7 +243,11 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* #endif if (gpu->temperature != gpu->temperature && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) - ffDetectNvidiaGpuTemp(&gpu->temperature, device->device_id); + { + char pciDeviceId[32]; + snprintf(pciDeviceId, sizeof(pciDeviceId) - 1, "%04x:%02x:%02x.%d", device->domain, device->bus, device->dev, device->func); + ffDetectNvidiaGpuTemp(&gpu->temperature, pciDeviceId, 0, 0); + } } jmp_buf pciInitJmpBuf; diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 80ed6fd91..3ddba91fc 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -75,13 +75,6 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->dedicated.total = dedicatedVideoMemory + dedicatedSystemMemory; gpu->shared.total = sharedSystemMemory; } - - if (options->temp && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) - { - uint32_t deviceId; - if(ffRegReadUint(hDirectxKey, L"DeviceId", &deviceId, NULL)) - ffDetectNvidiaGpuTemp(&gpu->temperature, deviceId); - } } else if (!ffRegReadUint64(hKey, L"HardwareInformation.qwMemorySize", &gpu->dedicated.total, NULL)) { @@ -91,6 +84,15 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; } } + + if (options->temp && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) + { + uint32_t vendorId, deviceId, subSystemId; + // See: https://download.nvidia.com/XFree86/Linux-x86_64/545.23.06/README/supportedchips.html + // displayDevice.DeviceID = MatchingDeviceId "PCI\\VEN_10DE&DEV_2782&SUBSYS_513417AA&REV_A1" + if (swscanf(displayDevice.DeviceID, L"PCI\\VEN_%x&DEV_%x&SUBSYS_%x", &vendorId, &deviceId, &subSystemId) == 3) + ffDetectNvidiaGpuTemp(&gpu->temperature, NULL, (deviceId << 16) | vendorId, subSystemId); + } } return NULL; diff --git a/src/detection/temps/temps_nvidia.c b/src/detection/temps/temps_nvidia.c index 90f241d1a..61194f3a1 100644 --- a/src/detection/temps/temps_nvidia.c +++ b/src/detection/temps/temps_nvidia.c @@ -6,13 +6,17 @@ struct FFNvmlData { FF_LIBRARY_SYMBOL(nvmlDeviceGetCount_v2) FF_LIBRARY_SYMBOL(nvmlDeviceGetHandleByIndex_v2) + FF_LIBRARY_SYMBOL(nvmlDeviceGetHandleByPciBusId_v2) FF_LIBRARY_SYMBOL(nvmlDeviceGetPciInfo_v3) FF_LIBRARY_SYMBOL(nvmlDeviceGetTemperature) bool inited; } nvmlData; -const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId) +// Use pciBusId if not NULL; use pciDeviceId and pciSubSystemId otherwise +// pciBusId = "domain:bus:device.function" +// pciDeviceId = (deviceId << 16) | vendorId +const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t pciDeviceId, uint32_t pciSubSystemId) { if (!nvmlData.inited) { @@ -29,6 +33,7 @@ const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlShutdown) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetCount_v2) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetHandleByIndex_v2) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetHandleByPciBusId_v2) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetPciInfo_v3) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetTemperature) @@ -44,30 +49,40 @@ const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId) if (nvmlData.ffnvmlDeviceGetTemperature == NULL) return "loading nvml library failed"; - uint32_t count; - if (nvmlData.ffnvmlDeviceGetCount_v2(&count) != NVML_SUCCESS) - return "nvmlDeviceGetCount_v2() failed"; - - for (uint32_t i = 0; i < count; i++) + nvmlDevice_t device = NULL; + if (pciBusId) { - nvmlDevice_t device; - if (nvmlData.ffnvmlDeviceGetHandleByIndex_v2(i, &device) != NVML_SUCCESS) - continue; + nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(pciBusId, &device); + if (ret != NVML_SUCCESS) + return "nvmlDeviceGetHandleByPciBusId_v2() failed"; + } + else + { + uint32_t count; + if (nvmlData.ffnvmlDeviceGetCount_v2(&count) != NVML_SUCCESS) + return "nvmlDeviceGetCount_v2() failed"; - nvmlPciInfo_t pciInfo; - if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_SUCCESS) - continue; + for (uint32_t i = 0; i < count; i++, device = NULL) + { + if (nvmlData.ffnvmlDeviceGetHandleByIndex_v2(i, &device) != NVML_SUCCESS) + continue; - if (pciInfo.pciDeviceId >> 16 != deviceId) - continue; + nvmlPciInfo_t pciInfo; + if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_SUCCESS) + continue; - uint32_t value; - if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) != NVML_SUCCESS) - return "nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) failed"; + if (pciInfo.pciDeviceId != pciDeviceId || pciInfo.pciSubSystemId != pciSubSystemId) + continue; - *temp = value; - return NULL; + break; + } + if (!device) return "Device not found"; } - return "Device not found"; + uint32_t value; + if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) != NVML_SUCCESS) + return "nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) failed"; + + *temp = value; + return NULL; } diff --git a/src/detection/temps/temps_nvidia.h b/src/detection/temps/temps_nvidia.h index 1b79d2522..3cf7dadda 100644 --- a/src/detection/temps/temps_nvidia.h +++ b/src/detection/temps/temps_nvidia.h @@ -2,4 +2,4 @@ #include -const char* ffDetectNvidiaGpuTemp(double* temp, uint32_t deviceId); +const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t pciDeviceId, uint32_t pciSubSystemId); From bfe1265c44e0a66b4605605726d86680ce1caa7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Fri, 27 Oct 2023 22:22:09 +0800 Subject: [PATCH 053/100] Logo (Builtin): add azos Ref: https://github.com/dylanaraps/neofetch/pull/2339 --- CHANGELOG.md | 1 + src/logo/ascii/azos.txt | 17 +++++++++++++++++ src/logo/builtin.c | 9 +++++++++ 3 files changed, 27 insertions(+) create mode 100644 src/logo/ascii/azos.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index cd686e92b..2e3e76451 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Logos: * Add Black Mesa * Add cycledream * Add Evolinx +* Add azos # 2.1.2 diff --git a/src/logo/ascii/azos.txt b/src/logo/ascii/azos.txt new file mode 100644 index 000000000..09fa5c910 --- /dev/null +++ b/src/logo/ascii/azos.txt @@ -0,0 +1,17 @@ +${c1} ////. ${c2} ((((( +${c1}//////// ${c2} @(((((((( +${c1}//////// ${c2} @(((((((( +${c1}//////// /////// ${c2} ((((((( @(((((((( +${c1}//////// ///////// ${c2} ((((((((( @(((((((( +${c1}//////// ///////// ${c2} ((((((((( @(((((((( +${c1}//////// ///////// ////// ${c2} (((((( ((((((((( @(((((((( +${c1}//////// ///////// //////// ${c2} (((((((( ((((((((( @(((((((( +${c1}//////// ///////// //////// ${c2} (((((((( ((((((((( @(((((((( +${c1}//////// ///////// //////// ${c2} ((((((( ((((((((( @(((((((( +${c1}//////// ///////// /// ${c2} ( ((((((((( @(((((((( +${c1}//////// ///////// ${c2} ((((((((( @(((((((( +${c1}//////// ///////// ${c2} &(((((((( @(((((((( +${c1}//////// ////// ${c2} @(((( @(((((((( +${c1}//////// ${c2} @(((((((( +${c1}//////// ${c2} @(((((((( +${c1} ///// ${c2} ((((( diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 67b41f763..582b898a0 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -524,6 +524,15 @@ static const FFlogo A[] = { .colorKeys = FF_COLOR_FG_YELLOW, .colorTitle = FF_COLOR_FG_WHITE, }, + // Azos + { + .names = {"Azos"}, + .lines = FASTFETCH_DATATEXT_LOGO_AZOS, + .colors = { + FF_COLOR_FG_CYAN, + FF_COLOR_FG_RED, + } + }, // LAST {}, }; From 2eb21e35216b573693897a9dc311d4359cd01309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 28 Oct 2023 13:00:45 +0800 Subject: [PATCH 054/100] TerminalFont: fix memleaks --- src/modules/terminalfont/terminalfont.c | 43 ++++++++++++------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/modules/terminalfont/terminalfont.c b/src/modules/terminalfont/terminalfont.c index 353e67845..5ee332f29 100644 --- a/src/modules/terminalfont/terminalfont.c +++ b/src/modules/terminalfont/terminalfont.c @@ -90,32 +90,31 @@ void ffGenerateTerminalFontJsonResult(FF_MAYBE_UNUSED FFTerminalOptions* options ffStrbufInit(&result.error); if(!ffDetectTerminalFont(&result)) - { yyjson_mut_obj_add_strbuf(doc, module, "error", &result.error); - return; - } - - yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); - - yyjson_mut_val* font = yyjson_mut_obj_add_obj(doc, obj, "font"); - yyjson_mut_obj_add_strbuf(doc, font, "name", &result.font.name); - yyjson_mut_obj_add_strbuf(doc, font, "size", &result.font.size); - yyjson_mut_val* fontStyles = yyjson_mut_obj_add_arr(doc, font, "styles"); - FF_LIST_FOR_EACH(FFstrbuf, style, result.font.styles) + else { - yyjson_mut_arr_add_strbuf(doc, fontStyles, style); - } - yyjson_mut_obj_add_strbuf(doc, font, "pretty", &result.font.pretty); + yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); - yyjson_mut_val* fallback = yyjson_mut_obj_add_obj(doc, obj, "fallback"); - yyjson_mut_obj_add_strbuf(doc, fallback, "name", &result.fallback.name); - yyjson_mut_obj_add_strbuf(doc, fallback, "size", &result.fallback.size); - yyjson_mut_val* fallbackStyles = yyjson_mut_obj_add_arr(doc, fallback, "styles"); - FF_LIST_FOR_EACH(FFstrbuf, style, result.fallback.styles) - { - yyjson_mut_arr_add_strbuf(doc, fallbackStyles, style); + yyjson_mut_val* font = yyjson_mut_obj_add_obj(doc, obj, "font"); + yyjson_mut_obj_add_strbuf(doc, font, "name", &result.font.name); + yyjson_mut_obj_add_strbuf(doc, font, "size", &result.font.size); + yyjson_mut_val* fontStyles = yyjson_mut_obj_add_arr(doc, font, "styles"); + FF_LIST_FOR_EACH(FFstrbuf, style, result.font.styles) + { + yyjson_mut_arr_add_strbuf(doc, fontStyles, style); + } + yyjson_mut_obj_add_strbuf(doc, font, "pretty", &result.font.pretty); + + yyjson_mut_val* fallback = yyjson_mut_obj_add_obj(doc, obj, "fallback"); + yyjson_mut_obj_add_strbuf(doc, fallback, "name", &result.fallback.name); + yyjson_mut_obj_add_strbuf(doc, fallback, "size", &result.fallback.size); + yyjson_mut_val* fallbackStyles = yyjson_mut_obj_add_arr(doc, fallback, "styles"); + FF_LIST_FOR_EACH(FFstrbuf, style, result.fallback.styles) + { + yyjson_mut_arr_add_strbuf(doc, fallbackStyles, style); + } + yyjson_mut_obj_add_strbuf(doc, fallback, "pretty", &result.fallback.pretty); } - yyjson_mut_obj_add_strbuf(doc, fallback, "pretty", &result.fallback.pretty); ffStrbufDestroy(&result.error); ffFontDestroy(&result.font); From 9d664e2b61ffada4c96aa7ecc2419c2e52f63541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 28 Oct 2023 13:11:04 +0800 Subject: [PATCH 055/100] GPU (Linux): support driver version detection --- src/detection/gpu/gpu_linux.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 651cc0e42..d252994b6 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -3,6 +3,7 @@ #include "detection/temps/temps_nvidia.h" #ifdef FF_HAVE_LIBPCI +#include "common/io/io.h" #include "common/library.h" #include "common/properties.h" #include "common/parsing.h" @@ -111,24 +112,28 @@ static void pciDetectDriverName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* #if PCI_LIB_VERSION >= 0x030800 pci->ffpci_fill_info(device, PCI_FILL_DRIVER); ffStrbufAppendS(&gpu->driver, pci->ffpci_get_string_property(device, PCI_FILL_DRIVER)); - - if(gpu->driver.length > 0) - return; #endif const char* base = pci->ffpci_get_param(pci->access, "sysfs.path"); if(!ffStrSet(base)) return; - FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateF("%s/devices/%04x:%02x:%02x.%d/driver", base, device->domain, device->bus, device->dev, device->func); - ffStrbufEnsureFree(&gpu->driver, 1023); - ssize_t resultLength = readlink(path.chars, gpu->driver.chars, gpu->driver.allocated - 1); //-1 for null terminator - if(resultLength > 0) + if (gpu->driver.length == 0) { - gpu->driver.length = (uint32_t) resultLength; - gpu->driver.chars[resultLength] = '\0'; - ffStrbufSubstrAfterLastC(&gpu->driver, '/'); + ffStrbufEnsureFree(&gpu->driver, 1023); + ssize_t resultLength = readlink(path.chars, gpu->driver.chars, gpu->driver.allocated - 1); //-1 for null terminator + if(resultLength > 0) + { + gpu->driver.length = (uint32_t) resultLength; + gpu->driver.chars[resultLength] = '\0'; + ffStrbufSubstrAfterLastC(&gpu->driver, '/'); + } } + + ffStrbufAppendC(&gpu->driver, ' '); + ffStrbufAppendS(&path, "/module/version"); + ffAppendFileBuffer(path.chars, &gpu->driver); + ffStrbufTrimRight(&gpu->driver, ' '); } FF_MAYBE_UNUSED static void pciDetectTemp(FFGPUResult* gpu, struct pci_dev* device) From 38d5791d57fb7b905d960cade7784cee4d8b6e9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 28 Oct 2023 13:12:04 +0800 Subject: [PATCH 056/100] GPU: support memory, core count detection --- CMakeLists.txt | 8 ++-- src/detection/gpu/gpu_linux.c | 13 ++++-- .../temps_nvidia.c => gpu/gpu_nvidia.c} | 46 +++++++++++++------ src/detection/gpu/gpu_nvidia.h | 23 ++++++++++ src/detection/gpu/gpu_windows.c | 15 ++++-- src/detection/temps/temps_nvidia.h | 5 -- src/modules/gpu/gpu.c | 5 +- 7 files changed, 84 insertions(+), 31 deletions(-) rename src/detection/{temps/temps_nvidia.c => gpu/gpu_nvidia.c} (63%) create mode 100644 src/detection/gpu/gpu_nvidia.h delete mode 100644 src/detection/temps/temps_nvidia.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f7fab9b6..96842bd7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ endif() set(WARNING_FLAGS "-Wall -Wextra -Wconversion -Werror=uninitialized -Werror=return-type") set(CMAKE_C_STANDARD 11) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=incompatible-pointer-types -Werror=implicit-function-declaration") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=int-conversion") if(WIN32 OR ENABLE_DIRECTX_HEADERS) enable_language(CXX) @@ -392,6 +392,7 @@ if(LINUX) src/detection/displayserver/linux/xlib.c src/detection/font/font_linux.c src/detection/gpu/gpu_linux.c + src/detection/gpu/gpu_nvidia.c src/detection/gtk_qt/gtk.c src/detection/host/host_linux.c src/detection/icons/icons_linux.c @@ -412,7 +413,6 @@ if(LINUX) src/detection/sound/sound_linux.c src/detection/swap/swap_linux.c src/detection/temps/temps_linux.c - src/detection/temps/temps_nvidia.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c src/detection/terminalsize/terminalsize_linux.c @@ -499,6 +499,7 @@ elseif(BSD) src/detection/displayserver/linux/xlib.c src/detection/font/font_linux.c src/detection/gpu/gpu_linux.c + src/detection/gpu/gpu_nvidia.c src/detection/gtk_qt/gtk.c src/detection/host/host_bsd.c src/detection/lm/lm_linux.c @@ -519,7 +520,6 @@ elseif(BSD) src/detection/sound/sound_linux.c src/detection/swap/swap_bsd.c src/detection/temps/temps_bsd.c - src/detection/temps/temps_nvidia.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c src/detection/terminalsize/terminalsize_linux.c @@ -603,6 +603,7 @@ elseif(WIN32) src/detection/displayserver/displayserver_windows.c src/detection/font/font_windows.c src/detection/gpu/gpu_windows.c + src/detection/gpu/gpu_nvidia.c src/detection/host/host_windows.c src/detection/icons/icons_windows.c src/detection/libc/libc_windows.cpp @@ -624,7 +625,6 @@ elseif(WIN32) src/detection/terminalshell/terminalshell_windows.c src/detection/terminalsize/terminalsize_windows.c src/detection/temps/temps_windows.cpp - src/detection/temps/temps_nvidia.c src/detection/theme/theme_nosupport.c src/detection/uptime/uptime_windows.c src/detection/users/users_windows.c diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index d252994b6..1401ebd88 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -1,6 +1,6 @@ #include "detection/gpu/gpu.h" +#include "detection/gpu/gpu_nvidia.h" #include "detection/vulkan/vulkan.h" -#include "detection/temps/temps_nvidia.h" #ifdef FF_HAVE_LIBPCI #include "common/io/io.h" @@ -247,11 +247,18 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* pciDetectTemp(gpu, device); #endif - if (gpu->temperature != gpu->temperature && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) { char pciDeviceId[32]; snprintf(pciDeviceId, sizeof(pciDeviceId) - 1, "%04x:%02x:%02x.%d", device->domain, device->bus, device->dev, device->func); - ffDetectNvidiaGpuTemp(&gpu->temperature, pciDeviceId, 0, 0); + + ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) { .pciBusId = pciDeviceId }, (FFGpuNvidiaResult) { + .temp = gpu->temperature != gpu->temperature ? &gpu->temperature : NULL, + .memory = &gpu->dedicated, + .coreCount = (uint32_t*) &gpu->coreCount, + }); + + gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; } } diff --git a/src/detection/temps/temps_nvidia.c b/src/detection/gpu/gpu_nvidia.c similarity index 63% rename from src/detection/temps/temps_nvidia.c rename to src/detection/gpu/gpu_nvidia.c index 61194f3a1..9ce4b2f8d 100644 --- a/src/detection/temps/temps_nvidia.c +++ b/src/detection/gpu/gpu_nvidia.c @@ -1,4 +1,4 @@ -#include "temps_nvidia.h" +#include "gpu_nvidia.h" #include "3rdparty/nvml/nvml.h" #include "common/library.h" @@ -9,14 +9,13 @@ struct FFNvmlData { FF_LIBRARY_SYMBOL(nvmlDeviceGetHandleByPciBusId_v2) FF_LIBRARY_SYMBOL(nvmlDeviceGetPciInfo_v3) FF_LIBRARY_SYMBOL(nvmlDeviceGetTemperature) + FF_LIBRARY_SYMBOL(nvmlDeviceGetMemoryInfo_v2) + FF_LIBRARY_SYMBOL(nvmlDeviceGetNumGpuCores) bool inited; } nvmlData; -// Use pciBusId if not NULL; use pciDeviceId and pciSubSystemId otherwise -// pciBusId = "domain:bus:device.function" -// pciDeviceId = (deviceId << 16) | vendorId -const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t pciDeviceId, uint32_t pciSubSystemId) +const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result) { if (!nvmlData.inited) { @@ -27,7 +26,7 @@ const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t p #else "libnvidia-ml" #endif - FF_LIBRARY_EXTENSION, -1 + FF_LIBRARY_EXTENSION, -1 ); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlInit_v2) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlShutdown) @@ -36,23 +35,25 @@ const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t p FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetHandleByPciBusId_v2) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetPciInfo_v3) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetTemperature) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetMemoryInfo_v2) + FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetNumGpuCores) if (ffnvmlInit_v2() != NVML_SUCCESS) { - nvmlData.ffnvmlDeviceGetTemperature = NULL; + nvmlData.ffnvmlDeviceGetNumGpuCores = NULL; return "nvmlInit_v2() failed"; } atexit((void*) ffnvmlShutdown); libnvml = NULL; // don't close nvml } - if (nvmlData.ffnvmlDeviceGetTemperature == NULL) + if (nvmlData.ffnvmlDeviceGetNumGpuCores == NULL) return "loading nvml library failed"; nvmlDevice_t device = NULL; - if (pciBusId) + if (cond.pciBusId) { - nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(pciBusId, &device); + nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(cond.pciBusId, &device); if (ret != NVML_SUCCESS) return "nvmlDeviceGetHandleByPciBusId_v2() failed"; } @@ -71,7 +72,7 @@ const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t p if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_SUCCESS) continue; - if (pciInfo.pciDeviceId != pciDeviceId || pciInfo.pciSubSystemId != pciSubSystemId) + if (pciInfo.pciDeviceId != cond.pciDeviceId || pciInfo.pciSubSystemId != cond.pciSubSystemId) continue; break; @@ -79,10 +80,25 @@ const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t p if (!device) return "Device not found"; } - uint32_t value; - if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) != NVML_SUCCESS) - return "nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) failed"; + if (result.temp) + { + uint32_t value; + if (nvmlData.ffnvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU, &value) == NVML_SUCCESS) + *result.temp = value; + } + + if (result.memory) + { + nvmlMemory_v2_t memory = { .version = nvmlMemory_v2 }; + if (nvmlData.ffnvmlDeviceGetMemoryInfo_v2(device, &memory) == NVML_SUCCESS) + { + result.memory->total = memory.used + memory.free; + result.memory->used = memory.used; + } + } + + if (result.coreCount) + nvmlData.ffnvmlDeviceGetNumGpuCores(device, result.coreCount); - *temp = value; return NULL; } diff --git a/src/detection/gpu/gpu_nvidia.h b/src/detection/gpu/gpu_nvidia.h new file mode 100644 index 000000000..b891595cf --- /dev/null +++ b/src/detection/gpu/gpu_nvidia.h @@ -0,0 +1,23 @@ +#pragma once + +#include "gpu.h" + +// Use pciBusId if not NULL; use pciDeviceId and pciSubSystemId otherwise +// pciBusId = "domain:bus:device.function" +// pciDeviceId = (deviceId << 16) | vendorId +typedef struct FFGpuNvidiaCondition +{ + const char* pciBusId; + uint32_t pciDeviceId; + uint32_t pciSubSystemId; +} FFGpuNvidiaCondition; + +// detect x if not NULL +typedef struct FFGpuNvidiaResult +{ + double* temp; + FFGPUMemory* memory; + uint32_t* coreCount; +} FFGpuNvidiaResult; + +const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result); diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 3ddba91fc..ce2d535c1 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -1,5 +1,5 @@ #include "gpu.h" -#include "detection/temps/temps_nvidia.h" +#include "detection/gpu/gpu_nvidia.h" #include "util/windows/unicode.h" #include "util/windows/registry.h" @@ -85,13 +85,22 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* } } - if (options->temp && gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || instance.config.general.allowSlowOperations)) { uint32_t vendorId, deviceId, subSystemId; // See: https://download.nvidia.com/XFree86/Linux-x86_64/545.23.06/README/supportedchips.html // displayDevice.DeviceID = MatchingDeviceId "PCI\\VEN_10DE&DEV_2782&SUBSYS_513417AA&REV_A1" if (swscanf(displayDevice.DeviceID, L"PCI\\VEN_%x&DEV_%x&SUBSYS_%x", &vendorId, &deviceId, &subSystemId) == 3) - ffDetectNvidiaGpuTemp(&gpu->temperature, NULL, (deviceId << 16) | vendorId, subSystemId); + { + ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) { + .pciDeviceId = (deviceId << 16) | vendorId, + .pciSubSystemId = subSystemId, + }, (FFGpuNvidiaResult) { + .temp = options->temp ? &gpu->temperature : NULL, + .memory = &gpu->dedicated, + .coreCount = (uint32_t*) &gpu->coreCount, + }); + } } } diff --git a/src/detection/temps/temps_nvidia.h b/src/detection/temps/temps_nvidia.h deleted file mode 100644 index 3cf7dadda..000000000 --- a/src/detection/temps/temps_nvidia.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -#include - -const char* ffDetectNvidiaGpuTemp(double* temp, const char* pciBusId, uint32_t pciDeviceId, uint32_t pciSubSystemId); diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 2a48e463d..02321e20e 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -275,7 +275,10 @@ void ffGenerateGPUJsonResult(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_ else yyjson_mut_obj_add_null(doc, sharedObj, "used"); - yyjson_mut_obj_add_null(doc, obj, "temperature"); + if(gpu->temperature == gpu->temperature) //FF_GPU_TEMP_UNSET + yyjson_mut_obj_add_real(doc, obj, "temperature", gpu->temperature); + else + yyjson_mut_obj_add_null(doc, obj, "temperature"); const char* type; switch (gpu->type) From 799628c083c950d8e6207bd843f657c300036728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 28 Oct 2023 17:23:49 +0800 Subject: [PATCH 057/100] GPU: guard nvml related code behind `--allow-slow-operations` --- src/detection/gpu/gpu_linux.c | 21 +++++++++++---------- src/detection/gpu/gpu_windows.c | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 1401ebd88..36e1fc475 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -242,24 +242,25 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; gpu->temperature = FF_GPU_TEMP_UNSET; - #ifdef __linux__ - if(options->temp) - pciDetectTemp(gpu, device); - #endif - - if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA) + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || instance.config.general.allowSlowOperations)) { char pciDeviceId[32]; snprintf(pciDeviceId, sizeof(pciDeviceId) - 1, "%04x:%02x:%02x.%d", device->domain, device->bus, device->dev, device->func); ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) { .pciBusId = pciDeviceId }, (FFGpuNvidiaResult) { - .temp = gpu->temperature != gpu->temperature ? &gpu->temperature : NULL, - .memory = &gpu->dedicated, - .coreCount = (uint32_t*) &gpu->coreCount, + .temp = options->temp ? &gpu->temperature : NULL, + .memory = instance.config.general.allowSlowOperations ? &gpu->dedicated : NULL, + .coreCount = instance.config.general.allowSlowOperations ? (uint32_t*) &gpu->coreCount : NULL, }); - gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; + if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) + gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; } + + #ifdef __linux__ + if(options->temp && gpu->temperature != gpu->temperature) + pciDetectTemp(gpu, device); + #endif } jmp_buf pciInitJmpBuf; diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index ce2d535c1..c9a585bee 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -97,8 +97,8 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* .pciSubSystemId = subSystemId, }, (FFGpuNvidiaResult) { .temp = options->temp ? &gpu->temperature : NULL, - .memory = &gpu->dedicated, - .coreCount = (uint32_t*) &gpu->coreCount, + .memory = instance.config.general.allowSlowOperations ? &gpu->dedicated : NULL, + .coreCount = instance.config.general.allowSlowOperations ? (uint32_t*) &gpu->coreCount : NULL, }); } } From c52353b4b8bcc150d9254c51f6c345ab85fd4c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 28 Oct 2023 20:14:22 +0800 Subject: [PATCH 058/100] Vulkan: remove used GPU memory detection, which is unreliable Ref: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_memory_budget.html#_description --- CHANGELOG.md | 3 ++- src/detection/vulkan/vulkan.c | 36 ++++++++--------------------------- 2 files changed, 10 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e3e76451..828298ac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,13 +15,14 @@ Features: * Support st version detection (Terminal, Linux) * Support st terminal font detection (TerminalFont, Linux) * Add option `--migrate-config ` -* Support Nvidia GPU temp detection via nvml (GPU) +* Support Nvidia GPU temp and cuda core count detection via nvml (GPU) * Try supporting Wifi authentication type detection in macOS Sonoma. Please file a feature request if you get `to be supported (num)` with result of `/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep auth` (Wifi, macOS) Bugfixes: * Better GPU memory and type detection (GPU, Windows) * Don't print display type twice (Display) * Detect BSSID instead of Wifi MAC address to align with other platforms (Wifi, macOS) +* Remove support of used GPU memory detection, which is not reliable and only supported with `--gpu-force-vulkan`. (GPU) Logos: * Add Black Mesa diff --git a/src/detection/vulkan/vulkan.c b/src/detection/vulkan/vulkan.c index dd337e8d2..07d10a57a 100644 --- a/src/detection/vulkan/vulkan.c +++ b/src/detection/vulkan/vulkan.c @@ -117,11 +117,7 @@ static const char* detectVulkan(FFVulkanResult* result) if(!ffvkGetPhysicalDeviceProperties2) ffvkGetPhysicalDeviceProperties = (PFN_vkGetPhysicalDeviceProperties) ffvkGetInstanceProcAddr(vkInstance, "vkGetPhysicalDeviceProperties"); - PFN_vkGetPhysicalDeviceMemoryProperties ffvkGetPhysicalDeviceMemoryProperties = NULL; - PFN_vkGetPhysicalDeviceMemoryProperties2 ffvkGetPhysicalDeviceMemoryProperties2 = - instance.config.general.allowSlowOperations ? (PFN_vkGetPhysicalDeviceMemoryProperties2) ffvkGetInstanceProcAddr(vkInstance, "vkGetPhysicalDeviceMemoryProperties2") : NULL; // 1.1 - if(!ffvkGetPhysicalDeviceMemoryProperties2) - ffvkGetPhysicalDeviceMemoryProperties = (PFN_vkGetPhysicalDeviceMemoryProperties) ffvkGetInstanceProcAddr(vkInstance, "vkGetPhysicalDeviceMemoryProperties"); + PFN_vkGetPhysicalDeviceMemoryProperties ffvkGetPhysicalDeviceMemoryProperties = (PFN_vkGetPhysicalDeviceMemoryProperties) ffvkGetInstanceProcAddr(vkInstance, "vkGetPhysicalDeviceMemoryProperties"); FFVersion maxDeviceApiVersion = FF_VERSION_INIT; FFVersion maxDeviceConformanceVersion = FF_VERSION_INIT; @@ -187,38 +183,22 @@ static const char* detectVulkan(FFVulkanResult* result) gpu->vulkanDeviceId = physicalDeviceProperties.properties.deviceID; - ffStrbufInit(&gpu->name); - ffStrbufAppendS(&gpu->name, physicalDeviceProperties.properties.deviceName); + ffStrbufInitS(&gpu->name, physicalDeviceProperties.properties.deviceName); - if(physicalDeviceProperties.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) - gpu->type = FF_GPU_TYPE_DISCRETE; - else - gpu->type = FF_GPU_TYPE_INTEGRATED; + gpu->type = physicalDeviceProperties.properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; ffStrbufInitS(&gpu->vendor, ffGetGPUVendorString(physicalDeviceProperties.properties.vendorID)); ffStrbufInitS(&gpu->driver, driverProperties.driverInfo); - VkPhysicalDeviceMemoryBudgetPropertiesEXT budgetProperties = { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT, - }; - VkPhysicalDeviceMemoryProperties2 memoryProperties2 = { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2, - .pNext = &budgetProperties, - }; - - if(ffvkGetPhysicalDeviceMemoryProperties2) - ffvkGetPhysicalDeviceMemoryProperties2(physicalDevices[i], &memoryProperties2); - else - ffvkGetPhysicalDeviceMemoryProperties(physicalDevices[i], &memoryProperties2.memoryProperties); + VkPhysicalDeviceMemoryProperties memoryProperties = {}; + ffvkGetPhysicalDeviceMemoryProperties(physicalDevices[i], &memoryProperties); gpu->dedicated.total = gpu->shared.total = 0; - gpu->dedicated.used = gpu->shared.used = ffvkGetPhysicalDeviceMemoryProperties2 ? 0 : FF_GPU_VMEM_SIZE_UNSET; - for(uint32_t index = 0; index < memoryProperties2.memoryProperties.memoryHeapCount; ++index) + gpu->dedicated.used = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET; + for(uint32_t index = 0; index < memoryProperties.memoryHeapCount; ++index) { - const VkMemoryHeap* heap = &memoryProperties2.memoryProperties.memoryHeaps[index]; + const VkMemoryHeap* heap = &memoryProperties.memoryHeaps[index]; FFGPUMemory* vmem = gpu->type == FF_GPU_TYPE_DISCRETE && (heap->flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) ? &gpu->dedicated : &gpu->shared; vmem->total += heap->size; - if(ffvkGetPhysicalDeviceMemoryProperties2) - vmem->used += heap->size - budgetProperties.heapBudget[index]; } //No way to detect those using vulkan From 2414246de9412e07d3d14b93d4d43d3d57c255f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 28 Oct 2023 21:52:28 +0800 Subject: [PATCH 059/100] Migration (Logo): fix `--logo-color-num` --- src/options/logo.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/options/logo.c b/src/options/logo.c index ae3210768..2b0daebe6 100644 --- a/src/options/logo.c +++ b/src/options/logo.c @@ -469,13 +469,13 @@ void ffOptionsGenerateLogoJsonConfig(FFOptionsLogo* options, yyjson_mut_doc* doc yyjson_mut_obj_add_str(doc, obj, "source", options->source.chars); { - yyjson_mut_val* color = yyjson_mut_arr(doc); + yyjson_mut_val* color = yyjson_mut_obj(doc); for (int i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++) { if (!ffStrbufEqual(&options->colors[i], &defaultOptions.colors[i])) - yyjson_mut_arr_add_strbuf(doc, color, &options->colors[i]); + yyjson_mut_obj_add_strbuf(doc, color, (const char [2]) { (char)('1' + i) }, &options->colors[i]); } - if (yyjson_mut_arr_size(color) > 0) + if (yyjson_mut_obj_size(color) > 0) yyjson_mut_obj_add_val(doc, obj, "color", color); } From 63032cd840cf6a92daa372f966085ee18540d94d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 28 Oct 2023 23:02:28 +0800 Subject: [PATCH 060/100] Doc: update help.txt --- doc/json_schema.json | 2 +- src/data/help.txt | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/doc/json_schema.json b/doc/json_schema.json index ddb007448..3211ccb29 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -449,7 +449,7 @@ }, "xcbRandr": { "type": "string", - "title": "" + "title": "X11 sessions for better display detection and faster WM detection.\nThe *randr ones provide multi monitor support The libxcb* ones usually have better performance.\n (Linux, FreeBSD)" }, "xcb": { "type": "string", diff --git a/src/data/help.txt b/src/data/help.txt index 719a46c67..a495119cb 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -14,21 +14,20 @@ Informative options: --print-config-system: Print the default system config --print-config-user: Print the default user config --print-structure: Print the default structure - --gen-config : Generate a sample config file in the default path. Param `type` can be `jsonc` or deprecated `conf` - --gen-config-force : Generate a sample config file in the default path. Overwrite the existing one - --migrate-config : Migrate old flag based config file to new JSONC format. Optional param `path` is the file path that new file should be write to + +Config options: + --load-config,--config,-c : Load a config file or preset (+) + --gen-config : Generate a sample config file in the default path. Param `type` can be `jsonc` or deprecated `conf` + --gen-config-force : Generate a sample config file in the default path. Overwrite the existing one + --migrate-config : Migrate old flag based config file to new JSONC format. Optional param `path` is the file path that new file should be write to General options: - --load-config : Load a config file or preset (+) - --config : Alias of --load-config (+) - --multithreading : Use multiple threads to detect values - --stat : Show time usage (in ms) for individual modules - --allow-slow-operations : Allow operations that are usually very slow for more detailed output - --escape-bedrock : On Bedrock Linux, whether to escape the bedrock jail - --pipe : Disable logo and all escape sequences - --wmi-timeout : Set the timeout (ms) for WMI queries. Windows only. Default is 5000 - --processing-timeout : Set the timeout (ms) when waiting for child processes. Default is 1000 - --ds-force-drm : Set if only DRM should be used to detect displays. Default is false + --multithreading,--thread : Use multiple threads to detect values + --allow-slow-operations : Allow operations that are usually very slow for more detailed output + --escape-bedrock : On Bedrock Linux, whether to escape the bedrock jail + --wmi-timeout : Set the timeout (ms) for WMI queries. Windows only. Default is 5000 + --processing-timeout : Set the timeout (ms) when waiting for child processes. Default is 1000 + --ds-force-drm : Set if only DRM should be used to detect displays. Default is false. Linux only Logo options: -l,--logo : Set the logo; if default, the name of a builtin logo or a path to a file @@ -42,6 +41,7 @@ Logo options: --logo-padding-right : Set the padding on the right of the logo --logo-padding-top : Set the padding on the top of the logo --logo-print-remaining : Whether to print the remaining logo, if it has more lines than modules to display + --logo-separate : If true, print modules at bottom of the logo --logo-recache : If true, regenerate image logo cache --file : Short for --logo-type file --logo --file-raw : Short for --logo-type file-raw --logo @@ -59,6 +59,8 @@ Logo options: Display options: -s,--structure : Set the structure of the fetch. Must be a colon separated list of keys. Use "fastfetch --list-modules" to see the ones available. + --stat : Show time usage (in ms) for individual modules + --pipe : Disable logo and all escape sequences --color-keys : Set the color of the keys --color-title : Set the color of the title --color : Set the color of both the keys and title @@ -124,7 +126,7 @@ Module specific options: --title-color-at : Set color of the @ symbol (middle part). Default is empty (use color of `--color-title`) --title-color-host : Set color of the host name (right part). Default is empty (use color of `--color-title`) --separator-string : Set the string printed by the separator module - --os-file : Set the path to the file containing OS information + --os-file : Set the path to the file containing OS information. Linux only --disk-folders : A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows) --disk-show-regular : Set if regular volume should be printed. Default is true --disk-show-external : Set if external volume should be printed. Default is true @@ -162,7 +164,7 @@ Module specific options: --weather-location: Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`). --weather-timeout: Time in milliseconds to wait for the weather server to respond. Default is disabled (0) --weather-output-format: The output weather format to be used. It must be URI encoded. - --player-name: The name of the player to use + --player-name: The name of the player to use for module Media and Player. Linux only --opengl-library : Set the OpenGL context creation library to use. Must be auto, egl, glx or osmesa. Default is auto --command-shell : Set the shell program to execute the command text. Default is cmd for Windows, /bin/sh for *nix --command-key : Set the module key to display From 25849dc4bbde57e0becb18eccc20e5d3f4b911f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 28 Oct 2023 23:39:15 +0800 Subject: [PATCH 061/100] Migration (Logo): fix `--logo-color-num` (v2) --- src/common/jsonconfig.h | 4 ++++ src/options/logo.c | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/jsonconfig.h b/src/common/jsonconfig.h index 917beadf2..12182855a 100644 --- a/src/common/jsonconfig.h +++ b/src/common/jsonconfig.h @@ -7,6 +7,10 @@ const char* ffJsonConfigParseEnum(yyjson_val* val, int* result, FFKeyValuePair p void ffPrintJsonConfig(bool prepare, yyjson_mut_doc* jsonDoc); void ffJsonConfigGenerateModuleArgsConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFModuleArgs* defaultModuleArgs, FFModuleArgs* moduleArgs); +yyjson_api_inline yyjson_mut_val* yyjson_mut_strbuf(yyjson_mut_doc *doc, const FFstrbuf* buf) { + return yyjson_mut_strncpy(doc, buf->chars, buf->length); +} + yyjson_api_inline bool yyjson_mut_obj_add_strbuf(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *_key, diff --git a/src/options/logo.c b/src/options/logo.c index 2b0daebe6..1d305e3b9 100644 --- a/src/options/logo.c +++ b/src/options/logo.c @@ -473,7 +473,10 @@ void ffOptionsGenerateLogoJsonConfig(FFOptionsLogo* options, yyjson_mut_doc* doc for (int i = 0; i < FASTFETCH_LOGO_MAX_COLORS; i++) { if (!ffStrbufEqual(&options->colors[i], &defaultOptions.colors[i])) - yyjson_mut_obj_add_strbuf(doc, color, (const char [2]) { (char)('1' + i) }, &options->colors[i]); + { + char c = (char)('1' + i); + yyjson_mut_obj_add(color, yyjson_mut_strncpy(doc, &c, 1), yyjson_mut_strbuf(doc, &options->colors[i])); + } } if (yyjson_mut_obj_size(color) > 0) yyjson_mut_obj_add_val(doc, obj, "color", color); From 627d5fc659785a51d9092a639ca3efd163946b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 29 Oct 2023 00:17:24 +0800 Subject: [PATCH 062/100] JsonConfig: restructure some keys --- CHANGELOG.md | 1 + doc/json_schema.json | 62 ++++++++++++++---------- src/options/display.c | 107 +++++++++++++++++++++++++----------------- 3 files changed, 103 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 828298ac0..561f6340a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This release introduces a new option `--migrate-config`, which migrates old flag Changes: * `--pipe` and `--stat` are moved from `general` options to `display` options. This affects cjson configuration. +* Display keys `percent*` and `size*` in JSON config are restructured. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }` * With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version) * Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version) diff --git a/doc/json_schema.json b/doc/json_schema.json index 3211ccb29..c401e5c45 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -359,18 +359,24 @@ } ] }, - "sizeNdigits": { - "type": "integer", - "title": "Set the number of digits to keep after the decimal point when formatting sizes", - "minimum": 0, - "maximum": 9, - "default": 2 - }, - "sizeMaxPrefix": { - "type": "string", - "title": "Set the largest binary prefix to use when formatting sizes", - "enum": ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], - "default": "YB" + "size": { + "type": "object", + "title": "Set how a size value should be displayed", + "properties": { + "maxPrefix": { + "type": "string", + "title": "Set the largest binary prefix to use when formatting sizes", + "enum": ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], + "default": "YB" + }, + "ndigits": { + "type": "integer", + "title": "Set the number of digits to keep after the decimal point when formatting sizes", + "minimum": 0, + "maximum": 9, + "default": 2 + } + } }, "temperatureUnit": { "type": "string", @@ -405,19 +411,25 @@ } } }, - "percentType": { - "type": "number", - "title": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number", - "minimum": 0, - "maximum": 255, - "default": 1 - }, - "percentNdigits": { - "type": "number", - "title": "Set the number of digits to keep after the decimal point when formatting percentage numbers", - "minimum": 0, - "maximum": 9, - "default": 0 + "percent": { + "type": "object", + "title": "Set how a percentage value should be displayed", + "properties": { + "type": { + "type": "number", + "title": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number", + "minimum": 0, + "maximum": 255, + "default": 1 + }, + "ndigits": { + "type": "number", + "title": "Set the number of digits to keep after the decimal point when formatting percentage numbers", + "minimum": 0, + "maximum": 9, + "default": 0 + }, + } }, "noBuffer": { "type": "boolean", diff --git a/src/options/display.c b/src/options/display.c index 6391bc87f..82385945b 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -65,25 +65,33 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va if (error) return error; options->binaryPrefixType = (FFBinaryPrefixType) value; } - else if (ffStrEqualsIgnCase(key, "sizeNdigits")) - options->sizeNdigits = (uint8_t) yyjson_get_uint(val); - else if (ffStrEqualsIgnCase(key, "sizeMaxPrefix")) + else if (ffStrEqualsIgnCase(key, "size")) { - int value; - const char* error = ffJsonConfigParseEnum(val, &value, (FFKeyValuePair[]) { - { "B", 0 }, - { "kB", 1 }, - { "MB", 2 }, - { "GB", 3 }, - { "TB", 4 }, - { "PB", 5 }, - { "EB", 6 }, - { "ZB", 7 }, - { "YB", 8 }, - {} - }); - if (error) return error; - options->sizeMaxPrefix = (uint8_t) value; + if (!yyjson_is_obj(val)) + return "display.size must be an object"; + + yyjson_val* maxPrefix = yyjson_obj_get(val, "maxPrefix"); + if (maxPrefix) + { + int value; + const char* error = ffJsonConfigParseEnum(maxPrefix, &value, (FFKeyValuePair[]) { + { "B", 0 }, + { "kB", 1 }, + { "MB", 2 }, + { "GB", 3 }, + { "TB", 4 }, + { "PB", 5 }, + { "EB", 6 }, + { "ZB", 7 }, + { "YB", 8 }, + {} + }); + if (error) return error; + options->sizeMaxPrefix = (uint8_t) value; + } + + yyjson_val* ndigits = yyjson_obj_get(val, "ndigits"); + if (ndigits) options->percentNdigits = (uint8_t) yyjson_get_uint(ndigits); } else if (ffStrEqualsIgnCase(key, "temperatureUnit")) { @@ -100,10 +108,17 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va if (error) return error; options->temperatureUnit = (FFTemperatureUnit) value; } - else if (ffStrEqualsIgnCase(key, "percentType")) - options->percentType = (uint8_t) yyjson_get_uint(val); - else if (ffStrEqualsIgnCase(key, "percentNdigits")) - options->percentNdigits = (uint8_t) yyjson_get_uint(val); + else if (ffStrEqualsIgnCase(key, "percent")) + { + if (!yyjson_is_obj(val)) + return "display.percent must be an object"; + + yyjson_val* type = yyjson_obj_get(val, "type"); + if (type) options->percentType = (uint8_t) yyjson_get_uint(type); + + yyjson_val* ndigits = yyjson_obj_get(val, "ndigits"); + if (ndigits) options->percentNdigits = (uint8_t) yyjson_get_uint(ndigits); + } else if (ffStrEqualsIgnCase(key, "bar")) { if (yyjson_is_obj(val)) @@ -357,22 +372,26 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do } } - if (options->sizeNdigits != defaultOptions.sizeNdigits) - yyjson_mut_obj_add_uint(doc, obj, "sizeNdigits", options->sizeNdigits); - - if (options->sizeMaxPrefix != defaultOptions.sizeMaxPrefix && options->sizeMaxPrefix <= 8) { - yyjson_mut_obj_add_str(doc, obj, "sizeMaxPrefix", ((const char* []) { - "B", - "kB", - "MB", - "GB", - "TB", - "PB", - "EB", - "ZB", - "YB", - })[options->sizeMaxPrefix]); + yyjson_mut_val* size = yyjson_mut_obj(doc); + if (options->sizeNdigits != defaultOptions.sizeNdigits) + yyjson_mut_obj_add_uint(doc, size, "ndigits", options->sizeNdigits); + if (options->sizeMaxPrefix != defaultOptions.sizeMaxPrefix && options->sizeMaxPrefix <= 8) + { + yyjson_mut_obj_add_str(doc, size, "maxPrefix", ((const char* []) { + "B", + "kB", + "MB", + "GB", + "TB", + "PB", + "EB", + "ZB", + "YB", + })[options->sizeMaxPrefix]); + } + if (yyjson_mut_obj_size(size) > 0) + yyjson_mut_obj_add_val(doc, obj, "size", size); } if (options->temperatureUnit != defaultOptions.temperatureUnit) @@ -391,11 +410,15 @@ void ffOptionsGenerateDisplayJsonConfig(FFOptionsDisplay* options, yyjson_mut_do } } - if (options->percentType != defaultOptions.percentType) - yyjson_mut_obj_add_uint(doc, obj, "percentType", options->percentType); - - if (options->percentNdigits != defaultOptions.percentNdigits) - yyjson_mut_obj_add_uint(doc, obj, "percentNdigits", options->percentNdigits); + { + yyjson_mut_val* percent = yyjson_mut_obj(doc); + if (options->percentType != defaultOptions.percentType) + yyjson_mut_obj_add_uint(doc, percent, "type", options->percentType); + if (options->percentNdigits != defaultOptions.percentNdigits) + yyjson_mut_obj_add_uint(doc, percent, "ndigits", options->percentNdigits); + if (yyjson_mut_obj_size(percent) > 0) + yyjson_mut_obj_add_val(doc, obj, "percent", percent); + } { yyjson_mut_val* bar = yyjson_mut_obj(doc); From 3a84a1a5fab3d11ee2bef3378961d91529acb6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 29 Oct 2023 19:37:31 +0800 Subject: [PATCH 063/100] Packages (Windows): add option `--packages-winget` --- CHANGELOG.md | 1 + doc/json_schema.json | 18 ++++++++++---- src/data/help.txt | 1 + src/detection/packages/packages.c | 6 ++--- src/detection/packages/packages.h | 2 +- src/detection/packages/packages_apple.c | 2 +- src/detection/packages/packages_linux.c | 2 +- src/detection/packages/packages_windows.c | 4 ++-- src/modules/packages/option.h | 4 ++++ src/modules/packages/packages.c | 29 +++++++++++++++++++++-- 10 files changed, 55 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 561f6340a..bb6e93bd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Changes: * Display keys `percent*` and `size*` in JSON config are restructured. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }` * With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version) * Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version) +* A new flag `--packages-winget` is introduced to control whether `winget` packages count should be detected. It was controlled by `--allow-slow-operations` previously. Note it's a very slow operation, please enable it with caution. Features: * Quirks for MIPS platforms (CPU, Linux) diff --git a/doc/json_schema.json b/doc/json_schema.json index c401e5c45..e82280bcf 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -708,10 +708,6 @@ "const": "os", "description": "Print operating system name and version" }, - { - "const": "packages", - "description": "List installed package managers and count of installed packages" - }, { "const": "player", "description": "Print music player name" @@ -1282,6 +1278,20 @@ }, "additionalProperties": false }, + { + "title": "Packages", + "properties": { + "type": { + "const": "packages", + "description": "List installed package managers and count of installed packages" + }, + "winget": { + "description": "Set if winget package count should be detected.\nNote this is very slow operation. Please make sure `winget list` works before enable this option\nWindows only", + "type": "boolean", + "default": false + } + } + }, { "title": "Public IP", "properties": { diff --git a/src/data/help.txt b/src/data/help.txt index a495119cb..865490150 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -137,6 +137,7 @@ Module specific options: --disk-use-available : Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes. Default is false --diskio-name-prefix : Show disks with given name prefix only. Default is empty --bluetooth-show-disconnected: : Set if disconnected bluetooth devices should be printed. Default is false + --packages-winget: : Set if winget package count should be detected. Default is false --display-compact-type: : Set if all displays should be printed in one line. Default is none --display-detect-name: : Set if display name should be detected and printed (if supported). Default is false --display-precise-refresh-rate: :Set if decimal refresh rates should not be rounded into integers when printing. Default is true diff --git a/src/detection/packages/packages.c b/src/detection/packages/packages.c index ce7c778c3..2d1268a80 100644 --- a/src/detection/packages/packages.c +++ b/src/detection/packages/packages.c @@ -3,11 +3,11 @@ #include -void ffDetectPackagesImpl(FFPackagesResult* result); +void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options); -const char* ffDetectPackages(FFPackagesResult* result) +const char* ffDetectPackages(FFPackagesResult* result, FFPackagesOptions* options) { - ffDetectPackagesImpl(result); + ffDetectPackagesImpl(result, options); for(uint32_t i = 0; i < offsetof(FFPackagesResult, all) / sizeof(uint32_t); ++i) result->all += ((uint32_t *)result)[i]; diff --git a/src/detection/packages/packages.h b/src/detection/packages/packages.h index 475d39301..1fb5e0d85 100644 --- a/src/detection/packages/packages.h +++ b/src/detection/packages/packages.h @@ -36,6 +36,6 @@ typedef struct FFPackagesResult FFstrbuf pacmanBranch; } FFPackagesResult; -const char* ffDetectPackages(FFPackagesResult* result); +const char* ffDetectPackages(FFPackagesResult* result, FFPackagesOptions* options); #endif diff --git a/src/detection/packages/packages_apple.c b/src/detection/packages/packages_apple.c index 97e858fbe..d49944d84 100644 --- a/src/detection/packages/packages_apple.c +++ b/src/detection/packages/packages_apple.c @@ -68,7 +68,7 @@ static uint32_t getMacPortsPackages() return countMacPortsPackages(FASTFETCH_TARGET_DIR_ROOT"/opt/local"); } -void ffDetectPackagesImpl(FFPackagesResult* result) +void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options) { getBrewPackages(result); result->port = getMacPortsPackages(); diff --git a/src/detection/packages/packages_linux.c b/src/detection/packages/packages_linux.c index 332fd3de0..9351b420f 100644 --- a/src/detection/packages/packages_linux.c +++ b/src/detection/packages/packages_linux.c @@ -327,7 +327,7 @@ static void getPackageCountsBedrock(FFstrbuf* baseDir, FFPackagesResult* package ffStrbufSubstrBefore(baseDir, baseDirLength); } -void ffDetectPackagesImpl(FFPackagesResult* result) +void ffDetectPackagesImpl(FFPackagesResult* result, FF_MAYBE_UNUSED FFPackagesOptions* options) { FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(512); ffStrbufAppendS(&baseDir, FASTFETCH_TARGET_DIR_ROOT); diff --git a/src/detection/packages/packages_windows.c b/src/detection/packages/packages_windows.c index e5b591361..4bd845e2a 100644 --- a/src/detection/packages/packages_windows.c +++ b/src/detection/packages/packages_windows.c @@ -105,11 +105,11 @@ static void detectWinget(FFPackagesResult* result) result->winget = count; } -void ffDetectPackagesImpl(FFPackagesResult* result) +void ffDetectPackagesImpl(FFPackagesResult* result, FFPackagesOptions* options) { detectScoop(result); detectChoco(result); detectPacman(result); - if (instance.config.general.allowSlowOperations) + if (options->winget) detectWinget(result); } diff --git a/src/modules/packages/option.h b/src/modules/packages/option.h index eb3050b96..afbbccccc 100644 --- a/src/modules/packages/option.h +++ b/src/modules/packages/option.h @@ -8,4 +8,8 @@ typedef struct FFPackagesOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; + +#ifdef _WIN32 + bool winget; +#endif } FFPackagesOptions; diff --git a/src/modules/packages/packages.c b/src/modules/packages/packages.c index 0e3202f41..915707244 100644 --- a/src/modules/packages/packages.c +++ b/src/modules/packages/packages.c @@ -11,7 +11,7 @@ void ffPrintPackages(FFPackagesOptions* options) FFPackagesResult counts = {}; ffStrbufInit(&counts.pacmanBranch); - const char* error = ffDetectPackages(&counts); + const char* error = ffDetectPackages(&counts, options); if(error) { @@ -109,6 +109,14 @@ bool ffParsePackagesCommandOptions(FFPackagesOptions* options, const char* key, if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; + #ifdef _WIN32 + if(ffStrEqualsIgnCase(subKey, "winget")) + { + options->winget = ffOptionParseBoolean(value); + return true; + } + #endif + return false; } @@ -125,6 +133,14 @@ void ffParsePackagesJsonObject(FFPackagesOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; + #ifdef _WIN32 + if (ffStrEqualsIgnCase(key, "winget")) + { + options->winget = yyjson_get_bool(val); + continue; + } + #endif + ffPrintError(FF_PACKAGES_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } @@ -135,6 +151,11 @@ void ffGeneratePackagesJsonConfig(FFPackagesOptions* options, yyjson_mut_doc* do ffInitPackagesOptions(&defaultOptions); ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + #ifdef _WIN32 + if (options->winget != defaultOptions.winget) + yyjson_mut_obj_add_bool(doc, module, "winget", options->winget); + #endif } void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) @@ -142,7 +163,7 @@ void ffGeneratePackagesJsonResult(FF_MAYBE_UNUSED FFPackagesOptions* options, yy FFPackagesResult counts = {}; ffStrbufInit(&counts.pacmanBranch); - const char* error = ffDetectPackages(&counts); + const char* error = ffDetectPackages(&counts, options); if(error) { @@ -225,6 +246,10 @@ void ffInitPackagesOptions(FFPackagesOptions* options) ffGeneratePackagesJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); + + #ifdef _WIN32 + options->winget = false; + #endif } void ffDestroyPackagesOptions(FFPackagesOptions* options) From 08a717f5f7c25765dfa5041b29b2f00e061ce423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 30 Oct 2023 09:14:13 +0800 Subject: [PATCH 064/100] JsonConfig: more friendly error message --- src/fastfetch.c | 2 +- src/options/display.c | 4 ++++ src/options/general.c | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index f42537aee..c815b5569 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -622,7 +622,7 @@ static void run(FFdata* data) (error = ffOptionsParseLibraryJsonConfig(&instance.config.library, root)) || false ) { - fputs(error, stderr); + fprintf(stderr, "JsonConfig Error: %s\n", error); exit(477); } } diff --git a/src/options/display.c b/src/options/display.c index 82385945b..a25dd1ca1 100644 --- a/src/options/display.c +++ b/src/options/display.c @@ -146,6 +146,10 @@ const char* ffOptionsParseDisplayJsonConfig(FFOptionsDisplay* options, yyjson_va options->noBuffer = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "keyWidth")) options->keyWidth = (uint32_t) yyjson_get_uint(val); + else if (ffStrStartsWithIgnCase(key, "percent")) + return "Property `display.percentX` has been changed to `display.percent.x`"; + else if (ffStrStartsWithIgnCase(key, "size")) + return "Property `display.sizeX` has been changed to `display.size.x`"; else return "Unknown display property"; } diff --git a/src/options/general.c b/src/options/general.c index c95062887..f4d1895a1 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -38,6 +38,11 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va options->wmiTimeout = (int32_t) yyjson_get_int(val); #endif + else if (ffStrEqualsIgnCase(key, "stat")) + return "Property `general.stat` has been changed to `display.stat`"; + else if (ffStrEqualsIgnCase(key, "pipe")) + return "Property `general.pipe` has been changed to `display.pipe`"; + else return "Unknown general property"; } From b439d9c20371465b5d677963defe8b670abd74a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 30 Oct 2023 09:21:01 +0800 Subject: [PATCH 065/100] Doc: we use Apple80211 instead of IO80211 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 308ad4900..00cfb7fb1 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ The following libraries are used if present at runtime: * [`MediaRemote`](https://iphonedev.wiki/index.php/MediaRemote.framework): Need for Media detection. It's a private framework provided by newer macOS system. * [`DisplayServices`](https://developer.apple.com/forums/thread/666383#663154022): Need for screen brightness detection. It's a private framework provided by newer macOS system. -* [`IO80211`](https://code.google.com/archive/p/iphone-wireless/wikis): Need for Wifi detection on Sonoma (and maybe later). It's a private framework provided by newer macOS system. +* [`Apple80211`](https://code.google.com/archive/p/iphone-wireless/wikis): Need for Wifi detection on Sonoma (and maybe later). It's a private framework provided by newer macOS system. * [`MoltenVK`](https://github.com/KhronosGroup/MoltenVK): Vulkan driver for macOS. [`molten-vk`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/molten-vk.rb) * [`libmagickcore` (ImageMagick)](https://www.imagemagick.org/): Images in terminal using sixel graphics protocol. [`imagemagick`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/imagemagick.rb) * [`libchafa`](https://github.com/hpjansson/chafa): Image output as ascii art. [`chafa`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/chafa.rb) From 2e30a57889983830bd7e0d82b2dbd5492c2acba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 30 Oct 2023 11:05:43 +0800 Subject: [PATCH 066/100] TerminalFont: always use kitten to detect kitty term fonts --- src/detection/terminalfont/terminalfont.c | 49 +++++++++++------------ 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/src/detection/terminalfont/terminalfont.c b/src/detection/terminalfont/terminalfont.c index cf5366f5b..a50e56525 100644 --- a/src/detection/terminalfont/terminalfont.c +++ b/src/detection/terminalfont/terminalfont.c @@ -242,35 +242,32 @@ FF_MAYBE_UNUSED static bool detectKitty(const FFstrbuf* exe, FFTerminalFontResul FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY fontSize = ffStrbufCreate(); - FFpropquery fontQuery[] = { - {"font_family ", &fontName}, - {"font_size ", &fontSize}, - }; - - if(instance.config.general.allowSlowOperations) + FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate(); + if(!ffProcessAppendStdOut(&buf, (char* const[]){ + exe->chars, + "+kitten", + "query-terminal", + NULL, + })) { - FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate(); - if(!ffProcessAppendStdOut(&buf, (char* const[]){ - exe->chars, - "+kitten", - "query-terminal", - NULL, - })) - { - ffParsePropLines(buf.chars, "font_family: ", &fontName); - ffParsePropLines(buf.chars, "font_size: ", &fontSize); - ffFontInitValues(&result->font, fontName.chars, fontSize.chars); - return true; - } + ffParsePropLines(buf.chars, "font_family: ", &fontName); + ffParsePropLines(buf.chars, "font_size: ", &fontSize); + } + else + { + FFpropquery fontQuery[] = { + {"font_family ", &fontName}, + {"font_size ", &fontSize}, + }; + + ffParsePropFileConfigValues("kitty/kitty.conf", 2, fontQuery); + + if(fontName.length == 0) + ffStrbufSetS(&fontName, "monospace"); + if(fontSize.length == 0) + ffStrbufSetS(&fontSize, "11.0"); } - if(!ffParsePropFileConfigValues("kitty/kitty.conf", 2, fontQuery)) - return false; - - if(fontName.length == 0) - ffStrbufSetS(&fontName, "monospace"); - if(fontSize.length == 0) - ffStrbufSetS(&fontSize, "11.0"); ffFontInitValues(&result->font, fontName.chars, fontSize.chars); From 485bcbf0543f57c9b3ae1ff770eeaea6c9588b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 30 Oct 2023 13:46:51 +0800 Subject: [PATCH 067/100] GPU: add flag `--gpu-use-nvml` --- CHANGELOG.md | 2 +- doc/json_schema.json | 5 +++++ src/data/help.txt | 1 + src/detection/gpu/gpu_linux.c | 6 +++--- src/detection/gpu/gpu_windows.c | 6 +++--- src/modules/gpu/gpu.c | 16 ++++++++++++++++ src/modules/gpu/option.h | 1 + 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb6e93bd4..0c0204ab6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ Features: * Support st version detection (Terminal, Linux) * Support st terminal font detection (TerminalFont, Linux) * Add option `--migrate-config ` -* Support Nvidia GPU temp and cuda core count detection via nvml (GPU) +* Support Nvidia GPU temp and cuda core count detection via nvml. Use `--gpu-use-nvml` to enable it (GPU) * Try supporting Wifi authentication type detection in macOS Sonoma. Please file a feature request if you get `to be supported (num)` with result of `/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep auth` (Wifi, macOS) Bugfixes: diff --git a/doc/json_schema.json b/doc/json_schema.json index e82280bcf..dd82f1903 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1130,6 +1130,11 @@ "type": "boolean", "default": false }, + "useNvml": { + "description": "Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc)", + "type": "boolean", + "default": false + }, "forceVulkan": { "title": "Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`", "type": "boolean", diff --git a/src/data/help.txt b/src/data/help.txt index 865490150..2e8b91693 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -148,6 +148,7 @@ Module specific options: --cpu-freq-ndigits : Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2 --cpuusage-separate : Display CPU usage per CPU logical core, instead of an average result. Default is false --gpu-temp : Detect and display GPU temperature if supported. Default is false + --gpu-use-nvml : Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc). Default is false --gpu-force-vulkan : Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false --gpu-hide-type : Specify the type of GPUs should not be printed. Must be `integrated`, `discrete` or `none`. Default is none --battery-temp : Detect and display Battery temperature if supported. Default is false diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 36e1fc475..69d5ab070 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -242,15 +242,15 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; gpu->temperature = FF_GPU_TEMP_UNSET; - if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || instance.config.general.allowSlowOperations)) + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->useNvml)) { char pciDeviceId[32]; snprintf(pciDeviceId, sizeof(pciDeviceId) - 1, "%04x:%02x:%02x.%d", device->domain, device->bus, device->dev, device->func); ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) { .pciBusId = pciDeviceId }, (FFGpuNvidiaResult) { .temp = options->temp ? &gpu->temperature : NULL, - .memory = instance.config.general.allowSlowOperations ? &gpu->dedicated : NULL, - .coreCount = instance.config.general.allowSlowOperations ? (uint32_t*) &gpu->coreCount : NULL, + .memory = options->useNvml ? &gpu->dedicated : NULL, + .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, }); if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index c9a585bee..106fdfc3f 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -85,7 +85,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* } } - if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || instance.config.general.allowSlowOperations)) + if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->useNvml)) { uint32_t vendorId, deviceId, subSystemId; // See: https://download.nvidia.com/XFree86/Linux-x86_64/545.23.06/README/supportedchips.html @@ -97,8 +97,8 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* .pciSubSystemId = subSystemId, }, (FFGpuNvidiaResult) { .temp = options->temp ? &gpu->temperature : NULL, - .memory = instance.config.general.allowSlowOperations ? &gpu->dedicated : NULL, - .coreCount = instance.config.general.allowSlowOperations ? (uint32_t*) &gpu->coreCount : NULL, + .memory = options->useNvml ? &gpu->dedicated : NULL, + .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, }); } } diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 02321e20e..63efe5e80 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -130,6 +130,12 @@ bool ffParseGPUCommandOptions(FFGPUOptions* options, const char* key, const char if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; + if (ffStrEqualsIgnCase(subKey, "use-nvml")) + { + options->useNvml = ffOptionParseBoolean(value); + return true; + } + if (ffStrEqualsIgnCase(subKey, "force-vulkan")) { options->forceVulkan = ffOptionParseBoolean(value); @@ -174,6 +180,12 @@ void ffParseGPUJsonObject(FFGPUOptions* options, yyjson_val* module) continue; } + if (ffStrEqualsIgnCase(key, "useNvml")) + { + options->useNvml = yyjson_get_bool(val); + continue; + } + if (ffStrEqualsIgnCase(key, "forceVulkan")) { options->forceVulkan = yyjson_get_bool(val); @@ -207,6 +219,9 @@ void ffGenerateGPUJsonConfig(FFGPUOptions* options, yyjson_mut_doc* doc, yyjson_ ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + if (options->useNvml != defaultOptions.useNvml) + yyjson_mut_obj_add_bool(doc, module, "useNvml", options->useNvml); + if (options->forceVulkan != defaultOptions.forceVulkan) yyjson_mut_obj_add_bool(doc, module, "forceVulkan", options->forceVulkan); @@ -330,6 +345,7 @@ void ffInitGPUOptions(FFGPUOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs); + options->useNvml = false; options->forceVulkan = false; options->temp = false; options->hideType = FF_GPU_TYPE_UNKNOWN; diff --git a/src/modules/gpu/option.h b/src/modules/gpu/option.h index 8525d6127..6aa34a9fe 100644 --- a/src/modules/gpu/option.h +++ b/src/modules/gpu/option.h @@ -18,5 +18,6 @@ typedef struct FFGPUOptions FFGPUType hideType; bool temp; + bool useNvml; bool forceVulkan; } FFGPUOptions; From b46200628006970eaa0e7958d1f83c9b1a628a3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 30 Oct 2023 14:31:19 +0800 Subject: [PATCH 068/100] Chassis (Windows): add flag `--chassis-use-wmi` --- CHANGELOG.md | 4 +++- doc/json_schema.json | 18 ++++++++++---- src/data/help.txt | 1 + src/detection/chassis/chassis.h | 2 +- src/detection/chassis/chassis_bsd.c | 2 +- src/detection/chassis/chassis_linux.c | 2 +- src/detection/chassis/chassis_nosupport.c | 2 +- src/detection/chassis/chassis_windows.cpp | 6 ++--- src/modules/chassis/chassis.c | 29 +++++++++++++++++++++-- src/modules/chassis/option.h | 4 ++++ 10 files changed, 56 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c0204ab6..adb0cb2b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ Changes: * Display keys `percent*` and `size*` in JSON config are restructured. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }` * With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version) * Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version) -* A new flag `--packages-winget` is introduced to control whether `winget` packages count should be detected. It was controlled by `--allow-slow-operations` previously. Note it's a very slow operation, please enable it with caution. +* The global flag `--allow-slow-operations` is splitted into some explicit flags in differnet modules + * `--packages-winget`: control whether `winget` packages count should be detected. Note it's a very slow operation, please enable it with caution. + * `--chassis-use-wmi`: control whether `WMI` query should be used to detect chassis type, which detects more information, but slower. This flag only affects `--chassis-format` and `--format json`. Features: * Quirks for MIPS platforms (CPU, Linux) diff --git a/doc/json_schema.json b/doc/json_schema.json index dd82f1903..ee84616f0 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -644,10 +644,6 @@ "const": "board", "description": "Print mather board name and other info" }, - { - "const": "chassis", - "description": "Print chassis type (desktop, laptop, etc)" - }, { "const": "cursor", "description": "Print cursor style name" @@ -867,6 +863,20 @@ } } }, + { + "title": "Chassis", + "properties": { + "type": { + "const": "chassis", + "description": "Print chassis type (desktop, laptop, etc)" + }, + "useWmi": { + "description": "Set if WMI query should be used on Windows, which detects more information but slower", + "type": "boolean", + "default": false + } + } + }, { "title": "CPU", "properties": { diff --git a/src/data/help.txt b/src/data/help.txt index 2e8b91693..cf2c48760 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -125,6 +125,7 @@ Module specific options: --title-color-user : Set color of the user name (left part). Default is empty (use color of `--color-title`). --title-color-at : Set color of the @ symbol (middle part). Default is empty (use color of `--color-title`) --title-color-host : Set color of the host name (right part). Default is empty (use color of `--color-title`) + --chassis-use-wmi : Set if WMI query should be used on Windows, which detects more information but slower. Default is false --separator-string : Set the string printed by the separator module --os-file : Set the path to the file containing OS information. Linux only --disk-folders : A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows) diff --git a/src/detection/chassis/chassis.h b/src/detection/chassis/chassis.h index 876936c8d..534141666 100644 --- a/src/detection/chassis/chassis.h +++ b/src/detection/chassis/chassis.h @@ -12,7 +12,7 @@ typedef struct FFChassisResult FFstrbuf version; } FFChassisResult; -const char* ffDetectChassis(FFChassisResult* result); +const char* ffDetectChassis(FFChassisResult* result, FFChassisOptions* options); const char* ffChassisTypeToString(uint32_t type); #endif diff --git a/src/detection/chassis/chassis_bsd.c b/src/detection/chassis/chassis_bsd.c index c38b562c2..54a84c7e9 100644 --- a/src/detection/chassis/chassis_bsd.c +++ b/src/detection/chassis/chassis_bsd.c @@ -2,7 +2,7 @@ #include "common/settings.h" #include "util/smbiosHelper.h" -const char* ffDetectChassis(FFChassisResult* result) +const char* ffDetectChassis(FFChassisResult* result, FF_MAYBE_UNUSED FFChassisOptions* options) { // Unlike other platforms, `smbios.chassis.type` return display string directly on my machine ffSettingsGetFreeBSDKenv("smbios.chassis.type", &result->type); diff --git a/src/detection/chassis/chassis_linux.c b/src/detection/chassis/chassis_linux.c index 074753eb6..e8ce65c82 100644 --- a/src/detection/chassis/chassis_linux.c +++ b/src/detection/chassis/chassis_linux.c @@ -17,7 +17,7 @@ static void getSmbiosValue(const char* devicesPath, const char* classPath, FFstr ffStrbufClear(buffer); } -const char* ffDetectChassis(FFChassisResult* result) +const char* ffDetectChassis(FFChassisResult* result, FF_MAYBE_UNUSED FFChassisOptions* options) { getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &result->type); getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_vendor", "/sys/class/dmi/id/chassis_vendor", &result->vendor); diff --git a/src/detection/chassis/chassis_nosupport.c b/src/detection/chassis/chassis_nosupport.c index c2acd7579..6d83b90d1 100644 --- a/src/detection/chassis/chassis_nosupport.c +++ b/src/detection/chassis/chassis_nosupport.c @@ -1,6 +1,6 @@ #include "chassis.h" -const char* ffDetectChassis(FF_MAYBE_UNUSED FFChassisResult* result) +const char* ffDetectChassis(FF_MAYBE_UNUSED FFChassisResult* result, FF_MAYBE_UNUSED FFChassisOptions* options) { return "Not supported on this platform"; } diff --git a/src/detection/chassis/chassis_windows.cpp b/src/detection/chassis/chassis_windows.cpp index 05fe63ad1..9a3d37fcc 100644 --- a/src/detection/chassis/chassis_windows.cpp +++ b/src/detection/chassis/chassis_windows.cpp @@ -36,7 +36,7 @@ FF_MAYBE_UNUSED static const char* detectWithWmi(FFChassisResult* result) { auto [arr, len] = vtProp.get>(); if(len == 0) - return "ChassisTypes contain no data failed"; + return "ChassisTypes contain no data"; for (uint32_t i = 0; i < len; ++i) { if (i > 0) @@ -65,9 +65,9 @@ FF_MAYBE_UNUSED static const char* detectWithWmi(FFChassisResult* result) } extern "C" -const char* ffDetectChassis(FFChassisResult* result) +const char* ffDetectChassis(FFChassisResult* result, FFChassisOptions* options) { - if (instance.config.general.allowSlowOperations) + if (options->useWmi) return detectWithWmi(result); return detectWithRegistry(result); } diff --git a/src/modules/chassis/chassis.c b/src/modules/chassis/chassis.c index bd1b0c208..f4ca8af96 100644 --- a/src/modules/chassis/chassis.c +++ b/src/modules/chassis/chassis.c @@ -13,7 +13,7 @@ void ffPrintChassis(FFChassisOptions* options) ffStrbufInit(&result.vendor); ffStrbufInit(&result.version); - const char* error = ffDetectChassis(&result); + const char* error = ffDetectChassis(&result, options); if(error) { @@ -57,6 +57,14 @@ bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, co if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; + #ifdef _WIN32 + if (ffStrEqualsIgnCase(subKey, "use-wmi")) + { + options->useWmi = ffOptionParseBoolean(value); + return true; + } + #endif + return false; } @@ -73,6 +81,14 @@ void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; + #ifdef _WIN32 + if (ffStrEqualsIgnCase(key, "useWmi")) + { + options->useWmi = yyjson_get_bool(val); + continue; + } + #endif + ffPrintError(FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } @@ -83,6 +99,11 @@ void ffGenerateChassisJsonConfig(FFChassisOptions* options, yyjson_mut_doc* doc, ffInitChassisOptions(&defaultOptions); ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + #ifdef _WIN32 + if (options->useWmi != defaultOptions.useWmi) + yyjson_mut_obj_add_bool(doc, module, "useWmi", options->useWmi); + #endif } void ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) @@ -92,7 +113,7 @@ void ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjs ffStrbufInit(&result.vendor); ffStrbufInit(&result.version); - const char* error = ffDetectChassis(&result); + const char* error = ffDetectChassis(&result, options); if (error) { @@ -139,6 +160,10 @@ void ffInitChassisOptions(FFChassisOptions* options) ffGenerateChassisJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); + + #ifdef _WIN32 + options->useWmi = false; + #endif } void ffDestroyChassisOptions(FFChassisOptions* options) diff --git a/src/modules/chassis/option.h b/src/modules/chassis/option.h index de6338cd5..25d7cee65 100644 --- a/src/modules/chassis/option.h +++ b/src/modules/chassis/option.h @@ -8,4 +8,8 @@ typedef struct FFChassisOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; + + #ifdef _WIN32 + bool useWmi; + #endif } FFChassisOptions; From ae3420824720e8e7a2dc8007f5bf42fcc0669467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 30 Oct 2023 14:49:00 +0800 Subject: [PATCH 069/100] Battery (Windows): add flag `--battery-use-setup-api` --- CHANGELOG.md | 1 + doc/json_schema.json | 5 +++++ src/data/help.txt | 3 ++- src/detection/battery/battery_windows.c | 2 +- src/modules/battery/battery.c | 23 +++++++++++++++++++++++ src/modules/battery/option.h | 2 ++ 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index adb0cb2b9..6b0ca4aae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Changes: * The global flag `--allow-slow-operations` is splitted into some explicit flags in differnet modules * `--packages-winget`: control whether `winget` packages count should be detected. Note it's a very slow operation, please enable it with caution. * `--chassis-use-wmi`: control whether `WMI` query should be used to detect chassis type, which detects more information, but slower. This flag only affects `--chassis-format` and `--format json`. + * `--battery-use-setup-api`: control whether `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Features: * Quirks for MIPS platforms (CPU, Linux) diff --git a/doc/json_schema.json b/doc/json_schema.json index ee84616f0..bed20cbe5 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -800,6 +800,11 @@ "title": "The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only", "type": "string" }, + "useSetupApi": { + "title": "Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only", + "type": "boolean", + "default": false + }, "temp": { "title": "Detect and display Battery temperature if supported", "type": "boolean", diff --git a/src/data/help.txt b/src/data/help.txt index cf2c48760..dd6ff6de7 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -144,7 +144,8 @@ Module specific options: --display-precise-refresh-rate: :Set if decimal refresh rates should not be rounded into integers when printing. Default is true --brightness-ddcci-sleep: Set the sleep times (in ms) when sending DDC/CI requests. See for detail. Default is 10 --sound-type: : Set what type of sound devices should be printed. Should be either main, active or all. Default is main - --battery-dir : The directory where the battery folders are. Standard: /sys/class/power_supply/ + --battery-dir : The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only + --battery-use-setup-api : Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only --cpu-temp : Detect and display CPU temperature if supported. Default is false --cpu-freq-ndigits : Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2 --cpuusage-separate : Display CPU usage per CPU logical core, instead of an average result. Default is false diff --git a/src/detection/battery/battery_windows.c b/src/detection/battery/battery_windows.c index e75baccbc..ea30df791 100644 --- a/src/detection/battery/battery_windows.c +++ b/src/detection/battery/battery_windows.c @@ -32,7 +32,7 @@ static inline void wrapSetupDiDestroyDeviceInfoList(HDEVINFO* hdev) const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results) { - if(instance.config.general.allowSlowOperations) + if(options->useSetupApi) { //https://learn.microsoft.com/en-us/windows/win32/power/enumerating-battery-devices HDEVINFO hdev __attribute__((__cleanup__(wrapSetupDiDestroyDeviceInfoList))) = diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index 7318289fd..afa0e2e60 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -122,6 +122,14 @@ bool ffParseBatteryCommandOptions(FFBatteryOptions* options, const char* key, co } #endif + #ifdef _WIN32 + if (ffStrEqualsIgnCase(subKey, "use-setup-api")) + { + options->useSetupApi = ffOptionParseBoolean(value); + return true; + } + #endif + return false; } @@ -146,6 +154,14 @@ void ffParseBatteryJsonObject(FFBatteryOptions* options, yyjson_val* module) } #endif + #ifdef _WIN32 + if (ffStrEqualsIgnCase(key, "useSetupApi")) + { + options->useSetupApi = yyjson_get_bool(val); + continue; + } + #endif + if (ffStrEqualsIgnCase(key, "temp")) { options->temp = yyjson_get_bool(val); @@ -168,6 +184,11 @@ void ffGenerateBatteryJsonConfig(FFBatteryOptions* options, yyjson_mut_doc* doc, yyjson_mut_obj_add_strbuf(doc, module, "dir", &options->dir); #endif + #ifdef _WIN32 + if (defaultOptions.useSetupApi != options->useSetupApi) + yyjson_mut_obj_add_bool(doc, module, "useSetupApi", options->useSetupApi); + #endif + if (options->temp != defaultOptions.temp) yyjson_mut_obj_add_bool(doc, module, "temp", options->temp); } @@ -233,6 +254,8 @@ void ffInitBatteryOptions(FFBatteryOptions* options) #ifdef __linux__ ffStrbufInit(&options->dir); + #elif defined(_WIN32) + options->useSetupApi = false; #endif } diff --git a/src/modules/battery/option.h b/src/modules/battery/option.h index 51bbb0c01..89f05bab4 100644 --- a/src/modules/battery/option.h +++ b/src/modules/battery/option.h @@ -13,5 +13,7 @@ typedef struct FFBatteryOptions #ifdef __linux__ FFstrbuf dir; + #elif defined(_WIN32) + bool useSetupApi; #endif } FFBatteryOptions; From 55b41144dbe9f8e8dc9f660b0e2b88064b09f00f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 30 Oct 2023 16:34:35 +0800 Subject: [PATCH 070/100] WM: add flag `--wm-detect-plugin` --- CMakeLists.txt | 3 ++ .../displayserver/displayserver_apple.c | 41 ------------------ .../displayserver/displayserver_windows.c | 6 ++- src/detection/wmde/wmde.h | 6 +++ src/detection/wmde/wmde_apple.c | 42 +++++++++++++++++++ src/detection/wmde/wmde_linux.c | 11 +++++ src/detection/wmde/wmde_nosupport.c | 11 +++++ src/modules/wm/option.h | 2 + src/modules/wm/wm.c | 27 ++++++++++++ 9 files changed, 106 insertions(+), 43 deletions(-) create mode 100644 src/detection/wmde/wmde.h create mode 100644 src/detection/wmde/wmde_apple.c create mode 100644 src/detection/wmde/wmde_linux.c create mode 100644 src/detection/wmde/wmde_nosupport.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 96842bd7f..3ab1453be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -421,6 +421,7 @@ if(LINUX) src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_linux.c src/detection/wifi/wifi_linux.c + src/detection/wmde/wmde_linux.c src/detection/wmtheme/wmtheme_linux.c src/util/platform/FFPlatform_unix.c ) @@ -528,6 +529,7 @@ elseif(BSD) src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_linux.c src/detection/wifi/wifi_bsd.c + src/detection/wmde/wmde_linux.c src/detection/wmtheme/wmtheme_linux.c src/util/platform/FFPlatform_unix.c ) @@ -578,6 +580,7 @@ elseif(APPLE) src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_apple.c src/detection/wifi/wifi_apple.m + src/detection/wmde/wmde_apple.c src/detection/wmtheme/wmtheme_apple.m src/util/apple/cf_helpers.c src/util/apple/osascript.m diff --git a/src/detection/displayserver/displayserver_apple.c b/src/detection/displayserver/displayserver_apple.c index 1bc386c52..cb1583270 100644 --- a/src/detection/displayserver/displayserver_apple.c +++ b/src/detection/displayserver/displayserver_apple.c @@ -1,10 +1,7 @@ #include "displayserver.h" -#include "common/sysctl.h" #include "util/apple/cf_helpers.h" -#include "util/mallocHelper.h" #include -#include #include #include #include @@ -70,35 +67,6 @@ static void detectDisplays(FFDisplayServerResult* ds) } } -static void detectWMPlugin(FFstrbuf* name) -{ - int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL}; - u_int requestLength = sizeof(request) / sizeof(*request); - - size_t length = 0; - FF_AUTO_FREE struct kinfo_proc* processes = ffSysctlGetData(request, requestLength, &length); - if(processes == NULL) - return; - - for(size_t i = 0; i < length / sizeof(struct kinfo_proc); i++) - { - const char* comm = processes[i].kp_proc.p_comm; - - if( - strcasecmp(comm, "spectacle") != 0 && - strcasecmp(comm, "amethyst") != 0 && - strcasecmp(comm, "kwm") != 0 && - strcasecmp(comm, "chunkwm") != 0 && - strcasecmp(comm, "yabai") != 0 && - strcasecmp(comm, "rectangle") != 0 - ) continue; - - ffStrbufAppendS(name, comm); - name->chars[0] = (char) toupper(name->chars[0]); - break; - } -} - void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) { { @@ -116,15 +84,6 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) } ffStrbufInit(&ds->wmProtocolName); - if(instance.config.general.allowSlowOperations) - { - FF_STRBUF_AUTO_DESTROY name; - ffStrbufInit(&name); - detectWMPlugin(&name); - if(name.length) - ffStrbufAppendF(&ds->wmPrettyName, " (with %s)", name.chars); - } - ffStrbufInit(&ds->deProcessName); ffStrbufInitStatic(&ds->dePrettyName, "Aqua"); ffStrbufInit(&ds->deVersion); diff --git a/src/detection/displayserver/displayserver_windows.c b/src/detection/displayserver/displayserver_windows.c index b4945436b..b8e2b54a8 100644 --- a/src/detection/displayserver/displayserver_windows.c +++ b/src/detection/displayserver/displayserver_windows.c @@ -143,15 +143,17 @@ static void detectDisplays(FFDisplayServerResult* ds) void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) { BOOL enabled; - if(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled == TRUE) + if(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled) { ffStrbufInitStatic(&ds->wmProcessName, "dwm.exe"); ffStrbufInitStatic(&ds->wmPrettyName, "Desktop Window Manager"); } else { + // `explorer.exe` only provides a subset of WM functions, as well as the taskbar and desktop icons. + // While a window itself is drawn by kernel (GDI). Killing `explorer.exe` won't affect how windows are displayed generally. ffStrbufInitStatic(&ds->wmProcessName, "explorer.exe"); - ffStrbufInitStatic(&ds->wmPrettyName, "Windows Explorer"); + ffStrbufInitStatic(&ds->wmPrettyName, "Internal"); } ffStrbufInit(&ds->wmProtocolName); ffStrbufInit(&ds->deProcessName); diff --git a/src/detection/wmde/wmde.h b/src/detection/wmde/wmde.h new file mode 100644 index 000000000..2e944991e --- /dev/null +++ b/src/detection/wmde/wmde.h @@ -0,0 +1,6 @@ +#pragma once + +#include "fastfetch.h" + +const char* ffDetectWMPlugin(FFstrbuf* pluginName); +const char* ffDetectDEVersion(); diff --git a/src/detection/wmde/wmde_apple.c b/src/detection/wmde/wmde_apple.c new file mode 100644 index 000000000..feb7a611f --- /dev/null +++ b/src/detection/wmde/wmde_apple.c @@ -0,0 +1,42 @@ +#include "wmde.h" + +#include "common/sysctl.h" +#include "util/mallocHelper.h" + +#include + +const char* ffDetectWMPlugin(FFstrbuf* pluginName) +{ + int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL}; + u_int requestLength = sizeof(request) / sizeof(*request); + + size_t length = 0; + FF_AUTO_FREE struct kinfo_proc* processes = ffSysctlGetData(request, requestLength, &length); + if(processes == NULL) + return "sysctl(CTL_KERN, KERN_PROC, KERN_PROC_ALL) failed"; + + for(size_t i = 0; i < length / sizeof(struct kinfo_proc); i++) + { + const char* comm = processes[i].kp_proc.p_comm; + + if( + strcasecmp(comm, "spectacle") != 0 && + strcasecmp(comm, "amethyst") != 0 && + strcasecmp(comm, "kwm") != 0 && + strcasecmp(comm, "chunkwm") != 0 && + strcasecmp(comm, "yabai") != 0 && + strcasecmp(comm, "rectangle") != 0 + ) continue; + + ffStrbufAppendS(pluginName, comm); + pluginName->chars[0] = (char) toupper(pluginName->chars[0]); + break; + } + + return NULL; +} + +const char* ffDetectDEVersion() +{ + return "No support"; +} diff --git a/src/detection/wmde/wmde_linux.c b/src/detection/wmde/wmde_linux.c new file mode 100644 index 000000000..047fd5905 --- /dev/null +++ b/src/detection/wmde/wmde_linux.c @@ -0,0 +1,11 @@ +#include "wmde.h" + +const char* ffDetectWMPlugin(FFstrbuf* pluginName) +{ + return "No support"; +} + +const char* ffDetectDEVersion() +{ + +} diff --git a/src/detection/wmde/wmde_nosupport.c b/src/detection/wmde/wmde_nosupport.c new file mode 100644 index 000000000..047fd5905 --- /dev/null +++ b/src/detection/wmde/wmde_nosupport.c @@ -0,0 +1,11 @@ +#include "wmde.h" + +const char* ffDetectWMPlugin(FFstrbuf* pluginName) +{ + return "No support"; +} + +const char* ffDetectDEVersion() +{ + +} diff --git a/src/modules/wm/option.h b/src/modules/wm/option.h index 24c16f311..b38ab7c3a 100644 --- a/src/modules/wm/option.h +++ b/src/modules/wm/option.h @@ -8,4 +8,6 @@ typedef struct FFWMOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; + + bool detectPlugin; } FFWMOptions; diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index 374e981f6..6c1e185f3 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -1,6 +1,7 @@ #include "common/printing.h" #include "common/jsonconfig.h" #include "detection/displayserver/displayserver.h" +#include "detection/wmde/wmde.h" #include "modules/wm/wm.h" #include "util/stringUtils.h" @@ -16,6 +17,10 @@ void ffPrintWM(FFWMOptions* options) return; } + FF_STRBUF_AUTO_DESTROY pluginName = ffStrbufCreate(); + if(options->detectPlugin) + ffDetectWMPlugin(&pluginName); + if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(FF_WM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); @@ -29,6 +34,13 @@ void ffPrintWM(FFWMOptions* options) putchar(')'); } + if(pluginName.length > 0) + { + fputs(" (with ", stdout); + ffStrbufWriteTo(&pluginName, stdout); + putchar(')'); + } + putchar('\n'); } else @@ -48,6 +60,12 @@ bool ffParseWMCommandOptions(FFWMOptions* options, const char* key, const char* if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; + if (ffStrEqualsIgnCase(subKey, "detect-plugin")) + { + options->detectPlugin = ffOptionParseBoolean(value); + return true; + } + return false; } @@ -64,6 +82,12 @@ void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; + if (ffStrEqualsIgnCase(key, "detectPlugin")) + { + options->detectPlugin = yyjson_get_bool(val); + continue; + } + ffPrintError(FF_WM_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } @@ -74,6 +98,9 @@ void ffGenerateWMJsonConfig(FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mu ffInitWMOptions(&defaultOptions); ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (options->detectPlugin != defaultOptions.detectPlugin) + yyjson_mut_obj_add_bool(doc, module, "detectPlugin", options->detectPlugin); } void ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) From cf666793235015311ab604ed55f421a32da88e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 30 Oct 2023 22:46:38 +0800 Subject: [PATCH 071/100] DE: move version detection code to separate files --- CMakeLists.txt | 12 +- src/detection/de/de.h | 5 + src/detection/de/de_linux.c | 169 ++++++++++++++ src/detection/de/de_nosupport.c | 6 + src/detection/displayserver/displayserver.h | 1 - .../displayserver/displayserver_android.c | 1 - .../displayserver/displayserver_apple.c | 1 - .../displayserver/displayserver_windows.c | 1 - .../displayserver/linux/displayserver_linux.c | 1 - src/detection/displayserver/linux/wmde.c | 215 +++--------------- src/detection/{wmde/wmde.h => wm/wm.h} | 1 - .../{wmde/wmde_apple.c => wm/wm_apple.c} | 7 +- src/detection/wm/wm_nosupport.c | 6 + src/detection/wmde/wmde_linux.c | 11 - src/detection/wmde/wmde_nosupport.c | 11 - src/modules/de/de.c | 32 ++- src/modules/de/option.h | 2 + src/modules/wm/wm.c | 2 +- 18 files changed, 264 insertions(+), 220 deletions(-) create mode 100644 src/detection/de/de.h create mode 100644 src/detection/de/de_linux.c create mode 100644 src/detection/de/de_nosupport.c rename src/detection/{wmde/wmde.h => wm/wm.h} (73%) rename src/detection/{wmde/wmde_apple.c => wm/wm_apple.c} (93%) create mode 100644 src/detection/wm/wm_nosupport.c delete mode 100644 src/detection/wmde/wmde_linux.c delete mode 100644 src/detection/wmde/wmde_nosupport.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ab1453be..104e67fde 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -421,7 +421,8 @@ if(LINUX) src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_linux.c src/detection/wifi/wifi_linux.c - src/detection/wmde/wmde_linux.c + src/detection/wm/wm_nosupport.c + src/detection/de/de_linux.c src/detection/wmtheme/wmtheme_linux.c src/util/platform/FFPlatform_unix.c ) @@ -471,6 +472,8 @@ elseif(ANDROID) src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_nosupport.c src/detection/wifi/wifi_android.c + src/detection/wm/wm_nosupport.c + src/detection/de/de_nosupport.c src/detection/wmtheme/wmtheme_nosupport.c src/util/platform/FFPlatform_unix.c ) @@ -530,6 +533,8 @@ elseif(BSD) src/detection/wallpaper/wallpaper_linux.c src/detection/wifi/wifi_bsd.c src/detection/wmde/wmde_linux.c + src/detection/wm/wm_nosupport.c + src/detection/de/de_linux.c src/detection/wmtheme/wmtheme_linux.c src/util/platform/FFPlatform_unix.c ) @@ -580,7 +585,8 @@ elseif(APPLE) src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_apple.c src/detection/wifi/wifi_apple.m - src/detection/wmde/wmde_apple.c + src/detection/wm/wm_apple.c + src/detection/de/de_nosupport.c src/detection/wmtheme/wmtheme_apple.m src/util/apple/cf_helpers.c src/util/apple/osascript.m @@ -633,6 +639,8 @@ elseif(WIN32) src/detection/users/users_windows.c src/detection/wallpaper/wallpaper_windows.c src/detection/wifi/wifi_windows.c + src/detection/wm/wm_nosupport.c + src/detection/de/de_nosupport.c src/detection/wmtheme/wmtheme_windows.c src/util/windows/getline.c src/util/windows/com.cpp diff --git a/src/detection/de/de.h b/src/detection/de/de.h new file mode 100644 index 000000000..9d8b2201f --- /dev/null +++ b/src/detection/de/de.h @@ -0,0 +1,5 @@ +#pragma once + +#include "fastfetch.h" + +const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOptions* options); diff --git a/src/detection/de/de_linux.c b/src/detection/de/de_linux.c new file mode 100644 index 000000000..b96a52399 --- /dev/null +++ b/src/detection/de/de_linux.c @@ -0,0 +1,169 @@ +#include "de.h" + +#include "common/parsing.h" +#include "common/properties.h" +#include "common/processing.h" +#include "detection/displayserver/displayserver.h" + +static void getKDE(FFstrbuf* result) +{ + ffParsePropFileValues("/usr/share/xsessions/plasmax11.desktop", 1, (FFpropquery[]) { + {"X-KDE-PluginInfo-Version =", result} + }); + if(result->length == 0) + ffParsePropFileData("xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", result); + if(result->length == 0) + ffParsePropFileData("xsessions/plasma5.desktop", "X-KDE-PluginInfo-Version =", result); + if(result->length == 0) + { + ffParsePropFileValues("/usr/share/wayland-sessions/plasma.desktop", 1, (FFpropquery[]) { + {"X-KDE-PluginInfo-Version =", result} + }); + } + if(result->length == 0) + ffParsePropFileData("wayland-sessions/plasmawayland.desktop", "X-KDE-PluginInfo-Version =", result); + if(result->length == 0) + ffParsePropFileData("wayland-sessions/plasmawayland5.desktop", "X-KDE-PluginInfo-Version =", result); + + if(result->length == 0 && instance.config.general.allowSlowOperations) + { + if (ffProcessAppendStdOut(result, (char* const[]){ + "plasmashell", + "--version", + NULL + }) == NULL) // plasmashell 5.27.5 + ffStrbufSubstrAfterLastC(result, ' '); + } +} + +static void getGnome(FFstrbuf* result) +{ + ffParsePropFileData("gnome-shell/org.gnome.Extensions", "version :", result); + + if (result->length == 0) + { + if (ffProcessAppendStdOut(result, (char* const[]){ + "gnome-shell", + "--version", + NULL + }) == NULL) // GNOME Shell 44.1 + ffStrbufSubstrAfterLastC(result, ' '); + } +} + +static void getCinnamon(FFstrbuf* result) +{ + ffParsePropFileData("applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version =", result); +} + +static void getMate(FFstrbuf* result) +{ + FF_STRBUF_AUTO_DESTROY major = ffStrbufCreate(); + FF_STRBUF_AUTO_DESTROY minor = ffStrbufCreate(); + FF_STRBUF_AUTO_DESTROY micro = ffStrbufCreate(); + + ffParsePropFileDataValues("mate-about/mate-version.xml", 3, (FFpropquery[]) { + {"", &major}, + {"", &minor}, + {"", µ} + }); + + ffParseSemver(result, &major, &minor, µ); + + if(result->length == 0 && instance.config.general.allowSlowOperations) + { + ffProcessAppendStdOut(result, (char* const[]){ + "mate-session", + "--version", + NULL + }); + + ffStrbufSubstrAfterFirstC(result, ' '); + ffStrbufTrim(result, ' '); + } +} + +static void getXFCE4(FFstrbuf* result) +{ + ffParsePropFileData("gtk-doc/html/libxfce4ui/index.html", "

Version", result); + + #ifdef __FreeBSD__ + if(result->length == 0) + { + FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/usr/local/share/licenses/"); + if (dirp) + { + struct dirent* entry; + while((entry = readdir(dirp)) != NULL) + { + if(!ffStrStartsWith(entry->d_name, "xfce-") || !isdigit(entry->d_name[5])) + continue; + ffStrbufAppendS(result, &entry->d_name[5]); + } + } + } + #endif + + if(result->length == 0 && instance.config.general.allowSlowOperations) + { + //This is somewhat slow + ffProcessAppendStdOut(result, (char* const[]){ + "xfce4-session", + "--version", + NULL + }); + + ffStrbufSubstrBeforeFirstC(result, '('); + ffStrbufSubstrAfterFirstC(result, ' '); + ffStrbufTrim(result, ' '); + } +} + +static void getLXQt(FFstrbuf* result) +{ + ffParsePropFileData("gconfig/lxqt.pc", "Version:", result); + + if(result->length == 0) + ffParsePropFileData("cmake/lxqt/lxqt-config.cmake", "set ( LXQT_VERSION", result); + if(result->length == 0) + ffParsePropFileData("cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", result); + + if(result->length == 0 && instance.config.general.allowSlowOperations) + { + //This is really, really, really slow. Thank you, LXQt developers + ffProcessAppendStdOut(result, (char* const[]){ + "lxqt-session", + "-v", + NULL + }); + + result->length = 0; //don't set '\0' byte + ffParsePropLines(result->chars , "liblxqt", result); + } +} + +static void getBudgie(FFstrbuf* result) +{ + ffParsePropFileData("budgie/budgie-version.xml", "", result); +} + +const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options) +{ + if (ffStrbufEqualS(deName, FF_DE_PRETTY_PLASMA)) + getKDE(result); + else if (ffStrbufEqualS(deName, FF_DE_PRETTY_GNOME) || ffStrbufEqualS(deName, FF_DE_PRETTY_GNOME)) + getGnome(result); + else if (ffStrbufEqualS(deName, FF_DE_PRETTY_CINNAMON)) + getCinnamon(result); + else if (ffStrbufEqualS(deName, FF_DE_PRETTY_XFCE4)) + getXFCE4(result); + else if (ffStrbufEqualS(deName, FF_DE_PRETTY_MATE)) + getMate(result); + else if (ffStrbufEqualS(deName, FF_DE_PRETTY_LXQT)) + getLXQt(result); + else if (ffStrbufEqualS(deName, FF_DE_PRETTY_BUDGIE)) + getBudgie(result); + else + return "Unsupported DE"; + return NULL; +} diff --git a/src/detection/de/de_nosupport.c b/src/detection/de/de_nosupport.c new file mode 100644 index 000000000..943e035f0 --- /dev/null +++ b/src/detection/de/de_nosupport.c @@ -0,0 +1,6 @@ +#include "de.h" + +const char* ffDetectDEVersion(FF_MAYBE_UNUSED const FFstrbuf* deName, FF_MAYBE_UNUSED FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/displayserver/displayserver.h b/src/detection/displayserver/displayserver.h index b4ab5283b..4ae40320f 100644 --- a/src/detection/displayserver/displayserver.h +++ b/src/detection/displayserver/displayserver.h @@ -68,7 +68,6 @@ typedef struct FFDisplayServerResult FFstrbuf wmProtocolName; FFstrbuf deProcessName; FFstrbuf dePrettyName; - FFstrbuf deVersion; FFlist displays; //List of FFDisplayResult } FFDisplayServerResult; diff --git a/src/detection/displayserver/displayserver_android.c b/src/detection/displayserver/displayserver_android.c index f60c315f4..a1c7508ac 100644 --- a/src/detection/displayserver/displayserver_android.c +++ b/src/detection/displayserver/displayserver_android.c @@ -107,7 +107,6 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) ffStrbufInit(&ds->wmProtocolName); ffStrbufInit(&ds->deProcessName); ffStrbufInit(&ds->dePrettyName); - ffStrbufInit(&ds->deVersion); ffListInitA(&ds->displays, sizeof(FFDisplayResult), 0); if (!detectWithGetprop(ds)) diff --git a/src/detection/displayserver/displayserver_apple.c b/src/detection/displayserver/displayserver_apple.c index cb1583270..352feafb3 100644 --- a/src/detection/displayserver/displayserver_apple.c +++ b/src/detection/displayserver/displayserver_apple.c @@ -86,7 +86,6 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) ffStrbufInit(&ds->deProcessName); ffStrbufInitStatic(&ds->dePrettyName, "Aqua"); - ffStrbufInit(&ds->deVersion); ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4); detectDisplays(ds); diff --git a/src/detection/displayserver/displayserver_windows.c b/src/detection/displayserver/displayserver_windows.c index b8e2b54a8..5573d3601 100644 --- a/src/detection/displayserver/displayserver_windows.c +++ b/src/detection/displayserver/displayserver_windows.c @@ -158,7 +158,6 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) ffStrbufInit(&ds->wmProtocolName); ffStrbufInit(&ds->deProcessName); ffStrbufInit(&ds->dePrettyName); - ffStrbufInit(&ds->deVersion); ffListInit(&ds->displays, sizeof(FFDisplayResult)); detectDisplays(ds); diff --git a/src/detection/displayserver/linux/displayserver_linux.c b/src/detection/displayserver/linux/displayserver_linux.c index 3de10d9dc..b0ceabfde 100644 --- a/src/detection/displayserver/linux/displayserver_linux.c +++ b/src/detection/displayserver/linux/displayserver_linux.c @@ -85,7 +85,6 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) ffStrbufInit(&ds->wmProtocolName); ffStrbufInit(&ds->deProcessName); ffStrbufInit(&ds->dePrettyName); - ffStrbufInit(&ds->deVersion); ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4); if (!instance.config.general.dsForceDrm) diff --git a/src/detection/displayserver/linux/wmde.c b/src/detection/displayserver/linux/wmde.c index 8829f2352..87594ea10 100644 --- a/src/detection/displayserver/linux/wmde.c +++ b/src/detection/displayserver/linux/wmde.c @@ -1,7 +1,6 @@ #include "displayserver_linux.h" #include "common/io/io.h" #include "common/properties.h" -#include "common/parsing.h" #include "common/processing.h" #include "util/stringUtils.h" @@ -131,177 +130,6 @@ static void applyBetterWM(FFDisplayServerResult* result, const char* processName ffStrbufAppend(&result->wmPrettyName, &result->wmProcessName); } -static void getKDE(FFDisplayServerResult* result) -{ - ffStrbufSetS(&result->deProcessName, "plasmashell"); - ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_PLASMA); - - ffParsePropFileValues("/usr/share/xsessions/plasmax11.desktop", 1, (FFpropquery[]) { - {"X-KDE-PluginInfo-Version =", &result->deVersion} - }); - if(result->deVersion.length == 0) - ffParsePropFileData("xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion); - if(result->deVersion.length == 0) - ffParsePropFileData("xsessions/plasma5.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion); - if(result->deVersion.length == 0) - { - ffParsePropFileValues("/usr/share/wayland-sessions/plasma.desktop", 1, (FFpropquery[]) { - {"X-KDE-PluginInfo-Version =", &result->deVersion} - }); - } - if(result->deVersion.length == 0) - ffParsePropFileData("wayland-sessions/plasmawayland.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion); - if(result->deVersion.length == 0) - ffParsePropFileData("wayland-sessions/plasmawayland5.desktop", "X-KDE-PluginInfo-Version =", &result->deVersion); - - if(result->deVersion.length == 0 && instance.config.general.allowSlowOperations) - { - if (ffProcessAppendStdOut(&result->deVersion, (char* const[]){ - "plasmashell", - "--version", - NULL - }) == NULL) // plasmashell 5.27.5 - ffStrbufSubstrAfterLastC(&result->deVersion, ' '); - } - - - applyBetterWM(result, getenv("KDEWM")); -} - -static void getGnome(FFDisplayServerResult* result) -{ - ffStrbufSetS(&result->deProcessName, "gnome-shell"); - const char* sessionMode = getenv("GNOME_SHELL_SESSION_MODE"); - if (sessionMode && ffStrEquals(sessionMode, "classic")) - ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_GNOME_CLASSIC); - else - ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_GNOME); - - ffParsePropFileData("gnome-shell/org.gnome.Extensions", "version :", &result->deVersion); - - if (result->deVersion.length == 0) - { - if (ffProcessAppendStdOut(&result->deVersion, (char* const[]){ - "gnome-shell", - "--version", - NULL - }) == NULL) // GNOME Shell 44.1 - ffStrbufSubstrAfterLastC(&result->deVersion, ' '); - } -} - -static void getCinnamon(FFDisplayServerResult* result) -{ - ffStrbufSetS(&result->deProcessName, "cinnamon"); - ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_CINNAMON); - ffParsePropFileData("applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version =", &result->deVersion); -} - -static void getMate(FFDisplayServerResult* result) -{ - ffStrbufSetS(&result->deProcessName, "mate-session"); - ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_MATE); - - FF_STRBUF_AUTO_DESTROY major = ffStrbufCreate(); - FF_STRBUF_AUTO_DESTROY minor = ffStrbufCreate(); - FF_STRBUF_AUTO_DESTROY micro = ffStrbufCreate(); - - ffParsePropFileDataValues("mate-about/mate-version.xml", 3, (FFpropquery[]) { - {"", &major}, - {"", &minor}, - {"", µ} - }); - - ffParseSemver(&result->deVersion, &major, &minor, µ); - - if(result->deVersion.length == 0 && instance.config.general.allowSlowOperations) - { - ffProcessAppendStdOut(&result->deVersion, (char* const[]){ - "mate-session", - "--version", - NULL - }); - - ffStrbufSubstrAfterFirstC(&result->deVersion, ' '); - ffStrbufTrim(&result->deVersion, ' '); - } -} - -static void getXFCE4(FFDisplayServerResult* result) -{ - ffStrbufSetS(&result->deProcessName, "xfce4-session"); - ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_XFCE4); - ffParsePropFileData("gtk-doc/html/libxfce4ui/index.html", "

Version", &result->deVersion); - - #ifdef __FreeBSD__ - if(result->deVersion.length == 0) - { - FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/usr/local/share/licenses/"); - if (dirp) - { - struct dirent* entry; - while((entry = readdir(dirp)) != NULL) - { - if(!ffStrStartsWith(entry->d_name, "xfce-") || !isdigit(entry->d_name[5])) - continue; - ffStrbufAppendS(&result->deVersion, &entry->d_name[5]); - } - } - } - #endif - - if(result->deVersion.length == 0 && instance.config.general.allowSlowOperations) - { - //This is somewhat slow - ffProcessAppendStdOut(&result->deVersion, (char* const[]){ - "xfce4-session", - "--version", - NULL - }); - - ffStrbufSubstrBeforeFirstC(&result->deVersion, '('); - ffStrbufSubstrAfterFirstC(&result->deVersion, ' '); - ffStrbufTrim(&result->deVersion, ' '); - } -} - -static void getLXQt(FFDisplayServerResult* result) -{ - ffStrbufSetS(&result->deProcessName, "lxqt-session"); - ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_LXQT); - ffParsePropFileData("gconfig/lxqt.pc", "Version:", &result->deVersion); - - if(result->deVersion.length == 0) - ffParsePropFileData("cmake/lxqt/lxqt-config.cmake", "set ( LXQT_VERSION", &result->deVersion); - if(result->deVersion.length == 0) - ffParsePropFileData("cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", &result->deVersion); - - if(result->deVersion.length == 0 && instance.config.general.allowSlowOperations) - { - //This is really, really, really slow. Thank you, LXQt developers - ffProcessAppendStdOut(&result->deVersion, (char* const[]){ - "lxqt-session", - "-v", - NULL - }); - - result->deVersion.length = 0; //don't set '\0' byte - ffParsePropLines(result->deVersion.chars , "liblxqt", &result->deVersion); - } - - FF_STRBUF_AUTO_DESTROY wmProcessNameBuffer = ffStrbufCreate(); - - ffParsePropFileConfig("lxqt/session.conf", "window_manager =", &wmProcessNameBuffer); - applyBetterWM(result, wmProcessNameBuffer.chars); -} - -static void getBudgie(FFDisplayServerResult* result) -{ - ffStrbufSetS(&result->deProcessName, "budgie-desktop"); - ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_BUDGIE); - ffParsePropFileData("budgie/budgie-version.xml", "", &result->deVersion); -} - static void applyPrettyNameIfDE(FFDisplayServerResult* result, const char* name) { if(!ffStrSet(name)) @@ -312,19 +140,33 @@ static void applyPrettyNameIfDE(FFDisplayServerResult* result, const char* name) strcasecmp(name, "plasma") == 0 || strcasecmp(name, "plasmashell") == 0 || strcasecmp(name, "plasmawayland") == 0 - ) getKDE(result); + ) { + ffStrbufSetStatic(&result->deProcessName, "plasmashell"); + ffStrbufSetStatic(&result->dePrettyName, FF_DE_PRETTY_PLASMA); + applyBetterWM(result, getenv("KDEWM")); + } else if( strcasecmp(name, "Gnome") == 0 || strcasecmp(name, "ubuntu:GNOME") == 0 || strcasecmp(name, "ubuntu") == 0 || strcasecmp(name, "gnome-shell") == 0 - ) getGnome(result); + ) { + ffStrbufSetStatic(&result->deProcessName, "gnome-shell"); + const char* sessionMode = getenv("GNOME_SHELL_SESSION_MODE"); + if (sessionMode && ffStrEquals(sessionMode, "classic")) + ffStrbufSetStatic(&result->dePrettyName, FF_DE_PRETTY_GNOME_CLASSIC); + else + ffStrbufSetStatic(&result->dePrettyName, FF_DE_PRETTY_GNOME); + } else if( strcasecmp(name, "X-Cinnamon") == 0 || strcasecmp(name, "Cinnamon") == 0 - ) getCinnamon(result); + ) { + ffStrbufSetS(&result->deProcessName, "cinnamon"); + ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_CINNAMON); + } else if( strcasecmp(name, "XFCE") == 0 || @@ -332,26 +174,41 @@ static void applyPrettyNameIfDE(FFDisplayServerResult* result, const char* name) strcasecmp(name, "XFCE4") == 0 || strcasecmp(name, "X-XFCE4") == 0 || strcasecmp(name, "xfce4-session") == 0 - ) getXFCE4(result); + ) { + ffStrbufSetS(&result->deProcessName, "xfce4-session"); + ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_XFCE4); + } else if( strcasecmp(name, "MATE") == 0 || strcasecmp(name, "X-MATE") == 0 || strcasecmp(name, "mate-session") == 0 - ) getMate(result); + ) { + ffStrbufSetS(&result->deProcessName, "mate-session"); + ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_MATE); + } else if( strcasecmp(name, "LXQt") == 0 || strcasecmp(name, "X-LXQT") == 0 || strcasecmp(name, "lxqt-session") == 0 - ) getLXQt(result); + ) { + ffStrbufSetS(&result->deProcessName, "lxqt-session"); + ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_LXQT); + FF_STRBUF_AUTO_DESTROY wmProcessNameBuffer = ffStrbufCreate(); + ffParsePropFileConfig("lxqt/session.conf", "window_manager =", &wmProcessNameBuffer); + applyBetterWM(result, wmProcessNameBuffer.chars); + } else if( strcasecmp(name, "Budgie") == 0 || strcasecmp(name, "X-Budgie") == 0 || strcasecmp(name, "budgie-desktop") == 0 || strcasecmp(name, "Budgie:GNOME") == 0 - ) getBudgie(result); + ) { + ffStrbufSetS(&result->deProcessName, "budgie-desktop"); + ffStrbufSetS(&result->dePrettyName, FF_DE_PRETTY_BUDGIE); + } } static void getWMProtocolNameFromEnv(FFDisplayServerResult* result) diff --git a/src/detection/wmde/wmde.h b/src/detection/wm/wm.h similarity index 73% rename from src/detection/wmde/wmde.h rename to src/detection/wm/wm.h index 2e944991e..5301cff94 100644 --- a/src/detection/wmde/wmde.h +++ b/src/detection/wm/wm.h @@ -3,4 +3,3 @@ #include "fastfetch.h" const char* ffDetectWMPlugin(FFstrbuf* pluginName); -const char* ffDetectDEVersion(); diff --git a/src/detection/wmde/wmde_apple.c b/src/detection/wm/wm_apple.c similarity index 93% rename from src/detection/wmde/wmde_apple.c rename to src/detection/wm/wm_apple.c index feb7a611f..b767f8e1e 100644 --- a/src/detection/wmde/wmde_apple.c +++ b/src/detection/wm/wm_apple.c @@ -1,4 +1,4 @@ -#include "wmde.h" +#include "wm.h" #include "common/sysctl.h" #include "util/mallocHelper.h" @@ -35,8 +35,3 @@ const char* ffDetectWMPlugin(FFstrbuf* pluginName) return NULL; } - -const char* ffDetectDEVersion() -{ - return "No support"; -} diff --git a/src/detection/wm/wm_nosupport.c b/src/detection/wm/wm_nosupport.c new file mode 100644 index 000000000..37c0105d7 --- /dev/null +++ b/src/detection/wm/wm_nosupport.c @@ -0,0 +1,6 @@ +#include "wm.h" + +const char* ffDetectWMPlugin(FF_MAYBE_UNUSED FFstrbuf* pluginName) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/wmde/wmde_linux.c b/src/detection/wmde/wmde_linux.c deleted file mode 100644 index 047fd5905..000000000 --- a/src/detection/wmde/wmde_linux.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "wmde.h" - -const char* ffDetectWMPlugin(FFstrbuf* pluginName) -{ - return "No support"; -} - -const char* ffDetectDEVersion() -{ - -} diff --git a/src/detection/wmde/wmde_nosupport.c b/src/detection/wmde/wmde_nosupport.c deleted file mode 100644 index 047fd5905..000000000 --- a/src/detection/wmde/wmde_nosupport.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "wmde.h" - -const char* ffDetectWMPlugin(FFstrbuf* pluginName) -{ - return "No support"; -} - -const char* ffDetectDEVersion() -{ - -} diff --git a/src/modules/de/de.c b/src/modules/de/de.c index ace665bf8..7cab66701 100644 --- a/src/modules/de/de.c +++ b/src/modules/de/de.c @@ -1,6 +1,7 @@ #include "common/printing.h" #include "common/jsonconfig.h" #include "detection/displayserver/displayserver.h" +#include "detection/de/de.h" #include "modules/de/de.h" #include "util/stringUtils.h" @@ -16,16 +17,19 @@ void ffPrintDE(FFDEOptions* options) return; } + FF_STRBUF_AUTO_DESTROY version = ffStrbufCreate(); + ffDetectDEVersion(&result->dePrettyName, &version, options); + if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(FF_DE_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT); ffStrbufWriteTo(&result->dePrettyName, stdout); - if(result->deVersion.length > 0) + if(version.length > 0) { putchar(' '); - ffStrbufWriteTo(&result->deVersion, stdout); + ffStrbufWriteTo(&version, stdout); } putchar('\n'); @@ -35,7 +39,7 @@ void ffPrintDE(FFDEOptions* options) ffPrintFormat(FF_DE_MODULE_NAME, 0, &options->moduleArgs, FF_DE_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->deProcessName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->dePrettyName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->deVersion} + {FF_FORMAT_ARG_TYPE_STRBUF, &version} }); } } @@ -47,6 +51,12 @@ bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; + if (ffStrEqualsIgnCase(key, "slow-version-detection")) + { + options->slowVersionDetection = ffOptionParseBoolean(value); + return true; + } + return false; } @@ -63,6 +73,12 @@ void ffParseDEJsonObject(FFDEOptions* options, yyjson_val* module) if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) continue; + if (ffStrEqualsIgnCase(key, "slowVersionDetection")) + { + options->slowVersionDetection = yyjson_get_bool(val); + continue; + } + ffPrintError(FF_DE_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } @@ -73,6 +89,9 @@ void ffGenerateDEJsonConfig(FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mu ffInitDEOptions(&defaultOptions); ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs); + + if (defaultOptions.slowVersionDetection != options->slowVersionDetection) + yyjson_mut_obj_add_bool(doc, module, "slowVersionDetection", options->slowVersionDetection); } void ffGenerateDEJsonResult(FF_MAYBE_UNUSED FFDEOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) @@ -85,10 +104,13 @@ void ffGenerateDEJsonResult(FF_MAYBE_UNUSED FFDEOptions* options, yyjson_mut_doc return; } + FF_STRBUF_AUTO_DESTROY version = ffStrbufCreate(); + ffDetectDEVersion(&result->dePrettyName, &version, options); + yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, obj, "processName", &result->deProcessName); yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->dePrettyName); - yyjson_mut_obj_add_strbuf(doc, obj, "version", &result->deVersion); + yyjson_mut_obj_add_strbuf(doc, obj, "version", &version); } void ffPrintDEHelpFormat(void) @@ -113,6 +135,8 @@ void ffInitDEOptions(FFDEOptions* options) ffGenerateDEJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs); + + options->slowVersionDetection = false; } void ffDestroyDEOptions(FFDEOptions* options) diff --git a/src/modules/de/option.h b/src/modules/de/option.h index 8ad2b2000..f94797666 100644 --- a/src/modules/de/option.h +++ b/src/modules/de/option.h @@ -8,4 +8,6 @@ typedef struct FFDEOptions { FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; + + bool slowVersionDetection; } FFDEOptions; diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index 6c1e185f3..460eea4f4 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -1,7 +1,7 @@ #include "common/printing.h" #include "common/jsonconfig.h" #include "detection/displayserver/displayserver.h" -#include "detection/wmde/wmde.h" +#include "detection/wm/wm.h" #include "modules/wm/wm.h" #include "util/stringUtils.h" From 4c3372a886f4550f677f76192a460189169a2b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 08:51:56 +0800 Subject: [PATCH 072/100] Logo (Builtin): fix phyOS --- src/logo/ascii/phyos.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/logo/ascii/phyos.txt b/src/logo/ascii/phyos.txt index 4bd8feaff..3b6919ce2 100644 --- a/src/logo/ascii/phyos.txt +++ b/src/logo/ascii/phyos.txt @@ -1,4 +1,3 @@ - ' .^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^.^^^^^. :777777777777777777777777777777^~7777: .~~~~~~~~~~~~~~~~~~~~~^~7777!:!777!. From b1b583721a0ec441ddc7484c65d5842a9f522cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 09:01:11 +0800 Subject: [PATCH 073/100] Logo (Builtin): add MainsailOS Ref: https://github.com/dylanaraps/neofetch/pull/2407 --- CHANGELOG.md | 1 + src/logo/ascii/mainsailos.txt | 18 ++++++++++++++++++ src/logo/ascii/mainsailos_small.txt | 7 +++++++ src/logo/builtin.c | 17 +++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 src/logo/ascii/mainsailos.txt create mode 100644 src/logo/ascii/mainsailos_small.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b0ca4aae..e6cfef380 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ Logo: * Add Chimera Linux * Add EndeavourSmall * Add Xenia +* Add MainsailOS # 2.1.0 diff --git a/src/logo/ascii/mainsailos.txt b/src/logo/ascii/mainsailos.txt new file mode 100644 index 000000000..3e65aa19b --- /dev/null +++ b/src/logo/ascii/mainsailos.txt @@ -0,0 +1,18 @@ + - + *%: + :%%%# + =%%%%%- + *%%%%%%# + :#%%%%%%%#. + -%%%%%%%%+ + *%%%%%%%%- : + .#%%%%%%%#. *%= + -%%%%%%%%+ :#%%%* + +%%%%%%%%- =%%%%%%#. + .#%%%%%%%#. *%%%%%%%%: + -%%%%%%%%* :#%%%%%%%#. + +%%%%%%%%- =%%%%%%%%+ :%*. + .#%%%%%%%#: *%%%%%%%%- +%%%%*: + :%%%%%%%%* :#%%%%%%%#. .*%%%%%%%* + +%%%%%%%%= -%%%%%%%%+ :%%%%%%%%* + .#%%%%%%%%: *%%%%%%%%- =%%%%%%%%= diff --git a/src/logo/ascii/mainsailos_small.txt b/src/logo/ascii/mainsailos_small.txt new file mode 100644 index 000000000..4117caa0a --- /dev/null +++ b/src/logo/ascii/mainsailos_small.txt @@ -0,0 +1,7 @@ + -: + +%* + .#%%+ + -%%%: += + +%%#..#%%- + .#%%+ -%%%- += + -%%%- +%%#..#%%+ diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 582b898a0..8204c3cf3 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -2295,6 +2295,23 @@ static const FFlogo M[] = { .colorKeys = FF_COLOR_FG_YELLOW, .colorTitle = FF_COLOR_FG_GREEN, }, + // MainsailOS + { + .names = {"MainsailOS"}, + .lines = FASTFETCH_DATATEXT_LOGO_MAINSAILOS, + .colors = { + FF_COLOR_FG_RED, + }, + }, + // MainsailOSSmall + { + .names = {"MainsailOS_small"}, + .type = FF_LOGO_LINE_TYPE_SMALL_BIT, + .lines = FASTFETCH_DATATEXT_LOGO_MAINSAILOS_SMALL, + .colors = { + FF_COLOR_FG_RED, + }, + }, // Mageia { .names = {"Mageia"}, From fd5aeb20525e83ef9e5672a05ce29b8ff6baea1a Mon Sep 17 00:00:00 2001 From: kojq <106934605+kojq@users.noreply.github.com> Date: Mon, 30 Oct 2023 21:27:10 -0400 Subject: [PATCH 074/100] Update structure.txt (#600) add swap information as default --- src/data/structure.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/data/structure.txt b/src/data/structure.txt index 851657c6d..22b859add 100644 --- a/src/data/structure.txt +++ b/src/data/structure.txt @@ -1 +1 @@ -Title:Separator:OS:Host:Kernel:Uptime:Packages:Shell:Display:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:GPU:Memory:Disk:Battery:PowerAdapter:Locale:Break:Colors +Title:Separator:OS:Host:Kernel:Uptime:Packages:Shell:Display:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Locale:Break:Colors From cd07354b6fb054f181bec7889c4846bec1e68ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 09:19:41 +0800 Subject: [PATCH 075/100] Doc: update changelog and other docs --- CHANGELOG.md | 3 ++ doc/json_schema.json | 84 +++++++++++++++++++++++++++++++++++++++----- src/data/help.txt | 2 ++ 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6cfef380..e5d9d16b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ Changes: * `--packages-winget`: control whether `winget` packages count should be detected. Note it's a very slow operation, please enable it with caution. * `--chassis-use-wmi`: control whether `WMI` query should be used to detect chassis type, which detects more information, but slower. This flag only affects `--chassis-format` and `--format json`. * `--battery-use-setup-api`: control whether `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. + * `--wm-detect-plugin`: control whether WM plugins should be detected. Note it's implemented with global processes enumeration and can report false results. + * `--de-slow-version-detection`: control DE version should be detected with slow operations. It's usually not necessary and only provided as a backup. Features: * Quirks for MIPS platforms (CPU, Linux) @@ -65,6 +67,7 @@ Logo: * Add EndeavourSmall * Add Xenia * Add MainsailOS +* Fix phyOS # 2.1.0 diff --git a/doc/json_schema.json b/doc/json_schema.json index bed20cbe5..9a9e1d1e9 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -652,10 +652,6 @@ "const": "datetime", "description": "Print current date and time" }, - { - "const": "de", - "description": "Print desktop environment name" - }, { "const": "font", "description": "Print system font name" @@ -760,10 +756,6 @@ "const": "wallpaper", "description": "Print image file path of current wallpaper" }, - { - "const": "wm", - "description": "Print window manager name and version" - }, { "const": "wifi", "description": "Print connected Wi-Fi info (SSID, connection and security protocol)" @@ -879,6 +871,18 @@ "description": "Set if WMI query should be used on Windows, which detects more information but slower", "type": "boolean", "default": false + }, + "key": { + "$ref": "#/$defs/key" + }, + "keyColor": { + "$ref": "#/$defs/keyColor" + }, + "keyWidth": { + "$ref": "#/$defs/keyWidth" + }, + "format": { + "$ref": "#/$defs/format" } } }, @@ -1133,6 +1137,32 @@ }, "additionalProperties": false }, + { + "title": "DE", + "properties": { + "type": { + "const": "de", + "description": "Print desktop environment name" + }, + "slowVersionDetection": { + "type": "boolean", + "description": "Set if DE version should be detected with slow operations.\nShould be unnecessary for most cases.", + "default": "false" + }, + "key": { + "$ref": "#/$defs/key" + }, + "keyColor": { + "$ref": "#/$defs/keyColor" + }, + "keyWidth": { + "$ref": "#/$defs/keyWidth" + }, + "format": { + "$ref": "#/$defs/format" + } + } + }, { "title": "GPU", "properties": { @@ -1309,6 +1339,18 @@ "description": "Set if winget package count should be detected.\nNote this is very slow operation. Please make sure `winget list` works before enable this option\nWindows only", "type": "boolean", "default": false + }, + "key": { + "$ref": "#/$defs/key" + }, + "keyColor": { + "$ref": "#/$defs/keyColor" + }, + "keyWidth": { + "$ref": "#/$defs/keyWidth" + }, + "format": { + "$ref": "#/$defs/format" } } }, @@ -1474,6 +1516,32 @@ } }, "additionalProperties": false + }, + { + "title": "WM", + "properties": { + "type": { + "const": "wm", + "description": "Print window manager name and version" + }, + "detectPlugin": { + "title": "Set if window manager plugin should be detected on supported platforms", + "type": "boolean", + "default": false + }, + "key": { + "$ref": "#/$defs/key" + }, + "keyColor": { + "$ref": "#/$defs/keyColor" + }, + "keyWidth": { + "$ref": "#/$defs/keyWidth" + }, + "format": { + "$ref": "#/$defs/format" + } + } } ] } diff --git a/src/data/help.txt b/src/data/help.txt index dd6ff6de7..a1516699d 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -149,6 +149,7 @@ Module specific options: --cpu-temp : Detect and display CPU temperature if supported. Default is false --cpu-freq-ndigits : Set the number of digits to keep after the decimal point when printing CPU frequency. Default is 2 --cpuusage-separate : Display CPU usage per CPU logical core, instead of an average result. Default is false + --de-slow-version-detection : Set if DE version should be detected with slow operations. Default is false --gpu-temp : Detect and display GPU temperature if supported. Default is false --gpu-use-nvml : Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc). Default is false --gpu-force-vulkan : Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`. Default is false @@ -168,6 +169,7 @@ Module specific options: --weather-location: Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`). --weather-timeout: Time in milliseconds to wait for the weather server to respond. Default is disabled (0) --weather-output-format: The output weather format to be used. It must be URI encoded. + --wm-detect-plugin: Set if window manager plugin should be detected on supported platforms. Default is false --player-name: The name of the player to use for module Media and Player. Linux only --opengl-library : Set the OpenGL context creation library to use. Must be auto, egl, glx or osmesa. Default is auto --command-shell : Set the shell program to execute the command text. Default is cmd for Windows, /bin/sh for *nix From fc3891c91388f96dfd4017367d2afd38b70cbf89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 09:54:12 +0800 Subject: [PATCH 076/100] DE: implement `--de-slow-version-detection` --- src/detection/de/de_linux.c | 38 ++++++++++++++++++------------------- src/modules/de/de.c | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/detection/de/de_linux.c b/src/detection/de/de_linux.c index b96a52399..3d75bcc41 100644 --- a/src/detection/de/de_linux.c +++ b/src/detection/de/de_linux.c @@ -5,7 +5,7 @@ #include "common/processing.h" #include "detection/displayserver/displayserver.h" -static void getKDE(FFstrbuf* result) +static void getKDE(FFstrbuf* result, FFDEOptions* options) { ffParsePropFileValues("/usr/share/xsessions/plasmax11.desktop", 1, (FFpropquery[]) { {"X-KDE-PluginInfo-Version =", result} @@ -25,7 +25,7 @@ static void getKDE(FFstrbuf* result) if(result->length == 0) ffParsePropFileData("wayland-sessions/plasmawayland5.desktop", "X-KDE-PluginInfo-Version =", result); - if(result->length == 0 && instance.config.general.allowSlowOperations) + if(result->length == 0 && options->slowVersionDetection) { if (ffProcessAppendStdOut(result, (char* const[]){ "plasmashell", @@ -36,7 +36,7 @@ static void getKDE(FFstrbuf* result) } } -static void getGnome(FFstrbuf* result) +static void getGnome(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options) { ffParsePropFileData("gnome-shell/org.gnome.Extensions", "version :", result); @@ -51,12 +51,12 @@ static void getGnome(FFstrbuf* result) } } -static void getCinnamon(FFstrbuf* result) +static void getCinnamon(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options) { ffParsePropFileData("applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version =", result); } -static void getMate(FFstrbuf* result) +static void getMate(FFstrbuf* result, FFDEOptions* options) { FF_STRBUF_AUTO_DESTROY major = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY minor = ffStrbufCreate(); @@ -70,7 +70,7 @@ static void getMate(FFstrbuf* result) ffParseSemver(result, &major, &minor, µ); - if(result->length == 0 && instance.config.general.allowSlowOperations) + if(result->length == 0 && options->slowVersionDetection) { ffProcessAppendStdOut(result, (char* const[]){ "mate-session", @@ -83,7 +83,7 @@ static void getMate(FFstrbuf* result) } } -static void getXFCE4(FFstrbuf* result) +static void getXFCE4(FFstrbuf* result, FFDEOptions* options) { ffParsePropFileData("gtk-doc/html/libxfce4ui/index.html", "

Version", result); @@ -104,7 +104,7 @@ static void getXFCE4(FFstrbuf* result) } #endif - if(result->length == 0 && instance.config.general.allowSlowOperations) + if(result->length == 0 && options->slowVersionDetection) { //This is somewhat slow ffProcessAppendStdOut(result, (char* const[]){ @@ -119,7 +119,7 @@ static void getXFCE4(FFstrbuf* result) } } -static void getLXQt(FFstrbuf* result) +static void getLXQt(FFstrbuf* result, FFDEOptions* options) { ffParsePropFileData("gconfig/lxqt.pc", "Version:", result); @@ -128,7 +128,7 @@ static void getLXQt(FFstrbuf* result) if(result->length == 0) ffParsePropFileData("cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", result); - if(result->length == 0 && instance.config.general.allowSlowOperations) + if(result->length == 0 && options->slowVersionDetection) { //This is really, really, really slow. Thank you, LXQt developers ffProcessAppendStdOut(result, (char* const[]){ @@ -142,27 +142,27 @@ static void getLXQt(FFstrbuf* result) } } -static void getBudgie(FFstrbuf* result) +static void getBudgie(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options) { ffParsePropFileData("budgie/budgie-version.xml", "", result); } -const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options) +const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOptions* options) { if (ffStrbufEqualS(deName, FF_DE_PRETTY_PLASMA)) - getKDE(result); + getKDE(result, options); else if (ffStrbufEqualS(deName, FF_DE_PRETTY_GNOME) || ffStrbufEqualS(deName, FF_DE_PRETTY_GNOME)) - getGnome(result); + getGnome(result, options); else if (ffStrbufEqualS(deName, FF_DE_PRETTY_CINNAMON)) - getCinnamon(result); + getCinnamon(result, options); else if (ffStrbufEqualS(deName, FF_DE_PRETTY_XFCE4)) - getXFCE4(result); + getXFCE4(result, options); else if (ffStrbufEqualS(deName, FF_DE_PRETTY_MATE)) - getMate(result); + getMate(result, options); else if (ffStrbufEqualS(deName, FF_DE_PRETTY_LXQT)) - getLXQt(result); + getLXQt(result, options); else if (ffStrbufEqualS(deName, FF_DE_PRETTY_BUDGIE)) - getBudgie(result); + getBudgie(result, options); else return "Unsupported DE"; return NULL; diff --git a/src/modules/de/de.c b/src/modules/de/de.c index 7cab66701..f80c059d3 100644 --- a/src/modules/de/de.c +++ b/src/modules/de/de.c @@ -51,7 +51,7 @@ bool ffParseDECommandOptions(FFDEOptions* options, const char* key, const char* if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; - if (ffStrEqualsIgnCase(key, "slow-version-detection")) + if (ffStrEqualsIgnCase(subKey, "slow-version-detection")) { options->slowVersionDetection = ffOptionParseBoolean(value); return true; From c9ef47271a722b4e648c5b9c750fef3678b4f3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 10:09:31 +0800 Subject: [PATCH 077/100] Brightness: fix flag `--brightness-ddcci-sleep` --- CHANGELOG.md | 1 + src/modules/brightness/brightness.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5d9d16b2..0fd529359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ Bugfixes: * Don't print display type twice (Display) * Detect BSSID instead of Wifi MAC address to align with other platforms (Wifi, macOS) * Remove support of used GPU memory detection, which is not reliable and only supported with `--gpu-force-vulkan`. (GPU) +* Fix flag `--brightness-ddcci-sleep` (Brightness, Linux) Logos: * Add Black Mesa diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index 4bcabec82..a97c5676f 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -91,7 +91,7 @@ bool ffParseBrightnessCommandOptions(FFBrightnessOptions* options, const char* k if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) return true; - if (ffStrEqualsIgnCase(key, "ddcci-sleep")) + if (ffStrEqualsIgnCase(subKey, "ddcci-sleep")) { options->ddcciSleep = ffOptionParseUInt32(key, value); return true; From c504096181eb2e96b2b546707f47ba8ee7d48d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 14:03:24 +0800 Subject: [PATCH 078/100] Processing (Linux): fix hanging if a child process prints to both stdout and stderr --- CHANGELOG.md | 1 + src/common/processing_linux.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fd529359..0c561d93b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ Bugfixes: * Detect BSSID instead of Wifi MAC address to align with other platforms (Wifi, macOS) * Remove support of used GPU memory detection, which is not reliable and only supported with `--gpu-force-vulkan`. (GPU) * Fix flag `--brightness-ddcci-sleep` (Brightness, Linux) +* Fix hanging if a child process prints to both stdout and stderr (Linux) Logos: * Add Black Mesa diff --git a/src/common/processing_linux.c b/src/common/processing_linux.c index b96a2ff85..81bf2eda2 100644 --- a/src/common/processing_linux.c +++ b/src/common/processing_linux.c @@ -34,10 +34,11 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use //Child if(childPid == 0) { + int nullFile = open("/dev/null", O_WRONLY); dup2(pipes[1], useStdErr ? STDERR_FILENO : STDOUT_FILENO); + dup2(nullFile, useStdErr ? STDOUT_FILENO : STDERR_FILENO); close(pipes[0]); close(pipes[1]); - close(useStdErr ? STDOUT_FILENO : STDERR_FILENO); setenv("LANG", "C", 1); execvp(argv[0], argv); exit(901); From b99f44423459bc3195af8a6b4d5780086abd635a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 14:10:21 +0800 Subject: [PATCH 079/100] Global: remove `--allow-slow-operations` --- CHANGELOG.md | 2 +- doc/json_schema.json | 5 ----- src/options/general.c | 14 ++++---------- src/options/general.h | 1 - 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c561d93b..ae397c3ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This release introduces a new option `--migrate-config`, which migrates old flag Changes: * `--pipe` and `--stat` are moved from `general` options to `display` options. This affects cjson configuration. -* Display keys `percent*` and `size*` in JSON config are restructured. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }` +* Display keys `percent*` and `size*` in JSON config are restructured. e.g. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }` * With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version) * Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version) * The global flag `--allow-slow-operations` is splitted into some explicit flags in differnet modules diff --git a/doc/json_schema.json b/doc/json_schema.json index 9a9e1d1e9..5a3d2ccd9 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -227,11 +227,6 @@ "title": "Fastfetch general configurations", "type": "object", "properties": { - "allowSlowOperations": { - "type": "boolean", - "title": "Allow operations that can be very slow for more detailed output", - "default": false - }, "multithreading": { "type": "boolean", "title": "Use multiple threads to detect values", diff --git a/src/options/general.c b/src/options/general.c index f4d1895a1..6357e04b8 100644 --- a/src/options/general.c +++ b/src/options/general.c @@ -17,9 +17,7 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va { const char* key = yyjson_get_str(key_); - if (ffStrEqualsIgnCase(key, "allowSlowOperations")) - options->allowSlowOperations = yyjson_get_bool(val); - else if (ffStrEqualsIgnCase(key, "thread") || ffStrEqualsIgnCase(key, "multithreading")) + if (ffStrEqualsIgnCase(key, "thread") || ffStrEqualsIgnCase(key, "multithreading")) options->multithreading = yyjson_get_bool(val); else if (ffStrEqualsIgnCase(key, "processingTimeout")) options->processingTimeout = (int32_t) yyjson_get_int(val); @@ -42,6 +40,8 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va return "Property `general.stat` has been changed to `display.stat`"; else if (ffStrEqualsIgnCase(key, "pipe")) return "Property `general.pipe` has been changed to `display.pipe`"; + else if (ffStrEqualsIgnCase(key, "allowSlowOperations")) + return "Property `general.allowSlowOperations` has been obsoleted. See CHANGELOG for detail"; else return "Unknown general property"; @@ -52,9 +52,7 @@ const char* ffOptionsParseGeneralJsonConfig(FFOptionsGeneral* options, yyjson_va bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key, const char* value) { - if(ffStrEqualsIgnCase(key, "--allow-slow-operations")) - options->allowSlowOperations = ffOptionParseBoolean(value); - else if(ffStrEqualsIgnCase(key, "--thread") || ffStrEqualsIgnCase(key, "--multithreading")) + if(ffStrEqualsIgnCase(key, "--thread") || ffStrEqualsIgnCase(key, "--multithreading")) options->multithreading = ffOptionParseBoolean(value); else if(ffStrEqualsIgnCase(key, "--processing-timeout")) options->processingTimeout = ffOptionParseInt32(key, value); @@ -82,7 +80,6 @@ bool ffOptionsParseGeneralCommandLine(FFOptionsGeneral* options, const char* key void ffOptionsInitGeneral(FFOptionsGeneral* options) { options->processingTimeout = 1000; - options->allowSlowOperations = false; options->multithreading = true; #if defined(__linux__) || defined(__FreeBSD__) @@ -110,9 +107,6 @@ void ffOptionsGenerateGeneralJsonConfig(FFOptionsGeneral* options, yyjson_mut_do yyjson_mut_val* obj = yyjson_mut_obj(doc); - if (options->allowSlowOperations != defaultOptions.allowSlowOperations) - yyjson_mut_obj_add_bool(doc, obj, "allowSlowOperations", options->allowSlowOperations); - if (options->multithreading != defaultOptions.multithreading) yyjson_mut_obj_add_bool(doc, obj, "thread", options->multithreading); diff --git a/src/options/general.h b/src/options/general.h index cb57719d2..156991028 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -4,7 +4,6 @@ typedef struct FFOptionsGeneral { - bool allowSlowOperations; bool multithreading; int32_t processingTimeout; From d3f673dc6f2318c72534196669e1b30a8aca45a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 14:32:30 +0800 Subject: [PATCH 080/100] Init: remove separate thread of displayserver and qt/gtk stuff detection These threads are detached. If the main thread exits before the sub threads end, fastfetch may crash in various ways. It barely benefits performance. `hyperfine` shows completely no difference between `--thread` enabled and disabled. Let's get rid of it. --- src/common/init.c | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/src/common/init.c b/src/common/init.c index 2fc032a27..5c5b2307a 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -51,29 +51,6 @@ void ffInitInstance(void) defaultConfig(); } -#if defined(FF_HAVE_THREADS) && !(defined(__APPLE__) || defined(_WIN32) || defined(__ANDROID__)) - -#include "detection/gtk_qt/gtk_qt.h" - -#define FF_START_DETECTION_THREADS - -FF_THREAD_ENTRY_DECL_WRAPPER_NOPARAM(ffConnectDisplayServer) -FF_THREAD_ENTRY_DECL_WRAPPER_NOPARAM(ffDetectQt) -FF_THREAD_ENTRY_DECL_WRAPPER_NOPARAM(ffDetectGTK2) -FF_THREAD_ENTRY_DECL_WRAPPER_NOPARAM(ffDetectGTK3) -FF_THREAD_ENTRY_DECL_WRAPPER_NOPARAM(ffDetectGTK4) - -void startDetectionThreads(void) -{ - ffThreadDetach(ffThreadCreate(ffConnectDisplayServerThreadMain, NULL)); - ffThreadDetach(ffThreadCreate(ffDetectQtThreadMain, NULL)); - ffThreadDetach(ffThreadCreate(ffDetectGTK2ThreadMain, NULL)); - ffThreadDetach(ffThreadCreate(ffDetectGTK3ThreadMain, NULL)); - ffThreadDetach(ffThreadCreate(ffDetectGTK4ThreadMain, NULL)); -} - -#endif //FF_HAVE_THREADS - static volatile bool ffDisableLinewrap = true; static volatile bool ffHideCursor = true; From 5b2006cd0635a9bd5f4266db88f69d132b8f14e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 14:42:45 +0800 Subject: [PATCH 081/100] Global: get rid of locks Psychological burden NO MORE --- src/common/dbus.c | 4 ---- src/common/settings.c | 7 ------- src/detection/displayserver/linux/wayland.c | 5 ----- src/detection/gtk_qt/gtk.c | 13 +------------ src/detection/gtk_qt/qt.c | 6 ------ src/detection/internal.h | 6 ------ src/detection/temps/temps_linux.c | 9 --------- src/detection/terminalshell/terminalshell_linux.c | 6 ------ src/detection/terminalshell/terminalshell_windows.c | 9 +-------- src/detection/vulkan/vulkan.c | 6 ------ 10 files changed, 2 insertions(+), 69 deletions(-) diff --git a/src/common/dbus.c b/src/common/dbus.c index 05f66e402..cf94128c7 100644 --- a/src/common/dbus.c +++ b/src/common/dbus.c @@ -33,9 +33,6 @@ static const FFDBusLibrary* loadLib(void) static FFDBusLibrary lib; static bool loaded = false; static bool loadSuccess = false; - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; - - ffThreadMutexLock(&mutex); if(!loaded) { @@ -43,7 +40,6 @@ static const FFDBusLibrary* loadLib(void) loadSuccess = loadLibSymbols(&lib); } - ffThreadMutexUnlock(&mutex); return loadSuccess ? &lib : NULL; } diff --git a/src/common/settings.c b/src/common/settings.c index 0e1dbeb29..ae057a292 100644 --- a/src/common/settings.c +++ b/src/common/settings.c @@ -15,18 +15,14 @@ typedef enum FFInitState #define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \ static dataObject data; \ - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \ static FFInitState initState = FF_INITSTATE_UNINITIALIZED; \ - ffThreadMutexLock(&mutex); \ if(initState != FF_INITSTATE_UNINITIALIZED) {\ - ffThreadMutexUnlock(&mutex); \ return initState == FF_INITSTATE_SUCCESSFUL ? &data : NULL; \ } \ initState = FF_INITSTATE_SUCCESSFUL; \ void* libraryHandle = ffLibraryLoad(&userLibraryName, __VA_ARGS__, NULL); \ if(libraryHandle == NULL) { \ initState = FF_INITSTATE_FAILED; \ - ffThreadMutexUnlock(&mutex); \ return NULL; \ } \ @@ -35,20 +31,17 @@ typedef enum FFInitState if(data.ff ## symbolName == NULL) { \ dlclose(libraryHandle); \ initState = FF_INITSTATE_FAILED; \ - ffThreadMutexUnlock(&mutex); \ return NULL; \ } #define FF_LIBRARY_DATA_LOAD_RETURN \ initState = FF_INITSTATE_SUCCESSFUL; \ - ffThreadMutexUnlock(&mutex); \ return &data; #define FF_LIBRARY_DATA_LOAD_ERROR \ { \ dlclose(libraryHandle); \ initState = FF_INITSTATE_FAILED; \ - ffThreadMutexUnlock(&mutex); \ return NULL; \ } diff --git a/src/detection/displayserver/linux/wayland.c b/src/detection/displayserver/linux/wayland.c index e9bfca341..559587fa5 100644 --- a/src/detection/displayserver/linux/wayland.c +++ b/src/detection/displayserver/linux/wayland.c @@ -202,9 +202,6 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist if(display.width <= 0 || display.height <= 0) return; - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; - ffThreadMutexLock(&mutex); - switch(display.transform) { case WL_OUTPUT_TRANSFORM_90: @@ -262,8 +259,6 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist ffStrbufDestroy(&display.vendorAndModelId); ffStrbufDestroy(&display.name); ffStrbufDestroy(&display.edidName); - - ffThreadMutexUnlock(&mutex); } static void waylandGlobalAddListener(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) diff --git a/src/detection/gtk_qt/gtk.c b/src/detection/gtk_qt/gtk.c index 8c7debe01..ef5e4f17a 100644 --- a/src/detection/gtk_qt/gtk.c +++ b/src/detection/gtk_qt/gtk.c @@ -36,8 +36,6 @@ static inline void applyGTKSettings(FFGTKResult* result, const char* themeName, static void detectGTKFromSettings(FFGTKResult* result) { - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; - static const char* themeName = NULL; static const char* iconsName = NULL; static const char* fontName = NULL; @@ -47,11 +45,8 @@ static void detectGTKFromSettings(FFGTKResult* result) static bool init = false; - ffThreadMutexLock(&mutex); - if(init) { - ffThreadMutexUnlock(&mutex); applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize, wallpaper); return; } @@ -103,7 +98,6 @@ static void detectGTKFromSettings(FFGTKResult* result) wallpaper = ffSettingsGet("/org/gnome/desktop/background/picture-uri", "org.gnome.desktop.background", NULL, "picture-uri", FF_VARIANT_TYPE_STRING).strValue; } - ffThreadMutexUnlock(&mutex); applyGTKSettings(result, themeName, iconsName, fontName, cursorTheme, cursorSize, wallpaper); } @@ -178,14 +172,10 @@ static void detectGTK(const char* version, FFGTKResult* result) } #define FF_DETECT_GTK_IMPL(version) \ - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \ static FFGTKResult result; \ static bool init = false; \ - ffThreadMutexLock(&mutex); \ - if(init){ \ - ffThreadMutexUnlock(&mutex);\ + if(init) \ return &result; \ - } \ init = true; \ ffStrbufInit(&result.theme); \ ffStrbufInit(&result.icons); \ @@ -194,7 +184,6 @@ static void detectGTK(const char* version, FFGTKResult* result) ffStrbufInit(&result.cursorSize); \ ffStrbufInit(&result.wallpaper); \ detectGTK(#version, &result); \ - ffThreadMutexUnlock(&mutex); \ return &result; const FFGTKResult* ffDetectGTK2(void) diff --git a/src/detection/gtk_qt/qt.c b/src/detection/gtk_qt/qt.c index 71b0536c7..a18a324b1 100644 --- a/src/detection/gtk_qt/qt.c +++ b/src/detection/gtk_qt/qt.c @@ -138,14 +138,9 @@ const FFQtResult* ffDetectQt(void) { static FFQtResult result; - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; static bool init = false; - ffThreadMutexLock(&mutex); if(init) - { - ffThreadMutexUnlock(&mutex); return &result; - } init = true; ffStrbufInit(&result.widgetStyle); @@ -161,6 +156,5 @@ const FFQtResult* ffDetectQt(void) else if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, FF_DE_PRETTY_LXQT) == 0) detectLXQt(&result); - ffThreadMutexUnlock(&mutex); return &result; } diff --git a/src/detection/internal.h b/src/detection/internal.h index 11b081f7e..19ec8d1a2 100644 --- a/src/detection/internal.h +++ b/src/detection/internal.h @@ -6,18 +6,12 @@ #include "common/thread.h" #define FF_DETECTION_INTERNAL_GUARD(ResultType, ...) \ - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; \ static ResultType result; \ static bool init = false; \ - ffThreadMutexLock(&mutex); \ if(init) \ - { \ - ffThreadMutexUnlock(&mutex); \ return &result; \ - } \ init = true; \ __VA_ARGS__; \ - ffThreadMutexUnlock(&mutex); \ return &result; \ #endif diff --git a/src/detection/temps/temps_linux.c b/src/detection/temps/temps_linux.c index ee30a85c4..1599321f1 100644 --- a/src/detection/temps/temps_linux.c +++ b/src/detection/temps/temps_linux.c @@ -44,15 +44,10 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) const FFTempsResult* ffDetectTemps(void) { static FFTempsResult result; - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; static bool init = false; - ffThreadMutexLock(&mutex); if(init) - { - ffThreadMutexUnlock(&mutex); return &result; - } init = true; ffListInitA(&result.values, sizeof(FFTempValue), 16); @@ -64,10 +59,7 @@ const FFTempsResult* ffDetectTemps(void) DIR* dirp = opendir(baseDir.chars); if(dirp == NULL) - { - ffThreadMutexUnlock(&mutex); return &result; - } struct dirent* entry; while((entry = readdir(dirp)) != NULL) @@ -92,6 +84,5 @@ const FFTempsResult* ffDetectTemps(void) closedir(dirp); - ffThreadMutexUnlock(&mutex); return &result; } diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 38d83e800..4d44746ac 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -310,15 +310,10 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* vers const FFTerminalShellResult* ffDetectTerminalShell() { - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; static FFTerminalShellResult result; static bool init = false; - ffThreadMutexLock(&mutex); if(init) - { - ffThreadMutexUnlock(&mutex); return &result; - } init = true; #ifdef __APPLE__ @@ -413,6 +408,5 @@ const FFTerminalShellResult* ffDetectTerminalShell() ffStrbufInit(&result.terminalVersion); fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion); - ffThreadMutexUnlock(&mutex); return &result; } diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index ebc062b33..746ba32a7 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -355,15 +355,10 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FFstrbuf* exe, FFstrbuf* vers const FFTerminalShellResult* ffDetectTerminalShell(void) { - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; static FFTerminalShellResult result; static bool init = false; - ffThreadMutexLock(&mutex); if(init) - { - ffThreadMutexUnlock(&mutex); return &result; - } init = true; ffStrbufInit(&result.shellProcessName); @@ -381,7 +376,7 @@ const FFTerminalShellResult* ffDetectTerminalShell(void) uint32_t ppid; if(!getProcessInfo(0, &ppid, NULL, NULL, NULL)) - goto exit; + return &result; ppid = getShellInfo(&result, ppid); if(ppid) @@ -393,7 +388,5 @@ const FFTerminalShellResult* ffDetectTerminalShell(void) ffStrbufInit(&result.terminalVersion); fftsGetTerminalVersion(&result.terminalProcessName, &result.terminalExe, &result.terminalVersion); -exit: - ffThreadMutexUnlock(&mutex); return &result; } diff --git a/src/detection/vulkan/vulkan.c b/src/detection/vulkan/vulkan.c index 07d10a57a..a9d3110be 100644 --- a/src/detection/vulkan/vulkan.c +++ b/src/detection/vulkan/vulkan.c @@ -228,15 +228,10 @@ static const char* detectVulkan(FFVulkanResult* result) FFVulkanResult* ffDetectVulkan(void) { static FFVulkanResult result; - static FFThreadMutex mutex = FF_THREAD_MUTEX_INITIALIZER; static bool init = false; - ffThreadMutexLock(&mutex); if(init) - { - ffThreadMutexUnlock(&mutex); return &result; - } init = true; ffStrbufInit(&result.driver); @@ -250,6 +245,5 @@ FFVulkanResult* ffDetectVulkan(void) result.error = "fastfetch was compiled without vulkan support"; #endif - ffThreadMutexUnlock(&mutex); return &result; } From c6e52218262259b37a7e57f3fcdf364a033d4a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 14:57:32 +0800 Subject: [PATCH 082/100] CMake: build with ASAN conditionally --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 104e67fde..da522c08f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,8 +70,9 @@ cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF) cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF) cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF) cmake_dependent_option(ENABLE_PCI_MEMORY "Enable detecting GPU memory size with libpci" OFF "LINUX OR BSD" OFF) -cmake_dependent_option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embeded) yyjson library" OFF "LINUX OR APPLE OR BSD OR WIN32 OR ANDROID" OFF) +option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embeded) yyjson library" OFF) +option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF) option(BUILD_TESTS "Build tests" OFF) # Also create test executables option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds @@ -116,7 +117,8 @@ if(APPLE AND DEFINED ENV{HOMEBREW_PREFIX}) endif() set(FASTFETCH_FLAGS_DEBUG "-fno-omit-frame-pointer") -if(NOT WIN32 AND NOT APPLE) +if(ENABLE_ASAN) + message(STATUS "Address sanitizer enabled (DEBUG only)") set(FASTFETCH_FLAGS_DEBUG "${FASTFETCH_FLAGS_DEBUG} -fsanitize=address") endif() set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}") From 9ac50fc42f232490c4d5b490c406be67257d9066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 15:11:22 +0800 Subject: [PATCH 083/100] GPU: add more vendors --- src/detection/gpu/gpu.c | 7 +++++++ src/detection/gpu/gpu.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/detection/gpu/gpu.c b/src/detection/gpu/gpu.c index 32fb5a3e9..70980f5f9 100644 --- a/src/detection/gpu/gpu.c +++ b/src/detection/gpu/gpu.c @@ -9,6 +9,8 @@ const char* FF_GPU_VENDOR_NAME_NVIDIA = "NVIDIA"; const char* FF_GPU_VENDOR_NAME_VMWARE = "VMware"; const char* FF_GPU_VENDOR_NAME_PARALLEL = "Parallel"; const char* FF_GPU_VENDOR_NAME_MICROSOFT = "Microsoft"; +const char* FF_GPU_VENDOR_NAME_REDHAT = "RedHat"; +const char* FF_GPU_VENDOR_NAME_ORACLE = "Oracle"; static inline bool arrayContains(const unsigned arr[], unsigned vendorId, unsigned length) { @@ -22,6 +24,7 @@ static inline bool arrayContains(const unsigned arr[], unsigned vendorId, unsign const char* ffGetGPUVendorString(unsigned vendorId) { + // https://devicehunt.com/all-pci-vendors if(vendorId == 0x106b) return FF_GPU_VENDOR_NAME_APPLE; if(arrayContains((const unsigned[]) {0x1002, 0x1022}, vendorId, 2)) @@ -32,10 +35,14 @@ const char* ffGetGPUVendorString(unsigned vendorId) return FF_GPU_VENDOR_NAME_NVIDIA; else if(arrayContains((const unsigned[]) {0x15ad}, vendorId, 1)) return FF_GPU_VENDOR_NAME_VMWARE; + else if(arrayContains((const unsigned[]) {0x1af4}, vendorId, 1)) + return FF_GPU_VENDOR_NAME_REDHAT; else if(arrayContains((const unsigned[]) {0x1ab8}, vendorId, 1)) return FF_GPU_VENDOR_NAME_PARALLEL; else if(arrayContains((const unsigned[]) {0x1414}, vendorId, 1)) return FF_GPU_VENDOR_NAME_MICROSOFT; + else if(arrayContains((const unsigned[]) {0x108e}, vendorId, 1)) + return FF_GPU_VENDOR_NAME_ORACLE; return NULL; } diff --git a/src/detection/gpu/gpu.h b/src/detection/gpu/gpu.h index 8398a826f..70ccd96b2 100644 --- a/src/detection/gpu/gpu.h +++ b/src/detection/gpu/gpu.h @@ -16,6 +16,8 @@ extern const char* FF_GPU_VENDOR_NAME_NVIDIA; extern const char* FF_GPU_VENDOR_NAME_VMWARE; extern const char* FF_GPU_VENDOR_NAME_PARALLEL; extern const char* FF_GPU_VENDOR_NAME_MICROSOFT; +extern const char* FF_GPU_VENDOR_NAME_REDHAT; +extern const char* FF_GPU_VENDOR_NAME_ORACLE; typedef struct FFGPUMemory { From 8fe291d161b6ccf14376ddf4fe0f7dc2275951a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 15:47:23 +0800 Subject: [PATCH 084/100] Doc: remove information of flag based configuration --- README.md | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 00cfb7fb1..5b8b1e4e9 100644 --- a/README.md +++ b/README.md @@ -25,23 +25,10 @@ There are [screenshots on different platforms](https://github.com/fastfetch-cli/ ## Customization -With customization and speed being two competing goals, this project actually builds two executables: - - - -* The main one is `fastfetch`, which can be very greatly configured via flags. These flags can be made persistent by modifying `$XDG_CONFIG_HOME/fastfetch/config.conf`. Use `fastfetch --gen-config conf` to generate one. To view the available options, run `fastfetch --help`. -* The second executable is called `flashfetch`, which is configured at compile time to eliminate any possible overhead. Configuration of it can be very easily done in [`src/flashfetch.c`](src/flashfetch.c). - -Currently, the performance difference is measurable, but too small to be recognizable by humans. But with more options planned, the leap will get bigger over time and on slow machines this might actually make a difference. - -There are some premade config files in [`presets`](presets), including the ones used for the screenshots above. You can load them using `--load-config `. They may also serve as a good example for format arguments. +Fastfetch uses the JSONC format for configuration. [See Wiki for detail](https://github.com/fastfetch-cli/fastfetch/wiki/Configuration). There are some premade config files in [`presets`](presets), including the ones used for the screenshots above. You can load them using `-c `. They may also serve as a good example for format arguments. Logos can be heavily customized too; see the [logo documentation](https://github.com/fastfetch-cli/fastfetch/wiki/Logo-options) for more information. -### Customization with new JSONC format - -A new, structure based, and user-friendly config file format was introduced in v2.0.0. This format is based on [JSONC](https://jsonc.org/). [See more details in Wiki](https://github.com/fastfetch-cli/fastfetch/wiki/Configuration) - ## Dependencies Fastfetch dynamically loads needed libraries if they are available. On Linux, its only hard dependencies are `libc` (any implementation of the c standard library), `libdl`, `libm` and [`libpthread`](https://man7.org/linux/man-pages/man7/pthreads.7.html) (if built with multithreading support). They are all shipped with [`glibc`](https://www.gnu.org/software/libc/), which is already installed on most Linux distributions. @@ -118,7 +105,7 @@ Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsa ``` -AerOS, Afterglow, AIX, AlmaLinux, Alpine, Alpine2Small, AlpineSmall, Alter, Amazon, AmazonLinux, AmogOS, Anarchy, Android, AndroidSmall, Antergos, Antix, AoscOS, AoscOS_old, AoscOsRetro, AoscOsRetro_small, Aperture, Apple, AppleSmall, Apricity, Arch, Arch2, ArchBox, Archcraft, Archcraft2, Archlabs, ArchSmall, ArchStrike, ArcoLinux, ArcoLinuxSmall, ArseLinux, Artix, Artix2Small, ArtixSmall, Arya, Asahi, Aster, AsteroidOS, AstOS, Astra, Ataraxia, Athena, Bedrock, BigLinux, Bitrig, BlackArch, BlackPanther, BLAG, BlankOn, BlueLight, Bodhi, Bonsai, BSD, BunsenLabs, CachyOS, CachyOSSmall, Calculate, CalinixOS, CalinixOSSmall, Carbs, CBL-Mariner, CelOS, Center, CentOS, CentOSSmall, Chakra, ChaletOS, Chapeau, Chimera Linux, ChonkySealOS, Chrom, Cleanjaro, CleanjaroSmall, ClearLinux, ClearOS, Clover, Cobalt, Condres, ContainerLinux, CRUX, CRUXSmall, CrystalLinux, Cucumber, CutefishOS, CuteOS, CyberOS, Dahlia, DarkOS, Debian, DebianSmall, Deepin, DesaOS, Devuan, DevuanSmall, DietPi, DracOS, DragonFly, DragonFlyOld, DragonFlySmall, Drauger, Droidian, Elbrus, Elementary, ElementarySmall, Elive, EncryptOS, Endeavour, EndeavourSmall, Endless, Enso, EuroLinux, EvolutionOS, EvolutionOS_old, EvolutionOSSmall, Exherbo, ExodiaPredator, Fedora, FedoraOld, FedoraSmall, FemboyOS, Feren, Finnix, Floflis, FreeBSD, FreeBSDSmall, FreeMiNT, Frugalware, Funtoo, GalliumOS, Garuda, GarudaDragon, GarudaSmall, Gentoo, GentooSmall, GhostBSD, Glaucus, GNewSense, Gnome, GNU, GoboLinux, GrapheneOS, Grombyang, Guix, GuixSmall, Haiku, HaikuSmall, HamoniKR, HarDClanZ, HardenedBSD, Hash, Huayra, Hybrid, HydroOS, Hyperbola, HyperbolaSmall, Iglunix, InstantOS, IRIX, Itc, Januslinux, Kaisen, Kali, KaliSmall, KaOS, KDENeon, Kibojoe, KISSLinux, Kogaion, Korora, KrassOS, KSLinux, Kubuntu, LainOS, LangitKetujuh, Laxeros, LEDE, LibreELEC, Linspire, Linux, LinuxLight, LinuxLightSmall, LinuxMint, LinuxMintOld, LinuxMintSmall, LinuxSmall, Live_Raizo, LMDE, Lunar, MacOS, MacOS2, MacOS2Small, MacOSSmall, Mageia, MageiaSmall, MagpieOS, Mandriva, Manjaro, ManjaroSmall, MassOS, MatuusOS, MaUI, Meowix, Mer, Minix, Mint, MintOld, MintSmall, MiracleLinux, MOS, Msys2, MX, MXSmall, Namib, Nekos, Neptune, NetBSD, NetRunner, Nitrux, NixOS, NixOS_small, NixOsOld, NixOsSmall, Nobara, NomadBSD, Nurunner, NuTyX, Obarun, OBRevenge, OmniOS, OpenBSD, OpenBSDSmall, OpenEuler, OpenIndiana, OpenKylin, OpenMamba, OpenMandriva, OpenStage, OpenSuse, OpenSuseLeap, OpenSuseSmall, OpenSuseTumbleweed, OpenWrt, OPNsense, Oracle, Orchid, OrchidSmall, OS_Elbrus, OSMC, OSX, OSXSmall, PacBSD, Panwah, Parabola, ParabolaSmall, Parch, Pardus, Parrot, Parsix, PCBSD, PCLinuxOS, PearOS, Pengwin, Pentoo, Peppermint, PhyOS, Pisi, PNMLinux, Pop, PopSmall, Porteus, PostMarketOS, PostMarketOSSmall, Proxmox, PuffOS, Puppy, PureOS, PureOSSmall, Q4OS, Qubes, Qubyt, Quibian, Radix, Raspbian, RaspbianSmall, RavynOS, Reborn, RebornSmall, RedCore, RedHatEnterpriseLinux, RedHatEnterpriseLinux_old, RedstarOS, Refracted Devuan, Regata, Regolith, RhaymOS, RockyLinux, RockyLinuxSmall, RosaLinux, Sabayon, Sabotage, Sailfish, SalentOS, SalientOS, Salix, SambaBOX, Sasanqua, Scientific, Semc, Septor, Serene, SharkLinux, ShastraOS, Siduction, SkiffOS, Slackel, Slackware, SlackwareSmall, Slitaz, SmartOS, Soda, Solaris, SolarisSmall, Solus, SourceMage, Sparky, Star, SteamOS, StockLinux, Sulin, Suse, SuseSmall, Swagarch, T2, Tails, TeArch, TorizonCore, Trisquel, TuxedoOS, Twister, Ubuntu, Ubuntu2Old, Ubuntu2Small, UbuntuBudgie, UbuntuCinnamon, UbuntuGnome, UbuntuKde, UbuntuKylin, UbuntuMate, UbuntuOld, UbuntuSmall, UbuntuStudio, UbuntuSway, UbuntuTouch, UbuntuUnity, Ultramarine, Univalent, Univention, UOS, UrukOS, Uwuntu, Vanilla, Venom, VenomSmall, Vnux, Void, VoidSmall, Vzlinux, WiiLinuxNgx, Windows, Windows11, Windows11Small, Windows8, Windows95, Xenia, Xferience, YiffOS, Zorin +AerOS, Afterglow, AIX, AlmaLinux, Alpine, Alpine2Small, AlpineSmall, Alter, Amazon, AmazonLinux, AmogOS, Anarchy, Android, AndroidSmall, Antergos, Antix, AoscOS, AoscOS_old, AoscOsRetro, AoscOsRetro_small, Aperture, Apple, AppleSmall, Apricity, Arch, Arch2, ArchBox, Archcraft, Archcraft2, Archlabs, ArchSmall, ArchStrike, ArcoLinux, ArcoLinuxSmall, ArseLinux, Artix, Artix2Small, ArtixSmall, Arya, Asahi, Aster, AsteroidOS, AstOS, Astra, Ataraxia, Athena, Azos, Bedrock, BigLinux, Bitrig, BlackArch, BlackMesa, BlackPanther, BLAG, BlankOn, BlueLight, Bodhi, Bonsai, BSD, BunsenLabs, CachyOS, CachyOSSmall, Calculate, CalinixOS, CalinixOSSmall, Carbs, CBL-Mariner, CelOS, Center, CentOS, CentOSSmall, Chakra, ChaletOS, Chapeau, Chimera Linux, ChonkySealOS, Chrom, Cleanjaro, CleanjaroSmall, ClearLinux, ClearOS, Clover, Cobalt, Condres, ContainerLinux, CRUX, CRUXSmall, CrystalLinux, Cucumber, CutefishOS, CuteOS, CyberOS, cycledream, Dahlia, DarkOS, Debian, DebianSmall, Deepin, DesaOS, Devuan, DevuanSmall, DietPi, DracOS, DragonFly, DragonFlyOld, DragonFlySmall, Drauger, Droidian, Elbrus, Elementary, ElementarySmall, Elive, EncryptOS, Endeavour, EndeavourSmall, Endless, Enso, EuroLinux, evolinx, EvolutionOS, EvolutionOS_old, EvolutionOSSmall, Exherbo, ExodiaPredator, Fedora, FedoraOld, FedoraSmall, FemboyOS, Feren, Finnix, Floflis, FreeBSD, FreeBSDSmall, FreeMiNT, Frugalware, Funtoo, GalliumOS, Garuda, GarudaDragon, GarudaSmall, Gentoo, GentooSmall, GhostBSD, Glaucus, GNewSense, Gnome, GNU, GoboLinux, GrapheneOS, Grombyang, Guix, GuixSmall, Haiku, HaikuSmall, HamoniKR, HarDClanZ, HardenedBSD, Hash, Huayra, Hybrid, HydroOS, Hyperbola, HyperbolaSmall, Iglunix, InstantOS, IRIX, Itc, Januslinux, Kaisen, Kali, KaliSmall, KaOS, KDENeon, Kibojoe, KISSLinux, Kogaion, Korora, KrassOS, KSLinux, Kubuntu, LainOS, LangitKetujuh, Laxeros, LEDE, LibreELEC, Linspire, Linux, LinuxLight, LinuxLightSmall, LinuxMint, LinuxMintOld, LinuxMintSmall, LinuxSmall, Live_Raizo, LMDE, Lunar, MacOS, MacOS2, MacOS2Small, MacOSSmall, Mageia, MageiaSmall, MagpieOS, MainsailOS, MainsailOSSmall, Mandriva, Manjaro, ManjaroSmall, MassOS, MatuusOS, MaUI, Meowix, Mer, Minix, Mint, MintOld, MintSmall, MiracleLinux, MOS, Msys2, MX, MXSmall, Namib, Nekos, Neptune, NetBSD, NetRunner, Nitrux, NixOS, NixOS_small, NixOsOld, NixOsSmall, Nobara, NomadBSD, Nurunner, NuTyX, Obarun, OBRevenge, OmniOS, OpenBSD, OpenBSDSmall, OpenEuler, OpenIndiana, OpenKylin, OpenMamba, OpenMandriva, OpenStage, OpenSuse, OpenSuseLeap, OpenSuseSmall, OpenSuseTumbleweed, OpenWrt, OPNsense, Oracle, Orchid, OrchidSmall, OS_Elbrus, OSMC, OSX, OSXSmall, PacBSD, Panwah, Parabola, ParabolaSmall, Parch, Pardus, Parrot, Parsix, PCBSD, PCLinuxOS, PearOS, Pengwin, Pentoo, Peppermint, PhyOS, Pisi, PNMLinux, Pop, PopSmall, Porteus, PostMarketOS, PostMarketOSSmall, Proxmox, PuffOS, Puppy, PureOS, PureOSSmall, Q4OS, Qubes, Qubyt, Quibian, Radix, Raspbian, RaspbianSmall, RavynOS, Reborn, RebornSmall, RedCore, RedHatEnterpriseLinux, RedHatEnterpriseLinux_old, RedstarOS, Refracted Devuan, Regata, Regolith, RhaymOS, RockyLinux, RockyLinuxSmall, RosaLinux, Sabayon, Sabotage, Sailfish, SalentOS, SalientOS, Salix, SambaBOX, Sasanqua, Scientific, Semc, Septor, Serene, SharkLinux, ShastraOS, Siduction, SkiffOS, Slackel, Slackware, SlackwareSmall, Slitaz, SmartOS, Soda, Solaris, SolarisSmall, Solus, SourceMage, Sparky, Star, SteamOS, StockLinux, Sulin, Suse, SuseSmall, Swagarch, T2, Tails, TeArch, TorizonCore, Trisquel, TuxedoOS, Twister, Ubuntu, Ubuntu2Old, Ubuntu2Small, UbuntuBudgie, UbuntuCinnamon, UbuntuGnome, UbuntuKde, UbuntuKylin, UbuntuMate, UbuntuOld, UbuntuSmall, UbuntuStudio, UbuntuSway, UbuntuTouch, UbuntuUnity, Ultramarine, Univalent, Univention, UOS, UrukOS, Uwuntu, Vanilla, Venom, VenomSmall, Vnux, Void, VoidSmall, Vzlinux, WiiLinuxNgx, Windows, Windows11, Windows11Small, Windows8, Windows95, Xenia, Xferience, YiffOS, Zorin ``` Run `fastfetch --print-logos` to print them From a16851f5de8f8e5bd56a3d30ff1617c0adbee595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 15:47:55 +0800 Subject: [PATCH 085/100] JsonConfig: update json schema; change most `title` to `description` --- doc/json_schema.json | 300 +++++++++++++++++++++---------------------- 1 file changed, 150 insertions(+), 150 deletions(-) diff --git a/doc/json_schema.json b/doc/json_schema.json index 5a3d2ccd9..801925de4 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -10,21 +10,21 @@ ] }, "key": { - "title": "Key of the module", + "description": "Key of the module", "type": "string" }, "keyColor": { - "title": "Color of the module key. Left empty to use `display.color.keys`", + "description": "Color of the module key. Left empty to use `display.color.keys`", "$ref": "#/$defs/colors" }, "keyWidth": { - "title": "Width of the module key. Use 0 to use `display.keyWidth`", + "description": "Width of the module key. Use 0 to use `display.keyWidth`", "type": "integer", "minimum": 0, "default": 0 }, "format": { - "title": "Output format of the module", + "description": "Output format of the module", "type": "string" } }, @@ -34,26 +34,26 @@ "properties": { "$schema": { "type": "string", - "title": "JSON schema URL, for JSON validation and IDE intelligence", + "description": "JSON schema URL, for JSON validation and IDE intelligence", "format": "uri", "default": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json" }, "logo": { "oneOf": [ { - "title": "Disable logo", + "description": "Disable logo", "type": "null" }, { - "title": "Set the source file of the logo", + "description": "Set the source file of the logo", "type": "string" }, { - "title": "Fastfetch logo configurations", + "description": "Fastfetch logo configurations", "type": "object", "properties": { "type": { - "title": "Set the type of the logo given", + "description": "Set the type of the logo given", "enum": [ "auto", "builtin", @@ -74,46 +74,46 @@ }, "source": { "type": "string", - "title": "Set the source file of the logo" + "description": "Set the source file of the logo" }, "color": { "type": "object", - "title": "Overwrite a color in the logo", + "description": "Overwrite a color in the logo", "properties": { "1": { - "title": "Color 1", + "description": "Color 1", "$ref": "#/$defs/colors" }, "2": { - "title": "Color 2", + "description": "Color 2", "$ref": "#/$defs/colors" }, "3": { - "title": "Color 3", + "description": "Color 3", "$ref": "#/$defs/colors" }, "4": { - "title": "Color 4", + "description": "Color 4", "$ref": "#/$defs/colors" }, "5": { - "title": "Color 5", + "description": "Color 5", "$ref": "#/$defs/colors" }, "6": { - "title": "Color 6", + "description": "Color 6", "$ref": "#/$defs/colors" }, "7": { - "title": "Color 7", + "description": "Color 7", "$ref": "#/$defs/colors" }, "8": { - "title": "Color 8", + "description": "Color 8", "$ref": "#/$defs/colors" }, "9": { - "title": "Color 9", + "description": "Color 9", "$ref": "#/$defs/colors" } }, @@ -121,31 +121,31 @@ }, "width": { "type": "integer", - "title": "Set the width of the logo (in characters). Required for iTerm image protocol", + "description": "Set the width of the logo (in characters). Required for iTerm image protocol", "minimum": 1 }, "height": { "type": "integer", - "title": "Set the height of the logo (in characters). Required for iTerm image protocol", + "description": "Set the height of the logo (in characters). Required for iTerm image protocol", "minimum": 1 }, "padding": { "type": "object", - "title": "Set the padding of the logo", + "description": "Set the padding of the logo", "properties": { "top": { "type": "integer", - "title": "Set the top padding of the logo", + "description": "Set the top padding of the logo", "minimum": 0 }, "left": { "type": "integer", - "title": "Set the left padding of the logo", + "description": "Set the left padding of the logo", "minimum": 0 }, "right": { "type": "integer", - "title": "Set the right padding of the logo", + "description": "Set the right padding of the logo", "minimum": 0 } }, @@ -153,40 +153,40 @@ }, "printRemaining": { "type": "boolean", - "title": "Whether to print the remaining logo, if it has more lines than modules to display", + "description": "Whether to print the remaining logo, if it has more lines than modules to display", "default": false }, "preserveAspectRadio": { "type": "boolean", - "title": "Whether to preserve the aspect ratio of the logo. Supported by iTerm image protocol", + "description": "Whether to preserve the aspect ratio of the logo. Supported by iTerm image protocol", "default": false }, "recache": { "type": "boolean", - "title": "If true, regenerate image logo cache", + "description": "If true, regenerate image logo cache", "default": false }, "separate": { "type": "boolean", - "title": "If true, print modules at bottom of the logo", + "description": "If true, print modules at bottom of the logo", "default": false }, "chafa": { "type": "object", - "title": "Chafa configuration. See chafa document for details", + "description": "Chafa configuration. See chafa document for details", "properties": { "fgOnly": { "type": "boolean", - "title": "Produce character-cell output using foreground colors only", + "description": "Produce character-cell output using foreground colors only", "default": false }, "symbols": { "type": "string", - "title": "Specify character symbols to employ in final output" + "description": "Specify character symbols to employ in final output" }, "canvasMode": { "type": "string", - "title": "Determine how colors are used in the output. This value maps the value of enum ChafaCanvasMode.", + "description": "Determine how colors are used in the output. This value maps the value of enum ChafaCanvasMode.", "enum": [ "TRUECOLOR", "INDEXED_256", @@ -200,7 +200,7 @@ }, "colorSpace": { "type": "string", - "title": "Set color space used for quantization. This value maps the value of enum ChafaColorSpace.", + "description": "Set color space used for quantization. This value maps the value of enum ChafaColorSpace.", "enum": [ "RGB", "DIN99D" @@ -208,7 +208,7 @@ }, "ditherMode": { "type": "string", - "title": "Set output dither mode (No effect with 24-bit color). This value maps the value of enum ChafaDitherMode.", + "description": "Set output dither mode (No effect with 24-bit color). This value maps the value of enum ChafaDitherMode.", "enum": [ "NONE", "ORDERED", @@ -224,100 +224,100 @@ ] }, "general": { - "title": "Fastfetch general configurations", + "description": "Fastfetch general configurations", "type": "object", "properties": { "multithreading": { "type": "boolean", - "title": "Use multiple threads to detect values", + "description": "Use multiple threads to detect values", "default": true }, "thread": { "type": "boolean", - "title": "Alias of multithreading", + "description": "Alias of multithreading", "default": true }, "escapeBedrock": { "type": "boolean", - "title": "On Bedrock Linux, whether to escape the bedrock jail", + "description": "On Bedrock Linux, whether to escape the bedrock jail", "default": true }, "playerName": { "type": "string", - "title": "The name of the player to use for module Media and Player. Linux only" + "description": "The name of the player to use for module Media and Player. Linux only" }, "osFile": { "type": "string", - "title": "Set the path to the file containing OS information. Linux only" + "description": "Set the path to the file containing OS information. Linux only" }, "dsForceDrm": { "type": "boolean", - "title": "Force display detection to use `/sys/class/drm`. Linux only", + "description": "Force display detection to use `/sys/class/drm`. Linux only", "default": false }, "wmiTimeout": { "type": "integer", - "title": "Set the timeout (ms) for WMI queries, `-1` for no timeout. Windows only", + "description": "Set the timeout (ms) for WMI queries, `-1` for no timeout. Windows only", "default": 5000 }, "processingTimeout": { "type": "integer", - "title": "Set the timeout (ms) when waiting for child processes, `-1` for no timeout", + "description": "Set the timeout (ms) when waiting for child processes, `-1` for no timeout", "default": 1000 } }, "additionalProperties": false }, "display": { - "title": "Configure how things to be displayed", + "description": "Configure how things to be displayed", "type": "object", "properties": { "stat": { "type": "boolean", - "title": "Show time usage (in ms) for individual modules", + "description": "Show time usage (in ms) for individual modules", "default": false }, "pipe": { "type": "boolean", - "title": "Whether to enable pipe mode (disable logo and all escape sequences)", + "description": "Whether to enable pipe mode (disable logo and all escape sequences)", "default": false }, "showErrors": { "type": "boolean", - "title": "Print occurring errors to the console. False to ignore errored modules", + "description": "Print occurring errors to the console. False to ignore errored modules", "default": false }, "disableLinewrap": { "type": "boolean", - "title": "Whether to disable line wrap during the run", + "description": "Whether to disable line wrap during the run", "default": true }, "hideCursor": { "type": "boolean", - "title": "Whether to hide the cursor during the run", + "description": "Whether to hide the cursor during the run", "default": true }, "separator": { "type": "string", - "title": "Set the separator between key and value", + "description": "Set the separator between key and value", "default": ": " }, "color": { - "title": "Set the color of the keys and title", + "description": "Set the color of the keys and title", "oneOf": [ { - "title": "Set the both color of the keys and title", + "description": "Set the both color of the keys and title", "$ref": "#/$defs/colors" }, { "type": "object", "properties": { "keys": { - "title": "Set the color of the keys", + "description": "Set the color of the keys", "$ref": "#/$defs/colors" }, "title": { - "title": "Set the color of the title", + "description": "Set the color of the title", "$ref": "#/$defs/colors" } }, @@ -326,19 +326,19 @@ ] }, "brightColor": { - "title": "Set if the keys, title and ASCII logo should be printed in bright color", + "description": "Set if the keys, title and ASCII logo should be printed in bright color", "type": "boolean", "default": true }, "keyWidth": { - "title": "Align the width of keys to number of characters, 0 to disable", + "description": "Align the width of keys to number of characters, 0 to disable", "type": "integer", "minimum": 0, "default": 0 }, "binaryPrefix": { "type": "string", - "title": "Set the binary prefix to used when printing bytes", + "description": "Set the binary prefix to used when printing bytes", "oneOf": [ { "const": "iec", @@ -356,17 +356,17 @@ }, "size": { "type": "object", - "title": "Set how a size value should be displayed", + "description": "Set how a size value should be displayed", "properties": { "maxPrefix": { "type": "string", - "title": "Set the largest binary prefix to use when formatting sizes", + "description": "Set the largest binary prefix to use when formatting sizes", "enum": ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], "default": "YB" }, "ndigits": { "type": "integer", - "title": "Set the number of digits to keep after the decimal point when formatting sizes", + "description": "Set the number of digits to keep after the decimal point when formatting sizes", "minimum": 0, "maximum": 9, "default": 2 @@ -375,32 +375,32 @@ }, "temperatureUnit": { "type": "string", - "title": "Set the unit of the temperature", + "description": "Set the unit of the temperature", "enum": ["CELSIUS", "C", "FAHRENHEIT", "F", "KELVIN", "K"], "default": "C" }, "bar": { "type": "object", - "title": "Set the bar configuration", + "description": "Set the bar configuration", "properties": { "charElapsed": { "type": "string", - "title": "Set the character to use in elapsed part", + "description": "Set the character to use in elapsed part", "default": "â– " }, "charTotal": { "type": "string", - "title": "Set the character to use in total part", + "description": "Set the character to use in total part", "default": "-" }, "border": { "type": "boolean", - "title": "Whether to show a border around the bar", + "description": "Whether to show a border around the bar", "default": true }, "width": { "type": "integer", - "title": "Set the width of the bar, in number of characters", + "description": "Set the width of the bar, in number of characters", "minimum": 1, "default": 10 } @@ -408,143 +408,143 @@ }, "percent": { "type": "object", - "title": "Set how a percentage value should be displayed", + "description": "Set how a percentage value should be displayed", "properties": { "type": { "type": "number", - "title": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number", + "description": "Set the percentage output type. 1 for percentage number, 2 for bar, 3 for both, 6 for bar only, 9 for colored number", "minimum": 0, "maximum": 255, "default": 1 }, "ndigits": { "type": "number", - "title": "Set the number of digits to keep after the decimal point when formatting percentage numbers", + "description": "Set the number of digits to keep after the decimal point when formatting percentage numbers", "minimum": 0, "maximum": 9, "default": 0 - }, + } } }, "noBuffer": { "type": "boolean", - "title": "Whether to disable the stdout application buffer", + "description": "Whether to disable the stdout application buffer", "default": false } }, "additionalProperties": false }, "library": { - "title": "Set the path of a library to load", + "description": "Set the path of a library to load", "type": "object", "properties": { "pci": { "type": "string", - "title": "GPU output (Linux and FreeBSD)" + "description": "GPU output (Linux and FreeBSD)" }, "vulkan": { "type": "string", - "title": "Vulkan module & fallback for GPU output" + "description": "Vulkan module & fallback for GPU output" }, "freetype": { "type": "string", - "title": "Used for Termux font detection (Android)" + "description": "Used for Termux font detection (Android)" }, "wayland": { "type": "string", - "title": "Better display performance and output in wayland sessions.\nSupports different refresh rates per monitor.\n(Linux)" + "description": "Better display performance and output in wayland sessions.\nSupports different refresh rates per monitor.\n(Linux)" }, "xcbRandr": { "type": "string", - "title": "X11 sessions for better display detection and faster WM detection.\nThe *randr ones provide multi monitor support The libxcb* ones usually have better performance.\n (Linux, FreeBSD)" + "description": "X11 sessions for better display detection and faster WM detection.\nThe *randr ones provide multi monitor support The libxcb* ones usually have better performance.\n (Linux, FreeBSD)" }, "xcb": { "type": "string", - "title": "X11 sessions for better display detection and faster WM detection.\nThe *randr ones provide multi monitor support The libxcb* ones usually have better performance.\n (Linux, FreeBSD)" + "description": "X11 sessions for better display detection and faster WM detection.\nThe *randr ones provide multi monitor support The libxcb* ones usually have better performance.\n (Linux, FreeBSD)" }, "xrandr": { "type": "string", - "title": "X11 sessions for better display detection and faster WM detection.\nThe *randr ones provide multi monitor support The libxcb* ones usually have better performance.\n (Linux, FreeBSD)" + "description": "X11 sessions for better display detection and faster WM detection.\nThe *randr ones provide multi monitor support The libxcb* ones usually have better performance.\n (Linux, FreeBSD)" }, "x11": { "type": "string", - "title": "X11 sessions for better display detection and faster WM detection.\nThe *randr ones provide multi monitor support The libxcb* ones usually have better performance.\n (Linux, FreeBSD)" + "description": "X11 sessions for better display detection and faster WM detection.\nThe *randr ones provide multi monitor support The libxcb* ones usually have better performance.\n (Linux, FreeBSD)" }, "gio": { "type": "string", - "title": "Needed for values that are only stored GSettings (Linux, FreeBSD)" + "description": "Needed for values that are only stored GSettings (Linux, FreeBSD)" }, "dconf": { "type": "string", - "title": "Needed for values that are only stored in DConf + Fallback for GSettings (Linux, FreeBSD)" + "description": "Needed for values that are only stored in DConf + Fallback for GSettings (Linux, FreeBSD)" }, "dbus": { "type": "string", - "title": "Bluetooth, Player & Media detection (Linux, FreeBSD)" + "description": "Bluetooth, Player & Media detection (Linux, FreeBSD)" }, "xfconf": { "type": "string", - "title": "Needed for XFWM theme and XFCE Terminal font (Linux, FreeBSD)" + "description": "Needed for XFWM theme and XFCE Terminal font (Linux, FreeBSD)" }, "sqlite3": { "type": "string", - "title": "Needed for pkg & rpm package count (Linux, FreeBSD)" + "description": "Needed for pkg & rpm package count (Linux, FreeBSD)" }, "rpm": { "type": "string", - "title": "Slower fallback for rpm package count. Needed on openSUSE & old CentOS / Redhat. (Linux)" + "description": "Slower fallback for rpm package count. Needed on openSUSE & old CentOS / Redhat. (Linux)" }, "imagemagick": { "type": "string", - "title": "Images in terminal using sixel or kitty graphics protocol (Linux, FreeBSD, macOS)" + "description": "Images in terminal using sixel or kitty graphics protocol (Linux, FreeBSD, macOS)" }, "z": { - "title": "Libz. Faster image output when using kitty graphics protocol (Linux, FreeBSD, macOS)", + "description": "Libz. Faster image output when using kitty graphics protocol (Linux, FreeBSD, macOS)", "type": "string" }, "chafa": { "type": "string", - "title": "Image output as ascii art (Linux, FreeBSD, macOS)" + "description": "Image output as ascii art (Linux, FreeBSD, macOS)" }, "egl": { "type": "string", - "title": "Needed by the OpenGL module for gl context creation (Linux, FreeBSD)" + "description": "Needed by the OpenGL module for gl context creation (Linux, FreeBSD)" }, "glx": { "type": "string", - "title": "Needed by the OpenGL module for gl context creation (Linux, FreeBSD)" + "description": "Needed by the OpenGL module for gl context creation (Linux, FreeBSD)" }, "osmesa": { "type": "string", - "title": "Needed by the OpenGL module for gl context creation (Linux, FreeBSD)" + "description": "Needed by the OpenGL module for gl context creation (Linux, FreeBSD)" }, "opencl": { "type": "string", - "title": "OpenCL module (Linux, FreeBSD, Windows)" + "description": "OpenCL module (Linux, FreeBSD, Windows)" }, "pulse": { - "title": "Pulseaudio. Used for Sound detection (Linux, FreeBSD)", + "description": "Pulseaudio. Used for Sound detection (Linux, FreeBSD)", "type": "string" }, "nm": { - "title": "NetworkManager. Used for Wifi detection (Linux)", + "description": "NetworkManager. Used for Wifi detection (Linux)", "type": "string" }, "ddcutil": { - "title": "Used for brightness detection of external displays (Linux)", + "description": "Used for brightness detection of external displays (Linux)", "type": "string" } }, "additionalProperties": false }, "modules": { - "title": "Fastfetch modules to run", + "description": "Fastfetch modules to run", "type": "array", "items": { "anyOf": [ { "type": "string", - "title": "Run module with default configurations", + "description": "Run module with default configurations", "enum": [ "battery", "bios", @@ -606,7 +606,7 @@ }, { "type": "object", - "title": "Run module with custom configurations", + "description": "Run module with custom configurations", "required": [ "type" ], @@ -627,7 +627,7 @@ "additionalProperties": false }, { - "title": "No additional properties", + "description": "No additional properties", "properties": { "type": { "anyOf": [ @@ -784,16 +784,16 @@ "description": "Print battery capacity, status, etc" }, "dir": { - "title": "The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only", + "description": "The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only", "type": "string" }, "useSetupApi": { - "title": "Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only", + "description": "Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only", "type": "boolean", "default": false }, "temp": { - "title": "Detect and display Battery temperature if supported", + "description": "Detect and display Battery temperature if supported", "type": "boolean", "default": false }, @@ -820,7 +820,7 @@ "const": "bluetooth" }, "showDisconnected": { - "title": "Set if disconnected bluetooth devices should be printed", + "description": "Set if disconnected bluetooth devices should be printed", "type": "boolean", "default": false }, @@ -889,12 +889,12 @@ "const": "cpu" }, "temp": { - "title": "Detect and display CPU temperature if supported", + "description": "Detect and display CPU temperature if supported", "type": "boolean", "default": false }, "freqNdigits": { - "title": "Set the number of digits to keep after the decimal point when printing CPU frequency", + "description": "Set the number of digits to keep after the decimal point when printing CPU frequency", "type": "integer", "minimum": 0, "maximum": 9, @@ -937,7 +937,7 @@ "const": "colors" }, "symbol": { - "title": "Set the symbol to use", + "description": "Set the symbol to use", "type": "string", "enum": [ "block", @@ -950,7 +950,7 @@ "default": "block" }, "paddingLeft": { - "title": "Set the number of white spaces to print before the symbol", + "description": "Set the number of white spaces to print before the symbol", "type": "integer", "minimum": 0, "default": 0 @@ -965,11 +965,11 @@ "const": "command" }, "shell": { - "title": "Set the shell program to execute the command text\nDefault: cmd for Windows, /bin/sh for *nix", + "description": "Set the shell program to execute the command text\nDefault: cmd for Windows, /bin/sh for *nix", "type": "string" }, "text": { - "title": "Set the command text to be executed", + "description": "Set the command text to be executed", "type": "string" }, "key": { @@ -995,7 +995,7 @@ "const": "custom" }, "key": { - "title": "Leave empty not to print the key", + "description": "Leave empty not to print the key", "type": "string" }, "keyColor": { @@ -1005,7 +1005,7 @@ "$ref": "#/$defs/keyWidth" }, "format": { - "title": "Text to print", + "description": "Text to print", "type": "string" } }, @@ -1027,11 +1027,11 @@ "original", "scaled" ], - "title": "Set if all displays should be printed in one line", + "description": "Set if all displays should be printed in one line", "default": "none" }, "preciseRefreshRate": { - "title": "Set if decimal refresh rates should not be rounded into integers when printing", + "description": "Set if decimal refresh rates should not be rounded into integers when printing", "type": "boolean", "default": true }, @@ -1059,36 +1059,36 @@ }, "folders": { "type": "string", - "title": "A colon (semicolon on Windows) separated list of folder paths for the disk output\nDefault: \"/:/home\" (\"C:\\\\;D:\\\\ ...\" on Windows)" + "description": "A colon (semicolon on Windows) separated list of folder paths for the disk output\nDefault: \"/:/home\" (\"C:\\\\;D:\\\\ ...\" on Windows)" }, "showExternal": { "type": "boolean", - "title": "Set if external volume should be printed", + "description": "Set if external volume should be printed", "default": true }, "showHidden": { "type": "boolean", - "title": "Set if hidden volumes should be printed", + "description": "Set if hidden volumes should be printed", "default": false }, "showSubvolumes": { "type": "boolean", - "title": "Set if subvolumes should be printed", + "description": "Set if subvolumes should be printed", "default": false }, "showReadOnly": { "type": "boolean", - "title": "Set if read only volumes should be printed", + "description": "Set if read only volumes should be printed", "default": false }, "showUnknown": { "type": "boolean", - "title": "Set if unknown (unable to detect sizes) volumes should be printed", + "description": "Set if unknown (unable to detect sizes) volumes should be printed", "default": false }, "useAvailable": { "type": "boolean", - "title": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes", + "description": "Use f_bavail (lpFreeBytesAvailableToCaller for Windows) instead of f_bfree to calculate used bytes", "default": false }, "key": { @@ -1114,7 +1114,7 @@ "const": "diskio" }, "namePrefix": { - "title": "Show disks with given name prefix only", + "description": "Show disks with given name prefix only", "type": "string" }, "key": { @@ -1166,7 +1166,7 @@ "const": "gpu" }, "temp": { - "title": "Detect and display GPU temperature if supported", + "description": "Detect and display GPU temperature if supported", "type": "boolean", "default": false }, @@ -1176,12 +1176,12 @@ "default": false }, "forceVulkan": { - "title": "Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`", + "description": "Force using vulkan to detect GPUs, which support video memory usage detection with `--allow-slow-operations`", "type": "boolean", "default": false }, "hideType": { - "title": "Specify the type of GPUs should not be printed", + "description": "Specify the type of GPUs should not be printed", "enum": [ "integrated", "discrete", @@ -1212,36 +1212,36 @@ "const": "localip" }, "showIpv4": { - "title": "Show IPv4 addresses", + "description": "Show IPv4 addresses", "type": "boolean", "default": true }, "showIpv6": { - "title": "Show IPv6 addresses", + "description": "Show IPv6 addresses", "type": "boolean", "default": false }, "showMac": { - "title": "Show MAC addresses", + "description": "Show MAC addresses", "type": "boolean", "default": false }, "showLoop": { - "title": "Show loop back addresses (127.0.0.1)", + "description": "Show loop back addresses (127.0.0.1)", "type": "boolean", "default": false }, "compact": { - "title": "Show all IPs in one line", + "description": "Show all IPs in one line", "type": "boolean", "default": false }, "namePrefix": { - "title": "Show IPs with given name prefix only", + "description": "Show IPs with given name prefix only", "type": "string" }, "defaultRouteOnly": { - "title": "Show ips that are used for default routing only", + "description": "Show ips that are used for default routing only", "type": "boolean", "default": false }, @@ -1268,11 +1268,11 @@ "const": "netio" }, "namePrefix": { - "title": "Show IPs with given name prefix only", + "description": "Show IPs with given name prefix only", "type": "string" }, "defaultRouteOnly": { - "title": "Show ips that are used for default routing only", + "description": "Show ips that are used for default routing only", "type": "boolean", "default": false }, @@ -1299,7 +1299,7 @@ "const": "opengl" }, "library": { - "title": "Set the OpenGL context creation library to use. Linux only", + "description": "Set the OpenGL context creation library to use. Linux only", "enum": [ "auto", "egl", @@ -1357,13 +1357,13 @@ "const": "publicip" }, "url": { - "title": "The URL of public IP detection server to be used. Only HTTP protocol is supported", + "description": "The URL of public IP detection server to be used. Only HTTP protocol is supported", "type": "string", "format": "url", "default": "http://ipinfo.io/ip" }, "timeout": { - "title": "Time in milliseconds to wait for the public ip server to respond", + "description": "Time in milliseconds to wait for the public ip server to respond", "type": "integer", "minimum": 0, "default": "disabled (0)" @@ -1391,7 +1391,7 @@ "const": "separator" }, "string": { - "title": "Set the string to be printed", + "description": "Set the string to be printed", "type": "string", "default": "-" } @@ -1406,7 +1406,7 @@ "const": "sound" }, "soundType": { - "title": "Set what type of sound devices should be printed", + "description": "Set what type of sound devices should be printed", "type": "string", "enum": [ "main", @@ -1439,22 +1439,22 @@ }, "fqdn": { "type": "boolean", - "title": "Set if the title should use fully qualified domain name", + "description": "Set if the title should use fully qualified domain name", "default": false }, "color": { - "title": "Set colors of the different part of title", + "description": "Set colors of the different part of title", "properties": { "user": { - "title": "Set color of the user name (left part)", + "description": "Set color of the user name (left part)", "$ref": "#/$defs/colors" }, "at": { - "title": "Set color of the @ symbol (middle part)", + "description": "Set color of the @ symbol (middle part)", "$ref": "#/$defs/colors" }, "host": { - "title": "Set color of the host name (right part)", + "description": "Set color of the host name (right part)", "$ref": "#/$defs/colors" } }, @@ -1483,17 +1483,17 @@ "const": "weather" }, "location": { - "title": "The location to display", + "description": "The location to display", "type": "string" }, "timeout": { - "title": "Time in milliseconds to wait for the weather server to respond", + "description": "Time in milliseconds to wait for the weather server to respond", "type": "integer", "minimum": 0, "default": "disabled (0)" }, "outputFormat": { - "title": "The output weather format to be used (must be URI encoded)", + "description": "The output weather format to be used (must be URI encoded)", "type": "string", "default": "%t+-+%C+(%l)" }, @@ -1520,7 +1520,7 @@ "description": "Print window manager name and version" }, "detectPlugin": { - "title": "Set if window manager plugin should be detected on supported platforms", + "description": "Set if window manager plugin should be detected on supported platforms", "type": "boolean", "default": false }, From 9ddefbc1a2ab075a56db4e89b5e2e66dc42a7a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 16:32:57 +0800 Subject: [PATCH 086/100] Doc: update README --- README.md | 133 ++++++++++-------------------------------------------- 1 file changed, 24 insertions(+), 109 deletions(-) diff --git a/README.md b/README.md index 5b8b1e4e9..2f387b60e 100644 --- a/README.md +++ b/README.md @@ -23,137 +23,52 @@ Fastfetch is a [neofetch](https://github.com/dylanaraps/neofetch)-like tool for There are [screenshots on different platforms](https://github.com/fastfetch-cli/fastfetch/wiki) -## Customization +## Installation -Fastfetch uses the JSONC format for configuration. [See Wiki for detail](https://github.com/fastfetch-cli/fastfetch/wiki/Configuration). There are some premade config files in [`presets`](presets), including the ones used for the screenshots above. You can load them using `-c `. They may also serve as a good example for format arguments. +### Linux -Logos can be heavily customized too; see the [logo documentation](https://github.com/fastfetch-cli/fastfetch/wiki/Logo-options) for more information. +* Debian / Ubuntu: Download `fastfetch--Linux.deb` from [Github release page](https://github.com/fastfetch-cli/fastfetch/releases/latest) and `sudo apt install fastfetch--Linux.deb` +* Arch Linux: `sudo pacman -S fastfetch` +* Fedora: `sudo dnf install fastfetch` +* Gentoo: `sudo emerge --ask app-misc/fastfetch` -## Dependencies - -Fastfetch dynamically loads needed libraries if they are available. On Linux, its only hard dependencies are `libc` (any implementation of the c standard library), `libdl`, `libm` and [`libpthread`](https://man7.org/linux/man-pages/man7/pthreads.7.html) (if built with multithreading support). They are all shipped with [`glibc`](https://www.gnu.org/software/libc/), which is already installed on most Linux distributions. - -The following libraries are used if present at runtime: - -### Linux and FreeBSD - -* [`libpci`](https://github.com/pciutils/pciutils): GPU output. -* [`libvulkan`](https://www.vulkan.org/): Vulkan module & fallback for GPU output. -* [`libxcb-randr`](https://xcb.freedesktop.org/), - [`libXrandr`](https://gitlab.freedesktop.org/xorg/lib/libxrandr), - [`libxcb`](https://xcb.freedesktop.org/), - [`libX11`](https://gitlab.freedesktop.org/xorg/lib/libx11): At least one of them sould be present in X11 sessions for better display detection and faster WM detection. The `*randr` ones provide multi monitor support The `libxcb*` ones usually have better performance. -* [`libwayland-client`](https://wayland.freedesktop.org/): Better display performance and output in wayland sessions. Supports different refresh rates per monitor. -* [`libGIO`](https://developer.gnome.org/gio/unstable/): Needed for values that are only stored GSettings. -* [`libDConf`](https://developer.gnome.org/dconf/unstable/): Needed for values that are only stored in DConf + Fallback for GSettings. -* [`libmagickcore` (ImageMagick)](https://www.imagemagick.org/): Images in terminal using sixel or kitty graphics protocol. -* [`libchafa`](https://github.com/hpjansson/chafa): Image output as ascii art. -* [`libZ`](https://www.zlib.net/): Faster image output when using kitty graphics protocol. -* [`libDBus`](https://www.freedesktop.org/wiki/Software/dbus): Bluetooth, Player & Media detection. -* [`libEGL`](https://www.khronos.org/registry/EGL/), - [`libGLX`](https://dri.freedesktop.org/wiki/GLX/), - [`libOSMesa`](https://docs.mesa3d.org/osmesa.html): At least one of them is needed by the OpenGL module for gl context creation. -* [`libOpenCL`](https://www.khronos.org/opencl/): OpenCL module -* [`libXFConf`](https://gitlab.xfce.org/xfce/xfconf): Needed for XFWM theme and XFCE Terminal font. -* [`libsqlite3`](https://www.sqlite.org/index.html): Needed for pkg & rpm package count. -* [`librpm`](http://rpm.org/): Slower fallback for rpm package count. Needed on openSUSE. -* [`libnm`](https://networkmanager.dev/docs/libnm/latest/): Used for Wifi detection. -* [`libpulse`](https://freedesktop.org/software/pulseaudio/doxygen/): Used for Sound detection. -* [`libddcutil`](https://github.com/rockowitz/ddcutil): Used for brightness detection of external displays -* [`DirectX-Headers`](https://github.com/microsoft/DirectX-Headers): Used for GPU detection in WSL +[See also if fastfetch has been packaged for your favorite Linux distro](#Packaging) ### macOS - -* [`MediaRemote`](https://iphonedev.wiki/index.php/MediaRemote.framework): Need for Media detection. It's a private framework provided by newer macOS system. -* [`DisplayServices`](https://developer.apple.com/forums/thread/666383#663154022): Need for screen brightness detection. It's a private framework provided by newer macOS system. -* [`Apple80211`](https://code.google.com/archive/p/iphone-wireless/wikis): Need for Wifi detection on Sonoma (and maybe later). It's a private framework provided by newer macOS system. -* [`MoltenVK`](https://github.com/KhronosGroup/MoltenVK): Vulkan driver for macOS. [`molten-vk`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/molten-vk.rb) -* [`libmagickcore` (ImageMagick)](https://www.imagemagick.org/): Images in terminal using sixel graphics protocol. [`imagemagick`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/imagemagick.rb) -* [`libchafa`](https://github.com/hpjansson/chafa): Image output as ascii art. [`chafa`](https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/chafa.rb) -* [`libsqlite3`](https://www.sqlite.org/index.html): Used for fast wallpaper detection ( fallback to AppleScript ) -For the image logo, iTerm with iterm image protocol should work. Apple Terminal is not supported. +`brew install fastfetch` ### Windows -* [`wlanapi`](https://learn.microsoft.com/en-us/windows/win32/api/wlanapi/): A system dll which isn't supported by Windows Server by default. Used for Wifi info detection. -* [`libvulkan`](https://www.vulkan.org/): Vulkan module. Usually has been provided by GPU drivers. [`vulkan-loader`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-vulkan-loader) [`vulkan-headers`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-vulkan-headers) -* [`libOpenCL`](https://www.khronos.org/opencl/): OpenCL module. [`opencl-icd`](https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-opencl-icd) +`scoop install fastfetch` -Note: In Windows 7, 8 and 8.1, [ConEmu](https://conemu.github.io/en/AnsiEscapeCodes.html) is required to run fastfetch due to [the lack of ASCII escape code native support](https://en.wikipedia.org/wiki/ANSI_escape_code#DOS,_OS/2,_and_Windows). In addition, as fastfetch for Windows targets [UCRT](https://learn.microsoft.com/en-us/cpp/windows/universal-crt-deployment) C runtime library, [it must be installed manually](https://support.microsoft.com/en-us/topic/update-for-universal-c-runtime-in-windows-c0514201-7fe6-95a3-b0a5-287930f3560c) as UCRT is only pre-installed in Windows 10 and later. +You may also download it directly from [GitHub releases page](https://github.com/fastfetch-cli/fastfetch/releases/latest) and extract the archive. -For the image logo, WezTerm with iterm image protocol is known to work, surprisingly. +### FreeBSD -### Android +`pkg install fastfetch` -* [`freetype`](https://www.freetype.org/): Used for Termux font detection. [`freetype`](https://github.com/termux/termux-packages/tree/master/packages/freetype) -* [`libvulkan`](https://www.vulkan.org/): Vulkan module, also used for GPU detection. Usually has been provided by Android system. [`vulkan-loader-android`](https://github.com/termux/termux-packages/tree/master/packages/vulkan-loader-android) [`vulkan-headers`](https://github.com/termux/termux-packages/tree/master/packages/vulkan-headers) -* [`termux-api`](https://github.com/termux/termux-api-package): Used for Wifi / Battery detection. Both the package [termux-api](https://github.com/termux/termux-packages/tree/master/packages/termux-api) and the Android app [Termux API](https://github.com/termux/termux-api) must be installed and the app `Termux API` must be configured to be able to self-running. In order to make Wifi detection actuall work, location privilege must be granted to the app `Termux API`. Read [the official doc](https://wiki.termux.com/wiki/Termux:API) for detail. -* [`libandroid-wordexp-static`](https://github.com/termux/termux-packages/tree/master/packages/libandroid-wordexp): `wordexp.h` support for Android. +### Android (Termux) -For the image logo, [Termux Monet](https://github.com/HardcodedCat/termux-monet) supports iterm image protocol. +`pkg install fastfetch` -## Support status -All categories not listed here should work without needing a specific implementation. +## Build from source -##### Available Modules -``` -Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsage, Cursor, Custom, Date, DateTime, DE, Disk, DiskIO, Display, Font, Gamepad, GPU, Host, Icons, Kernel, LM, Locale, LocalIP, Media, Memory, Monitor, NetIO, OpenCL, OpenGL, OS, Packages, Player, Power Adapter, Processes, PublicIP, Separator, Shell, Sound, Swap, Terminal, Terminal Font, Terminal Size, Theme, Time, Title, Uptime, Version, Vulkan, Wallpaper, Weather, Wifi, WM, WMTheme -``` +See Wiki: https://github.com/fastfetch-cli/fastfetch/wiki/Building -##### Builtin logos +## Usage - -``` -AerOS, Afterglow, AIX, AlmaLinux, Alpine, Alpine2Small, AlpineSmall, Alter, Amazon, AmazonLinux, AmogOS, Anarchy, Android, AndroidSmall, Antergos, Antix, AoscOS, AoscOS_old, AoscOsRetro, AoscOsRetro_small, Aperture, Apple, AppleSmall, Apricity, Arch, Arch2, ArchBox, Archcraft, Archcraft2, Archlabs, ArchSmall, ArchStrike, ArcoLinux, ArcoLinuxSmall, ArseLinux, Artix, Artix2Small, ArtixSmall, Arya, Asahi, Aster, AsteroidOS, AstOS, Astra, Ataraxia, Athena, Azos, Bedrock, BigLinux, Bitrig, BlackArch, BlackMesa, BlackPanther, BLAG, BlankOn, BlueLight, Bodhi, Bonsai, BSD, BunsenLabs, CachyOS, CachyOSSmall, Calculate, CalinixOS, CalinixOSSmall, Carbs, CBL-Mariner, CelOS, Center, CentOS, CentOSSmall, Chakra, ChaletOS, Chapeau, Chimera Linux, ChonkySealOS, Chrom, Cleanjaro, CleanjaroSmall, ClearLinux, ClearOS, Clover, Cobalt, Condres, ContainerLinux, CRUX, CRUXSmall, CrystalLinux, Cucumber, CutefishOS, CuteOS, CyberOS, cycledream, Dahlia, DarkOS, Debian, DebianSmall, Deepin, DesaOS, Devuan, DevuanSmall, DietPi, DracOS, DragonFly, DragonFlyOld, DragonFlySmall, Drauger, Droidian, Elbrus, Elementary, ElementarySmall, Elive, EncryptOS, Endeavour, EndeavourSmall, Endless, Enso, EuroLinux, evolinx, EvolutionOS, EvolutionOS_old, EvolutionOSSmall, Exherbo, ExodiaPredator, Fedora, FedoraOld, FedoraSmall, FemboyOS, Feren, Finnix, Floflis, FreeBSD, FreeBSDSmall, FreeMiNT, Frugalware, Funtoo, GalliumOS, Garuda, GarudaDragon, GarudaSmall, Gentoo, GentooSmall, GhostBSD, Glaucus, GNewSense, Gnome, GNU, GoboLinux, GrapheneOS, Grombyang, Guix, GuixSmall, Haiku, HaikuSmall, HamoniKR, HarDClanZ, HardenedBSD, Hash, Huayra, Hybrid, HydroOS, Hyperbola, HyperbolaSmall, Iglunix, InstantOS, IRIX, Itc, Januslinux, Kaisen, Kali, KaliSmall, KaOS, KDENeon, Kibojoe, KISSLinux, Kogaion, Korora, KrassOS, KSLinux, Kubuntu, LainOS, LangitKetujuh, Laxeros, LEDE, LibreELEC, Linspire, Linux, LinuxLight, LinuxLightSmall, LinuxMint, LinuxMintOld, LinuxMintSmall, LinuxSmall, Live_Raizo, LMDE, Lunar, MacOS, MacOS2, MacOS2Small, MacOSSmall, Mageia, MageiaSmall, MagpieOS, MainsailOS, MainsailOSSmall, Mandriva, Manjaro, ManjaroSmall, MassOS, MatuusOS, MaUI, Meowix, Mer, Minix, Mint, MintOld, MintSmall, MiracleLinux, MOS, Msys2, MX, MXSmall, Namib, Nekos, Neptune, NetBSD, NetRunner, Nitrux, NixOS, NixOS_small, NixOsOld, NixOsSmall, Nobara, NomadBSD, Nurunner, NuTyX, Obarun, OBRevenge, OmniOS, OpenBSD, OpenBSDSmall, OpenEuler, OpenIndiana, OpenKylin, OpenMamba, OpenMandriva, OpenStage, OpenSuse, OpenSuseLeap, OpenSuseSmall, OpenSuseTumbleweed, OpenWrt, OPNsense, Oracle, Orchid, OrchidSmall, OS_Elbrus, OSMC, OSX, OSXSmall, PacBSD, Panwah, Parabola, ParabolaSmall, Parch, Pardus, Parrot, Parsix, PCBSD, PCLinuxOS, PearOS, Pengwin, Pentoo, Peppermint, PhyOS, Pisi, PNMLinux, Pop, PopSmall, Porteus, PostMarketOS, PostMarketOSSmall, Proxmox, PuffOS, Puppy, PureOS, PureOSSmall, Q4OS, Qubes, Qubyt, Quibian, Radix, Raspbian, RaspbianSmall, RavynOS, Reborn, RebornSmall, RedCore, RedHatEnterpriseLinux, RedHatEnterpriseLinux_old, RedstarOS, Refracted Devuan, Regata, Regolith, RhaymOS, RockyLinux, RockyLinuxSmall, RosaLinux, Sabayon, Sabotage, Sailfish, SalentOS, SalientOS, Salix, SambaBOX, Sasanqua, Scientific, Semc, Septor, Serene, SharkLinux, ShastraOS, Siduction, SkiffOS, Slackel, Slackware, SlackwareSmall, Slitaz, SmartOS, Soda, Solaris, SolarisSmall, Solus, SourceMage, Sparky, Star, SteamOS, StockLinux, Sulin, Suse, SuseSmall, Swagarch, T2, Tails, TeArch, TorizonCore, Trisquel, TuxedoOS, Twister, Ubuntu, Ubuntu2Old, Ubuntu2Small, UbuntuBudgie, UbuntuCinnamon, UbuntuGnome, UbuntuKde, UbuntuKylin, UbuntuMate, UbuntuOld, UbuntuSmall, UbuntuStudio, UbuntuSway, UbuntuTouch, UbuntuUnity, Ultramarine, Univalent, Univention, UOS, UrukOS, Uwuntu, Vanilla, Venom, VenomSmall, Vnux, Void, VoidSmall, Vzlinux, WiiLinuxNgx, Windows, Windows11, Windows11Small, Windows8, Windows95, Xenia, Xferience, YiffOS, Zorin -``` +* Run it with default configuration: `fastfetch` +* Run it with [all supported modules](https://github.com/fastfetch-cli/fastfetch/wiki/Support+Status#available-modules) and find what you interest: `fastfetch -c all.jsonc` +* Find all data that fastfetch detects: `fastfetch -s --format json` +* Get help messages: `fastfetch --help` -Run `fastfetch --print-logos` to print them +## Customization -##### Package managers -``` -apk, brew, Chocolatey, dpkg, emerge, eopkg, Flatpak, MacPorts, nix, opkg, Pacman, paludis, pkg, pkgtool, rpm, scoop, Snap, xbps -``` +Fastfetch uses the JSONC (or JSON with comments) for configuration. [See Wiki for detail](https://github.com/fastfetch-cli/fastfetch/wiki/Configuration). There are some premade config files in [`presets`](presets), including the ones used for the screenshots above. You can load them using `-c `. They may also serve as a good example for format arguments. -##### WM themes -``` -DWM (Windows), KWin, Marco, Muffin, Mutter, Openbox (LXDE, LXQT & without DE), Quartz Compositor (macOS), XFWM -``` +Logos can be heavily customized too; see the [logo documentation](https://github.com/fastfetch-cli/fastfetch/wiki/Logo-options) for more information. -##### DE versions -``` -Budgie, Cinnamon, Gnome, KDE Plasma, LXQt, Mate, XFCE4 -``` - -##### Terminal fonts -``` -Alacritty, Apple Terminal, ConEmu, Deepin Terminal, foot, Gnome Console, Gnome Terminal, iTerm2, Kitty, Konsole, LXTerminal, MATE Terminal, mintty, QTerminal, st, Tabby, Terminator, Termux, Tilix, TTY, Warp, WezTerm, Windows Terminal, XFCE4 Terminal, Yakuake -``` - -## Building - -fastfetch uses [`cmake`](https://cmake.org/) for building. [`pkg-config`](https://www.freedesktop.org/wiki/Software/pkg-config/) is recommended for better library detection. The simplest steps to build the fastfetch and flashfetch binaries are: -```bash -mkdir -p build -cd build -cmake .. -cmake --build . --target fastfetch --target flashfetch -``` - -If the build process fails to find the headers for a library listed in [dependencies](#dependencies), fastfetch will simply build without support for that specific feature. This means, it won't look for it at runtime and just act like it isn't available. - -### Building on Windows - -Currently GCC or clang is required (MSVC is not supported). MSYS2 with CLANG64 subsystem (or CLANGARM64 if needed) is suggested (and tested) to build fastfetch. If you need Windows 7 / 8.x support, using MINGW64 is suggested. - -1. Install [MSYS2](https://www.msys2.org/#installation) -1. Open `MSYS2 / CLANG64` (not `MSYS2 / MSYS`, which targets cygwin C runtime) -1. Install dependencies -```bash -pacman -Syu mingw-w64-clang-x86_64-cmake mingw-w64-clang-x86_64-pkgconf mingw-w64-clang-x86_64-clang mingw-w64-clang-x86_64-vulkan-loader mingw-w64-clang-x86_64-opencl-icd -``` - -Follow the building instructions of Linux next. ## Packaging From b6e759f3a267eec26d69eb73b504be17e74fd84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 19:45:12 +0800 Subject: [PATCH 087/100] LocalIP / NetIO: make `defaultRouteOnly` defaults to true --- CHANGELOG.md | 1 + doc/json_schema.json | 4 ++-- src/data/help.txt | 4 ++-- src/modules/localip/localip.c | 4 ++-- src/modules/netio/netio.c | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae397c3ff..07fbc962a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Changes: * `--battery-use-setup-api`: control whether `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. * `--wm-detect-plugin`: control whether WM plugins should be detected. Note it's implemented with global processes enumeration and can report false results. * `--de-slow-version-detection`: control DE version should be detected with slow operations. It's usually not necessary and only provided as a backup. +* `--localip-default-route-only` and `--netio-default-route-only` defaults to true to avoid large number of results Features: * Quirks for MIPS platforms (CPU, Linux) diff --git a/doc/json_schema.json b/doc/json_schema.json index 801925de4..4dec417bd 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1243,7 +1243,7 @@ "defaultRouteOnly": { "description": "Show ips that are used for default routing only", "type": "boolean", - "default": false + "default": true }, "key": { "$ref": "#/$defs/key" @@ -1274,7 +1274,7 @@ "defaultRouteOnly": { "description": "Show ips that are used for default routing only", "type": "boolean", - "default": false + "default": true }, "key": { "$ref": "#/$defs/key" diff --git a/src/data/help.txt b/src/data/help.txt index a1516699d..ef5b98569 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -160,10 +160,10 @@ Module specific options: --localip-show-mac : Show mac addresses in local ip module. Default is false --localip-show-loop : Show loop back addresses (127.0.0.1) in local ip module. Default is false --localip-name-prefix : Show interfaces with given interface name prefix only. Default is empty - --localip-default-route-only : Show the interface that is used for default routing only. Default is false + --localip-default-route-only : Show the interface that is used for default routing only. Default is true --localip-compact : Show all IPs in one line. Default is false --netio-name-prefix : Show interfaces with given name prefix only. Default is empty - --netio-default-route-only : Show the interfac that is used for default routing only. Default is false + --netio-default-route-only : Show the interfac that is used for default routing only. Default is true --publicip-timeout: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0) --publicip-url: The URL of public IP detection server to be used. --weather-location: Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`). diff --git a/src/modules/localip/localip.c b/src/modules/localip/localip.c index 9f17891fc..4d2150f8d 100644 --- a/src/modules/localip/localip.c +++ b/src/modules/localip/localip.c @@ -105,7 +105,7 @@ void ffPrintLocalIp(FFLocalIpOptions* options) if(options->moduleArgs.outputFormat.length == 0) { ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY); - printIp(ip, !options->defaultRouteOnly); + printIp(ip, true); putchar('\n'); } else @@ -370,7 +370,7 @@ void ffInitLocalIpOptions(FFLocalIpOptions* options) options->showType = FF_LOCALIP_TYPE_IPV4_BIT; ffStrbufInit(&options->namePrefix); - options->defaultRouteOnly = false; + options->defaultRouteOnly = true; } void ffDestroyLocalIpOptions(FFLocalIpOptions* options) diff --git a/src/modules/netio/netio.c b/src/modules/netio/netio.c index 9542cb021..6105e52ef 100644 --- a/src/modules/netio/netio.c +++ b/src/modules/netio/netio.c @@ -230,7 +230,7 @@ void ffInitNetIOOptions(FFNetIOOptions* options) ffOptionInitModuleArg(&options->moduleArgs); ffStrbufInit(&options->namePrefix); - options->defaultRouteOnly = false; + options->defaultRouteOnly = true; } void ffDestroyNetIOOptions(FFNetIOOptions* options) From b4777fe73a3ea769c55dac602bfc515a3c86e947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 21:55:17 +0800 Subject: [PATCH 088/100] Windows: silence compiler warnings --- src/modules/datetime/datetime.c | 2 ++ src/modules/users/users.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/modules/datetime/datetime.c b/src/modules/datetime/datetime.c index 445f17088..05d1991e8 100644 --- a/src/modules/datetime/datetime.c +++ b/src/modules/datetime/datetime.c @@ -6,6 +6,8 @@ #include +#pragma GCC diagnostic ignored "-Wformat" // warning: unknown conversion type character 'F' in format + #define FF_DATETIME_DISPLAY_NAME "Date & Time" #define FF_DATETIME_NUM_FORMAT_ARGS 20 diff --git a/src/modules/users/users.c b/src/modules/users/users.c index 59fd43f62..b4265ee98 100644 --- a/src/modules/users/users.c +++ b/src/modules/users/users.c @@ -6,6 +6,8 @@ #include +#pragma GCC diagnostic ignored "-Wformat" // warning: unknown conversion type character 'F' in format + #define FF_USERS_NUM_FORMAT_ARGS 1 void ffPrintUsers(FFUsersOptions* options) From 38ac3390114dec18d3e56d0dd53227535450ce96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 21:56:50 +0800 Subject: [PATCH 089/100] WM: support WindowBlinds detection --- CMakeLists.txt | 2 +- .../terminalshell/terminalshell_windows.c | 3 +- src/detection/wm/wm_windows.cpp | 66 +++++++++++++++++++ src/modules/wm/wm.c | 14 +++- 4 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 src/detection/wm/wm_windows.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index da522c08f..fa203d130 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -641,7 +641,7 @@ elseif(WIN32) src/detection/users/users_windows.c src/detection/wallpaper/wallpaper_windows.c src/detection/wifi/wifi_windows.c - src/detection/wm/wm_nosupport.c + src/detection/wm/wm_windows.cpp src/detection/de/de_nosupport.c src/detection/wmtheme/wmtheme_windows.c src/util/windows/getline.c diff --git a/src/detection/terminalshell/terminalshell_windows.c b/src/detection/terminalshell/terminalshell_windows.c index 746ba32a7..06ef8c573 100644 --- a/src/detection/terminalshell/terminalshell_windows.c +++ b/src/detection/terminalshell/terminalshell_windows.c @@ -130,7 +130,7 @@ static uint32_t getShellInfo(FFTerminalShellResult* result, uint32_t pid) { ffStrbufClear(&result->shellPrettyName); - HANDLE snapshot; + FF_AUTO_CLOSE_FD HANDLE snapshot = NULL; while(!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid)) && GetLastError() == ERROR_BAD_LENGTH) {} if(snapshot) @@ -147,7 +147,6 @@ static uint32_t getShellInfo(FFTerminalShellResult* result, uint32_t pid) break; } } - CloseHandle(snapshot); } if(result->shellPrettyName.length == 0) ffStrbufAppendS(&result->shellPrettyName, "Command Prompt"); diff --git a/src/detection/wm/wm_windows.cpp b/src/detection/wm/wm_windows.cpp new file mode 100644 index 000000000..941052830 --- /dev/null +++ b/src/detection/wm/wm_windows.cpp @@ -0,0 +1,66 @@ +extern "C" +{ +#include "wm.h" +#include "common/io/io.h" +#include "detection/terminalshell/terminalshell.h" +} + +#include "util/windows/com.hpp" + +#include +#include +#include +#include +#include + +template +struct on_scope_exit { + on_scope_exit(Fn &&fn): _fn(std::move(fn)) {} + ~on_scope_exit() { this->_fn(); } + +private: + Fn _fn; +}; + +extern "C" +const char* ffDetectWMPlugin(FFstrbuf* pluginName) +{ + DWORD pid = ffDetectTerminalShell()->terminalPid; // Whatever GUI program + if (pid == 0) return "Unable to find a GUI program"; + + FF_AUTO_CLOSE_FD HANDLE snapshot = NULL; + while(!(snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid)) && GetLastError() == ERROR_BAD_LENGTH) {} + + if(!snapshot) + return "CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid) failed"; + + if (ffInitCom()) + return "ffInitCom() failed"; + + MODULEENTRY32W module; + module.dwSize = sizeof(module); + for(BOOL success = Module32FirstW(snapshot, &module); success; success = Module32NextW(snapshot, &module)) + { + if(wcscmp(module.szModule, L"wbhelp64.dll") == 0 || wcscmp(module.szModule, L"wbhelp.dll") == 0) + { + IShellItem2* shellItem = NULL; + if (FAILED(SHCreateItemFromParsingName(module.szExePath, NULL, IID_IShellItem2, (void**) &shellItem))) + continue; + + on_scope_exit destroyShellItem([=] { shellItem->Release(); }); + + wchar_t* desc = NULL; + if (FAILED(shellItem->GetString(PKEY_FileDescription, &desc))) + continue; + + on_scope_exit destroyDesc([=] { CoTaskMemFree(desc); }); + + if (wcscmp(desc, L"WindowBlinds Helper DLL") == 0) + { + ffStrbufSetStatic(pluginName, "WindowBlinds"); + break; + } + } + } + return NULL; +} diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index 460eea4f4..0e2811c96 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -5,7 +5,7 @@ #include "modules/wm/wm.h" #include "util/stringUtils.h" -#define FF_WM_NUM_FORMAT_ARGS 3 +#define FF_WM_NUM_FORMAT_ARGS 4 void ffPrintWM(FFWMOptions* options) { @@ -48,7 +48,8 @@ void ffPrintWM(FFWMOptions* options) ffPrintFormat(FF_WM_MODULE_NAME, 0, &options->moduleArgs, FF_WM_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProcessName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmPrettyName}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName} + {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName}, + {FF_FORMAT_ARG_TYPE_STRBUF, &pluginName}, }); } } @@ -112,10 +113,16 @@ void ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc yyjson_mut_obj_add_str(doc, module, "error", "No WM found"); return; } + + FF_STRBUF_AUTO_DESTROY pluginName = ffStrbufCreate(); + if(options->detectPlugin) + ffDetectWMPlugin(&pluginName); + yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); yyjson_mut_obj_add_strbuf(doc, obj, "processName", &result->wmProcessName); yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->wmPrettyName); yyjson_mut_obj_add_strbuf(doc, obj, "protocolName", &result->wmProtocolName); + yyjson_mut_obj_add_strbuf(doc, obj, "pluginName", &pluginName); } void ffPrintWMHelpFormat(void) @@ -123,7 +130,8 @@ void ffPrintWMHelpFormat(void) ffPrintModuleFormatHelp(FF_WM_MODULE_NAME, "{2} ({3})", FF_WM_NUM_FORMAT_ARGS, (const char* []) { "WM process name", "WM pretty name", - "WM protocol name" + "WM protocol name", + "WM plugin name" }); } From ab51a209d790966a7b093adebb6dcea35d1b6bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 19:51:05 +0800 Subject: [PATCH 090/100] CI: try fixing FreeBSD build --- .github/workflows/ci.yml | 7 ++++--- CMakeLists.txt | 1 - src/detection/de/de_linux.c | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d8de61d5..85ba828ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -171,11 +171,12 @@ jobs: uses: actions/checkout@v4 - name: run VM - uses: vmactions/freebsd-vm@v0 + uses: cross-platform-actions/action@v0.21.0 with: - prepare: | - pkg install -y cmake git pkgconf binutils pciutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 glib dconf dbus sqlite3-tcl xfce4-conf ImageMagick6 ImageMagick7 chafa egl libosmesa opencl ocl-icd pulseaudio + operating_system: freebsd + version: '13.2' run: | + sudo pkg install -y cmake git pkgconf binutils pciutils wayland vulkan-headers vulkan-loader libxcb libXrandr libX11 glib dconf dbus sqlite3-tcl xfce4-conf ImageMagick6 ImageMagick7 chafa egl libosmesa opencl ocl-icd pulseaudio cmake -DSET_TWEAK=Off -DBUILD_TESTS=On . cmake --build . --target package ./fastfetch --list-features diff --git a/CMakeLists.txt b/CMakeLists.txt index fa203d130..10e56fc58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -534,7 +534,6 @@ elseif(BSD) src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_linux.c src/detection/wifi/wifi_bsd.c - src/detection/wmde/wmde_linux.c src/detection/wm/wm_nosupport.c src/detection/de/de_linux.c src/detection/wmtheme/wmtheme_linux.c diff --git a/src/detection/de/de_linux.c b/src/detection/de/de_linux.c index 3d75bcc41..067d80307 100644 --- a/src/detection/de/de_linux.c +++ b/src/detection/de/de_linux.c @@ -1,9 +1,11 @@ #include "de.h" +#include "common/io/io.h" #include "common/parsing.h" #include "common/properties.h" #include "common/processing.h" #include "detection/displayserver/displayserver.h" +#include "util/stringUtils.h" static void getKDE(FFstrbuf* result, FFDEOptions* options) { From 3b9b03a08640c908802b59f3c8e778110ca6762a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 31 Oct 2023 23:43:29 +0800 Subject: [PATCH 091/100] FreeBSD: fix build --- src/detection/de/de_linux.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/detection/de/de_linux.c b/src/detection/de/de_linux.c index 067d80307..6ff8cfc73 100644 --- a/src/detection/de/de_linux.c +++ b/src/detection/de/de_linux.c @@ -7,6 +7,8 @@ #include "detection/displayserver/displayserver.h" #include "util/stringUtils.h" +#include + static void getKDE(FFstrbuf* result, FFDEOptions* options) { ffParsePropFileValues("/usr/share/xsessions/plasmax11.desktop", 1, (FFpropquery[]) { From a2f576f3e5120287de257035f28c34a560f8dbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 00:07:23 +0800 Subject: [PATCH 092/100] GPU (WSL): support nvml too --- src/detection/gpu/gpu_linux.c | 2 +- src/detection/gpu/gpu_nvidia.c | 11 ++--------- src/detection/gpu/gpu_nvidia.h | 6 +++--- src/detection/gpu/gpu_windows.c | 2 +- src/detection/gpu/gpu_wsl.cpp | 16 +++++++++++++++- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 69d5ab070..e6056d744 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -251,7 +251,7 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* .temp = options->temp ? &gpu->temperature : NULL, .memory = options->useNvml ? &gpu->dedicated : NULL, .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, - }); + }, "libnvidia-ml.so"); if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; diff --git a/src/detection/gpu/gpu_nvidia.c b/src/detection/gpu/gpu_nvidia.c index 9ce4b2f8d..214f0b992 100644 --- a/src/detection/gpu/gpu_nvidia.c +++ b/src/detection/gpu/gpu_nvidia.c @@ -15,19 +15,12 @@ struct FFNvmlData { bool inited; } nvmlData; -const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result) +const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result, const char* soName) { if (!nvmlData.inited) { nvmlData.inited = true; - FF_LIBRARY_LOAD(libnvml, NULL, "dlopen nvml failed", -#ifdef _WIN32 - "nvml" -#else - "libnvidia-ml" -#endif - FF_LIBRARY_EXTENSION, -1 - ); + FF_LIBRARY_LOAD(libnvml, NULL, "dlopen nvml failed", soName , 1); FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlInit_v2) FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libnvml, nvmlShutdown) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetCount_v2) diff --git a/src/detection/gpu/gpu_nvidia.h b/src/detection/gpu/gpu_nvidia.h index b891595cf..bce84aa8d 100644 --- a/src/detection/gpu/gpu_nvidia.h +++ b/src/detection/gpu/gpu_nvidia.h @@ -3,11 +3,11 @@ #include "gpu.h" // Use pciBusId if not NULL; use pciDeviceId and pciSubSystemId otherwise -// pciBusId = "domain:bus:device.function" -// pciDeviceId = (deviceId << 16) | vendorId typedef struct FFGpuNvidiaCondition { + // "domain:bus:device.function" const char* pciBusId; + // (deviceId << 16) | vendorId uint32_t pciDeviceId; uint32_t pciSubSystemId; } FFGpuNvidiaCondition; @@ -20,4 +20,4 @@ typedef struct FFGpuNvidiaResult uint32_t* coreCount; } FFGpuNvidiaResult; -const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result); +const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result, const char* soName); diff --git a/src/detection/gpu/gpu_windows.c b/src/detection/gpu/gpu_windows.c index 106fdfc3f..8f1fac03a 100644 --- a/src/detection/gpu/gpu_windows.c +++ b/src/detection/gpu/gpu_windows.c @@ -99,7 +99,7 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* .temp = options->temp ? &gpu->temperature : NULL, .memory = options->useNvml ? &gpu->dedicated : NULL, .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, - }); + }, "nvml.dll"); } } } diff --git a/src/detection/gpu/gpu_wsl.cpp b/src/detection/gpu/gpu_wsl.cpp index fa77a4be0..a2a01fc14 100644 --- a/src/detection/gpu/gpu_wsl.cpp +++ b/src/detection/gpu/gpu_wsl.cpp @@ -4,6 +4,7 @@ extern "C" { #include "common/library.h" #include "detection/gpu/gpu.h" +#include "detection/gpu/gpu_nvidia.h" } #include @@ -92,7 +93,20 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF if (SUCCEEDED(adapter->GetProperty(DXCoreAdapterProperty::HardwareID, sizeof(hardwareId), &hardwareId))) { const char* vendorStr = ffGetGPUVendorString((unsigned) hardwareId.vendorID); - ffStrbufAppendS(&gpu->vendor, vendorStr); + ffStrbufSetStatic(&gpu->vendor, vendorStr); + + if (vendorStr == FF_GPU_VENDOR_NAME_NVIDIA && options->useNvml) + { + ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) { + .pciBusId = nullptr, + .pciDeviceId = (hardwareId.deviceID << 16) | hardwareId.vendorID, + .pciSubSystemId = hardwareId.subSysID + }, (FFGpuNvidiaResult) { + .temp = options->temp ? &gpu->temperature : NULL, + .memory = options->useNvml ? &gpu->dedicated : NULL, + .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, + }, "/usr/lib/wsl/lib/libnvidia-ml.so"); + } } } From 761c649817fcddcff77097cf500cd1131dfa66e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 08:55:00 +0800 Subject: [PATCH 093/100] TerminalShell: better support for environment running with `su` --- src/detection/terminalshell/terminalshell.c | 16 ++++++++++++++++ .../terminalshell/terminalshell_linux.c | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/detection/terminalshell/terminalshell.c b/src/detection/terminalshell/terminalshell.c index 60bff0490..c0444047d 100644 --- a/src/detection/terminalshell/terminalshell.c +++ b/src/detection/terminalshell/terminalshell.c @@ -455,6 +455,22 @@ bool fftsGetTerminalVersion(FFstrbuf* processName, FF_MAYBE_UNUSED FFstrbuf* exe } } + termProgramVersion = getenv("LC_TERMINAL_VERSION"); + if(termProgramVersion) + { + const char* termProgram = getenv("LC_TERMINAL"); + if(termProgram) + { + if(ffStrbufStartsWithIgnCaseS(processName, termProgram) || // processName ends with `.exe` on Windows + (ffStrEquals(termProgram, "vscode") && ffStrbufStartsWithIgnCaseS(processName, "code")) || + (ffStrStartsWith(termProgram, "iTerm") && ffStrbufStartsWithIgnCaseS(processName, "iTermServer-")) + ) { + ffStrbufSetS(version, termProgramVersion); + return true; + } + } + } + #ifdef _WIN32 return getFileVersion(exe->chars, version); diff --git a/src/detection/terminalshell/terminalshell_linux.c b/src/detection/terminalshell/terminalshell_linux.c index 4d44746ac..460f99fc4 100644 --- a/src/detection/terminalshell/terminalshell_linux.c +++ b/src/detection/terminalshell/terminalshell_linux.c @@ -139,6 +139,7 @@ static void getTerminalShell(FFTerminalShellResult* result, pid_t pid) strcasecmp(name, "sshd") == 0 || strcasecmp(name, "gdb") == 0 || strcasecmp(name, "lldb") == 0 || + strcasecmp(name, "login") == 0 || strcasecmp(name, "guake-wrapped") == 0 || strcasestr(name, "debug") != NULL || strcasestr(name, "command-not-found") != NULL || @@ -251,6 +252,9 @@ static void getTerminalFromEnv(FFTerminalShellResult* result) if(!ffStrSet(term)) term = getenv("TERM_PROGRAM"); + if(!ffStrSet(term)) + term = getenv("LC_TERMINAL"); + //Normal Terminal if(!ffStrSet(term)) term = getenv("TERM"); From 494cc1493e708a87ee122f712b58c7b860118693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 09:39:24 +0800 Subject: [PATCH 094/100] TerminalFont (Linux): support xfce4-terminal 1.1.0+ Fixes #602 --- CHANGELOG.md | 1 + .../terminalfont/terminalfont_linux.c | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07fbc962a..84ce4d940 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Features: * Support urxvt version detection (Terminal, Linux) * Support st version detection (Terminal, Linux) * Support st terminal font detection (TerminalFont, Linux) +* Support xfce4-terminal 1.1.0+ terminal font detection (TerminalFont, Linux) * Add option `--migrate-config ` * Support Nvidia GPU temp and cuda core count detection via nvml. Use `--gpu-use-nvml` to enable it (GPU) * Try supporting Wifi authentication type detection in macOS Sonoma. Please file a feature request if you get `to be supported (num)` with result of `/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep auth` (Wifi, macOS) diff --git a/src/detection/terminalfont/terminalfont_linux.c b/src/detection/terminalfont/terminalfont_linux.c index 71299af6a..36004ad1f 100644 --- a/src/detection/terminalfont/terminalfont_linux.c +++ b/src/detection/terminalfont/terminalfont_linux.c @@ -125,15 +125,33 @@ static void detectXFCETerminal(FFTerminalFontResult* terminalFont) FF_STRBUF_AUTO_DESTROY useSysFont = ffStrbufCreate(); FF_STRBUF_AUTO_DESTROY fontName = ffStrbufCreate(); - ffParsePropFileConfigValues("xfce4/terminal/terminalrc", 2, (FFpropquery[]) { - {"FontUseSystem = ", &useSysFont}, - {"FontName = ", &fontName} + const char* path = "xfce4/xfconf/xfce-perchannel-xml/xfce4-terminal.xml"; + bool configFound = ffParsePropFileConfigValues(path, 2, (FFpropquery[]) { + {"error, "Couldn't find FontName in .config/xfce4/terminal/terminalrc"); + ffStrbufAppendF(&terminalFont->error, "Couldn't find FontName in %s", path); else ffFontInitPango(&terminalFont->font, fontName.chars); } From d0a8d3cdc49da9f4f6ada159b90ebf3deb1f351a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 09:42:52 +0800 Subject: [PATCH 095/100] TerminalFont (Linux): early return --- src/detection/terminalfont/terminalfont_linux.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/detection/terminalfont/terminalfont_linux.c b/src/detection/terminalfont/terminalfont_linux.c index 36004ad1f..e1d51a2f4 100644 --- a/src/detection/terminalfont/terminalfont_linux.c +++ b/src/detection/terminalfont/terminalfont_linux.c @@ -146,7 +146,10 @@ static void detectXFCETerminal(FFTerminalFontResult* terminalFont) } if (!configFound) + { ffStrbufSetStatic(&terminalFont->error, "Couldn't find xfce4/xfconf/xfce-perchannel-xml/xfce4-terminal.xml or xfce4/terminal/terminalrc"); + return; + } if(useSysFont.length == 0 || ffStrbufIgnCaseCompS(&useSysFont, "false") == 0) { From 6508ccfc0d5ebe572c48ab2e5dec020a6c61c4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 09:52:15 +0800 Subject: [PATCH 096/100] FreeBSD: debug --- src/detection/gpu/gpu_linux.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index e6056d744..09116338f 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -204,11 +204,15 @@ FF_MAYBE_UNUSED static void pciDetectType(FFGPUResult* gpu) static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* results, PCIData* pci, struct pci_dev* device) { + puts("10"); pci->ffpci_fill_info(device, PCI_FILL_CLASS); + puts("11"); + char class[1024]; pci->ffpci_lookup_name(pci->access, class, sizeof(class) - 1, PCI_LOOKUP_CLASS, device->device_class); + puts("12"); if( //https://pci-ids.ucw.cz/read/PD/03 strcasecmp("VGA compatible controller", class) != 0 && @@ -217,19 +221,25 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* strcasecmp("Display controller", class) != 0 ) return; + puts("13"); pci->ffpci_fill_info(device, PCI_FILL_IDENT); FFGPUResult* gpu = ffListAdd(results); + puts("14"); ffStrbufInit(&gpu->vendor); pciDetectVendorName(gpu, pci, device); + puts("15"); ffStrbufInit(&gpu->name); pciDetectDeviceName(gpu, pci, device); + puts("16"); ffStrbufInit(&gpu->driver); pciDetectDriverName(gpu, pci, device); + puts("17"); + #if FF_USE_PCI_MEMORY // Libpci reports at least 2 false results (#495, #497) pciDetectMemory(gpu, pci, device); @@ -238,12 +248,14 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->dedicated.used = gpu->shared.used = gpu->dedicated.total = gpu->shared.total = FF_GPU_VMEM_SIZE_UNSET; gpu->type = FF_GPU_TYPE_UNKNOWN; #endif + puts("18"); gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; gpu->temperature = FF_GPU_TEMP_UNSET; if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->useNvml)) { + puts("19"); char pciDeviceId[32]; snprintf(pciDeviceId, sizeof(pciDeviceId) - 1, "%04x:%02x:%02x.%d", device->domain, device->bus, device->dev, device->func); @@ -253,14 +265,17 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, }, "libnvidia-ml.so"); + puts("20"); if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; } + puts("21"); #ifdef __linux__ if(options->temp && gpu->temperature != gpu->temperature) pciDetectTemp(gpu, device); #endif + puts("22"); } jmp_buf pciInitJmpBuf; @@ -306,6 +321,8 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libpci, pci, pci_get_string_property); #endif + puts("1"); + pci.access = ffpci_alloc(); pci.access->warning = handlePciWarning; pci.access->error = handlePciInitError; @@ -315,8 +332,13 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus) return "pcilib: Cannot find any working access method."; pci.access->error = handlePciGenericError; // set back to generic error so we don't mess up error handling in other places + + puts("2"); + ffpci_scan_bus(pci.access); + puts("3"); + struct pci_dev* device = pci.access->devices; while(device != NULL) { @@ -324,6 +346,8 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus) device = device->next; } + puts("done"); + ffpci_cleanup(pci.access); return NULL; } From 4bf9f524d9a6b59bd680129229160aadd28a3cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 11:16:16 +0800 Subject: [PATCH 097/100] Logo (Builtin): add Interix --- CHANGELOG.md | 1 + src/logo/ascii/interix.txt | 17 +++++++++++++++++ src/logo/builtin.c | 12 ++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/logo/ascii/interix.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 84ce4d940..bffd8619e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ Logos: * Add cycledream * Add Evolinx * Add azos +* Add Interix # 2.1.2 diff --git a/src/logo/ascii/interix.txt b/src/logo/ascii/interix.txt new file mode 100644 index 000000000..df036b85f --- /dev/null +++ b/src/logo/ascii/interix.txt @@ -0,0 +1,17 @@ + .${c3}. +${c1} 75${c3}G! +${c1} ^?PG${c3}&&J. +${c1} :!5GPP${c3}&&&B! +${c1} :YPPPPP${c3}&&&&&Y: +${c1} !5PPPPPP${c3}&&&&&&B! +${c1} :?PPPPPPPP${c3}&&&&&&&&Y~ +${c1} !5PPPPPPPPP${c3}###&&&&&&B7 +${c1} :?PPPP5555555${c3}B####&&&&&&5: +${c1} ~5PPPP555YJ${c5}7!~7?${c3}5B###&&&&&B?. +${c1} .:JPPPP5555Y${c5}?^....:^?${c3}G####&&&&&5: +${c1} 75PPP555555Y${c5}7:....:^!${c3}5#####&&&&&B7. +${c1} :JPPPP${c2}555555YY?${c5}~::::^~${c2}7YPGBB###${c3}&&&&&5^ +${c1}75${c2}GGPPPPPP555555YJ?77??YYYYYY55PPGGB#${c3}&B? +${c2}~!!7JY5PGGBBBBBBBBGGGGGGGBGGGGGP5YJ?7~~~ + .::^~7?JYPGBB#BGPYJ?7!7^:. + ..:^... diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 8204c3cf3..d9252f561 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -1867,6 +1867,18 @@ static const FFlogo I[] = { .colorKeys = FF_COLOR_FG_BLUE, .colorTitle = FF_COLOR_FG_CYAN, }, + // Interix + { + .names = {"Interix"}, + .lines = FASTFETCH_DATATEXT_LOGO_INTERIX, + .colors = { + FF_COLOR_FG_RED, + FF_COLOR_FG_WHITE, + FF_COLOR_FG_BLUE, + FF_COLOR_FG_BLACK, + FF_COLOR_FG_YELLOW, + }, + }, // IRIX { .names = {"IRIX"}, From 7bc4c63eb413488ce3d565ea9cb8decfa7e104a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 11:28:08 +0800 Subject: [PATCH 098/100] Migration: don't overwrite existing files --- README.md | 3 ++- src/fastfetch.c | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f387b60e..a5e243cd9 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,8 @@ See Wiki: https://github.com/fastfetch-cli/fastfetch/wiki/Building * Run it with default configuration: `fastfetch` * Run it with [all supported modules](https://github.com/fastfetch-cli/fastfetch/wiki/Support+Status#available-modules) and find what you interest: `fastfetch -c all.jsonc` * Find all data that fastfetch detects: `fastfetch -s --format json` -* Get help messages: `fastfetch --help` +* Display help messages: `fastfetch --help` +* Generate config file based on command line arguments: `fastfetch --arg1 --arg2 --mirgrate-config` ## Customization diff --git a/src/fastfetch.c b/src/fastfetch.c index c815b5569..61237ff60 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -481,7 +481,7 @@ static void parseOption(FFdata* data, const char* key, const char* value) { if (instance.state.configDoc) { - fputs("Error: existing jsonc config file detected. Aborting\n", stderr); + fputs("Error: existing jsonc config detected. Aborting\n", stderr); exit(477); } @@ -492,6 +492,12 @@ static void parseOption(FFdata* data, const char* key, const char* value) } else ffStrbufSetS(&instance.state.migrateConfigPath, value); + + if (ffPathExists(instance.state.migrateConfigPath.chars, FF_PATHTYPE_ANY)) + { + fprintf(stderr, "Error: file `%s` exists. Aborting\n", instance.state.migrateConfigPath.chars); + exit(477); + } } else if(ffStrEqualsIgnCase(key, "--load-user-config")) data->loadUserConfig = ffOptionParseBoolean(value); From f59be1faf22b657d4cba75e5cf12064a7223cb1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 11:29:03 +0800 Subject: [PATCH 099/100] Release v2.2.0 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10e56fc58..d7b68d58c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url project(fastfetch - VERSION 2.1.2 + VERSION 2.2.0 LANGUAGES C DESCRIPTION "Fast system information tool" HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch" From 11d7eec4db4febfc917443ac1115448ba5bedc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Nov 2023 12:22:28 +0800 Subject: [PATCH 100/100] Revert "FreeBSD: debug" This reverts commit 6508ccfc0d5ebe572c48ab2e5dec020a6c61c4c5. --- src/detection/gpu/gpu_linux.c | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/detection/gpu/gpu_linux.c b/src/detection/gpu/gpu_linux.c index 09116338f..e6056d744 100644 --- a/src/detection/gpu/gpu_linux.c +++ b/src/detection/gpu/gpu_linux.c @@ -204,15 +204,11 @@ FF_MAYBE_UNUSED static void pciDetectType(FFGPUResult* gpu) static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* results, PCIData* pci, struct pci_dev* device) { - puts("10"); pci->ffpci_fill_info(device, PCI_FILL_CLASS); - puts("11"); - char class[1024]; pci->ffpci_lookup_name(pci->access, class, sizeof(class) - 1, PCI_LOOKUP_CLASS, device->device_class); - puts("12"); if( //https://pci-ids.ucw.cz/read/PD/03 strcasecmp("VGA compatible controller", class) != 0 && @@ -221,25 +217,19 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* strcasecmp("Display controller", class) != 0 ) return; - puts("13"); pci->ffpci_fill_info(device, PCI_FILL_IDENT); FFGPUResult* gpu = ffListAdd(results); - puts("14"); ffStrbufInit(&gpu->vendor); pciDetectVendorName(gpu, pci, device); - puts("15"); ffStrbufInit(&gpu->name); pciDetectDeviceName(gpu, pci, device); - puts("16"); ffStrbufInit(&gpu->driver); pciDetectDriverName(gpu, pci, device); - puts("17"); - #if FF_USE_PCI_MEMORY // Libpci reports at least 2 false results (#495, #497) pciDetectMemory(gpu, pci, device); @@ -248,14 +238,12 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpu->dedicated.used = gpu->shared.used = gpu->dedicated.total = gpu->shared.total = FF_GPU_VMEM_SIZE_UNSET; gpu->type = FF_GPU_TYPE_UNKNOWN; #endif - puts("18"); gpu->coreCount = FF_GPU_CORE_COUNT_UNSET; gpu->temperature = FF_GPU_TEMP_UNSET; if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->useNvml)) { - puts("19"); char pciDeviceId[32]; snprintf(pciDeviceId, sizeof(pciDeviceId) - 1, "%04x:%02x:%02x.%d", device->domain, device->bus, device->dev, device->func); @@ -265,17 +253,14 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* .coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL, }, "libnvidia-ml.so"); - puts("20"); if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET) gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED; } - puts("21"); #ifdef __linux__ if(options->temp && gpu->temperature != gpu->temperature) pciDetectTemp(gpu, device); #endif - puts("22"); } jmp_buf pciInitJmpBuf; @@ -321,8 +306,6 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libpci, pci, pci_get_string_property); #endif - puts("1"); - pci.access = ffpci_alloc(); pci.access->warning = handlePciWarning; pci.access->error = handlePciInitError; @@ -332,13 +315,8 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus) return "pcilib: Cannot find any working access method."; pci.access->error = handlePciGenericError; // set back to generic error so we don't mess up error handling in other places - - puts("2"); - ffpci_scan_bus(pci.access); - puts("3"); - struct pci_dev* device = pci.access->devices; while(device != NULL) { @@ -346,8 +324,6 @@ static const char* pciDetectGPUs(const FFGPUOptions* options, FFlist* gpus) device = device->next; } - puts("done"); - ffpci_cleanup(pci.access); return NULL; }