eclipse-iceoryx / iceoryx

Eclipse iceoryx™ - true zero-copy inter-process-communication
https://iceoryx.io
Apache License 2.0
1.57k stars 373 forks source link

Suport for register_availability_handler similar to GENIVI VSOME/IP #528

Open Indra5196 opened 3 years ago

Indra5196 commented 3 years ago

In order to fully support ara::com with iceoryx, we need a method like register_availability_handler similar to GENIVI VSOME/IP, so that actions could be performed based on the availability of publishers

Wanted to know some things here: Is it possible to have such functionality within iceoryx? If yes, can you give me a brief Idea how? Is it practical to have it?

elfenpiff commented 3 years ago

@Indra5196 I am currently working on the issue #350 . When the event driven callbacks are implemented (in the next weeks) you should be able to write code like:

// here you create a ActiveCallbackSet, an object with an underlying thread which will call all attached event driven callbacks when the event occurs.
ActiveCallbackSet myCallbackSet;

void onSampleReceived(Subscriber * subscriber) {
  subscriber.take()
    .and_then([](auto & sample){ std::cout << "received sample: " << sample->myValue << std::endl; }
    .or_else([](auto & error) { /* perform some error handling */ };
}

myCallbackSet.attachEvent(subscriber, SubscriberEvent::HAS_SAMPLE_RECEIVED, onSampleReceived);

You can read the current design draft here: https://github.com/eclipse-iceoryx/iceoryx/blob/master/doc/design/draft/eventdriven-callbacks.md where you can find more usage examples.

Is this what you would like to have? Register a callback for events like "a new sample received", "is subscribed", "some service is available".

Additionally, if you have some remarks or suggestion on creating a comfortable and easy to use API they are more then welcome. Or if you see some use case which you cannot implement with this approach then please let me know - then I will consider it!

Indra5196 commented 3 years ago

@elfenpiff Yes, I was looking to register callbacks if some service is available

Currently, the subscriber application, using GENIVI VSOME/IP, calls a method "StartFindService" along with a callback method. Once a service is available, Callback is invoked and the corresponding proxy (subscriber) object is created.

I know this is not needed in case of Iceoryx, but its required for ara::com compatibility

elfenpiff commented 3 years ago

@Indra5196 then I will ping you as soon as the feature is merged!

budrus commented 3 years ago

@elfenpiff @Indra5196 . This half of the way, the other half would be #415., When we have a built-in topic that gets updated when there is a change in the service registry and you combine this with #350 you could do the following:

  1. have a callback that is invoked when there is a new sample for your service registry subscriber
  2. in this callback evaluate a data structure that is updated with StartFindService / StopFindService
  3. Then call the user callbacks according to the result of the evaluation

This is my plan so far. #350 is in progress #415 is today a maybe candidate for the 1.0.0 release...

Indra5196 commented 3 years ago

Hi @elfenpiff @budrus, One thing crossed my mind,

Why Set/UnsetReceiveHandler was removed in the later versions? Is there a new API which provides a similar functionality?

elfenpiff commented 3 years ago

@Indra5196 we are currently working on that new API and it will be available in iceoryx v1.0.

budrus commented 2 years ago

@mossmaurice I think we can close this if we have #415 and an example that shows how to combine this with a waitset/listener. Assigning this to you as you are working on #415