Debian Codegraph @

include/private/xml.h

raw
1 /*
2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright © 2009-2017 Inria. All rights reserved.
4 * See COPYING in top-level directory.
5 */
6
7 #ifndef PRIVATE_XML_H
8 #define PRIVATE_XML_H 1
9
10 #include "hwloc.h"
11
12 #include <sys/types.h>
13
14 HWLOC_DECLSPEC int hwloc__xml_verbose(void);
15
16 /**************
17 * XML import *
18 **************/
19
20 typedef struct hwloc__xml_import_state_s {
21 struct hwloc__xml_import_state_s *parent;
22
23 /* globals shared between the entire stack of states during import */
24 struct hwloc_xml_backend_data_s *global;
25
26 /* opaque data used to store backend-specific data.
27 * statically allocated to allow stack-allocation by the common code without knowing actual backend needs.
28 * libxml is 3 ptrs. nolibxml is 3 ptr + one int.
29 */
30 char data[4 * SIZEOF_VOID_P];
31 } * hwloc__xml_import_state_t;
32
33 struct hwloc__xml_imported_v1distances_s {
34 unsigned long kind;
35 unsigned nbobjs;
36 float *floats;
37 struct hwloc__xml_imported_v1distances_s *prev, *next;
38 };
39
40 HWLOC_DECLSPEC int hwloc__xml_import_diff(hwloc__xml_import_state_t state, hwloc_topology_diff_t *firstdiffp);
41
42 struct hwloc_xml_backend_data_s {
43 /* xml backend parameters */
44 int (*look_init)(struct hwloc_xml_backend_data_s *bdata, struct hwloc__xml_import_state_s *state);
45 void (*look_done)(struct hwloc_xml_backend_data_s *bdata, int result);
46 void (*backend_exit)(struct hwloc_xml_backend_data_s *bdata);
47 int (*next_attr)(struct hwloc__xml_import_state_s * state, char **namep, char **valuep);
48 int (*find_child)(struct hwloc__xml_import_state_s * state, struct hwloc__xml_import_state_s * childstate, char **tagp);
49 int (*close_tag)(struct hwloc__xml_import_state_s * state); /* look for an explicit closing tag </name> */
50 void (*close_child)(struct hwloc__xml_import_state_s * state);
51 int (*get_content)(struct hwloc__xml_import_state_s * state, const char **beginp, size_t expected_length); /* return 0 on empty content (and sets beginp to empty string), 1 on actual content, -1 on error or unexpected content length */
52 void (*close_content)(struct hwloc__xml_import_state_s * state);
53 char * msgprefix;
54 void *data; /* libxml2 doc, or nolibxml buffer */
55 unsigned version_major, version_minor;
56 unsigned nbnumanodes;
57 hwloc_obj_t first_numanode, last_numanode; /* temporary cousin-list for handling v1distances */
58 unsigned v3memtiers_nr;
59 struct hwloc__xml_imported_v1distances_s *first_v1dist, *last_v1dist;
60 };
61
62 /**************
63 * XML export *
64 **************/
65
66 typedef struct hwloc__xml_export_state_s {
67 struct hwloc__xml_export_state_s *parent;
68
69 void (*new_child)(struct hwloc__xml_export_state_s *parentstate, struct hwloc__xml_export_state_s *state, const char *name);
70 void (*new_prop)(struct hwloc__xml_export_state_s *state, const char *name, const char *value);
71 void (*add_content)(struct hwloc__xml_export_state_s *state, const char *buffer, size_t length);
72 void (*end_object)(struct hwloc__xml_export_state_s *state, const char *name);
73
74 struct hwloc__xml_export_data_s {
75 hwloc_obj_t v1_memory_group; /* if we need to insert intermediate group above memory children when exporting to v1 */
76 } *global;
77
78 /* opaque data used to store backend-specific data.
79 * statically allocated to allow stack-allocation by the common code without knowing actual backend needs.
80 * libxml is 1 ptr. nolibxml is 1 ptr + 2 size_t + 3 ints.
81 */
82 char data[6 * SIZEOF_VOID_P];
83 } * hwloc__xml_export_state_t;
84
85 HWLOC_DECLSPEC void hwloc__xml_export_topology(hwloc__xml_export_state_t parentstate, hwloc_topology_t topology, unsigned long flags);
86
87 HWLOC_DECLSPEC void hwloc__xml_export_diff(hwloc__xml_export_state_t parentstate, hwloc_topology_diff_t diff);
88
89 /******************
90 * XML components *
91 ******************/
92
93 struct hwloc_xml_callbacks {
94 int (*backend_init)(struct hwloc_xml_backend_data_s *bdata, const char *xmlpath, const char *xmlbuffer, int xmlbuflen);
95 int (*export_file)(struct hwloc_topology *topology, struct hwloc__xml_export_data_s *edata, const char *filename, unsigned long flags);
96 int (*export_buffer)(struct hwloc_topology *topology, struct hwloc__xml_export_data_s *edata, char **xmlbuffer, int *buflen, unsigned long flags);
97 void (*free_buffer)(void *xmlbuffer);
98 int (*import_diff)(struct hwloc__xml_import_state_s *state, const char *xmlpath, const char *xmlbuffer, int xmlbuflen, hwloc_topology_diff_t *diff, char **refnamep);
99 int (*export_diff_file)(union hwloc_topology_diff_u *diff, const char *refname, const char *filename);
100 int (*export_diff_buffer)(union hwloc_topology_diff_u *diff, const char *refname, char **xmlbuffer, int *buflen);
101 };
102
103 struct hwloc_xml_component {
104 struct hwloc_xml_callbacks *nolibxml_callbacks;
105 struct hwloc_xml_callbacks *libxml_callbacks;
106 };
107
108 HWLOC_DECLSPEC void hwloc_xml_callbacks_register(struct hwloc_xml_component *component);
109 HWLOC_DECLSPEC void hwloc_xml_callbacks_reset(void);
110
111 #endif /* PRIVATE_XML_H */