Hard refactoring. CodecEngine is associated to a unique stack.
[anna.git] / include / anna / diameter / codec / tme / Engine.hpp__
diff --git a/include/anna/diameter/codec/tme/Engine.hpp__ b/include/anna/diameter/codec/tme/Engine.hpp__
new file mode 100644 (file)
index 0000000..92fbc31
--- /dev/null
@@ -0,0 +1,88 @@
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
+
+
+#ifndef anna_diameter_codec_tme_Engine_hpp
+#define anna_diameter_codec_tme_Engine_hpp
+
+
+// STL
+#include <string>
+
+#include <anna/core/util/Recycler.hpp>
+
+#include <anna/diameter/codec/tme/Message.hpp>
+#include <anna/diameter/codec/tme/Avp.hpp>
+#include <anna/diameter/codec/EngineImpl.hpp>
+
+
+using namespace anna::diameter::codec::tme;
+
+
+//------------------------------------------------------------------------------
+//---------------------------------------------------------------------- #define
+//------------------------------------------------------------------------------
+
+
+namespace anna {
+
+namespace diameter {
+
+namespace codec {
+
+namespace tme {
+
+
+
+/**
+ * Standard inheritance for engine component implementation, allocating basic Avp and Message classes.
+ */
+class Engine : public EngineImpl {
+
+public:
+
+  /**
+     Constructor
+     @param className Logical name for the class.
+  */
+  Engine(const char *className = "anna::diameter::codec::tme::Engine") : EngineImpl(className) {;}
+
+  void releaseAvp(anna::diameter::codec::Avp* avp) throw() {
+    if(avp == NULL) return;
+
+    Avp* aux = static_cast <Avp*>(avp);
+    aux->clear(); // free internal data-part storage specially for grouped avps which will release its childrens
+    a_avps.release(aux);
+  }
+
+  void releaseMessage(anna::diameter::codec::Message* message) throw() {
+    if(message == NULL) return;
+
+    Message* aux = static_cast <Message*>(message);
+    aux->clear(); // free internal data-part storage specially for childrens releasing
+    a_messages.release(aux);
+  }
+
+protected:
+
+  anna::Recycler<Avp> a_avps;
+  anna::Recycler<Message> a_messages;
+
+  anna::diameter::codec::Avp* allocateAvp() throw() { return a_avps.create(); }
+  anna::diameter::codec::Message* allocateMessage() throw() { return a_messages.create(); }
+
+  friend class Message;
+  friend class Avp;
+};
+
+}
+}
+}
+}
+
+#endif
+