1 // 2 // Copyright 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/memory/ref_counted.h> 20 21 #include "service/ipc/ipc_manager.h" 22 23 namespace bluetooth { 24 class Adapter; 25 } // namespace bluetooth 26 27 namespace ipc { 28 29 // IPCHandler is an interface that classes implementing different IPC mechanisms 30 // must conform to. 31 class IPCHandler : public base::RefCountedThreadSafe<IPCHandler> { 32 public: 33 IPCHandler(bluetooth::Adapter* adapter, IPCManager::Delegate* delegate); 34 35 IPCHandler(const IPCHandler&) = delete; 36 IPCHandler& operator=(const IPCHandler&) = delete; 37 38 virtual ~IPCHandler(); 39 40 // Initializes and runs the IPC mechanism. Returns true on success, false 41 // otherwise. 42 virtual bool Run() = 0; 43 44 // Stops the IPC mechanism. 45 virtual void Stop() = 0; 46 47 protected: 48 // Getters for private members to allow subclasses to access them in read-only 49 // fashion. adapter()50 bluetooth::Adapter* adapter() const { return adapter_; } delegate()51 IPCManager::Delegate* delegate() const { return delegate_; } 52 53 private: 54 IPCHandler() = default; 55 56 // Weak reference to the global Adapter instance. 57 bluetooth::Adapter* adapter_; 58 59 // The delegate that is interested in notifications from us. 60 IPCManager::Delegate* delegate_; 61 }; 62 63 } // namespace ipc 64