libnl 3.5.0

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