• 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   ServiceIPCHostImpl(base::TaskRunner*);
37   ~ServiceIPCHostImpl() override;
38 
39   // ServiceIPCHost implementation.
40   bool Start(const char* producer_socket_name,
41              const char* consumer_socket_name) override;
42   bool Start(base::ScopedSocketHandle producer_socket_fd,
43              base::ScopedSocketHandle consumer_socket_fd) override;
44 
45   TracingService* service() const override;
46 
47  private:
48   bool DoStart();
49   void Shutdown();
50 
51   base::TaskRunner* const task_runner_;
52   std::unique_ptr<TracingService> svc_;  // The service business logic.
53 
54   // The IPC host that listens on the Producer socket. It owns the
55   // PosixServiceProducerPort instance which deals with all producers' IPC(s).
56   std::unique_ptr<ipc::Host> producer_ipc_port_;
57 
58   // As above, but for the Consumer port.
59   std::unique_ptr<ipc::Host> consumer_ipc_port_;
60 };
61 
62 }  // namespace perfetto
63 
64 #endif  // SRC_TRACING_IPC_SERVICE_SERVICE_IPC_HOST_IMPL_H_
65