Preparing for multistack
[anna.git] / example / diameter / launcher / Launcher.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_Launcher_hpp
10 #define example_diameter_launcher_Launcher_hpp
11
12 // Standard
13 #include <string>
14 #include <map>
15 #include <fstream>
16
17 // Project
18 #include <anna/core/core.hpp>
19 #include <anna/comm/comm.hpp>
20 #include <anna/diameter.comm/Entity.hpp>
21 #include <anna/time/Date.hpp>
22 #include <anna/timex/Engine.hpp>
23
24 namespace anna {
25   namespace diameter {
26     namespace comm {
27       //class Entity;
28       //class Response;
29       class LocalServer;
30     }
31   }
32 }
33
34 // Process
35 #include "MyCommunicator.hpp"
36 #include "MyCounterRecorder.hpp"
37 #include "MyDiameterEngine.hpp"
38
39
40 class Launcher : public anna::comm::Application {
41
42   MyCommunicator *a_communicator;
43   MyDiameterEngine *a_myDiameterEngine;
44   MyDiameterEntity *a_entity;
45   anna::diameter::codec::Engine *a_codecEngine;
46   std::string a_logFile, a_burstLogFile;
47   std::ofstream a_burstLogStream;
48   bool a_splitLog, a_detailedLog, a_dumpLog;
49   anna::time::Date a_start_time;
50   anna::timex::Engine* a_timeEngine;
51   MyCounterRecorder *a_counterRecorder;
52   MyCounterRecorderClock *a_counterRecorderClock;
53   std::string a_cerPathfile;
54   std::string a_dwrPathfile;
55
56   // Burst feature
57   int a_burstCycle;
58   bool a_burstRepeat;
59   bool a_burstActive;
60   std::map < int /* dummy, p.e. used for order number */, anna::diameter::comm::Message* > a_burstMessages;
61   int a_burstLoadIndx;
62   std::map<int, anna::diameter::comm::Message*>::const_iterator a_burstDeliveryIt;
63   int a_otaRequest;
64   int a_burstPopCounter;
65
66   // comm Messages factory:
67   anna::Recycler<anna::diameter::comm::Message> a_commMessages;
68
69   anna::comm::ServerSocket* a_httpServerSocket; // HTTP
70   MyLocalServer* a_diameterLocalServer; // DIAMETER
71   void checkTimeMeasure(const char * commandLineParameter, bool optional = true) throw(anna::RuntimeException);
72   void initialize() throw(anna::RuntimeException); // HTTP
73   void run() throw(anna::RuntimeException);
74
75 public:
76   Launcher();
77
78   anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; } // XXXXXXXXXXXXXXXXX El del nodo de trabajo
79   MyCommunicator *getCommunicator() throw() { return a_communicator; }
80   MyDiameterEngine* getMyDiameterEngine() const throw() { return (a_myDiameterEngine); }
81   void baseProtocolSetupAsClient(anna::diameter::codec::Engine *codecEngine) throw(anna::RuntimeException);
82   MyDiameterEntity *getEntity() throw() { return a_entity; }
83   MyLocalServer* getDiameterLocalServer() throw() { return a_diameterLocalServer; }
84   void eventOperation(const std::string &, std::string &) throw(anna::RuntimeException);
85   bool logEnabled() const throw() { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); }
86   void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail, anna::diameter::codec::Engine *codecEngine) const throw();
87   void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const throw();
88   void writeBurstLogFile(const std::string &buffer) throw();
89   bool burstLogEnabled() const throw() { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); }
90   void startDiameterServer(int) throw(anna::RuntimeException);
91   void forceCountersRecord() throw(anna::RuntimeException) { if (a_counterRecorderClock) a_counterRecorderClock->tick(); }
92
93   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
94   void resetStatistics() throw() { a_myDiameterEngine->resetStatistics(); }
95   void resetCounters() throw();
96   void signalUSR2() throw(anna::RuntimeException);
97   std::string help() const throw();
98
99   // Messages factory:
100   anna::diameter::comm::Message *createCommMessage() throw(anna::RuntimeException);
101   void releaseCommMessage(anna::diameter::comm::Message*) throw();
102
103   // helpers
104   bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) const throw();
105
106   // Burst feature
107   int clearBurst() throw(); // returns removed
108   int loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException);
109   void repeatBurst(bool repeat) throw() { a_burstRepeat = repeat; }
110   int startBurst(int initialLoad) throw();  // return processed on start, or -1 if burst list is empty, -2 if invalid initial load (0 or negative)
111   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)
112   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)
113   int popBurst(int releaseAmount) throw(); // returns popped (perhaps is less than provided because of OTA request), or -1 if burst stopped
114   int stopBurst() throw(); // returns remaining on cycle, or -1 if burst already stopped
115   bool burstActive() const throw() { return a_burstActive; }
116   bool sendBurstMessage(bool anyway = false) throw();
117   std::string lookBurst(int order) const throw();
118   std::string gotoBurst(int order) throw();
119 };
120
121 #endif