reSIProcate/repro  9694
XmlRpcServerBase.hxx
Go to the documentation of this file.
00001 #if !defined(XmlRpcServerBase_hxx)
00002 #define XmlRpcServerBase_hxx 
00003 
00004 #include <map>
00005 #include <rutil/Data.hxx>
00006 #include <rutil/Socket.hxx>
00007 #include <rutil/TransportType.hxx>
00008 #include <rutil/Fifo.hxx>
00009 #include <resip/stack/Tuple.hxx>
00010 #include <rutil/SelectInterruptor.hxx>
00011 
00012 /// This Class is used to implement a primitive form of RPC using loose XML formatting.
00013 /// The XML formatting used is specific to this implementation and is NOT currently intended to 
00014 /// be compatible with the XML-RPC protocol defined by the following:  http://www.xmlrpc.com/
00015 
00016 namespace repro
00017 {
00018 class XmlRpcConnection;
00019 
00020 class ResponseInfo
00021 {
00022 public:
00023    ResponseInfo(unsigned int connectionId,
00024                 unsigned int requestId,
00025                 const resip::Data& responseData,
00026                 bool isFinal) :
00027       mConnectionId(connectionId),
00028       mRequestId(requestId),
00029       mResponseData(responseData),
00030       mIsFinal(isFinal) {}
00031 
00032    ~ResponseInfo() {}
00033 
00034    unsigned int getConnectionId() const { return mConnectionId; }
00035    unsigned int getRequestId() const { return mRequestId; }
00036    const resip::Data& getResponseData() const { return mResponseData; }
00037    bool getIsFinal() const { return mIsFinal; }
00038 
00039 private:
00040    unsigned int mConnectionId;
00041    unsigned int mRequestId;
00042    resip::Data mResponseData;
00043    bool mIsFinal;
00044 };
00045 
00046 class XmlRpcServerBase
00047 {
00048    friend class XmlRpcConnection;
00049       
00050 public:
00051    XmlRpcServerBase(int port, resip::IpVersion version);
00052    virtual ~XmlRpcServerBase();
00053       
00054    void buildFdSet(resip::FdSet& fdset);
00055    void process(resip::FdSet& fdset);
00056 
00057    bool isSane();
00058    static void logSocketError(int e);
00059 
00060    // thread safe - uses fifo
00061    void sendResponse(unsigned int connectionId,
00062                      unsigned int requestId,
00063                      const resip::Data& responseData,
00064                      bool isFinal=true);
00065 
00066    // thread safe - uses fifo (use connectionId == 0 to send to all connections)
00067    void sendEvent(unsigned int connectionId,
00068                   const resip::Data& eventData);
00069 
00070 protected:
00071    virtual void handleRequest(unsigned int connectionId, 
00072                               unsigned int requestId, 
00073                               const resip::Data& request) = 0; 
00074       
00075 private:
00076    static const unsigned int MaxConnections = 60;   // Note:  use caution if making this any bigger, default fd_set size in windows is 64
00077       
00078    resip::Socket mFd;
00079    resip::Tuple mTuple;
00080    bool mSane;
00081 
00082    typedef std::map<unsigned int, XmlRpcConnection*> ConnectionMap;
00083    ConnectionMap mConnections;
00084    void closeOldestConnection();
00085 
00086    resip::Fifo<ResponseInfo> mResponseFifo;
00087    resip::SelectInterruptor mSelectInterruptor;
00088 };
00089 
00090 }
00091 
00092 #endif  
00093 
00094 /* ====================================================================
00095  * The Vovida Software License, Version 1.0 
00096  * 
00097  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00098  * Copyright (c) 2010 SIP Spectrum, Inc.  All rights reserved.
00099  * 
00100  * Redistribution and use in source and binary forms, with or without
00101  * modification, are permitted provided that the following conditions
00102  * are met:
00103  * 
00104  * 1. Redistributions of source code must retain the above copyright
00105  *    notice, this list of conditions and the following disclaimer.
00106  * 
00107  * 2. Redistributions in binary form must reproduce the above copyright
00108  *    notice, this list of conditions and the following disclaimer in
00109  *    the documentation and/or other materials provided with the
00110  *    distribution.
00111  * 
00112  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00113  *    and "Vovida Open Communication Application Library (VOCAL)" must
00114  *    not be used to endorse or promote products derived from this
00115  *    software without prior written permission. For written
00116  *    permission, please contact vocal@vovida.org.
00117  *
00118  * 4. Products derived from this software may not be called "VOCAL", nor
00119  *    may "VOCAL" appear in their name, without prior written
00120  *    permission of Vovida Networks, Inc.
00121  * 
00122  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00123  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00124  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00125  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00126  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00127  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00128  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00129  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00130  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00131  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00132  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00133  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00134  * DAMAGE.
00135  * 
00136  * ====================================================================
00137  * 
00138  * This software consists of voluntary contributions made by Vovida
00139  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00140  * Inc.  For more information on Vovida Networks, Inc., please see
00141  * <http://www.vovida.org/>.
00142  *
00143  */
00144