2 * Copyright (c) 2012 Simon Busch <morphis@gravedo.de>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <android/hardware/hardware.h>
21 #include <hybris/internal/binding.h>
23 static void *_libhardware
= NULL
;
25 static int (*_hw_get_module
)(const char *id
, const struct hw_module_t
**module
) = NULL
;
27 static int (*_hw_get_module_by_class
)(const char *class_id
, const char *inst
, const struct hw_module_t
**module
) = NULL
;
29 #define HARDWARE_DLSYM(fptr, sym) do { if (_libhardware == NULL) { _init_lib_hardware(); }; if (*(fptr) == NULL) { *(fptr) = (void *) android_dlsym(_libhardware, sym); } } while (0)
31 static void _init_lib_hardware()
33 _libhardware
= (void *) android_dlopen("/system/lib/libhardware.so", RTLD_LAZY
);
36 int hw_get_module(const char *id
, const struct hw_module_t
**module
)
38 HARDWARE_DLSYM(&_hw_get_module
, "hw_get_module");
39 return (*_hw_get_module
)(id
, module
);
42 int hw_get_module_by_class(const char *class_id
, const char *inst
,
43 const struct hw_module_t
**module
)
45 HARDWARE_DLSYM(&_hw_get_module_by_class
, "hw_get_module_by_class");
46 return (*_hw_get_module_by_class
)(class_id
, inst
, module
);
49 // vim:ts=4:sw=4:noexpandtab