Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

eap_method_registrar.hxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 /* $Id: eap_method_registrar.hxx,v 1.16 2004/06/17 21:13:36 yohba Exp $ */
00034 /* 
00035    eap_method_registrar.hxx:  class for EAP state machine registration
00036 
00037    Written by Yoshihiro Ohba
00038    
00039 */
00040 
00066 #ifndef __EAP_METHOD_REGISTRAR_HXX__
00067 #define __EAP_METHOD_REGISTRAR_HXX__
00068 
00069 #include <string>
00070 #include <list>
00071 #include <ace/Singleton.h>
00072 #include <ace/Reactor.h>
00073 #include <boost/function/function1.hpp>
00074 #include "eap.hxx"
00075 #include "eap_fsm.hxx"
00076 
00079 typedef boost::function1<EapMethodStateMachine*, EapSwitchStateMachine&>
00080 EapMethodStateMachineFunctor;
00081 
00085 template <class T> class EapMethodStateMachineCreator
00086 {
00087 public:
00088   EapMethodStateMachine* operator()(EapSwitchStateMachine &s)
00089   {
00090     return new T(s);
00091   };
00092 };
00093 
00095 class EAP_EXPORTS EapMethodTableEntry
00096 {
00097   friend class EapMethodTable_S;
00098   friend class EapSwitchStateMachine;
00099 public:
00100   EapMethodTableEntry(std::string name, EapType type, EapRole role, 
00101                       EapMethodStateMachineFunctor creator)
00102   {
00103     this->name = name;
00104     this->type = type;
00105     this->role = role;
00106     this->creator = creator;
00107   }
00108 private:
00109   std::string  name;
00110   EapType type;
00111   EapRole role;
00112   EapMethodStateMachineFunctor creator;
00113 };
00114 
00116 class EAP_EXPORTS EapMethodTable_S : public std::list<EapMethodTableEntry*> 
00117 {
00118   friend class ACE_Singleton<EapMethodTable_S, ACE_Recursive_Thread_Mutex>;
00119 public:
00120 
00122   EapMethodTableEntry *Find(EapType type, EapRole role)
00123   {
00124     iterator i;
00125     for (i=begin(); i!=end(); i++)
00126       {
00127         EapMethodTableEntry* e = (*i);
00128         if (e->type == type && e->role == role) { return e; }
00129       }
00130     return NULL;
00131   }
00132 
00134   inline void add(EapMethodTableEntry *e) { push_back(e); }
00135 
00136 private:
00137   EapMethodTable_S() { registerDefaultMethods(); };
00138   ~EapMethodTable_S() {};
00139   void registerDefaultMethods();
00140 };
00141 
00142 typedef ACE_Singleton<EapMethodTable_S, ACE_Recursive_Thread_Mutex>
00143 EapMethodTable;
00144 
00150 class EAP_EXPORTS EapMethodRegistrar
00151 {
00152 public:
00153   void registerMethod(std::string name, EapType type, EapRole role, 
00154                       EapMethodStateMachineFunctor creator);
00155 };
00156 #endif  // __EAP_METHOD_REGISTRAR_HXX__

Generated on Fri Jun 25 19:16:16 2004 for EAP State Machine by doxygen 1.3.5