gssettingsuis/Gs/GSFramework/src/GSBaseDocument.cpp
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     1 /*
       
     2 * Copyright (c) 2002-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Base Document for the General Settings Application
       
    15 *
       
    16 */
       
    17 
       
    18 #include "GSBaseDocument.h"
       
    19 
       
    20 // User includes
       
    21 #include "GSPluginWrapper.h"
       
    22 #include "GSPluginAndViewIdCache.h"
       
    23 #include "GSWatchDog.h"
       
    24 #include "gsplugininterface.h"
       
    25 #include "GsLogger.h"
       
    26 
       
    27 // Constants
       
    28 const TInt KGSPluginWrapperObjectGranularity = 10;
       
    29 
       
    30 
       
    31 // ================= MEMBER FUNCTIONS =======================
       
    32 
       
    33 // ----------------------------------------------------
       
    34 // CGSBaseDocument::CGSBaseDocument()
       
    35 // constructor
       
    36 //
       
    37 // ----------------------------------------------------
       
    38 //
       
    39 EXPORT_C CGSBaseDocument::CGSBaseDocument( CEikApplication& aApp )
       
    40 :   CAknDocument( aApp ),
       
    41     iUnloadWrapperObjects( KGSPluginWrapperObjectGranularity ),
       
    42     iWatchDog ( NULL )
       
    43     {
       
    44     }
       
    45 
       
    46 
       
    47 // ----------------------------------------------------
       
    48 // CGSBaseDocument::~CGSBaseDocument()
       
    49 // destructor
       
    50 //
       
    51 // ----------------------------------------------------
       
    52 //
       
    53 EXPORT_C CGSBaseDocument::~CGSBaseDocument()
       
    54     {
       
    55     // This physically unloads the plugin dlls if their ECOM
       
    56     // reference count is zero. This must be the last thing to
       
    57     // occur to any plugin object (i.e. all of its code must have
       
    58     // finished running by the time this next line takes place).
       
    59     const TInt count = iUnloadWrapperObjects.Count();
       
    60     for( TInt i=count-1; i>=0; i-- )
       
    61         {
       
    62         CGSPluginWrapper* object = iUnloadWrapperObjects[ i ];
       
    63         (void) object;
       
    64         delete object;
       
    65         }
       
    66 
       
    67     iUnloadWrapperObjects.Close();
       
    68     delete iPluginViewIdCache;
       
    69 #ifdef GS_ENABLE_WATCH_DOG
       
    70     delete iWatchDog;
       
    71 #endif
       
    72 
       
    73     iImplInfoArray.ResetAndDestroy();// This is needed
       
    74     iImplInfoArray.Close();
       
    75     }
       
    76 
       
    77 
       
    78 // ----------------------------------------------------
       
    79 // CGSBaseDocument::ConstructL()
       
    80 // Symbian OS second phase constructor
       
    81 //
       
    82 // ----------------------------------------------------
       
    83 //
       
    84 EXPORT_C void CGSBaseDocument::ConstructL()
       
    85     {
       
    86 #ifdef GS_ENABLE_WATCH_DOG
       
    87     iWatchDog = CGSWatchDog::NewL();
       
    88 #endif
       
    89 
       
    90     REComSession::ListImplementationsL(
       
    91         KGSPluginInterfaceUid,
       
    92         iImplInfoArray );
       
    93 #ifdef _DEBUG
       
    94     PrintImplInfoArray( iImplInfoArray );
       
    95 #endif //_DEBUG
       
    96         
       
    97     __GSLOGSTRING1(
       
    98         "[CGSBaseDocument::ConstructL] iImplInfoArray count:%d",
       
    99         iImplInfoArray.Count() );
       
   100     }
       
   101 
       
   102 
       
   103 // ----------------------------------------------------
       
   104 // CGSBaseDocument::NewPluginUnloadWrapperLC()
       
   105 //
       
   106 //
       
   107 // ----------------------------------------------------
       
   108 //
       
   109 EXPORT_C CGSPluginWrapper* CGSBaseDocument::NewPluginUnloadWrapperLC()
       
   110     {
       
   111     CGSPluginWrapper* wrapper = new(ELeave) CGSPluginWrapper( *this );
       
   112     TCleanupItem wrapperCleanupItem( CleanupPluginWrapperObject, wrapper );
       
   113     CleanupStack::PushL( wrapperCleanupItem );
       
   114     iUnloadWrapperObjects.AppendL( wrapper );
       
   115     //
       
   116     return wrapper;
       
   117     }
       
   118 
       
   119 
       
   120 // ----------------------------------------------------
       
   121 // CGSBaseDocument::PreparePluginCacheL()
       
   122 //
       
   123 //
       
   124 // ----------------------------------------------------
       
   125 //
       
   126 EXPORT_C void CGSBaseDocument::PreparePluginCacheL( CEikAppUi& aAppUi )
       
   127     {
       
   128     iPluginViewIdCache = CGSPluginAndViewIdCache::NewL( aAppUi );
       
   129     }
       
   130 
       
   131 
       
   132 // ----------------------------------------------------
       
   133 // CGSBaseDocument::PrepareForUIDestruction()
       
   134 //
       
   135 //
       
   136 // ----------------------------------------------------
       
   137 //
       
   138 EXPORT_C void CGSBaseDocument::PrepareForUIDestruction()
       
   139     {
       
   140     if  ( iPluginViewIdCache )
       
   141         {
       
   142         iPluginViewIdCache->PrepareForUIDestruction();
       
   143         }
       
   144     }
       
   145 
       
   146 
       
   147 // ----------------------------------------------------
       
   148 // CGSBaseDocument::CleanupPluginWrapperObject()
       
   149 // Cleanup support
       
   150 //
       
   151 // ----------------------------------------------------
       
   152 //
       
   153 void CGSBaseDocument::CleanupPluginWrapperObject( TAny* aWrapper )
       
   154     {
       
   155     CGSPluginWrapper* wrapper =
       
   156         reinterpret_cast< CGSPluginWrapper* >( aWrapper );
       
   157     CGSBaseDocument& document = wrapper->Document();
       
   158     document.DoCleanupPluginWrapper( wrapper );
       
   159     }
       
   160 
       
   161 
       
   162 // ----------------------------------------------------
       
   163 // CGSBaseDocument::DoCleanupPluginWrapper()
       
   164 // Cleanup support - called when loading a plugin fails
       
   165 //
       
   166 // ----------------------------------------------------
       
   167 //
       
   168 void CGSBaseDocument::DoCleanupPluginWrapper( CGSPluginWrapper* aWrapper )
       
   169     {
       
   170     const TInt index = iUnloadWrapperObjects.Find( aWrapper );
       
   171     if  ( index >= 0 && index < iUnloadWrapperObjects.Count() )
       
   172         {
       
   173         iUnloadWrapperObjects.Remove( index );
       
   174         delete aWrapper;
       
   175         }
       
   176     }
       
   177 
       
   178 
       
   179 // ----------------------------------------------------
       
   180 // CGSBaseDocument::PluginViewIdCache()
       
   181 //
       
   182 //
       
   183 // ----------------------------------------------------
       
   184 //
       
   185 CGSPluginAndViewIdCache& CGSBaseDocument::PluginViewIdCache()
       
   186     {
       
   187     ASSERT( iPluginViewIdCache );
       
   188     return *iPluginViewIdCache;
       
   189     }
       
   190 
       
   191 
       
   192 // ----------------------------------------------------
       
   193 // CGSBaseDocument::PluginViewIdCache()
       
   194 //
       
   195 //
       
   196 // ----------------------------------------------------
       
   197 //
       
   198 const CGSPluginAndViewIdCache& CGSBaseDocument::PluginViewIdCache() const
       
   199     {
       
   200     ASSERT( iPluginViewIdCache );
       
   201     return *iPluginViewIdCache;
       
   202     }
       
   203 
       
   204 
       
   205 
       
   206 // ----------------------------------------------------
       
   207 // CGSBaseDocument::WatchDog()
       
   208 //
       
   209 //
       
   210 // ----------------------------------------------------
       
   211 //
       
   212 EXPORT_C MGSWatchDog* CGSBaseDocument::WatchDog()
       
   213     {
       
   214     return iWatchDog;
       
   215     }
       
   216 
       
   217 // ----------------------------------------------------
       
   218 // CGSBaseDocument::GetImplInfos()
       
   219 //
       
   220 //
       
   221 // ----------------------------------------------------
       
   222 //
       
   223 EXPORT_C RImplInfoPtrArray CGSBaseDocument::GetImplInfo()
       
   224     {
       
   225     return iImplInfoArray;
       
   226     }
       
   227 
       
   228 EXPORT_C void CGSBaseDocument::CreateShimmedViewL(const TUid aViewUid)
       
   229 	{
       
   230 	ASSERT(iPluginViewIdCache);
       
   231 	if ( !iPluginViewIdCache->PluginInstance(aViewUid) )
       
   232 		{
       
   233 		iPluginViewIdCache->RegisterViewAndImplementationAssociationL(aViewUid, aViewUid, ETrue);
       
   234 		}
       
   235 	}
       
   236 
       
   237 void CGSBaseDocument::PrintImplInfoArray( const RImplInfoPtrArray& aImplInfoArray )
       
   238     {
       
   239     for( TInt i = 0; i < aImplInfoArray.Count(); i++ )
       
   240         {
       
   241         PrintImplInfo( *aImplInfoArray[ i ] );
       
   242         }
       
   243     }
       
   244 
       
   245 
       
   246 void CGSBaseDocument::PrintImplInfo( const CImplementationInformation& aInfo )
       
   247     {
       
   248     __GSLOGSTRING1( "[CGSBaseDocument] --Plugin 0x%X info--", &aInfo);
       
   249     __GSLOGSTRING1( "[CGSBaseDocument] DisplayName:%S", &aInfo.DisplayName() );
       
   250     __GSLOGSTRING1( "[CGSBaseDocument] ImplementationUid:0x%X",
       
   251                     aInfo.ImplementationUid() );
       
   252 
       
   253     const TInt KMaxEComDataLength = 256;
       
   254 
       
   255     HBufC* dataType = HBufC::New( KMaxEComDataLength );
       
   256     HBufC* opaqueData = HBufC::New( KMaxEComDataLength );
       
   257 
       
   258     dataType->Des().Copy( aInfo.DataType() );
       
   259     opaqueData->Des().Copy( aInfo.OpaqueData() );
       
   260     __GSLOGSTRING1( "[CGSBaseDocument] DataType:%S", dataType );
       
   261     __GSLOGSTRING1( "[CGSBaseDocument] OpaqueData:%S", opaqueData );
       
   262 
       
   263     delete opaqueData;
       
   264     delete dataType;
       
   265     }
       
   266 
       
   267 
       
   268 
       
   269 // End of File