source: sources/src/rpcServer.cc @ 1464:3f6711617be1

Revision 1464:3f6711617be1, 3.0 KB checked in by niam, 22 months ago (diff)

{issue #58[resolved]} support for non-c++ exceptions

Line 
1/***************************************************************************
2 *            rpcServer.cc
3 *
4 *  Sat Mar 29 2008
5 *  Copyright  2008  Dmytro Milinevskyy
6 *  milinevskyy@gmail.com
7 ****************************************************************************/
8
9/*
10 *  This program is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU Lesser General Public License version 2.1 as published by
12 *  the Free Software Foundation;
13 *
14 *  This program is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU Library General Public License for more details.
18 *
19 *  You should have received a copy of the GNU Lesser General Public License
20 *  along with this program; if not, write to the Free Software
21 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24/**
25 * vim indentation settings
26 * set tabstop=4
27 * set shiftwidth=4
28 */
29
30#include <libdodo/directives.h>
31
32#include <libdodo/rpcServer.h>
33#include <libdodo/ioChannel.h>
34#include <libdodo/types.h>
35#include <libdodo/rpcValue.h>
36#include <libdodo/rpcResponse.h>
37#include <libdodo/rpcMethod.h>
38#include <libdodo/exceptionBasic.h>
39
40using namespace dodo::rpc;
41
42server::server(io::channel &io) : defaultHandler(&rpcDefaultHandler),
43                                  io(io)
44{
45}
46
47//-------------------------------------------------------------------
48
49server::~server()
50{
51}
52
53//-------------------------------------------------------------------
54
55response
56server::rpcDefaultHandler(const dodo::string &,
57                          const dodoArray<value> &,
58                          const void *,
59                          void *)
60{
61    response response;
62    response.fault("rpcDefaultHandler");
63
64    return response;
65}
66
67//-------------------------------------------------------------------
68
69void
70server::setDefault(handler handler)
71{
72    defaultHandler = handler;
73}
74
75//-------------------------------------------------------------------
76
77void
78server::setHandler(const dodo::string &method,
79                   handler          handler)
80{
81    handlers.insert(std::make_pair(method, handler));
82}
83
84//-------------------------------------------------------------------
85
86void
87server::removeHandler(const dodo::string &method)
88{
89    handlers.erase(method);
90}
91
92//-------------------------------------------------------------------
93
94void
95server::serve()
96{
97    dodo_try {
98        method meth = processCallRequest();
99
100        dodoMap<dodo::string, handler, dodoMapStringCompare>::iterator handler = handlers.find(meth.name);
101
102        if (handler == handlers.end())
103            processCallResult(defaultHandler(meth.name, meth.arguments, NULL, NULL));
104        else
105            processCallResult(handler->second(meth.name, meth.arguments, NULL, NULL));
106    } dodo_catch (exception::basic *e UNUSED) {
107        response response;
108        response.fault(e->errStr);
109
110        processCallResult(response);
111    }
112}
113
114//-------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.