• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 #include <mediautils/Library.h>
18 #include <mediautils/MediaUtilsDelayed.h>
19 #include "MediaUtilsDelayedLibrary.h"
20 
21 #define LOG_TAG "MediaUtilsDelayed"
22 #include <utils/Log.h>
23 #include <memory>
24 
25 namespace android::mediautils {
26 
27 namespace {
28 //  Specific implementation details for MediaUtils Delayed Library.
29 
30 // The following use static Meyer's singleton caches instead of letting
31 // refcounted management as provided above. This is for speed.
getDelayedLibrary()32 std::shared_ptr<void> getDelayedLibrary() {
33     static std::shared_ptr<void> library = loadLibrary(MEDIAUTILS_DELAYED_LIBRARY_NAME);
34     return library;
35 }
36 
37 // Get the delayed dispatch table.  This is refcounted and keeps the underlying library alive.
getDelayedDispatchTable()38 std::shared_ptr<delayed_library::DelayedDispatchTable> getDelayedDispatchTable() {
39     static auto delayedDispatchTable =
40             getObjectFromLibrary<delayed_library::DelayedDispatchTable>(
41                     MEDIAUTILS_DELAYED_DISPATCH_TABLE_SYMBOL_NAME, getDelayedLibrary());
42     return delayedDispatchTable;
43 }
44 
45 } // namespace
46 
47 // Public implementations of methods here.
48 
getCallStackStringForTid(pid_t tid)49 std::string getCallStackStringForTid(pid_t tid) {
50     auto delayedDispatchTable = getDelayedDispatchTable();
51     if (!delayedDispatchTable) return {};  // on failure, return empty string
52     return delayedDispatchTable->getCallStackStringForTid(tid);
53 }
54 
55 } // android::mediautils
56