1 : // Copyright 2014 Google Inc. All Rights Reserved.
2 : //
3 : // Licensed under the Apache License, Version 2.0 (the "License");
4 : // you may not use this file except in compliance with the License.
5 : // You may obtain a copy of the License at
6 : //
7 : // http://www.apache.org/licenses/LICENSE-2.0
8 : //
9 : // Unless required by applicable law or agreed to in writing, software
10 : // distributed under the License is distributed on an "AS IS" BASIS,
11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 : // See the License for the specific language governing permissions and
13 : // limitations under the License.
14 :
15 : #ifndef SYZYGY_KASKO_SERVICE_BRIDGE_H_
16 : #define SYZYGY_KASKO_SERVICE_BRIDGE_H_
17 :
18 : #include "base/macros.h"
19 : #include "base/memory/scoped_ptr.h"
20 : #include "base/strings/string16.h"
21 :
22 : #include "syzygy/kasko/kasko_rpc.h"
23 :
24 m : namespace common {
25 m : namespace rpc {
26 :
27 m : class ScopedRpcInterfaceRegistration;
28 :
29 m : } // namespace rpc
30 m : } // namespace common
31 :
32 m : namespace kasko {
33 :
34 m : class Service;
35 :
36 : // Establishes an RPC service that forwards requests for the Kasko interface to
37 : // a Service implementation. The Service will be invoked on a worker thread.
38 : //
39 : // Only a single instance of this class may exist at a time in a given process.
40 m : class ServiceBridge {
41 m : public:
42 : // Instantiates a ServiceBridge configured to use |protocol| and |endpoint|
43 : // and to forwards requests to |service|.
44 m : ServiceBridge(const base::string16& protocol, const base::string16& endpoint,
45 m : scoped_ptr<Service> service);
46 m : ~ServiceBridge();
47 :
48 : // Starts serving requests. Returns immediately. The return value indicates
49 : // whether the service successfully started.
50 : //
51 : // If Run() returns true you _must_ call Stop() before destroying the
52 : // ServiceBridge.
53 m : bool Run();
54 :
55 : // Stops listening for new requests. Blocks until all in-process requests are
56 : // handled. It is harmless to call Stop() on a non-running ServiceBridge.
57 m : void Stop();
58 :
59 m : private:
60 : // Without the parentheses the '::' is associated with 'boolean'.
61 m : friend boolean(::KaskoService_SendDiagnosticReport)( // NOLINT
62 m : handle_t IDL_handle,
63 m : MinidumpRequest request);
64 :
65 m : scoped_ptr<common::rpc::ScopedRpcInterfaceRegistration>
66 m : interface_registration_;
67 m : scoped_ptr<Service> service_;
68 :
69 m : base::string16 protocol_;
70 m : base::string16 endpoint_;
71 m : bool running_;
72 :
73 m : DISALLOW_COPY_AND_ASSIGN(ServiceBridge);
74 m : };
75 :
76 m : } // namespace kasko
77 :
78 : #endif // SYZYGY_KASKO_SERVICE_BRIDGE_H_
|