Dynamic lib selection and deployment
[anna.git] / example / diameter / launcher / 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 example_diameter_launcher_OriginHost_hpp
10 #define example_diameter_launcher_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
22
23 namespace anna {
24   namespace diameter {
25     namespace codec {
26       class Engine;
27     }
28     namespace stack {
29       class Dictionary;
30     }
31     namespace comm {
32       class Message;
33     }
34   }
35 }
36
37
38 class MyDiameterEntity;
39 class MyDiameterEngine;
40 class MyLocalServer;
41
42
43 class OriginHost {
44
45   MyDiameterEngine *a_commEngine;
46   MyDiameterEntity *a_entity; // we could get it finding the unique instante within comm engine, but it is more comfortable assign here.
47   MyLocalServer* a_diameterServer; // idem
48   anna::diameter::codec::Engine *a_codecEngine;
49
50   // resources
51   int a_requestRetransmissions;
52   anna::Recycler<anna::diameter::comm::Message> a_commMessages;
53
54   // main
55   std::string a_originHost;
56   unsigned int a_applicationId;
57
58   // Timming
59   anna::Millisecond a_allowedInactivityTime;
60   anna::Millisecond a_tcpConnectDelay;
61   anna::Millisecond a_answersTimeout;
62   anna::Millisecond a_ceaTimeout;
63   anna::Millisecond a_watchdogPeriod;
64
65   // Logs & burst
66   std::string a_logFile;
67   bool a_splitLog, a_detailedLog, a_dumpLog;
68   std::string a_burstLogFile;
69   std::ofstream a_burstLogStream;
70   int a_burstCycle;
71   bool a_burstRepeat;
72   bool a_burstActive;
73   std::map < int /* dummy, p.e. used for order number */, anna::diameter::comm::Message* > a_burstMessages;
74   int a_burstLoadIndx;
75   std::map<int, anna::diameter::comm::Message*>::const_iterator a_burstDeliveryIt;
76   int a_otaRequest;
77   int a_burstPopCounter;
78
79 public:
80   OriginHost(const std::string &originHost, unsigned int applicationId, const anna::diameter::stack::Dictionary *baseProtocolDictionary);
81   ~OriginHost() {;}
82
83   const std::string &getName() const throw() { return a_originHost; }
84
85   // Core resources:
86   MyDiameterEngine* getMyDiameterEngine() const throw() { return a_commEngine; }
87   unsigned int getApplicationId() const throw() { return a_applicationId; }
88   anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; }
89
90   void createEntity(const std::string &entityRepresentation, const anna::Millisecond &bindTimeout, const anna::Millisecond &applicationTimeout) throw(anna::RuntimeException);
91   MyDiameterEntity *getEntity() const throw() { return a_entity; }
92   void startDiameterServer(const std::string &serverRepresentation, int sessions, const anna::Millisecond &inactivityTimeout, const anna::Millisecond &applicationTimeout, const std::string &ceaPathfile) throw(anna::RuntimeException);
93   MyLocalServer* getDiameterServer() throw() { return a_diameterServer; }
94   void setRequestRetransmissions(int r) throw() { if (r >= 0) a_requestRetransmissions = r; }
95
96   // Messages factory:
97   anna::diameter::comm::Message *createCommMessage() throw(anna::RuntimeException);
98   void releaseCommMessage(anna::diameter::comm::Message*) throw();
99
100   // Traffic logs & burst:
101   void setLogs(const std::string &log, bool splitLog, bool detailedLog, bool dumpLog, const std::string &burstLog) throw() {
102     a_logFile = log;
103     a_splitLog = splitLog;
104     a_detailedLog = detailedLog;
105     a_dumpLog = dumpLog;
106     a_burstLogFile = burstLog;
107   }
108
109   bool logEnabled() const throw() { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); }
110   void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw();
111   void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const throw();
112   void writeBurstLogFile(const std::string &buffer) throw();
113   bool burstLogEnabled() const throw() { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); }
114   int clearBurst() throw(); // returns removed
115   int loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException);
116   void repeatBurst(bool repeat) throw() { a_burstRepeat = repeat; }
117   int startBurst(int initialLoad) throw();  // return processed on start, or -1 if burst list is empty, -2 if invalid initial load (0 or negative)
118   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)
119   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)
120   int popBurst(int releaseAmount) throw(); // returns popped (perhaps is less than provided because of OTA request), or -1 if burst stopped
121   int stopBurst() throw(); // returns remaining on cycle, or -1 if burst already stopped
122   bool burstActive() const throw() { return a_burstActive; }
123   bool sendBurstMessage(bool anyway = false) throw();
124   std::string lookBurst(int order = -1) const throw();
125   std::string gotoBurst(int order) throw();
126
127   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
128   std::string asXMLString() const throw();
129 };
130
131 #endif