<commit_before>/*****************************************************************************
*                                                                            *
*  OpenNI 2.x Alpha                                                          *
*  Copyright (C) 2012 PrimeSense Ltd.                                        *
*                                                                            *
*  This file is part of OpenNI.                                              *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
*****************************************************************************/
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "LinkOniMapStream.h"
//#include "LinkOniColorStream.h"
#include <XnLog.h>

//---------------------------------------------------------------------------
// LinkOniMapStream class
//---------------------------------------------------------------------------

LinkOniMapStream::LinkOniMapStream(const char* configFile, const char* configSection, xn::PrimeClient* pSensor, OniSensorType sensorType, LinkOniDevice* pDevice) :
	LinkOniStream(configFile, configSection, pSensor, sensorType, pDevice),
	m_nSupportedModesCount(0),
	m_aSupportedModes(NULL)
{
}

LinkOniMapStream::~LinkOniMapStream()
{
	if (m_aSupportedModes != NULL)
	{
		XN_DELETE_ARR(m_aSupportedModes);
		m_aSupportedModes = NULL;
	}
}

XnStatus LinkOniMapStream::Init()
{
	XnStatus nRetVal = XN_STATUS_OK;

	nRetVal = LinkOniStream::Init();
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = FillSupportedVideoModes();
	XN_IS_STATUS_OK(nRetVal);

	// read video mode
	XnChar section[255];
	sprintf(section, "%s.VideoMode", m_configSection);
	OniVideoMode videoMode;
	GetVideoMode(&videoMode);

	// override with streams default values
	GetDefaultVideoMode(&videoMode);

	// override with INI config
	XnInt32 temp32;
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, section, "XResolution", &temp32))
	{
		videoMode.resolutionX = (int)temp32;
	}
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, section, "YResolution", &temp32))
	{
		videoMode.resolutionY = (int)temp32;
	}
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, section, "FPS", &temp32))
	{
		videoMode.fps = (int)temp32;
	}
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, section, "PixelFormat", &temp32))
	{
		videoMode.pixelFormat = (OniPixelFormat)temp32;
	}

	nRetVal = SetVideoMode(&videoMode);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = setIntPropertyFromINI("LinkPixelFormat", LINK_PROP_PIXEL_FORMAT);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = setIntPropertyFromINI("Compression", LINK_PROP_COMPRESSION);
	XN_IS_STATUS_OK(nRetVal);

	OniBool bMirror = TRUE;
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, section, "Mirror", &temp32))
	{
		bMirror = (temp32 == 1);
	}

	nRetVal = SetMirror(bMirror);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}

