diff --git a/README b/README index e49e8db..355c3d5 100644 --- a/README +++ b/README @@ -2,7 +2,13 @@ Debugging --------- To compile debugging code configure the project with the --enable-debug option. Then at runtime you may set the environment variable "DBUSXX_VERBOSE=1" to activate debugging and to '0' to deactivate debugging. + Hints ----- Your applications based on dbus-c++ have to support PTHREAD and to export the variable HAVE_PTHREAD_H. + +BUGS: +----- +- dbus seems to stop working sometimes (only seen with ecore integrattion) +- ecore dbus integration is really "raw" (but working) at the moment diff --git a/configure.ac b/configure.ac index 77759e1..fb34ee9 100644 --- a/configure.ac +++ b/configure.ac @@ -203,7 +203,8 @@ AC_OUTPUT( examples/Makefile examples/properties/Makefile examples/echo/Makefile - examples/hal/Makefile + examples/ecore/Makefile + examples/hal/Makefile examples/glib/Makefile dbus-c++-1.pc dbus-c++-1-uninstalled.pc diff --git a/examples/Makefile.am b/examples/Makefile.am index b346604..3e81869 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = properties echo hal glib +SUBDIRS = properties echo hal glib ecore MAINTAINERCLEANFILES = \ Makefile.in diff --git a/examples/ecore/Makefile.am b/examples/ecore/Makefile.am new file mode 100644 index 0000000..93ab959 --- /dev/null +++ b/examples/ecore/Makefile.am @@ -0,0 +1,23 @@ +EXTRA_DIST = + +AM_CPPFLAGS = -I$(top_srcdir)/include $(ecore_CFLAGS) $(xml_CFLAGS) -I$(top_srcdir)/tools + +if ENABLE_ECORE +noinst_PROGRAMS = dbus_ecore +endif + +dbus_ecore_SOURCES = dbus_ecore-glue.h dbus_ecore.h dbus_ecore.cpp $(top_srcdir)/tools/xml.cpp +dbus_ecore_LDADD = $(top_builddir)/src/libdbus-c++-1.la $(ecore_LIBS) $(xml_LIBS) + +dbus_ecore-glue.h: $(top_srcdir)/data/org.freedesktop.DBus.xml + $(top_builddir)/tools/dbusxx-xml2cpp $^ --proxy=$@ + +BUILT_SOURCES = dbus_ecore-glue.h +CLEANFILES = $(BUILT_SOURCES) + +dist-hook: + cd $(distdir); rm -f $(BUILT_SOURCES) + +MAINTAINERCLEANFILES = \ + Makefile.in + diff --git a/examples/ecore/dbus_ecore.cpp b/examples/ecore/dbus_ecore.cpp new file mode 100644 index 0000000..8cc827f --- /dev/null +++ b/examples/ecore/dbus_ecore.cpp @@ -0,0 +1,145 @@ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "dbus_ecore.h" + +#include +#include + +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) +{ + typedef std::vector< ::DBus::String > Names; + + Names names = ListNames(); + + for(Names::iterator it = names.begin(); it != names.end(); ++it) + { + //_cb_busnames.append_text(*it); + + cout << *it << endl; + } + + /*_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::Ecore::BusDispatcher dispatcher; + +void niam( int sig ) +{ + ecore_main_loop_quit(); +} + +int main(int argc, char* argv[]) +{ + signal(SIGTERM, niam); + signal(SIGINT, niam); + + ecore_init(); + + DBus::default_dispatcher = &dispatcher; + + DBus::Connection conn = DBus::Connection::SessionBus(); + + DBusBrowser browser(conn); + + ecore_main_loop_begin(); + ecore_shutdown(); + + return 0; +} diff --git a/examples/ecore/dbus_ecore.h b/examples/ecore/dbus_ecore.h new file mode 100644 index 0000000..ccd4b99 --- /dev/null +++ b/examples/ecore/dbus_ecore.h @@ -0,0 +1,61 @@ +#ifndef __DEMO_DBUS_BROWSER_H +#define __DEMO_DBUS_BROWSER_H + +#include +#include +#include + +#include "dbus_ecore-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: + + DBusBrowser( ::DBus::Connection& conn ); + +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 name; + }; + + Gtk::VBox _vbox; + Gtk::ScrolledWindow _sc_tree; + Gtk::ComboBoxText _cb_busnames; + Gtk::TreeView _tv_inspect; + Glib::RefPtr _tm_inspect;*/ + //InspectRecord _records; +}; + +#endif//__DEMO_DBUS_BROWSER_H