Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 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 | |
| 17 | // |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 18 | #ifndef ANDROID_HARDWARE_IINTERFACE_H |
| 19 | #define ANDROID_HARDWARE_IINTERFACE_H |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 20 | |
Martijn Coenen | 4080edc | 2016-05-04 14:17:02 +0200 | [diff] [blame] | 21 | #include <hwbinder/Binder.h> |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 22 | |
Steven Moreland | b5f6e00 | 2021-02-26 01:51:20 +0000 | [diff] [blame] | 23 | // WARNING: this code is part of libhwbinder, a fork of libbinder. Generally, |
| 24 | // this means that it is only relevant to HIDL. Any AIDL- or libbinder-specific |
| 25 | // code should not try to use these things. |
| 26 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 27 | namespace android { |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 28 | namespace hardware { |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 29 | // ---------------------------------------------------------------------- |
| 30 | |
| 31 | class IInterface : public virtual RefBase |
| 32 | { |
| 33 | public: |
Mathias Agopian | a6286c3 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 34 | IInterface(); |
Marco Nelissen | 461a672 | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 35 | static sp<IBinder> asBinder(const IInterface*); |
| 36 | static sp<IBinder> asBinder(const sp<IInterface>&); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 37 | protected: |
Mathias Agopian | a6286c3 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 38 | virtual ~IInterface(); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 39 | virtual IBinder* onAsBinder() = 0; |
| 40 | }; |
| 41 | |
| 42 | // ---------------------------------------------------------------------- |
| 43 | |
| 44 | template<typename INTERFACE> |
Yifan Hong | a2ce3b8 | 2017-01-12 14:49:26 -0800 | [diff] [blame] | 45 | class BpInterface : public INTERFACE, public IInterface, public BpHwRefBase |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 46 | { |
| 47 | public: |
Chih-Hung Hsieh | 2ecdeaf | 2016-09-01 11:44:54 -0700 | [diff] [blame] | 48 | explicit BpInterface(const sp<IBinder>& remote); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 49 | virtual IBinder* onAsBinder(); |
| 50 | }; |
| 51 | |
| 52 | // ---------------------------------------------------------------------- |
| 53 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 54 | // ---------------------------------------------------------------------- |
Mathias Agopian | a6286c3 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 55 | // No user-serviceable parts after this... |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 56 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 57 | |
| 58 | template<typename INTERFACE> |
| 59 | inline BpInterface<INTERFACE>::BpInterface(const sp<IBinder>& remote) |
Yifan Hong | a2ce3b8 | 2017-01-12 14:49:26 -0800 | [diff] [blame] | 60 | : BpHwRefBase(remote) |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 61 | { |
| 62 | } |
| 63 | |
| 64 | template<typename INTERFACE> |
| 65 | inline IBinder* BpInterface<INTERFACE>::onAsBinder() |
| 66 | { |
| 67 | return remote(); |
| 68 | } |
Andreas Huber | 85af321 | 2016-08-05 14:30:52 -0700 | [diff] [blame] | 69 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 70 | // ---------------------------------------------------------------------- |
| 71 | |
Steven Moreland | 7173a4c | 2019-09-26 15:55:02 -0700 | [diff] [blame] | 72 | } // namespace hardware |
| 73 | } // namespace android |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 74 | |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 75 | #endif // ANDROID_HARDWARE_IINTERFACE_H |