Tomasz Wiszkowski | 95ee07f | 2017-12-04 12:52:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #pragma once |
| 17 | |
| 18 | #include <memory> |
| 19 | #include <set> |
| 20 | |
| 21 | #include "common/libs/wifi/netlink.h" |
| 22 | #include "common/libs/wifi/virtual_wifi.h" |
| 23 | #include "common/libs/wifi/wr_client.h" |
| 24 | #include "common/vsoc/lib/wifi_exchange_view.h" |
| 25 | |
| 26 | namespace cvd { |
| 27 | |
| 28 | class PacketSwitch { |
| 29 | public: |
| 30 | PacketSwitch(Netlink* nl) : nl_(nl) {} |
| 31 | ~PacketSwitch(); |
| 32 | |
| 33 | bool Init(); |
| 34 | void Start(); |
| 35 | void Stop(); |
| 36 | |
| 37 | private: |
| 38 | void ProcessPacket(nl_msg* m, bool is_incoming); |
| 39 | |
| 40 | Netlink* nl_; |
| 41 | |
| 42 | std::mutex op_mutex_; |
| 43 | // Started is referenced by all threads created by PacketSwitch to determine |
| 44 | // whether to carry on working, or terminate. |
Tomasz Wiszkowski | 60ed577 | 2017-12-07 08:37:10 -0800 | [diff] [blame] | 45 | bool started_ = false; |
Tomasz Wiszkowski | 95ee07f | 2017-12-04 12:52:15 -0800 | [diff] [blame] | 46 | |
| 47 | std::unique_ptr<std::thread> shm_xchg_; |
Tomasz Wiszkowski | 96638a7 | 2017-12-14 15:27:12 -0800 | [diff] [blame] | 48 | std::unique_ptr<vsoc::RegionWorker> worker_; |
Ryan Haining | 59063a9 | 2018-02-08 17:32:22 -0800 | [diff] [blame^] | 49 | vsoc::wifi::WifiExchangeView* shm_wifi_; |
Tomasz Wiszkowski | 95ee07f | 2017-12-04 12:52:15 -0800 | [diff] [blame] | 50 | |
| 51 | PacketSwitch(const PacketSwitch&) = delete; |
| 52 | PacketSwitch& operator=(const PacketSwitch&) = delete; |
| 53 | }; |
| 54 | |
| 55 | } // namespace cvd |