Dynamic lib selection and deployment
[anna.git] / example / diameter / launcher / testing / TestCondition.cpp
index 7f535d5..ced5db6 100644 (file)
@@ -13,6 +13,7 @@
 #include <anna/xml/Compiler.hpp>
 #include <anna/diameter/defines.hpp>
 #include <anna/diameter/codec/functions.hpp>
+#include <anna/diameter/codec/Message.hpp>
 #include <anna/diameter/helpers/base/functions.hpp>
 
 #include <anna/diameter/helpers/dcca/defines.hpp>
@@ -21,7 +22,6 @@
 
 // Process
 #include <TestCondition.hpp>
-#include <Launcher.hpp>
 
 
 const char* TestCondition::asText(const Type::_v type)
@@ -34,7 +34,7 @@ bool TestCondition::exists() const throw() {
   if (a_type == Type::Generic)
     return (a_regexp != "");
   else
-    return (a_code != "" || a_bitR != "" || a_resultCode != "" || a_sessionId != "" || a_hopByHop != "" || a_msisdn != "" || a_imsi != "" || a_serviceContextId != "");
+    return (a_code != "" || a_bitR != "" || a_hopByHop != "" || a_applicationId != "" || a_sessionId != "" || a_resultCode != "" || a_msisdn != "" || a_imsi != "" || a_serviceContextId != "");
 }
 
 bool operator==(const TestCondition &c1, const TestCondition &c2) throw() {
@@ -47,9 +47,10 @@ bool operator==(const TestCondition &c1, const TestCondition &c2) throw() {
   else {
     if (c1.a_code != c2.a_code) return false;
     if (c1.a_bitR != c2.a_bitR) return false;
-    if (c1.a_resultCode != c2.a_resultCode) return false;
-    if (c1.a_sessionId != c2.a_sessionId) return false;
     if (c1.a_hopByHop != c2.a_hopByHop) return false;
+    if (c1.a_applicationId != c2.a_applicationId) return false;
+    if (c1.a_sessionId != c2.a_sessionId) return false;
+    if (c1.a_resultCode != c2.a_resultCode) return false;
     if (c1.a_msisdn != c2.a_msisdn) return false;
     if (c1.a_imsi != c2.a_imsi) return false;
     if (c1.a_serviceContextId != c2.a_serviceContextId) return false;
@@ -61,15 +62,8 @@ bool operator==(const TestCondition &c1, const TestCondition &c2) throw() {
 bool TestCondition::comply(const anna::DataBlock &message/*, bool matchSessionId*/) const throw() {
 
   if (a_type == Type::Generic) {
-    Launcher& my_app = static_cast <Launcher&>(anna::app::functions::getApp());
-    static anna::diameter::codec::Message codecMsg(my_app.getCodecEngine());
-    try {
-      codecMsg.decode(message);
-    }
-    catch (anna::RuntimeException &ex) {
-      ex.trace();
-    }
-
+    anna::diameter::codec::Message codecMsg;
+    try { codecMsg.decode(message); } catch (anna::RuntimeException &ex) { ex.trace(); }
     return codecMsg.isLike(a_regexp);
   }
 
@@ -94,32 +88,41 @@ bool TestCondition::comply(const anna::DataBlock &message/*, bool matchSessionId
     if (a_bitR != compare) return false;
   }
 
-  if (a_resultCode != "") {
+  if (a_hopByHop != "") {
     try {
-      anna::U32 rc = anna::diameter::helpers::base::functions::getResultCode(message);
-      compare = anna::functions::asString(rc);
+      anna::diameter::HopByHop h = anna::diameter::codec::functions::getHopByHop(message);
+      compare = anna::functions::asString(h);
     }
     catch (anna::RuntimeException &) { return false; }
-    if (a_resultCode != compare) return false;
+    if (a_hopByHop != compare) return false;
+  }
+
+  if (a_applicationId != "") {
+    try {
+      anna::diameter::ApplicationId a = anna::diameter::codec::functions::getApplicationId(message);
+      compare = anna::functions::asString(a);
+    }
+    catch (anna::RuntimeException &) { return false; }
+    if (a_applicationId != compare) return false;
   }
 
   //if (matchSessionId) {
-    if (a_sessionId != "") {
-      try {
-        compare = anna::diameter::helpers::base::functions::getSessionId(message);
-      }
-      catch (anna::RuntimeException &) { return false; }
-      if (a_sessionId != compare) return false;
+  if (a_sessionId != "") {
+    try {
+      compare = anna::diameter::helpers::base::functions::getSessionId(message);
     }
+    catch (anna::RuntimeException &) { return false; }
+    if (a_sessionId != compare) return false;
+  }
   //}
 
-  if (a_hopByHop != "") {
+  if (a_resultCode != "") {
     try {
-      anna::diameter::HopByHop h = anna::diameter::codec::functions::getHopByHop(message);
-      compare = anna::functions::asString(h);
+      anna::U32 rc = anna::diameter::helpers::base::functions::getResultCode(message);
+      compare = anna::functions::asString(rc);
     }
     catch (anna::RuntimeException &) { return false; }
-    if (a_hopByHop != compare) return false;
+    if (a_resultCode != compare) return false;
   }
 
   if (a_msisdn != "") {
@@ -160,9 +163,10 @@ throw() {
   else {
     if (a_code != "") result->createAttribute("Code", atoi(a_code.c_str()));
     if (a_bitR != "") result->createAttribute("BitR", ((a_bitR == "1") ? "yes":"no"));
+    if (a_hopByHop != "") result->createAttribute("HopByHop", atoll(a_hopByHop.c_str()));
+    if (a_applicationId != "") result->createAttribute("ApplicationId", atoll(a_applicationId.c_str()));
     if (a_sessionId != "") result->createAttribute("SessionId", a_sessionId);
     if (a_resultCode != "") result->createAttribute("ResultCode", atoi(a_resultCode.c_str()));
-    if (a_hopByHop != "") result->createAttribute("HopByHop", atoll(a_hopByHop.c_str()));
     if (a_msisdn != "") result->createAttribute("Msisdn", a_msisdn);
     if (a_imsi != "") result->createAttribute("Imsi", a_imsi);
     if (a_serviceContextId != "") result->createAttribute("ServiceContextId", a_serviceContextId);