1a15fcc3cSEric Blake /* 2a15fcc3cSEric Blake * Clone Visitor 3a15fcc3cSEric Blake * 4a15fcc3cSEric Blake * Copyright (C) 2016 Red Hat, Inc. 5a15fcc3cSEric Blake * 6a15fcc3cSEric Blake * This work is licensed under the terms of the GNU GPL, version 2 or later. 7a15fcc3cSEric Blake * See the COPYING file in the top-level directory. 8a15fcc3cSEric Blake * 9a15fcc3cSEric Blake */ 10a15fcc3cSEric Blake 11a15fcc3cSEric Blake #ifndef QAPI_CLONE_VISITOR_H 12a15fcc3cSEric Blake #define QAPI_CLONE_VISITOR_H 13a15fcc3cSEric Blake 1437f9e0a2SEric Blake #include "qemu/typedefs.h" 15a15fcc3cSEric Blake #include "qapi/visitor.h" 1637f9e0a2SEric Blake #include "qapi-visit.h" 17a15fcc3cSEric Blake 18a15fcc3cSEric Blake /* 19a15fcc3cSEric Blake * The clone visitor is for direct use only by the QAPI_CLONE() macro; 20a15fcc3cSEric Blake * it requires that the root visit occur on an object, list, or 21a15fcc3cSEric Blake * alternate, and is not usable directly on built-in QAPI types. 22a15fcc3cSEric Blake */ 23a15fcc3cSEric Blake typedef struct QapiCloneVisitor QapiCloneVisitor; 24a15fcc3cSEric Blake 25a15fcc3cSEric Blake void *qapi_clone(const void *src, void (*visit_type)(Visitor *, const char *, 26a15fcc3cSEric Blake void **, Error **)); 27*4626a19cSMarkus Armbruster void qapi_clone_members(void *dst, const void *src, size_t sz, 28*4626a19cSMarkus Armbruster void (*visit_type_members)(Visitor *, void *, 29*4626a19cSMarkus Armbruster Error **)); 30a15fcc3cSEric Blake 31a15fcc3cSEric Blake /* 32a15fcc3cSEric Blake * Deep-clone QAPI object @src of the given @type, and return the result. 33a15fcc3cSEric Blake * 34a15fcc3cSEric Blake * Not usable on QAPI scalars (integers, strings, enums), nor on a 35a15fcc3cSEric Blake * QAPI object that references the 'any' type. Safe when @src is NULL. 36a15fcc3cSEric Blake */ 37a15fcc3cSEric Blake #define QAPI_CLONE(type, src) \ 38a15fcc3cSEric Blake ((type *)qapi_clone(src, \ 39a15fcc3cSEric Blake (void (*)(Visitor *, const char *, void**, \ 40a15fcc3cSEric Blake Error **))visit_type_ ## type)) 41a15fcc3cSEric Blake 42*4626a19cSMarkus Armbruster /* 43*4626a19cSMarkus Armbruster * Copy deep clones of @type members from @src to @dst. 44*4626a19cSMarkus Armbruster * 45*4626a19cSMarkus Armbruster * Not usable on QAPI scalars (integers, strings, enums), nor on a 46*4626a19cSMarkus Armbruster * QAPI object that references the 'any' type. 47*4626a19cSMarkus Armbruster */ 48*4626a19cSMarkus Armbruster #define QAPI_CLONE_MEMBERS(type, dst, src) \ 49*4626a19cSMarkus Armbruster qapi_clone_members(dst, src, sizeof(type), \ 50*4626a19cSMarkus Armbruster (void (*)(Visitor *, void *, \ 51*4626a19cSMarkus Armbruster Error **))visit_type_ ## type ## _members) 52*4626a19cSMarkus Armbruster 53a15fcc3cSEric Blake #endif 54