idlehomescreen/xmluirendering/utils/src/xnecomhandler.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  Handles ecom plugins
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "xnecomhandler.h"
       
    22 #include    "xnpanic.h"
       
    23 #include    "xnarray.h"
       
    24 #include    "xnpointerarraywithownership.h"
       
    25 #include    <utf.h>
       
    26 #include    <ecom/ecom.h>
       
    27 #include    <ecom/implementationinformation.h>
       
    28 #include    <f32file.h>
       
    29 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 //extern  ?external_data;
       
    32 
       
    33 // EXTERNAL FUNCTION PROTOTYPES  
       
    34 //extern ?external_function( ?arg_type,?arg_type );
       
    35 
       
    36 // CONSTANTS
       
    37 //const ?type ?constant_var = ?constant;
       
    38 
       
    39 // MACROS
       
    40 //#define ?macro ?macro_def
       
    41 
       
    42 // LOCAL CONSTANTS AND MACROS
       
    43 //const ?type ?constant_var = ?constant;
       
    44 //#define ?macro_name ?macro_def
       
    45 // MODULE DATA STRUCTURES
       
    46 //enum ?declaration
       
    47 //typedef ?declaration
       
    48 
       
    49 /**
       
    50 *  A struct used for holding an implementation pointer and notifying ecom of implementation destruction
       
    51 *  @since Series 90 2.0
       
    52 */
       
    53 struct CXnEcomHandler::CEcomItem : public CBase
       
    54     {
       
    55     CEcomItem(TUid aInterfaceUid, CBase* aPluginImpl, TUid aDestructorId) : iInterfaceUid(aInterfaceUid), iPluginImpl(aPluginImpl), iDestructorId(aDestructorId) 
       
    56         {
       
    57         }
       
    58     // plugin interface id
       
    59     TUid iInterfaceUid;
       
    60     // plugin implementation pointer
       
    61     CBase* iPluginImpl;
       
    62     // ecom destructor id
       
    63     TUid iDestructorId;
       
    64     // plugin type
       
    65     HBufC8* iType;
       
    66     // destructor
       
    67     ~CEcomItem()
       
    68         {
       
    69         delete iPluginImpl;
       
    70         delete iType;
       
    71         REComSession::DestroyedImplementation(iDestructorId);
       
    72         }
       
    73     };
       
    74 
       
    75 // LOCAL FUNCTION PROTOTYPES
       
    76 //?type ?function_name( ?arg_type, ?arg_type );
       
    77 
       
    78 // FORWARD DECLARATIONS
       
    79 //class ?FORWARD_CLASSNAME;
       
    80 
       
    81 // ============================= LOCAL FUNCTIONS ===============================
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // ?function_name ?description.
       
    85 // ?description
       
    86 // Returns: ?value_1: ?description
       
    87 //          ?value_n: ?description_line1
       
    88 //                    ?description_line2
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 //?type ?function_name(
       
    92 //    ?arg_type arg,  // ?description
       
    93 //    ?arg_type arg)  // ?description
       
    94 //    {
       
    95 
       
    96 //    ?code  // ?comment
       
    97 
       
    98     // ?comment
       
    99 //    ?code
       
   100 //    }
       
   101 
       
   102 
       
   103 // ============================ MEMBER FUNCTIONS ===============================
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CXnEcomHandler::CXnEcomHandler
       
   107 // C++ default constructor can NOT contain any code, that
       
   108 // might leave.
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 CXnEcomHandler::CXnEcomHandler()
       
   112     {
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CXnEcomHandler::ConstructL
       
   117 // Symbian 2nd phase constructor can leave.
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CXnEcomHandler::ConstructL()
       
   121     {
       
   122     }
       
   123 
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CXnEcomHandler::NewL
       
   127 // Two-phased constructor.
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 EXPORT_C CXnEcomHandler* CXnEcomHandler::NewL()
       
   131     {
       
   132     CXnEcomHandler* self = new( ELeave ) CXnEcomHandler;
       
   133     
       
   134     CleanupStack::PushL( self );
       
   135     self->ConstructL();
       
   136     CleanupStack::Pop();
       
   137 
       
   138     return self;
       
   139     }
       
   140 
       
   141     
       
   142 // Destructor
       
   143 CXnEcomHandler::~CXnEcomHandler()
       
   144     {
       
   145     iPlugins.ResetAndDestroy();
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CXnEcomHandler::PluginsL
       
   150 // Get pointers to plugins
       
   151 // -----------------------------------------------------------------------------
       
   152 EXPORT_C void CXnEcomHandler::PluginsL(TUid aInterfaceUid, const TDesC8& aType, CXnArray& aFunctions)
       
   153     {
       
   154     TBool cached = EFalse;
       
   155     for (TInt i = iPlugins.Count() - 1 ; i >= 0; --i)
       
   156         {
       
   157         CEcomItem* tmp = iPlugins[i];
       
   158         if (tmp->iInterfaceUid == aInterfaceUid
       
   159         && *(tmp->iType) == aType)
       
   160             {
       
   161             cached = ETrue;
       
   162             if(aFunctions.Container().Append(tmp->iPluginImpl) != KErrNone)
       
   163                 {
       
   164                 User::Leave(KXnErrAppendingPluginFailed);
       
   165                 }
       
   166             }
       
   167         }
       
   168     if (cached)
       
   169         {
       
   170         return;
       
   171         }
       
   172     HBufC8* defaultData = aType.AllocL();
       
   173     CleanupStack::PushL(defaultData);
       
   174     TEComResolverParams resolverParams;
       
   175     resolverParams.SetDataType(*defaultData);
       
   176     RImplInfoPtrArray implInfoArray;
       
   177     CXnPointerArrayWithOwnership* safeArray = CXnPointerArrayWithOwnership::NewL();
       
   178     CleanupStack::PushL(safeArray);
       
   179     REComSession::ListImplementationsL(aInterfaceUid, resolverParams, implInfoArray);        
       
   180 //    REComSession::ListImplementationsL(aInterfaceUid, implInfoArray);        
       
   181     TInt count = implInfoArray.Count();
       
   182     for (TInt i = implInfoArray.Count() - 1; i >= 0; --i)
       
   183         {
       
   184         CImplementationInformation* impl = implInfoArray[i];
       
   185         (safeArray->Container()).Insert(impl, 0); 
       
   186         }
       
   187     if ((safeArray->Container()).Count() != count)
       
   188         {
       
   189         (safeArray->Container()).Reset();
       
   190         implInfoArray.ResetAndDestroy();
       
   191         User::Leave(KErrNoMemory);
       
   192         }
       
   193     implInfoArray.Reset();        
       
   194     for (TInt i = safeArray->Container().Count() - 1; i >= 0; --i)
       
   195         {
       
   196         CImplementationInformation* impl = static_cast<CImplementationInformation*>(safeArray->Container()[i]);
       
   197         TUid dtorIdKey;
       
   198         CBase* plugin = (CBase*) REComSession::CreateImplementationL(impl->ImplementationUid(), dtorIdKey);
       
   199         CleanupStack::PushL(plugin);
       
   200         CEcomItem* tmp = new (ELeave) CEcomItem(aInterfaceUid, plugin, dtorIdKey);
       
   201         CleanupStack::PushL(tmp);
       
   202         tmp->iType = aType.AllocL();
       
   203         //tmp->iType = impl->DataType().AllocL();
       
   204         if(iPlugins.Append(tmp) != KErrNone)
       
   205             {
       
   206             User::Leave(KXnErrAppendingPluginFailedAgain);
       
   207             }
       
   208         CleanupStack::Pop(tmp);
       
   209         CleanupStack::Pop(plugin);        
       
   210         }
       
   211     for (TInt i = iPlugins.Count() - 1 ; i >= 0; --i)
       
   212         {
       
   213         CEcomItem* tmp = iPlugins[i];
       
   214         if (tmp->iInterfaceUid == aInterfaceUid
       
   215         && *(tmp->iType) == aType)
       
   216             {
       
   217             cached = ETrue;
       
   218             if(aFunctions.Container().Append(tmp->iPluginImpl) != KErrNone)
       
   219                 {
       
   220                 User::Leave(KXnErrAppendingPluginImplFailed);
       
   221                 }
       
   222             }
       
   223         }
       
   224     CleanupStack::PopAndDestroy(safeArray);        
       
   225     CleanupStack::PopAndDestroy(defaultData);
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // ?classname::?member_function
       
   230 // ?implementation_description
       
   231 // (other items were commented in a header).
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 //?type ?classname::?member_function(
       
   235 //    ?arg_type arg,
       
   236 //    ?arg_type arg )
       
   237 //    {
       
   238     
       
   239 //    ?code
       
   240     
       
   241 //    }
       
   242 
       
   243 
       
   244 	
       
   245 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // ?function_name implements...
       
   249 // ?implementation_description.
       
   250 // Returns: ?value_1: ?description
       
   251 //          ?value_n: ?description
       
   252 //                    ?description
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 //?type  ?function_name(
       
   256 //    ?arg_type arg,  // ?description
       
   257 //    ?arg_type arg )  // ?description
       
   258 //    {
       
   259 
       
   260 //    ?code
       
   261 
       
   262 //    }
       
   263 
       
   264 
       
   265 //  End of File