NVIDIA DeepStream SDK API Reference

6.4 Release
gst-nvdsvideotemplate/includes/nvdscustomlib_factory.hpp
Go to the documentation of this file.
1 
23 #ifndef __NVDSCUSTOMLIB_FACTORY_HPP__
24 #define __NVDSCUSTOMLIB_FACTORY_HPP__
25 
26 #include <dlfcn.h>
27 #include <errno.h>
28 
29 #include <iostream>
30 #include <functional>
31 
33 
34 template<class T>
35 T* dlsym_ptr(void* handle, char const* name) {
36  return reinterpret_cast<T*>(dlsym(handle, name));
37 }
38 
40 {
41 public:
43  {
44  }
45 
47  {
48  if (m_libHandle)
49  {
50  dlclose(m_libHandle);
51  m_libHandle = NULL;
52  m_libName.clear();
53  }
54  }
55 
56  IDSCustomLibrary *CreateCustomAlgoCtx(std::string libName, GObject* object)
57  {
58  m_libName.assign(libName);
59 
60  m_libHandle = dlopen(m_libName.c_str(), RTLD_NOW);
61  std::function<IDSCustomLibrary*(GObject*)> createAlgoCtx = nullptr;
62  if (m_libHandle)
63  {
64  //std::cout << "Library Opened Successfully" << std::endl;
65 
66  createAlgoCtx = dlsym_ptr<IDSCustomLibrary*(GObject*)>(m_libHandle, "CreateCustomAlgoCtx");
67  if (!createAlgoCtx)
68  {
69  throw std::runtime_error("createCustomAlgoCtx function not found in library");
70  }
71  }
72  else
73  {
74  throw std::runtime_error(dlerror());
75  }
76 
77  return createAlgoCtx ? createAlgoCtx(object) : nullptr;
78  }
79 
80 public:
81  void *m_libHandle;
82  std::string m_libName;
83 };
84 
85 #endif
DSCustomLibrary_Factory::DSCustomLibrary_Factory
DSCustomLibrary_Factory()
Definition: gst-nvdsvideotemplate/includes/nvdscustomlib_factory.hpp:42
DSCustomLibrary_Factory
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:39
DSCustomLibrary_Factory::CreateCustomAlgoCtx
IDSCustomLibrary * CreateCustomAlgoCtx(std::string libName, GObject *object)
Definition: gst-nvdsvideotemplate/includes/nvdscustomlib_factory.hpp:56
IDSCustomLibrary
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_interface.hpp:53
dlsym_ptr
T * dlsym_ptr(void *handle, char const *name)
Copyright (c) 2020-2021, NVIDIA CORPORATION.
Definition: gst-nvdsvideotemplate/includes/nvdscustomlib_factory.hpp:35
DSCustomLibrary_Factory::~DSCustomLibrary_Factory
~DSCustomLibrary_Factory()
Definition: gst-nvdsvideotemplate/includes/nvdscustomlib_factory.hpp:46
DSCustomLibrary_Factory::m_libHandle
void * m_libHandle
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:81
nvdscustomlib_interface.hpp
DSCustomLibrary_Factory::m_libName
std::string m_libName
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:82