ulxr_method_adder.h

Go to the documentation of this file.
00001 /***************************************************************************
00002            ulxr-method_adder.h  -  interface for adding methods
00003                              -------------------
00004     begin                : Thu Jul 12 2007
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_mtrpc_server.h 940 2006-12-30 18:22:05Z ewald-arnold $
00009 
00010  ***************************************************************************/
00011 
00012 /**************************************************************************
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as
00016  * published by the Free Software Foundation; either version 2 of the License,
00017  * or (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027  *
00028  ***************************************************************************/
00029 
00030 #ifndef ULXR_METHOD_ADDER_H
00031 #define ULXR_METHOD_ADDER_H
00032 
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00034 
00035 namespace ulxr {
00036 
00037 
00038 class MethodResponse;
00039 class MethodCall;
00040 class Dispatcher;
00041 class Signature;
00042 
00043 
00044 namespace hidden {
00045 
00046 
00049 class ULXR_API_DECL0 MethodWrapperBase
00050 {
00051   public:
00052 
00053     virtual ~MethodWrapperBase();
00054 
00055     virtual MethodResponse call(const MethodCall &calldata) const = 0;
00056 };
00057 
00058 
00061 template <class T>
00062 class MethodWrapper : public MethodWrapperBase
00063 {
00064   public:
00065 
00066    typedef MethodResponse (T::*PMF)(const MethodCall &calldata);
00067 
00068    virtual ~MethodWrapper()
00069    {
00070    }
00071 
00072    virtual MethodResponse call (const MethodCall &calldata) const
00073    {
00074       return (obj->*adr) (calldata);
00075    }
00076 
00077    MethodWrapper(T *o, PMF a)
00078     : obj(o), adr(a)
00079      {}
00080 
00081   private:
00082    T    *obj;
00083    PMF   adr ;
00084 
00085  private:
00086     // forbid them all due to internal pointers
00087     const MethodWrapper& operator= (const MethodWrapper&);
00088     MethodWrapper (const MethodWrapper&);
00089 };
00090 
00091 
00092 }  // namespace hidden
00093 
00094 
00098 class ULXR_API_DECL0 MethodAdder
00099 {
00100   public:
00101 
00102     typedef MethodResponse (*StaticMethodCall_t)(const MethodCall &);
00103 
00104     typedef MethodResponse (*SystemMethodCall_t)(const MethodCall &,
00105                                                  const Dispatcher* disp);
00106 
00107     typedef hidden::MethodWrapperBase*  DynamicMethodCall_t;    // call Wrappers call();
00108 
00109     enum   CallType { CallNone,
00110                       CallSystem,
00111                       CallStatic,
00112                       CallDynamic
00113                     };
00114 
00115   protected:
00116 
00117     friend StaticMethodCall_t make_method(const StaticMethodCall_t);
00118 
00119     typedef union
00120     {
00121        StaticMethodCall_t    static_function;
00122        SystemMethodCall_t    system_function;
00123        DynamicMethodCall_t   dynamic_function;
00124     } MethodCall_t;
00125 
00126   public:
00127 
00128     virtual ~MethodAdder()
00129     {}
00130 
00142    virtual void addMethod (StaticMethodCall_t adr,
00143                    const CppString &ret_signature,
00144                    const CppString &name,
00145                    const CppString &signature,
00146                    const CppString &help) = 0;
00147 
00160    virtual void addMethod (DynamicMethodCall_t wrapper,
00161                    const CppString &ret_signature,
00162                    const CppString &name,
00163                    const CppString &signature,
00164                    const CppString &help) = 0;
00165 
00177    virtual void addMethod (SystemMethodCall_t adr,
00178                    const CppString &ret_signature,
00179                    const CppString &name,
00180                    const CppString &signature,
00181                    const CppString &help) = 0;
00182 
00194    virtual void addMethod (StaticMethodCall_t adr,
00195                    const Signature &ret_signature,
00196                    const CppString &name,
00197                    const Signature &signature,
00198                    const CppString &help) = 0;
00199 
00212    virtual void addMethod (DynamicMethodCall_t wrapper,
00213                    const Signature &ret_signature,
00214                    const CppString &name,
00215                    const Signature &signature,
00216                    const CppString &help) = 0;
00217 
00229    virtual void addMethod (SystemMethodCall_t adr,
00230                    const Signature &ret_signature,
00231                    const CppString &name,
00232                    const Signature &signature,
00233                    const CppString &help) = 0;
00234 
00238    virtual void removeMethod(const CppString &name) = 0;
00239 };
00240 
00241 
00249 #ifndef _MSC_VER
00250 
00251 template <class T>
00252 inline hidden::MethodWrapperBase*
00253 make_method(T &w, typename hidden::MethodWrapper<T>::PMF pmf)
00254 {
00255   return new hidden::MethodWrapper<T> (&w, pmf);
00256 }
00257 
00258 #else // work around m$vc bug
00259 
00260 template <class T, class U>
00261 inline hidden::MethodWrapper<T>*
00262 make_method(T &w, U pmf)
00263 {
00264   return new hidden::MethodWrapper<T> (&w, pmf);
00265 }
00266 
00267 #endif
00268 
00269 typedef MethodAdder::StaticMethodCall_t MethodAdder_StaticMethodCall_t;
00270 
00275 inline MethodAdder_StaticMethodCall_t
00276 make_method(MethodAdder_StaticMethodCall_t ptr)
00277 {
00278   return ptr;
00279 }
00280 
00281 
00282 } // namespace
00283 
00284 #endif // ULXR_METHOD_ADDER_H

Generated on Sun Aug 19 20:08:57 2007 for ulxmlrpcpp by  doxygen 1.5.1