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