Multistack launcher
[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; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
54   std::string a_dwrPathfile; // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
55   std::string a_workingNode; // this is the node name (usually equals to the Origin-Realm value
56
57   // Burst feature
58   int a_burstCycle;
59   bool a_burstRepeat;
60   bool a_burstActive;
61   std::map < int /* dummy, p.e. used for order number */, anna::diameter::comm::Message* > a_burstMessages; // XXXXXXXXXXXXXXXXXXXXX
62   int a_burstLoadIndx;
63   std::map<int, anna::diameter::comm::Message*>::const_iterator a_burstDeliveryIt;
64   int a_otaRequest;
65   int a_burstPopCounter;
66
67   // comm Messages factory:
68   anna::Recycler<anna::diameter::comm::Message> a_commMessages;
69
70   anna::comm::ServerSocket* a_httpServerSocket; // HTTP
71   MyLocalServer* a_diameterLocalServer; // DIAMETER  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
72   void checkTimeMeasure(const char * commandLineParameter, bool optional = true) throw(anna::RuntimeException);
73   void initialize() throw(anna::RuntimeException); // HTTP
74   void run() throw(anna::RuntimeException);
75
76 public:
77   Launcher();
78
79   anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; }
80   std::string getWorkingNode() const throw() { return a_workingNode; }
81   void setWorkingNode(const std::string &node) throw() { a_workingNode = node; }
82   MyCommunicator *getCommunicator() throw() { return a_communicator; }
83   MyDiameterEngine* getMyDiameterEngine() const throw() { return (a_myDiameterEngine); }
84   void baseProtocolSetupAsClient(void) throw(anna::RuntimeException);
85   MyDiameterEntity *getEntity() throw() { return a_entity; } // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
86   MyLocalServer* getDiameterLocalServer() throw() { return a_diameterLocalServer; } // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
87   void eventOperation(const std::string &, std::string &) throw(anna::RuntimeException);
88   bool logEnabled() const throw() { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); }
89   void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw(); // XXXXXXXXXXXXXXXXXXXXX
90   void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const throw(); // XXXXXXXXXXXXXXXXXX
91   void writeBurstLogFile(const std::string &buffer) throw();
92   bool burstLogEnabled() const throw() { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); }
93   void startDiameterServer(int) throw(anna::RuntimeException); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
94   void forceCountersRecord() throw(anna::RuntimeException) { if (a_counterRecorderClock) a_counterRecorderClock->tick(); }
95
96   anna::xml::Node* asXML(anna::xml::Node* parent) const throw(); // XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
97   void resetStatistics() throw() { a_myDiameterEngine->resetStatistics(); }
98   void resetCounters() throw();
99   void signalUSR2() throw(anna::RuntimeException);
100   std::string help() const throw();
101
102   // Messages factory:
103   anna::diameter::comm::Message *createCommMessage() throw(anna::RuntimeException);
104   void releaseCommMessage(anna::diameter::comm::Message*) throw();
105
106   // helpers
107   bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) const throw();
108
109   // Burst feature
110   int clearBurst() throw(); // returns removed
111   int loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException);
112   void repeatBurst(bool repeat) throw() { a_burstRepeat = repeat; }
113   int startBurst(int initialLoad) throw();  // return processed on start, or -1 if burst list is empty, -2 if invalid initial load (0 or negative)
114   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)
115   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)
116   int popBurst(int releaseAmount) throw(); // returns popped (perhaps is less than provided because of OTA request), or -1 if burst stopped
117   int stopBurst() throw(); // returns remaining on cycle, or -1 if burst already stopped
118   bool burstActive() const throw() { return a_burstActive; }
119   bool sendBurstMessage(bool anyway = false) throw();
120   std::string lookBurst(int order) const throw();
121   std::string gotoBurst(int order) throw();
122 };
123
124 #endif