| 1 | /* |
| 2 | * Copyright (c) 2012 Simon Busch <morphis@gravedo.de> |
| 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 | |
| 18 | #include <dlfcn.h> |
| 19 | #include <stddef.h> |
| 20 | #include <android/hardware/hardware.h> |
| 21 | #include <hybris/internal/binding.h> |
| 22 | |
| 23 | static void *_libhardware = NULL; |
| 24 | |
| 25 | static int (*_hw_get_module)(const char *id, const struct hw_module_t **module) = NULL; |
| 26 | |
| 27 | static int (*_hw_get_module_by_class)(const char *class_id, const char *inst, const struct hw_module_t **module) = NULL; |
| 28 | |
| 29 | #define HARDWARE_DLSYM(fptr, sym) do { if (_libhardware == NULL) { _init_lib_hardware(); }; if (*(fptr) == NULL) { *(fptr) = (void *) android_dlsym(_libhardware, sym); } } while (0) |
| 30 | |
| 31 | static void _init_lib_hardware() |
| 32 | { |
| 33 | _libhardware = (void *) android_dlopen("/system/lib/libhardware.so", RTLD_LAZY); |
| 34 | } |
| 35 | |
| 36 | int hw_get_module(const char *id, const struct hw_module_t **module) |
| 37 | { |
| 38 | HARDWARE_DLSYM(&_hw_get_module, "hw_get_module"); |
| 39 | return (*_hw_get_module)(id, module); |
| 40 | } |
| 41 | |
| 42 | int hw_get_module_by_class(const char *class_id, const char *inst, |
| 43 | const struct hw_module_t **module) |
| 44 | { |
| 45 | HARDWARE_DLSYM(&_hw_get_module_by_class, "hw_get_module_by_class"); |
| 46 | return (*_hw_get_module_by_class)(class_id, inst, module); |
| 47 | } |
| 48 | |
| 49 | // vim:ts=4:sw=4:noexpandtab |