Data Structures | |
struct | nl_derived_object |
Modules | |
Object API | |
Object Creation/Deletion | |
| |
struct nl_object * | nl_object_alloc (struct nl_object_ops *ops) |
Allocate a new object of kind specified by the operations handle. | |
struct nl_object * | nl_object_alloc_name (const char *kind) |
Allocate a new object of kind specified by the name. | |
struct nl_object * | nl_object_clone (struct nl_object *obj) |
Allocate a new object and copy all data from an existing object. | |
void | nl_object_free (struct nl_object *obj) |
Free a cacheable object. | |
Reference Management | |
| |
void | nl_object_get (struct nl_object *obj) |
Acquire a reference on a object. | |
void | nl_object_put (struct nl_object *obj) |
Release a reference from an object. | |
int | nl_object_shared (struct nl_object *obj) |
Check whether this object is used by multiple users. | |
Marks | |
| |
void | nl_object_mark (struct nl_object *obj) |
Add mark to object. | |
void | nl_object_unmark (struct nl_object *obj) |
Remove mark from object. | |
int | nl_object_is_marked (struct nl_object *obj) |
Return true if object is marked. | |
Utillities | |
| |
void | nl_object_dump (struct nl_object *obj, struct nl_dump_params *params) |
Dump this object according to the specified parameters. | |
int | nl_object_identical (struct nl_object *a, struct nl_object *b) |
Check if the identifiers of two objects are identical. | |
uint32_t | nl_object_diff (struct nl_object *a, struct nl_object *b) |
Compute bitmask representing difference in attribute values. | |
int | nl_object_match_filter (struct nl_object *obj, struct nl_object *filter) |
Match a filter against an object. | |
char * | nl_object_attrs2str (struct nl_object *obj, uint32_t attrs, char *buf, size_t len) |
Convert bitmask of attributes to a character string. | |
char * | nl_object_attr_list (struct nl_object *obj, char *buf, size_t len) |
Return list of attributes present in an object. | |
Attributes | |
| |
int | nl_object_get_refcnt (struct nl_object *obj) |
struct nl_cache * | nl_object_get_cache (struct nl_object *obj) |
void * | nl_object_priv (struct nl_object *obj) |
struct nl_object* nl_object_alloc | ( | struct nl_object_ops * | ops | ) | [read] |
ops | cache operations handle |
Definition at line 42 of file object.c.
References nl_object_ops::oo_constructor, and nl_object_ops::oo_size.
Referenced by nl_object_alloc_name(), and nl_object_clone().
00043 { 00044 struct nl_object *new; 00045 00046 if (ops->oo_size < sizeof(*new)) 00047 BUG(); 00048 00049 new = calloc(1, ops->oo_size); 00050 if (!new) { 00051 nl_errno(ENOMEM); 00052 return NULL; 00053 } 00054 00055 new->ce_refcnt = 1; 00056 nl_init_list_head(&new->ce_list); 00057 00058 new->ce_ops = ops; 00059 if (ops->oo_constructor) 00060 ops->oo_constructor(new); 00061 00062 NL_DBG(4, "Allocated new object %p\n", new); 00063 00064 return new; 00065 }
struct nl_object* nl_object_alloc_name | ( | const char * | kind | ) | [read] |
kind | name of object type |
Definition at line 72 of file object.c.
References nl_cache_ops_lookup(), and nl_object_alloc().
00073 { 00074 struct nl_cache_ops *ops; 00075 00076 ops = nl_cache_ops_lookup(kind); 00077 if (!ops) { 00078 nl_error(ENOENT, "Unable to lookup cache kind \"%s\"", kind); 00079 return NULL; 00080 } 00081 00082 return nl_object_alloc(ops->co_obj_ops); 00083 }
struct nl_object* nl_object_clone | ( | struct nl_object * | obj | ) | [read] |
obj | object to inherite data from |
Definition at line 95 of file object.c.
References nl_object_alloc(), nl_object_free(), nl_object_ops::oo_clone, nl_object_ops::oo_free_data, and nl_object_ops::oo_size.
Referenced by nl_cache_add().
00096 { 00097 struct nl_object *new; 00098 struct nl_object_ops *ops = obj_ops(obj); 00099 int doff = offsetof(struct nl_derived_object, data); 00100 int size; 00101 00102 new = nl_object_alloc(ops); 00103 if (!new) 00104 return NULL; 00105 00106 size = ops->oo_size - doff; 00107 if (size < 0) 00108 BUG(); 00109 00110 new->ce_ops = obj->ce_ops; 00111 new->ce_msgtype = obj->ce_msgtype; 00112 00113 if (size) 00114 memcpy((void *)new + doff, (void *)obj + doff, size); 00115 00116 if (ops->oo_clone) { 00117 if (ops->oo_clone(new, obj) < 0) { 00118 nl_object_free(new); 00119 return NULL; 00120 } 00121 } else if (size && ops->oo_free_data) 00122 BUG(); 00123 00124 return new; 00125 }
void nl_object_free | ( | struct nl_object * | obj | ) |
obj | object to free |
Definition at line 133 of file object.c.
References nl_cache_remove(), and nl_object_ops::oo_free_data.
Referenced by nl_object_clone(), and nl_object_put().
00134 { 00135 struct nl_object_ops *ops = obj_ops(obj); 00136 00137 if (obj->ce_refcnt > 0) 00138 NL_DBG(1, "Warning: Freeing object in use...\n"); 00139 00140 if (obj->ce_cache) 00141 nl_cache_remove(obj); 00142 00143 if (ops->oo_free_data) 00144 ops->oo_free_data(obj); 00145 00146 free(obj); 00147 00148 NL_DBG(4, "Freed object %p\n", obj); 00149 }
void nl_object_get | ( | struct nl_object * | obj | ) |
obj | object to acquire reference from |
Definition at line 162 of file object.c.
Referenced by genl_ctrl_search(), genl_ctrl_search_by_name(), nl_cache_add(), nl_cache_move(), nl_cache_search(), rtnl_link_get(), rtnl_link_get_by_name(), rtnl_neigh_get(), rtnl_neightbl_get(), rtnl_qdisc_get(), and rtnl_qdisc_get_by_parent().
void nl_object_put | ( | struct nl_object * | obj | ) |
obj | object to release reference from |
Definition at line 173 of file object.c.
References nl_object_free().
Referenced by nl_cache_remove().
00174 { 00175 if (!obj) 00176 return; 00177 00178 obj->ce_refcnt--; 00179 NL_DBG(4, "Returned object reference %p, %d remaining\n", 00180 obj, obj->ce_refcnt); 00181 00182 if (obj->ce_refcnt < 0) 00183 BUG(); 00184 00185 if (obj->ce_refcnt <= 0) 00186 nl_object_free(obj); 00187 }
int nl_object_shared | ( | struct nl_object * | obj | ) |
void nl_object_mark | ( | struct nl_object * | obj | ) |
obj | Object to mark |
Definition at line 210 of file object.c.
Referenced by nl_cache_mark_all().
void nl_object_unmark | ( | struct nl_object * | obj | ) |
int nl_object_is_marked | ( | struct nl_object * | obj | ) |
void nl_object_dump | ( | struct nl_object * | obj, | |
struct nl_dump_params * | params | |||
) |
int nl_object_identical | ( | struct nl_object * | a, | |
struct nl_object * | b | |||
) |
a | an object | |
b | another object of same type |
Definition at line 258 of file object.c.
References nl_object_ops::oo_compare.
Referenced by nl_cache_search().
00259 { 00260 struct nl_object_ops *ops = obj_ops(a); 00261 int req_attrs; 00262 00263 /* Both objects must be of same type */ 00264 if (ops != obj_ops(b)) 00265 return 0; 00266 00267 req_attrs = ops->oo_id_attrs; 00268 00269 /* Both objects must provide all required attributes to uniquely 00270 * identify an object */ 00271 if ((a->ce_mask & req_attrs) != req_attrs || 00272 (b->ce_mask & req_attrs) != req_attrs) 00273 return 0; 00274 00275 /* Can't judge unless we can compare */ 00276 if (ops->oo_compare == NULL) 00277 return 0; 00278 00279 return !(ops->oo_compare(a, b, req_attrs, 0)); 00280 }
uint32_t nl_object_diff | ( | struct nl_object * | a, | |
struct nl_object * | b | |||
) |
a | an object | |
b | another object of same type |
The bitmask returned is specific to an object type, each bit set represents an attribute which mismatches in either of the two objects. Unavailability of an attribute in one object and presence in the other is regarded a mismatch as well.
Definition at line 294 of file object.c.
References nl_object_ops::oo_compare.
00295 { 00296 struct nl_object_ops *ops = obj_ops(a); 00297 00298 if (ops != obj_ops(b) || ops->oo_compare == NULL) 00299 return UINT_MAX; 00300 00301 return ops->oo_compare(a, b, ~0, 0); 00302 }
int nl_object_match_filter | ( | struct nl_object * | obj, | |
struct nl_object * | filter | |||
) |
obj | object to check | |
filter | object of same type acting as filter |
Definition at line 313 of file object.c.
References nl_object_ops::oo_compare.
Referenced by nl_cache_dump_filter(), nl_cache_foreach_filter(), nl_cache_nitems_filter(), and nl_cache_subset().
00314 { 00315 struct nl_object_ops *ops = obj_ops(obj); 00316 00317 if (ops != obj_ops(filter) || ops->oo_compare == NULL) 00318 return 0; 00319 00320 return !(ops->oo_compare(obj, filter, filter->ce_mask, 00321 LOOSE_FLAG_COMPARISON)); 00322 }
char* nl_object_attrs2str | ( | struct nl_object * | obj, | |
uint32_t | attrs, | |||
char * | buf, | |||
size_t | len | |||
) |
obj | object of same type as attribute bitmask | |
attrs | bitmask of attribute types | |
buf | destination buffer | |
len | length of destination buffer |
Converts the bitmask of attribute types into a list of attribute names separated by comas.
Definition at line 336 of file object.c.
Referenced by nl_object_attr_list().
00338 { 00339 struct nl_object_ops *ops = obj_ops(obj); 00340 00341 if (ops->oo_attrs2str != NULL) 00342 return ops->oo_attrs2str(attrs, buf, len); 00343 else { 00344 memset(buf, 0, len); 00345 return buf; 00346 } 00347 }
char* nl_object_attr_list | ( | struct nl_object * | obj, | |
char * | buf, | |||
size_t | len | |||
) |
obj | an object | |
buf | destination buffer | |
len | length of destination buffer |
Definition at line 357 of file object.c.
References nl_object_attrs2str().
00358 { 00359 return nl_object_attrs2str(obj, obj->ce_mask, buf, len); 00360 }