ewmscp  ..
dcapCommon.h
Go to the documentation of this file.
1 #ifndef __dcapCommon_h__
2 #define __dcapCommon_h__
3 #define _REENTRANT
4 #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64
5 #define dcapStat stat64
6 #else
7 #define dcapStat stat
8 #endif
9 
10 
11 #include "ioHandle.h"
12 #include "pathHandler.h"
13 #include <dcap.h>
14 #include <throwcall.h>
15 #include <mutex>
16 #include <iostream>
17 
18 
19 namespace throwcall {
20  namespace dcap {
21  template <typename T, typename ... Args> inline void good0(T call, const Args& ... args) {
22  if (__builtin_expect(call, 0)) {
23  std::ostringstream msg;
24  conCatString(msg, "dcap error ", dc_errno, " (", dc_strerror(dc_errno), ") ", args...);
25  throw std::runtime_error(msg.str());
26  }
27  };
28  template <typename T, typename t, typename ... Args> inline T badval(T call, t badvalue, const Args& ... args) {
29  if (__builtin_expect(call == badvalue, false)) {
30  std::ostringstream msg;
31  conCatString(msg, "dcap error ", dc_errno, " (", dc_strerror(dc_errno), ") ", args...);
32  throw std::runtime_error(msg.str());
33  }
34  return call;
35  };
36  } // namespace dcap
37 } // namespace throwcall
38 
39 
40 class dCapLock: public std::unique_lock<std::mutex> {
41  // because the dcap lib has only one extra option instance we need to us a lock
42  // around handling them. can be realeased once dc_bla... returns
43  protected:
44  static std::mutex extraOptionMutex;
45  const char *f;
46  const char *F;
47  int l;
48  public:
49  dCapLock(const char *aFunc = __builtin_FUNCTION(),
50  int aLine = __builtin_LINE(),
51  const char *aFile = __builtin_FILE()): std::unique_lock<std::mutex>(extraOptionMutex) {
52 
53  f = aFile;
54  l = aLine;
55  F = aFunc;
56  // std::cerr << f << ":" << l << ": " << F << ": lock\n";
57  dc_resetExtraOption();
58  };
60  //std::cerr << f << ":" << l << ": " << F << ": unlock\n";
61  }
62 };
63 
64 
65 class dcapCommon: virtual public pathHandler {
66  public:
67  dcapCommon();
68  static std::string fixPathUrl(const std::string& path);
69  bool pathExists(const std::string& path) override;
70  std::unique_ptr<const genericStat> getStat(const std::string& path,
71  bool followLink) override;
72 };
73 
74 class dcapIoCommon: virtual public ioHandle {
75  protected:
76  const std::string path;
77  int fd = -1;
78  public:
79  dcapIoCommon(const std::string& aPath);
80  std::unique_ptr<const genericStat> getStat() override;
81 };
82 
83 #endif
throwcall::dcap::badval
T badval(T call, t badvalue, const Args &... args)
Definition: dcapCommon.h:28
dcapIoCommon
Definition: dcapCommon.h:74
throwcall::conCatString
void conCatString(std::ostringstream &msg, const T &begin)
Definition: throwcall.h:26
dCapLock
Definition: dcapCommon.h:40
throwcall
Definition: throwcall.h:25
dcapCommon::dcapCommon
dcapCommon()
Definition: dcapCommon.cpp:119
dCapLock::l
int l
Definition: dcapCommon.h:47
dcapIoCommon::path
const std::string path
Definition: dcapCommon.h:76
dcapIoCommon::getStat
std::unique_ptr< const genericStat > getStat() override
Definition: dcapCommon.cpp:189
dCapLock::~dCapLock
~dCapLock()
Definition: dcapCommon.h:59
dcapCommon::fixPathUrl
static std::string fixPathUrl(const std::string &path)
Definition: dcapCommon.cpp:127
throwcall.h
ioHandle.h
dcapIoCommon::dcapIoCommon
dcapIoCommon(const std::string &aPath)
Definition: dcapCommon.cpp:181
dCapLock::extraOptionMutex
static std::mutex extraOptionMutex
Definition: dcapCommon.h:44
pathHandler
Definition: pathHandler.h:6
dcapCommon::pathExists
bool pathExists(const std::string &path) override
Definition: dcapCommon.cpp:146
throwcall::dcap::good0
void good0(T call, const Args &... args)
Definition: dcapCommon.h:21
pathHandler.h
dCapLock::F
const char * F
Definition: dcapCommon.h:46
ioHandle
class as base for inputHandler::base::reader and outputHandler::base::writer containing the common pa...
Definition: ioHandle.h:15
dcapIoCommon::fd
int fd
Definition: dcapCommon.h:77
dCapLock::dCapLock
dCapLock(const char *aFunc=__builtin_FUNCTION(), int aLine=__builtin_LINE(), const char *aFile=__builtin_FILE())
Definition: dcapCommon.h:49
dcapCommon
Definition: dcapCommon.h:65
dCapLock::f
const char * f
Definition: dcapCommon.h:45
dcapCommon::getStat
std::unique_ptr< const genericStat > getStat(const std::string &path, bool followLink) override
Definition: dcapCommon.cpp:157