<commit_before>#include <FarPluginBase.h>
#ifdef _DEBUG
#include <debug.h>
#endif
#include "wcx.class.h"

int __stdcall WcxArchive::ProcessDataProc (char *FileName, int Size)
{
	if ( m_pfnCallback )
		return m_pfnCallback (AM_PROCESS_DATA, 0, (int)Size);

	return 1;
}

int __stdcall WcxArchive::SetChangeVolProc (char *ArcName, int Mode)
{
	return 1;
}

WcxModule::WcxModule (const char *lpFileName)
{
	m_hModule = LoadLibraryEx (
			lpFileName,
			NULL,
			LOAD_WITH_ALTERED_SEARCH_PATH
			);

	if ( m_hModule )
	{
		m_pfnOpenArchive=(PLUGINOPENARCHIVE)GetProcAddress(m_hModule,"OpenArchive");
		m_pfnCloseArchive=(PLUGINCLOSEARCHIVE)GetProcAddress(m_hModule,"CloseArchive");
		m_pfnReadHeader=(PLUGINREADHEADER)GetProcAddress(m_hModule,"ReadHeader");
		m_pfnProcessFile=(PLUGINPROCESSFILE)GetProcAddress(m_hModule,"ProcessFile");
		m_pfnPackFiles=(PLUGINPACKFILES)GetProcAddress(m_hModule,"PackFiles");
		m_pfnDeleteFiles=(PLUGINDELETEFILES)GetProcAddress(m_hModule,"DeleteFiles");
		m_pfnSetChangeVolProc=(PLUGINSETCHANGEVOLPROC)GetProcAddress(m_hModule,"SetChangeVolProc");
		m_pfnSetProcessDataProc=(PLUGINSETPROCESSDATAPROC)GetProcAddress(m_hModule,"SetProcessDataProc");
		m_pfnConfigurePacker=(PLUGINCONFIGUREPACKER)GetProcAddress(m_hModule,"ConfigurePacker");
		m_pfnGetPackerCaps=(PLUGINGETPACKERCAPS)GetProcAddress(m_hModule,"GetPackerCaps");
		m_pfnCanYouHandleThisFile=(PLUGINCANYOUHANDLETHISFILE)GetProcAddress(m_hModule,"CanYouHandleThisFile");
		m_pfnPackSetDefaultParams=(PLUGINPACKSETDEFAULTPARAMS)GetProcAddress(m_hModule,"PackSetDefaultParams");
	}

	if ( LoadedOK() )
	{
		if (m_pfnPackSetDefaultParams)
		{
			PackDefaultParamStruct dps;

			dps.size = sizeof(dps);
			dps.PluginInterfaceVersionLow = 10;
			dps.PluginInterfaceVersionHi = 2;
			strcpy(dps.DefaultIniName,"");

			m_pfnPackSetDefaultParams(&dps);
		}
	}
}

bool WcxModule::LoadedOK ()
{
	if ( !(m_hModule && m_pfnOpenArchive && m_pfnCloseArchive && m_pfnReadHeader && m_pfnProcessFile) )
		return false;

	return true;
}

WcxModule::~WcxModule ()
{
	FreeLibrary (m_hModule);
}

WcxModules::WcxModules ()
{
	memset (&m_PluginInfo, 0, sizeof (m_PluginInfo));

	char *lpPluginsPath = StrDuplicate (Info.ModuleName, 260);

	CutToSlash (lpPluginsPath);

	strcat (lpPluginsPath, "Formats");

	m_Modules.Create(10);
	m_ExtraPluginInfo.Create(10);

	FSF.FarRecursiveSearch(lpPluginsPath,"*.wcx",(FRSUSERFUNC)LoadWcxModules,FRS_RECUR,this);

	StrFree(lpPluginsPath);

	m_PluginInfo.pFormatInfo = (ArchiveFormatInfo *) realloc (m_PluginInfo.pFormatInfo, sizeof (ArchiveFormatInfo) * m_PluginInfo.nFormats);

	for (int i=0; i<m_ExtraPluginInfo.GetCount (); i++)
	{
		m_PluginInfo.pFormatInfo[i].dwFlags = AFF_SUPPORT_INTERNAL_EXTRACT|AFF_SUPPORT_INTERNAL_TEST;
		m_PluginInfo.pFormatInfo[i].lpName = m_ExtraPluginInfo[i]->Name;
		m_PluginInfo.pFormatInfo[i].lpDefaultExtention = m_ExtraPluginInfo[i]->DefaultExtention;
	}
}

WcxModules::~WcxModules ()
{
	if ( m_PluginInfo.pFormatInfo )
		free (m_PluginInfo.pFormatInfo);

	m_ExtraPluginInfo.Free ();
	m_Modules.Free ();
}

WcxModule *WcxModules::IsArchive (QueryArchiveStruct *pQAS, int *nModuleNum)
{
	WcxModule *TrueArc = NULL;

    *nModuleNum = -1;

	for (int i=0; i<m_Modules.GetCount(); i++)
	{
		if ( m_Modules[i]->m_pfnCanYouHandleThisFile )
		{
			if (m_Modules[i]->m_pfnCanYouHandleThisFile (pQAS->lpFileName))
			{
				TrueArc = m_Modules[i];
				*nModuleNum = i;
				break;
			}
		}
		else
		{
			tOpenArchiveData OpenArchiveData = {0};

			OpenArchiveData.ArcName = (char *)pQAS->lpFileName;
			OpenArchiveData.OpenMode = PK_OM_LIST;

			HANDLE hArchive = m_Modules[i]->m_pfnOpenArchive (&OpenArchiveData);

			if (hArchive)
			{
				m_Modules[i]->m_pfnCloseArchive (hArchive);
				TrueArc = m_Modules[i];
				*nModuleNum = i;
				break;
			}
		}
	}

	return TrueArc;
}

