ulxr_requester.h

Go to the documentation of this file.
00001 /***************************************************************************
00002              ulxr_requester.h  -  send rpc request ("rpc-client")
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_requester.h 942 2006-12-31 13:10:54Z 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_REQUESTER_H
00031 #define ULXR_REQUESTER_H
00032 
00033 #include <exception>
00034 
00035 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00036 #include <ulxmlrpcpp/ulxr_call.h>
00037 #include <ulxmlrpcpp/ulxr_mutex.h>
00038 #include <ulxmlrpcpp/ulxr_response.h>
00039 
00040 
00041 namespace ulxr {
00042 
00043 
00044 class Protocol;
00045 class Connection;
00046 class Exception;
00047 
00048 namespace hidden {
00049 
00050 
00054 class ULXR_API_DECL0 ReceiverWrapperBase
00055 {
00056   public:
00057 
00058     virtual ~ReceiverWrapperBase();
00059 
00060     virtual void receive(const MethodResponse &resp) const = 0;
00061 };
00062 
00063 
00067 template <class T>
00068 class ReceiverWrapper : public ReceiverWrapperBase
00069 {
00070   public:
00071 
00072    typedef void (T::*PMF)(const MethodResponse &resp);
00073 
00074    virtual ~ReceiverWrapper()
00075    {}
00076 
00077    virtual void receive(const MethodResponse &resp) const
00078    {
00079       (obj->*adr) (resp);
00080    }
00081 
00082   public:
00083 
00084    ReceiverWrapper(T *o, PMF a)
00085     : obj(o), adr(a)
00086    {}
00087 
00088   private:
00089    T    *obj;
00090    PMF   adr ;
00091 
00092  private:
00093     // forbid them all due to internal pointers
00094     const ReceiverWrapper& operator= (const ReceiverWrapper&);
00095     ReceiverWrapper (const ReceiverWrapper&);
00096 };
00097 
00098 
00099 typedef void (*StaticReceiver_t)(const MethodResponse &);
00100 
00101 typedef ReceiverWrapperBase *DynamicReceiver_t;    // call Wrappers receiver
00102 
00105 class ULXR_API_DECL0 Receiver_t
00106 {
00107  public:
00111     Receiver_t(StaticReceiver_t recv);
00112 
00116     Receiver_t(DynamicReceiver_t recv);
00117 
00121     void receive(const MethodResponse &resp);
00122 
00125     void free();
00126 
00127  protected:
00128 
00129    StaticReceiver_t    static_recv;
00130    DynamicReceiver_t   dynamic_recv;
00131 /*
00132  private:
00133     // forbid them all due to internal pointers
00134     const Receiver_t& operator= (const Receiver_t&);
00135     Receiver_t (const Receiver_t&);
00136 */
00137 };
00138 
00139 
00140 }  // namespace hidden
00141 
00142 
00143 struct DispatcherData;
00144 
00145 
00152 class ULXR_API_DECL0 Requester
00153 {
00154  public:
00155 
00160    Requester(Protocol* prot, bool wbxml_mode = false);
00161 
00164    virtual ~Requester();
00165 
00172    MethodResponse call (const MethodCall& call,
00173                         const CppString &resource);
00174 
00183    MethodResponse call (const MethodCall& call,
00184                         const CppString &resource,
00185                         const CppString &user,
00186                         const CppString &pass);
00187 
00188 #ifdef ULXR_MULTITHREADED
00189 
00199    void call (const MethodCall& call,
00200               const CppString &resource,
00201               hidden::Receiver_t recv);
00202 
00214    void call (const MethodCall& call,
00215               const CppString &resource,
00216               const CppString &user,
00217               const CppString &pass,
00218               hidden::Receiver_t recv);
00219 
00220 #endif // ULXR_MULTITHREADED
00221 
00227    void transmit (const MethodCall& call,
00228                   const CppString &resource);
00229 
00237    void transmit (const MethodCall& call,
00238                   const CppString &resource,
00239                   const CppString &user,
00240                   const CppString &pass);
00241 
00247    static MethodResponse waitForResponse(Protocol *conn, bool wbxml);
00248 
00249 #ifdef ULXR_MULTITHREADED
00250 
00254    unsigned numPendingRequests() const;
00255 
00256 #endif
00257 
00261    bool isWbXml() const;
00262 
00263  protected:
00264 
00269    void send_call(const MethodCall& call,
00270                   const CppString &resource);
00271 
00275    MethodResponse waitForResponse();
00276 
00277 #ifdef ULXR_MULTITHREADED
00278 
00286    void startDispatch(const MethodCall& call,
00287                       const CppString &resource,
00288                       hidden::Receiver_t recv);
00289 
00290 #endif // ULXR_MULTITHREADED
00291 
00292  private:
00293 
00294 #ifdef ULXR_MULTITHREADED
00295 
00296    friend void *dispatchThreaded(DispatcherData *data);
00297 
00302    virtual void forwardException();
00303 
00309    virtual void forwardException(const Exception &ex);
00310 
00316    virtual void forwardException(const std::exception &ex);
00317 
00320    void incPending();
00321 
00324    void decPending();
00325 
00326 #endif
00327 
00328    bool               wbxml_mode;
00329    Protocol          *protocol;
00330    unsigned           cntPendingRequests;
00331    Mutex              pendingMutex;
00332 };
00333 
00334 
00341 #ifndef _MSC_VER
00342 
00343 template <class T>
00344 inline hidden::ReceiverWrapperBase*
00345 make_receiver(T &w, typename hidden::ReceiverWrapper<T>::PMF pmf)
00346 {
00347   return new hidden::ReceiverWrapper<T> (&w, pmf);
00348 }
00349 
00350 #else // work around m$vc bug
00351 
00352 template <class T, class U>
00353 inline hidden::ReceiverWrapper<T>*
00354 make_receiver(T &w, U pmf)
00355 {
00356   return new hidden::ReceiverWrapper<T> (&w, pmf);
00357 }
00358 
00359 #endif
00360 
00365 inline hidden::StaticReceiver_t
00366 make_receiver(hidden::StaticReceiver_t ptr)
00367 {
00368   return ptr;
00369 }
00370 
00371 
00372 }  // namespace ulxr
00373 
00374 
00375 #endif // ULXR_REQUESTER_H

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