1/* 2 * Copyright 2018, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef _SYS_KOBJ_H_ 6#define _SYS_KOBJ_H_ 7 8 9typedef struct kobj* kobj_t; 10typedef driver_t* kobj_class_t; 11typedef const struct device_method kobj_method_t; 12typedef device_method_signature_t kobjop_t; 13typedef void* kobj_ops_t; 14typedef struct kobjop_desc* kobjop_desc_t; 15 16struct kobjop_desc { 17 int32 id; 18 kobj_method_t deflt; /* default implementation */ 19}; 20 21 22/* kobj */ 23struct kobj_ops { 24 kobj_class_t cls; 25}; 26 27#define KOBJ_FIELDS \ 28 struct kobj_ops ops 29 30struct kobj { 31 KOBJ_FIELDS; 32}; 33 34 35/* this *must* be kept in sync with driver_t as defined in haiku-module.h */ 36#define KOBJ_CLASS_FIELDS \ 37 const char* name; \ 38 kobj_method_t* methods; \ 39 size_t size; /* object size */ 40 41 42#define KOBJOPLOOKUP(OPS,OP) do { \ 43 kobjop_desc_t _desc = &OP##_##desc; \ 44 kobj_method_t* _ce = NULL; \ 45 _ce = kobj_lookup_method(OPS.cls, \ 46 NULL, _desc); \ 47 _m = _ce->method; \ 48} while(0) 49 50 51void kobj_init(kobj_t obj, kobj_class_t cls); 52kobj_method_t* kobj_lookup_method(kobj_class_t cls, kobj_method_t **cep, 53 kobjop_desc_t desc); 54int kobj_error_method(void); 55 56 57/* we don't need these functions */ 58static inline void kobj_class_compile(kobj_class_t cls) {} 59static inline void kobj_class_compile_static(kobj_class_t cls, kobj_ops_t ops) {} 60static inline void kobj_class_free(kobj_class_t cls) {} 61static inline void kobj_init_static(kobj_t obj, kobj_class_t cls) {} 62 63 64#endif /* !_SYS_KOBJ_H_ */ 65