NVIDIA DeepStream SDK API Reference

7.0 Release
gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4  *
5  * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6  * property and proprietary rights in and to this material, related
7  * documentation and any modifications thereto. Any use, reproduction,
8  * disclosure or distribution of this material and related documentation
9  * without an express license agreement from NVIDIA CORPORATION or
10  * its affiliates is strictly prohibited.
11  */
12 
13 #ifndef __NVDSCUSTOMLIB_FACTORY_HPP__
14 #define __NVDSCUSTOMLIB_FACTORY_HPP__
15 
16 #include <dlfcn.h>
17 #include <errno.h>
18 
19 #include <iostream>
20 #include <functional>
21 
23 
24 template<class T>
25 T* dlsym_ptr(void* handle, char const* name) {
26  return reinterpret_cast<T*>(dlsym(handle, name));
27 }
28 
30 {
31 public:
33  {
34  }
35 
37  {
38  if (m_libHandle)
39  {
40  dlclose(m_libHandle);
41  m_libHandle = NULL;
42  m_libName.clear();
43  }
44  }
45 
46  IDSCustomLibrary *CreateCustomAlgoCtx(std::string libName, GObject* object)
47  {
48  m_libName.assign(libName);
49 
50  m_libHandle = dlopen(m_libName.c_str(), RTLD_NOW);
51  std::function<IDSCustomLibrary*(GObject*)> createAlgoCtx = nullptr;
52  if (m_libHandle)
53  {
54  //std::cout << "Library Opened Successfully" << std::endl;
55 
56  createAlgoCtx = dlsym_ptr<IDSCustomLibrary*(GObject*)>(m_libHandle, "CreateCustomAlgoCtx");
57  if (!createAlgoCtx)
58  {
59  throw std::runtime_error("createCustomAlgoCtx function not found in library");
60  }
61  }
62  else
63  {
64  throw std::runtime_error(dlerror());
65  }
66 
67  return createAlgoCtx ? createAlgoCtx(object) : nullptr;
68  }
69 
70 public:
71  void *m_libHandle;
72  std::string m_libName;
73 };
74 
75 #endif
DSCustomLibrary_Factory::DSCustomLibrary_Factory
DSCustomLibrary_Factory()
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:32
DSCustomLibrary_Factory
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:29
DSCustomLibrary_Factory::CreateCustomAlgoCtx
IDSCustomLibrary * CreateCustomAlgoCtx(std::string libName, GObject *object)
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:46
IDSCustomLibrary
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_interface.hpp:43
DSCustomLibrary_Factory::~DSCustomLibrary_Factory
~DSCustomLibrary_Factory()
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:36
dlsym_ptr
T * dlsym_ptr(void *handle, char const *name)
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:25
DSCustomLibrary_Factory::m_libHandle
void * m_libHandle
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:71
DSCustomLibrary_Factory::m_libName
std::string m_libName
Definition: gst-nvdsA2Vtemplate/includes/nvdscustomlib_factory.hpp:72
nvdscustomlib_interface.hpp