blob: 16f2c4a8e399614c3412298a8d7e9eac05c3cc8d [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
Hans Boehm88b75412014-07-23 11:35:13 -070020#include <stdatomic.h>
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070021#include <binder/IBinder.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080022
23// ---------------------------------------------------------------------------
24namespace android {
25
26class BBinder : public IBinder
27{
28public:
29 BBinder();
30
Mathias Agopian83c04462009-05-22 19:00:22 -070031 virtual const String16& getInterfaceDescriptor() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032 virtual bool isBinderAlive() const;
33 virtual status_t pingBinder();
34 virtual status_t dump(int fd, const Vector<String16>& args);
35
36 virtual status_t transact( uint32_t code,
37 const Parcel& data,
38 Parcel* reply,
39 uint32_t flags = 0);
40
41 virtual status_t linkToDeath(const sp<DeathRecipient>& recipient,
42 void* cookie = NULL,
43 uint32_t flags = 0);
44
45 virtual status_t unlinkToDeath( const wp<DeathRecipient>& recipient,
46 void* cookie = NULL,
47 uint32_t flags = 0,
48 wp<DeathRecipient>* outRecipient = NULL);
49
50 virtual void attachObject( const void* objectID,
51 void* object,
52 void* cleanupCookie,
53 object_cleanup_func func);
54 virtual void* findObject(const void* objectID) const;
55 virtual void detachObject(const void* objectID);
56
57 virtual BBinder* localBinder();
58
59protected:
60 virtual ~BBinder();
61
62 virtual status_t onTransact( uint32_t code,
63 const Parcel& data,
64 Parcel* reply,
65 uint32_t flags = 0);
66
67private:
68 BBinder(const BBinder& o);
69 BBinder& operator=(const BBinder& o);
70
71 class Extras;
72
Hans Boehm88b75412014-07-23 11:35:13 -070073 atomic_uintptr_t mExtras; // should be atomic<Extras *>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 void* mReserved0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080075};
76
77// ---------------------------------------------------------------------------
78
79class BpRefBase : public virtual RefBase
80{
81protected:
82 BpRefBase(const sp<IBinder>& o);
83 virtual ~BpRefBase();
84 virtual void onFirstRef();
85 virtual void onLastStrongRef(const void* id);
86 virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
87
88 inline IBinder* remote() { return mRemote; }
89 inline IBinder* remote() const { return mRemote; }
90
91private:
92 BpRefBase(const BpRefBase& o);
93 BpRefBase& operator=(const BpRefBase& o);
94
95 IBinder* const mRemote;
96 RefBase::weakref_type* mRefs;
97 volatile int32_t mState;
98};
99
100}; // namespace android
101
102// ---------------------------------------------------------------------------
103
104#endif // ANDROID_BINDER_H