Clarify
[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  * That is to say: only one communication engine, then:
37  * - For client: one CER, then one application Id
38  * - For server: no app id control, and multiple serverSession overwrites tsw server session (TestManager), no way to distinguish with single port ...
39  */
40 class OriginHost {
41
42   anna::diameter::comm::Engine *a_commEngine;
43   anna::diameter::comm::Entity *a_entity; // we could get it finding the unique instante within comm engine, but it is more comfortable assign here.
44   anna::diameter::comm::LocalServer* a_diameterServer; // idem
45   anna::diameter::codec::Engine *a_codecEngine;
46
47   // resources
48   int a_requestRetransmissions;
49   anna::Recycler<anna::diameter::comm::Message> a_commMessages;
50
51   // main
52   unsigned int a_applicationId;
53
54   // Logs & burst
55   std::string a_logFile;
56   bool a_splitLog, a_detailedLog, a_dumpLog;
57   std::string a_burstLogFile;
58   std::ofstream a_burstLogStream;
59   int a_burstCycle;
60   bool a_burstRepeat;
61   bool a_burstActive;
62   std::map < int /* dummy, p.e. used for order number */, anna::diameter::comm::Message* > a_burstMessages;
63   int a_burstLoadIndx;
64   std::map<int, anna::diameter::comm::Message*>::const_iterator a_burstDeliveryIt;
65   int a_otaRequest;
66   int a_burstPopCounter;
67
68 public:
69   OriginHost(anna::diameter::comm::Engine* commEngine, unsigned int applicationId);
70   ~OriginHost() {;}
71
72   // OriginHost name:
73   const std::string &getName() const throw();
74
75   // Core resources:
76   anna::diameter::comm::Engine* getCommEngine() const throw() { return a_commEngine; }
77   unsigned int getApplicationId() const throw() { return a_applicationId; }
78   anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; }
79
80   void createEntity(const std::string &entityRepresentation, const anna::Millisecond &bindTimeout, const anna::Millisecond &applicationTimeout) throw(anna::RuntimeException);
81   anna::diameter::comm::Entity *getEntity() const throw() { return a_entity; }
82
83   void createDiameterServer(const std::string &serverRepresentation, int sessions, const anna::Millisecond &inactivityTimeout, const anna::Millisecond &applicationTimeout, const std::string &ceaPathfile) throw(anna::RuntimeException);
84   anna::diameter::comm::LocalServer* getDiameterServer() throw() { return a_diameterServer; }
85   void setRequestRetransmissions(int r) throw() { if (r >= 0) a_requestRetransmissions = r; }
86
87   // Messages factory:
88   anna::diameter::comm::Message *createCommMessage() throw(anna::RuntimeException);
89   void releaseCommMessage(anna::diameter::comm::Message*) throw();
90
91   // Traffic logs & burst:
92   void setLogs(const std::string &log, bool splitLog, bool detailedLog, bool dumpLog, const std::string &burstLog) throw() {
93     a_logFile = log;
94     a_splitLog = splitLog;
95     a_detailedLog = detailedLog;
96     a_dumpLog = dumpLog;
97     a_burstLogFile = burstLog;
98   }
99
100   bool logEnabled() const throw() { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); }
101   void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw();
102   void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const throw();
103   void writeBurstLogFile(const std::string &buffer) throw();
104   bool burstLogEnabled() const throw() { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); }
105   int clearBurst() throw(); // returns removed
106   int loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException);
107   void repeatBurst(bool repeat) throw() { a_burstRepeat = repeat; }
108   int startBurst(int initialLoad) throw();  // return processed on start, or -1 if burst list is empty, -2 if invalid initial load (0 or negative)
109   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)
110   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)
111   int popBurst(int releaseAmount) throw(); // returns popped (perhaps is less than provided because of OTA request), or -1 if burst stopped
112   int stopBurst() throw(); // returns remaining on cycle, or -1 if burst already stopped
113   bool burstActive() const throw() { return a_burstActive; }
114   bool sendBurstMessage(bool anyway = false) throw();
115   std::string lookBurst(int order = -1) const throw();
116   std::string gotoBurst(int order) throw();
117
118   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
119   std::string asXMLString() const throw();
120 };
121
122 }
123 }
124 }
125
126 #endif