-
Notifications
You must be signed in to change notification settings - Fork 145
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
Quick question about talking with native code #66
Comments
First of all, what are you trying to accomplish? Maybe I can help. Essentially for the same c++ code to interact with Java and ObjC code with no changes, you'll need some sort of polymorphism. Now, I suppose you don't necessarily need runtime polymorphism, you could accomplish it at compile time, but djinni doesn't support this (its kind of a weird thing to support anyway). So, given that we need polymorphism - we have to interact with the host-language code over pure virtual interfaces that get implemented in either Java or Objc. So, you'll need a kind of dependency injection pattern (what you're calling callbacks) to make that work. |
Hey @skabbes, Sorry I never got back to reply to this. I moved on to another part of the project that I am working on so I do not know that I will be getting back to exploring this. Essentially though, I was wanting to setup something similar to Square's Otto. So we would need to be able to call from the C++ code to other parts (possibly multiple) of the native code. I think this would be a useful thing for mx3, but I don't know if anyone else needs this or if there is another method to this issue that I am missing, such as some polymorphic approach as you had mentioned. Honestly, I do not see how to use polymorphism to tie the c++ code to the Java or ObjC. That might just be my own misunderstanding of something. |
Well, otto seems to only be Java-based. So, it would kind of only be single platform (therefore polymorphism wouldn't really get you anything). However, if you wanted an "event bus" like thing. You'd need to define that interface, and then implement it on android (with otto) and on iOS with something else.
Then in your code, you'd need to do one of the following:
Or, you could simply pass the |
Yes, Otto is for Java only. What you've explained makes sense, but I would actually be wanting to do the publishing of events and routing to the appropriate subscribers within the C++ code. I was basically looking to not use Otto but make some a cross-platform solution to use in place of Otto since it is Java only. However, due to some other dependencies the project has gone to strictly native code for iOS and Android. |
So the more I've become familiar with the example the only way I've seen that the C++ code talks back to the native code is with callbacks. Is there another way to talk from the C++ side of the code to the native side? Or do you just have to use the callback pattern that is being used to go from C++ to native?
The text was updated successfully, but these errors were encountered: