exynos: libmemtrack: Add open method for memtrack
authorRuchi Kandoi <kandoiruchi@google.com>
Fri, 4 Nov 2016 16:56:58 +0000 (09:56 -0700)
committerFrancescodario Cuzzocrea <bosconovic@gmail.com>
Tue, 26 Jan 2021 16:08:11 +0000 (17:08 +0100)
Open method is used to dl-open the HAL for hidl.

Test: HIDL successfully loads the HAL
Bug: 31180823
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
Change-Id: I2452e2d749b9ab7b4f5722b1ce79ae64032d12ee

libmemtrack/memtrack_exynos.c

index 77fa96e2415741c8ae1a7fd08bdeb40d03fa3bc9..1c3b79612d34ac63b3fe57fb5cb40f4d1de28c8d 100644 (file)
@@ -15,6 +15,9 @@
  */
 
 #include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <log/log.h>
 
 #include <hardware/memtrack.h>
 
@@ -40,8 +43,38 @@ int exynos_memtrack_get_memory(const struct memtrack_module __unused *module,
     return -EINVAL;
 }
 
+static int memtrack_open(__attribute__((unused)) const hw_module_t* module, const char* name,
+                    hw_device_t** device)
+{
+    ALOGD("%s: enter; name=%s", __FUNCTION__, name);
+    int retval = 0; /* 0 is ok; -1 is error */
+
+    if (strcmp(name, "memtrack") == 0) {
+        struct memtrack_module *dev = (struct memtrack_module *)calloc(1,
+                sizeof(struct memtrack_module));
+
+        if (dev) {
+            /* Common hw_device_t fields */
+            dev->common.tag = HARDWARE_DEVICE_TAG;
+            dev->common.module_api_version = MEMTRACK_MODULE_API_VERSION_0_1;
+            dev->common.hal_api_version = HARDWARE_HAL_API_VERSION;
+
+            dev->init = exynos_memtrack_init;
+            dev->getMemory = exynos_memtrack_get_memory;
+
+            *device = (hw_device_t*)dev;
+        } else
+            retval = -ENOMEM;
+    } else {
+        retval = -EINVAL;
+    }
+
+    ALOGD("%s: exit %d", __FUNCTION__, retval);
+    return retval;
+}
+
 static struct hw_module_methods_t memtrack_module_methods = {
-    .open = NULL,
+    .open = memtrack_open,
 };
 
 struct memtrack_module HAL_MODULE_INFO_SYM = {