#include #include #include #include #include "utils.h" #include "pugixml.hpp" #include LicenceGenerator::LicenceGenerator() { } LicenceGenerator::LicenceGenerator(string uid, string cid, string csd, string dataFileName) { try { if (dataFileName.empty()) throw std::runtime_error("Missing dataFileName par."); if (uid.empty() == false) { this->licData.uid = uid; } else { if (cid.empty()) throw std::runtime_error("Missing CID par."); if (csd.empty()) throw std::runtime_error("Missing CSD par."); } } catch (const std::exception &e) { this->argumentsCorrect = false; std::cerr << "error: " << e.what() << endl; return; } this->configFileName = dataFileName; this->licData.cid = cid; this->licData.csd = csd; this->argumentsCorrect = true; if (processInputConfiguration() == false) { cerr << "Chyba: " << error.message << endl; } } bool LicenceGenerator::processInputConfiguration() { string fullFile = getCompletePath(this->configFileName); const int fileNameLength = fullFile.length(); char fileName[fileNameLength] = {}; getCharsFromString(fullFile, fileName, fileNameLength); #ifdef WINDOWS pugi::xml_parse_result result = doc.load_file("licData.xml"); #else pugi::xml_parse_result result = doc.load_file(fileName); #endif if (result) { const char *dataRootName = doc.child("data") ? "data" : "licence"; // kompatibilita s verzí, která měla ještě root "data" Mapping mapping; if (atoi(&doc.child(dataRootName).attribute("xmlVersion").value()[0]) != XML_VERSION) { error.code = -1; error.message = "Invalid XML VERSION"; return false; } this->licData.doc = &doc; string licType = doc.child(dataRootName).child("licenceType").child_value(); if (!licType.empty()) { this->licIdentification.licLicenceType = mapping.licMapTypes[licType]; // LicenceType::EOS_EOV; } else { cerr << endl << " ERROR MISSING licenceType " << endl; return false; } this->licIdentification.licenceVersion = atoi(&doc.child(dataRootName).child("licenceType").attribute("licenceVersion").value()[0]); this->licIdentification.revision = doc.child(dataRootName).attribute("revision").value()[0]; this->licIdentification.licenceIndex = atoi(&doc.child(dataRootName).child("licenceType").attribute("licenceIndex").value()[0]); this->licIdentification.licElcType = (ELCType)atoi(&doc.child(dataRootName).attribute("elc").value()[0]); //licElcType = (ELCType)atoi(&doc.child(dataRootName).attribute("elc").value()[0]); //licCompatibility = atoi(&doc.child(dataRootName).attribute("compatibility").value()[0]); this->licIdentification.licCompatibility = atoi(&doc.child(dataRootName).attribute("compatibility").value()[0]); string plcType = doc.child(dataRootName).child("plcType").child_value(); if (!plcType.empty()) { this->licIdentification.licPlcType = mapping.licMapPlcType[plcType]; } } else { std::cerr << "Unable to open the config file." << std::endl; } return true; } void LicenceGenerator::createLicenceFile() { switch (this->licIdentification.licElcType) { case ELCType::ELC1: createLicenceELC1(); break; case ELCType::ELC2: createLicenceELC2(); break; case ELCType::ELC3: createLicenceELC3(); break; } } void LicenceGenerator::readLicenceFile() { switch (this->licIdentification.licElcType) { case ELCType::ELC1: readLicenceELC1(); break; case ELCType::ELC2: readLicenceELC2(); break; case ELCType::ELC3: readLicenceELC3(); break; } } void LicenceGenerator::createLicenceELC1() // přejmenvat na ELC1 { LicenceELC11 plcWriteLicence = LicenceELC11(this->licData.cid, this->licData.csd, "file", this->configFileName); plcWriteLicence.createLicence(); } void LicenceGenerator::createLicenceELC2() { switch (this->licIdentification.licCompatibility) { case 1: LicenceELC21 licence = LicenceELC21(this->licData); licence.createLicence(); break; } } void LicenceGenerator::createLicenceELC3() { switch (this->licIdentification.licCompatibility) { case 1: LicenceELC31 licence = LicenceELC31(this->licData); licence.createLicence(); break; } } void LicenceGenerator::readLicenceELC1() { cout << "reading ELC1" << endl; } void LicenceGenerator::readLicenceELC2() { LicenceELC21 licence = LicenceELC21(this->licIdentification); } void LicenceGenerator::readLicenceELC3() { cout << "reading ELC3" << endl; } LicenceGenerator::~LicenceGenerator() { }