ANNA Suite  2020b
Multipurpose development suite for Telco applications
Resource.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_core_mt_Resource_hpp
10 #define anna_core_mt_Resource_hpp
11 
12 #include <anna/core/mt/Mutex.hpp>
13 #include <anna/core/mt/Guard.hpp>
14 #include <anna/config/defines.hpp>
16 
17 namespace anna {
18 
19 namespace xml {
20 class Node;
21 }
22 
26 class Resource : public Mutex {
27 public:
35  Resource(const std::string& name) :
36  Mutex(),
37  a_name(name),
38  a_isEnabled(true),
39  a_timeStamp(0)
40  {;}
41 
46  const std::string& getName() const { return a_name; }
47 
58  bool isEnabled() const { return a_isEnabled; }
59 
67  void setTimeStamp(const Millisecond &timeStamp) { a_timeStamp = timeStamp; }
68 
69  /*
70  * Devuelve la marca de tiempo asociada al recurso.
71  * \return la marca de tiempo asociada al recurso.
72  */
73  const Millisecond &getTimeStamp() const { return a_timeStamp; }
74 
81  bool operator == (const std::string& name) const { return a_name == name; }
82 
89  bool operator == (const Resource& other) const { return a_name == other.a_name; }
90 
97  void enable() noexcept(false) { Guard guard(this, "Resource"); a_isEnabled = true; }
98 
103  void disable() noexcept(false) { Guard guard(this, "Resource"); a_isEnabled = false; }
104 
109  virtual std::string asString() const ;
110 
121  virtual bool isAvailable() const noexcept(false) = 0;
122 
123 private:
124  const std::string a_name;
125  bool a_isEnabled;
126  Millisecond a_timeStamp;
127 };
128 
129 }
130 
131 #endif
void setTimeStamp(const Millisecond &timeStamp)
Definition: Resource.hpp:67
Definition: Millisecond.hpp:24
Resource(const std::string &name)
Definition: Resource.hpp:35
const std::string & getName() const
Definition: Resource.hpp:46
void enable() noexcept(false)
Definition: Resource.hpp:97
const Millisecond & getTimeStamp() const
Definition: Resource.hpp:73
void disable() noexcept(false)
Definition: Resource.hpp:103
xml::Node Node
Definition: Node.hpp:21
Definition: app.hpp:12
Definition: Guard.hpp:35
Definition: Resource.hpp:26
Definition: Mutex.hpp:41
bool isEnabled() const
Definition: Resource.hpp:58