hxcommn.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:15k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "hxtypes.h"
  36. #include "hxcom.h"
  37. #include "hxresult.h"
  38. #include "hxstrutl.h"
  39. #include "hxstring.h"
  40. #include "hxcomm.h"
  41. #include "ihxpckts.h"
  42. #include "hxfiles.h"
  43. #include "hxcore.h"
  44. #include "hxmon.h"
  45. #include "hxplugn.h"
  46. #include "hxvalue.h"
  47. #include "hxcache.h"
  48. #include "hxtbuf.h"
  49. #include "cachobj.h"
  50. #include "smartptr.h"
  51. #include "miscsp.h"
  52. #include "unkimp.h"
  53. //#include "rncont.h"
  54. #include "hxlist.h"
  55. //#include "rnmap.h"
  56. #include "chxfgbuf.h"
  57. #include "chxpckts.h"
  58. #include "watchlst.h"
  59. #include "hxclreg.h"
  60. #include "hxrquest.h"
  61. #include "hxvalues.h"
  62. #if defined(_WINDOWS) && !defined(_WINCE)
  63. #ifdef _WIN32
  64. #include <vfw.h>
  65. #else
  66. #include <windows.h>
  67. #include <drawdib.h>
  68. #endif /* _WIN32 */
  69. #endif /* _WINDOWS */
  70. // Needed for CHXSiteWindowed
  71. #include "hxwintyp.h"
  72. #include "chxxtype.h"
  73. #include "hxwin.h"
  74. #include "hxengin.h"
  75. #include "hxsite2.h"
  76. #include "hxslist.h"
  77. //#include "hxcodec.h"
  78. #include "hxvsurf.h"
  79. #include "hxvctrl.h"
  80. #include "dllacces.h"
  81. #include "dllaccesserver.h"
  82. #include "dllpath.h"
  83. #if defined(HELIX_FEATURE_FILESYSTEMMGR)
  84. #include "hxfsmgr.h"
  85. #endif
  86. #include "hxmisus.h"
  87. //#include "rmafsmgr.h"
  88. #include "hxcommn.h"
  89. //#include "plgnhand.h"
  90. #include "plghand2.h"
  91. #include "hxplugn.h"
  92. #include "hxgrpen2.h"
  93. #include "chxuuid.h"
  94. //#include "rmargn.h"
  95. //#include "hxausvc.h"
  96. #include "hxmutex.h"
  97. #include "chxminiccf.h"
  98. #include "hxheap.h"
  99. #ifdef _DEBUG
  100. #undef HX_THIS_FILE
  101. static const char HX_THIS_FILE[] = __FILE__;
  102. #endif
  103. HXCommonClassFactory::HXCommonClassFactory(IUnknown* pContext) :
  104.      m_lRefCount (0)
  105.     ,m_pContext(pContext)
  106.     ,m_pMiniCCF(new CHXMiniCCF())
  107. {
  108.     if (m_pContext)
  109.     {
  110. m_pContext->AddRef();
  111.     }
  112.     if (m_pMiniCCF)
  113.     {
  114. m_pMiniCCF->AddRef();
  115.     }
  116. }
  117. HXCommonClassFactory::~HXCommonClassFactory()
  118.     Close();
  119. }
  120. void
  121. HXCommonClassFactory::Close()
  122.     HX_RELEASE(m_pContext);
  123.     HX_RELEASE(m_pMiniCCF);
  124. }
  125. /*
  126.  * IUnknown methods
  127.  */
  128. /////////////////////////////////////////////////////////////////////////
  129. // Method:
  130. // IUnknown::QueryInterface
  131. // Purpose:
  132. // Implement this to export the interfaces supported by your 
  133. // object.
  134. //
  135. STDMETHODIMP HXCommonClassFactory::QueryInterface(REFIID riid, void** ppvObj)
  136. {
  137.     QInterfaceList qiList[] =
  138.         {
  139.             { GET_IIDHANDLE(IID_IHXCommonClassFactory), (IHXCommonClassFactory*)this },
  140.             { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXCommonClassFactory*)this },
  141.         };
  142.     
  143.     return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  144. }
  145. /////////////////////////////////////////////////////////////////////////
  146. // Method:
  147. // IUnknown::AddRef
  148. // Purpose:
  149. // Everyone usually implements this the same... feel free to use
  150. // this implementation.
  151. //
  152. STDMETHODIMP_(ULONG32) HXCommonClassFactory::AddRef()
  153. {
  154.     return InterlockedIncrement(&m_lRefCount);
  155. }
  156. /////////////////////////////////////////////////////////////////////////
  157. // Method:
  158. // IUnknown::Release
  159. // Purpose:
  160. // Everyone usually implements this the same... feel free to use
  161. // this implementation.
  162. //
  163. STDMETHODIMP_(ULONG32) HXCommonClassFactory::Release()
  164. {
  165.     if (InterlockedDecrement(&m_lRefCount) > 0)
  166.     {
  167. return m_lRefCount;
  168.     }
  169.     delete this;
  170.     return 0;
  171. }
  172. /************************************************************************
  173.  * Method:
  174.  * IHXController::CreateInstance
  175.  * Purpose:
  176.  * Creates instances of common objects supported by the system,
  177.  * like IHXBuffer, IHXPacket, IHXValues, etc.
  178.  *
  179.  * This method is similar to Window's CoCreateInstance() in its 
  180.  * purpose, except that it only creates objects of a well known
  181.  * types.
  182.  *
  183.  * NOTE: Aggregation is never used. Therefore and outer unknown is
  184.  * not passed to this function, and you do not need to code for this
  185.  * situation.
  186.  */
  187. STDMETHODIMP HXCommonClassFactory::CreateInstance
  188. (
  189.     REFCLSID /*IN*/ rclsid,
  190.     void** /*OUT*/ ppUnknown
  191. )
  192. {
  193.     if (m_pMiniCCF)
  194.     {
  195. HX_RESULT res = m_pMiniCCF->CreateInstance(rclsid, ppUnknown);
  196. if (HXR_NOINTERFACE != res)
  197. {
  198.     return res;
  199. }
  200.     }
  201.     if (IsEqualCLSID(rclsid, CLSID_IHXPacket))
  202.     {
  203. *ppUnknown = (IUnknown*)(IHXPacket*)(new CHXPacket());
  204.         if( !*ppUnknown )
  205.         {
  206.             return HXR_OUTOFMEMORY;
  207.         }
  208. ((IUnknown*)*ppUnknown)->AddRef();
  209. return HXR_OK;
  210.     }
  211.     else if (IsEqualCLSID(rclsid, CLSID_IHXRTPPacket))
  212.     {
  213. *ppUnknown = (IUnknown*)(IHXRTPPacket*)(new CHXRTPPacket());
  214.         if( !*ppUnknown )
  215.         {
  216.             return HXR_OUTOFMEMORY;
  217.         }
  218. ((IUnknown*)*ppUnknown)->AddRef();
  219. return HXR_OK;
  220.     }
  221.     else if(IsEqualCLSID(rclsid, CLSID_IHXRequest))
  222.     {
  223. *ppUnknown = (IUnknown*)(IHXRequest*)(new CHXRequest());
  224.         if( !*ppUnknown )
  225.         {
  226.             return HXR_OUTOFMEMORY;
  227.         }
  228. ((IUnknown*)*ppUnknown)->AddRef();
  229. return HXR_OK;
  230.     }
  231. #if defined(HELIX_FEATURE_FIFOCACHE)
  232.     else if(IsEqualCLSID(rclsid, CLSID_IHXFIFOCache))
  233.     {
  234. *ppUnknown = (IUnknown*)(IHXFIFOCache*)(new HXFIFOCache());
  235.         if( !*ppUnknown )
  236.         {
  237.             return HXR_OUTOFMEMORY;
  238.         }
  239. ((IUnknown*)*ppUnknown)->AddRef();
  240. return HXR_OK;
  241.     }
  242. #endif /* HELIX_FEATURE_FIFOCACHE */
  243. #if defined(HELIX_FEATURE_REGION)
  244. #ifdef _WIN32
  245.     else if(IsEqualCLSID(rclsid, CLSID_IHXRegion))
  246.     {
  247. HXRegion *pRegion = new HXRegion();
  248.         if( !pRegion )
  249.         {
  250.             return HXR_OUTOFMEMORY;
  251.         }
  252. return pRegion->QueryInterface(IID_IUnknown, (void**) ppUnknown);
  253.     }
  254. #endif
  255. #endif /* HELIX_FEATURE_REGION */
  256. #if defined(HELIX_FEATURE_FRAGMENTBUFFER)
  257.     else if (IsEqualCLSID(rclsid, CLSID_IHXFragmentedBuffer))
  258.     {
  259. return CHXFragmentedBuffer::CreateInstance((IUnknown**)ppUnknown);
  260.     }
  261. #endif /* HELIX_FEATURE_FRAGMENTBUFFER */
  262.     else if(IsEqualCLSID(rclsid, CLSID_IHXKeyValueList))
  263.     {
  264. *ppUnknown = (IUnknown*)(IHXKeyValueList*)(new CKeyValueList());
  265.         if( !*ppUnknown )
  266.         {
  267.             return HXR_OUTOFMEMORY;
  268.         }
  269. ((IUnknown*)*ppUnknown)->AddRef();
  270. return HXR_OK;
  271.     }
  272. #if defined(HELIX_FEATURE_FILESYSTEMMGR)
  273.     else if (IsEqualCLSID(rclsid, CLSID_IHXFileSystemManager))
  274.     {
  275. *ppUnknown = (IUnknown*)(IHXFileSystemManager*)(new HXFileSystemManager(m_pContext));
  276.         if( !*ppUnknown )
  277.         {
  278.             return HXR_OUTOFMEMORY;
  279.         }
  280. ((IUnknown*)*ppUnknown)->AddRef();
  281. return HXR_OK;
  282.     }
  283. #endif /* HELIX_FEATURE_FILESYSTEMMGR */
  284.     else if (IsEqualCLSID(rclsid, CLSID_IHXMutex))
  285.     {
  286.         CHXMutex *pMutex = new CHXMutex();
  287.         if (pMutex)
  288.         {
  289.             return pMutex->QueryInterface(IID_IUnknown, (void**) ppUnknown);
  290.         }
  291.     }
  292. // Unix now implements this as a factory plugin.  Windows and Mac may
  293. // do so someday too.
  294. #if (defined (_WINDOWS) || defined (_MACINTOSH)) && !defined(_WINCE)
  295.     else if(IsEqualCLSID(rclsid, CLSID_IHXSiteWindowed))
  296.     {
  297. {
  298.     IHXPreferences* pPreferences = NULL;
  299.     IHXBuffer* pBuffer = NULL;
  300.     BOOL bUseNewSite = TRUE;
  301.     if (HXR_OK == m_pContext->QueryInterface(IID_IHXPreferences,(void**)&pPreferences))
  302.     {   
  303. if (pPreferences->ReadPref("UseHXVideo", pBuffer) == HXR_OK)
  304. {
  305.     bUseNewSite = (::atoi((char*) pBuffer->GetBuffer()) == 1);
  306.     HX_RELEASE(pBuffer);
  307. }
  308. HX_RELEASE(pPreferences);
  309.     }
  310.     if (bUseNewSite)
  311.     {
  312. goto classFactory;
  313.     }
  314. }
  315. #ifdef _WIN32
  316.         // Can not use the plugin handler to create the 
  317.         // site, since it uses the same class ID as 
  318.         // pnvideo, and the plugin handler gets REALLY
  319.         // confused.
  320.         // futher we can not use DLL access, since we WANT to keep
  321.         // a reference on the DLL object created.
  322.         UINT32 uDLLNameLen = 256;
  323.         char    szDllName[256]; /* Flawfinder: ignore */
  324.         DLLAccess::CreateName("pnol", "pnoldvideo", szDllName, uDLLNameLen);
  325.         const char* pPath = NULL;
  326.         CHXString fileName;
  327.         pPath = GetDLLAccessPath()->GetPath(DLLTYPE_PLUGIN);
  328.         fileName = pPath;
  329.         fileName += "\";
  330.         fileName += szDllName;
  331.         HINSTANCE hinst = LoadLibrary(fileName);
  332.         FPCREATEINSTANCE fpCreateInstance = (FPCREATEINSTANCE) GetProcAddress(hinst, HXCREATEINSTANCESTR);
  333.         *ppUnknown = 0;
  334.         if (fpCreateInstance)
  335.         {
  336.             fpCreateInstance((IUnknown**) ppUnknown);
  337.             IHXPlugin* pPlug = NULL;
  338.             if (HXR_OK == (*(IUnknown**)ppUnknown)->QueryInterface(IID_IHXPlugin, (void**)&pPlug))
  339.             {
  340.                 pPlug->InitPlugin(m_pContext);
  341.                 HX_RELEASE(*(IUnknown**)ppUnknown);
  342.                 fpCreateInstance((IUnknown**) ppUnknown);
  343.             }
  344.             return HXR_OK;
  345.         }
  346.         return HXR_FAIL;
  347.     }
  348. #endif
  349. #ifdef _MACINTOSH
  350.     goto classFactory;
  351. /*
  352.     {
  353.     *ppUnknown = (IUnknown*)(IHXSiteWindowed*)(new CHXSiteWindowed(m_pContext));
  354. }
  355. return ((IUnknown*)*ppUnknown)->QueryInterface(IID_IHXSiteWindowed,
  356. (void**)ppUnknown);
  357. */
  358.     }
  359. #endif
  360. #endif
  361. #if defined(HELIX_FEATURE_VIDEO) && defined (HELIX_FEATURE_MISU)
  362.     else if(IsEqualCLSID(rclsid, CLSID_IHXMultiInstanceSiteUserSupplier))
  363.     {
  364. *ppUnknown = (IUnknown*)(IHXMultiInstanceSiteUserSupplier*)(new CHXMultiInstanceSiteUserSupplier());
  365.         if( !*ppUnknown )
  366.         {
  367.             return HXR_OUTOFMEMORY;
  368.         }
  369. return ((IUnknown*)*ppUnknown)->
  370.     QueryInterface(IID_IHXMultiInstanceSiteUserSupplier,
  371. (void**)ppUnknown);
  372.     }
  373. #endif /* HELIX_FEATURE_VIDEO */
  374. #if !defined(_STATICALLY_LINKED)
  375.     else if(IsEqualCLSID(rclsid, CLSID_IHXPluginGroupEnumerator))
  376.     {
  377. IHXPlugin2Handler* pPlugin2Handler = NULL;
  378. m_pContext->QueryInterface
  379. (
  380.     IID_IHXPlugin2Handler,
  381.     (void**)&pPlugin2Handler
  382. );
  383. *ppUnknown = (IUnknown*)(IHXPluginGroupEnumerator*)
  384. (
  385.     new CHXPlugin2GroupEnumerator(pPlugin2Handler)
  386. );
  387.         if( !*ppUnknown )
  388.         {
  389.             return HXR_OUTOFMEMORY;
  390.         }
  391. HX_RELEASE(pPlugin2Handler);
  392. return ((IUnknown*)*ppUnknown)->QueryInterface
  393. (
  394.     IID_IHXPluginGroupEnumerator,
  395.     (void**)ppUnknown
  396. );
  397.     }
  398. #endif /* _STATICALLY_LINKED */
  399. #if defined(HELIX_FEATURE_DLLACCESS_SERVER)
  400.     else if (IsEqualCLSID(rclsid, CLSID_IHXDllAccess))
  401.     {
  402. *ppUnknown = (IUnknown*)(IHXDllAccess*)(new DLLAccessServer);
  403. if (*ppUnknown)
  404. {
  405.     ((IUnknown*)*ppUnknown)->AddRef();
  406.     return HXR_OK;
  407. }
  408. return HXR_OUTOFMEMORY;
  409.     }
  410. #endif // HELIX_FEATURE_DLLACCESS_SERVER
  411.     else
  412.     {
  413. classFactory:
  414. // Try the factory plugins
  415. IHXPlugin2Handler* pPlugin2Handler = NULL;
  416. m_pContext->QueryInterface
  417. (
  418.     IID_IHXPlugin2Handler,
  419.     (void**)&pPlugin2Handler
  420. );
  421. *ppUnknown = NULL;
  422. IUnknown* pIUnknownInstance = NULL;
  423. if(pPlugin2Handler)
  424. {
  425.     if 
  426.     (
  427. SUCCEEDED
  428. (
  429.     pPlugin2Handler->FindImplementationFromClassID
  430.     (
  431. rclsid, 
  432. pIUnknownInstance
  433.     )
  434. )
  435.     )
  436.     {
  437. *ppUnknown = pIUnknownInstance;
  438. HX_RELEASE(pPlugin2Handler);
  439. return HXR_OK;
  440.     }
  441. }
  442. #if defined(HELIX_FEATURE_PLUGINHANDLER1)
  443. else
  444. {   // The encoder still uses the old PluginHandler..
  445.     // Try the factory plugins
  446.     PluginHandler* pPluginHandler = NULL;
  447.     m_pContext->QueryInterface
  448.     (
  449. IID_IHXPluginHandler,
  450. (void**)&pPluginHandler
  451.     );
  452.     *ppUnknown = NULL;
  453.     if(pPluginHandler)
  454.     {
  455. PluginHandler::Factory* pFactories;
  456. PluginHandler::Plugin*  pPlugin;
  457. CHXSimpleList::Iterator i;
  458. pFactories = pPluginHandler->m_factory_handler;
  459. for(i = pFactories->m_pPlugins->Begin();
  460.     i != pFactories->m_pPlugins->End();
  461.     ++i)
  462. {
  463.     IUnknown* pInstance = 0;
  464.     pPlugin = (PluginHandler::Plugin*)(*i);
  465.     pPlugin->GetInstance(&pInstance);
  466.     if(pInstance)
  467.     {
  468. HX_RESULT res;
  469. IHXPlugin* pFPlugin = 0;
  470. res = pInstance->QueryInterface(IID_IHXPlugin,
  471. (void**)&pFPlugin);
  472. if(res == HXR_OK)
  473. {
  474.     IHXCommonClassFactory* pClassFactory;
  475.     pFPlugin->InitPlugin(m_pContext);
  476.     pFPlugin->Release();
  477.     res = pInstance->QueryInterface(
  478. IID_IHXCommonClassFactory,
  479. (void**)&pClassFactory);
  480.     if(HXR_OK == res)
  481.     {
  482. res = pClassFactory->CreateInstance(rclsid,
  483.    ppUnknown);
  484. if(HXR_OK != res)
  485.     *ppUnknown = NULL;
  486. pClassFactory->Release();
  487.     }
  488. }
  489. pInstance->Release();
  490. pPlugin->ReleaseInstance();
  491. if(*ppUnknown)
  492. {
  493.     return HXR_OK;
  494. }
  495.     }
  496. }
  497.     }
  498.     HX_RELEASE(pPluginHandler);
  499. }
  500. #endif /* HELIX_FEATURE_PLUGINHANDLER1 */
  501. HX_RELEASE(pPlugin2Handler);
  502.     }
  503.  
  504.     *ppUnknown = NULL;
  505.     return HXR_NOINTERFACE;
  506. }
  507. /************************************************************************
  508.  *  Method:
  509.  * IHXController::CreateInstanceAggregatable
  510.  *  Purpose:
  511.  * Creates instances of common objects supported by the system,
  512.  * like IHXBuffer, IHXPacket, IHXValues, etc.
  513.  *
  514.  * This method is similar to Window's CoCreateInstance() in its 
  515.  * purpose, except that it only creates objects of a well known
  516.  * types.
  517.  *
  518.  * NOTE 1: Unlike CreateInstance, this method will create internal
  519.  * objects that support Aggregation.
  520.  *
  521.  * NOTE 2: The output interface is always the non-delegating 
  522.  * IUnknown.
  523.  */
  524. STDMETHODIMP HXCommonClassFactory::CreateInstanceAggregatable
  525. (
  526.     REFCLSID     /*IN*/ rclsid,
  527.     REF(IUnknown*)  /*OUT*/ pUnknown,
  528.     IUnknown*     /*IN*/ pUnkOuter
  529. )
  530. {
  531.     pUnknown = NULL;
  532.     return HXR_NOINTERFACE;
  533. }