blob: ac5dbcf2fb6ef6b7e1e79fb5c6018b80b8dab317 [file] [log] [blame]
Henry Fanga9f93652019-10-11 17:30:15 -07001/*
2 * Copyright (C) 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_NDEBUG 0
18#define LOG_TAG "android.hardware.cas@1.1-SharedLibrary"
19
20#include "SharedLibrary.h"
21#include <dlfcn.h>
22#include <media/stagefright/foundation/ADebug.h>
23#include <utils/Log.h>
24
25namespace android {
26namespace hardware {
27namespace cas {
28namespace V1_1 {
29namespace implementation {
30
31SharedLibrary::SharedLibrary(const String8& path) {
Tomasz Wasilczyk3e74f0b2023-08-11 16:04:23 +000032 mLibHandle = dlopen(path.c_str(), RTLD_NOW);
Henry Fanga9f93652019-10-11 17:30:15 -070033}
34
35SharedLibrary::~SharedLibrary() {
36 if (mLibHandle != NULL) {
37 dlclose(mLibHandle);
38 mLibHandle = NULL;
39 }
40}
41
42bool SharedLibrary::operator!() const {
43 return mLibHandle == NULL;
44}
45
46void* SharedLibrary::lookup(const char* symbol) const {
47 if (!mLibHandle) {
48 return NULL;
49 }
50 // Clear last error before we load the symbol again,
51 // in case the caller didn't retrieve it.
52 (void)dlerror();
53 return dlsym(mLibHandle, symbol);
54}
55
56const char* SharedLibrary::lastError() const {
57 const char* error = dlerror();
58 return error ? error : "No errors or unknown error";
59}
60
61} // namespace implementation
62} // namespace V1_1
63} // namespace cas
64} // namespace hardware
65} // namespace android