contentpublishingsrv/contentpublishingutils/pluginvalidator/src/charvesterpluginvalidator.cpp
branchRCL_3
changeset 101 9e077f9a342c
parent 64 b276298d5729
child 110 2c7f27287390
equal deleted inserted replaced
82:ace62b58f4b2 101:9e077f9a342c
     1 /*
     1 /*
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:
    14  * Description:
    15  *
    15  *
    16 */
    16  */
    17 
    17 
    18 #include <e32property.h>
    18 #include <e32property.h>
    19 #include <ecom/ecom.h>
    19 #include <ecom/ecom.h>
    20 #include <mmf/common/mmfcontrollerpluginresolver.h>
    20 #include <mmf/common/mmfcontrollerpluginresolver.h>
    21 #include <contentharvesterplugin.h> // harvesting plugin
    21 #include <contentharvesterplugin.h> // harvesting plugin
    22 
       
    23 #include "charvesterpluginvalidator.h"
    22 #include "charvesterpluginvalidator.h"
    24 #include "cblacklisthandler.h"
    23 #include "cblacklisthandler.h"
    25 
    24 
    26 const TUint32 KInProgressPropertyKey	= { 0x1028000E };
    25 const TUint32 KInProgressPropertyKey =
    27 const TUint32 KHarvesterUid	= { 0x10282E5A };
    26     {
       
    27     0x1028000E
       
    28     };
       
    29 const TUint32 KHarvesterUid =
       
    30     {
       
    31     0x10282E5A
       
    32     };
    28 
    33 
    29 // ======== MEMBER FUNCTIONS ========
    34 // ======== MEMBER FUNCTIONS ========
    30 
    35 
    31 // ----------------------------------------------------------------------------
    36 // ----------------------------------------------------------------------------
    32 //
    37 //
    33 // ----------------------------------------------------------------------------
    38 // ----------------------------------------------------------------------------
    34 //
    39 //
    35 EXPORT_C CHarvesterPluginValidator* CHarvesterPluginValidator::NewL( TUid aUid,
    40 EXPORT_C CHarvesterPluginValidator* CHarvesterPluginValidator::NewL(
    36                                                    TAny *aParameter )
    41         TUid aUid, TAny *aParameter)
    37     {
    42     {
    38     CHarvesterPluginValidator* self =
    43     CHarvesterPluginValidator* self = CHarvesterPluginValidator::NewLC(aUid,
    39           CHarvesterPluginValidator::NewLC( aUid , aParameter );
    44             aParameter);
    40     CleanupStack::Pop( self );
    45     CleanupStack::Pop(self);
    41     return self;
    46     return self;
    42     }
    47     }
    43 
    48 
    44 // ----------------------------------------------------------------------------
    49 // ----------------------------------------------------------------------------
    45 //
    50 //
    46 // ----------------------------------------------------------------------------
    51 // ----------------------------------------------------------------------------
    47 //
    52 //
    48 EXPORT_C CHarvesterPluginValidator* CHarvesterPluginValidator::NewLC( TUid aUid,
    53 EXPORT_C CHarvesterPluginValidator* CHarvesterPluginValidator::NewLC(
    49                                                     TAny *aParameter )
    54         TUid aUid, TAny *aParameter)
    50     {
    55     {
    51     CHarvesterPluginValidator* self = new( ELeave )
    56     CHarvesterPluginValidator* self = new (ELeave) CHarvesterPluginValidator(
    52         CHarvesterPluginValidator( aUid, aParameter );
    57             aUid, aParameter);
    53     CleanupStack::PushL( self );
    58     CleanupStack::PushL(self);
    54     self->ConstructL();
    59     self->ConstructL();
    55     return self;
    60     return self;
    56     }
    61     }
    57 
       
    58 
       
    59 
    62 
    60 // ---------------------------------------------------------------------------
    63 // ---------------------------------------------------------------------------
    61 // destructor
    64 // destructor
    62 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    63 CHarvesterPluginValidator::~CHarvesterPluginValidator()
    66 CHarvesterPluginValidator::~CHarvesterPluginValidator()
    64     {
    67     {
    65     iInProgressProperty.Close( );
    68     iInProgressProperty.Close();
    66     delete iBlacklist;
    69     delete iBlacklist;
       
    70     delete iUpdateIdle;
    67     }
    71     }
    68 
    72 
    69 // ----------------------------------------------------------------------------
    73 // ----------------------------------------------------------------------------
    70 //
    74 //
    71 // ----------------------------------------------------------------------------
    75 // ----------------------------------------------------------------------------
    72 //
    76 //
    73 CHarvesterPluginValidator::CHarvesterPluginValidator(TUid aUid,
    77 CHarvesterPluginValidator::CHarvesterPluginValidator(TUid aUid,
    74     TAny* aParameter) :
    78         TAny* aParameter) :
    75     CPluginValidator(aUid, aParameter)
    79     CPluginValidator(aUid, aParameter)
    76 {
    80     {
    77 
    81 
    78 }
    82     }
    79 
    83 
    80 // ----------------------------------------------------------------------------
    84 // ----------------------------------------------------------------------------
    81 //
    85 //
    82 // ----------------------------------------------------------------------------
    86 // ----------------------------------------------------------------------------
    83 //
    87 //
    84 void CHarvesterPluginValidator::ConstructL()
    88 void CHarvesterPluginValidator::ConstructL()
    85     {
    89     {
    86     iBlacklist = CBlacklistHandler::NewL();
    90     iBlacklist = CBlacklistHandler::NewL();
       
    91     iUpdateIdle = CIdle::NewL( CActive::EPriorityIdle );
       
    92     iUpdateIdle->Start( TCallBack( UpdateCallback, this ) );
    87     CPluginValidator::ConstructL();
    93     CPluginValidator::ConstructL();
    88     }
    94     }
    89 
    95 
    90 
       
    91 // ----------------------------------------------------------------------------
    96 // ----------------------------------------------------------------------------
    92 //
    97 //
    93 // ----------------------------------------------------------------------------
    98 // ----------------------------------------------------------------------------
    94 //
    99 //
    95 void CHarvesterPluginValidator::ManagePluginsL()
   100 void CHarvesterPluginValidator::ManagePluginsL()
    96     {
   101     {
    97     TInt errorCode = iInProgressProperty.Define( TUid::Uid( KHarvesterUid ),
   102     TInt errorCode = iInProgressProperty.Define(TUid::Uid(KHarvesterUid),
    98             KInProgressPropertyKey, RProperty::EInt );
   103             KInProgressPropertyKey, RProperty::EInt);
    99 
   104 
   100     if ( KErrAlreadyExists == errorCode )
   105     if (KErrAlreadyExists == errorCode)
   101       {
   106         {
   102       TInt value(-1);
   107         TInt value(-1);
   103       iInProgressProperty.Get( TUid::Uid( KHarvesterUid ),
   108         iInProgressProperty.Get(TUid::Uid(KHarvesterUid),
   104             KInProgressPropertyKey, value);
   109                 KInProgressPropertyKey, value);
   105       if ( value == 1 )
   110         if (value == 1)
   106         {
   111             {
   107         // property value == inprogress
   112             // property value == inprogress
   108         // there was a panic in the previous startup
   113             // there was a panic in the previous startup
   109         // so we make unofficial blacklist official
   114             // so we make unofficial blacklist official
   110         iBlacklist->CopyBlacklistL( EFalse );
   115             iBlacklist->CopyBlacklistL(EFalse);
   111         }
   116             }
   112       }
   117         }
   113     else
   118     else
   114       {
   119         {
   115       User::LeaveIfError( errorCode );
   120         User::LeaveIfError(errorCode);
   116       }
   121         }
   117     // copy blacklisted plugins to unoffical blacklist at startup
   122     // copy blacklisted plugins to unoffical blacklist at startup
   118     iBlacklist->CopyBlacklistL( ETrue );
   123     iBlacklist->CopyBlacklistL(ETrue);
   119 
   124 
   120     // set property value to 1 (which means "in progress")
   125     // set property value to 1 (which means "in progress")
   121     iInProgressProperty.Set( TUid::Uid( KHarvesterUid ),
   126     iInProgressProperty.Set(TUid::Uid(KHarvesterUid), KInProgressPropertyKey,
   122         KInProgressPropertyKey, 1 );
   127             1);
   123 
       
   124     CPluginValidator::ManagePluginsL();
   128     CPluginValidator::ManagePluginsL();
   125 
       
   126     // set property value to 0 (which means "finished")
   129     // set property value to 0 (which means "finished")
   127     iInProgressProperty.Set( TUid::Uid( KHarvesterUid ),
   130     iInProgressProperty.Set( TUid::Uid( KHarvesterUid ),
   128         KInProgressPropertyKey, 0 );
   131         KInProgressPropertyKey, 0 );
   129     }
   132     }
   130 
   133 
   131 // ----------------------------------------------------------------------------
   134 // ----------------------------------------------------------------------------
   132 //
   135 //
   133 // ----------------------------------------------------------------------------
   136 // ----------------------------------------------------------------------------
   134 //
   137 //
   135 void CHarvesterPluginValidator::LoadPluginL( TPluginInfo& aPluginInfo )
   138 void CHarvesterPluginValidator::LoadPluginL(TPluginInfo& aPluginInfo)
   136     {
   139     {
   137     if ( !iBlacklist->IsPresentL( aPluginInfo.iImplementationUid ) )
   140     if (!iBlacklist->IsPresentL(aPluginInfo.iImplementationUid))
   138       {
   141         {
   139       //first we append UID to the blacklist
   142         //first we append UID to the blacklist
   140       iBlacklist->AppendL( aPluginInfo.iImplementationUid );
   143         iBlacklist->AppendL(aPluginInfo.iImplementationUid);
   141       TAny* plug ( NULL );
   144         TAny* plug(NULL);
   142       TInt err( KErrNone );
   145         TInt err(KErrNone);
   143       TRAP( err, plug = REComSession::CreateImplementationL(
   146             TRAP( err, plug = REComSession::CreateImplementationL(
   144                     aPluginInfo.iImplementationUid,
   147                             aPluginInfo.iImplementationUid,
   145                     aPluginInfo.iDtor_ID_Key, iParameter ) );
   148                             aPluginInfo.iDtor_ID_Key, iParameter ) );
   146       if( err==KErrNone && plug )
   149         if (err == KErrNone && plug)
   147         {
   150             {
   148       TRAP_IGNORE(
   151                 TRAP_IGNORE(
   149         CleanupStack::PushL( plug );
   152                         CleanupStack::PushL( plug );
   150         aPluginInfo.iPlugin = plug;
   153                         aPluginInfo.iPlugin = plug;
   151         iPluginArray.AppendL( aPluginInfo );
   154                         iPluginArray.AppendL( aPluginInfo );
   152         CleanupStack::Pop( plug );
   155                         CleanupStack::Pop( plug );
   153            static_cast<CContentHarvesterPlugin*>( plug )->UpdateL()
   156                 );
   154             );
   157             }
   155         }
   158         //no panic during load so we can remove UID from blacklist
   156       //no panic during load so we can remove UID from blacklist
   159         iBlacklist->RemoveL(aPluginInfo.iImplementationUid);
   157       iBlacklist->RemoveL( aPluginInfo.iImplementationUid );
   160         }
   158       }
   161     }
   159     }
   162 
   160 
   163 // ----------------------------------------------------------------------------
   161 
   164 //
   162 
   165 // ----------------------------------------------------------------------------
   163 
   166 //
       
   167 void CHarvesterPluginValidator::UpdatePluginsL()
       
   168     {
       
   169     // set property value to 1 (which means "in progress")
       
   170     iInProgressProperty.Set(TUid::Uid(KHarvesterUid), KInProgressPropertyKey,
       
   171             1);
       
   172     for (TInt i = 0; i < iPluginArray.Count(); i++)
       
   173         {
       
   174         //first we append UID to the blacklist
       
   175         iBlacklist->AppendL(iPluginArray[i].iImplementationUid);
       
   176 
       
   177         TRAP_IGNORE( static_cast<CContentHarvesterPlugin*>
       
   178                     ( iPluginArray[i].iPlugin )->UpdateL() );
       
   179 
       
   180         //no panic during update so we can remove UID from blacklist
       
   181         iBlacklist->RemoveL(iPluginArray[i].iImplementationUid);
       
   182         }
       
   183     // set property value to 0 (which means "finished")
       
   184     iInProgressProperty.Set(TUid::Uid(KHarvesterUid), KInProgressPropertyKey,
       
   185             0);
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 // -----------------------------------------------------------------------------
       
   191 //  
       
   192 TInt CHarvesterPluginValidator::UpdateCallback( TAny* aValidator )
       
   193     {
       
   194     if ( aValidator )
       
   195         {
       
   196         TRAP_IGNORE( static_cast<CHarvesterPluginValidator*>(aValidator)->
       
   197                 UpdatePluginsL( ));
       
   198         }
       
   199     return KErrNone;
       
   200     }