int WINAPI WcxModules::LoadWcxModules (const WIN32_FIND_DATA *pFindData,
		const char *lpFullName,
		WcxModules *pModules
		)
{
	if ( pFindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
		return TRUE;

	WcxModule *pModule = new WcxModule (lpFullName);

	if ( !pModule )
		return TRUE;

	if ( !pModule->LoadedOK () )
	{
		delete pModule;
		return TRUE;
	}

    pModules->m_PluginInfo.nFormats++;

    ExtraPluginInfo *pExtraPluginInfo = (ExtraPluginInfo *) malloc (sizeof (ExtraPluginInfo));

	strcpy(pExtraPluginInfo->Name,FSF.PointToName(lpFullName));
	*strrchr(pExtraPluginInfo->Name,'.') = 0;
	strcpy(pExtraPluginInfo->DefaultExtention,pExtraPluginInfo->Name);
	strcat(pExtraPluginInfo->Name," [wcx]");

	pModules->m_ExtraPluginInfo.Add (pExtraPluginInfo);
	pModules->m_Modules.Add (pModule);

	return TRUE;
}

void WcxModules::GetArchivePluginInfo (ArchivePluginInfo *ai)
{
	ai->nFormats = m_PluginInfo.nFormats;
	ai->pFormatInfo = m_PluginInfo.pFormatInfo;
}

bool WcxModules::GetDefaultCommand (int nFormat, int nCommand, char *lpCommand)
{
	return false;
}

WcxArchive::WcxArchive (WcxModule *pModule, int nModuleNum, const char *lpFileName)
{
	m_pModule = pModule;

	m_lpFileName = StrDuplicate (lpFileName);

	m_nModuleNum = nModuleNum;

	m_hArchive = NULL;

	CreateClassThunk (WcxArchive, ProcessDataProc, m_pfnProcessDataProc);
	CreateClassThunk (WcxArchive, SetChangeVolProc, m_pfnSetChangeVolProc);

	m_pfnCallback = NULL;
}

WcxArchive::~WcxArchive ()
{
	StrFree (m_lpFileName);

	free (m_pfnProcessDataProc);
	free (m_pfnSetChangeVolProc);
}

int WcxArchive::ConvertResult (int nResult)
{
	switch (nResult)
	{
		case E_END_ARCHIVE:
			return E_EOF;
		case E_BAD_ARCHIVE:
			return E_BROKEN;
		case E_BAD_DATA:
			return E_UNEXPECTED_EOF;
		case E_EREAD:
			return E_READ_ERROR;
	}

	return E_UNEXPECTED_EOF;
}

bool __stdcall WcxArchive::pOpenArchive (int nOpMode, ARCHIVECALLBACK pfnCallback)
{
	m_pfnCallback = pfnCallback;

	tOpenArchiveData OpenArchiveData = {0};

	OpenArchiveData.ArcName = m_lpFileName;
	OpenArchiveData.OpenMode = (nOpMode == OM_EXTRACT)?PK_OM_EXTRACT:PK_OM_LIST;

	m_hArchive = m_pModule->m_pfnOpenArchive (&OpenArchiveData);

	if ( m_hArchive )
	{
		if (m_pModule->m_pfnSetProcessDataProc)
			m_pModule->m_pfnSetProcessDataProc (m_hArchive, (tProcessDataProc)m_pfnProcessDataProc);

		if (m_pModule->m_pfnSetChangeVolProc)
			m_pModule->m_pfnSetChangeVolProc (m_hArchive, (tChangeVolProc)m_pfnSetChangeVolProc);

		return true;
	}

	return false;
}

void __stdcall WcxArchive::pCloseArchive ()
{
	m_pModule->m_pfnCloseArchive (m_hArchive);
}

int __stdcall WcxArchive::pGetArchiveItem (ArchiveItemInfo *pItem)
{
	int nResult = 0;

	//__debug ("%d", m_hArchive);

/*	if (!m_hArchive)
	{
		tOpenArchiveData OpenArchiveData = {0};

		OpenArchiveData.ArcName = m_lpFileName;
		OpenArchiveData.OpenMode = PK_OM_LIST;

		m_hArchive = m_pModule->m_pfnOpenArchive (&OpenArchiveData);

		if (m_hArchive)
		{
			if (m_pModule->m_pfnSetProcessDataProc)
				m_pModule->m_pfnSetProcessDataProc (m_hArchive, ProcessDataProc);
			if (m_pModule->m_pfnSetChangeVolProc)
				m_pModule->m_pfnSetChangeVolProc (m_hArchive, SetChangeVolProc);
		}
	}
	else        */
	//{
	nResult = m_pModule->m_pfnProcessFile (m_hArchive, PK_SKIP, NULL, NULL);
	//}

	//if (m_hArchive)
	{
		if (!nResult)
		{
			tHeaderData HeaderData;
			memset (&HeaderData, 0, sizeof (HeaderData));
			//strcpy (HeaderData.ArcName, m_lpFileName);

			nResult = m_pModule->m_pfnReadHeader (m_hArchive, &HeaderData);

			if ( !nResult )
			{
				CharToOem(HeaderData.FileName,pItem->pi.FindData.cFileName);

				pItem->pi.FindData.dwFileAttributes = HeaderData.FileAttr;
				pItem->pi.FindData.nFileSizeLow = HeaderData.UnpSize;

				FILETIME filetime;
				DosDateTimeToFileTime ((WORD)((DWORD)HeaderData.FileTime >> 16), (WORD)HeaderData.FileTime, &filetime);
				LocalFileTimeToFileTime (&filetime, &pItem->pi.FindData.ftLastWriteTime);
				pItem->pi.FindData.ftCreationTime = pItem->pi.FindData.ftLastAccessTime = pItem->pi.FindData.ftLastWriteTime;

				pItem->pi.PackSize = HeaderData.PackSize;
				pItem->pi.CRC32 = HeaderData.FileCRC;

				return E_SUCCESS;
			}
		}

	//	m_pModule->m_pfnCloseArchive (m_hArchive);
	//	m_hArchive = NULL;
	}

	return ConvertResult (nResult);
}

int __stdcall WcxArchive::pGetArchiveType ()
{
	return (m_nModuleNum);
}

bool __stdcall WcxArchive::pExtract (
		PluginPanelItem *pItems,
		int nItemsNumber,
		const char *lpDestPath,
		const char *lpCurrentFolder
		)
{
	int nProcessed = 0;
	int nResult = 0;

	bool bFound;

	char *lpDestName = StrCreate (260);
	char *lpTemp = StrCreate (260);

	/*if (!m_hArchive)
	{
		tOpenArchiveData OpenArchiveData = {0};

		OpenArchiveData.ArcName = m_lpFileName;
		OpenArchiveData.OpenMode = PK_OM_EXTRACT;

		m_hArchive = m_pModule->m_pfnOpenArchive (&OpenArchiveData);

		if (m_hArchive)
		{
			if (m_pModule->m_pfnSetProcessDataProc)
				m_pModule->m_pfnSetProcessDataProc (m_hArchive, m_pfnProcessDataProc);
			if (m_pModule->m_pfnSetChangeVolProc)
				m_pModule->m_pfnSetChangeVolProc (m_hArchive, m_pfnSetChangeVolProc);
		}
	}*/

	while ( m_hArchive && nResult == 0 )
	{
		tHeaderData HeaderData;
		memset (&HeaderData, 0, sizeof (HeaderData));

		nResult = m_pModule->m_pfnReadHeader (m_hArchive, &HeaderData);

		if ( nResult == 0 )
		{
			CharToOem (HeaderData.FileName, lpTemp);

			bFound = false;

			int i = 0;

			for (; i < nItemsNumber; i++)
			{
				if ( !strcmp (pItems[i].FindData.cFileName, lpTemp) )
				{
					OemToChar (lpDestPath, lpDestName);

					FSF.AddEndSlash (lpDestName);

					char *lpName = HeaderData.FileName;

					if ( *lpCurrentFolder /*&& !strncmp (
							lpName,
							lpCurrentFolder,
							strlen (lpCurrentFolder)
							)*/ )
						lpName += strlen (lpCurrentFolder);

					if ( *lpName == '\\' )
						lpName++;

					strcat (lpDestName, lpName);

					if ( m_pfnCallback )
						m_pfnCallback (AM_START_EXTRACT_FILE, (int)&pItems[i], (int)lpDestName);

					int nProcessResult = m_pModule->m_pfnProcessFile (m_hArchive, PK_EXTRACT, NULL, lpDestName);

					if ( !nProcessResult )
						nProcessed++;

					if ( /*m_bAborted ||*/ nProcessResult || (nProcessed == nItemsNumber) )
						goto l_1;

					bFound = true;

					break;
				}
			}

			if ( !bFound )
				m_pModule->m_pfnProcessFile (m_hArchive, PK_SKIP, NULL, NULL);
		}
	}

l_1:

/*	if (m_hArchive)
	{
		m_pModule->m_pfnCloseArchive (m_hArchive);
		m_hArchive = NULL;
	}*/

	//m_bAborted = false;

	StrFree (lpDestName);
	StrFree (lpTemp);

	return nProcessed!=0;
}
<commit_msg>small bug<commit_after>#include <FarPluginBase.h>
#ifdef _DEBUG
#include <debug.h>
#endif
#include "wcx.class.h"

int __stdcall WcxArchive::ProcessDataProc (char *FileName, int Size)
{
	if ( m_pfnCallback )
		return m_pfnCallback (AM_PROCESS_DATA, 0, (int)Size);

	return 1;
}

int __stdcall WcxArchive::SetChangeVolProc (char *ArcName, int Mode)
{
	return 1;
}

WcxModule::WcxModule (const char *lpFileName)
{
	m_hModule = LoadLibraryEx (
			lpFileName,
			NULL,
			LOAD_WITH_ALTERED_SEARCH_PATH
			);

	if ( m_hModule )
	{
		m_pfnOpenArchive=(PLUGINOPENARCHIVE)GetProcAddress(m_hModule,"OpenArchive");
		m_pfnCloseArchive=(PLUGINCLOSEARCHIVE)GetProcAddress(m_hModule,"CloseArchive");
		m_pfnReadHeader=(PLUGINREADHEADER)GetProcAddress(m_hModule,"ReadHeader");
		m_pfnProcessFile=(PLUGINPROCESSFILE)GetProcAddress(m_hModule,"ProcessFile");
		m_pfnPackFiles=(PLUGINPACKFILES)GetProcAddress(m_hModule,"PackFiles");
		m_pfnDeleteFiles=(PLUGINDELETEFILES)GetProcAddress(m_hModule,"DeleteFiles");
		m_pfnSetChangeVolProc=(PLUGINSETCHANGEVOLPROC)GetProcAddress(m_hModule,"SetChangeVolProc");
		m_pfnSetProcessDataProc=(PLUGINSETPROCESSDATAPROC)GetProcAddress(m_hModule,"SetProcessDataProc");
		m_pfnConfigurePacker=(PLUGINCONFIGUREPACKER)GetProcAddress(m_hModule,"ConfigurePacker");
		m_pfnGetPackerCaps=(PLUGINGETPACKERCAPS)GetProcAddress(m_hModule,"GetPackerCaps");
		m_pfnCanYouHandleThisFile=(PLUGINCANYOUHANDLETHISFILE)GetProcAddress(m_hModule,"CanYouHandleThisFile");
		m_pfnPackSetDefaultParams=(PLUGINPACKSETDEFAULTPARAMS)GetProcAddress(m_hModule,"PackSetDefaultParams");
	}

	if ( LoadedOK() )
	{
		if (m_pfnPackSetDefaultParams)
		{
			PackDefaultParamStruct dps;

			dps.size = sizeof(dps);
			dps.PluginInterfaceVersionLow = 10;
			dps.PluginInterfaceVersionHi = 2;
			strcpy(dps.DefaultIniName,"");

			m_pfnPackSetDefaultParams(&dps);
		}
	}
}

bool WcxModule::LoadedOK ()
{
	if ( !(m_hModule && m_pfnOpenArchive && m_pfnCloseArchive && m_pfnReadHeader && m_pfnProcessFile) )
		return false;

	return true;
}

WcxModule::~WcxModule ()
{
	FreeLibrary (m_hModule);
}

WcxModules::WcxModules ()
{
	memset (&m_PluginInfo, 0, sizeof (m_PluginInfo));

	char *lpPluginsPath = StrDuplicate (Info.ModuleName, 260);

	CutToSlash (lpPluginsPath);

	strcat (lpPluginsPath, "Formats");

	m_Modules.Create(10);
	m_ExtraPluginInfo.Create(10);

	FSF.FarRecursiveSearch(lpPluginsPath,"*.wcx",(FRSUSERFUNC)LoadWcxModules,FRS_RECUR,this);

	StrFree(lpPluginsPath);

	m_PluginInfo.pFormatInfo = (ArchiveFormatInfo *) realloc (m_PluginInfo.pFormatInfo, sizeof (ArchiveFormatInfo) * m_PluginInfo.nFormats);

	for (int i=0; i<m_ExtraPluginInfo.GetCount (); i++)
	{
		m_PluginInfo.pFormatInfo[i].dwFlags = AFF_SUPPORT_INTERNAL_EXTRACT|AFF_SUPPORT_INTERNAL_TEST;
		m_PluginInfo.pFormatInfo[i].lpName = m_ExtraPluginInfo[i]->Name;
		m_PluginInfo.pFormatInfo[i].lpDefaultExtention = m_ExtraPluginInfo[i]->DefaultExtention;
	}
}

WcxModules::~WcxModules ()
{
	if ( m_PluginInfo.pFormatInfo )
		free (m_PluginInfo.pFormatInfo);

	m_ExtraPluginInfo.Free ();
	m_Modules.Free ();
}

WcxModule *WcxModules::IsArchive (QueryArchiveStruct *pQAS, int *nModuleNum)
{
	WcxModule *TrueArc = NULL;

    *nModuleNum = -1;

	for (int i=0; i<m_Modules.GetCount(); i++)
	{
		if ( m_Modules[i]->m_pfnCanYouHandleThisFile )
		{
			if (m_Modules[i]->m_pfnCanYouHandleThisFile (pQAS->lpFileName))
			{
				TrueArc = m_Modules[i];
				*nModuleNum = i;
				break;
			}
		}
		else
		{
			tOpenArchiveData OpenArchiveData = {0};

			OpenArchiveData.ArcName = (char *)pQAS->lpFileName;
			OpenArchiveData.OpenMode = PK_OM_LIST;

			HANDLE hArchive = m_Modules[i]->m_pfnOpenArchive (&OpenArchiveData);

			if (hArchive)
			{
				m_Modules[i]->m_pfnCloseArchive (hArchive);
				TrueArc = m_Modules[i];
				*nModuleNum = i;
				break;
			}
		}
	}

	return TrueArc;
}

int WINAPI WcxModules::LoadWcxModules (const WIN32_FIND_DATA *pFindData,
		const char *lpFullName,
		WcxModules *pModules
		)
{
	if ( pFindData->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
		return TRUE;

	WcxModule *pModule = new WcxModule (lpFullName);

	if ( !pModule )
		return TRUE;

	if ( !pModule->LoadedOK () )
	{
		delete pModule;
		return TRUE;
	}

    pModules->m_PluginInfo.nFormats++;

    ExtraPluginInfo *pExtraPluginInfo = (ExtraPluginInfo *) malloc (sizeof (ExtraPluginInfo));

	strcpy(pExtraPluginInfo->Name,FSF.PointToName(lpFullName));
	*strrchr(pExtraPluginInfo->Name,'.') = 0;
	strcpy(pExtraPluginInfo->DefaultExtention,pExtraPluginInfo->Name);
	strcat(pExtraPluginInfo->Name," [wcx]");

	pModules->m_ExtraPluginInfo.Add (pExtraPluginInfo);
	pModules->m_Modules.Add (pModule);

	return TRUE;
}

void WcxModules::GetArchivePluginInfo (ArchivePluginInfo *ai)
{
	ai->nFormats = m_PluginInfo.nFormats;
	ai->pFormatInfo = m_PluginInfo.pFormatInfo;
}

bool WcxModules::GetDefaultCommand (int nFormat, int nCommand, char *lpCommand)
{
	return false;
}

WcxArchive::WcxArchive (WcxModule *pModule, int nModuleNum, const char *lpFileName)
{
	m_pModule = pModule;

	m_lpFileName = StrDuplicate (lpFileName);

	m_nModuleNum = nModuleNum;

	m_hArchive = NULL;

	CreateClassThunk (WcxArchive, ProcessDataProc, m_pfnProcessDataProc);
	CreateClassThunk (WcxArchive, SetChangeVolProc, m_pfnSetChangeVolProc);

	m_pfnCallback = NULL;
}

WcxArchive::~WcxArchive ()
{
	StrFree (m_lpFileName);

	free (m_pfnProcessDataProc);
	free (m_pfnSetChangeVolProc);
}

int WcxArchive::ConvertResult (int nResult)
{
	switch (nResult)
	{
		case E_END_ARCHIVE:
			return E_EOF;
		case E_BAD_ARCHIVE:
			return E_BROKEN;
		case E_BAD_DATA:
			return E_UNEXPECTED_EOF;
		case E_EREAD:
			return E_READ_ERROR;
	}

	return E_UNEXPECTED_EOF;
}

bool __stdcall WcxArchive::pOpenArchive (int nOpMode, ARCHIVECALLBACK pfnCallback)
{
	m_pfnCallback = pfnCallback;

	tOpenArchiveData OpenArchiveData = {0};

	OpenArchiveData.ArcName = m_lpFileName;
	OpenArchiveData.OpenMode = (nOpMode == OM_EXTRACT)?PK_OM_EXTRACT:PK_OM_LIST;

	m_hArchive = m_pModule->m_pfnOpenArchive (&OpenArchiveData);

	if ( m_hArchive )
	{
		if (m_pModule->m_pfnSetProcessDataProc)
			m_pModule->m_pfnSetProcessDataProc (m_hArchive, (tProcessDataProc)m_pfnProcessDataProc);

		if (m_pModule->m_pfnSetChangeVolProc)
			m_pModule->m_pfnSetChangeVolProc (m_hArchive, (tChangeVolProc)m_pfnSetChangeVolProc);

		return true;
	}

	return false;
}

void __stdcall WcxArchive::pCloseArchive ()
{
	m_pModule->m_pfnCloseArchive (m_hArchive);
}

int __stdcall WcxArchive::pGetArchiveItem (ArchiveItemInfo *pItem)
{
	int nResult = 0;

	//__debug ("%d", m_hArchive);

/*	if (!m_hArchive)
	{
		tOpenArchiveData OpenArchiveData = {0};

		OpenArchiveData.ArcName = m_lpFileName;
		OpenArchiveData.OpenMode = PK_OM_LIST;

		m_hArchive = m_pModule->m_pfnOpenArchive (&OpenArchiveData);

		if (m_hArchive)
		{
			if (m_pModule->m_pfnSetProcessDataProc)
				m_pModule->m_pfnSetProcessDataProc (m_hArchive, ProcessDataProc);
			if (m_pModule->m_pfnSetChangeVolProc)
				m_pModule->m_pfnSetChangeVolProc (m_hArchive, SetChangeVolProc);
		}
	}
	else        */
	//{
		//nResult = m_pModule->m_pfnProcessFile (m_hArchive, PK_SKIP, NULL, NULL);
	//}

	//if (m_hArchive)
	{
		if (!nResult)
		{
			tHeaderData HeaderData;
			memset (&HeaderData, 0, sizeof (HeaderData));
			//strcpy (HeaderData.ArcName, m_lpFileName);

			nResult = m_pModule->m_pfnReadHeader (m_hArchive, &HeaderData);

			m_pModule->m_pfnProcessFile (m_hArchive, PK_SKIP, NULL, NULL);

			if ( !nResult )
			{
				CharToOem(HeaderData.FileName,pItem->pi.FindData.cFileName);

				pItem->pi.FindData.dwFileAttributes = HeaderData.FileAttr;
				pItem->pi.FindData.nFileSizeLow = HeaderData.UnpSize;

				FILETIME filetime;
				DosDateTimeToFileTime ((WORD)((DWORD)HeaderData.FileTime >> 16), (WORD)HeaderData.FileTime, &filetime);
				LocalFileTimeToFileTime (&filetime, &pItem->pi.FindData.ftLastWriteTime);
				pItem->pi.FindData.ftCreationTime = pItem->pi.FindData.ftLastAccessTime = pItem->pi.FindData.ftLastWriteTime;

				pItem->pi.PackSize = HeaderData.PackSize;
				pItem->pi.CRC32 = HeaderData.FileCRC;

				return E_SUCCESS;
			}

		}

	//	m_pModule->m_pfnCloseArchive (m_hArchive);
	//	m_hArchive = NULL;
	}

	return ConvertResult (nResult);
}

int __stdcall WcxArchive::pGetArchiveType ()
{
	return (m_nModuleNum);
}

bool __stdcall WcxArchive::pExtract (
		PluginPanelItem *pItems,
		int nItemsNumber,
		const char *lpDestPath,
		const char *lpCurrentFolder
		)
{
	int nProcessed = 0;
	int nResult = 0;

	bool bFound;

	char *lpDestName = StrCreate (260);
	char *lpTemp = StrCreate (260);

	/*if (!m_hArchive)
	{
		tOpenArchiveData OpenArchiveData = {0};

		OpenArchiveData.ArcName = m_lpFileName;
		OpenArchiveData.OpenMode = PK_OM_EXTRACT;

		m_hArchive = m_pModule->m_pfnOpenArchive (&OpenArchiveData);

		if (m_hArchive)
		{
			if (m_pModule->m_pfnSetProcessDataProc)
				m_pModule->m_pfnSetProcessDataProc (m_hArchive, m_pfnProcessDataProc);
			if (m_pModule->m_pfnSetChangeVolProc)
				m_pModule->m_pfnSetChangeVolProc (m_hArchive, m_pfnSetChangeVolProc);
		}
	}*/

	while ( /*m_hArchive &&*/ nResult == 0 )
	{
		tHeaderData HeaderData;
		memset (&HeaderData, 0, sizeof (HeaderData));

		nResult = m_pModule->m_pfnReadHeader (m_hArchive, &HeaderData);

		if ( nResult == 0 )
		{
			CharToOem (HeaderData.FileName, lpTemp);

			bFound = false;

			int i = 0;

			for (; i < nItemsNumber; i++)
			{
				if ( !strcmp (pItems[i].FindData.cFileName, lpTemp) )
				{
					OemToChar (lpDestPath, lpDestName);

					FSF.AddEndSlash (lpDestName);

					char *lpName = HeaderData.FileName;

					if ( *lpCurrentFolder /*&& !strncmp (
							lpName,
							lpCurrentFolder,
							strlen (lpCurrentFolder)
							)*/ )
						lpName += strlen (lpCurrentFolder);

					if ( *lpName == '\\' )
						lpName++;

					strcat (lpDestName, lpName);

					if ( m_pfnCallback )
						m_pfnCallback (AM_START_EXTRACT_FILE, (int)&pItems[i], (int)lpDestName);

					int nProcessResult = m_pModule->m_pfnProcessFile (m_hArchive, PK_EXTRACT, NULL, lpDestName);

					if ( !nProcessResult )
						nProcessed++;

					if ( /*m_bAborted ||*/ nProcessResult || (nProcessed == nItemsNumber) )
						goto l_1;

					bFound = true;

					break;
				}
			}

			if ( !bFound )
				m_pModule->m_pfnProcessFile (m_hArchive, PK_SKIP, NULL, NULL);
		}
	}

l_1:

/*	if (m_hArchive)
	{
		m_pModule->m_pfnCloseArchive (m_hArchive);
		m_hArchive = NULL;
	}*/

	//m_bAborted = false;

	StrFree (lpDestName);
	StrFree (lpTemp);

	return nProcessed!=0;
}
<|endoftext|>


<commit_before>/*
    Copyright (C) 1998-2000 by Jorrit Tyberghein

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdarg.h>

#define SYSDEF_SOFTWARE2D
#include "cssysdef.h"
#include "soft_g3d.h"
#include "softex3d.h"
#include "isystem.h"
#include "igraph2d.h"
#include "csutil/inifile.h"

IMPLEMENT_FACTORY (csGraphics3DSoftware)
IMPLEMENT_FACTORY (csDynamicTextureSoft3D)

EXPORT_CLASS_TABLE (soft3d)
  EXPORT_CLASS (csGraphics3DSoftware, "crystalspace.graphics3d.software",
    "Software 3D graphics driver for Crystal Space")
  EXPORT_CLASS (csDynamicTextureSoft3D,
    "crystalspace.graphics3d.software.offscreen",
    "Software 3D off screen driver")
EXPORT_CLASS_TABLE_END

IMPLEMENT_IBASE (csGraphics3DSoftware)
  IMPLEMENTS_INTERFACE (iPlugIn)
  IMPLEMENTS_INTERFACE (iGraphics3D)
  IMPLEMENTS_EMBEDDED_INTERFACE (iConfig)
IMPLEMENT_IBASE_END

#define SysPrintf System->Printf

csGraphics3DSoftware::csGraphics3DSoftware (iBase *iParent)
  : csGraphics3DSoftwareCommon ()
{
  CONSTRUCT_IBASE (iParent);
  CONSTRUCT_EMBEDDED_IBASE (scfiConfig);
  csScan_Initialize ();
}

csGraphics3DSoftware::~csGraphics3DSoftware ()
{
  csScan_Finalize ();
}

bool csGraphics3DSoftware::Initialize (iSystem *iSys)
{
  if (!csGraphics3DSoftwareCommon::Initialize (iSys))
    return false;

  const char *driver = config->GetStr ("Hardware", "Driver2D", SOFTWARE_2D_DRIVER);
  G2D = LOAD_PLUGIN (System, driver, NULL, iGraphics2D);

  return G2D ? true : false;
}
bool csGraphics3DSoftware::Open (const char *Title)
{
  if (!csGraphics3DSoftwareCommon::Open (Title))
    return false;

  bool bFullScreen = G2D->GetFullScreen ();
  SysPrintf(MSG_INITIALIZATION, "Using %s mode %dx%d (internal rendering at %dx%d).\n",
            bFullScreen ? "full screen" : "windowed", G2D->GetWidth (), G2D->GetHeight (), width, height);

  if (pfmt.PixelBytes == 4)
    SysPrintf (MSG_INITIALIZATION, "Using truecolor mode with %d bytes per pixel and %d:%d:%d RGB mode.\n",
          pfmt.PixelBytes, pfmt.RedBits, pfmt.GreenBits, pfmt.BlueBits);
  else if (pfmt.PixelBytes == 2)
    SysPrintf (MSG_INITIALIZATION, "Using truecolor mode with %d bytes per pixel and %d:%d:%d RGB mode.\n",
          pfmt.PixelBytes, pfmt.RedBits, pfmt.GreenBits, pfmt.BlueBits);
  else
    SysPrintf (MSG_INITIALIZATION, "Using palette mode with 1 byte per pixel (256 colors).\n");

  return true;
}

iGraphics3D *csGraphics3DSoftware::CreateOffScreenRenderer
  (iGraphics2D */*parent_g2d*/, int width, int height, csPixelFormat *pfmt,
   void *buffer, RGBPixel *palette, int pal_size)
{
  csDynamicTextureSoft3D *tex3d =
       new csDynamicTextureSoft3D (NULL);
  tex3d->Initialize (System);
  return tex3d->CreateOffScreenRenderer (G2D, width, height, pfmt, buffer,
				       palette, pal_size);
}

//---------------------------------------------------------------------------

IMPLEMENT_EMBEDDED_IBASE (csGraphics3DSoftware::csSoftConfig)
  IMPLEMENTS_INTERFACE (iConfig)
IMPLEMENT_EMBEDDED_IBASE_END

#define NUM_OPTIONS 8

static const csOptionDescription config_options [NUM_OPTIONS] =
{
  { 0, "ilace", "Interlacing", CSVAR_BOOL },
  { 1, "light", "Texture lighting", CSVAR_BOOL },
  { 2, "transp", "Transparent textures", CSVAR_BOOL },
  { 3, "txtmap", "Texture mapping", CSVAR_BOOL },
  { 4, "mmx", "MMX support", CSVAR_BOOL },
  { 5, "gamma", "Gamma value", CSVAR_FLOAT },
  { 6, "gouraud", "Gouraud shading", CSVAR_BOOL },
  { 7, "smaller", "Smaller rendering", CSVAR_BOOL },
};

bool csGraphics3DSoftware::csSoftConfig::SetOption (int id, csVariant* value)
{
  if (value->type != config_options[id].type)
    return false;
  switch (id)
  {
    case 0: scfParent->do_interlaced = value->v.b ? 0 : -1; break;
    case 1: scfParent->do_lighting = value->v.b; break;
    case 2: scfParent->do_transp = value->v.b; break;
    case 3: scfParent->do_textured = value->v.b; break;
#ifdef DO_MMX
    case 4: scfParent->do_mmx = value->v.b; break;
#endif
    case 5: scfParent->texman->Gamma = value->v.f; break;
    case 6: scfParent->do_gouraud = value->v.b; break;
    case 7: scfParent->do_smaller_rendering = value->v.b; break;
    default: return false;
  }
  scfParent->ScanSetup ();
  return true;
}

bool csGraphics3DSoftware::csSoftConfig::GetOption (int id, csVariant* value)
{
  value->type = config_options[id].type;
  switch (id)
  {
    case 0: value->v.b = scfParent->do_interlaced != -1; break;
    case 1: value->v.b = scfParent->do_lighting; break;
    case 2: value->v.b = scfParent->do_transp; break;
    case 3: value->v.b = scfParent->do_textured; break;
#ifdef DO_MMX
    case 4: value->v.b = scfParent->do_mmx; break;
#endif
    case 5: value->v.f = scfParent->Gamma / 65536.; break;
    case 6: value->v.b = scfParent->do_gouraud; break;
    case 7: value->v.b = scfParent->do_smaller_rendering; break;
    default: return false;
  }
  return true;
}

bool csGraphics3DSoftware::csSoftConfig::GetOptionDescription
  (int idx, csOptionDescription* option)
{
  if (idx < 0 || idx >= NUM_OPTIONS)
    return false;
  *option = config_options[idx];
  return true;
}
<commit_msg>Eliminated compilation warning about */ appearing outside of comment.<commit_after>/*
    Copyright (C) 1998-2000 by Jorrit Tyberghein

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    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
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdarg.h>

#define SYSDEF_SOFTWARE2D
#include "cssysdef.h"
#include "soft_g3d.h"
#include "softex3d.h"
#include "isystem.h"
#include "igraph2d.h"
#include "csutil/inifile.h"

IMPLEMENT_FACTORY (csGraphics3DSoftware)
IMPLEMENT_FACTORY (csDynamicTextureSoft3D)

EXPORT_CLASS_TABLE (soft3d)
  EXPORT_CLASS (csGraphics3DSoftware, "crystalspace.graphics3d.software",
    "Software 3D graphics driver for Crystal Space")
  EXPORT_CLASS (csDynamicTextureSoft3D,
    "crystalspace.graphics3d.software.offscreen",
    "Software 3D off screen driver")
EXPORT_CLASS_TABLE_END

IMPLEMENT_IBASE (csGraphics3DSoftware)
  IMPLEMENTS_INTERFACE (iPlugIn)
  IMPLEMENTS_INTERFACE (iGraphics3D)
  IMPLEMENTS_EMBEDDED_INTERFACE (iConfig)
IMPLEMENT_IBASE_END

#define SysPrintf System->Printf

csGraphics3DSoftware::csGraphics3DSoftware (iBase *iParent)
  : csGraphics3DSoftwareCommon ()
{
  CONSTRUCT_IBASE (iParent);
  CONSTRUCT_EMBEDDED_IBASE (scfiConfig);
  csScan_Initialize ();
}

csGraphics3DSoftware::~csGraphics3DSoftware ()
{
  csScan_Finalize ();
}

bool csGraphics3DSoftware::Initialize (iSystem *iSys)
{
  if (!csGraphics3DSoftwareCommon::Initialize (iSys))
    return false;

  const char *driver = config->GetStr ("Hardware", "Driver2D", SOFTWARE_2D_DRIVER);
  G2D = LOAD_PLUGIN (System, driver, NULL, iGraphics2D);

  return G2D ? true : false;
}
bool csGraphics3DSoftware::Open (const char *Title)
{
  if (!csGraphics3DSoftwareCommon::Open (Title))
    return false;

  bool bFullScreen = G2D->GetFullScreen ();
  SysPrintf(MSG_INITIALIZATION, "Using %s mode %dx%d (internal rendering at %dx%d).\n",
            bFullScreen ? "full screen" : "windowed", G2D->GetWidth (), G2D->GetHeight (), width, height);

  if (pfmt.PixelBytes == 4)
    SysPrintf (MSG_INITIALIZATION, "Using truecolor mode with %d bytes per pixel and %d:%d:%d RGB mode.\n",
          pfmt.PixelBytes, pfmt.RedBits, pfmt.GreenBits, pfmt.BlueBits);
  else if (pfmt.PixelBytes == 2)
    SysPrintf (MSG_INITIALIZATION, "Using truecolor mode with %d bytes per pixel and %d:%d:%d RGB mode.\n",
          pfmt.PixelBytes, pfmt.RedBits, pfmt.GreenBits, pfmt.BlueBits);
  else
    SysPrintf (MSG_INITIALIZATION, "Using palette mode with 1 byte per pixel (256 colors).\n");

  return true;
}

iGraphics3D *csGraphics3DSoftware::CreateOffScreenRenderer
  (iGraphics2D* /*parent_g2d*/, int width, int height, csPixelFormat *pfmt,
   void *buffer, RGBPixel *palette, int pal_size)
{
  csDynamicTextureSoft3D *tex3d =
       new csDynamicTextureSoft3D (NULL);
  tex3d->Initialize (System);
  return tex3d->CreateOffScreenRenderer (G2D, width, height, pfmt, buffer,
				       palette, pal_size);
}

