daemon_win.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include <windows.h> 
00012 
00013 #include "daemon.h"
00014 #include <mutex>
00015 #include <condition_variable>
00016 #include <iostream>
00017 #include <signal.h>
00018 
00019 namespace
00020 {
00021 
00022   OpcUa::Daemon* DaemonInstance = 0;
00023 
00024   BOOL CtrlHandler( DWORD fdwCtrlType ) 
00025   { 
00026     switch( fdwCtrlType ) 
00027     { 
00028       // Handle the CTRL-C signal. 
00029       case CTRL_C_EVENT: 
00030       case CTRL_CLOSE_EVENT: 
00031       case CTRL_BREAK_EVENT: 
00032       case CTRL_LOGOFF_EVENT: 
00033       case CTRL_SHUTDOWN_EVENT: 
00034 
00035         if (DaemonInstance)
00036         {
00037           std::cout << "terminating.." << std::endl;
00038           DaemonInstance->Terminate();
00039           DaemonInstance = nullptr;
00040         }
00041         return TRUE;
00042 
00043       default: 
00044         return FALSE; 
00045     } 
00046   } 
00047 
00048 }
00049 
00050 namespace OpcUa
00051 {
00052 
00053   void Daemon::Daemonize(const std::string& logFile)
00054   {
00055     // TODO Implement windows srvice behavior.
00056   }
00057 
00058   void Daemon::SetTerminateHandlers()
00059   {
00060     if(!SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE))
00061     {
00062       std::cerr << "Cannot set terminate handler. Application may not response on exit event." << std::endl;
00063     }
00064     DaemonInstance = this;
00065   }
00066 
00067 }
00068 


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:40