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 27 namespace perfetto { 28 namespace base { 29 class TaskRunner; 30 } // namespace base. 31 32 class TracingService; 33 34 // Creates an instance of the service (business logic + UNIX socket transport). 35 // Exposed to: 36 // The code in the tracing client that will host the service e.g., traced. 37 // Implemented in: 38 // src/tracing/ipc/service/service_ipc_host_impl.cc 39 class PERFETTO_EXPORT ServiceIPCHost { 40 public: 41 static std::unique_ptr<ServiceIPCHost> CreateInstance(base::TaskRunner*); 42 virtual ~ServiceIPCHost(); 43 44 // Start listening on the Producer & Consumer ports. Returns false in case of 45 // failure (e.g., something else is listening on |socket_name|). 46 virtual bool Start(const char* producer_socket_name, 47 const char* consumer_socket_name) = 0; 48 49 // Like the above, but takes two file descriptors to already bound sockets. 50 // This is used when building as part of the Android tree, where init opens 51 // and binds the socket beore exec()-ing us. 52 virtual bool Start(base::ScopedSocketHandle producer_socket_fd, 53 base::ScopedSocketHandle consumer_socket_fd) = 0; 54 55 virtual TracingService* service() const = 0; 56 57 protected: 58 ServiceIPCHost(); 59 60 private: 61 ServiceIPCHost(const ServiceIPCHost&) = delete; 62 ServiceIPCHost& operator=(const ServiceIPCHost&) = delete; 63 }; 64 65 } // namespace perfetto 66 67 #endif // INCLUDE_PERFETTO_EXT_TRACING_IPC_SERVICE_IPC_HOST_H_ 68