deviceNodeParser.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "main.h"
  2. #include "./DeviceNodeParser.h"
  3. #include "../../xml/obj_xml.h"
  4. DeviceNodeParser::DeviceNodeParser()
  5. : reader(NULL), test(NULL)
  6. {
  7. }
  8. DeviceNodeParser::~DeviceNodeParser()
  9. {
  10. End();
  11. }
  12. BOOL DeviceNodeParser::Begin(obj_xml *xmlReader, TestSuite *testSuite)
  13. {
  14. if (NULL != reader || NULL != test)
  15. return FALSE;
  16. if (NULL == xmlReader || NULL == testSuite)
  17. return FALSE;
  18. reader = xmlReader;
  19. reader->AddRef();
  20. test = testSuite;
  21. reader->xmlreader_registerCallback(L"testprovider\fdevices\fdevice", this);
  22. return TRUE;
  23. }
  24. void DeviceNodeParser::End()
  25. {
  26. if (NULL != reader)
  27. {
  28. reader->xmlreader_unregisterCallback(this);
  29. reader->Release();
  30. reader = NULL;
  31. }
  32. if (NULL != test)
  33. test = NULL;
  34. }
  35. void DeviceNodeParser::Event_XmlStartElement(const wchar_t *xmlpath, const wchar_t *xmltag, ifc_xmlreaderparams *params)
  36. {
  37. elementParser.Begin(reader, params);
  38. }
  39. void DeviceNodeParser::Event_XmlEndElement(const wchar_t *xmlpath, const wchar_t *xmltag)
  40. {
  41. Device *result;
  42. if (FALSE != elementParser.End(reader, &result))
  43. {
  44. if (NULL != test)
  45. test->AddDevice(result);
  46. result->Release();
  47. }
  48. }
  49. void DeviceNodeParser::Event_XmlError(int linenum, int errcode, const wchar_t *errstr)
  50. {
  51. }
  52. #define CBCLASS DeviceNodeParser
  53. START_DISPATCH;
  54. VCB(ONSTARTELEMENT, Event_XmlStartElement)
  55. VCB(ONENDELEMENT, Event_XmlEndElement)
  56. VCB(ONERROR, Event_XmlError)
  57. END_DISPATCH;
  58. #undef CBCLASS