blob: 9c7f38554a53a5ffd7e876e74016ed7c7b5c5a7f [file] [log] [blame]
Chong Zhanga4f67512017-04-24 17:18:25 -07001/*
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
17//#define LOG_NDEBUG 0
18#define LOG_TAG "android.hardware.cas@1.0-SharedLibrary"
19
20#include <dlfcn.h>
21#include <media/stagefright/foundation/ADebug.h>
22#include "SharedLibrary.h"
23#include <utils/Log.h>
24
25namespace android {
26namespace hardware {
27namespace cas {
28namespace V1_0 {
29namespace implementation {
30
31SharedLibrary::SharedLibrary(const String8 &path) {
32 mLibHandle = dlopen(path.string(), RTLD_NOW);
33}
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_0
63} // namespace cas
64} // namespace hardware
65} // namespace android