-
Notifications
You must be signed in to change notification settings - Fork 89
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
How to use callback functions when calling celix service #775
Comments
Interesting question. Yes in many cases I think this can be solved as you mention, but this does mean that the service are heavily intertwined. IMO the C language is missing some async concepts to do this nicely. For C++ std::future could be used and the OSGi spec has also something for this OSGi Promise. ASF Celix also has a implementation for Promises, but only for C++. Let assume there was also C implementation for this. The instead of a callback the provide api could look something like:
Maybe with promise api like:
And a separate promise api for a The provider could do something like:
And the consumer snippet:
This also means that the provider is not aware how the consumer will handle the (async) result. Important concept would be that both the provided and consumer can drop the promise/deferred and it should clean itself up. But maybe something already exists for this. Because although I like the Promise concept, I am not sure if we need a C implementation for this. Also this concept then needs to be directly supported in remote services (first class citizen) so that the remote service admins can generated endpoint/proxies that can handle promise and deferred objects. For Java this is also mentioned in the remote service admin spec: https://docs.osgi.org/specification/osgi.cmpn/8.1.0/service.remoteservices.html#d0e1444 |
In some service usage scenarios, the result may not be returned immediately after the service call is completed, it may be returned through a callback function at some time after the service call is completed. How should we use callback functions in celix services (it includes remote services and local services)?
In my opinion, it is unsafe to design function pointers directly in the service method parameters, because the service provider may have been destroyed after the service call is completed. At this time, if the callback function is called again, problems will occur. In addition, designing callback function pointers in the service method may make the implementation of RSA complex.
Therefore, I think the callback function can be designed as a celix service. If a service method needs a callback function, the service method's input parameters should include the service identifier of the callback function (Maybe the service identifier is a string composed of
framework uuid
andservice id
). When calling the service method, the service caller needs to register the callback function service first, and then pass the callback function service identifier to the service method. The service provider can invoke the callback function through the callback function service. The example is as follows:@pnoltes
Do you have any suggestions for the design of callback function?
The text was updated successfully, but these errors were encountered: