genericopenlibs/openenvcore/backend/src/corebackend/localif.cpp
branchRCL_3
changeset 64 c44f36bb61a3
parent 57 2efc27d87e1c
child 75 254b651f304e
equal deleted inserted replaced
60:82ca0c6a68ed 64:c44f36bb61a3
    77 		return &TheBackend;
    77 		return &TheBackend;
    78 #else
    78 #else
    79 		return &backend;
    79 		return &backend;
    80 #endif
    80 #endif
    81 		}
    81 		}
       
    82 		
       
    83 EXPORT_C RTz& CLocalSystemInterface::TZServer(TInt &aStatus)
       
    84 	{
       
    85 	aStatus = OnDemandTZServerConnection();
       
    86 	return iTzServer;
       
    87 	} 
       
    88 		
       
    89 TInt CLocalSystemInterface::OnDemandTZServerConnection()
       
    90         {
       
    91 		TInt v = EFalse;
       
    92 		TInt err = KErrNone;
       
    93 		
       
    94 		if(__e32_atomic_load_acq32(&iIsRTzConnected))
       
    95 			return err;
       
    96 			
       
    97 		iTzServerLock.Wait();
       
    98 		if (!iIsRTzConnected) 
       
    99 			{
       
   100 			err = iTzServer.Connect();
       
   101 			if ( err == KErrNone ) 
       
   102 				{
       
   103 				err = iTzServer.ShareAuto();
       
   104 				if( err == KErrNone) {
       
   105 					v = ETrue;
       
   106 					}
       
   107 				}
       
   108 			__e32_atomic_store_rel32(&iIsRTzConnected, v); 
       
   109 			}
       
   110 		iTzServerLock.Signal();
       
   111 		
       
   112         return err;
       
   113         } 
    82 
   114 
    83 // Construction of Backend Object which is going to be singleton object for the process
   115 // Construction of Backend Object which is going to be singleton object for the process
    84 EXPORT_C CLocalSystemInterface::CLocalSystemInterface() : iOpenDirList(CLocalSystemInterface::KDirGran),
   116 EXPORT_C CLocalSystemInterface::CLocalSystemInterface() : iOpenDirList(CLocalSystemInterface::KDirGran),
    85 iTLDInfoList(CLocalSystemInterface::KTLDInfoListGran), iDefConnResurrect(ETrue), iDefConnPref(NULL)
   117 iTLDInfoList(CLocalSystemInterface::KTLDInfoListGran), iDefConnResurrect(ETrue), iDefConnPref(NULL), iIsRTzConnected(EFalse)
    86 		{
   118 		{
    87 #ifdef SYMBIAN_OE_POSIX_SIGNALS
   119 #ifdef SYMBIAN_OE_POSIX_SIGNALS
    88 		iSignalsInitialized = EFalse;
   120 		iSignalsInitialized = EFalse;
    89 		iSigInitWaitCount = 0;
   121 		iSigInitWaitCount = 0;
    90 		iSigInitWaitMutex.CreateLocal();
   122 		iSigInitWaitMutex.CreateLocal();
   163 			err |= iSessionPathLock.CreateLocal();
   195 			err |= iSessionPathLock.CreateLocal();
   164 			//Lock for protecting iASelectRequest across threads
   196 			//Lock for protecting iASelectRequest across threads
   165 			err |=  iASelectLock.CreateLocal();
   197 			err |=  iASelectLock.CreateLocal();
   166 	        //Protect the iDefConnection from concurrent GetDefaultConnection calls
   198 	        //Protect the iDefConnection from concurrent GetDefaultConnection calls
   167 	        err |= iDefConnLock.CreateLocal();
   199 	        err |= iDefConnLock.CreateLocal();
   168 			}
   200 			//Protect the time zone server while connecting
   169 
   201 			err |= iTzServerLock.CreateLocal();
   170         if(err == KErrNone)
   202 			}
   171             {
       
   172             err = iTzServer.Connect();
       
   173             if(!err)
       
   174                 {
       
   175                 err = iTzServer.ShareAuto();
       
   176                 }
       
   177             }
       
   178 
       
   179 
   203 
   180 		//Panic if any of the above operation returns with error
   204 		//Panic if any of the above operation returns with error
   181 		if (err)
   205 		if (err)
   182 			{
   206 			{
   183 			User::Panic(KEstlibInit, err);
   207 			User::Panic(KEstlibInit, err);
   184 			}
   208 			}
   185 
   209 
   186 		iCleanup.StorePtrs(iPrivateHeap, &iFs, &iSs, &iCs, &iSSLock, &iCSLock,&iDefConnLock,&iASelectLock);
   210 		iCleanup.StorePtrs(iPrivateHeap, &iFs, &iSs, &iCs, &iSSLock, &iCSLock,&iDefConnLock,&iASelectLock,&iTzServerLock);
   187 
   211 
   188 		}
   212 		}
   189 
   213 
   190 EXPORT_C CLocalSystemInterface::~CLocalSystemInterface()
   214 EXPORT_C CLocalSystemInterface::~CLocalSystemInterface()
   191 //
   215 //
   216 
   240 
   217 	// Close the array that maintains aselect request details 
   241 	// Close the array that maintains aselect request details 
   218 	iASelectRequest.Close();
   242 	iASelectRequest.Close();
   219 	//close the RTz connection
   243 	//close the RTz connection
   220 	iTzServer.Close();
   244 	iTzServer.Close();
   221 
       
   222 
   245 
   223 	if( iDefConnPref )
   246 	if( iDefConnPref )
   224 	    {
   247 	    {
   225 	    switch( iDefConnPref->ExtensionId() )
   248 	    switch( iDefConnPref->ExtensionId() )
   226 	        {
   249 	        {
  1738 		f->Close();	// balances the Dup() in CFileTable::Asynch() - live dangerously!
  1761 		f->Close();	// balances the Dup() in CFileTable::Asynch() - live dangerously!
  1739 		}
  1762 		}
  1740 	return MapError(err,anErrno);
  1763 	return MapError(err,anErrno);
  1741 	}
  1764 	}
  1742 
  1765 
       
  1766 EXPORT_C void CLocalSystemInterface::freednssuffixes(if_dns_suffixes * suffixes)
       
  1767     {
       
  1768     CSocketDesc::FreeDNSSuffixes(suffixes->suffixes);
       
  1769     }
       
  1770 
  1743 int CLocalSystemInterface::ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)
  1771 int CLocalSystemInterface::ioctl_complete (int fid, int cmd, void* param, TRequestStatus& aStatus, int& anErrno)
  1744 	{
  1772 	{
  1745 	return iFids.ioctlcomplete(fid,cmd,param,aStatus,anErrno);
  1773 	return iFids.ioctlcomplete(fid,cmd,param,aStatus,anErrno);
  1746 	}
  1774 	}
  1747 
  1775 
  2164 
  2192 
  2165     if (timeout) 
  2193     if (timeout) 
  2166         { 
  2194         { 
  2167         timer.After(*reqarray[numReqs+arraycount], timeout); 
  2195         timer.After(*reqarray[numReqs+arraycount], timeout); 
  2168         // Wait for any request to complete 
  2196         // Wait for any request to complete 
  2169         CLocalSystemInterface::WaitForNRequest(*reqarray, numReqs+arraycount+1);     
  2197         CLocalSystemInterface::WaitForNRequest(reqarray, numReqs+arraycount+1);     
  2170         if( (*reqarray[numReqs+arraycount]).Int() == KRequestPending) 
  2198         if( (*reqarray[numReqs+arraycount]).Int() == KRequestPending) 
  2171             {
  2199             {
  2172             // The timer hasn't fired yet.
  2200             // The timer hasn't fired yet.
  2173             timer.Cancel(); 
  2201             timer.Cancel(); 
  2174             }
  2202             }
  2179         timer.Close();
  2207         timer.Close();
  2180         // No need to set onedown to True as numReqs does not include the Timer request
  2208         // No need to set onedown to True as numReqs does not include the Timer request
  2181         } 
  2209         } 
  2182     else 
  2210     else 
  2183         { 
  2211         { 
  2184         CLocalSystemInterface::WaitForNRequest(*reqarray, numReqs+arraycount);
  2212         CLocalSystemInterface::WaitForNRequest(reqarray, numReqs+arraycount);
  2185         // Completion Status of one request has been gathered
  2213         // Completion Status of one request has been gathered
  2186         onedown = ETrue;
  2214         onedown = ETrue;
  2187         }
  2215         }
  2188 
  2216 
  2189     for (int i = 0; i < numReqs; ++i) 
  2217     for (int i = 0; i < numReqs; ++i) 
  3618 //
  3646 //
  3619 const CFileTable& CLocalSystemInterface::FileTable() const
  3647 const CFileTable& CLocalSystemInterface::FileTable() const
  3620 {
  3648 {
  3621 return iFids;
  3649 return iFids;
  3622 }
  3650 }
       
  3651 
       
  3652 // ---------------------------------------------------------------------------------
       
  3653 // CLocalSystemInterface::WaitForNRequest
       
  3654 // Wait for any one of the input asynchronous requests to complete
       
  3655 // Used in lieu of User::WaitForNRequest because of need to support pre-Argus builds
       
  3656 // ---------------------------------------------------------------------------------
       
  3657 //
       
  3658 void CLocalSystemInterface::WaitForNRequest(TRequestStatus **aStatusArray, TInt aNum)
       
  3659 	{
       
  3660 	if (aNum)
       
  3661 		{
       
  3662 		// used to keep count of requests we have not been asked to wait for
       
  3663 		TInt nOther = -1;
       
  3664 		TBool done = EFalse;
       
  3665 
       
  3666 		do
       
  3667 			{
       
  3668 			++nOther;
       
  3669 			User::WaitForAnyRequest();
       
  3670 			for (TInt i = 0; i < aNum; ++i)
       
  3671 				{
       
  3672 				if ((*aStatusArray[i]).Int() != KRequestPending)
       
  3673 					{
       
  3674 					done = ETrue;
       
  3675 					break;
       
  3676 					}
       
  3677 				}
       
  3678 			} while (!done);
       
  3679 
       
  3680 		if (nOther)
       
  3681 			{
       
  3682 			// Adjust the thread's signal semaphore to account for the requests
       
  3683 			// we were not asked to wait for.
       
  3684 			RThread thrd;
       
  3685 			for (TInt i = 0; i < nOther; ++i)
       
  3686 				{
       
  3687 				thrd.RequestSignal();
       
  3688 				}
       
  3689 			}
       
  3690 		}
       
  3691 	}
  3623 
  3692 
  3624 // ---------------------------------------------------------------------------------
  3693 // ---------------------------------------------------------------------------------
  3625 // CLocalSystemInterface::WaitForNRequest
  3694 // CLocalSystemInterface::WaitForNRequest
  3626 // Wait for any one of the input asynchronous requests to complete
  3695 // Wait for any one of the input asynchronous requests to complete
  3627 // Used in lieu of User::WaitForNRequest because of need to support pre-Argus builds
  3696 // Used in lieu of User::WaitForNRequest because of need to support pre-Argus builds