8338e0d162a44a596b00f0ba4e727b021e3740d5
[anna.git] / include / anna / diameter.comm / OriginHost.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_OriginHost_hpp
10 #define anna_diameter_comm_OriginHost_hpp
11
12 // Standard
13 #include <string>
14 #include <fstream>
15
16 // Project
17 #include <anna/core/util/Millisecond.hpp>
18 #include <anna/core/util/Recycler.hpp>
19 #include <anna/core/DataBlock.hpp>
20 #include <anna/diameter/codec/Message.hpp>
21 #include <anna/diameter.comm/Message.hpp>
22
23
24 namespace anna {
25   namespace diameter {
26     namespace codec {
27       class Engine;
28     }
29     namespace comm {
30       class Engine;
31       class Entity;
32       class LocalServer;
33
34 /**
35  * OriginHost with single access point for client and server
36  */
37 class OriginHost {
38
39   anna::diameter::comm::Engine *a_commEngine;
40   anna::diameter::comm::Entity *a_entity; // we could get it finding the unique instante within comm engine, but it is more comfortable assign here.
41   anna::diameter::comm::LocalServer* a_diameterServer; // idem
42   anna::diameter::codec::Engine *a_codecEngine;
43
44   // resources
45   int a_requestRetransmissions;
46   anna::Recycler<anna::diameter::comm::Message> a_commMessages;
47
48   // main
49   unsigned int a_applicationId;
50
51   // Logs & burst
52   std::string a_logFile;
53   bool a_splitLog, a_detailedLog, a_dumpLog;
54   std::string a_burstLogFile;
55   std::ofstream a_burstLogStream;
56   int a_burstCycle;
57   bool a_burstRepeat;
58   bool a_burstActive;
59   std::map < int /* dummy, p.e. used for order number */, anna::diameter::comm::Message* > a_burstMessages;
60   int a_burstLoadIndx;
61   std::map<int, anna::diameter::comm::Message*>::const_iterator a_burstDeliveryIt;
62   int a_otaRequest;
63   int a_burstPopCounter;
64
65 public:
66   OriginHost(anna::diameter::comm::Engine* commEngine, unsigned int applicationId);
67   ~OriginHost() {;}
68
69   // OriginHost name:
70   const std::string &getName() const throw();
71
72   // Core resources:
73   anna::diameter::comm::Engine* getCommEngine() const throw() { return a_commEngine; }
74   unsigned int getApplicationId() const throw() { return a_applicationId; }
75   anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; }
76
77   void createEntity(const std::string &entityRepresentation, const anna::Millisecond &bindTimeout, const anna::Millisecond &applicationTimeout) throw(anna::RuntimeException);
78   anna::diameter::comm::Entity *getEntity() const throw() { return a_entity; }
79
80   void createDiameterServer(const std::string &serverRepresentation, int sessions, const anna::Millisecond &inactivityTimeout, const anna::Millisecond &applicationTimeout, const std::string &ceaPathfile) throw(anna::RuntimeException);
81   anna::diameter::comm::LocalServer* getDiameterServer() throw() { return a_diameterServer; }
82   void setRequestRetransmissions(int r) throw() { if (r >= 0) a_requestRetransmissions = r; }
83
84   // Messages factory:
85   anna::diameter::comm::Message *createCommMessage() throw(anna::RuntimeException);
86   void releaseCommMessage(anna::diameter::comm::Message*) throw();
87
88   // Traffic logs & burst:
89   void setLogs(const std::string &log, bool splitLog, bool detailedLog, bool dumpLog, const std::string &burstLog) throw() {
90     a_logFile = log;
91     a_splitLog = splitLog;
92     a_detailedLog = detailedLog;
93     a_dumpLog = dumpLog;
94     a_burstLogFile = burstLog;
95   }
96
97   bool logEnabled() const throw() { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); }
98   void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw();
99   void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const throw();
100   void writeBurstLogFile(const std::string &buffer) throw();
101   bool burstLogEnabled() const throw() { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); }
102   int clearBurst() throw(); // returns removed
103   int loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException);
104   void repeatBurst(bool repeat) throw() { a_burstRepeat = repeat; }
105   int startBurst(int initialLoad) throw();  // return processed on start, or -1 if burst list is empty, -2 if invalid initial load (0 or negative)
106   int pushBurst(int loadAmount) throw(); // returns pushed (perhaps is less than provided because of no repeat mode and burst list exhausted), or -1 if burst list is empty, -2 if invalid load (0 or negative)
107   int sendBurst(int loadAmount) throw(); // returns sent (burst always cycled using send), returns -1 if burst list is empty, -2 if invalid load (0 or negative)
108   int popBurst(int releaseAmount) throw(); // returns popped (perhaps is less than provided because of OTA request), or -1 if burst stopped
109   int stopBurst() throw(); // returns remaining on cycle, or -1 if burst already stopped
110   bool burstActive() const throw() { return a_burstActive; }
111   bool sendBurstMessage(bool anyway = false) throw();
112   std::string lookBurst(int order = -1) const throw();
113   std::string gotoBurst(int order) throw();
114
115   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
116   std::string asXMLString() const throw();
117 };
118
119 }
120 }
121 }
122
123 #endif