Skip to content
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

Open
wesselj1 opened this issue May 21, 2015 · 4 comments
Open

Quick question about talking with native code #66

wesselj1 opened this issue May 21, 2015 · 4 comments

Comments

@wesselj1
Copy link

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?

@skabbes
Copy link
Contributor

skabbes commented May 22, 2015

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.

@wesselj1
Copy link
Author

wesselj1 commented Jul 8, 2015

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.

@skabbes
Copy link
Contributor

skabbes commented Jul 11, 2015

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.

EventBus = interface +o +j {
   publish(message: string);
}

Then in your code, you'd need to do one of the following:

#ifdef __android__
EventBus * e = new JavaEventBus();
#endif
#ifdef __APPLE__
EventBus * e = new ObjcEventBus();
#endif

Or, you could simply pass the EventBus * as a parameter to your application (which is what djinni forces you to do). Does that make more sense?

@wesselj1
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants