ANNA Suite  2020b
Multipurpose development suite for Telco applications
Command.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_diameter_stack_Command_hpp
10 #define anna_diameter_stack_Command_hpp
11 
12 
13 // Local
17 
19 #include <anna/config/defines.hpp>
20 
21 // STL
22 #include <string>
23 #include <map>
24 
25 
26 
27 namespace anna {
28 namespace xml {
29 class Node;
30 }
31 }
32 
33 
34 namespace anna {
35 
36 namespace diameter {
37 
38 namespace stack {
39 
40 class Dictionary;
41 
42 //------------------------------------------------------------------------------
43 //---------------------------------------------------------------- class Command
44 //------------------------------------------------------------------------------
48 class Command {
49 
50 public:
51 
52  //typedef std::map<AvpId, AvpRule> avprule_container;
53  typedef std::map < int /*position*/, AvpRule > avprule_container;
54  typedef avprule_container::iterator avprule_iterator;
55  typedef avprule_container::const_iterator const_avprule_iterator;
56 
57 
58 private:
59 
60  const Dictionary *a_dictionary;
61  CommandId a_id;
62  std::string a_name;
63 
64  // Children:
65  avprule_container a_avprules;
66  bool a_allowFixedRule;
67  int a_avprulePosition;
68 
69  void _initializeRules() {
70  a_avprules.clear();
71  a_allowFixedRule = true;
72  a_avprulePosition = 0;
73  }
74 
75  void _initialize(const Dictionary *d) {
76  a_dictionary = d;
77  _initializeRules();
78  }
79 
80 public:
81 
82  Command(const Dictionary *d = NULL) { _initialize(d); }
83  ~Command() {};
84 
85 
86  // get
87  const CommandId & getId(void) const { return a_id; }
88  const std::string & getName(void) const { return a_name; }
89 
90 
91  // containers
92  const_avprule_iterator avprule_begin() const { return a_avprules.begin(); }
93  const_avprule_iterator avprule_end() const { return a_avprules.end(); }
94  int avprule_size() const { return a_avprules.size(); }
95 
96 
97  // helpers
98  bool isEmpty(void) const { return (!a_avprules.size()); }
99  bool isRequest(void) const { return (a_id.second); }
100  bool isAnswer(void) const { return (!a_id.second); }
101  bool isChild(const AvpId & avp) const ;
102 
103  std::string asString(void) const ;
104  anna::xml::Node* asXML(anna::xml::Node* parent) const ;
105 
106  // operators
107 
108  // set
109  void initialize(const Dictionary *d = NULL) { _initialize(d); }
110  void setCode(const U24 & c) noexcept(false) {
111 
112  a_id.first = c;
113  }
114  void setRequest(bool r = true) { a_id.second = r; }
115  void setAnswer(bool a = true) { a_id.second = a; }
116  void setName(const std::string & n) noexcept(false) {
117  if(n == "") throw anna::RuntimeException("Empty command-name string not allowed", ANNA_FILE_LOCATION);
118 
119  a_name = n;
120  }
121  void addAvpRule(const AvpRule & avpRule) noexcept(false);
122 };
123 
124 
125 }
126 }
127 }
128 
129 
130 #endif
const CommandId & getId(void) const
Definition: Command.hpp:87
Definition: Node.hpp:56
bool isAnswer(void) const
Definition: Command.hpp:100
avprule_container::iterator avprule_iterator
Definition: Command.hpp:54
void setAnswer(bool a=true)
Definition: Command.hpp:115
const_avprule_iterator avprule_end() const
Definition: Command.hpp:93
void clear(void)
Definition: Dictionary.hpp:212
Command(const Dictionary *d=NULL)
Definition: Command.hpp:82
bool isEmpty(void) const
Definition: Command.hpp:98
void setRequest(bool r=true)
Definition: Command.hpp:114
std::pair< S32, S32 > AvpId
Definition: defines.hpp:31
void setName(const std::string &n) noexcept(false)
Definition: Command.hpp:116
int avprule_size() const
Definition: Command.hpp:94
const_avprule_iterator avprule_begin() const
Definition: Command.hpp:92
U32 U24
Definition: defines.hpp:96
std::map< int, AvpRule > avprule_container
Definition: Command.hpp:53
~Command()
Definition: Command.hpp:83
bool isRequest(void) const
Definition: Command.hpp:99
xml::Node Node
Definition: Node.hpp:21
Definition: Dictionary.hpp:50
Definition: Command.hpp:48
Definition: app.hpp:12
void setCode(const U24 &c) noexcept(false)
Definition: Command.hpp:110
const std::string & getName(void) const
Definition: Command.hpp:88
#define ANNA_FILE_LOCATION
Definition: defines.hpp:23
void initialize(const Dictionary *d=NULL)
Definition: Command.hpp:109
std::pair< U24, bool > CommandId
Definition: defines.hpp:32
Definition: RuntimeException.hpp:23
avprule_container::const_iterator const_avprule_iterator
Definition: Command.hpp:55
Definition: AvpRule.hpp:51