cls_method_handle_t h_user_set_buckets_info;
cls_method_handle_t h_user_remove_bucket;
cls_method_handle_t h_user_list_buckets;
+cls_method_handle_t h_user_get_header;
static int write_entry(cls_method_context_t hctx, const string& key, const cls_user_bucket_entry& entry)
{
return 0;
}
+static int cls_user_get_header(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
+{
+ bufferlist::iterator in_iter = in->begin();
+
+ cls_user_get_header_op op;
+ try {
+ ::decode(op, in_iter);
+ } catch (buffer::error& err) {
+ CLS_LOG(1, "ERROR: cls_user_get_header_op(): failed to decode op");
+ return -EINVAL;
+ }
+
+ cls_user_get_header_ret op_ret;
+
+ int ret = read_header(hctx, &op_ret.header);
+ if (ret < 0)
+ return ret;
+
+ ::encode(op_ret, *out);
+
+ return 0;
+}
+
void __cls_init()
{
CLS_LOG(1, "Loaded user class!");
cls_user_set_buckets_info, &h_user_set_buckets_info);
cls_register_cxx_method(h_class, "remove_bucket", CLS_METHOD_RD | CLS_METHOD_WR, cls_user_remove_bucket, &h_user_remove_bucket);
cls_register_cxx_method(h_class, "list_buckets", CLS_METHOD_RD, cls_user_list_buckets, &h_user_list_buckets);
+ cls_register_cxx_method(h_class, "get_header", CLS_METHOD_RD, cls_user_get_header, &h_user_get_header);
return;
}
op.exec("user", "list_buckets", inbl, new ClsUserListCtx(&entries, out_marker, truncated));
}
+class ClsUserGetHeaderCtx : public ObjectOperationCompletion {
+ cls_user_header *header;
+public:
+ ClsUserGetHeaderCtx(cls_user_header *_h) : header(_h) {}
+ void handle_completion(int r, bufferlist& outbl) {
+ if (r >= 0) {
+ cls_user_get_header_ret ret;
+ try {
+ bufferlist::iterator iter = outbl.begin();
+ ::decode(ret, iter);
+ if (header)
+ *header = ret.header;
+ } catch (buffer::error& err) {
+ // nothing we can do about it atm
+ }
+ }
+ }
+};
+
+void cls_user_get_header(librados::ObjectReadOperation& op,
+ cls_user_header *header)
+{
+ bufferlist inbl;
+ cls_user_get_header_op call;
+
+ ::encode(call, inbl);
+
+ op.exec("user", "get_header", inbl, new ClsUserGetHeaderCtx(header));
+}
WRITE_CLASS_ENCODER(cls_user_list_buckets_ret)
+struct cls_user_get_header_op {
+ cls_user_get_header_op() {}
+
+ void encode(bufferlist& bl) const {
+ ENCODE_START(1, 1, bl);
+ ENCODE_FINISH(bl);
+ }
+
+ void decode(bufferlist::iterator& bl) {
+ DECODE_START(1, bl);
+ DECODE_FINISH(bl);
+ }
+};
+WRITE_CLASS_ENCODER(cls_user_get_header_op)
+
+struct cls_user_get_header_ret {
+ cls_user_header header;
+
+ cls_user_get_header_ret() {}
+
+ void encode(bufferlist& bl) const {
+ ENCODE_START(1, 1, bl);
+ ::encode(header, bl);
+ ENCODE_FINISH(bl);
+ }
+
+ void decode(bufferlist::iterator& bl) {
+ DECODE_START(1, bl);
+ ::decode(header, bl);
+ DECODE_FINISH(bl);
+ }
+};
+WRITE_CLASS_ENCODER(cls_user_get_header_ret)
+
+
#endif