Fixes and improvs. Basic DRA feature.
[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
22 // Process
23 #include <MyCommunicator.hpp>
24 #include <MyCounterRecorder.hpp>
25 #include <TestManager.hpp>
26
27
28 namespace anna {
29   namespace timex {
30     class Engine;
31   }
32   namespace diameter {
33     namespace codec {
34       class Engine;
35     }
36   }
37 }
38
39 class TestManager;
40
41 // RealmNode resources
42 class RealmNode;
43 typedef std::map<std::string, RealmNode*> realm_nodes_t;
44 typedef std::map<std::string, RealmNode*>::const_iterator realm_nodes_it;
45 typedef std::map<std::string, RealmNode*>::iterator realm_nodes_nc_it;
46
47
48 class Launcher : public anna::comm::Application {
49
50   // Start time:
51   anna::time::Date a_start_time;
52
53   // Core engines:
54   MyCommunicator *a_communicator;
55   anna::diameter::codec::Engine *a_codecEngine;
56   anna::diameter::stack::Dictionary *a_baseProtocolDictionary;
57   anna::timex::Engine* a_timeEngine;
58   MyCounterRecorder *a_counterRecorder;
59   anna::Millisecond a_admlMinResolution;
60   MyCounterRecorderClock *a_counterRecorderClock;
61
62   // Nodes deployment:
63   realm_nodes_t a_nodes;
64   RealmNode *a_workingNode;
65
66   // comm resources:
67   anna::comm::ServerSocket* a_httpServerSocket; // HTTP
68
69   const anna::Millisecond &getADMLMinResolution() const throw() { return a_admlMinResolution; }
70
71   void servicesFromXML(const anna::xml::Node* servicesNode, bool eventOperation) throw(anna::RuntimeException);
72   anna::Millisecond checkTimeMeasure(const std::string &parameter, const std::string &value) throw(anna::RuntimeException);
73   void initialize() throw(anna::RuntimeException); // HTTP
74   void run() throw(anna::RuntimeException);
75
76 public:
77   Launcher();
78
79   void loadServices(const std::string & xmlPathFile, bool eventOperation = false) throw(anna::RuntimeException);
80   void startServices() throw(anna::RuntimeException);
81
82   anna::diameter::codec::Engine *getCodecEngine() const throw() { return a_codecEngine; }
83   //anna::diameter::stack::Dictionary *getBaseProtocolDictionary() const throw() { return a_baseProtocolDictionary; }
84   RealmNode *getWorkingNode() const throw(anna::RuntimeException); // management operations working node
85   bool setWorkingNode(const std::string &name) throw(); // we could update ignoreFlagsOnValidation/integrationAndDebugging over the global codec engine
86                                                         //  but finally, that configuration issues will be global to the process.
87
88   RealmNode *getRealmNode(const std::string &realmName) const throw();
89
90
91   MyCommunicator *getCommunicator() throw() { return a_communicator; }
92   void eventOperation(const std::string &, std::string &) throw(anna::RuntimeException);
93   void forceCountersRecord() throw(anna::RuntimeException) { if (a_counterRecorderClock) a_counterRecorderClock->tick(); }
94
95   anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
96   void resetStatistics() throw();
97   void resetCounters() throw();
98   void signalUSR2() throw(anna::RuntimeException);
99   std::string help() const throw();
100
101   // helpers
102   bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) const throw();
103
104   friend class TestManager;
105 };
106
107 #endif