NVIDIA DeepStream SDK API Reference

9.2 Release
9.2/includes/opentelemetry/plugin/factory.h
Go to the documentation of this file.
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <memory>
7 #include <string>
8 
9 #include "opentelemetry/plugin/detail/utility.h" // IWYU pragma: export
10 #include "opentelemetry/plugin/tracer.h"
11 #include "opentelemetry/version.h"
12 
14 namespace plugin
15 {
19 class Factory final
20 {
21 public:
22  class FactoryImpl
23  {
24  public:
25  virtual ~FactoryImpl() {}
26 
28  nostd::string_view tracer_config,
29  nostd::unique_ptr<char[]> &error_message) const noexcept = 0;
30  };
31 
32  Factory(std::shared_ptr<DynamicLibraryHandle> library_handle,
33  std::unique_ptr<FactoryImpl> &&factory_impl) noexcept
34  : library_handle_{std::move(library_handle)}, factory_impl_{std::move(factory_impl)}
35  {}
36 
43  std::shared_ptr<trace::Tracer> MakeTracer(nostd::string_view tracer_config,
44  std::string &error_message) const noexcept
45  {
46  nostd::unique_ptr<char[]> plugin_error_message;
47  auto tracer_handle = factory_impl_->MakeTracerHandle(tracer_config, plugin_error_message);
48  if (tracer_handle == nullptr)
49  {
50  detail::CopyErrorMessage(plugin_error_message.get(), error_message);
51  return nullptr;
52  }
53  return std::shared_ptr<trace::Tracer>{new (std::nothrow)
54  Tracer{library_handle_, std::move(tracer_handle)}};
55  }
56 
57 private:
58  // Note: The order is important here.
59  //
60  // It's undefined behavior to close the library while a loaded FactoryImpl is still active.
61  std::shared_ptr<DynamicLibraryHandle> library_handle_;
62  std::unique_ptr<FactoryImpl> factory_impl_;
63 };
64 } // namespace plugin
nostd::unique_ptr
Provide a simplified port of std::unique_ptr that has ABI stability.
Definition: includes/opentelemetry/nostd/unique_ptr.h:45
plugin::Factory::Factory
Factory(std::shared_ptr< DynamicLibraryHandle > library_handle, std::unique_ptr< FactoryImpl > &&factory_impl) noexcept
Definition: 9.2/includes/opentelemetry/plugin/factory.h:32
nostd::unique_ptr::get
pointer get() const noexcept
Definition: includes/opentelemetry/nostd/unique_ptr.h:107
OPENTELEMETRY_BEGIN_NAMESPACE
#define OPENTELEMETRY_BEGIN_NAMESPACE
Definition: includes/opentelemetry/version.h:21
plugin::Factory::MakeTracer
std::shared_ptr< trace::Tracer > MakeTracer(nostd::string_view tracer_config, std::string &error_message) const noexcept
Construct a tracer from a configuration string.
Definition: 9.2/includes/opentelemetry/plugin/factory.h:43
plugin::Factory::FactoryImpl::~FactoryImpl
virtual ~FactoryImpl()
Definition: 9.2/includes/opentelemetry/plugin/factory.h:25
OPENTELEMETRY_END_NAMESPACE
#define OPENTELEMETRY_END_NAMESPACE
Definition: includes/opentelemetry/version.h:24
plugin
Definition: includes/opentelemetry/plugin/dynamic_load.h:19
absl::move
constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::remove_reference_t< T > && move(T &&t) noexcept
Definition: includes/opentelemetry/nostd/internal/absl/utility/utility.h:199
plugin::Factory::FactoryImpl::MakeTracerHandle
virtual nostd::unique_ptr< TracerHandle > MakeTracerHandle(nostd::string_view tracer_config, nostd::unique_ptr< char[]> &error_message) const noexcept=0
plugin::Tracer
Definition: includes/opentelemetry/plugin/tracer.h:84
plugin::detail::CopyErrorMessage
void CopyErrorMessage(const char *source, std::string &destination) noexcept
Definition: includes/opentelemetry/plugin/detail/utility.h:19
nostd::string_view
Back port of std::string_view to work with pre-cpp-17 compilers.
Definition: includes/opentelemetry/nostd/string_view.h:37