catch (ModesEx &e) {
ERR("parser Fail(%s)", e.what());
}
-
return MODES_ERROR_NONE;
}
try {
ModeParser *parser = getParser(filePath);
+ parser->validateMode();
addModeName(parser, filePath);
delete parser;
}
catch (ModesEx &e) {
- ERR("parser Fail(%s)", e.what());
+ ERR("parser(%s) Fail(%s)", filePath.c_str(), e.what());
}
catch (std::invalid_argument &e) {
ERR("parser Fail(%s)", e.what());
*/
#include "ModeXMLParser.h"
-#include <libxml/tree.h>
#include <string>
+#include <libxml/tree.h>
+#include <libxml/xmlschemas.h>
#include "mdss.h"
#include "Mode.h"
#include "ModesEx.h"
MODES_NAMESPACE_USE;
const xmlChar* const ModeXMLParser::MODE_TAG_TIZEN = (xmlChar*)"tizen";
+const xmlChar* const ModeXMLParser::MODE_TAG_TIZEN_MODES = (xmlChar*)"tizen_modes";
const xmlChar* const ModeXMLParser::MODE_TAG_XMLNS = (xmlChar*)"xmlns";
const xmlChar* const ModeXMLParser::MODE_TAG_VERSION = (xmlChar*)"version";
const xmlChar* const ModeXMLParser::MODE_TAG_MODE = (xmlChar*)"mode";
const xmlChar* const ModeXMLParser::MODE_TAG_ACHIEVE = (xmlChar*)"Achieve";
const xmlChar* const ModeXMLParser::MODE_TAG_CHANGEABLE = (xmlChar*)"Changeable";
+// TODO: Add routine to choose xsd file automatically from xml fileinfo.
+const char* const ModeXMLParser::MODE_XSD_PATH = "./tizen_mode.xsd";
+
ModeXMLParser::ModeXMLParser(const std::string &path)
{
doc = xmlParseFile(path.c_str());
}
DBG("Action<%s> : value=%s, Changeable=%s, Achieve=%s", action.getName().c_str(),
- action.getValue().c_str(), action.getChangeable().c_str(), action.getAchieve().c_str());
+ action.getValue().c_str(), action.getChangeable().c_str(), action.getAchieve().c_str());
modedesc.addAction(action);
}
return modeName;
}
+
+void ModeXMLParser::validateMode()
+{
+ xmlSchemaPtr xsdSchema;
+ xmlSchemaParserCtxtPtr ctxt;
+ xmlSchemaValidCtxtPtr cvtxt;
+
+ ctxt = xmlSchemaNewParserCtxt(MODE_XSD_PATH);
+ if (NULL == ctxt) {
+ ERR("xmlSchemaNewParserCtxt(%s) Fail", MODE_XSD_PATH);
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
+
+ xsdSchema = xmlSchemaParse(ctxt);
+ if (NULL == xsdSchema) {
+ ERR("xmlSchemaParse() Fail");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
+
+ xmlSchemaFreeParserCtxt(ctxt);
+
+ cvtxt = xmlSchemaNewValidCtxt(xsdSchema);
+
+ if (NULL == cvtxt ) {
+ ERR("xmlSchemaNewValidCtxt() Fail");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
+
+ if (0 != xmlSchemaValidateDoc(cvtxt, doc)) {
+ ERR("xmlSchemaValidateDoc() Fail");
+ throw ModesEx(ModesEx::INVALID_ARG);
+ }
+
+ xmlSchemaFreeValidCtxt(cvtxt);
+ xmlSchemaFree(xsdSchema);
+
+// TODO: call xmlSchemaCleanupTypes() when end of this deamon.
+
+ return;
+}
Mode getMode();
std::string getModeName();
+ void validateMode();
private:
static const xmlChar* const MODE_TAG_TIZEN;
+ static const xmlChar* const MODE_TAG_TIZEN_MODES;
static const xmlChar* const MODE_TAG_XMLNS;
static const xmlChar* const MODE_TAG_VERSION;
static const xmlChar* const MODE_TAG_MODE;
static const xmlChar* const MODE_TAG_ACHIEVE;
static const xmlChar* const MODE_TAG_CHANGEABLE;
+ static const char* const MODE_XSD_PATH;
+
void parseMode(xmlNodePtr node, Mode &modedesc);
void parseAction(xmlNodePtr node, Mode &modedesc);
void getDatafromNode(xmlNodePtr node, Mode &modedesc);
#=======================================================================================#
SET(MODES_CLIENT_TEST "modes-test-client")
-#FILE(GLOB MODES_CLIENT_TEST_SRCS "${CMAKE_SOURCE_DIR}/common/*.c" "${CMAKE_SOURCE_DIR}/client/*.c"
-# "${MODES_CLIENT_TEST}.c" )
-#SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/common/dbus.c
-# PROPERTIES GENERATED TRUE)
-#SET(MODES_CLIENT_TEST_SRCS ${MODES_CLIENT_TEST_SRCS} ${CMAKE_SOURCE_DIR}/common/dbus.c)
SET(MODES_CLIENT_TEST_SRCS "modes_client_test.c")
ADD_DEFINITIONS("-DMODES_DBUS_INTERFACE=\"${DBUS_INTERFACE}\"")