2021-09-14 21:52:06 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_runtime_class.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_runtime_class_t *v1_runtime_class_create_internal(
|
2021-09-14 21:52:06 +08:00
|
|
|
char *api_version,
|
|
|
|
|
char *handler,
|
|
|
|
|
char *kind,
|
|
|
|
|
v1_object_meta_t *metadata,
|
|
|
|
|
v1_overhead_t *overhead,
|
|
|
|
|
v1_scheduling_t *scheduling
|
|
|
|
|
) {
|
|
|
|
|
v1_runtime_class_t *v1_runtime_class_local_var = malloc(sizeof(v1_runtime_class_t));
|
|
|
|
|
if (!v1_runtime_class_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_runtime_class_local_var->api_version = api_version;
|
|
|
|
|
v1_runtime_class_local_var->handler = handler;
|
|
|
|
|
v1_runtime_class_local_var->kind = kind;
|
|
|
|
|
v1_runtime_class_local_var->metadata = metadata;
|
|
|
|
|
v1_runtime_class_local_var->overhead = overhead;
|
|
|
|
|
v1_runtime_class_local_var->scheduling = scheduling;
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_runtime_class_local_var->_library_owned = 1;
|
2021-09-14 21:52:06 +08:00
|
|
|
return v1_runtime_class_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_runtime_class_t *v1_runtime_class_create(
|
|
|
|
|
char *api_version,
|
|
|
|
|
char *handler,
|
|
|
|
|
char *kind,
|
|
|
|
|
v1_object_meta_t *metadata,
|
|
|
|
|
v1_overhead_t *overhead,
|
|
|
|
|
v1_scheduling_t *scheduling
|
|
|
|
|
) {
|
|
|
|
|
return v1_runtime_class_create_internal (
|
|
|
|
|
api_version,
|
|
|
|
|
handler,
|
|
|
|
|
kind,
|
|
|
|
|
metadata,
|
|
|
|
|
overhead,
|
|
|
|
|
scheduling
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
void v1_runtime_class_free(v1_runtime_class_t *v1_runtime_class) {
|
|
|
|
|
if(NULL == v1_runtime_class){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_runtime_class->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_runtime_class_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
listEntry_t *listEntry;
|
|
|
|
|
if (v1_runtime_class->api_version) {
|
|
|
|
|
free(v1_runtime_class->api_version);
|
|
|
|
|
v1_runtime_class->api_version = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_runtime_class->handler) {
|
|
|
|
|
free(v1_runtime_class->handler);
|
|
|
|
|
v1_runtime_class->handler = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_runtime_class->kind) {
|
|
|
|
|
free(v1_runtime_class->kind);
|
|
|
|
|
v1_runtime_class->kind = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_runtime_class->metadata) {
|
|
|
|
|
v1_object_meta_free(v1_runtime_class->metadata);
|
|
|
|
|
v1_runtime_class->metadata = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_runtime_class->overhead) {
|
|
|
|
|
v1_overhead_free(v1_runtime_class->overhead);
|
|
|
|
|
v1_runtime_class->overhead = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_runtime_class->scheduling) {
|
|
|
|
|
v1_scheduling_free(v1_runtime_class->scheduling);
|
|
|
|
|
v1_runtime_class->scheduling = NULL;
|
|
|
|
|
}
|
|
|
|
|
free(v1_runtime_class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_runtime_class_convertToJSON(v1_runtime_class_t *v1_runtime_class) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->api_version
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_runtime_class->api_version) {
|
2021-09-14 21:52:06 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "apiVersion", v1_runtime_class->api_version) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->handler
|
|
|
|
|
if (!v1_runtime_class->handler) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
if(cJSON_AddStringToObject(item, "handler", v1_runtime_class->handler) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->kind
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_runtime_class->kind) {
|
2021-09-14 21:52:06 +08:00
|
|
|
if(cJSON_AddStringToObject(item, "kind", v1_runtime_class->kind) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->metadata
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_runtime_class->metadata) {
|
2021-09-14 21:52:06 +08:00
|
|
|
cJSON *metadata_local_JSON = v1_object_meta_convertToJSON(v1_runtime_class->metadata);
|
|
|
|
|
if(metadata_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "metadata", metadata_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->overhead
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_runtime_class->overhead) {
|
2021-09-14 21:52:06 +08:00
|
|
|
cJSON *overhead_local_JSON = v1_overhead_convertToJSON(v1_runtime_class->overhead);
|
|
|
|
|
if(overhead_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "overhead", overhead_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->scheduling
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_runtime_class->scheduling) {
|
2021-09-14 21:52:06 +08:00
|
|
|
cJSON *scheduling_local_JSON = v1_scheduling_convertToJSON(v1_runtime_class->scheduling);
|
|
|
|
|
if(scheduling_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "scheduling", scheduling_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_runtime_class_t *v1_runtime_class_parseFromJSON(cJSON *v1_runtime_classJSON){
|
|
|
|
|
|
|
|
|
|
v1_runtime_class_t *v1_runtime_class_local_var = NULL;
|
|
|
|
|
|
2021-11-05 14:13:35 +08:00
|
|
|
// define the local variable for v1_runtime_class->metadata
|
|
|
|
|
v1_object_meta_t *metadata_local_nonprim = NULL;
|
|
|
|
|
|
|
|
|
|
// define the local variable for v1_runtime_class->overhead
|
|
|
|
|
v1_overhead_t *overhead_local_nonprim = NULL;
|
|
|
|
|
|
|
|
|
|
// define the local variable for v1_runtime_class->scheduling
|
|
|
|
|
v1_scheduling_t *scheduling_local_nonprim = NULL;
|
|
|
|
|
|
2021-09-14 21:52:06 +08:00
|
|
|
// v1_runtime_class->api_version
|
|
|
|
|
cJSON *api_version = cJSON_GetObjectItemCaseSensitive(v1_runtime_classJSON, "apiVersion");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(api_version)) {
|
|
|
|
|
api_version = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
if (api_version) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(api_version) && !cJSON_IsNull(api_version))
|
2021-09-14 21:52:06 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->handler
|
|
|
|
|
cJSON *handler = cJSON_GetObjectItemCaseSensitive(v1_runtime_classJSON, "handler");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(handler)) {
|
|
|
|
|
handler = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
if (!handler) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!cJSON_IsString(handler))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->kind
|
|
|
|
|
cJSON *kind = cJSON_GetObjectItemCaseSensitive(v1_runtime_classJSON, "kind");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(kind)) {
|
|
|
|
|
kind = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
if (kind) {
|
2022-12-29 10:58:47 +08:00
|
|
|
if(!cJSON_IsString(kind) && !cJSON_IsNull(kind))
|
2021-09-14 21:52:06 +08:00
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->metadata
|
|
|
|
|
cJSON *metadata = cJSON_GetObjectItemCaseSensitive(v1_runtime_classJSON, "metadata");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(metadata)) {
|
|
|
|
|
metadata = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
if (metadata) {
|
|
|
|
|
metadata_local_nonprim = v1_object_meta_parseFromJSON(metadata); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->overhead
|
|
|
|
|
cJSON *overhead = cJSON_GetObjectItemCaseSensitive(v1_runtime_classJSON, "overhead");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(overhead)) {
|
|
|
|
|
overhead = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
if (overhead) {
|
|
|
|
|
overhead_local_nonprim = v1_overhead_parseFromJSON(overhead); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_runtime_class->scheduling
|
|
|
|
|
cJSON *scheduling = cJSON_GetObjectItemCaseSensitive(v1_runtime_classJSON, "scheduling");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(scheduling)) {
|
|
|
|
|
scheduling = NULL;
|
|
|
|
|
}
|
2021-09-14 21:52:06 +08:00
|
|
|
if (scheduling) {
|
|
|
|
|
scheduling_local_nonprim = v1_scheduling_parseFromJSON(scheduling); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_runtime_class_local_var = v1_runtime_class_create_internal (
|
2022-12-29 10:58:47 +08:00
|
|
|
api_version && !cJSON_IsNull(api_version) ? strdup(api_version->valuestring) : NULL,
|
2021-09-14 21:52:06 +08:00
|
|
|
strdup(handler->valuestring),
|
2022-12-29 10:58:47 +08:00
|
|
|
kind && !cJSON_IsNull(kind) ? strdup(kind->valuestring) : NULL,
|
2021-09-14 21:52:06 +08:00
|
|
|
metadata ? metadata_local_nonprim : NULL,
|
|
|
|
|
overhead ? overhead_local_nonprim : NULL,
|
|
|
|
|
scheduling ? scheduling_local_nonprim : NULL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_runtime_class_local_var;
|
|
|
|
|
end:
|
|
|
|
|
if (metadata_local_nonprim) {
|
|
|
|
|
v1_object_meta_free(metadata_local_nonprim);
|
|
|
|
|
metadata_local_nonprim = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (overhead_local_nonprim) {
|
|
|
|
|
v1_overhead_free(overhead_local_nonprim);
|
|
|
|
|
overhead_local_nonprim = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (scheduling_local_nonprim) {
|
|
|
|
|
v1_scheduling_free(scheduling_local_nonprim);
|
|
|
|
|
scheduling_local_nonprim = NULL;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|