MiniM. Saving time.


| About | Download | Tools | Knowledge Base | How to Buy |

MiniM Overview

Getting Started

Download

Documentation

Tools

Cache Tools

GT.M Tools

Knowledge Base

FAQ

Contacts

Copyrights

MiniM Knowledge Base | RUS | Jan 10, 2012

Ctrl+C handling in MiniMono host application

On long time execution sometime operator need to interupt executed process. This article descrbes how to do this in MiniMono host application, GUI or CHUI.

To interrupt process execution console and telnet process of full MiniM Database Server supports handling of Ctrl+C pressing. If this event was occured, process interrupts and generates error INTERRUPT.

Unlike of what process do, Windows call specially declared function to handle Ctrl+C pressing in special process context. In this context application cannot call many functionality, but may set up special internal interruption indicator. MiniM interpreter periodically check this internal indicator state, but in regular execution context. If this interuption indicator is on, process generate error INTERRUPT. Moreover, Ctrl+C handling is embedded into read from the keyboard procedures.

To make interuption possible in MiniMono context too, MiniMono since version 1.12 implements additional function CtrlBreakVM:

extern "C" __declspec( dllexport) 
  void __stdcall CtrlBreakVM( int set_break);

If value of set_break is 0, internal interruption indicator is off, otherwise is on. This function intended for Ctrl+C handler context. Moreover, this function may be called from any host process context and from any process's thread, independently of GUI or CHUI application type.

To use interuption handler, developer must to do the following:

  • Obtain pointer to function CtrlBreakVM.
  • Define Ctrl+C handler.
  • In Ctrl+C handler on interruption event call CtrlBreakVM to set up indicator.
  • Add defined Ctrl+C handler.
  • On application termination remove Ctrl+C handler.

On C / С++ this things looks like:

Interruption handler:

#include <windows.h>
#include "minimono.h"
#include "zdevice.h"

static ctrlbreakvm_t CtrlBreakVM = NULL;

BOOL WINAPI ConsoleHandler( DWORD dwCtrlType)
{
  switch( dwCtrlType)
  {
    case CTRL_C_EVENT:      // нажали Ctrl+C
    case CTRL_BREAK_EVENT:  // нажали Ctrl+Break
      if( CtrlBreakVM)
      {
        CtrlBreakVM( 1);
      }
      break;
  }
  return TRUE;
};

Importing pointer to function and setting up interruption handler after MiniMono virtual mashine been created:

  CtrlBreakVM = (ctrlbreakvm_t)GetProcAddress( hModule, "CtrlBreakVM");
  SetConsoleCtrlHandler( ConsoleHandler, TRUE);

Removing Ctrl+C handler on application termination:

  SetConsoleCtrlHandler( ConsoleHandler, FALSE);

If all this steps done ok, MiniMono host application now can signal to MiniMono interpreter about interruption.

Note that function CtrlBreakVM is only setting up internal indicator, so this function may be called from any host process's thread and from any process context.

Eugene Karataev
support@minimdb.com


Copyright (C) 2017 Eugene Karataev
Emails: Info Tech Support