OSDN Git Service

RootCanal: New Directory Structure
[android-x86/system-bt.git] / vendor_libs / test_vendor_lib / model / devices / link_layer_socket_device.h
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 "device.h"
23 #include "include/link.h"
24 #include "include/phy.h"
25 #include "packets/link_layer/link_layer_packet_view.h"
26 #include "polled_socket.h"
27
28 namespace test_vendor_lib {
29
30 class LinkLayerSocketDevice : public Device {
31  public:
32   LinkLayerSocketDevice(int socket_fd, Phy::Type phy_type);
33   LinkLayerSocketDevice(LinkLayerSocketDevice&& s) = default;
34   virtual ~LinkLayerSocketDevice() = default;
35
36   static std::shared_ptr<Device> Create(int socket_fd, Phy::Type phy_type) {
37     return std::make_shared<LinkLayerSocketDevice>(socket_fd, phy_type);
38   }
39
40   virtual std::string GetTypeString() const override {
41     return "link_layer_socket_device";
42   }
43
44   virtual void Initialize(const std::vector<std::string>&) override {}
45
46   virtual void IncomingPacket(packets::LinkLayerPacketView packet) override;
47
48   virtual void TimerTick() override;
49
50  private:
51   net::PolledSocket socket_;
52   Phy::Type phy_type_;
53   size_t bytes_left_{0};
54   size_t offset_;
55   std::shared_ptr<std::vector<uint8_t>> received_;
56   std::vector<packets::LinkLayerPacketView> packet_queue_;
57 };
58
59 }  // namespace test_vendor_lib