]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/rados/objclass.h
ea07dfc790aefc9708bced9dd90082ae6ab18067
[ceph.git] / ceph / src / include / rados / objclass.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_OBJCLASS_OBJCLASS_PUBLIC_H
5 #define CEPH_OBJCLASS_OBJCLASS_PUBLIC_H
6
7 #ifdef __cplusplus
8
9 #include "buffer.h"
10
11 extern "C" {
12 #endif
13
14 #ifndef BUILDING_FOR_EMBEDDED
15 #define CLS_VER(maj,min) \
16 int __cls_ver__## maj ## _ ##min = 0; \
17 int __cls_ver_maj = maj; \
18 int __cls_ver_min = min;
19
20 #define CLS_NAME(name) \
21 int __cls_name__## name = 0; \
22 const char *__cls_name = #name;
23 #define CLS_INIT(name) \
24 void CEPH_CLS_API __cls_init()
25 #else
26 #define CLS_VER(maj,min)
27 #define CLS_NAME(name)
28 #define CLS_INIT(name) \
29 void CEPH_CLS_API name##_cls_init()
30 #endif
31
32 #define CLS_METHOD_RD 0x1 /// method executes read operations
33 #define CLS_METHOD_WR 0x2 /// method executes write operations
34 #define CLS_METHOD_PROMOTE 0x8 /// method cannot be proxied to base tier
35
36 #define CLS_LOG(level, fmt, ...) \
37 cls_log(level, "<cls> %s:%d: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
38 #define CLS_ERR(fmt, ...) CLS_LOG(0, fmt, ##__VA_ARGS__)
39
40 /**
41 * Initialize a class.
42 */
43 void __cls_init();
44
45 /**
46 * @typdef cls_handle_t
47 *
48 * A handle for interacting with the object class.
49 */
50 typedef void *cls_handle_t;
51
52 /**
53 * @typedef cls_method_handle_t
54 *
55 * A handle for interacting with the method of the object class.
56 */
57 typedef void *cls_method_handle_t;
58
59 /**
60 * @typedef cls_method_context_t
61 *
62 * A context for the method of the object class.
63 */
64 typedef void* cls_method_context_t;
65
66 /*class utils*/
67 extern int cls_log(int level, const char *format, ...)
68 __attribute__((__format__(printf, 2, 3)));
69
70 /* class registration api */
71 extern int cls_register(const char *name, cls_handle_t *handle);
72
73 #ifdef __cplusplus
74 }
75
76 /**
77 * @typedef cls_method_cxx_call_t
78 *
79 */
80 typedef int (*cls_method_cxx_call_t)(cls_method_context_t ctx,
81 class ceph::buffer::list *inbl, class ceph::buffer::list *outbl);
82
83 /**
84 * Register a method.
85 *
86 * @param hclass
87 * @param method
88 * @param flags
89 * @param class_call
90 * @param handle
91 */
92 extern int cls_register_cxx_method(cls_handle_t hclass, const char *method, int flags,
93 cls_method_cxx_call_t class_call, cls_method_handle_t *handle);
94
95 /**
96 * Create an object.
97 *
98 * @param hctx
99 * @param exclusive
100 */
101 extern int cls_cxx_create(cls_method_context_t hctx, bool exclusive);
102
103 /**
104 * Remove an object.
105 *
106 * @param hctx
107 */
108 extern int cls_cxx_remove(cls_method_context_t hctx);
109
110 /**
111 * Check on the status of an object.
112 *
113 * @param hctx
114 * @param size
115 * @param mtime
116 */
117 extern int cls_cxx_stat(cls_method_context_t hctx, uint64_t *size, time_t *mtime);
118
119 /**
120 * Read contents of an object.
121 *
122 * @param hctx
123 * @param ofs
124 * @param len
125 * @param bl
126 */
127 extern int cls_cxx_read(cls_method_context_t hctx, int ofs, int len, ceph::bufferlist *bl);
128
129 /**
130 * Write to the object.
131 *
132 * @param hctx
133 * @param ofs
134 * @param len
135 * @param bl
136 */
137 extern int cls_cxx_write(cls_method_context_t hctx, int ofs, int len, ceph::bufferlist *bl);
138
139 /**
140 * Get xattr of the object.
141 *
142 * @param hctx
143 * @param name
144 * @param outbl
145 */
146 extern int cls_cxx_getxattr(cls_method_context_t hctx, const char *name,
147 ceph::bufferlist *outbl);
148
149 /**
150 * Set xattr of the object.
151 *
152 * @param hctx
153 * @param name
154 * @param inbl
155 */
156 extern int cls_cxx_setxattr(cls_method_context_t hctx, const char *name,
157 ceph::bufferlist *inbl);
158
159 /**
160 * Get value corresponding to a key from the map.
161 *
162 * @param hctx
163 * @param key
164 * @param outbl
165 */
166 extern int cls_cxx_map_get_val(cls_method_context_t hctx,
167 const std::string &key, ceph::bufferlist *outbl);
168
169 /**
170 * Set value corresponding to a key in the map.
171 *
172 * @param hctx
173 * @param key
174 * @param inbl
175 */
176 extern int cls_cxx_map_set_val(cls_method_context_t hctx,
177 const std::string &key, ceph::bufferlist *inbl);
178
179 #endif
180
181 #endif