OniStatus LinkOniMapStream::getProperty(int propertyId, void* data, int* pDataSize)
{
	XnStatus nRetVal = XN_STATUS_ERROR;

	switch(propertyId)
	{
		case ONI_STREAM_PROPERTY_VIDEO_MODE:
			EXACT_PROP_SIZE(*pDataSize, OniVideoMode);
			nRetVal = GetVideoMode((OniVideoMode*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case ONI_STREAM_PROPERTY_MIRRORING:
			EXACT_PROP_SIZE(*pDataSize, OniBool);
			nRetVal = GetMirror((OniBool*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case ONI_STREAM_PROPERTY_CROPPING:
			EXACT_PROP_SIZE(*pDataSize, OniCropping);
			nRetVal = GetCropping(*(OniCropping*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case LINK_PROP_PIXEL_FORMAT:
			ENSURE_PROP_SIZE(*pDataSize, XnLinkPixelFormat);
			ASSIGN_PROP_VALUE_INT(data, *pDataSize, m_pInputStream->GetVideoMode().m_nPixelFormat);
			break;

		case LINK_PROP_COMPRESSION:
			ENSURE_PROP_SIZE(*pDataSize, XnLinkCompressionType);
			ASSIGN_PROP_VALUE_INT(data, *pDataSize, m_pInputStream->GetVideoMode().m_nCompression);
			break;

		case PS_PROPERTY_GAIN:
			{
				ENSURE_PROP_SIZE(*pDataSize, XnUInt16);
				XnUInt16 gain;
				nRetVal = m_pInputStream->GetGain(gain);
				XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
				ASSIGN_PROP_VALUE_INT(data, *pDataSize, gain);
			}
			break;

		default:
		{
			return LinkOniStream::getProperty(propertyId, data, pDataSize);
		}
	}

	return ONI_STATUS_OK;
}

OniStatus LinkOniMapStream::setProperty(int propertyId, const void* data, int dataSize)
{
	XnStatus nRetVal = XN_STATUS_ERROR;

	switch(propertyId)
	{
		case ONI_STREAM_PROPERTY_VIDEO_MODE:
			EXACT_PROP_SIZE(dataSize, OniVideoMode);
			nRetVal = SetVideoMode((OniVideoMode*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case ONI_STREAM_PROPERTY_MIRRORING:
			EXACT_PROP_SIZE(dataSize, OniBool);
			nRetVal = SetMirror(*(OniBool*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case ONI_STREAM_PROPERTY_CROPPING:
			EXACT_PROP_SIZE(dataSize, OniCropping);
			nRetVal = SetCropping(*(OniCropping*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case LINK_PROP_PIXEL_FORMAT:
			{
				ENSURE_PROP_SIZE(dataSize, XnLinkPixelFormat);
				XnFwStreamVideoMode mode = m_pInputStream->GetVideoMode();
				mode.m_nPixelFormat = *(XnFwPixelFormat*)data;
				nRetVal = m_pInputStream->SetVideoMode(mode);
				XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
				break;
			}

		case LINK_PROP_COMPRESSION:
			{
				ENSURE_PROP_SIZE(dataSize, XnLinkCompressionType);
				XnFwStreamVideoMode mode = m_pInputStream->GetVideoMode();
				mode.m_nCompression = *(XnFwCompressionType*)data;
				nRetVal = m_pInputStream->SetVideoMode(mode);
				XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
				break;
			}

		case PS_PROPERTY_GAIN:
			{
				ENSURE_PROP_SIZE(dataSize, XnUInt16);
				nRetVal = m_pInputStream->SetGain(*(XnUInt16*)data);
				XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
				break;
			}

		default:
			return LinkOniStream::setProperty(propertyId, data, dataSize);
	}

	return ONI_STATUS_OK;
}

OniBool LinkOniMapStream::isPropertySupported(int propertyId)
{
	switch (propertyId)
	{
	case ONI_STREAM_PROPERTY_VIDEO_MODE:
	case ONI_STREAM_PROPERTY_MIRRORING:
	case ONI_STREAM_PROPERTY_CROPPING:
	case LINK_PROP_PIXEL_FORMAT:
	case LINK_PROP_COMPRESSION:
		return true;
	default:
		return LinkOniStream::isPropertySupported(propertyId);
	}
}

void LinkOniMapStream::notifyAllProperties()
{
	LinkOniStream::notifyAllProperties();

	int nValue;
	int size = sizeof(int);

	getProperty(LINK_PROP_PIXEL_FORMAT, &nValue, &size);
	raisePropertyChanged(LINK_PROP_PIXEL_FORMAT, &nValue, size);

	getProperty(LINK_PROP_COMPRESSION, &nValue, &size);
	raisePropertyChanged(LINK_PROP_COMPRESSION, &nValue, size);
}

XnStatus LinkOniMapStream::GetVideoMode(OniVideoMode* pVideoMode)
{
	// output format
	pVideoMode->pixelFormat = m_pInputStream->GetOutputFormat();

	// resolution
	pVideoMode->resolutionX = (int)m_pInputStream->GetVideoMode().m_nXRes;
	pVideoMode->resolutionY = (int)m_pInputStream->GetVideoMode().m_nYRes;

	// fps
	pVideoMode->fps = (int)m_pInputStream->GetVideoMode().m_nFPS;

	return XN_STATUS_OK;
}

XnStatus LinkOniMapStream::SetVideoMode(OniVideoMode* pVideoMode)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnFwStreamVideoMode currFwMode = m_pInputStream->GetVideoMode();

	if ((int)currFwMode.m_nXRes == pVideoMode->resolutionX &&
		(int)currFwMode.m_nYRes == pVideoMode->resolutionY &&
		(int)currFwMode.m_nFPS == pVideoMode->fps &&
		m_pInputStream->GetOutputFormat() == pVideoMode->pixelFormat)
	{
		// nothing to do here
		return (ONI_STATUS_OK);
	}

	// now look for the first mode that matches
	const xnl::Array<XnFwStreamVideoMode>& supportedModes = m_pInputStream->GetSupportedVideoModes();
	XnInt32 selectedIndex = -1;
	for (XnUInt32 i = 0; i < supportedModes.GetSize(); ++i)
	{
		if (pVideoMode->resolutionX == (int)supportedModes[i].m_nXRes &&
			pVideoMode->resolutionY == (int)supportedModes[i].m_nYRes &&
			pVideoMode->fps         == (int)supportedModes[i].m_nFPS)
		{
			// prefer the one that also keeps on other parameters. If no such mode exists, switch to the first one on the list
			if (supportedModes[i].m_nPixelFormat == currFwMode.m_nPixelFormat &&
				supportedModes[i].m_nCompression == currFwMode.m_nCompression)
			{
				selectedIndex = i;
				break;
			}
			else if (selectedIndex == -1)
			{
				selectedIndex = i;
			}
		}
	}

	if (selectedIndex == -1)
	{
		xnLogError(XN_MASK_LINK, "Tried to set unsupported mode: %ux%u@%u fps",
			pVideoMode->resolutionX, pVideoMode->resolutionY, pVideoMode->fps);
		XN_ASSERT(FALSE);
		return XN_STATUS_BAD_PARAM;
	}

	nRetVal = m_pInputStream->SetVideoMode(supportedModes[selectedIndex]);
	XN_IS_STATUS_OK_LOG_ERROR("Set video mode", nRetVal);

	nRetVal = m_pInputStream->SetOutputFormat(pVideoMode->pixelFormat);
	XN_IS_STATUS_OK_LOG_ERROR("Set output format", nRetVal);

	return XN_STATUS_OK;
}

XnStatus LinkOniMapStream::FillSupportedVideoModes()
{
	int nCount;
	const xnl::Array<XnFwStreamVideoMode> *pSupported;
	pSupported = &m_pInputStream->GetSupportedVideoModes();
	nCount = (int)pSupported->GetSize();

	m_aSupportedModes = XN_NEW_ARR(SupportedVideoMode, nCount);
	XN_VALIDATE_ALLOC_PTR(m_aSupportedModes);
	m_nSupportedModesCount = nCount;

	for (int i = 0; i < nCount; ++i)
	{
		m_aSupportedModes[i].nInputFormat			= pSupported->GetData()[i].m_nPixelFormat;

		m_aSupportedModes[i].OutputMode.resolutionX	= pSupported->GetData()[i].m_nXRes;
		m_aSupportedModes[i].OutputMode.resolutionY	= pSupported->GetData()[i].m_nYRes;;
		m_aSupportedModes[i].OutputMode.fps			= pSupported->GetData()[i].m_nFPS;;
		m_aSupportedModes[i].OutputMode.pixelFormat	= (OniPixelFormat)-1; // this field is not to be used here.;
	}

	return (XN_STATUS_OK);
}

XnStatus LinkOniMapStream::GetMirror(OniBool* pEnabled)
{
	*pEnabled = (OniBool)m_pInputStream->GetMirror();
	return (XN_STATUS_OK);
}

XnStatus LinkOniMapStream::SetMirror(OniBool enabled)
{
	return m_pInputStream->SetMirror((XnBool)enabled);
}

XnStatus LinkOniMapStream::GetCropping(OniCropping &cropping)
{
	const OniCropping &pCropping = m_pInputStream->GetCropping();
	xnOSMemCopy(&cropping, &pCropping, sizeof(OniCropping));
	return (XN_STATUS_OK);
}

XnStatus LinkOniMapStream::SetCropping(const OniCropping &cropping)
{
	return m_pInputStream->SetCropping(cropping);
}

XnStatus LinkOniMapStream::GetDefaultVideoMode( OniVideoMode* /*pVideoMode*/ )
{
	return XN_STATUS_IS_EMPTY;
}

<commit_msg>PSLink.ini - can't set mirror on/off<commit_after>/*****************************************************************************
*                                                                            *
*  OpenNI 2.x Alpha                                                          *
*  Copyright (C) 2012 PrimeSense Ltd.                                        *
*                                                                            *
*  This file is part of OpenNI.                                              *
*                                                                            *
*  Licensed under the Apache License, Version 2.0 (the "License");           *
*  you may not use this file except in compliance with the License.          *
*  You may obtain a copy of the License at                                   *
*                                                                            *
*      http://www.apache.org/licenses/LICENSE-2.0                            *
*                                                                            *
*  Unless required by applicable law or agreed to in writing, software       *
*  distributed under the License is distributed on an "AS IS" BASIS,         *
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
*  See the License for the specific language governing permissions and       *
*  limitations under the License.                                            *
*                                                                            *
*****************************************************************************/
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "LinkOniMapStream.h"
//#include "LinkOniColorStream.h"
#include <XnLog.h>

//---------------------------------------------------------------------------
// LinkOniMapStream class
//---------------------------------------------------------------------------

LinkOniMapStream::LinkOniMapStream(const char* configFile, const char* configSection, xn::PrimeClient* pSensor, OniSensorType sensorType, LinkOniDevice* pDevice) :
	LinkOniStream(configFile, configSection, pSensor, sensorType, pDevice),
	m_nSupportedModesCount(0),
	m_aSupportedModes(NULL)
{
}

LinkOniMapStream::~LinkOniMapStream()
{
	if (m_aSupportedModes != NULL)
	{
		XN_DELETE_ARR(m_aSupportedModes);
		m_aSupportedModes = NULL;
	}
}

XnStatus LinkOniMapStream::Init()
{
	XnStatus nRetVal = XN_STATUS_OK;

	nRetVal = LinkOniStream::Init();
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = FillSupportedVideoModes();
	XN_IS_STATUS_OK(nRetVal);

	// read video mode
	XnChar videoModeSection[255];
	sprintf(videoModeSection, "%s.VideoMode", m_configSection);
	OniVideoMode videoMode;
	GetVideoMode(&videoMode);

	// override with streams default values
	GetDefaultVideoMode(&videoMode);

	// override with INI config
	XnInt32 temp32;
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, videoModeSection, "XResolution", &temp32))
	{
		videoMode.resolutionX = (int)temp32;
	}
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, videoModeSection, "YResolution", &temp32))
	{
		videoMode.resolutionY = (int)temp32;
	}
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, videoModeSection, "FPS", &temp32))
	{
		videoMode.fps = (int)temp32;
	}
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, videoModeSection, "PixelFormat", &temp32))
	{
		videoMode.pixelFormat = (OniPixelFormat)temp32;
	}

	nRetVal = SetVideoMode(&videoMode);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = setIntPropertyFromINI("LinkPixelFormat", LINK_PROP_PIXEL_FORMAT);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = setIntPropertyFromINI("Compression", LINK_PROP_COMPRESSION);
	XN_IS_STATUS_OK(nRetVal);

	OniBool bMirror = TRUE;
	if (XN_STATUS_OK == xnOSReadIntFromINI(m_configFile, m_configSection, "Mirror", &temp32))
	{
		bMirror = (temp32 == 1);
	}

	nRetVal = SetMirror(bMirror);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}

OniStatus LinkOniMapStream::getProperty(int propertyId, void* data, int* pDataSize)
{
	XnStatus nRetVal = XN_STATUS_ERROR;

	switch(propertyId)
	{
		case ONI_STREAM_PROPERTY_VIDEO_MODE:
			EXACT_PROP_SIZE(*pDataSize, OniVideoMode);
			nRetVal = GetVideoMode((OniVideoMode*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case ONI_STREAM_PROPERTY_MIRRORING:
			EXACT_PROP_SIZE(*pDataSize, OniBool);
			nRetVal = GetMirror((OniBool*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case ONI_STREAM_PROPERTY_CROPPING:
			EXACT_PROP_SIZE(*pDataSize, OniCropping);
			nRetVal = GetCropping(*(OniCropping*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case LINK_PROP_PIXEL_FORMAT:
			ENSURE_PROP_SIZE(*pDataSize, XnLinkPixelFormat);
			ASSIGN_PROP_VALUE_INT(data, *pDataSize, m_pInputStream->GetVideoMode().m_nPixelFormat);
			break;

		case LINK_PROP_COMPRESSION:
			ENSURE_PROP_SIZE(*pDataSize, XnLinkCompressionType);
			ASSIGN_PROP_VALUE_INT(data, *pDataSize, m_pInputStream->GetVideoMode().m_nCompression);
			break;

		case PS_PROPERTY_GAIN:
			{
				ENSURE_PROP_SIZE(*pDataSize, XnUInt16);
				XnUInt16 gain;
				nRetVal = m_pInputStream->GetGain(gain);
				XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
				ASSIGN_PROP_VALUE_INT(data, *pDataSize, gain);
			}
			break;

		default:
		{
			return LinkOniStream::getProperty(propertyId, data, pDataSize);
		}
	}

	return ONI_STATUS_OK;
}

OniStatus LinkOniMapStream::setProperty(int propertyId, const void* data, int dataSize)
{
	XnStatus nRetVal = XN_STATUS_ERROR;

	switch(propertyId)
	{
		case ONI_STREAM_PROPERTY_VIDEO_MODE:
			EXACT_PROP_SIZE(dataSize, OniVideoMode);
			nRetVal = SetVideoMode((OniVideoMode*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case ONI_STREAM_PROPERTY_MIRRORING:
			EXACT_PROP_SIZE(dataSize, OniBool);
			nRetVal = SetMirror(*(OniBool*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case ONI_STREAM_PROPERTY_CROPPING:
			EXACT_PROP_SIZE(dataSize, OniCropping);
			nRetVal = SetCropping(*(OniCropping*)data);
			XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
			break;

		case LINK_PROP_PIXEL_FORMAT:
			{
				ENSURE_PROP_SIZE(dataSize, XnLinkPixelFormat);
				XnFwStreamVideoMode mode = m_pInputStream->GetVideoMode();
				mode.m_nPixelFormat = *(XnFwPixelFormat*)data;
				nRetVal = m_pInputStream->SetVideoMode(mode);
				XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
				break;
			}

		case LINK_PROP_COMPRESSION:
			{
				ENSURE_PROP_SIZE(dataSize, XnLinkCompressionType);
				XnFwStreamVideoMode mode = m_pInputStream->GetVideoMode();
				mode.m_nCompression = *(XnFwCompressionType*)data;
				nRetVal = m_pInputStream->SetVideoMode(mode);
				XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
				break;
			}

		case PS_PROPERTY_GAIN:
			{
				ENSURE_PROP_SIZE(dataSize, XnUInt16);
				nRetVal = m_pInputStream->SetGain(*(XnUInt16*)data);
				XN_IS_STATUS_OK_RET(nRetVal, ONI_STATUS_ERROR);
				break;
			}

		default:
			return LinkOniStream::setProperty(propertyId, data, dataSize);
	}

	return ONI_STATUS_OK;
}

OniBool LinkOniMapStream::isPropertySupported(int propertyId)
{
	switch (propertyId)
	{
	case ONI_STREAM_PROPERTY_VIDEO_MODE:
	case ONI_STREAM_PROPERTY_MIRRORING:
	case ONI_STREAM_PROPERTY_CROPPING:
	case LINK_PROP_PIXEL_FORMAT:
	case LINK_PROP_COMPRESSION:
		return true;
	default:
		return LinkOniStream::isPropertySupported(propertyId);
	}
}

void LinkOniMapStream::notifyAllProperties()
{
	LinkOniStream::notifyAllProperties();

	int nValue;
	int size = sizeof(int);

	getProperty(LINK_PROP_PIXEL_FORMAT, &nValue, &size);
	raisePropertyChanged(LINK_PROP_PIXEL_FORMAT, &nValue, size);

	getProperty(LINK_PROP_COMPRESSION, &nValue, &size);
	raisePropertyChanged(LINK_PROP_COMPRESSION, &nValue, size);
}

XnStatus LinkOniMapStream::GetVideoMode(OniVideoMode* pVideoMode)
{
	// output format
	pVideoMode->pixelFormat = m_pInputStream->GetOutputFormat();

	// resolution
	pVideoMode->resolutionX = (int)m_pInputStream->GetVideoMode().m_nXRes;
	pVideoMode->resolutionY = (int)m_pInputStream->GetVideoMode().m_nYRes;

	// fps
	pVideoMode->fps = (int)m_pInputStream->GetVideoMode().m_nFPS;

	return XN_STATUS_OK;
}

XnStatus LinkOniMapStream::SetVideoMode(OniVideoMode* pVideoMode)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnFwStreamVideoMode currFwMode = m_pInputStream->GetVideoMode();

	if ((int)currFwMode.m_nXRes == pVideoMode->resolutionX &&
		(int)currFwMode.m_nYRes == pVideoMode->resolutionY &&
		(int)currFwMode.m_nFPS == pVideoMode->fps &&
		m_pInputStream->GetOutputFormat() == pVideoMode->pixelFormat)
	{
		// nothing to do here
		return (ONI_STATUS_OK);
	}

	// now look for the first mode that matches
	const xnl::Array<XnFwStreamVideoMode>& supportedModes = m_pInputStream->GetSupportedVideoModes();
	XnInt32 selectedIndex = -1;
	for (XnUInt32 i = 0; i < supportedModes.GetSize(); ++i)
	{
		if (pVideoMode->resolutionX == (int)supportedModes[i].m_nXRes &&
			pVideoMode->resolutionY == (int)supportedModes[i].m_nYRes &&
			pVideoMode->fps         == (int)supportedModes[i].m_nFPS)
		{
			// prefer the one that also keeps on other parameters. If no such mode exists, switch to the first one on the list
			if (supportedModes[i].m_nPixelFormat == currFwMode.m_nPixelFormat &&
				supportedModes[i].m_nCompression == currFwMode.m_nCompression)
			{
				selectedIndex = i;
				break;
			}
			else if (selectedIndex == -1)
			{
				selectedIndex = i;
			}
		}
	}

	if (selectedIndex == -1)
	{
		xnLogError(XN_MASK_LINK, "Tried to set unsupported mode: %ux%u@%u fps",
			pVideoMode->resolutionX, pVideoMode->resolutionY, pVideoMode->fps);
		XN_ASSERT(FALSE);
		return XN_STATUS_BAD_PARAM;
	}

	nRetVal = m_pInputStream->SetVideoMode(supportedModes[selectedIndex]);
	XN_IS_STATUS_OK_LOG_ERROR("Set video mode", nRetVal);

	nRetVal = m_pInputStream->SetOutputFormat(pVideoMode->pixelFormat);
	XN_IS_STATUS_OK_LOG_ERROR("Set output format", nRetVal);

	return XN_STATUS_OK;
}

XnStatus LinkOniMapStream::FillSupportedVideoModes()
{
	int nCount;
	const xnl::Array<XnFwStreamVideoMode> *pSupported;
	pSupported = &m_pInputStream->GetSupportedVideoModes();
	nCount = (int)pSupported->GetSize();

	m_aSupportedModes = XN_NEW_ARR(SupportedVideoMode, nCount);
	XN_VALIDATE_ALLOC_PTR(m_aSupportedModes);
	m_nSupportedModesCount = nCount;

	for (int i = 0; i < nCount; ++i)
	{
		m_aSupportedModes[i].nInputFormat			= pSupported->GetData()[i].m_nPixelFormat;

		m_aSupportedModes[i].OutputMode.resolutionX	= pSupported->GetData()[i].m_nXRes;
		m_aSupportedModes[i].OutputMode.resolutionY	= pSupported->GetData()[i].m_nYRes;;
		m_aSupportedModes[i].OutputMode.fps			= pSupported->GetData()[i].m_nFPS;;
		m_aSupportedModes[i].OutputMode.pixelFormat	= (OniPixelFormat)-1; // this field is not to be used here.;
	}

	return (XN_STATUS_OK);
}

XnStatus LinkOniMapStream::GetMirror(OniBool* pEnabled)
{
	*pEnabled = (OniBool)m_pInputStream->GetMirror();
	return (XN_STATUS_OK);
}

XnStatus LinkOniMapStream::SetMirror(OniBool enabled)
{
	return m_pInputStream->SetMirror((XnBool)enabled);
}

XnStatus LinkOniMapStream::GetCropping(OniCropping &cropping)
{
	const OniCropping &pCropping = m_pInputStream->GetCropping();
	xnOSMemCopy(&cropping, &pCropping, sizeof(OniCropping));
	return (XN_STATUS_OK);
}

XnStatus LinkOniMapStream::SetCropping(const OniCropping &cropping)
{
	return m_pInputStream->SetCropping(cropping);
}

XnStatus LinkOniMapStream::GetDefaultVideoMode( OniVideoMode* /*pVideoMode*/ )
{
	return XN_STATUS_IS_EMPTY;
}

<|endoftext|>


<commit_before>/*****************************************************************************\
 *                        ANALYSIS PERFORMANCE TOOLS                         *
 *                               libparaver-api                              *
 *                      API Library for libparaver-kernel                    *
 *****************************************************************************
 *     ___     This library is free software; you can redistribute it and/or *
 *    /  __         modify it under the terms of the GNU LGPL as published   *
 *   /  /  _____    by the Free Software Foundation; either version 2.1      *
 *  /  /  /     \   of the License, or (at your option) any later version.   *
 * (  (  ( B S C )                                                           *
 *  \  \  \_____/   This library is distributed in hope that it will be      *
 *   \  \__         useful but WITHOUT ANY WARRANTY; without even the        *
 *    \___          implied warranty of MERCHANTABILITY or FITNESS FOR A     *
 *                  PARTICULAR PURPOSE. See the GNU LGPL for more details.   *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public License  *
 * along with this library; if not, write to the Free Software Foundation,   *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA          *
 * The GNU LEsser General Public License is contained in the file COPYING.   *
 *                                 ---------                                 *
 *   Barcelona Supercomputing Center - Centro Nacional de Supercomputacion   *
\*****************************************************************************/

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *\
 | @file: $HeadURL$
 | @last_commit: $Date$
 | @version:     $Revision$
\* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

#include <set>

#include "traceeditactions.h"
#include "eventtranslator.h"
#ifdef OLD_PCFPARSER
#include "utils/pcfparser/old/ParaverTraceConfig.h"
#else
#include "utils/pcfparser/UIParaverTraceConfig.h"
#endif

/****************************************************************************
 ********                  PCFEventMergerAction                      ********
 ****************************************************************************/

void cloneValuesIntoGroup( vector< unsigned int >::iterator begin,
                           vector< unsigned int >::iterator end,
                           unsigned int oldValue,
                           unsigned int newValue,
                           map< TTypeValuePair, TTypeValuePair > &translation )
{
  for ( vector< unsigned int >::iterator it = begin; it != end; ++it )
  {
    translation[ TTypeValuePair( *it, oldValue ) ] = TTypeValuePair( *it, newValue );
  }
}

vector<TraceEditSequence::TSequenceStates> PCFEventMergerAction::getStateDependencies() const
{
  vector<TraceEditSequence::TSequenceStates> tmpStates;
  tmpStates.push_back( TraceEditSequence::eventTranslationTableState );
  tmpStates.push_back( TraceEditSequence::outputTraceFileNameState );
  tmpStates.push_back( TraceEditSequence::outputDirSuffixState );
  tmpStates.push_back( TraceEditSequence::pcfMergerReferenceState );

  return tmpStates;
}

bool PCFEventMergerAction::execute( std::string whichTrace )
{
  TraceEditSequence *tmpSequence = mySequence;

#ifndef OLD_PCFPARSER
  // Get new tracename
  std::string newName = ( (OutputTraceFileNameState *)tmpSequence->getState( TraceEditSequence::outputTraceFileNameState ) )->getData();
  if ( !tmpSequence->isEndOfSequence() || newName.empty() )
  {
    std::string tmpSuffix = ( (OutputDirSuffixState *)tmpSequence->getState( TraceEditSequence::outputDirSuffixState ) )->getData();
    std::string outputPath = whichTrace.substr( 0, whichTrace.find_last_of( mySequence->getKernelConnection()->getPathSeparator() ) ) +
                           mySequence->getKernelConnection()->getPathSeparator() + tmpSuffix;

    vector< std::string > tmpID;
    tmpID.push_back( EventTranslator::getID() );

    newName = mySequence->getKernelConnection()->getNewTraceName( whichTrace, outputPath, tmpID, false );
  }

  // Read reference pcf
  std::string referenceTrace = ( (PCFMergerReferenceState *)tmpSequence->getState( TraceEditSequence::pcfMergerReferenceState ) )->getData();
  std::string referencePCFFile = LocalKernel::composeName( referenceTrace, "pcf" );
#ifdef OLD_PCFPARSER
  ParaverTraceConfig *referenceTraceConfig = new ParaverTraceConfig( referencePCFFile );
  referenceTraceConfig->parse();
#else
  UIParaverTraceConfig *referenceTraceConfig = new UIParaverTraceConfig();
  referenceTraceConfig->parse( referencePCFFile );
#endif

  // Read source pcf
  std::string sourceTrace = LocalKernel::composeName( whichTrace, "pcf" );
#ifdef OLD_PCFPARSER
  ParaverTraceConfig *sourceTraceConfig = new ParaverTraceConfig( sourceTrace );
  sourceTraceConfig->parse();
#else
  UIParaverTraceConfig *sourceTraceConfig = new UIParaverTraceConfig();
  sourceTraceConfig->parse( sourceTrace );
#endif

  // Translation algorithm
  map< TTypeValuePair, TTypeValuePair > translation;

  vector< vector< unsigned int > > sourceGroupedTypes = sourceTraceConfig->getGroupedEventTypes();
  std::vector< unsigned int > tmpCodes = referenceTraceConfig->getEventTypes();
  std::set< unsigned int > referenceTypes;
  referenceTypes.insert( tmpCodes.begin(), tmpCodes.end() );

  for ( vector< vector< unsigned int > >::iterator itGroupType = sourceGroupedTypes.begin(); itGroupType != sourceGroupedTypes.end(); ++itGroupType )
  {
    vector< unsigned int >::iterator itSourceType;
    itSourceType = (*itGroupType).begin();

    if ( referenceTypes.find( *itSourceType ) != referenceTypes.end() )
    {
      vector< unsigned int > sourceValues;
      try
      {
        sourceValues = sourceTraceConfig->getEventValues( *itSourceType );
      }
#ifdef OLD_PCFPARSER
      catch( libparaver::ParaverTraceConfig::value_not_found )
#else
      catch( libparaver::UIParaverTraceConfig::value_not_found )
#endif
      {}

      if ( sourceValues.empty() )
        continue;

      map< std::string, unsigned int > referenceValues;
      try
      {
        tmpCodes = referenceTraceConfig->getEventValues( *itSourceType );
      }
#ifdef OLD_PCFPARSER
      catch( libparaver::ParaverTraceConfig::value_not_found )
#else
      catch( libparaver::UIParaverTraceConfig::value_not_found )
#endif
      {}

      if ( tmpCodes.empty() )
        continue;

      for ( vector< unsigned int >::iterator itReferenceValue = tmpCodes.begin(); itReferenceValue != tmpCodes.end(); ++itReferenceValue )
      {
        referenceValues[ referenceTraceConfig->getEventValue( *itSourceType, *itReferenceValue ) ] = *itReferenceValue;
      }

      map< unsigned int, std::string > valuesColliding;
      map< unsigned int, std::string > valuesFinal;

      for ( vector< unsigned int >::iterator itSourceValue = sourceValues.begin(); itSourceValue != sourceValues.end(); ++itSourceValue )
      {
        std::string sourceTag = sourceTraceConfig->getEventValue( *itSourceType, *itSourceValue );
        map< std::string, unsigned int >::iterator itRefValue = referenceValues.find( sourceTag );
        if ( itRefValue != referenceValues.end() )
        {
          if ( valuesFinal.find( (*itRefValue).second ) != valuesFinal.end() )
          {
            valuesColliding[ (*itRefValue).second ] = valuesFinal[ (*itRefValue).second ];
          }
          else
          {
            if ( *itSourceValue != (*itRefValue).second )
              cloneValuesIntoGroup( itSourceType, (*itGroupType).end(), *itSourceValue, (*itRefValue).second, translation );
          }

          valuesFinal[ (*itRefValue).second ] = sourceTag;
        }
        else
        {
          if ( valuesFinal.find( *itSourceValue ) != valuesFinal.end() )
          {
            valuesColliding[ *itSourceValue ] = sourceTag;
          }
          else
          {
            valuesFinal[ *itSourceValue ] = sourceTag;
          }
        }
      }

      unsigned int maxValue = (--valuesFinal.end())->first;
      for ( map< unsigned int, std::string >::iterator itCollision = valuesColliding.begin(); itCollision != valuesColliding.end(); ++itCollision )
      {
        valuesFinal[ ++maxValue ] = (*itCollision).second;
        if ( (*itCollision).first != maxValue )
          cloneValuesIntoGroup( itSourceType, (*itGroupType).end(), (*itCollision).first, maxValue, translation );
      }

      sourceTraceConfig->setEventValues( *itSourceType, valuesFinal );
    }
  }

/*
  for ( map< TTypeValuePair, TTypeValuePair>::iterator it = translation.begin(); it !=  translation.end();++it)
  {

    std::cout << (*it).first.first << " " ;
    std::cout << (*it).first.second << " " ;
    std::cout << (*it).second.first << " " ;
    std::cout << (*it).second.second << " " ;
    std::cout << std::endl;
  }
*/

  // Write files
  ( (EventTranslationTableState *)tmpSequence->getState( TraceEditSequence::eventTranslationTableState ) )->setData( translation );

  if ( !translation.empty() )
  {
    mySequence->getKernelConnection()->copyROW( whichTrace, newName );
    std::fstream tmpFileDestiny;
    tmpFileDestiny.open( LocalKernel::composeName( newName, std::string( "pcf" ) ).c_str(), std::ios::out );
    tmpFileDestiny << sourceTraceConfig->toString();
    tmpFileDestiny.close();
  }

  delete sourceTraceConfig;
  delete referenceTraceConfig;
#endif

  tmpSequence->executeNextAction( whichTrace );

  return true;
}
<commit_msg>BUG FIXED: EventTranslator wasn't getting "-o" parameter<commit_after>/*****************************************************************************\
 *                        ANALYSIS PERFORMANCE TOOLS                         *
 *                               libparaver-api                              *
 *                      API Library for libparaver-kernel                    *
 *****************************************************************************
 *     ___     This library is free software; you can redistribute it and/or *
 *    /  __         modify it under the terms of the GNU LGPL as published   *
 *   /  /  _____    by the Free Software Foundation; either version 2.1      *
 *  /  /  /     \   of the License, or (at your option) any later version.   *
 * (  (  ( B S C )                                                           *
 *  \  \  \_____/   This library is distributed in hope that it will be      *
 *   \  \__         useful but WITHOUT ANY WARRANTY; without even the        *
 *    \___          implied warranty of MERCHANTABILITY or FITNESS FOR A     *
 *                  PARTICULAR PURPOSE. See the GNU LGPL for more details.   *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public License  *
 * along with this library; if not, write to the Free Software Foundation,   *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA          *
 * The GNU LEsser General Public License is contained in the file COPYING.   *
 *                                 ---------                                 *
 *   Barcelona Supercomputing Center - Centro Nacional de Supercomputacion   *
\*****************************************************************************/

/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- *\
 | @file: $HeadURL$
 | @last_commit: $Date$
 | @version:     $Revision$
\* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

#include <set>

#include "traceeditactions.h"
#include "eventtranslator.h"
#ifdef OLD_PCFPARSER
#include "utils/pcfparser/old/ParaverTraceConfig.h"
#else
#include "utils/pcfparser/UIParaverTraceConfig.h"
#endif

/****************************************************************************
 ********                  PCFEventMergerAction                      ********
 ****************************************************************************/

void cloneValuesIntoGroup( vector< unsigned int >::iterator begin,
                           vector< unsigned int >::iterator end,
                           unsigned int oldValue,
                           unsigned int newValue,
                           map< TTypeValuePair, TTypeValuePair > &translation )
{
  for ( vector< unsigned int >::iterator it = begin; it != end; ++it )
  {
    translation[ TTypeValuePair( *it, oldValue ) ] = TTypeValuePair( *it, newValue );
  }
}

vector<TraceEditSequence::TSequenceStates> PCFEventMergerAction::getStateDependencies() const
{
  vector<TraceEditSequence::TSequenceStates> tmpStates;
  tmpStates.push_back( TraceEditSequence::eventTranslationTableState );
  tmpStates.push_back( TraceEditSequence::outputTraceFileNameState );
  tmpStates.push_back( TraceEditSequence::outputDirSuffixState );
  tmpStates.push_back( TraceEditSequence::pcfMergerReferenceState );

  return tmpStates;
}

bool PCFEventMergerAction::execute( std::string whichTrace )
{
  TraceEditSequence *tmpSequence = mySequence;

#ifndef OLD_PCFPARSER
  // Get new tracename
  std::string newName = ( (OutputTraceFileNameState *)tmpSequence->getState( TraceEditSequence::outputTraceFileNameState ) )->getData();
  if ( newName.empty() )
  {
    std::string tmpSuffix = ( (OutputDirSuffixState *)tmpSequence->getState( TraceEditSequence::outputDirSuffixState ) )->getData();
    std::string outputPath = whichTrace.substr( 0, whichTrace.find_last_of( mySequence->getKernelConnection()->getPathSeparator() ) ) +
                           mySequence->getKernelConnection()->getPathSeparator() + tmpSuffix;

    vector< std::string > tmpID;
    tmpID.push_back( EventTranslator::getID() );

    newName = mySequence->getKernelConnection()->getNewTraceName( whichTrace, outputPath, tmpID, false );
  }

  // Read reference pcf
  std::string referenceTrace = ( (PCFMergerReferenceState *)tmpSequence->getState( TraceEditSequence::pcfMergerReferenceState ) )->getData();
  std::string referencePCFFile = LocalKernel::composeName( referenceTrace, "pcf" );
#ifdef OLD_PCFPARSER
  ParaverTraceConfig *referenceTraceConfig = new ParaverTraceConfig( referencePCFFile );
  referenceTraceConfig->parse();
#else
  UIParaverTraceConfig *referenceTraceConfig = new UIParaverTraceConfig();
  referenceTraceConfig->parse( referencePCFFile );
#endif

  // Read source pcf
  std::string sourceTrace = LocalKernel::composeName( whichTrace, "pcf" );
#ifdef OLD_PCFPARSER
  ParaverTraceConfig *sourceTraceConfig = new ParaverTraceConfig( sourceTrace );
  sourceTraceConfig->parse();
#else
  UIParaverTraceConfig *sourceTraceConfig = new UIParaverTraceConfig();
  sourceTraceConfig->parse( sourceTrace );
#endif

  // Translation algorithm
  map< TTypeValuePair, TTypeValuePair > translation;

  vector< vector< unsigned int > > sourceGroupedTypes = sourceTraceConfig->getGroupedEventTypes();
  std::vector< unsigned int > tmpCodes = referenceTraceConfig->getEventTypes();
  std::set< unsigned int > referenceTypes;
  referenceTypes.insert( tmpCodes.begin(), tmpCodes.end() );

  for ( vector< vector< unsigned int > >::iterator itGroupType = sourceGroupedTypes.begin(); itGroupType != sourceGroupedTypes.end(); ++itGroupType )
  {
    vector< unsigned int >::iterator itSourceType;
    itSourceType = (*itGroupType).begin();

    if ( referenceTypes.find( *itSourceType ) != referenceTypes.end() )
    {
      vector< unsigned int > sourceValues;
      try
      {
        sourceValues = sourceTraceConfig->getEventValues( *itSourceType );
      }
#ifdef OLD_PCFPARSER
      catch( libparaver::ParaverTraceConfig::value_not_found )
#else
      catch( libparaver::UIParaverTraceConfig::value_not_found )
#endif
      {}

      if ( sourceValues.empty() )
        continue;

      map< std::string, unsigned int > referenceValues;
      try
      {
        tmpCodes = referenceTraceConfig->getEventValues( *itSourceType );
      }
#ifdef OLD_PCFPARSER
      catch( libparaver::ParaverTraceConfig::value_not_found )
#else
      catch( libparaver::UIParaverTraceConfig::value_not_found )
#endif
      {}

      if ( tmpCodes.empty() )
        continue;

      for ( vector< unsigned int >::iterator itReferenceValue = tmpCodes.begin(); itReferenceValue != tmpCodes.end(); ++itReferenceValue )
      {
        referenceValues[ referenceTraceConfig->getEventValue( *itSourceType, *itReferenceValue ) ] = *itReferenceValue;
      }

      map< unsigned int, std::string > valuesColliding;
      map< unsigned int, std::string > valuesFinal;

      for ( vector< unsigned int >::iterator itSourceValue = sourceValues.begin(); itSourceValue != sourceValues.end(); ++itSourceValue )
      {
        std::string sourceTag = sourceTraceConfig->getEventValue( *itSourceType, *itSourceValue );
        map< std::string, unsigned int >::iterator itRefValue = referenceValues.find( sourceTag );
        if ( itRefValue != referenceValues.end() )
        {
          if ( valuesFinal.find( (*itRefValue).second ) != valuesFinal.end() )
          {
            valuesColliding[ (*itRefValue).second ] = valuesFinal[ (*itRefValue).second ];
          }
          else
          {
            if ( *itSourceValue != (*itRefValue).second )
              cloneValuesIntoGroup( itSourceType, (*itGroupType).end(), *itSourceValue, (*itRefValue).second, translation );
          }

          valuesFinal[ (*itRefValue).second ] = sourceTag;
        }
        else
        {
          if ( valuesFinal.find( *itSourceValue ) != valuesFinal.end() )
          {
            valuesColliding[ *itSourceValue ] = sourceTag;
          }
          else
          {
            valuesFinal[ *itSourceValue ] = sourceTag;
          }
        }
      }

      unsigned int maxValue = (--valuesFinal.end())->first;
      for ( map< unsigned int, std::string >::iterator itCollision = valuesColliding.begin(); itCollision != valuesColliding.end(); ++itCollision )
      {
        valuesFinal[ ++maxValue ] = (*itCollision).second;
        if ( (*itCollision).first != maxValue )
          cloneValuesIntoGroup( itSourceType, (*itGroupType).end(), (*itCollision).first, maxValue, translation );
      }

      sourceTraceConfig->setEventValues( *itSourceType, valuesFinal );
    }
  }

  // Write files
  ( (EventTranslationTableState *)tmpSequence->getState( TraceEditSequence::eventTranslationTableState ) )->setData( translation );

  if ( !translation.empty() )
  {
    mySequence->getKernelConnection()->copyROW( whichTrace, newName );
    std::fstream tmpFileDestiny;
    tmpFileDestiny.open( LocalKernel::composeName( newName, std::string( "pcf" ) ).c_str(), std::ios::out );
    tmpFileDestiny << sourceTraceConfig->toString();
    tmpFileDestiny.close();
  }

  delete sourceTraceConfig;
  delete referenceTraceConfig;
#endif

  tmpSequence->executeNextAction( whichTrace );

  return true;
}
<|endoftext|>


<commit_before>// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Some tests for the framework itself.

#include "testing/gtest/include/gtest/gtest.h"
#include "sandbox/win/src/sandbox.h"
#include "sandbox/win/src/target_services.h"
#include "sandbox/win/src/sandbox_factory.h"
#include "sandbox/win/tests/common/controller.h"

namespace sandbox {

// Returns the current process state.
SBOX_TESTS_COMMAND int IntegrationTestsTest_state(int argc, wchar_t **argv) {
  if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled())
    return BEFORE_INIT;

  if (!SandboxFactory::GetTargetServices()->GetState()->RevertedToSelf())
    return BEFORE_REVERT;

  return AFTER_REVERT;
}

// Returns the current process state, keeping track of it.
SBOX_TESTS_COMMAND int IntegrationTestsTest_state2(int argc, wchar_t **argv) {
  static SboxTestsState state = MIN_STATE;
  if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled()) {
    if (MIN_STATE == state)
      state = BEFORE_INIT;
    return state;
  }

  if (!SandboxFactory::GetTargetServices()->GetState()->RevertedToSelf()) {
    if (BEFORE_INIT == state)
      state = BEFORE_REVERT;
    return state;
  }

  if (BEFORE_REVERT == state)
    state =  AFTER_REVERT;
  return state;
}

// Blocks the process for argv[0] milliseconds simulating stuck child.
SBOX_TESTS_COMMAND int IntegrationTestsTest_stuck(int argc, wchar_t **argv) {
  int timeout = 500;
  if (argc > 0) {
    timeout = _wtoi(argv[0]);
  }

  ::Sleep(timeout);
  return 1;
}

// Returns the number of arguments
SBOX_TESTS_COMMAND int IntegrationTestsTest_args(int argc, wchar_t **argv) {
  for (int i = 0; i < argc; i++) {
    wchar_t argument[20];
    size_t argument_bytes = wcslen(argv[i]) * sizeof(wchar_t);
    memcpy(argument, argv[i], __min(sizeof(argument), argument_bytes));
  }

  return argc;
}

TEST(IntegrationTestsTest, CallsBeforeInit) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(BEFORE_INIT);
  ASSERT_EQ(BEFORE_INIT, runner.RunTest(L"IntegrationTestsTest_state"));
}

TEST(IntegrationTestsTest, CallsBeforeRevert) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(BEFORE_REVERT);
  ASSERT_EQ(BEFORE_REVERT, runner.RunTest(L"IntegrationTestsTest_state"));
}

TEST(IntegrationTestsTest, CallsAfterRevert) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(AFTER_REVERT);
  ASSERT_EQ(AFTER_REVERT, runner.RunTest(L"IntegrationTestsTest_state"));
}

TEST(IntegrationTestsTest, CallsEveryState) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(EVERY_STATE);
  ASSERT_EQ(AFTER_REVERT, runner.RunTest(L"IntegrationTestsTest_state2"));
}

TEST(IntegrationTestsTest, ForwardsArguments) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(BEFORE_INIT);
  ASSERT_EQ(1, runner.RunTest(L"IntegrationTestsTest_args first"));
  ASSERT_EQ(4, runner.RunTest(L"IntegrationTestsTest_args first second third "
                              L"fourth"));
}

TEST(IntegrationTestsTest, StuckChild) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  // In this case the process must have finished.
  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
}

TEST(IntegrationTestsTest, StuckChildNoJob) {
  TestRunner runner(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 2000"));
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  // In this case the processes are not tracked by the broker and should be
  // still active.
  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(STILL_ACTIVE, exit_code);
  // Terminate the test process now.
  ::TerminateProcess(runner.process(), 0);
}

TEST(IntegrationTestsTest, TwoStuckChildrenSecondOneHasNoJob) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  TestRunner runner2(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
  runner2.SetTimeout(2000);
  runner2.SetAsynchronous(true);
  runner2.SetKillOnDestruction(false);
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner2.RunTest(L"IntegrationTestsTest_stuck 2000"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  // In this case the processes are not tracked by the broker and should be
  // still active.
  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
  ASSERT_TRUE(::GetExitCodeProcess(runner2.process(), &exit_code));
  ASSERT_EQ(STILL_ACTIVE, exit_code);
  // Terminate the test process now.
  ::TerminateProcess(runner2.process(), 0);
}

TEST(IntegrationTestsTest, TwoStuckChildrenFirstOneHasNoJob) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  TestRunner runner2(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
  runner2.SetTimeout(2000);
  runner2.SetAsynchronous(true);
  runner2.SetKillOnDestruction(false);
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner2.RunTest(L"IntegrationTestsTest_stuck 2000"));
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  // In this case the processes are not tracked by the broker and should be
  // still active.
  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
  ASSERT_TRUE(::GetExitCodeProcess(runner2.process(), &exit_code));
  ASSERT_EQ(STILL_ACTIVE, exit_code);
  // Terminate the test process now.
  ::TerminateProcess(runner2.process(), 0);
}

TEST(IntegrationTestsTest, MultipleStuckChildrenSequential) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  TestRunner runner2(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
  runner2.SetTimeout(2000);
  runner2.SetAsynchronous(true);
  runner2.SetKillOnDestruction(false);

  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner2.RunTest(L"IntegrationTestsTest_stuck 2000"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());

  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
  ASSERT_TRUE(::GetExitCodeProcess(runner2.process(), &exit_code));
  ASSERT_EQ(STILL_ACTIVE, exit_code);
  // Terminate the test process now.
  ::TerminateProcess(runner2.process(), 0);

  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
}

}  // namespace sandbox
<commit_msg>Temporarily disable failing integration tests on Windows<commit_after>// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Some tests for the framework itself.

#include "testing/gtest/include/gtest/gtest.h"
#include "sandbox/win/src/sandbox.h"
#include "sandbox/win/src/target_services.h"
#include "sandbox/win/src/sandbox_factory.h"
#include "sandbox/win/tests/common/controller.h"

namespace sandbox {

// Returns the current process state.
SBOX_TESTS_COMMAND int IntegrationTestsTest_state(int argc, wchar_t **argv) {
  if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled())
    return BEFORE_INIT;

  if (!SandboxFactory::GetTargetServices()->GetState()->RevertedToSelf())
    return BEFORE_REVERT;

  return AFTER_REVERT;
}

// Returns the current process state, keeping track of it.
SBOX_TESTS_COMMAND int IntegrationTestsTest_state2(int argc, wchar_t **argv) {
  static SboxTestsState state = MIN_STATE;
  if (!SandboxFactory::GetTargetServices()->GetState()->InitCalled()) {
    if (MIN_STATE == state)
      state = BEFORE_INIT;
    return state;
  }

  if (!SandboxFactory::GetTargetServices()->GetState()->RevertedToSelf()) {
    if (BEFORE_INIT == state)
      state = BEFORE_REVERT;
    return state;
  }

  if (BEFORE_REVERT == state)
    state =  AFTER_REVERT;
  return state;
}

// Blocks the process for argv[0] milliseconds simulating stuck child.
SBOX_TESTS_COMMAND int IntegrationTestsTest_stuck(int argc, wchar_t **argv) {
  int timeout = 500;
  if (argc > 0) {
    timeout = _wtoi(argv[0]);
  }

  ::Sleep(timeout);
  return 1;
}

// Returns the number of arguments
SBOX_TESTS_COMMAND int IntegrationTestsTest_args(int argc, wchar_t **argv) {
  for (int i = 0; i < argc; i++) {
    wchar_t argument[20];
    size_t argument_bytes = wcslen(argv[i]) * sizeof(wchar_t);
    memcpy(argument, argv[i], __min(sizeof(argument), argument_bytes));
  }

  return argc;
}

TEST(IntegrationTestsTest, CallsBeforeInit) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(BEFORE_INIT);
  ASSERT_EQ(BEFORE_INIT, runner.RunTest(L"IntegrationTestsTest_state"));
}

TEST(IntegrationTestsTest, CallsBeforeRevert) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(BEFORE_REVERT);
  ASSERT_EQ(BEFORE_REVERT, runner.RunTest(L"IntegrationTestsTest_state"));
}

TEST(IntegrationTestsTest, CallsAfterRevert) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(AFTER_REVERT);
  ASSERT_EQ(AFTER_REVERT, runner.RunTest(L"IntegrationTestsTest_state"));
}

TEST(IntegrationTestsTest, CallsEveryState) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(EVERY_STATE);
  ASSERT_EQ(AFTER_REVERT, runner.RunTest(L"IntegrationTestsTest_state2"));
}

TEST(IntegrationTestsTest, ForwardsArguments) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetTestState(BEFORE_INIT);
  ASSERT_EQ(1, runner.RunTest(L"IntegrationTestsTest_args first"));
  ASSERT_EQ(4, runner.RunTest(L"IntegrationTestsTest_args first second third "
                              L"fourth"));
}

TEST(IntegrationTestsTest, DISABLED_StuckChild) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  // In this case the process must have finished.
  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
}

TEST(IntegrationTestsTest, DISABLED_StuckChildNoJob) {
  TestRunner runner(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 2000"));
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  // In this case the processes are not tracked by the broker and should be
  // still active.
  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(STILL_ACTIVE, exit_code);
  // Terminate the test process now.
  ::TerminateProcess(runner.process(), 0);
}

TEST(IntegrationTestsTest, DISABLED_TwoStuckChildrenSecondOneHasNoJob) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  TestRunner runner2(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
  runner2.SetTimeout(2000);
  runner2.SetAsynchronous(true);
  runner2.SetKillOnDestruction(false);
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner2.RunTest(L"IntegrationTestsTest_stuck 2000"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  // In this case the processes are not tracked by the broker and should be
  // still active.
  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
  ASSERT_TRUE(::GetExitCodeProcess(runner2.process(), &exit_code));
  ASSERT_EQ(STILL_ACTIVE, exit_code);
  // Terminate the test process now.
  ::TerminateProcess(runner2.process(), 0);
}

TEST(IntegrationTestsTest, DISABLED_TwoStuckChildrenFirstOneHasNoJob) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  TestRunner runner2(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
  runner2.SetTimeout(2000);
  runner2.SetAsynchronous(true);
  runner2.SetKillOnDestruction(false);
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner2.RunTest(L"IntegrationTestsTest_stuck 2000"));
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  // In this case the processes are not tracked by the broker and should be
  // still active.
  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
  ASSERT_TRUE(::GetExitCodeProcess(runner2.process(), &exit_code));
  ASSERT_EQ(STILL_ACTIVE, exit_code);
  // Terminate the test process now.
  ::TerminateProcess(runner2.process(), 0);
}

TEST(IntegrationTestsTest, DISABLED_MultipleStuckChildrenSequential) {
  TestRunner runner;
  runner.SetTimeout(2000);
  runner.SetAsynchronous(true);
  runner.SetKillOnDestruction(false);
  TestRunner runner2(JOB_NONE, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
  runner2.SetTimeout(2000);
  runner2.SetAsynchronous(true);
  runner2.SetKillOnDestruction(false);

  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner2.RunTest(L"IntegrationTestsTest_stuck 2000"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());

  DWORD exit_code;
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
  ASSERT_TRUE(::GetExitCodeProcess(runner2.process(), &exit_code));
  ASSERT_EQ(STILL_ACTIVE, exit_code);
  // Terminate the test process now.
  ::TerminateProcess(runner2.process(), 0);

  ASSERT_EQ(SBOX_TEST_SUCCEEDED,
            runner.RunTest(L"IntegrationTestsTest_stuck 100"));
  // Actually both runners share the same singleton broker.
  ASSERT_EQ(SBOX_ALL_OK, runner.broker()->WaitForAllTargets());
  ASSERT_TRUE(::GetExitCodeProcess(runner.process(), &exit_code));
  ASSERT_EQ(1, exit_code);
}

}  // namespace sandbox
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: warnings.hxx,v $
 *
 *  $Revision: 1.4 $
 *
 *  last change: $Author: rt $ $Date: 2006-05-04 08:38:53 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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 the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef DBA_CORE_WARNINGS_HXX
#define DBA_CORE_WARNINGS_HXX

/** ==== begin UNO includes === **/
#ifndef _COM_SUN_STAR_SDBC_XWARNINGSSUPPLIER_HPP_
#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
#include <com/sun/star/sdb/SQLContext.hpp>
#endif
/** ==== end UNO includes === **/

//.........................................................................
namespace dbaccess
{
//.........................................................................

    //=====================================================================
    //= IWarningsContainer
    //=====================================================================
    class SAL_NO_VTABLE IWarningsContainer
    {
    public:
        virtual void appendWarning(const ::com::sun::star::sdbc::SQLException& _rWarning) = 0;
        virtual void appendWarning(const ::com::sun::star::sdbc::SQLWarning& _rWarning) = 0;
        virtual void appendWarning(const ::com::sun::star::sdb::SQLContext& _rContext) = 0;
    };

    //====================================================================
    //= WarningsContainer
    //====================================================================
    /** helper class for implementing XWarningsSupplier, which mixes own warnings with
        warnings obtained from an external instance
    */
    class WarningsContainer : public IWarningsContainer
    {
    private:
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XWarningsSupplier >   m_xExternalWarnings;
        ::com::sun::star::uno::Any                                                      m_aOwnWarnings;

    public:
        WarningsContainer() { }
        WarningsContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XWarningsSupplier >& _rxExternalWarnings )
            :m_xExternalWarnings( _rxExternalWarnings )
        {
        }

        // IWarningsContainer
        virtual void appendWarning(const ::com::sun::star::sdbc::SQLException& _rWarning);
        virtual void appendWarning(const ::com::sun::star::sdbc::SQLWarning& _rWarning);
        virtual void appendWarning(const ::com::sun::star::sdb::SQLContext& _rContext);

        // XWarningsSupplier
        ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) const;
        void SAL_CALL clearWarnings(  );
    };

//.........................................................................
}   // namespace dbaccess
//.........................................................................

