ewmscp  ..
fileInWork.cpp
Go to the documentation of this file.
1 #include "fileInWork.h"
2 #include "copyRequest.h"
3 
4 namespace copyRequest {
8 
9 
10  std::ostream& operator<< (std::ostream& stream,
12  switch (t) {
14  stream << "none";
15  break;
17  stream << "copy";
18  break;
20  stream << "move";
21  break;
23  stream << "unlink";
24  break;
25  default:
26  stream << "oops";
27  break;
28  }
29  return stream;
30  }
31 
33  std::unique_lock<decltype(filesInWorkMutex)> lock(filesInWorkMutex);
34 
35  timerInst(wait);
36  while (! filesInWork.empty()) {
37  cv.wait(lock);
38  }
39  }
40 
42  if (this->empty()) {
43  return queuedRequestType;
44  } else {
45  return this->back()->getSlotType();
46  }
47  }
48 
49 
50  void fileInWork::inserter::enRegister(std::unique_ptr<copyRequest::base>& request) {
51  request->registerIterator(iter);
52  iter->second.remove_if([&request](std::unique_ptr<copyRequest::base>& item) {
53  return item->getSlotType() == request->getSlotType();
54  });
55  iter->second.emplace_back(std::move(request));
56  }
57  void fileInWork::inserter::markForQueueing(std::unique_ptr<copyRequest::base>& request) {
58  request->registerIterator(iter);
59  getFileInWork().queuedRequestType = request->getSlotType();
60  }
61 
62 
64  lockuser(request.getFilesInWorkIteraror()) {
65  }
66  std::unique_ptr<copyRequest::base> fileInWork::eraser::getNext() {
67  if (iter == filesInWork.end()) { // happens for nonFollow request providers
68  return nullptr;
69  }
70  if (iter->second.empty()) {
71  timerInst(erase);
72  filesInWork.erase(iter);
73  return nullptr;
74  } else {
75  auto request = std::move(iter->second.front());
76  iter->second.pop_front();
77  iter->second.queuedRequestType = request->getSlotType();
78  return request;
79  }
80  }
82  lockuser(request.getFilesInWorkIteraror()) {
84  request.state.set(newType);
85  }
86 }; // end namespace copyRequest
fileInWork.h
copyRequest::fileInWork::filesInWork
static std::map< std::string, fileInWork > filesInWork
maps file names to filesInWork objects
Definition: fileInWork.h:30
copyRequest::fileInWork::slotTypes::copy
@ copy
copyRequest::fileInWork::slotTypes::move
@ move
copyRequest::stateBitType
stateBitType
Definition: copyRequestTypes.h:50
copyRequest::fileInWork::slotTypes::none
@ none
copyRequest::fileInWork::lockuser::iter
decltype(filesInWork) ::iterator iter
Definition: fileInWork.h:42
copyRequest::base
class for copy requests.
Definition: copyRequest.h:99
copyRequest::fileInWork::typeChanger::typeChanger
typeChanger(copyRequest::base &request, stateBitType newType)
Definition: fileInWork.cpp:81
copyRequest::fileInWork::lockuser
this class handles the mutex protection of the filesInWork map
Definition: fileInWork.h:39
copyRequest::fileInWork::slotTypes::unlink
@ unlink
copyRequest::base::getSlotType
fileInWork::slotTypes getSlotType() const
Definition: copyRequest.h:348
copyRequest::fileInWork::inserter::enRegister
void enRegister(std::unique_ptr< copyRequest::base > &request)
register a request in the fileInWork list
Definition: fileInWork.cpp:50
copyRequest::operator<<
std::ostream & operator<<(std::ostream &stream, const copyRequest::clock_type::time_point &t)
Definition: copyRequest.cpp:1946
copyRequest::fileInWork::inserter::markForQueueing
void markForQueueing(std::unique_ptr< copyRequest::base > &request)
Definition: fileInWork.cpp:57
copyRequest::fileInWork::cv
static std::condition_variable cv
needed for signaling that no file is in work anymore
Definition: fileInWork.h:32
copyRequest::fileInWork::eraser::getNext
std::unique_ptr< copyRequest::base > getNext()
Definition: fileInWork.cpp:66
defineStaticNoArg
#define defineStaticNoArg(var)
defines a static variable that needs no arguments to it's constructor
Definition: ewmscp.h:44
copyRequest::stateBitType::action
@ action
copyRequest::base::registerIterator
void registerIterator(decltype(filesInWorkIterator) iter)
Definition: copyRequest.h:342
copyRequest.h
enumAsBitmask::set
void set(const T aBits)
Definition: enumAsBitmask.h:34
copyRequest::base::state
stateType state
Definition: copyRequest.h:282
copyRequest::fileInWork::waitForAllInstancesGone
static void waitForAllInstancesGone()
Definition: fileInWork.cpp:32
copyRequest::fileInWork::queuedRequestType
slotTypes queuedRequestType
Definition: fileInWork.h:28
timerInst
#define timerInst(subfunc)
Definition: timer.h:157
copyRequest::fileInWork::getLatestRequestType
slotTypes getLatestRequestType() const
Definition: fileInWork.cpp:41
copyRequest::fileInWork::eraser::eraser
eraser(const copyRequest::base &request)
Definition: fileInWork.cpp:63
copyRequest::fileInWork::filesInWorkMutex
static std::mutex filesInWorkMutex
protects the filesInWork map
Definition: fileInWork.h:31
copyRequest::fileInWork::slotTypes
slotTypes
Definition: fileInWork.h:23
enumAsBitmask::clear
void clear(const T aBits)
Definition: enumAsBitmask.h:31
copyRequest
Definition: checksumTestRequestProvider.cpp:25