genericopenlibs/openenvcore/backend/src/corebackend/localif.cpp
changeset 44 97b0fb8a2cc2
parent 22 ddc455616bd6
child 66 38bdaa106551
equal deleted inserted replaced
22:ddc455616bd6 44:97b0fb8a2cc2
    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)
    85 iTLDInfoList(CLocalSystemInterface::KTLDInfoListGran), 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, &iTzServer);
   186 		iCleanup.StorePtrs(iPrivateHeap, &iFs, &iSs, &iCs, &iSSLock, &iCSLock);
   187 		
   187 
   188 		// No connection settings by default
       
   189 		iDefConnPref = NULL;
       
   190 		}
   188 		}
   191 
   189 
   192 EXPORT_C CLocalSystemInterface::~CLocalSystemInterface()
   190 EXPORT_C CLocalSystemInterface::~CLocalSystemInterface()
   193 //
   191 //
   194 // Shut down all server connections in use
   192 // Shut down all server connections in use
   198 	iSessionPathLock.Close();
   196 	iSessionPathLock.Close();
   199 	// Close the aselect lock
   197 	// Close the aselect lock
   200 	iASelectLock.Close();
   198 	iASelectLock.Close();
   201 	// Close the default connection lock
   199 	// Close the default connection lock
   202 	iDefConnLock.Close();
   200 	iDefConnLock.Close();
       
   201 	
   203 	//close the default RConnection
   202 	//close the default RConnection
   204 	if(iDefConnection.SubSessionHandle() != 0)
   203 	if(iDefConnection.SubSessionHandle() != 0)
       
   204 	    {
   205 		iDefConnection.Close();
   205 		iDefConnection.Close();
       
   206 	    }
   206 
   207 
   207 	RHeap* oHeap = User::SwitchHeap(iPrivateHeap);
   208 	RHeap* oHeap = User::SwitchHeap(iPrivateHeap);
   208 	for (TInt i = 0, count = iTLDInfoList.Count(); i < count; i++ )
   209 	for (TInt i = 0, count = iTLDInfoList.Count(); i < count; i++ )
   209 		{
   210 		{
   210 		iTLDInfoList[i].Close(iPrivateHeap);
   211 		iTLDInfoList[i].Close(iPrivateHeap);
   214 	iTLDInfoList.Close();
   215 	iTLDInfoList.Close();
   215 	// Cleanup the threads serving aselect requests
   216 	// Cleanup the threads serving aselect requests
   216 	int err;
   217 	int err;
   217 	// passing 1 to cancelaselect will kill all the threads serving aselect
   218 	// passing 1 to cancelaselect will kill all the threads serving aselect
   218 	cancelaselect(NULL,err,1);
   219 	cancelaselect(NULL,err,1);
   219 	// Switch to backend heap
   220 
   220 	RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
       
   221 	// Close the array that maintains aselect request details 
   221 	// Close the array that maintains aselect request details 
   222 	iASelectRequest.Close();
   222 	iASelectRequest.Close();
   223 	//close the RTz server
   223 	//close the RTz connection
   224 	iTzServer.Close();
   224 	iTzServer.Close();
   225 	// Switch back to old heap
   225 
   226 	User::SwitchHeap(oldHeap);
       
   227 
   226 
   228 	if( iDefConnPref )
   227 	if( iDefConnPref )
   229 	    {
   228 	    {
   230 	    switch( iDefConnPref->ExtensionId() )
   229 	    switch( iDefConnPref->ExtensionId() )
   231 	        {
   230 	        {
   232 	        case TConnPref::EConnPrefSnap:
   231 	        case TConnPref::EConnPrefSnap:
   233 	            {
   232 	            {
   234 	            RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
       
   235 	            delete (TCommSnapPref*)iDefConnPref;
   233 	            delete (TCommSnapPref*)iDefConnPref;
   236 	            // Switch back to old heap
       
   237 	            User::SwitchHeap(oldHeap);
       
   238 	            iDefConnPref = NULL;              
   234 	            iDefConnPref = NULL;              
   239 	            }
   235 	            }
   240 	            break;
   236 	            break;
   241 
   237 
   242 	        case TConnPref::EConnPrefCommDb:
   238 	        case TConnPref::EConnPrefCommDb:
   243 	            {
   239 	            {
   244 	            RHeap* oldHeap = User::SwitchHeap(iPrivateHeap);
       
   245 	            delete (TCommDbConnPref*)iDefConnPref;
   240 	            delete (TCommDbConnPref*)iDefConnPref;
   246 	            // Switch back to old heap
       
   247 	            User::SwitchHeap(oldHeap);
       
   248 	            iDefConnPref = NULL;
   241 	            iDefConnPref = NULL;
   249 	            }
   242 	            }
   250 	            break;              
   243 	            break;              
   251 
   244 
   252 	        default:
   245 	        default:
   255 	            }
   248 	            }
   256 	        }
   249 	        }
   257 	    }
   250 	    }
   258 
   251 
   259 #if (defined SYMBIAN_OE_POSIX_SIGNALS && defined SYMBIAN_OE_LIBRT)
   252 #if (defined SYMBIAN_OE_POSIX_SIGNALS && defined SYMBIAN_OE_LIBRT)
   260 	iTimerOverrunsMutex.Close();
   253 	iTimerOverrunsMutex.Close();	
   261 	iTimerOverruns.Close(); 
   254 	iTimerOverruns.Close(); 
   262 #endif	
   255 #endif	
       
   256 	
       
   257 #if (defined SYMBIAN_OE_POSIX_SIGNALS)
       
   258 	iSigInitWaitMutex.Close();
       
   259 	iSigInitWaitSemaphore.Close();
       
   260 	iBlockedSAMutex.Close();
       
   261 	iSignalWaiterMutex.Close();
       
   262 	iSignalInitSemaphore.Close();
       
   263 #endif
   263 	//close the RpointerArray
   264 	//close the RpointerArray
   264 	iOpenDirList.Close();
   265 	iOpenDirList.Close();
       
   266 	
       
   267 	iSSLock.Close();
       
   268 	iCSLock.Close();
       
   269 	iSignalSession.Close();
       
   270 	iIpcS.Close();
       
   271 		
   265 	User::SwitchHeap(oHeap);
   272 	User::SwitchHeap(oHeap);
   266 	}
   273 	}
   267 
   274 
   268 #ifdef __SYMBIAN_COMPILE_UNUSED__
   275 #ifdef __SYMBIAN_COMPILE_UNUSED__
   269 CLocalSystemInterface& CLocalSystemInterface::Clone()
   276 CLocalSystemInterface& CLocalSystemInterface::Clone()
   298 // -----------------------------------------------------------------------------
   305 // -----------------------------------------------------------------------------
   299 //
   306 //
   300 void CLocalSystemInterface::Exit(int code)
   307 void CLocalSystemInterface::Exit(int code)
   301 	{
   308 	{
   302 #ifdef SYMBIAN_OE_POSIX_SIGNALS
   309 #ifdef SYMBIAN_OE_POSIX_SIGNALS
   303     TRequestStatus status = KRequestPending;
   310     if(iSignalsInitialized)
   304     iSignalHandlerThread.Logon(status);
   311         {
   305 	iSignalLoopRunning = EFalse;
   312         TRequestStatus status = KRequestPending;
   306 	iSignalHandlerThread.RequestSignal();
   313         iSignalHandlerThread.Logon(status);
   307 	User::WaitForRequest(status);
   314         iSignalLoopRunning = EFalse;
       
   315         iSignalHandlerThread.RequestSignal();
       
   316         User::WaitForRequest(status);
       
   317         }
   308 #endif
   318 #endif
   309 	iFids.Close();
   319 	iFids.Close();
   310 	User::SetCritical(User::EProcessPermanent);
   320 	User::SetCritical(User::EProcessPermanent);
   311 	User::Exit(code);
   321 	User::Exit(code);
   312 	}
   322 	}
   332 	{
   342 	{
   333 	return PosixFilesystem::mkdir(iFs, aPath, perms, anErrno);
   343 	return PosixFilesystem::mkdir(iFs, aPath, perms, anErrno);
   334 	}
   344 	}
   335 
   345 
   336 int CLocalSystemInterface::stat (const wchar_t* name, struct stat *st, int& anErrno)
   346 int CLocalSystemInterface::stat (const wchar_t* name, struct stat *st, int& anErrno)
   337     {
   347     {    
   338     const wchar_t* filename;
   348     const wchar_t* filename  = name;
   339     // This needs to be zero terminated
   349     // This needs to be zero terminated
   340     TBuf<KMaxFileName> inputName;
   350     TBuf<KMaxFileName> inputName;
   341     TUint pathAtt = 0;
   351     TUint pathAtt = 0;
   342     TInt err = GetFullFile(inputName,(const TText16*)name,iFs);
   352     TInt err = GetFullFile(inputName,(const TText16*)name,iFs);
   343     if( !err )
   353     if( !err )
   345         TInt err = iFs.Att(inputName,pathAtt);
   355         TInt err = iFs.Att(inputName,pathAtt);
   346         if ( (err == KErrNone) && (pathAtt & KEntryAttDir) )
   356         if ( (err == KErrNone) && (pathAtt & KEntryAttDir) )
   347             {                    
   357             {                    
   348             inputName.Append(_L("\\"));            
   358             inputName.Append(_L("\\"));            
   349             }
   359             }
   350         filename = (wchar_t*)inputName.PtrZ();
       
   351         }
       
   352     // try to stat anyway
       
   353     else
       
   354         {
       
   355         inputName.Copy((const TText16*)name);
       
   356         filename = (wchar_t*)inputName.PtrZ();
   360         filename = (wchar_t*)inputName.PtrZ();
   357         }
   361         }
   358     TSpecialFileType fileType;
   362     TSpecialFileType fileType;
   359     struct SLinkInfo enBuf;
   363     struct SLinkInfo enBuf;
   360     // Check the type of file
   364     // Check the type of file
  3728 		TCommDbConnPref &aConnPref)
  3732 		TCommDbConnPref &aConnPref)
  3729 	{
  3733 	{
  3730 	TInt err = KErrNone;
  3734 	TInt err = KErrNone;
  3731 
  3735 
  3732 	//Open the database and create the IAP view.
  3736 	//Open the database and create the IAP view.
  3733 	CCommsDatabase *iApDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
  3737 	CCommsDatabase *apDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
  3734 	CleanupStack::PushL(iApDb);
  3738 	CleanupStack::PushL(apDb);
  3735 	iApDb->ShowHiddenRecords();
  3739 	apDb->ShowHiddenRecords();
  3736 	//The following pushes the view onto the cleanup stack
  3740 	//The following pushes the view onto the cleanup stack
  3737 	CCommsDbTableView *view = iApDb->OpenTableLC(TPtrC(IAP));
  3741 	CCommsDbTableView *view = apDb->OpenTableLC(TPtrC(IAP));
  3738 
  3742 
  3739 	//Iterate through the records to find the matching entry
  3743 	//Iterate through the records to find the matching entry
  3740 	TAccessPointRecord apRecord;
  3744 	TAccessPointRecord apRecord;
  3741 	err = view->GotoFirstRecord();
  3745 	err = view->GotoFirstRecord();
  3742 	while (err == KErrNone)
  3746 	while (err == KErrNone)
  3748 
  3752 
  3749 		err = view->GotoNextRecord();
  3753 		err = view->GotoNextRecord();
  3750 		}
  3754 		}
  3751 
  3755 
  3752 	CleanupStack::PopAndDestroy(); //Free the view
  3756 	CleanupStack::PopAndDestroy(); //Free the view
  3753 	CleanupStack::PopAndDestroy(iApDb); //Free the db itself
  3757 	CleanupStack::PopAndDestroy(apDb); //Free the db itself
  3754 
  3758 
  3755 	if(err != KErrNone) //Record not found
  3759 	if(err != KErrNone) //Record not found
  3756 		return KErrNotFound;
  3760 		return KErrNotFound;
  3757 
  3761 
  3758 	aConnPref.SetIapId(apRecord.iId);
  3762 	aConnPref.SetIapId(apRecord.iId);
  3763 
  3767 
  3764 	return KErrNone;
  3768 	return KErrNone;
  3765 	}
  3769 	}
  3766 
  3770 
  3767 // -----------------------------------------------------------------------------
  3771 // -----------------------------------------------------------------------------
  3768 // CLocalSystemInterface::RestartDefConnection
  3772 // CLocalSystemInterface::StartDefConnection
  3769 //
  3773 //
  3770 // Helper function for the setdefaultif() API to restart the 
  3774 // Helper function for the setdefaultif() API to restart the 
  3771 // default RConnection with the new settings.
  3775 // default RConnection with the new settings.
  3772 // -----------------------------------------------------------------------------
  3776 // -----------------------------------------------------------------------------
  3773 //
  3777 //
  3774 TInt CLocalSystemInterface::StartDefConnection()
  3778 TInt CLocalSystemInterface::StartDefConnection()
  3775 	{
  3779 	{
  3776 	//Close the connection and re-open it with the new preferences
       
  3777 	if(iDefConnection.SubSessionHandle() != 0)
       
  3778 		iDefConnection.Close();
       
  3779 
       
  3780 	TInt err = iDefConnection.Open(iSs);
  3780 	TInt err = iDefConnection.Open(iSs);
  3781 	if( err != KErrNone )
  3781 	if( err != KErrNone )
  3782 		return err;
  3782 		return err;
  3783 
  3783 	// If connection preference is set
  3784 	err = iDefConnection.Start(*iDefConnPref);
  3784 	if (iDefConnPref)
  3785 	if( err != KErrNone )
  3785 	    {
       
  3786 	    err = iDefConnection.Start(*iDefConnPref);
       
  3787 	    }
       
  3788 	else // No connection preference available
       
  3789 	    {
       
  3790 	    err = iDefConnection.Start();
       
  3791 	    }
       
  3792 	if (err != KErrNone)
  3786 		iDefConnection.Close();
  3793 		iDefConnection.Close();
  3787 
       
  3788 	return err;
  3794 	return err;
  3789 	}
  3795 	}
  3790 
  3796 
  3791 // -----------------------------------------------------------------------------
  3797 // -----------------------------------------------------------------------------
  3792 // CLocalSystemInterface::setdefaultif
  3798 // CLocalSystemInterface::setdefaultif
  3799     //If the argument is NULL, close the existing connection
  3805     //If the argument is NULL, close the existing connection
  3800     if(aIfReq == NULL )
  3806     if(aIfReq == NULL )
  3801         {
  3807         {
  3802         // Obtain lock on the iDefConnection
  3808         // Obtain lock on the iDefConnection
  3803         iDefConnLock.Wait();
  3809         iDefConnLock.Wait();
  3804         if(iDefConnection.SubSessionHandle() != 0)
  3810 
  3805             iDefConnection.Close();
  3811     if (iDefConnection.SubSessionHandle() != 0)
       
  3812         {
       
  3813         TUint count = iSocketArray.Count();
       
  3814         for (TInt i = 0; i < count; ++i)
       
  3815             {                
       
  3816             iSocketArray[i]->TempClose();
       
  3817             }
       
  3818         iDefConnection.Close();        
       
  3819         RHeap* oheap = User::SwitchHeap(iPrivateHeap);
       
  3820         iSocketArray.Reset();
       
  3821         User::SwitchHeap(oheap);
       
  3822         }
       
  3823 
  3806         if( iDefConnPref )
  3824         if( iDefConnPref )
  3807             {
  3825             {
  3808             switch( iDefConnPref->ExtensionId() )
  3826             switch( iDefConnPref->ExtensionId() )
  3809                 {
  3827                 {
  3810                 case TConnPref::EConnPrefSnap:
  3828                 case TConnPref::EConnPrefSnap:
  3933 // -----------------------------------------------------------------------------
  3951 // -----------------------------------------------------------------------------
  3934 //
  3952 //
  3935 RConnection& CLocalSystemInterface::GetDefaultConnection()
  3953 RConnection& CLocalSystemInterface::GetDefaultConnection()
  3936     {
  3954     {
  3937     // If GetDefaultConnection is called without calling
  3955     // If GetDefaultConnection is called without calling
  3938     // setdefaultif then the connection is not started
  3956     // setdefaultif then the connection started without any preferences
  3939     // Obtain lock on the iDefConnection
  3957     // Obtain lock on the iDefConnection
  3940     iDefConnLock.Wait();
  3958     iDefConnLock.Wait();
  3941     if(iDefConnection.SubSessionHandle() == 0)
  3959     if(iDefConnection.SubSessionHandle() == 0)
  3942         {
  3960         {
  3943         // iDefConnPref should not be NULL for starting the connection
  3961         StartDefConnection();
  3944         if( iDefConnPref )
       
  3945             {
       
  3946             StartDefConnection();
       
  3947             }
       
  3948         }
  3962         }
  3949     // Release lock on the iDefConnection
  3963     // Release lock on the iDefConnection
  3950     iDefConnLock.Signal();
  3964     iDefConnLock.Signal();
  3951     return iDefConnection;
  3965     return iDefConnection;
  3952     }
  3966     }