xref: /haiku/src/libs/compat/freebsd_iflib/kobj.c (revision fd41233b076b95615c5a10af3026c24ae605af11)
1 /*
2  * Copyright 2018-2019, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include <sys/cdefs.h>
7 #include <sys/param.h>
8 #include <sys/kernel.h>
9 #include <sys/kobj.h>
10 #include <sys/lock.h>
11 #include <sys/mutex.h>
12 
13 
14 static kobj_method_t kobj_default_method = {
15 	"kobj_default_method", 0, (kobjop_t)kobj_error_method
16 };
17 
18 
19 void
kobj_init(kobj_t obj,kobj_class_t cls)20 kobj_init(kobj_t obj, kobj_class_t cls)
21 {
22 	obj->ops.cls = cls;
23 }
24 
25 
26 kobj_method_t*
kobj_lookup_method(kobj_class_t class,kobj_method_t ** cep,kobjop_desc_t desc)27 kobj_lookup_method(kobj_class_t class, kobj_method_t** cep,
28 	kobjop_desc_t desc)
29 {
30 	int32 i, id;
31 	kobj_method_t* ret = NULL;
32 
33 	id = desc->id;
34 	if (id == 0)
35 		id = desc->deflt.id;
36 
37 	for (i = 0; class->methods[i].name != NULL; i++) {
38 		kobj_method_t* mth = &class->methods[i];
39 		if (mth->id != id)
40 			continue;
41 
42 		ret = mth;
43 		break;
44 	}
45 	if (ret == NULL || ret->method == NULL)
46 		ret = &desc->deflt;
47 	if (ret == NULL || ret->method == NULL)
48 		ret = &kobj_default_method;
49 
50 	if (cep != NULL)
51 		*cep = ret;
52 	return ret;
53 }
54 
55 
56 int
kobj_error_method(void)57 kobj_error_method(void)
58 {
59 	return ENXIO;
60 }
61