• 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 "nl-default.h"
28 #include <netlink/object.h>
31 #include "nl-core.h"
32 #include "nl-priv-dynamic-core/nl-core.h"
33 #include "nl-priv-dynamic-core/object-api.h"
34 #include "nl-priv-dynamic-core/cache-api.h"
35 #include "nl-aux-core/nl-core.h"
39 if (!obj->ce_ops) in obj_ops()
42 return obj->ce_ops; in obj_ops()
46 * @name Object Creation/Deletion
51 * Allocate a new object of kind specified by the operations handle
53 * @return The new object or NULL
57 struct nl_object *new; in nl_object_alloc() local
59 if (ops->oo_size < sizeof(*new)) in nl_object_alloc()
62 new = calloc(1, ops->oo_size); in nl_object_alloc()
63 if (!new) in nl_object_alloc()
66 new->ce_refcnt = 1; in nl_object_alloc()
67 nl_init_list_head(&new->ce_list); in nl_object_alloc()
69 new->ce_ops = ops; in nl_object_alloc()
70 if (ops->oo_constructor) in nl_object_alloc()
71 ops->oo_constructor(new); in nl_object_alloc()
73 NL_DBG(4, "Allocated new object %p\n", new); in nl_object_alloc()
75 return new; in nl_object_alloc()
79 * Allocate new object of kind specified by the name
80 * @arg kind name of object type
91 return -NLE_OPNOTSUPP; in nl_object_alloc_name()
93 *result = nl_object_alloc(ops->co_obj_ops); in nl_object_alloc_name()
96 return -NLE_NOMEM; in nl_object_alloc_name()
107 * Allocate a new object and copy all data from an existing object
108 * @arg obj object to inherite data from
109 * @return The new object or NULL.
113 struct nl_object *new; in nl_object_clone() local
122 new = nl_object_alloc(ops); in nl_object_clone()
123 if (!new) in nl_object_clone()
126 size = ops->oo_size - doff; in nl_object_clone()
130 new->ce_ops = obj->ce_ops; in nl_object_clone()
131 new->ce_msgtype = obj->ce_msgtype; in nl_object_clone()
132 new->ce_mask = obj->ce_mask; in nl_object_clone()
135 memcpy((char *)new + doff, (char *)obj + doff, size); in nl_object_clone()
137 /* Note that the base implementation already initializes @new via memcpy(). in nl_object_clone()
139 * However, this is only a shallow-copy, so oo_clone() MUST fix all in nl_object_clone()
142 if (ops->oo_clone) { in nl_object_clone()
143 if (ops->oo_clone(new, obj) < 0) { in nl_object_clone()
144 nl_object_free(new); in nl_object_clone()
147 } else if (size && ops->oo_free_data) in nl_object_clone()
150 return new; in nl_object_clone()
154 * Merge a cacheable object
155 * @arg dst object to be merged into
156 * @arg src new object to be merged into dst
164 if (ops->oo_update) in nl_object_update()
165 return ops->oo_update(dst, src); in nl_object_update()
167 return -NLE_OPNOTSUPP; in nl_object_update()
171 * Free a cacheable object
172 * @arg obj object to free
185 if (obj->ce_refcnt > 0) in nl_object_free()
186 NL_DBG(1, "Warning: Freeing object in use...\n"); in nl_object_free()
188 if (obj->ce_cache) in nl_object_free()
191 if (ops->oo_free_data) in nl_object_free()
192 ops->oo_free_data(obj); in nl_object_free()
194 NL_DBG(4, "Freed object %p\n", obj); in nl_object_free()
207 * Acquire a reference on a object
208 * @arg obj object to acquire reference from
212 obj->ce_refcnt++; in nl_object_get()
213 NL_DBG(4, "New reference to object %p, total %d\n", in nl_object_get()
214 obj, obj->ce_refcnt); in nl_object_get()
218 * Release a reference from an object
219 * @arg obj object to release reference from
226 obj->ce_refcnt--; in nl_object_put()
227 NL_DBG(4, "Returned object reference %p, %d remaining\n", in nl_object_put()
228 obj, obj->ce_refcnt); in nl_object_put()
230 if (obj->ce_refcnt < 0) in nl_object_put()
233 if (obj->ce_refcnt <= 0) in nl_object_put()
238 * Check whether this object is used by multiple users
239 * @arg obj object to check
244 return obj->ce_refcnt > 1; in nl_object_shared()
255 * Add mark to object
256 * @arg obj Object to mark
260 obj->ce_flags |= NL_OBJ_MARK; in nl_object_mark()
264 * Remove mark from object
265 * @arg obj Object to unmark
269 obj->ce_flags &= ~NL_OBJ_MARK; in nl_object_unmark()
273 * Return true if object is marked
274 * @arg obj Object to check
275 * @return true if object is marked, otherwise false
279 return (obj->ce_flags & NL_OBJ_MARK); in nl_object_is_marked()
290 * Dump this object according to the specified parameters
291 * @arg obj object to dump
296 if (params->dp_buf) in nl_object_dump()
297 memset(params->dp_buf, 0, params->dp_buflen); in nl_object_dump()
314 * @arg a an object
315 * @arg b another object of same type
334 if (ops->oo_compare == NULL) in nl_object_identical()
337 if (ops->oo_id_attrs_get) { in nl_object_identical()
338 req_attrs_a = ops->oo_id_attrs_get(a); in nl_object_identical()
339 req_attrs_b = ops->oo_id_attrs_get(b); in nl_object_identical()
340 } else if (ops->oo_id_attrs) { in nl_object_identical()
341 req_attrs_a = ops->oo_id_attrs; in nl_object_identical()
348 req_attrs_a &= a->ce_mask; in nl_object_identical()
349 req_attrs_b &= b->ce_mask; in nl_object_identical()
352 * identify an object */ in nl_object_identical()
356 return !(ops->oo_compare(a, b, req_attrs_a, ID_COMPARISON)); in nl_object_identical()
361 * @arg a an object
362 * @arg b another object of same type
364 * The bitmask returned is specific to an object type, each bit set represents
366 * of an attribute in one object and presence in the other is regarded a
375 if (ops != obj_ops(b) || ops->oo_compare == NULL) in nl_object_diff64()
378 return ops->oo_compare(a, b, UINT64_MAX, 0); in nl_object_diff64()
382 * Compute 32-bit bitmask representing difference in attribute values
383 * @arg a an object
384 * @arg b another object of same type
386 * The bitmask returned is specific to an object type, each bit set represents
388 * of an attribute in one object and presence in the other is regarded a
392 * 32nd bit indicates if higher bits from the 64-bit compare were
407 * Match a filter against an object
408 * @arg obj object to check
409 * @arg filter object of same type acting as filter
411 * @return 1 if the object matches the filter or 0
419 if (ops != obj_ops(filter) || ops->oo_compare == NULL) in nl_object_match_filter()
422 return !(ops->oo_compare(obj, filter, filter->ce_mask, in nl_object_match_filter()
428 * @arg obj object of same type as attribute bitmask
443 if (ops->oo_attrs2str != NULL) in nl_object_attrs2str()
444 return ops->oo_attrs2str(attrs, buf, len); in nl_object_attrs2str()
452 * Return list of attributes present in an object
453 * @arg obj an object
461 return nl_object_attrs2str(obj, obj->ce_mask, buf, len); in nl_object_attr_list()
465 * Generate object hash key
466 * @arg obj the object
477 if (ops->oo_keygen) in nl_object_keygen()
478 ops->oo_keygen(obj, hashkey, hashtbl_sz); in nl_object_keygen()
494 * @arg obj object
496 * @return The number of references held to this object
500 return obj->ce_refcnt; in nl_object_get_refcnt()
504 * Return cache the object is associated with
505 * @arg obj object
514 return obj->ce_cache; in nl_object_get_cache()
518 * Return the object's type
519 * @arg obj object
521 * FIXME: link to list of object types
523 * @return Name of the object type
527 if (!obj->ce_ops) in nl_object_get_type()
530 return obj->ce_ops->oo_name; in nl_object_get_type()
534 * Return the netlink message type the object was derived from
535 * @arg obj object
541 return obj->ce_msgtype; in nl_object_get_msgtype()
545 * Return object operations structure
546 * @arg obj object
548 * @return Pointer to the object operations structure
552 return obj->ce_ops; in nl_object_get_ops()
556 * Return object id attribute mask
557 * @arg obj object
559 * @return object id attribute mask
569 if (ops->oo_id_attrs_get) in nl_object_get_id_attrs()
570 id_attrs = ops->oo_id_attrs_get(obj); in nl_object_get_id_attrs()
572 id_attrs = ops->oo_id_attrs; in nl_object_get_id_attrs()