• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 /*
3  * Copyright (C) 2017 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <memory>
19 
20 #include "common/libs/fs/shared_fd.h"
21 #include "host/commands/ivserver/options.h"
22 #include "host/commands/ivserver/vsocsharedmem.h"
23 
24 namespace ivserver {
25 
26 // This class is responsible for orchestrating the setup and then serving
27 // new connections.
28 class IVServer final {
29  public:
30   // The qemu_channel_fd and client_channel_fd are the server sockets. If
31   // non-positive values are provided the server will create those sockets
32   // itself.
33   IVServer(const IVServerOptions &options, int qemu_channel_fd,
34            int client_channel_fd);
35   IVServer(const IVServer &) = delete;
36   IVServer& operator=(const IVServer&) = delete;
37 
38   // Serves incoming client and qemu connection.
39   // This method should never return.
40   void Serve();
41 
42  private:
43   void HandleNewClientConnection();
44   void HandleNewQemuConnection();
45 
46   std::unique_ptr<VSoCSharedMemory> vsoc_shmem_;
47   cvd::SharedFD qemu_channel_;
48   cvd::SharedFD client_channel_;
49 };
50 
51 }  // namespace ivserver
52