~ubuntu-branches/ubuntu/saucy/resiprocate/saucy-proposed

« back to all changes in this revision

Viewing changes to apps/clicktocall/XmlRpcServerBase.hxx

  • Committer: Package Import Robot
  • Author(s): Daniel Pocock
  • Date: 2012-05-17 19:29:59 UTC
  • Revision ID: package-import@ubuntu.com-20120517192959-vv00m77isztdy64q
Tags: upstream-1.8.2
ImportĀ upstreamĀ versionĀ 1.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if !defined(XmlRpcServerBase_hxx)
 
2
#define XmlRpcServerBase_hxx 
 
3
 
 
4
#include <map>
 
5
#include <rutil/Data.hxx>
 
6
#include <rutil/Socket.hxx>
 
7
#include <rutil/TransportType.hxx>
 
8
#include <rutil/Fifo.hxx>
 
9
#include <resip/stack/Tuple.hxx>
 
10
#include <rutil/SelectInterruptor.hxx>
 
11
 
 
12
namespace clicktocall
 
13
{
 
14
class XmlRpcConnection;
 
15
 
 
16
class ResponseInfo
 
17
{
 
18
public:
 
19
   ResponseInfo(unsigned int connectionId,
 
20
                unsigned int requestId,
 
21
                const resip::Data& responseData,
 
22
                bool isFinal) :
 
23
      mConnectionId(connectionId),
 
24
      mRequestId(requestId),
 
25
      mResponseData(responseData),
 
26
      mIsFinal(isFinal) {}
 
27
 
 
28
   ~ResponseInfo() {}
 
29
 
 
30
   unsigned int getConnectionId() const { return mConnectionId; }
 
31
   unsigned int getRequestId() const { return mRequestId; }
 
32
   const resip::Data& getResponseData() const { return mResponseData; }
 
33
   bool getIsFinal() const { return mIsFinal; }
 
34
 
 
35
private:
 
36
   unsigned int mConnectionId;
 
37
   unsigned int mRequestId;
 
38
   resip::Data mResponseData;
 
39
   bool mIsFinal;
 
40
};
 
41
 
 
42
class XmlRpcServerBase
 
43
{
 
44
   friend class XmlRpcConnection;
 
45
      
 
46
public:
 
47
   XmlRpcServerBase(int port, resip::IpVersion version);
 
48
   virtual ~XmlRpcServerBase();
 
49
      
 
50
   void buildFdSet(resip::FdSet& fdset);
 
51
   void process(resip::FdSet& fdset);
 
52
 
 
53
   bool isSane();
 
54
   static void logSocketError(int e);
 
55
 
 
56
   // thread safe - uses fifo
 
57
   void sendResponse(unsigned int connectionId,
 
58
                     unsigned int requestId, 
 
59
                     const resip::Data& responseData,
 
60
                     bool isFinal=true);
 
61
 
 
62
protected:
 
63
   virtual void handleRequest(unsigned int connectionId, 
 
64
                              unsigned int requestId, 
 
65
                              const resip::Data& request) = 0; 
 
66
      
 
67
private:
 
68
   static const unsigned int MaxConnections = 60;   // Note:  use caution if making this any bigger, default fd_set size in windows is 64
 
69
      
 
70
   resip::Socket mFd;
 
71
   resip::Tuple mTuple;
 
72
   bool mSane;
 
73
 
 
74
   typedef std::map<unsigned int, XmlRpcConnection*> ConnectionMap;
 
75
   ConnectionMap mConnections;
 
76
   void closeOldestConnection();
 
77
 
 
78
   resip::Fifo<ResponseInfo> mResponseFifo;
 
79
   resip::SelectInterruptor mSelectInterruptor;
 
80
};
 
81
 
 
82
}
 
83
 
 
84
#endif  
 
85
 
 
86
/* ====================================================================
 
87
 
 
88
 Copyright (c) 2009, SIP Spectrum, Inc.
 
89
 All rights reserved.
 
90
 
 
91
 Redistribution and use in source and binary forms, with or without
 
92
 modification, are permitted provided that the following conditions are 
 
93
 met:
 
94
 
 
95
 1. Redistributions of source code must retain the above copyright 
 
96
    notice, this list of conditions and the following disclaimer. 
 
97
 
 
98
 2. Redistributions in binary form must reproduce the above copyright
 
99
    notice, this list of conditions and the following disclaimer in the
 
100
    documentation and/or other materials provided with the distribution. 
 
101
 
 
102
 3. Neither the name of SIP Spectrum nor the names of its contributors 
 
103
    may be used to endorse or promote products derived from this 
 
104
    software without specific prior written permission. 
 
105
 
 
106
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 
107
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 
108
 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 
109
 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 
110
 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 
111
 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 
112
 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 
113
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 
114
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 
115
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 
116
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
117
 
 
118
 ==================================================================== */
 
119