xml.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @file xml.h
  3. * @version 1.0
  4. * @brief header file to support of xml configuration.
  5. *
  6. * @details this file is the header file for the implementation of dynamic registers using xml and several funtionalities for the "pci-tool" line command tool from XML files. the xml part has been implemented using libxml2.
  7. *
  8. * this code was meant to be evolutive as the XML files evolute. In this meaning, most of the xml parsing is realized with XPath expressions(when it was possible), so that changing the xml xould result mainly in changing the XPAth pathes present here.
  9. * @todo cf compilation chain
  10. */
  11. #ifndef _PCILIB_XML_H
  12. #define _PCILIB_XML_H
  13. #include <pcilib.h>
  14. #include <libxml/tree.h>
  15. #include <libxml/xpath.h>
  16. #include <libxml/xmlschemas.h>
  17. #define PCILIB_MAX_MODEL_FILES 32
  18. typedef struct pcilib_xml_s pcilib_xml_t;
  19. struct pcilib_xml_s {
  20. size_t num_files; /**< Number of currently loaded XML documents */
  21. xmlDocPtr docs[PCILIB_MAX_MODEL_FILES]; /**< Pointers to parsed XML documents */
  22. xmlXPathContextPtr xpath[PCILIB_MAX_MODEL_FILES]; /**< Per-file XPath context */
  23. xmlParserCtxtPtr parser; /**< Pointer to the XML parser context */
  24. xmlSchemaPtr schema; /**< Pointer to the parsed xsd schema */
  25. xmlSchemaValidCtxtPtr validator; /**< Pointer to the XML validation context */
  26. xmlSchemaPtr parts_schema; /**< Pointer to the parsed xsd schema capable of validating individual XML files - no check for cross-references */
  27. xmlSchemaValidCtxtPtr parts_validator; /**< Pointer to the XML validation context capable of validating individual XML files - no check for cross-references */
  28. xmlNodePtr bank_nodes[PCILIB_MAX_REGISTER_BANKS]; /**< pointer to xml nodes of banks in the xml file */
  29. };
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /** Initializes XML stack and loads a default set of XML files.
  34. * The default location for XML files is /usr/local/share/pcilib/models/@b{model}.
  35. * This can be altered using CMake PCILIB_MODEL_DIR variable while building or using
  36. * PCILIB_MODEL_DIR environmental variable dynamicly. More XML files can be added
  37. * later using pcilib_process_xml() call.
  38. *
  39. * @param[in,out] ctx - pcilib context
  40. * @param[in] model - the name of the model
  41. * @return - error or 0 on success
  42. */
  43. int pcilib_init_xml(pcilib_t *ctx, const char *model);
  44. /** Cleans up memory used by various XML structures
  45. * @param[in] ctx - the pcilib_t context
  46. */
  47. void pcilib_free_xml(pcilib_t *ctx);
  48. /** Processes a bunch of XML files in the specified directory. During the initialization, all XML files
  49. * in the corresponding model directory will be loaded. This function allows to additionally load XML
  50. * files from the specified subdirectories of the model directory. I.e. the XML files from the
  51. * /usr/local/share/pcilib/models/@b{current_model}/@b{location} will be loaded. As with pcilib_init_xml,
  52. * the directory can be adjusted using CMake build configuration or PCILIB_MODEL_DIR environmental
  53. * variable.
  54. * @param[in] ctx - pcilib context
  55. * @param[in] location - Specifies sub-directory with XML files relative to the model directory.
  56. * @return - error or 0 on success
  57. */
  58. int pcilib_process_xml(pcilib_t *ctx, const char *location);
  59. /** This is an internal function which returns a specified node attribute in the pcilib_value_t structure.
  60. * This function should not be used directly. Instead subsystem specific calls like pcilib_get_register_attr,
  61. * pcilib_get_property_attr, ...have to be used.
  62. * @param[in] ctx - pcilib context
  63. * @param[in] node - LibXML2 node
  64. * @param[in] attr - attribute name
  65. * @param[out] val - the result will be returned in this variable. Prior to first usage pcilib_value_t variable should be initalized to 0.
  66. * @return - error or 0 on success
  67. */
  68. int pcilib_get_xml_attr(pcilib_t *ctx, pcilib_xml_node_t *node, const char *attr, pcilib_value_t *val);
  69. #ifdef __cplusplus
  70. }
  71. #endif
  72. #endif /*_PCILIB_XML_H */