• source navigation  • diff markup  • identifier search  • freetext search  • 

Sources/libnl-tiny/include/netlink/object.h

  1 /*
  2  * netlink/object.c     Generic Cacheable Object
  3  *
  4  *      This library is free software; you can redistribute it and/or
  5  *      modify it under the terms of the GNU Lesser General Public
  6  *      License as published by the Free Software Foundation version 2.1
  7  *      of the License.
  8  *
  9  * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
 10  */
 11 
 12 #ifndef NETLINK_OBJECT_H_
 13 #define NETLINK_OBJECT_H_
 14 
 15 #include <netlink/netlink.h>
 16 #include <netlink/utils.h>
 17 #include <netlink/object-api.h>
 18 
 19 #ifdef __cplusplus
 20 extern "C" {
 21 #endif
 22 
 23 #define NL_OBJ_MARK             1
 24 
 25 struct nl_cache;
 26 struct nl_object;
 27 struct nl_object_ops;
 28 
 29 struct nl_object
 30 {
 31         NLHDR_COMMON
 32 };
 33 
 34 #define OBJ_CAST(ptr)           ((struct nl_object *) (ptr))
 35 
 36 /* General */
 37 extern struct nl_object *       nl_object_alloc(struct nl_object_ops *);
 38 extern void                     nl_object_free(struct nl_object *);
 39 extern struct nl_object *       nl_object_clone(struct nl_object *obj);
 40 
 41 #ifdef disabled
 42 
 43 extern int                      nl_object_alloc_name(const char *,
 44                                                      struct nl_object **);
 45 extern void                     nl_object_dump(struct nl_object *,
 46                                                struct nl_dump_params *);
 47 
 48 extern uint32_t                 nl_object_diff(struct nl_object *,
 49                                                struct nl_object *);
 50 extern int                      nl_object_match_filter(struct nl_object *,
 51                                                        struct nl_object *);
 52 extern int                      nl_object_identical(struct nl_object *,
 53                                                     struct nl_object *);
 54 extern char *                   nl_object_attrs2str(struct nl_object *,
 55                                                     uint32_t attrs, char *buf,
 56                                                     size_t);
 57 #endif
 58 /**
 59  * Check whether this object is used by multiple users
 60  * @arg obj             object to check
 61  * @return true or false
 62  */
 63 static inline int nl_object_shared(struct nl_object *obj)
 64 {
 65         return obj->ce_refcnt > 1;
 66 }
 67 
 68 
 69 static inline void nl_object_get(struct nl_object *obj)
 70 {
 71         obj->ce_refcnt++;
 72 }
 73 
 74 static inline void nl_object_put(struct nl_object *obj)
 75 {
 76         if (!obj)
 77                 return;
 78 
 79         obj->ce_refcnt--;
 80 
 81         if (obj->ce_refcnt <= 0)
 82                 nl_object_free(obj);
 83 }
 84 
 85 
 86 /**
 87  * @name Marks
 88  * @{
 89  */
 90 
 91 /**
 92  * Add mark to object
 93  * @arg obj             Object to mark
 94  */
 95 static inline void nl_object_mark(struct nl_object *obj)
 96 {
 97         obj->ce_flags |= NL_OBJ_MARK;
 98 }
 99 
100 /**
101  * Remove mark from object
102  * @arg obj             Object to unmark
103  */
104 static inline void nl_object_unmark(struct nl_object *obj)
105 {
106         obj->ce_flags &= ~NL_OBJ_MARK;
107 }
108 
109 /**
110  * Return true if object is marked
111  * @arg obj             Object to check
112  * @return true if object is marked, otherwise false
113  */
114 static inline int nl_object_is_marked(struct nl_object *obj)
115 {
116         return (obj->ce_flags & NL_OBJ_MARK);
117 }
118 
119 /** @} */
120 
121 #ifdef disabled
122 /**
123  * Return list of attributes present in an object
124  * @arg obj             an object
125  * @arg buf             destination buffer
126  * @arg len             length of destination buffer
127  *
128  * @return destination buffer.
129  */
130 static inline char *nl_object_attr_list(struct nl_object *obj, char *buf, size_t len)
131 {
132         return nl_object_attrs2str(obj, obj->ce_mask, buf, len);
133 }
134 #endif
135 
136 /**
137  * @name Attributes
138  * @{
139  */
140 
141 static inline int nl_object_get_refcnt(struct nl_object *obj)
142 {
143         return obj->ce_refcnt;
144 }
145 
146 static inline struct nl_cache *nl_object_get_cache(struct nl_object *obj)
147 {
148         return obj->ce_cache;
149 }
150 
151 static inline void *            nl_object_priv(struct nl_object *obj)
152 {
153         return obj;
154 }
155 
156 
157 /** @} */
158 
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif
165 

This page was automatically generated by LXR 0.3.1.  •  OpenWrt