#endif // DBA_CORE_WARNINGS_HXX

<commit_msg>INTEGRATION: CWS qiq (1.4.4); FILE MERGED 2006/06/30 13:28:23 fs 1.4.4.2: warning-free code 2006/05/10 14:24:34 fs 1.4.4.1: #i51143# convenience version of appendWarning<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: warnings.hxx,v $
 *
 *  $Revision: 1.5 $
 *
 *  last change: $Author: obo $ $Date: 2006-07-10 15:15:50 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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 the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef DBA_CORE_WARNINGS_HXX
#define DBA_CORE_WARNINGS_HXX

/** ==== begin UNO includes === **/
#ifndef _COM_SUN_STAR_SDBC_XWARNINGSSUPPLIER_HPP_
#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
#include <com/sun/star/sdb/SQLContext.hpp>
#endif
/** ==== end UNO includes === **/

//.........................................................................
namespace dbaccess
{
//.........................................................................

    //=====================================================================
    //= IWarningsContainer
    //=====================================================================
    class SAL_NO_VTABLE IWarningsContainer
    {
    public:
        virtual void appendWarning(const ::com::sun::star::sdbc::SQLException& _rWarning) = 0;
        virtual void appendWarning(const ::com::sun::star::sdbc::SQLWarning& _rWarning) = 0;
        virtual void appendWarning(const ::com::sun::star::sdb::SQLContext& _rContext) = 0;
    };

