2023-03-10 14:14:32 +08:00
|
|
|
#include "common/printing.h"
|
2023-06-10 15:01:54 +08:00
|
|
|
#include "common/jsonconfig.h"
|
2023-03-10 14:14:32 +08:00
|
|
|
#include "modules/kernel/kernel.h"
|
2023-06-19 15:21:49 +08:00
|
|
|
#include "util/stringUtils.h"
|
2023-03-10 14:14:32 +08:00
|
|
|
|
|
|
|
|
#define FF_KERNEL_NUM_FORMAT_ARGS 4
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffPrintKernel(FFKernelOptions* options)
|
2023-03-10 14:14:32 +08:00
|
|
|
{
|
2023-09-23 11:51:37 +08:00
|
|
|
const FFPlatform* platform = &instance.state.platform;
|
2023-03-10 14:14:32 +08:00
|
|
|
if(options->moduleArgs.outputFormat.length == 0)
|
|
|
|
|
{
|
2023-08-15 21:40:22 +08:00
|
|
|
ffPrintLogoAndKey(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
2023-09-23 11:51:37 +08:00
|
|
|
ffStrbufWriteTo(&platform->systemRelease, stdout);
|
2023-03-10 14:14:32 +08:00
|
|
|
|
2023-09-23 11:51:37 +08:00
|
|
|
if(platform->systemDisplayVersion.length > 0)
|
|
|
|
|
printf(" (%s)\n", platform->systemDisplayVersion.chars);
|
|
|
|
|
else
|
|
|
|
|
putchar('\n');
|
2023-03-10 14:14:32 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
ffPrintFormat(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_KERNEL_NUM_FORMAT_ARGS, (FFformatarg[]){
|
2023-09-23 11:51:37 +08:00
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemName},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemRelease},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemVersion},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemArchitecture},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &platform->systemDisplayVersion}
|
2023-03-10 14:14:32 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffInitKernelOptions(FFKernelOptions* options)
|
|
|
|
|
{
|
2023-09-05 16:09:46 +08:00
|
|
|
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_KERNEL_MODULE_NAME, ffParseKernelCommandOptions, ffParseKernelJsonObject, ffPrintKernel, ffGenerateKernelJson);
|
2023-03-10 14:14:32 +08:00
|
|
|
ffOptionInitModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ffParseKernelCommandOptions(FFKernelOptions* options, const char* key, const char* value)
|
|
|
|
|
{
|
|
|
|
|
const char* subKey = ffOptionTestPrefix(key, FF_KERNEL_MODULE_NAME);
|
|
|
|
|
if (!subKey) return false;
|
|
|
|
|
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffDestroyKernelOptions(FFKernelOptions* options)
|
|
|
|
|
{
|
|
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 10:56:54 +08:00
|
|
|
void ffParseKernelJsonObject(FFKernelOptions* options, yyjson_val* module)
|
2023-03-10 14:14:32 +08:00
|
|
|
{
|
2023-08-17 16:09:41 +08:00
|
|
|
yyjson_val *key_, *val;
|
|
|
|
|
size_t idx, max;
|
|
|
|
|
yyjson_obj_foreach(module, idx, max, key_, val)
|
2023-03-10 14:14:32 +08:00
|
|
|
{
|
2023-08-17 16:09:41 +08:00
|
|
|
const char* key = yyjson_get_str(key_);
|
|
|
|
|
if(ffStrEqualsIgnCase(key, "type"))
|
|
|
|
|
continue;
|
2023-06-10 15:01:54 +08:00
|
|
|
|
2023-08-17 16:09:41 +08:00
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
|
|
|
|
|
continue;
|
2023-03-10 14:14:32 +08:00
|
|
|
|
2023-08-17 16:09:41 +08:00
|
|
|
ffPrintError(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
2023-03-10 14:14:32 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-05 16:09:46 +08:00
|
|
|
|
|
|
|
|
void ffGenerateKernelJson(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);
|
|
|
|
|
yyjson_mut_obj_add_strbuf(doc, obj, "name", &instance.state.platform.systemName);
|
|
|
|
|
yyjson_mut_obj_add_strbuf(doc, obj, "release", &instance.state.platform.systemRelease);
|
|
|
|
|
yyjson_mut_obj_add_strbuf(doc, obj, "version", &instance.state.platform.systemVersion);
|
2023-09-23 11:51:37 +08:00
|
|
|
yyjson_mut_obj_add_strbuf(doc, obj, "displayVersion", &instance.state.platform.systemDisplayVersion);
|
2023-09-05 16:09:46 +08:00
|
|
|
}
|