NVIDIA DeepStream SDK API Reference

8.0 Release
object.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024-2025 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 
26 #ifndef NVIDIA_DEEPSTREAM_OBJECT
27 #define NVIDIA_DEEPSTREAM_OBJECT
28 
29 #include <string>
30 #include "yaml-cpp/yaml.h"
31 
32 // opaque structures
33 typedef struct _GValue GValue;
34 typedef struct _GstObject GstObject;
35 
36 namespace deepstream {
37 
38 class SignalHandler;
39 class SignalEmitter;
40 
44 class Object {
45 public:
46 
53  class Value {
54  public:
55  Value();
56  Value(char value);
57  Value(unsigned char value);
58  Value(int value);
59  Value(unsigned int value);
60  Value(long value);
61  Value(unsigned long value);
62  Value(float value);
63  Value(double value);
64  Value(const std::string value);
65  Value(const char* value);
66  Value(bool value);
67 
68  Value(const Value& other);
69 
70  virtual ~Value();
71 
72  Value &operator=(const Value& other);
73 
74  operator char() const;
75  operator unsigned char() const;
76  operator int() const;
77  operator unsigned int() const;
78  operator long() const;
79  operator unsigned long() const;
80  operator float() const;
81  operator double() const;
82  operator std::string() const;
83  operator const char*() const;
84  operator bool() const;
85 
86  bool isChar() const;
87  bool isUnsignedChar() const;
88  bool isInteger() const;
89  bool isUnsignedInteger() const;
90  bool isFloat() const;
91  bool isString() const;
92  bool isBoolean() const;
93 
94  private:
95  GValue* value_;
96 
97  Value(unsigned long, int);
98 
99  friend class Object;
100  };
101 
103  Object();
110  Object(unsigned long type_id, const std::string& name);
111 
113  Object(const Object&);
114 
116  Object(Object&&);
117 
119  Object& operator=(const Object&);
120 
122  Object& operator=(Object&&);
123 
125  virtual ~Object();
126 
128  const std::string getName() const;
129 
131  explicit operator bool () const noexcept { return object_ != nullptr; }
132 
134  bool operator == (const Object& other) noexcept { return object_ == other.object_; }
135 
137  GstObject* give();
138 
141  return object_;
142  }
143 
145  Object& take(GstObject* object);
146 
148  Object& seize(GstObject* object);
149 
151  Object& set(const YAML::Node& params);
152 
153  // set the properties through ke/value pair directly
154  Object& set(const std::string& name, const Value& value) {
155  this->set_(name, value);
156  return *this;
157  }
158 
159  // template for setting multiple properties
160  template<typename T, typename... Args>
161  Object& set(const std::string& name, const T& value, const Args&... args) {
162  set_(name, Value(value));
163  if constexpr (sizeof...(args) > 0) {
164  this->set(args...);
165  }
166  return *this;
167  }
168 
170  template<typename T, typename... Args>
171  Object& getProperty(const std::string& name, T& value, Args&... args) {
172  value = (T) get_(name);
173  if constexpr (sizeof...(args) > 0) {
174  this->getProperty(args...);
175  }
176  return *this;
177  }
178 
180  std::vector<std::string> listSignals(bool is_action);
181 
189  bool connectSignal(const std::string&signal_name, SignalHandler& handler);
190 
192  void emitSignal(const std::string&signal_name, va_list args);
193 
195  static unsigned long type();
196 
197 protected:
199 
200  virtual void set_(const std::string& name, const Value& value);
201  virtual void set_(const std::string& name, const YAML::Node& value);
202  virtual Value get_(const std::string&name);
203 
204 friend class Pipeline;
205 friend class Element;
206 };
207 
208 }
209 
210 #endif
deepstream::Object::Value::~Value
virtual ~Value()
deepstream::Object::set
Object & set(const std::string &name, const T &value, const Args &... args)
Definition: object.hpp:161
deepstream::Object::Value::isUnsignedInteger
bool isUnsignedInteger() const
deepstream::Object::Value::isString
bool isString() const
deepstream::Object::Value::isUnsignedChar
bool isUnsignedChar() const
deepstream::Object::Value
Value wrapper for various types.
Definition: object.hpp:53
deepstream::Object::set
Object & set(const YAML::Node &params)
Set the properties from key/value pairs in the yaml format.
deepstream::Element
Element class definition.
Definition: element.hpp:49
deepstream::Object::set_
virtual void set_(const std::string &name, const Value &value)
GstObject
struct _GstObject GstObject
Definition: object.hpp:34
deepstream::Object::Value::isChar
bool isChar() const
deepstream::Object::Value::Value
Value()
deepstream::Object::Value::isFloat
bool isFloat() const
deepstream::Pipeline
Pipeline class definition.
Definition: pipeline.hpp:46
deepstream::Object::Value::isBoolean
bool isBoolean() const
deepstream::Object::type
static unsigned long type()
Return the object's type id.
GValue
struct _GValue GValue
Definition: object.hpp:33
deepstream::Object::connectSignal
bool connectSignal(const std::string &signal_name, SignalHandler &handler)
Connect a signal handler to the object.
deepstream
Definition: buffer.hpp:33
deepstream::Object::operator=
Object & operator=(const Object &)
Copy assignment.
deepstream::Object::set
Object & set(const std::string &name, const Value &value)
Definition: object.hpp:154
deepstream::Object::seize
Object & seize(GstObject *object)
Seize a opaque object to prevent it from being destroyed somewhere.
deepstream::Object::take
Object & take(GstObject *object)
Takes the ownership of a object through the opaque pointer.
deepstream::Object::getGObject
GstObject * getGObject()
Return the opaque object pointer.
Definition: object.hpp:140
deepstream::Object::Value::operator=
Value & operator=(const Value &other)
deepstream::Object::Object
Object()
Constructor of a void object.
deepstream::Object::getName
const std::string getName() const
Return the name assigned during the construction.
deepstream::Object::give
GstObject * give()
Give up the ownership and return the opaque pointer.
deepstream::Object::emitSignal
void emitSignal(const std::string &signal_name, va_list args)
Emit a signal.
deepstream::Object::object_
GstObject * object_
Definition: object.hpp:198
deepstream::Object::operator==
bool operator==(const Object &other) noexcept
Check if the two objects are the same.
Definition: object.hpp:134
deepstream::Object::get_
virtual Value get_(const std::string &name)
deepstream::Object::Value::isInteger
bool isInteger() const
deepstream::Object::~Object
virtual ~Object()
Destructor.
deepstream::Object::listSignals
std::vector< std::string > listSignals(bool is_action)
List all the supported signals from the object.
deepstream::SignalHandler
SignalHandler class.
Definition: signal_handler.hpp:40
deepstream::Object
Base Object class.
Definition: object.hpp:44
deepstream::Object::getProperty
Object & getProperty(const std::string &name, T &value, Args &... args)
Template for getting multiple properties.
Definition: object.hpp:171