The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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_PROCESS_STATE_H |
| 18 | #define ANDROID_PROCESS_STATE_H |
| 19 | |
Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 20 | #include <binder/IBinder.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | #include <utils/KeyedVector.h> |
| 22 | #include <utils/String8.h> |
| 23 | #include <utils/String16.h> |
| 24 | |
| 25 | #include <utils/threads.h> |
| 26 | |
| 27 | // --------------------------------------------------------------------------- |
| 28 | namespace android { |
| 29 | |
| 30 | // Global variables |
| 31 | extern int mArgC; |
| 32 | extern const char* const* mArgV; |
| 33 | extern int mArgLen; |
| 34 | |
| 35 | class IPCThreadState; |
| 36 | |
| 37 | class ProcessState : public virtual RefBase |
| 38 | { |
| 39 | public: |
| 40 | static sp<ProcessState> self(); |
| 41 | |
| 42 | static void setSingleProcess(bool singleProcess); |
| 43 | |
| 44 | void setContextObject(const sp<IBinder>& object); |
| 45 | sp<IBinder> getContextObject(const sp<IBinder>& caller); |
| 46 | |
| 47 | void setContextObject(const sp<IBinder>& object, |
| 48 | const String16& name); |
| 49 | sp<IBinder> getContextObject(const String16& name, |
| 50 | const sp<IBinder>& caller); |
| 51 | |
| 52 | bool supportsProcesses() const; |
| 53 | |
| 54 | void startThreadPool(); |
| 55 | |
| 56 | typedef bool (*context_check_func)(const String16& name, |
| 57 | const sp<IBinder>& caller, |
| 58 | void* userData); |
| 59 | |
| 60 | bool isContextManager(void) const; |
| 61 | bool becomeContextManager( |
| 62 | context_check_func checkFunc, |
| 63 | void* userData); |
| 64 | |
| 65 | sp<IBinder> getStrongProxyForHandle(int32_t handle); |
| 66 | wp<IBinder> getWeakProxyForHandle(int32_t handle); |
| 67 | void expungeHandle(int32_t handle, IBinder* binder); |
| 68 | |
| 69 | void setArgs(int argc, const char* const argv[]); |
| 70 | int getArgC() const; |
| 71 | const char* const* getArgV() const; |
| 72 | |
| 73 | void setArgV0(const char* txt); |
| 74 | |
| 75 | void spawnPooledThread(bool isMain); |
| 76 | |
| 77 | private: |
| 78 | friend class IPCThreadState; |
| 79 | |
| 80 | ProcessState(); |
| 81 | ~ProcessState(); |
| 82 | |
| 83 | ProcessState(const ProcessState& o); |
| 84 | ProcessState& operator=(const ProcessState& o); |
| 85 | |
| 86 | struct handle_entry { |
| 87 | IBinder* binder; |
| 88 | RefBase::weakref_type* refs; |
| 89 | }; |
| 90 | |
| 91 | handle_entry* lookupHandleLocked(int32_t handle); |
| 92 | |
| 93 | int mDriverFD; |
| 94 | void* mVMStart; |
| 95 | |
| 96 | mutable Mutex mLock; // protects everything below. |
| 97 | |
| 98 | Vector<handle_entry>mHandleToObject; |
| 99 | |
| 100 | bool mManagesContexts; |
| 101 | context_check_func mBinderContextCheckFunc; |
| 102 | void* mBinderContextUserData; |
| 103 | |
| 104 | KeyedVector<String16, sp<IBinder> > |
| 105 | mContexts; |
| 106 | |
| 107 | |
| 108 | String8 mRootDir; |
| 109 | bool mThreadPoolStarted; |
| 110 | volatile int32_t mThreadPoolSeq; |
| 111 | }; |
| 112 | |
| 113 | }; // namespace android |
| 114 | |
| 115 | // --------------------------------------------------------------------------- |
| 116 | |
| 117 | #endif // ANDROID_PROCESS_STATE_H |