1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_diameter_stack_Command_hpp
38 #define anna_diameter_stack_Command_hpp
42 #include <anna/diameter/defines.hpp>
43 #include <anna/diameter/stack/AvpRule.hpp>
44 #include <anna/diameter/codec/Format.hpp>
46 #include <anna/core/RuntimeException.hpp>
47 #include <anna/config/defines.hpp>
70 //------------------------------------------------------------------------------
71 //---------------------------------------------------------------- class Command
72 //------------------------------------------------------------------------------
80 //typedef std::map<AvpId, AvpRule> avprule_container;
81 typedef std::map < int /*position*/, AvpRule > avprule_container;
82 typedef avprule_container::iterator avprule_iterator;
83 typedef avprule_container::const_iterator const_avprule_iterator;
88 const Dictionary *a_dictionary;
93 avprule_container a_avprules;
94 bool a_allowFixedRule;
95 int a_avprulePosition;
97 void _initializeRules() throw() {
99 a_allowFixedRule = true;
100 a_avprulePosition = 0;
103 void _initialize(const Dictionary *d) throw() {
110 Command(const Dictionary *d = NULL) { _initialize(d); }
115 const CommandId & getId(void) const throw() { return a_id; }
116 const std::string & getName(void) const throw() { return a_name; }
120 const_avprule_iterator avprule_begin() const throw() { return a_avprules.begin(); }
121 const_avprule_iterator avprule_end() const throw() { return a_avprules.end(); }
122 int avprule_size() const throw() { return a_avprules.size(); }
126 bool isEmpty(void) const throw() { return (!a_avprules.size()); }
127 bool isRequest(void) const throw() { return (a_id.second); }
128 bool isAnswer(void) const throw() { return (!a_id.second); }
129 bool isChild(const AvpId & avp) const throw();
131 std::string asString(void) const throw();
132 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
137 void initialize(const Dictionary *d = NULL) throw() { _initialize(d); }
138 void setCode(const U24 & c) throw(anna::RuntimeException) {
142 void setRequest(bool r = true) throw() { a_id.second = r; }
143 void setAnswer(bool a = true) throw() { a_id.second = a; }
144 void setName(const std::string & n) throw(anna::RuntimeException) {
145 if(n == "") throw anna::RuntimeException("Empty command-name string not allowed", ANNA_FILE_LOCATION);
149 void addAvpRule(const AvpRule & avpRule) throw(anna::RuntimeException);