1 //
2 //  Copyright (C) 2015 Google, Inc.
3 //
4 //  Licensed under the Apache License, Version 2.0 (the "License");
5 //  you may not use this file except in compliance with the License.
6 //  You may obtain a copy of the License at:
7 //
8 //  http://www.apache.org/licenses/LICENSE-2.0
9 //
10 //  Unless required by applicable law or agreed to in writing, software
11 //  distributed under the License is distributed on an "AS IS" BASIS,
12 //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 //  See the License for the specific language governing permissions and
14 //  limitations under the License.
15 //
16 
17 #pragma once
18 
19 #include <base/macros.h>
20 #include <base/memory/ref_counted.h>
21 
22 #include "service/ipc/ipc_manager.h"
23 
24 namespace bluetooth {
25 class Adapter;
26 }  // namespace bluetooth
27 
28 namespace ipc {
29 
30 // IPCHandler is an interface that classes implementing different IPC mechanisms
31 // must conform to.
32 class IPCHandler : public base::RefCountedThreadSafe<IPCHandler> {
33  public:
34   IPCHandler(bluetooth::Adapter* adapter, IPCManager::Delegate* delegate);
35   virtual ~IPCHandler();
36 
37   // Initializes and runs the IPC mechanism. Returns true on success, false
38   // otherwise.
39   virtual bool Run() = 0;
40 
41   // Stops the IPC mechanism.
42   virtual void Stop() = 0;
43 
44  protected:
45   // Getters for private members to allow subclasses to access them in read-only
46   // fashion.
adapter()47   bluetooth::Adapter* adapter() const { return adapter_; }
delegate()48   IPCManager::Delegate* delegate() const { return delegate_; }
49 
50  private:
51   IPCHandler() = default;
52 
53   // Weak reference to the global Adapter instance.
54   bluetooth::Adapter* adapter_;
55 
56   // The delegate that is interested in notifications from us.
57   IPCManager::Delegate* delegate_;
58 
59   DISALLOW_COPY_AND_ASSIGN(IPCHandler);
60 };
61 
62 }  // namespace ipc
63