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