blob: 34db761e912be9a8f731f32cb77c56e79b17917d [file] [log] [blame]
Jeff Tinker441a78d2013-02-08 10:18:35 -08001/*
2 * Copyright (C) 2013 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 "Drm"
19#include <utils/Log.h>
20#include <media/stagefright/foundation/ADebug.h>
21
22#include <dlfcn.h>
23
24#include "SharedLibrary.h"
25
26namespace android {
27
28 SharedLibrary::SharedLibrary(const String8 &path) {
29 mLibHandle = dlopen(path.string(), RTLD_NOW);
30 }
31
32 SharedLibrary::~SharedLibrary() {
33 if (mLibHandle != NULL) {
34 dlclose(mLibHandle);
35 mLibHandle = NULL;
36 }
37 }
38
39 bool SharedLibrary::operator!() const {
40 return mLibHandle == NULL;
41 }
42
43 void *SharedLibrary::lookup(const char *symbol) const {
44 if (!mLibHandle) {
45 return NULL;
46 }
47 return dlsym(mLibHandle, symbol);
48 }
leozwang@google.comd1eff572013-07-13 21:52:50 -070049
50 const char *SharedLibrary::lastError() const {
51 const char *error = dlerror();
52 return error ? error : "No errors or unknown error";
53 }
54
Jeff Tinker441a78d2013-02-08 10:18:35 -080055};