blob: 7fec75f8c1ca4cac0ef26cf02e4b94fa29036e7c [file] [log] [blame]
Mathias Agopian16475702009-05-19 19:08:10 -07001/*
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 Coenenf75a23d2016-08-01 11:55:17 +020018#ifndef ANDROID_HARDWARE_IINTERFACE_H
19#define ANDROID_HARDWARE_IINTERFACE_H
Mathias Agopian16475702009-05-19 19:08:10 -070020
Martijn Coenen4080edc2016-05-04 14:17:02 +020021#include <hwbinder/Binder.h>
Mathias Agopian16475702009-05-19 19:08:10 -070022
Steven Morelandb5f6e002021-02-26 01:51:20 +000023// 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 Agopian16475702009-05-19 19:08:10 -070027namespace android {
Martijn Coenenf75a23d2016-08-01 11:55:17 +020028namespace hardware {
Mathias Agopian16475702009-05-19 19:08:10 -070029// ----------------------------------------------------------------------
30
31class IInterface : public virtual RefBase
32{
33public:
Mathias Agopiana6286c32009-05-22 19:00:22 -070034 IInterface();
Marco Nelissen461a6722014-11-14 08:01:01 -080035 static sp<IBinder> asBinder(const IInterface*);
36 static sp<IBinder> asBinder(const sp<IInterface>&);
Mathias Agopian16475702009-05-19 19:08:10 -070037protected:
Mathias Agopiana6286c32009-05-22 19:00:22 -070038 virtual ~IInterface();
Mathias Agopian16475702009-05-19 19:08:10 -070039 virtual IBinder* onAsBinder() = 0;
40};
41
42// ----------------------------------------------------------------------
43
44template<typename INTERFACE>
Yifan Honga2ce3b82017-01-12 14:49:26 -080045class BpInterface : public INTERFACE, public IInterface, public BpHwRefBase
Mathias Agopian16475702009-05-19 19:08:10 -070046{
47public:
Chih-Hung Hsieh2ecdeaf2016-09-01 11:44:54 -070048 explicit BpInterface(const sp<IBinder>& remote);
Mathias Agopian16475702009-05-19 19:08:10 -070049 virtual IBinder* onAsBinder();
50};
51
52// ----------------------------------------------------------------------
53
Mathias Agopian16475702009-05-19 19:08:10 -070054// ----------------------------------------------------------------------
Mathias Agopiana6286c32009-05-22 19:00:22 -070055// No user-serviceable parts after this...
Mathias Agopian16475702009-05-19 19:08:10 -070056
Mathias Agopian16475702009-05-19 19:08:10 -070057
58template<typename INTERFACE>
59inline BpInterface<INTERFACE>::BpInterface(const sp<IBinder>& remote)
Yifan Honga2ce3b82017-01-12 14:49:26 -080060 : BpHwRefBase(remote)
Mathias Agopian16475702009-05-19 19:08:10 -070061{
62}
63
64template<typename INTERFACE>
65inline IBinder* BpInterface<INTERFACE>::onAsBinder()
66{
67 return remote();
68}
Andreas Huber85af3212016-08-05 14:30:52 -070069
Mathias Agopian16475702009-05-19 19:08:10 -070070// ----------------------------------------------------------------------
71
Steven Moreland7173a4c2019-09-26 15:55:02 -070072} // namespace hardware
73} // namespace android
Mathias Agopian16475702009-05-19 19:08:10 -070074
Martijn Coenenf75a23d2016-08-01 11:55:17 +020075#endif // ANDROID_HARDWARE_IINTERFACE_H