17 #ifndef LIB_WINSS_SVSCAN_SERVICE_HPP_ 18 #define LIB_WINSS_SVSCAN_SERVICE_HPP_ 24 #include "easylogging/easylogging++.hpp" 25 #include "../windows_interface.hpp" 26 #include "../filesystem_interface.hpp" 27 #include "../handle_wrapper.hpp" 30 namespace fs = std::experimental::filesystem;
41 template<
typename TServiceProcess>
55 SECURITY_ATTRIBUTES sa;
56 sa.nLength =
sizeof(SECURITY_ATTRIBUTES);
57 sa.bInheritHandle = FALSE;
58 sa.lpSecurityDescriptor =
nullptr;
60 HANDLE stdin_pipe =
nullptr;
61 HANDLE stdout_pipe =
nullptr;
63 if (!
WINDOWS.CreatePipe(&stdin_pipe, &stdout_pipe, &sa, 0)) {
64 VLOG(1) <<
"CreatePipe() failed: " << ::GetLastError();
75 static constexpr
const char kLogDir[4] =
"log";
88 main(TServiceProcess(name)),
89 log(TServiceProcess(name / fs::path(kLogDir))) {}
99 main(std::move(s.main)), log(std::move(s.log)),
100 flagged(s.flagged) {}
133 if (main.IsCreated()) {
139 if (
FILESYSTEM.DirectoryExists(log.GetServiceDir())) {
140 VLOG(3) <<
"Log directory exists for service " <<
name;
142 log.Start(pipes,
true);
145 main.Start(pipes,
false);
154 virtual bool Close(
bool ignore_flagged) {
155 if (ignore_flagged || !flagged) {
173 name = std::move(s.name);
174 main = std::move(s.main);
175 log = std::move(s.log);
187 #endif // LIB_WINSS_SVSCAN_SERVICE_HPP_ A wrapper for a Windows HANDLE.
Definition: handle_wrapper.hpp:39
ServiceTmpl()
The default service template constructor.
Definition: service.hpp:80
TServiceProcess log
The log supervisor.
Definition: service.hpp:46
ServiceTmpl & operator=(ServiceTmpl &&s)
Moves the service object to this object.
Definition: service.hpp:172
#define WINDOWS
Definition: windows_interface.hpp:25
ServiceTmpl(const std::string &name)
Initializes the service with the name and directory.
Definition: service.hpp:87
Definition: case_ignore.hpp:23
virtual void Check()
Checks the service is running.
Definition: service.hpp:130
bool flagged
Flagged for removal.
Definition: service.hpp:47
TServiceProcess main
The main supervisor.
Definition: service.hpp:45
winss::ServicePipes CreatePipes()
Creates pipes for redirecting STDIN and STDOUT.
Definition: service.hpp:54
A template for a service.
Definition: service.hpp:42
virtual bool Close(bool ignore_flagged)
Close the service.
Definition: service.hpp:154
static constexpr const char kLogDir[4]
The log definition.
Definition: service.hpp:75
#define FILESYSTEM
Definition: filesystem_interface.hpp:26
ServiceTmpl< winss::ServiceProcess > Service
Concrete service implementation.
Definition: service.hpp:184
virtual const std::string & GetName() const
Gets the name of the service.
Definition: service.hpp:107
Holds the STDIN and STDOUT pipes for redirecting.
Definition: service_process.hpp:34
ServiceTmpl(ServiceTmpl &&s)
Creates a new service and moves it from an old one.
Definition: service.hpp:98
ServiceTmpl & operator=(const ServiceTmpl &)=delete
No copy.
std::string name
The name of the service.
Definition: service.hpp:44
virtual bool IsFlagged() const
Gets if the service is flagged or not.
Definition: service.hpp:116
virtual void Reset()
Resets the service.
Definition: service.hpp:123