ulxr_dispatcher.h

Go to the documentation of this file.
00001 /***************************************************************************
00002          ulxr_dispatcher.h  -  answer rpc requests ("rpc-server")
00003                              -------------------
00004     begin                : Sat Mar 23 2002
00005     copyright            : (C) 2002-2007 by Ewald Arnold
00006     email                : ulxmlrpcpp@ewald-arnold.de
00007 
00008     $Id: ulxr_dispatcher.h 1026 2007-07-25 07:48:09Z 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_DISPATCHER_H
00031 #define ULXR_DISPATCHER_H
00032 
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00034 
00035 #include <ulxmlrpcpp/ulxr_call.h>
00036 #include <ulxmlrpcpp/ulxr_response.h>
00037 #include <ulxmlrpcpp/ulxr_method_adder.h>
00038 
00039 
00040 namespace ulxr {
00041 
00042 
00043 class Protocol;
00044 class Connection;
00045 class Struct;
00046 class Signature;
00047 
00048 
00058 class ULXR_API_DECL0 Dispatcher : public MethodAdder
00059 {
00060  public:
00061 
00062    struct ULXR_API_DECL0 MethodCallDescriptor
00063    {
00064 
00065      friend class Dispatcher;
00066 
00070      MethodCallDescriptor(const MethodCall &call);
00071 
00079      MethodCallDescriptor(CallType calltype,
00080                           const CppString &ret_sig,
00081                           const CppString &name,
00082                           const CppString &signature,
00083                           const CppString &help);
00084 
00088      bool operator == (const MethodCallDescriptor &desc) const
00089        { return getSignature(true, false) == desc.getSignature(true, false); }
00090 
00094      bool operator < (const MethodCallDescriptor &desc) const
00095        { return getSignature(true, false) < desc.getSignature(true, false); }
00096 
00102      CppString getSignature(bool with_name, bool with_return) const;
00103 
00107      unsigned long getInvoked() const;
00108 
00111      void incInvoked() const;
00112 
00116      bool isEnabled() const;
00117 
00121      void setEnabled(bool ena) const;
00122 
00126      CppString getMethodName() const;
00127 
00131      CppString getParameterSignature() const;
00132 
00136      CppString getReturnValueSignature() const;
00137 
00141      CppString getDocumentation() const;
00142 
00146      CallType getCallType() const;
00147 
00148     private:
00149 
00150      CallType         calltype;
00151      CppString        method_name;
00152      CppString        signature;
00153      CppString        return_signature;
00154      CppString        documentation;
00155 
00156      mutable unsigned long  invoked;
00157      mutable bool           enabled;
00158    };
00159 
00160  protected:
00161 
00162    typedef std::map<MethodCallDescriptor, MethodCall_t> MethodCallMap;
00163 
00164    friend void free_dynamic_method(const MethodCallMap::value_type &);
00165 
00166    friend struct MethodCallDescriptor;
00167 
00168  public:
00169 
00174    Dispatcher (Protocol* prot = 0, bool wbxml_mode = false);
00175 
00180    virtual ~Dispatcher ();
00181 
00193    void addMethod (StaticMethodCall_t adr,
00194                    const CppString &ret_signature,
00195                    const CppString &name,
00196                    const CppString &signature,
00197                    const CppString &help);
00198 
00211    void addMethod (DynamicMethodCall_t wrapper,
00212                    const CppString &ret_signature,
00213                    const CppString &name,
00214                    const CppString &signature,
00215                    const CppString &help);
00216 
00228    void addMethod (SystemMethodCall_t adr,
00229                    const CppString &ret_signature,
00230                    const CppString &name,
00231                    const CppString &signature,
00232                    const CppString &help);
00233 
00245    void addMethod (StaticMethodCall_t adr,
00246                    const Signature &ret_signature,
00247                    const CppString &name,
00248                    const Signature &signature,
00249                    const CppString &help);
00250 
00263    void addMethod (DynamicMethodCall_t wrapper,
00264                    const Signature &ret_signature,
00265                    const CppString &name,
00266                    const Signature &signature,
00267                    const CppString &help);
00268 
00280    void addMethod (SystemMethodCall_t adr,
00281                    const Signature &ret_signature,
00282                    const CppString &name,
00283                    const Signature &signature,
00284                    const CppString &help);
00285 
00290    virtual MethodCall waitForCall(int timeout = 0);
00291 
00296    virtual MethodResponse dispatchCall(const MethodCall &call) const;
00297 
00304    virtual MethodResponse dispatchCallLoc(const MethodCall &call) const;
00305 
00309    virtual void sendResponse(const MethodResponse &resp);
00310 
00314    Protocol* getProtocol() const;
00315 
00319    void setProtocol(Protocol *prot);
00320 
00324    unsigned numMethods() const;
00325 
00330    const MethodCallDescriptor * const getMethod(unsigned index);
00331 
00336    bool hasMethod(const MethodCall &call) const;
00337 
00341    void removeMethod(const CppString &name);
00342 
00343  protected:
00344 
00349    void addMethodDescriptor (const MethodCallDescriptor &desc,
00350                              MethodCall_t mct);
00351 
00354    void setupSystemMethods();
00355 
00361    static MethodResponse xml_pretty_print(const MethodCall &calldata,
00362                                           const Dispatcher *disp);
00363 
00369    static MethodResponse system_listMethods(const MethodCall &calldata,
00370                                             const Dispatcher *disp);
00371 
00379    static MethodResponse system_methodSignature(const MethodCall &calldata,
00380                                                 const Dispatcher *disp);
00381 
00389    static MethodResponse system_methodHelp(const MethodCall &calldata,
00390                                            const Dispatcher *disp);
00391 
00399   static MethodResponse system_getCapabilities(const MethodCall &calldata,
00400                                                const Dispatcher *disp);
00401 
00405    virtual void getCapabilities (Struct &str) const;
00406 
00407  private:
00408 
00409    MethodCallMap             methodcalls;
00410    Protocol                 *protocol;
00411    bool                      wbxml_mode;
00412 };
00413 
00414 
00415 }  // namespace ulxr
00416 
00417 
00418 #endif // ULXR_DISPATCHER_H

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