xref: /aosp_15_r20/external/perfetto/src/tracing/ipc/service/service_ipc_host_impl.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 SRC_TRACING_IPC_SERVICE_SERVICE_IPC_HOST_IMPL_H_
18 #define SRC_TRACING_IPC_SERVICE_SERVICE_IPC_HOST_IMPL_H_
19 
20 #include <memory>
21 
22 #include "perfetto/ext/tracing/ipc/service_ipc_host.h"
23 
24 namespace perfetto {
25 
26 namespace ipc {
27 class Host;
28 }
29 
30 // The implementation of the IPC host for the tracing service. This class does
31 // very few things: it mostly initializes the IPC transport. The actual
32 // implementation of the IPC <> Service business logic glue lives in
33 // producer_ipc_service.cc and consumer_ipc_service.cc.
34 class ServiceIPCHostImpl : public ServiceIPCHost {
35  public:
36   explicit ServiceIPCHostImpl(base::TaskRunner*,
37                               TracingService::InitOpts init_opts = {});
38   ~ServiceIPCHostImpl() override;
39 
40   // ServiceIPCHost implementation.
41   bool Start(const std::vector<std::string>& producer_socket_names,
42              const char* consumer_socket_name) override;
43   bool Start(base::ScopedSocketHandle producer_socket_fd,
44              base::ScopedSocketHandle consumer_socket_fd) override;
45   bool Start(std::unique_ptr<ipc::Host> producer_host,
46              std::unique_ptr<ipc::Host> consumer_host) override;
47 
48   TracingService* service() const override;
49 
50  private:
51   bool DoStart();
52   void Shutdown();
53 
54   base::TaskRunner* const task_runner_;
55   const TracingService::InitOpts init_opts_;
56   std::unique_ptr<TracingService> svc_;  // The service business logic.
57 
58   // The IPC hosts that listen on the Producer sockets. They own the
59   // PosixServiceProducerPort instances which deal with all producers' IPC(s).
60   // Note that there can be multiple producer sockets if it's specified in the
61   // producer socket name (e.g. for listening both on vsock for VMs and AF_UNIX
62   // for processes on the same machine).
63   std::vector<std::unique_ptr<ipc::Host>> producer_ipc_ports_;
64 
65   // As above, but for the Consumer port.
66   std::unique_ptr<ipc::Host> consumer_ipc_port_;
67 };
68 
69 }  // namespace perfetto
70 
71 #endif  // SRC_TRACING_IPC_SERVICE_SERVICE_IPC_HOST_IMPL_H_
72