• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(std::list<ListenEndpoint> producer_sockets,
42              ListenEndpoint consumer_socket) override;
43 
44   TracingService* service() const override;
45 
46  private:
47   bool DoStart();
48   void Shutdown();
49 
50   base::TaskRunner* const task_runner_;
51   const TracingService::InitOpts init_opts_;
52   std::unique_ptr<TracingService> svc_;  // The service business logic.
53 
54   // The IPC hosts that listen on the Producer sockets. They own the
55   // PosixServiceProducerPort instances which deal with all producers' IPC(s).
56   // Note that there can be multiple producer sockets if it's specified in the
57   // producer socket name (e.g. for listening both on vsock for VMs and AF_UNIX
58   // for processes on the same machine).
59   std::vector<std::unique_ptr<ipc::Host>> producer_ipc_ports_;
60 
61   // As above, but for the Consumer port.
62   std::unique_ptr<ipc::Host> consumer_ipc_port_;
63 };
64 
65 }  // namespace perfetto
66 
67 #endif  // SRC_TRACING_IPC_SERVICE_SERVICE_IPC_HOST_IMPL_H_
68