daemon_win.cpp
Go to the documentation of this file.
1 
11 #include <windows.h>
12 
13 #include "daemon.h"
14 #include <mutex>
15 #include <condition_variable>
16 #include <iostream>
17 #include <signal.h>
18 
19 namespace
20 {
21 
22 OpcUa::Daemon * DaemonInstance = 0;
23 
24 BOOL CtrlHandler(DWORD fdwCtrlType)
25 {
26  switch (fdwCtrlType)
27  {
28  // Handle the CTRL-C signal.
29  case CTRL_C_EVENT:
30  case CTRL_CLOSE_EVENT:
31  case CTRL_BREAK_EVENT:
32  case CTRL_LOGOFF_EVENT:
33  case CTRL_SHUTDOWN_EVENT:
34 
35  if (DaemonInstance)
36  {
37  std::cout << "terminating.." << std::endl;
38  DaemonInstance->Terminate();
39  DaemonInstance = nullptr;
40  }
41 
42  return TRUE;
43 
44  default:
45  return FALSE;
46  }
47 }
48 
49 }
50 
51 namespace OpcUa
52 {
53 
54 void Daemon::Daemonize(const std::string & logFile)
55 {
56  // TODO Implement windows srvice behavior.
57 }
58 
60 {
61  if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE))
62  {
63  std::cerr << "Cannot set terminate handler. Application may not response on exit event." << std::endl;
64  }
65 
66  DaemonInstance = this;
67 }
68 
69 }
70 
void Terminate()
Definition: daemon.cpp:32
OPC UA Address space part. GNU LGPL.
void Daemonize(const std::string &str)
Definition: daemon_lin.cpp:68
void SetTerminateHandlers()
Definition: daemon_lin.cpp:48


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:06:04