//---------------------------------------------------------------------------

IMPLEMENT_EMBEDDED_IBASE (csGraphics3DSoftware::csSoftConfig)
  IMPLEMENTS_INTERFACE (iConfig)
IMPLEMENT_EMBEDDED_IBASE_END

#define NUM_OPTIONS 8

static const csOptionDescription config_options [NUM_OPTIONS] =
{
  { 0, "ilace", "Interlacing", CSVAR_BOOL },
  { 1, "light", "Texture lighting", CSVAR_BOOL },
  { 2, "transp", "Transparent textures", CSVAR_BOOL },
  { 3, "txtmap", "Texture mapping", CSVAR_BOOL },
  { 4, "mmx", "MMX support", CSVAR_BOOL },
  { 5, "gamma", "Gamma value", CSVAR_FLOAT },
  { 6, "gouraud", "Gouraud shading", CSVAR_BOOL },
  { 7, "smaller", "Smaller rendering", CSVAR_BOOL },
};

bool csGraphics3DSoftware::csSoftConfig::SetOption (int id, csVariant* value)
{
  if (value->type != config_options[id].type)
    return false;
  switch (id)
  {
    case 0: scfParent->do_interlaced = value->v.b ? 0 : -1; break;
    case 1: scfParent->do_lighting = value->v.b; break;
    case 2: scfParent->do_transp = value->v.b; break;
    case 3: scfParent->do_textured = value->v.b; break;
#ifdef DO_MMX
    case 4: scfParent->do_mmx = value->v.b; break;
#endif
    case 5: scfParent->texman->Gamma = value->v.f; break;
    case 6: scfParent->do_gouraud = value->v.b; break;
    case 7: scfParent->do_smaller_rendering = value->v.b; break;
    default: return false;
  }
  scfParent->ScanSetup ();
  return true;
}

