-
Notifications
You must be signed in to change notification settings - Fork 373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refine modern pub/sub API #408
Comments
Original response by @elBoberido in #360 (comment) This is a tough question and boils down to the raw pointer access like you pointed out. I'm not sure how to fix this, except making it harder to get to a non-owning raw pointer. e.g. by replacing The
With this, we could get rid of the |
Original response by @elfenpiff in #360 (comment) I would clearly state in the docu: Please use the typed API but if you are an expert, you know what you are doing and you want to get your hands dirty then use the untyped one. With this statement and the assumption that the users know what they are doing we could get rid of the untypedSubscriber->take().and_then([&](const void * payload){
auto header = freeFunctionToAcquireHeaderPtr(payload);
doStuff(payload, header);
untypedSubscriber->releaseRawSample(payload);
}); You could also pack this Maybe it is also then useful to not recommend the functional approach and stick to the classic approach and use it like: auto payload = untypedSubscriber->take();
if ( !payload.has_value() ) {
doStuff(payload.value()); // acquires void *
untypedSubscriber->releaseRawSample(*payload);
} |
From a different PR posted by @elBoberido in #403 (comment) @ithier what do you think about adjusting the
then we could have
|
Thanks @elBoberido for creating this follow up issue |
Prasanna have a PR with the adress sanitizer enabled and it's throwing an interesting error when using the publisher
This is giving the following error: According to the code the
So we have two places now with placement new and it seems that the one in |
How about discouraging the usage of placement new in user code. We could just have a Similarly
would become
|
posted by @MatthiasKillat in #421 comment Actually, it is not quite as easy with type inference in play like this due to overloads of and_then I think... I will look at the reason, but the call *sample.get() will not work anymore with auto since it is now detected to be an optional of sample, which is not what it should be (incorrect monadic behavior in my book). Now, changing the call to account for this seems to not play nicely with auto and it breaks. Will need a closer look. |
Here a list of things I stumbled upon. We have to discuss what needs to be done an what maybe not
|
@elBoberido I agree, emplacement new on the user side is a bad idea. Especially if there is already something constructed at this memory location (which would need to have a destructor called manually). My reasoning is that as a user I have a harder time to know whether the pointer points to just memory (even if typed) or to an already constructed object. With references I assume it is a valid sample. You can always circumvent this and mislead the user and have dangling references and, but this is bad style. But we need something with at least the void pointer for interaction with low level APIs. Accessing the data via the Anyway, a true monadic Everything else belongs to different cases. This is just a rough sketch of how a monadic interface should probably work if we want such an interface. We are also missing something convenient to get all available samples. Currently we need a loop for that, but I propose some function such as An important question is whether the data should be copied into the container. Ideally ownership is passed somehow, without involving the copy. The handler can specify this on its own. This has the advantage Just a rough sketch and it is hard to say what is best, but the current interface can be improved. To get a better feel for it I have to use it more. |
…ne parser Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
…ne parser Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
…ne parser Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Mathias Kraus <mathias.kraus@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Matthias Killat <matthias.killat@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
…n-to-1-0-c-api Iox eclipse-iceoryx#408 transition to 1 0 c api
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
…nto iox-eclipse-iceoryx#408-offer-and-subscribe-on-create
…tMiddlewareSubscriber Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
…nto iox-eclipse-iceoryx#408-offer-and-subscribe-on-create
Signed-off-by: Michael Poehnl <michael.poehnl@apex.ai>
…-subscribe-on-create Iox eclipse-iceoryx#408 offer and subscribe on create
Originally posted by @budrus in #360 (comment)
How do we prevent this? With the old API people were more aware that they should not copy pointers that are coming from the middleware. In ara::com it's a unique ptr to make this even harder. I guess our Sample is also just an advanced unique_ptr but when I look at this code I fear that people think they must call
sample.get()
to be able to work with the payload. But in factget()
is the most dangerous method.We need
get
for frameworks where you get a Sample from the iceoryx API and have to pass e.g. a void* to the next layer (like in ROS). Then this layer has to return the pointer and the sample must be released with the iceoryx API.How would this look like? @elBoberido @ithier
sample.get()
sample.release()
Shoud we make an example for this? This is a use case a lot people have. Would it be better to have a
release()
that releases the ownersip but additionally returns the pointer like in the STL and to remove the get() method? Having a get() that gives you a pointer to a shared memory chunk which is released when the Sample goes out of scope is a dangerous thing . The STL unique_ptr also has it but maybe people are more aware thereHere in iceperf we want to copy the payload. How can we do something like
auto receivedSample = *(static_cast<const PerfTopic*>(receivedChunk));
?With the
Sample
class, theget
method and the fact that the subscriber has noreleaseChunk
method any more, the lifetime and ownership question has some complexity. This must be well documented in the new API docu @elfenpiff @FerdinandSpitzschnueffler @MatthiasKillatTo-do:
PublisherOptions
and enable it as default (will close example multi publisher, subscriber -> missing some data #575)Sample
from untyped API and make it feel similar to the C-API (releaseChunk called by user)expected
but instead anoptional
and do the error handling for the user under the hood (fail fast & hard)Rename CaPro strings and add terminology table in overview.mddefine a payload_t or use void*?The text was updated successfully, but these errors were encountered: