Remove dynamic exceptions
[anna.git] / include / anna / diameter / codec / tme / Engine.hpp__
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_diameter_codec_tme_Engine_hpp
10 #define anna_diameter_codec_tme_Engine_hpp
11
12
13 // STL
14 #include <string>
15
16 #include <anna/core/util/Recycler.hpp>
17
18 #include <anna/diameter/codec/tme/Message.hpp>
19 #include <anna/diameter/codec/tme/Avp.hpp>
20 #include <anna/diameter/codec/EngineImpl.hpp>
21
22
23 using namespace anna::diameter::codec::tme;
24
25
26 //------------------------------------------------------------------------------
27 //---------------------------------------------------------------------- #define
28 //------------------------------------------------------------------------------
29
30
31 namespace anna {
32
33 namespace diameter {
34
35 namespace codec {
36
37 namespace tme {
38
39
40
41 /**
42  * Standard inheritance for engine component implementation, allocating basic Avp and Message classes.
43  */
44 class Engine : public EngineImpl {
45
46 public:
47
48   /**
49      Constructor
50      @param className Logical name for the class.
51   */
52   Engine(const char *className = "anna::diameter::codec::tme::Engine") : EngineImpl(className) {;}
53
54   void releaseAvp(anna::diameter::codec::Avp* avp) {
55     if(avp == NULL) return;
56
57     Avp* aux = static_cast <Avp*>(avp);
58     aux->clear(); // free internal data-part storage specially for grouped avps which will release its childrens
59     a_avps.release(aux);
60   }
61
62   void releaseMessage(anna::diameter::codec::Message* message) {
63     if(message == NULL) return;
64
65     Message* aux = static_cast <Message*>(message);
66     aux->clear(); // free internal data-part storage specially for childrens releasing
67     a_messages.release(aux);
68   }
69
70 protected:
71
72   anna::Recycler<Avp> a_avps;
73   anna::Recycler<Message> a_messages;
74
75   anna::diameter::codec::Avp* allocateAvp() { return a_avps.create(); }
76   anna::diameter::codec::Message* allocateMessage() { return a_messages.create(); }
77
78   friend class Message;
79   friend class Avp;
80 };
81
82 }
83 }
84 }
85 }
86
87 #endif
88