bool csGraphics3DSoftware::csSoftConfig::GetOption (int id, csVariant* value)
{
  value->type = config_options[id].type;
  switch (id)
  {
    case 0: value->v.b = scfParent->do_interlaced != -1; break;
    case 1: value->v.b = scfParent->do_lighting; break;
    case 2: value->v.b = scfParent->do_transp; break;
    case 3: value->v.b = scfParent->do_textured; break;
#ifdef DO_MMX
    case 4: value->v.b = scfParent->do_mmx; break;
#endif
    case 5: value->v.f = scfParent->Gamma / 65536.; break;
    case 6: value->v.b = scfParent->do_gouraud; break;
    case 7: value->v.b = scfParent->do_smaller_rendering; break;
    default: return false;
  }
  return true;
}

bool csGraphics3DSoftware::csSoftConfig::GetOptionDescription
  (int idx, csOptionDescription* option)
{
  if (idx < 0 || idx >= NUM_OPTIONS)
    return false;
  *option = config_options[idx];
  return true;
}
<|endoftext|>


<commit_before>/* main.cpp - main entry point for the command-line tool `dm`
 *
 * The current implementation is specific to chains of integrators;
 * however, the design is intended to be general to facilitate later
 * treatment of other kinds of systems.
 *
 * While some infrastructure is in place for building without ROS, it
 * is as yet not operational.
 *
 *
 * SCL; Jan 2015
 */

#ifdef USE_ROS
#include <ros/ros.h>
#include <dynamaestro/VectorStamped.h>
#endif

#include <cmath>
#include <vector>

#include <pthread.h>

class TrajectoryGenerator {
private:
	std::vector<double> X;
	double t;  // Current time
	int numdim_input;
	int numdim_output;

public:
	/* Because we are assuming the chain of integrators system, the
	   number of dimensions of the input (parameter numdim_input to
	   the constructors) must equal the number of dimensions of the
	   output (parameter numdim_output). */
	TrajectoryGenerator( int numdim_state, int numdim_input, int numdim_output );
	TrajectoryGenerator( std::vector<double> Xinit, int numdim_input, int numdim_output );

	double step( double dt, const double &U );
	double getTime() const
		{ return t; }
	double getStateDim() const
		{ return X.size(); }

	// Output vector
	double operator[]( int i ) const;

	/* Access to full, current state vector */
	double getState( int i ) const
		{ return X[i]; }
};

TrajectoryGenerator::TrajectoryGenerator( int numdim_state, int numdim_input, int numdim_output )
	: t(0.0), numdim_input(numdim_input), numdim_output(numdim_output)
{
	for (int i = 0; i < numdim_state; i++)
		X.push_back( 5.0 );
}

TrajectoryGenerator::TrajectoryGenerator( std::vector<double> Xinit, int numdim_input, int numdim_output  )
	: t(0.0), X(Xinit), numdim_input(numdim_input), numdim_output(numdim_output)
{ }

double TrajectoryGenerator::step( double dt, const double &U )
{
	int numdim_state = X.size();

	for (int i = 0; i <= numdim_state-2; i++)
		X[i] += dt*X[i+1];

	X[numdim_state-1] += dt*U;

	t += dt;
	return t;
}

double TrajectoryGenerator::operator[]( int i ) const
{
	if (i < numdim_output) {
		return X[i];
	} else {
		ROS_ERROR( "Invalid index into output vector: %d", i );
		return 0.0/0.0;
	}
}

/* nhp should point to an instance of ros::NodeHandle */
void *tgthread( void *nhp )
{
	ros::Publisher statepub = ((ros::NodeHandle *)nhp)->advertise<dynamaestro::VectorStamped>( "output", 10 );

	double h = 0.1;  // Sampling period
	TrajectoryGenerator tg( 3, 1, 1 );

	// Send initial output, before any input is applied or time has begun.
	dynamaestro::VectorStamped pt;
	pt.header.frame_id = std::string( "map" );
	pt.header.stamp = ros::Time::now();
	for (int i = 0; i < tg.getStateDim(); i++)
		pt.point.push_back( tg.getState( i ) );
	statepub.publish( pt );
	ros::spinOnce();

	ros::Rate rate( 1/h );
	while (ros::ok()) {
		tg.step( h, -(tg.getState( 0 ) + 2.4142*tg.getState( 1 ) + 2.4142*tg.getState( 2 )) );

		dynamaestro::VectorStamped pt;
		pt.header.frame_id = std::string( "map" );
		pt.header.stamp = ros::Time::now();
		for (int i = 0; i < tg.getStateDim(); i++)
			pt.point.push_back( tg.getState( i ) );
		statepub.publish( pt );
		ros::spinOnce();
		rate.sleep();
	}
}

int main( int argc, char **argv )
{
#ifdef USE_ROS
	ros::init( argc, argv, "dynamaestro" );
	ros::NodeHandle nh;

	pthread_t tgID;
	if (pthread_create( &tgID, NULL, tgthread, (void *)&nh )) {
		perror( "dm, pthread_create" );
		return -1;
	}

	ros::Rate rate( 10. );
	while (ros::ok()) {
		ros::spinOnce();
		rate.sleep();
	}

#endif
	return 0;
}
<commit_msg>Basic implementation of general case of chain of integrators<commit_after>/* main.cpp - main entry point for the command-line tool `dm`
 *
 * The current implementation is specific to chains of integrators;
 * however, the design is intended to be general to facilitate later
 * treatment of other kinds of systems.
 *
 * While some infrastructure is in place for building without ROS, it
 * is as yet not operational.
 *
 *
 * SCL; Jan 2015
 */

#ifdef USE_ROS
#include <ros/ros.h>
#include <dynamaestro/VectorStamped.h>
#endif

#include <cmath>
#include <vector>

#include <pthread.h>

/* Because we are assuming the chain of integrators system, the number of
   dimensions of the input (parameter numdim_input to the constructors) must
   equal the number of dimensions of the output (parameter numdim_output).

   The trajectories are the solutions of linear time-invariant control
   system. Control input is applied using a zero-order hold, i.e., applied
   constantly during the duration given as the first parameter of step().

   Let M be the highest order of derivative, and let N be the dimension of the
   output space.  The state variable indexing is such that the first output
   variable is the first state variable, the second output variable is the
   second state variable, etc. Thus the component systems are interleaved in the
   sense that the first subsystem is formed from state variable indices 1, 1+N,
   1+2N, ..., 1+(M-1)N, and the input to this subsystem is applied at state
   variable index 1+(M-1)N.
*/
class TrajectoryGenerator {
private:
	std::vector<double> X;
	double t;  // Current time
	int highest_order_deriv;
	int numdim_output;

public:
	TrajectoryGenerator( int numdim_output, int highest_order_deriv );

	/* Consult the class description regarding the assumed arrangement of the
	   state variables, i.e., the indexing and the assumption that the system is
	   a chain of integrators. */
	TrajectoryGenerator( std::vector<double>Xinit, int numdim_output );

	/* Forward Euler integration for duration dt using constant input U */
	double step( double dt, const std::vector<double> &U );

	double getTime() const
		{ return t; }
	double getStateDim() const
		{ return X.size(); }
	double getOutputDim() const
		{ return numdim_output; }

	// Output vector
	double operator[]( int i ) const;

	/* Access to full, current state vector */
	double getState( int i ) const
		{ return X[i]; }
};

TrajectoryGenerator::TrajectoryGenerator( int numdim_output, int highest_order_deriv )
	: t(0.0), highest_order_deriv(highest_order_deriv), numdim_output(numdim_output)
{
	for (int i = 0; i < numdim_output*highest_order_deriv; i++)
		X.push_back( 5.0 );
}

TrajectoryGenerator::TrajectoryGenerator( std::vector<double> Xinit, int numdim_output  )
	: t(0.0), X(Xinit), numdim_output(numdim_output)
{
	highest_order_deriv = X.size()/numdim_output;  // N.B., assumed to divide evenly!
}

double TrajectoryGenerator::step( double dt, const std::vector<double> &U )
{
	if (U.size() > numdim_output) {
		ROS_ERROR( "Input vector has too many elements." );
		return 0.0/0.0;
	}

	int numdim_state = X.size();

	int i, j;
	for (j = 0; j < numdim_output; j++) {
		for (i = 0; i <= highest_order_deriv-2; i++) {
			X[i*numdim_output+j] += dt*X[(i+1)*numdim_output+j];
		}
		X[(highest_order_deriv-1)*numdim_output+j] += dt*U[j];
	}

	t += dt;
	return t;
}

double TrajectoryGenerator::operator[]( int i ) const
{
	if (i < numdim_output) {
		return X[i];
	} else {
		ROS_ERROR( "Invalid index into output vector: %d", i );
		return 0.0/0.0;
	}
}

/* nhp should point to an instance of ros::NodeHandle */
void *tgthread( void *nhp )
{
	ros::Publisher statepub = ((ros::NodeHandle *)nhp)->advertise<dynamaestro::VectorStamped>( "output", 10 );
	//ros::Subscriber inputsub = ((ros::NodeHandle *)nhp)->subscribe( "input", 1, inputcb );

	double h = 0.1;  // Sampling period
	TrajectoryGenerator tg( 1, 3 );

	// Send initial output, before any input is applied or time has begun.
	dynamaestro::VectorStamped pt;
	pt.header.frame_id = std::string( "map" );
	pt.header.stamp = ros::Time::now();
	for (int i = 0; i < tg.getStateDim(); i++)
		pt.point.push_back( tg.getState( i ) );
	statepub.publish( pt );
	ros::spinOnce();

	ros::Rate rate( 1/h );
	std::vector<double> U;
	for (int i = 0; i < tg.getOutputDim(); i++)
		U.push_back( 0.0 );

	while (ros::ok()) {
		U[0] = -(tg.getState( 0 ) + 2.4142*tg.getState( 1 ) + 2.4142*tg.getState( 2 ));
		tg.step( h, U );

		dynamaestro::VectorStamped pt;
		pt.header.frame_id = std::string( "map" );
		pt.header.stamp = ros::Time::now();
		for (int i = 0; i < tg.getStateDim(); i++)
			pt.point.push_back( tg.getState( i ) );
		statepub.publish( pt );
		ros::spinOnce();
		rate.sleep();
	}
}