    //====================================================================
    //= WarningsContainer
    //====================================================================
    /** helper class for implementing XWarningsSupplier, which mixes own warnings with
        warnings obtained from an external instance
    */
    class WarningsContainer : public IWarningsContainer
    {
    private:
        ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XWarningsSupplier >   m_xExternalWarnings;
        ::com::sun::star::uno::Any                                                      m_aOwnWarnings;

    public:
        WarningsContainer() { }
        WarningsContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XWarningsSupplier >& _rxExternalWarnings )
            :m_xExternalWarnings( _rxExternalWarnings )
        {
        }
        virtual ~WarningsContainer();

        // convenience
        /** appends an SQLWarning instance to the chain
            @param  _rWarning
                the warning message
            @param  _pAsciiSQLState
                the SQLState of the warning
            @param  _rxContext
                the context of the warning
        */
        void appendWarning(
            const ::rtl::OUString& _rWarning,
            const sal_Char* _pAsciiSQLState,
            const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxContext );

        // IWarningsContainer
        virtual void appendWarning(const ::com::sun::star::sdbc::SQLException& _rWarning);
        virtual void appendWarning(const ::com::sun::star::sdbc::SQLWarning& _rWarning);
        virtual void appendWarning(const ::com::sun::star::sdb::SQLContext& _rContext);

        // XWarningsSupplier
        ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) const;
        void SAL_CALL clearWarnings(  );
    };

//.........................................................................
}   // namespace dbaccess
//.........................................................................

#endif // DBA_CORE_WARNINGS_HXX

<|endoftext|>