• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include <binder/IBinder.h>
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 class IPCThreadState;
31 
32 class ProcessState : public virtual RefBase
33 {
34 public:
35     static  sp<ProcessState>    self();
36 
37             void                setContextObject(const sp<IBinder>& object);
38             sp<IBinder>         getContextObject(const sp<IBinder>& caller);
39 
40             void                setContextObject(const sp<IBinder>& object,
41                                                  const String16& name);
42             sp<IBinder>         getContextObject(const String16& name,
43                                                  const sp<IBinder>& caller);
44 
45             void                startThreadPool();
46 
47     typedef bool (*context_check_func)(const String16& name,
48                                        const sp<IBinder>& caller,
49                                        void* userData);
50 
51             bool                isContextManager(void) const;
52             bool                becomeContextManager(
53                                     context_check_func checkFunc,
54                                     void* userData);
55 
56             sp<IBinder>         getStrongProxyForHandle(int32_t handle);
57             wp<IBinder>         getWeakProxyForHandle(int32_t handle);
58             void                expungeHandle(int32_t handle, IBinder* binder);
59 
60             void                spawnPooledThread(bool isMain);
61 
62             status_t            setThreadPoolMaxThreadCount(size_t maxThreads);
63             void                giveThreadPoolName();
64 
65 private:
66     friend class IPCThreadState;
67 
68                                 ProcessState();
69                                 ~ProcessState();
70 
71                                 ProcessState(const ProcessState& o);
72             ProcessState&       operator=(const ProcessState& o);
73             String8             makeBinderThreadName();
74 
75             struct handle_entry {
76                 IBinder* binder;
77                 RefBase::weakref_type* refs;
78             };
79 
80             handle_entry*       lookupHandleLocked(int32_t handle);
81 
82             int                 mDriverFD;
83             void*               mVMStart;
84 
85     mutable Mutex               mLock;  // protects everything below.
86 
87             Vector<handle_entry>mHandleToObject;
88 
89             bool                mManagesContexts;
90             context_check_func  mBinderContextCheckFunc;
91             void*               mBinderContextUserData;
92 
93             KeyedVector<String16, sp<IBinder> >
94                                 mContexts;
95 
96 
97             String8             mRootDir;
98             bool                mThreadPoolStarted;
99     volatile int32_t            mThreadPoolSeq;
100 };
101 
102 }; // namespace android
103 
104 // ---------------------------------------------------------------------------
105 
106 #endif // ANDROID_PROCESS_STATE_H
107