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 INCLUDE_PERFETTO_EXT_TRACING_IPC_SERVICE_IPC_HOST_H_ 18 #define INCLUDE_PERFETTO_EXT_TRACING_IPC_SERVICE_IPC_HOST_H_ 19 20 #include <memory> 21 22 #include "perfetto/base/export.h" 23 #include "perfetto/ext/base/scoped_file.h" 24 #include "perfetto/ext/base/unix_socket.h" 25 #include "perfetto/ext/tracing/core/basic_types.h" 26 #include "perfetto/ext/tracing/core/tracing_service.h" 27 #include "perfetto/tracing/default_socket.h" 28 29 namespace perfetto { 30 namespace base { 31 class TaskRunner; 32 } // namespace base. 33 34 namespace ipc { 35 class Host; 36 } // namespace ipc 37 38 // Creates an instance of the service (business logic + UNIX socket transport). 39 // Exposed to: 40 // The code in the tracing client that will host the service e.g., traced. 41 // Implemented in: 42 // src/tracing/ipc/service/service_ipc_host_impl.cc 43 class PERFETTO_EXPORT_COMPONENT ServiceIPCHost { 44 public: 45 static std::unique_ptr<ServiceIPCHost> CreateInstance( 46 base::TaskRunner*, 47 TracingService::InitOpts = {}); 48 virtual ~ServiceIPCHost(); 49 50 // The overload to wrap the multi-value producer socket name in the 51 // single-value variant for compatibility in tests. Start(const char * producer_socket_name,const char * consumer_socket_name)52 bool Start(const char* producer_socket_name, 53 const char* consumer_socket_name) { 54 return Start(TokenizeProducerSockets(producer_socket_name), 55 consumer_socket_name); 56 } 57 // Start listening on the Producer & Consumer ports. Returns false in case of 58 // failure (e.g., something else is listening on |socket_name|). 59 virtual bool Start(const std::vector<std::string>& producer_socket_names, 60 const char* consumer_socket_name) = 0; 61 62 // Like the above, but takes two file descriptors to already bound sockets. 63 // This is used when building as part of the Android tree, where init opens 64 // and binds the socket beore exec()-ing us. 65 virtual bool Start(base::ScopedSocketHandle producer_socket_fd, 66 base::ScopedSocketHandle consumer_socket_fd) = 0; 67 68 // Allows callers to supply preconstructed Hosts. 69 virtual bool Start(std::unique_ptr<ipc::Host> producer_host, 70 std::unique_ptr<ipc::Host> consumer_host) = 0; 71 72 virtual TracingService* service() const = 0; 73 74 protected: 75 ServiceIPCHost(); 76 77 private: 78 ServiceIPCHost(const ServiceIPCHost&) = delete; 79 ServiceIPCHost& operator=(const ServiceIPCHost&) = delete; 80 }; 81 82 } // namespace perfetto 83 84 #endif // INCLUDE_PERFETTO_EXT_TRACING_IPC_SERVICE_IPC_HOST_H_ 85