Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 INCLUDE_PERFETTO_IPC_CLIENT_INFO_H_ |
| 18 | #define INCLUDE_PERFETTO_IPC_CLIENT_INFO_H_ |
| 19 | |
Sami Kyostila | 32e0b54 | 2018-02-14 08:55:43 +0000 | [diff] [blame] | 20 | #include <unistd.h> |
| 21 | |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 22 | #include "perfetto/base/logging.h" |
| 23 | #include "perfetto/ipc/basic_types.h" |
| 24 | |
| 25 | namespace perfetto { |
| 26 | namespace ipc { |
| 27 | |
| 28 | // Passed to Service(s) to identify remote clients. |
| 29 | class ClientInfo { |
| 30 | public: |
| 31 | ClientInfo() = default; |
Sami Kyostila | 32e0b54 | 2018-02-14 08:55:43 +0000 | [diff] [blame] | 32 | ClientInfo(ClientID client_id, uid_t uid) |
| 33 | : client_id_(client_id), uid_(uid) {} |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 34 | |
| 35 | bool operator==(const ClientInfo& other) const { |
| 36 | return (client_id_ == other.client_id_ && uid_ == other.uid_); |
| 37 | } |
| 38 | bool operator!=(const ClientInfo& other) const { return !(*this == other); } |
| 39 | |
| 40 | // For map<> and other sorted containers. |
| 41 | bool operator<(const ClientInfo& other) const { |
| 42 | PERFETTO_DCHECK(client_id_ != other.client_id_ || *this == other); |
| 43 | return client_id_ < other.client_id_; |
| 44 | } |
| 45 | |
| 46 | bool is_valid() const { return client_id_ != 0; } |
| 47 | |
| 48 | // A monotonic counter. |
| 49 | ClientID client_id() const { return client_id_; } |
| 50 | |
| 51 | // Posix User ID. Comes from the kernel, can be trusted. |
Sami Kyostila | 32e0b54 | 2018-02-14 08:55:43 +0000 | [diff] [blame] | 52 | uid_t uid() const { return uid_; } |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 53 | |
| 54 | private: |
| 55 | ClientID client_id_ = 0; |
Primiano Tucci | 3cbb10a | 2018-04-10 17:52:40 +0100 | [diff] [blame] | 56 | uid_t uid_ = kInvalidUid; |
Primiano Tucci | 4f9b6d7 | 2017-12-05 20:59:16 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | } // namespace ipc |
| 60 | } // namespace perfetto |
| 61 | |
| 62 | #endif // INCLUDE_PERFETTO_IPC_CLIENT_INFO_H_ |