1 /*
2  * Copyright 2022 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 <unordered_set>
21 
22 #include "model/devices/device.h"
23 #include "phy.h"
24 
25 namespace rootcanal {
26 
27 class PhyLayer;
28 class Device;
29 
30 class PhyDevice {
31 public:
32   using Identifier = uint32_t;
33 
34   PhyDevice(std::string type, std::shared_ptr<Device> device);
35   PhyDevice(PhyDevice&&) = delete;
36   ~PhyDevice() = default;
37 
38   void Register(PhyLayer* phy);
39   void Unregister(PhyLayer* phy);
40 
41   void Tick();
42   void Receive(std::vector<uint8_t> const& packet, Phy::Type type, int8_t rssi);
43   void Send(std::vector<uint8_t> const& packet, Phy::Type type, int8_t tx_power);
44 
45   bluetooth::hci::Address GetAddress() const;
46   std::shared_ptr<Device> GetDevice() const;
47   void SetAddress(bluetooth::hci::Address address);
48   std::string ToString();
49 
50   // Id and type are public but immutable.
51   const Identifier id;
52   const std::string type;
53 
54 private:
55   const std::shared_ptr<Device> device_;
56   std::unordered_set<PhyLayer*> phy_layers_;
57 };
58 
59 }  // namespace rootcanal
60