1 /* 2 * Copyright 2019 The Android Open Source Project 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 #ifndef ANDROID_AUTOMOTIVE_COMPUTEPIPE_ROUTER_PIPE_HANDLE 17 #define ANDROID_AUTOMOTIVE_COMPUTEPIPE_ROUTER_PIPE_HANDLE 18 19 #include <memory> 20 #include <string> 21 #include <utility> 22 23 namespace android { 24 namespace automotive { 25 namespace computepipe { 26 namespace router { 27 28 /** 29 * This abstracts the runner interface object and hides its 30 * details from the inner routing logic. 31 */ 32 template <typename T> 33 class PipeHandle { 34 public: PipeHandle(std::unique_ptr<T> intf)35 explicit PipeHandle(std::unique_ptr<T> intf) : mInterface(std::move(intf)) { 36 } 37 // Check if runner process is still alive 38 virtual bool isAlive() = 0; 39 // Start the monitor for the pipe 40 virtual bool startPipeMonitor() = 0; 41 // Any successful client lookup, clones this handle 42 // The implementation must handle refcounting of remote objects 43 // accordingly. 44 virtual PipeHandle<T>* clone() const = 0; 45 // Retrieve the underlying remote IPC object getInterface()46 std::shared_ptr<T> getInterface() { 47 return mInterface; 48 } 49 virtual ~PipeHandle() = default; 50 51 protected: PipeHandle(std::shared_ptr<T> intf)52 explicit PipeHandle(std::shared_ptr<T> intf) : mInterface(intf){}; 53 // Interface object 54 std::shared_ptr<T> mInterface; 55 }; 56 57 } // namespace router 58 } // namespace computepipe 59 } // namespace automotive 60 } // namespace android 61 62 #endif 63