Compute Graph Framework SDK Reference  5.8
ChannelPacketImpl.hpp
Go to the documentation of this file.
1
2//
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_PACKET_HPP_
32#define DW_FRAMEWORK_CHANNEL_PACKET_HPP_
33
35
36namespace dw
37{
38namespace framework
39{
40
43{
44public:
45 uint8_t* getBuffer() override
46 {
47 return m_buffer.get();
48 }
49
50 size_t getBufferSize() override
51 {
52 return m_bufferSize;
53 }
54
55 size_t serialize() override
56 {
58 return m_bufferSize;
59 }
60
61 // Serializes the frame before transmission
62 virtual void serializeImpl()
63 {
64 throw Exception(DW_NOT_SUPPORTED, "ChannelPacketBase: serialize: not implemented");
65 }
66
67 // Deserializes the frame before transmission
68 void deserialize(size_t) override
69 {
70 throw Exception(DW_NOT_SUPPORTED, "ChannelPacketBase: deserialize: not implemented");
71 }
72
73protected:
75
76 ChannelSocketPacketBase(size_t bufferSize)
77 {
78 initBuffer(bufferSize);
79 }
80
81 void initBuffer(size_t bufferSize)
82 {
83 m_bufferSize = bufferSize;
84
85 // TODO (ajayawardane): the extra uint32_t is to ensure there is enough room
86 // to insert sync count after buffer. Figure out a better way to handle this
87 m_buffer = std::make_unique<uint8_t[]>(m_bufferSize + sizeof(uint32_t));
88
89 if (m_buffer == nullptr)
90 {
91 throw Exception(DW_BAD_ALLOC, "ChannelPacketBase: initBuffer: cannot allocate memory");
92 }
93 }
94
95 // packet should have a buffer of type uint8_t
96 // for serialization and de-serialization
97 size_t m_bufferSize = 0;
98 std::unique_ptr<uint8_t[]> m_buffer;
99};
100
102{
103public:
105 {
106 if (!m_frame)
107 {
108 throw Exception(DW_INTERNAL_ERROR, "ChannelPacketBase: getGenericData: not set by implementation.");
109 }
110 return m_frame.value();
111 }
112
114
115protected:
116 dw::core::Optional<GenericData> m_frame;
117};
118
119template <typename T>
121{
122 virtual void notImplemented() = 0;
123};
124
125} // namespace framework
126} // namespace dw
127
128#endif // DW_FRAMEWORK_CHANNEL_PACKET_HPP_
GenericData getGenericData() override
dw::core::Optional< GenericData > m_frame
std::unique_ptr< uint8_t[]> m_buffer
Definition: Exception.hpp:47