1 /*
2 * Copyright 2024 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 #include "lpp_offload_manager.h"
17
18 #include <bluetooth/log.h>
19
20 #include <string>
21
22 #include "hal/socket_hal.h"
23 #include "module.h"
24 #include "os/handler.h"
25 #include "os/system_properties.h"
26
27 namespace bluetooth::lpp {
28
29 const ModuleFactory LppOffloadManager::Factory =
__anon60ed042d0102() 30 ModuleFactory([]() { return new LppOffloadManager(); });
31
32 struct LppOffloadManager::impl {
~implbluetooth::lpp::LppOffloadManager::impl33 ~impl() {}
34
startbluetooth::lpp::LppOffloadManager::impl35 void start(os::Handler* handler, hal::SocketHal* socket_hal) {
36 log::info("");
37 handler_ = handler;
38 socket_hal_ = socket_hal;
39 socket_capabilities_ = socket_hal_->GetSocketCapabilities();
40 }
41
stopbluetooth::lpp::LppOffloadManager::impl42 void stop() {
43 log::info("");
44 socket_capabilities_ = {};
45 }
46
register_socket_hal_callbacksbluetooth::lpp::LppOffloadManager::impl47 bool register_socket_hal_callbacks(hal::SocketHalCallback* callbacks) {
48 log::info("");
49 return socket_hal_->RegisterCallback(callbacks);
50 }
51
get_socket_capabilitiesbluetooth::lpp::LppOffloadManager::impl52 hal::SocketCapabilities get_socket_capabilities() const {
53 log::info("");
54 return socket_capabilities_;
55 }
56
socket_openedbluetooth::lpp::LppOffloadManager::impl57 bool socket_opened(const hal::SocketContext& context) {
58 log::info("socket_id: {}", context.socket_id);
59 return socket_hal_->Opened(context);
60 }
61
socket_closedbluetooth::lpp::LppOffloadManager::impl62 void socket_closed(uint64_t socket_id) {
63 log::info("socket_id: {}", socket_id);
64 return socket_hal_->Closed(socket_id);
65 }
66
67 os::Handler* handler_;
68 hal::SocketHal* socket_hal_;
69 hal::SocketCapabilities socket_capabilities_;
70 };
71
LppOffloadManager()72 LppOffloadManager::LppOffloadManager() { pimpl_ = std::make_unique<impl>(); }
73
74 LppOffloadManager::~LppOffloadManager() = default;
75
ListDependencies(ModuleList * list) const76 void LppOffloadManager::ListDependencies(ModuleList* list) const { list->add<hal::SocketHal>(); }
77
Start()78 void LppOffloadManager::Start() { pimpl_->start(GetHandler(), GetDependency<hal::SocketHal>()); }
79
Stop()80 void LppOffloadManager::Stop() { pimpl_->stop(); }
81
ToString() const82 std::string LppOffloadManager::ToString() const { return "Low Power Processor Offload Manager"; }
83
RegisterSocketHalCallback(hal::SocketHalCallback * callbacks)84 bool LppOffloadManager::RegisterSocketHalCallback(hal::SocketHalCallback* callbacks) {
85 return pimpl_->register_socket_hal_callbacks(callbacks);
86 }
87
GetSocketCapabilities() const88 hal::SocketCapabilities LppOffloadManager::GetSocketCapabilities() const {
89 return pimpl_->get_socket_capabilities();
90 }
91
SocketOpened(const hal::SocketContext & context)92 bool LppOffloadManager::SocketOpened(const hal::SocketContext& context) {
93 return pimpl_->socket_opened(context);
94 }
95
SocketClosed(uint64_t socket_id)96 void LppOffloadManager::SocketClosed(uint64_t socket_id) {
97 CallOn(pimpl_.get(), &impl::socket_closed, socket_id);
98 }
99
100 } // namespace bluetooth::lpp
101