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