Allow to log statistics samples as a event operation
[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 <fstream>
14 #include <string>
15 #include <map>
16
17 // Project
18 #include <anna/core/core.hpp>
19 #include <anna/comm/comm.hpp>
20 #include <anna/time/Date.hpp>
21 #include <anna/diameter/codec/Message.hpp>
22
23 // Process
24 #include <MyCommunicator.hpp>
25 #include <MyCounterRecorder.hpp>
26 #include <TestManager.hpp>
27
28
29 #define SH_COMMAND_TAG_FOR_REPLACE__CYCLE_ID    "##cycleid##"
30 #define SH_COMMAND_TAG_FOR_REPLACE__TESTCASE_ID "##testcaseid##"
31 #define SH_COMMAND_TAG_FOR_REPLACE__TESTSTEP_ID "##teststepid##"
32
33
34 namespace anna {
35   namespace timex {
36     class Engine;
37   }
38   namespace diameter {
39     namespace codec {
40       class Engine;
41     }
42   }
43 }
44
45 class TestManager;
46 class OriginHost;
47 class MyDiameterEntity;
48 class MyLocalServer;
49 class MyDiameterEngine;
50
51 // OriginHost resources
52 class OriginHost;
53 typedef std::map<std::string, OriginHost*> origin_hosts_t;
54 typedef std::map<std::string, OriginHost*>::const_iterator origin_hosts_it;
55 typedef std::map<std::string, OriginHost*>::iterator origin_hosts_nc_it;
56
57
58 class Launcher : public anna::comm::Application {
59
60   // Start time:
61   anna::time::Date a_start_time;
62   std::string a_initialWorkingDirectory;
63
64   // Core engines:
65   MyCommunicator *a_communicator;
66   anna::timex::Engine* a_timeEngine;
67   MyCounterRecorder *a_counterRecorder;
68   anna::Millisecond a_admlMinResolution;
69   MyCounterRecorderClock *a_counterRecorderClock;
70
71   // Nodes deployment:
72   origin_hosts_t a_originHosts;
73   OriginHost *a_workingNode;
74   OriginHost *a_operatedHost; // auxiliary for eventOperation
75
76   // comm resources:
77   anna::comm::ServerSocket* a_httpServerSocket; // HTTP
78
79   const anna::Millisecond &getADMLMinResolution() const throw() { return a_admlMinResolution; }
80
81   std::string getSignalUSR2InputFile() const throw();
82   std::string getSignalUSR2OutputFile() const throw();
83
84   void servicesFromXML(const anna::xml::Node* servicesNode, bool eventOperation) throw(anna::RuntimeException);
85   anna::Millisecond checkTimeMeasure(const std::string &parameter, const std::string &value) throw(anna::RuntimeException);
86   void initialize() throw(anna::RuntimeException); // HTTP
87   void run() throw(anna::RuntimeException);
88
89
90
91 public:
92   Launcher();
93   //~Launcher(); TODO
94
95   void loadServices(const std::string & xmlPathFile, bool eventOperation = false) throw(anna::RuntimeException);
96   void startServices() throw(anna::RuntimeException);
97
98   bool setWorkingNode(const std::string &name) throw();
99   OriginHost *getOriginHost(const std::string &oh) const throw(anna::RuntimeException);
100   OriginHost *getOriginHost(const anna::diameter::codec::Message &message) const throw(anna::RuntimeException);
101   bool uniqueOriginHost() const throw() { return (a_originHosts.size() == 1); }
102
103   // Operated host for communication resources smart assignment ////////////////////////////////////////////////////////////
104   void updateOperatedOriginHostWithMessage(const anna::diameter::codec::Message &message) throw(anna::RuntimeException);
105   OriginHost *getOperatedHost() const throw(anna::RuntimeException);
106   MyDiameterEntity *getOperatedEntity() const throw(anna::RuntimeException);
107   MyLocalServer *getOperatedServer() const throw(anna::RuntimeException);
108   MyDiameterEngine *getOperatedEngine() const throw(anna::RuntimeException);
109   ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
110
111
112   MyCommunicator *getCommunicator() throw() { return a_communicator; }
113   void eventOperation(const std::string &, std::string &) throw(anna::RuntimeException);
114   void forceCountersRecord() throw(anna::RuntimeException) { if (a_counterRecorderClock) a_counterRecorderClock->tick(); }
115   void logStatisticsSamples(const std::string &conceptsList) throw();
116
117
118   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
119   void resetStatistics() throw();
120   void resetCounters() throw();
121   void signalUSR2() throw(anna::RuntimeException);
122   std::string help() const throw();
123   anna::xml::Node* oamAsXML(anna::xml::Node* parent) const throw();
124   anna::xml::Node* statsAsXML(anna::xml::Node* parent) const throw();
125
126   // helpers
127   bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) const throw();
128
129   friend class TestManager;
130 };
131
132 #endif