Change wrap calls in VFS plugin.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 11 Sep 2013 13:59:42 +0000 (15:59 +0200)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Wed, 11 Sep 2013 13:59:42 +0000 (15:59 +0200)
src/Throw.cpp
src/Vfs.h
src/VfsNs.cpp

index 15a2e9b..a3ba6f5 100644 (file)
@@ -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;
 }
index 5ca8f9f..02ca183 100644 (file)
--- a/src/Vfs.h
+++ b/src/Vfs.h
 #include <dmlite/cpp/io.h>
 #include <dmlite/cpp/poolmanager.h>
 
+#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);
 
 };
 
index e7f1ec0..c1f09c3 100644 (file)
@@ -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;
   }