midgard_dbus API is very simple, but my approach was to make it just simple as possible. Basically we have two major methods of midgard_dbus:
- constructor, which registers object at path
- send, which asynchronously send message to object at given path
New initialized object doesn't do anything special. It just waits for any call to him and then emits "notified" signal, which you can connect callback to.
I tested simple code with midgard-php and midgard-python.
midgard_python "service":
import dbus.mainloop.glib
import _midgard as midgard
def mbus_callback(object, arg):
print "Hi! I am midgard_dbus from midgard-python. I got message:"
print object.get_message()
mbus = midgard.dbus("/midgard_article")
mbus.connect("notified", mbus_callback, "foo")
mainloop = gobject.MainLoop()
mainloop.run()
midgard-php "client":
$message = "Greetings from midgard-php!(" . mgd_version() . ") PHP ver." . phpversion();
midgard_dbus::send("/midgard_article", $message);
I started php script which immidietialy ended, and on midgard-python service's terminal I got this message:
Hi! I am midgard_dbus from midgard-python. I got message:
Greetings from midgard-php! (2.0alpha0) PHP ver.5.2.5-3
Probably the code will be soon ported to 1-9 branch, so I will be able to test midgard_dbus in Apache environment. But for now, basic idea looks fine and works fine. We just notify objects at path with particular message, and local proccess does the rest with connected callbacks.