NVIDIA DeepStream SDK API Reference

9.1 Release
service-maker/includes/lib/msgbroker_c2d_receiver.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 
18 #ifndef DEEPSTREAM_MSGBROKER_C2D_RECEIVER_HPP
19 #define DEEPSTREAM_MSGBROKER_C2D_RECEIVER_HPP
20 
21 #include <string>
22 #include <functional>
23 #include <vector>
24 #include <unordered_map>
25 #include <algorithm>
26 #include <cstdint>
27 
29 
30 namespace deepstream {
32  public:
33  typedef struct {
34  std::string proto_lib;
35  std::string conn_str;
36  std::string config_file_path;
37  std::string topicList;
38  std::string sensor_list_file;
39  } Config;
40  class IHandler {
41  public:
42  virtual ~IHandler() {}
43  };
44 
45  // smart recording controller
47  public:
48  virtual void startSmartRecord(int64_t camera_id, uint32_t *sessionId,
49  unsigned int startTime, unsigned int duration,
50  void *userData) = 0;
51  virtual void stopSmartRecord(int64_t camera_id, uint32_t sessionId) = 0;
52  };
53 
55  virtual ~Cloud2DeviceReceiver();
56 
57  void connect(Config& config);
58  void disconnect();
59  bool isConnected() { return context_ != nullptr; }
60  bool hasHandler(IHandler* handler) {
61  return std::find(handlers_.begin(), handlers_.end(), handler) != handlers_.end();
62  }
63  void addHandler(IHandler* handler) { handlers_.push_back(handler); }
64 
65  bool handleMessage(const char* topic, const char* payload, unsigned int size);
66 
68 
69  // static Cloud2DeviceReceiver& getInstance() {
70  // static Cloud2DeviceReceiver instance; // create a single instance on first use
71  // return instance;
72  // }
73 
74  private:
75 
76  bool parse_msgconv_config(const std::string& file_path);
77 
78  std::string config_path_;
79  NvDsC2DContext* context_ = nullptr;
80  std::vector<IHandler*> handlers_;
81  std::unordered_map<std::string, int64_t> sensor_name_id_map_;
82  std::unordered_map<std::string, uint32_t> sensor_sr_session_id_map_;
83 };
84 }
85 
86 #endif
deepstream::Cloud2DeviceReceiver::addHandler
void addHandler(IHandler *handler)
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:63
NvDsC2DContext
Definition: sources/apps/apps-common/includes/deepstream_c2d_msg.h:29
deepstream::Cloud2DeviceReceiver::IHandler::~IHandler
virtual ~IHandler()
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:42
deepstream::Cloud2DeviceReceiver::Config::conn_str
std::string conn_str
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:35
deepstream::Cloud2DeviceReceiver::Config::config_file_path
std::string config_file_path
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:36
deepstream::Cloud2DeviceReceiver::Cloud2DeviceReceiver
Cloud2DeviceReceiver()
deepstream::Cloud2DeviceReceiver::IHandler
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:40
deepstream::Cloud2DeviceReceiver::Config::sensor_list_file
std::string sensor_list_file
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:38
deepstream::Cloud2DeviceReceiver::Config::proto_lib
std::string proto_lib
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:34
deepstream
Definition: service-maker/includes/buffer.hpp:38
deepstream::Cloud2DeviceReceiver::ISmartRecordingController
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:46
deepstream::Cloud2DeviceReceiver::connect
void connect(Config &config)
deepstream::Cloud2DeviceReceiver::Config
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:33
deepstream::Cloud2DeviceReceiver::ISmartRecordingController::startSmartRecord
virtual void startSmartRecord(int64_t camera_id, uint32_t *sessionId, unsigned int startTime, unsigned int duration, void *userData)=0
deepstream::Cloud2DeviceReceiver::isConnected
bool isConnected()
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:59
deepstream::Cloud2DeviceReceiver
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:31
deepstream::Cloud2DeviceReceiver::getInstance
static Cloud2DeviceReceiver & getInstance()
deepstream::Cloud2DeviceReceiver::~Cloud2DeviceReceiver
virtual ~Cloud2DeviceReceiver()
deepstream::Cloud2DeviceReceiver::hasHandler
bool hasHandler(IHandler *handler)
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:60
deepstream::Cloud2DeviceReceiver::Config::topicList
std::string topicList
Definition: service-maker/includes/lib/msgbroker_c2d_receiver.hpp:37
deepstream::Cloud2DeviceReceiver::disconnect
void disconnect()
deepstream::Cloud2DeviceReceiver::ISmartRecordingController::stopSmartRecord
virtual void stopSmartRecord(int64_t camera_id, uint32_t sessionId)=0
deepstream::Cloud2DeviceReceiver::handleMessage
bool handleMessage(const char *topic, const char *payload, unsigned int size)