Motr  M0
xcode.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2015-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #pragma once
24 
25 #ifndef __MOTR_XCODE_XCODE_H__
26 #define __MOTR_XCODE_XCODE_H__
27 
28 #include "lib/vec.h" /* m0_bufvec_cursor */
29 #include "lib/types.h" /* m0_bcount_t */
30 #include "lib/assert.h" /* M0_BASSERT */
31 #include "xcode/xcode_attr.h" /* M0_XC_ATTR */
32 #include "xcode/enum.h"
33 
143 /* import */
144 struct m0_bufvec_cursor;
145 struct m0_be_seg;
146 struct m0_be_tx;
147 
148 /* export */
149 struct m0_xcode;
150 struct m0_xcode_type;
151 struct m0_xcode_type_ops;
152 struct m0_xcode_ctx;
153 struct m0_xcode_obj;
154 struct m0_xcode_field;
155 struct m0_xcode_cursor;
156 struct m0_xcode_field_ops;
157 
218 };
219 
223 extern const char *m0_xcode_aggr_name[M0_XA_NR];
224 
236 
238 };
239 
241 extern const char *m0_xcode_atom_type_name[M0_XAT_NR];
242 
243 enum {
246 };
247 
251  const char *xf_name;
253  const struct m0_xcode_type *xf_type;
271  uint64_t xf_tag;
280  int (*xf_opaque)(const struct m0_xcode_obj *par,
281  const struct m0_xcode_type **out);
285  uint32_t xf_offset;
294  int (*xf_read)(const struct m0_xcode_cursor *it,
295  struct m0_xcode_obj *obj,
296  const char *str);
297 
298 };
299 
307 };
308 M0_BASSERT(sizeof(enum m0_xcode_type_flags) <= sizeof(uint32_t));
309 
318  const char *xct_name;
320  const struct m0_xcode_type_ops *xct_ops;
331  uint32_t xct_flags;
341  size_t xct_sizeof;
343  size_t xct_nr;
346 };
347 
349 struct m0_xcode_obj {
351  const struct m0_xcode_type *xo_type;
353  void *xo_ptr;
354 };
355 
365  int (*xto_length)(struct m0_xcode_ctx *ctx, const void *obj);
366  int (*xto_encode)(struct m0_xcode_ctx *ctx, const void *obj);
367  int (*xto_decode)(struct m0_xcode_ctx *ctx, void *obj);
379  int (*xto_read)(const struct m0_xcode_cursor *it,
380  struct m0_xcode_obj *obj, const char *str);
381 };
382 
383 enum { M0_XCODE_DEPTH_MAX = 10 };
384 
421 };
422 
425 
447  uint64_t s_elno;
451  uint64_t s_datum;
453 };
454 
455 M0_INTERNAL void m0_xcode_cursor_init(struct m0_xcode_cursor *it,
456  const struct m0_xcode_obj *obj);
457 
506 M0_INTERNAL int m0_xcode_next(struct m0_xcode_cursor *it);
507 
511 M0_INTERNAL void m0_xcode_skip(struct m0_xcode_cursor *it);
512 
514 M0_INTERNAL struct m0_xcode_cursor_frame *
516 
518 M0_INTERNAL const struct m0_xcode_field *
520 
567 };
568 
570 extern const char *m0_xcode_endianness_name[M0_XEND_NR];
571 
577 struct m0_xcode_ctx {
600  void *(*xcx_alloc)(struct m0_xcode_cursor *, size_t);
601  void (*xcx_free)(struct m0_xcode_cursor *ctx);
606  int (*xcx_iter)(const struct m0_xcode_cursor *it);
612  void (*xcx_iter_end)(const struct m0_xcode_cursor *it);
613 };
614 
618 M0_INTERNAL void m0_xcode_ctx_init(struct m0_xcode_ctx *ctx,
619  const struct m0_xcode_obj *obj);
620 
624 M0_INTERNAL int m0_xcode_decode(struct m0_xcode_ctx *ctx);
625 
629 M0_INTERNAL int m0_xcode_encode(struct m0_xcode_ctx *ctx);
630 
632 M0_INTERNAL int m0_xcode_length(struct m0_xcode_ctx *ctx);
640 M0_INTERNAL void m0_xcode_type_iterate(struct m0_xcode_type *xt,
641  void (*t)(struct m0_xcode_type *,
642  void *),
643  void (*f)(struct m0_xcode_type *,
644  struct m0_xcode_field *,
645  void *), void *datum);
646 
650 };
651 
656 M0_INTERNAL int m0_xcode_encdec(struct m0_xcode_obj *obj,
657  struct m0_bufvec_cursor *cur,
658  enum m0_xcode_what what);
659 
661 M0_INTERNAL int m0_xcode_obj_enc_to_buf(struct m0_xcode_obj *obj,
662  void **buf, m0_bcount_t *len);
663 
665 M0_INTERNAL int m0_xcode_obj_dec_from_buf(struct m0_xcode_obj *obj,
666  void *buf, m0_bcount_t len);
667 
669 M0_INTERNAL int m0_xcode_data_size(struct m0_xcode_ctx *ctx,
670  const struct m0_xcode_obj *obj);
671 
672 M0_INTERNAL void *m0_xcode_alloc(struct m0_xcode_cursor *it, size_t nob);
673 
677 M0_INTERNAL bool m0_xcode_is_byte_array(const struct m0_xcode_type *xt);
678 
689 M0_INTERNAL ssize_t
691  void *(*alloc)(struct m0_xcode_cursor *, size_t));
752 M0_INTERNAL int m0_xcode_read(struct m0_xcode_obj *obj, const char *str);
753 
764 M0_INTERNAL int m0_xcode_print(const struct m0_xcode_obj *obj,
765  char *str, int nr);
766 
767 M0_INTERNAL void m0_xcode_free_obj(struct m0_xcode_obj *obj);
768 M0_INTERNAL void m0_xcode_free(struct m0_xcode_ctx *ctx);
769 M0_INTERNAL int m0_xcode_cmp(const struct m0_xcode_obj *o0,
770  const struct m0_xcode_obj *o1);
771 M0_INTERNAL int m0_xcode_dup(struct m0_xcode_ctx *dest,
772  struct m0_xcode_ctx *src);
779 M0_INTERNAL bool m0_xcode_type_flags(struct m0_xcode_type *xt,
780  uint32_t on, uint32_t off,
781  uint64_t aggr_umask);
782 
810 M0_INTERNAL void *m0_xcode_addr(const struct m0_xcode_obj *obj, int fieldno,
811  uint64_t elno);
812 
816 M0_INTERNAL uint64_t m0_xcode_atom(const struct m0_xcode_obj *obj);
817 
821 #define M0_XCODE_VAL(obj, fieldno, elno, __type) \
822  ((__type *)m0_xcode_addr(obj, fieldno, elno))
823 
835 M0_INTERNAL int m0_xcode_subobj(struct m0_xcode_obj *subobj,
836  const struct m0_xcode_obj *obj, int fieldno,
837  uint64_t elno);
838 
849 M0_INTERNAL uint64_t m0_xcode_tag(const struct m0_xcode_obj *obj);
850 
857 M0_INTERNAL int m0_xcode_find(struct m0_xcode_obj *obj,
858  const struct m0_xcode_type *xt, void **place);
859 
860 bool m0_xcode_type_invariant(const struct m0_xcode_type *xt);
861 
889 M0_INTERNAL void m0_xcode_union_init(struct m0_xcode_type *un, const char *name,
890  const char *discriminator,
891  size_t maxbranches);
892 
898 M0_INTERNAL void m0_xcode_union_fini(struct m0_xcode_type *un);
899 
905 M0_INTERNAL void m0_xcode_union_add (struct m0_xcode_type *un, const char *name,
906  const struct m0_xcode_type *xt,
907  uint64_t tag);
913 M0_INTERNAL void m0_xcode_union_close(struct m0_xcode_type *un);
914 
915 extern const struct m0_xcode_type M0_XT_VOID;
916 extern const struct m0_xcode_type M0_XT_U8;
917 extern const struct m0_xcode_type M0_XT_U32;
918 extern const struct m0_xcode_type M0_XT_U64;
919 
920 extern const struct m0_xcode_type M0_XT_OPAQUE;
921 
925 typedef char m0_void_t[0];
926 
947 M0_INTERNAL int m0_xcode_decor_register(void);
948 
949 struct m0_bob_type;
950 
956 M0_INTERNAL void m0_xcode_bob_type_init(struct m0_bob_type *bt,
957  const struct m0_xcode_type *xt,
958  size_t magix_field, uint64_t magix);
959 
960 M0_INTERNAL void *m0_xcode_ctx_top(const struct m0_xcode_ctx *ctx);
961 
962 #define M0_XCODE_OBJ(type, ptr) (struct m0_xcode_obj){ \
963  .xo_type = type, \
964  .xo_ptr = ptr, \
965 }
966 
967 void m0_xc_u8_init(void);
968 void m0_xc_u16_init(void);
969 void m0_xc_u32_init(void);
970 void m0_xc_u64_init(void);
971 void m0_xc_void_init(void);
972 void m0_xc_opaque_init(void);
973 
976 /* __MOTR_XCODE_XCODE_H__ */
977 #endif
978 
979 /*
980  * Local variables:
981  * c-indentation-style: "K&R"
982  * c-basic-offset: 8
983  * tab-width: 8
984  * fill-column: 80
985  * scroll-step: 1
986  * End:
987  */
void(* xcx_free)(struct m0_xcode_cursor *ctx)
Definition: xcode.h:601
struct m0_xcode_cursor xcx_it
Definition: xcode.h:595
M0_INTERNAL struct m0_xcode_cursor_frame * m0_xcode_cursor_top(struct m0_xcode_cursor *it)
Definition: cursor.c:41
M0_INTERNAL int m0_xcode_encdec(struct m0_xcode_obj *obj, struct m0_bufvec_cursor *cur, enum m0_xcode_what what)
Definition: xcode.c:416
M0_INTERNAL void * m0_xcode_addr(const struct m0_xcode_obj *obj, int fileno, uint64_t elno)
Definition: xcode.c:612
M0_INTERNAL int m0_xcode_print(const struct m0_xcode_obj *obj, char *str, int nr)
Definition: string.c:278
static size_t nr
Definition: dump.c:1505
M0_INTERNAL void * m0_xcode_ctx_top(const struct m0_xcode_ctx *ctx)
Definition: xcode.c:746
const struct m0_xcode_type * xo_type
Definition: xcode.h:351
const struct m0_xcode_type * xf_type
Definition: xcode.h:253
M0_EXTERN ssize_t m0_xcode_alloc_obj(struct m0_xcode_cursor *it, void *(*alloc)(struct m0_xcode_cursor *, size_t))
Definition: xcode.c:228
M0_INTERNAL void m0_xcode_type_iterate(struct m0_xcode_type *xt, void(*t)(struct m0_xcode_type *, void *), void(*f)(struct m0_xcode_type *, struct m0_xcode_field *, void *), void *datum)
Definition: xcode.c:395
M0_INTERNAL void m0_xcode_union_close(struct m0_xcode_type *un)
Definition: xcode.c:805
static struct buffer * cur(struct m0_addb2_mach *mach, m0_bcount_t space)
Definition: addb2.c:791
static FILE * f
Definition: adieu.c:79
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
M0_INTERNAL int m0_xcode_read(struct m0_xcode_obj *obj, const char *str)
Definition: string.c:162
size_t xct_nr
Definition: xcode.h:343
m0_xcode_aggr
Definition: xcode.h:164
void m0_xc_u16_init(void)
Definition: xcode.c:896
M0_INTERNAL int m0_xcode_subobj(struct m0_xcode_obj *subobj, const struct m0_xcode_obj *obj, int fieldno, uint64_t elno)
Definition: xcode.c:631
static struct m0_be_emap_cursor it
Definition: extmap.c:46
struct m0_bufvec_cursor xcx_buf
Definition: xcode.h:591
struct m0_xcode_field xct_child[0]
Definition: xcode.h:345
m0_xcode_endianness
Definition: xcode.h:561
int(* xto_length)(struct m0_xcode_ctx *ctx, const void *obj)
Definition: xcode.h:365
M0_INTERNAL void m0_xcode_free_obj(struct m0_xcode_obj *obj)
Definition: xcode.c:248
struct m0_xcode_cursor::m0_xcode_cursor_frame xcu_stack[M0_XCODE_DEPTH_MAX]
uint64_t m0_bcount_t
Definition: types.h:77
M0_INTERNAL int m0_xcode_decode(struct m0_xcode_ctx *ctx)
Definition: xcode.c:380
const struct m0_xcode_type_ops * xct_ops
Definition: xcode.h:320
m0_xcode_what
Definition: xcode.h:647
static struct m0_xcode_type ** xt[]
Definition: protocol.c:64
void m0_xc_void_init(void)
Definition: xcode.c:908
const char * m0_xcode_endianness_name[M0_XEND_NR]
Definition: xcode.c:972
static struct foo * obj
Definition: tlist.c:302
Definition: sock.c:887
m0_xode_atom_type
Definition: xcode.h:231
M0_INTERNAL int m0_xcode_dup(struct m0_xcode_ctx *dest, struct m0_xcode_ctx *src)
Definition: xcode.c:522
const char * m0_xcode_cursor_flag_name[M0_XCODE_CURSOR_NR]
Definition: xcode.c:977
M0_INTERNAL int m0_xcode_length(struct m0_xcode_ctx *ctx)
Definition: xcode.c:390
void * xf_decor[M0_XCODE_DECOR_MAX]
Definition: xcode.h:293
static struct btype bt[]
Definition: beck.c:459
M0_INTERNAL void m0_xcode_union_fini(struct m0_xcode_type *un)
Definition: xcode.c:768
int(* xto_read)(const struct m0_xcode_cursor *it, struct m0_xcode_obj *obj, const char *str)
Definition: xcode.h:379
M0_INTERNAL bool m0_xcode_is_byte_array(const struct m0_xcode_type *xt)
Definition: xcode.c:221
const char * name
Definition: trace.c:110
M0_INTERNAL uint64_t m0_xcode_tag(const struct m0_xcode_obj *obj)
Definition: xcode.c:679
Definition: xcode.c:45
const struct m0_xcode_type M0_XT_OPAQUE
Definition: xcode.c:948
M0_INTERNAL void m0_xcode_union_add(struct m0_xcode_type *un, const char *name, const struct m0_xcode_type *xt, uint64_t tag)
Definition: xcode.c:780
M0_INTERNAL int m0_xcode_cmp(const struct m0_xcode_obj *o0, const struct m0_xcode_obj *o1)
Definition: xcode.c:572
enum m0_xode_atom_type xct_atype
Definition: xcode.h:326
static struct m0_thread t[8]
Definition: service_ut.c:1230
const struct m0_xcode_type M0_XT_VOID
Definition: xcode.c:916
Definition: bob.c:40
M0_INTERNAL int m0_xcode_obj_enc_to_buf(struct m0_xcode_obj *obj, void **buf, m0_bcount_t *len)
Definition: xcode.c:832
uint64_t xf_tag
Definition: xcode.h:271
static struct ff2c_term * alloc(void)
Definition: parser.c:37
void * xct_decor[M0_XCODE_DECOR_MAX]
Definition: xcode.h:339
int(* xf_opaque)(const struct m0_xcode_obj *par, const struct m0_xcode_type **out)
Definition: xcode.h:280
M0_INTERNAL void m0_xcode_union_init(struct m0_xcode_type *un, const char *name, const char *discriminator, size_t maxbranches)
Definition: xcode.c:751
m0_xcode_type_flags
Definition: xcode.h:300
M0_INTERNAL int m0_xcode_next(struct m0_xcode_cursor *it)
Definition: cursor.c:59
bool m0_xcode_type_invariant(const struct m0_xcode_type *xt)
Definition: xcode.c:74
M0_INTERNAL void * m0_xcode_alloc(struct m0_xcode_cursor *it, size_t nob)
Definition: xcode.c:444
Definition: seg.h:66
static struct fdmi_ctx ctx
Definition: main.c:80
const char * m0_xcode_atom_type_name[M0_XAT_NR]
Definition: xcode.c:965
M0_INTERNAL void m0_xcode_bob_type_init(struct m0_bob_type *bt, const struct m0_xcode_type *xt, size_t magix_field, uint64_t magix)
Definition: xcode.c:731
void m0_xc_u64_init(void)
Definition: xcode.c:904
const char * m0_xcode_aggr_name[M0_XA_NR]
Definition: xcode.c:955
M0_INTERNAL void m0_xcode_free(struct m0_xcode_ctx *ctx)
Definition: xcode.c:476
M0_INTERNAL int m0_xcode_data_size(struct m0_xcode_ctx *ctx, const struct m0_xcode_obj *obj)
Definition: xcode.c:437
int(* xcx_iter)(const struct m0_xcode_cursor *it)
Definition: xcode.h:606
M0_INTERNAL uint64_t m0_xcode_atom(const struct m0_xcode_obj *obj)
Definition: xcode.c:652
int(* xto_decode)(struct m0_xcode_ctx *ctx, void *obj)
Definition: xcode.h:367
const struct m0_xcode_type M0_XT_U32
Definition: xcode.c:932
enum m0_xcode_endianness xcx_end
Definition: xcode.h:579
void(* xcx_iter_end)(const struct m0_xcode_cursor *it)
Definition: xcode.h:612
M0_INTERNAL void m0_xcode_cursor_init(struct m0_xcode_cursor *it, const struct m0_xcode_obj *obj)
Definition: cursor.c:33
M0_INTERNAL int m0_xcode_decor_register(void)
int(* xf_read)(const struct m0_xcode_cursor *it, struct m0_xcode_obj *obj, const char *str)
Definition: xcode.h:294
enum m0_xcode_aggr xct_aggr
Definition: xcode.h:316
m0_xcode_cursor_flag
Definition: xcode.h:408
char m0_void_t[0]
Definition: xcode.h:925
M0_INTERNAL int m0_xcode_obj_dec_from_buf(struct m0_xcode_obj *obj, void *buf, m0_bcount_t len)
Definition: xcode.c:850
M0_BASSERT(sizeof(struct in_addr)<=sizeof(struct in6_addr))
M0_INTERNAL int m0_xcode_find(struct m0_xcode_obj *obj, const struct m0_xcode_type *xt, void **place)
Definition: xcode.c:713
uint32_t xf_offset
Definition: xcode.h:285
M0_INTERNAL int m0_xcode_encode(struct m0_xcode_ctx *ctx)
Definition: xcode.c:385
const struct m0_xcode_type M0_XT_U8
Definition: xcode.c:924
M0_INTERNAL void m0_xcode_skip(struct m0_xcode_cursor *it)
Definition: cursor.c:148
size_t xct_sizeof
Definition: xcode.h:341
M0_INTERNAL const struct m0_xcode_field * m0_xcode_cursor_field(const struct m0_xcode_cursor *it)
Definition: cursor.c:48
enum m0_xcode_cursor_flag s_flag
Definition: xcode.h:449
void m0_xc_u8_init(void)
Definition: xcode.c:892
void * xo_ptr
Definition: xcode.h:353
void m0_xc_u32_init(void)
Definition: xcode.c:900
int xcu_depth
Definition: xcode.h:434
Definition: nucleus.c:42
M0_INTERNAL void m0_xcode_ctx_init(struct m0_xcode_ctx *ctx, const struct m0_xcode_obj *obj)
Definition: xcode.c:373
#define out(...)
Definition: gen.c:41
const char * xf_name
Definition: xcode.h:251
const struct m0_xcode_type M0_XT_U64
Definition: xcode.c:940
void m0_xc_opaque_init(void)
Definition: xcode.c:912
struct m0_pdclust_src_addr src
Definition: fd.c:108
int(* xto_encode)(struct m0_xcode_ctx *ctx, const void *obj)
Definition: xcode.h:366
uint32_t xct_flags
Definition: xcode.h:331
const char * xct_name
Definition: xcode.h:318
Definition: tx.h:280