diff --git a/configure.ac b/configure.ac index fb34ee9..7d87ee9 100644 --- a/configure.ac +++ b/configure.ac @@ -203,8 +203,8 @@ AC_OUTPUT( examples/Makefile examples/properties/Makefile examples/echo/Makefile - examples/ecore/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 3e81869..a940bc8 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = properties echo hal glib ecore +SUBDIRS = properties echo hal glib ecore MAINTAINERCLEANFILES = \ Makefile.in diff --git a/examples/echo/echo-client.cpp b/examples/echo/echo-client.cpp index 3e1f19e..0a42b36 100644 --- a/examples/echo/echo-client.cpp +++ b/examples/echo/echo-client.cpp @@ -9,15 +9,15 @@ using namespace std; -static const char* ECHO_SERVER_NAME = "org.freedesktop.DBus.Examples.Echo"; -static const char* ECHO_SERVER_PATH = "/org/freedesktop/DBus/Examples/Echo"; +static const char *ECHO_SERVER_NAME = "org.freedesktop.DBus.Examples.Echo"; +static const char *ECHO_SERVER_PATH = "/org/freedesktop/DBus/Examples/Echo"; -EchoClient::EchoClient( DBus::Connection& connection, const char* path, const char* name ) +EchoClient::EchoClient(DBus::Connection &connection, const char *path, const char *name) : DBus::ObjectProxy(connection, path, name) { } -void EchoClient::Echoed( const DBus::Variant& value ) +void EchoClient::Echoed(const DBus::Variant &value) { cout << "!"; } @@ -26,13 +26,13 @@ void EchoClient::Echoed( const DBus::Variant& value ) * For some strange reason, libdbus frequently dies with an OOM */ -static const int THREADS = 16; +static const int THREADS = 3; static bool spin = true; -void* greeter_thread( void* arg ) +void *greeter_thread(void *arg) { - DBus::Connection* conn = reinterpret_cast(arg); + DBus::Connection *conn = reinterpret_cast(arg); EchoClient client(*conn, ECHO_SERVER_PATH, ECHO_SERVER_NAME); @@ -40,7 +40,7 @@ void* greeter_thread( void* arg ) snprintf(idstr, sizeof(idstr), "%lu", pthread_self()); - for(int i = 0; i < 100 && spin; ++i) + for (int i = 0; i < 30 && spin; ++i) { cout << client.Hello(idstr) << endl; } @@ -52,7 +52,7 @@ void* greeter_thread( void* arg ) DBus::BusDispatcher dispatcher; -void niam( int sig ) +void niam(int sig) { spin = false; @@ -76,7 +76,7 @@ int main() pthread_t threads[THREADS]; - for(int i = 0; i < THREADS; ++i) + for (int i = 0; i < THREADS; ++i) { pthread_create(threads+i, NULL, greeter_thread, &conn); } @@ -85,7 +85,7 @@ int main() cout << "terminating" << endl; - for(int i = 0; i < THREADS; ++i) + for (int i = 0; i < THREADS; ++i) { pthread_join(threads[i], NULL); } diff --git a/examples/echo/echo-client.h b/examples/echo/echo-client.h index 0f88e80..abfb620 100644 --- a/examples/echo/echo-client.h +++ b/examples/echo/echo-client.h @@ -11,9 +11,9 @@ class EchoClient { public: - EchoClient( DBus::Connection& connection, const char* path, const char* name ); + EchoClient(DBus::Connection &connection, const char *path, const char *name); - void Echoed( const DBus::Variant& value ); + void Echoed(const DBus::Variant &value); }; #endif//__DEMO_ECHO_CLIENT_H diff --git a/examples/echo/echo-server.cpp b/examples/echo/echo-server.cpp index deb1aa7..188f0d5 100644 --- a/examples/echo/echo-server.cpp +++ b/examples/echo/echo-server.cpp @@ -9,58 +9,59 @@ #include #include -static const char* ECHO_SERVER_NAME = "org.freedesktop.DBus.Examples.Echo"; -static const char* ECHO_SERVER_PATH = "/org/freedesktop/DBus/Examples/Echo"; +static const char *ECHO_SERVER_NAME = "org.freedesktop.DBus.Examples.Echo"; +static const char *ECHO_SERVER_PATH = "/org/freedesktop/DBus/Examples/Echo"; -EchoServer::EchoServer( DBus::Connection& connection ) +EchoServer::EchoServer(DBus::Connection &connection) : DBus::ObjectAdaptor(connection, ECHO_SERVER_PATH) { } -DBus::Int32 EchoServer::Random() +int32_t EchoServer::Random() { return rand(); } -DBus::String EchoServer::Hello( const DBus::String& name ) +std::string EchoServer::Hello(const std::string &name) { + sleep (10); return "Hello " + name + "!"; } -DBus::Variant EchoServer::Echo( const DBus::Variant& value ) +DBus::Variant EchoServer::Echo(const DBus::Variant &value) { this->Echoed(value); return value; } -std::vector< DBus::Byte > EchoServer::Cat( const DBus::String & file ) +std::vector< uint8_t > EchoServer::Cat(const std::string &file) { - FILE* handle = fopen(file.c_str(), "rb"); + FILE *handle = fopen(file.c_str(), "rb"); - if(!handle) throw DBus::Error("org.freedesktop.DBus.EchoDemo.ErrorFileNotFound", "file not found"); + if (!handle) throw DBus::Error("org.freedesktop.DBus.EchoDemo.ErrorFileNotFound", "file not found"); - DBus::Byte buff[1024]; + uint8_t buff[1024]; size_t nread = fread(buff, 1, sizeof(buff), handle); fclose(handle); - return std::vector< DBus::Byte > (buff, buff + nread); + return std::vector< uint8_t > (buff, buff + nread); } -DBus::Int32 EchoServer::Sum( const std::vector& ints ) +int32_t EchoServer::Sum(const std::vector& ints) { - DBus::Int32 sum = 0; + int32_t sum = 0; - for(size_t i = 0; i < ints.size(); ++i) sum += ints[i]; + for (size_t i = 0; i < ints.size(); ++i) sum += ints[i]; return sum; } -std::map< DBus::String, DBus::String > EchoServer::Info() +std::map< std::string, std::string > EchoServer::Info() { - std::map< DBus::String, DBus::String > info; + std::map< std::string, std::string > info; char hostname[HOST_NAME_MAX]; gethostname(hostname, sizeof(hostname)); @@ -73,7 +74,7 @@ std::map< DBus::String, DBus::String > EchoServer::Info() DBus::BusDispatcher dispatcher; -void niam( int sig ) +void niam(int sig) { dispatcher.leave(); } diff --git a/examples/echo/echo-server.h b/examples/echo/echo-server.h index 989d84c..94d597e 100644 --- a/examples/echo/echo-server.h +++ b/examples/echo/echo-server.h @@ -11,19 +11,19 @@ class EchoServer { public: - EchoServer( DBus::Connection& connection ); + EchoServer(DBus::Connection &connection); - DBus::Int32 Random(); + int32_t Random(); - DBus::String Hello( const DBus::String & name ); + std::string Hello(const std::string &name); - DBus::Variant Echo( const DBus::Variant & value ); + DBus::Variant Echo(const DBus::Variant &value); - std::vector< DBus::Byte > Cat( const DBus::String & file ); + std::vector< uint8_t > Cat(const std::string &file); - DBus::Int32 Sum( const std::vector & ints ); + int32_t Sum(const std::vector & ints); - std::map< DBus::String, DBus::String > Info(); + std::map< std::string, std::string > Info(); }; #endif//__DEMO_ECHO_SERVER_H diff --git a/examples/ecore/dbus_ecore.cpp b/examples/ecore/dbus_ecore.cpp index e24b178..569285d 100644 --- a/examples/ecore/dbus_ecore.cpp +++ b/examples/ecore/dbus_ecore.cpp @@ -15,7 +15,7 @@ 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; + typedef std::vector< std::string > Names; Names names = ListNames(); @@ -26,17 +26,17 @@ DBusBrowser::DBusBrowser( ::DBus::Connection& conn ) } void DBusBrowser::NameOwnerChanged( - const ::DBus::String& name, const ::DBus::String& old_owner, const ::DBus::String& new_owner ) + const std::string& name, const std::string& old_owner, const std::string& new_owner ) { cout << name << ": " << old_owner << " -> " << new_owner << endl; } -void DBusBrowser::NameLost( const ::DBus::String& name ) +void DBusBrowser::NameLost( const std::string& name ) { cout << name << " lost" << endl; } -void DBusBrowser::NameAcquired( const ::DBus::String& name ) +void DBusBrowser::NameAcquired( const std::string& name ) { cout << name << " acquired" << endl; } diff --git a/examples/ecore/dbus_ecore.h b/examples/ecore/dbus_ecore.h index e5190e9..295068c 100644 --- a/examples/ecore/dbus_ecore.h +++ b/examples/ecore/dbus_ecore.h @@ -18,11 +18,11 @@ public: private: - void NameOwnerChanged( const ::DBus::String&, const ::DBus::String&, const ::DBus::String& ); + void NameOwnerChanged( const std::string&, const std::string&, const std::string& ); - void NameLost( const ::DBus::String& ); + void NameLost( const std::string& ); - void NameAcquired( const ::DBus::String& ); + void NameAcquired( const std::string& ); private: diff --git a/examples/glib/dbus-browser.cpp b/examples/glib/dbus-browser.cpp index 09ec119..5e27fc4 100644 --- a/examples/glib/dbus-browser.cpp +++ b/examples/glib/dbus-browser.cpp @@ -9,26 +9,26 @@ using namespace std; -static const char* DBUS_SERVER_NAME = "org.freedesktop.DBus"; -static const char* DBUS_SERVER_PATH = "/org/freedesktop/DBus"; +static const char *DBUS_SERVER_NAME = "org.freedesktop.DBus"; +static const char *DBUS_SERVER_PATH = "/org/freedesktop/DBus"; -DBusBrowser::DBusBrowser( ::DBus::Connection& conn ) +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; + typedef std::vector< std::string > Names; Names names = ListNames(); - for(Names::iterator it = names.begin(); it != names.end(); ++it) + 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) ); + _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); @@ -46,17 +46,17 @@ DBusBrowser::DBusBrowser( ::DBus::Connection& conn ) } void DBusBrowser::NameOwnerChanged( - const ::DBus::String& name, const ::DBus::String& old_owner, const ::DBus::String& new_owner ) + const std::string &name, const std::string &old_owner, const std::string &new_owner) { cout << name << ": " << old_owner << " -> " << new_owner << endl; } -void DBusBrowser::NameLost( const ::DBus::String& name ) +void DBusBrowser::NameLost(const std::string &name) { cout << name << " lost" << endl; } -void DBusBrowser::NameAcquired( const ::DBus::String& name ) +void DBusBrowser::NameAcquired(const std::string &name) { cout << name << " acquired" << endl; } @@ -64,24 +64,24 @@ void DBusBrowser::NameAcquired( const ::DBus::String& name ) void DBusBrowser::on_select_busname() { Glib::ustring busname = _cb_busnames.get_active_text(); - if(busname.empty()) return; + 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 ) +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::Node &root = *(doc.root); ::DBus::Xml::Nodes ifaces = root["interface"]; - for(::DBus::Xml::Nodes::iterator ii = ifaces.begin(); ii != ifaces.end(); ++ii) + for (::DBus::Xml::Nodes::iterator ii = ifaces.begin(); ii != ifaces.end(); ++ii) { - ::DBus::Xml::Node& iface = **ii; + ::DBus::Xml::Node &iface = **ii; Gtk::TreeModel::Row i_row = row ? *(_tm_inspect->append(row->children())) @@ -90,7 +90,7 @@ void DBusBrowser::_inspect_append( Gtk::TreeModel::Row* row, const std::string& ::DBus::Xml::Nodes methods = iface["method"]; - for(::DBus::Xml::Nodes::iterator im = methods.begin(); im != methods.end(); ++im) + 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"); @@ -98,7 +98,7 @@ void DBusBrowser::_inspect_append( Gtk::TreeModel::Row* row, const std::string& ::DBus::Xml::Nodes signals = iface["signal"]; - for(::DBus::Xml::Nodes::iterator is = signals.begin(); is != signals.end(); ++is) + 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"); @@ -107,7 +107,7 @@ void DBusBrowser::_inspect_append( Gtk::TreeModel::Row* row, const std::string& ::DBus::Xml::Nodes nodes = root["node"]; - for(::DBus::Xml::Nodes::iterator in = nodes.begin(); in != nodes.end(); ++in) + for (::DBus::Xml::Nodes::iterator in = nodes.begin(); in != nodes.end(); ++in) { std::string name = (*in)->get("name"); @@ -122,7 +122,7 @@ void DBusBrowser::_inspect_append( Gtk::TreeModel::Row* row, const std::string& DBus::Glib::BusDispatcher dispatcher; -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); diff --git a/examples/glib/dbus-browser.h b/examples/glib/dbus-browser.h index 10c9b3d..4e95980 100644 --- a/examples/glib/dbus-browser.h +++ b/examples/glib/dbus-browser.h @@ -13,7 +13,7 @@ class DBusInspector { public: - DBusInspector( DBus::Connection& conn, const char* path, const char* service ) + DBusInspector(DBus::Connection &conn, const char *path, const char *service) : DBus::ObjectProxy(conn, path, service) {} }; @@ -26,19 +26,19 @@ class DBusBrowser { public: - DBusBrowser( ::DBus::Connection& ); + DBusBrowser(::DBus::Connection &); private: - void NameOwnerChanged( const ::DBus::String&, const ::DBus::String&, const ::DBus::String& ); + void NameOwnerChanged(const std::string &, const std::string &, const std::string &); - void NameLost( const ::DBus::String& ); + void NameLost(const std::string &); - void NameAcquired( const ::DBus::String& ); + void NameAcquired(const std::string &); void on_select_busname(); - void _inspect_append( Gtk::TreeModel::Row*, const std::string&, const std::string& ); + void _inspect_append(Gtk::TreeModel::Row *, const std::string &, const std::string &); private: diff --git a/examples/hal/hal-listen.cpp b/examples/hal/hal-listen.cpp index 3d1262a..1939f8a 100644 --- a/examples/hal/hal-listen.cpp +++ b/examples/hal/hal-listen.cpp @@ -7,17 +7,17 @@ #include #include -HalManagerProxy::HalManagerProxy( DBus::Connection& connection ) +HalManagerProxy::HalManagerProxy(DBus::Connection &connection) : DBus::InterfaceProxy("org.freedesktop.Hal.Manager"), DBus::ObjectProxy(connection, "/org/freedesktop/Hal/Manager", "org.freedesktop.Hal") { connect_signal(HalManagerProxy, DeviceAdded, DeviceAddedCb); connect_signal(HalManagerProxy, DeviceRemoved, DeviceRemovedCb); - std::vector< DBus::String > devices = GetAllDevices(); + std::vector< std::string > devices = GetAllDevices(); - std::vector< DBus::String >::iterator it; - for(it = devices.begin(); it != devices.end(); ++it) + std::vector< std::string >::iterator it; + for (it = devices.begin(); it != devices.end(); ++it) { DBus::Path udi = *it; @@ -27,9 +27,9 @@ HalManagerProxy::HalManagerProxy( DBus::Connection& connection ) } } -std::vector< DBus::String > HalManagerProxy::GetAllDevices() +std::vector< std::string > HalManagerProxy::GetAllDevices() { - std::vector< DBus::String > udis; + std::vector< std::string > udis; DBus::CallMessage call; call.member("GetAllDevices"); @@ -41,10 +41,10 @@ std::vector< DBus::String > HalManagerProxy::GetAllDevices() return udis; } -void HalManagerProxy::DeviceAddedCb( const DBus::SignalMessage& sig ) +void HalManagerProxy::DeviceAddedCb(const DBus::SignalMessage &sig) { DBus::MessageIter it = sig.reader(); - DBus::String devname; + std::string devname; it >> devname; @@ -54,10 +54,10 @@ void HalManagerProxy::DeviceAddedCb( const DBus::SignalMessage& sig ) std::cout << "added device " << udi << std::endl; } -void HalManagerProxy::DeviceRemovedCb( const DBus::SignalMessage& sig ) +void HalManagerProxy::DeviceRemovedCb(const DBus::SignalMessage &sig) { DBus::MessageIter it = sig.reader(); - DBus::String devname; + std::string devname; it >> devname; @@ -66,7 +66,7 @@ void HalManagerProxy::DeviceRemovedCb( const DBus::SignalMessage& sig ) _devices.erase(devname); } -HalDeviceProxy::HalDeviceProxy( DBus::Connection& connection, DBus::Path& udi ) +HalDeviceProxy::HalDeviceProxy(DBus::Connection &connection, DBus::Path &udi) : DBus::InterfaceProxy("org.freedesktop.Hal.Device"), DBus::ObjectProxy(connection, udi, "org.freedesktop.Hal") { @@ -74,18 +74,18 @@ HalDeviceProxy::HalDeviceProxy( DBus::Connection& connection, DBus::Path& udi ) connect_signal(HalDeviceProxy, Condition, ConditionCb); } -void HalDeviceProxy::PropertyModifiedCb( const DBus::SignalMessage& sig ) +void HalDeviceProxy::PropertyModifiedCb(const DBus::SignalMessage &sig) { - typedef DBus::Struct< DBus::String, DBus::Bool, DBus::Bool > HalProperty; + typedef DBus::Struct< std::string, bool, bool > HalProperty; DBus::MessageIter it = sig.reader(); - DBus::Int32 number; + int32_t number; it >> number; DBus::MessageIter arr = it.recurse(); - for(int i = 0; i < number; ++i, ++arr) + for (int i = 0; i < number; ++i, ++arr) { HalProperty hp; @@ -95,10 +95,10 @@ void HalDeviceProxy::PropertyModifiedCb( const DBus::SignalMessage& sig ) } } -void HalDeviceProxy::ConditionCb( const DBus::SignalMessage& sig ) +void HalDeviceProxy::ConditionCb(const DBus::SignalMessage &sig) { DBus::MessageIter it = sig.reader(); - DBus::String condition; + std::string condition; it >> condition; @@ -107,7 +107,7 @@ void HalDeviceProxy::ConditionCb( const DBus::SignalMessage& sig ) DBus::BusDispatcher dispatcher; -void niam( int sig ) +void niam(int sig) { dispatcher.leave(); } diff --git a/examples/hal/hal-listen.h b/examples/hal/hal-listen.h index 8401fbf..12862e6 100644 --- a/examples/hal/hal-listen.h +++ b/examples/hal/hal-listen.h @@ -13,17 +13,17 @@ class HalManagerProxy { public: - HalManagerProxy( DBus::Connection& connection ); + HalManagerProxy(DBus::Connection &connection); - std::vector< DBus::String > GetAllDevices(); + std::vector< std::string > GetAllDevices(); private: - void DeviceAddedCb( const DBus::SignalMessage& sig ); + void DeviceAddedCb(const DBus::SignalMessage &sig); - void DeviceRemovedCb( const DBus::SignalMessage& sig ); + void DeviceRemovedCb(const DBus::SignalMessage &sig); - std::map< DBus::String, DBus::RefPtr< HalDeviceProxy > > _devices; + std::map< std::string, DBus::RefPtr< HalDeviceProxy > > _devices; }; class HalDeviceProxy @@ -32,13 +32,13 @@ class HalDeviceProxy { public: - HalDeviceProxy( DBus::Connection& connection, DBus::Path& udi ); + HalDeviceProxy(DBus::Connection &connection, DBus::Path &udi); private: - void PropertyModifiedCb( const DBus::SignalMessage& sig ); + void PropertyModifiedCb(const DBus::SignalMessage &sig); - void ConditionCb( const DBus::SignalMessage& sig ); + void ConditionCb(const DBus::SignalMessage &sig); }; #endif//__DEMO_HAL_LISTEN_H diff --git a/examples/properties/props-server.cpp b/examples/properties/props-server.cpp index a5f72c6..4c9999d 100644 --- a/examples/properties/props-server.cpp +++ b/examples/properties/props-server.cpp @@ -5,10 +5,10 @@ #include "props-server.h" #include -static const char* PROPS_SERVER_NAME = "org.freedesktop.DBus.Examples.Properties"; -static const char* PROPS_SERVER_PATH = "/org/freedesktop/DBus/Examples/Properties"; +static const char *PROPS_SERVER_NAME = "org.freedesktop.DBus.Examples.Properties"; +static const char *PROPS_SERVER_PATH = "/org/freedesktop/DBus/Examples/Properties"; -PropsServer::PropsServer( DBus::Connection& connection ) +PropsServer::PropsServer(DBus::Connection &connection) : DBus::ObjectAdaptor(connection, PROPS_SERVER_PATH) { Version = 1; @@ -16,18 +16,18 @@ PropsServer::PropsServer( DBus::Connection& connection ) } void PropsServer::on_set_property - ( DBus::InterfaceAdaptor& interface, const DBus::String& property, const DBus::Variant& value ) + (DBus::InterfaceAdaptor &interface, const std::string &property, const DBus::Variant &value) { - if(property == "Message") + if (property == "Message") { - DBus::String msg = value; + std::string msg = value; this->MessageChanged(msg); } } DBus::BusDispatcher dispatcher; -void niam( int sig ) +void niam(int sig) { dispatcher.leave(); } diff --git a/examples/properties/props-server.h b/examples/properties/props-server.h index 93d13ee..cf9ba83 100644 --- a/examples/properties/props-server.h +++ b/examples/properties/props-server.h @@ -12,10 +12,10 @@ class PropsServer { public: - PropsServer( DBus::Connection& connection ); + PropsServer(DBus::Connection &connection); void on_set_property - ( DBus::InterfaceAdaptor& interface, const DBus::String& property, const DBus::Variant& value ); + (DBus::InterfaceAdaptor &interface, const std::string &property, const DBus::Variant &value); }; #endif//__DEMO_PROPS_SERVER_H diff --git a/include/dbus-c++/connection.h b/include/dbus-c++/connection.h index b47144e..96993c9 100644 --- a/include/dbus-c++/connection.h +++ b/include/dbus-c++/connection.h @@ -72,377 +72,377 @@ public: bool operator == ( const Connection& ) const; - /*! - * \brief Adds a match rule to match messages going through the message bus. - * - * The "rule" argument is the string form of a match rule. - * - * If you pass NULL for the error, this function will not block; the match - * thus won't be added until you flush the connection, and if there's an error - * adding the match (only possible error is lack of resources in the bus), you - * won't find out about it. - * - * Normal API conventions would have the function return a boolean value - * indicating whether the error was set, but that would require blocking always - * to determine the return value. - * - * The AddMatch method is fully documented in the D-Bus specification. For - * quick reference, the format of the match rules is discussed here, but the - * specification is the canonical version of this information. - * - * Rules are specified as a string of comma separated key/value pairs. An - * example is "type='signal',sender='org.freedesktop.DBus', - * interface='org.freedesktop.DBus',member='Foo', path='/bar/foo',destination=':452345.34'" - * - * Possible keys you can match on are type, sender, interface, member, path, - * destination and numbered keys to match message args (keys are 'arg0', 'arg1', etc.). - * Omitting a key from the rule indicates a wildcard match. For instance omitting - * the member from a match rule but adding a sender would let all messages from - * that sender through regardless of the member. - * - * Matches are inclusive not exclusive so as long as one rule matches the - * message will get through. It is important to note this because every time a - * essage is received the application will be paged into memory to process it. - * This can cause performance problems such as draining batteries on embedded platforms. - * - * If you match message args ('arg0', 'arg1', and so forth) only string arguments - * will match. That is, arg0='5' means match the string "5" not the integer 5. - * - * Currently there is no way to match against non-string arguments. - * - * Matching on interface is tricky because method call messages only optionally - * specify the interface. If a message omits the interface, then it will NOT - * match if the rule specifies an interface name. This means match rules on - * method calls should not usually give an interface. - * - * However, signal messages are required to include the interface so when - * matching signals usually you should specify the interface in the match rule. - * - * For security reasons, you can match arguments only up to DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER. - * - * Match rules have a maximum length of DBUS_MAXIMUM_MATCH_RULE_LENGTH bytes. - * - * Both of these maximums are much higher than you're likely to need, they only - * exist because the D-Bus bus daemon has fixed limits on all resource usage. - * - * \param rule Textual form of match rule. - * \throw Error - */ + /*! + * \brief Adds a match rule to match messages going through the message bus. + * + * The "rule" argument is the string form of a match rule. + * + * If you pass NULL for the error, this function will not block; the match + * thus won't be added until you flush the connection, and if there's an error + * adding the match (only possible error is lack of resources in the bus), you + * won't find out about it. + * + * Normal API conventions would have the function return a boolean value + * indicating whether the error was set, but that would require blocking always + * to determine the return value. + * + * The AddMatch method is fully documented in the D-Bus specification. For + * quick reference, the format of the match rules is discussed here, but the + * specification is the canonical version of this information. + * + * Rules are specified as a string of comma separated key/value pairs. An + * example is "type='signal',sender='org.freedesktop.DBus', + * interface='org.freedesktop.DBus',member='Foo', path='/bar/foo',destination=':452345.34'" + * + * Possible keys you can match on are type, sender, interface, member, path, + * destination and numbered keys to match message args (keys are 'arg0', 'arg1', etc.). + * Omitting a key from the rule indicates a wildcard match. For instance omitting + * the member from a match rule but adding a sender would let all messages from + * that sender through regardless of the member. + * + * Matches are inclusive not exclusive so as long as one rule matches the + * message will get through. It is important to note this because every time a + * essage is received the application will be paged into memory to process it. + * This can cause performance problems such as draining batteries on embedded platforms. + * + * If you match message args ('arg0', 'arg1', and so forth) only string arguments + * will match. That is, arg0='5' means match the string "5" not the integer 5. + * + * Currently there is no way to match against non-string arguments. + * + * Matching on interface is tricky because method call messages only optionally + * specify the interface. If a message omits the interface, then it will NOT + * match if the rule specifies an interface name. This means match rules on + * method calls should not usually give an interface. + * + * However, signal messages are required to include the interface so when + * matching signals usually you should specify the interface in the match rule. + * + * For security reasons, you can match arguments only up to DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER. + * + * Match rules have a maximum length of DBUS_MAXIMUM_MATCH_RULE_LENGTH bytes. + * + * Both of these maximums are much higher than you're likely to need, they only + * exist because the D-Bus bus daemon has fixed limits on all resource usage. + * + * \param rule Textual form of match rule. + * \throw Error + */ void add_match( const char* rule ); - /*! - * \brief Removes a previously-added match rule "by value" (the most - * recently-added identical rule gets removed). - * - * The "rule" argument is the string form of a match rule. - * - * The bus compares match rules semantically, not textually, so whitespace and - * ordering don't have to be identical to the rule you passed to add_match(). - * - * \param rule Textual form of match rule. - * \throw Error - */ + /*! + * \brief Removes a previously-added match rule "by value" (the most + * recently-added identical rule gets removed). + * + * The "rule" argument is the string form of a match rule. + * + * The bus compares match rules semantically, not textually, so whitespace and + * ordering don't have to be identical to the rule you passed to add_match(). + * + * \param rule Textual form of match rule. + * \throw Error + */ void remove_match( const char* rule ); - /*! - * \brief Adds a message filter. - * - * Filters are handlers that are run on all incoming messages, prior to the - * objects registered with ObjectAdaptor::register_obj(). Filters are - * run in the order that they were added. The same handler can be added as a - * filter more than once, in which case it will be run more than once. Filters - * added during a filter callback won't be run on the message being processed. - * - * \param s The MessageSlot to add. - */ + /*! + * \brief Adds a message filter. + * + * Filters are handlers that are run on all incoming messages, prior to the + * objects registered with ObjectAdaptor::register_obj(). Filters are + * run in the order that they were added. The same handler can be added as a + * filter more than once, in which case it will be run more than once. Filters + * added during a filter callback won't be run on the message being processed. + * + * \param s The MessageSlot to add. + */ bool add_filter( MessageSlot& s); - /*! - * \brief Removes a previously-added message filter. - * - * It is a programming error to call this function for a handler that has not - * been added as a filter. If the given handler was added more than once, only - * one instance of it will be removed (the most recently-added instance). - * - * \param s The MessageSlot to remove. - */ + /*! + * \brief Removes a previously-added message filter. + * + * It is a programming error to call this function for a handler that has not + * been added as a filter. If the given handler was added more than once, only + * one instance of it will be removed (the most recently-added instance). + * + * \param s The MessageSlot to remove. + */ void remove_filter( MessageSlot& s); - /*! - * \brief Sets the unique name of the connection, as assigned by the message bus. - * - * Can only be used if you registered with the bus manually (i.e. if you did - * not call register_bus()). Can only be called once per connection. After - * the unique name is set, you can get it with unique_name(void). - * - * The only reason to use this function is to re-implement the equivalent of - * register_bus() yourself. One (probably unusual) reason to do that might - * be to do the bus registration call asynchronously instead of synchronously. - * - * \note Just use dbus_bus_get() or dbus_bus_get_private(), or worst case - * register_bus(), instead of messing with this function. There's - * really no point creating pain for yourself by doing things manually. - * (Not sure if this is yet wrapped.) - * - * It's hard to use this function safely on shared connections (created by - * Connection()) in a multithreaded application, because only one - * registration attempt can be sent to the bus. If two threads are both - * sending the registration message, there is no mechanism in libdbus itself - * to avoid sending it twice. - * - * Thus, you need a way to coordinate which thread sends the registration - * attempt; which also means you know which thread will call - * unique_name(const char*). If you don't know about all threads in the app - * (for example, if some libraries you're using might start libdbus-using - * threads), then you need to avoid using this function on shared connections. - * - * \param n The unique name. - */ + /*! + * \brief Sets the unique name of the connection, as assigned by the message bus. + * + * Can only be used if you registered with the bus manually (i.e. if you did + * not call register_bus()). Can only be called once per connection. After + * the unique name is set, you can get it with unique_name(void). + * + * The only reason to use this function is to re-implement the equivalent of + * register_bus() yourself. One (probably unusual) reason to do that might + * be to do the bus registration call asynchronously instead of synchronously. + * + * \note Just use dbus_bus_get() or dbus_bus_get_private(), or worst case + * register_bus(), instead of messing with this function. There's + * really no point creating pain for yourself by doing things manually. + * (Not sure if this is yet wrapped.) + * + * It's hard to use this function safely on shared connections (created by + * Connection()) in a multithreaded application, because only one + * registration attempt can be sent to the bus. If two threads are both + * sending the registration message, there is no mechanism in libdbus itself + * to avoid sending it twice. + * + * Thus, you need a way to coordinate which thread sends the registration + * attempt; which also means you know which thread will call + * unique_name(const char*). If you don't know about all threads in the app + * (for example, if some libraries you're using might start libdbus-using + * threads), then you need to avoid using this function on shared connections. + * + * \param n The unique name. + */ bool unique_name( const char* n ); - /*! - * \brief Gets the unique name of the connection as assigned by the message bus. - * - * Only possible after the connection has been registered with the message bus. - * All connections returned by dbus_bus_get() or dbus_bus_get_private() have - * been successfully registered. (Not sure if this is yet wrapped.) - * - * The name remains valid until the connection is freed, and should not be - * freed by the caller. - * - * Other than dbus_bus_get(), there are two ways to set the unique name; one - * is register_bus(), the other is unique_name(const char*). You are - * responsible for calling unique_name(const char*) if you register by hand - * instead of using register_bus(). - */ + /*! + * \brief Gets the unique name of the connection as assigned by the message bus. + * + * Only possible after the connection has been registered with the message bus. + * All connections returned by dbus_bus_get() or dbus_bus_get_private() have + * been successfully registered. (Not sure if this is yet wrapped.) + * + * The name remains valid until the connection is freed, and should not be + * freed by the caller. + * + * Other than dbus_bus_get(), there are two ways to set the unique name; one + * is register_bus(), the other is unique_name(const char*). You are + * responsible for calling unique_name(const char*) if you register by hand + * instead of using register_bus(). + */ const char* unique_name() const; - /*! - * \brief Registers a connection with the bus. - * - * This must be the first thing an application does when connecting to the - * message bus. If registration succeeds, the unique name will be set, and - * can be obtained using unique_name(void). - * - * This function will block until registration is complete. - * - * If the connection has already registered with the bus (determined by - * checking whether unique_name(void) returns a non-NULL value), - * then this function does nothing. - * - * If you use dbus_bus_get() or dbus_bus_get_private() this function will be - * called for you. (Not sure if this is yet wrapped.) - * - * \note Just use dbus_bus_get() or dbus_bus_get_private() instead of - * register_bus() and save yourself some pain. Using register_bus() - * manually is only useful if you have your own custom message bus not found - * in DBusBusType. - * - * If you open a bus connection by the contructor of Connection() you will have to register_bus() - * yourself, or make the appropriate registration method calls yourself. If - * you send the method calls yourself, call unique_name(const char*) with - * the unique bus name you get from the bus. - * - * For shared connections (created with dbus_connection_open()) in a - * multithreaded application, you can't really make the registration calls - * yourself, because you don't know whether some other thread is also - * registering, and the bus will kick you off if you send two registration - * messages. (TODO: how is this done in the wrapper?) - * - * If you use register_bus() however, there is a lock that keeps both - * apps from registering at the same time. - * - * The rule in a multithreaded app, then, is that register_bus() must be - * used to register, or you need to have your own locks that all threads in - * the app will respect. - * - * In a single-threaded application you can register by hand instead of using - * register_bus(), as long as you check unique_name(void) to - * see if a unique name has already been stored by another thread before you - * send the registration messages. - */ + /*! + * \brief Registers a connection with the bus. + * + * This must be the first thing an application does when connecting to the + * message bus. If registration succeeds, the unique name will be set, and + * can be obtained using unique_name(void). + * + * This function will block until registration is complete. + * + * If the connection has already registered with the bus (determined by + * checking whether unique_name(void) returns a non-NULL value), + * then this function does nothing. + * + * If you use dbus_bus_get() or dbus_bus_get_private() this function will be + * called for you. (Not sure if this is yet wrapped.) + * + * \note Just use dbus_bus_get() or dbus_bus_get_private() instead of + * register_bus() and save yourself some pain. Using register_bus() + * manually is only useful if you have your own custom message bus not found + * in DBusBusType. + * + * If you open a bus connection by the contructor of Connection() you will have to register_bus() + * yourself, or make the appropriate registration method calls yourself. If + * you send the method calls yourself, call unique_name(const char*) with + * the unique bus name you get from the bus. + * + * For shared connections (created with dbus_connection_open()) in a + * multithreaded application, you can't really make the registration calls + * yourself, because you don't know whether some other thread is also + * registering, and the bus will kick you off if you send two registration + * messages. (TODO: how is this done in the wrapper?) + * + * If you use register_bus() however, there is a lock that keeps both + * apps from registering at the same time. + * + * The rule in a multithreaded app, then, is that register_bus() must be + * used to register, or you need to have your own locks that all threads in + * the app will respect. + * + * In a single-threaded application you can register by hand instead of using + * register_bus(), as long as you check unique_name(void) to + * see if a unique name has already been stored by another thread before you + * send the registration messages. + */ bool register_bus(); - /*! - * \brief Gets whether the connection is currently open. - * - * A connection may become disconnected when the remote application closes its - * end, or exits; a connection may also be disconnected with disconnect(). - * - * There are not separate states for "closed" and "disconnected," the two - * terms are synonymous. - * - * \return true If the connection is still alive. - */ + /*! + * \brief Gets whether the connection is currently open. + * + * A connection may become disconnected when the remote application closes its + * end, or exits; a connection may also be disconnected with disconnect(). + * + * There are not separate states for "closed" and "disconnected," the two + * terms are synonymous. + * + * \return true If the connection is still alive. + */ bool connected() const; - /*! - * \brief Closes a private connection, so no further data can be sent or received. - * - * This disconnects the transport (such as a socket) underlying the connection. - * - * Attempts to send messages after closing a connection are safe, but will - * result in error replies generated locally in libdbus. - * - * This function does not affect the connection's reference count. It's safe - * to close a connection more than once; all calls after the first do nothing. - * It's impossible to "reopen" a connection, a new connection must be created. - * This function may result in a call to the DBusDispatchStatusFunction set - * with Private::init(), as the disconnect - * message it generates needs to be dispatched. - * - * If a connection is dropped by the remote application, it will close itself. - * - * You must close a connection prior to releasing the last reference to the - * connection. - * - * You may not close a shared connection. Connections created with - * dbus_connection_open() or dbus_bus_get() are shared. These connections are - * owned by libdbus, and applications should only unref them, never close them. - * Applications can know it is safe to unref these connections because libdbus - * will be holding a reference as long as the connection is open. Thus, either - * the connection is closed and it is OK to drop the last reference, or the - * connection is open and the app knows it does not have the last reference. - * - * Connections created with dbus_connection_open_private() or - * dbus_bus_get_private() are not kept track of or referenced by libdbus. - * The creator of these connections is responsible for calling - * dbus_connection_close() prior to releasing the last reference, if the - * connection is not already disconnected. - * - * \todo dbus_connection_disconnect() was removed in dbus 0.9x. Maybe this - * function should be renamed to close(). - */ + /*! + * \brief Closes a private connection, so no further data can be sent or received. + * + * This disconnects the transport (such as a socket) underlying the connection. + * + * Attempts to send messages after closing a connection are safe, but will + * result in error replies generated locally in libdbus. + * + * This function does not affect the connection's reference count. It's safe + * to close a connection more than once; all calls after the first do nothing. + * It's impossible to "reopen" a connection, a new connection must be created. + * This function may result in a call to the DBusDispatchStatusFunction set + * with Private::init(), as the disconnect + * message it generates needs to be dispatched. + * + * If a connection is dropped by the remote application, it will close itself. + * + * You must close a connection prior to releasing the last reference to the + * connection. + * + * You may not close a shared connection. Connections created with + * dbus_connection_open() or dbus_bus_get() are shared. These connections are + * owned by libdbus, and applications should only unref them, never close them. + * Applications can know it is safe to unref these connections because libdbus + * will be holding a reference as long as the connection is open. Thus, either + * the connection is closed and it is OK to drop the last reference, or the + * connection is open and the app knows it does not have the last reference. + * + * Connections created with dbus_connection_open_private() or + * dbus_bus_get_private() are not kept track of or referenced by libdbus. + * The creator of these connections is responsible for calling + * dbus_connection_close() prior to releasing the last reference, if the + * connection is not already disconnected. + * + * \todo dbus_connection_disconnect() was removed in dbus 0.9x. Maybe this + * function should be renamed to close(). + */ void disconnect(); - /*! - * \brief Set whether _exit() should be called when the connection receives a - * disconnect signal. - * - * The call to _exit() comes after any handlers for the disconnect signal run; - * handlers can cancel the exit by calling this function. - * - * By default, exit_on_disconnect is false; but for message bus connections - * returned from dbus_bus_get() it will be toggled on by default. - * - * \param exit true If _exit() should be called after a disconnect signal. - */ + /*! + * \brief Set whether _exit() should be called when the connection receives a + * disconnect signal. + * + * The call to _exit() comes after any handlers for the disconnect signal run; + * handlers can cancel the exit by calling this function. + * + * By default, exit_on_disconnect is false; but for message bus connections + * returned from dbus_bus_get() it will be toggled on by default. + * + * \param exit true If _exit() should be called after a disconnect signal. + */ void exit_on_disconnect( bool exit ); - /*! - * \brief Blocks until the outgoing message queue is empty. - */ + /*! + * \brief Blocks until the outgoing message queue is empty. + */ void flush(); - /*! - * \brief Adds a message to the outgoing message queue. - * - * Does not block to write the message to the network; that happens - * asynchronously. To force the message to be written, call - * dbus_connection_flush(). Because this only queues the message, the only - * reason it can fail is lack of memory. Even if the connection is disconnected, - * no error will be returned. - * - * If the function fails due to lack of memory, it returns FALSE. The function - * will never fail for other reasons; even if the connection is disconnected, - * you can queue an outgoing message, though obviously it won't be sent. - * - * The message serial is used by the remote application to send a reply; see - * Message::serial() or the D-Bus specification. - * - * \param msg The Message to write. + /*! + * \brief Adds a message to the outgoing message queue. + * + * Does not block to write the message to the network; that happens + * asynchronously. To force the message to be written, call + * dbus_connection_flush(). Because this only queues the message, the only + * reason it can fail is lack of memory. Even if the connection is disconnected, + * no error will be returned. + * + * If the function fails due to lack of memory, it returns FALSE. The function + * will never fail for other reasons; even if the connection is disconnected, + * you can queue an outgoing message, though obviously it won't be sent. + * + * The message serial is used by the remote application to send a reply; see + * Message::serial() or the D-Bus specification. + * + * \param msg The Message to write. * \param serial Return location for message serial, or NULL if you don't care. - * \return true On success. - */ + * \return true On success. + */ bool send( const Message& msg, unsigned int* serial = NULL ); - /*! - * \brief Sends a message and blocks a certain time period while waiting for a reply. - * - * This function does not reenter the main loop, i.e. messages other than the - * reply are queued up but not processed. This function is used to invoke - * method calls on a remote object. - * - * If a normal reply is received, it is returned, and removed from the - * incoming message queue. If it is not received, NULL is returned and the - * error is set to DBUS_ERROR_NO_REPLY. If an error reply is received, it is - * converted to a DBusError and returned as an error, then the reply message - * is deleted and NULL is returned. If something else goes wrong, result is - * set to whatever is appropriate, such as DBUS_ERROR_NO_MEMORY or DBUS_ERROR_DISCONNECTED. - * - * \warning While this function blocks the calling thread will not be - * processing the incoming message queue. This means you can end up - * deadlocked if the application you're talking to needs you to reply - * to a method. To solve this, either avoid the situation, block in a - * separate thread from the main connection-dispatching thread, or - * use PendingCall to avoid blocking. - * - * \param msg The Message to write. - * \param timeout Timeout in milliseconds (omit for default). - * \throw Error - */ + /*! + * \brief Sends a message and blocks a certain time period while waiting for a reply. + * + * This function does not reenter the main loop, i.e. messages other than the + * reply are queued up but not processed. This function is used to invoke + * method calls on a remote object. + * + * If a normal reply is received, it is returned, and removed from the + * incoming message queue. If it is not received, NULL is returned and the + * error is set to DBUS_ERROR_NO_REPLY. If an error reply is received, it is + * converted to a DBusError and returned as an error, then the reply message + * is deleted and NULL is returned. If something else goes wrong, result is + * set to whatever is appropriate, such as DBUS_ERROR_NO_MEMORY or DBUS_ERROR_DISCONNECTED. + * + * \warning While this function blocks the calling thread will not be + * processing the incoming message queue. This means you can end up + * deadlocked if the application you're talking to needs you to reply + * to a method. To solve this, either avoid the situation, block in a + * separate thread from the main connection-dispatching thread, or + * use PendingCall to avoid blocking. + * + * \param msg The Message to write. + * \param timeout Timeout in milliseconds (omit for default). + * \throw Error + */ Message send_blocking( Message& msg, int timeout = -1); - /*! - * \brief Queues a message to send, as with send(), but also - * returns a DBusPendingCall used to receive a reply to the message. - * - * If no reply is received in the given timeout_milliseconds, this function - * expires the pending reply and generates a synthetic error reply (generated - * in-process, not by the remote application) indicating that a timeout occurred. - * - * A PendingCall will see a reply message before any filters or registered - * object path handlers. See Connection::Private::do_dispatch() in dbus documentation - * for details on when handlers are run. (here: Connection::Private::do_dispatch()) - * - * A PendingCall will always see exactly one reply message, unless it's - * cancelled with PendingCall::cancel(). - * - * If -1 is passed for the timeout, a sane default timeout is used. -1 is - * typically the best value for the timeout for this reason, unless you want - * a very short or very long timeout. There is no way to avoid a timeout - * entirely, other than passing INT_MAX for the timeout to mean "very long - * timeout." libdbus clamps an INT_MAX timeout down to a few hours timeout though. - * - * \param msg The Message to write. - * \param timeout Timeout in milliseconds (omit for default). - * \throw ErrorNoMemory - */ + /*! + * \brief Queues a message to send, as with send(), but also + * returns a DBusPendingCall used to receive a reply to the message. + * + * If no reply is received in the given timeout_milliseconds, this function + * expires the pending reply and generates a synthetic error reply (generated + * in-process, not by the remote application) indicating that a timeout occurred. + * + * A PendingCall will see a reply message before any filters or registered + * object path handlers. See Connection::Private::do_dispatch() in dbus documentation + * for details on when handlers are run. (here: Connection::Private::do_dispatch()) + * + * A PendingCall will always see exactly one reply message, unless it's + * cancelled with PendingCall::cancel(). + * + * If -1 is passed for the timeout, a sane default timeout is used. -1 is + * typically the best value for the timeout for this reason, unless you want + * a very short or very long timeout. There is no way to avoid a timeout + * entirely, other than passing INT_MAX for the timeout to mean "very long + * timeout." libdbus clamps an INT_MAX timeout down to a few hours timeout though. + * + * \param msg The Message to write. + * \param timeout Timeout in milliseconds (omit for default). + * \throw ErrorNoMemory + */ PendingCall send_async( Message& msg, int timeout = -1); void request_name( const char* name, int flags = 0 ); - /*! - * \brief Asks the bus whether a certain name has an owner. - * - * Using this can easily result in a race condition, since an owner can appear - * or disappear after you call this. - * - * If you want to request a name, just request it; if you want to avoid - * replacing a current owner, don't specify DBUS_NAME_FLAG_REPLACE_EXISTING - * and you will get an error if there's already an owner. - * - * \param name The name. - * \throw Error - */ + /*! + * \brief Asks the bus whether a certain name has an owner. + * + * Using this can easily result in a race condition, since an owner can appear + * or disappear after you call this. + * + * If you want to request a name, just request it; if you want to avoid + * replacing a current owner, don't specify DBUS_NAME_FLAG_REPLACE_EXISTING + * and you will get an error if there's already an owner. + * + * \param name The name. + * \throw Error + */ bool has_name( const char* name ); - /*! - * \brief Starts a service that will request ownership of the given name. - * - * The returned result will be one of be one of DBUS_START_REPLY_SUCCESS or - * DBUS_START_REPLY_ALREADY_RUNNING if successful. Pass NULL if you don't - * care about the result. - * - * The flags parameter is for future expansion, currently you should specify 0. - * - * It's often easier to avoid explicitly starting services, and just send a - * method call to the service's bus name instead. Method calls start a service - * to handle them by default unless you call dbus_message_set_auto_start() to - * disable this behavior. - * - * \todo dbus_message_set_auto_start() not yet wrapped! - */ + /*! + * \brief Starts a service that will request ownership of the given name. + * + * The returned result will be one of be one of DBUS_START_REPLY_SUCCESS or + * DBUS_START_REPLY_ALREADY_RUNNING if successful. Pass NULL if you don't + * care about the result. + * + * The flags parameter is for future expansion, currently you should specify 0. + * + * It's often easier to avoid explicitly starting services, and just send a + * method call to the service's bus name instead. Method calls start a service + * to handle them by default unless you call dbus_message_set_auto_start() to + * disable this behavior. + * + * \todo dbus_message_set_auto_start() not yet wrapped! + */ bool start_service( const char* name, unsigned long flags ); const std::vector& names(); diff --git a/include/dbus-c++/debug.h b/include/dbus-c++/debug.h index 0daeb9d..5079a7f 100644 --- a/include/dbus-c++/debug.h +++ b/include/dbus-c++/debug.h @@ -31,7 +31,7 @@ namespace DBus { -typedef void (*LogFunction)(const char* format, ...); +typedef void (*LogFunction)(const char *format, ...); extern DXXAPI LogFunction debug_log; diff --git a/include/dbus-c++/dispatcher.h b/include/dbus-c++/dispatcher.h index 3a50864..5a19773 100644 --- a/include/dbus-c++/dispatcher.h +++ b/include/dbus-c++/dispatcher.h @@ -38,49 +38,49 @@ public: class Internal; - Timeout( Internal* i ); + Timeout(Internal *i); virtual ~Timeout(){} /*! - * \brief Gets the timeout interval. - * - * The dbus_timeout_handle() should be called each time this interval elapses, - * starting after it elapses once. - * - * The interval may change during the life of the timeout; if so, the timeout - * will be disabled and re-enabled (calling the "timeout toggled function") to - * notify you of the change. - * + * \brief Gets the timeout interval. + * + * The dbus_timeout_handle() should be called each time this interval elapses, + * starting after it elapses once. + * + * The interval may change during the life of the timeout; if so, the timeout + * will be disabled and re-enabled (calling the "timeout toggled function") to + * notify you of the change. + * * return The interval in miliseconds. */ int interval() const; bool enabled() const; - /*! - * \brief Calls the timeout handler for this timeout. - * - * This function should be called when the timeout occurs. - * - * If this function returns FALSE, then there wasn't enough memory to handle - * the timeout. Typically just letting the timeout fire again next time it - * naturally times out is an adequate response to that problem, but you could - * try to do more if you wanted. - * - * return false If there wasn't enough memory. - */ + /*! + * \brief Calls the timeout handler for this timeout. + * + * This function should be called when the timeout occurs. + * + * If this function returns FALSE, then there wasn't enough memory to handle + * the timeout. Typically just letting the timeout fire again next time it + * naturally times out is an adequate response to that problem, but you could + * try to do more if you wanted. + * + * return false If there wasn't enough memory. + */ bool handle(); virtual void toggle() = 0; private: - DXXAPILOCAL Timeout( const Timeout& ); + DXXAPILOCAL Timeout(const Timeout &); private: - Internal* _int; + Internal *_int; }; class DXXAPI Watch @@ -89,63 +89,63 @@ public: class Internal; - Watch( Internal* i ); + Watch(Internal *i); virtual ~Watch(){} - /*! - * \brief A main loop could poll this descriptor to integrate dbus-c++. - * - * This function calls dbus_watch_get_socket() on win32 and - * dbus_watch_get_unix_fd() on all other systems. (see dbus documentation) - * - * @return The file descriptor. - */ + /*! + * \brief A main loop could poll this descriptor to integrate dbus-c++. + * + * This function calls dbus_watch_get_socket() on win32 and + * dbus_watch_get_unix_fd() on all other systems. (see dbus documentation) + * + * @return The file descriptor. + */ int descriptor() const; - /*! - * \brief Gets flags from DBusWatchFlags indicating what conditions should be - * monitored on the file descriptor. - * - * The flags returned will only contain DBUS_WATCH_READABLE and DBUS_WATCH_WRITABLE, - * never DBUS_WATCH_HANGUP or DBUS_WATCH_ERROR; all watches implicitly include - * a watch for hangups, errors, and other exceptional conditions. - * - * @return The conditions to watch. - */ + /*! + * \brief Gets flags from DBusWatchFlags indicating what conditions should be + * monitored on the file descriptor. + * + * The flags returned will only contain DBUS_WATCH_READABLE and DBUS_WATCH_WRITABLE, + * never DBUS_WATCH_HANGUP or DBUS_WATCH_ERROR; all watches implicitly include + * a watch for hangups, errors, and other exceptional conditions. + * + * @return The conditions to watch. + */ int flags() const; bool enabled() const; - /*! - * \brief Called to notify the D-Bus library when a previously-added watch - * is ready for reading or writing, or has an exception such as a hangup. - * - * If this function returns FALSE, then the file descriptor may still be - * ready for reading or writing, but more memory is needed in order to do the - * reading or writing. If you ignore the FALSE return, your application may - * spin in a busy loop on the file descriptor until memory becomes available, - * but nothing more catastrophic should happen. - * - * dbus_watch_handle() cannot be called during the DBusAddWatchFunction, as the - * connection will not be ready to handle that watch yet. - * - * It is not allowed to reference a DBusWatch after it has been passed to remove_function. - * - * @param flags The poll condition using DBusWatchFlags values. - * @return false If there wasn't enough memory. - */ - bool handle( int flags ); + /*! + * \brief Called to notify the D-Bus library when a previously-added watch + * is ready for reading or writing, or has an exception such as a hangup. + * + * If this function returns FALSE, then the file descriptor may still be + * ready for reading or writing, but more memory is needed in order to do the + * reading or writing. If you ignore the FALSE return, your application may + * spin in a busy loop on the file descriptor until memory becomes available, + * but nothing more catastrophic should happen. + * + * dbus_watch_handle() cannot be called during the DBusAddWatchFunction, as the + * connection will not be ready to handle that watch yet. + * + * It is not allowed to reference a DBusWatch after it has been passed to remove_function. + * + * @param flags The poll condition using DBusWatchFlags values. + * @return false If there wasn't enough memory. + */ + bool handle(int flags); virtual void toggle() = 0; private: - DXXAPILOCAL Watch( const Watch& ); + DXXAPILOCAL Watch(const Watch &); private: - Internal* _int; + Internal *_int; }; class DXXAPI Dispatcher @@ -155,7 +155,7 @@ public: virtual ~Dispatcher() {} - void queue_connection( Connection::Private* ); + void queue_connection(Connection::Private *); void dispatch_pending(); @@ -163,13 +163,13 @@ public: virtual void leave() = 0; - virtual Timeout* add_timeout( Timeout::Internal* ) = 0; + virtual Timeout *add_timeout(Timeout::Internal *) = 0; - virtual void rem_timeout( Timeout* ) = 0; + virtual void rem_timeout(Timeout *) = 0; - virtual Watch* add_watch( Watch::Internal* ) = 0; + virtual Watch *add_watch(Watch::Internal *) = 0; - virtual void rem_watch( Watch* ) = 0; + virtual void rem_watch(Watch *) = 0; struct Private; @@ -179,7 +179,7 @@ private: Connection::PrivatePList _pending_queue; }; -extern DXXAPI Dispatcher* default_dispatcher; +extern DXXAPI Dispatcher *default_dispatcher; /* classes for multithreading support */ @@ -198,7 +198,7 @@ public: protected: - Internal* _int; + Internal *_int; }; class DXXAPI CondVar @@ -207,9 +207,9 @@ public: virtual ~CondVar() {} - virtual void wait( Mutex* ) = 0; + virtual void wait(Mutex *) = 0; - virtual bool wait_timeout( Mutex*, int timeout ) = 0; + virtual bool wait_timeout(Mutex *, int timeout) = 0; virtual void wake_one() = 0; @@ -219,27 +219,27 @@ public: protected: - Internal* _int; + Internal *_int; }; #ifndef DBUS_HAS_RECURSIVE_MUTEX -typedef Mutex* (*MutexNewFn)(); -typedef bool (*MutexFreeFn)( Mutex* mx ); -typedef bool (*MutexLockFn)( Mutex* mx ); -typedef void (*MutexUnlockFn)( Mutex* mx ); +typedef Mutex *(*MutexNewFn)(); +typedef bool (*MutexFreeFn)(Mutex *mx); +typedef bool (*MutexLockFn)(Mutex *mx); +typedef void (*MutexUnlockFn)(Mutex *mx); #else -typedef Mutex* (*MutexNewFn)(); -typedef void (*MutexFreeFn)( Mutex* mx ); -typedef void (*MutexLockFn)( Mutex* mx ); -typedef void (*MutexUnlockFn)( Mutex* mx ); +typedef Mutex *(*MutexNewFn)(); +typedef void (*MutexFreeFn)(Mutex *mx); +typedef void (*MutexLockFn)(Mutex *mx); +typedef void (*MutexUnlockFn)(Mutex *mx); #endif//DBUS_HAS_RECURSIVE_MUTEX -typedef CondVar* (*CondVarNewFn)(); -typedef void (*CondVarFreeFn)( CondVar* cv ); -typedef void (*CondVarWaitFn)( CondVar* cv, Mutex* mx ); -typedef bool (*CondVarWaitTimeoutFn)( CondVar* cv, Mutex* mx, int timeout ); -typedef void (*CondVarWakeOneFn)( CondVar* cv ); -typedef void (*CondVarWakeAllFn)( CondVar* cv ); +typedef CondVar *(*CondVarNewFn)(); +typedef void (*CondVarFreeFn)(CondVar *cv); +typedef void (*CondVarWaitFn)(CondVar *cv, Mutex *mx); +typedef bool (*CondVarWaitTimeoutFn)(CondVar *cv, Mutex *mx, int timeout); +typedef void (*CondVarWakeOneFn)(CondVar *cv); +typedef void (*CondVarWakeAllFn)(CondVar *cv); #ifdef DBUS_HAS_THREADS_INIT_DEFAULT void DXXAPI _init_threading(); @@ -261,52 +261,52 @@ struct Threading ); } - static Mutex* mutex_new() + static Mutex *mutex_new() { return new Mx; } - static void mutex_free( Mutex* mx ) + static void mutex_free(Mutex *mx) { delete mx; } - static void mutex_lock( Mutex* mx ) + static void mutex_lock(Mutex *mx) { mx->lock(); } - static void mutex_unlock( Mutex* mx ) + static void mutex_unlock(Mutex *mx) { mx->unlock(); } - static CondVar* condvar_new() + static CondVar *condvar_new() { return new Cv; } - static void condvar_free( CondVar* cv ) + static void condvar_free(CondVar *cv) { delete cv; } - static void condvar_wait( CondVar* cv, Mutex* mx ) + static void condvar_wait(CondVar *cv, Mutex *mx) { cv->wait(mx); } - static bool condvar_wait_timeout( CondVar* cv, Mutex* mx, int timeout ) + static bool condvar_wait_timeout(CondVar *cv, Mutex *mx, int timeout) { return cv->wait_timeout(mx, timeout); } - static void condvar_wake_one( CondVar* cv ) + static void condvar_wake_one(CondVar *cv) { cv->wake_one(); } - static void condvar_wake_all( CondVar* cv ) + static void condvar_wake_all(CondVar *cv) { cv->wake_all(); } diff --git a/include/dbus-c++/error.h b/include/dbus-c++/error.h index f4ff416..8caeca7 100644 --- a/include/dbus-c++/error.h +++ b/include/dbus-c++/error.h @@ -42,21 +42,21 @@ public: Error(); - Error( InternalError& ); + Error(InternalError &); - Error( const char* name, const char* message ); + Error(const char *name, const char *message); - Error( Message& ); + Error(Message &); ~Error() throw(); - const char* what() const throw(); + const char *what() const throw(); - const char* name() const; + const char *name() const; - const char* message() const; + const char *message() const; - void set( const char* name, const char* message ); + void set(const char *name, const char *message); // parameters MUST be static strings bool is_set() const; @@ -73,210 +73,210 @@ private: struct DXXAPI ErrorFailed : public Error { - ErrorFailed( const char* message ) + ErrorFailed(const char *message) : Error("org.freedesktop.DBus.Error.Failed", message) {} }; struct DXXAPI ErrorNoMemory : public Error { - ErrorNoMemory( const char* message ) + ErrorNoMemory(const char *message) : Error("org.freedesktop.DBus.Error.NoMemory", message) {} }; struct DXXAPI ErrorServiceUnknown : public Error { - ErrorServiceUnknown( const char* message ) + ErrorServiceUnknown(const char *message) : Error("org.freedesktop.DBus.Error.ServiceUnknown", message) {} }; struct DXXAPI ErrorNameHasNoOwner : public Error { - ErrorNameHasNoOwner( const char* message ) + ErrorNameHasNoOwner(const char *message) : Error("org.freedesktop.DBus.Error.NameHasNoOwner", message) {} }; struct DXXAPI ErrorNoReply : public Error { - ErrorNoReply( const char* message ) + ErrorNoReply(const char *message) : Error("org.freedesktop.DBus.Error.NoReply", message) {} }; struct DXXAPI ErrorIOError : public Error { - ErrorIOError( const char* message ) + ErrorIOError(const char *message) : Error("org.freedesktop.DBus.Error.IOError", message) {} }; struct DXXAPI ErrorBadAddress : public Error { - ErrorBadAddress( const char* message ) + ErrorBadAddress(const char *message) : Error("org.freedesktop.DBus.Error.BadAddress", message) {} }; struct DXXAPI ErrorNotSupported : public Error { - ErrorNotSupported( const char* message ) + ErrorNotSupported(const char *message) : Error("org.freedesktop.DBus.Error.NotSupported", message) {} }; struct DXXAPI ErrorLimitsExceeded : public Error { - ErrorLimitsExceeded( const char* message ) + ErrorLimitsExceeded(const char *message) : Error("org.freedesktop.DBus.Error.LimitsExceeded", message) {} }; struct DXXAPI ErrorAccessDenied : public Error { - ErrorAccessDenied( const char* message ) + ErrorAccessDenied(const char *message) : Error("org.freedesktop.DBus.Error.AccessDenied", message) {} }; struct DXXAPI ErrorAuthFailed : public Error { - ErrorAuthFailed( const char* message ) + ErrorAuthFailed(const char *message) : Error("org.freedesktop.DBus.Error.AuthFailed", message) {} }; struct DXXAPI ErrorNoServer : public Error { - ErrorNoServer( const char* message ) + ErrorNoServer(const char *message) : Error("org.freedesktop.DBus.Error.NoServer", message) {} }; struct DXXAPI ErrorTimeout : public Error { - ErrorTimeout( const char* message ) + ErrorTimeout(const char *message) : Error("org.freedesktop.DBus.Error.Timeout", message) {} }; struct DXXAPI ErrorNoNetwork : public Error { - ErrorNoNetwork( const char* message ) + ErrorNoNetwork(const char *message) : Error("org.freedesktop.DBus.Error.NoNetwork", message) {} }; struct DXXAPI ErrorAddressInUse : public Error { - ErrorAddressInUse( const char* message ) + ErrorAddressInUse(const char *message) : Error("org.freedesktop.DBus.Error.AddressInUse", message) {} }; struct DXXAPI ErrorDisconnected : public Error { - ErrorDisconnected( const char* message ) + ErrorDisconnected(const char *message) : Error("org.freedesktop.DBus.Error.Disconnected", message) {} }; struct DXXAPI ErrorInvalidArgs : public Error { - ErrorInvalidArgs( const char* message ) + ErrorInvalidArgs(const char *message) : Error("org.freedesktop.DBus.Error.InvalidArgs", message) {} }; struct DXXAPI ErrorFileNotFound : public Error { - ErrorFileNotFound( const char* message ) + ErrorFileNotFound(const char *message) : Error("org.freedesktop.DBus.Error.FileNotFound", message) {} }; struct DXXAPI ErrorUnknownMethod : public Error { - ErrorUnknownMethod( const char* message ) + ErrorUnknownMethod(const char *message) : Error("org.freedesktop.DBus.Error.UnknownMethod", message) {} }; struct DXXAPI ErrorTimedOut : public Error { - ErrorTimedOut( const char* message ) + ErrorTimedOut(const char *message) : Error("org.freedesktop.DBus.Error.TimedOut", message) {} }; struct DXXAPI ErrorMatchRuleNotFound : public Error { - ErrorMatchRuleNotFound( const char* message ) + ErrorMatchRuleNotFound(const char *message) : Error("org.freedesktop.DBus.Error.MatchRuleNotFound", message) {} }; struct DXXAPI ErrorMatchRuleInvalid : public Error { - ErrorMatchRuleInvalid( const char* message ) + ErrorMatchRuleInvalid(const char *message) : Error("org.freedesktop.DBus.Error.MatchRuleInvalid", message) {} }; struct DXXAPI ErrorSpawnExecFailed : public Error { - ErrorSpawnExecFailed( const char* message ) + ErrorSpawnExecFailed(const char *message) : Error("org.freedesktop.DBus.Error.Spawn.ExecFailed", message) {} }; struct DXXAPI ErrorSpawnForkFailed : public Error { - ErrorSpawnForkFailed( const char* message ) + ErrorSpawnForkFailed(const char *message) : Error("org.freedesktop.DBus.Error.Spawn.ForkFailed", message) {} }; struct DXXAPI ErrorSpawnChildExited : public Error { - ErrorSpawnChildExited( const char* message ) + ErrorSpawnChildExited(const char *message) : Error("org.freedesktop.DBus.Error.Spawn.ChildExited", message) {} }; struct DXXAPI ErrorSpawnChildSignaled : public Error { - ErrorSpawnChildSignaled( const char* message ) + ErrorSpawnChildSignaled(const char *message) : Error("org.freedesktop.DBus.Error.Spawn.ChildSignaled", message) {} }; struct DXXAPI ErrorSpawnFailed : public Error { - ErrorSpawnFailed( const char* message ) + ErrorSpawnFailed(const char *message) : Error("org.freedesktop.DBus.Error.Spawn.Failed", message) {} }; struct DXXAPI ErrorInvalidSignature : public Error { - ErrorInvalidSignature( const char* message ) + ErrorInvalidSignature(const char *message) : Error("org.freedesktop.DBus.Error.InvalidSignature", message) {} }; struct DXXAPI ErrorUnixProcessIdUnknown : public Error { - ErrorUnixProcessIdUnknown( const char* message ) + ErrorUnixProcessIdUnknown(const char *message) : Error("org.freedesktop.DBus.Error.UnixProcessIdUnknown", message) {} }; struct DXXAPI ErrorSELinuxSecurityContextUnknown : public Error { - ErrorSELinuxSecurityContextUnknown( const char* message ) + ErrorSELinuxSecurityContextUnknown(const char *message) : Error("org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown", message) {} }; diff --git a/include/dbus-c++/eventloop-integration.h b/include/dbus-c++/eventloop-integration.h index 0b3f3a8..645471a 100644 --- a/include/dbus-c++/eventloop-integration.h +++ b/include/dbus-c++/eventloop-integration.h @@ -41,7 +41,7 @@ class BusDispatcher; class DXXAPI BusTimeout : public Timeout, public DefaultTimeout { - BusTimeout( Timeout::Internal*, BusDispatcher* ); + BusTimeout(Timeout::Internal *, BusDispatcher *); void toggle(); @@ -50,7 +50,7 @@ friend class BusDispatcher; class DXXAPI BusWatch : public Watch, public DefaultWatch { - BusWatch( Watch::Internal*, BusDispatcher* ); + BusWatch(Watch::Internal *, BusDispatcher *); void toggle(); @@ -73,17 +73,17 @@ public: virtual void do_iteration(); - virtual Timeout* add_timeout( Timeout::Internal* ); + virtual Timeout *add_timeout(Timeout::Internal *); - virtual void rem_timeout( Timeout* ); + virtual void rem_timeout(Timeout *); - virtual Watch* add_watch( Watch::Internal* ); + virtual Watch *add_watch(Watch::Internal *); - virtual void rem_watch( Watch* ); + virtual void rem_watch(Watch *); - void watch_ready( DefaultWatch& ); + void watch_ready(DefaultWatch &); - void timeout_expired( DefaultTimeout& ); + void timeout_expired(DefaultTimeout &); private: diff --git a/include/dbus-c++/eventloop.h b/include/dbus-c++/eventloop.h index 90e77cf..ac44a0f 100644 --- a/include/dbus-c++/eventloop.h +++ b/include/dbus-c++/eventloop.h @@ -39,10 +39,10 @@ namespace DBus { /* - * these Default* classes implement a very simple event loop which + * these Default *classes implement a very simple event loop which * is used here as the default main loop, if you want to hook - * a different one use the Bus* classes in eventloop-integration.h - * or the Glib::Bus* classes as a reference + * a different one use the Bus *classes in eventloop-integration.h + * or the Glib::Bus *classes as a reference */ class DefaultMainLoop; @@ -51,7 +51,7 @@ class DXXAPI DefaultTimeout { public: - DefaultTimeout( int interval, bool repeat, DefaultMainLoop* ); + DefaultTimeout(int interval, bool repeat, DefaultMainLoop *); virtual ~DefaultTimeout(); @@ -64,10 +64,10 @@ public: bool repeat(){ return _repeat; } void repeat(bool r){ _repeat = r; } - void* data(){ return _data; } - void data(void* d){ _data = d; } + void *data(){ return _data; } + void data(void *d){ _data = d; } - Slot expired; + Slot expired; private: @@ -78,20 +78,20 @@ private: double _expiration; - void* _data; + void *_data; - DefaultMainLoop* _disp; + DefaultMainLoop *_disp; friend class DefaultMainLoop; }; -typedef std::list< DefaultTimeout* > DefaultTimeouts; +typedef std::list< DefaultTimeout *> DefaultTimeouts; class DXXAPI DefaultWatch { public: - DefaultWatch( int fd, int flags, DefaultMainLoop* ); + DefaultWatch(int fd, int flags, DefaultMainLoop *); virtual ~DefaultWatch(); @@ -101,14 +101,14 @@ public: int descriptor(){ return _fd; } int flags(){ return _flags; } - void flags( int f ){ _flags = f; } + void flags(int f){ _flags = f; } int state(){ return _state; } - void* data(){ return _data; } - void data(void* d){ _data = d; } + void *data(){ return _data; } + void data(void *d){ _data = d; } - Slot ready; + Slot ready; private: @@ -118,14 +118,14 @@ private: int _flags; int _state; - void* _data; + void *_data; - DefaultMainLoop* _disp; + DefaultMainLoop *_disp; friend class DefaultMainLoop; }; -typedef std::list< DefaultWatch* > DefaultWatches; +typedef std::list< DefaultWatch *> DefaultWatches; class DXXAPI DefaultMutex { diff --git a/include/dbus-c++/glib-integration.h b/include/dbus-c++/glib-integration.h index a5e8bba..034beb0 100644 --- a/include/dbus-c++/glib-integration.h +++ b/include/dbus-c++/glib-integration.h @@ -41,13 +41,13 @@ class DXXAPI BusTimeout : public Timeout { private: - BusTimeout( Timeout::Internal*, GMainContext* ); + BusTimeout(Timeout::Internal *, GMainContext *, int); ~BusTimeout(); void toggle(); - static gboolean timeout_handler( gpointer ); + static gboolean timeout_handler(gpointer); void _enable(); @@ -55,8 +55,9 @@ private: private: - GSource* _source; - GMainContext* _ctx; + GSource *_source; + GMainContext *_ctx; + int _priority; friend class BusDispatcher; }; @@ -65,13 +66,13 @@ class DXXAPI BusWatch : public Watch { private: - BusWatch( Watch::Internal*, GMainContext* ); + BusWatch(Watch::Internal *, GMainContext *, int); ~BusWatch(); void toggle(); - static gboolean watch_handler( gpointer ); + static gboolean watch_handler(gpointer); void _enable(); @@ -79,8 +80,9 @@ private: private: - GSource* _source; - GMainContext* _ctx; + GSource *_source; + GMainContext *_ctx; + int _priority; friend class BusDispatcher; }; @@ -88,25 +90,29 @@ friend class BusDispatcher; class DXXAPI BusDispatcher : public Dispatcher { public: - BusDispatcher() : _ctx(NULL) {} - void attach( GMainContext* ); + BusDispatcher() : _ctx(NULL), _priority(G_PRIORITY_DEFAULT) {} + + void attach(GMainContext *); void enter() {} void leave() {} - Timeout* add_timeout( Timeout::Internal* ); + Timeout *add_timeout(Timeout::Internal *); - void rem_timeout( Timeout* ); + void rem_timeout(Timeout *); - Watch* add_watch( Watch::Internal* ); + Watch *add_watch(Watch::Internal *); - void rem_watch( Watch* ); + void rem_watch(Watch *); + + void set_priority(int priority); private: - GMainContext* _ctx; + GMainContext *_ctx; + int _priority; }; } /* namespace Glib */ diff --git a/include/dbus-c++/interface.h b/include/dbus-c++/interface.h index faf6da6..fa9179f 100644 --- a/include/dbus-c++/interface.h +++ b/include/dbus-c++/interface.h @@ -54,22 +54,22 @@ class ObjectAdaptor; class InterfaceAdaptor; class SignalMessage; -typedef std::map InterfaceAdaptorTable; +typedef std::map InterfaceAdaptorTable; class DXXAPI AdaptorBase { public: - virtual const ObjectAdaptor* object() const = 0 ; + virtual const ObjectAdaptor *object() const = 0 ; protected: - InterfaceAdaptor* find_interface( const std::string& name ); + InterfaceAdaptor *find_interface(const std::string &name); virtual ~AdaptorBase() {} - virtual void _emit_signal( SignalMessage& ) = 0; + virtual void _emit_signal(SignalMessage &) = 0; InterfaceAdaptorTable _interfaces; }; @@ -81,22 +81,22 @@ class ObjectProxy; class InterfaceProxy; class CallMessage; -typedef std::map InterfaceProxyTable; +typedef std::map InterfaceProxyTable; class DXXAPI ProxyBase { public: - virtual const ObjectProxy* object() const = 0 ; + virtual const ObjectProxy *object() const = 0 ; protected: - InterfaceProxy* find_interface( const std::string& name ); + InterfaceProxy *find_interface(const std::string &name); virtual ~ProxyBase() {} - virtual Message _invoke_method( CallMessage& ) = 0; + virtual Message _invoke_method(CallMessage &) = 0; InterfaceProxyTable _interfaces; }; @@ -105,11 +105,11 @@ class DXXAPI Interface { public: - Interface( const std::string& name ); + Interface(const std::string &name); virtual ~Interface(); - inline const std::string& name() const; + inline const std::string &name() const; private: @@ -119,7 +119,7 @@ private: /* */ -const std::string& Interface::name() const +const std::string &Interface::name() const { return _name; } @@ -127,23 +127,23 @@ const std::string& Interface::name() const /* */ -typedef std::map< std::string, Slot > MethodTable; +typedef std::map< std::string, Slot > MethodTable; class DXXAPI InterfaceAdaptor : public Interface, public virtual AdaptorBase { public: - InterfaceAdaptor( const std::string& name ); + InterfaceAdaptor(const std::string &name); - Message dispatch_method( const CallMessage& ); + Message dispatch_method(const CallMessage &); - void emit_signal( const SignalMessage& ); + void emit_signal(const SignalMessage &); - Variant* get_property( const std::string& name ); + Variant *get_property(const std::string &name); - void set_property( const std::string& name, Variant& value ); + void set_property(const std::string &name, Variant &value); - virtual IntrospectedInterface* const introspect() const + virtual IntrospectedInterface *const introspect() const { return NULL; } @@ -157,17 +157,17 @@ protected: /* */ -typedef std::map< std::string, Slot > SignalTable; +typedef std::map< std::string, Slot > SignalTable; class DXXAPI InterfaceProxy : public Interface, public virtual ProxyBase { public: - InterfaceProxy( const std::string& name ); + InterfaceProxy(const std::string &name); - Message invoke_method( const CallMessage& ); + Message invoke_method(const CallMessage &); - bool dispatch_signal( const SignalMessage& ); + bool dispatch_signal(const SignalMessage &); protected: @@ -176,17 +176,17 @@ protected: # define register_method(interface, method, callback) \ InterfaceAdaptor::_methods[ #method ] = \ - new ::DBus::Callback< interface, ::DBus::Message, const ::DBus::CallMessage& >(this, & interface :: callback ); + new ::DBus::Callback< interface, ::DBus::Message, const ::DBus::CallMessage &>(this, & interface :: callback); # define bind_property(variable, type, can_read, can_write) \ InterfaceAdaptor::_properties[ #variable ].read = can_read; \ InterfaceAdaptor::_properties[ #variable ].write = can_write; \ InterfaceAdaptor::_properties[ #variable ].sig = type; \ - variable.bind( InterfaceAdaptor::_properties[ #variable ] ); + variable.bind(InterfaceAdaptor::_properties[ #variable ]); # define connect_signal(interface, signal, callback) \ InterfaceProxy::_signals[ #signal ] = \ - new ::DBus::Callback< interface, void, const ::DBus::SignalMessage& >(this, & interface :: callback ); + new ::DBus::Callback< interface, void, const ::DBus::SignalMessage &>(this, & interface :: callback); } /* namespace DBus */ diff --git a/include/dbus-c++/introspection.h b/include/dbus-c++/introspection.h index 51a9003..b52dca7 100644 --- a/include/dbus-c++/introspection.h +++ b/include/dbus-c++/introspection.h @@ -34,31 +34,31 @@ namespace DBus { struct DXXAPI IntrospectedArgument { - const char* name; - const char* type; + const char *name; + const char *type; const bool in; }; struct DXXAPI IntrospectedMethod { - const char* name; - const IntrospectedArgument* args; + const char *name; + const IntrospectedArgument *args; }; struct DXXAPI IntrospectedProperty { - const char* name; - const char* type; + const char *name; + const char *type; const bool read; const bool write; }; struct DXXAPI IntrospectedInterface { - const char* name; - const IntrospectedMethod* methods; - const IntrospectedMethod* signals; - const IntrospectedProperty* properties; + const char *name; + const IntrospectedMethod *methods; + const IntrospectedMethod *signals; + const IntrospectedProperty *properties; }; class DXXAPI IntrospectableAdaptor : public InterfaceAdaptor @@ -67,11 +67,11 @@ public: IntrospectableAdaptor(); - Message Introspect( const CallMessage& ); + Message Introspect(const CallMessage &); protected: - IntrospectedInterface* const introspect() const; + IntrospectedInterface *const introspect() const; }; class DXXAPI IntrospectableProxy : public InterfaceProxy diff --git a/include/dbus-c++/message.h b/include/dbus-c++/message.h index 082a402..6f6ae4c 100644 --- a/include/dbus-c++/message.h +++ b/include/dbus-c++/message.h @@ -54,104 +54,104 @@ public: bool has_next(); - MessageIter& operator ++(); + MessageIter &operator ++(); MessageIter operator ++(int); - bool append_byte( unsigned char byte ); + bool append_byte(unsigned char byte); unsigned char get_byte(); - bool append_bool( bool b ); + bool append_bool(bool b); bool get_bool(); - bool append_int16( signed short i ); + bool append_int16(signed short i); signed short get_int16(); - bool append_uint16( unsigned short u ); + bool append_uint16(unsigned short u); unsigned short get_uint16(); - bool append_int32( signed int i ); + bool append_int32(signed int i); signed int get_int32(); - bool append_uint32( unsigned int u ); + bool append_uint32(unsigned int u); unsigned int get_uint32(); - bool append_int64( signed long long i ); + bool append_int64(signed long long i); signed long long get_int64(); - bool append_uint64( unsigned long long i ); + bool append_uint64(unsigned long long i); unsigned long long get_uint64(); - bool append_double( double d ); + bool append_double(double d); double get_double(); - bool append_string( const char* chars ); + bool append_string(const char *chars); - const char* get_string(); + const char *get_string(); - bool append_path( const char* chars ); + bool append_path(const char *chars); - const char* get_path(); + const char *get_path(); - bool append_signature( const char* chars ); + bool append_signature(const char *chars); - const char* get_signature(); + const char *get_signature(); - char* signature() const; //returned string must be manually free()'d + char *signature() const; //returned string must be manually free()'d MessageIter recurse(); - bool append_array( char type, const void* ptr, size_t length ); + bool append_array(char type, const void *ptr, size_t length); int array_type(); - int get_array( void* ptr ); + int get_array(void *ptr); bool is_array(); bool is_dict(); - MessageIter new_array( const char* sig ); + MessageIter new_array(const char *sig); - MessageIter new_variant( const char* sig ); + MessageIter new_variant(const char *sig); MessageIter new_struct(); MessageIter new_dict_entry(); - void close_container( MessageIter& container ); + void close_container(MessageIter &container); - void copy_data( MessageIter& to ); + void copy_data(MessageIter &to); - Message& msg() const + Message &msg() const { return *_msg; } private: - DXXAPILOCAL MessageIter(Message& msg) : _msg(&msg) {} + DXXAPILOCAL MessageIter(Message &msg) : _msg(&msg) {} - DXXAPILOCAL bool append_basic( int type_id, void* value ); + DXXAPILOCAL bool append_basic(int type_id, void *value); - DXXAPILOCAL void get_basic( int type_id, void* ptr ); + DXXAPILOCAL void get_basic(int type_id, void *ptr); private: /* I'm sorry, but don't want to include dbus.h in the public api */ - unsigned char _iter[sizeof(void*)*3+sizeof(int)*11]; + unsigned char _iter[sizeof(void *)*3+sizeof(int)*11]; - Message* _msg; + Message *_msg; friend class Message; }; @@ -162,13 +162,13 @@ public: struct Private; - Message( Private*, bool incref = true ); + Message(Private *, bool incref = true); - Message( const Message& m ); + Message(const Message &m); ~Message(); - Message& operator = ( const Message& m ); + Message &operator = (const Message &m); Message copy(); @@ -178,25 +178,25 @@ public: int reply_serial() const; - bool reply_serial( int ); + bool reply_serial(int); - const char* sender() const; + const char *sender() const; - bool sender( const char* s ); + bool sender(const char *s); - const char* destination() const; + const char *destination() const; - bool destination( const char* s ); + bool destination(const char *s); bool is_error() const; - bool is_signal( const char* interface, const char* member ) const; + bool is_signal(const char *interface, const char *member) const; MessageIter reader() const; MessageIter writer(); - bool append( int first_type, ... ); + bool append(int first_type, ...); void terminate(); @@ -226,13 +226,13 @@ public: ErrorMessage(); - ErrorMessage( const Message&, const char* name, const char* message ); + ErrorMessage(const Message &, const char *name, const char *message); - const char* name() const; + const char *name() const; - bool name( const char* n ); + bool name(const char *n); - bool operator == ( const ErrorMessage& ) const; + bool operator == (const ErrorMessage &) const; }; /* @@ -242,25 +242,25 @@ class DXXAPI SignalMessage : public Message { public: - SignalMessage( const char* name ); + SignalMessage(const char *name); - SignalMessage( const char* path, const char* interface, const char* name ); + SignalMessage(const char *path, const char *interface, const char *name); - const char* interface() const; + const char *interface() const; - bool interface( const char* i ); + bool interface(const char *i); - const char* member() const; + const char *member() const; - bool member( const char* m ); + bool member(const char *m); - const char* path() const; + const char *path() const; - char** path_split() const; + char ** path_split() const; - bool path( const char* p ); + bool path(const char *p); - bool operator == ( const SignalMessage& ) const; + bool operator == (const SignalMessage &) const; }; /* @@ -272,25 +272,25 @@ public: CallMessage(); - CallMessage( const char* dest, const char* path, const char* iface, const char* method ); + CallMessage(const char *dest, const char *path, const char *iface, const char *method); - const char* interface() const; + const char *interface() const; - bool interface( const char* i ); + bool interface(const char *i); - const char* member() const; + const char *member() const; - bool member( const char* m ); + bool member(const char *m); - const char* path() const; + const char *path() const; - char** path_split() const; + char ** path_split() const; - bool path( const char* p ); + bool path(const char *p); - const char* signature() const; + const char *signature() const; - bool operator == ( const CallMessage& ) const; + bool operator == (const CallMessage &) const; }; /* @@ -300,9 +300,9 @@ class DXXAPI ReturnMessage : public Message { public: - ReturnMessage( const CallMessage& callee ); + ReturnMessage(const CallMessage &callee); - const char* signature() const; + const char *signature() const; }; } /* namespace DBus */ diff --git a/include/dbus-c++/object.h b/include/dbus-c++/object.h index 033fc3d..2075142 100644 --- a/include/dbus-c++/object.h +++ b/include/dbus-c++/object.h @@ -42,21 +42,21 @@ class DXXAPI Object { protected: - Object( Connection& conn, const Path& path, const char* service ); + Object(Connection &conn, const Path &path, const char *service); public: virtual ~Object(); - inline const DBus::Path& path() const; + inline const DBus::Path &path() const; - inline const std::string& service() const; + inline const std::string &service() const; - inline Connection& conn(); + inline Connection &conn(); private: - DXXAPILOCAL virtual bool handle_message( const Message& ) = 0; + DXXAPILOCAL virtual bool handle_message(const Message &) = 0; DXXAPILOCAL virtual void register_obj() = 0; DXXAPILOCAL virtual void unregister_obj() = 0; @@ -70,17 +70,17 @@ private: /* */ -Connection& Object::conn() +Connection &Object::conn() { return _conn; } -const DBus::Path& Object::path() const +const DBus::Path &Object::path() const { return _path; } -const std::string& Object::service() const +const std::string &Object::service() const { return _service; } @@ -101,26 +101,26 @@ public: class ObjectAdaptor; -typedef std::list ObjectAdaptorPList; +typedef std::list ObjectAdaptorPList; typedef std::list ObjectPathList; class DXXAPI ObjectAdaptor : public Object, public virtual AdaptorBase { public: - static ObjectAdaptor* from_path( const Path& path ); + static ObjectAdaptor *from_path(const Path &path); - static ObjectAdaptorPList from_path_prefix( const std::string& prefix ); + static ObjectAdaptorPList from_path_prefix(const std::string &prefix); - static ObjectPathList child_nodes_from_prefix( const std::string& prefix ); + static ObjectPathList child_nodes_from_prefix(const std::string &prefix); struct Private; - ObjectAdaptor( Connection& conn, const Path& path ); + ObjectAdaptor(Connection &conn, const Path &path); ~ObjectAdaptor(); - inline const ObjectAdaptor* object() const; + inline const ObjectAdaptor *object() const; protected: @@ -128,57 +128,57 @@ protected: { public: - inline MessageIter& writer(); + inline MessageIter &writer(); - inline Tag* tag(); + inline Tag *tag(); private: - Continuation( Connection& conn, const CallMessage& call, const Tag* tag ); + Continuation(Connection &conn, const CallMessage &call, const Tag *tag); Connection _conn; CallMessage _call; MessageIter _writer; ReturnMessage _return; - const Tag* _tag; + const Tag *_tag; friend class ObjectAdaptor; }; - void return_later( const Tag* tag ); + void return_later(const Tag *tag); - void return_now( Continuation* ret ); + void return_now(Continuation *ret); - void return_error( Continuation* ret, const Error error ); + void return_error(Continuation *ret, const Error error); - Continuation* find_continuation( const Tag* tag ); + Continuation *find_continuation(const Tag *tag); private: - void _emit_signal( SignalMessage& ); + void _emit_signal(SignalMessage &); - bool handle_message( const Message& ); + bool handle_message(const Message &); void register_obj(); void unregister_obj(); - typedef std::map ContinuationMap; + typedef std::map ContinuationMap; ContinuationMap _continuations; friend struct Private; }; -const ObjectAdaptor* ObjectAdaptor::object() const +const ObjectAdaptor *ObjectAdaptor::object() const { return this; } -Tag* ObjectAdaptor::Continuation::tag() +Tag *ObjectAdaptor::Continuation::tag() { - return const_cast(_tag); + return const_cast(_tag); } -MessageIter& ObjectAdaptor::Continuation::writer() +MessageIter &ObjectAdaptor::Continuation::writer() { return _writer; } @@ -188,23 +188,23 @@ MessageIter& ObjectAdaptor::Continuation::writer() class ObjectProxy; -typedef std::list ObjectProxyPList; +typedef std::list ObjectProxyPList; class DXXAPI ObjectProxy : public Object, public virtual ProxyBase { public: - ObjectProxy( Connection& conn, const Path& path, const char* service = "" ); + ObjectProxy(Connection &conn, const Path &path, const char *service = ""); ~ObjectProxy(); - inline const ObjectProxy* object() const; + inline const ObjectProxy *object() const; private: - Message _invoke_method( CallMessage& ); + Message _invoke_method(CallMessage &); - bool handle_message( const Message& ); + bool handle_message(const Message &); void register_obj(); void unregister_obj(); @@ -214,7 +214,7 @@ private: MessageSlot _filtered; }; -const ObjectProxy* ObjectProxy::object() const +const ObjectProxy *ObjectProxy::object() const { return this; } diff --git a/include/dbus-c++/pendingcall.h b/include/dbus-c++/pendingcall.h index 48a6bbf..f5e77f1 100644 --- a/include/dbus-c++/pendingcall.h +++ b/include/dbus-c++/pendingcall.h @@ -41,85 +41,85 @@ public: struct Private; - PendingCall( Private* ); + PendingCall(Private *); - PendingCall( const PendingCall& ); + PendingCall(const PendingCall &); virtual ~PendingCall(); - PendingCall& operator = ( const PendingCall& ); + PendingCall &operator = (const PendingCall &); - /*! - * \brief Checks whether the pending call has received a reply yet, or not. - * - * \return true If a reply has been received. - */ + /*! + * \brief Checks whether the pending call has received a reply yet, or not. + * + * \return true If a reply has been received. + */ bool completed(); - /*! - * \brief Cancels the pending call, such that any reply or error received will - * just be ignored. - * - * Drops the dbus library's internal reference to the DBusPendingCall so will - * free the call if nobody else is holding a reference. However you usually - * get a reference from Connection::send_async() so probably your app - * owns a ref also. - * - * Note that canceling a pending call will not simulate a timed-out call; if a - * call times out, then a timeout error reply is received. If you cancel the - * call, no reply is received unless the the reply was already received before - * you canceled. - */ + /*! + * \brief Cancels the pending call, such that any reply or error received will + * just be ignored. + * + * Drops the dbus library's internal reference to the DBusPendingCall so will + * free the call if nobody else is holding a reference. However you usually + * get a reference from Connection::send_async() so probably your app + * owns a ref also. + * + * Note that canceling a pending call will not simulate a timed-out call; if a + * call times out, then a timeout error reply is received. If you cancel the + * call, no reply is received unless the the reply was already received before + * you canceled. + */ void cancel(); - /*! - * \brief Block until the pending call is completed. - * - * The blocking is as with Connection::send_blocking(); it - * does not enter the main loop or process other messages, it simply waits for - * the reply in question. - * - * If the pending call is already completed, this function returns immediately. - */ + /*! + * \brief Block until the pending call is completed. + * + * The blocking is as with Connection::send_blocking(); it + * does not enter the main loop or process other messages, it simply waits for + * the reply in question. + * + * If the pending call is already completed, this function returns immediately. + */ void block(); - /*! - * \brief Stores a pointer on a PendingCall, along with an optional function to - * be used for freeing the data when the data is set again, or when the - * pending call is finalized. - * - * The slot is allocated automatic. - * - * \param data The data to store. - * \throw ErrorNoMemory - */ + /*! + * \brief Stores a pointer on a PendingCall, along with an optional function to + * be used for freeing the data when the data is set again, or when the + * pending call is finalized. + * + * The slot is allocated automatic. + * + * \param data The data to store. + * \throw ErrorNoMemory + */ void data( void* data ); - /*! - * \brief Retrieves data previously set with dbus_pending_call_set_data(). - * - * The slot must still be allocated (must not have been freed). - * - * \return The data, or NULL if not found. - */ - void* data(); - - /*! - * \return The data slot. - */ - Slot& slot(); - - /*! - * \brief Gets the reply - * - * Ownership of the reply message passes to the caller. This function can only - * be called once per pending call, since the reply message is tranferred to - * the caller. - * - * \return The reply Message. - * \throw ErrorNoReply + /*! + * \brief Retrieves data previously set with dbus_pending_call_set_data(). + * + * The slot must still be allocated (must not have been freed). + * + * \return The data, or NULL if not found. */ - Message steal_reply(); + void *data(); + + /*! + * \return The data slot. + */ + Slot& slot(); + + /*! + * \brief Gets the reply + * + * Ownership of the reply message passes to the caller. This function can only + * be called once per pending call, since the reply message is tranferred to + * the caller. + * + * \return The reply Message. + * \throw ErrorNoReply + */ + Message steal_reply(); private: diff --git a/include/dbus-c++/property.h b/include/dbus-c++/property.h index 60a997f..a608b93 100644 --- a/include/dbus-c++/property.h +++ b/include/dbus-c++/property.h @@ -41,7 +41,7 @@ public: PropertyAdaptor() : _data(0) {} - void bind( PropertyData& data ) + void bind(PropertyData &data) { _data = &data; } @@ -51,7 +51,7 @@ public: return (T)_data->value; } - PropertyAdaptor& operator = ( const T& t ) + PropertyAdaptor &operator = (const T &t) { _data->value.clear(); MessageIter wi = _data->value.writer(); @@ -61,7 +61,7 @@ public: private: - PropertyData* _data; + PropertyData *_data; }; struct IntrospectedInterface; @@ -72,19 +72,19 @@ public: PropertiesAdaptor(); - Message Get( const CallMessage& ); + Message Get(const CallMessage &); - Message Set( const CallMessage& ); + Message Set(const CallMessage &); protected: - virtual void on_get_property( InterfaceAdaptor& interface, const String& property, Variant& value ) + virtual void on_get_property(InterfaceAdaptor &interface, const std::string &property, Variant &value) {} - virtual void on_set_property( InterfaceAdaptor& interface, const String& property, const Variant& value ) + virtual void on_set_property(InterfaceAdaptor &interface, const std::string &property, const Variant &value) {} - IntrospectedInterface* const introspect() const; + IntrospectedInterface *const introspect() const; }; class DXXAPI PropertiesProxy : public InterfaceProxy @@ -93,9 +93,9 @@ public: PropertiesProxy(); - Variant Get( const String& interface, const String& property ); + Variant Get(const std::string &interface, const std::string &property); - void Set( const String& interface, const String& property, const Variant& value ); + void Set(const std::string &interface, const std::string &property, const Variant &value); }; } /* namespace DBus */ diff --git a/include/dbus-c++/refptr_impl.h b/include/dbus-c++/refptr_impl.h index 8d1a593..a0f71ed 100644 --- a/include/dbus-c++/refptr_impl.h +++ b/include/dbus-c++/refptr_impl.h @@ -33,14 +33,14 @@ namespace DBus { template -RefPtrI::RefPtrI( T* ptr ) +RefPtrI::RefPtrI(T *ptr) : __ptr(ptr) {} template RefPtrI::~RefPtrI() { - if(__cnt.one()) delete __ptr; + if (__cnt.one()) delete __ptr; } } /* namespace DBus */ diff --git a/include/dbus-c++/server.h b/include/dbus-c++/server.h index 9115fa9..1918cd4 100644 --- a/include/dbus-c++/server.h +++ b/include/dbus-c++/server.h @@ -45,15 +45,15 @@ class DXXAPI Server { public: - Server( const char* address ); + Server(const char *address); - Dispatcher* setup( Dispatcher* ); + Dispatcher *setup(Dispatcher *); virtual ~Server(); bool listening() const; - bool operator == ( const Server& ) const; + bool operator == (const Server &) const; void disconnect(); @@ -61,10 +61,10 @@ public: protected: - Server( const Server& s ) + Server(const Server &s) {} - virtual void on_new_connection( Connection& c ) = 0; + virtual void on_new_connection(Connection &c) = 0; private: diff --git a/include/dbus-c++/types.h b/include/dbus-c++/types.h index 8e617aa..d2a62e6 100644 --- a/include/dbus-c++/types.h +++ b/include/dbus-c++/types.h @@ -27,6 +27,7 @@ #include "dbus-c++-config.h" +#include #include #include #include @@ -38,23 +39,12 @@ namespace DBus { -typedef unsigned char Byte; -typedef bool Bool; -typedef signed short Int16; -typedef unsigned short UInt16; -typedef signed int Int32; -typedef unsigned int UInt32; -typedef signed long long Int64; -typedef unsigned long long UInt64; -typedef double Double; -typedef std::string String; - struct DXXAPI Path : public std::string { Path() {} - Path( const std::string& s ) : std::string(s) {} - Path( const char* c ) : std::string(c) {} - Path& operator = ( std::string& s ) + Path(const std::string &s) : std::string(s) {} + Path(const char *c) : std::string(c) {} + Path &operator = (std::string &s) { std::string::operator = (s); return *this; @@ -64,9 +54,9 @@ struct DXXAPI Path : public std::string struct DXXAPI Signature : public std::string { Signature() {} - Signature( const std::string& s ) : std::string(s) {} - Signature( const char* c ) : std::string(c) {} - Signature& operator = ( std::string& s ) + Signature(const std::string &s) : std::string(s) {} + Signature(const char *c) : std::string(c) {} + Signature &operator = (std::string &s) { std::string::operator = (s); return *this; @@ -81,9 +71,9 @@ public: Variant(); - Variant( MessageIter& it ); + Variant(MessageIter &it); - Variant& operator = ( const Variant& v ); + Variant &operator = (const Variant &v); const Signature signature() const; @@ -129,7 +119,7 @@ struct Struct }; template -inline bool dict_has_key( const std::map& map, const K& key ) +inline bool dict_has_key(const std::map& map, const K &key) { return map.find(key) != map.end(); } @@ -144,17 +134,17 @@ struct type } }; -template <> struct type { static std::string sig(){ return "v"; } }; -template <> struct type { static std::string sig(){ return "y"; } }; -template <> struct type { static std::string sig(){ return "b"; } }; -template <> struct type { static std::string sig(){ return "n"; } }; -template <> struct type { static std::string sig(){ return "q"; } }; -template <> struct type { static std::string sig(){ return "i"; } }; -template <> struct type { static std::string sig(){ return "u"; } }; -template <> struct type { static std::string sig(){ return "x"; } }; -template <> struct type { static std::string sig(){ return "t"; } }; -template <> struct type { static std::string sig(){ return "d"; } }; -template <> struct type { static std::string sig(){ return "s"; } }; +template <> struct type { static std::string sig(){ return "v"; } }; +template <> struct type { static std::string sig(){ return "y"; } }; +template <> struct type { static std::string sig(){ return "b"; } }; +template <> struct type { static std::string sig(){ return "n"; } }; +template <> struct type { static std::string sig(){ return "q"; } }; +template <> struct type { static std::string sig(){ return "i"; } }; +template <> struct type { static std::string sig(){ return "u"; } }; +template <> struct type { static std::string sig(){ return "x"; } }; +template <> struct type { static std::string sig(){ return "t"; } }; +template <> struct type { static std::string sig(){ return "d"; } }; +template <> struct type { static std::string sig(){ return "s"; } }; template <> struct type { static std::string sig(){ return "o"; } }; template <> struct type { static std::string sig(){ return "g"; } }; template <> struct type { static std::string sig(){ return ""; } }; @@ -196,91 +186,91 @@ struct type< Struct > } /* namespace DBus */ -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Invalid& ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const DBus::Invalid &) { return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Byte& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const uint8_t &val) { iter.append_byte(val); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Bool& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const bool &val) { iter.append_bool(val); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Int16& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const int16_t& val) { iter.append_int16(val); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::UInt16& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const uint16_t& val) { iter.append_uint16(val); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Int32& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const int32_t& val) { iter.append_int32(val); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::UInt32& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const uint32_t& val) { iter.append_uint32(val); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Int64& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const int64_t& val) { iter.append_int64(val); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::UInt64& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const uint64_t& val) { iter.append_uint64(val); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Double& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const double &val) { iter.append_double(val); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::String& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const std::string &val) { iter.append_string(val.c_str()); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Path& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const DBus::Path &val) { iter.append_path(val.c_str()); return iter; } -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Signature& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const DBus::Signature &val) { iter.append_signature(val.c_str()); return iter; } template -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::vector& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const std::vector& val) { const std::string sig = DBus::type::sig(); DBus::MessageIter ait = iter.new_array(sig.c_str()); typename std::vector::const_iterator vit; - for(vit = val.begin(); vit != val.end(); ++vit) + for (vit = val.begin(); vit != val.end(); ++vit) { ait << *vit; } @@ -290,7 +280,7 @@ inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::vect } template<> -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::vector& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const std::vector& val) { DBus::MessageIter ait = iter.new_array("y"); ait.append_array('y', &val.front(), val.size()); @@ -299,13 +289,13 @@ inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::vect } template -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const std::map& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const std::map& val) { const std::string sig = "{" + DBus::type::sig() + DBus::type::sig() + "}"; DBus::MessageIter ait = iter.new_array(sig.c_str()); typename std::map::const_iterator mit; - for(mit = val.begin(); mit != val.end(); ++mit) + for (mit = val.begin(); mit != val.end(); ++mit) { DBus::MessageIter eit = ait.new_dict_entry(); @@ -328,7 +318,7 @@ template < typename T7, typename T8 > -inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Struct& val ) +inline DBus::MessageIter &operator << (DBus::MessageIter &iter, const DBus::Struct& val) { /* const std::string sig = DBus::type::sig() + DBus::type::sig() + DBus::type::sig() + DBus::type::sig() + @@ -343,97 +333,97 @@ inline DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Str return iter; } -extern DXXAPI DBus::MessageIter& operator << ( DBus::MessageIter& iter, const DBus::Variant& val ); +extern DXXAPI DBus::MessageIter &operator << (DBus::MessageIter &iter, const DBus::Variant &val); /* */ -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Invalid& ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, DBus::Invalid &) { return iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Byte& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, uint8_t &val) { val = iter.get_byte(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Bool& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, bool &val) { val = iter.get_bool(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Int16& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, int16_t& val) { val = iter.get_int16(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::UInt16& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, uint16_t& val) { val = iter.get_uint16(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Int32& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, int32_t& val) { val = iter.get_int32(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::UInt32& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, uint32_t& val) { val = iter.get_uint32(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Int64& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, int64_t& val) { val = iter.get_int64(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::UInt64& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, uint64_t& val) { val = iter.get_uint64(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Double& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, double &val) { val = iter.get_double(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::String& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, std::string &val) { val = iter.get_string(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Path& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, DBus::Path &val) { val = iter.get_path(); return ++iter; } -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Signature& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, DBus::Signature &val) { val = iter.get_signature(); return ++iter; } template -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, std::vector& val) { - if(!iter.is_array()) + if (!iter.is_array()) throw DBus::ErrorInvalidArgs("array expected"); DBus::MessageIter ait = iter.recurse(); - while(!ait.at_end()) + while (!ait.at_end()) { E elem; @@ -445,17 +435,17 @@ inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector& } template<> -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, std::vector& val) { - if(!iter.is_array()) + if (!iter.is_array()) throw DBus::ErrorInvalidArgs("array expected"); - if(iter.array_type() != 'y') + if (iter.array_type() != 'y') throw DBus::ErrorInvalidArgs("byte-array expected"); DBus::MessageIter ait = iter.recurse(); - DBus::Byte* array; + uint8_t *array; size_t length = ait.get_array(&array); val.insert(val.end(), array, array+length); @@ -464,14 +454,14 @@ inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::vector -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, std::map& val ) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, std::map& val) { - if(!iter.is_dict()) + if (!iter.is_dict()) throw DBus::ErrorInvalidArgs("dictionary value expected"); DBus::MessageIter mit = iter.recurse(); - while(!mit.at_end()) + while (!mit.at_end()) { K key; V value; @@ -497,7 +487,7 @@ template < typename T7, typename T8 > -inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Struct& val) +inline DBus::MessageIter &operator >> (DBus::MessageIter &iter, DBus::Struct& val) { DBus::MessageIter sit = iter.recurse(); @@ -506,7 +496,7 @@ inline DBus::MessageIter& operator >> ( DBus::MessageIter& iter, DBus::Struct> ( DBus::MessageIter& iter, DBus::Variant& val ); +extern DXXAPI DBus::MessageIter &operator >> (DBus::MessageIter &iter, DBus::Variant &val); #endif//__DBUSXX_TYPES_H diff --git a/include/dbus-c++/util.h b/include/dbus-c++/util.h index e95d352..9133adb 100644 --- a/include/dbus-c++/util.h +++ b/include/dbus-c++/util.h @@ -46,7 +46,7 @@ public: (*__ref) = 1; } - RefCnt( const RefCnt& rc ) + RefCnt(const RefCnt &rc) { __ref = rc.__ref; ref(); @@ -57,7 +57,7 @@ public: unref(); } - RefCnt& operator = ( const RefCnt& ref ) + RefCnt &operator = (const RefCnt &ref) { ref.ref(); unref(); @@ -85,12 +85,12 @@ private: { -- (*__ref); - if( (*__ref) < 0 ) + if ((*__ref) < 0) { debug_log("%p: refcount dropped below zero!", __ref); } - if( noref() ) + if (noref()) { delete __ref; } @@ -110,15 +110,15 @@ class RefPtrI // RefPtr to incomplete type { public: - RefPtrI( T* ptr = 0 ); + RefPtrI(T *ptr = 0); ~RefPtrI(); - RefPtrI& operator = ( const RefPtrI& ref ) + RefPtrI &operator = (const RefPtrI &ref) { - if( this != &ref ) + if (this != &ref) { - if(__cnt.one()) delete __ptr; + if (__cnt.one()) delete __ptr; __ptr = ref.__ptr; __cnt = ref.__cnt; @@ -126,28 +126,28 @@ public: return *this; } - T& operator *() const + T &operator *() const { return *__ptr; } - T* operator ->() const + T *operator ->() const { - if(__cnt.noref()) return 0; + if (__cnt.noref()) return 0; return __ptr; } - T* get() const + T *get() const { - if(__cnt.noref()) return 0; + if (__cnt.noref()) return 0; return __ptr; } private: - T* __ptr; + T *__ptr; RefCnt __cnt; }; @@ -156,20 +156,20 @@ class RefPtr { public: - RefPtr( T* ptr = 0) + RefPtr(T *ptr = 0) : __ptr(ptr) {} ~RefPtr() { - if(__cnt.one()) delete __ptr; + if (__cnt.one()) delete __ptr; } - RefPtr& operator = ( const RefPtr& ref ) + RefPtr &operator = (const RefPtr &ref) { - if( this != &ref ) + if (this != &ref) { - if(__cnt.one()) delete __ptr; + if (__cnt.one()) delete __ptr; __ptr = ref.__ptr; __cnt = ref.__cnt; @@ -177,28 +177,28 @@ public: return *this; } - T& operator *() const + T &operator *() const { return *__ptr; } - T* operator ->() const + T *operator ->() const { - if(__cnt.noref()) return 0; + if (__cnt.noref()) return 0; return __ptr; } - T* get() const + T *get() const { - if(__cnt.noref()) return 0; + if (__cnt.noref()) return 0; return __ptr; } private: - T* __ptr; + T *__ptr; RefCnt __cnt; }; @@ -211,7 +211,7 @@ class Callback_Base { public: - virtual R call( P param ) const = 0; + virtual R call(P param) const = 0; virtual ~Callback_Base() {} @@ -222,21 +222,21 @@ class Slot { public: - Slot& operator = ( Callback_Base* s ) + Slot &operator = (Callback_Base* s) { _cb = s; return *this; } - R operator()( P param ) const + R operator()(P param) const { - /*if(_cb.get())*/ return _cb->call(param); + /*if (_cb.get())*/ return _cb->call(param); } - R call( P param ) const + R call(P param) const { - /*if(_cb.get())*/ return _cb->call(param); + /*if (_cb.get())*/ return _cb->call(param); } bool empty() @@ -256,18 +256,18 @@ public: typedef R (C::*M)(P); - Callback( C* c, M m ) + Callback(C *c, M m) : _c(c), _m(m) {} - R call( P param ) const + R call(P param) const { - /*if(_c)*/ return (_c->*_m)(param); + /*if (_c)*/ return (_c->*_m)(param); } private: - C* _c; M _m; + C *_c; M _m; }; } /* namespace DBus */ diff --git a/src/connection.cpp b/src/connection.cpp index 16d951f..4620594 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -44,19 +44,19 @@ using namespace DBus; -Connection::Private::Private( DBusConnection* c, Server::Private* s ) +Connection::Private::Private(DBusConnection *c, Server::Private *s) : conn(c) , dispatcher(0), server(s) { init(); } -Connection::Private::Private( DBusBusType type ) +Connection::Private::Private(DBusBusType type) { InternalError e; conn = dbus_bus_get_private(type, e); - if(e) throw Error(e); + if (e) throw Error(e); init(); } @@ -67,11 +67,11 @@ Connection::Private::~Private() detach_server(); - if(dbus_connection_get_is_connected(conn)) + if (dbus_connection_get_is_connected(conn)) { std::vector::iterator i = names.begin(); - while(i != names.end()) + while (i != names.end()) { debug_log("%s: releasing bus name %s", dbus_bus_get_unique_name(conn), i->c_str()); dbus_bus_release_name(conn, i->c_str(), NULL); @@ -87,7 +87,7 @@ void Connection::Private::init() dbus_connection_ref(conn); dbus_connection_ref(conn); //todo: the library has to own another reference - disconn_filter = new Callback( + disconn_filter = new Callback( this, &Connection::Private::disconn_filter_function ); @@ -99,17 +99,17 @@ void Connection::Private::init() void Connection::Private::detach_server() { -/* Server::Private* tmp = server; +/* Server::Private *tmp = server; server = NULL; - if(tmp) + if (tmp) { ConnectionList::iterator i; - for(i = tmp->connections.begin(); i != tmp->connections.end(); ++i) + for (i = tmp->connections.begin(); i != tmp->connections.end(); ++i) { - if(i->_pvt.get() == this) + if (i->_pvt.get() == this) { tmp->connections.erase(i); break; @@ -122,7 +122,7 @@ bool Connection::Private::do_dispatch() { debug_log("dispatching on %p", conn); - if(!dbus_connection_get_is_connected(conn)) + if (!dbus_connection_get_is_connected(conn)) { debug_log("connection terminated"); @@ -134,11 +134,11 @@ bool Connection::Private::do_dispatch() return dbus_connection_dispatch(conn) != DBUS_DISPATCH_DATA_REMAINS; } -void Connection::Private::dispatch_status_stub( DBusConnection* dc, DBusDispatchStatus status, void* data ) +void Connection::Private::dispatch_status_stub(DBusConnection *dc, DBusDispatchStatus status, void *data) { - Private* p = static_cast(data); + Private *p = static_cast(data); - switch(status) + switch (status) { case DBUS_DISPATCH_DATA_REMAINS: debug_log("some dispatching to do on %p", dc); @@ -155,9 +155,9 @@ void Connection::Private::dispatch_status_stub( DBusConnection* dc, DBusDispatch } } -DBusHandlerResult Connection::Private::message_filter_stub( DBusConnection* conn, DBusMessage* dmsg, void* data ) +DBusHandlerResult Connection::Private::message_filter_stub(DBusConnection *conn, DBusMessage *dmsg, void *data) { - MessageSlot* slot = static_cast(data); + MessageSlot *slot = static_cast(data); Message msg = Message(new Message::Private(dmsg)); @@ -166,9 +166,9 @@ DBusHandlerResult Connection::Private::message_filter_stub( DBusConnection* conn : DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } -bool Connection::Private::disconn_filter_function( const Message& msg ) +bool Connection::Private::disconn_filter_function(const Message &msg) { - if(msg.is_signal(DBUS_INTERFACE_LOCAL,"Disconnected")) + if (msg.is_signal(DBUS_INTERFACE_LOCAL,"Disconnected")) { debug_log("%p disconnected by local bus", conn); dbus_connection_close(conn); @@ -193,14 +193,14 @@ Connection Connection::ActivationBus() return Connection(new Private(DBUS_BUS_STARTER)); } -Connection::Connection( const char* address, bool priv ) +Connection::Connection(const char *address, bool priv) { InternalError e; - DBusConnection* conn = priv + DBusConnection *conn = priv ? dbus_connection_open_private(address, e) : dbus_connection_open(address, e); - if(e) throw Error(e); + if (e) throw Error(e); _pvt = new Private(conn); @@ -209,13 +209,13 @@ Connection::Connection( const char* address, bool priv ) debug_log("connected to %s", address); } -Connection::Connection( Connection::Private* p ) +Connection::Connection(Connection::Private *p) : _pvt(p) { setup(default_dispatcher); } -Connection::Connection( const Connection& c ) +Connection::Connection(const Connection &c) : _pvt(c._pvt) { dbus_connection_ref(_pvt->conn); @@ -226,15 +226,15 @@ Connection::~Connection() dbus_connection_unref(_pvt->conn); } -Dispatcher* Connection::setup( Dispatcher* dispatcher ) +Dispatcher *Connection::setup(Dispatcher *dispatcher) { debug_log("registering stubs for connection %p", _pvt->conn); - if(!dispatcher) dispatcher = default_dispatcher; + if (!dispatcher) dispatcher = default_dispatcher; - if(!dispatcher) throw ErrorFailed("no default dispatcher set for new connection"); + if (!dispatcher) throw ErrorFailed("no default dispatcher set for new connection"); - Dispatcher* prev = _pvt->dispatcher; + Dispatcher *prev = _pvt->dispatcher; _pvt->dispatcher = dispatcher; @@ -261,7 +261,7 @@ Dispatcher* Connection::setup( Dispatcher* dispatcher ) return prev; } -bool Connection::operator == ( const Connection& c ) const +bool Connection::operator == (const Connection &c) const { return _pvt->conn == c._pvt->conn; } @@ -272,7 +272,7 @@ bool Connection::register_bus() bool r = dbus_bus_register(_pvt->conn, e); - if(e) throw (e); + if (e) throw (e); return r; } @@ -288,17 +288,17 @@ void Connection::disconnect() dbus_connection_close(_pvt->conn); } -void Connection::exit_on_disconnect( bool exit ) +void Connection::exit_on_disconnect(bool exit) { dbus_connection_set_exit_on_disconnect(_pvt->conn, exit); } -bool Connection::unique_name( const char* n ) +bool Connection::unique_name(const char *n) { return dbus_bus_set_unique_name(_pvt->conn, n); } -const char* Connection::unique_name() const +const char *Connection::unique_name() const { return dbus_bus_get_unique_name(_pvt->conn); } @@ -308,7 +308,7 @@ void Connection::flush() dbus_connection_flush(_pvt->conn); } -void Connection::add_match( const char* rule ) +void Connection::add_match(const char *rule) { InternalError e; @@ -316,10 +316,10 @@ void Connection::add_match( const char* rule ) debug_log("%s: added match rule %s", unique_name(), rule); - if(e) throw Error(e); + if (e) throw Error(e); } -void Connection::remove_match( const char* rule ) +void Connection::remove_match(const char *rule) { InternalError e; @@ -327,50 +327,50 @@ void Connection::remove_match( const char* rule ) debug_log("%s: removed match rule %s", unique_name(), rule); - if(e) throw Error(e); + if (e) throw Error(e); } -bool Connection::add_filter( MessageSlot& s ) +bool Connection::add_filter(MessageSlot &s) { debug_log("%s: adding filter", unique_name()); return dbus_connection_add_filter(_pvt->conn, Private::message_filter_stub, &s, NULL); } -void Connection::remove_filter( MessageSlot& s ) +void Connection::remove_filter(MessageSlot &s) { debug_log("%s: removing filter", unique_name()); dbus_connection_remove_filter(_pvt->conn, Private::message_filter_stub, &s); } -bool Connection::send( const Message& msg, unsigned int* serial ) +bool Connection::send(const Message &msg, unsigned int *serial) { return dbus_connection_send(_pvt->conn, msg._pvt->msg, serial); } -Message Connection::send_blocking( Message& msg, int timeout ) +Message Connection::send_blocking(Message &msg, int timeout) { - DBusMessage* reply; + DBusMessage *reply; InternalError e; reply = dbus_connection_send_with_reply_and_block(_pvt->conn, msg._pvt->msg, timeout, e); - if(e) throw Error(e); + if (e) throw Error(e); return Message(new Message::Private(reply), false); } -PendingCall Connection::send_async( Message& msg, int timeout ) +PendingCall Connection::send_async(Message &msg, int timeout) { - DBusPendingCall* pending; + DBusPendingCall *pending; - if(!dbus_connection_send_with_reply(_pvt->conn, msg._pvt->msg, &pending, timeout)) + if (!dbus_connection_send_with_reply(_pvt->conn, msg._pvt->msg, &pending, timeout)) { throw ErrorNoMemory("Unable to start asynchronous call"); } return PendingCall(new PendingCall::Private(pending)); } -void Connection::request_name( const char* name, int flags ) +void Connection::request_name(const char *name, int flags) { InternalError e; @@ -378,11 +378,11 @@ void Connection::request_name( const char* name, int flags ) dbus_bus_request_name(_pvt->conn, name, flags, e); //we deliberately don't check return value - if(e) throw Error(e); + if (e) throw Error(e); // this->remove_match("destination"); - if(name) + if (name) { _pvt->names.push_back(name); std::string match = "destination='" + _pvt->names.back() + "'"; @@ -390,13 +390,13 @@ void Connection::request_name( const char* name, int flags ) } } -bool Connection::has_name( const char* name ) +bool Connection::has_name(const char *name) { InternalError e; bool b = dbus_bus_name_has_owner(_pvt->conn, name, e); - if(e) throw Error(e); + if (e) throw Error(e); return b; } @@ -406,13 +406,13 @@ const std::vector& Connection::names() return _pvt->names; } -bool Connection::start_service( const char* name, unsigned long flags ) +bool Connection::start_service(const char *name, unsigned long flags) { InternalError e; bool b = dbus_bus_start_service_by_name(_pvt->conn, name, flags, NULL, e); - if(e) throw Error(e); + if (e) throw Error(e); return b; } diff --git a/src/connection_p.h b/src/connection_p.h index 3b9b665..65d6c71 100644 --- a/src/connection_p.h +++ b/src/connection_p.h @@ -43,30 +43,30 @@ namespace DBus { struct DXXAPILOCAL Connection::Private { - DBusConnection* conn; + DBusConnection * conn; std::vector names; - Dispatcher* dispatcher; + Dispatcher *dispatcher; bool do_dispatch(); MessageSlot disconn_filter; - bool disconn_filter_function( const Message& ); + bool disconn_filter_function(const Message &); - Server::Private* server; + Server::Private *server; void detach_server(); - Private( DBusConnection*, Server::Private* = NULL ); + Private(DBusConnection *, Server::Private * = NULL); - Private( DBusBusType ); + Private(DBusBusType); ~Private(); void init(); - static void dispatch_status_stub( DBusConnection*, DBusDispatchStatus, void* ); + static void dispatch_status_stub(DBusConnection *, DBusDispatchStatus, void *); - static DBusHandlerResult message_filter_stub( DBusConnection*, DBusMessage*, void* ); + static DBusHandlerResult message_filter_stub(DBusConnection *, DBusMessage *, void *); }; } /* namespace DBus */ diff --git a/src/debug.cpp b/src/debug.cpp index e83369b..95d8083 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -32,13 +32,13 @@ #include #include -static void _debug_log_default(const char* format, ...) +static void _debug_log_default(const char *format, ...) { #ifdef DEBUG static int debug_env = getenv("DBUSXX_VERBOSE") ? 1 : 0; - if(debug_env) + if (debug_env) { va_list args; va_start(args, format); diff --git a/src/dispatcher.cpp b/src/dispatcher.cpp index 58aacca..0e1619a 100644 --- a/src/dispatcher.cpp +++ b/src/dispatcher.cpp @@ -34,38 +34,38 @@ #include "server_p.h" #include "connection_p.h" -DBus::Dispatcher* DBus::default_dispatcher = NULL; +DBus::Dispatcher *DBus::default_dispatcher = NULL; using namespace DBus; -Timeout::Timeout( Timeout::Internal* i ) +Timeout::Timeout(Timeout::Internal *i) : _int(i) { - dbus_timeout_set_data((DBusTimeout*)i, this, NULL); + dbus_timeout_set_data((DBusTimeout *)i, this, NULL); } int Timeout::interval() const { - return dbus_timeout_get_interval((DBusTimeout*)_int); + return dbus_timeout_get_interval((DBusTimeout *)_int); } bool Timeout::enabled() const { - return dbus_timeout_get_enabled((DBusTimeout*)_int); + return dbus_timeout_get_enabled((DBusTimeout *)_int); } bool Timeout::handle() { - return dbus_timeout_handle((DBusTimeout*)_int); + return dbus_timeout_handle((DBusTimeout *)_int); } /* */ -Watch::Watch( Watch::Internal* i ) +Watch::Watch(Watch::Internal *i) : _int(i) { - dbus_watch_set_data((DBusWatch*)i, this, NULL); + dbus_watch_set_data((DBusWatch *)i, this, NULL); } int Watch::descriptor() const @@ -79,77 +79,77 @@ int Watch::descriptor() const int Watch::flags() const { - return dbus_watch_get_flags((DBusWatch*)_int); + return dbus_watch_get_flags((DBusWatch *)_int); } bool Watch::enabled() const { - return dbus_watch_get_enabled((DBusWatch*)_int); + return dbus_watch_get_enabled((DBusWatch *)_int); } -bool Watch::handle( int flags ) +bool Watch::handle(int flags) { - return dbus_watch_handle((DBusWatch*)_int, flags); + return dbus_watch_handle((DBusWatch *)_int, flags); } /* */ -dbus_bool_t Dispatcher::Private::on_add_watch( DBusWatch* watch, void* data ) +dbus_bool_t Dispatcher::Private::on_add_watch(DBusWatch *watch, void *data) { - Dispatcher* d = static_cast(data); + Dispatcher *d = static_cast(data); - Watch::Internal* w = reinterpret_cast(watch); + Watch::Internal *w = reinterpret_cast(watch); d->add_watch(w); return true; } -void Dispatcher::Private::on_rem_watch( DBusWatch* watch, void* data ) +void Dispatcher::Private::on_rem_watch(DBusWatch *watch, void *data) { - Dispatcher* d = static_cast(data); + Dispatcher *d = static_cast(data); - Watch* w = static_cast(dbus_watch_get_data(watch)); + Watch *w = static_cast(dbus_watch_get_data(watch)); d->rem_watch(w); } -void Dispatcher::Private::on_toggle_watch( DBusWatch* watch, void* data ) +void Dispatcher::Private::on_toggle_watch(DBusWatch *watch, void *data) { - Watch* w = static_cast(dbus_watch_get_data(watch)); + Watch *w = static_cast(dbus_watch_get_data(watch)); w->toggle(); } -dbus_bool_t Dispatcher::Private::on_add_timeout( DBusTimeout* timeout, void* data ) +dbus_bool_t Dispatcher::Private::on_add_timeout(DBusTimeout *timeout, void *data) { - Dispatcher* d = static_cast(data); + Dispatcher *d = static_cast(data); - Timeout::Internal* t = reinterpret_cast(timeout); + Timeout::Internal *t = reinterpret_cast(timeout); d->add_timeout(t); return true; } -void Dispatcher::Private::on_rem_timeout( DBusTimeout* timeout, void* data ) +void Dispatcher::Private::on_rem_timeout(DBusTimeout *timeout, void *data) { - Dispatcher* d = static_cast(data); + Dispatcher *d = static_cast(data); - Timeout* t = static_cast(dbus_timeout_get_data(timeout)); + Timeout *t = static_cast(dbus_timeout_get_data(timeout)); d->rem_timeout(t); } -void Dispatcher::Private::on_toggle_timeout( DBusTimeout* timeout, void* data ) +void Dispatcher::Private::on_toggle_timeout(DBusTimeout *timeout, void *data) { - Timeout* t = static_cast(dbus_timeout_get_data(timeout)); + Timeout *t = static_cast(dbus_timeout_get_data(timeout)); t->toggle(); } -void Dispatcher::queue_connection( Connection::Private* cp ) +void Dispatcher::queue_connection(Connection::Private *cp) { _mutex_p.lock(); _pending_queue.push_back(cp); @@ -160,19 +160,19 @@ void Dispatcher::dispatch_pending() { _mutex_p.lock(); - while(_pending_queue.size() > 0) + while (_pending_queue.size() > 0) { Connection::PrivatePList::iterator i, j; i = _pending_queue.begin(); - while(i != _pending_queue.end()) + while (i != _pending_queue.end()) { j = i; ++j; - if((*i)->do_dispatch()) + if ((*i)->do_dispatch()) _pending_queue.erase(i); i = j; diff --git a/src/dispatcher_p.h b/src/dispatcher_p.h index ac4c9ff..5f25782 100644 --- a/src/dispatcher_p.h +++ b/src/dispatcher_p.h @@ -40,17 +40,17 @@ namespace DBus { struct DXXAPILOCAL Dispatcher::Private { - static dbus_bool_t on_add_watch( DBusWatch* watch, void* data ); + static dbus_bool_t on_add_watch(DBusWatch *watch, void *data); - static void on_rem_watch( DBusWatch* watch, void* data ); + static void on_rem_watch(DBusWatch *watch, void *data); - static void on_toggle_watch( DBusWatch* watch, void* data ); + static void on_toggle_watch(DBusWatch *watch, void *data); - static dbus_bool_t on_add_timeout( DBusTimeout* timeout, void* data ); + static dbus_bool_t on_add_timeout(DBusTimeout *timeout, void *data); - static void on_rem_timeout( DBusTimeout* timeout, void* data ); + static void on_rem_timeout(DBusTimeout *timeout, void *data); - static void on_toggle_timeout( DBusTimeout* timeout, void* data ); + static void on_toggle_timeout(DBusTimeout *timeout, void *data); }; } /* namespace DBus */ diff --git a/src/error.cpp b/src/error.cpp index c08c697..dc17d00 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -43,17 +43,17 @@ Error::Error() : _int(new InternalError) {} -Error::Error(InternalError& i) +Error::Error(InternalError &i) : _int(new InternalError(i)) {} -Error::Error( const char* name, const char* message ) +Error::Error(const char *name, const char *message) : _int(new InternalError) { set(name, message); } -Error::Error( Message& m ) +Error::Error(Message &m) : _int(new InternalError) { dbus_set_error_from_message(&(_int->error), m._pvt->msg); @@ -63,12 +63,12 @@ Error::~Error() throw() { } -const char* Error::name() const +const char *Error::name() const { return _int->error.name; } -const char* Error::message() const +const char *Error::message() const { return _int->error.message; } @@ -78,12 +78,12 @@ bool Error::is_set() const return *(_int); } -void Error::set( const char* name, const char* message ) +void Error::set(const char *name, const char *message) { dbus_set_error_const(&(_int->error), name, message); } -const char* Error::what() const throw() +const char *Error::what() const throw() { return _int->error.message; } diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp index b3ef2bb..5cdc79a 100644 --- a/src/eventloop-integration.cpp +++ b/src/eventloop-integration.cpp @@ -35,7 +35,7 @@ using namespace DBus; -BusTimeout::BusTimeout( Timeout::Internal* ti, BusDispatcher* bd ) +BusTimeout::BusTimeout(Timeout::Internal *ti, BusDispatcher *bd) : Timeout(ti), DefaultTimeout(Timeout::interval(), true, bd) { DefaultTimeout::enabled(Timeout::enabled()); @@ -48,14 +48,14 @@ void BusTimeout::toggle() DefaultTimeout::enabled(Timeout::enabled()); } -BusWatch::BusWatch( Watch::Internal* wi, BusDispatcher* bd ) +BusWatch::BusWatch(Watch::Internal *wi, BusDispatcher *bd) : Watch(wi), DefaultWatch(Watch::descriptor(), 0, bd) { int flags = POLLHUP | POLLERR; - if(Watch::flags() & DBUS_WATCH_READABLE) + if (Watch::flags() & DBUS_WATCH_READABLE) flags |= POLLIN; - if(Watch::flags() & DBUS_WATCH_WRITABLE) + if (Watch::flags() & DBUS_WATCH_WRITABLE) flags |= POLLOUT; DefaultWatch::flags(flags); @@ -75,7 +75,7 @@ void BusDispatcher::enter() _running = true; - while(_running) + while (_running) { do_iteration(); } @@ -94,72 +94,72 @@ void BusDispatcher::do_iteration() dispatch(); } -Timeout* BusDispatcher::add_timeout( Timeout::Internal* ti ) +Timeout *BusDispatcher::add_timeout(Timeout::Internal *ti) { - BusTimeout* bt = new BusTimeout(ti, this); + BusTimeout *bt = new BusTimeout(ti, this); - bt->expired = new Callback(this, &BusDispatcher::timeout_expired); + bt->expired = new Callback(this, &BusDispatcher::timeout_expired); bt->data(bt); - debug_log("added timeout %p (%s)", bt, ((Timeout*)bt)->enabled() ? "on":"off"); + debug_log("added timeout %p (%s)", bt, ((Timeout *)bt)->enabled() ? "on":"off"); return bt; } -void BusDispatcher::rem_timeout( Timeout* t ) +void BusDispatcher::rem_timeout(Timeout *t) { debug_log("removed timeout %p", t); delete t; } -Watch* BusDispatcher::add_watch( Watch::Internal* wi ) +Watch *BusDispatcher::add_watch(Watch::Internal *wi) { - BusWatch* bw = new BusWatch(wi, this); + BusWatch *bw = new BusWatch(wi, this); - bw->ready = new Callback(this, &BusDispatcher::watch_ready); + bw->ready = new Callback(this, &BusDispatcher::watch_ready); bw->data(bw); debug_log("added watch %p (%s) fd=%d flags=%d", - bw, ((Watch*)bw)->enabled() ? "on":"off", ((Watch*)bw)->descriptor(), ((Watch*)bw)->flags() + bw, ((Watch *)bw)->enabled() ? "on":"off", ((Watch *)bw)->descriptor(), ((Watch *)bw)->flags() ); return bw; } -void BusDispatcher::rem_watch( Watch* w ) +void BusDispatcher::rem_watch(Watch *w) { debug_log("removed watch %p", w); delete w; } -void BusDispatcher::timeout_expired( DefaultTimeout& et ) +void BusDispatcher::timeout_expired(DefaultTimeout &et) { debug_log("timeout %p expired", &et); - BusTimeout* timeout = reinterpret_cast(et.data()); + BusTimeout *timeout = reinterpret_cast(et.data()); timeout->handle(); } -void BusDispatcher::watch_ready( DefaultWatch& ew ) +void BusDispatcher::watch_ready(DefaultWatch &ew) { - BusWatch* watch = reinterpret_cast(ew.data()); + BusWatch *watch = reinterpret_cast(ew.data()); debug_log("watch %p ready, flags=%d state=%d", - watch, ((Watch*)watch)->flags(), watch->state() + watch, ((Watch *)watch)->flags(), watch->state() ); int flags = 0; - if(watch->state() & POLLIN) + if (watch->state() & POLLIN) flags |= DBUS_WATCH_READABLE; - if(watch->state() & POLLOUT) + if (watch->state() & POLLOUT) flags |= DBUS_WATCH_WRITABLE; - if(watch->state() & POLLHUP) + if (watch->state() & POLLHUP) flags |= DBUS_WATCH_HANGUP; - if(watch->state() & POLLERR) + if (watch->state() & POLLERR) flags |= DBUS_WATCH_ERROR; watch->handle(flags); diff --git a/src/eventloop.cpp b/src/eventloop.cpp index 94cdee5..5112231 100644 --- a/src/eventloop.cpp +++ b/src/eventloop.cpp @@ -36,12 +36,12 @@ using namespace DBus; -static double millis( timeval tv ) +static double millis(timeval tv) { - return (tv.tv_sec*1000.0 + tv.tv_usec/1000.0); + return (tv.tv_sec *1000.0 + tv.tv_usec/1000.0); } -DefaultTimeout::DefaultTimeout( int interval, bool repeat, DefaultMainLoop* ed ) +DefaultTimeout::DefaultTimeout(int interval, bool repeat, DefaultMainLoop *ed) : _enabled(true), _interval(interval), _repeat(repeat), _expiration(0), _data(0), _disp(ed) { timeval now; @@ -61,7 +61,7 @@ DefaultTimeout::~DefaultTimeout() _disp->_mutex_t.unlock(); } -DefaultWatch::DefaultWatch( int fd, int flags, DefaultMainLoop* ed ) +DefaultWatch::DefaultWatch(int fd, int flags, DefaultMainLoop *ed) : _enabled(true), _fd(fd), _flags(flags), _state(0), _data(0), _disp(ed) { _disp->_mutex_w.lock(); @@ -125,7 +125,7 @@ DefaultMainLoop::~DefaultMainLoop() _mutex_w.lock(); DefaultWatches::iterator wi = _watches.begin(); - while(wi != _watches.end()) + while (wi != _watches.end()) { DefaultWatches::iterator wmp = wi; ++wmp; @@ -139,7 +139,7 @@ DefaultMainLoop::~DefaultMainLoop() _mutex_t.lock(); DefaultTimeouts::iterator ti = _timeouts.begin(); - while(ti != _timeouts.end()) + while (ti != _timeouts.end()) { DefaultTimeouts::iterator tmp = ti; ++tmp; @@ -161,9 +161,9 @@ void DefaultMainLoop::dispatch() DefaultWatches::iterator wi = _watches.begin(); - for(nfd = 0; wi != _watches.end(); ++wi) + for (nfd = 0; wi != _watches.end(); ++wi) { - if((*wi)->enabled()) + if ((*wi)->enabled()) { fds[nfd].fd = (*wi)->descriptor(); fds[nfd].events = (*wi)->flags(); @@ -180,9 +180,9 @@ void DefaultMainLoop::dispatch() _mutex_t.lock(); - for(ti = _timeouts.begin(); ti != _timeouts.end(); ++ti) + for (ti = _timeouts.begin(); ti != _timeouts.end(); ++ti) { - if((*ti)->enabled() && (*ti)->interval() < wait_min) + if ((*ti)->enabled() && (*ti)->interval() < wait_min) wait_min = (*ti)->interval(); } @@ -199,16 +199,16 @@ void DefaultMainLoop::dispatch() ti = _timeouts.begin(); - while(ti != _timeouts.end()) + while (ti != _timeouts.end()) { DefaultTimeouts::iterator tmp = ti; ++tmp; - if((*ti)->enabled() && now_millis >= (*ti)->_expiration) + if ((*ti)->enabled() && now_millis >= (*ti)->_expiration) { (*ti)->expired(*(*ti)); - if((*ti)->_repeat) + if ((*ti)->_repeat) { (*ti)->_expiration = now_millis + (*ti)->_interval; } @@ -222,18 +222,18 @@ void DefaultMainLoop::dispatch() _mutex_w.lock(); - for(int j = 0; j < nfd; ++j) + for (int j = 0; j < nfd; ++j) { DefaultWatches::iterator wi; - for(wi = _watches.begin(); wi != _watches.end();) + for (wi = _watches.begin(); wi != _watches.end();) { DefaultWatches::iterator tmp = wi; ++tmp; - if((*wi)->enabled() && (*wi)->_fd == fds[j].fd) + if ((*wi)->enabled() && (*wi)->_fd == fds[j].fd) { - if(fds[j].revents) + if (fds[j].revents) { (*wi)->_state = fds[j].revents; diff --git a/src/glib-integration.cpp b/src/glib-integration.cpp index 840aa52..c82c77a 100644 --- a/src/glib-integration.cpp +++ b/src/glib-integration.cpp @@ -31,8 +31,8 @@ using namespace DBus; -Glib::BusTimeout::BusTimeout( Timeout::Internal* ti, GMainContext* ctx ) -: Timeout(ti), _ctx(ctx) +Glib::BusTimeout::BusTimeout(Timeout::Internal *ti, GMainContext *ctx, int priority) +: Timeout(ti), _ctx(ctx), _priority(priority) { _enable(); } @@ -46,13 +46,13 @@ void Glib::BusTimeout::toggle() { debug_log("glib: timeout %p toggled (%s)", this, Timeout::enabled() ? "on":"off"); - if(Timeout::enabled()) _enable(); + if (Timeout::enabled()) _enable(); else _disable(); } -gboolean Glib::BusTimeout::timeout_handler( gpointer data ) +gboolean Glib::BusTimeout::timeout_handler(gpointer data) { - Glib::BusTimeout* t = reinterpret_cast(data); + Glib::BusTimeout *t = reinterpret_cast(data); t->handle(); @@ -62,6 +62,7 @@ gboolean Glib::BusTimeout::timeout_handler( gpointer data ) void Glib::BusTimeout::_enable() { _source = g_timeout_source_new(Timeout::interval()); + g_source_set_priority(_source, _priority); g_source_set_callback(_source, timeout_handler, this, NULL); g_source_attach(_source, _ctx); } @@ -77,7 +78,7 @@ struct BusSource GPollFD poll; }; -static gboolean watch_prepare( GSource *source, gint *timeout ) +static gboolean watch_prepare(GSource *source, gint *timeout) { // debug_log("glib: watch_prepare"); @@ -85,15 +86,15 @@ static gboolean watch_prepare( GSource *source, gint *timeout ) return FALSE; } -static gboolean watch_check( GSource *source ) +static gboolean watch_check(GSource *source) { // debug_log("glib: watch_check"); - BusSource* io = (BusSource*)source; + BusSource *io = (BusSource *)source; return io->poll.revents ? TRUE : FALSE; } -static gboolean watch_dispatch( GSource *source, GSourceFunc callback, gpointer data ) +static gboolean watch_dispatch(GSource *source, GSourceFunc callback, gpointer data) { debug_log("glib: watch_dispatch"); @@ -109,8 +110,8 @@ static GSourceFuncs watch_funcs = { NULL }; -Glib::BusWatch::BusWatch( Watch::Internal* wi, GMainContext* ctx ) -: Watch(wi), _ctx(ctx) +Glib::BusWatch::BusWatch(Watch::Internal *wi, GMainContext *ctx, int priority) +: Watch(wi), _ctx(ctx), _priority(priority) { _enable(); } @@ -124,24 +125,24 @@ void Glib::BusWatch::toggle() { debug_log("glib: watch %p toggled (%s)", this, Watch::enabled() ? "on":"off"); - if(Watch::enabled()) _enable(); + if (Watch::enabled()) _enable(); else _disable(); } -gboolean Glib::BusWatch::watch_handler( gpointer data ) +gboolean Glib::BusWatch::watch_handler(gpointer data) { - Glib::BusWatch* w = reinterpret_cast(data); + Glib::BusWatch *w = reinterpret_cast(data); - BusSource* io = (BusSource*)(w->_source); + BusSource *io = (BusSource *)(w->_source); int flags = 0; - if(io->poll.revents & G_IO_IN) + if (io->poll.revents &G_IO_IN) flags |= DBUS_WATCH_READABLE; - if(io->poll.revents & G_IO_OUT) + if (io->poll.revents &G_IO_OUT) flags |= DBUS_WATCH_WRITABLE; - if(io->poll.revents & G_IO_ERR) + if (io->poll.revents &G_IO_ERR) flags |= DBUS_WATCH_ERROR; - if(io->poll.revents & G_IO_HUP) + if (io->poll.revents &G_IO_HUP) flags |= DBUS_WATCH_HANGUP; w->handle(flags); @@ -152,21 +153,22 @@ gboolean Glib::BusWatch::watch_handler( gpointer data ) void Glib::BusWatch::_enable() { _source = g_source_new(&watch_funcs, sizeof(BusSource)); + g_source_set_priority(_source, _priority); g_source_set_callback(_source, watch_handler, this, NULL); int flags = Watch::flags(); int condition = 0; - if(flags & DBUS_WATCH_READABLE) + if (flags &DBUS_WATCH_READABLE) condition |= G_IO_IN; -// if(flags & DBUS_WATCH_WRITABLE) +// if (flags &DBUS_WATCH_WRITABLE) // condition |= G_IO_OUT; - if(flags & DBUS_WATCH_ERROR) + if (flags &DBUS_WATCH_ERROR) condition |= G_IO_ERR; - if(flags & DBUS_WATCH_HANGUP) + if (flags &DBUS_WATCH_HANGUP) condition |= G_IO_HUP; - GPollFD* poll = &(((BusSource*)_source)->poll); + GPollFD *poll = &(((BusSource *)_source)->poll); poll->fd = Watch::descriptor(); poll->events = condition; poll->revents = 0; @@ -177,35 +179,35 @@ void Glib::BusWatch::_enable() void Glib::BusWatch::_disable() { - GPollFD* poll = &(((BusSource*)_source)->poll); + GPollFD *poll = &(((BusSource *)_source)->poll); g_source_remove_poll(_source, poll); g_source_destroy(_source); } -void Glib::BusDispatcher::attach( GMainContext* ctx ) +void Glib::BusDispatcher::attach(GMainContext *ctx) { _ctx = ctx ? ctx : g_main_context_default(); } -Timeout* Glib::BusDispatcher::add_timeout( Timeout::Internal* wi ) +Timeout *Glib::BusDispatcher::add_timeout(Timeout::Internal *wi) { - Timeout* t = new Glib::BusTimeout(wi, _ctx); + Timeout *t = new Glib::BusTimeout(wi, _ctx, _priority); debug_log("glib: added timeout %p (%s)", t, t->enabled() ? "on":"off"); return t; } -void Glib::BusDispatcher::rem_timeout( Timeout* t ) +void Glib::BusDispatcher::rem_timeout(Timeout *t) { debug_log("glib: removed timeout %p", t); delete t; } -Watch* Glib::BusDispatcher::add_watch( Watch::Internal* wi ) +Watch *Glib::BusDispatcher::add_watch(Watch::Internal *wi) { - Watch* w = new Glib::BusWatch(wi, _ctx); + Watch *w = new Glib::BusWatch(wi, _ctx, _priority); debug_log("glib: added watch %p (%s) fd=%d flags=%d", w, w->enabled() ? "on":"off", w->descriptor(), w->flags() @@ -213,9 +215,14 @@ Watch* Glib::BusDispatcher::add_watch( Watch::Internal* wi ) return w; } -void Glib::BusDispatcher::rem_watch( Watch* w ) +void Glib::BusDispatcher::rem_watch(Watch *w) { debug_log("glib: removed watch %p", w); delete w; } + +void Glib::BusDispatcher::set_priority(int priority) +{ + _priority = priority; +} diff --git a/src/interface.cpp b/src/interface.cpp index e765523..63bc443 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -33,21 +33,21 @@ using namespace DBus; -Interface::Interface( const std::string& name ) +Interface::Interface(const std::string &name) : _name(name) {} Interface::~Interface() {} -InterfaceAdaptor* AdaptorBase::find_interface( const std::string& name ) +InterfaceAdaptor *AdaptorBase::find_interface(const std::string &name) { InterfaceAdaptorTable::const_iterator ii = _interfaces.find(name); return ii != _interfaces.end() ? ii->second : NULL; } -InterfaceAdaptor::InterfaceAdaptor( const std::string& name ) +InterfaceAdaptor::InterfaceAdaptor(const std::string &name) : Interface(name) { debug_log("adding interface %s", name.c_str()); @@ -55,14 +55,14 @@ InterfaceAdaptor::InterfaceAdaptor( const std::string& name ) _interfaces[name] = this; } -Message InterfaceAdaptor::dispatch_method( const CallMessage& msg ) +Message InterfaceAdaptor::dispatch_method(const CallMessage &msg) { - const char* name = msg.member(); + const char *name = msg.member(); MethodTable::iterator mi = _methods.find(name); - if( mi != _methods.end() ) + if (mi != _methods.end()) { - return mi->second.call( msg ); + return mi->second.call(msg); } else { @@ -70,21 +70,21 @@ Message InterfaceAdaptor::dispatch_method( const CallMessage& msg ) } } -void InterfaceAdaptor::emit_signal( const SignalMessage& sig ) +void InterfaceAdaptor::emit_signal(const SignalMessage &sig) { - SignalMessage& sig2 = const_cast(sig); + SignalMessage &sig2 = const_cast(sig); - sig2.interface( name().c_str() ); + sig2.interface(name().c_str()); _emit_signal(sig2); } -Variant* InterfaceAdaptor::get_property( const std::string& name ) +Variant *InterfaceAdaptor::get_property(const std::string &name) { PropertyTable::iterator pti = _properties.find(name); - if( pti != _properties.end() ) + if (pti != _properties.end()) { - if( !pti->second.read ) + if (!pti->second.read) throw ErrorAccessDenied("property is not readable"); return &(pti->second.value); @@ -92,18 +92,18 @@ Variant* InterfaceAdaptor::get_property( const std::string& name ) return NULL; } -void InterfaceAdaptor::set_property( const std::string& name, Variant& value ) +void InterfaceAdaptor::set_property(const std::string &name, Variant &value) { PropertyTable::iterator pti = _properties.find(name); - if( pti != _properties.end() ) + if (pti != _properties.end()) { - if( !pti->second.write ) + if (!pti->second.write) throw ErrorAccessDenied("property is not writeable"); Signature sig = value.signature(); - if( pti->second.sig != sig ) + if (pti->second.sig != sig) throw ErrorInvalidSignature("property expects a different type"); pti->second.value = value; @@ -112,14 +112,14 @@ void InterfaceAdaptor::set_property( const std::string& name, Variant& value ) throw ErrorFailed("requested property not found"); } -InterfaceProxy* ProxyBase::find_interface( const std::string& name ) +InterfaceProxy *ProxyBase::find_interface(const std::string &name) { InterfaceProxyTable::const_iterator ii = _interfaces.find(name); return ii != _interfaces.end() ? ii->second : NULL; } -InterfaceProxy::InterfaceProxy( const std::string& name ) +InterfaceProxy::InterfaceProxy(const std::string &name) : Interface(name) { debug_log("adding interface %s", name.c_str()); @@ -127,14 +127,14 @@ InterfaceProxy::InterfaceProxy( const std::string& name ) _interfaces[name] = this; } -bool InterfaceProxy::dispatch_signal( const SignalMessage& msg ) +bool InterfaceProxy::dispatch_signal(const SignalMessage &msg) { - const char* name = msg.member(); + const char *name = msg.member(); SignalTable::iterator si = _signals.find(name); - if( si != _signals.end() ) + if (si != _signals.end()) { - si->second.call( msg ); + si->second.call(msg); // Here we always return false because there might be // another InterfaceProxy listening for the same signal. // This way we instruct libdbus-1 to go on dispatching @@ -147,10 +147,10 @@ bool InterfaceProxy::dispatch_signal( const SignalMessage& msg ) } } -Message InterfaceProxy::invoke_method( const CallMessage& call ) +Message InterfaceProxy::invoke_method(const CallMessage &call) { - CallMessage& call2 = const_cast(call); + CallMessage &call2 = const_cast(call); - call2.interface( name().c_str() ); + call2.interface(name().c_str()); return _invoke_method(call2); } diff --git a/src/internalerror.h b/src/internalerror.h index 7a6bbe0..9636c6b 100644 --- a/src/internalerror.h +++ b/src/internalerror.h @@ -45,16 +45,16 @@ struct DXXAPI InternalError dbus_error_init(&error); } - explicit InternalError( DBusError* e ) + explicit InternalError(DBusError *e) { dbus_error_init(&error); dbus_move_error(e, &error); } - InternalError(const InternalError& ie) + InternalError(const InternalError &ie) { dbus_error_init(&error); - dbus_move_error(const_cast(&(ie.error)), &error); + dbus_move_error(const_cast(&(ie.error)), &error); } ~InternalError() @@ -62,7 +62,7 @@ struct DXXAPI InternalError dbus_error_free(&error); } - operator DBusError*() + operator DBusError *() { return &error; } diff --git a/src/introspection.cpp b/src/introspection.cpp index 7137964..eb17218 100644 --- a/src/introspection.cpp +++ b/src/introspection.cpp @@ -36,7 +36,7 @@ using namespace DBus; -static const char* introspectable_name = "org.freedesktop.DBus.Introspectable"; +static const char *introspectable_name = "org.freedesktop.DBus.Introspectable"; IntrospectableAdaptor::IntrospectableAdaptor() : InterfaceAdaptor(introspectable_name) @@ -44,7 +44,7 @@ IntrospectableAdaptor::IntrospectableAdaptor() register_method(IntrospectableAdaptor, Introspect, Introspect); } -Message IntrospectableAdaptor::Introspect( const CallMessage& call ) +Message IntrospectableAdaptor::Introspect(const CallMessage &call) { debug_log("requested introspection data"); @@ -58,37 +58,37 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call ) InterfaceAdaptorTable::const_iterator iti; - for(iti = _interfaces.begin(); iti != _interfaces.end(); ++iti) + for (iti = _interfaces.begin(); iti != _interfaces.end(); ++iti) { debug_log("introspecting interface %s", iti->first.c_str()); - IntrospectedInterface* const intro = iti->second->introspect(); - if(intro) + IntrospectedInterface *const intro = iti->second->introspect(); + if (intro) { xml << "\n\tname << "\">"; - for(const IntrospectedProperty* p = intro->properties; p->name; ++p) + for (const IntrospectedProperty *p = intro->properties; p->name; ++p) { std::string access; - if(p->read) access += "read"; - if(p->write) access += "write"; + if (p->read) access += "read"; + if (p->write) access += "write"; xml << "\n\t\tname << "\"" << " type=\"" << p->type << "\"" << " access=\"" << access << "\"/>"; } - for(const IntrospectedMethod* m = intro->methods; m->args; ++m) + for (const IntrospectedMethod *m = intro->methods; m->args; ++m) { xml << "\n\t\tname << "\">"; - for(const IntrospectedArgument* a = m->args; a->type; ++a) + for (const IntrospectedArgument *a = m->args; a->type; ++a) { xml << "\n\t\t\tin ? "in" : "out") << "\"" << " type=\"" << a->type << "\""; - if(a->name) xml << " name=\"" << a->name << "\""; + if (a->name) xml << " name=\"" << a->name << "\""; xml << "/>"; } @@ -96,15 +96,15 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call ) xml << "\n\t\t"; } - for(const IntrospectedMethod* m = intro->signals; m->args; ++m) + for (const IntrospectedMethod *m = intro->signals; m->args; ++m) { xml << "\n\t\tname << "\">"; - for(const IntrospectedArgument* a = m->args; a->type; ++a) + for (const IntrospectedArgument *a = m->args; a->type; ++a) { xml << "type << "\""; - if(a->name) xml << " name=\"" << a->name << "\""; + if (a->name) xml << " name=\"" << a->name << "\""; xml << "/>"; } @@ -118,7 +118,7 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call ) const ObjectPathList nodes = ObjectAdaptor::child_nodes_from_prefix(path + '/'); ObjectPathList::const_iterator oni; - for(oni = nodes.begin(); oni != nodes.end(); ++oni) + for (oni = nodes.begin(); oni != nodes.end(); ++oni) { xml << "\n\t"; } @@ -128,7 +128,7 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call ) ObjectAdaptorPList::const_iterator oci; - for(oci = children.begin(); oci != children.end(); ++oci) + for (oci = children.begin(); oci != children.end(); ++oci) { std::string name = (*oci)->path().substr(path.length()+1); name.substr(name.find('/')); @@ -145,7 +145,7 @@ Message IntrospectableAdaptor::Introspect( const CallMessage& call ) return reply; } -IntrospectedInterface* const IntrospectableAdaptor::introspect() const +IntrospectedInterface *const IntrospectableAdaptor::introspect() const { static IntrospectedArgument Introspect_args[] = { @@ -188,7 +188,7 @@ std::string IntrospectableProxy::Introspect() DBus::Message ret = invoke_method(call); DBus::MessageIter ri = ret.reader(); - const char* str = ri.get_string(); + const char *str = ri.get_string(); return str; } diff --git a/src/message.cpp b/src/message.cpp index 1c4fb9c..bf48405 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -41,7 +41,7 @@ using namespace DBus; int MessageIter::type() { - return dbus_message_iter_get_arg_type((DBusMessageIter*)&_iter); + return dbus_message_iter_get_arg_type((DBusMessageIter *)&_iter); } bool MessageIter::at_end() @@ -51,12 +51,12 @@ bool MessageIter::at_end() bool MessageIter::has_next() { - return dbus_message_iter_has_next((DBusMessageIter*)&_iter); + return dbus_message_iter_has_next((DBusMessageIter *)&_iter); } -MessageIter& MessageIter::operator ++() +MessageIter &MessageIter::operator ++() { - dbus_message_iter_next((DBusMessageIter*)&_iter); + dbus_message_iter_next((DBusMessageIter *)&_iter); return (*this); } @@ -67,20 +67,20 @@ MessageIter MessageIter::operator ++(int) return copy; } -bool MessageIter::append_basic( int type_id, void* value ) +bool MessageIter::append_basic(int type_id, void *value) { - return dbus_message_iter_append_basic((DBusMessageIter*)&_iter, type_id, value); + return dbus_message_iter_append_basic((DBusMessageIter *)&_iter, type_id, value); } -void MessageIter::get_basic( int type_id, void* ptr ) +void MessageIter::get_basic(int type_id, void *ptr) { - if(type() != type_id) + if (type() != type_id) throw ErrorInvalidArgs("type mismatch"); - dbus_message_iter_get_basic((DBusMessageIter*)_iter, ptr); + dbus_message_iter_get_basic((DBusMessageIter *)_iter, ptr); } -bool MessageIter::append_byte( unsigned char b ) +bool MessageIter::append_byte(unsigned char b) { return append_basic(DBUS_TYPE_BYTE, &b); } @@ -92,7 +92,7 @@ unsigned char MessageIter::get_byte() return b; } -bool MessageIter::append_bool( bool b ) +bool MessageIter::append_bool(bool b) { dbus_bool_t db = b; return append_basic(DBUS_TYPE_BOOLEAN, &db); @@ -105,7 +105,7 @@ bool MessageIter::get_bool() return (bool)db; } -bool MessageIter::append_int16( signed short i ) +bool MessageIter::append_int16(signed short i) { return append_basic(DBUS_TYPE_INT16, &i); } @@ -117,7 +117,7 @@ signed short MessageIter::get_int16() return i; } -bool MessageIter::append_uint16( unsigned short u ) +bool MessageIter::append_uint16(unsigned short u) { return append_basic(DBUS_TYPE_UINT16, &u); } @@ -129,7 +129,7 @@ unsigned short MessageIter::get_uint16() return u; } -bool MessageIter::append_int32( signed int i ) +bool MessageIter::append_int32(signed int i) { return append_basic(DBUS_TYPE_INT32, &i); } @@ -141,7 +141,7 @@ signed int MessageIter::get_int32() return i; } -bool MessageIter::append_uint32( unsigned int u ) +bool MessageIter::append_uint32(unsigned int u) { return append_basic(DBUS_TYPE_UINT32, &u); } @@ -160,7 +160,7 @@ signed long long MessageIter::get_int64() return i; } -bool MessageIter::append_int64( signed long long i ) +bool MessageIter::append_int64(signed long long i) { return append_basic(DBUS_TYPE_INT64, &i); } @@ -172,7 +172,7 @@ unsigned long long MessageIter::get_uint64() return u; } -bool MessageIter::append_uint64( unsigned long long u ) +bool MessageIter::append_uint64(unsigned long long u) { return append_basic(DBUS_TYPE_UINT64, &u); } @@ -184,43 +184,43 @@ double MessageIter::get_double() return d; } -bool MessageIter::append_double( double d ) +bool MessageIter::append_double(double d) { return append_basic(DBUS_TYPE_DOUBLE, &d); } -bool MessageIter::append_string( const char* chars ) +bool MessageIter::append_string(const char *chars) { return append_basic(DBUS_TYPE_STRING, &chars); } -const char* MessageIter::get_string() +const char *MessageIter::get_string() { - char* chars; + char *chars; get_basic(DBUS_TYPE_STRING, &chars); return chars; } -bool MessageIter::append_path( const char* chars ) +bool MessageIter::append_path(const char *chars) { return append_basic(DBUS_TYPE_OBJECT_PATH, &chars); } -const char* MessageIter::get_path() +const char *MessageIter::get_path() { - char* chars; + char *chars; get_basic(DBUS_TYPE_OBJECT_PATH, &chars); return chars; } -bool MessageIter::append_signature( const char* chars ) +bool MessageIter::append_signature(const char *chars) { return append_basic(DBUS_TYPE_SIGNATURE, &chars); } -const char* MessageIter::get_signature() +const char *MessageIter::get_signature() { - char* chars; + char *chars; get_basic(DBUS_TYPE_SIGNATURE, &chars); return chars; } @@ -228,56 +228,56 @@ const char* MessageIter::get_signature() MessageIter MessageIter::recurse() { MessageIter iter(msg()); - dbus_message_iter_recurse((DBusMessageIter*)&_iter, (DBusMessageIter*)&(iter._iter)); + dbus_message_iter_recurse((DBusMessageIter *)&_iter, (DBusMessageIter *)&(iter._iter)); return iter; } -char* MessageIter::signature() const +char *MessageIter::signature() const { - return dbus_message_iter_get_signature((DBusMessageIter*)&_iter); + return dbus_message_iter_get_signature((DBusMessageIter *)&_iter); } -bool MessageIter::append_array( char type, const void* ptr, size_t length ) +bool MessageIter::append_array(char type, const void *ptr, size_t length) { - return dbus_message_iter_append_fixed_array((DBusMessageIter*)&_iter, type, &ptr, length); + return dbus_message_iter_append_fixed_array((DBusMessageIter *)&_iter, type, &ptr, length); } int MessageIter::array_type() { - return dbus_message_iter_get_element_type((DBusMessageIter*)&_iter); + return dbus_message_iter_get_element_type((DBusMessageIter *)&_iter); } -int MessageIter::get_array( void* ptr ) +int MessageIter::get_array(void *ptr) { int length; - dbus_message_iter_get_fixed_array((DBusMessageIter*)&_iter, ptr, &length); + dbus_message_iter_get_fixed_array((DBusMessageIter *)&_iter, ptr, &length); return length; } bool MessageIter::is_array() { - return dbus_message_iter_get_arg_type((DBusMessageIter*)&_iter) == DBUS_TYPE_ARRAY; + return dbus_message_iter_get_arg_type((DBusMessageIter *)&_iter) == DBUS_TYPE_ARRAY; } bool MessageIter::is_dict() { - return is_array() && dbus_message_iter_get_element_type((DBusMessageIter*)_iter) == DBUS_TYPE_DICT_ENTRY; + return is_array() && dbus_message_iter_get_element_type((DBusMessageIter *)_iter) == DBUS_TYPE_DICT_ENTRY; } -MessageIter MessageIter::new_array( const char* sig ) +MessageIter MessageIter::new_array(const char *sig) { MessageIter arr(msg()); dbus_message_iter_open_container( - (DBusMessageIter*)&_iter, DBUS_TYPE_ARRAY, sig, (DBusMessageIter*)&(arr._iter) + (DBusMessageIter *)&_iter, DBUS_TYPE_ARRAY, sig, (DBusMessageIter *)&(arr._iter) ); return arr; } -MessageIter MessageIter::new_variant( const char* sig ) +MessageIter MessageIter::new_variant(const char *sig) { MessageIter var(msg()); dbus_message_iter_open_container( - (DBusMessageIter*)_iter, DBUS_TYPE_VARIANT, sig, (DBusMessageIter*)&(var._iter) + (DBusMessageIter *)_iter, DBUS_TYPE_VARIANT, sig, (DBusMessageIter *)&(var._iter) ); return var; } @@ -286,7 +286,7 @@ MessageIter MessageIter::new_struct() { MessageIter stu(msg()); dbus_message_iter_open_container( - (DBusMessageIter*)_iter, DBUS_TYPE_STRUCT, NULL, (DBusMessageIter*)&(stu._iter) + (DBusMessageIter *)_iter, DBUS_TYPE_STRUCT, NULL, (DBusMessageIter *)&(stu._iter) ); return stu; } @@ -295,19 +295,19 @@ MessageIter MessageIter::new_dict_entry() { MessageIter ent(msg()); dbus_message_iter_open_container( - (DBusMessageIter*)_iter, DBUS_TYPE_DICT_ENTRY, NULL, (DBusMessageIter*)&(ent._iter) + (DBusMessageIter *)_iter, DBUS_TYPE_DICT_ENTRY, NULL, (DBusMessageIter *)&(ent._iter) ); return ent; } -void MessageIter::close_container( MessageIter& container ) +void MessageIter::close_container(MessageIter &container) { - dbus_message_iter_close_container((DBusMessageIter*)&_iter, (DBusMessageIter*)&(container._iter)); + dbus_message_iter_close_container((DBusMessageIter *)&_iter, (DBusMessageIter *)&(container._iter)); } static bool is_basic_type(int typecode) { - switch(typecode) + switch (typecode) { case 'y': case 'b': @@ -327,11 +327,11 @@ static bool is_basic_type(int typecode) } } -void MessageIter::copy_data( MessageIter& to ) +void MessageIter::copy_data(MessageIter &to) { - for(MessageIter& from = *this; !from.at_end(); ++from) + for (MessageIter &from = *this; !from.at_end(); ++from) { - if(is_basic_type(from.type())) + if (is_basic_type(from.type())) { debug_log("copying basic type: %c", from.type()); @@ -342,17 +342,17 @@ void MessageIter::copy_data( MessageIter& to ) else { MessageIter from_container = from.recurse(); - char* sig = from_container.signature(); + char *sig = from_container.signature(); debug_log("copying compound type: %c[%s]", from.type(), sig); MessageIter to_container (to.msg()); dbus_message_iter_open_container ( - (DBusMessageIter*)&(to._iter), + (DBusMessageIter *)&(to._iter), from.type(), from.type() == DBUS_TYPE_VARIANT ? NULL : sig, - (DBusMessageIter*)&(to_container._iter) + (DBusMessageIter *)&(to_container._iter) ); from_container.copy_data(to_container); @@ -370,13 +370,13 @@ Message::Message() { } -Message::Message( Message::Private* p, bool incref ) +Message::Message(Message::Private *p, bool incref) : _pvt(p) { - if(_pvt->msg && incref) dbus_message_ref(_pvt->msg); + if (_pvt->msg && incref) dbus_message_ref(_pvt->msg); } -Message::Message( const Message& m ) +Message::Message(const Message &m) : _pvt(m._pvt) { dbus_message_ref(_pvt->msg); @@ -387,9 +387,9 @@ Message::~Message() dbus_message_unref(_pvt->msg); } -Message& Message::operator = ( const Message& m ) +Message &Message::operator = (const Message &m) { - if(&m != this) + if (&m != this) { dbus_message_unref(_pvt->msg); _pvt = m._pvt; @@ -400,11 +400,11 @@ Message& Message::operator = ( const Message& m ) Message Message::copy() { - Private* pvt = new Private(dbus_message_copy(_pvt->msg)); + Private *pvt = new Private(dbus_message_copy(_pvt->msg)); return Message(pvt); } -bool Message::append( int first_type, ... ) +bool Message::append(int first_type, ...) { va_list vl; va_start(vl, first_type); @@ -435,27 +435,27 @@ int Message::reply_serial() const return dbus_message_get_reply_serial(_pvt->msg); } -bool Message::reply_serial( int s ) +bool Message::reply_serial(int s) { return dbus_message_set_reply_serial(_pvt->msg, s); } -const char* Message::sender() const +const char *Message::sender() const { return dbus_message_get_sender(_pvt->msg); } -bool Message::sender( const char* s ) +bool Message::sender(const char *s) { return dbus_message_set_sender(_pvt->msg, s); } -const char* Message::destination() const +const char *Message::destination() const { return dbus_message_get_destination(_pvt->msg); } -bool Message::destination( const char* s ) +bool Message::destination(const char *s) { return dbus_message_set_destination(_pvt->msg, s); } @@ -465,7 +465,7 @@ bool Message::is_error() const return type() == DBUS_MESSAGE_TYPE_ERROR; } -bool Message::is_signal( const char* interface, const char* member ) const +bool Message::is_signal(const char *interface, const char *member) const { return dbus_message_is_signal(_pvt->msg, interface, member); } @@ -473,14 +473,14 @@ bool Message::is_signal( const char* interface, const char* member ) const MessageIter Message::writer() { MessageIter iter(*this); - dbus_message_iter_init_append(_pvt->msg, (DBusMessageIter*)&(iter._iter)); + dbus_message_iter_init_append(_pvt->msg, (DBusMessageIter *)&(iter._iter)); return iter; } MessageIter Message::reader() const { - MessageIter iter(const_cast(*this)); - dbus_message_iter_init(_pvt->msg, (DBusMessageIter*)&(iter._iter)); + MessageIter iter(const_cast(*this)); + dbus_message_iter_init(_pvt->msg, (DBusMessageIter *)&(iter._iter)); return iter; } @@ -492,22 +492,22 @@ ErrorMessage::ErrorMessage() _pvt->msg = dbus_message_new(DBUS_MESSAGE_TYPE_ERROR); } -ErrorMessage::ErrorMessage( const Message& to_reply, const char* name, const char* message ) +ErrorMessage::ErrorMessage(const Message &to_reply, const char *name, const char *message) { _pvt->msg = dbus_message_new_error(to_reply._pvt->msg, name, message); } -bool ErrorMessage::operator == ( const ErrorMessage& m ) const +bool ErrorMessage::operator == (const ErrorMessage &m) const { return dbus_message_is_error(_pvt->msg, m.name()); } -const char* ErrorMessage::name() const +const char *ErrorMessage::name() const { return dbus_message_get_error_name(_pvt->msg); } -bool ErrorMessage::name( const char* n ) +bool ErrorMessage::name(const char *n) { return dbus_message_set_error_name(_pvt->msg, n); } @@ -515,55 +515,55 @@ bool ErrorMessage::name( const char* n ) /* */ -SignalMessage::SignalMessage( const char* name ) +SignalMessage::SignalMessage(const char *name) { _pvt->msg = dbus_message_new(DBUS_MESSAGE_TYPE_SIGNAL); member(name); } -SignalMessage::SignalMessage( const char* path, const char* interface, const char* name ) +SignalMessage::SignalMessage(const char *path, const char *interface, const char *name) { _pvt->msg = dbus_message_new_signal(path, interface, name); } -bool SignalMessage::operator == ( const SignalMessage& m ) const +bool SignalMessage::operator == (const SignalMessage &m) const { return dbus_message_is_signal(_pvt->msg, m.interface(), m.member()); } -const char* SignalMessage::interface() const +const char *SignalMessage::interface() const { return dbus_message_get_interface(_pvt->msg); } -bool SignalMessage::interface( const char* i ) +bool SignalMessage::interface(const char *i) { return dbus_message_set_interface(_pvt->msg, i); } -const char* SignalMessage::member() const +const char *SignalMessage::member() const { return dbus_message_get_member(_pvt->msg); } -bool SignalMessage::member( const char* m ) +bool SignalMessage::member(const char *m) { return dbus_message_set_member(_pvt->msg, m); } -const char* SignalMessage::path() const +const char *SignalMessage::path() const { return dbus_message_get_path(_pvt->msg); } -char** SignalMessage::path_split() const +char ** SignalMessage::path_split() const { - char** p; + char ** p; dbus_message_get_path_decomposed(_pvt->msg, &p); //todo: return as a std::vector ? return p; } -bool SignalMessage::path( const char* p ) +bool SignalMessage::path(const char *p) { return dbus_message_set_path(_pvt->msg, p); } @@ -576,54 +576,54 @@ CallMessage::CallMessage() _pvt->msg = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_CALL); } -CallMessage::CallMessage( const char* dest, const char* path, const char* iface, const char* method ) +CallMessage::CallMessage(const char *dest, const char *path, const char *iface, const char *method) { _pvt->msg = dbus_message_new_method_call(dest, path, iface, method); } -bool CallMessage::operator == ( const CallMessage& m ) const +bool CallMessage::operator == (const CallMessage &m) const { return dbus_message_is_method_call(_pvt->msg, m.interface(), m.member()); } -const char* CallMessage::interface() const +const char *CallMessage::interface() const { return dbus_message_get_interface(_pvt->msg); } -bool CallMessage::interface( const char* i ) +bool CallMessage::interface(const char *i) { return dbus_message_set_interface(_pvt->msg, i); } -const char* CallMessage::member() const +const char *CallMessage::member() const { return dbus_message_get_member(_pvt->msg); } -bool CallMessage::member( const char* m ) +bool CallMessage::member(const char *m) { return dbus_message_set_member(_pvt->msg, m); } -const char* CallMessage::path() const +const char *CallMessage::path() const { return dbus_message_get_path(_pvt->msg); } -char** CallMessage::path_split() const +char ** CallMessage::path_split() const { - char** p; + char ** p; dbus_message_get_path_decomposed(_pvt->msg, &p); return p; } -bool CallMessage::path( const char* p ) +bool CallMessage::path(const char *p) { return dbus_message_set_path(_pvt->msg, p); } -const char* CallMessage::signature() const +const char *CallMessage::signature() const { return dbus_message_get_signature(_pvt->msg); } @@ -631,12 +631,12 @@ const char* CallMessage::signature() const /* */ -ReturnMessage::ReturnMessage( const CallMessage& callee ) +ReturnMessage::ReturnMessage(const CallMessage &callee) { _pvt = new Private(dbus_message_new_method_return(callee._pvt->msg)); } -const char* ReturnMessage::signature() const +const char *ReturnMessage::signature() const { return dbus_message_get_signature(_pvt->msg); } diff --git a/src/message_p.h b/src/message_p.h index 404847b..830e63d 100644 --- a/src/message_p.h +++ b/src/message_p.h @@ -39,12 +39,12 @@ namespace DBus { struct DXXAPILOCAL Message::Private { - DBusMessage* msg; + DBusMessage *msg; Private() : msg(0) {} - Private( DBusMessage* m ) : msg(m) + Private(DBusMessage *m) : msg(m) {} }; diff --git a/src/object.cpp b/src/object.cpp index cf4be24..13b7052 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -40,8 +40,8 @@ using namespace DBus; -Object::Object( Connection& conn, const Path& path, const char* service ) -: _conn(conn), _path(path), _service(service ? service : "") +Object::Object(Connection &conn, const Path &path, const char *service) +: _conn(conn), _path(path), _service(service ? service : "") { } @@ -51,8 +51,8 @@ Object::~Object() struct ObjectAdaptor::Private { - static void unregister_function_stub( DBusConnection*, void* ); - static DBusHandlerResult message_function_stub( DBusConnection*, DBusMessage*, void* ); + static void unregister_function_stub(DBusConnection *, void *); + static DBusHandlerResult message_function_stub(DBusConnection *, DBusMessage *, void *); }; static DBusObjectPathVTable _vtable = @@ -62,16 +62,16 @@ static DBusObjectPathVTable _vtable = NULL, NULL, NULL, NULL }; -void ObjectAdaptor::Private::unregister_function_stub( DBusConnection* conn, void* data ) +void ObjectAdaptor::Private::unregister_function_stub(DBusConnection *conn, void *data) { //TODO: what do we have to do here ? } -DBusHandlerResult ObjectAdaptor::Private::message_function_stub( DBusConnection*, DBusMessage* dmsg, void* data ) +DBusHandlerResult ObjectAdaptor::Private::message_function_stub(DBusConnection *, DBusMessage *dmsg, void *data) { - ObjectAdaptor* o = static_cast(data); + ObjectAdaptor *o = static_cast(data); - if( o ) + if (o) { Message msg(new Message::Private(dmsg)); @@ -92,20 +92,20 @@ DBusHandlerResult ObjectAdaptor::Private::message_function_stub( DBusConnection* } } -typedef std::map ObjectAdaptorTable; +typedef std::map ObjectAdaptorTable; static ObjectAdaptorTable _adaptor_table; -ObjectAdaptor* ObjectAdaptor::from_path( const Path& path ) +ObjectAdaptor *ObjectAdaptor::from_path(const Path &path) { ObjectAdaptorTable::iterator ati = _adaptor_table.find(path); - if(ati != _adaptor_table.end()) + if (ati != _adaptor_table.end()) return ati->second; return NULL; } -ObjectAdaptorPList ObjectAdaptor::from_path_prefix( const std::string& prefix ) +ObjectAdaptorPList ObjectAdaptor::from_path_prefix(const std::string &prefix) { ObjectAdaptorPList ali; @@ -113,9 +113,9 @@ ObjectAdaptorPList ObjectAdaptor::from_path_prefix( const std::string& prefix ) size_t plen = prefix.length(); - while(ati != _adaptor_table.end()) + while (ati != _adaptor_table.end()) { - if(!strncmp(ati->second->path().c_str(), prefix.c_str(), plen)) + if (!strncmp(ati->second->path().c_str(), prefix.c_str(), plen)) ali.push_back(ati->second); ++ati; @@ -124,7 +124,7 @@ ObjectAdaptorPList ObjectAdaptor::from_path_prefix( const std::string& prefix ) return ali; } -ObjectPathList ObjectAdaptor::child_nodes_from_prefix( const std::string& prefix ) +ObjectPathList ObjectAdaptor::child_nodes_from_prefix(const std::string &prefix) { ObjectPathList ali; @@ -132,9 +132,9 @@ ObjectPathList ObjectAdaptor::child_nodes_from_prefix( const std::string& prefix size_t plen = prefix.length(); - while(ati != _adaptor_table.end()) + while (ati != _adaptor_table.end()) { - if(!strncmp(ati->second->path().c_str(), prefix.c_str(), plen)) + if (!strncmp(ati->second->path().c_str(), prefix.c_str(), plen)) { std::string p = ati->second->path().substr(plen); p = p.substr(0,p.find('/')); @@ -149,8 +149,8 @@ ObjectPathList ObjectAdaptor::child_nodes_from_prefix( const std::string& prefix return ali; } -ObjectAdaptor::ObjectAdaptor( Connection& conn, const Path& path ) -: Object(conn, path, conn.unique_name()) +ObjectAdaptor::ObjectAdaptor(Connection &conn, const Path &path) +: Object(conn, path, conn.unique_name()) { register_obj(); } @@ -164,7 +164,7 @@ void ObjectAdaptor::register_obj() { debug_log("registering local object %s", path().c_str()); - if(!dbus_connection_register_object_path(conn()._pvt->conn, path().c_str(), &_vtable, this)) + if (!dbus_connection_register_object_path(conn()._pvt->conn, path().c_str(), &_vtable, this)) { throw ErrorNoMemory("unable to register object path"); } @@ -181,7 +181,7 @@ void ObjectAdaptor::unregister_obj() dbus_connection_unregister_object_path(conn()._pvt->conn, path().c_str()); } -void ObjectAdaptor::_emit_signal( SignalMessage& sig ) +void ObjectAdaptor::_emit_signal(SignalMessage &sig) { sig.path(path().c_str()); @@ -190,35 +190,35 @@ void ObjectAdaptor::_emit_signal( SignalMessage& sig ) struct ReturnLaterError { - const Tag* tag; + const Tag *tag; }; -bool ObjectAdaptor::handle_message( const Message& msg ) +bool ObjectAdaptor::handle_message(const Message &msg) { - switch( msg.type() ) + switch (msg.type()) { case DBUS_MESSAGE_TYPE_METHOD_CALL: { - const CallMessage& cmsg = reinterpret_cast(msg); - const char* member = cmsg.member(); - const char* interface = cmsg.interface(); + const CallMessage &cmsg = reinterpret_cast(msg); + const char *member = cmsg.member(); + const char *interface = cmsg.interface(); debug_log(" invoking method %s.%s", interface, member); - InterfaceAdaptor* ii = find_interface(interface); - if( ii ) + InterfaceAdaptor *ii = find_interface(interface); + if (ii) { try { Message ret = ii->dispatch_method(cmsg); conn().send(ret); } - catch(Error& e) + catch(Error &e) { ErrorMessage em(cmsg, e.name(), e.message()); conn().send(em); } - catch(ReturnLaterError& rle) + catch(ReturnLaterError &rle) { _continuations[rle.tag] = new Continuation(conn(), cmsg, rle.tag); } @@ -236,13 +236,13 @@ bool ObjectAdaptor::handle_message( const Message& msg ) } } -void ObjectAdaptor::return_later( const Tag* tag ) +void ObjectAdaptor::return_later(const Tag *tag) { ReturnLaterError rle = { tag }; throw rle; } -void ObjectAdaptor::return_now( Continuation* ret ) +void ObjectAdaptor::return_now(Continuation *ret) { ret->_conn.send(ret->_return); @@ -253,7 +253,7 @@ void ObjectAdaptor::return_now( Continuation* ret ) _continuations.erase(di); } -void ObjectAdaptor::return_error( Continuation* ret, const Error error ) +void ObjectAdaptor::return_error(Continuation *ret, const Error error) { ret->_conn.send(ErrorMessage(ret->_call, error.name(), error.message())); @@ -264,14 +264,14 @@ void ObjectAdaptor::return_error( Continuation* ret, const Error error ) _continuations.erase(di); } -ObjectAdaptor::Continuation* ObjectAdaptor::find_continuation( const Tag* tag ) +ObjectAdaptor::Continuation *ObjectAdaptor::find_continuation(const Tag *tag) { ContinuationMap::iterator di = _continuations.find(tag); return di != _continuations.end() ? di->second : NULL; } -ObjectAdaptor::Continuation::Continuation( Connection& conn, const CallMessage& call, const Tag* tag ) +ObjectAdaptor::Continuation::Continuation(Connection &conn, const CallMessage &call, const Tag *tag) : _conn(conn), _call(call), _return(_call), _tag(tag) { _writer = _return.writer(); //todo: verify @@ -280,8 +280,8 @@ ObjectAdaptor::Continuation::Continuation( Connection& conn, const CallMessage& /* */ -ObjectProxy::ObjectProxy( Connection& conn, const Path& path, const char* service ) -: Object(conn, path, service) +ObjectProxy::ObjectProxy(Connection &conn, const Path &path, const char *service) +: Object(conn, path, service) { register_obj(); } @@ -295,12 +295,12 @@ void ObjectProxy::register_obj() { debug_log("registering remote object %s", path().c_str()); - _filtered = new Callback(this, &ObjectProxy::handle_message); + _filtered = new Callback(this, &ObjectProxy::handle_message); conn().add_filter(_filtered); InterfaceProxyTable::const_iterator ii = _interfaces.begin(); - while( ii != _interfaces.end() ) + while (ii != _interfaces.end()) { std::string im = "type='signal',interface='"+ii->first+"',path='"+path()+"'"; conn().add_match(im.c_str()); @@ -313,7 +313,7 @@ void ObjectProxy::unregister_obj() debug_log("unregistering remote object %s", path().c_str()); InterfaceProxyTable::const_iterator ii = _interfaces.begin(); - while( ii != _interfaces.end() ) + while (ii != _interfaces.end()) { std::string im = "type='signal',interface='"+ii->first+"',path='"+path()+"'"; conn().remove_match(im.c_str()); @@ -322,7 +322,7 @@ void ObjectProxy::unregister_obj() conn().remove_filter(_filtered); } -Message ObjectProxy::_invoke_method( CallMessage& call ) +Message ObjectProxy::_invoke_method(CallMessage &call) { call.path(path().c_str()); call.destination(service().c_str()); @@ -330,24 +330,24 @@ Message ObjectProxy::_invoke_method( CallMessage& call ) return conn().send_blocking(call); } -bool ObjectProxy::handle_message( const Message& msg ) +bool ObjectProxy::handle_message(const Message &msg) { - switch( msg.type() ) + switch (msg.type()) { case DBUS_MESSAGE_TYPE_SIGNAL: { - const SignalMessage& smsg = reinterpret_cast(msg); - const char* interface = smsg.interface(); - const char* member = smsg.member(); - const char* objpath = smsg.path(); + const SignalMessage &smsg = reinterpret_cast(msg); + const char *interface = smsg.interface(); + const char *member = smsg.member(); + const char *objpath = smsg.path(); - if( objpath != path() ) return false; + if (objpath != path()) return false; debug_log("filtered signal %s(in %s) from %s to object %s", member, interface, msg.sender(), objpath); - InterfaceProxy* ii = find_interface(interface); - if( ii ) + InterfaceProxy *ii = find_interface(interface); + if (ii) { return ii->dispatch_signal(smsg); } diff --git a/src/pendingcall.cpp b/src/pendingcall.cpp index 482bcfd..dd14dbd 100644 --- a/src/pendingcall.cpp +++ b/src/pendingcall.cpp @@ -36,10 +36,10 @@ using namespace DBus; -PendingCall::Private::Private( DBusPendingCall* dpc ) +PendingCall::Private::Private(DBusPendingCall *dpc) : call(dpc), dataslot(-1) { - if(!dbus_pending_call_allocate_data_slot(&dataslot)) + if (!dbus_pending_call_allocate_data_slot(&dataslot)) { throw ErrorNoMemory("Unable to allocate data slot"); } @@ -47,30 +47,30 @@ PendingCall::Private::Private( DBusPendingCall* dpc ) PendingCall::Private::~Private() { - if(dataslot != -1) + if (dataslot != -1) { dbus_pending_call_allocate_data_slot(&dataslot); } } -void PendingCall::Private::notify_stub( DBusPendingCall* dpc, void* data ) +void PendingCall::Private::notify_stub(DBusPendingCall *dpc, void *data) { - PendingCall::Private* pvt = static_cast(data); + PendingCall::Private *pvt = static_cast(data); PendingCall pc(pvt); pvt->slot(pc); } -PendingCall::PendingCall( PendingCall::Private* p ) +PendingCall::PendingCall(PendingCall::Private *p) : _pvt(p) { - if(!dbus_pending_call_set_notify(_pvt->call, Private::notify_stub, p, NULL)) + if (!dbus_pending_call_set_notify(_pvt->call, Private::notify_stub, p, NULL)) { throw ErrorNoMemory("Unable to initialize pending call"); } } -PendingCall::PendingCall( const PendingCall& c ) +PendingCall::PendingCall(const PendingCall &c) : _pvt(c._pvt) { dbus_pending_call_ref(_pvt->call); @@ -81,9 +81,9 @@ PendingCall::~PendingCall() dbus_pending_call_unref(_pvt->call); } -PendingCall& PendingCall::operator = ( const PendingCall& c ) +PendingCall &PendingCall::operator = (const PendingCall &c) { - if(&c != this) + if (&c != this) { dbus_pending_call_unref(_pvt->call); _pvt = c._pvt; @@ -107,37 +107,37 @@ void PendingCall::block() dbus_pending_call_block(_pvt->call); } -void PendingCall::data( void* p ) +void PendingCall::data(void *p) { - if(!dbus_pending_call_set_data(_pvt->call, _pvt->dataslot, p, NULL)) + if (!dbus_pending_call_set_data(_pvt->call, _pvt->dataslot, p, NULL)) { throw ErrorNoMemory("Unable to initialize data slot"); } } -void* PendingCall::data() +void *PendingCall::data() { return dbus_pending_call_get_data(_pvt->call, _pvt->dataslot); } -Slot& PendingCall::slot() +Slot& PendingCall::slot() { return _pvt->slot; } Message PendingCall::steal_reply() { - DBusMessage* dmsg = dbus_pending_call_steal_reply(_pvt->call); - if(!dmsg) + DBusMessage *dmsg = dbus_pending_call_steal_reply(_pvt->call); + if (!dmsg) { dbus_bool_t callComplete = dbus_pending_call_get_completed(_pvt->call); - if(callComplete) + if (callComplete) throw ErrorNoReply("No reply available"); else throw ErrorNoReply("Call not complete"); } - return Message( new Message::Private(dmsg) ); + return Message(new Message::Private(dmsg)); } diff --git a/src/pendingcall_p.h b/src/pendingcall_p.h index 90efdf1..dea4cbf 100644 --- a/src/pendingcall_p.h +++ b/src/pendingcall_p.h @@ -39,15 +39,15 @@ namespace DBus { struct DXXAPILOCAL PendingCall::Private { - DBusPendingCall* call; + DBusPendingCall *call; int dataslot; - Slot slot; + Slot slot; - Private( DBusPendingCall* ); + Private(DBusPendingCall *); ~Private(); - static void notify_stub( DBusPendingCall* dpc, void* data ); + static void notify_stub(DBusPendingCall *dpc, void *data); }; } /* namespace DBus */ diff --git a/src/property.cpp b/src/property.cpp index 6c17d44..69ba352 100644 --- a/src/property.cpp +++ b/src/property.cpp @@ -33,7 +33,7 @@ using namespace DBus; -static const char* properties_name = "org.freedesktop.DBus.Properties"; +static const char *properties_name = "org.freedesktop.DBus.Properties"; PropertiesAdaptor::PropertiesAdaptor() : InterfaceAdaptor(properties_name) @@ -42,25 +42,25 @@ PropertiesAdaptor::PropertiesAdaptor() register_method(PropertiesAdaptor, Set, Set); } -Message PropertiesAdaptor::Get( const CallMessage& call ) +Message PropertiesAdaptor::Get(const CallMessage &call) { MessageIter ri = call.reader(); - String iface_name; - String property_name; + std::string iface_name; + std::string property_name; ri >> iface_name >> property_name; debug_log("requesting property %s on interface %s", property_name.c_str(), iface_name.c_str()); - InterfaceAdaptor* interface = (InterfaceAdaptor*) find_interface(iface_name); + InterfaceAdaptor *interface = (InterfaceAdaptor *) find_interface(iface_name); - if(!interface) + if (!interface) throw ErrorFailed("requested interface not found"); - Variant* value = interface->get_property(property_name); + Variant *value = interface->get_property(property_name); - if(!value) + if (!value) throw ErrorFailed("requested property not found"); on_get_property(*interface, property_name, *value); @@ -73,19 +73,19 @@ Message PropertiesAdaptor::Get( const CallMessage& call ) return reply; } -Message PropertiesAdaptor::Set( const CallMessage& call ) +Message PropertiesAdaptor::Set(const CallMessage &call) { MessageIter ri = call.reader(); - String iface_name; - String property_name; + std::string iface_name; + std::string property_name; Variant value; ri >> iface_name >> property_name >> value; - InterfaceAdaptor* interface = (InterfaceAdaptor*) find_interface(iface_name); + InterfaceAdaptor *interface = (InterfaceAdaptor *) find_interface(iface_name); - if(!interface) + if (!interface) throw ErrorFailed("requested interface not found"); on_set_property(*interface, property_name, value); @@ -97,7 +97,7 @@ Message PropertiesAdaptor::Set( const CallMessage& call ) return reply; } -IntrospectedInterface* const PropertiesAdaptor::introspect() const +IntrospectedInterface *const PropertiesAdaptor::introspect() const { static IntrospectedArgument Get_args[] = { @@ -142,14 +142,14 @@ PropertiesProxy::PropertiesProxy() { } -Variant PropertiesProxy::Get( const String& iface, const String& property ) +Variant PropertiesProxy::Get(const std::string &iface, const std::string &property) { //todo Variant v; return v; } -void PropertiesProxy::Set( const String& iface, const String& property, const Variant& value ) +void PropertiesProxy::Set(const std::string &iface, const std::string &property, const Variant &value) { //todo } diff --git a/src/server.cpp b/src/server.cpp index 1882d70..2493b74 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -36,7 +36,7 @@ using namespace DBus; -Server::Private::Private( DBusServer* s ) +Server::Private::Private(DBusServer *s) : server(s) { } @@ -45,9 +45,9 @@ Server::Private::~Private() { } -void Server::Private::on_new_conn_cb( DBusServer* server, DBusConnection* conn, void* data ) +void Server::Private::on_new_conn_cb(DBusServer *server, DBusConnection *conn, void *data) { - Server* s = static_cast(data); + Server *s = static_cast(data); Connection nc (new Connection::Private(conn, s->_pvt.get())); @@ -58,12 +58,12 @@ void Server::Private::on_new_conn_cb( DBusServer* server, DBusConnection* conn, debug_log("incoming connection 0x%08x", conn); } -Server::Server( const char* address ) +Server::Server(const char *address) { InternalError e; - DBusServer* server = dbus_server_listen(address, e); + DBusServer *server = dbus_server_listen(address, e); - if(e) throw Error(e); + if (e) throw Error(e); debug_log("server 0x%08x listening on %s", server, address); @@ -74,7 +74,7 @@ Server::Server( const char* address ) setup(default_dispatcher); } /* -Server::Server( const Server& s ) +Server::Server(const Server &s) : _pvt(s._pvt) { dbus_server_ref(_pvt->server); @@ -85,11 +85,11 @@ Server::~Server() dbus_server_unref(_pvt->server); } -Dispatcher* Server::setup( Dispatcher* dispatcher ) +Dispatcher *Server::setup(Dispatcher *dispatcher) { debug_log("registering stubs for server %p", _pvt->server); - Dispatcher* prev = _pvt->dispatcher; + Dispatcher *prev = _pvt->dispatcher; dbus_server_set_watch_functions( _pvt->server, @@ -114,7 +114,7 @@ Dispatcher* Server::setup( Dispatcher* dispatcher ) return prev; } -bool Server::operator == ( const Server& s ) const +bool Server::operator == (const Server &s) const { return _pvt->server == s._pvt->server; } diff --git a/src/server_p.h b/src/server_p.h index 8c83750..b510712 100644 --- a/src/server_p.h +++ b/src/server_p.h @@ -40,17 +40,17 @@ namespace DBus { struct DXXAPILOCAL Server::Private { - DBusServer* server; + DBusServer *server; - Dispatcher* dispatcher; + Dispatcher *dispatcher; ConnectionList connections; - Private( DBusServer* ); + Private(DBusServer *); ~Private(); - static void on_new_conn_cb( DBusServer* server, DBusConnection* conn, void* data ); + static void on_new_conn_cb(DBusServer *server, DBusConnection *conn, void *data); }; } /* namespace DBus */ diff --git a/src/types.cpp b/src/types.cpp index b2c3543..f902b61 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -42,7 +42,7 @@ Variant::Variant() { } -Variant::Variant( MessageIter& it ) +Variant::Variant(MessageIter &it) : _msg(CallMessage()) { MessageIter vi = it.recurse(); @@ -50,9 +50,9 @@ Variant::Variant( MessageIter& it ) vi.copy_data(mi); } -Variant& Variant::operator = ( const Variant& v ) +Variant &Variant::operator = (const Variant &v) { - if(&v != this) + if (&v != this) { _msg = v._msg; } @@ -67,7 +67,7 @@ void Variant::clear() const Signature Variant::signature() const { - char* sigbuf = reader().signature(); + char *sigbuf = reader().signature(); Signature signature = sigbuf; @@ -76,7 +76,7 @@ const Signature Variant::signature() const return signature; } -MessageIter& operator << ( MessageIter& iter, const Variant& val ) +MessageIter &operator << (MessageIter &iter, const Variant &val) { const Signature sig = val.signature(); @@ -90,9 +90,9 @@ MessageIter& operator << ( MessageIter& iter, const Variant& val ) return iter; } -MessageIter& operator >> ( MessageIter& iter, Variant& val ) +MessageIter &operator >> (MessageIter &iter, Variant &val) { - if(iter.type() != DBUS_TYPE_VARIANT) + if (iter.type() != DBUS_TYPE_VARIANT) throw ErrorInvalidArgs("variant type expected"); val.clear(); diff --git a/tools/introspect.cpp b/tools/introspect.cpp index d25d8c6..8ce9f3a 100644 --- a/tools/introspect.cpp +++ b/tools/introspect.cpp @@ -29,10 +29,10 @@ DBus::BusDispatcher dispatcher; static bool systembus; -static char* path; -static char* service; +static char *path; +static char *service; -void niam( int sig ) +void niam(int sig) { DBus::Connection conn = systembus ? DBus::Connection::SystemBus() : DBus::Connection::SessionBus(); @@ -43,19 +43,19 @@ void niam( int sig ) dispatcher.leave(); } -int main( int argc, char** argv ) +int main(int argc, char ** argv) { signal(SIGTERM, niam); signal(SIGINT, niam); signal(SIGALRM, niam); - if(argc == 1) + if (argc == 1) { std::cerr << std::endl << "Usage: " << argv[0] << " [--system] []" << std::endl << std::endl; } else { - if(strcmp(argv[1], "--system")) + if (strcmp(argv[1], "--system")) { systembus = false; path = argv[1]; diff --git a/tools/introspect.h b/tools/introspect.h index 3633611..1c6e326 100644 --- a/tools/introspect.h +++ b/tools/introspect.h @@ -36,7 +36,7 @@ class IntrospectedObject : public DBus::IntrospectableProxy, public DBus::Object { public: - IntrospectedObject( DBus::Connection& conn, const char* path, const char* service ) + IntrospectedObject(DBus::Connection &conn, const char *path, const char *service) : DBus::ObjectProxy(conn, path, service) {} }; diff --git a/tools/xml.cpp b/tools/xml.cpp index 69b403e..68ae5a6 100644 --- a/tools/xml.cpp +++ b/tools/xml.cpp @@ -28,7 +28,7 @@ #include -std::istream& operator >> ( std::istream& in, DBus::Xml::Document& doc ) +std::istream &operator >> (std::istream &in, DBus::Xml::Document &doc) { std::stringbuf xmlbuf; in.get(xmlbuf, '\0'); @@ -37,7 +37,7 @@ std::istream& operator >> ( std::istream& in, DBus::Xml::Document& doc ) return in; } -std::ostream& operator << ( std::ostream& out, const DBus::Xml::Document& doc ) +std::ostream &operator << (std::ostream &out, const DBus::Xml::Document &doc) { return out << doc.to_xml(); } @@ -45,7 +45,7 @@ std::ostream& operator << ( std::ostream& out, const DBus::Xml::Document& doc ) using namespace DBus; using namespace DBus::Xml; -Error::Error( const char* error, int line, int column ) +Error::Error(const char *error, int line, int column) { std::ostringstream estream; @@ -54,11 +54,11 @@ Error::Error( const char* error, int line, int column ) _error = estream.str(); } -Node::Node( const char* n, const char** a ) +Node::Node(const char *n, const char ** a) : name(n) { - if(a) - for(int i = 0; a[i]; i += 2) + if (a) + for (int i = 0; a[i]; i += 2) { _attrs[a[i]] = a[i+1]; @@ -66,11 +66,11 @@ Node::Node( const char* n, const char** a ) } } -Nodes Nodes::operator[]( const std::string& key ) +Nodes Nodes::operator[](const std::string &key) { Nodes result; - for(iterator i = begin(); i != end(); ++i) + for (iterator i = begin(); i != end(); ++i) { Nodes part = (**i)[key]; @@ -79,43 +79,43 @@ Nodes Nodes::operator[]( const std::string& key ) return result; } -Nodes Nodes::select( const std::string& attr, const std::string& value ) +Nodes Nodes::select(const std::string &attr, const std::string &value) { Nodes result; - for(iterator i = begin(); i != end(); ++i) + for (iterator i = begin(); i != end(); ++i) { - if((*i)->get(attr) == value) + if ((*i)->get(attr) == value) result.insert(result.end(), *i); } return result; } -Nodes Node::operator[]( const std::string& key ) +Nodes Node::operator[](const std::string &key) { Nodes result; - if(key.length() == 0) return result; + if (key.length() == 0) return result; - for(Children::iterator i = children.begin(); i != children.end(); ++i) + for (Children::iterator i = children.begin(); i != children.end(); ++i) { - if(i->name == key) + if (i->name == key) result.push_back(&(*i)); } return result; } -std::string Node::get( const std::string& attribute ) +std::string Node::get(const std::string &attribute) { - if(_attrs.find(attribute) != _attrs.end()) + if (_attrs.find(attribute) != _attrs.end()) return _attrs[attribute]; else return ""; } -void Node::set( const std::string& attribute, std::string value ) +void Node::set(const std::string &attribute, std::string value) { - if(value.length()) + if (value.length()) _attrs[attribute] = value; else _attrs.erase(value); @@ -131,17 +131,17 @@ std::string Node::to_xml() const return xml; } -void Node::_raw_xml( std::string& xml, int& depth ) const +void Node::_raw_xml(std::string &xml, int &depth) const { - xml.append(depth*2, ' '); + xml.append(depth *2, ' '); xml.append("<"+name); - for(Attributes::const_iterator i = _attrs.begin(); i != _attrs.end(); ++i) + for (Attributes::const_iterator i = _attrs.begin(); i != _attrs.end(); ++i) { xml.append(" "+i->first+"=\""+i->second+"\""); } - if(cdata.length() == 0 && children.size() == 0) + if (cdata.length() == 0 && children.size() == 0) { xml.append("/>\n"); } @@ -149,23 +149,23 @@ void Node::_raw_xml( std::string& xml, int& depth ) const { xml.append(">"); - if(cdata.length()) + if (cdata.length()) { xml.append(cdata); } - if(children.size()) + if (children.size()) { xml.append("\n"); depth++; - for(Children::const_iterator i = children.begin(); i != children.end(); ++i) + for (Children::const_iterator i = children.begin(); i != children.end(); ++i) { i->_raw_xml(xml, depth); } depth--; - xml.append(depth*2, ' '); + xml.append(depth *2, ' '); } xml.append("\n"); } @@ -176,7 +176,7 @@ Document::Document() { } -Document::Document( const std::string& xml ) +Document::Document(const std::string &xml) : root(0), _depth(0) { from_xml(xml); @@ -190,15 +190,15 @@ Document::~Document() struct Document::Expat { static void start_doctype_decl_handler( - void* data, const XML_Char* name, const XML_Char* sysid, const XML_Char* pubid, int has_internal_subset + void *data, const XML_Char *name, const XML_Char *sysid, const XML_Char *pubid, int has_internal_subset ); - static void end_doctype_decl_handler( void* data ); - static void start_element_handler( void *data, const XML_Char *name, const XML_Char **atts ); - static void character_data_handler( void *data, const XML_Char* chars, int len ); - static void end_element_handler( void *data, const XML_Char *name ); + static void end_doctype_decl_handler(void *data); + static void start_element_handler(void *data, const XML_Char *name, const XML_Char **atts); + static void character_data_handler(void *data, const XML_Char *chars, int len); + static void end_element_handler(void *data, const XML_Char *name); }; -void Document::from_xml( const std::string& xml ) +void Document::from_xml(const std::string &xml) { _depth = 0; delete root; @@ -227,9 +227,9 @@ void Document::from_xml( const std::string& xml ) XML_Status status = XML_Parse(parser, xml.c_str(), xml.length(), true); - if(status == XML_STATUS_ERROR) + if (status == XML_STATUS_ERROR) { - const char* error = XML_ErrorString(XML_GetErrorCode(parser)); + const char *error = XML_ErrorString(XML_GetErrorCode(parser)); int line = XML_GetCurrentLineNumber(parser); int column = XML_GetCurrentColumnNumber(parser); @@ -249,30 +249,30 @@ std::string Document::to_xml() const } void Document::Expat::start_doctype_decl_handler( - void* data, const XML_Char* name, const XML_Char* sysid, const XML_Char* pubid, int has_internal_subset + void *data, const XML_Char *name, const XML_Char *sysid, const XML_Char *pubid, int has_internal_subset ) { } -void Document::Expat::end_doctype_decl_handler( void* data ) +void Document::Expat::end_doctype_decl_handler(void *data) { } -void Document::Expat::start_element_handler( void *data, const XML_Char *name, const XML_Char **atts ) +void Document::Expat::start_element_handler(void *data, const XML_Char *name, const XML_Char **atts) { - Document* doc = (Document*)data; + Document *doc = (Document *)data; //debug_log("xml:%d -> %s", doc->_depth, name); - if(!doc->root) + if (!doc->root) { doc->root = new Node(name, atts); } else { - Node::Children* cld = &(doc->root->children); + Node::Children *cld = &(doc->root->children); - for(int i = 1; i < doc->_depth; ++i) + for (int i = 1; i < doc->_depth; ++i) { cld = &(cld->back().children); } @@ -283,13 +283,13 @@ void Document::Expat::start_element_handler( void *data, const XML_Char *name, c doc->_depth++; } -void Document::Expat::character_data_handler( void *data, const XML_Char* chars, int len ) +void Document::Expat::character_data_handler(void *data, const XML_Char *chars, int len) { - Document* doc = (Document*)data; + Document *doc = (Document *)data; - Node* nod = doc->root; + Node *nod = doc->root; - for(int i = 1; i < doc->_depth; ++i) + for (int i = 1; i < doc->_depth; ++i) { nod = &(nod->children.back()); } @@ -298,15 +298,15 @@ void Document::Expat::character_data_handler( void *data, const XML_Char* chars, x = 0; y = len-1; - while(isspace(chars[y]) && y > 0) --y; - while(isspace(chars[x]) && x < y) ++x; + while (isspace(chars[y]) && y > 0) --y; + while (isspace(chars[x]) && x < y) ++x; nod->cdata = std::string(chars, x, y+1); } -void Document::Expat::end_element_handler( void *data, const XML_Char *name ) +void Document::Expat::end_element_handler(void *data, const XML_Char *name) { - Document* doc = (Document*)data; + Document *doc = (Document *)data; //debug_log("xml:%d <- %s", doc->_depth, name); diff --git a/tools/xml.h b/tools/xml.h index 79574c0..6a8e69c 100644 --- a/tools/xml.h +++ b/tools/xml.h @@ -44,12 +44,12 @@ class Error : public std::exception { public: - Error( const char* error, int line, int column ); + Error(const char *error, int line, int column); ~Error() throw() {} - const char* what() const throw() + const char *what() const throw() { return _error.c_str(); } @@ -61,13 +61,13 @@ private: class Node; -class Nodes : public std::vector +class Nodes : public std::vector { public: - Nodes operator[]( const std::string& key ); + Nodes operator[](const std::string &key); - Nodes select( const std::string& attr, const std::string& value ); + Nodes select(const std::string &attr, const std::string &value); }; class Node @@ -82,21 +82,21 @@ public: std::string cdata; Children children; - Node( std::string& n, Attributes& a ) + Node(std::string &n, Attributes &a) : name(n), _attrs(a) {} - Node( const char* n, const char** a = NULL ); + Node(const char *n, const char ** a = NULL); - Nodes operator[]( const std::string& key ); + Nodes operator[](const std::string &key); - std::string get( const std::string& attribute ); + std::string get(const std::string &attribute); - void set( const std::string& attribute, std::string value ); + void set(const std::string &attribute, std::string value); std::string to_xml() const; - Node& add( Node child ) + Node &add(Node child) { children.push_back(child); return children.back(); @@ -104,7 +104,7 @@ public: private: - void _raw_xml( std::string& xml, int& depth ) const; + void _raw_xml(std::string &xml, int &depth) const; Attributes _attrs; }; @@ -115,15 +115,15 @@ public: struct Expat; - Node* root; + Node *root; Document(); - Document( const std::string& xml ); + Document(const std::string &xml); ~Document(); - void from_xml( const std::string& xml ); + void from_xml(const std::string &xml); std::string to_xml() const; @@ -136,7 +136,7 @@ private: } /* namespace DBus */ -std::istream& operator >> ( std::istream&, DBus::Xml::Document& ); -std::ostream& operator << ( std::ostream&, DBus::Xml::Document& ); +std::istream &operator >> (std::istream &, DBus::Xml::Document &); +std::ostream &operator << (std::ostream &, DBus::Xml::Document &); #endif//__DBUSXX_XML_H diff --git a/tools/xml2cpp.cpp b/tools/xml2cpp.cpp index 144d9ff..25a32d2 100644 --- a/tools/xml2cpp.cpp +++ b/tools/xml2cpp.cpp @@ -37,66 +37,66 @@ using namespace std; using namespace DBus; -static const char* tab = " "; +static const char *tab = " "; -static const char* header = "\n\ +static const char *header = "\n\ /*\n\ * This file was automatically generated by dbusxx-xml2cpp; DO NOT EDIT!\n\ */\n\ \n\ "; -static const char* dbus_includes = "\n\ +static const char *dbus_includes = "\n\ #include \n\ \n\ "; typedef map TypeCache; -void usage( const char* argv0 ) +void usage(const char *argv0) { cerr << endl << "Usage: " << argv0 << " [ --proxy= ] [ --adaptor= ]" << endl << endl; exit(-1); } -void underscorize( string& str ) +void underscorize(string &str) { - for(unsigned int i = 0; i < str.length(); ++i) + for (unsigned int i = 0; i < str.length(); ++i) { - if(!isalpha(str[i]) && !isdigit(str[i])) str[i] = '_'; + if (!isalpha(str[i]) && !isdigit(str[i])) str[i] = '_'; } } -string stub_name( string name ) +string stub_name(string name) { underscorize(name); return "_" + name + "_stub"; } -int char_to_atomic_type( char t ) +int char_to_atomic_type(char t) { - if(strchr("ybnqiuxtdsgavre", t)) + if (strchr("ybnqiuxtdsgavre", t)) return t; return DBUS_TYPE_INVALID; } -const char* atomic_type_to_string( char t ) +const char *atomic_type_to_string(char t) { - static struct { char type; const char* name; } atos[] = + static struct { char type; const char *name; } atos[] = { - { 'y', "::DBus::Byte" }, - { 'b', "::DBus::Bool" }, - { 'n', "::DBus::Int16" }, - { 'q', "::DBus::UInt16" }, - { 'i', "::DBus::Int32" }, - { 'u', "::DBus::UInt32" }, - { 'x', "::DBus::Int64" }, - { 't', "::DBus::UInt64" }, - { 'd', "::DBus::Double" }, - { 's', "::DBus::String" }, + { 'y', "uint8_t" }, + { 'b', "bool" }, + { 'n', "int16_t" }, + { 'q', "uint16_t" }, + { 'i', "int32_t" }, + { 'u', "uint32_t" }, + { 'x', "int64_t" }, + { 't', "uint64_t" }, + { 'd', "double" }, + { 's', "std::string" }, { 'o', "::DBus::Path" }, { 'g', "::DBus::Signature" }, { 'v', "::DBus::Variant" }, @@ -104,34 +104,34 @@ const char* atomic_type_to_string( char t ) }; int i; - for(i = 0; atos[i].type; ++i) + for (i = 0; atos[i].type; ++i) { - if(atos[i].type == t) break; + if (atos[i].type == t) break; } return atos[i].name; } -bool is_atomic_type( const string& type ) +bool is_atomic_type(const string &type) { return type.length() == 1 && char_to_atomic_type(type[0]) != DBUS_TYPE_INVALID; } -void _parse_signature( const string& signature, string& type, unsigned int& i ) +void _parse_signature(const string &signature, string &type, unsigned int &i) { - for(; i < signature.length(); ++i) + for (; i < signature.length(); ++i) { - switch(signature[i]) + switch (signature[i]) { case 'a': { - switch(signature[++i]) + switch (signature[++i]) { case '{': { type += "std::map< "; - const char* atom = atomic_type_to_string(signature[++i]); - if(!atom) + const char *atom = atomic_type_to_string(signature[++i]); + if (!atom) { cerr << "invalid signature" << endl; exit(-1); @@ -157,7 +157,7 @@ void _parse_signature( const string& signature, string& type, unsigned int& i ) ++i; _parse_signature(signature, type, i); type += " >"; - if(signature[i+1]) + if (signature[i+1]) { type += ", "; } @@ -170,15 +170,15 @@ void _parse_signature( const string& signature, string& type, unsigned int& i ) } default: { - const char* atom = atomic_type_to_string(signature[i]); - if(!atom) + const char *atom = atomic_type_to_string(signature[i]); + if (!atom) { cerr << "invalid signature" << endl; exit(-1); } type += atom; - if(signature[i+1] != ')' && signature[i+1] != '}' && i+1 < signature.length()) + if (signature[i+1] != ')' && signature[i+1] != '}' && i+1 < signature.length()) { type += ", "; } @@ -188,7 +188,7 @@ void _parse_signature( const string& signature, string& type, unsigned int& i ) } } -string signature_to_type( const string& signature ) +string signature_to_type(const string &signature) { string type; unsigned int i = 0; @@ -196,12 +196,12 @@ string signature_to_type( const string& signature ) return type; } -void generate_proxy( Xml::Document& doc, const char* filename ) +void generate_proxy(Xml::Document &doc, const char *filename) { cerr << "writing " << filename << endl; ofstream file(filename); - if(file.bad()) + if (file.bad()) { cerr << "unable to write file " << filename << endl; exit(-1); @@ -218,12 +218,12 @@ void generate_proxy( Xml::Document& doc, const char* filename ) file << dbus_includes; - Xml::Node& root = *(doc.root); + Xml::Node &root = *(doc.root); Xml::Nodes interfaces = root["interface"]; - for(Xml::Nodes::iterator i = interfaces.begin(); i != interfaces.end(); ++i) + for (Xml::Nodes::iterator i = interfaces.begin(); i != interfaces.end(); ++i) { - Xml::Node& iface = **i; + Xml::Node &iface = **i; Xml::Nodes methods = iface["method"]; Xml::Nodes signals = iface["signal"]; Xml::Nodes properties = iface["property"]; @@ -232,7 +232,7 @@ void generate_proxy( Xml::Document& doc, const char* filename ) ms.insert(ms.end(), signals.begin(), signals.end()); string ifacename = iface.get("name"); - if(ifacename == "org.freedesktop.DBus.Introspectable" + if (ifacename == "org.freedesktop.DBus.Introspectable" ||ifacename == "org.freedesktop.DBus.Properties") { cerr << "skipping interface " << ifacename << endl; @@ -243,7 +243,7 @@ void generate_proxy( Xml::Document& doc, const char* filename ) string nspace; unsigned int nspaces = 0; - while(ss.str().find('.', ss.tellg()) != string::npos) + while (ss.str().find('.', ss.tellg()) != string::npos) { getline(ss, nspace, '.'); @@ -268,9 +268,9 @@ void generate_proxy( Xml::Document& doc, const char* filename ) << tab << ": ::DBus::InterfaceProxy(\"" << ifacename << "\")" << endl << tab << "{" << endl; - for(Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) + for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) { - Xml::Node& signal = **si; + Xml::Node &signal = **si; string marshname = "_" + signal.get("name") + "_stub"; @@ -288,75 +288,75 @@ void generate_proxy( Xml::Document& doc, const char* filename ) << tab << " * this functions will invoke the corresponding methods on the remote objects" << endl << tab << " */" << endl; - for(Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) + for (Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) { - Xml::Node& method = **mi; + Xml::Node &method = **mi; Xml::Nodes args = method["arg"]; Xml::Nodes args_in = args.select("direction","in"); Xml::Nodes args_out = args.select("direction","out"); - if(args_out.size() == 0 || args_out.size() > 1 ) + if (args_out.size() == 0 || args_out.size() > 1) { file << tab << "void "; } - else if(args_out.size() == 1) + else if (args_out.size() == 1) { file << tab << signature_to_type(args_out.front()->get("type")) << " "; } - file << method.get("name") << "( "; + file << method.get("name") << "("; unsigned int i = 0; - for(Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i) + for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i) { - Xml::Node& arg = **ai; + Xml::Node &arg = **ai; file << "const " << signature_to_type(arg.get("type")) << "& "; string arg_name = arg.get("name"); - if(arg_name.length()) + if (arg_name.length()) file << arg_name; else file << "argin" << i; - if((i+1 != args_in.size() || args_out.size() > 1)) + if ((i+1 != args_in.size() || args_out.size() > 1)) file << ", "; } - if(args_out.size() > 1) + if (args_out.size() > 1) { unsigned int i = 0; - for(Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i) + for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i) { - Xml::Node& arg = **ao; + Xml::Node &arg = **ao; file << signature_to_type(arg.get("type")) << "&"; string arg_name = arg.get("name"); - if(arg_name.length()) + if (arg_name.length()) file << " " << arg_name; else file << " argout" << i; - if(i+1 != args_out.size()) + if (i+1 != args_out.size()) file << ", "; } } - file << " )" << endl; + file << ")" << endl; file << tab << "{" << endl << tab << tab << "::DBus::CallMessage call;" << endl; - if(args_in.size() > 0) + if (args_in.size() > 0) { file << tab << tab << "::DBus::MessageIter wi = call.writer();" << endl << endl; } unsigned int j = 0; - for(Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++j) + for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++j) { - Xml::Node& arg = **ai; + Xml::Node &arg = **ai; string arg_name = arg.get("name"); - if(arg_name.length()) + if (arg_name.length()) file << tab << tab << "wi << " << arg_name << ";" << endl; else file << tab << tab << "wi << argin" << j << ";" << endl; @@ -366,27 +366,27 @@ void generate_proxy( Xml::Document& doc, const char* filename ) << tab << tab << "::DBus::Message ret = invoke_method(call);" << endl; - if(args_out.size() > 0) + if (args_out.size() > 0) { file << tab << tab << "::DBus::MessageIter ri = ret.reader();" << endl << endl; } - if(args_out.size() == 1) + if (args_out.size() == 1) { file << tab << tab << signature_to_type(args_out.front()->get("type")) << " argout;" << endl; file << tab << tab << "ri >> argout;" << endl; file << tab << tab << "return argout;" << endl; } - else if(args_out.size() > 1) + else if (args_out.size() > 1) { unsigned int i = 0; - for(Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i) + for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i) { - Xml::Node& arg = **ao; + Xml::Node &arg = **ao; string arg_name = arg.get("name"); - if(arg_name.length()) + if (arg_name.length()) file << tab << tab << "ri >> " << arg.get("name") << ";" << endl; else file << tab << tab << "ri >> argout" << i << ";" << endl; @@ -403,29 +403,29 @@ void generate_proxy( Xml::Document& doc, const char* filename ) << tab << "/* signal handlers for this interface" << endl << tab << " */" << endl; - for(Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) + for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) { - Xml::Node& signal = **si; + Xml::Node &signal = **si; Xml::Nodes args = signal["arg"]; - file << tab << "virtual void " << signal.get("name") << "( "; + file << tab << "virtual void " << signal.get("name") << "("; unsigned int i = 0; - for(Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai, ++i) + for (Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai, ++i) { - Xml::Node& arg = **ai; + Xml::Node &arg = **ai; file << "const " << signature_to_type(arg.get("type")) << "& "; string arg_name = arg.get("name"); - if(arg_name.length()) + if (arg_name.length()) file << arg_name; else file << "argin" << i; - if((ai+1 != args.end())) + if ((ai+1 != args.end())) file << ", "; } - file << " ) = 0;" << endl; + file << ") = 0;" << endl; } file << endl @@ -434,28 +434,28 @@ void generate_proxy( Xml::Document& doc, const char* filename ) << tab << "/* unmarshalers (to unpack the DBus message before calling the actual signal handler)" << endl << tab << " */" << endl; - for(Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) + for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) { - Xml::Node& signal = **si; + Xml::Node &signal = **si; Xml::Nodes args = signal["arg"]; - file << tab << "void " << stub_name(signal.get("name")) << "( const ::DBus::SignalMessage& sig )" << endl + file << tab << "void " << stub_name(signal.get("name")) << "(const ::DBus::SignalMessage &sig)" << endl << tab << "{" << endl; - if(args.size() > 0) + if (args.size() > 0) { file << tab << tab << "::DBus::MessageIter ri = sig.reader();" << endl << endl; } unsigned int i = 0; - for(Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai, ++i) + for (Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai, ++i) { - Xml::Node& arg = **ai; + Xml::Node &arg = **ai; file << tab << tab << signature_to_type(arg.get("type")) << " " ; string arg_name = arg.get("name"); - if(arg_name.length()) + if (arg_name.length()) file << arg_name << ";" << " ri >> " << arg_name << ";" << endl; else file << "arg" << i << ";" << " ri >> " << "arg" << i << ";" << endl; @@ -464,17 +464,17 @@ void generate_proxy( Xml::Document& doc, const char* filename ) file << tab << tab << signal.get("name") << "("; unsigned int j = 0; - for(Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai, ++j) + for (Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai, ++j) { - Xml::Node& arg = **ai; + Xml::Node &arg = **ai; string arg_name = arg.get("name"); - if(arg_name.length()) + if (arg_name.length()) file << arg_name; else file << "arg" << j; - if(ai+1 != args.end()) + if (ai+1 != args.end()) file << ", "; } @@ -487,7 +487,7 @@ void generate_proxy( Xml::Document& doc, const char* filename ) file << "};" << endl << endl; - for(unsigned int i = 0; i < nspaces; ++i) + for (unsigned int i = 0; i < nspaces; ++i) { file << "} "; } @@ -499,12 +499,12 @@ void generate_proxy( Xml::Document& doc, const char* filename ) file.close(); } -void generate_adaptor( Xml::Document& doc, const char* filename ) +void generate_adaptor(Xml::Document &doc, const char *filename) { cerr << "writing " << filename << endl; ofstream file(filename); - if(file.bad()) + if (file.bad()) { cerr << "unable to write file " << filename << endl; exit(-1); @@ -521,12 +521,12 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file << dbus_includes; - Xml::Node& root = *(doc.root); + Xml::Node &root = *(doc.root); Xml::Nodes interfaces = root["interface"]; - for(Xml::Nodes::iterator i = interfaces.begin(); i != interfaces.end(); ++i) + for (Xml::Nodes::iterator i = interfaces.begin(); i != interfaces.end(); ++i) { - Xml::Node& iface = **i; + Xml::Node &iface = **i; Xml::Nodes methods = iface["method"]; Xml::Nodes signals = iface["signal"]; Xml::Nodes properties = iface["property"]; @@ -535,7 +535,7 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) ms.insert(ms.end(), signals.begin(), signals.end()); string ifacename = iface.get("name"); - if(ifacename == "org.freedesktop.DBus.Introspectable" + if (ifacename == "org.freedesktop.DBus.Introspectable" ||ifacename == "org.freedesktop.DBus.Properties") { cerr << "skipping interface " << ifacename << endl; @@ -546,7 +546,7 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) string nspace; unsigned int nspaces = 0; - while(ss.str().find('.', ss.tellg()) != string::npos) + while (ss.str().find('.', ss.tellg()) != string::npos) { getline(ss, nspace, '.'); @@ -571,26 +571,26 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) << tab << ": ::DBus::InterfaceAdaptor(\"" << ifacename << "\")" << endl << tab << "{" << endl; - for(Xml::Nodes::iterator pi = properties.begin(); pi != properties.end(); ++pi) + for (Xml::Nodes::iterator pi = properties.begin(); pi != properties.end(); ++pi) { - Xml::Node& property = **pi; + Xml::Node &property = **pi; file << tab << tab << "bind_property(" << property.get("name") << ", " << "\"" << property.get("type") << "\", " - << ( property.get("access").find("read") != string::npos + << (property.get("access").find("read") != string::npos ? "true" - : "false" ) + : "false") << ", " - << ( property.get("access").find("write") != string::npos + << (property.get("access").find("write") != string::npos ? "true" - : "false" ) + : "false") << ");" << endl; } - for(Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) + for (Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) { - Xml::Node& method = **mi; + Xml::Node &method = **mi; file << tab << tab << "register_method(" << ifaceclass << ", " << method.get("name") << ", "<< stub_name(method.get("name")) @@ -600,24 +600,24 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file << tab << "}" << endl << endl; - file << tab << "::DBus::IntrospectedInterface* const introspect() const " << endl + file << tab << "::DBus::IntrospectedInterface *const introspect() const " << endl << tab << "{" << endl; - for(Xml::Nodes::iterator mi = ms.begin(); mi != ms.end(); ++mi) + for (Xml::Nodes::iterator mi = ms.begin(); mi != ms.end(); ++mi) { - Xml::Node& method = **mi; + Xml::Node &method = **mi; Xml::Nodes args = method["arg"]; file << tab << tab << "static ::DBus::IntrospectedArgument " << method.get("name") << "_args[] = " << endl << tab << tab << "{" << endl; - for(Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai) + for (Xml::Nodes::iterator ai = args.begin(); ai != args.end(); ++ai) { - Xml::Node& arg = **ai; + Xml::Node &arg = **ai; file << tab << tab << tab << "{ "; - if(arg.get("name").length()) + if (arg.get("name").length()) { file << "\"" << arg.get("name") << "\", "; } @@ -626,7 +626,7 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file << "0, "; } file << "\"" << arg.get("type") << "\", " - << ( arg.get("direction") == "in" ? "true" : "false" ) + << (arg.get("direction") == "in" ? "true" : "false") << " }," << endl; } file << tab << tab << tab << "{ 0, 0, 0 }" << endl @@ -636,9 +636,9 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file << tab << tab << "static ::DBus::IntrospectedMethod " << ifaceclass << "_methods[] = " << endl << tab << tab << "{" << endl; - for(Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) + for (Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) { - Xml::Node& method = **mi; + Xml::Node &method = **mi; file << tab << tab << tab << "{ \"" << method.get("name") << "\", " << method.get("name") << "_args }," << endl; } @@ -649,9 +649,9 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file << tab << tab << "static ::DBus::IntrospectedMethod " << ifaceclass << "_signals[] = " << endl << tab << tab << "{" << endl; - for(Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) + for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) { - Xml::Node& method = **si; + Xml::Node &method = **si; file << tab << tab << tab << "{ \"" << method.get("name") << "\", " << method.get("name") << "_args }," << endl; } @@ -662,20 +662,20 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file << tab << tab << "static ::DBus::IntrospectedProperty " << ifaceclass << "_properties[] = " << endl << tab << tab << "{" << endl; - for(Xml::Nodes::iterator pi = properties.begin(); pi != properties.end(); ++pi) + for (Xml::Nodes::iterator pi = properties.begin(); pi != properties.end(); ++pi) { - Xml::Node& property = **pi; + Xml::Node &property = **pi; file << tab << tab << tab << "{ " << "\"" << property.get("name") << "\", " << "\"" << property.get("type") << "\", " - << ( property.get("access").find("read") != string::npos + << (property.get("access").find("read") != string::npos ? "true" - : "false" ) + : "false") << ", " - << ( property.get("access").find("write") != string::npos + << (property.get("access").find("write") != string::npos ? "true" - : "false" ) + : "false") << " }," << endl; } @@ -700,9 +700,9 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) << tab << " * property() and property(value) to get and set a particular property" << endl << tab << " */" << endl; - for(Xml::Nodes::iterator pi = properties.begin(); pi != properties.end(); ++pi) + for (Xml::Nodes::iterator pi = properties.begin(); pi != properties.end(); ++pi) { - Xml::Node& property = **pi; + Xml::Node &property = **pi; string name = property.get("name"); string type = property.get("type"); string type_name = signature_to_type(type); @@ -718,57 +718,57 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) << tab << " * you will have to implement them in your ObjectAdaptor" << endl << tab << " */" << endl; - for(Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) + for (Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) { - Xml::Node& method = **mi; + Xml::Node &method = **mi; Xml::Nodes args = method["arg"]; Xml::Nodes args_in = args.select("direction","in"); Xml::Nodes args_out = args.select("direction","out"); file << tab << "virtual "; - if(args_out.size() == 0 || args_out.size() > 1 ) + if (args_out.size() == 0 || args_out.size() > 1) { file << "void "; } - else if(args_out.size() == 1) + else if (args_out.size() == 1) { file << signature_to_type(args_out.front()->get("type")) << " "; } - file << method.get("name") << "( "; + file << method.get("name") << "("; unsigned int i = 0; - for(Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i) + for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i) { - Xml::Node& arg = **ai; + Xml::Node &arg = **ai; file << "const " << signature_to_type(arg.get("type")) << "& "; string arg_name = arg.get("name"); - if(arg_name.length()) + if (arg_name.length()) file << arg_name; - if((i+1 != args_in.size() || args_out.size() > 1)) + if ((i+1 != args_in.size() || args_out.size() > 1)) file << ", "; } - if(args_out.size() > 1) + if (args_out.size() > 1) { unsigned int i = 0; - for(Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i) + for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i) { - Xml::Node& arg = **ao; + Xml::Node &arg = **ao; file << signature_to_type(arg.get("type")) << "&"; string arg_name = arg.get("name"); - if(arg_name.length()) + if (arg_name.length()) file << " " << arg_name; - if(i+1 != args_out.size()) + if (i+1 != args_out.size()) file << ", "; } } - file << " ) = 0;" << endl; + file << ") = 0;" << endl; } file << endl @@ -777,34 +777,34 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) << tab << "/* signal emitters for this interface" << endl << tab << " */" << endl; - for(Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) + for (Xml::Nodes::iterator si = signals.begin(); si != signals.end(); ++si) { - Xml::Node& signal = **si; + Xml::Node &signal = **si; Xml::Nodes args = signal["arg"]; - file << tab << "void " << signal.get("name") << "( "; + file << tab << "void " << signal.get("name") << "("; unsigned int i = 0; - for(Xml::Nodes::iterator a = args.begin(); a != args.end(); ++a, ++i) + for (Xml::Nodes::iterator a = args.begin(); a != args.end(); ++a, ++i) { - Xml::Node& arg = **a; + Xml::Node &arg = **a; file << "const " << signature_to_type(arg.get("type")) << "& arg" << i+1; - if(i+1 != args.size()) + if (i+1 != args.size()) file << ", "; } - file << " )" << endl + file << ")" << endl << tab << "{" << endl << tab << tab << "::DBus::SignalMessage sig(\"" << signal.get("name") <<"\");" << endl;; - if(args.size() > 0) + if (args.size() > 0) { file << tab << tab << "::DBus::MessageIter wi = sig.writer();" << endl; - for(unsigned int i = 0; i < args.size(); ++i) + for (unsigned int i = 0; i < args.size(); ++i) { file << tab << tab << "wi << arg" << i+1 << ";" << endl; } @@ -820,40 +820,40 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) << tab << "/* unmarshalers (to unpack the DBus message before calling the actual interface method)" << endl << tab << " */" << endl; - for(Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) + for (Xml::Nodes::iterator mi = methods.begin(); mi != methods.end(); ++mi) { - Xml::Node& method = **mi; + Xml::Node &method = **mi; Xml::Nodes args = method["arg"]; Xml::Nodes args_in = args.select("direction","in"); Xml::Nodes args_out = args.select("direction","out"); - file << tab << "::DBus::Message " << stub_name(method.get("name")) << "( const ::DBus::CallMessage& call )" << endl + file << tab << "::DBus::Message " << stub_name(method.get("name")) << "(const ::DBus::CallMessage &call)" << endl << tab << "{" << endl << tab << tab << "::DBus::MessageIter ri = call.reader();" << endl << endl; unsigned int i = 1; - for(Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i) + for (Xml::Nodes::iterator ai = args_in.begin(); ai != args_in.end(); ++ai, ++i) { - Xml::Node& arg = **ai; + Xml::Node &arg = **ai; file << tab << tab << signature_to_type(arg.get("type")) << " argin" << i << ";" << " ri >> argin" << i << ";" << endl; } - if(args_out.size() == 0) + if (args_out.size() == 0) { file << tab << tab; } - else if(args_out.size() == 1) + else if (args_out.size() == 1) { file << tab << tab << signature_to_type(args_out.front()->get("type")) << " argout1 = "; } else { unsigned int i = 1; - for(Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i) + for (Xml::Nodes::iterator ao = args_out.begin(); ao != args_out.end(); ++ao, ++i) { - Xml::Node& arg = **ao; + Xml::Node &arg = **ao; file << tab << tab << signature_to_type(arg.get("type")) << " argout" << i << ";" << endl; } file << tab << tab; @@ -861,20 +861,20 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file << method.get("name") << "("; - for(unsigned int i = 0; i < args_in.size(); ++i) + for (unsigned int i = 0; i < args_in.size(); ++i) { file << "argin" << i+1; - if((i+1 != args_in.size() || args_out.size() > 1)) + if ((i+1 != args_in.size() || args_out.size() > 1)) file << ", "; } - if(args_out.size() > 1) - for(unsigned int i = 0; i < args_out.size(); ++i) + if (args_out.size() > 1) + for (unsigned int i = 0; i < args_out.size(); ++i) { file << "argout" << i+1; - if(i+1 != args_out.size()) + if (i+1 != args_out.size()) file << ", "; } @@ -882,11 +882,11 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file << tab << tab << "::DBus::ReturnMessage reply(call);" << endl; - if(args_out.size() > 0) + if (args_out.size() > 0) { file << tab << tab << "::DBus::MessageIter wi = reply.writer();" << endl; - for(unsigned int i = 0; i < args_out.size(); ++i) + for (unsigned int i = 0; i < args_out.size(); ++i) { file << tab << tab << "wi << argout" << i+1 << ";" << endl; } @@ -900,7 +900,7 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file << "};" << endl << endl; - for(unsigned int i = 0; i < nspaces; ++i) + for (unsigned int i = 0; i < nspaces; ++i) { file << "} "; } @@ -912,9 +912,9 @@ void generate_adaptor( Xml::Document& doc, const char* filename ) file.close(); } -int main( int argc, char** argv ) +int main(int argc, char ** argv) { - if(argc < 2) + if (argc < 2) { usage(argv[0]); } @@ -928,26 +928,26 @@ int main( int argc, char** argv ) adaptor_mode = false; adaptor = 0; - for(int a = 1; a < argc; ++a) + for (int a = 1; a < argc; ++a) { - if(!strncmp(argv[a], "--proxy=", 8)) + if (!strncmp(argv[a], "--proxy=", 8)) { proxy_mode = true; proxy = argv[a] +8; } else - if(!strncmp(argv[a], "--adaptor=", 10)) + if (!strncmp(argv[a], "--adaptor=", 10)) { adaptor_mode = true; adaptor = argv[a] +10; } } - if(!proxy_mode && !adaptor_mode) usage(argv[0]); + if (!proxy_mode && !adaptor_mode) usage(argv[0]); ifstream xmlfile(argv[1]); - if(xmlfile.bad()) + if (xmlfile.bad()) { cerr << "unable to open file " << argv[1] << endl; return -1; @@ -960,20 +960,20 @@ int main( int argc, char** argv ) xmlfile >> doc; //cout << doc.to_xml(); } - catch(Xml::Error& e) + catch(Xml::Error &e) { cerr << "error parsing " << argv[1] << ": " << e.what() << endl; return -1; } - if(!doc.root) + if (!doc.root) { cerr << "empty document" << endl; return -1; } - if(proxy_mode) generate_proxy(doc, proxy); - if(adaptor_mode) generate_adaptor(doc, adaptor); + if (proxy_mode) generate_proxy(doc, proxy); + if (adaptor_mode) generate_adaptor(doc, adaptor); return 0; }