Remove dynamic exceptions
[anna.git] / include / anna / diameter.comm / Timer.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_comm_Timer_hpp
10 #define anna_diameter_comm_Timer_hpp
11
12 #include <anna/core/RuntimeException.hpp>
13 #include <anna/core/Allocator.hpp>
14 #include <anna/timex/Transaction.hpp>
15
16
17 namespace anna {
18
19 namespace diameter {
20
21 namespace comm {
22
23
24 class Session;
25 class Response;
26 class LocalServer;
27 class TimerManager;
28
29
30 class Timer : public anna::timex::Transaction {
31
32 public:
33   struct Type { enum _v { ResponseExpiration, SessionUnbind, SessionRecover, LocalServerAttach }; };
34
35   // getters for responses
36   Response* getResponse() { return reinterpret_cast <Response*>(getContext()); }
37   const Response* getResponse() const { return reinterpret_cast <const Response*>(getContext()); }
38
39   // getters for session (client-session at the moment)
40   Session* getSession() { return reinterpret_cast <Session*>(getContext()); }
41   const Session* getSession() const { return reinterpret_cast <const Session*>(getContext()); }
42
43   // getters for local server
44   LocalServer* getLocalServer() { return reinterpret_cast <LocalServer*>(getContext()); }
45   const LocalServer* getLocalServer() const { return reinterpret_cast <const LocalServer*>(getContext()); }
46
47   std::string asString() const ;
48
49 private:
50   Timer() {;}
51
52
53   Type::_v a_type;
54
55   void expire(anna::timex::Engine*) noexcept(false);
56
57   Type::_v getType() const { return a_type; }
58   void setType(const Type::_v type)  { a_type = type; }
59   static const char* asText(const Type::_v) ;
60
61
62   friend class TimerManager;
63   friend class anna::Allocator<Timer>;
64 };
65
66 }
67 }
68 }
69
70 #endif
71