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 <memory>
19 :
20 : #include "base/macros.h"
21 : #include "base/strings/string16.h"
22 :
23 : #include "syzygy/kasko/kasko_rpc.h"
24 :
25 m : namespace common {
26 m : namespace rpc {
27 :
28 m : class ScopedRpcInterfaceRegistration;
29 :
30 m : } // namespace rpc
31 m : } // namespace common
32 :
33 m : namespace kasko {
34 :
35 m : class Service;
36 :
37 : // Establishes an RPC service that forwards requests for the Kasko interface to
38 : // a Service implementation. The Service will be invoked on a worker thread.
39 : //
40 : // Only a single instance of this class may exist at a time in a given process.
41 m : class ServiceBridge {
42 m : public:
43 : // Instantiates a ServiceBridge configured to use |protocol| and |endpoint|
44 : // and to forwards requests to |service|.
45 m : ServiceBridge(const base::string16& protocol,
46 m : const base::string16& endpoint,
47 m : std::unique_ptr<Service> service);
48 m : ~ServiceBridge();
49 :
50 : // Starts serving requests. Returns immediately. The return value indicates
51 : // whether the service successfully started.
52 : //
53 : // If Run() returns true you _must_ call Stop() before destroying the
54 : // ServiceBridge.
55 m : bool Run();
56 :
57 : // Stops listening for new requests. Blocks until all in-process requests are
58 : // handled. It is harmless to call Stop() on a non-running ServiceBridge.
59 m : void Stop();
60 :
61 m : private:
62 : // Without the parentheses the '::' is associated with 'boolean'.
63 m : friend boolean(::KaskoService_SendDiagnosticReport)( // NOLINT
64 m : handle_t IDL_handle,
65 m : MinidumpRequest request);
66 :
67 m : std::unique_ptr<common::rpc::ScopedRpcInterfaceRegistration>
68 m : interface_registration_;
69 m : std::unique_ptr<Service> service_;
70 :
71 m : base::string16 protocol_;
72 m : base::string16 endpoint_;
73 m : bool running_;
74 :
75 m : DISALLOW_COPY_AND_ASSIGN(ServiceBridge);
76 m : };
77 :
78 m : } // namespace kasko
79 :
80 : #endif // SYZYGY_KASKO_SERVICE_BRIDGE_H_
|