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