int main( int argc, char **argv )
{
#ifdef USE_ROS
	ros::init( argc, argv, "dynamaestro" );
	ros::NodeHandle nh;

	pthread_t tgID;
	if (pthread_create( &tgID, NULL, tgthread, (void *)&nh )) {
		perror( "dm, pthread_create" );
		return -1;
	}

	ros::Rate rate( 10. );
	while (ros::ok()) {
		ros::spinOnce();
		rate.sleep();
	}

#endif
	return 0;
}
<|endoftext|>


<commit_before>/***************************************************************************
 *   Copyright (C) 2005-2012 by the FIFE team                              *
 *   http://www.fifengine.net                                              *
 *   This file is part of FIFE.                                            *
 *                                                                         *
 *   FIFE is free software; you can redistribute it and/or                 *
 *   modify it under the terms of the GNU Lesser General Public            *
 *   License as published by the Free Software Foundation; either          *
 *   version 2.1 of the License, or (at your option) any later version.    *
 *                                                                         *
 *   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.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

// Standard C++ library includes

// 3rd party library includes
#include <CEGUI/CEGUI.h>

// FIFE includes
// These includes are split up in two parts, separated by one empty line
// First block: files included from the FIFE root src directory
// Second block: files included from the same folder

#include "ceguiinputprocessor.h"

namespace FIFE {
	CEGuiInputProcessor::CEGuiInputProcessor() {
	}

	CEGuiInputProcessor::~CEGuiInputProcessor() {
	}

	bool CEGuiInputProcessor::onSdlEvent(SDL_Event& event) {
		bool consumed = false;

		switch(event.type) {

			case SDL_KEYUP:
			case SDL_KEYDOWN:
				consumed = processKeyInput(event);
				break;

			case SDL_MOUSEBUTTONUP:
			case SDL_MOUSEBUTTONDOWN:
				consumed = processMouseInput(event);
				break;

			case SDL_MOUSEMOTION:
				consumed = processMouseMotion(event);
				break;

			default:
				;
		}

		return consumed;
	}

	bool CEGuiInputProcessor::processKeyInput(SDL_Event& event) {
		switch(event.type) {
			case SDL_KEYDOWN:
				if((event.key.keysym.unicode & 0xFF80) == 0)
				{
					CEGUI::System::getSingleton().injectChar(event.key.keysym.unicode & 0x7F);
				}
				break;

			case SDL_KEYUP:
				CEGUI::System::getSingleton().injectKeyUp(event.key.keysym.scancode);
				break;

			default:
				;
		}

		return false;
	}

	bool CEGuiInputProcessor::processMouseInput(SDL_Event& event) {
		switch(event.type) {
			case SDL_MOUSEBUTTONDOWN:
				switch(event.button.button) {
					case SDL_BUTTON_LEFT:
						CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
						break;

					case SDL_BUTTON_RIGHT:
						CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
						break;

					case SDL_BUTTON_MIDDLE:
						CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton) ;
						break;

					case SDL_BUTTON_WHEELDOWN:
						CEGUI::System::getSingleton().injectMouseWheelChange(-1);
						break;

					case SDL_BUTTON_WHEELUP:
						CEGUI::System::getSingleton().injectMouseWheelChange(1);
						break;

					default:
						;
				}
				break;

			case SDL_MOUSEBUTTONUP:
				switch(event.button.button) {
					case SDL_BUTTON_LEFT:
						CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
						break;

					case SDL_BUTTON_RIGHT:
						CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
						break;

					case SDL_BUTTON_MIDDLE:
						CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton) ;
						break;

					case SDL_BUTTON_WHEELDOWN:
						break;

					case SDL_BUTTON_WHEELUP:
						break;

					default:
						;
				}
				break;

			default:
				;
		}

		return false;
	}

	bool CEGuiInputProcessor::processMouseMotion(SDL_Event& event) {
		CEGUI::System::getSingleton().injectMousePosition(static_cast<float>(event.motion.x), static_cast<float>(event.motion.y));

		return false;
	}
}<commit_msg>Possible fix. refs #777<commit_after>/***************************************************************************
 *   Copyright (C) 2005-2012 by the FIFE team                              *
 *   http://www.fifengine.net                                              *
 *   This file is part of FIFE.                                            *
 *                                                                         *
 *   FIFE is free software; you can redistribute it and/or                 *
 *   modify it under the terms of the GNU Lesser General Public            *
 *   License as published by the Free Software Foundation; either          *
 *   version 2.1 of the License, or (at your option) any later version.    *
 *                                                                         *
 *   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.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

// Standard C++ library includes

// 3rd party library includes
#include <CEGUI/CEGUI.h>

// FIFE includes
// These includes are split up in two parts, separated by one empty line
// First block: files included from the FIFE root src directory
// Second block: files included from the same folder

#include "ceguiinputprocessor.h"

namespace FIFE {
	CEGuiInputProcessor::CEGuiInputProcessor() {
	}

	CEGuiInputProcessor::~CEGuiInputProcessor() {
	}

	bool CEGuiInputProcessor::onSdlEvent(SDL_Event& event) {
		bool consumed = false;

		switch(event.type) {

			case SDL_KEYUP:
			case SDL_KEYDOWN:
				consumed = processKeyInput(event);
				break;

			case SDL_MOUSEBUTTONUP:
			case SDL_MOUSEBUTTONDOWN:
				consumed = processMouseInput(event);
				break;

			case SDL_MOUSEMOTION:
				consumed = processMouseMotion(event);
				break;

			default:
				;
		}

		return consumed;
	}

	bool CEGuiInputProcessor::processKeyInput(SDL_Event& event) {
                bool consumed = false;

		switch(event.type) {
			case SDL_KEYDOWN:
				if((event.key.keysym.unicode & 0xFF80) == 0)
				{
					consumed = CEGUI::System::getSingleton().injectChar(event.key.keysym.unicode & 0x7F);
				}
				break;

			case SDL_KEYUP:
				consumed = CEGUI::System::getSingleton().injectKeyUp(event.key.keysym.scancode);
				break;

			default:
				;
		}

		return consumed;
	}

	bool CEGuiInputProcessor::processMouseInput(SDL_Event& event) {
                bool consumed = false;

		switch(event.type) {
			case SDL_MOUSEBUTTONDOWN:
				switch(event.button.button) {
					case SDL_BUTTON_LEFT:
						consumed = CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::LeftButton);
						break;

					case SDL_BUTTON_RIGHT:
						consumed = CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::RightButton);
						break;

					case SDL_BUTTON_MIDDLE:
						consumed = CEGUI::System::getSingleton().injectMouseButtonDown(CEGUI::MiddleButton) ;
						break;

					case SDL_BUTTON_WHEELDOWN:
						consumed = CEGUI::System::getSingleton().injectMouseWheelChange(-1);
						break;

					case SDL_BUTTON_WHEELUP:
						consumed = CEGUI::System::getSingleton().injectMouseWheelChange(1);
						break;

					default:
						;
				}
				break;

			case SDL_MOUSEBUTTONUP:
				switch(event.button.button) {
					case SDL_BUTTON_LEFT:
						consumed = CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::LeftButton);
						break;

					case SDL_BUTTON_RIGHT:
						consumed = CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::RightButton);
						break;

					case SDL_BUTTON_MIDDLE:
						consumed = CEGUI::System::getSingleton().injectMouseButtonUp(CEGUI::MiddleButton) ;
						break;

					case SDL_BUTTON_WHEELDOWN:
						break;

					case SDL_BUTTON_WHEELUP:
						break;

					default:
						;
				}
				break;

			default:
				;
		}

		return consumed;
	}

	bool CEGuiInputProcessor::processMouseMotion(SDL_Event& event) {
	    return CEGUI::System::getSingleton().injectMousePosition(static_cast<float>(event.motion.x), static_cast<float>(event.motion.y));
	}
}
<|endoftext|>


<commit_before>//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// 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.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#include <iostream>

#include "RCSDiscoveryManager.h"
#include "RCSRepresentation.h"
#include "RCSRemoteResourceObject.h"
#include "RCSResourceAttributes.h"
#include "RCSAddress.h"

#include "OCPlatform.h"

#define DECLARE_MENU(FUNC, ...) { #FUNC, FUNC }

using namespace OC;
using namespace OIC::Service;

struct CloseApp {};

struct MenuItem
{
private:
    typedef void(*Handler)();

public:
    const std::string title;
    const Handler handler;
};

typedef void(*Runner)();

constexpr int RESOURCE_TEMP = 1;
constexpr int RESOURCE_LIGHT = 2;

const std::string RESOURCE_TYPE_TEMP = "oic.r.temperaturesensor";
const std::string RESOURCE_TYPE_LIGHT = "oic.r.light";

RCSRemoteResourceObject::Ptr g_selectedResource;
std::vector<RCSRemoteResourceObject::Ptr> g_discoveredResources;

std::string g_attrKey;

Runner g_currentRun;

std::ostream& operator<<(std::ostream& os, const RCSRemoteResourceObject::Ptr& object)
{
    return os << "\turi : " << object->getUri() << std::endl <<
            "\thost address : " << object->getAddress();
}

std::ostream& operator<<(std::ostream& os, const MenuItem& item)
{
    return os << item.title;
}

void onSelected(const RCSRemoteResourceObject::Ptr& object)
{
    g_selectedResource = object;
}

void onSelected(const MenuItem& item)
{
    std::cout << item.title << " start.." << std::endl;
    item.handler();
}

int processUserInput(int min = std::numeric_limits<int>::min(),
        int max = std::numeric_limits<int>::max())
{
    assert(min <= max);

    int input = 0;

    std::cin >> input;
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

    if (!std::cin.fail() && min <= input && input <= max)
    {
        return input;
    }

    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

    throw std::runtime_error("Invalid Input, please try again");
}

template<typename D>
void displayItem(int width, int index, const D& data)
{
    std::cout.width(width);
    std::cout << std::right << index << ". ";
    std::cout << data << std::endl;
}

template<typename T>
void displayItems(const std::vector<T>& items)
{
    std::cout << std::endl;

    const auto width = (items.size() + 1) / 10 + 1;

    for (size_t i = 0; i < items.size(); ++i)
    {
        displayItem(width, i + 1, items[i]);
    }
    displayItem(width, items.size() + 1, "quit");
}

template<typename T>
void selectItem(const std::vector<T>& items)
{
    int selected = processUserInput(1, items.size() + 1) - 1;

    if (selected == static_cast<int>(items.size()))
    {
        throw CloseApp();
    }

    onSelected(items[selected]);
}

template<typename T>
void handleItems(const std::vector<T>& items)
{
    displayItems(items);
    selectItem(items);
}

std::string inputInterface()
{
    std::string interfaceName;

    std::cout << "\tInput the Interface you want to set : ";
    std::cin >> interfaceName;

    return interfaceName;
}

RCSResourceAttributes inputKeyValue()
{
    std::string key;

    std::cout << "\tEnter the Key you want to set : ";
    std::cin >> key;

    std::cout << "\tEnter the value(INT) you want to set :";
    RCSResourceAttributes attrs;
    attrs[key] = processUserInput();

    return attrs;
}

void printAttribute(const std::string& key, const RCSResourceAttributes::Value& value)
{
    std::cout << "\tkey : " << key << std::endl
              << "\tvalue : " << value.toString() << std::endl;
}

void printAttributes(const RCSResourceAttributes& attributes)
{
    if (attributes.empty())
    {
       std::cout << "\tattributes is empty" << std::endl;
    }

    for (const auto& attr : attributes)
    {
        printAttribute(attr.key(), attr.value());
    }
}

void print(const std::string& name, const std::vector< std::string >& elements)
{
    if (elements.empty())
    {
       std::cout << "\t" << name << " is empty" << std::endl;
       return;
    }

    std::cout << "\t" << name << " : " << std::endl;
    for (const auto& item : elements)
    {
        std::cout << item << " ";
    }
    std::cout << std::endl;
}

void printUri(const std::string& uri)
{
    if (uri.empty())
    {
        std::cout << "\turi is empty" << std::endl;
    }
    else
    {
        std::cout << "\turi : " << uri << std::endl;
    }
}

void printRepresentation(const RCSRepresentation& rep)
{
    printUri(rep.getUri());
    print("interfaces", rep.getInterfaces());
    print("resourceTypes", rep.getResourceTypes());
    printAttributes(rep.getAttributes());

    const auto& children = rep.getChildren();

    if (children.empty())
    {
        std::cout << "\tchildren is empty" << std::endl;
    }
    else
    {
        int cnt = 0;
        for (const auto& child : children)
        {
            std::cout << "========================================================" << std::endl;
            std::cout << ++cnt << " chlid" << std::endl;
            printRepresentation(child);
            std::cout << "========================================================" << std::endl;
        }
    }
}

void onResourceStateChanged(ResourceState resourceState)
{
    std::cout << "onResourceStateChanged callback" << std::endl;

    switch (resourceState)
    {
        case ResourceState::NONE:
            std::cout << "\tState changed to : NOT_MONITORING" << std::endl;
            break;

        case ResourceState::ALIVE:
            std::cout << "\tState changed to : ALIVE" << std::endl;
            break;

        case ResourceState::REQUESTED:
            std::cout << "\tState changed to : REQUESTED" << std::endl;
            break;

        case ResourceState::LOST_SIGNAL:
            std::cout << "\tState changed to : LOST_SIGNAL" << std::endl;
            break;

        case ResourceState::DESTROYED:
            std::cout << "\tState changed to : DESTROYED" << std::endl;
            break;
    }
}

void onCacheUpdated(const RCSResourceAttributes& attributes, int eCode)
{
    std::cout << "onCacheUpdated callback : " << eCode << std::endl;

    printAttributes(attributes);
}

void onRemoteAttributesReceived(const RCSResourceAttributes& attributes, int)
{
    std::cout << "onRemoteAttributesReceived callback" << std::endl;

    printAttributes(attributes);
}

void onRemoteGetReceived(const HeaderOpts&, const RCSRepresentation& rep, int)
{
    std::cout << "onRemoteGetReceived callback" << std::endl;

    printRepresentation(rep);
}

void onRemoteSetReceived(const HeaderOpts&, const RCSRepresentation& rep, int)
{
    std::cout << "onRemoteSetReceived callback" << std::endl;

    printRepresentation(rep);
}

void startMonitoring()
{
    if (g_selectedResource->isMonitoring())
    {
        std::cout << "\tAlready Started..." << std::endl;
        return;
    }

    g_selectedResource->startMonitoring(&onResourceStateChanged);
    std::cout << "\tMonitoring Started..." << std::endl;
}

void stopMonitoring()
{
    if (!g_selectedResource->isMonitoring())
    {
        std::cout << "\tMonitoring not started..." << std::endl;
        return;
    }

    g_selectedResource->stopMonitoring();
    std::cout << "\tMonitoring stopped..." << std::endl;
}

void getRemoteAttributes()
{
    g_selectedResource->getRemoteAttributes(onRemoteAttributesReceived);
}

void setRemoteAttributes()
{
    g_selectedResource->setRemoteAttributes(inputKeyValue(), onRemoteAttributesReceived);
}

void getWithInterface()
{
    RCSQueryParams queryParams;
    queryParams.setResourceInterface(inputInterface());

    g_selectedResource->get(queryParams, onRemoteGetReceived);
}

void setWithInterface()
{
    RCSQueryParams queryParams;
    queryParams.setResourceInterface(inputInterface());

    g_selectedResource->set(queryParams, inputKeyValue(), onRemoteSetReceived);
}

void startCaching(RCSRemoteResourceObject::CacheUpdatedCallback cb)
{
    if (g_selectedResource->isCaching())
    {
        std::cout << "\tAlready Started Caching..." << std::endl;
        return;
    }

    g_selectedResource->startCaching(std::move(cb));
    std::cout << "\tCaching Started..." << std::endl;
}

void startCachingWithoutCallback()
{
    startCaching(nullptr);
}

void startCachingWithCallback()
{
    startCaching(onCacheUpdated);
}

void getResourceCacheState()
{
    switch(g_selectedResource->getCacheState())
    {
        case CacheState::READY:
            std::cout << "\tCurrent Cache State : CACHE_STATE::READY" << std::endl;
            break;

        case CacheState::UNREADY:
            std::cout << "\tCurrent Cache State : CACHE_STATE::UNREADY" << std::endl;
            break;

        case CacheState::LOST_SIGNAL:
            std::cout << "\tCurrent Cache State : CACHE_STATE::LOST_SIGNAL" << std::endl;
            break;

        case CacheState::NONE:
            std::cout << "\tCurrent Cache State : CACHE_STATE::NONE" << std::endl;
            break;
    }
}

void getCachedAttributes()
{
    printAttributes(g_selectedResource->getCachedAttributes());
}

void getCachedAttribute()
{
    printAttribute(g_attrKey, g_selectedResource->getCachedAttribute(g_attrKey));
}

void stopCaching()
{
    if (!g_selectedResource->isCaching())
    {
        std::cout << "\tCaching not started..." << std::endl;
        return;
    }

    g_selectedResource->stopCaching();
    std::cout << "\tCaching stopped..." << std::endl;
}

std::string selectResourceType()
{
    std::cout << "========================================================" << std::endl;
    std::cout << "1. Temperature Resource Discovery" << std::endl;
    std::cout << "2. Light Resource Discovery" << std::endl;
    std::cout << "========================================================" << std::endl;

    switch (processUserInput(RESOURCE_TEMP, RESOURCE_LIGHT))
    {
        case RESOURCE_TEMP:
        {
            g_attrKey = "Temperature";
            return RESOURCE_TYPE_TEMP;
        }
        case RESOURCE_LIGHT:
        {
            g_attrKey = "Brightness";
            return RESOURCE_TYPE_LIGHT;
        }
    }

    throw std::logic_error("unreachable");
}

RCSAddress inputAddress()
{
    std::cout << "========================================================" << std::endl;
    std::cout << "Please input address (empty for multicast)" << std::endl;
    std::cout << "========================================================" << std::endl;

    std::string address;

    if (std::cin.peek() != '\n')
    {
        std::cin >> address;
    }

    return address.empty() ? RCSAddress::multicast() : RCSAddress::unicast(address);
}

void printDiscoveryInProgress()
{
    std::cout << "Discovery in progress, press '1' to stop." << std::endl;
}

void discoverResource()
{
    auto onResourceDiscovered = [](
            const RCSRemoteResourceObject::Ptr& discoveredResource)
    {
        std::cout << "onResourceDiscovered callback :: " << std::endl;

        std::cout << "uri : " << discoveredResource->getUri() << std::endl;
        std::cout << "host address : " << discoveredResource->getAddress() << std::endl;

        g_discoveredResources.push_back(discoveredResource);

        printDiscoveryInProgress();
    };

    auto resourceType = selectResourceType();
    auto address = inputAddress();

    printDiscoveryInProgress();

    auto discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(address,
            resourceType, onResourceDiscovered);

    while (processUserInput() != 1);

    discoveryTask->cancel();
}

void runResourceControl()
{
    static std::vector<MenuItem> resourceMenuItems {
        DECLARE_MENU(startMonitoring),
        DECLARE_MENU(stopMonitoring),
        DECLARE_MENU(getRemoteAttributes),
        DECLARE_MENU(setRemoteAttributes),
        DECLARE_MENU(getWithInterface),
        DECLARE_MENU(setWithInterface),
        DECLARE_MENU(startCachingWithoutCallback),
        DECLARE_MENU(startCachingWithCallback),
        DECLARE_MENU(getResourceCacheState),
        DECLARE_MENU(getCachedAttributes),
        DECLARE_MENU(getCachedAttribute),
        DECLARE_MENU(stopCaching),
    };

    handleItems(resourceMenuItems);
}

void runResourceSelection()
{
    handleItems(g_discoveredResources);

    g_currentRun = runResourceControl;
}

void runDiscovery()
{
    static std::vector<MenuItem> discoveryMenuItems {
        DECLARE_MENU(discoverResource),
    };

    handleItems(discoveryMenuItems);

    if (g_discoveredResources.empty())
    {
        throw std::runtime_error("No resource found!");
    }

    g_currentRun = runResourceSelection;
}

void configurePlatform()
{
    PlatformConfig config
    {
        OC::ServiceType::InProc, ModeType::Client, "0.0.0.0", 0, OC::QualityOfService::LowQos
    };
    OCPlatform::Configure(config);
}

int main()
{
    configurePlatform();

    g_currentRun = runDiscovery;

    while (true)
    {
        try
        {
            g_currentRun();
        }
        catch (const std::exception& e)
        {
            std::cout << e.what() << std::endl;
        }
        catch (const CloseApp&)
        {
            break;
        }
    }

    std::cout << "Stopping the client" << std::endl;

    return 0;
}
<commit_msg>Fix for catching of exception on the RE linux sample.<commit_after>//******************************************************************
//
// Copyright 2015 Samsung Electronics All Rights Reserved.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
// 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.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#include <iostream>

#include "RCSDiscoveryManager.h"
#include "RCSRepresentation.h"
#include "RCSRemoteResourceObject.h"
#include "RCSResourceAttributes.h"
#include "RCSAddress.h"

#include "OCPlatform.h"

#define DECLARE_MENU(FUNC, ...) { #FUNC, FUNC }

using namespace OC;
using namespace OIC::Service;

struct CloseApp {};

struct MenuItem
{
private:
    typedef void(*Handler)();

public:
    const std::string title;
    const Handler handler;
};

typedef void(*Runner)();

constexpr int RESOURCE_TEMP = 1;
constexpr int RESOURCE_LIGHT = 2;

const std::string RESOURCE_TYPE_TEMP = "oic.r.temperaturesensor";
const std::string RESOURCE_TYPE_LIGHT = "oic.r.light";

RCSRemoteResourceObject::Ptr g_selectedResource;
std::vector<RCSRemoteResourceObject::Ptr> g_discoveredResources;

std::string g_attrKey;

Runner g_currentRun;

std::ostream& operator<<(std::ostream& os, const RCSRemoteResourceObject::Ptr& object)
{
    return os << "\turi : " << object->getUri() << std::endl <<
            "\thost address : " << object->getAddress();
}

std::ostream& operator<<(std::ostream& os, const MenuItem& item)
{
    return os << item.title;
}

void onSelected(const RCSRemoteResourceObject::Ptr& object)
{
    g_selectedResource = object;
}

void onSelected(const MenuItem& item)
{
    std::cout << item.title << " start.." << std::endl;
    item.handler();
}

int processUserInput(int min = std::numeric_limits<int>::min(),
        int max = std::numeric_limits<int>::max())
{
    assert(min <= max);

    int input = 0;

    std::cin >> input;
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

    if (!std::cin.fail() && min <= input && input <= max)
    {
        return input;
    }

    std::cin.clear();
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

    throw std::runtime_error("Invalid Input, please try again");
}

template<typename D>
void displayItem(int width, int index, const D& data)
{
    std::cout.width(width);
    std::cout << std::right << index << ". ";
    std::cout << data << std::endl;
}

template<typename T>
void displayItems(const std::vector<T>& items)
{
    std::cout << std::endl;

    const auto width = (items.size() + 1) / 10 + 1;

    for (size_t i = 0; i < items.size(); ++i)
    {
        displayItem(width, i + 1, items[i]);
    }
    displayItem(width, items.size() + 1, "quit");
}

template<typename T>
void selectItem(const std::vector<T>& items)
{
    int selected = processUserInput(1, items.size() + 1) - 1;

    if (selected == static_cast<int>(items.size()))
    {
        throw CloseApp();
    }

    onSelected(items[selected]);
}

template<typename T>
void handleItems(const std::vector<T>& items)
{
    displayItems(items);
    selectItem(items);
}

std::string inputInterface()
{
    std::string interfaceName;

    std::cout << "\tInput the Interface you want to set : ";
    std::cin >> interfaceName;

    return interfaceName;
}

RCSResourceAttributes inputKeyValue()
{
    std::string key;

    std::cout << "\tEnter the Key you want to set : ";
    std::cin >> key;

    std::cout << "\tEnter the value(INT) you want to set :";
    RCSResourceAttributes attrs;
    attrs[key] = processUserInput();

    return attrs;
}

void printAttribute(const std::string& key, const RCSResourceAttributes::Value& value)
{
    std::cout << "\tkey : " << key << std::endl
              << "\tvalue : " << value.toString() << std::endl;
}

void printAttributes(const RCSResourceAttributes& attributes)
{
    if (attributes.empty())
    {
       std::cout << "\tattributes is empty" << std::endl;
    }

    for (const auto& attr : attributes)
    {
        printAttribute(attr.key(), attr.value());
    }
}

void print(const std::string& name, const std::vector< std::string >& elements)
{
    if (elements.empty())
    {
       std::cout << "\t" << name << " is empty" << std::endl;
       return;
    }

    std::cout << "\t" << name << " : " << std::endl;
    for (const auto& item : elements)
    {
        std::cout << item << " ";
    }
    std::cout << std::endl;
}

void printUri(const std::string& uri)
{
    if (uri.empty())
    {
        std::cout << "\turi is empty" << std::endl;
    }
    else
    {
        std::cout << "\turi : " << uri << std::endl;
    }
}

void printRepresentation(const RCSRepresentation& rep)
{
    printUri(rep.getUri());
    print("interfaces", rep.getInterfaces());
    print("resourceTypes", rep.getResourceTypes());
    printAttributes(rep.getAttributes());

    const auto& children = rep.getChildren();

    if (children.empty())
    {
        std::cout << "\tchildren is empty" << std::endl;
    }
    else
    {
        int cnt = 0;
        for (const auto& child : children)
        {
            std::cout << "========================================================" << std::endl;
            std::cout << ++cnt << " chlid" << std::endl;
            printRepresentation(child);
            std::cout << "========================================================" << std::endl;
        }
    }
}

void onResourceStateChanged(ResourceState resourceState)
{
    std::cout << "onResourceStateChanged callback" << std::endl;

    switch (resourceState)
    {
        case ResourceState::NONE:
            std::cout << "\tState changed to : NOT_MONITORING" << std::endl;
            break;

        case ResourceState::ALIVE:
            std::cout << "\tState changed to : ALIVE" << std::endl;
            break;

        case ResourceState::REQUESTED:
            std::cout << "\tState changed to : REQUESTED" << std::endl;
            break;

        case ResourceState::LOST_SIGNAL:
            std::cout << "\tState changed to : LOST_SIGNAL" << std::endl;
            break;

        case ResourceState::DESTROYED:
            std::cout << "\tState changed to : DESTROYED" << std::endl;
            break;
    }
}

void onCacheUpdated(const RCSResourceAttributes& attributes, int eCode)
{
    std::cout << "onCacheUpdated callback : " << eCode << std::endl;

    printAttributes(attributes);
}

void onRemoteAttributesReceived(const RCSResourceAttributes& attributes, int)
{
    std::cout << "onRemoteAttributesReceived callback" << std::endl;

    printAttributes(attributes);
}

void onRemoteGetReceived(const HeaderOpts&, const RCSRepresentation& rep, int)
{
    std::cout << "onRemoteGetReceived callback" << std::endl;

    printRepresentation(rep);
}

void onRemoteSetReceived(const HeaderOpts&, const RCSRepresentation& rep, int)
{
    std::cout << "onRemoteSetReceived callback" << std::endl;

    printRepresentation(rep);
}

void startMonitoring()
{
    if (g_selectedResource->isMonitoring())
    {
        std::cout << "\tAlready Started..." << std::endl;
        return;
    }

    g_selectedResource->startMonitoring(&onResourceStateChanged);
    std::cout << "\tMonitoring Started..." << std::endl;
}

void stopMonitoring()
{
    if (!g_selectedResource->isMonitoring())
    {
        std::cout << "\tMonitoring not started..." << std::endl;
        return;
    }

    g_selectedResource->stopMonitoring();
    std::cout << "\tMonitoring stopped..." << std::endl;
}

void getRemoteAttributes()
{
    g_selectedResource->getRemoteAttributes(onRemoteAttributesReceived);
}

void setRemoteAttributes()
{
    g_selectedResource->setRemoteAttributes(inputKeyValue(), onRemoteAttributesReceived);
}

void getWithInterface()
{
    RCSQueryParams queryParams;
    queryParams.setResourceInterface(inputInterface());

    g_selectedResource->get(queryParams, onRemoteGetReceived);
}

void setWithInterface()
{
    RCSQueryParams queryParams;
    queryParams.setResourceInterface(inputInterface());

    g_selectedResource->set(queryParams, inputKeyValue(), onRemoteSetReceived);
}

void startCaching(RCSRemoteResourceObject::CacheUpdatedCallback cb)
{
    if (g_selectedResource->isCaching())
    {
        std::cout << "\tAlready Started Caching..." << std::endl;
        return;
    }

    g_selectedResource->startCaching(std::move(cb));
    std::cout << "\tCaching Started..." << std::endl;
}

void startCachingWithoutCallback()
{
    startCaching(nullptr);
}

void startCachingWithCallback()
{
    startCaching(onCacheUpdated);
}

void getResourceCacheState()
{
    switch(g_selectedResource->getCacheState())
    {
        case CacheState::READY:
            std::cout << "\tCurrent Cache State : CACHE_STATE::READY" << std::endl;
            break;

        case CacheState::UNREADY:
            std::cout << "\tCurrent Cache State : CACHE_STATE::UNREADY" << std::endl;
            break;

        case CacheState::LOST_SIGNAL:
            std::cout << "\tCurrent Cache State : CACHE_STATE::LOST_SIGNAL" << std::endl;
            break;

        case CacheState::NONE:
            std::cout << "\tCurrent Cache State : CACHE_STATE::NONE" << std::endl;
            break;
    }
}

void getCachedAttributes()
{
    try
    {
        printAttributes(g_selectedResource->getCachedAttributes());
    }
    catch (const RCSBadRequestException & e)
    {
        std::cout << e.what() << std::endl;
    }
}

void getCachedAttribute()
{
    try
    {
        printAttribute(g_attrKey, g_selectedResource->getCachedAttribute(g_attrKey));
    }
    catch (const RCSBadRequestException & e)
    {
        std::cout << e.what() << std::endl;
    }
}

void stopCaching()
{
    if (!g_selectedResource->isCaching())
    {
        std::cout << "\tCaching not started..." << std::endl;
        return;
    }

    g_selectedResource->stopCaching();
    std::cout << "\tCaching stopped..." << std::endl;
}

std::string selectResourceType()
{
    std::cout << "========================================================" << std::endl;
    std::cout << "1. Temperature Resource Discovery" << std::endl;
    std::cout << "2. Light Resource Discovery" << std::endl;
    std::cout << "========================================================" << std::endl;

    switch (processUserInput(RESOURCE_TEMP, RESOURCE_LIGHT))
    {
        case RESOURCE_TEMP:
        {
            g_attrKey = "Temperature";
            return RESOURCE_TYPE_TEMP;
        }
        case RESOURCE_LIGHT:
        {
            g_attrKey = "Brightness";
            return RESOURCE_TYPE_LIGHT;
        }
    }

    throw std::logic_error("unreachable");
}

RCSAddress inputAddress()
{
    std::cout << "========================================================" << std::endl;
    std::cout << "Please input address (empty for multicast)" << std::endl;
    std::cout << "========================================================" << std::endl;

    std::string address;

    if (std::cin.peek() != '\n')
    {
        std::cin >> address;
    }

    return address.empty() ? RCSAddress::multicast() : RCSAddress::unicast(address);
}

void printDiscoveryInProgress()
{
    std::cout << "Discovery in progress, press '1' to stop." << std::endl;
}

void discoverResource()
{
    auto onResourceDiscovered = [](
            const RCSRemoteResourceObject::Ptr& discoveredResource)
    {
        std::cout << "onResourceDiscovered callback :: " << std::endl;

        std::cout << "uri : " << discoveredResource->getUri() << std::endl;
        std::cout << "host address : " << discoveredResource->getAddress() << std::endl;

        g_discoveredResources.push_back(discoveredResource);

        printDiscoveryInProgress();
    };

    auto resourceType = selectResourceType();
    auto address = inputAddress();

    printDiscoveryInProgress();

    auto discoveryTask = RCSDiscoveryManager::getInstance()->discoverResourceByType(address,
            resourceType, onResourceDiscovered);

    while (processUserInput() != 1);

    discoveryTask->cancel();
}

void runResourceControl()
{
    static std::vector<MenuItem> resourceMenuItems {
        DECLARE_MENU(startMonitoring),
        DECLARE_MENU(stopMonitoring),
        DECLARE_MENU(getRemoteAttributes),
        DECLARE_MENU(setRemoteAttributes),
        DECLARE_MENU(getWithInterface),
        DECLARE_MENU(setWithInterface),
        DECLARE_MENU(startCachingWithoutCallback),
        DECLARE_MENU(startCachingWithCallback),
        DECLARE_MENU(getResourceCacheState),
        DECLARE_MENU(getCachedAttributes),
        DECLARE_MENU(getCachedAttribute),
        DECLARE_MENU(stopCaching),
    };

    handleItems(resourceMenuItems);
}

void runResourceSelection()
{
    handleItems(g_discoveredResources);

    g_currentRun = runResourceControl;
}

void runDiscovery()
{
    static std::vector<MenuItem> discoveryMenuItems {
        DECLARE_MENU(discoverResource),
    };

    handleItems(discoveryMenuItems);

    if (g_discoveredResources.empty())
    {
        throw std::runtime_error("No resource found!");
    }

    g_currentRun = runResourceSelection;
}

void configurePlatform()
{
    PlatformConfig config
    {
        OC::ServiceType::InProc, ModeType::Client, "0.0.0.0", 0, OC::QualityOfService::LowQos
    };
    OCPlatform::Configure(config);
}

int main()
{
    configurePlatform();

    g_currentRun = runDiscovery;

    while (true)
    {
        try
        {
            g_currentRun();
        }
        catch (const std::exception& e)
        {
            std::cout << e.what() << std::endl;
        }
        catch (const CloseApp&)
        {
            break;
        }
    }

    std::cout << "Stopping the client" << std::endl;

    return 0;
}
<|endoftext|>


<commit_before>/*
MIT License
Copyright (c) 2019 Arlen Keshabyan (arlen.albert@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#define BL_STATIC

#include "external/asmjit/src/asmjit/core/arch.cpp"
#include "external/asmjit/src/asmjit/core/assembler.cpp"
#include "external/asmjit/src/asmjit/core/builder.cpp"
#include "external/asmjit/src/asmjit/core/callconv.cpp"
#include "external/asmjit/src/asmjit/core/codeholder.cpp"
#include "external/asmjit/src/asmjit/core/compiler.cpp"
#include "external/asmjit/src/asmjit/core/constpool.cpp"
#include "external/asmjit/src/asmjit/core/cpuinfo.cpp"
#include "external/asmjit/src/asmjit/core/emitter.cpp"
#include "external/asmjit/src/asmjit/core/func.cpp"
#include "external/asmjit/src/asmjit/core/globals.cpp"
#include "external/asmjit/src/asmjit/core/inst.cpp"
#include "external/asmjit/src/asmjit/core/jitallocator.cpp"
#include "external/asmjit/src/asmjit/core/jitruntime.cpp"
#include "external/asmjit/src/asmjit/core/logging.cpp"
#include "external/asmjit/src/asmjit/core/operand.cpp"
#include "external/asmjit/src/asmjit/core/osutils.cpp"
#include "external/asmjit/src/asmjit/core/ralocal.cpp"
#include "external/asmjit/src/asmjit/core/rapass.cpp"
#include "external/asmjit/src/asmjit/core/rastack.cpp"
#include "external/asmjit/src/asmjit/core/string.cpp"
#include "external/asmjit/src/asmjit/core/support.cpp"
#include "external/asmjit/src/asmjit/core/target.cpp"
#include "external/asmjit/src/asmjit/core/type.cpp"
#include "external/asmjit/src/asmjit/core/virtmem.cpp"
#include "external/asmjit/src/asmjit/core/zone.cpp"
#include "external/asmjit/src/asmjit/core/zonehash.cpp"
#include "external/asmjit/src/asmjit/core/zonelist.cpp"
#include "external/asmjit/src/asmjit/core/zonestack.cpp"
#include "external/asmjit/src/asmjit/core/zonetree.cpp"
#include "external/asmjit/src/asmjit/core/zonevector.cpp"
#include "external/asmjit/src/asmjit/x86/x86assembler.cpp"
#include "external/asmjit/src/asmjit/x86/x86builder.cpp"
#include "external/asmjit/src/asmjit/x86/x86callconv.cpp"
#include "external/asmjit/src/asmjit/x86/x86compiler.cpp"
#include "external/asmjit/src/asmjit/x86/x86features.cpp"
#include "external/asmjit/src/asmjit/x86/x86instdb.cpp"
#include "external/asmjit/src/asmjit/x86/x86internal.cpp"
#include "external/asmjit/src/asmjit/x86/x86logging.cpp"
#include "external/asmjit/src/asmjit/x86/x86operand.cpp"
#include "external/asmjit/src/asmjit/x86/x86rapass.cpp"
#include "external/asmjit/src/asmjit/x86/x86ssetoavx.cpp"
#include "external/blend2d/src/blend2d/blapi-nocxx.cpp"
#include "external/blend2d/src/blend2d/blarray.cpp"
#include "external/blend2d/src/blend2d/blarrayops.cpp"
#include "external/blend2d/src/blend2d/blbitarray.cpp"
#include "external/blend2d/src/blend2d/blcompop.cpp"
#include "external/blend2d/src/blend2d/blcontext.cpp"
#include "external/blend2d/src/blend2d/blfilesystem.cpp"
#include "external/blend2d/src/blend2d/blfont.cpp"
#include "external/blend2d/src/blend2d/blformat.cpp"
#include "external/blend2d/src/blend2d/blgeometry.cpp"
#include "external/blend2d/src/blend2d/blglyphbuffer.cpp"
#include "external/blend2d/src/blend2d/blgradient.cpp"
#include "external/blend2d/src/blend2d/blgradient_avx2.cpp"
#include "external/blend2d/src/blend2d/blgradient_sse2.cpp"
#include "external/blend2d/src/blend2d/blimage.cpp"
#include "external/blend2d/src/blend2d/blimagescale.cpp"
#include "external/blend2d/src/blend2d/blmath.cpp"
#include "external/blend2d/src/blend2d/blmatrix.cpp"
#include "external/blend2d/src/blend2d/blmatrix_avx.cpp"
#include "external/blend2d/src/blend2d/blmatrix_sse2.cpp"
#include "external/blend2d/src/blend2d/blpath.cpp"
#include "external/blend2d/src/blend2d/blpathstroke.cpp"
#include "external/blend2d/src/blend2d/blpattern.cpp"
#include "external/blend2d/src/blend2d/blpipedefs.cpp"
#include "external/blend2d/src/blend2d/blpiperuntime.cpp"
#include "external/blend2d/src/blend2d/blpiperuntime_p.h"
#include "external/blend2d/src/blend2d/blpixelconverter.cpp"
#include "external/blend2d/src/blend2d/blpixelconverter_avx2.cpp"
#include "external/blend2d/src/blend2d/blpixelconverter_sse2.cpp"
#include "external/blend2d/src/blend2d/blpixelconverter_ssse3.cpp"
#include "external/blend2d/src/blend2d/blpixelops.cpp"
#include "external/blend2d/src/blend2d/blrandom.cpp"
#include "external/blend2d/src/blend2d/blregion.cpp"
#include "external/blend2d/src/blend2d/blrgba.cpp"
#include "external/blend2d/src/blend2d/blruntime.cpp"
#include "external/blend2d/src/blend2d/blstring.cpp"
#include "external/blend2d/src/blend2d/blsupport.cpp"
#include "external/blend2d/src/blend2d/bltables.cpp"
#include "external/blend2d/src/blend2d/blthreading.cpp"
#include "external/blend2d/src/blend2d/blthreadpool.cpp"
#include "external/blend2d/src/blend2d/bltrace.cpp"
#include "external/blend2d/src/blend2d/blunicode.cpp"
#include "external/blend2d/src/blend2d/blvariant.cpp"
#include "external/blend2d/src/blend2d/blzeroallocator.cpp"
#include "external/blend2d/src/blend2d/blzoneallocator.cpp"
#include "external/blend2d/src/blend2d/blzonelist.cpp"
#include "external/blend2d/src/blend2d/blzonetree.cpp"
#include "external/blend2d/src/blend2d/codec/blbmpcodec.cpp"
#include "external/blend2d/src/blend2d/codec/bldeflate.cpp"
#include "external/blend2d/src/blend2d/codec/bljpegcodec.cpp"
#include "external/blend2d/src/blend2d/codec/bljpeghuffman.cpp"
#include "external/blend2d/src/blend2d/codec/bljpegops.cpp"
#include "external/blend2d/src/blend2d/codec/bljpegops_sse2.cpp"
#include "external/blend2d/src/blend2d/codec/blpngcodec.cpp"
#include "external/blend2d/src/blend2d/codec/blpngops.cpp"
#include "external/blend2d/src/blend2d/codec/blpngops_sse2.cpp"
#include "external/blend2d/src/blend2d/fixedpipe/blfixedpiperuntime.cpp"
#include "external/blend2d/src/blend2d/fixedpipe/blfixedpiperuntime_p.h"
#include "external/blend2d/src/blend2d/opentype/blotcff.cpp"
#include "external/blend2d/src/blend2d/opentype/blotcmap.cpp"
#include "external/blend2d/src/blend2d/opentype/blotcore.cpp"
#include "external/blend2d/src/blend2d/opentype/blotface.cpp"
#include "external/blend2d/src/blend2d/opentype/blotglyf.cpp"
#include "external/blend2d/src/blend2d/opentype/blotkern.cpp"
#include "external/blend2d/src/blend2d/opentype/blotlayout.cpp"
#include "external/blend2d/src/blend2d/opentype/blotmetrics.cpp"
#include "external/blend2d/src/blend2d/opentype/blotname.cpp"
#include "external/blend2d/src/blend2d/pipegen/blcompoppart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchgradientpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchpatternpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchpixelptrpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchsolidpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchutils.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfillpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blpipecompiler.cpp"
#include "external/blend2d/src/blend2d/pipegen/blpipegencore.cpp"
#include "external/blend2d/src/blend2d/pipegen/blpipepart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blpipegenruntime.cpp"
#include "external/blend2d/src/blend2d/raster/blrastercontext.cpp"
#include "external/blend2d/src/blend2d/raster/blrasterfiller.cpp"
#include "external/blend2d/src/blend2d/raster/blrasterworker.cpp"
<commit_msg>blend2d update<commit_after>/*
MIT License
Copyright (c) 2019 Arlen Keshabyan (arlen.albert@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#define BL_STATIC

#include "external/asmjit/src/asmjit/core/arch.cpp"
#include "external/asmjit/src/asmjit/core/assembler.cpp"
#include "external/asmjit/src/asmjit/core/builder.cpp"
#include "external/asmjit/src/asmjit/core/callconv.cpp"
#include "external/asmjit/src/asmjit/core/codeholder.cpp"
#include "external/asmjit/src/asmjit/core/compiler.cpp"
#include "external/asmjit/src/asmjit/core/constpool.cpp"
#include "external/asmjit/src/asmjit/core/cpuinfo.cpp"
#include "external/asmjit/src/asmjit/core/emitter.cpp"
#include "external/asmjit/src/asmjit/core/func.cpp"
#include "external/asmjit/src/asmjit/core/globals.cpp"
#include "external/asmjit/src/asmjit/core/inst.cpp"
#include "external/asmjit/src/asmjit/core/jitallocator.cpp"
#include "external/asmjit/src/asmjit/core/jitruntime.cpp"
#include "external/asmjit/src/asmjit/core/logging.cpp"
#include "external/asmjit/src/asmjit/core/operand.cpp"
#include "external/asmjit/src/asmjit/core/osutils.cpp"
#include "external/asmjit/src/asmjit/core/ralocal.cpp"
#include "external/asmjit/src/asmjit/core/rapass.cpp"
#include "external/asmjit/src/asmjit/core/rastack.cpp"
#include "external/asmjit/src/asmjit/core/string.cpp"
#include "external/asmjit/src/asmjit/core/support.cpp"
#include "external/asmjit/src/asmjit/core/target.cpp"
#include "external/asmjit/src/asmjit/core/type.cpp"
#include "external/asmjit/src/asmjit/core/virtmem.cpp"
#include "external/asmjit/src/asmjit/core/zone.cpp"
#include "external/asmjit/src/asmjit/core/zonehash.cpp"
#include "external/asmjit/src/asmjit/core/zonelist.cpp"
#include "external/asmjit/src/asmjit/core/zonestack.cpp"
#include "external/asmjit/src/asmjit/core/zonetree.cpp"
#include "external/asmjit/src/asmjit/core/zonevector.cpp"
#include "external/asmjit/src/asmjit/x86/x86assembler.cpp"
#include "external/asmjit/src/asmjit/x86/x86builder.cpp"
#include "external/asmjit/src/asmjit/x86/x86callconv.cpp"
#include "external/asmjit/src/asmjit/x86/x86compiler.cpp"
#include "external/asmjit/src/asmjit/x86/x86features.cpp"
#include "external/asmjit/src/asmjit/x86/x86instdb.cpp"
#include "external/asmjit/src/asmjit/x86/x86internal.cpp"
#include "external/asmjit/src/asmjit/x86/x86logging.cpp"
#include "external/asmjit/src/asmjit/x86/x86operand.cpp"
#include "external/asmjit/src/asmjit/x86/x86rapass.cpp"
#include "external/blend2d/src/blend2d/blapi-nocxx.cpp"
#include "external/blend2d/src/blend2d/blarray.cpp"
#include "external/blend2d/src/blend2d/blarrayops.cpp"
#include "external/blend2d/src/blend2d/blbitarray.cpp"
#include "external/blend2d/src/blend2d/blcompop.cpp"
#include "external/blend2d/src/blend2d/blcontext.cpp"
#include "external/blend2d/src/blend2d/blfilesystem.cpp"
#include "external/blend2d/src/blend2d/blfont.cpp"
#include "external/blend2d/src/blend2d/blformat.cpp"
#include "external/blend2d/src/blend2d/blgeometry.cpp"
#include "external/blend2d/src/blend2d/blglyphbuffer.cpp"
#include "external/blend2d/src/blend2d/blgradient.cpp"
#include "external/blend2d/src/blend2d/blgradient_avx2.cpp"
#include "external/blend2d/src/blend2d/blgradient_sse2.cpp"
#include "external/blend2d/src/blend2d/blimage.cpp"
#include "external/blend2d/src/blend2d/blimagescale.cpp"
#include "external/blend2d/src/blend2d/blmath.cpp"
#include "external/blend2d/src/blend2d/blmatrix.cpp"
#include "external/blend2d/src/blend2d/blmatrix_avx.cpp"
#include "external/blend2d/src/blend2d/blmatrix_sse2.cpp"
#include "external/blend2d/src/blend2d/blpath.cpp"
#include "external/blend2d/src/blend2d/blpathstroke.cpp"
#include "external/blend2d/src/blend2d/blpattern.cpp"
#include "external/blend2d/src/blend2d/blpipedefs.cpp"
#include "external/blend2d/src/blend2d/blpiperuntime.cpp"
#include "external/blend2d/src/blend2d/blpiperuntime_p.h"
#include "external/blend2d/src/blend2d/blpixelconverter.cpp"
#include "external/blend2d/src/blend2d/blpixelconverter_avx2.cpp"
#include "external/blend2d/src/blend2d/blpixelconverter_sse2.cpp"
#include "external/blend2d/src/blend2d/blpixelconverter_ssse3.cpp"
#include "external/blend2d/src/blend2d/blpixelops.cpp"
#include "external/blend2d/src/blend2d/blrandom.cpp"
#include "external/blend2d/src/blend2d/blregion.cpp"
#include "external/blend2d/src/blend2d/blrgba.cpp"
#include "external/blend2d/src/blend2d/blruntime.cpp"
#include "external/blend2d/src/blend2d/blstring.cpp"
#include "external/blend2d/src/blend2d/blsupport.cpp"
#include "external/blend2d/src/blend2d/bltables.cpp"
#include "external/blend2d/src/blend2d/blthreading.cpp"
#include "external/blend2d/src/blend2d/blthreadpool.cpp"
#include "external/blend2d/src/blend2d/bltrace.cpp"
#include "external/blend2d/src/blend2d/blunicode.cpp"
#include "external/blend2d/src/blend2d/blvariant.cpp"
#include "external/blend2d/src/blend2d/blzeroallocator.cpp"
#include "external/blend2d/src/blend2d/blzoneallocator.cpp"
#include "external/blend2d/src/blend2d/blzonelist.cpp"
#include "external/blend2d/src/blend2d/blzonetree.cpp"
#include "external/blend2d/src/blend2d/codec/blbmpcodec.cpp"
#include "external/blend2d/src/blend2d/codec/bldeflate.cpp"
#include "external/blend2d/src/blend2d/codec/bljpegcodec.cpp"
#include "external/blend2d/src/blend2d/codec/bljpeghuffman.cpp"
#include "external/blend2d/src/blend2d/codec/bljpegops.cpp"
#include "external/blend2d/src/blend2d/codec/bljpegops_sse2.cpp"
#include "external/blend2d/src/blend2d/codec/blpngcodec.cpp"
#include "external/blend2d/src/blend2d/codec/blpngops.cpp"
#include "external/blend2d/src/blend2d/codec/blpngops_sse2.cpp"
#include "external/blend2d/src/blend2d/fixedpipe/blfixedpiperuntime.cpp"
#include "external/blend2d/src/blend2d/fixedpipe/blfixedpiperuntime_p.h"
#include "external/blend2d/src/blend2d/opentype/blotcff.cpp"
#include "external/blend2d/src/blend2d/opentype/blotcmap.cpp"
#include "external/blend2d/src/blend2d/opentype/blotcore.cpp"
#include "external/blend2d/src/blend2d/opentype/blotface.cpp"
#include "external/blend2d/src/blend2d/opentype/blotglyf.cpp"
#include "external/blend2d/src/blend2d/opentype/blotkern.cpp"
#include "external/blend2d/src/blend2d/opentype/blotlayout.cpp"
#include "external/blend2d/src/blend2d/opentype/blotmetrics.cpp"
#include "external/blend2d/src/blend2d/opentype/blotname.cpp"
#include "external/blend2d/src/blend2d/pipegen/blcompoppart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchgradientpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchpatternpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchpixelptrpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchsolidpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfetchutils.cpp"
#include "external/blend2d/src/blend2d/pipegen/blfillpart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blpipecompiler.cpp"
#include "external/blend2d/src/blend2d/pipegen/blpipegencore.cpp"
#include "external/blend2d/src/blend2d/pipegen/blpipepart.cpp"
#include "external/blend2d/src/blend2d/pipegen/blpipegenruntime.cpp"
#include "external/blend2d/src/blend2d/raster/blrastercontext.cpp"
#include "external/blend2d/src/blend2d/raster/blrasterfiller.cpp"
#include "external/blend2d/src/blend2d/raster/blrasterworker.cpp"
<|endoftext|>