ewmscp  ..
ewmscp.h
Go to the documentation of this file.
1 #ifndef __ewmscp_h__
2 #define __ewmscp_h__
3 
4 /*
5  ewmscp: copy program with extended functionality
6  Copyright (C) 2018 Juergen Hannappel
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21 
22 
23 #include <chrono>
24 #include <atomic>
25 #include <Options.h>
26 
27 #include <forward_list>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #include <system_error>
31 
32 #include "checksumBase.h"
33 #include "inputHandler.h"
34 #include "messageQueue.h"
35 #include "outputHandler.h"
36 #include "throttle.h"
37 
42 #define defineStatic(var,...) decltype(var) var(__VA_ARGS__)
43 #define defineStaticNoArg(var) decltype(var) var
45 
52 class modeBitType : public options::fundamental_wrapper<mode_t> {
53  public:
54  modeBitType(unsigned int aBits = 0): fundamental_wrapper(aBits) {};
55  friend std::ostream& operator<<(std::ostream& out, const modeBitType& item) {
56  const mode_t& bits(item);
57  auto flags = out.flags();
58  out << std::oct << bits;
59  out.flags(flags);
60  return out;
61  }
62  friend std::istream& operator>>(std::istream& in, modeBitType& item) {
63  mode_t& bits(item);
64  auto flags = in.flags();
65  in >> std::oct >> bits;
66  in.flags(flags);
67  return in;
68  }
69 };
70 
71 class preservables {
72  public:
73  preservables() noexcept :
74  mode(false),
75  ownership(false),
76  timestamps(false),
77  attrs(false),
78  acls(false) {};
79  bool mode;
80  bool ownership;
81  bool timestamps;
82  bool attrs;
83  bool acls;
84  void set(const std::string& opt);
85 
86 };
87 
88 
91 extern preservables preserve;
106 #ifdef WithJsonCpp
107 extern options::single<std::string> prefixJsonName;
108 extern options::map<std::string> jsonExtraFields;
109 #endif
110 
113 extern std::forward_list<const checksum::base::factoryClass*> checksumCreators;
114 
116 
117 class stopRequest {
118  public:
119  enum class handlerIdType {
120  unhandled,
121  undefined,
124  };
125  private:
127  static std::string reason;
128  static void sigHandler(int);
129  static volatile std::atomic<bool> stopRequested;
130  public:
131  static void instantiate(handlerIdType id);
132  static bool Requested();
133  static bool Requested(handlerIdType id);
134  static void RequestStop(const std::string& aReason);
135  static void ThrowUpReasonably();
136 };
137 
138 #endif
modeBitType
wrapper for mode_t.
Definition: ewmscp.h:52
verbose
options::single< bool > verbose
dereference
options::single< bool > dereference
options::single< int >
quiet
options::single< bool > quiet
options::fundamental_wrapper< mode_t >::fundamental_wrapper
fundamental_wrapper()
Definition: Options.h:86
checksumBase.h
stopRequest::instantiate
static void instantiate(handlerIdType id)
Definition: ewmscp.cpp:143
noCopy
options::single< bool > noCopy
workDir
options::single< std::string > workDir
options::single< bool >
class specialisation for options of type bool
Definition: Options.h:595
stopRequest
Definition: ewmscp.h:117
requestProviderName
options::single< std::string > requestProviderName
statPrefix
options::single< std::string > statPrefix
outputHandlerName
options::single< std::string > outputHandlerName
modeBitType::modeBitType
modeBitType(unsigned int aBits=0)
Definition: ewmscp.h:54
modeBitType::operator>>
friend std::istream & operator>>(std::istream &in, modeBitType &item)
Definition: ewmscp.h:62
preservables::mode
bool mode
Definition: ewmscp.h:78
stopRequest::stopRequested
static volatile std::atomic< bool > stopRequested
Definition: ewmscp.h:129
gid
options::single< int > gid
Options.h
readRateLimit
throttle::watch readRateLimit
options::map< std::string >
modeBitType::operator<<
friend std::ostream & operator<<(std::ostream &out, const modeBitType &item)
Definition: ewmscp.h:55
stopRequest::handlerId
static handlerIdType handlerId
Definition: ewmscp.h:126
stopRequest::handlerIdType::processLoop
@ processLoop
preservables::timestamps
bool timestamps
Definition: ewmscp.h:81
throttle::watch
class for limiting process load.
Definition: throttle.h:18
stopRequest::sigHandler
static void sigHandler(int)
Definition: ewmscp.cpp:139
preservables::attrs
bool attrs
Definition: ewmscp.h:82
fileRateLimit
throttle::watch fileRateLimit
preservables::ownership
bool ownership
Definition: ewmscp.h:80
preservables::set
void set(const std::string &opt)
Definition: ewmscp.cpp:185
preservables::acls
bool acls
Definition: ewmscp.h:83
stopRequest::Requested
static bool Requested()
Definition: ewmscp.cpp:153
options::fundamental_wrapper
wrapper class for fundamental types
Definition: Options.h:82
messageQueue.h
preservables::preservables
preservables() noexcept
Definition: ewmscp.h:73
inputHandlerName
options::single< std::string > inputHandlerName
throttle.h
uid
options::single< int > uid
stopRequest::handlerIdType::unhandled
@ unhandled
stopRequest::handlerIdType::requestProvider
@ requestProvider
checksumCreators
std::forward_list< const checksum::base::factoryClass * > checksumCreators
Definition: ewmscp.cpp:113
stopRequest::handlerIdType::undefined
@ undefined
stopRequest::reason
static std::string reason
Definition: ewmscp.h:127
printStatAnyway
options::single< bool > printStatAnyway
nThreads
options::single< unsigned int > nThreads
stopRequest::ThrowUpReasonably
static void ThrowUpReasonably()
Definition: ewmscp.cpp:173
continueOnError
options::single< bool > continueOnError
writeRateLimit
throttle::watch writeRateLimit
messageQueue::queue
Definition: messageQueue.h:8
stopRequest::handlerIdType
handlerIdType
Definition: ewmscp.h:119
preservables
Definition: ewmscp.h:71
resultOutput
messageQueue::queue * resultOutput
stopRequest::RequestStop
static void RequestStop(const std::string &aReason)
Definition: ewmscp.cpp:162
preserve
preservables preserve
set of properties to preserve in the copy
Definition: ewmscp.cpp:111
outputHandler.h
inputHandler.h
modeBits
options::single< modeBitType > modeBits