blob: 0490fd3ec2063804fed003612fb5adb03f8f81c4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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#ifndef ANDROID_IPC_THREAD_STATE_H
18#define ANDROID_IPC_THREAD_STATE_H
19
20#include <utils/Errors.h>
21#include <utils/Parcel.h>
22#include <utils/ProcessState.h>
23#include <utils/Vector.h>
24
25#ifdef HAVE_WIN32_PROC
26typedef int uid_t;
27#endif
28
29// ---------------------------------------------------------------------------
30namespace android {
31
32class IPCThreadState
33{
34public:
35 static IPCThreadState* self();
36
37 sp<ProcessState> process();
38
39 status_t clearLastError();
40
41 int getCallingPid();
42 int getCallingUid();
43
44 int64_t clearCallingIdentity();
45 void restoreCallingIdentity(int64_t token);
46
47 void flushCommands();
48
49 void joinThreadPool(bool isMain = true);
50
51 // Stop the local process.
52 void stopProcess(bool immediate = true);
53
54 status_t transact(int32_t handle,
55 uint32_t code, const Parcel& data,
56 Parcel* reply, uint32_t flags);
57
58 void incStrongHandle(int32_t handle);
59 void decStrongHandle(int32_t handle);
60 void incWeakHandle(int32_t handle);
61 void decWeakHandle(int32_t handle);
62 status_t attemptIncStrongHandle(int32_t handle);
63 static void expungeHandle(int32_t handle, IBinder* binder);
64 status_t requestDeathNotification( int32_t handle,
65 BpBinder* proxy);
66 status_t clearDeathNotification( int32_t handle,
67 BpBinder* proxy);
68
69 static void shutdown();
70
71private:
72 IPCThreadState();
73 ~IPCThreadState();
74
75 status_t sendReply(const Parcel& reply, uint32_t flags);
76 status_t waitForResponse(Parcel *reply,
77 status_t *acquireResult=NULL);
78 status_t talkWithDriver(bool doReceive=true);
79 status_t writeTransactionData(int32_t cmd,
80 uint32_t binderFlags,
81 int32_t handle,
82 uint32_t code,
83 const Parcel& data,
84 status_t* statusBuffer);
85 status_t executeCommand(int32_t command);
86
87 void clearCaller();
88
89 static void threadDestructor(void *st);
90 static void freeBuffer(Parcel* parcel,
91 const uint8_t* data, size_t dataSize,
92 const size_t* objects, size_t objectsSize,
93 void* cookie);
94
95 const sp<ProcessState> mProcess;
96 Vector<BBinder*> mPendingStrongDerefs;
97 Vector<RefBase::weakref_type*> mPendingWeakDerefs;
98
99 Parcel mIn;
100 Parcel mOut;
101 status_t mLastError;
102 pid_t mCallingPid;
103 uid_t mCallingUid;
104};
105
106}; // namespace android
107
108// ---------------------------------------------------------------------------
109
110#endif // ANDROID_IPC_THREAD_STATE_H