1 /*
2  * Copyright 2018 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 #pragma once
18 
19 #include <cstdint>
20 #include <vector>
21 
22 #include "model/controller/dual_mode_controller.h"
23 #include "model/devices/h4_packetizer.h"
24 
25 namespace test_vendor_lib {
26 
27 class HciSocketDevice : public DualModeController {
28  public:
29   HciSocketDevice(int socket_fd);
30   ~HciSocketDevice() = default;
31 
Create(int socket_fd)32   static std::shared_ptr<HciSocketDevice> Create(int socket_fd) {
33     return std::make_shared<HciSocketDevice>(socket_fd);
34   }
35 
GetTypeString()36   virtual std::string GetTypeString() const override {
37     return "hci_socket_device";
38   }
39 
40   virtual void TimerTick() override;
41 
42   void SendHci(PacketType packet_type,
43                const std::shared_ptr<std::vector<uint8_t>> packet);
44 
45   void RegisterCloseCallback(std::function<void()>);
46 
47  private:
48   int socket_file_descriptor_{-1};
49   H4Packetizer h4_{socket_file_descriptor_,
50                    [](const std::vector<uint8_t>&) {},
51                    [](const std::vector<uint8_t>&) {},
52                    [](const std::vector<uint8_t>&) {},
53                    [](const std::vector<uint8_t>&) {},
54                    [](const std::vector<uint8_t>&) {},
55                    [] {}};
56 
57   std::function<void()> close_callback_;
58 };
59 
60 }  // namespace test_vendor_lib
61