-
Notifications
You must be signed in to change notification settings - Fork 488
Proxy interface generation #337
Comments
I don't think I understand what you're proposing to generate well enough to have a clear opinion yet. A "proxy interface" can mean a lot of things, and indeed both of those words have existing meanings in Djinni which I'd suggest you not overload. My thoughts on your questions at a high level:
|
"Proxy interface" was a poor choice of words on my part. Allow me to explain. For each page in my mobile app, there is typically a Djinni interface for the ViewController/Activity and a Djinni interface for the C++ view model. The ViewController/Activity that implements the one interface makes calls to the view model that implements the other interface and vice-versa. The view model's interface includes a static "create" function, and it is the ViewController/Activity that creates an instance of the view model and has ownership of it. Where possible, I make it so that the view model doesn't keep a permanent reference to the view. The view model's methods just take the view as an argument, the way they would if the view model were written in a purely functional language. Doing things that way is not always easy; sometimes it makes more sense to give the view model a permanent reference to the ViewController/Activity. In that case, I have to place a proxy implementation of the view's interface in between the view model and the ViewController/Activity in order to break a reference cycle, as the ViewController/Activity owns the view model. This is an abbreviated example of one of my view interfaces and its Java proxy implementation.
The class above and its ObjC counterpart are what I want to generate. It's certainly not hard to implement, but it's violating the DRY principle to implement it by hand, and it's a real bother to have to write or update this boilerplate code in two languages every time I create or edit a Djinni interface that has proxy implementations. I'm not sure how useful this is to others, although mknejp said a while back that he did things this way. If I had all the time in the world, I think that I would add to Djinni generic support for plugins, and I would create a separate plugin to generate this bit of code. I don't think I'll have time for that though. |
Interesting. So it sounds like your use case for this "proxy" is specific to a particular MVVM pattern, but what you need Djinni to generate isn't. If I'm understanding it correctly, the general pattern is for interface X, you want to generate a concrete class Y which implements the interface X, and holds a weak reference to another X to which it forwards all methods. It sounds like you'd want Djinni to generate Y as a concrete class in the same languages as X can be implemented (so Java and ObjC in the case of your That seems like a generic enough feature to fit in Djinni. The plug-in suggestion you brought up would be even better as a general mechanism, but I could see this feature as a built-in option. As described, I think There might also be an approach to this which would be built into the proxy layer, perhaps operating off of strong/weak annotations on args/returns in the IDL. Even better would be finding some way to make plain weak_ptr work across languages. I think either of those are probably too much of a stretch unless someone is excited and has an idea of how to accomplish them. |
I'll try to get around to this over the holiday break. |
In order to break reference cycles between view and view model classes, I regularly create a proxy view class that holds a weak reference to the actual view, as described by mknejp in #110. I'm working on a change to generate that proxy class automatically. The change is complete aside from the logic to determine which interfaces Djinni generates a proxy for. I have a couple of questions:
+' expected but
{' found." That said, I wasn't crazy about using "+w" to indicate that I wanted a proxy anyways.This is what I have so far: csimmons0/djinni@develop...csimmons0:weak-proxy
The text was updated successfully, but these errors were encountered: