ZeroTierOneService.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #pragma once
  19. #include <stdio.h>
  20. #include "ServiceBase.h"
  21. #include <string>
  22. #include "../../node/Mutex.hpp"
  23. #include "../../osdep/Thread.hpp"
  24. #include "../../service/OneService.hpp"
  25. // Uncomment to make debugging Windows services suck slightly less hard.
  26. //#define ZT_DEBUG_SERVICE "C:\\ZeroTierOneServiceDebugLog.txt"
  27. #ifdef ZT_DEBUG_SERVICE
  28. extern FILE *SVCDBGfile;
  29. extern ZeroTier::Mutex SVCDBGfile_m;
  30. #define ZT_SVCDBG(f,...) { SVCDBGfile_m.lock(); fprintf(SVCDBGfile,f,##__VA_ARGS__); fflush(SVCDBGfile); SVCDBGfile_m.unlock(); }
  31. #else
  32. #define ZT_SVCDBG(f,...) {}
  33. #endif
  34. #define ZT_SERVICE_NAME "ZeroTierOneService"
  35. #define ZT_SERVICE_DISPLAY_NAME "ZeroTier One"
  36. #define ZT_SERVICE_START_TYPE SERVICE_AUTO_START
  37. #define ZT_SERVICE_DEPENDENCIES ""
  38. //#define ZT_SERVICE_ACCOUNT "NT AUTHORITY\\LocalService"
  39. #define ZT_SERVICE_ACCOUNT NULL
  40. #define ZT_SERVICE_PASSWORD NULL
  41. class ZeroTierOneService : public CServiceBase
  42. {
  43. public:
  44. ZeroTierOneService();
  45. virtual ~ZeroTierOneService(void);
  46. /**
  47. * Thread main method; do not call elsewhere
  48. */
  49. void threadMain()
  50. throw();
  51. protected:
  52. virtual void OnStart(DWORD dwArgc, PSTR *pszArgv);
  53. virtual void OnStop();
  54. virtual void OnShutdown();
  55. private:
  56. ZeroTier::OneService *volatile _service;
  57. ZeroTier::Mutex _lock;
  58. ZeroTier::Thread _thread;
  59. };