2023-06-09 10:08:04 +08:00
|
|
|
#include "common/printing.h"
|
2023-06-10 15:01:54 +08:00
|
|
|
#include "common/jsonconfig.h"
|
2023-06-09 10:08:04 +08:00
|
|
|
#include "detection/chassis/chassis.h"
|
|
|
|
|
#include "modules/chassis/chassis.h"
|
|
|
|
|
|
|
|
|
|
#define FF_CHASSIS_NUM_FORMAT_ARGS 3
|
|
|
|
|
|
|
|
|
|
void ffPrintChassis(FFinstance* instance, FFChassisOptions* options)
|
|
|
|
|
{
|
|
|
|
|
FFChassisResult result;
|
2023-06-16 16:33:43 +08:00
|
|
|
ffStrbufInit(&result.chassisType);
|
|
|
|
|
ffStrbufInit(&result.chassisVendor);
|
|
|
|
|
ffStrbufInit(&result.chassisVersion);
|
2023-06-09 10:08:04 +08:00
|
|
|
|
2023-06-16 16:33:43 +08:00
|
|
|
const char* error = ffDetectChassis(&result);
|
|
|
|
|
|
|
|
|
|
if(error)
|
2023-06-09 10:08:04 +08:00
|
|
|
{
|
2023-06-16 16:33:43 +08:00
|
|
|
ffPrintError(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "%s", error);
|
2023-06-09 10:08:04 +08:00
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(result.chassisType.length == 0)
|
|
|
|
|
{
|
|
|
|
|
ffPrintError(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "chassis_type is not set by O.E.M.");
|
2023-06-16 16:33:43 +08:00
|
|
|
goto exit;
|
2023-06-09 10:08:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(options->moduleArgs.outputFormat.length == 0)
|
|
|
|
|
{
|
|
|
|
|
ffPrintLogoAndKey(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs.key);
|
|
|
|
|
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY output = ffStrbufCreateCopy(&result.chassisType);
|
|
|
|
|
|
|
|
|
|
if(result.chassisVersion.length > 0)
|
|
|
|
|
ffStrbufAppendF(&output, " (%s)", result.chassisVersion.chars);
|
|
|
|
|
|
|
|
|
|
ffStrbufPutTo(&output, stdout);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ffPrintFormat(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, FF_CHASSIS_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result.chassisType},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result.chassisVendor},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, &result.chassisVersion},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exit:
|
|
|
|
|
ffStrbufDestroy(&result.chassisType);
|
|
|
|
|
ffStrbufDestroy(&result.chassisVendor);
|
|
|
|
|
ffStrbufDestroy(&result.chassisVersion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffInitChassisOptions(FFChassisOptions* options)
|
|
|
|
|
{
|
|
|
|
|
options->moduleName = FF_CHASSIS_MODULE_NAME;
|
|
|
|
|
ffOptionInitModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, const char* value)
|
|
|
|
|
{
|
|
|
|
|
const char* subKey = ffOptionTestPrefix(key, FF_CHASSIS_MODULE_NAME);
|
|
|
|
|
if (!subKey) return false;
|
|
|
|
|
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ffDestroyChassisOptions(FFChassisOptions* options)
|
|
|
|
|
{
|
|
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-10 15:01:54 +08:00
|
|
|
void ffParseChassisJsonObject(FFinstance* instance, yyjson_val* module)
|
2023-06-09 10:08:04 +08:00
|
|
|
{
|
|
|
|
|
FFChassisOptions __attribute__((__cleanup__(ffDestroyChassisOptions))) options;
|
|
|
|
|
ffInitChassisOptions(&options);
|
|
|
|
|
|
|
|
|
|
if (module)
|
|
|
|
|
{
|
2023-06-10 15:01:54 +08:00
|
|
|
yyjson_val *key_, *val;
|
|
|
|
|
size_t idx, max;
|
|
|
|
|
yyjson_obj_foreach(module, idx, max, key_, val)
|
2023-06-09 10:08:04 +08:00
|
|
|
{
|
2023-06-10 15:01:54 +08:00
|
|
|
const char* key = yyjson_get_str(key_);
|
|
|
|
|
if(strcasecmp(key, "type") == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-06-09 10:08:04 +08:00
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ffPrintError(instance, FF_CHASSIS_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffPrintChassis(instance, &options);
|
|
|
|
|
}
|