CR: removing persistent plugin data with MediaPlatform

Tad Yeager <[email protected]>
Newsgroups gmane.comp.multimedia.helix.devel
Message-ID <[email protected]>
>Synopsis: encapsulate the removal of persistent plugin data in the 
>MediaPlatform.
>
>Summary:
>Applications (eg realplayer) and browser plugins (eg rpbrowserecordplugin) 
>attempt to kill registry keys prior to loading MediaPlatform/ObjectBroker 
>so that plugin handler data will be regenerated when mount points are 
>added.  This happens at installation time or if an application detects 
>that plugins have changed locations.
>
>MediaPlatform owns a Plugin2Handler which attempts to rewrite the plugin 
>handler data if persistent checksums don't match when AddPluginMountPoint 
>is called.  However,  Plugin2Handler::ReloadPluginsNoPropagate can do a 
>partial regeneration, rewriting FileInfo but not PluginInfo for the dlls 
>in FileInfo.  This happens when the plugin handler data store's checksum 
>fails (ReadPluginInfoFast) but the dll checksum does not fail in 
>ReloadPluginsNoPropagate.
>
>The attached changes to MediaPlatform expose a method that deletes 
>preferences using code factored out of MediaPlatform's Reset() 
>function.  The location and format of the persistent plugin data can 
>change. The attached changes move ownership from 
>ObjectBroker/MediaPlatform's clients to MediaPlatform.
>
>
>Branch:
>head, hxclient_3_1_0_atlas
>
>Affected:
>Media Platform.
>
>Risks:
>low.
>
>Please review the attached diffs.  Let me know if you have questions or 
>suggestions.

_______________________________________________
Helix-client-dev mailing list
[email protected]
http://lists.helixcommunity.org/mailman/listinfo/helix-client-dev
include.irmamedpltfm.h.txt (text/plain, 2.2 KB)
Index: irmamedpltfm.h
===================================================================
RCS file: /home/source/include/irmamedpltfm.h,v
retrieving revision 1.4.46.2
diff -u -2 -0 -r1.4.46.2 irmamedpltfm.h
--- irmamedpltfm.h	12 Feb 2009 21:38:48 -0000	1.4.46.2
+++ irmamedpltfm.h	18 Feb 2009 23:48:37 -0000
@@ -139,40 +139,50 @@
      *	    IRMAMediaPlatform::Reset
      *	Purpose:
      *	    Reset the media platform, it not only closes the media platform
      *	    but also clears persistent information maintained by the platform. 
      *
      *	    If pContext is not NULL, the platform will QI for the persistent 
      *	    storage interface (IHXPreferences) from pContext and clear it up. 
      *
      *	    Note, the caller needs to pass the same pContext to Reset() as it 
      *	    passes to Init() if Init() is called earlier. On the other hand, 
      *	    the caller is allowed to call Reset() without Init() if the caller 
      *	    only wants to clear up the persistent information, one example is 
      *	    the uninstaller of the application.
      */
     STDMETHOD(Reset)		(THIS_
 				 IUnknown* pContext,
                                  BOOL bPlatformOnly) PURE;
 
     /************************************************************************
      *	Method:
+     *	    IHXMediaPlatform::RemovePersistentPluginData
+     *	Purpose:
+     *	    Remove MountPoints from Preferences so PluginHandlerData may be 
+     *      regenerated
+     *
+     */
+    STDMETHOD(RemovePersistentPluginData) (THIS) PURE;
+
+    /************************************************************************
+     *	Method:
      *	    IRMAMediaPlatform::Purge
      *	Purpose:
      *	    Force unloading of any unused plugins by the platform
      */
     STDMETHOD(Purge)		(THIS) PURE;
 
     /************************************************************************
      *	Method:
      *	    IRMAMediaPlatform::CreateChildContext
      *	Purpose:
      *	    Create a new media platform context from the current context
      */
     STDMETHOD(CreateChildContext)   (THIS_
 				     IRMAMediaPlatform** ppChildContext) PURE;
 };
 
 
 #ifdef __cplusplus 
    #include "rncomptr.h" 
    typedef RNCOMPtr<IRMAMediaPlatform> SPIRMAMediaPlatform;
