sdm: Add DynLib utility for dynamic library lifecycle management.

- Add DynLib utility to automatically unload libraries upon
  destruction of the utility object.

CRs-Fixed: 1029997
Change-Id: I4e13ad984949db170498fe1ec5c133fa4a798bdd
diff --git a/sdm/include/utils/sys.h b/sdm/include/utils/sys.h
index ae75967..c06b7f8 100644
--- a/sdm/include/utils/sys.h
+++ b/sdm/include/utils/sys.h
@@ -26,6 +26,7 @@
 #define __SYS_H__
 
 #include <sys/eventfd.h>
+#include <dlfcn.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -75,6 +76,20 @@
   static eventfd eventfd_;
 };
 
+class DynLib {
+ public:
+  ~DynLib();
+  bool Open(const char *lib_name);
+  bool Sym(const char *func_name, void **func_ptr);
+  const char * Error() { return ::dlerror(); }
+  operator bool() const { return lib_ != NULL; }
+
+ private:
+  void Close();
+
+  void *lib_ = NULL;
+};
+
 }  // namespace sdm
 
 #endif  // __SYS_H__