libnl: /data/src/libnl/lib/idiag/idiag_meminfo_obj.c Source File

libnl 3.12.0

idiag_meminfo_obj.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2013 Sassano Systems LLC <joe@sassanosystems.com>
4 */
5
6#include "nl-default.h"
7
8#include <netlink/idiag/meminfo.h>
9
10#include "nl-idiag.h"
11
12/**
13 * @ingroup idiag
14 * @defgroup idiagnl_meminfo Inet Diag Memory Info
15 *
16 * @details
17 * @idiagnl_doc{idiagnl_meminfo, Inet Diag Memory Info Documentation}
18 * @{
19 */
20struct idiagnl_meminfo *idiagnl_meminfo_alloc(void)
21{
22 return (struct idiagnl_meminfo *) nl_object_alloc(&idiagnl_meminfo_obj_ops);
23}
24
25void idiagnl_meminfo_get(struct idiagnl_meminfo *minfo)
26{
27 nl_object_get((struct nl_object *) minfo);
28}
29
30void idiagnl_meminfo_put(struct idiagnl_meminfo *minfo)
31{
32 nl_object_put((struct nl_object *) minfo);
33}
34
35/**
36 * @name Attributes
37 * @{
38 */
39uint32_t idiagnl_meminfo_get_rmem(const struct idiagnl_meminfo *minfo)
40{
41 return minfo->idiag_rmem;
42}
43
44void idiagnl_meminfo_set_rmem(struct idiagnl_meminfo *minfo, uint32_t rmem)
45{
46 minfo->idiag_rmem = rmem;
47}
48
49uint32_t idiagnl_meminfo_get_wmem(const struct idiagnl_meminfo *minfo)
50{
51 return minfo->idiag_wmem;
52}
53
54void idiagnl_meminfo_set_wmem(struct idiagnl_meminfo *minfo, uint32_t wmem)
55{
56 minfo->idiag_wmem = wmem;
57}
58
59uint32_t idiagnl_meminfo_get_fmem(const struct idiagnl_meminfo *minfo)
60{
61 return minfo->idiag_fmem;
62}
63
64void idiagnl_meminfo_set_fmem(struct idiagnl_meminfo *minfo, uint32_t fmem)
65{
66 minfo->idiag_fmem = fmem;
67}
68
69uint32_t idiagnl_meminfo_get_tmem(const struct idiagnl_meminfo *minfo)
70{
71 return minfo->idiag_tmem;
72}
73
74void idiagnl_meminfo_set_tmem(struct idiagnl_meminfo *minfo, uint32_t tmem)
75{
76 minfo->idiag_tmem = tmem;
77}
78/** @} */
79
80/** @cond SKIP */
81static uint64_t idiagnl_meminfo_compare(struct nl_object *_a, struct nl_object *_b,
82 uint64_t attrs, int flags)
83{
84 struct idiagnl_meminfo *a = (struct idiagnl_meminfo *) _a;
85 struct idiagnl_meminfo *b = (struct idiagnl_meminfo *) _b;
86
87 /* meminfo is a very simple object. It has no attribe flags (ce_mask),
88 * hence compare just returns 0 or 1, not a bit mask of attributes. */
89 return a->idiag_rmem != b->idiag_rmem ||
90 a->idiag_wmem != b->idiag_wmem ||
91 a->idiag_fmem != b->idiag_fmem ||
92 a->idiag_tmem != b->idiag_tmem;
93}
94
95struct nl_object_ops idiagnl_meminfo_obj_ops = {
96 .oo_name = "idiag/idiag_meminfo",
97 .oo_size = sizeof(struct idiagnl_meminfo),
98 .oo_compare = idiagnl_meminfo_compare,
99};
100/** @endcond */
101/** @} */
nl_object_put
void nl_object_put(struct nl_object *obj)
Release a reference from an object.
Definition object.c:221
nl_object_get
void nl_object_get(struct nl_object *obj)
Acquire a reference on a object.
Definition object.c:210
nl_object_alloc
struct nl_object * nl_object_alloc(struct nl_object_ops *ops)
Allocate a new object of kind specified by the operations handle.
Definition object.c:55
idiagnl_meminfo
Definition nl-idiag.h:12