mpx/collectionframework/collectionengine/src/mpxcollectionpluginhandler.cpp
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Collection plug-in handler
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mpxlog.h>
       
    19 #include <mpxcollectionplugin.h>
       
    20 #include <mpxcollectionplugin.hrh>
       
    21 #include "mpxcollectionpluginhandler.h"
       
    22 #include "mpxcollectionplugininfo.h"
       
    23 
       
    24 // ============================ MEMBER FUNCTIONS ==============================
       
    25 
       
    26 // ----------------------------------------------------------------------------
       
    27 // Two-phased constructor.
       
    28 // ----------------------------------------------------------------------------
       
    29 //
       
    30 CMPXCollectionPluginHandler* CMPXCollectionPluginHandler::NewL(
       
    31     MMPXCollectionPluginObserver& aPluginObserver,
       
    32     MMPXPluginHandlerObserver& aObserver)
       
    33     {
       
    34     CMPXCollectionPluginHandler* p=new(ELeave)CMPXCollectionPluginHandler(
       
    35         aPluginObserver, aObserver);
       
    36     CleanupStack::PushL(p);
       
    37     p->ConstructL();
       
    38     CleanupStack::Pop(p);
       
    39     return p;
       
    40     }
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // Constructor.
       
    44 // ----------------------------------------------------------------------------
       
    45 //
       
    46 CMPXCollectionPluginHandler::CMPXCollectionPluginHandler(
       
    47     MMPXCollectionPluginObserver& aPluginObserver,
       
    48     MMPXPluginHandlerObserver& aObserver)
       
    49 :   CMPXPluginHandlerBase(KMPXCollectionInterfaceUid, ESelectionType, EMcLocal, aObserver),
       
    50     iPluginObserver(&aPluginObserver)
       
    51     {
       
    52     }
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // 2nd phase constructor.
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 void CMPXCollectionPluginHandler::ConstructL()
       
    59     {
       
    60     BaseConstructL();
       
    61     }
       
    62 
       
    63 // ----------------------------------------------------------------------------
       
    64 // Destructor.
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 CMPXCollectionPluginHandler::~CMPXCollectionPluginHandler()
       
    68     {
       
    69     //close plugins
       
    70     for (TInt i = iLoadedPlugins.Count(); --i >= 0;)
       
    71         {
       
    72         CMPXCollectionPlugin* p=iLoadedPlugins[i];
       
    73         TRAP_IGNORE( p->CommandL(EMcCmdClose) );
       
    74         }
       
    75     iLoadedPlugins.ResetAndDestroy();
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // Return the list of loaded plugins
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 TArray<CMPXCollectionPlugin*> CMPXCollectionPluginHandler::LoadedPlugins()
       
    83     {
       
    84     return iLoadedPlugins.Array();
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // Remove tasks of a client which is the observer of tasks
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 void CMPXCollectionPluginHandler::RemoveTask(TAny* aCallback)
       
    92     {
       
    93     for (TInt i=iLoadedPlugins.Count(); --i>=0; )
       
    94         {
       
    95         CMPXCollectionPlugin* plugin(iLoadedPlugins[i]);
       
    96         if (plugin->Callback()==aCallback)
       
    97             {
       
    98             MPX_DEBUG1("CMPXCollectoinPluginHandler::RemoveTask removes active task");
       
    99             plugin->CancelRequest();
       
   100             plugin->CompleteTask();
       
   101             plugin->SetCallback(NULL);
       
   102             plugin->SetObserver(*iPluginObserver);
       
   103             }
       
   104         else
       
   105             {
       
   106             iLoadedPlugins[i]->RemoveTask(aCallback);
       
   107             }
       
   108         }
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------------------------------
       
   112 // Get the list of noncacheable attributes
       
   113 // ----------------------------------------------------------------------------
       
   114 //
       
   115 const TArray<TUid> CMPXCollectionPluginHandler::NonCacheableAttributesL(
       
   116                                                         const TUid& aPluginId )
       
   117     {
       
   118     TInt i(KErrNotFound);
       
   119     TInt count( iPluginInfoArray.Count() );
       
   120     TBool found( EFalse );
       
   121     for( i = 0; !found && i < count; ++i )
       
   122         {
       
   123         if ( iPluginInfoArray[i]->ImplementationUid() == aPluginId )
       
   124             {
       
   125             found = ETrue;
       
   126             break;
       
   127             }
       
   128         }
       
   129     if ( !found )
       
   130         {
       
   131         User::Leave( KErrNotFound );
       
   132         }
       
   133 
       
   134     return ((CMPXCollectionPluginInfo*)iPluginInfoArray[i])->NonCacheableAttrs();
       
   135     }
       
   136 
       
   137 // ----------------------------------------------------------------------------
       
   138 // Get whether the plugin is cacheable or not
       
   139 // ----------------------------------------------------------------------------
       
   140 //
       
   141 TBool CMPXCollectionPluginHandler::PluginCachable( const TUid& aPluginId )
       
   142     {
       
   143     TUint flags(0);
       
   144 
       
   145     TInt count( iPluginInfoArray.Count() );
       
   146     for( TInt i = 0; i < count; ++i )
       
   147         {
       
   148         if ( iPluginInfoArray[i]->ImplementationUid() == aPluginId )
       
   149             {
       
   150             flags = iPluginInfoArray[i]->Flags();
       
   151             break;
       
   152             }
       
   153         }
       
   154     return ((flags&EMPXCollectionPluginFlagCacheable) != 0);
       
   155     }
       
   156 
       
   157 // ----------------------------------------------------------------------------
       
   158 // CMPXCollectionPluginHandler::LoadedPlugin
       
   159 // ----------------------------------------------------------------------------
       
   160 //
       
   161 CMPXCollectionPlugin* CMPXCollectionPluginHandler::LoadedPlugin(const TUid& aUid)
       
   162     {
       
   163     CMPXCollectionPlugin* plugin(NULL);
       
   164     TInt index(LoadedPluginIndex(aUid));
       
   165     if (KErrNotFound != index)
       
   166         {
       
   167         plugin = iLoadedPlugins[index];
       
   168         }
       
   169     return plugin;
       
   170     }
       
   171 
       
   172 // ----------------------------------------------------------------------------
       
   173 // Resolve a plugin to iPlugin, based on properties (iDataType, iExt and iScheme)
       
   174 // and selection criteria. If selection is by type, then there is always a
       
   175 // plug-in resolved (if there are any of that type). Room for optimisation!
       
   176 // ----------------------------------------------------------------------------
       
   177 //
       
   178 void CMPXCollectionPluginHandler::ResolvePluginL()
       
   179     {
       
   180     //
       
   181     // Resolve plugin
       
   182     //
       
   183     TUid pluginUid( KNullUid );
       
   184     TInt index( KErrNotFound );
       
   185     TPtrC displayName;
       
   186     TInt pluginType( EMcUnknown );
       
   187 
       
   188     DoResolvePluginL(pluginUid, index, displayName, pluginType );
       
   189 
       
   190     iPlugin = CreateCollectionPluginL(pluginUid);
       
   191     if(iPlugin != NULL)
       
   192     UsePlugin(pluginUid);
       
   193     }
       
   194 // ----------------------------------------------------------------------------
       
   195 // CMPXCollectionPluginHandler::IsPluginLoaded
       
   196 // ----------------------------------------------------------------------------
       
   197 //
       
   198 TBool CMPXCollectionPluginHandler::IsPluginLoaded(
       
   199     const TUid& aPluginUid)
       
   200     {
       
   201     return LoadedPluginIndex(aPluginUid) != KErrNotFound;
       
   202     }
       
   203 
       
   204 // ----------------------------------------------------------------------------
       
   205 // CMPXCollectionPluginHandler::LoadPluginL
       
   206 // ----------------------------------------------------------------------------
       
   207 //
       
   208 void CMPXCollectionPluginHandler::LoadPluginL(
       
   209     const TUid& aPluginUid)
       
   210     {
       
   211     (void)CreateCollectionPluginL(aPluginUid);
       
   212     }
       
   213 
       
   214 // ----------------------------------------------------------------------------
       
   215 // Constructs the collection plugin info class
       
   216 // ----------------------------------------------------------------------------
       
   217 //
       
   218 CMPXPluginInfo* CMPXCollectionPluginHandler::ConstructPluginInfoLC(
       
   219                                      const CImplementationInformation& aData  )
       
   220     {
       
   221     return CMPXCollectionPluginInfo::NewLC( aData );
       
   222     }
       
   223 
       
   224 // ----------------------------------------------------------------------------
       
   225 // Unloads a specified plugin.
       
   226 // ----------------------------------------------------------------------------
       
   227 //
       
   228 void CMPXCollectionPluginHandler::UnloadPlugin(
       
   229     const TUid& aUid)
       
   230     {
       
   231     MPX_DEBUG3("===>CMPXCollectionPluginHandler::UnloadPlugin 0x%08x uid 0x%08x",
       
   232                this, aUid.iUid);
       
   233     TInt index(LoadedPluginIndex(aUid));
       
   234     if (index != KErrNotFound)
       
   235         {
       
   236         UnloadPlugin(index);
       
   237         }
       
   238     MPX_DEBUG3("<===CMPXCollectionPluginHandler::UnloadPlugin 0x%08x uid 0x%08x",
       
   239                this, aUid.iUid);
       
   240     }
       
   241 
       
   242 // ----------------------------------------------------------------------------
       
   243 // Return a plugin controller with the specific id
       
   244 // ----------------------------------------------------------------------------
       
   245 //
       
   246 CMPXCollectionPlugin*
       
   247 CMPXCollectionPluginHandler::CreateCollectionPluginL(const TUid& aUid)
       
   248     {
       
   249     MPX_DEBUG3("===>CMPXCollectionPluginHandler::CreateCollectionPluginL 0x%08x uid 0x%08x",
       
   250                this, aUid.iUid);
       
   251 
       
   252     CMPXCollectionPlugin* p=NULL;
       
   253 
       
   254     TInt index(LoadedPluginIndex(aUid));
       
   255     if (index == KErrNotFound)
       
   256         {
       
   257         MPX_DEBUG3("CMPXCollectionPluginHandler::CreateCollectionPluginL create a new plugin 0x%08x uid 0x%08x",
       
   258                    this, aUid.iUid);
       
   259         TRAPD(err, p = CMPXCollectionPlugin::NewL(aUid, *iPluginObserver));
       
   260         if(err == KErrNone)
       
   261             {
       
   262         CleanupStack::PushL(p);
       
   263         iLoadedPlugins.AppendL(p);
       
   264         CleanupStack::Pop(p);
       
   265             }
       
   266         else
       
   267             {
       
   268             MPX_DEBUG3("CMPXCollectionPluginHandler::CreateCollectionPluginL error creating plugin %d uid 0x%08x",
       
   269                                err, aUid.iUid);
       
   270             User::Leave(err);
       
   271             }
       
   272         }
       
   273      else
       
   274         {
       
   275         p = iLoadedPlugins[index];
       
   276         }
       
   277 
       
   278     MPX_DEBUG3("<===CMPXCollectionPluginHandler::CreateCollectionPluginL 0x%08x uid 0x%08x",
       
   279                this, aUid.iUid);
       
   280 
       
   281     return p;
       
   282     }
       
   283 
       
   284 // ----------------------------------------------------------------------------
       
   285 // CMPXCollectionPluginHandler::LoadedPluginIndex
       
   286 // ----------------------------------------------------------------------------
       
   287 //
       
   288 TInt CMPXCollectionPluginHandler::LoadedPluginIndex(const TUid& aUid)
       
   289     {
       
   290     TInt index(KErrNotFound);
       
   291 
       
   292     for (TInt i = iLoadedPlugins.Count(); --i >= 0; )
       
   293         {
       
   294         if (iLoadedPlugins[i]->Uid() == aUid)
       
   295             {
       
   296             index = i;
       
   297             break;
       
   298             }
       
   299         }
       
   300 
       
   301     return index;
       
   302     }
       
   303 
       
   304 // ----------------------------------------------------------------------------
       
   305 // CMPXCollectionPluginHandler::UnloadPlugin
       
   306 // ----------------------------------------------------------------------------
       
   307 //
       
   308 void CMPXCollectionPluginHandler::UnloadPlugin(TInt aIndex)
       
   309     {
       
   310     MPX_DEBUG3("===>CMPXCollectionPluginHandler::UnloadPlugin 0x%08x index 0x%08x",
       
   311                this, aIndex);
       
   312     CMPXCollectionPlugin* p = iLoadedPlugins[aIndex];
       
   313     TRAP_IGNORE(p->CommandL(EMcCmdClose));
       
   314     iLoadedPlugins.Remove(aIndex);
       
   315     delete p;
       
   316     MPX_DEBUG3("<===CMPXCollectionPluginHandler::UnloadPlugin 0x%08x index 0x%08x",
       
   317                this, aIndex);
       
   318     }
       
   319 
       
   320 // End of file