ewmscp  ..
followInotifyWatchRequestProvider.cpp
Go to the documentation of this file.
2 #include "errMsgQueue.h"
3 #include <string.h>
4 
5 
36 
37 
39  char delimiter = nullDelimiter ? '\0' : '\n';
40  std::string line;
41 
42  while (stream) {
43  if (stopRequest::Requested()) {
45  "request provider", "stop request received"
46  , "ignoring further requests");
47  break;
48  }
49  char cmdbuff[4] = {0, 0, 0, 0};
50  stream.read(cmdbuff, 3);
51  auto readTime = copyRequest::clock_type::now();
52  if (stream.eof()) {
53  break;
54  }
55 
56  double timestampAsDouble;
57  stream >> timestampAsDouble;
58  auto timestamp = copyRequest::clock_type::time_point(std::chrono::duration_cast<copyRequest::clock_type::duration>(std::chrono::duration<double>(timestampAsDouble)));
59  stream.ignore(); // skip one character after timestamp
60  std::getline(stream, line, delimiter);
61 
62  if (strcmp(cmdbuff, "ig ") == 0) { // ignore this line, to be used as keepalive
63  continue;
64  }
65 
66  if (strcmp(cmdbuff, "mv ") == 0) { // special case move...
67  std::string target;
68  std::getline(stream, target, delimiter);
69  std::string fromPath;
70  auto mapEntryD = getDstPath(line, fromPath);
71  std::string dstPath;
72  auto mapEntryS = getDstPath(target, dstPath);
73  handleMove(target, dstPath, fromPath, line, mapEntryD, timestamp);
74  } else {
75  auto requestForRemoval = strcmp(cmdbuff, "rm ") == 0;
76  std::string dstPath;
77  auto mapEntry = getDstPath(line, dstPath);
78 
79  handleOther(line, dstPath, mapEntry, timestamp, requestForRemoval);
80  }
81  auto enqueueDoneTime = copyRequest::clock_type::now();
82  copyRequest::base::tEnqueueStat.addValue(enqueueDoneTime - readTime);
83 
84  }
85 }
errMsgQueue.h
errMsg::location
class for defining the location of a error message in the source code.
Definition: errMsgQueue.h:14
copyRequest::base::tEnqueueStat
static statCollector::typed< copyRequest::clock_type::duration > tEnqueueStat
Definition: copyRequest.h:320
followRequestProvider::handleMove
virtual void handleMove(const std::string &srcPath, const std::string &dstPath, const std::string &fromPath, const std::string &origPath, const singleMap &mapEntry, copyRequest::clock_type::time_point timestamp)
Definition: followRequestProvider.cpp:31
errMsg::level::info
@ info
followInotifyWatchRequestProvider::factory
static factoryTemplate< followInotifyWatchRequestProvider > factory
Definition: followInotifyWatchRequestProvider.h:7
followInotifyWatchRequestProvider::followStream
void followStream(std::istream &stream) override
Definition: followInotifyWatchRequestProvider.cpp:38
followInotifyWatchRequestProvider.h
followRequestProvider::nullDelimiter
static options::single< bool > nullDelimiter
Definition: followRequestProvider.h:20
stopRequest::Requested
static bool Requested()
Definition: ewmscp.cpp:153
errMsg::emit
void emit(level aLogLevel, const location &loc, const std::string &aObject, const std::string &aAction, const Args &... args)
function to create and enqueue a message, this is the only way that messages should be created!
Definition: errMsgQueue.h:148
statCollector::typed::addValue
void addValue(T value)
Definition: statCollector.h:37
requestProvider::getDstPath
virtual const singleMap & getDstPath(const std::string &source, std::string &destination, bool baseNameOnly=false)
get detstination papth for a given source path
Definition: requestProvider.cpp:30
followRequestProvider::handleOther
virtual void handleOther(const std::string &srcPath, const std::string &dstPath, const singleMap &mapEntry, copyRequest::clock_type::time_point timestamp, bool requestForRemoval)
Definition: followRequestProvider.cpp:41
defineStatic
#define defineStatic(var,...)
defines a static variable and instatitates the constructor with the variable number of arguments.
Definition: ewmscp.h:42