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
6 #include "include/types.h"
7 #include "objclass/objclass.h"
8 #include "common/Mutex.h"
21 struct ClassHandler::ClassData
*cls
;
24 cls_method_call_t func
;
25 cls_method_cxx_call_t cxx_func
;
27 int exec(cls_method_context_t ctx
, bufferlist
& indata
, bufferlist
& outdata
);
31 Mutex::Locker
l(cls
->handler
->mutex
);
35 ClassMethod() : cls(0), flags(0), func(0), cxx_func(0) {}
39 struct ClassHandler::ClassData
*cls
;
41 cls_cxx_filter_factory_t fn
;
52 CLASS_MISSING
, // missing
53 CLASS_MISSING_DEPS
, // missing dependencies
54 CLASS_INITIALIZING
, // calling init() right now
55 CLASS_OPEN
, // initialized, usable
59 ClassHandler
*handler
;
64 map
<string
, ClassMethod
> methods_map
;
65 map
<string
, ClassFilter
> filters_map
;
67 set
<ClassData
*> dependencies
; /* our dependencies */
68 set
<ClassData
*> missing_dependencies
; /* only missing dependencies */
70 ClassMethod
*_get_method(const char *mname
);
72 ClassData() : status(CLASS_UNKNOWN
),
77 ClassMethod
*register_method(const char *mname
, int flags
, cls_method_call_t func
);
78 ClassMethod
*register_cxx_method(const char *mname
, int flags
, cls_method_cxx_call_t func
);
79 void unregister_method(ClassMethod
*method
);
81 ClassFilter
*register_cxx_filter(
82 const std::string
&filter_name
,
83 cls_cxx_filter_factory_t fn
);
84 void unregister_filter(ClassFilter
*method
);
86 ClassMethod
*get_method(const char *mname
) {
87 Mutex::Locker
l(handler
->mutex
);
88 return _get_method(mname
);
90 int get_method_flags(const char *mname
);
92 ClassFilter
*get_filter(const std::string
&filter_name
)
94 Mutex::Locker
l(handler
->mutex
);
95 std::map
<std::string
, ClassFilter
>::iterator i
= filters_map
.find(filter_name
);
96 if (i
== filters_map
.end()) {
105 map
<string
, ClassData
> classes
;
107 ClassData
*_get_class(const string
& cname
, bool check_allowed
);
108 int _load_class(ClassData
*cls
);
110 static bool in_class_list(const std::string
& cname
,
111 const std::string
& list
);
116 explicit ClassHandler(CephContext
*cct_
) : cct(cct_
), mutex("ClassHandler") {}
118 int open_all_classes();
120 void add_embedded_class(const string
& cname
);
121 int open_class(const string
& cname
, ClassData
**pcls
);
123 ClassData
*register_class(const char *cname
);
124 void unregister_class(ClassData
*cls
);