Compute Graph Framework SDK Reference  5.16
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-2023 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
36#include <dwshared/dwfoundation/dw/core/base/ExceptionWithStatus.hpp>
37#include <dwshared/dwfoundation/dw/core/safety/Safety.hpp>
38
39namespace dw
40{
41namespace framework
42{
43
45// coverity[autosar_cpp14_m3_4_1_violation]
47{
48public:
49 uint8_t* getBuffer() override
50 {
51 return m_buffer.get();
52 }
53
54 size_t getBufferSize() override
55 {
56 return m_bufferSize;
57 }
58
59 // coverity[autosar_cpp14_a2_10_5_violation] RFD Pending: TID-2053
60 size_t serialize() override
61 {
63 return m_bufferSize;
64 }
65
66 // Serializes the frame before transmission
67 virtual void serializeImpl()
68 {
69 throw ExceptionWithStatus(DW_NOT_SUPPORTED, "ChannelPacketBase: serialize: not implemented");
70 }
71
72 // Deserializes the frame before transmission
73 void deserialize(size_t) override
74 {
75 throw ExceptionWithStatus(DW_NOT_SUPPORTED, "ChannelPacketBase: deserialize: not implemented");
76 }
77
78protected:
80
81 explicit ChannelSocketPacketBase(size_t bufferSize)
82 : IChannelPacket::SocketCallbacks()
83 {
84 initBuffer(bufferSize);
85 }
86
87 void initBuffer(size_t bufferSize)
88 {
89 m_bufferSize = bufferSize;
90
91 // TODO (ajayawardane): the extra uint32_t is to ensure there is enough room
92 // to insert sync count after buffer. Figure out a better way to handle this
93 // the buffer size isn't close to the maximum value of size_t, hence no risk of overflow
94 m_buffer = std::make_unique<uint8_t[]>(dw::core::safeAdd(m_bufferSize, sizeof(ChannelMetadata)).value());
95
96 if (nullptr == m_buffer)
97 {
98 throw ExceptionWithStatus(DW_BAD_ALLOC, "ChannelPacketBase: initBuffer: cannot allocate memory");
99 }
100 }
101
102 // packet should have a buffer of type uint8_t
103 // for serialization and de-serialization
104 size_t m_bufferSize{0U};
105 std::unique_ptr<uint8_t[]> m_buffer;
106};
107
108// coverity[autosar_cpp14_m3_4_1_violation]
109// coverity[autosar_cpp14_a10_1_1_violation]
111{
112public:
114 {
115 if (!m_frame.has_value())
116 {
117 throw ExceptionWithStatus(DW_INTERNAL_ERROR, "ChannelPacketBase: getGenericData: not set by implementation.");
118 }
119 return m_frame.value();
120 }
121
123
124protected:
125 dw::core::Optional<GenericData> m_frame;
126};
127
128// coverity[autosar_cpp14_a14_1_1_violation]
129template <typename T>
131{
132 virtual void notImplemented() = 0;
133};
134
135} // namespace framework
136} // namespace dw
137
138#endif // DW_FRAMEWORK_CHANNEL_PACKET_HPP_
GenericData getGenericData() override
dw::core::Optional< GenericData > m_frame
Definition: Buffer.hpp:40