networkcontrol/ipcprshim/src/shimcprfactory.cpp
branchRCL_3
changeset 58 8d540f55e491
parent 57 abbed5a4b42a
child 59 e36178c55292
child 63 425d8f4f7fa5
equal deleted inserted replaced
57:abbed5a4b42a 58:8d540f55e491
     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 // SHIMCPRFACTORY.H
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <ecom/ecom.h>
       
    19 #include <implementationproxy.h>
       
    20 #include "shimcprfactory.h"	// for CConnectionProviderFactoryShim
       
    21 
       
    22 #include "connectionSelectorShim.h"
       
    23 #include "shimcpr.h"
       
    24 #include "shimnifmansconn.h"
       
    25 #include "idquerynetmsg.h"
       
    26 #include <nifman.h>
       
    27 #ifdef SYMBIAN_NETWORKING_UMTSR5
       
    28 #include <esockmessages.h>
       
    29 #endif // #ifdef SYMBIAN_NETWORKING_UMTSR5	
       
    30 
       
    31 
       
    32 const TUint KShimConnectionProviderImplementationUid = 0x102070FF;
       
    33 /**
       
    34 Data required for instantiating ECOM Plugin
       
    35 */
       
    36 const TImplementationProxy ImplementationTable[] = 
       
    37 	{
       
    38 	IMPLEMENTATION_PROXY_ENTRY(KShimConnectionProviderImplementationUid, CConnectionProviderFactoryShim::NewL),
       
    39 	};
       
    40 
       
    41 
       
    42 /**
       
    43 ECOM Implementation Factory
       
    44 */
       
    45 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
       
    46     {
       
    47     aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
       
    48 
       
    49     return ImplementationTable;
       
    50     }
       
    51 
       
    52 CConnectionProviderFactoryShim* CConnectionProviderFactoryShim::NewL(TAny* aConstructionParameters)
       
    53 	{
       
    54 	CConnectionProviderFactoryShim* ptr = new (ELeave) CConnectionProviderFactoryShim(KShimConnectionProviderFactoryId, *(reinterpret_cast<CConnectionFactoryContainer*>(aConstructionParameters)));
       
    55 	CleanupStack::PushL(ptr);
       
    56 	ptr->ConstructL();
       
    57 	CleanupStack::Pop(ptr);
       
    58 	return ptr;
       
    59 	}
       
    60    
       
    61 void CConnectionProviderFactoryShim::ConstructL()
       
    62 	{//create a provider session for global tasks (enumerate connections/all interface notification....)
       
    63     iNifmanSession = Nif::NewConnectionL(this, 0);
       
    64     iNifmanSession->AllInterfaceNotificationL();
       
    65 	}
       
    66 // Destructor
       
    67 CConnectionProviderFactoryShim::~CConnectionProviderFactoryShim()
       
    68 	{
       
    69 	delete iNifmanSession;
       
    70 	}
       
    71    
       
    72 // Constructor
       
    73 CConnectionProviderFactoryShim::CConnectionProviderFactoryShim(TUint aFactoryId, CConnectionFactoryContainer& aParentContainer) :
       
    74 	CConnectionProviderFactoryBase( aFactoryId, aParentContainer )
       
    75 	{
       
    76 	}
       
    77 
       
    78 #ifdef SYMBIAN_NETWORKING_UMTSR5
       
    79 // Sets the IAP lock status
       
    80 void CConnectionProviderFactoryShim::SetIAPLockStatus(TBool aLockStatus, TInt aLockedIAP)
       
    81 	{
       
    82 	iIsIAPLocked = aLockStatus;
       
    83 	iLockedIAP = aLockedIAP;
       
    84 	}
       
    85 // Gets the IAP lock status
       
    86 void CConnectionProviderFactoryShim::GetIAPLockStatus(TBool &aLockStatus, TInt &aLockedIAP)
       
    87 	{
       
    88 	aLockStatus = iIsIAPLocked;
       
    89 	aLockedIAP = iLockedIAP;
       
    90 	}
       
    91 	
       
    92 #endif // #ifdef SYMBIAN_NETWORKING_UMTSR5	
       
    93 
       
    94 CConnectionProviderBase* CConnectionProviderFactoryShim::DoCreateProviderL()
       
    95 	{
       
    96 #ifdef SYMBIAN_NETWORKING_UMTSR5	
       
    97 	CConnectionProviderShim * shimProv = CConnectionProviderShim::NewL(*this);
       
    98 	shimProv->SetFactoryIfactory(this);
       
    99 	return shimProv;
       
   100 #else
       
   101 	return CConnectionProviderShim::NewL(*this);
       
   102 #endif // #ifdef SYMBIAN_NETWORKING_UMTSR5		
       
   103 	}
       
   104    
       
   105 MProviderSelector* CConnectionProviderFactoryShim::DoSelectProvider( Meta::SMetaData& aPreferences, ISelectionNotify& aSelectionNotify, const RMessagePtr2* aMessage )
       
   106 	{
       
   107 	//create self-destructing object
       
   108 	CConnectionSelectorShim* selector = new CConnectionSelectorShim(aSelectionNotify);
       
   109 	if (!selector)
       
   110 		{
       
   111 		aSelectionNotify.SelectComplete(NULL,KErrNoMemory);
       
   112 		aSelectionNotify.Detach();
       
   113 		}
       
   114 	else 
       
   115 		{
       
   116 		#ifdef SYMBIAN_NETWORKING_UMTSR5	
       
   117 		selector->SetFactoryIface(this);	
       
   118 		#endif
       
   119 		if ( selector->Select(aPreferences, aMessage) != KErrNone )
       
   120 			{
       
   121 			selector = NULL;
       
   122 			}	
       
   123 		}
       
   124 		
       
   125 		
       
   126 	return selector;
       
   127 	}
       
   128    
       
   129 MProviderSelector* CConnectionProviderFactoryShim::DoSelectNextLayerProvider( Meta::SMetaData& /*aPreferences*/, ISelectionNotify& /*aSelectionNotify*/, const RMessagePtr2* /*aMessage*/ )
       
   130 	{	
       
   131 	return NULL;
       
   132 	}
       
   133 	
       
   134 void CConnectionProviderFactoryShim::DoEnumerateConnectionsL(RPointerArray<TConnectionInfo>& aConnectionInfoPtrArray)
       
   135 	{
       
   136     iNifmanSession->EnumerateConnectionsL(aConnectionInfoPtrArray);
       
   137 	}
       
   138 
       
   139 //MConnectionNotify interface to catch the global events
       
   140 void CConnectionProviderFactoryShim::SelectionComplete(TInt /*aError*/, const TDesC8& /*aSelectionInfo*/)
       
   141 	{
       
   142 	
       
   143 	ASSERT(NULL);//it's never to happen
       
   144 	}
       
   145 	
       
   146 void CConnectionProviderFactoryShim::ConnectionError(TInt /*aError*/)
       
   147 	{
       
   148 	ASSERT(NULL);//it's never to happen
       
   149 	}
       
   150 	
       
   151 void CConnectionProviderFactoryShim::LinkLayerOpen(TInt /*aError*/)
       
   152 	{
       
   153 	ASSERT(NULL);//it's never to happen
       
   154 	}
       
   155 	
       
   156 void CConnectionProviderFactoryShim::LinkLayerClosed(TInt /*aError*/)
       
   157 	{
       
   158 	ASSERT(NULL);//it's never to happen
       
   159 	}
       
   160 	
       
   161 void CConnectionProviderFactoryShim::ProgressNotification(TInt /*aStage*/, TInt /*aError*/)
       
   162 	{
       
   163 	ASSERT(NULL);//it's never to happen
       
   164 	}
       
   165 	
       
   166 void CConnectionProviderFactoryShim::ProgressNotification(TSubConnectionUniqueId /*aSubConnectionUniqueId*/, TInt /*aStage*/, TInt /*aError*/)
       
   167 	{
       
   168 	ASSERT(NULL);//it's never to happen
       
   169 	}
       
   170 	
       
   171 void CConnectionProviderFactoryShim::ServiceChangeNotification(TUint32 /*aId*/, const TDesC& /*aType*/)
       
   172 	{
       
   173 	ASSERT(NULL);//it's never to happen
       
   174 	}
       
   175 	
       
   176 void CConnectionProviderFactoryShim::InterfaceStateChangeNotification(TDesC8& aInfo)
       
   177 	{
       
   178 	TInt count = iConnectionFactoryNotify.Count();
       
   179 	for (TInt n = 0; n < count; n++)
       
   180 		{
       
   181 		iConnectionFactoryNotify[n].InterfaceStateChange(aInfo);
       
   182 		}
       
   183 	}
       
   184 	
       
   185 void CConnectionProviderFactoryShim::NotifyDataSent(TSubConnectionUniqueId /*aSubConnectionUniqueId*/, TUint /*aUplinkVolume*/)
       
   186 	{
       
   187 	ASSERT(NULL);//it's never to happen
       
   188 	}
       
   189 	
       
   190 void CConnectionProviderFactoryShim::NotifyDataReceived(TSubConnectionUniqueId /*aSubConnectionUniqueId*/, TUint /*aDownlinkVolume*/)
       
   191 	{
       
   192 	ASSERT(NULL);//it's never to happen
       
   193 	}
       
   194 	
       
   195 void CConnectionProviderFactoryShim::SubConnectionEvent(const TSubConnectionEvent& /*aSubConnectionEvent*/)
       
   196 	{
       
   197 	ASSERT(NULL);//it's never to happen
       
   198 	}
       
   199 	
       
   200 
       
   201 /**
       
   202 Define the factory query to find out particular CSubConnectionLinkShimClient object based on CConnection address 
       
   203 */
       
   204 
       
   205 class XShimFactoryQuery : public MCommsFactoryQuery
       
   206 	{
       
   207 	friend class CConnectionProviderFactoryShim;
       
   208 	
       
   209 public:
       
   210 	explicit XShimFactoryQuery( NetMessages::CTypeIdQuery& aQuery ) :
       
   211 		iQuery(aQuery),
       
   212 		iClient(NULL)
       
   213 		{
       
   214 		}
       
   215 
       
   216 protected:
       
   217 	NetMessages::CTypeIdQuery& iQuery;
       
   218 	CSubConnectionLinkShimClient* iClient;
       
   219 
       
   220 public:
       
   221 	virtual TMatchResult Match( TFactoryObjectInfo& aInfo );
       
   222 	};
       
   223 
       
   224 //This method is called for each instance of particular class being managed by CommsFactory framework
       
   225 MCommsFactoryQuery::TMatchResult XShimFactoryQuery::Match( TFactoryObjectInfo& aInfo )
       
   226 	{
       
   227 	CConnectionProviderShim* connectionProvider = static_cast<CConnectionProviderShim*>(aInfo.iInfo.iFactoryObject);
       
   228 	ASSERT(connectionProvider);
       
   229 	//call the CNifManSubConnectionShim interface to do the job
       
   230 	iClient = connectionProvider->QuerySubSessions(iQuery.iTypeId, reinterpret_cast<CConnection*> (iQuery.iHandle));
       
   231 	
       
   232 	return iClient ? MCommsFactoryQuery::EMatch : MCommsFactoryQuery::EContinue;
       
   233 	}
       
   234 	
       
   235 /**	Handles incoming messages
       
   236 
       
   237 @param aNetMessage Messsge reference
       
   238 @return KErrNone|KErrNotFound|KErrNotSupported
       
   239 @return if object found passes its pointer to the aNetMessasge object
       
   240 */
       
   241 TInt CConnectionProviderFactoryShim::DoReceiveMessage( NetMessages::CMessage& aNetMessage )
       
   242 {
       
   243 STypeId tid = STypeId::CreateSTypeId(NetMessages::KInterfaceUid, NetMessages::ETypeIdQueryId);
       
   244 NetMessages::CTypeIdQuery& query = static_cast<NetMessages::CTypeIdQuery&>(aNetMessage);
       
   245 TInt ret = KErrNotSupported;
       
   246 if (aNetMessage.GetTypeId() == tid && query.iUid == KShimCommsUid)
       
   247 	{
       
   248 	XShimFactoryQuery q(query);
       
   249 	ret = FindObject(q) ? KErrNone : KErrNotFound;
       
   250 	//carry the result back
       
   251 	query.iHandle = (TInt)(static_cast<MShimControlClient*>(q.iClient));
       
   252 	}
       
   253 return ret;
       
   254 }
       
   255 
       
   256