• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/phy.h"
20 #include "packets/link_layer_packets.h"
21 namespace rootcanal {
22 
23 class PhyLayer {
24  public:
PhyLayer(Phy::Type phy_type,uint32_t id,const std::function<void (model::packets::LinkLayerPacketView)> & device_receive,uint32_t device_id)25   PhyLayer(Phy::Type phy_type, uint32_t id,
26            const std::function<void(model::packets::LinkLayerPacketView)>&
27                device_receive,
28            uint32_t device_id)
29       : phy_type_(phy_type),
30         id_(id),
31         device_id_(device_id),
32         transmit_to_device_(device_receive) {}
33 
34   virtual void Send(
35       std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet) = 0;
36   virtual void Send(model::packets::LinkLayerPacketView packet) = 0;
37 
38   virtual void Receive(model::packets::LinkLayerPacketView packet) = 0;
39 
40   virtual void TimerTick() = 0;
41 
42   virtual bool IsFactoryId(uint32_t factory_id) = 0;
43 
44   virtual void Unregister() = 0;
45 
GetType()46   Phy::Type GetType() { return phy_type_; }
47 
GetId()48   uint32_t GetId() { return id_; }
49 
GetDeviceId()50   uint32_t GetDeviceId() { return device_id_; }
51 
52   virtual ~PhyLayer() = default;
53 
54  private:
55   Phy::Type phy_type_;
56   uint32_t id_;
57   uint32_t device_id_;
58 
59  protected:
60   const std::function<void(model::packets::LinkLayerPacketView)>
61       transmit_to_device_;
62 };
63 
64 }  // namespace rootcanal
65