1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 #ifndef CEPH_CLASSHANDLER_H
4 #define CEPH_CLASSHANDLER_H
8 #include "include/types.h"
9 #include "include/common_fwd.h"
10 #include "common/ceph_mutex.h"
11 #include "objclass/objclass.h"
21 const std::string name
;
22 using func_t
= std::variant
<cls_method_cxx_call_t
, cls_method_call_t
>;
25 ClassData
*cls
= nullptr;
27 int exec(cls_method_context_t ctx
,
28 ceph::bufferlist
& indata
,
29 ceph::bufferlist
& outdata
);
33 std::lock_guard
l(cls
->handler
->mutex
);
36 ClassMethod(const char* name
, func_t call
, int flags
, ClassData
* cls
)
37 : name
{name
}, func
{call
}, flags
{flags
}, cls
{cls
}
42 ClassData
*cls
= nullptr;
44 cls_cxx_filter_factory_t fn
= nullptr;
52 CLASS_MISSING
, // missing
53 CLASS_MISSING_DEPS
, // missing dependencies
54 CLASS_INITIALIZING
, // calling init() right now
55 CLASS_OPEN
, // initialized, usable
56 } status
= CLASS_UNKNOWN
;
59 ClassHandler
*handler
= nullptr;
60 void *handle
= nullptr;
64 std::map
<std::string
, ClassMethod
> methods_map
;
65 std::map
<std::string
, ClassFilter
> filters_map
;
67 std::set
<ClassData
*> dependencies
; /* our dependencies */
68 std::set
<ClassData
*> missing_dependencies
; /* only missing dependencies */
70 ClassMethod
*_get_method(const std::string
& mname
);
72 ClassMethod
*register_method(const char *mname
,
74 cls_method_call_t func
);
75 ClassMethod
*register_cxx_method(const char *mname
,
77 cls_method_cxx_call_t func
);
78 void unregister_method(ClassMethod
*method
);
80 ClassFilter
*register_cxx_filter(const std::string
&filter_name
,
81 cls_cxx_filter_factory_t fn
);
82 void unregister_filter(ClassFilter
*method
);
84 ClassMethod
*get_method(const std::string
& mname
) {
85 std::lock_guard
l(handler
->mutex
);
86 return _get_method(mname
);
88 int get_method_flags(const std::string
& mname
);
90 ClassFilter
*get_filter(const std::string
&filter_name
) {
91 std::lock_guard
l(handler
->mutex
);
92 if (auto i
= filters_map
.find(filter_name
); i
== filters_map
.end()) {
101 std::map
<std::string
, ClassData
> classes
;
103 ClassData
*_get_class(const std::string
& cname
, bool check_allowed
);
104 int _load_class(ClassData
*cls
);
106 static bool in_class_list(const std::string
& cname
,
107 const std::string
& list
);
109 ceph::mutex mutex
= ceph::make_mutex("ClassHandler");
112 explicit ClassHandler(CephContext
*cct
) : cct(cct
) {}
114 int open_all_classes();
115 int open_class(const std::string
& cname
, ClassData
**pcls
);
117 ClassData
*register_class(const char *cname
);
118 void unregister_class(ClassData
*cls
);
122 static ClassHandler
& get_instance();