upnpframework/upnpextensionpluginif/src/upnppluginloader.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 2006-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:  Implements CUPnPPluginLoader class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <ecom/ecom.h>
       
    20 #include <ecom/implementationinformation.h>
       
    21 
       
    22 // upnpframework / home media extension api
       
    23 #include <upnpplugininterface.h>
       
    24 
       
    25 // component internal
       
    26 #include "upnppluginloaderobserver.h"
       
    27 #include "upnppluginloader.h"
       
    28 
       
    29 // log facility
       
    30 _LIT( KComponentLogfile, "upnpextensionpluginif.txt");
       
    31 #include "upnplog.h"
       
    32 
       
    33 #ifdef __UPNP_CONSOLE_MT__
       
    34 static const TUid KTestPluginId = { 0x20009C9D };
       
    35 #endif // __UPNP_CONSOLE_MT__
       
    36 
       
    37 //---------------------------------------------------------------------------
       
    38 // CUPnPPluginLoader::NewL
       
    39 // Construction method.
       
    40 //---------------------------------------------------------------------------
       
    41 EXPORT_C CUPnPPluginLoader* CUPnPPluginLoader::NewL(
       
    42     MUPnPPluginLoaderObserver& aLoaderObserver)
       
    43     {
       
    44     __LOG("CUPnPPluginLoader::NewL");
       
    45 
       
    46     CUPnPPluginLoader* self = 
       
    47         new( ELeave ) CUPnPPluginLoader(aLoaderObserver);
       
    48     return self;
       
    49     }
       
    50 
       
    51 //---------------------------------------------------------------------------
       
    52 // CUPnPPluginLoader::CUPnPPluginLoader
       
    53 // Default constructor. Sets the iLoaderObserver
       
    54 //---------------------------------------------------------------------------
       
    55 CUPnPPluginLoader::CUPnPPluginLoader(MUPnPPluginLoaderObserver&
       
    56                                                         aLoaderObserver)
       
    57     {
       
    58     __LOG( "CUPnPPluginLoader::CUPnPPluginLoader" );
       
    59 
       
    60     iLoaderObserver = &aLoaderObserver;
       
    61     }
       
    62 
       
    63 //---------------------------------------------------------------------------
       
    64 // CUPnPPluginLoader::~CUPnPPluginLoader
       
    65 // Destroys all the plugins
       
    66 //---------------------------------------------------------------------------
       
    67 EXPORT_C CUPnPPluginLoader::~CUPnPPluginLoader()
       
    68     {
       
    69     __LOG( "CUPnPPluginLoader::~CUPnPPluginLoader" );
       
    70 
       
    71     for (TInt i=0;i<iPluginArray.Count();i++) 
       
    72         {
       
    73         delete iPluginArray[i];
       
    74         }
       
    75 
       
    76     iPluginArray.Close();
       
    77     REComSession::FinalClose();
       
    78     }
       
    79 
       
    80 //---------------------------------------------------------------------------
       
    81 // CUPnPPluginLoader::CreatePluginsL
       
    82 // Creates all plugins which implement CUPnPPluginInterface
       
    83 //---------------------------------------------------------------------------
       
    84 EXPORT_C const RPointerArray<CUPnPPluginInterface>& 
       
    85     CUPnPPluginLoader::CreatePluginsL()
       
    86     {
       
    87     __LOG( "CUPnPPluginLoader::CreatePluginsL" );
       
    88 
       
    89     CImplementationInformation* implInfo = NULL;
       
    90     RImplInfoPtrArray implArray;
       
    91 
       
    92     REComSession::ListImplementationsL(interfaceUid,implArray);
       
    93     for(TInt i=0;i<implArray.Count();i++)
       
    94         {
       
    95         implInfo = implArray[i];
       
    96        
       
    97         if( implInfo->VendorId() == VID_DEFAULT
       
    98 #ifdef __UPNP_CONSOLE_MT__
       
    99             // In case of module testing load only our test plugin
       
   100             && implInfo-> ImplementationUid().iUid == KTestPluginId.iUid
       
   101 #endif // __UPNP_CONSOLE_MT__
       
   102         )
       
   103             {
       
   104            CUPnPPluginInterface* interface = NULL;           
       
   105            interface = CUPnPPluginInterface::NewL
       
   106                       ( implInfo->ImplementationUid(), *this );
       
   107            
       
   108            CleanupStack::PushL( interface );  
       
   109            // interface ownership is transfered and 
       
   110            // iPluginArray will handle the destroying of interface.
       
   111            iPluginArray.AppendL( interface );           
       
   112            CleanupStack::Pop( interface );
       
   113             }
       
   114         else
       
   115             {
       
   116             __LOG( "CUPnPPluginLoader::CreatePluginsL - \
       
   117 Invalid plugin vendor id" );
       
   118             }
       
   119         }
       
   120     implArray.ResetAndDestroy();
       
   121     implArray.Close();
       
   122     return iPluginArray;
       
   123     }
       
   124 
       
   125 //---------------------------------------------------------------------------
       
   126 // CUPnPPluginLoader::DeletePlugin
       
   127 // Deletes plugin from iPluginArray
       
   128 //---------------------------------------------------------------------------
       
   129 EXPORT_C void CUPnPPluginLoader::DeletePlugin( TInt aPluginIndex )
       
   130     {
       
   131     __LOG( "CUPnPPluginLoader::DeletePlugin" );
       
   132     __ASSERTD( aPluginIndex >= 0, __FILE__, __LINE__ );
       
   133     __ASSERTD( aPluginIndex < iPluginArray.Count(), __FILE__, __LINE__ );
       
   134 
       
   135     if ( aPluginIndex < iPluginArray.Count() )
       
   136         {
       
   137         delete iPluginArray[aPluginIndex];
       
   138         iPluginArray.Remove(aPluginIndex);
       
   139         }
       
   140     }
       
   141 
       
   142 //---------------------------------------------------------------------------
       
   143 // CUPnPPluginLoader::ExtensionEvent
       
   144 // From base class MUPnPPluginObserver
       
   145 // Handles the events which come from plugins
       
   146 //---------------------------------------------------------------------------
       
   147 void CUPnPPluginLoader::ExtensionEvent(const TExtensionEvent& aEvent) 
       
   148     {
       
   149     __LOG( "CUPnPPluginLoader::ExtensionEvent" );
       
   150 
       
   151     switch ( aEvent )
       
   152         {
       
   153         case EExtensionEnabled:
       
   154             {
       
   155             // the extension is enabled by default - no need to call 
       
   156             // explicitly
       
   157             // NOT IMPLEMENTED
       
   158             break;
       
   159             }
       
   160         case EExtensionDisabled:
       
   161             {
       
   162             // when called, disables the item in the list, cannot execute
       
   163             // NOT IMPLEMENTED
       
   164             break;
       
   165             }
       
   166         case EExtensionIconChanged:
       
   167             {
       
   168             // will call GetI1con again, and redraw
       
   169             iLoaderObserver->PluginsUpdated();
       
   170             break;
       
   171             }
       
   172         case EExtensionTitleChanged:
       
   173             {
       
   174             // will call GetTitle again, and redraw
       
   175             iLoaderObserver->PluginsUpdated();
       
   176             break;
       
   177             }
       
   178         case EExtensionSecondaryTextChanged:
       
   179             {
       
   180             // will call GetSubTitle again, and redraw
       
   181             iLoaderObserver->PluginsUpdated();
       
   182             break;
       
   183             }
       
   184         case EExtensionClosed:
       
   185             {
       
   186             // extension which was ExecuteL'd, has been closed.
       
   187             // NOT IMPLEMENTED
       
   188             break;
       
   189             }
       
   190         default:
       
   191             {
       
   192             break;
       
   193             }
       
   194         }
       
   195     }
       
   196 
       
   197 // end of file