• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 #define LOG_TAG "bt_shim_storage"
18 
19 #include "main/shim/dumpsys.h"
20 #include "main/shim/entry.h"
21 #include "main/shim/shim.h"
22 
23 #include "shim/dumpsys.h"
24 
25 namespace {
26 constexpr char kModuleName[] = "shim::legacy::dumpsys";
27 static std::unordered_map<const void*, bluetooth::shim::DumpsysFunction>*
28     dumpsys_functions_;
29 }  // namespace
30 
RegisterDumpsysFunction(const void * token,DumpsysFunction func)31 void bluetooth::shim::RegisterDumpsysFunction(const void* token,
32                                               DumpsysFunction func) {
33   dumpsys_functions_ =
34       new std::unordered_map<const void*, bluetooth::shim::DumpsysFunction>();
35   CHECK(dumpsys_functions_->find(token) == dumpsys_functions_->end());
36   dumpsys_functions_->insert({token, func});
37 }
38 
UnregisterDumpsysFunction(const void * token)39 void bluetooth::shim::UnregisterDumpsysFunction(const void* token) {
40   CHECK(dumpsys_functions_->find(token) != dumpsys_functions_->end());
41   dumpsys_functions_->erase(token);
42 }
43 
Dump(int fd)44 void bluetooth::shim::Dump(int fd) {
45   dprintf(fd, "%s Dumping shim legacy targets:%zd\n", kModuleName,
46           dumpsys_functions_->size());
47   for (auto& dumpsys : *dumpsys_functions_) {
48     dumpsys.second(fd);
49   }
50   if (bluetooth::shim::is_gd_stack_started_up()) {
51     bluetooth::shim::GetDumpsys()->Dump(fd);
52   } else {
53     dprintf(fd, "%s gd stack has not started up\n", kModuleName);
54   }
55 }
56