X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2FbatchConverter%2Fmain.cpp;h=9009b61f30dabd2f1bb361754dad3b0e40ef5da8;hb=5a6cba5fde2b2f538a7515f8293cc0a8d9589dfa;hp=0e7eff42c81f61c872a7a66731f8ca4c7c34c358;hpb=687b0fa0b7c8440f71837334b0b29c28dfae2dca;p=anna.git diff --git a/example/diameter/batchConverter/main.cpp b/example/diameter/batchConverter/main.cpp index 0e7eff4..9009b61 100644 --- a/example/diameter/batchConverter/main.cpp +++ b/example/diameter/batchConverter/main.cpp @@ -25,7 +25,7 @@ #include #include #include -//#include // ApplicationId anna::diameter::codec::functions::getApplicationId(const anna::DataBlock &) throw(anna::RuntimeException); +//#include // ApplicationId anna::diameter::codec::functions::getApplicationId(const anna::DataBlock &) noexcept(false); using namespace anna; @@ -33,7 +33,7 @@ using namespace anna::diameter; anna::diameter::codec::Message G_codecMsg; -bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) throw() { +bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) { // Get hex string static char buffer[8192]; std::ifstream infile(pathfile.c_str(), std::ifstream::in); @@ -68,13 +68,17 @@ void _exit(const std::string &message, int resultCode = 1) { } // Decodes a diameter message coming from a datablock -void decodeDataBlock(const anna::DataBlock &db/*, unsigned int & detectedApplicationId*/) throw() { +bool decodeDataBlock(const anna::DataBlock &db/*, unsigned int & detectedApplicationId*/) { try { - G_codecMsg.setEngine(NULL); // perhaps we will need another codec engine ... + G_codecMsg.clear(); G_codecMsg.decode(db); } catch(RuntimeException &ex) { - _exit(ex.asString()); + std::cerr << ex.asString() << std::endl << std::endl; + //_exit(ex.asString()); + return false; } + + return true; } //------------------------------------------------------------------- @@ -190,7 +194,7 @@ int main(int argc, char **argv) { directoryHex.read(wkDir.c_str(), anna::io::Directory::Mode::FullPath); directoryXml.setPattern(".xml$"); directoryXml.read(wkDir.c_str(), anna::io::Directory::Mode::FullPath); - + // Processing .hex files: bool anyHexConverted = false; if (processHex) { @@ -202,15 +206,16 @@ int main(int argc, char **argv) { _exit("Error reading hex file provided"); // Decode datablock: - decodeDataBlock(db_aux); + if (decodeDataBlock(db_aux)) { - // Write conversion: - std::string outputFile = entry + ".as.xml"; - std::ofstream out(outputFile.c_str(), std::ifstream::out); - out << G_codecMsg.asXMLString(); - out.close(); + // Write conversion: + std::string outputFile = entry + ".as.xml"; + std::ofstream out(outputFile.c_str(), std::ifstream::out); + out << G_codecMsg.asXMLString(); + out.close(); - anyHexConverted = true; + anyHexConverted = true; + } } } @@ -220,17 +225,17 @@ int main(int argc, char **argv) { for (anna::io::Directory::const_iterator it = directoryXml.begin(); it != directoryXml.end(); it++) { const std::string& entry = anna::io::Directory::data (it); LOGDEBUG(anna::Logger::debug(entry + " is being converted to hex", ANNA_FILE_LOCATION)); - + // Load file: - G_codecMsg.loadXML(entry); - + G_codecMsg.loadXMLFile(entry); + // Write conversion: std::string hexString = anna::functions::asHexString(G_codecMsg.code()); std::string outputFile = entry + ".as.hex"; std::ofstream out(outputFile.c_str(), std::ifstream::out); out.write(hexString.c_str(), hexString.size()); out.close(); - + anyXmlConverted = true; } }