client.medpltfm.chxmedpltfm.cpp.txt (text/plain, 4.7 KB)
Index: chxmedpltfm.cpp
===================================================================
RCS file: /cvsroot/client/medpltfm/chxmedpltfm.cpp,v
retrieving revision 1.51.2.19
diff -u -2 -0 -r1.51.2.19 chxmedpltfm.cpp
--- chxmedpltfm.cpp	8 Nov 2008 17:25:36 -0000	1.51.2.19
+++ chxmedpltfm.cpp	18 Feb 2009 23:39:44 -0000
@@ -586,44 +586,40 @@
     }
 
     // Extended context must be released last as it may have overriden 
     // services used by pther platform objects and it may also have 
     // aggregated itself into the platform.
     // In such case, releasing of the external context will result in its
     // destruction and thus any objects that may use its service must
     // be released/closed first.
     HX_RELEASE(m_pExtCCF);
     HX_RELEASE(m_pExtContext);
 
     m_bInitialized = FALSE;
 
     return HXR_OK;
 }
 
 STDMETHODIMP
 CHXMediaPlatform::Reset(IUnknown* pContext, HXBOOL bPlatformOnly)
 {
     HX_RESULT                   rc = HXR_OK;
-    IHXBuffer*                  pPrefKey = NULL;
-    IHXPreferences2*            pPref2 = NULL;
-    IHXPreferences3*            pPref3 = NULL;
-    IHXPreferenceEnumerator*    pPrefEnumerator = NULL;
     IHXPluginEnumerator*        pPluginEnumerator = NULL;
 
     if (!bPlatformOnly && m_pPluginHandlerUnkown)
     {
         if (HXR_OK == m_pPluginHandlerUnkown->QueryInterface(IID_IHXPluginEnumerator,
                                                              (void**)&pPluginEnumerator))
         {
             UINT32      ulIndex = 0;
             UINT32      ulNumOfPlugins = pPluginEnumerator->GetNumOfPlugins();
             IUnknown*   pPlugin = NULL;
             IHXPlugin2* pPlugin2 = NULL;
 
             for(ulIndex = 0; ulIndex < ulNumOfPlugins; ulIndex++)
             {
                 if (SUCCEEDED(pPluginEnumerator->GetPlugin(ulIndex, pPlugin)))
                 {
                     if (SUCCEEDED(pPlugin->QueryInterface(IID_IHXPlugin2, (void**)&pPlugin2)))
                     {
                         pPlugin2->Reset();
                     }
@@ -632,58 +628,87 @@
                 HX_RELEASE(pPlugin);
             }
         }
         HX_RELEASE(pPluginEnumerator);   
     }
 
     // We reset the m_pPreferences if it's already initialized via Init()
     //
     // On the other hand, Reset() can be called without Init(), this can
     // happen when the app simply wants to reset the media platform
     // during its un-installation
     if (!m_pPreferences)
     {       
         if (!m_pExtContext ||
             HXR_OK != m_pExtContext->QueryInterface(IID_IHXPreferences, (void**)&m_pPreferences))
         {
             InitDefaultPreferences();
         }
     }
 
+    RemovePreferences(FALSE);
+
+    Close();
+
+    return HXR_OK;
+}
+
+STDMETHODIMP
+CHXMediaPlatform::RemovePersistentPluginData()
+{
+    return RemovePreferences(TRUE);
+}
+
+
+HX_RESULT         
+CHXMediaPlatform::RemovePreferences(HXBOOL bMountPointsOnly)
+{
+    IHXBuffer*                  pPrefKey = NULL;
+    IHXPreferences2*            pPref2 = NULL;
+    IHXPreferences3*            pPref3 = NULL;
+    IHXPreferenceEnumerator*    pPrefEnumerator = NULL;
+
     // remove all the entries within m_pPreferences
     if (m_pPreferences &&
         HXR_OK == m_pPreferences->QueryInterface(IID_IHXPreferences2, (void**)&pPref2) &&
         HXR_OK == m_pPreferences->QueryInterface(IID_IHXPreferences3, (void**)&pPref3) &&
         HXR_OK == pPref2->GetPreferenceEnumerator(pPrefEnumerator))
     {
         while (HXR_OK == pPrefEnumerator->GetPrefKey(0, pPrefKey))
         {
-            pPref3->DeletePref((const char*)pPrefKey->GetBuffer());
+            if (!bMountPointsOnly)
+            {
+                pPref3->DeletePref((const char*)pPrefKey->GetBuffer());
+            }
+            else if (pPrefKey->GetSize() >= sizeof("MountPoints") -1 && 
+                !strncmp("MountPoints", (const char*)pPrefKey->GetBuffer(), sizeof("MountPoints")-1))
+            {
+                pPref3->DeletePref((const char*)pPrefKey->GetBuffer());
+                HX_RELEASE(pPrefKey);
+                break; //assuming only one MountPoints mount point
+            }
             HX_RELEASE(pPrefKey);
         }
         HX_RELEASE(pPrefEnumerator);
         HX_RELEASE(pPref3);
         HX_RELEASE(pPref2);
     }
-
-    Close();
-
     return HXR_OK;
 }
 
 STDMETHODIMP
 CHXMediaPlatform::Purge(void)
 {
     // Purge is not supported on child media platform context
     if (m_pParent)
     {
         return m_pParent->Purge();
     }
 
 #if !defined(_STATICALLY_LINKED) && defined(HELIX_FEATURE_PLUGINHANDLER2)
     if (m_pPluginHandlerUnkown)
     {
         // shortcut, UnloadDeadDLLs() needs to be part of the interface 
         ((Plugin2Handler*)(IHXPlugin2Handler*)m_pPluginHandlerUnkown)->UnloadDeadDLLs();
     }
     
     return HXR_OK;
client.medpltfm.pub.chxmedpltfm.h.txt (text/plain, 2.8 KB)
Index: pub/chxmedpltfm.h
===================================================================
RCS file: /cvsroot/client/medpltfm/pub/chxmedpltfm.h,v
retrieving revision 1.19.2.6
diff -u -2 -0 -r1.19.2.6 chxmedpltfm.h
--- pub/chxmedpltfm.h	6 Jun 2008 00:37:44 -0000	1.19.2.6
+++ pub/chxmedpltfm.h	18 Feb 2009 21:43:56 -0000
@@ -187,67 +187,70 @@
     CHXSimpleList*	    m_pSingleLoadPlugins;
     CHXSimpleList*          m_pLoadAtStartupPlugins;
 
     HX_RESULT		    InitBasicServices(void);
     HX_RESULT               LoadStartupPlugins(void);
     void                    UnloadStartupPlugins(void);
     HX_RESULT		    InitExtendableServices(void);
     HX_RESULT		    CheckAndQueryInterface(HX_MP_COM_TYPE type, REFIID riid, void** ppvObj);
     HX_RESULT		    CheckAndCreateInstance(HX_MP_COM_TYPE type, REFCLSID rclsid, void** ppUnknown);
 
     virtual HX_RESULT	    CreateIntrinsicType(REFCLSID rclsid, REF(IUnknown*) pUnknown, IUnknown* pOuter);
     virtual HX_RESULT	    CreateGeneralType(REFCLSID clsid, REF(IUnknown*) pObject, IUnknown* pUnkOuter, IUnknown* pContext);
 
     HX_RESULT		    CreateInstanceFromPluginHandler(REFCLSID rclsid, void** ppUnknown, IUnknown *pUnkOuter, IUnknown* pContext);
 
     HX_RESULT		    InitDefaultPreferences(void);
     HX_RESULT               InitLogging();
 
     HX_RESULT		    _InternalQI(REFIID riid, void** ppvObj);
 
+    HX_RESULT               RemovePreferences(HXBOOL bMountPointsOnly);
 public:
     static CHXMediaPlatform* CreateInstance(CHXMediaPlatform* pParent = NULL, 
 					    CHXMediaPlatform* pRoot = NULL);
 
     CHXMediaPlatform(CHXMediaPlatform* pParent = NULL, CHXMediaPlatform* pRoot = NULL);
     ~CHXMediaPlatform(void);
 
     /*
      *  IHXMediaPlatform methods     
      *  see common/include/ihxmedpltfm.h for detail description
      */
     STDMETHOD(GetVersion)	(THIS_
 			         UINT32* pVersion);
 
     STDMETHOD(AddPluginPath)	(THIS_
 				 const char* pszName,
 				 const char* pszPath);
 
     STDMETHOD(Init)		(THIS_
 				 IUnknown* pContext);
 
     STDMETHOD(Close)		(THIS);
 
     STDMETHOD(Reset)		(THIS_
 				 IUnknown* pContext,
 				 HXBOOL	   bPlatformOnly = TRUE);
 
+    STDMETHOD(RemovePersistentPluginData) (THIS);
+
     STDMETHOD(Purge)		(THIS);
 
     STDMETHOD(CreateChildContext)   (THIS_
 				     IHXMediaPlatform** ppChildContext);
 
     /*
      *	IHXCommonClassFactory methods
      */
     STDMETHOD(CreateInstance)		    (THIS_
 					     REFCLSID	rclsid,
 					     void**	ppUnknown);
 
     STDMETHOD(CreateInstanceAggregatable)   (THIS_
 					     REFCLSID	    rclsid,
 					     REF(IUnknown*) ppUnknown,
 					     IUnknown*	    pUnkOuter);
 
     // IHXObjectManagerPrivate methods
     STDMETHOD(ObjectFromCLSIDPrivate) (THIS_ REFCLSID clsid,REF(IUnknown *)pObject, 
 						IUnknown *pUnkOuter, IUnknown* pContext );
common.include.ihxmedpltfm.h.txt (text/plain, 2.2 KB)
Index: ihxmedpltfm.h
===================================================================
RCS file: /cvsroot/common/include/ihxmedpltfm.h,v
retrieving revision 1.10.2.3
diff -u -2 -0 -r1.10.2.3 ihxmedpltfm.h
--- ihxmedpltfm.h	5 Feb 2009 15:07:52 -0000	1.10.2.3
+++ ihxmedpltfm.h	18 Feb 2009 23:45:55 -0000
@@ -190,40 +190,50 @@
      *	    but also clears persistent information maintained by the platform. 
      *
      *	    If pContext is not NULL, the platform will QI for the persistent 
      *	    storage interface (IHXPreferences) from pContext and clear it up. 
      *
      *	    Note, the caller needs to pass the same pContext to Reset() as it 
      *	    passes to Init() if Init() is called earlier. On the other hand, 
      *	    the caller is allowed to call Reset() without Init() if the caller 
      *	    only wants to clear up the persistent information, one example is 
      *	    the uninstaller of the application.
      *
      *      If bPlatformOnly is TRUE(by default), then only the platform will be reset. 
      *      Otherwise, all the plugins loaded by the Platform will also be reset.
      */
     STDMETHOD(Reset)		(THIS_
 				 IUnknown* pContext,
 				 HXBOOL	   bPlatformOnly) PURE;
 
     /************************************************************************
      *	Method:
+     *	    IHXMediaPlatform::RemovePersistentPluginData
+     *	Purpose:
+     *	    Remove MountPoints from Preferences so PluginHandlerData may be 
+     *      regenerated
+     *
+     */
+    STDMETHOD(RemovePersistentPluginData) (THIS) PURE;
+
+    /************************************************************************
+     *	Method:
      *	    IHXMediaPlatform::Purge
      *	Purpose:
      *	    Force unloading of any unused plugins by the platform
      */
     STDMETHOD(Purge)		(THIS) PURE;
 
     /************************************************************************
      *	Method:
      *	    IHXMediaPlatform::CreateChildContext
      *	Purpose:
      *	    Create a new media platform context from the current context
      */
     STDMETHOD(CreateChildContext)   (THIS_
 				     IHXMediaPlatform** ppChildContext) PURE;
 };
 
 /****************************************************************************
  * 
  *  Interface:
  *
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.