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