From: František Dvořák Date: Wed, 11 Sep 2013 13:59:42 +0000 (+0200) Subject: Change wrap calls in VFS plugin. X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=e692abf8481d87ba55a475cd3fa12627db78c32f;p=dmlite-plugins-vfs.git Change wrap calls in VFS plugin. --- diff --git a/src/Throw.cpp b/src/Throw.cpp index 15a2e9b..a3ba6f5 100644 --- a/src/Throw.cpp +++ b/src/Throw.cpp @@ -7,27 +7,30 @@ #include "Vfs.h" - -void dmlite::ThrowExceptionFromErrno(int err, const char* extra) throw(DmException) -{ - if (extra == 0) extra = ""; - throw DmException(err, "%s: %s", strerror(err), extra); +void dmlite::vfsThrowHelper(const std::string& func, int code, const std::string& msg) throw (DmException) { + throw DmException(code, "VfsCatalog::" + func + "(): " + msg); } -int dmlite::wrapCall(int r) throw (DmException) -{ - if (r < 0) - ThrowExceptionFromErrno(errno); +int dmlite::vfsWrapCallHelper(const std::string &func, int r, const std::string& msg) throw (DmException) { + if (r < 0) { + if (msg.length() != 0) + vfsThrowHelper(func, errno, msg + ": " + strerror(errno)); + else + vfsThrowHelper(func, errno, strerror(errno)); + } return r; } -void* dmlite::wrapCall(void* p) throw (DmException) -{ - if (p == NULL && errno != 0) - ThrowExceptionFromErrno(errno); +void *dmlite::vfsWrapCallHelper(const std::string &func, void *p, const std::string& msg) throw (DmException) { + if (!p) { + if (msg.length() != 0) + vfsThrowHelper(func, errno, msg + ": " + strerror(errno)); + else + vfsThrowHelper(func, errno, strerror(errno)); + } return p; } diff --git a/src/Vfs.h b/src/Vfs.h index 5ca8f9f..02ca183 100644 --- a/src/Vfs.h +++ b/src/Vfs.h @@ -10,6 +10,15 @@ #include #include +#define vfsThrowErrno(MSG) dmlite::vfsThrowHelper(__func__, DMLITE_SYSERR(errno), (MSG)) +#define vfsThrow(CODE, MSG) dmlite::vfsThrowHelper(__func__, (CODE), (MSG)) + +#ifdef __GNUC__ + #define wrapCall(RETVAL, MSG...) dmlite::vfsWrapCallHelper(__func__, (RETVAL) , ##MSG) +#else + #define wrapCall(RETVAL, ...) dmlite::vfsWrapCallHelper(__func__, (RETVAL) , ##__VA_ARGS__) +#endif + namespace dmlite { /// Concrete factory for DPM wrapper @@ -39,9 +48,9 @@ namespace dmlite { unsigned tokenLife_; }; - void ThrowExceptionFromErrno(int err, const char* extra = 0x00) throw(DmException); - int wrapCall(int ret) throw (DmException); - void* wrapCall(void* ret) throw (DmException); + void vfsThrowHelper(const std::string& func, int code, const std::string& msg = "") throw (DmException); + int vfsWrapCallHelper(const std::string &func, int r, const std::string& msg = "") throw (DmException); + void *vfsWrapCallHelper(const std::string &func, void *p, const std::string& msg = "") throw (DmException); }; diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index e7f1ec0..c1f09c3 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -254,7 +254,7 @@ Directory* VfsCatalog::openDir(const std::string& path) throw (DmException) privateDir->dir = opendir(path.c_str()); if (privateDir->dir == NULL) { delete privateDir; - ThrowExceptionFromErrno(errno); + vfsThrowErrno("error opening directory '" + path + "'"); return NULL; }