summaryrefslogtreecommitdiffstats
path: root/branches/lydia/xmlrpc++/XmlRpcThreadedServer.h
blob: bedbeecd0ca1e6bbdf0a9cbe83d3d9c313245ed0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#ifndef _XMLRPCTHREADEDSERVER_H_
#define _XMLRPCTHREADEDSERVER_H_
//
// XmlRpc++ Copyright (c) 2002-2003 by Chris Morley
//
#if defined(_MSC_VER)
# pragma warning(disable:4786)    // identifier was truncated in debug info
#endif

#ifndef MAKEDEPEND
# include <map>
# include <vector>
#endif


#include "XmlRpcMutex.h"
#include "XmlRpcServer.h"
#include "XmlRpcThread.h"


namespace XmlRpc {

  //! A class to handle multiple simultaneous XML RPC requests
  class XmlRpcThreadedServer : public XmlRpcServer {
  public:

    //! Create a server object with a specified number of worker threads.
    XmlRpcThreadedServer(int nWorkers = 6) : _workers(nWorkers) {}


    //! Execute a request

  protected:

    //! Each client request is assigned to one worker to handle.
    //! Workers are executed on separate threads, and one worker may be
    //! responsible for dispatching events to multiple client connections.
    class Worker : XmlRpcRunnable {
    public:
      //! Constructor. Executes the run method in a separate thread.
      Worker() { _thread.setRunnable(this); _thread.start(); }

      //! Implement the Runnable interface
      void run();

    protected:

      //! The thread this worker is running in.
      XmlRpcThread _thread;

    };


    //! The worker pool
    std::vector<Worker> _workers;


    //! Serialize dispatcher access
    XmlRpcMutex _mutex;


  };  // class XmlRpcThreadedServer

}

#endif  // _XMLRPCTHREADEDSERVER_H_