chxclientenginemanager.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:7k
源码类别:
Symbian
开发平台:
Visual C++
- /*============================================================================*
- *
- * (c) 1995-2002 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- *============================================================================*/
- #include "hxassert.h"
- #include "hxtypes.h"
- #include "hxcom.h"
- #include "hxcomm.h"
- #include "hxcore.h"
- #include "dllacces.h"
- #include "dllpath.h"
- #include "hxengin.h"
- #include "hxcore.h"
- #include "....symbianplayer.ver"
- #include "chxavconfignames.h"
- #include "comptr_traits.h"
- #include "chxavfileutil.h"
- #include "chxavcleanstring.h"
- #include "chxavcleanupstack.h"
- #include "chxavmisc.h"
- #include "hxsym_leaveutil.h"
- #include "hxsym_debug.h"
- #include "hxapihelp.h"
- #include "chxclientenginemanager.h"
- struct GlobalData
- {
- DLLAccessPath accessPath;
- };
- GlobalData*& GetGlobal()
- {
- #if defined(HELIX_CONFIG_NOSTATICS)
- static const int key = 0; // address of static var (we hope) comprises unique key id
- GlobalData*& g_pGlobalData = (GlobalData*&)HXGlobalPtr::Get(&key);
- #else
- static GlobalData* g_pGlobalData = NULL;
- #endif
- if(!g_pGlobalData)
- {
- g_pGlobalData = new GlobalData();
- }
- return g_pGlobalData;
- }
- // required for class DLLAccess
- DLLAccessPath* GetDLLAccessPath()
- {
- return &(GetGlobal()->accessPath);
- }
- ///////////////////////////////////
- // ctor
- CHXClientEngineManager::CHXClientEngineManager()
- : m_fpCreateEngine(0)
- , m_fpCloseEngine(0)
- , m_fpSetDLLAccessPath(0)
- , m_pDllAccess(0)
- {
- }
- ///////////////////////////////////
- // dtor
- CHXClientEngineManager::~CHXClientEngineManager()
- {
- if(m_fpCloseEngine)
- {
- HX_ASSERT(m_clientEngine);
- m_fpCloseEngine(m_clientEngine);
- m_clientEngine = 0;
- }
- m_prefs = 0;
- m_factory = 0;
- //
- // We are unloading the client core dll. All interfaces to objects
- // implemented in the client core dll *must* be released by now.
- //
- if (m_pDllAccess )
- {
- m_pDllAccess->close();
- HX_DELETE(m_pDllAccess);
- }
- GlobalData* pGlobal = GetGlobal();
- delete pGlobal;
- m_fpCloseEngine = 0;
- m_fpCreateEngine = 0;
- m_fpSetDLLAccessPath = 0;
- }
- // ConstructL helper
- void CHXClientEngineManager::LoadClientCoreL()
- {
- // this must be hardcoded (relative to player app folder)
- _LIT(KClientCoreLib, "lib\clntcore.dll");
- // get full path to client core dll
- TFileName* pFullPathClientCore = CHXAvFile::AllocAppFolderPathL(KClientCoreLib);
- AUTO_PUSH_POP_DEL(pFullPathClientCore);
- CHXString strLibPath = CHXAvStringUtils::DescToString(*pFullPathClientCore);
- // open the dll
- m_pDllAccess = new (ELeave) DLLAccess();
- int res = m_pDllAccess->open(strLibPath);
- if (DLLAccess::OUT_OF_MEMORY == res)
- {
- HXSYM_LEAVE(KErrNoMemory);
- }
- else if (DLLAccess::DLL_OK != res)
- {
- HXSYM_LEAVE(KErrGeneral);
- }
- // get the functions from the dll
- m_fpCreateEngine = (FPRMCREATEENGINE) m_pDllAccess->getSymbol("CreateEngine");
- m_fpCloseEngine = (FPRMCLOSEENGINE) m_pDllAccess->getSymbol("CloseEngine");
- m_fpSetDLLAccessPath = (FPRMSETDLLACCESSPATH) m_pDllAccess->getSymbol("SetDLLAccessPath");
- HXSYM_LEAVE_IF_FALSE(m_fpCreateEngine != 0);
- HXSYM_LEAVE_IF_FALSE(m_fpCloseEngine != 0);
- HXSYM_LEAVE_IF_FALSE(m_fpSetDLLAccessPath != 0);
- }
- namespace
- {
- void AddAccessPath(CHXString& str, const CHXString& lhs, const CHXString& rhs)
- {
- CHXString strAdd(lhs);
- strAdd += "=";
- strAdd += rhs;
- // append key-val pair followed by terminator
- str += strAdd;
- str += 'n';
- }
- }
- ////////////////////////////////
- // ConstructL helper
- void CHXClientEngineManager::InitLibSearchPathL()
- {
- // get full path to location for player dlls (plugin, codecs, etc.)
- TFileName* pFullPathLibRoot = CHXAvFile::AllocFullPrefPathL(m_prefs, CHXAV_PlayerLibPath);
- HXSYM_LEAVE_IF_FALSE(pFullPathLibRoot != 0);
- AUTO_PUSH_POP_DEL(pFullPathLibRoot);
- CHXString strFullLibRoot = CHXAvStringUtils::DescToString(*pFullPathLibRoot);
- // set dll search path
- CHXString strAccessPath;
- AddAccessPath(strAccessPath, "DT_Common", strFullLibRoot);
- AddAccessPath(strAccessPath, "DT_Plugins", strFullLibRoot);
- AddAccessPath(strAccessPath, "DT_Codecs", strFullLibRoot);
- strAccessPath += 'n';
- // replace newlines with null-terminators
- for(TInt idx = 0; idx < strAccessPath.GetLength(); ++idx)
- {
- if(strAccessPath[idx] == 'n')
- {
- strAccessPath.SetAt(idx, ' ');
- }
- }
- m_fpSetDLLAccessPath(strAccessPath);
- }
- void CHXClientEngineManager::ConstructL()
- {
- // load engine dll
- LoadClientCoreL();
- // create the engine; note: this function does not add-ref returned com pointer for us (so we do it ourselves)!
- IHXClientEngine* pEngine = 0;
- m_fpCreateEngine(&pEngine);
- m_clientEngine = pEngine;
- HXSYM_LEAVE_IF_FALSE(m_clientEngine != 0);
- // get the factory from the engine
- m_factory.From(m_clientEngine);
- // create prefs to override core default (see below)
- CreatePrefsL();
- // this is earliest we can set up log sink and mask to proper values (from registry)
- dbg::SetupDebug(m_prefs);
- DPRINTF(SYMP_INFO, ("CHXClientEngineManager()::ConstructL(): just initialized debug maskn"));
- // configure paths (based on preferences) for finding libraries
- InitLibSearchPathL();
- // ensure 'PluginArchiveFileName' path is set
- CHXString strArchiveFileName = prefs::GetString(m_prefs, CHXAV_PluginArchiveFileName);
- if( strArchiveFileName.IsEmpty() )
- {
- // we need to set this so plugin manager can use it to write plugin state information
- TFileName* pFullPath = CHXAvFile::AllocAppFolderPathL(CHXAvUtil::KPlayerDataFolder);
- AUTO_PUSH_POP_DEL(pFullPath);
- CHXAvFile::AppendPath(*pFullPath, KPluginArchiveName, CHXAvFile::ntFile);
- strArchiveFileName = CHXAvStringUtils::DescToString(*pFullPath);
- prefs::Write(m_factory, m_prefs, CHXAV_PluginArchiveFileName, strArchiveFileName);
- }
- //
- // initialize the client core; engine will look for interfaces that override its
- // default implementation, including
- //
- // preferences
- // hypernavigate
- //
- // then it will load plugins
- //
- comptr<IHXClientEngineSetup> clientEngineSetup;
- clientEngineSetup.From(m_clientEngine);
- clientEngineSetup->Setup(static_cast<IHXPreferences*>(m_prefs)); // arbitrary unknown
- }
- //
- //
- //
- void CHXClientEngineManager::CreatePrefsL()
- {
- HX_ASSERT(m_factory);
- TFileName* pFullPathConfig = CHXAvFile::AllocAppFolderPathL(CHXAvUtil::KPlayerDataFolder);
- AUTO_PUSH_POP_DEL(pFullPathConfig);
- CHXString strConfigPath = CHXAvStringUtils::DescToString(*pFullPathConfig);
- m_prefs = new (ELeave) CHXLitePrefs(strConfigPath);
- m_prefs->SetContext(m_factory);
- CHXAvCleanString productName(R_AVP_PRODUCT_NAME);
- CHXString productNameStr = CHXAvStringUtils::DescToString(productName());
- CHXAvCleanString companyName(R_AVP_COMPANY_NAME);
- CHXString companyNameStr = CHXAvStringUtils::DescToString(companyName());
- m_prefs->Open(companyNameStr, productNameStr, TARVER_MAJOR_VERSION, TARVER_MINOR_VERSION);
- }