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