//
// Copyright (c) 2009 Froduald Kabanza and the Université de Sherbrooke.
// Use of this software is permitted for non-commercial research purposes, and
// it may be copied or applied only for that use. All copies must include this
// copyright message.
// 
// This is a research prototype and it has not gone through intensive tests and
// is delivered as is. It may still contain bugs. Froduald Kabanza and the
// Université de Sherbrooke disclaim any responsibility for damage that may be
// caused by using it.
//
// Implementation: Simon Chamberland
// Project Manager: Froduald Kabanza
//
#include "stdafx.h"
#include "ICancellable.h"
#include <signal.h>

ICancellable* ICancellable::current = NULL;

void CtrlCHandler(int sig)
{
  if (ICancellable::current != NULL)
    ICancellable::current->cancel();
}

ICancellable::ICancellable()
  : m_cancelled(false)
{
}

void ICancellable::start(ICancellable* cancellable)
{
  current = cancellable;
  signal(SIGINT, CtrlCHandler);
}

void ICancellable::stop()
{
  current = NULL;
}

void ICancellable::cancel()
{
  m_cancelled = true;
}