* Included config.h in all headers
* Don't define DBUS_API_SUBJECT_TO_CHANGE unless for old D-Bus versions * Use recursive mutex functions if libdbus supports it * Specify the path when adding match rules, otherwise messages wouldn't be forwarded to the right object under some circumstances * Added integration with the glib main loop (configure with --enable-glib) * Added a gtkmm dbus-browser clone to demonstrate glib integration * Fixed a typo in dbusxx-xml2cpp proxy output * Added python usage instructions for the Echo example git-svn-id: http://dev.openwengo.org/svn/openwengo/wengophone-ng/branches/wengophone-dbus-api/libs/dbus@10948 30a43799-04e7-0310-8b2b-ea0d24f86d0e
This commit is contained in:
parent
771ca71556
commit
48a1be9f2a
37 changed files with 427 additions and 23 deletions
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS = properties echo hal
|
||||
SUBDIRS = properties echo hal glib
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
Makefile.in
|
||||
|
|
|
@ -9,3 +9,15 @@ dbus-send --dest=org.freedesktop.DBus.Examples.Echo --type=method_call --print-r
|
|||
dbus-send --dest=org.freedesktop.DBus.Examples.Echo --type=method_call --print-reply /org/freedesktop/DBus/Examples/Echo org.freedesktop.DBus.EchoDemo.Sum array:int32:10,100,250
|
||||
|
||||
dbus-send --dest=org.freedesktop.DBus.Examples.Echo --type=method_call --print-reply /org/freedesktop/DBus/Examples/Echo org.freedesktop.DBus.EchoDemo.Info
|
||||
|
||||
or, using python instead
|
||||
|
||||
$ python
|
||||
import dbus
|
||||
bus = dbus.SessionBus()
|
||||
object = bus.get_object('org.freedesktop.DBus.Examples.Echo','/org/freedesktop/DBus/Examples/Echo')
|
||||
echo = dbus.Interface(object, dbus_interface='org.freedesktop.DBus.EchoDemo')
|
||||
echo.Random()
|
||||
echo.Hello("world")
|
||||
echo.Sum([123, 234, 95, 520])
|
||||
echo.Info()
|
||||
|
|
22
examples/glib/Makefile.am
Normal file
22
examples/glib/Makefile.am
Normal file
|
@ -0,0 +1,22 @@
|
|||
EXTRA_DIST =
|
||||
|
||||
AM_CPPFLAGS = -I$(top_srcdir)/include $(gtkmm_CFLAGS)
|
||||
|
||||
if HAVE_GTKMM
|
||||
noinst_PROGRAMS = dbus-browser
|
||||
endif
|
||||
|
||||
dbus_browser_SOURCES = dbus-glue.h dbus-browser.h dbus-browser.cpp
|
||||
dbus_browser_LDADD = $(top_builddir)/src/libdbus-c++-1.la $(gtkmm_LIBS)
|
||||
|
||||
dbus-glue.h: $(top_srcdir)/data/org.freedesktop.DBus.xml
|
||||
$(top_builddir)/tools/dbusxx-xml2cpp $^ --proxy=$@
|
||||
|
||||
BUILT_SOURCES = dbus-glue.h
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
dist-hook:
|
||||
cd $(distdir); rm -f $(BUILT_SOURCES)
|
||||
|
||||
MAINTAINERCLEANFILES = \
|
||||
Makefile.in
|
135
examples/glib/dbus-browser.cpp
Normal file
135
examples/glib/dbus-browser.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
#include "dbus-browser.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static const char* DBUS_SERVER_NAME = "org.freedesktop.DBus";
|
||||
static const char* DBUS_SERVER_PATH = "/org/freedesktop/DBus";
|
||||
|
||||
DBusBrowser::DBusBrowser( ::DBus::Connection& conn )
|
||||
: ::DBus::ObjectProxy(conn, DBUS_SERVER_PATH, DBUS_SERVER_NAME)
|
||||
{
|
||||
set_title("D-Bus Browser");
|
||||
set_border_width(5);
|
||||
set_default_size(400, 500);
|
||||
|
||||
typedef std::vector< ::DBus::String > Names;
|
||||
|
||||
Names names = ListNames();
|
||||
|
||||
for(Names::iterator it = names.begin(); it != names.end(); ++it)
|
||||
{
|
||||
_cb_busnames.append_text(*it);
|
||||
}
|
||||
|
||||
_cb_busnames.signal_changed().connect( sigc::mem_fun(*this, &DBusBrowser::on_select_busname) );
|
||||
|
||||
_tm_inspect = Gtk::TreeStore::create(_records);
|
||||
_tv_inspect.set_model(_tm_inspect);
|
||||
_tv_inspect.append_column("Node", _records.name);
|
||||
|
||||
_sc_tree.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
||||
_sc_tree.add(_tv_inspect);
|
||||
|
||||
_vbox.pack_start(_cb_busnames, Gtk::PACK_SHRINK);
|
||||
_vbox.pack_start(_sc_tree);
|
||||
|
||||
add(_vbox);
|
||||
|
||||
show_all_children();
|
||||
}
|
||||
|
||||
void DBusBrowser::NameOwnerChanged(
|
||||
const ::DBus::String& name, const ::DBus::String& old_owner, const ::DBus::String& new_owner )
|
||||
{
|
||||
cout << name << ": " << old_owner << " -> " << new_owner << endl;
|
||||
}
|
||||
|
||||
void DBusBrowser::NameLost( const ::DBus::String& name )
|
||||
{
|
||||
cout << name << " lost" << endl;
|
||||
}
|
||||
|
||||
void DBusBrowser::NameAcquired( const ::DBus::String& name )
|
||||
{
|
||||
cout << name << " acquired" << endl;
|
||||
}
|
||||
|
||||
void DBusBrowser::on_select_busname()
|
||||
{
|
||||
Glib::ustring busname = _cb_busnames.get_active_text();
|
||||
if(busname.empty()) return;
|
||||
|
||||
_tm_inspect->clear();
|
||||
_inspect_append(NULL, "", busname);
|
||||
}
|
||||
|
||||
void DBusBrowser::_inspect_append( Gtk::TreeModel::Row* row, const std::string& buspath, const std::string& busname )
|
||||
{
|
||||
DBusInspector inspector(conn(), buspath.empty() ? "/" : buspath.c_str(), busname.c_str());
|
||||
|
||||
::DBus::Xml::Document doc(inspector.Introspect());
|
||||
::DBus::Xml::Node& root = *(doc.root);
|
||||
|
||||
::DBus::Xml::Nodes ifaces = root["interface"];
|
||||
|
||||
for(::DBus::Xml::Nodes::iterator ii = ifaces.begin(); ii != ifaces.end(); ++ii)
|
||||
{
|
||||
::DBus::Xml::Node& iface = **ii;
|
||||
|
||||
Gtk::TreeModel::Row i_row = row
|
||||
? *(_tm_inspect->append(row->children()))
|
||||
: *(_tm_inspect->append());
|
||||
i_row[_records.name] = "interface: " + iface.get("name");
|
||||
|
||||
::DBus::Xml::Nodes methods = iface["method"];
|
||||
|
||||
for(::DBus::Xml::Nodes::iterator im = methods.begin(); im != methods.end(); ++im)
|
||||
{
|
||||
Gtk::TreeModel::Row m_row = *(_tm_inspect->append(i_row.children()));
|
||||
m_row[_records.name] = "method: " + (*im)->get("name");
|
||||
}
|
||||
|
||||
::DBus::Xml::Nodes signals = iface["signal"];
|
||||
|
||||
for(::DBus::Xml::Nodes::iterator is = signals.begin(); is != signals.end(); ++is)
|
||||
{
|
||||
Gtk::TreeModel::Row s_row = *(_tm_inspect->append(i_row.children()));
|
||||
s_row[_records.name] = "signal: " + (*is)->get("name");
|
||||
}
|
||||
}
|
||||
|
||||
::DBus::Xml::Nodes nodes = root["node"];
|
||||
|
||||
for(::DBus::Xml::Nodes::iterator in = nodes.begin(); in != nodes.end(); ++in)
|
||||
{
|
||||
std::string name = (*in)->get("name");
|
||||
|
||||
Gtk::TreeModel::Row n_row = row
|
||||
? *(_tm_inspect->append(row->children()))
|
||||
: *(_tm_inspect->append());
|
||||
n_row[_records.name] = name;
|
||||
|
||||
_inspect_append(&n_row, buspath + "/" + name, busname);
|
||||
}
|
||||
}
|
||||
|
||||
DBus::Glib::BusDispatcher dispatcher;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Gtk::Main kit(argc, argv);
|
||||
|
||||
DBus::default_dispatcher = &dispatcher;
|
||||
|
||||
dispatcher.attach(NULL);
|
||||
|
||||
DBus::Connection conn = DBus::Connection::SessionBus();
|
||||
|
||||
DBusBrowser browser(conn);
|
||||
|
||||
Gtk::Main::run(browser);
|
||||
|
||||
return 0;
|
||||
}
|
62
examples/glib/dbus-browser.h
Normal file
62
examples/glib/dbus-browser.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
#ifndef __DEMO_DBUS_BROWSER_H
|
||||
#define __DEMO_DBUS_BROWSER_H
|
||||
|
||||
#include <dbus-c++/dbus.h>
|
||||
#include <dbus-c++/glib-integration.h>
|
||||
#include <gtkmm.h>
|
||||
|
||||
#include "dbus-glue.h"
|
||||
|
||||
class DBusInspector
|
||||
: public DBus::IntrospectableProxy,
|
||||
public DBus::ObjectProxy
|
||||
{
|
||||
public:
|
||||
|
||||
DBusInspector( DBus::Connection& conn, const char* path, const char* service )
|
||||
: DBus::ObjectProxy(conn, path, service)
|
||||
{}
|
||||
};
|
||||
|
||||
class DBusBrowser
|
||||
: public org::freedesktop::DBus,
|
||||
public DBus::IntrospectableProxy,
|
||||
public DBus::ObjectProxy,
|
||||
public Gtk::Window
|
||||
{
|
||||
public:
|
||||
|
||||
DBusBrowser( ::DBus::Connection& );
|
||||
|
||||
private:
|
||||
|
||||
void NameOwnerChanged( const ::DBus::String&, const ::DBus::String&, const ::DBus::String& );
|
||||
|
||||
void NameLost( const ::DBus::String& );
|
||||
|
||||
void NameAcquired( const ::DBus::String& );
|
||||
|
||||
void on_select_busname();
|
||||
|
||||
void _inspect_append( Gtk::TreeModel::Row*, const std::string&, const std::string& );
|
||||
|
||||
private:
|
||||
|
||||
class InspectRecord : public Gtk::TreeModel::ColumnRecord
|
||||
{
|
||||
public:
|
||||
|
||||
InspectRecord() { add(name); }
|
||||
|
||||
Gtk::TreeModelColumn<Glib::ustring> name;
|
||||
};
|
||||
|
||||
Gtk::VBox _vbox;
|
||||
Gtk::ScrolledWindow _sc_tree;
|
||||
Gtk::ComboBoxText _cb_busnames;
|
||||
Gtk::TreeView _tv_inspect;
|
||||
Glib::RefPtr<Gtk::TreeStore> _tm_inspect;
|
||||
InspectRecord _records;
|
||||
};
|
||||
|
||||
#endif//__DEMO_DBUS_BROWSER_H
|
Loading…
Add table
Add a link
Reference in a new issue