• 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 // 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             void                setContextObject(const sp<IBinder>& object);
43             sp<IBinder>         getContextObject(const sp<IBinder>& caller);
44 
45             void                setContextObject(const sp<IBinder>& object,
46                                                  const String16& name);
47             sp<IBinder>         getContextObject(const String16& name,
48                                                  const sp<IBinder>& caller);
49 
50             void                startThreadPool();
51 
52     typedef bool (*context_check_func)(const String16& name,
53                                        const sp<IBinder>& caller,
54                                        void* userData);
55 
56             bool                isContextManager(void) const;
57             bool                becomeContextManager(
58                                     context_check_func checkFunc,
59                                     void* userData);
60 
61             sp<IBinder>         getStrongProxyForHandle(int32_t handle);
62             wp<IBinder>         getWeakProxyForHandle(int32_t handle);
63             void                expungeHandle(int32_t handle, IBinder* binder);
64 
65             void                setArgs(int argc, const char* const argv[]);
66             int                 getArgC() const;
67             const char* const*  getArgV() const;
68 
69             void                setArgV0(const char* txt);
70 
71             void                spawnPooledThread(bool isMain);
72 
73             status_t            setThreadPoolMaxThreadCount(size_t maxThreads);
74 
75 private:
76     friend class IPCThreadState;
77 
78                                 ProcessState();
79                                 ~ProcessState();
80 
81                                 ProcessState(const ProcessState& o);
82             ProcessState&       operator=(const ProcessState& o);
83 
84             struct handle_entry {
85                 IBinder* binder;
86                 RefBase::weakref_type* refs;
87             };
88 
89             handle_entry*       lookupHandleLocked(int32_t handle);
90 
91             int                 mDriverFD;
92             void*               mVMStart;
93 
94     mutable Mutex               mLock;  // protects everything below.
95 
96             Vector<handle_entry>mHandleToObject;
97 
98             bool                mManagesContexts;
99             context_check_func  mBinderContextCheckFunc;
100             void*               mBinderContextUserData;
101 
102             KeyedVector<String16, sp<IBinder> >
103                                 mContexts;
104 
105 
106             String8             mRootDir;
107             bool                mThreadPoolStarted;
108     volatile int32_t            mThreadPoolSeq;
109 };
110 
111 }; // namespace android
112 
113 // ---------------------------------------------------------------------------
114 
115 #endif // ANDROID_PROCESS_STATE_H
116