blob: 34048816cd90f70eb87aecb1ad00de78e7ba9af3 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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#ifndef ANDROID_BINDER_H
18#define ANDROID_BINDER_H
19
Bailey Forrest6913c462015-08-18 17:15:10 -070020#include <atomic>
Hans Boehm3effaba2014-08-12 22:56:00 +000021#include <stdint.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070022#include <binder/IBinder.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023
24// ---------------------------------------------------------------------------
25namespace android {
26
27class BBinder : public IBinder
28{
29public:
30 BBinder();
31
Mathias Agopian83c04462009-05-22 19:00:22 -070032 virtual const String16& getInterfaceDescriptor() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033 virtual bool isBinderAlive() const;
34 virtual status_t pingBinder();
35 virtual status_t dump(int fd, const Vector<String16>& args);
36
37 virtual status_t transact( uint32_t code,
38 const Parcel& data,
39 Parcel* reply,
40 uint32_t flags = 0);
41
42 virtual status_t linkToDeath(const sp<DeathRecipient>& recipient,
43 void* cookie = NULL,
44 uint32_t flags = 0);
45
46 virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient,
47 void* cookie = NULL,
48 uint32_t flags = 0,
49 wp<DeathRecipient>* outRecipient = NULL);
50
51 virtual void attachObject( const void* objectID,
52 void* object,
53 void* cleanupCookie,
54 object_cleanup_func func);
55 virtual void* findObject(const void* objectID) const;
56 virtual void detachObject(const void* objectID);
57
58 virtual BBinder* localBinder();
59
60protected:
61 virtual ~BBinder();
62
63 virtual status_t onTransact( uint32_t code,
64 const Parcel& data,
65 Parcel* reply,
66 uint32_t flags = 0);
67
68private:
69 BBinder(const BBinder& o);
70 BBinder& operator=(const BBinder& o);
71
72 class Extras;
73
Bailey Forrest6913c462015-08-18 17:15:10 -070074 std::atomic<Extras*> mExtras;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080075 void* mReserved0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076};
77
78// ---------------------------------------------------------------------------
79
80class BpRefBase : public virtual RefBase
81{
82protected:
Chih-Hung Hsiehe3ab0e82016-09-01 11:44:54 -070083 explicit BpRefBase(const sp<IBinder>& o);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084 virtual ~BpRefBase();
85 virtual void onFirstRef();
86 virtual void onLastStrongRef(const void* id);
87 virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
88
89 inline IBinder* remote() { return mRemote; }
90 inline IBinder* remote() const { return mRemote; }
91
92private:
93 BpRefBase(const BpRefBase& o);
94 BpRefBase& operator=(const BpRefBase& o);
95
96 IBinder* const mRemote;
97 RefBase::weakref_type* mRefs;
Bailey Forrest6913c462015-08-18 17:15:10 -070098 std::atomic<int32_t> mState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099};
100
101}; // namespace android
102
103// ---------------------------------------------------------------------------
104
105#endif // ANDROID_BINDER_H