iceoryx_doc  1.0.1
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
iox::rp::BaseRelativePointer Class Reference

pointer class to use when pointer and pointee are located in different shared memory segments We can have the following scenario: Pointer p is stored in segment S1 and points to object X of type T in segment S2. More...

#include <base_relative_pointer.hpp>

Inheritance diagram for iox::rp::BaseRelativePointer:
Inheritance graph
[legend]

Public Types

using id_t = uint64_t
 
using ptr_t = void *
 
using const_ptr_t = const void *const
 
using offset_t = std::uintptr_t
 

Public Member Functions

 BaseRelativePointer (ptr_t ptr, id_t id) noexcept
 constructs a BaseRelativePointer pointing to the same pointee as ptr in a segment identified by id More...
 
 BaseRelativePointer (offset_t offset, id_t id) noexcept
 constructs a BaseRelativePointer from a given offset and segment id More...
 
 BaseRelativePointer (ptr_t ptr=nullptr) noexcept
 constructs a BaseRelativePointer pointing to the same pointer as ptr More...
 
 BaseRelativePointer (const BaseRelativePointer &other) noexcept
 copy constructor More...
 
 BaseRelativePointer (BaseRelativePointer &&other) noexcept
 move constructor More...
 
BaseRelativePointeroperator= (const BaseRelativePointer &other) noexcept
 copy assignment More...
 
BaseRelativePointeroperator= (void *ptr) noexcept
 assigns the BaseRelativePointer to point to the same pointee as ptr More...
 
BaseRelativePointeroperator= (BaseRelativePointer &&other) noexcept
 move assignment More...
 
ptr_t get () const noexcept
 access to the underlying object More...
 
id_t getId () const noexcept
 returns the id which identifies the segment More...
 
offset_t getOffset () const noexcept
 returns the offset More...
 
ptr_t getBasePtr () const noexcept
 get the base pointer associated with this' id More...
 
offset_t computeOffset (ptr_t ptr) const noexcept
 get the offset from the start address of the segment and ptr More...
 
ptr_t computeRawPtr () const noexcept
 get the pointer from stored id and offset More...
 

Static Public Member Functions

static id_t registerPtr (const ptr_t ptr, uint64_t size=0U) noexcept
 registers a memory segment at ptr with size of a new id More...
 
static bool registerPtr (const id_t id, const ptr_t ptr, uint64_t size=0U) noexcept
 tries to register a memory segment with a given size starting at ptr to a given id More...
 
static bool unregisterPtr (const id_t id) noexcept
 unregisters ptr with given id More...
 
static ptr_t getBasePtr (const id_t id) noexcept
 get the base ptr associated with the given id More...
 
static void unregisterAll () noexcept
 unregisters all ptr id pairs (leads to initial state)
 
static offset_t getOffset (const id_t id, const_ptr_t ptr) noexcept
 get the offset from id and ptr More...
 
static ptr_t getPtr (const id_t id, const offset_t offset) noexcept
 get the pointer from id and offset ("inverse" to getOffset) More...
 
static id_t searchId (ptr_t ptr) noexcept
 get the id for a given ptr More...
 
static bool isValid (id_t id) noexcept
 checks if given id is valid More...
 
static PointerRepository< id_t, ptr_t > & getRepository () noexcept
 returns the pointer repository More...
 

Static Public Attributes

static constexpr id_t NULL_POINTER_ID = std::numeric_limits<id_t>::max()
 
static constexpr offset_t NULL_POINTER_OFFSET = std::numeric_limits<offset_t>::max()
 

Protected Attributes

id_t m_id {NULL_POINTER_ID}
 
offset_t m_offset {NULL_POINTER_OFFSET}
 

Detailed Description

pointer class to use when pointer and pointee are located in different shared memory segments We can have the following scenario: Pointer p is stored in segment S1 and points to object X of type T in segment S2.

Shared Memory S1: p S2: X |___________________^ App1 a1 b1 c1 d1 App2 a2 b2 c2 d2

Now it is no longer true in general that both segments will be offset by the same difference in App2 and therefore relocatable pointers are no longer sufficient. Relative pointers solve this problem by incorporating the information from where they need to measure differences (i.e. relative to the given address). This requires an additional registration mechanism to be used by all applications where the start addresses and the size of all segments to be used are registered. Since these start address may differ between applications, each segment is identified by a unique id, which can be provided upon registration by the first application. In the figure, this means that the starting addresses of both segments(a1, a2 and c1, c2) would have to be registered in both applications. Once this registration is done, relative pointers can be constructed from raw pointers similar to relocatable pointers.

Note
It should be noted that relocating a memory segment will invalidate relative pointers, i.e. relative pointers are NOT relocatable. This is because the registration mechanism cannot be automatically informed about the copy of a whole segment, such a segment would have to be registered on its own (and the original segment deregistered).

Constructor & Destructor Documentation

◆ BaseRelativePointer() [1/5]

iox::rp::BaseRelativePointer::BaseRelativePointer ( ptr_t  ptr,
id_t  id 
)
noexcept

constructs a BaseRelativePointer pointing to the same pointee as ptr in a segment identified by id

Parameters
[in]ptrthe pointer whose pointee shall be the same for this
[in]idis the unique id of the segment

◆ BaseRelativePointer() [2/5]

iox::rp::BaseRelativePointer::BaseRelativePointer ( offset_t  offset,
id_t  id 
)
noexcept

constructs a BaseRelativePointer from a given offset and segment id

Parameters
[in]offsetis the offset
[in]idis the unique id of the segment

