Changed LICENSE. Now referenced to web site and file on project root directory
[anna.git] / include / anna / diameter / codec / EngineImpl.hpp
index 049906b..e282724 100644 (file)
@@ -1,37 +1,9 @@
-// ANNA - Anna is Not Nothingness Anymore
-//
-// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
-//
-// http://redmine.teslayout.com/projects/anna-suite
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-//     * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-//     * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-//     *  Neither the name of the copyright holder nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-// Authors: eduardo.ramos.testillano@gmail.com
-//          cisco.tierra@gmail.com
+// ANNA - Anna is Not Nothingness Anymore                                                         //
+//                                                                                                //
+// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
+//                                                                                                //
+// See project site at http://redmine.teslayout.com/projects/anna-suite                           //
+// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
 
 
 #ifndef anna_diameter_codec_EngineImpl_hpp
@@ -183,7 +155,7 @@ public:
    * Defines behaviour mode regarding when to validate a message: before encoding, after decoding (by default), always or never
    * Anyway validation procedure may be called at any moment (#valid)
    */
-  struct ValidationMode { enum _v { BeforeCoding, AfterDecoding /* default */, Always, Never /* optimization */ }; };
+  struct ValidationMode { enum _v { BeforeEncoding, AfterDecoding /* default */, Always, Never /* optimization */ }; };
 
   /**
    * Defines behaviour mode regarding when to fix a message: before encoding (by default), after decoding, always or never.
@@ -194,7 +166,7 @@ public:
    *  hide any validation problem regarding Avps position at any level.
    * Anyway fix procedure may be called at any moment (#fix)
    */
-  struct FixMode { enum _v { BeforeCoding /* default */, AfterDecoding, Always, Never /* optimization */ }; };
+  struct FixMode { enum _v { BeforeEncoding /* default */, AfterDecoding, Always, Never /* optimization */ }; };
 
 
   // Creators
@@ -209,6 +181,8 @@ private:
   ValidationMode::_v a_validationMode;
   bool a_ignoreFlags;
   FixMode::_v a_fixMode;
+  bool a_selectStackWithApplicationId; // default behaviour: let the user switch the stack (false for this boolean)
+
 
   // Auxiliary
   const stack::Dictionary * a_dictionary;
@@ -231,6 +205,7 @@ public:
   virtual ~EngineImpl() {;}
 
 
+  // setters
   /**
      Sets diameter dictionary loaded at stack engine. It's recommended to configure a valid dictionary
      (if not, or NULL provided at #setDictionary, all avps will be managed as 'Unknown' format and all
@@ -238,20 +213,45 @@ public:
 
      @param dictionary Diameter dictionary. At single threaded processes, the same codec engine could be used with
      different diameter dictionaries (multi-stack applications). In that case the process must switch the stack for
-     the whole decoding or enconding operation over a Message depending on the context. But the smart way implies
-     inherit from this engine creating a component for each diameter stack managed in the application. Inheritance
-     is mandatory in multi-threaded processes: one engine, a unique stack.
+     the whole decoding or enconding operation over a Message depending on the context (normally the message header
+     Application-Id is used as stack identifier). But the smart way implies inherit from this engine creating a
+     component for each diameter stack managed in the application. Inheritance is mandatory in multi-threaded processes:
+     one engine, a unique stack.
   */
   void setDictionary(const stack::Dictionary * dictionary) throw() { a_dictionary = dictionary; }
 
-  // get
   /**
   * Sets diameter dictionary loaded at stack engine with the provided identifier.
   *
-  * @param stackId Stack identifier. When missing, default stack (stack::Engine::getDefaultStack()) will be used
+  * @param stackId Stack identifier. When missing, NULL will be returned
   * @return Returns configured dictionary (NULL if stack id was not found)
   */
-  const stack::Dictionary *setDictionary(int stackId = -1) throw();
+  const stack::Dictionary *setDictionary(unsigned int stackId) throw();
+
+
+  /**
+  * By default, the user will select the appropiate stack id depending on the context (see #setDictionary), but
+  * some applications could consider interesting automatic stack selection based on managed messages (incoming
+  * decoded ones, or built messages to be encoded). By default, on engine construction, no changes are done.
+  * Multithreaded processes should have a unique codec engine for each managed stack (then you don't have to
+  * worry about), but mono processes with multistack implementation over the same-unique engine, should activate
+  * this to have the commonly recommended way to choose the stack: using the Application-Id value.
+  *
+  * @warning do not activate in case of multithreaded applications.
+  * @param enable Activates/deactivates the stack selection from the Application-Id value within the message header.
+  */
+  void selectStackWithApplicationId (bool enable) throw() { a_selectStackWithApplicationId = enable; }
+
+  // getters
+
+  /**
+    Gets the currently configured behaviour regarding stack selection for multistack codec engines in mono thread
+    applications.
+
+    @return True if selection is done with the Application-Id. False if no selection is performed (user responsibility).
+  */
+  bool hasSelectStackWithApplicationId (void) throw() { return a_selectStackWithApplicationId; }
+
 
   /**
      Gets currently configured dictionary. NULL if not configured (manual encode/decode operations).