blob: 5c4fe5b2db83c4fff0da68b72e1028a59b1636bd [file] [log] [blame]
Primiano Tucci4f9b6d72017-12-05 20:59:16 +00001/*
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 Kyostila32e0b542018-02-14 08:55:43 +000020#include <unistd.h>
21
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000022#include "perfetto/base/logging.h"
23#include "perfetto/ipc/basic_types.h"
24
25namespace perfetto {
26namespace ipc {
27
28// Passed to Service(s) to identify remote clients.
29class ClientInfo {
30 public:
31 ClientInfo() = default;
Sami Kyostila32e0b542018-02-14 08:55:43 +000032 ClientInfo(ClientID client_id, uid_t uid)
33 : client_id_(client_id), uid_(uid) {}
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000034
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 Kyostila32e0b542018-02-14 08:55:43 +000052 uid_t uid() const { return uid_; }
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000053
54 private:
55 ClientID client_id_ = 0;
Primiano Tucci3cbb10a2018-04-10 17:52:40 +010056 uid_t uid_ = kInvalidUid;
Primiano Tucci4f9b6d72017-12-05 20:59:16 +000057};
58
59} // namespace ipc
60} // namespace perfetto
61
62#endif // INCLUDE_PERFETTO_IPC_CLIENT_INFO_H_