Loading...
Searching...
No Matches
time_period.c
Go to the documentation of this file.
#include "plugins_types.h"
#include <stdlib.h>
#include <string.h>
#include "libyang.h"
#include "compat.h"
#include "ly_common.h"
#include "plugins_internal.h" /* LY_TYPE_*_STR */
static int
lyplg_type_sort_time_period(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
{
const char *value1, *value2;
char unit1, unit2;
long v1, v2;
value1 = lyd_value_get_canonical(ctx, val1);
value2 = lyd_value_get_canonical(ctx, val2);
/* get the units (last character) and the values (all characters except the last one) */
unit1 = value1[strlen(value1) - 1];
unit2 = value2[strlen(value2) - 1];
v1 = strtol(value1, NULL, 10);
v2 = strtol(value2, NULL, 10);
/* descending order */
if (unit1 == unit2) {
if (v1 > v2) {
return -1;
} else if (v1 == v2) {
return 0;
} else {
return 1;
}
} else if (unit1 == 'm') {
return -1;
} else if ((unit1 == 'w') && (unit2 != 'm')) {
return -1;
} else if ((unit1 == 'd') && (unit2 == 'h')) {
return -1;
} else {
return 1;
}
}
const struct lyplg_type_record plugins_time_period[] = {
{
.module = "libnetconf2-netconf-server",
.revision = "2024-07-09",
.name = "time-period",
.plugin.id = "libyang 2 - time-period, version 1",
.plugin.store = lyplg_type_store_string,
.plugin.validate = NULL,
.plugin.compare = lyplg_type_compare_simple,
.plugin.sort = lyplg_type_sort_time_period,
.plugin.print = lyplg_type_print_simple,
.plugin.duplicate = lyplg_type_dup_simple,
.plugin.free = lyplg_type_free_simple,
.plugin.lyb_data_len = -1,
},
{0}
};
ly_ctx
libyang context handler.
lyplg_type_record::revision
const char *const char * revision
Definition plugins_types.h:638
lyplg_type_record
Definition plugins_types.h:635
lyplg_type_print_simple
LIBYANG_API_DECL const void * lyplg_type_print_simple(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format, void *prefix_data, ly_bool *dynamic, size_t *value_len)
Implementation of lyplg_type_print_clb for a generic simple type.
lyplg_type_dup_simple
LIBYANG_API_DECL LY_ERR lyplg_type_dup_simple(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
Implementation of lyplg_type_dup_clb for a generic simple type.
lyplg_type_free_simple
LIBYANG_API_DECL void lyplg_type_free_simple(const struct ly_ctx *ctx, struct lyd_value *value)
Implementation of lyplg_type_free_clb for a generic simple type.
lyplg_type_compare_simple
LIBYANG_API_DECL LY_ERR lyplg_type_compare_simple(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for a generic simple type.
lyplg_type_store_string
LIBYANG_API_DECL LY_ERR lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len, uint32_t options, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node, struct lyd_value *storage, struct lys_glob_unres *unres, struct ly_err_item **err)
Implementation of lyplg_type_store_clb for the built-in string type.
libyang.h
The main libyang public header.
plugins_types.h
API for (user) types plugins.
plugins_time_period
const struct lyplg_type_record plugins_time_period[]
Plugin information for time-period type implementation.
Definition time_period.c:83
lyd_value_get_canonical
LIBYANG_API_DECL const char * lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value)
Get the (canonical) value of a lyd_value.
lyd_value
YANG data representation.
Definition tree_data.h:567