baseconnectionproviders/refcpr/src/ReferenceCPR_connProvFactory.cpp
branchRCL_3
changeset 25 9d7ce34704c8
equal deleted inserted replaced
24:00c6709d25aa 25:9d7ce34704c8
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Reference (empty) implementation file for a SubConnection Provider Factory
       
    15 //
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #include <implementationproxy.h>
       
    24 #include <ss_glob.h>
       
    25 
       
    26 #include "ReferenceCPR_connProv.h"
       
    27 #include "ReferenceCPR_connProvFactory.h"
       
    28 
       
    29 #ifdef _DEBUG
       
    30 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    31 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    32 _LIT(KSpecAssert_RefCprConProvFac, "RefCprConProvFac");
       
    33 #endif
       
    34 
       
    35 //-=========================================================
       
    36 // Data/functions required for instantiating ECOM Plugin
       
    37 //-=========================================================
       
    38 const TInt KReferenceConnectionProviderImplementationUid=0x102738D0;
       
    39 
       
    40 const TImplementationProxy ImplementationTable[] =
       
    41 	{
       
    42 	IMPLEMENTATION_PROXY_ENTRY(KReferenceConnectionProviderImplementationUid, CReferenceProviderFactory::NewL)
       
    43 	};
       
    44 
       
    45 /**
       
    46 ECOM Implementation Factory
       
    47 */
       
    48 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    49     {
       
    50     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    51     return ImplementationTable;
       
    52     }
       
    53 
       
    54 
       
    55 
       
    56 
       
    57 
       
    58 //-=========================================================
       
    59 // CReferenceProviderFactory
       
    60 //-=========================================================
       
    61 
       
    62 /**NewL is the actual ECOM Connection Provider interface implemented.
       
    63 ESOCK will call it to instantiate the factory and store it in the
       
    64 CConnectionProviderFactoryContainer.
       
    65 
       
    66 @param aConstructionParameters construction data passed by ECOM
       
    67 @returns pointer to a constructed factory
       
    68 */
       
    69 CReferenceProviderFactory* CReferenceProviderFactory::NewL(TAny* aParentContainer)
       
    70 	{
       
    71  	return new (ELeave) CReferenceProviderFactory(KReferenceConnectionProviderFactoryId,
       
    72  					*(reinterpret_cast<CConnectionFactoryContainer*>(aParentContainer)));
       
    73 	}
       
    74 
       
    75 /**C'tor
       
    76 @param aFactoryId - the id of this factory. The id should represent the type of subconnection
       
    77                     providers this factory can produce.
       
    78 @param aParentContainer - the factory container the new factory object should add itself to.
       
    79 */
       
    80 CReferenceProviderFactory::CReferenceProviderFactory(TUint aFactoryId, CConnectionFactoryContainer& aParentContainer)
       
    81 :CConnectionProviderFactoryBase(aFactoryId, aParentContainer)
       
    82 	{
       
    83 	}
       
    84 
       
    85 CConnectionProviderBase* CReferenceProviderFactory::DoCreateProviderL()
       
    86 	{
       
    87     return CReferenceConnectionProvider::NewL(*this);
       
    88 	}
       
    89 
       
    90 
       
    91 /**A sample/reference derivation of DoSelectProvider. The method is responsible for:
       
    92 - selecting an instance of the connection provider at this level of the connection provider stack.
       
    93 - determining the connection provider type at the layer below this
       
    94 - triggering the selection at the layer below.
       
    95 
       
    96 @param aPreferences     - connection preferences for the connection to be selected.
       
    97 @param aSelectionNotify - the notify interface (see class ISelectionNotify and see its usage
       
    98                           in the implementation file).
       
    99 @param aMessage         - the orignal IPC message.
       
   100 @returns pointer to a MProviderSelector object. The pointer can be used by the caller to cancel the
       
   101 selection. Please note, this is a self-destructing object - the caller should assume the pointer
       
   102 becomes invalid after the selection.
       
   103 */
       
   104 MProviderSelector* CReferenceProviderFactory::DoSelectProvider( Meta::SMetaData& aPreferences, ISelectionNotify& aSelectionNotify, const RMessagePtr2* aMessage )
       
   105 	{
       
   106 	CReferenceSelector* selector = new CReferenceSelector(aSelectionNotify,*this);
       
   107 	if (NULL == selector)
       
   108 		{
       
   109 		aSelectionNotify.SelectComplete(NULL, KErrNoMemory);
       
   110 		}
       
   111 	else if (selector->Select(aPreferences, aMessage) != KErrNone)
       
   112 		{
       
   113 		selector = NULL;
       
   114 		}
       
   115 	return selector;
       
   116 
       
   117   	}
       
   118 
       
   119 /**A sample/reference derivation of DoSelectNextLayerProvider. The method is responsible for:
       
   120 - determining the connection provider type at the layer below this
       
   121 - triggering the selection at the layer below.
       
   122 One can observe that DoSelectNextLayerProvider has a subset of the responsibilities held by
       
   123 DoSelectNextLayerProvider.
       
   124 
       
   125 @param aPreferences     - connection preferences for the connection to be selected.
       
   126 @param aSelectionNotify - the notify interface (see class ISelectionNotify and see its usage
       
   127                           in the implementation file).
       
   128 @param aMessage         - the orignal IPC message.
       
   129 @returns pointer to a MProviderSelector object. The pointer can be used by the caller to cancel the
       
   130 selection. Please note, this is a self-destructing object - the caller should assume the pointer
       
   131 becomes invalid after the selection.
       
   132 */
       
   133 MProviderSelector* CReferenceProviderFactory::DoSelectNextLayerProvider( Meta::SMetaData& aPreferences, ISelectionNotify& aSelectionNotify, const RMessagePtr2* aMessage )
       
   134 	{
       
   135 	//This method should determine the type (factoryId) of the connection below this layer.
       
   136 	TInt factoryId = KInvalidFactoryId;
       
   137 	//When done
       
   138 	CConnectionFactoryContainer* connectionFactories = SockManGlobals::Get()->iConnectionFactories;
       
   139 	__ASSERT_DEBUG(connectionFactories, User::Panic(KSpecAssert_RefCprConProvFac, 1));
       
   140 	CConnectionProviderFactoryBase* factory = connectionFactories->FindFactory(factoryId);
       
   141 
       
   142 	return factory->SelectProvider(aPreferences, aSelectionNotify, aMessage);
       
   143 	}
       
   144 
       
   145 void CReferenceProviderFactory::DoEnumerateConnectionsL(RPointerArray<TConnectionInfo>& /*aConnectionInfoPtrArray*/)
       
   146 	{
       
   147 	//TODO: enumerate connections.
       
   148 	}
       
   149 
       
   150 
       
   151 
       
   152 
       
   153 
       
   154 
       
   155 
       
   156 
       
   157 //-=========================================================
       
   158 // CReferenceSelector
       
   159 //-=========================================================
       
   160 
       
   161 CReferenceSelector::CReferenceSelector(ISelectionNotify& aNotify, CReferenceProviderFactory& aFactory)
       
   162 :iNotify(aNotify),
       
   163  iFactory(aFactory),
       
   164  iNextLayerSelector(NULL)
       
   165 	{
       
   166 	}
       
   167 
       
   168 //CReferenceSelector
       
   169 TInt CReferenceSelector::Cancel()
       
   170 	{
       
   171 	//TODO: cancel the selection
       
   172     if (iNextLayerSelector)
       
   173         {
       
   174         return iNextLayerSelector->Cancel();
       
   175         }
       
   176     return KErrNotReady;
       
   177 	}
       
   178 
       
   179 TInt CReferenceSelector::Cancel(TInt aReason, const RMessage2* aMessage)
       
   180 	{
       
   181 	//TODO: cancel the selection
       
   182     if (iNextLayerSelector)
       
   183         {
       
   184         return iNextLayerSelector->Cancel(aReason, aMessage);
       
   185         }
       
   186     return KErrNotReady;
       
   187 	}
       
   188 
       
   189 TInt CReferenceSelector::Select(Meta::SMetaData& aPreferences, const RMessagePtr2* aMessage)
       
   190     {
       
   191 	//Prepare ISelectionNotify. MProviderSelector may choose the events it wishes to be notified
       
   192 	//about by implementing a subset of the possible upcalls. The list of the actually implemented
       
   193 	//is used to create an ISelectionNotify object (a loose function pointer holder) and passed
       
   194 	//to the factory below to perform the selection at the lower level.
       
   195 	ISelectionNotify selectNotify( this, TSelectionNotify<CReferenceSelector>::SelectComplete,
       
   196 	                                     TProgressNotify<CReferenceSelector>::ProgressNotification,
       
   197 	                                     TServiceChangeNotify<CReferenceSelector>::ServiceChangeNotification,
       
   198 	                                     TLayerUp<CReferenceSelector>::LayerUp,
       
   199 	                                     TSubConnectionEventTmpl<CReferenceSelector>::SubConnectionEvent,
       
   200 	                                     TDetachNotify<CReferenceSelector>::Detach);
       
   201 
       
   202 	iNextLayerSelector = iFactory.SelectNextLayerProvider(aPreferences, selectNotify, aMessage);
       
   203 	return (iNextLayerSelector ? KErrNone : KErrNotReady);
       
   204     }
       
   205 
       
   206 
       
   207 void CReferenceSelector::SelectComplete(CConnectionProviderBase* aConnProvider, TInt aError)
       
   208     {
       
   209     CReferenceConnectionProvider* connProvider = NULL;
       
   210     if (aError == KErrNone)
       
   211         {
       
   212 	    __ASSERT_DEBUG(aConnProvider, User::Panic(KSpecAssert_RefCprConProvFac, 2));
       
   213         XConnectionFindSameLowerLayerQuery query(aConnProvider);
       
   214 
       
   215         TRAP( aError, connProvider = static_cast<CReferenceConnectionProvider*>(iFactory.FindOrCreateProviderL(query)));
       
   216         if (aError == KErrNone && connProvider->NextLayer() == NULL)
       
   217             {
       
   218             //the factory returned a new instance - must set the lower layer
       
   219             TRAP(aError,connProvider->JoinNextLayerL(aConnProvider));
       
   220             }
       
   221         }
       
   222     iNotify.SelectComplete(connProvider, aError);
       
   223     }
       
   224 
       
   225 void CReferenceSelector::ProgressNotification(TInt aStage, TInt aError)
       
   226     {
       
   227     iNotify.ProgressNotification(aStage, aError);
       
   228     }
       
   229 
       
   230 void CReferenceSelector::LayerUp(TInt aError)
       
   231 	{
       
   232     iNotify.LayerUp(aError);
       
   233 	}
       
   234 
       
   235 void CReferenceSelector::SubConnectionEvent(CSubConnectionProviderBase* aSubConnNextLayerProvider, const TSubConnectionEvent& aSubConnectionEvent)
       
   236 	{
       
   237 	iNotify.SubConnectionEvent(aSubConnNextLayerProvider, aSubConnectionEvent);
       
   238 	}
       
   239 
       
   240 void CReferenceSelector::ServiceChangeNotification(TUint32 aId, const TDesC& aType)
       
   241 	{
       
   242     iNotify.ServiceChangeNotification(aId, aType);
       
   243 	}
       
   244 
       
   245 void CReferenceSelector::Detach()
       
   246 	{
       
   247 	iNotify.Detach();
       
   248 	iNextLayerSelector = NULL;
       
   249 	delete this;
       
   250 	}
       
   251 
       
   252 CReferenceSelector::~CReferenceSelector()
       
   253     {
       
   254 	if (iNextLayerSelector)
       
   255 		{
       
   256 		iNextLayerSelector->Cancel();
       
   257 		}
       
   258     }
       
   259 
       
   260 
       
   261 
       
   262 
       
   263 //-=========================================================
       
   264 // XConnectionFindSameLowerLayerQuery
       
   265 //-=========================================================
       
   266 
       
   267 MCommsFactoryQuery::TMatchResult XConnectionFindSameLowerLayerQuery::Match( TFactoryObjectInfo& aProviderInfo )
       
   268 	{
       
   269 	CConnectionProviderBase* prov = static_cast<CConnectionProviderBase*>(aProviderInfo.iInfo.iFactoryObject);
       
   270 	return prov->NextLayer() == iConnectionProviderBase ? EMatch : EContinue;
       
   271 	}
       
   272