1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
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 //
9 #ifndef anna_diameter_stack_Dictionary_hpp
10 #define anna_diameter_stack_Dictionary_hpp
14 #include <anna/diameter/defines.hpp>
15 #include <anna/diameter/stack/Format.hpp>
16 #include <anna/diameter/stack/Vendor.hpp>
17 #include <anna/diameter/stack/Avp.hpp>
18 #include <anna/diameter/stack/Command.hpp>
20 #include <anna/core/RuntimeException.hpp>
44 //------------------------------------------------------------------------------
45 //------------------------------------------------------------- class Dictionary
46 //------------------------------------------------------------------------------
48 * Dictionary information
54 typedef std::map<std::string, Format> format_container;
55 typedef format_container::const_iterator const_format_iterator;
57 typedef std::map<S32, Vendor> vendor_container;
58 typedef vendor_container::const_iterator const_vendor_iterator;
60 struct lessAvp { // order by vendor id
61 bool operator()(AvpId id1, AvpId id2) const {
62 if(id1.second == id2.second) return (id1.first < id2.first);
64 return (id1.second < id2.second);
67 typedef std::map<AvpId, Avp, lessAvp> avp_container;
68 typedef avp_container::const_iterator const_avp_iterator;
72 bool operator()(CommandId id1, CommandId id2) const {
73 if(id1.first == id2.first) {
74 if(id1.second != id2.second) return (id1.second); // request -> answer
79 return (id1.first < id2.first);
82 typedef std::map<CommandId, Command, lessCommand> command_container;
83 typedef command_container::const_iterator const_command_iterator;
91 format_container a_formats;
92 vendor_container a_vendors;
94 command_container a_commands;
97 const anna::xml::DTDMemory * a_dtd;
100 typedef std::map<std::string, const Vendor *> vendorNames_container;
101 typedef vendorNames_container::const_iterator const_vendorNames_iterator;
103 typedef std::map<std::string, const Avp *> avpNames_container;
104 typedef avpNames_container::const_iterator const_avpNames_iterator;
106 typedef std::map<std::string, const Command *> commandNames_container;
107 typedef commandNames_container::const_iterator const_commandNames_iterator;
109 vendorNames_container a_vendorNames;
110 avpNames_container a_avpNames;
111 commandNames_container a_commandNames;
115 void initialize() throw();
118 //void checkUniqueIdentifiers(const anna::xml::Node *rootNode) const throw(anna::RuntimeException);
119 void extractFormats(const anna::xml::Node *rootNode) throw(anna::RuntimeException);
120 void extractVendors(const anna::xml::Node *rootNode) throw(anna::RuntimeException);
121 void extractAvps(const anna::xml::Node *rootNode) throw(anna::RuntimeException);
122 void extractCommands(const anna::xml::Node *rootNode) throw(anna::RuntimeException);
130 const std::string & getName() const throw() { return a_name; }
131 const Format * getFormat(const std::string & formatName) const throw();
132 const Vendor * getVendor(S32 vendorId) const throw();
133 const Vendor * getVendor(const std::string & vendorName) const throw();
134 const Avp * getAvp(const AvpId & avpId) const throw();
135 const Avp * getAvp(const std::string & avpName) const throw();
136 const Command * getCommand(const CommandId & commandId) const throw();
137 const Command * getCommand(const std::string & commandName) const throw();
140 void allowUpdates(bool allow = true) throw() { a_allowUpdates = allow; }
141 void addFormat(const Format &, bool reserved = false) throw(anna::RuntimeException);
142 void addVendor(const Vendor &) throw(anna::RuntimeException);
143 void addAvp(const Avp &) throw(anna::RuntimeException);
144 void addCommand(const Command &) throw(anna::RuntimeException);
147 const_format_iterator format_begin() const throw() { return a_formats.begin(); }
148 const_format_iterator format_end() const throw() { return a_formats.end(); }
149 int format_size() const throw() { return a_formats.size(); }
151 const_vendor_iterator vendor_begin() const throw() { return a_vendors.begin(); }
152 const_vendor_iterator vendor_end() const throw() { return a_vendors.end(); }
153 int vendor_size() const throw() { return a_vendors.size(); }
155 const_avp_iterator avp_begin() const throw() { return a_avps.begin(); }
156 const_avp_iterator avp_end() const throw() { return a_avps.end(); }
157 int avp_size() const throw() { return a_avps.size(); }
159 const_command_iterator command_begin() const throw() { return a_commands.begin(); }
160 const_command_iterator command_end() const throw() { return a_commands.end(); }
161 int command_size() const throw() { return a_commands.size(); }
166 * Class string representation
168 * @return String with class content
170 std::string asString(void) const throw();
173 Class XML representation.
174 \param parent XML node over which we will put instance information.
175 \return XML documentcon with class content.
177 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
180 Class XML string representation
181 \return XML string representation with class content.
183 std::string asXMLString() const throw();
188 * Loads an XML dictionary document over the diameter dictionary.
190 * Successive loadings will imply data accumulation, and the behaviour for redefinitions could be configured
191 * in two ways: allow updating for dictionary items, or launch exception when any collision is found. This
192 * could be set at #allowUpdates, and default value deny such redefinitions. It could be interesting, in order
193 * to keep a more compact multi-stack configuration, allow updates sharing out the whole stack dictionaries as
194 * many parts as possible to get centralized definitions. I.e. common vendors and avps used at a unique xml file,
195 * and stack-specific commands in other set of xml files. Application only would have to load common part for all
196 * the created dictionaries with this method and specific one for each final dictionary:
198 * @param pathFile Path file to the xml document which represents the diameter dictionary.
201 * Dictionary *nokiaStack = stackEngine.createDictionary("/var/tmp/vendors_and_avps.xml", NOKIA_STACK_ID);
202 * Dictionary *huaweiStack = stackEngine.createDictionary("/var/tmp/vendors_and_avps.xml", HUAWEI_STACK_ID);
203 * nokiaStack->load("/var/tmp/nokia_commands.xml");
204 * huaweiStack->load("/var/tmp/huawei_commands.xml");
207 virtual void load(const std::string & pathFile) throw(anna::RuntimeException);
210 * Clears dictionary content
212 void clear(void) throw() { initialize(); } // initialize and prepares the dictionary