Home | History | Annotate | Download | only in default
      1 /*
      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 (at) 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 
     25 namespace android {
     26 namespace hardware {
     27 namespace cas {
     28 namespace V1_1 {
     29 namespace implementation {
     30 
     31 SharedLibrary::SharedLibrary(const String8& path) {
     32     mLibHandle = dlopen(path.string(), RTLD_NOW);
     33 }
     34 
     35 SharedLibrary::~SharedLibrary() {
     36     if (mLibHandle != NULL) {
     37         dlclose(mLibHandle);
     38         mLibHandle = NULL;
     39     }
     40 }
     41 
     42 bool SharedLibrary::operator!() const {
     43     return mLibHandle == NULL;
     44 }
     45 
     46 void* 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 
     56 const 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
     66