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_EXT_IPC_CLIENT_INFO_H_ 18 #define INCLUDE_PERFETTO_EXT_IPC_CLIENT_INFO_H_ 19 20 #include "perfetto/base/logging.h" 21 #include "perfetto/ext/base/utils.h" 22 #include "perfetto/ext/ipc/basic_types.h" 23 24 namespace perfetto { 25 namespace ipc { 26 27 // Passed to Service(s) to identify remote clients. 28 class ClientInfo { 29 public: 30 ClientInfo() = default; ClientInfo(ClientID client_id,uid_t uid)31 ClientInfo(ClientID client_id, uid_t uid) 32 : client_id_(client_id), uid_(uid) {} 33 34 bool operator==(const ClientInfo& other) const { 35 return (client_id_ == other.client_id_ && uid_ == other.uid_); 36 } 37 bool operator!=(const ClientInfo& other) const { return !(*this == other); } 38 39 // For map<> and other sorted containers. 40 bool operator<(const ClientInfo& other) const { 41 PERFETTO_DCHECK(client_id_ != other.client_id_ || *this == other); 42 return client_id_ < other.client_id_; 43 } 44 is_valid()45 bool is_valid() const { return client_id_ != 0; } 46 47 // A monotonic counter. client_id()48 ClientID client_id() const { return client_id_; } 49 50 // Posix User ID. Comes from the kernel, can be trusted. uid()51 uid_t uid() const { return uid_; } 52 53 private: 54 ClientID client_id_ = 0; 55 uid_t uid_ = kInvalidUid; 56 }; 57 58 } // namespace ipc 59 } // namespace perfetto 60 61 #endif // INCLUDE_PERFETTO_EXT_IPC_CLIENT_INFO_H_ 62