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 char* producer_socket_name, 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 host that listens on the Producer socket. It owns the 59 // PosixServiceProducerPort instance which deals with all producers' IPC(s). 60 std::unique_ptr<ipc::Host> producer_ipc_port_; 61 62 // As above, but for the Consumer port. 63 std::unique_ptr<ipc::Host> consumer_ipc_port_; 64 }; 65 66 } // namespace perfetto 67 68 #endif // SRC_TRACING_IPC_SERVICE_SERVICE_IPC_HOST_IMPL_H_ 69