GNOME Bugzilla – Bug 107658
Impossible to aggregate a pure Python CORBA object to a BonoboObject.
Last modified: 2004-12-22 21:47:04 UTC
See the test program. I get the following output: --------------------------- Traceback (most recent call last):
+ Trace 34544
control.add_interface(myobj)
not MyObject --------------------------- I think the test program plus error message are self explanatory. What this means is that I cannot define and IDL interface, implement it in python and then aggregate the python object to an exising C object. I don't know how to solve this particular problem, but the solution may lie in a different implementation of bonobo.Object.add_interface. I'll investigate further, but any help is appreciated!
Created attachment 14794 [details] test program
So we need to be able to create a bonobo.Object (as opposed to a Bonobo.Unknown ...) for the custom interface. We will need to find out how best to do that. I hope that doing so isn't _too_ tied to creating GObject subclasses in C (it does weird things like putting epv's into the GObject class structs, and then constructing the vepv from them ...).
I'm going to try to create a bonobo.Unknown object, which serves as a delegate to a PortableServer.Servant (the constructor expects a servant is input). bonobo.Unknown will implement IDL:Bonobo/Unknown:1.0 -- queryInterface(), ref(), unref() -- and also add_interface(). bonobo.Object.add_interface will be overriden so that it detects when the new interface being added is a bonobo.Unknown, in which case a special bonobo API will be used to aggregate the object reference. More details will follow when (if) I get this implemented.
Created attachment 15548 [details] [review] preliminary, untested patch; needs more work, probably.
The most pythonic way to handle this is probably to get add_interface() to take either a bonobo.Object or CORBA.Object as an argument. In the CORBA.Object case, it would call bonobo_object_add_foreign_interface() (once it has been added).
I'm thinking it is not enough. We have to provide an implementation of the Bonobo::Unknown interface, and make sure the foreign interface implements that interface. Two things are required: 1. Check that CORBA_Object_is_a(obj, "IDL:Bonobo/Unknown:1.0", &ev); 2. Provide a python base class that implements that interface, by having the methods ref, unref, queryInterface, that call respectively bonobo_object_ref, bonobo_object_unref, bonobo_object_query_local_interface, with the BonoboForeignObject as argument. I am considering naming that class bonobo.Unknown. Considering these requirements, I'm thinking that bonobo.Object.add_interface should accept either bonobo.Object or bonobo.Unknown as argument. Does that sound reasonable?
I am still not quite sure why this is necessary. It is a given that the interface you are implementing in Python will be derived from Bonobo.Unknown. That implementation could simply proxy those method calls onto the equivalent methods of one of the other aggregated interfaces (one with a C impl). Have I missed something?
Yes, the programmer could do that, but it is better to create a class that does that automatically, and programmers would derive from that class. In C, when you create a BonoboObject you don't have to worry about proxying interface methods or anything like that; it happens automatically. In python, it should be at least as simple as that.
Now that BonoboForeignObject is in libbonobo, the python part becomes very simple. The following patch takes James' and Johan's suggestion of a "mixin" class, i.e. providing a standard BonoboUnknow implementation through multiple inheritance.
Created attachment 15755 [details] [review] custom bonobo object support patch
I'm attaching a new version of the patch, that should conditionally compile with any version libbonobo. I haven't tested with 2.2.x, but I'm confident it would compile. However, this new patch depends on the codegen changes in #113638.
Created attachment 16797 [details] [review] Foreign object support, with conditional compiling.
I'm interesting to develop an application using this stuff. In fact, I've already started testing, and it seems to be working fine, so far. When can I commit this? ;)
Created attachment 19471 [details] [review] new version of patch, so it doesn't get lost
The patch works well but if you add the line: print listener.corba_objref().queryInterface("IDL:Bonobo/Unknown:1.0") at the end of the unknown.py file, you'll notice that it returns <CORBA.Object 'IDL:Bonobo/PersistStream:1.0' at 0xXXXXXXXX> Shouldn't it bee 'IDL:Bonobo/Unknown:1.0' ?
Well, Bonobo::PersistStream is a subclass of Bonobo::Unknown, so the result is still correct.
James said it was OK to commit, and so I did, but with some changes ;) The following patch shows exactly what I have committed. The example program highlights a BonoboObject/GObject reference counting problem, which is a different problem altogether and is unrelated to this patch. I'll submit a bug report about it too.
Created attachment 21803 [details] [review] Code that is now in CVS
Since gjc has committed this, I'll close the bug report. Any new issues can be tracked separately.