From d083d0716776b60a9396053b204497b4577b9ec4 Mon Sep 17 00:00:00 2001 From: Andreas Volz Date: Thu, 3 Jun 2010 20:44:32 +0200 Subject: SourceForge Patches ID: 2701443 - Add methods to adjust timeout. Submitted: Oron Peled ( oron ) - 2009-03-21 23:27:55 CET --- include/dbus-c++/object.h | 10 ++++++++++ src/eventloop-integration.cpp | 7 +++++-- src/object.cpp | 12 ++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/dbus-c++/object.h b/include/dbus-c++/object.h index 962bf77..494aa82 100644 --- a/include/dbus-c++/object.h +++ b/include/dbus-c++/object.h @@ -52,6 +52,10 @@ public: inline Connection &conn(); + void set_timeout(int new_timeout = -1); + + inline int get_timeout() const; + private: DXXAPILOCAL virtual bool handle_message(const Message &) = 0; @@ -63,6 +67,7 @@ private: Connection _conn; DBus::Path _path; std::string _service; + int _default_timeout; }; /* @@ -83,6 +88,11 @@ const std::string &Object::service() const return _service; } +int Object::get_timeout() const +{ + return _default_timeout; +} + /* */ diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp index d801574..8b9c49b 100644 --- a/src/eventloop-integration.cpp +++ b/src/eventloop-integration.cpp @@ -109,8 +109,11 @@ Timeout *BusDispatcher::add_timeout(Timeout::Internal *ti) bt->expired = new Callback(this, &BusDispatcher::timeout_expired); bt->data(bt); - debug_log("added timeout %p (%s) interval=%d", - bt, ((Timeout *)bt)->enabled() ? "on":"off", ((Timeout *)bt)->interval()); + debug_log("added timeout %p (%s) (%d millies)", + bt, + ((Timeout*)bt)->enabled() ? "on":"off", + ((Timeout*)bt)->interval() + ); return bt; } diff --git a/src/object.cpp b/src/object.cpp index f7d0916..88c3bb0 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -40,7 +40,7 @@ using namespace DBus; Object::Object(Connection &conn, const Path &path, const char *service) -: _conn(conn), _path(path), _service(service ? service : "") +: _conn(conn), _path(path), _service(service ? service : ""), _default_timeout(-1) { } @@ -48,6 +48,14 @@ Object::~Object() { } +void Object::set_timeout(int new_timeout) +{ + debug_log("%s: %d millies", __PRETTY_FUNCTION__, new_timeout); + if(new_timeout < 0 && new_timeout != -1) + throw ErrorInvalidArgs("Bad timeout, cannot set it"); + _default_timeout = new_timeout; +} + struct ObjectAdaptor::Private { static void unregister_function_stub(DBusConnection *, void *); @@ -329,7 +337,7 @@ Message ObjectProxy::_invoke_method(CallMessage &call) if (call.destination() == NULL) call.destination(service().c_str()); - return conn().send_blocking(call); + return conn().send_blocking(call, get_timeout()); } bool ObjectProxy::_invoke_method_noreply(CallMessage &call) -- cgit v1.2.1