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