Compute Graph Framework SDK Reference
5.4.5418 Release
For Test and Development only

ChannelParameters.hpp
Go to the documentation of this file.
1 //
3 // Notice
4 // ALL NVIDIA DESIGN SPECIFICATIONS AND CODE ("MATERIALS") ARE PROVIDED "AS IS" NVIDIA MAKES
5 // NO REPRESENTATIONS, WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
6 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTIES OF NONINFRINGEMENT,
7 // MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 //
9 // NVIDIA CORPORATION & AFFILIATES assumes no responsibility for the consequences of use of such
10 // information or for any infringement of patents or other rights of third parties that may
11 // result from its use. No license is granted by implication or otherwise under any patent
12 // or patent rights of NVIDIA CORPORATION & AFFILIATES. No third party distribution is allowed unless
13 // expressly authorized by NVIDIA. Details are subject to change without notice.
14 // This code supersedes and replaces all information previously supplied.
15 // NVIDIA CORPORATION & AFFILIATES products are not authorized for use as critical
16 // components in life support devices or systems without express written approval of
17 // NVIDIA CORPORATION & AFFILIATES.
18 //
19 // SPDX-FileCopyrightText: Copyright (c) 2018-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
20 // SPDX-License-Identifier: LicenseRef-NvidiaProprietary
21 //
22 // NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
23 // property and proprietary rights in and to this material, related
24 // documentation and any modifications thereto. Any use, reproduction,
25 // disclosure or distribution of this material and related documentation
26 // without an express license agreement from NVIDIA CORPORATION or
27 // its affiliates is strictly prohibited.
28 //
30 
31 #ifndef DW_FRAMEWORK_CHANNEL_PARAMETERS_HPP_
32 #define DW_FRAMEWORK_CHANNEL_PARAMETERS_HPP_
33 
34 #include <dwcgf/Types.hpp>
35 #include <dwcgf/Exception.hpp>
36 #include <dw/core/base/Types.h>
37 #include <dw/core/container/BaseString.hpp>
38 #include <dw/core/container/VectorFixed.hpp>
39 #include <dw/core/system/NvMediaExt.h>
41 #include <sstream>
42 #include <limits>
43 
44 namespace dw
45 {
46 namespace framework
47 {
48 
50 using ChannelType = enum ChannelType : uint8_t {
51  DW_CHANNEL_TYPE_SHMEM_LOCAL = 0,
52  DW_CHANNEL_TYPE_SHMEM_REMOTE = 1,
53  DW_CHANNEL_TYPE_EGLSTREAM = 2,
54  DW_CHANNEL_TYPE_SOCKET = 3,
55  DW_CHANNEL_TYPE_DDS = 4,
56  DW_CHANNEL_TYPE_NVSCI = 5,
57 };
58 
59 static inline const char* ToParam(ChannelType channelType)
60 {
61  const char* result;
62  switch (channelType)
63  {
64  case DW_CHANNEL_TYPE_SHMEM_LOCAL:
65  result = "type=SHMEM_LOCAL";
66  break;
67  case DW_CHANNEL_TYPE_SHMEM_REMOTE:
68  result = "type=SHMEM_REMOTE";
69  break;
70  case DW_CHANNEL_TYPE_EGLSTREAM:
71  result = "type=EGLSTREAM";
72  break;
73  case DW_CHANNEL_TYPE_SOCKET:
74  result = "type=SOCKET";
75  break;
76  case DW_CHANNEL_TYPE_DDS:
77  result = "type=DDS";
78  break;
79  case DW_CHANNEL_TYPE_NVSCI:
80  result = "type=NVSCI";
81  break;
82  default:
83  result = "";
84  break;
85  }
86  return result;
87 }
88 
89 enum class ChannelRole : uint8_t
90 {
94  DW_CHANNEL_ROLE_COMPOSITE = 0b11, // Contains both producer and consumer
95 };
96 
97 inline constexpr bool IsProducer(ChannelRole role)
98 {
99  return static_cast<uint8_t>(role) & static_cast<uint8_t>(ChannelRole::DW_CHANNEL_ROLE_PRODUCER);
100 }
101 
102 inline constexpr bool IsConsumer(ChannelRole role)
103 {
104  return static_cast<uint8_t>(role) & static_cast<uint8_t>(ChannelRole::DW_CHANNEL_ROLE_CONSUMER);
105 }
106 
107 static constexpr uint16_t MAX_CHANNEL_PARAM_SIZE = 256;
108 static constexpr uint16_t MAX_CHANNEL_ALL_PARAMS_SIZE = 256;
109 static constexpr uint16_t MAX_CHANNEL_PRODUCERS_COUNT = 1024;
110 static constexpr uint16_t MAX_CHANNEL_CONSUMERS_COUNT = 256;
111 
112 using ChannelParamStr = dw::core::FixedString<MAX_CHANNEL_PARAM_SIZE>;
113 
114 enum class ChannelMode
115 {
116  FIFO,
117  MAILBOX,
118  SINGLETON
119 };
120 
121 // NOTE(eklein): This is slightly awkward. I would much prefer to put this in
122 // the ChannelNvSciStreamParams class directly, but I need access to the
123 // operator overloads inside ChannelNvSciStreamParams.
124 // I cannot forward declare the operators inside the class, and I cannot put the
125 // operators inside the enum class (as you would ideally do). The best compromise
126 // I could think of was to put this enum class here outside.
128 {
129  COMPONENT_NONE = 0,
130 
131  COMPONENT_CPU = 1 << 0,
132  COMPONENT_EGL = 1 << 1,
133  COMPONENT_CUDA = 1 << 2,
134  COMPONENT_PVA = 1 << 3,
135  COMPONENT_DLA = 1 << 4,
136  COMPONENT_NVMEDIA = 1 << 5,
137 };
138 
139 // whether the channel is created statically, or dynamically at runtime
141 {
145 };
146 
147 // the farthest reach this channel can achieve
148 // shorter reach is faster, so if topology is known upfront,
149 // use the shortest matching reach for maximum performance
150 enum class ChannelReach
151 {
152  REACH_NONE = 0,
153  REACH_THREAD,
155  REACH_VM,
156  REACH_CHIP
157 };
158 
161 {
162  return static_cast<ChannelNvSciStreamEnabledComponents>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
163 }
164 
167 {
168  return static_cast<ChannelNvSciStreamEnabledComponents>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
169 }
170 
171 template <typename T>
172 static inline T ParseChannelParameter(const ChannelParamStr& value);
173 
174 template <>
176 {
177  std::size_t start = 0;
178  std::size_t end;
180  do
181  {
182  end = value.find("|", start);
183 
184  ChannelParamStr valueSubString = (end != dw::core::FixedString<1>::NPOS) ? value.substr(start, end - start) : value.substr(start, value.length() - start);
185 
186  if (valueSubString == "CPU")
187  {
189  }
190  else if (valueSubString == "EGL")
191  {
193  }
194  else if (valueSubString == "CUDA")
195  {
197  }
198  else if (valueSubString == "PVA")
199  {
201  }
202  else if (valueSubString == "DLA")
203  {
205  }
206  else if (valueSubString == "NVMEDIA")
207  {
209  }
210  else
211  {
212  throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: enabledComponents sub-value unrecongnized: ", valueSubString);
213  }
214 
215  start = end + 1;
216  } while (end != dw::core::FixedString<1>::NPOS);
217 
218  return result;
219 }
220 
221 template <>
223 {
224  ChannelConnectionType result;
225  if (value == "dynamic")
226  {
228  }
229  else if (value == "static")
230  {
232  }
233  else
234  {
235  throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: connection phase value unrecongnized: ", value);
236  }
237  return result;
238 }
239 
240 template <>
242 {
243  ChannelReach result;
244  if (value == "thread")
245  {
247  }
248  else if (value == "process")
249  {
251  }
252  else if (value == "vm")
253  {
254  result = ChannelReach::REACH_VM;
255  }
256  else if (value == "chip")
257  {
258  result = ChannelReach::REACH_CHIP;
259  }
260  else
261  {
262  throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: reach value unrecongnized: ", value);
263  }
264 
265  return result;
266 }
267 
268 template <>
270 {
271  auto translatedSize = strtol(value.c_str(), nullptr, 10);
272  return translatedSize;
273 }
274 
275 template <>
277 {
278  auto translatedSize = ParseChannelParameter<int64_t>(value);
279  if (translatedSize < 0)
280  {
281  throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: size_t is negative");
282  }
283  size_t result = static_cast<size_t>(translatedSize);
284  return result;
285 }
286 
287 template <>
289 {
290  auto translatedSize = ParseChannelParameter<size_t>(value);
291  uint32_t result = static_cast<uint32_t>(translatedSize);
292  return result;
293 }
294 
295 template <>
297 {
298  auto translatedSize = ParseChannelParameter<size_t>(value);
299  if (translatedSize > 0xFFFF)
300  {
301  throw Exception(DW_INVALID_ARGUMENT, "ChannelSocketParams: port is larger than uint16_t allows!");
302  }
303  uint16_t result = static_cast<uint16_t>(translatedSize);
304  return result;
305 }
306 
307 template <>
309 {
310  bool result;
311  if ((value == "true") || (value == "1"))
312  {
313  result = true;
314  }
315  else if ((value == "false") || (value == "0"))
316  {
317  result = false;
318  }
319  else
320  {
321  throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: needs to be 'true' or 'false' or 1/0");
322  }
323  return result;
324 }
325 
326 template <>
328 {
329  ChannelRole result{};
330  if (value == "producer")
331  {
333  }
334  else if (value == "consumer")
335  {
337  }
338  else if (value == "composite")
339  {
341  }
342  else
343  {
344  throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: role unknown!");
345  }
346  return result;
347 }
348 
349 template <>
351 {
352  ChannelType result{};
353  if (value == "SHMEM_LOCAL")
354  {
355  result = ChannelType::DW_CHANNEL_TYPE_SHMEM_LOCAL;
356  }
357  else if (value == "SHMEM_REMOTE")
358  {
359  result = ChannelType::DW_CHANNEL_TYPE_SHMEM_REMOTE;
360  }
361  else if (value == "EGLSTREAM")
362  {
363  result = ChannelType::DW_CHANNEL_TYPE_EGLSTREAM;
364  }
365  else if (value == "SOCKET")
366  {
367  result = ChannelType::DW_CHANNEL_TYPE_SOCKET;
368  }
369  else if (value == "DDS")
370  {
371  result = ChannelType::DW_CHANNEL_TYPE_DDS;
372  }
373  else if (value == "NVSCI")
374  {
375  result = ChannelType::DW_CHANNEL_TYPE_NVSCI;
376  }
377  else
378  {
379  throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: type unknown!");
380  }
381 
382  return result;
383 }
384 
385 template <>
387 {
388  ChannelMode result;
389  if (value == "mailbox")
390  {
391  result = ChannelMode::MAILBOX;
392  }
393  else if (value == "singleton")
394  {
395  result = ChannelMode::SINGLETON;
396  }
397  else
398  {
399  throw Exception(DW_INVALID_ARGUMENT, "ParseChannelParameter: ChannelMode unknown!");
400  }
401  return result;
402 }
403 
404 template <typename T>
405 void ParseChannelParameter(const ChannelParamStr& value, T& result)
406 {
407  result = ParseChannelParameter<T>(value);
408 }
409 
410 template <size_t Size>
411 void ParseChannelParameter(const ChannelParamStr& value, dw::core::FixedString<Size>& result)
412 {
413  result = value;
414 }
415 
416 template <typename T, size_t N>
417 void ParseChannelParameter(const ChannelParamStr& value, dw::core::VectorFixed<T, N>& result)
418 {
419  size_t pos = 0U;
420  size_t endpos = 0U;
421  bool done = false;
422  while (!done)
423  {
424  endpos = value.find(":", pos);
425  done = endpos == dw::core::FixedString<1>::NPOS;
426  size_t count = done ? endpos : endpos - pos;
427  T entry{};
428  ParseChannelParameter(value.substr(pos, count), entry);
429  result.push_back(entry);
430  pos = endpos + 1;
431  }
432 }
433 
434 static inline void ParseChannelParameters(const ChannelParamStr&, const ChannelParamStr&)
435 {
436  return;
437 }
438 
439 template <typename T, typename... Others>
440 static inline void ParseChannelParameters(const ChannelParamStr& key, const ChannelParamStr& value, const char* staticKey, T& result, Others&&... others)
441 {
442  if (key == staticKey)
443  {
444  ParseChannelParameter(value, result);
445  return;
446  }
447  ParseChannelParameters(key, value, std::forward<Others>(others)...);
448 }
449 
450 template <typename... Others>
451 static inline void ParseAllChannelParameters(const ChannelParamStr& channelParams, Others&&... others)
452 {
453  std::size_t key = 0;
454  std::size_t pos = channelParams.find("=");
455  std::size_t value = 0;
456  std::size_t valueEnd = 0;
457 
458  ChannelParamStr keyString;
459  ChannelParamStr valueString;
460  while (pos != dw::core::FixedString<1>::NPOS && value != dw::core::FixedString<1>::NPOS)
461  {
462  keyString = channelParams.substr(key, pos - key);
463  value = channelParams.find(",", pos);
464  valueEnd = (value == dw::core::FixedString<1>::NPOS) ? (channelParams.length() - (pos + 1)) : (value - pos - 1);
465  valueString = channelParams.substr(pos + 1, valueEnd);
466  ParseChannelParameters(keyString, valueString, std::forward<Others>(others)...);
467 
468  key = value + 1;
469  pos = channelParams.find("=", key);
470  }
471 }
472 
474 {
475 public:
476  static inline ChannelParamStr getParamStr(const char* serverIP,
477  uint16_t port,
478  bool producerFifo = false,
479  uint16_t numBlockingConnections = 1)
480  {
481  std::stringstream ss;
482  ss.flags(std::ios::dec);
483  ss << "type=SOCKET";
484  if (serverIP != nullptr)
485  {
486  ss << ",ip=";
487  ss << serverIP;
488  }
489  ss << ",id=";
490  ss << port;
491  ss << ",producer-fifo=";
492  ss << static_cast<uint32_t>(producerFifo);
493  ss << ",num-clients=";
494  ss << numBlockingConnections;
495  ChannelParamStr result(ss.str().c_str());
496  return result;
497  }
498 
499  ChannelSocketParams() = default;
500  explicit ChannelSocketParams(const char* params)
501  {
502  dw::core::FixedString<MAX_CHANNEL_ALL_PARAMS_SIZE> channelParams(params);
503  ParseAllChannelParameters(channelParams,
504  "ip", m_serverIP,
505  "producer-fifo", m_producerFifo,
506  "id", m_port);
507  }
508 
509  ChannelSocketParams(const ChannelSocketParams& other) = default;
510 
511  ChannelSocketParams& operator=(const ChannelSocketParams& other) = default;
512 
513  ChannelParamStr getServerIP() const { return m_serverIP; }
514  uint16_t getPort() const { return m_port; }
515  bool hasProducerFifo() const { return m_producerFifo; }
516 
517 private:
518  ChannelParamStr m_serverIP; // needed for socket client connection
519  uint16_t m_port = 0;
520  bool m_producerFifo = false; // Allow the socket producer to have its own fifo to queue up work
521 };
522 
524 
526 {
527 public:
528  ChannelNvSciStreamParams() = default;
529 
530  explicit ChannelNvSciStreamParams(const char* params)
532  {
533  dw::core::FixedString<MAX_CHANNEL_ALL_PARAMS_SIZE> channelParams(params);
534  ParseAllChannelParameters(channelParams,
535  "streamName", m_streamNames,
536  "enabledComponents", m_enabledComponents,
537  "connectionType", m_connectionType,
538  "timeoutUsec", m_timeoutUsec,
539  "reach", m_reaches);
540  }
541 
542  ChannelNvSciStreamParams(const ChannelNvSciStreamParams& other) = default;
543 
544  ChannelNvSciStreamParams& operator=(const ChannelNvSciStreamParams& other) = default;
545 
546  dwTime_t getTimeoutUsec() const { return m_timeoutUsec; }
547 
548  ChannelNvSciStreamEnabledComponents getEnabledComponents() const { return m_enabledComponents; }
549  bool isEnabledComponentCpu() const { return ((m_enabledComponents & ChannelNvSciStreamEnabledComponents::COMPONENT_CPU) == ChannelNvSciStreamEnabledComponents::COMPONENT_CPU); }
550  bool isEnabledComponentEgl() const { return ((m_enabledComponents & ChannelNvSciStreamEnabledComponents::COMPONENT_EGL) == ChannelNvSciStreamEnabledComponents::COMPONENT_EGL); }
551  bool isEnabledComponentCuda() const { return ((m_enabledComponents & ChannelNvSciStreamEnabledComponents::COMPONENT_CUDA) == ChannelNvSciStreamEnabledComponents::COMPONENT_CUDA); }
552  bool isEnabledComponentPva() const { return ((m_enabledComponents & ChannelNvSciStreamEnabledComponents::COMPONENT_PVA) == ChannelNvSciStreamEnabledComponents::COMPONENT_PVA); }
553  bool isEnabledComponentDla() const { return ((m_enabledComponents & ChannelNvSciStreamEnabledComponents::COMPONENT_DLA) == ChannelNvSciStreamEnabledComponents::COMPONENT_DLA); }
554  bool isEnabledComponentNvmedia() const { return ((m_enabledComponents & ChannelNvSciStreamEnabledComponents::COMPONENT_NVMEDIA) == ChannelNvSciStreamEnabledComponents::COMPONENT_NVMEDIA); }
555 
556  ChannelConnectionType getChannelConnectionType() const { return m_connectionType; }
557  bool isConnectionTypeStatic() const { return (m_connectionType == ChannelConnectionType::CONNECTION_TYPE_STATIC); }
558  bool isConnectionTypeDynamic() const { return (m_connectionType == ChannelConnectionType::CONNECTION_TYPE_DYNAMIC); }
559  uint16_t getNumOutputs() const
560  {
561  static_assert(decltype(m_streamNames)::CAPACITY_AT_COMPILE_TIME < std::numeric_limits<uint16_t>::max(), "ChannelNvSciStreamParams: number of outputs over limit");
562  return static_cast<uint16_t>(m_streamNames.size());
563  }
564 
565  bool isMulticast() const
566  {
567  return m_streamNames.size() > 1U;
568  }
569 
570  const char* getStreamName(uint16_t index = 0) const
571  {
572  if (index >= m_streamNames.size())
573  {
574  throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: stream name index out of range");
575  }
576  return m_streamNames[index].c_str();
577  }
578 
579  ChannelReach getChannelReach(uint16_t index = 0) const
580  {
581  if (m_reaches.size() == 0)
582  {
584  }
585  if (index >= m_reaches.size())
586  {
587  throw Exception(DW_INVALID_ARGUMENT, "ChannelNvSciStreamParams: reach index out of range");
588  }
589  return m_reaches[index];
590  }
591 
592 protected:
593  dwTime_t m_timeoutUsec = 5000 * 1000;
594  // bitmask of ChannelNvSciStreamEnabledComponents enum
597  dw::core::VectorFixed<dw::core::FixedString<64>, 8> m_streamNames{};
598  dw::core::VectorFixed<ChannelReach, 8> m_reaches{};
599 };
600 
602 {
603 public:
604  explicit ChannelParams(const char* params)
605  : m_str(params)
606  {
608  "fifo-size", m_fifoSize,
609  "id", m_id,
610  "singleton-id", m_singletonId,
611  "trace-name", m_traceId, // TODO(chale): should be trace-id but assumption that id field is
612  // is only parameter with 'id' as a substring is hardcoded in many places
613  "mode", m_mode,
614  "reuse", m_reuseEnabled,
615  "debug-port", m_debugPort,
616  "num-clients", m_clientsCount,
617  "debug-num-clients", m_debugClientsCount,
618  "role", m_role,
619  "type", m_type,
620  "data-offset", m_dataOffset,
621  "strict", m_strictFifo,
622  "sync-enabled", m_syncEnabled);
623 
624  adjustPoolCapacity();
625 
626  if (m_clientsCount == 0)
627  {
628  m_clientsCount = 1;
629  }
630 
631  if (!m_singletonId.empty())
632  {
633  m_mode = ChannelMode::SINGLETON;
634  }
635 
636  if (m_mode == ChannelMode::MAILBOX)
637  {
638  m_mailboxMode = true;
639  }
640  else if (m_mode == ChannelMode::SINGLETON)
641  {
642  m_singletonMode = true;
643 
644  // Assign singletonId with id
645  if (!m_id.empty() && m_singletonId.empty())
646  {
647  m_singletonId = m_id;
648  }
649  }
650 
651  // Why break this up like this? Code complexity.
652  // Without this, we fail the code complexity analysis.
653  ValidateMailbox();
654  ValidateSingleton();
655 
656  switch (m_type)
657  {
658  case DW_CHANNEL_TYPE_SHMEM_LOCAL:
659  break;
660  case DW_CHANNEL_TYPE_SOCKET:
661  m_socketParams = ChannelSocketParams(params);
662  break;
663  case DW_CHANNEL_TYPE_NVSCI:
664  m_nvSciStreamParams = ChannelNvSciStreamParams(params);
665  break;
666  case DW_CHANNEL_TYPE_SHMEM_REMOTE:
667  case DW_CHANNEL_TYPE_EGLSTREAM:
668  case DW_CHANNEL_TYPE_DDS:
669  default:
670  throw Exception(DW_NOT_IMPLEMENTED, "ChannelParams: no parameters for channel type");
671  break;
672  }
673  }
674 
676  {
677  *this = other;
678  }
679 
680  ChannelParams& operator=(const ChannelParams& other) = default;
681  ~ChannelParams() = default;
682 
683  const char* getStr() const { return m_str.c_str(); }
684  ChannelParamStr getId() const { return m_id; }
685  ChannelParamStr getSingletonId() const { return m_singletonId; }
686  uint16_t getDebugPort() const { return m_debugPort; }
687  size_t getFifoSize() const { return m_fifoSize; }
688  // Note(chale): Normally the fifo length governs whether a consumer
689  // will receive packet. The actual packet pool's size may be larger
690  // than the fifo length. non-strict mode allows consumers to receive
691  // up to the entire pool size instead of just their fifo length.
692  bool isStrictFifo() const { return m_strictFifo; }
693  void setStrictFifo(bool strictFifo)
694  {
695  m_strictFifo = strictFifo;
696  }
697  size_t getPoolCapacity() const { return m_poolCapacity; }
698  bool getMailboxMode() const { return m_mailboxMode; }
699  // Note (ajayawardane): The data-offset parameter is used to describe
700  // the consumption offset between the producer and the consumer
701  // in the sync packet use-case. For example, if a packet is produced with the
702  // sync count x, and is inteneded to be consumed when the sync count is x + 1,
703  // the data-offset would be 1. This parameter is also used to identify whether
704  // to use sync packets to transfer data, so needs to be included in both the
705  // producer and the consumer params.
706  uint32_t getDataOffset() const { return m_dataOffset; }
707  bool getSyncEnabled() const { return m_syncEnabled; }
708  void setMailboxMode(bool mailboxEnabled) { m_mailboxMode = mailboxEnabled; }
709  bool getSingletonMode() const { return m_singletonMode; }
710  bool getReuseEnabled() const { return m_reuseEnabled; }
711  bool getDebugMode() const { return m_debugPort > 0; }
712  uint16_t getExpectedConnectionsCount() const { return m_clientsCount; }
713  uint16_t getExpectedDebugConnectionsCount() const { return m_debugClientsCount; }
714  ChannelRole getRole() const { return m_role; }
715  ChannelType getType() const { return m_type; }
716  ChannelParamStr getTraceId() const { return m_traceId; }
717 
719  {
720  if (m_type != ChannelType::DW_CHANNEL_TYPE_SOCKET)
721  {
722  throw Exception(DW_CALL_NOT_ALLOWED, "ChannelParams: getSocketParams: channel is not of type SOCKET");
723  }
724  return m_socketParams;
725  }
726 
728  {
729  if (m_type != ChannelType::DW_CHANNEL_TYPE_NVSCI)
730  {
731  throw Exception(DW_CALL_NOT_ALLOWED, "ChannelParams: getNvSciStreamParams: channel is not of type NVSCI");
732  }
733  return m_nvSciStreamParams;
734  }
735 
736 private:
737  void ValidateMailbox()
738  {
739  if (m_singletonMode)
740  {
741  if (m_fifoSize != 1)
742  {
743  throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: Singleton and mailbox modes are incompatible with a fifo setting other than 1");
744  }
745  }
746  if (!m_mailboxMode && m_reuseEnabled)
747  {
748  throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: reuse=true specified when mode!=mailbox. Not valid");
749  }
750  if (m_mailboxMode && m_singletonMode)
751  {
752  throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: Singleton mode is incompatible mailbox mode");
753  }
754  }
755 
756  void ValidateSingleton()
757  {
758  // Assign singletonId with id in singleton mode
759  if (m_singletonMode && m_singletonId.empty())
760  {
761  m_singletonId = m_id;
762  }
763  if (!m_singletonMode && !m_singletonId.empty())
764  {
765  throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: Singleton mode requires both the mode set AND singletonId set");
766  }
767  if (m_singletonMode && (m_type != ChannelType::DW_CHANNEL_TYPE_SHMEM_LOCAL))
768  {
769  throw Exception(DW_INVALID_ARGUMENT, "ChannelParams: Singleton mode is only valid for SHMEM_LOCAL channels");
770  }
771  }
772 
773  void adjustPoolCapacity()
774  {
775  // This deserves a comment. The LocalShmem pools (in the fifo-case)
776  // need the following number of slots, in the worst case:
777  // 1 for getImpl to return at any time
778  // 1 per consumer for in-flight data
779  // fifo-size to store a full fifo worth of packets
780  // So assuming max consumers, we'd need fifo-size + MAX_CHANNEL_CONSUMERS_COUNT + 1
781  if (m_fifoSize + MAX_CHANNEL_CONSUMERS_COUNT + 1 > m_poolCapacity)
782  {
783  m_poolCapacity = m_fifoSize + MAX_CHANNEL_CONSUMERS_COUNT + 1;
784  }
785  }
786 
787 private:
788  ChannelParamStr m_str{};
789  ChannelParamStr m_id{};
790  ChannelParamStr m_singletonId{};
791  ChannelParamStr m_traceId{};
792 
793  // fifo size of the socket client that implies the maximum number of packets
794  // a client can hold simultaneously
795  size_t m_fifoSize = 1;
796  // This deserves a comment. The LocalShmem pools (in the fifo-case)
797  // need the following number of slots, in the worst case:
798  // 1 for getImpl to return at any time
799  // 1 per consumer for in-flight data
800  // fifo-size to store a full fifo worth of packets
801  // So assuming a fifo-size of 1 and max consumers, we'd need MAX_CHANNEL_CONSUMERS_COUNT + 2
802  size_t m_poolCapacity = MAX_CHANNEL_CONSUMERS_COUNT + 2;
804  uint32_t m_dataOffset = 0;
805  bool m_syncEnabled = false;
806  bool m_mailboxMode = false;
807  bool m_singletonMode = false;
808  bool m_reuseEnabled = false;
810  ChannelType m_type = ChannelType::DW_CHANNEL_TYPE_SHMEM_LOCAL;
811  bool m_strictFifo = true;
812 
813  uint16_t m_clientsCount = 1; // number of clients for blocking mode for socket
814  uint16_t m_debugClientsCount = 1; // number of debug clients for blocking mode for socket
815 
816  uint16_t m_debugPort = 0;
817 
818  ChannelSocketParams m_socketParams{};
819  ChannelNvSciStreamParams m_nvSciStreamParams{};
820 };
821 
822 } // namespace framework
823 } // namespace dw
824 
825 #endif // DW_FRAMEWORK_CHANNEL_HPP_
constexpr bool IsProducer(ChannelRole role)
void setMailboxMode(bool mailboxEnabled)
static constexpr uint16_t MAX_CHANNEL_PRODUCERS_COUNT
constexpr ChannelNvSciStreamEnabledComponents operator|(ChannelNvSciStreamEnabledComponents a, ChannelNvSciStreamEnabledComponents b)
const ChannelNvSciStreamParams & getNvSciStreamParams() const
ChannelParamStr getTraceId() const
static void ParseAllChannelParameters(const ChannelParamStr &channelParams, Others &&... others)
enum ChannelType :uint8_t { DW_CHANNEL_TYPE_SHMEM_LOCAL=0, DW_CHANNEL_TYPE_SHMEM_REMOTE=1, DW_CHANNEL_TYPE_EGLSTREAM=2, DW_CHANNEL_TYPE_SOCKET=3, DW_CHANNEL_TYPE_DDS=4, DW_CHANNEL_TYPE_NVSCI=5, } ChannelType
const ChannelSocketParams & getSocketParams() const
ChannelConnectionType getChannelConnectionType() const
ChannelParams(const ChannelParams &other)
ChannelReach getChannelReach(uint16_t index=0) const
uint16_t getExpectedDebugConnectionsCount() const
static T ParseChannelParameter(const ChannelParamStr &value)
constexpr ChannelNvSciStreamEnabledComponents operator &(ChannelNvSciStreamEnabledComponents a, ChannelNvSciStreamEnabledComponents b)
ChannelNvSciStreamEnabledComponents getEnabledComponents() const
static constexpr uint16_t MAX_CHANNEL_CONSUMERS_COUNT
static constexpr uint16_t MAX_CHANNEL_ALL_PARAMS_SIZE
void setStrictFifo(bool strictFifo)
ChannelParamStr getSingletonId() const
static void ParseChannelParameters(const ChannelParamStr &, const ChannelParamStr &)
Definition: Exception.hpp:46
uint16_t getExpectedConnectionsCount() const
static constexpr uint16_t MAX_CHANNEL_PARAM_SIZE
ChannelParamStr getId() const
dw::core::FixedString< MAX_CHANNEL_PARAM_SIZE > ChannelParamStr
static ChannelParamStr getParamStr(const char *serverIP, uint16_t port, bool producerFifo=false, uint16_t numBlockingConnections=1)
static const char * ToParam(ChannelType channelType)
const char * getStreamName(uint16_t index=0) const
constexpr bool IsConsumer(ChannelRole role)