genericopenlibs/openenvcore/backend/src/corebackend/localif.cpp
branchRCL_3
changeset 54 4332f0f7be53
parent 53 9d9daa0f4b62
child 56 acd3cd4aaceb
equal deleted inserted replaced
53:9d9daa0f4b62 54:4332f0f7be53
    80 #endif
    80 #endif
    81 		}
    81 		}
    82 
    82 
    83 // Construction of Backend Object which is going to be singleton object for the process
    83 // Construction of Backend Object which is going to be singleton object for the process
    84 EXPORT_C CLocalSystemInterface::CLocalSystemInterface() : iOpenDirList(CLocalSystemInterface::KDirGran),
    84 EXPORT_C CLocalSystemInterface::CLocalSystemInterface() : iOpenDirList(CLocalSystemInterface::KDirGran),
    85 iTLDInfoList(CLocalSystemInterface::KTLDInfoListGran), iDefConnPref(NULL)
    85 iTLDInfoList(CLocalSystemInterface::KTLDInfoListGran), iDefConnResurrect(ETrue), iDefConnPref(NULL)
    86 		{
    86 		{
    87 #ifdef SYMBIAN_OE_POSIX_SIGNALS
    87 #ifdef SYMBIAN_OE_POSIX_SIGNALS
    88 		iSignalsInitialized = EFalse;
    88 		iSignalsInitialized = EFalse;
    89 		iSigInitWaitCount = 0;
    89 		iSigInitWaitCount = 0;
    90 		iSigInitWaitMutex.CreateLocal();
    90 		iSigInitWaitMutex.CreateLocal();
   181 		if (err)
   181 		if (err)
   182 			{
   182 			{
   183 			User::Panic(KEstlibInit, err);
   183 			User::Panic(KEstlibInit, err);
   184 			}
   184 			}
   185 
   185 
   186 		iCleanup.StorePtrs(iPrivateHeap, &iFs, &iSs, &iCs, &iSSLock, &iCSLock);
   186 		iCleanup.StorePtrs(iPrivateHeap, &iFs, &iSs, &iCs, &iSSLock, &iCSLock,&iDefConnLock,&iASelectLock);
   187 
   187 
   188 		}
   188 		}
   189 
   189 
   190 EXPORT_C CLocalSystemInterface::~CLocalSystemInterface()
   190 EXPORT_C CLocalSystemInterface::~CLocalSystemInterface()
   191 //
   191 //
   192 // Shut down all server connections in use
   192 // Shut down all server connections in use
   193 //
   193 //
   194 	{
   194 	{
   195 	iTLDListLock.Close();
   195 	iTLDListLock.Close();
   196 	iSessionPathLock.Close();
   196 	iSessionPathLock.Close();
   197 	// Close the aselect lock
       
   198 	iASelectLock.Close();
       
   199 	// Close the default connection lock
       
   200 	iDefConnLock.Close();
       
   201 	
   197 	
   202 	//close the default RConnection
   198 	//close the default RConnection
   203 	if(iDefConnection.SubSessionHandle() != 0)
   199 	if(iDefConnection.SubSessionHandle() != 0)
   204 	    {
   200 	    {
   205 		iDefConnection.Close();
   201 		iDefConnection.Close();
  1586 	TInt err=iFids.Asynch(fid,f);
  1582 	TInt err=iFids.Asynch(fid,f);
  1587 	TInt mapErr = err;
  1583 	TInt mapErr = err;
  1588 
  1584 
  1589 	if(!err)
  1585 	if(!err)
  1590 		{
  1586 		{
  1591 		// Check if a connection request is already in progress
  1587 		// Check if a connection request is already in progress for a non-blocking socket.
  1592 		// for a non-blocking socket.
  1588 		if (f->GetConnectionProgress())
  1593 		if(f->GetConnectionProgress())
  1589 			{
  1594 			{
  1590 			mapErr = f->iPollErr;
  1595 			// Poll to see if the connect() is completed
  1591 			
  1596 			err = f->Poll( EReadyForWriting );
  1592 			if (f->iPollErr < 0)
  1597 
  1593 			    {
  1598 			// The above Poll is common for all descriptors. 
  1594                 mapErr = f->iPollErr;
  1599 			// In case of socket-descriptors, Poll will either return "KErrNone"
  1595                 f->iPollErr = 0;
  1600 			// or any of the requested events. To check for Poll error in case of 
  1596                 f->SetConnectionProgress(EFalse);
  1601 			// socket-descriptors, "iPollErr" should be checked.			
  1597                 }
  1602 			if( (err < 0) || (f->iPollErr < 0) ) //Error in poll
  1598 			else
  1603 				(err < 0) ? (mapErr = err):(mapErr = f->iPollErr);
  1599 			    {
  1604 			else if( err == 0 ) //Connect still in progress
  1600                 // Poll to see if the connect() is completed
  1605 				mapErr = EALREADY;
  1601                 err = f->Poll(EReadyForWriting);
  1606 			else if( err & EReadyForWriting ) //Connect has completed
  1602                 // The above Poll is common for all descriptors. 
  1607 				f->SetConnectionProgress(EFalse);
  1603                 // In case of socket-descriptors, Poll will either return "KErrNone"
       
  1604                 // or any of the requested events. To check for Poll error in case of 
       
  1605                 // socket-descriptors, "iPollErr" should be checked.
       
  1606                 if (f->iPollErr < 0)
       
  1607                     {
       
  1608                     mapErr = f->iPollErr;
       
  1609                     f->iPollErr = 0;
       
  1610                     }
       
  1611                 else if (err == 0) //Connect still in progress
       
  1612                     mapErr = EALREADY;
       
  1613                 else if (err & EReadyForWriting)
       
  1614                     {
       
  1615                     mapErr = EISCONN; 
       
  1616                     }
       
  1617 			    }
  1608 			}
  1618 			}
  1609 
  1619 
  1610 		if(!mapErr)
  1620 		if(!mapErr)
  1611 			{
  1621 			{
  1612 			TRequestStatus status;
  1622 			TRequestStatus status;
  1613 			f->Connect(addr,size,status);
  1623 			f->Connect(addr,size,status);
  1614 			err=status.Int();
  1624 			err = status.Int();
  1615 
  1625 
  1616 			if (err == KErrWouldBlock)
  1626 			if (err == KErrWouldBlock)
  1617 				{
  1627 				{
  1618 				f->SetConnectionProgress(ETrue);
       
  1619 				mapErr = EINPROGRESS;
  1628 				mapErr = EINPROGRESS;
  1620 				}
  1629 				}
  1621 			else if(err == KErrAlreadyExists)
  1630 			else if (err == KErrAlreadyExists)
  1622 				{
  1631 				{
  1623 				mapErr = EISCONN;
  1632 				mapErr = EISCONN;
  1624 				}
  1633 				}
  1625 			else
  1634 			else
  1626 				mapErr = err;
  1635 				mapErr = err;
  1784 	}
  1793 	}
  1785 // -----------------------------------------------------------------------------
  1794 // -----------------------------------------------------------------------------
  1786 // CLocalSystemInterface::aselect
  1795 // CLocalSystemInterface::aselect
  1787 // -----------------------------------------------------------------------------
  1796 // -----------------------------------------------------------------------------
  1788 //
  1797 //
  1789 int CLocalSystemInterface::cancelaselect(TRequestStatus* requeststatus,int& anErrno,int performcleanup)
  1798 int CLocalSystemInterface::cancelaselect(TRequestStatus* requeststatus, int& anErrno, TBool perform_cleanup)
  1790 	{
  1799 	{
  1791 	iASelectLock.Wait();
  1800 	iASelectLock.Wait();
  1792 	// Search for the aselect request entry in the aselect request array
  1801 	// Search for the aselect request entry in the aselect request array
  1793 	for ( TInt i=0; i<iASelectRequest.Count(); i++ )
  1802 	for (TInt i = 0; i < iASelectRequest.Count(); ++i)
  1794 		{
  1803 		{
  1795 		if( (iASelectRequest[i].iRequestStatus == requeststatus) || performcleanup )
  1804 		if (iASelectRequest[i].iRequestStatus == requeststatus || perform_cleanup)
  1796 			{
  1805 			{
  1797 			// The specified request exists
  1806 			// The specified request exists
  1798 			RThread threadHandle;
  1807 			RThread thread;
  1799 			// Open a handle to the service thread
  1808 			// Open a handle to the service thread
  1800 			TInt res = threadHandle.Open(iASelectRequest[i].iThreadId,EOwnerThread);
  1809 			TInt res = thread.Open(iASelectRequest[i].iThreadId,EOwnerThread);
  1801 			if( res == KErrNone )
  1810 			if (res == KErrNone)
  1802 				{
  1811 				{
  1803 				// Kill the service thread
  1812 				// Kill the service thread
  1804 				threadHandle.Kill(KErrCancel);
  1813 				thread.Kill(KErrCancel);
  1805 				threadHandle.Close();
  1814 				thread.Close();
  1806 				if( !performcleanup )
  1815 				if (!perform_cleanup)
  1807 					{
  1816 					{
  1808 					// Complete the request with KErrcancel
       
  1809 					User::RequestComplete(iASelectRequest[i].iRequestStatus,KErrCancel);
  1817 					User::RequestComplete(iASelectRequest[i].iRequestStatus,KErrCancel);
  1810 					}
  1818 					}
  1811 				// Switch to backend heap
  1819 				// Switch to backend heap
  1812 				RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
  1820 				RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
  1813 				// Remove the request details from the array
  1821 				// Remove the request details from the array
  1814 				iASelectRequest.Remove(i);
  1822 				iASelectRequest.Remove(i);
  1815 				// Switch back to old heap
  1823 				// Switch back to old heap
  1816 				User::SwitchHeap(oldHeap);
  1824 				User::SwitchHeap(oldHeap);
  1817 				if( !performcleanup )
  1825 				if (!perform_cleanup)
  1818 					{
  1826 					{
  1819 					iASelectLock.Signal();
  1827 					iASelectLock.Signal();
  1820 					return MapError(KErrNone, anErrno);
  1828 					return KErrNone;
  1821 					}
  1829 					}
  1822 				}
  1830 				}
  1823 			else
  1831 			else
  1824 				{
  1832 				{
  1825 				if( !performcleanup )
  1833 				if (!perform_cleanup)
  1826 					{
  1834 					{
  1827 					iASelectLock.Signal();
  1835 					iASelectLock.Signal();
  1828 					// unable to open a handle to the service thread
  1836 					// unable to open a handle to the service thread
  1829 					return MapError(res, anErrno);
  1837 					return MapError(res, anErrno);
  1830 					}
  1838 					}
  1831 				}
  1839 				}
  1832 			}
  1840 			}
  1833 		}
  1841 		}
  1834 	iASelectLock.Signal();
  1842 	iASelectLock.Signal();
  1835 	// No request found with the specified TRequestStatus object
  1843 	// No request found with the specified TRequestStatus object
  1836 	if( !performcleanup )
  1844 	return MapError((!perform_cleanup ? KErrNotFound : KErrNone), anErrno);
  1837 		{
       
  1838 		return MapError(KErrNotFound, anErrno);
       
  1839 		}
       
  1840 	else
       
  1841 		{
       
  1842 		return MapError(KErrNone, anErrno);
       
  1843 		}
       
  1844 	}
  1845 	}
  1845 // -----------------------------------------------------------------------------
  1846 // -----------------------------------------------------------------------------
  1846 // CLocalSystemInterface::ASelectRequest
  1847 // CLocalSystemInterface::ASelectRequest
  1847 // -----------------------------------------------------------------------------
  1848 // -----------------------------------------------------------------------------
  1848 //
  1849 //
  2193             }
  2194             }
  2194 
  2195 
  2195         if ( (*reqarray[i]).Int() != KRequestPending ) 
  2196         if ( (*reqarray[i]).Int() != KRequestPending ) 
  2196             {
  2197             {
  2197             TInt readyevents = fdesc->TweakReadyEvents((*reqarray[i]).Int());
  2198             TInt readyevents = fdesc->TweakReadyEvents((*reqarray[i]).Int());
  2198             if (readfds && FD_ISSET(reqfds[i], readfds) && (readyevents & EReadyForReading) ) 
  2199             TInt event_marked = EFalse;
       
  2200             if (readfds && FD_ISSET(reqfds[i], readfds) && (readyevents & EReadyForReading)) 
  2199                 { 
  2201                 { 
  2200                 FD_SET(reqfds[i], &retreadfds); 
  2202                 FD_SET(reqfds[i], &retreadfds); 
  2201                 ++nDescriptorsSet; 
  2203                 ++nDescriptorsSet;
       
  2204                 event_marked = ETrue;
       
  2205 
  2202                 }
  2206                 }
  2203             if(writefds && FD_ISSET(reqfds[i], writefds) && (readyevents & EReadyForWriting) ) 
  2207             if(writefds && FD_ISSET(reqfds[i], writefds) && (readyevents & EReadyForWriting) ) 
  2204                 { 
  2208                 { 
  2205                 FD_SET(reqfds[i], &retwritefds); 
  2209                 FD_SET(reqfds[i], &retwritefds); 
       
  2210 
       
  2211                 event_marked = ETrue;
  2206                 ++nDescriptorsSet; 
  2212                 ++nDescriptorsSet; 
  2207                 }
  2213                 }
  2208             if(exceptfds && FD_ISSET(reqfds[i], exceptfds) && (readyevents & EAnyException))
  2214             if(exceptfds && FD_ISSET(reqfds[i], exceptfds) && (readyevents & EAnyException))
  2209                 {
  2215                 {
       
  2216                 if (!fdesc->GetConnectionProgress() || !event_marked)
       
  2217                     {
  2210                 FD_SET(reqfds[i], &retexceptfds); 
  2218                 FD_SET(reqfds[i], &retexceptfds); 
  2211                 ++nDescriptorsSet;
  2219                 ++nDescriptorsSet;
       
  2220                     }
  2212                 }
  2221                 }
  2213             }
  2222             }
  2214         else
  2223         else
  2215             {
  2224             {
  2216             //Cancel all other requests.
  2225             //Cancel all other requests.
  3769 	}
  3778 	}
  3770 
  3779 
  3771 // -----------------------------------------------------------------------------
  3780 // -----------------------------------------------------------------------------
  3772 // CLocalSystemInterface::StartDefConnection
  3781 // CLocalSystemInterface::StartDefConnection
  3773 //
  3782 //
  3774 // Helper function for the setdefaultif() API to restart the 
  3783 // Helper function for the setdefaultif() API to start the 
  3775 // default RConnection with the new settings.
  3784 // default RConnection with/without preferences
  3776 // -----------------------------------------------------------------------------
  3785 // -----------------------------------------------------------------------------
  3777 //
  3786 //
  3778 TInt CLocalSystemInterface::StartDefConnection()
  3787 TInt CLocalSystemInterface::StartDefConnection()
  3779 	{
  3788 	{
  3780 	TInt err = iDefConnection.Open(iSs);
  3789 	TInt err = iDefConnection.Open(iSs);
  3792 	if (err != KErrNone)
  3801 	if (err != KErrNone)
  3793 		iDefConnection.Close();
  3802 		iDefConnection.Close();
  3794 	return err;
  3803 	return err;
  3795 	}
  3804 	}
  3796 
  3805 
  3797 // -----------------------------------------------------------------------------
  3806 TInt CLocalSystemInterface::unsetdefaultif(TBool allow_bringup)
  3798 // CLocalSystemInterface::setdefaultif
       
  3799 //
       
  3800 // Set the default interface for network operations
       
  3801 // -----------------------------------------------------------------------------
       
  3802 //
       
  3803 int CLocalSystemInterface::setdefaultif(const struct ifreq* aIfReq)
       
  3804     {
  3807     {
  3805     //If the argument is NULL, close the existing connection
  3808     iDefConnLock.Wait();
  3806     if(aIfReq == NULL )
       
  3807         {
       
  3808         // Obtain lock on the iDefConnection
       
  3809         iDefConnLock.Wait();
       
  3810 
       
  3811     if (iDefConnection.SubSessionHandle() != 0)
  3809     if (iDefConnection.SubSessionHandle() != 0)
  3812         {
  3810         {
  3813         TUint count = iSocketArray.Count();
  3811         TUint count = iSocketArray.Count();            
  3814         for (TInt i = 0; i < count; ++i)
  3812         for (TInt i = 0; i < count; ++i)
  3815             {                
  3813             {                
  3816             iSocketArray[i]->TempClose();
  3814             iSocketArray[i]->TempClose();
  3817             }
  3815             }
  3818         iDefConnection.Close();        
  3816         iDefConnection.Close();
  3819         RHeap* oheap = User::SwitchHeap(iPrivateHeap);
       
  3820         iSocketArray.Reset();
       
  3821         User::SwitchHeap(oheap);
       
  3822         }
  3817         }
  3823 
  3818     
  3824         if( iDefConnPref )
  3819     RHeap* oheap = User::SwitchHeap(iPrivateHeap);
       
  3820     iSocketArray.Reset();
       
  3821     
       
  3822     if (iDefConnPref)
       
  3823         {
       
  3824         if (iDefConnPref->ExtensionId() == TConnPref::EConnPrefSnap)
  3825             {
  3825             {
  3826             switch( iDefConnPref->ExtensionId() )
  3826             delete (TCommSnapPref*)iDefConnPref;
  3827                 {
       
  3828                 case TConnPref::EConnPrefSnap:
       
  3829                     {                    
       
  3830                     RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
       
  3831                     delete (TCommSnapPref*)iDefConnPref;
       
  3832                     // Switch back to old heap
       
  3833                     User::SwitchHeap(oldHeap);
       
  3834                     iDefConnPref = NULL;		        
       
  3835                     }
       
  3836                     break;
       
  3837 
       
  3838                 case TConnPref::EConnPrefCommDb:
       
  3839                     {
       
  3840                     RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
       
  3841                     delete (TCommDbConnPref*)iDefConnPref;
       
  3842                     // Switch back to old heap
       
  3843                     User::SwitchHeap(oldHeap);
       
  3844                     iDefConnPref = NULL;
       
  3845                     }
       
  3846                     break;		        
       
  3847 
       
  3848                 default:
       
  3849                     {
       
  3850                     iDefConnLock.Signal();
       
  3851                     // Unknown type of Connection Pref
       
  3852                     return KErrUnknown;
       
  3853                     }
       
  3854                 }
       
  3855             }
  3827             }
  3856         // Release lock on the iDefConnection
  3828         else
  3857         iDefConnLock.Signal();
  3829             {
  3858         return KErrNone;
  3830             delete (TCommDbConnPref*)iDefConnPref;
       
  3831             }
       
  3832         }
       
  3833     User::SwitchHeap(oheap);
       
  3834     
       
  3835     iDefConnPref = NULL;
       
  3836     iDefConnResurrect = allow_bringup;
       
  3837     iDefConnLock.Signal();
       
  3838     return KErrNone;
       
  3839     }
       
  3840 
       
  3841 
       
  3842 // -----------------------------------------------------------------------------
       
  3843 // CLocalSystemInterface::setdefaultif
       
  3844 //
       
  3845 // Set the default interface for network operations
       
  3846 // -----------------------------------------------------------------------------
       
  3847 //
       
  3848 int CLocalSystemInterface::setdefaultif(const struct ifreq* aIfReq)
       
  3849     {
       
  3850     // Do this in any case - whether the argument be a valid pref or NULL
       
  3851     iDefConnResurrect = ETrue;
       
  3852     
       
  3853     // If the argument is NULL, tear down existing connection
       
  3854     if (aIfReq == NULL)
       
  3855         {
       
  3856         return unsetdefaultif();
  3859         }
  3857         }
  3860 
  3858 
  3861     TPtrC8 namePtr((TText8*)aIfReq->ifr_name);
  3859     TPtrC8 namePtr((TText8*)aIfReq->ifr_name);
  3862     TBuf<KCommsDbSvrMaxColumnNameLength> name;
  3860     TBuf<KCommsDbSvrMaxColumnNameLength> name;
  3863     TInt err  = CnvUtfConverter::ConvertToUnicodeFromUtf8(name,namePtr);
  3861     
  3864     if( err != KErrNone )
  3862     TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8(name, namePtr);
       
  3863     if (err != KErrNone)
  3865         return err;
  3864         return err;
  3866 
  3865     
  3867     if( iDefConnPref )
  3866     if (name.Length() == 0)
  3868         {
  3867         {
  3869         switch( iDefConnPref->ExtensionId() )
  3868         // interface name is an empty string, SNAP id is specified in ifr_ifru.snap_id
       
  3869         if (iDefConnPref && iDefConnPref->ExtensionId() == TConnPref::EConnPrefSnap)
  3870             {
  3870             {
  3871             case TConnPref::EConnPrefSnap:
  3871             ((TCommSnapPref*)iDefConnPref)->SetSnap(aIfReq->ifr_ifru.snap_id);
  3872                 {
  3872             return KErrNone;
  3873                 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
       
  3874                 delete (TCommSnapPref*)iDefConnPref;
       
  3875                 // Switch back to old heap
       
  3876                 User::SwitchHeap(oldHeap);
       
  3877                 iDefConnPref = NULL;              
       
  3878                 }
       
  3879                 break;
       
  3880 
       
  3881             case TConnPref::EConnPrefCommDb:
       
  3882                 {
       
  3883                 RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
       
  3884                 delete (TCommDbConnPref*)iDefConnPref;
       
  3885                 // Switch back to old heap
       
  3886                 User::SwitchHeap(oldHeap);
       
  3887                 iDefConnPref = NULL;
       
  3888                 }
       
  3889                 break;              
       
  3890 
       
  3891             default:
       
  3892                 {
       
  3893                 // Unknown type of Connection Pref
       
  3894                 return KErrUnknown;
       
  3895                 }
       
  3896             }
  3873             }
  3897         }
  3874         
  3898 
       
  3899     // If the interface name is an empty string, the SNAP id is to be set 
       
  3900     if(name.Length() == 0)
       
  3901         {
       
  3902         // Switch to backend heap
       
  3903         RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
  3875         RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
       
  3876         delete (TCommDbConnPref*)iDefConnPref; // may be a delete(NULL)
  3904         iDefConnPref = new TCommSnapPref;
  3877         iDefConnPref = new TCommSnapPref;
  3905         // Switch back to old heap
       
  3906         User::SwitchHeap(oldHeap);
  3878         User::SwitchHeap(oldHeap);
  3907         if( iDefConnPref == NULL )
  3879 
       
  3880         if (!iDefConnPref)
  3908             {
  3881             {
  3909             return KErrNoMemory;
  3882             return KErrNoMemory;
  3910             }
  3883             }
  3911         TCommSnapPref* snapprefptr = (TCommSnapPref*)iDefConnPref;
  3884         
  3912         snapprefptr->SetSnap(aIfReq->ifr_ifru.snap_id);
  3885         ((TCommSnapPref*)iDefConnPref)->SetSnap(aIfReq->ifr_ifru.snap_id);
  3913         return KErrNone;
  3886         return KErrNone;
  3914         }
  3887         }
  3915     else //Set the IAP name
  3888     
       
  3889     CTrapCleanup *cleanupStack = NULL;
       
  3890     
       
  3891     // Create a cleanup stack if one doesn't exist
       
  3892     if (User::TrapHandler() == NULL)
  3916         {
  3893         {
  3917         CTrapCleanup *cleanupStack = NULL;
  3894         cleanupStack = CTrapCleanup::New();
  3918         //Create a clean up stack if it is not existing.
  3895         if (cleanupStack == NULL)
  3919         if(User::TrapHandler() == NULL)
  3896             return KErrNoMemory;
       
  3897         }
       
  3898     
       
  3899     if (iDefConnPref && iDefConnPref->ExtensionId() == TConnPref::EConnPrefCommDb)
       
  3900         {
       
  3901         TRAP(err, (err = GetConnectionPreferencesL(name, *(TCommDbConnPref*)iDefConnPref)));
       
  3902         }
       
  3903     else
       
  3904         {
       
  3905         RHeap *oldHeap = User::SwitchHeap(iPrivateHeap);
       
  3906         delete (TCommSnapPref*)iDefConnPref;
       
  3907         iDefConnPref = new TCommDbConnPref;
       
  3908         User::SwitchHeap(oldHeap);
       
  3909         
       
  3910         if (iDefConnPref)
  3920             {
  3911             {
  3921             cleanupStack = CTrapCleanup::New(); //This will be deleted after use
  3912             TRAP(err, (err = GetConnectionPreferencesL(name, *(TCommDbConnPref*)iDefConnPref)));
  3922             if(cleanupStack == NULL)
       
  3923                 return KErrNoMemory;
       
  3924             }
  3913             }
  3925 
       
  3926         // Switch to backend heap
       
  3927         RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
       
  3928         iDefConnPref = new TCommDbConnPref;
       
  3929         // Switch back to old heap
       
  3930         User::SwitchHeap(oldHeap);
       
  3931         if( iDefConnPref == NULL )
       
  3932             {
       
  3933             if( cleanupStack != NULL )
       
  3934                 delete cleanupStack;
       
  3935             return KErrNoMemory;
       
  3936             }
       
  3937         TRAP(err, (err = GetConnectionPreferencesL(name,*(TCommDbConnPref*)iDefConnPref)))
       
  3938 
       
  3939         if( cleanupStack != NULL )
       
  3940             delete cleanupStack;
       
  3941 
       
  3942         return err;
       
  3943         }
  3914         }
       
  3915     
       
  3916     delete cleanupStack;
       
  3917     
       
  3918     return (iDefConnPref ? KErrNone : KErrNoMemory);
  3944     }
  3919     }
       
  3920 
  3945 
  3921 
  3946 // -----------------------------------------------------------------------------
  3922 // -----------------------------------------------------------------------------
  3947 // CLocalSystemInterface::GetDefaultConnection
  3923 // CLocalSystemInterface::GetDefaultConnection
  3948 //
  3924 //
  3949 // Function to get the default connection instance from backend.
  3925 // Function to get the default connection instance from backend.
  3951 // -----------------------------------------------------------------------------
  3927 // -----------------------------------------------------------------------------
  3952 //
  3928 //
  3953 RConnection& CLocalSystemInterface::GetDefaultConnection()
  3929 RConnection& CLocalSystemInterface::GetDefaultConnection()
  3954     {
  3930     {
  3955     // If GetDefaultConnection is called without calling
  3931     // If GetDefaultConnection is called without calling
  3956     // setdefaultif then the connection started without any preferences
  3932     // setdefaultif then the connection is started without any preferences
  3957     // Obtain lock on the iDefConnection
  3933     // Obtain lock on the iDefConnection
  3958     iDefConnLock.Wait();
  3934     iDefConnLock.Wait();
  3959     if(iDefConnection.SubSessionHandle() == 0)
  3935     if(iDefConnection.SubSessionHandle() == 0 && iDefConnResurrect)
  3960         {
  3936         {
  3961         StartDefConnection();
  3937         StartDefConnection();
  3962         }
  3938         }
  3963     // Release lock on the iDefConnection
  3939     // Release lock on the iDefConnection
  3964     iDefConnLock.Signal();
  3940     iDefConnLock.Signal();
  3965     return iDefConnection;
  3941    return iDefConnection;
  3966     }
  3942     }
  3967 
  3943 
  3968 // -----------------------------------------------------------------------------
  3944 // -----------------------------------------------------------------------------
  3969 // CLocalSystemInterface::GetSessionPath
  3945 // CLocalSystemInterface::GetSessionPath
  3970 //
  3946 //