obj: add set and namespace object callbacks
This commit is contained in:
23
obj/object.c
23
obj/object.c
@@ -2,7 +2,7 @@
|
||||
#include <socks/queue.h>
|
||||
#include <socks/locks.h>
|
||||
|
||||
#define HAS_OP(obj, opname) ((obj)->ob_type->ob_ops && (obj)->ob_type->ob_ops->opname)
|
||||
#define HAS_OP(obj, opname) ((obj)->ob_type->ob_ops.opname)
|
||||
|
||||
static queue_t object_types;
|
||||
static spin_lock_t object_types_lock = SPIN_LOCK_INIT;
|
||||
@@ -53,6 +53,7 @@ object_t *object_create(object_type_t *type)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj->ob_type = type;
|
||||
obj->ob_lock = SPIN_LOCK_INIT;
|
||||
obj->ob_magic = OBJECT_MAGIC;
|
||||
obj->ob_refcount = 1;
|
||||
@@ -85,7 +86,7 @@ void object_deref(object_t *obj)
|
||||
}
|
||||
|
||||
if (HAS_OP(obj, delete)) {
|
||||
obj->ob_type->ob_ops->delete(obj);
|
||||
obj->ob_type->ob_ops.delete(obj);
|
||||
}
|
||||
|
||||
vm_cache_free(&obj->ob_type->ob_cache, obj);
|
||||
@@ -118,32 +119,32 @@ object_t *object_header(void *p)
|
||||
return obj;
|
||||
}
|
||||
|
||||
object_t *object_get_child_named(object_t *obj, const char *name)
|
||||
kern_status_t object_get_child_named(object_t *obj, const char *name, object_t **out)
|
||||
{
|
||||
object_t *out = NULL;
|
||||
kern_status_t status = KERN_UNSUPPORTED;
|
||||
|
||||
if (HAS_OP(obj, get_named)) {
|
||||
obj->ob_type->ob_ops->get_named(obj, name, &out);
|
||||
status = obj->ob_type->ob_ops.get_named(obj, name, out);
|
||||
}
|
||||
|
||||
return out;
|
||||
return status;
|
||||
}
|
||||
|
||||
object_t *object_get_child_at(object_t *obj, size_t at)
|
||||
kern_status_t object_get_child_at(object_t *obj, size_t at, object_t **out)
|
||||
{
|
||||
object_t *out = NULL;
|
||||
kern_status_t status = KERN_UNSUPPORTED;
|
||||
|
||||
if (HAS_OP(obj, get_at)) {
|
||||
obj->ob_type->ob_ops->get_at(obj, at, &out);
|
||||
status = obj->ob_type->ob_ops.get_at(obj, at, out);
|
||||
}
|
||||
|
||||
return out;
|
||||
return status;
|
||||
}
|
||||
|
||||
kern_status_t object_query_name(object_t *obj, char name[OBJECT_NAME_MAX])
|
||||
{
|
||||
if (HAS_OP(obj, query_name)) {
|
||||
return obj->ob_type->ob_ops->query_name(obj, name);
|
||||
return obj->ob_type->ob_ops.query_name(obj, name);
|
||||
}
|
||||
|
||||
return KERN_UNSUPPORTED;
|
||||
|
||||
Reference in New Issue
Block a user