aboutsummaryrefslogtreecommitdiff
path: root/include/kdbinder/binder/IPCThreadState.h
blob: e034fe714654a41a726c9eae0edc1ab6149bbb5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef INCLUDE_KDBINDER_BINDER_IPCTHREADSTATE_H_
#define INCLUDE_KDBINDER_BINDER_IPCTHREADSTATE_H_

#include <binder/BpBinder.h>
#include <binder/ProcessState.h>
#include <binder/Parcel.h>

#include <kdbinder/kdbus/KDBinder.h>

#include <utils/RefBase.h>
#include <utils/Errors.h>

namespace android {

class IPCThreadState : public virtual RefBase {
 public:
  static IPCThreadState* self();

  pid_t getCallingPid() const;
  uid_t getCallingUid() const;

  void flushCommands();

  void joinThreadPool(bool isMain = true);

  void stopProcess(bool immediate = true);

  status_t transact(int32_t handle,
                    uint32_t code,
                    const Parcel& data,
                    Parcel* reply,
                    uint32_t flags = 0);

  status_t requestDeathNotification(int32_t handle,
                                    BpBinder *proxy);
  status_t clearDeathNotification(int32_t handle,
                                  BpBinder *proxy);

 private:
  IPCThreadState();
  ~IPCThreadState() {}

  // Represents the time each worker thread should spend waiting for a
  // request.
  // TODO: tune this.
  static const int kQuantumMs = 100;
  // This timeout value represents when a client should give up on a
  // transaction.
  // TODO: tune this.
  static const int kTimeOutMs = 1000000;

  static void threadDestructor(void *st);

  // Take the given entry and wait for a transaction request.  If a
  // transaction arrives then handle it by calling
  // entry.binder->transact.  Overwise return after kQuantumMs
  // milliseconds.
  status_t handleService(const struct ProcessState::binder_entry& entry);
  status_t handleDeathRecipient(
      const struct ProcessState::binder_entry& entry);

  const pid_t mMyThreadId;
  sp<ProcessState> mProcess;
};

}  // namespace android

#endif  // INCLUDE_KDBINDER_BINDER_IPCTHREADSTATE_H_