Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-os-example-mros2 example-mbed-mros2-sub-pose example-mbed-mros2-pub-twist example-mbed-mros2-mturtle-teleop
PBufWrapper.h
00001 /* 00002 The MIT License 00003 Copyright (c) 2019 Lehrstuhl Informatik 11 - RWTH Aachen University 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 The above copyright notice and this permission notice shall be included in 00011 all copies or substantial portions of the Software. 00012 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00013 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00014 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00015 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00016 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00018 THE SOFTWARE 00019 00020 This file is part of embeddedRTPS. 00021 00022 Author: i11 - Embedded Software, RWTH Aachen University 00023 */ 00024 00025 #ifndef RTPS_PBUFWRAPPER_H 00026 #define RTPS_PBUFWRAPPER_H 00027 00028 #include "lwip/pbuf.h" 00029 #include "rtps/common/types.h" 00030 00031 namespace rtps { 00032 00033 struct PBufWrapper { 00034 00035 pbuf *firstElement = nullptr; 00036 00037 PBufWrapper() = default; 00038 explicit PBufWrapper(pbuf *bufferToWrap); 00039 explicit PBufWrapper(DataSize_t length); 00040 00041 // Shallow Copy. No copying of the underlying pbuf. Just another reference 00042 // like a shared pointer. 00043 PBufWrapper(const PBufWrapper &other); 00044 PBufWrapper &operator=(const PBufWrapper &other); 00045 00046 PBufWrapper(PBufWrapper &&other) noexcept; 00047 PBufWrapper &operator=(PBufWrapper &&other) noexcept; 00048 00049 ~PBufWrapper(); 00050 00051 PBufWrapper deepCopy() const; 00052 00053 bool isValid() const; 00054 00055 bool append(const uint8_t *data, DataSize_t length); 00056 00057 /// Note that unused reserved memory is now part of the wrapper. New calls to 00058 /// append(uint8_t*[...]) will continue behind the appended wrapper 00059 void append(PBufWrapper &&other); 00060 00061 bool reserve(DataSize_t length); 00062 00063 /// After calling this function, data is added starting from the beginning 00064 /// again. It does not revert reserve. 00065 void reset(); 00066 00067 DataSize_t spaceLeft() const; 00068 DataSize_t spaceUsed() const; 00069 00070 private: 00071 constexpr static pbuf_layer m_layer = PBUF_TRANSPORT; 00072 constexpr static pbuf_type m_type = PBUF_POOL; 00073 00074 DataSize_t m_freeSpace = 0; 00075 00076 bool increaseSizeBy(uint16_t length); 00077 00078 void copySimpleMembersAndResetBuffer(const PBufWrapper &other); 00079 }; 00080 00081 } // namespace rtps 00082 00083 #endif // RTPS_PBUFWRAPPER_H
Generated on Sun Jul 31 2022 04:49:47 by
1.7.2