◆ BaseRelativePointer() [3/5]

iox::rp::BaseRelativePointer::BaseRelativePointer ( ptr_t  ptr = nullptr)
noexcept

constructs a BaseRelativePointer pointing to the same pointer as ptr

Parameters
[in]ptrthe pointer whose pointee shall be the same for this

◆ BaseRelativePointer() [4/5]

iox::rp::BaseRelativePointer::BaseRelativePointer ( const BaseRelativePointer other)
noexcept

copy constructor

Parameters
[in]otheris the copy origin

◆ BaseRelativePointer() [5/5]

iox::rp::BaseRelativePointer::BaseRelativePointer ( BaseRelativePointer &&  other)
noexcept

move constructor

Parameters
[in]otheris the move origin

Member Function Documentation

◆ computeOffset()

offset_t iox::rp::BaseRelativePointer::computeOffset ( ptr_t  ptr) const
noexcept

get the offset from the start address of the segment and ptr

Parameters
[in]ptris the pointer whose offset should be calculated
Returns
offset

◆ computeRawPtr()

ptr_t iox::rp::BaseRelativePointer::computeRawPtr ( ) const
noexcept

get the pointer from stored id and offset

Returns
the pointer for stored id and offset

◆ get()

ptr_t iox::rp::BaseRelativePointer::get ( ) const
noexcept

access to the underlying object

Returns
a pointer to the underlying object

◆ getBasePtr() [1/2]

ptr_t iox::rp::BaseRelativePointer::getBasePtr ( ) const
noexcept

get the base pointer associated with this' id

Returns
the registered base pointer

◆ getBasePtr() [2/2]

static ptr_t iox::rp::BaseRelativePointer::getBasePtr ( const id_t  id)
staticnoexcept

get the base ptr associated with the given id

Parameters
[in]idis the id of the segment
Returns
ptr registered at the given id, nullptr if none was registered

◆ getId()

id_t iox::rp::BaseRelativePointer::getId ( ) const
noexcept

returns the id which identifies the segment

Returns
the id which identifies the segment

◆ getOffset() [1/2]

offset_t iox::rp::BaseRelativePointer::getOffset ( ) const
noexcept

returns the offset

Returns
the offset

◆ getOffset() [2/2]

static offset_t iox::rp::BaseRelativePointer::getOffset ( const id_t  id,
const_ptr_t  ptr 
)
staticnoexcept

get the offset from id and ptr

Parameters
[in]idis the id of the segment and is used to get the base pointer
[in]ptris the pointer whose offset should be calculated
Returns
offset

◆ getPtr()

static ptr_t iox::rp::BaseRelativePointer::getPtr ( const id_t  id,
const offset_t  offset 
)
staticnoexcept

get the pointer from id and offset ("inverse" to getOffset)

Parameters
[in]idis the id of the segment and is used to get the base pointer
[in]offsetis the offset for which the pointer should be calculated
Returns
the pointer from id and offset

◆ getRepository()

static PointerRepository<id_t, ptr_t>& iox::rp::BaseRelativePointer::getRepository ( )
staticnoexcept

returns the pointer repository

Returns
the pointer repository

◆ isValid()

static bool iox::rp::BaseRelativePointer::isValid ( id_t  id)
staticnoexcept

checks if given id is valid

Parameters
[in]idis the id to be checked
Returns
true if the given id is valid, otherwise false

◆ operator=() [1/3]

BaseRelativePointer& iox::rp::BaseRelativePointer::operator= ( BaseRelativePointer &&  other)
noexcept

move assignment

Parameters
[in]otheris the move origin
Returns
a reference to self

◆ operator=() [2/3]

BaseRelativePointer& iox::rp::BaseRelativePointer::operator= ( const BaseRelativePointer other)
noexcept

copy assignment

Parameters
[in]otheris the copy origin
Returns
a reference to self

◆ operator=() [3/3]

BaseRelativePointer& iox::rp::BaseRelativePointer::operator= ( void *  ptr)
noexcept

assigns the BaseRelativePointer to point to the same pointee as ptr

Parameters
[in]ptrthe pointer whose pointee shall be the same for this
Returns
reference to self

◆ registerPtr() [1/2]

static bool iox::rp::BaseRelativePointer::registerPtr ( const id_t  id,
const ptr_t  ptr,
uint64_t  size = 0U 
)
staticnoexcept

tries to register a memory segment with a given size starting at ptr to a given id

Parameters
[in]idis the id of the segment
[in]ptrstarting address of the segment to be registered
[in]sizeis the size of the segment
Returns
true if successful (id not occupied), false otherwise

◆ registerPtr() [2/2]

static id_t iox::rp::BaseRelativePointer::registerPtr ( const ptr_t  ptr,
uint64_t  size = 0U 
)
staticnoexcept

registers a memory segment at ptr with size of a new id

Parameters
[in]ptrstarting address of the segment to be registered
[in]sizeis the size of the segment
Returns
id it was registered to

◆ searchId()

static id_t iox::rp::BaseRelativePointer::searchId ( ptr_t  ptr)
staticnoexcept

get the id for a given ptr

Parameters
[in]ptrthe pointer whose corresponding id is searched for
Returns
id the pointer was registered to

◆ unregisterPtr()

static bool iox::rp::BaseRelativePointer::unregisterPtr ( const id_t  id)
staticnoexcept

unregisters ptr with given id

Parameters
[in]idis the id of the segment
Returns
true if successful (ptr was registered with this id before), false otherwise

The documentation for this class was generated from the following file: