NEW Restruct launcher source code. Separate classes in different files to improve...
[anna.git] / example / diameter / launcher / Launcher.hpp
index e69de29..9a61627 100644 (file)
@@ -0,0 +1,111 @@
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
+
+
+#ifndef example_diameter_launcher_Launcher_hpp
+#define example_diameter_launcher_Launcher_hpp
+
+// Standard
+#include <string>
+#include <map>
+#include <fstream>
+
+// Project
+#include <anna/comm/comm.hpp>
+#include <anna/diameter.comm/Entity.hpp>
+#include <anna/time/Date.hpp>
+#include <anna/timex/Engine.hpp>
+
+namespace anna {
+  namespace diameter {
+    namespace comm {
+      //class Entity;
+      //class Response;
+      class LocalServer;
+    }
+  }
+}
+
+// Process
+#include "MyCommunicator.hpp"
+#include "MyCounterRecorder.hpp"
+#include "MyDiameterEngine.hpp"
+
+
+class Launcher : public anna::comm::Application {
+
+  MyCommunicator *a_communicator;
+  MyDiameterEngine *a_myDiameterEngine;
+  MyDiameterEntity *a_entity;
+  std::string a_logFile, a_burstLogFile;
+  std::ofstream a_burstLogStream;
+  bool a_splitLog, a_detailedLog, a_dumpLog;
+  anna::time::Date a_start_time;
+  anna::timex::Engine* a_timeEngine;
+  MyCounterRecorder *a_counterRecorder;
+  MyCounterRecorderClock *a_counterRecorderClock;
+  std::string a_cerPathfile;
+  std::string a_dwrPathfile;
+
+  // Burst feature
+  int a_burstCycle;
+  bool a_burstRepeat;
+  bool a_burstActive;
+  std::map < int /* dummy, p.e. used for order number */, anna::diameter::comm::Message* > a_burstMessages;
+  int a_burstLoadIndx;
+  std::map<int, anna::diameter::comm::Message*>::const_iterator a_burstDeliveryIt;
+  int a_otaRequest;
+  int a_burstPopCounter;
+
+  anna::comm::ServerSocket* a_httpServerSocket; // HTTP
+  MyLocalServer* a_diameterLocalServer; // DIAMETER
+  void checkTimeMeasure(const char * commandLineParameter, bool optional = true) throw(anna::RuntimeException);
+  void initialize() throw(anna::RuntimeException); // HTTP
+  void run() throw(anna::RuntimeException);
+
+public:
+  Launcher();
+
+  MyCommunicator *getCommunicator() throw() { return a_communicator; }
+  MyDiameterEngine* getMyDiameterEngine() const throw() { return (a_myDiameterEngine); }
+  void baseProtocolSetupAsClient(void) throw(anna::RuntimeException);
+  MyDiameterEntity *getEntity() throw() { return a_entity; }
+  MyLocalServer* getDiameterLocalServer() throw() { return a_diameterLocalServer; }
+  void eventOperation(const std::string &, std::string &) throw(anna::RuntimeException);
+  bool logEnabled() const throw() { return (((a_logFile == "") || (a_logFile == "null")) ? false : true); }
+  void writeLogFile(const anna::DataBlock & db, const std::string &logExtension, const std::string &detail) const throw();
+  void writeLogFile(const anna::diameter::codec::Message & decodedMessage, const std::string &logExtension, const std::string &detail) const throw();
+  void writeBurstLogFile(const std::string &buffer) throw();
+  bool burstLogEnabled() const throw() { return (((a_burstLogFile == "") || (a_burstLogFile == "null")) ? false : true); }
+  void startDiameterServer(int) throw(anna::RuntimeException);
+  void forceCountersRecord() throw(anna::RuntimeException) { if (a_counterRecorderClock) a_counterRecorderClock->tick(); }
+
+  anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
+  void resetStatistics() throw() { a_myDiameterEngine->resetStatistics(); }
+  void resetCounters() throw();
+  void signalUSR2() throw(anna::RuntimeException);
+  std::string help() const throw();
+
+  // helpers
+  bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) const throw();
+
+  // Burst feature
+  int clearBurst() throw(); // returns removed
+  int loadBurstMessage(const anna::DataBlock & db) throw(anna::RuntimeException);
+  void repeatBurst(bool repeat) throw() { a_burstRepeat = repeat; }
+  int startBurst(int initialLoad) throw();  // return processed on start, or -1 if burst list is empty, -2 if invalid initial load (0 or negative)
+  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)
+  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)
+  int popBurst(int releaseAmount) throw(); // returns popped (perhaps is less than provided because of OTA request), or -1 if burst stopped
+  int stopBurst() throw(); // returns remaining on cycle, or -1 if burst already stopped
+  bool burstActive() const throw() { return a_burstActive; }
+  bool sendBurstMessage(bool anyway = false) throw();
+  std::string lookBurst(int order) const throw();
+  std::string gotoBurst(int order) throw();
+};
+
+#endif