NVIDIA DeepStream SDK API Reference

9.1 Release
service-maker/includes/object.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
31 #ifndef NVIDIA_DEEPSTREAM_OBJECT
32 #define NVIDIA_DEEPSTREAM_OBJECT
33 
34 #include <string>
35 #include "yaml-cpp/yaml.h"
36 
37 // opaque structures
38 typedef struct _GValue GValue;
39 typedef struct _GstObject GstObject;
40 
41 namespace deepstream {
42 
43 class SignalHandler;
44 class SignalEmitter;
45 
49 class Object {
50 public:
51 
58  class Value {
59  public:
60  Value();
61  Value(char value);
62  Value(unsigned char value);
63  Value(int value);
64  Value(unsigned int value);
65  Value(long value);
66  Value(unsigned long value);
67  Value(float value);
68  Value(double value);
69  Value(const std::string value);
70  Value(const char* value);
71  Value(bool value);
72 
73  Value(const Value& other);
74 
75  virtual ~Value();
76 
77  Value &operator=(const Value& other);
78 
79  operator char() const;
80  operator unsigned char() const;
81  operator int() const;
82  operator unsigned int() const;
83  operator long() const;
84  operator unsigned long() const;
85  operator float() const;
86  operator double() const;
87  operator std::string() const;
88  operator const char*() const;
89  operator bool() const;
90 
91  bool isChar() const;
92  bool isUnsignedChar() const;
93  bool isInteger() const;
94  bool isUnsignedInteger() const;
95  bool isFloat() const;
96  bool isString() const;
97  bool isBoolean() const;
98 
99  private:
100  GValue* value_;
101 
102  Value(unsigned long, int);
103 
104  friend class Object;
105  };
106 
108  Object();
115  Object(unsigned long type_id, const std::string& name);
116 
118  Object(const Object&);
119 
121  Object(Object&&) noexcept;
122 
124  Object& operator=(const Object&);
125 
127  Object& operator=(Object&&) noexcept;
128 
130  virtual ~Object();
131 
133  const std::string getName() const;
134 
136  explicit operator bool () const noexcept { return object_ != nullptr; }
137 
139  bool operator == (const Object& other) noexcept { return object_ == other.object_; }
140 
142  GstObject* give();
143 
146  return object_;
147  }
148 
150  Object& take(GstObject* object);
151 
153  Object& seize(GstObject* object);
154 
156  Object& set(const YAML::Node& params);
157 
158  // set the properties through ke/value pair directly
159  Object& set(const std::string& name, const Value& value) {
160  this->set_(name, value);
161  return *this;
162  }
163 
164  // template for setting multiple properties
165  template<typename T, typename... Args>
166  Object& set(const std::string& name, const T& value, const Args&... args) {
167  set_(name, Value(value));
168  if constexpr (sizeof...(args) > 0) {
169  this->set(args...);
170  }
171  return *this;
172  }
173 
175  template<typename T, typename... Args>
176  Object& getProperty(const std::string& name, T& value, Args&... args) {
177  value = (T) get_(name);
178  if constexpr (sizeof...(args) > 0) {
179  this->getProperty(args...);
180  }
181  return *this;
182  }
183 
185  std::vector<std::string> listSignals(bool is_action);
186 
194  bool connectSignal(const std::string&signal_name, SignalHandler& handler);
195 
197  void emitSignal(const std::string&signal_name, va_list args);
198 
200  static unsigned long type();
201 
202 protected:
204 
205  virtual void set_(const std::string& name, const Value& value);
206  virtual void set_(const std::string& name, const YAML::Node& value);
207  virtual Value get_(const std::string&name);
208 
209 friend class Pipeline;
210 friend class Element;
211 };
212 
213 }
214 
215 #endif
deepstream::Object::Value::~Value
virtual ~Value()
deepstream::Object::set
Object & set(const std::string &name, const T &value, const Args &... args)
Definition: service-maker/includes/object.hpp:166
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: service-maker/includes/object.hpp:58
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: service-maker/includes/element.hpp:54
deepstream::Object::set_
virtual void set_(const std::string &name, const Value &value)
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: service-maker/includes/pipeline.hpp:96
deepstream::Object::Value::isBoolean
bool isBoolean() const
deepstream::Object::type
static unsigned long type()
Return the object's type id.
deepstream::Object::object_
GstObject * object_
Definition: service-maker/includes/object.hpp:203
deepstream::Object::connectSignal
bool connectSignal(const std::string &signal_name, SignalHandler &handler)
Connect a signal handler to the object.
deepstream
Definition: service-maker/includes/buffer.hpp:38
deepstream::Object::set
Object & set(const std::string &name, const Value &value)
Definition: service-maker/includes/object.hpp:159
deepstream::Object::seize
Object & seize(GstObject *object)
Seize a opaque object to prevent it from being destroyed somewhere.
GValue
struct _GValue GValue
Definition: service-maker/includes/object.hpp:38
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: service-maker/includes/object.hpp:145
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::operator==
bool operator==(const Object &other) noexcept
Check if the two objects are the same.
Definition: service-maker/includes/object.hpp:139
deepstream::Object::get_
virtual Value get_(const std::string &name)
GstObject
struct _GstObject GstObject
Definition: service-maker/includes/object.hpp:39
deepstream::Object::Value::isInteger
bool isInteger() const
deepstream::Object::listSignals
std::vector< std::string > listSignals(bool is_action)
List all the supported signals from the object.
deepstream::SignalHandler
SignalHandler class.
Definition: service-maker/includes/signal_handler.hpp:45
deepstream::Object
Base Object class.
Definition: service-maker/includes/object.hpp:49
deepstream::Object::getProperty
Object & getProperty(const std::string &name, T &value, Args &... args)
Template for getting multiple properties.
Definition: service-maker/includes/object.hpp:176