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

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