/*======================================================================================

	Program:		Range Imaging Toolkit (RITK)
	Module:			ritkPluginBase.cxx
	Version:		$Revision: 1761 $
	Date:			$Date: 2011-09-23 17:25:41 +0200 (Fr, 23 Sep 2011) $

	Copyright (c) 2010-2011
	Pattern Recognition Lab, 
    University Erlangen-Nuremberg, Germany
    All rights reserved.

	This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
	See RITKCopyright.txt for more information.

	http://www5.informatik.uni-erlangen.de/research/software/ritk

========================================================================================*/

#include "ritkPluginBase.h"
#include "ritkDebugManager.h"

#include <iostream>

namespace ritk
{

PluginBase::PluginBase()
{
	// The plugin is not sturted within the constructor
	m_Started = false;

	// Default runtime: negative values indicate that runtime computation is not supported
	m_Runtime[0] = -1;
	m_Runtime[1] = -1;
}


PluginBase::~PluginBase()
{
}


//----------------------------------------------------------------------------
bool
PluginBase::StartPlugin(void *p)
{
	// We're already started 
	if ( m_Started )
	{
		return false;
	}

	// Set the flag and signal success
	m_Started = true;
	return true;
}


//----------------------------------------------------------------------------
bool
PluginBase::StopPlugin()
{
	// We're already stopped
	if ( !m_Started )
		return false;

	// Set the flag and signal success
	m_Started = false;
	return true;
}


//----------------------------------------------------------------------------
bool
PluginBase::Started()
{
	// Return the member which is set by the StartPlugin() and StopPlugin() methods
	return m_Started;
}


//----------------------------------------------------------------------------
void
PluginBase::GetRuntime(double *Runtime, double *RuntimeStdDeviation)
{
	// Lock the plugin to ensure thread safe access
	//LockPlugin();

	// Return values
	*Runtime = m_Runtime[0];
	if ( RuntimeStdDeviation )
		*RuntimeStdDeviation = m_Runtime[1];

	// Unlock plugin
	//UnlockPlugin();
}


//----------------------------------------------------------------------------
QWidget*
PluginBase::GetPluginGUI()
{
	// No GUI by default. This is the task of subclasses
	return NULL;
}


//----------------------------------------------------------------------------
void
PluginBase::LockPlugin()
{
	m_Mutex.lock();
}


//----------------------------------------------------------------------------
void
PluginBase::UnlockPlugin()
{
	m_Mutex.unlock();
}


//----------------------------------------------------------------------------
void
PluginBase::SetParameter(QString Name, QString Value)
{
}


} // end namespace ritk
