root/trunk/whisperlib/net/rpc/lib/server/rpc_services_manager.h

Revision 7, 4.8 kB (checked in by whispercastorg, 2 years ago)

version 0.2.0

Line 
1 // Copyright (c) 2009, Whispersoft s.r.l.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Whispersoft s.r.l. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: Cosmin Tudorache
31
32 #ifndef __NET_RPC_LIB_SERVER_RPC_SERVICES_MANAGER_H__
33 #define __NET_RPC_LIB_SERVER_RPC_SERVICES_MANAGER_H__
34
35 #include <map>
36 #include <string>
37
38 #include <whisperlib/net/rpc/lib/server/rpc_service_invoker.h>
39 #include <whisperlib/net/rpc/lib/server/rpc_core_types.h>
40
41 // This guy keeps all the RPCServices. He receives RPC calls and directs them
42 // to the appropiate RPCService for execution.
43
44 namespace rpc {
45
46 class ServicesManager {
47  public:
48   ServicesManager();
49   virtual ~ServicesManager();
50
51   //  Returns a list of registered services. Elements are separated by "glue".
52   string StrListServices(const string& glue) const;
53
54   //  Find service by name.
55   rpc::ServiceInvoker* FindService(const string& serviceName);
56
57   //  Register a new remote service.
58   //  The service name is given by service.GetName() .
59   //
60   //  Registering a "service" S having name N means that calling local method
61   //  Call(N, method, params, ..) will actually invoke
62   //  S.Call(method, params, ..) .
63   // input:
64   //   service: the service to register.
65   // returns:
66   //   Success status. It is illegal to register the same service twice.
67   // NOTE: you must NOT delete a registered service!
68   //       Call UnregisterService(..) before deleting the service.
69   bool RegisterService(rpc::ServiceInvoker& service);
70
71   // Unregister remote service by service name.
72   // This is the reverse of the RegisterService(service) method.
73   void UnregisterService(const string& serviceName);
74
75   // Unregister remote service. You must provide the same service object here,
76   // that was used on RegisterService(service).
77   void UnregisterService(const rpc::ServiceInvoker& service);
78
79
80   //  Executes the RPC query by finding the corresponding service,
81   //  and passeing query execution to that service.
82   // input:
83   //  [IN/OUT] q: contains the query to be executed (method, params) and also
84   //              has a completion method which forwards the result to
85   //              the transport layer.
86   //              After the query is executed, call q->Complete(return
87   //              value, status)
88   //               Return value can be any rpc::Object.
89   //               Status possible values:
90   //                  - RPC_SUCCESS = success.
91   //                  - RPC_SERVICE_UNAVAIL = no such service.
92   //                  - RPC_PROC_UNAVAIL = no such procedure.
93   //                  - RPC_GARBAGE_ARGS = bad parameters.
94   //                  - RPC_SYSTEM_ERR = unpredictable errors,
95   //                                     like out of memory.
96   // returns:
97   //  true = execution succeeded. However the call may have failed.
98   //         E.g. If the parameters are wrong, this Call should execute
99   //              q->Complete(rpc::Void(), RPC_GARBAGE_ARGS) and return true.
100   //  false = internal error. q->Complete has not been called.
101   //          Check GetLastError() for more info.
102   //          This should probably never happen.
103   bool Call(rpc::Query* query);
104
105   //  Describes the manager.
106   string ToString() const;
107  protected:
108   // Map of services. ["service name" -> service invoker]
109   typedef map<string, ServiceInvoker*> ServicesMap;
110   ServicesMap services_;
111
112  private:
113   DISALLOW_EVIL_CONSTRUCTORS(ServicesManager);
114 };
115 }
116 #endif   // __NET_RPC_LIB_SERVER_RPC_SERVICES_MANAGER_H__
Note: See TracBrowser for help on using the browser.