123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #ifndef SERVICE_HPP
- #define SERVICE_HPP
-
- #ifdef WIN32
-
- #include <windows.h>
-
- #else
-
- #include <chrono>
-
- #endif
-
- #include <string>
- #include <vector>
- #include <mutex>
-
- #ifdef WIN32
-
- int main(int argc, char *argv[]);
-
- VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv);
-
- VOID WINAPI ServiceCtrlHandler(DWORD message);
-
- #else
-
- int main(int argc, char *argv[]);
-
- #endif
-
- namespace CodeDweller {
-
-
-
- class Service
- {
- public:
-
-
- class Callback {
-
- public:
-
-
- virtual void operator()() = 0;
-
- };
-
-
-
-
-
-
- static void onPauseCall(Callback &pauseFunctor);
-
-
-
-
-
-
- static void onResumeCall(Callback &resumeFunctor);
-
-
-
-
-
-
- static void onStopCall(Callback &stopFunctor);
-
-
-
-
-
- static bool receivedPause();
-
-
-
-
-
- static bool receivedResume();
-
-
-
-
-
-
- static bool receivedStop();
-
-
- static void clearReceivedPause();
-
-
- static void clearReceivedResume();
-
-
- static void clearReceivedStop();
-
-
-
-
-
-
-
- static const std::vector<std::string> &arguments();
-
-
-
-
-
-
-
-
-
- static void setStopCallbackTimeout_ms(int timeout_ms);
-
- private:
-
-
- Service();
-
-
- Service(Service const&) {}
-
-
- void operator=(Service const&) {}
-
-
-
-
-
- static Service& getInstance();
-
-
-
-
-
-
-
-
-
-
-
- int main(int argc, char *argv[]);
-
- #ifdef WIN32
-
-
-
-
-
-
-
-
- void serviceMain(DWORD argc, LPTSTR *argv);
-
- #endif
-
-
-
-
-
-
-
-
-
-
-
- void loadArguments(int argc, char *argv[]);
-
-
-
-
-
- int run();
-
-
- static std::mutex objectMutex;
-
- #ifdef WIN32
-
-
-
-
-
- void processCtrlMessage(DWORD message);
-
- #else
-
-
- void processMessages();
-
- #endif
-
-
-
-
-
- void watchdog();
-
-
- static std::vector<std::string> cmdLineArgs;
-
-
- static bool pauseReceived;
-
-
- static bool resumeReceived;
-
-
- static bool stopReceived;
-
-
- static std::vector<Callback *> pauseCallbacks;
-
-
- static std::vector<Callback *> resumeCallbacks;
-
-
- static std::vector<Callback *> stopCallbacks;
-
-
- static int stopCallbackTimeout_ms;
-
-
- std::chrono::time_point<std::chrono::steady_clock> timeoutTime;
-
-
- bool stopCallbacksActive;
-
- #ifdef WIN32
-
-
- SERVICE_STATUS serviceStatus;
-
-
- SERVICE_STATUS_HANDLE serviceStatusHandle = NULL;
-
- friend int ::main(int argc, char *argv[]);
-
- friend VOID WINAPI ::ServiceMain(DWORD argc, LPTSTR *argv);
-
- friend VOID WINAPI ::ServiceCtrlHandler(DWORD message);
-
- #else
-
-
- sigset_t signalSet;
-
- friend int ::main(int argc, char *argv[]);
-
- #endif
-
- };
-
- }
-
- #endif
|