mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-12 17:33:00 +08:00
remove unused libxml module from sysman
Signed-off-by: T J Vivek Vilvaraj <t.j.vivek.vilvaraj@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
26779e2f34
commit
aba7d74bcd
@@ -12,7 +12,6 @@
|
||||
namespace L0 {
|
||||
|
||||
ze_result_t LinuxSysmanImp::init() {
|
||||
pXmlParser = XmlParser::create();
|
||||
pFwUtilInterface = FirmwareUtil::create();
|
||||
pFsAccess = FsAccess::create();
|
||||
UNRECOVERABLE_IF(nullptr == pFsAccess);
|
||||
@@ -52,10 +51,6 @@ PmuInterface *LinuxSysmanImp::getPmuInterface() {
|
||||
return pPmuInterface;
|
||||
}
|
||||
|
||||
XmlParser *LinuxSysmanImp::getXmlParser() {
|
||||
return pXmlParser;
|
||||
}
|
||||
|
||||
FirmwareUtil *LinuxSysmanImp::getFwUtilInterface() {
|
||||
return pFwUtilInterface;
|
||||
}
|
||||
@@ -140,10 +135,6 @@ LinuxSysmanImp::~LinuxSysmanImp() {
|
||||
delete pFsAccess;
|
||||
pFsAccess = nullptr;
|
||||
}
|
||||
if (nullptr != pXmlParser) {
|
||||
delete pXmlParser;
|
||||
pXmlParser = nullptr;
|
||||
}
|
||||
if (nullptr != pFwUtilInterface) {
|
||||
delete pFwUtilInterface;
|
||||
pFwUtilInterface = nullptr;
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include "level_zero/tools/source/sysman/linux/fs_access.h"
|
||||
#include "level_zero/tools/source/sysman/linux/pmt/pmt.h"
|
||||
#include "level_zero/tools/source/sysman/linux/pmu/pmu_imp.h"
|
||||
#include "level_zero/tools/source/sysman/linux/xml_parser/xml_parser.h"
|
||||
#include "level_zero/tools/source/sysman/sysman_imp.h"
|
||||
|
||||
#include <map>
|
||||
@@ -30,7 +29,6 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
||||
|
||||
ze_result_t init() override;
|
||||
|
||||
XmlParser *getXmlParser();
|
||||
PmuInterface *getPmuInterface();
|
||||
FirmwareUtil *getFwUtilInterface();
|
||||
FsAccess &getFsAccess();
|
||||
@@ -44,7 +42,6 @@ class LinuxSysmanImp : public OsSysman, NEO::NonCopyableOrMovableClass {
|
||||
void releasePmtObject();
|
||||
|
||||
protected:
|
||||
XmlParser *pXmlParser = nullptr;
|
||||
FsAccess *pFsAccess = nullptr;
|
||||
ProcfsAccess *pProcfsAccess = nullptr;
|
||||
SysfsAccess *pSysfsAccess = nullptr;
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
if(PC_LIBXML_FOUND)
|
||||
set(L0_SRCS_TOOLS_SYSMAN_LINUX_XML_PARSER
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xml_parser_imp.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xml_parser_imp.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xml2_api.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xml2_api.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xml_parser.h
|
||||
)
|
||||
else()
|
||||
set(L0_SRCS_TOOLS_SYSMAN_LINUX_XML_PARSER
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xml_parser_stub.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/xml_parser.h
|
||||
)
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
target_sources(${L0_STATIC_LIB_NAME}
|
||||
PRIVATE
|
||||
${L0_SRCS_TOOLS_SYSMAN_LINUX_XML_PARSER}
|
||||
)
|
||||
endif()
|
||||
|
||||
# Make our source files visible to parent
|
||||
set_property(GLOBAL PROPERTY L0_SRCS_TOOLS_SYSMAN_XML_PARSER_LINUX ${L0_SRCS_TOOLS_SYSMAN_XML_PARSER_LINUX})
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "level_zero/tools/source/sysman/linux/xml_parser/xml2_api.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
const std::string Xml2Api::xml2LibraryFile = "libxml2.so.2";
|
||||
const std::string Xml2Api::xmlInitParserRoutine = "xmlInitParser";
|
||||
const std::string Xml2Api::xmlCleanupParserRoutine = "xmlCleanupParser";
|
||||
const std::string Xml2Api::xmlReadFileRoutine = "xmlReadFile";
|
||||
const std::string Xml2Api::xmlReadMemoryRoutine = "xmlReadMemory";
|
||||
const std::string Xml2Api::xmlFreeDocRoutine = "xmlFreeDoc";
|
||||
const std::string Xml2Api::xmlXPathNewContextRoutine = "xmlXPathNewContext";
|
||||
const std::string Xml2Api::xmlXPathFreeContextRoutine = "xmlXPathFreeContext";
|
||||
const std::string Xml2Api::xmlXPathEvalRoutine = "xmlXPathEval";
|
||||
const std::string Xml2Api::xmlXPathNodeEvalRoutine = "xmlXPathNodeEval";
|
||||
const std::string Xml2Api::xmlXPathCastNodeToStringRoutine = "xmlXPathCastNodeToString";
|
||||
const std::string Xml2Api::xmlXPathFreeObjectRoutine = "xmlXPathFreeObject";
|
||||
const std::string Xml2Api::xmlGetNodePathRoutine = "xmlGetNodePath";
|
||||
const std::string Xml2Api::xmlGetPropRoutine = "xmlGetProp";
|
||||
const std::string Xml2Api::xmlMemGetRoutine = "xmlMemGet";
|
||||
|
||||
template <class T>
|
||||
bool Xml2Api::getProcAddr(const std::string name, T &proc) {
|
||||
void *addr;
|
||||
addr = libraryHandle->getProcAddress(name);
|
||||
proc = reinterpret_cast<T>(addr);
|
||||
return nullptr != proc;
|
||||
}
|
||||
|
||||
bool Xml2Api::loadEntryPoints() {
|
||||
bool ok = true;
|
||||
ok = ok && getProcAddr(xmlInitParserRoutine, xmlInitParserEntry);
|
||||
ok = ok && getProcAddr(xmlCleanupParserRoutine, xmlCleanupParserEntry);
|
||||
ok = ok && getProcAddr(xmlReadFileRoutine, xmlReadFileEntry);
|
||||
ok = ok && getProcAddr(xmlReadMemoryRoutine, xmlReadMemoryEntry);
|
||||
ok = ok && getProcAddr(xmlFreeDocRoutine, xmlFreeDocEntry);
|
||||
ok = ok && getProcAddr(xmlXPathNewContextRoutine, xmlXPathNewContextEntry);
|
||||
ok = ok && getProcAddr(xmlXPathFreeContextRoutine, xmlXPathFreeContextEntry);
|
||||
ok = ok && getProcAddr(xmlXPathEvalRoutine, xmlXPathEvalEntry);
|
||||
ok = ok && getProcAddr(xmlXPathNodeEvalRoutine, xmlXPathNodeEvalEntry);
|
||||
ok = ok && getProcAddr(xmlXPathCastNodeToStringRoutine, xmlXPathCastNodeToStringEntry);
|
||||
ok = ok && getProcAddr(xmlXPathFreeObjectRoutine, xmlXPathFreeObjectEntry);
|
||||
ok = ok && getProcAddr(xmlGetNodePathRoutine, xmlGetNodePathEntry);
|
||||
ok = ok && getProcAddr(xmlGetPropRoutine, xmlGetPropEntry);
|
||||
|
||||
// Can't just get the symbol for xmlFree. Use xmlMemGet to find the xmlFree routine the library is using
|
||||
pXmlMemGet xmlMemGetEntry;
|
||||
ok = ok && getProcAddr(xmlMemGetRoutine, xmlMemGetEntry);
|
||||
ok = ok && !(*xmlMemGetEntry)(&xmlFreeEntry, nullptr, nullptr, nullptr);
|
||||
return ok;
|
||||
}
|
||||
|
||||
void Xml2Api::xmlInitParser() {
|
||||
UNRECOVERABLE_IF(nullptr == xmlInitParserEntry);
|
||||
(*xmlInitParserEntry)();
|
||||
return;
|
||||
}
|
||||
|
||||
void Xml2Api::xmlCleanupParser() {
|
||||
UNRECOVERABLE_IF(nullptr == xmlCleanupParserEntry);
|
||||
(*xmlCleanupParserEntry)();
|
||||
return;
|
||||
}
|
||||
|
||||
xmlDocPtr Xml2Api::xmlReadFile(const std::string filename, int options) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlReadFileEntry);
|
||||
return (*xmlReadFileEntry)(filename.c_str(), NULL, options);
|
||||
}
|
||||
|
||||
xmlDocPtr Xml2Api::xmlReadMemory(const std::string buffer, int options) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlReadMemoryEntry);
|
||||
const char *cbuf = buffer.c_str();
|
||||
int size = static_cast<int>(buffer.length());
|
||||
return (*xmlReadMemoryEntry)(cbuf, size, NULL, NULL, options);
|
||||
}
|
||||
|
||||
void Xml2Api::xmlFreeDoc(xmlDocPtr doc) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlFreeDocEntry);
|
||||
(*xmlFreeDocEntry)(doc);
|
||||
return;
|
||||
}
|
||||
|
||||
xmlXPathContextPtr Xml2Api::xmlXPathNewContext(xmlDocPtr doc) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlXPathNewContextEntry);
|
||||
return (*xmlXPathNewContextEntry)(doc);
|
||||
}
|
||||
|
||||
void Xml2Api::xmlXPathFreeContext(xmlXPathContextPtr cntx) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlXPathFreeContextEntry);
|
||||
(*xmlXPathFreeContextEntry)(cntx);
|
||||
return;
|
||||
}
|
||||
|
||||
xmlXPathObjectPtr Xml2Api::xmlXPathEval(const std::string expr, xmlXPathContextPtr cntx) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlXPathEvalEntry);
|
||||
return (*xmlXPathEvalEntry)(reinterpret_cast<const xmlChar *>(expr.c_str()), cntx);
|
||||
}
|
||||
|
||||
xmlXPathObjectPtr Xml2Api::xmlXPathNodeEval(xmlNodePtr node, const std::string expr, xmlXPathContextPtr cntx) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlXPathNodeEvalEntry);
|
||||
return (*xmlXPathNodeEvalEntry)(node, reinterpret_cast<const xmlChar *>(expr.c_str()), cntx);
|
||||
}
|
||||
|
||||
std::string Xml2Api::xmlXPathCastNodeToString(xmlNodePtr node) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlXPathCastNodeToStringEntry);
|
||||
xmlChar *pXmlChar = (*xmlXPathCastNodeToStringEntry)(node);
|
||||
if (nullptr == pXmlChar) {
|
||||
return std::string();
|
||||
} else {
|
||||
std::string str(reinterpret_cast<char *>(pXmlChar));
|
||||
this->xmlFree(pXmlChar);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
void Xml2Api::xmlXPathFreeObject(xmlXPathObjectPtr obj) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlXPathFreeObjectEntry);
|
||||
(*xmlXPathFreeObjectEntry)(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string Xml2Api::xmlGetNodePath(const xmlNodePtr node) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlGetNodePathEntry);
|
||||
xmlChar *pXmlChar = (*xmlGetNodePathEntry)(node);
|
||||
if (nullptr == pXmlChar) {
|
||||
return std::string();
|
||||
} else {
|
||||
std::string str(reinterpret_cast<const char *>(pXmlChar));
|
||||
this->xmlFree(pXmlChar);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Xml2Api::xmlGetProp(const xmlNodePtr node, std::string prop) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlGetPropEntry);
|
||||
xmlChar *pXmlChar = (*xmlGetPropEntry)(node, reinterpret_cast<const xmlChar *>(prop.c_str()));
|
||||
if (nullptr == pXmlChar) {
|
||||
return std::string();
|
||||
} else {
|
||||
std::string str(reinterpret_cast<char *>(pXmlChar));
|
||||
this->xmlFree(pXmlChar);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
void Xml2Api::xmlFree(void *obj) {
|
||||
UNRECOVERABLE_IF(nullptr == xmlFreeEntry);
|
||||
(*xmlFreeEntry)(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
Xml2Api *Xml2Api::create() {
|
||||
Xml2Api *pXml2Api = new Xml2Api;
|
||||
UNRECOVERABLE_IF(nullptr == pXml2Api);
|
||||
|
||||
pXml2Api->libraryHandle = NEO::OsLibrary::load(xml2LibraryFile);
|
||||
if (pXml2Api->libraryHandle == nullptr || !pXml2Api->loadEntryPoints()) {
|
||||
delete pXml2Api;
|
||||
return nullptr;
|
||||
}
|
||||
return pXml2Api;
|
||||
}
|
||||
|
||||
Xml2Api::~Xml2Api() {
|
||||
if (nullptr != libraryHandle) {
|
||||
delete libraryHandle;
|
||||
libraryHandle = nullptr;
|
||||
}
|
||||
}
|
||||
} // namespace L0
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "level_zero/core/source/device/device.h"
|
||||
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <libxml/xpath.h>
|
||||
#include <libxml/xpathInternals.h>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
typedef void (*pXmlInitParser)();
|
||||
typedef void (*pXmlCleanupParser)();
|
||||
typedef xmlDocPtr (*pXmlReadFile)(const char *, const char *, int);
|
||||
typedef xmlDocPtr (*pXmlReadMemory)(const char *, int, const char *, const char *, int);
|
||||
typedef void (*pXmlFreeDoc)(xmlDocPtr);
|
||||
typedef xmlXPathContextPtr (*pXmlXPathNewContext)(xmlDocPtr);
|
||||
typedef void (*pXmlXPathFreeContext)(xmlXPathContextPtr);
|
||||
typedef xmlXPathObjectPtr (*pXmlXPathEval)(const xmlChar *, xmlXPathContextPtr);
|
||||
typedef xmlXPathObjectPtr (*pXmlXPathNodeEval)(xmlNodePtr, const xmlChar *, xmlXPathContextPtr);
|
||||
typedef xmlChar *(*pXmlXPathCastNodeToString)(xmlNodePtr);
|
||||
typedef void (*pXmlXPathFreeObject)(xmlXPathObjectPtr);
|
||||
typedef xmlChar *(*pXmlGetNodePath)(const xmlNodePtr);
|
||||
typedef xmlChar *(*pXmlGetProp)(const xmlNodePtr, const xmlChar *);
|
||||
typedef int (*pXmlMemGet)(xmlFreeFunc *, xmlMallocFunc *, xmlReallocFunc *, xmlStrdupFunc *);
|
||||
|
||||
class Xml2Api : public NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
void xmlInitParser();
|
||||
void xmlCleanupParser();
|
||||
xmlDocPtr xmlReadFile(const std::string filename, int options);
|
||||
xmlDocPtr xmlReadMemory(const std::string buffer, int options);
|
||||
void xmlFreeDoc(xmlDocPtr doc);
|
||||
xmlXPathContextPtr xmlXPathNewContext(xmlDocPtr doc);
|
||||
void xmlXPathFreeContext(xmlXPathContextPtr);
|
||||
xmlXPathObjectPtr xmlXPathEval(const std::string expr, xmlXPathContextPtr cntx);
|
||||
xmlXPathObjectPtr xmlXPathNodeEval(xmlNodePtr node, const std::string expr, xmlXPathContextPtr cntx);
|
||||
std::string xmlXPathCastNodeToString(xmlNodePtr node);
|
||||
void xmlXPathFreeObject(xmlXPathObjectPtr obj);
|
||||
std::string xmlGetNodePath(const xmlNodePtr node);
|
||||
std::string xmlGetProp(const xmlNodePtr node, std::string prop);
|
||||
|
||||
~Xml2Api();
|
||||
static Xml2Api *create();
|
||||
|
||||
private:
|
||||
template <class T>
|
||||
bool getProcAddr(const std::string name, T &proc);
|
||||
Xml2Api() = default;
|
||||
|
||||
bool loadEntryPoints();
|
||||
void xmlFree(void *obj);
|
||||
|
||||
NEO::OsLibrary *libraryHandle = nullptr;
|
||||
static const std::string xml2LibraryFile;
|
||||
static const std::string xmlInitParserRoutine;
|
||||
static const std::string xmlCleanupParserRoutine;
|
||||
static const std::string xmlReadFileRoutine;
|
||||
static const std::string xmlReadMemoryRoutine;
|
||||
static const std::string xmlFreeDocRoutine;
|
||||
static const std::string xmlXPathNewContextRoutine;
|
||||
static const std::string xmlXPathFreeContextRoutine;
|
||||
static const std::string xmlXPathEvalRoutine;
|
||||
static const std::string xmlXPathNodeEvalRoutine;
|
||||
static const std::string xmlXPathCastNodeToStringRoutine;
|
||||
static const std::string xmlXPathFreeObjectRoutine;
|
||||
static const std::string xmlGetNodePathRoutine;
|
||||
static const std::string xmlGetPropRoutine;
|
||||
static const std::string xmlMemGetRoutine;
|
||||
|
||||
pXmlInitParser xmlInitParserEntry = nullptr;
|
||||
pXmlCleanupParser xmlCleanupParserEntry = nullptr;
|
||||
pXmlReadFile xmlReadFileEntry = nullptr;
|
||||
pXmlReadMemory xmlReadMemoryEntry = nullptr;
|
||||
pXmlFreeDoc xmlFreeDocEntry = nullptr;
|
||||
pXmlXPathNewContext xmlXPathNewContextEntry = nullptr;
|
||||
pXmlXPathFreeContext xmlXPathFreeContextEntry = nullptr;
|
||||
pXmlXPathEval xmlXPathEvalEntry = nullptr;
|
||||
pXmlXPathNodeEval xmlXPathNodeEvalEntry = nullptr;
|
||||
pXmlXPathCastNodeToString xmlXPathCastNodeToStringEntry = nullptr;
|
||||
pXmlXPathFreeObject xmlXPathFreeObjectEntry = nullptr;
|
||||
pXmlGetNodePath xmlGetNodePathEntry = nullptr;
|
||||
pXmlGetProp xmlGetPropEntry = nullptr;
|
||||
xmlFreeFunc xmlFreeEntry = nullptr;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class XmlNode {
|
||||
public:
|
||||
virtual ~XmlNode() = default;
|
||||
|
||||
virtual std::vector<XmlNode *> xPath(std::string path) = 0;
|
||||
virtual std::string getName() = 0;
|
||||
virtual std::string getPath() = 0;
|
||||
virtual std::string getText() = 0;
|
||||
virtual std::string getAttribute(std::string attribute) = 0;
|
||||
};
|
||||
|
||||
class XmlDoc {
|
||||
public:
|
||||
virtual ~XmlDoc() = default;
|
||||
|
||||
virtual std::vector<XmlNode *> xPath(std::string path) = 0;
|
||||
};
|
||||
|
||||
class XmlParser {
|
||||
public:
|
||||
virtual ~XmlParser() = default;
|
||||
|
||||
virtual XmlDoc *parseFile(std::string filename) = 0;
|
||||
virtual XmlDoc *parseBuffer(std::string buffer) = 0;
|
||||
|
||||
static XmlParser *create();
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sysman/linux/xml_parser/xml_parser_imp.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
std::vector<XmlNode *> XmlNodeImp::xPath(std::string path) {
|
||||
std::vector<XmlNode *> nodes;
|
||||
xmlXPathContextPtr cntx = pXml2Api->xmlXPathNewContext(doc);
|
||||
if (nullptr != cntx) {
|
||||
xmlXPathObjectPtr xpathObj = pXml2Api->xmlXPathNodeEval(node, path, cntx);
|
||||
if (nullptr != xpathObj) {
|
||||
xmlNodeSetPtr nodeset = xpathObj->nodesetval;
|
||||
for (int i = 0; i < xmlXPathNodeSetGetLength(nodeset); i++) {
|
||||
xmlNodePtr node = xmlXPathNodeSetItem(nodeset, i);
|
||||
if (nullptr == node) {
|
||||
continue;
|
||||
}
|
||||
XmlNodeImp *pXmlNodeImp = new XmlNodeImp(pXml2Api, doc, node);
|
||||
UNRECOVERABLE_IF(nullptr == pXmlNodeImp);
|
||||
nodes.push_back(pXmlNodeImp);
|
||||
}
|
||||
pXml2Api->xmlXPathFreeObject(xpathObj);
|
||||
}
|
||||
pXml2Api->xmlXPathFreeContext(cntx);
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
std::string XmlNodeImp::getName() {
|
||||
return std::string(reinterpret_cast<const char *>(node->name));
|
||||
}
|
||||
|
||||
std::string XmlNodeImp::getPath() {
|
||||
return pXml2Api->xmlGetNodePath(node);
|
||||
}
|
||||
|
||||
std::string XmlNodeImp::getText() {
|
||||
return pXml2Api->xmlXPathCastNodeToString(node);
|
||||
}
|
||||
|
||||
std::string XmlNodeImp::getAttribute(std::string attribute) {
|
||||
return pXml2Api->xmlGetProp(node, attribute);
|
||||
}
|
||||
|
||||
std::vector<XmlNode *> XmlDocImp::xPath(std::string path) {
|
||||
std::vector<XmlNode *> nodes;
|
||||
xmlXPathContextPtr cntx = pXml2Api->xmlXPathNewContext(doc);
|
||||
if (nullptr != cntx) {
|
||||
xmlXPathObjectPtr xpathObj = pXml2Api->xmlXPathEval(path, cntx);
|
||||
if (nullptr != xpathObj) {
|
||||
xmlNodeSetPtr nodeset = xpathObj->nodesetval;
|
||||
for (int i = 0; i < xmlXPathNodeSetGetLength(nodeset); i++) {
|
||||
xmlNodePtr node = xmlXPathNodeSetItem(nodeset, i);
|
||||
if (nullptr == node) {
|
||||
continue;
|
||||
}
|
||||
XmlNodeImp *pXmlNodeImp = new XmlNodeImp(pXml2Api, doc, node);
|
||||
UNRECOVERABLE_IF(nullptr == pXmlNodeImp);
|
||||
nodes.push_back(pXmlNodeImp);
|
||||
}
|
||||
pXml2Api->xmlXPathFreeObject(xpathObj);
|
||||
}
|
||||
pXml2Api->xmlXPathFreeContext(cntx);
|
||||
}
|
||||
return nodes;
|
||||
}
|
||||
|
||||
XmlDoc *XmlDocImp::parseFile(Xml2Api *pXml2Api, std::string filename) {
|
||||
// Don't allow the parser to print errors or warnings. Don't allow network file access.
|
||||
xmlDocPtr doc = pXml2Api->xmlReadFile(filename, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET);
|
||||
if (nullptr != doc) {
|
||||
return new XmlDocImp(pXml2Api, doc);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
XmlDoc *XmlDocImp::parseBuffer(Xml2Api *pXml2Api, std::string buffer) {
|
||||
// Don't allow the parser to print errors or warnings. Don't allow network file access.
|
||||
xmlDocPtr doc = pXml2Api->xmlReadMemory(buffer, XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NONET);
|
||||
if (nullptr != doc) {
|
||||
return new XmlDocImp(pXml2Api, doc);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
XmlDocImp::~XmlDocImp() {
|
||||
pXml2Api->xmlFreeDoc(doc);
|
||||
}
|
||||
|
||||
XmlDoc *XmlParserImp::parseFile(std::string filename) {
|
||||
return XmlDocImp::parseFile(pXml2Api, filename);
|
||||
}
|
||||
|
||||
XmlDoc *XmlParserImp::parseBuffer(std::string buffer) {
|
||||
return XmlDocImp::parseBuffer(pXml2Api, buffer);
|
||||
}
|
||||
|
||||
XmlParserImp::XmlParserImp() {
|
||||
pXml2Api = Xml2Api::create();
|
||||
if (nullptr != pXml2Api) {
|
||||
pXml2Api->xmlInitParser();
|
||||
}
|
||||
}
|
||||
|
||||
XmlParserImp::~XmlParserImp() {
|
||||
if (nullptr != pXml2Api) {
|
||||
pXml2Api->xmlCleanupParser();
|
||||
delete pXml2Api;
|
||||
pXml2Api = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
XmlParser *XmlParser::create() {
|
||||
XmlParserImp *pXmlParserImp = new XmlParserImp;
|
||||
UNRECOVERABLE_IF(nullptr == pXmlParserImp);
|
||||
if (!pXmlParserImp->isAvailable()) {
|
||||
delete pXmlParserImp;
|
||||
pXmlParserImp = nullptr;
|
||||
}
|
||||
return pXmlParserImp;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
|
||||
#include "level_zero/tools/source/sysman/linux/xml_parser/xml2_api.h"
|
||||
#include "level_zero/tools/source/sysman/linux/xml_parser/xml_parser.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
class XmlNodeImp : public XmlNode, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
XmlNodeImp() = delete;
|
||||
XmlNodeImp(Xml2Api *pXml2Api, xmlDocPtr doc, xmlNodePtr node) : pXml2Api(pXml2Api), doc(doc), node(node) {}
|
||||
~XmlNodeImp() override = default;
|
||||
|
||||
std::vector<XmlNode *> xPath(std::string path) override;
|
||||
std::string getName() override;
|
||||
std::string getPath() override;
|
||||
std::string getText() override;
|
||||
std::string getAttribute(std::string attribute) override;
|
||||
|
||||
private:
|
||||
Xml2Api *pXml2Api = nullptr;
|
||||
xmlDocPtr doc = nullptr;
|
||||
xmlNodePtr node = nullptr;
|
||||
};
|
||||
|
||||
class XmlDocImp : public XmlDoc, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
XmlDocImp() = delete;
|
||||
~XmlDocImp() override;
|
||||
|
||||
std::vector<XmlNode *> xPath(std::string path) override;
|
||||
|
||||
static XmlDoc *parseFile(Xml2Api *pXml2Api, std::string filename);
|
||||
static XmlDoc *parseBuffer(Xml2Api *pXml2Api, std::string buffer);
|
||||
|
||||
private:
|
||||
XmlDocImp(Xml2Api *pXml2Api, xmlDocPtr doc) : pXml2Api(pXml2Api), doc(doc) {}
|
||||
|
||||
Xml2Api *pXml2Api = nullptr;
|
||||
xmlDocPtr doc = nullptr;
|
||||
};
|
||||
|
||||
class XmlParserImp : public XmlParser, NEO::NonCopyableOrMovableClass {
|
||||
public:
|
||||
XmlParserImp();
|
||||
~XmlParserImp() override;
|
||||
|
||||
XmlDoc *parseFile(std::string filename) override;
|
||||
XmlDoc *parseBuffer(std::string buffer) override;
|
||||
|
||||
bool isAvailable() { return nullptr != pXml2Api; }
|
||||
|
||||
private:
|
||||
Xml2Api *pXml2Api = nullptr;
|
||||
};
|
||||
|
||||
} // namespace L0
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sysman/linux/xml_parser/xml_parser.h"
|
||||
|
||||
namespace L0 {
|
||||
|
||||
XmlParser *XmlParser::create() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
Reference in New Issue
Block a user