Fix xml representations
[anna.git] / example / diameter / launcher / EventOperation.cpp
index 8d8a97d..4d80410 100644 (file)
 // Process
 #include <EventOperation.hpp>
 #include <Launcher.hpp>
+#include <Procedure.hpp>
+#include <MyDiameterEngine.hpp>
+#include <MyLocalServer.hpp>
+#include <anna/testing/TestManager.hpp>
 
-// Project
-#include <anna/diameter.comm/OriginHost.hpp>
-
-
-//// Standard
-//#include <sstream>      // std::istringstream
-//#include <iostream>     // std::cout
+// Standard
 #include <fstream>
-//#include <math.h> // ceil
-//#include <climits>
 #include <unistd.h> // chdir
-//#include <stdio.h>
-//
-//// Project
+
+// Project
+#include <anna/diameter.comm/OriginHost.hpp>
 #include <anna/json/functions.hpp>
 #include <anna/diameter/codec/Message.hpp>
-//#include <anna/timex/Engine.hpp>
-//#include <anna/statistics/Engine.hpp>
-//#include <anna/diameter/codec/functions.hpp>
-//#include <anna/diameter/codec/Engine.hpp>
-//#include <anna/diameter/codec/EngineManager.hpp>
-//#include <anna/http/Transport.hpp>
-//#include <anna/diameter/stack/Engine.hpp>
 #include <anna/diameter/helpers/base/functions.hpp>
 #include <anna/time/functions.hpp>
 #include <anna/core/functions.hpp>
-//#include <anna/diameter.comm/ApplicationMessageOamModule.hpp>
-//#include <anna/testing/defines.hpp>
 #include <anna/xml/xml.hpp>
-//#include <anna/diameter.comm/OriginHost.hpp>
-//#include <anna/diameter.comm/OriginHostManager.hpp>
 #include <anna/diameter.comm/Message.hpp>
-//
-//// Process
-//#include <Launcher.hpp>
-//#include <Procedure.hpp>
-//#include <EventOperation.hpp>
-#include <MyDiameterEngine.hpp>
-#include <MyLocalServer.hpp>
-#include <anna/testing/TestManager.hpp>
-//#include <anna/testing/TestCase.hpp>
 
 
 /////////////////////
@@ -381,7 +357,7 @@ bool EventOperation::sendmsg_hex_2e(std::string &response, const std::string & d
   if(my_app.getOperatedHost()->logEnabled()) {
     anna::diameter::comm::Server *usedServer = my_app.getOperatedEntity()->getLastUsedResource();
     anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL;
-    std::string detail = usedClientSession ? usedClientSession->asString() : "<null client session>"; // shouldn't happen
+    std::string detail = usedClientSession ? usedClientSession->asString() : "[null client session]"; // shouldn't happen
     my_app.getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2e" : "send2eError"), detail);
   }
 
@@ -446,7 +422,7 @@ bool EventOperation::sendmsg_hex_2c(std::string &response, const std::string & d
   // Detailed log:
   if(my_app.getOperatedHost()->logEnabled()) {
     anna::diameter::comm::ServerSession *usedServerSession = my_app.getOperatedServer()->getLastUsedResource();
-    std::string detail = usedServerSession ? usedServerSession->asString() : "<null server session>"; // shouldn't happen
+    std::string detail = usedServerSession ? usedServerSession->asString() : "[null server session]"; // shouldn't happen
     my_app.getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2c" : "send2cError"), detail);
   }
 
@@ -901,12 +877,12 @@ bool EventOperation::test__ip_limit(std::string &response, int amount) {
   if (amount > -2) {
     testManager.setInProgressLimit(amount);
     response = "New in-progress limit: ";
-    response += (amount != -1) ? anna::functions::asString(amount) : "<no limit>";
+    response += (amount != -1) ? anna::functions::asString(amount) : "[no limit]";
   }
   else {
     response = "In-progress limit amount: ";
     int limit = testManager.getInProgressLimit();
-    response += (limit != -1) ? anna::functions::asString(limit) : "<no limit>";
+    response += (limit != -1) ? anna::functions::asString(limit) : "[no limit]";
     response += "; currently there are ";
     response += anna::functions::asString(testManager.getInProgressCount());
     response += " test cases running";
@@ -1236,3 +1212,21 @@ bool EventOperation::test__dump_stdout(std::string &response, bool enable) {
   return true; // OK
 }
 
+bool EventOperation::test__dynamic(std::string &response, const nlohmann::json &arguments) {
+
+  Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
+
+  Procedure p(&my_app);
+  try {
+    p.execute(arguments, response);
+  }
+  catch(anna::RuntimeException &ex) {
+    ex.trace();
+    response += ex.asString();
+    return false;
+  }
+
+  return true; // OK
+}
+
+