|
From: Andreas V. <li...@br...> - 2008-08-29 22:25:29
|
Hello, while writing a DBUS interface for my application I found a way to give objects direct "through" DBUS. In reality the objects aren't give through DBUS. Only the copyable contents are given though DBUS. So how does it work? See the example communication framework here. It's only a prototype and still has some problems. http://tux-style.de/tmp/oicf-0.1.tar.gz Look at OICFControlListener.cpp: (below as reference. Use the source for more overview) class OICFControlListener : public org::oicf::ControlListener, public DBus::IntrospectableProxy, public DBus::ObjectProxy { public: OICFControlListener ( DBus::Connection& connection, const char* path, const char* name ) : DBus::ObjectProxy (connection, path, name) {} virtual void onAxisListener (const KeyEvent &event) = 0; virtual void onButtonListener (const KeyEvent &event) = 0; private: void onAxisListener(const KeyEvent_Dbus_t &eventAxis) { KeyEvent event; event << eventAxis; onAxisListener (event); } void onButtonListener(const KeyEvent_Dbus_t &eventButton) { KeyEvent event; event << eventButton; onButtonListener (event); } }; As you see the private onAxisListener() from dbus-c++ is overwritten and creates the object KeyEvent, fills it with the '<<' operator and calls the new public callback function. Look into KeyEvent.h: typedef ::DBus::Struct <int32_t, int16_t, uint8_t, bool> KeyEvent_Dbus_t; class KeyEvent { public: ... public: int32_t time; int16_t value; int8_t number; public: void operator << (const KeyEvent_Dbus_t& event) { time = event._1; value = event._2; number = event._3; } }; This works as long as '<<' and '>>' operator is implemented correct in the class you like to give "through" dbus-c++. (See CoordWGS84.h) for another example. For sure objects are not given through DBUS, but it looks and behaves for the user in that way. Look at the introspection XML: <?xml version="1.0" ?> <node name="/org/oicf/ControlListener"> <interface name="org.oicf.ControlListener"> <signal name="onAxisListener"> <arg type="(inyb)" name="eventAxis" direction="out"/> </signal> <signal name="onButtonListener"> <arg type="(inyb)" name="eventButton" direction="out"/> </signal> </interface> </node> You see that it has a struct that exactly fits the KeyEvent.h data. This works so far, but it's much way to write all that wrapper functions on my own. This is exact the work a code generator is done for. I would propose to change the XML format in that way: <?xml version="1.0" ?> <node name="/org/oicf/ControlListener"> <interface name="org.oicf.ControlListener"> <signal name="onAxisListener"> <arg type="(inyb)" name="eventAxis" direction="out" object="KeyEvent"/> </signal> <signal name="onButtonListener"> <arg type="(inyb)" name="eventButton" direction="out" object="KeyEvent"/> </signal> </interface> </node> So the code generator know that he should add some code to give "class KeyEvent" in a "KeyEvent.h" in dbus-c++ as shown above. The only thing that has to be hand written is the KeyEvent.h and the '<<' and '>>' operator. This proposal is backwards compatible as other DBUS implementations simply ignore the "object" tag and give access to the data with the normal DBUS mechanisms. What do you think about this idea? regards Andreas |