blob: 257ccd23adc17c302377849fcbb3cdb931d146d3 [file] [log] [blame]
Tomasz Wiszkowski95ee07f2017-12-04 12:52:15 -08001/*
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
26namespace cvd {
27
28class 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 Wiszkowski60ed5772017-12-07 08:37:10 -080045 bool started_ = false;
Tomasz Wiszkowski95ee07f2017-12-04 12:52:15 -080046
47 std::unique_ptr<std::thread> shm_xchg_;
Tomasz Wiszkowski96638a72017-12-14 15:27:12 -080048 std::unique_ptr<vsoc::RegionWorker> worker_;
Ryan Haining59063a92018-02-08 17:32:22 -080049 vsoc::wifi::WifiExchangeView* shm_wifi_;
Tomasz Wiszkowski95ee07f2017-12-04 12:52:15 -080050
51 PacketSwitch(const PacketSwitch&) = delete;
52 PacketSwitch& operator=(const PacketSwitch&) = delete;
53};
54
55} // namespace cvd