diff options
author | Andreas Volz <andreas@optolix.mittelerde> | 2009-12-01 23:31:49 +0100 |
---|---|---|
committer | Andreas Volz <andreas@optolix.mittelerde> | 2009-12-01 23:31:49 +0100 |
commit | c505052353b6338e5cdd73133bd45aee2f8cf1de (patch) | |
tree | ecc3018446d94fe9c6a1eea838b1a288200f23a5 | |
parent | e23c8c47503fc6a24886173e233355414975cb67 (diff) | |
download | dbus-c++-c505052353b6338e5cdd73133bd45aee2f8cf1de.tar.gz |
return check
-rw-r--r-- | include/dbus-c++/eventloop-integration.h | 8 | ||||
-rw-r--r-- | include/dbus-c++/util.h | 12 | ||||
-rw-r--r-- | src/eventloop-integration.cpp | 6 |
3 files changed, 22 insertions, 4 deletions
diff --git a/include/dbus-c++/eventloop-integration.h b/include/dbus-c++/eventloop-integration.h index 8ea2b08..b8e02c7 100644 --- a/include/dbus-c++/eventloop-integration.h +++ b/include/dbus-c++/eventloop-integration.h @@ -25,6 +25,7 @@ #ifndef __DBUSXX_EVENTLOOP_INTEGRATION_H #define __DBUSXX_EVENTLOOP_INTEGRATION_H +#include <errno.h> #include "api.h" #include "dispatcher.h" #include "util.h" @@ -65,11 +66,12 @@ public: BusDispatcher() : _running(false) { //pipe to create a new fd used to unlock a dispatcher at any - // moment (used by leave function) - pipe(_pipe); + // moment (used by leave function) + int ret = pipe(_pipe); + if (ret == -1) throw Error("PipeError:errno", toString(errno).c_str()); + _fdunlock[0] = _pipe[0]; _fdunlock[1] = _pipe[1]; - } ~BusDispatcher() diff --git a/include/dbus-c++/util.h b/include/dbus-c++/util.h index 225e1ca..b46732f 100644 --- a/include/dbus-c++/util.h +++ b/include/dbus-c++/util.h @@ -25,6 +25,9 @@ #ifndef __DBUSXX_UTIL_H #define __DBUSXX_UTIL_H +#include <sstream> +#include <iostream> +#include <iomanip> #include "api.h" #include "debug.h" @@ -268,6 +271,15 @@ private: C *_c; M _m; }; +/// create std::string from any number +template <typename T> +std::string toString (const T &thing, int w = 0, int p = 0) +{ + std::ostringstream os; + os << std::setw(w) << std::setprecision(p) << thing; + return os.str(); +} + } /* namespace DBus */ #endif//__DBUSXX_UTIL_H diff --git a/src/eventloop-integration.cpp b/src/eventloop-integration.cpp index 9e333fe..d801574 100644 --- a/src/eventloop-integration.cpp +++ b/src/eventloop-integration.cpp @@ -33,6 +33,7 @@ #include <sys/poll.h> #include <dbus/dbus.h> +#include <errno.h> using namespace DBus; @@ -87,7 +88,10 @@ void BusDispatcher::enter() void BusDispatcher::leave() { _running = false; - write(_fdunlock[1],"exit",strlen("exit")); + + int ret = write(_fdunlock[1],"exit",strlen("exit")); + if (ret == -1) throw Error("WriteError:errno", toString(errno).c_str()); + close(_fdunlock[1]); close(_fdunlock[0]); } |