xml.h 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /**
  34. * Resolves device model from vendor and device ids using XML configuration
  35. * The association of vendor/device id pairs with model are provided devices.xml under PCILIB_MODEL_DIR
  36. * @param[in,out] ctx - pcilib context
  37. * @param[in] vendor_id - the vendor id
  38. * @param[in] device_id - the device id
  39. * @return - the name of model or NULL on an error and unknown device. It is caller responsibility to free returned string.
  40. */
  41. char *pcilib_detect_xml_model(pcilib_t *ctx, unsigned int vendor_id, unsigned int device_id);
  42. /** Initializes XML stack and loads a default set of XML files.
  43. * The default location for XML files is /usr/local/share/pcilib/models/@b{model}.
  44. * This can be altered using CMake PCILIB_MODEL_DIR variable while building or using
  45. * PCILIB_MODEL_DIR environmental variable dynamicly. More XML files can be added
  46. * later using pcilib_process_xml() call.
  47. *
  48. * @param[in,out] ctx - pcilib context
  49. * @param[in] model - the name of the model
  50. * @return - error or 0 on success
  51. */
  52. int pcilib_init_xml(pcilib_t *ctx, const char *model);
  53. /** Cleans up memory used by various XML structures
  54. * @param[in] ctx - the pcilib_t context
  55. */
  56. void pcilib_free_xml(pcilib_t *ctx);
  57. /** Processes a bunch of XML files in the specified directory. During the initialization, all XML files
  58. * in the corresponding model directory will be loaded. This function allows to additionally load XML
  59. * files from the specified subdirectories of the model directory. I.e. the XML files from the
  60. * /usr/local/share/pcilib/models/@b{current_model}/@b{location} will be loaded. As with pcilib_init_xml,
  61. * the directory can be adjusted using CMake build configuration or PCILIB_MODEL_DIR environmental
  62. * variable.
  63. * @param[in] ctx - pcilib context
  64. * @param[in] location - Specifies sub-directory with XML files relative to the model directory.
  65. * @return - error or 0 on success
  66. */
  67. int pcilib_process_xml(pcilib_t *ctx, const char *location);
  68. /** This is an internal function which returns a specified node attribute in the pcilib_value_t structure.
  69. * This function should not be used directly. Instead subsystem specific calls like pcilib_get_register_attr,
  70. * pcilib_get_property_attr, ...have to be used.
  71. * @param[in] ctx - pcilib context
  72. * @param[in] node - LibXML2 node
  73. * @param[in] attr - attribute name
  74. * @param[out] val - the result will be returned in this variable. Prior to first usage pcilib_value_t variable should be initalized to 0.
  75. * @return - error or 0 on success
  76. */
  77. int pcilib_get_xml_attr(pcilib_t *ctx, pcilib_xml_node_t *node, const char *attr, pcilib_value_t *val);
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /*_PCILIB_XML_H */