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