ANNA Suite  2020b
Multipurpose development suite for Telco applications
Component.hpp
Go to the documentation of this file.
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 anna_app_Component_hpp
10 #define anna_app_Component_hpp
11 
12 #include <vector>
14 #include <anna/app/Application.hpp>
15 
16 namespace anna {
17 
18 namespace xml {
19 class Node;
20 }
21 
22 namespace app {
23 
44 class Component : public anna::Component {
45 public:
49  virtual ~Component();
50 
56  void attach() noexcept(false);
57 
62  virtual std::string asString() const ;
63 
69  virtual xml::Node* asXML(xml::Node* parent) const ;
70 
71 protected:
76  struct State { enum _v { Stopped, Starting, Running }; };
77 
82  explicit Component(const char* className);
83 
88  State::_v getState() const { return a_state; }
89 
95  void addPredecessor(const char* componentName) ;
96 
101  void initialize() noexcept(false);
102 
110  void stop() { a_state = State::Stopped; do_stop(); }
111 
118  virtual void kill() { stop(); }
119 
120 private:
121  typedef std::vector <std::string>::iterator iterator;
122 
123  State::_v a_state;
124  std::vector <std::string> a_predecessors;
125 
126  Component(const Component& other);
127  iterator begin() { return a_predecessors.begin(); }
128  iterator end() { return a_predecessors.end(); }
129  const std::string& data(iterator& ii) { return *ii; }
130 
135  virtual void do_initialize() noexcept(false) = 0;
136 
143  virtual void do_stop() = 0;
144 
150  virtual void do_cloneParent() noexcept(false) { ; }
151 
157  virtual void do_cloneChild() noexcept(false) { ; }
158 
159  friend void Application::startComponents() noexcept(false);
160  friend void Application::stopComponents() noexcept(false);
161  friend void Application::attach(Component*) noexcept(false);
162  friend Application& Application::clone() noexcept(false);
163 };
164 
165 }
166 }
167 
168 #endif
Definition: Application.hpp:35
Definition: Node.hpp:56
virtual void kill()
Definition: Component.hpp:118
void stop()
Definition: Component.hpp:110
Definition: Component.hpp:76
Definition: Component.hpp:39
xml::Node Node
Definition: Node.hpp:21
Definition: app.hpp:12
Definition: Component.hpp:44
Definition: Component.hpp:76
_v
Definition: Component.hpp:76
State::_v getState() const
Definition: Component.hpp:88