NVIDIA DeepStream SDK API Reference

7.0 Release
nvdspostprocesslib_factory.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef __NVDSPOSTPROCESSLIB_FACTORY_HPP__
25 #define __NVDSPOSTPROCESSLIB_FACTORY_HPP__
26 
27 #include <dlfcn.h>
28 #include <errno.h>
29 
30 #include <iostream>
31 #include <functional>
32 
34 
35 template<class T>
36 T* dlsym_ptr(void* handle, char const* name) {
37  return reinterpret_cast<T*>(dlsym(handle, name));
38 }
39 
41 {
42 public:
44  {
45  }
46 
48  {
49  if (m_libHandle)
50  {
51  dlclose(m_libHandle);
52  m_libHandle = NULL;
53  m_libName.clear();
54  }
55  }
56 
58  {
59  m_libName.assign(libName);
60 
61  m_libHandle = dlopen(m_libName.c_str(), RTLD_NOW);
62  if (m_libHandle)
63  {
64  //std::cout << "Library Opened Successfully" << std::endl;
65  m_CreateAlgoCtx = dlsym_ptr<IDSPostProcessLibrary*(DSPostProcess_CreateParams*)>(m_libHandle, "CreateCustomAlgoCtx");
66  if (!m_CreateAlgoCtx)
67  {
68 
69  //throw std::runtime_error("CreateCustomAlgoCtx function not found in library");
70  std::cout << "CreateCustomAlgoCtx function not found in library" << std::endl;
71  return nullptr;
72  }
73  }
74  else
75  {
76  // throw std::runtime_error(dlerror());
77  std::cout << dlerror() << std::endl;
78  return nullptr;
79  }
80 
82  }
83 
84 public:
85  void *m_libHandle;
86  std::string m_libName;
88 };
89 
90 #endif
DSPostProcessLibrary_Factory::CreateCustomAlgoCtx
IDSPostProcessLibrary * CreateCustomAlgoCtx(std::string libName, DSPostProcess_CreateParams *params)
Definition: nvdspostprocesslib_factory.hpp:57
IDSPostProcessLibrary
Definition: nvdspostprocesslib_interface.hpp:53
DSPostProcessLibrary_Factory::m_CreateAlgoCtx
std::function< IDSPostProcessLibrary *(DSPostProcess_CreateParams *)> m_CreateAlgoCtx
Definition: nvdspostprocesslib_factory.hpp:87
DSPostProcessLibrary_Factory::~DSPostProcessLibrary_Factory
~DSPostProcessLibrary_Factory()
Definition: nvdspostprocesslib_factory.hpp:47
DSPostProcessLibrary_Factory::m_libHandle
void * m_libHandle
Definition: nvdspostprocesslib_factory.hpp:85
DSPostProcessLibrary_Factory::m_libName
std::string m_libName
Definition: nvdspostprocesslib_factory.hpp:86
DSPostProcessLibrary_Factory
Definition: nvdspostprocesslib_factory.hpp:40
DSPostProcess_CreateParams
Definition: nvdspostprocesslib_interface.hpp:37
nvdspostprocesslib_interface.hpp
dlsym_ptr
T * dlsym_ptr(void *handle, char const *name)
Definition: nvdspostprocesslib_factory.hpp:36
DSPostProcessLibrary_Factory::DSPostProcessLibrary_Factory
DSPostProcessLibrary_Factory()
Definition: nvdspostprocesslib_factory.hpp:43