GlobalSessionMonitor.cpp
Go to the documentation of this file.
1 #include "stdafx.h"
2 #include "GlobalSessionMonitor.h"
3 
4 using namespace BazisLib;
5 using namespace MSP430Proxy;
6 
8 
10 {
11  MutexLocker lck(g_SessionMonitor.m_Mutex);
12  if (pSession)
13  return false;
14  pSession = pTarget;
15  return true;
16 }
17 
19 {
20  MutexLocker lck(g_SessionMonitor.m_Mutex);
21  ASSERT(pSession == pTarget);
22  pSession = NULL;
23 }
24 
26  : pSession(NULL)
27 {
28  SetConsoleCtrlHandler(CtrlHandler, TRUE);
29 }
30 
31 BOOL CALLBACK MSP430Proxy::GlobalSessionMonitor::CtrlHandler( DWORD dwType )
32 {
33  if (dwType == CTRL_C_EVENT)
34  {
35  MutexLocker lck(g_SessionMonitor.m_Mutex);
36  if (g_SessionMonitor.pSession)
37  g_SessionMonitor.pSession->SendBreakInRequestAsync();
38  else
39  printf("No active session. To stop listening, press Ctrl+Break.\n");
40  return TRUE;
41  }
42  return FALSE;
43 }