alfwidgetutils/src/alffactorypluginloaderimpl.cpp
branchRCL_3
changeset 20 0e9bb658ef58
parent 0 e83bab7cf002
equal deleted inserted replaced
19:4ea6f81c838a 20:0e9bb658ef58
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Encapsulates factory plugin loading mechanism
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <ecom/ecom.h>
       
    21 //#include <alf/alfecompluginfactoryuid.rh>
       
    22 #include <alf/ialffactoryplugin.h>
       
    23 #include <string.h>
       
    24 #include <memory>
       
    25 #include <osn/osnnew.h>
       
    26 #include <stdexcept>
       
    27 
       
    28 #include "alf/alfecompluginfactoryuid.rh"
       
    29 #include "alffactorypluginloaderimpl.h"
       
    30 
       
    31 using namespace std;
       
    32 
       
    33 namespace Alf
       
    34     {
       
    35 
       
    36 
       
    37 
       
    38 class AlfFactoryPluginMap
       
    39     {
       
    40 public:
       
    41     AlfFactoryPluginMap();
       
    42     ~AlfFactoryPluginMap();
       
    43 
       
    44     /**
       
    45      * Owned factory plugin.
       
    46      */
       
    47     IAlfFactoryPlugin*  mFactoryPlugin;
       
    48     /**
       
    49      * ECom destructor handle.
       
    50      */
       
    51     int    mDtorKey;
       
    52     };
       
    53 
       
    54 static bool loadPluginIntoMap(
       
    55     AlfFactoryPluginMap*& aMap,
       
    56     const char* aProduct)
       
    57     {
       
    58     TEComResolverParams resolverParams;
       
    59     resolverParams.SetDataType(TPtrC8((TUint8*)aProduct));
       
    60     resolverParams.SetWildcardMatch(ETrue);
       
    61 
       
    62     TAny* plugin = NULL;
       
    63     TUid tmpDtor;
       
    64 
       
    65     TRAPD(err,plugin = REComSession::CreateImplementationL(
       
    66                            TUid::Uid(KFactoryPluginUid),
       
    67                            tmpDtor,resolverParams))
       
    68 
       
    69 
       
    70     if (!err)
       
    71         {
       
    72         aMap->mDtorKey = tmpDtor.iUid;
       
    73         aMap->mFactoryPlugin = reinterpret_cast<IAlfFactoryPlugin*>(
       
    74                                                             plugin);
       
    75         return true;
       
    76         }
       
    77 
       
    78     return false;
       
    79     }
       
    80 
       
    81 AlfFactoryPluginMap::AlfFactoryPluginMap()
       
    82         :mFactoryPlugin(0),mDtorKey(0)
       
    83     {
       
    84 
       
    85     }
       
    86 
       
    87 AlfFactoryPluginMap::~AlfFactoryPluginMap()
       
    88     {
       
    89     if (mFactoryPlugin)
       
    90         {
       
    91         REComSession::DestroyedImplementation(TUid::Uid(mDtorKey));
       
    92         delete mFactoryPlugin;
       
    93         }
       
    94     }
       
    95 
       
    96 AlfFactoryPluginLoaderImpl::AlfFactoryPluginLoaderImpl()
       
    97     {
       
    98 
       
    99     }
       
   100 
       
   101 AlfFactoryPluginLoaderImpl::~AlfFactoryPluginLoaderImpl()
       
   102     {
       
   103     mFactoryPluginList.clear();
       
   104 
       
   105     }
       
   106 
       
   107 IAlfFactoryPlugin* AlfFactoryPluginLoaderImpl::load(
       
   108     const char*  aLoadId)
       
   109     {
       
   110     IAlfFactoryPlugin* ret(0);
       
   111     IAlfFactoryPlugin* tmp(0);
       
   112     // Do we have it already?
       
   113     unsigned int itemCount(mFactoryPluginList.count());
       
   114 
       
   115     for (int i=0;i<itemCount && !ret;i++)
       
   116         {
       
   117         tmp = mFactoryPluginList.at(i)->mFactoryPlugin;
       
   118         int productCount = tmp->productCount();
       
   119         for (int j=0;j<productCount && !ret;j++)
       
   120             {
       
   121             if (!strcmp(tmp->productInfo(j),aLoadId ))
       
   122                 {
       
   123                 ret = tmp;
       
   124                 }
       
   125             }
       
   126         }
       
   127     if (!ret)
       
   128         {
       
   129         auto_ptr<AlfFactoryPluginMap> mapPtr(new(EMM)AlfFactoryPluginMap());
       
   130         AlfFactoryPluginMap* map = mapPtr.get();
       
   131 
       
   132         if (loadPluginIntoMap(map,aLoadId))
       
   133             {
       
   134             ret = mapPtr->mFactoryPlugin;
       
   135             mFactoryPluginList.resize(itemCount+1);
       
   136             mFactoryPluginList.insert(itemCount,map);
       
   137 
       
   138             mapPtr.release();
       
   139 
       
   140             }
       
   141 
       
   142         }
       
   143 
       
   144     return ret;
       
   145 
       
   146     }
       
   147     
       
   148     }
       
   149 
       
   150 // End of File