📄 hxplugin.cpp
字号:
/* ***** BEGIN LICENSE BLOCK *****
* Version: RCSL 1.0/RPSL 1.0
*
* Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
*
* The contents of this file, and the files included with this file, are
* subject to the current version of the RealNetworks Public Source License
* Version 1.0 (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the RealNetworks Community Source License Version 1.0
* (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
* in which case the RCSL will apply. You may also obtain the license terms
* directly from RealNetworks. You may not use this file except in
* compliance with the RPSL or, if you have a valid RCSL with RealNetworks
* applicable to this file, the RCSL. Please see the applicable RPSL or
* RCSL for the rights, obligations and limitations governing use of the
* contents of the file.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the portions
* it created.
*
* This file, and the files included with this file, is distributed and made
* available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
#include "hxtypes.h"
#include "hxresult.h"
#include "hxassert.h"
#include "hxcom.h"
#include "hxcomm.h"
#include "hxstring.h"
#include "hxccf.h" // IHXCommonClassFactory
#include "ihxpckts.h" // IHXBuffer
#include "hxplugn.h" //IHXComponentPlugin
#include "hxformt.h" //IHXFileFormatObject
#include "hxfwrtr.h" //IHXFileWriter
#include "hxfiles.h" //IHXFileSystemObject
#include "hxrendr.h" //IHXRenderer
#include "hxdtcvt.h" //IHXDataRevert
#include "hxsdesc.h" //IHXStreamDescription
#include "hxplgns.h" //IHXPluginProperties
#include "hxmeta1.h" //IHXMetaFileFormatObject
#include "chxpckts.h" //CHXHeader
#include "hxpluginarchive.h"
#include "hxstrutl.h" //SafeStrCat
#include "dllacces.h"
#include "dllpath.h"
#include "debug.h"
#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif
#if defined(_STATICALLY_LINKED)
#include "staticff.h"
#endif
#include "hxplugindll.h"
#include "hxplugin.h"
BEGIN_INTERFACE_LIST_NOCREATE(HXPlugin)
END_INTERFACE_LIST
const char* const k_pszValueSeperator = "|";
HXPlugin::HXPlugin(IUnknown* pContext)
: m_pValues(0)
, m_pDll(0)
, m_pContext(pContext)
, m_idxPlugin(0)
, m_pClassFactory(NULL)
{
HX_ASSERT(m_pContext);
m_pContext->AddRef();
m_pContext->QueryInterface(IID_IHXCommonClassFactory, (void**)&m_pClassFactory);
HX_ASSERT(m_pClassFactory);
m_pClassFactory->CreateInstance(CLSID_IHXValues,(void**)&m_pValues);
}
// deserializing constructor
HXPlugin::HXPlugin(IUnknown* pContext, HXPluginArchiveReader& ar)
: m_pValues(0)
, m_pDll(0)
, m_pContext(pContext)
, m_idxPlugin(0)
, m_pClassFactory(NULL)
{
m_pContext->AddRef();
m_pContext->QueryInterface(IID_IHXCommonClassFactory, (void**)&m_pClassFactory);
ar.Read(m_pValues);
}
// serialize object
void HXPlugin::Archive(HXPluginArchiveWriter& ar)
{
ar.Write(m_pValues);
}
HXPlugin::~HXPlugin()
{
HX_RELEASE(m_pValues);
//HX_RELEASE(m_pDll); weak ref
HX_RELEASE(m_pClassFactory);
HX_RELEASE(m_pContext);
}
void HXPlugin::SetPluginProperty(const char* pszPluginType)
{
DPRINTF(D_INFO, ("HXPlugin()::SetPluginProperty(): type = %s\n", pszPluginType));
IHXBuffer* pBuffer = NULL;
m_pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pBuffer);
HX_ASSERT(pBuffer);
pBuffer->Set((UCHAR*)pszPluginType, strlen(pszPluginType)+1);
m_pValues->SetPropertyCString(PLUGIN_CLASS, pBuffer);
pBuffer->Release();
}
BOOL HXPlugin::DoesMatch(IHXValues* pValues)
{
CHXSimpleList PossibleValues1;
CHXSimpleList PossibleValues2;
const char* pPropName = NULL;
ULONG32 nInValue;
ULONG32 nOutValue;
IHXBuffer* pInBuffer = NULL;
IHXBuffer* pOutBuffer = NULL;
// Check ULONGS 1st
if (HXR_OK == pValues->GetFirstPropertyULONG32(pPropName, nInValue))
{
if (HXR_OK==m_pValues->GetPropertyULONG32(pPropName, nOutValue))
{
if (nInValue != nOutValue)
{
goto notFoundexit;
}
}
else
{
goto notFoundexit;
}
while (HXR_OK == pValues->GetNextPropertyULONG32(pPropName, nInValue))
{
if (HXR_OK == m_pValues->GetPropertyULONG32(pPropName, nOutValue))
{
if (nInValue != nOutValue)
{
goto notFoundexit;
}
}
else
{
goto notFoundexit;
}
}
}
// Check String Props.
if (HXR_OK == pValues->GetFirstPropertyCString(pPropName, pInBuffer))
{
if (HXR_OK == m_pValues->GetPropertyCString(pPropName, pOutBuffer))
{
if (!AreBufferEqual(pOutBuffer, pInBuffer))
{
goto notFoundexit;
}
}
else
{
goto notFoundexit;
}
HX_RELEASE(pInBuffer);
HX_RELEASE(pOutBuffer);
while (HXR_OK == pValues->GetNextPropertyCString(pPropName, pInBuffer))
{
if (HXR_OK == m_pValues->GetPropertyCString(pPropName, pOutBuffer))
{
if ( !AreBufferEqual(pOutBuffer, pInBuffer))
{
goto notFoundexit;
}
}
else
{
goto notFoundexit;
}
HX_RELEASE(pInBuffer);
HX_RELEASE(pOutBuffer);
}
}
// Check Buffer Properties
if (HXR_OK == pValues->GetFirstPropertyBuffer(pPropName, pInBuffer))
{
// XXXND Make some utility functions for doing this...
if (HXR_OK == m_pValues->GetPropertyBuffer(pPropName, pOutBuffer))
{
if( pOutBuffer->GetSize() == pInBuffer->GetSize() )
{
if( ::memcmp( pOutBuffer->GetBuffer(), pInBuffer->GetBuffer(), pOutBuffer->GetSize() ) )
{
goto notFoundexit;
}
}
}
else
{
goto notFoundexit;
}
HX_RELEASE(pInBuffer);
HX_RELEASE(pOutBuffer);
while (HXR_OK == pValues->GetNextPropertyBuffer(pPropName, pInBuffer))
{
if (HXR_OK == m_pValues->GetPropertyBuffer(pPropName, pOutBuffer))
{
// XXXND Make some utility functions for doing this...
if( pOutBuffer->GetSize() == pInBuffer->GetSize() )
{
if( ::memcmp( pOutBuffer->GetBuffer(), pInBuffer->GetBuffer(), pOutBuffer->GetSize() ) )
{
goto notFoundexit;
}
}
}
else
{
goto notFoundexit;
}
HX_RELEASE(pInBuffer);
HX_RELEASE(pOutBuffer);
}
}
return TRUE; // we made it!
notFoundexit:
HX_RELEASE(pInBuffer);
HX_RELEASE(pOutBuffer);
return FALSE;
}
HX_RESULT HXPlugin::Init(HXPluginDLL* pDll, UINT16 idxPlugin)
{
HX_ASSERT(!m_pDll);
HX_ASSERT(pDll);
m_pDll = pDll; // weak ref
m_idxPlugin = idxPlugin;
m_pValues->SetPropertyULONG32(PLUGIN_INDEX, idxPlugin);
IHXBuffer* pBuff = HXBufferUtil::CreateBuffer(m_pClassFactory, m_pDll->GetFileName());
m_pValues->SetPropertyCString(PLUGIN_FILENAME, pBuff);
HX_RELEASE(pBuff);
return HXR_OK;
}
BOOL HXPlugin::AreBufferEqual(IHXBuffer* pBigBuff,
IHXBuffer* pSmallBuff)
{
char* pTemp;
BOOL bRetVal = FALSE;
pTemp = new char[pBigBuff->GetSize()];
strcpy(pTemp, (char*)pBigBuff->GetBuffer()); /* Flawfinder: ignore */
char* token;
token = strtok(pTemp, k_pszValueSeperator);
while (token)
{
CHXString tokenCHXstring;
CHXString smallCHXstring;
tokenCHXstring = token;
smallCHXstring = (char*)pSmallBuff->GetBuffer();
tokenCHXstring.TrimLeft();
tokenCHXstring.TrimRight();
smallCHXstring.TrimLeft();
smallCHXstring.TrimRight();
if (!strcasecmp(tokenCHXstring, smallCHXstring))
{
bRetVal = TRUE;
break;
}
token = strtok(NULL, k_pszValueSeperator);
}
delete[] pTemp;
return bRetVal;
}
HX_RESULT HXPlugin::GetValuesFromDLL(IHXPlugin* pHXPlugin)
{
HX_RESULT hr = GetBasicValues(pHXPlugin);
if(SUCCEEDED(hr))
{
hr = GetExtendedValues(pHXPlugin);
}
return hr;
}
HX_RESULT HXPlugin::GetPlugin(IUnknown*& pUnknown )
{
pUnknown = NULL;
HX_RESULT hr = HXR_FAIL;
HX_ASSERT(m_pDll);
if (m_pDll)
{
// load DLL if not loaded
if (!m_pDll->IsLoaded())
{
hr = m_pDll->Load();
}
if(m_pDll->IsLoaded())
{
hr = m_pDll->CreateInstance(&pUnknown, m_idxPlugin);
}
}
return hr;
}
HX_RESULT HXPlugin::GetInstance(IUnknown*& pUnknown, IUnknown* pIUnkOuter )
{
// Initialize out parameter
pUnknown = NULL;
IUnknown* pUnkPlugin = NULL;
HX_RESULT hr = GetPlugin( pUnkPlugin );
if( SUCCEEDED(hr) )
{
hr = HXR_FAIL;
IHXComponentPlugin* pComponentPlugin = NULL;
if( SUCCEEDED( pUnkPlugin->QueryInterface( IID_IHXComponentPlugin, (void**) &pComponentPlugin ) ) )
{
// Ask for the correct object by CLSID
IHXBuffer* pCLSID = NULL;
if( SUCCEEDED( m_pValues->GetPropertyBuffer( PLUGIN_COMPONENT_CLSID, pCLSID ) ) )
{
hr = pComponentPlugin->CreateComponentInstance( *(GUID*) pCLSID->GetBuffer(), pUnknown, pIUnkOuter );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -