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_Engine_hpp
38 #define anna_diameter_stack_Engine_hpp
42 #include <anna/diameter/stack/Dictionary.hpp>
44 #include <anna/xml/DTDMemory.hpp>
45 #include <anna/core/RuntimeException.hpp>
46 #include <anna/core/Singleton.hpp>
61 //------------------------------------------------------------------------------
62 //----------------------------------------------------------------- class Engine
63 //------------------------------------------------------------------------------
67 class Engine : public anna::Singleton <Engine> {
70 const anna::xml::DTDMemory * getDictionariesDTD() const throw() { return &a_dtd; }
74 typedef std::map<int, Dictionary*> stack_container;
75 typedef stack_container::const_iterator const_stack_iterator;
76 typedef stack_container::iterator stack_iterator;
81 * Returns the dictionary registered with the provided identifier
83 * @param stackId Stack identifier.
84 * @return Dictionary reference, NULL if no stack found
86 const Dictionary * getDictionary(int stackId) const throw();
88 /** Beginning stack iterator */
89 const_stack_iterator stack_begin() const throw() { return a_stacks.begin(); }
90 /** Ending stack iterator */
91 const_stack_iterator stack_end() const throw() { return a_stacks.end(); }
93 int stack_size() const throw() { return a_stacks.size(); }
97 * Gets boolean about empty stack condition
99 * @return Boolean about empty stack condition
101 bool isEmpty(void) const throw() { return (!a_stacks.size()); }
104 * Class string representation
106 * @return String with class content
108 std::string asString(void) const throw();
113 * Creates a diameter dictionary based on xml document file and store it over the provided stack identifier.
114 * If the stack is currently used, an exception will be launched to notify the stack collision (a dictionary
115 * could be removed with #removeStack).
116 * If missing xml path file, the dictionary will be created without loading data.
119 * Method 1 - Create and load xml data (commonly used for mono-load stacks):
120 * engine->createDictionary(MMS_STACK_ID, "/var/tmp/mms.xml");
122 * Method 2 - Create and then, load xml data (useful for multi-load stacks):
123 * Dictionary * d = engine->createDictionary(MMS_STACK_ID);
125 * d->load("/var/tmp/mms.xml");
127 * Method 3 - Create and then, load data through Dictionary API (*):
128 * Dictionary * d = engine->createDictionary(MMS_STACK_ID);
134 * (*) Applications could create a dictionary with its own API (#Dictionary) but it is much more difficult,
135 * and usually, the method version with xml document load is used instead of this.
139 * @param stackId Stack identifier for created dictionary.
140 * @param xmlPathFile Path file to the xml document which represents the diameter dictionary.
142 * @return Dictionary registered. When exception happen, dictionary can be accessed by #getDictionary
144 Dictionary * createDictionary(int stackId, const std::string & xmlPathFile = "") throw(anna::RuntimeException);
147 * Loads an XML dictionary document over the diameter stack identifiers (one or more stack id's).
148 * Passing more than one stack id, synchronized loadings are performed, which could be useful when
149 * an application loads many dictionaries with common avps.
151 * @param stacks Stacks identifiers over which the dictionary will be load.
152 * @param xmlPathFile Path file to the xml document which represents the diameter dictionary.
154 void loadDictionary(const std::vector<int> & stacks, const std::string & xmlPathFile) throw(anna::RuntimeException);
157 * Loads an XML dictionary document over all the diameter engine registered stacks. When more than one stack id is
158 * used, synchronized loadings are performed, which could be useful when an application loads many dictionaries with
161 * @param xmlPathFile Path file to the xml document which represents the diameter dictionary.
163 void loadDictionary(const std::string & xmlPathFile) throw(anna::RuntimeException);
166 * Remove all stacks registered on diameter stack engine
168 void removeStacks(void) throw() { a_stacks.clear(); }
171 * Remove the stack provided.
173 * @param stackId Stack identifier for created dictionary
175 void removeStack(int stackId) throw();
179 anna::xml::DTDMemory a_dtd;
180 stack_container a_stacks;
184 friend class anna::Singleton <Engine>;
185 friend class Dictionary; // access to 'getDictionariesDTD()'