• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 #pragma once
17 
18 namespace android {
19 
20 #pragma clang diagnostic push
21 #pragma clang diagnostic error "-Wpadded"
22 
23 enum : uint32_t {
24     /**
25      * follows is RpcWireTransaction, if flags != oneway, reply w/ RPC_COMMAND_REPLY expected
26      */
27     RPC_COMMAND_TRANSACT = 0,
28     /**
29      * follows is RpcWireReply
30      */
31     RPC_COMMAND_REPLY,
32     /**
33      * follows is RpcWireAddress
34      *
35      * note - this in the protocol directly instead of as a 'special
36      * transaction' in order to keep it as lightweight as possible (we don't
37      * want to create a 'Parcel' object for every decref)
38      */
39     RPC_COMMAND_DEC_STRONG,
40 };
41 
42 /**
43  * These commands are used when the address in an RpcWireTransaction is zero'd
44  * out (no address). This allows the transact/reply flow to be used for
45  * additional server commands, without making the protocol for
46  * transactions/replies more complicated.
47  */
48 enum : uint32_t {
49     RPC_SPECIAL_TRANSACT_GET_ROOT = 0,
50     RPC_SPECIAL_TRANSACT_GET_MAX_THREADS = 1,
51     RPC_SPECIAL_TRANSACT_GET_SESSION_ID = 2,
52 };
53 
54 constexpr int32_t RPC_SESSION_ID_NEW = -1;
55 
56 // serialization is like:
57 // |RpcWireHeader|struct desginated by 'command'| (over and over again)
58 
59 struct RpcWireHeader {
60     uint32_t command; // RPC_COMMAND_*
61     uint32_t bodySize;
62 
63     uint32_t reserved[2];
64 };
65 
66 struct RpcWireAddress {
67     uint8_t address[32];
68 };
69 
70 struct RpcWireTransaction {
71     RpcWireAddress address;
72     uint32_t code;
73     uint32_t flags;
74 
75     uint64_t asyncNumber;
76 
77     uint32_t reserved[4];
78 
79     uint8_t data[0];
80 };
81 
82 struct RpcWireReply {
83     int32_t status; // transact return
84     uint8_t data[0];
85 };
86 
87 #pragma clang diagnostic pop
88 
89 } // namespace android
90