• Home
  • Raw
  • Download

Lines Matching +full:new +full:- +full:object

1 /* SPDX-License-Identifier: LGPL-2.1-only */
3 * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
8 * @defgroup object Object (Cacheable)
10 * Generic object data type, for inheritance purposes to implement cacheable
18 * ------
20 * #include <netlink/object.h>
24 #include <netlink-private/netlink.h>
27 #include <netlink/object.h>
32 if (!obj->ce_ops) in obj_ops()
35 return obj->ce_ops; in obj_ops()
39 * @name Object Creation/Deletion
44 * Allocate a new object of kind specified by the operations handle
46 * @return The new object or NULL
50 struct nl_object *new; in nl_object_alloc() local
52 if (ops->oo_size < sizeof(*new)) in nl_object_alloc()
55 new = calloc(1, ops->oo_size); in nl_object_alloc()
56 if (!new) in nl_object_alloc()
59 new->ce_refcnt = 1; in nl_object_alloc()
60 nl_init_list_head(&new->ce_list); in nl_object_alloc()
62 new->ce_ops = ops; in nl_object_alloc()
63 if (ops->oo_constructor) in nl_object_alloc()
64 ops->oo_constructor(new); in nl_object_alloc()
66 NL_DBG(4, "Allocated new object %p\n", new); in nl_object_alloc()
68 return new; in nl_object_alloc()
72 * Allocate new object of kind specified by the name
73 * @arg kind name of object type
84 return -NLE_OPNOTSUPP; in nl_object_alloc_name()
86 *result = nl_object_alloc(ops->co_obj_ops); in nl_object_alloc_name()
89 return -NLE_NOMEM; in nl_object_alloc_name()
100 * Allocate a new object and copy all data from an existing object
101 * @arg obj object to inherite data from
102 * @return The new object or NULL.
106 struct nl_object *new; in nl_object_clone() local
115 new = nl_object_alloc(ops); in nl_object_clone()
116 if (!new) in nl_object_clone()
119 size = ops->oo_size - doff; in nl_object_clone()
123 new->ce_ops = obj->ce_ops; in nl_object_clone()
124 new->ce_msgtype = obj->ce_msgtype; in nl_object_clone()
125 new->ce_mask = obj->ce_mask; in nl_object_clone()
128 memcpy((char *)new + doff, (char *)obj + doff, size); in nl_object_clone()
130 /* Note that the base implementation already initializes @new via memcpy(). in nl_object_clone()
132 * However, this is only a shallow-copy, so oo_clone() MUST fix all in nl_object_clone()
135 if (ops->oo_clone) { in nl_object_clone()
136 if (ops->oo_clone(new, obj) < 0) { in nl_object_clone()
137 nl_object_free(new); in nl_object_clone()
140 } else if (size && ops->oo_free_data) in nl_object_clone()
143 return new; in nl_object_clone()
147 * Merge a cacheable object
148 * @arg dst object to be merged into
149 * @arg src new object to be merged into dst
157 if (ops->oo_update) in nl_object_update()
158 return ops->oo_update(dst, src); in nl_object_update()
160 return -NLE_OPNOTSUPP; in nl_object_update()
164 * Free a cacheable object
165 * @arg obj object to free
178 if (obj->ce_refcnt > 0) in nl_object_free()
179 NL_DBG(1, "Warning: Freeing object in use...\n"); in nl_object_free()
181 if (obj->ce_cache) in nl_object_free()
184 if (ops->oo_free_data) in nl_object_free()
185 ops->oo_free_data(obj); in nl_object_free()
187 NL_DBG(4, "Freed object %p\n", obj); in nl_object_free()
200 * Acquire a reference on a object
201 * @arg obj object to acquire reference from
205 obj->ce_refcnt++; in nl_object_get()
206 NL_DBG(4, "New reference to object %p, total %d\n", in nl_object_get()
207 obj, obj->ce_refcnt); in nl_object_get()
211 * Release a reference from an object
212 * @arg obj object to release reference from
219 obj->ce_refcnt--; in nl_object_put()
220 NL_DBG(4, "Returned object reference %p, %d remaining\n", in nl_object_put()
221 obj, obj->ce_refcnt); in nl_object_put()
223 if (obj->ce_refcnt < 0) in nl_object_put()
226 if (obj->ce_refcnt <= 0) in nl_object_put()
231 * Check whether this object is used by multiple users
232 * @arg obj object to check
237 return obj->ce_refcnt > 1; in nl_object_shared()
248 * Add mark to object
249 * @arg obj Object to mark
253 obj->ce_flags |= NL_OBJ_MARK; in nl_object_mark()
257 * Remove mark from object
258 * @arg obj Object to unmark
262 obj->ce_flags &= ~NL_OBJ_MARK; in nl_object_unmark()
266 * Return true if object is marked
267 * @arg obj Object to check
268 * @return true if object is marked, otherwise false
272 return (obj->ce_flags & NL_OBJ_MARK); in nl_object_is_marked()
283 * Dump this object according to the specified parameters
284 * @arg obj object to dump
289 if (params->dp_buf) in nl_object_dump()
290 memset(params->dp_buf, 0, params->dp_buflen); in nl_object_dump()
307 * @arg a an object
308 * @arg b another object of same type
327 if (ops->oo_compare == NULL) in nl_object_identical()
330 if (ops->oo_id_attrs_get) { in nl_object_identical()
331 req_attrs_a = ops->oo_id_attrs_get(a); in nl_object_identical()
332 req_attrs_b = ops->oo_id_attrs_get(b); in nl_object_identical()
333 } else if (ops->oo_id_attrs) { in nl_object_identical()
334 req_attrs_a = ops->oo_id_attrs; in nl_object_identical()
341 req_attrs_a &= a->ce_mask; in nl_object_identical()
342 req_attrs_b &= b->ce_mask; in nl_object_identical()
345 * identify an object */ in nl_object_identical()
349 return !(ops->oo_compare(a, b, req_attrs_a, ID_COMPARISON)); in nl_object_identical()
354 * @arg a an object
355 * @arg b another object of same type
357 * The bitmask returned is specific to an object type, each bit set represents
359 * of an attribute in one object and presence in the other is regarded a
368 if (ops != obj_ops(b) || ops->oo_compare == NULL) in nl_object_diff64()
371 return ops->oo_compare(a, b, UINT64_MAX, 0); in nl_object_diff64()
375 * Compute 32-bit bitmask representing difference in attribute values
376 * @arg a an object
377 * @arg b another object of same type
379 * The bitmask returned is specific to an object type, each bit set represents
381 * of an attribute in one object and presence in the other is regarded a
385 * 32nd bit indicates if higher bits from the 64-bit compare were
400 * Match a filter against an object
401 * @arg obj object to check
402 * @arg filter object of same type acting as filter
404 * @return 1 if the object matches the filter or 0
412 if (ops != obj_ops(filter) || ops->oo_compare == NULL) in nl_object_match_filter()
415 return !(ops->oo_compare(obj, filter, filter->ce_mask, in nl_object_match_filter()
421 * @arg obj object of same type as attribute bitmask
436 if (ops->oo_attrs2str != NULL) in nl_object_attrs2str()
437 return ops->oo_attrs2str(attrs, buf, len); in nl_object_attrs2str()
445 * Return list of attributes present in an object
446 * @arg obj an object
454 return nl_object_attrs2str(obj, obj->ce_mask, buf, len); in nl_object_attr_list()
458 * Generate object hash key
459 * @arg obj the object
470 if (ops->oo_keygen) in nl_object_keygen()
471 ops->oo_keygen(obj, hashkey, hashtbl_sz); in nl_object_keygen()
487 * @arg obj object
489 * @return The number of references held to this object
493 return obj->ce_refcnt; in nl_object_get_refcnt()
497 * Return cache the object is associated with
498 * @arg obj object
507 return obj->ce_cache; in nl_object_get_cache()
511 * Return the object's type
512 * @arg obj object
514 * FIXME: link to list of object types
516 * @return Name of the object type
520 if (!obj->ce_ops) in nl_object_get_type()
523 return obj->ce_ops->oo_name; in nl_object_get_type()
527 * Return the netlink message type the object was derived from
528 * @arg obj object
534 return obj->ce_msgtype; in nl_object_get_msgtype()
538 * Return object operations structure
539 * @arg obj object
541 * @return Pointer to the object operations structure
545 return obj->ce_ops; in nl_object_get_ops()
549 * Return object id attribute mask
550 * @arg obj object
552 * @return object id attribute mask
562 if (ops->oo_id_attrs_get) in nl_object_get_id_attrs()
563 id_attrs = ops->oo_id_attrs_get(obj); in nl_object_get_id_attrs()
565 id_attrs = ops->oo_id_attrs; in nl_object_get_id_attrs()