fotaapplication/fmserver/src/fmsserver.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 25 b183ec05bd8c
child 27 5cc2995847ea
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Implementation of fotaserver component
       
    15 * 	This is part of fotaapplication.
       
    16 *
       
    17 */
       
    18 
       
    19 #include <systemwarninglevels.hrh>
       
    20 #include <e32property.h>
       
    21 #include <bldvariant.hrh>
       
    22 #include <startupdomainpskeys.h>
       
    23 #include <hwrmpowerstatesdkpskeys.h>
       
    24 #include <f32file.h>
       
    25 #include <sysutil.h> 
       
    26 #include <centralrepository.h>
       
    27 #include <ctsydomainpskeys.h>
       
    28 #include "fotaserverPrivateCRKeys.h"
       
    29 #include "fmsserver.h"
       
    30 #include "fmsinterruptaob.h"
       
    31 #include "fmsclientserver.h"
       
    32 #include "fmsserversession.h"
       
    33 #include <schinfo.h>
       
    34 #include <csch_cli.h>
       
    35 #include "FotaIPCTypes.h"
       
    36 // ----------------------------------------------------------------------------------------
       
    37 // Server startup code
       
    38 // ----------------------------------------------------------------------------------------
       
    39 static void RunServerL()
       
    40 	{
       
    41 	// naming the server thread after the server helps to debug panics
       
    42 	User::LeaveIfError(User::RenameThread(KFMSServerName)); 
       
    43 
       
    44 	// create and install the active scheduler
       
    45 	CActiveScheduler* s=new(ELeave) CActiveScheduler;
       
    46 	CleanupStack::PushL(s);
       
    47 	CActiveScheduler::Install(s);
       
    48 
       
    49 	// create the server (leave it on the cleanup stack)
       
    50 	CFMSServer::NewLC();
       
    51 
       
    52 	// Initialisation complete, now signal the client
       
    53 	RProcess::Rendezvous(KErrNone);
       
    54 
       
    55 	// Ready to run
       
    56 	CActiveScheduler::Start();
       
    57 
       
    58 	// Cleanup the server and scheduler
       
    59 	CleanupStack::PopAndDestroy(2);
       
    60 	}
       
    61 
       
    62 
       
    63 // ----------------------------------------------------------------------------------------
       
    64 // static method LogNwRequestL() called to submit async n/w request
       
    65 // ----------------------------------------------------------------------------------------
       
    66 static TInt LogNwRequestL(TAny* aPtr)
       
    67 	{
       
    68 	CFMSServer* ptr = (CFMSServer*) aPtr;
       
    69 	FLOG(_L("static LogNwRequestL:-Begin"));
       
    70 	TRAPD(err, ptr->StartMonitoringL(EDLNetworkInterrupt));
       
    71 	FLOG(_L("LogNwRequestL started monitoring"));
       
    72 	ptr->StopAsyncRequest();
       
    73 	FLOG(_L("static LogNwRequestL:-end"));
       
    74 	return err;
       
    75 	}
       
    76 
       
    77 
       
    78 // ----------------------------------------------------------------------------------------
       
    79 // static method LogCallEndMonitorRequestL() called to submit async call end monitor request
       
    80 // ----------------------------------------------------------------------------------------
       
    81 static TInt LogCallEndMonitorRequestL(TAny* aPtr)
       
    82     {
       
    83     CFMSServer* ptr = (CFMSServer*) aPtr;
       
    84     FLOG(_L("static LogCallEndMonitorRequestL:-Begin"));
       
    85     TRAPD(err, ptr->StartUpdateInterruptMonitoringL(EUpdMonitorPhoneCallEnd));
       
    86     FLOG(_L("LogCallEndMonitorRequestL started monitoring"));
       
    87     ptr->StopAsyncRequest();
       
    88     FLOG(_L("static LogCallEndMonitorRequestL:-end"));
       
    89 	return err;
       
    90 	}
       
    91 
       
    92 // ----------------------------------------------------------------------------------------
       
    93 // Server process entry-point
       
    94 // ----------------------------------------------------------------------------------------
       
    95 TInt E32Main()
       
    96 	{
       
    97 	__UHEAP_MARK;
       
    98 	CTrapCleanup* cleanup=CTrapCleanup::New();
       
    99 	TInt r=KErrNoMemory;
       
   100 	if (cleanup)
       
   101 		{
       
   102 		TRAP(r,RunServerL());
       
   103 		delete cleanup;
       
   104 		}
       
   105 	__UHEAP_MARKEND;
       
   106 	return r;
       
   107 	}
       
   108 
       
   109 // ----------------------------------------------------------------------------------------
       
   110 // CFMSServer::NewLC
       
   111 // ----------------------------------------------------------------------------------------
       
   112 CServer2* CFMSServer::NewLC()
       
   113 {
       
   114 CFMSServer* self=new(ELeave) CFMSServer;
       
   115 CleanupStack::PushL(self);
       
   116 self->ConstructL();	
       
   117 return self;
       
   118 }
       
   119 
       
   120 // ----------------------------------------------------------------------------------------
       
   121 // CFMSServer::ConstructL
       
   122 // ----------------------------------------------------------------------------------------
       
   123 void CFMSServer::ConstructL()
       
   124 	{
       
   125 	FLOG(_L("CFMSServer::ConstructL- begin"));
       
   126 	StartL(KFMSServerName);		
       
   127 	User::LeaveIfError( iFs.Connect() );
       
   128 	TInt err;
       
   129 	err = iFs.CreatePrivatePath(EDriveC);
       
   130 	if ( err != KErrNone && err != KErrAlreadyExists )
       
   131 		{ User::Leave (err); }
       
   132 	User::LeaveIfError( iFs.SetSessionToPrivate( EDriveC ) );
       
   133 	err = iFile.Create(iFs,KFotaInterruptFileName,EFileWrite);
       
   134 	if(err == KErrNone)//means file created now and opened
       
   135 		{
       
   136 		FLOG(_L("CFMSServer::ConstructL- file closed"));
       
   137 		iFile.Close();
       
   138 		}
       
   139 	else if( err != KErrAlreadyExists )
       
   140 		{
       
   141 		FLOG(_L("CFMSServer::ConstructL- leaving with err as %d"),err);
       
   142 		User::Leave(err);
       
   143 		}
       
   144 	FindVariation();
       
   145 	iFMSInterruptAob.ConstructL();
       
   146 	iFMSInterruptAob.iServer = this;  
       
   147 	FLOG(_L("CFMSServer::ConstructL- end"));
       
   148 	}
       
   149 
       
   150 // ----------------------------------------------------------------------------------------
       
   151 // CFMSServer::CFMSServer() 
       
   152 // ----------------------------------------------------------------------------------------
       
   153 CFMSServer::CFMSServer() :CServer2(EPriorityStandard, EUnsharableSessions) /*CServer2(0)*/
       
   154 	{	
       
   155 	iSessionCount = 0;
       
   156 	//iNetworkMon = ETrue; //Incase of cenrep key has problem
       
   157 	iNetworkMon = EFalse; 
       
   158 	iChargerMon = EFalse;
       
   159 	iPhoneRestartMon = EFalse;
       
   160 	iMemoryMon = EFalse;
       
   161 	iDeleteFile = ETrue;
       
   162 	iLogAsyncRequest = NULL;
       
   163 	}
       
   164 
       
   165 // ----------------------------------------------------------------------------------------
       
   166 // CFMSServer::MemoryToMonitorL() 
       
   167 // ----------------------------------------------------------------------------------------
       
   168 void CFMSServer::MemoryToMonitorL(TInt aSize, TDriveNumber aDrive)
       
   169 	{
       
   170 	if( iSessionCount == 0 )// no pending request
       
   171 		{
       
   172 		iFMSInterruptAob.MemoryToMonitorL(aSize,aDrive);
       
   173 		}
       
   174 	}
       
   175 // ----------------------------------------------------------------------------------------
       
   176 // CFMSServer::NetworkTypeL() 
       
   177 // ----------------------------------------------------------------------------------------
       
   178 void CFMSServer::NetworkTypeL(TInt aBearer)
       
   179 	{
       
   180 	if( iSessionCount == 0 )// no pending request
       
   181 		{
       
   182 		iFMSInterruptAob.NetworkTypeL(aBearer);
       
   183 		}
       
   184 	}
       
   185 
       
   186 //------------------------------------------------------------
       
   187 // Call from session class in fotastartup  case 
       
   188 // CFMSServer::CheckNetworkL
       
   189 //------------------------------------------------------------
       
   190 void CFMSServer::CheckNetworkL(TInt& aBearerId, TInt& aDrive, TInt& aSize,
       
   191 		TBool& aWcdma)
       
   192 	{
       
   193 	if(iNetworkMon)//n/w monitoring supports
       
   194 		{
       
   195 		FLOG(_L("CFMSServer::CheckNetworkL- n/w monitor supported"));
       
   196 		if(iFMSInterruptAob.CheckNetworkL()) //not n/w interrupt + WLAN or GPRS
       
   197 			{
       
   198 			FLOG(_L("CFMSServer::CheckNetworkL- n/w mon supported & launch fota"));
       
   199 			iFMSInterruptAob.LaunchFotaEngineL();		
       
   200 			DropSession(); // to close the session & server
       
   201 			return;
       
   202 			}			
       
   203 		else //if network not up, monitor for that
       
   204 			{
       
   205 			//from session itself we set the bearer type
       
   206 			FLOG(_L("CFMSServer::CheckNetworkL- n/w not up beaerer 3G %d"),aWcdma);
       
   207 			WriteToFile(EDLNetworkInterrupt,aBearerId,
       
   208 					(TDriveNumber)aDrive, aSize, aWcdma );
       
   209 			StartMonitoringL(EDLNetworkInterrupt);
       
   210 			}
       
   211 		}
       
   212 	else //user interrupt or general interrupt dont check n/w call fota
       
   213 		{
       
   214 		FLOG(_L("CFMSServer::CheckNetworkL- n/w monitor not supported & launch fota"));		
       
   215 		iFMSInterruptAob.LaunchFotaEngineL();
       
   216 		FLOG(_L("CFMSServer::CheckNetworkL- stop server"));		
       
   217 		DropSession();
       
   218 		}
       
   219 	}
       
   220 
       
   221 //------------------------------------------------------------
       
   222 // Call from session class in hard reboot only 
       
   223 // CFMSServer::TriggerFotaL
       
   224 //------------------------------------------------------------
       
   225 void CFMSServer::TriggerFotaL()
       
   226 	{
       
   227 	FLOG(_L("CFMSServer::TriggerFotaL- begin"));	
       
   228 	if(iNetworkMon)//n/w monitoring supports
       
   229 		{
       
   230 		FLOG(_L("CFMSServer::TriggerFotaL- n/w monitor supported"));
       
   231 #if defined (__WINS__)
       
   232 		if(ETrue)
       
   233 #else
       
   234 		if(iFMSInterruptAob.CheckNetworkL())
       
   235 #endif
       
   236 			{
       
   237 			FLOG(_L("CFMSServer::TriggerFotaL- n/w mon supported & launch fota"));
       
   238 			iFMSInterruptAob.LaunchFotaEngineL();				
       
   239 			}
       
   240 		else if(iFMSInterruptAob.CheckGlobalRFStateL())
       
   241 			{
       
   242 			FLOG(_L("CFMSServer::TriggerFotaL- n/w check started"));
       
   243 			iFMSInterruptAob.StartNetworkRegistryCheckL();
       
   244 			return; //dont call drop session as it closes server
       
   245 			}
       
   246 		else
       
   247 			{
       
   248 			FLOG(_L("CFMSServer::TriggerFotaL- phone is offline"));			
       
   249 			}
       
   250 		}
       
   251 	else //user interrupt or general interrupt dont check n/w call fota
       
   252 		{
       
   253 		FLOG(_L("CFMSServer::TriggerFotaL- n/w monitor not supported & launch fota"));		
       
   254 		iFMSInterruptAob.LaunchFotaEngineL();		
       
   255 		FLOG(_L("CFMSServer::TriggerFotaL- stop server"));			
       
   256 		}
       
   257 	DropSession(); // to close the session & server in any case
       
   258 	FLOG(_L("CFMSServer::TriggerFotaL- End"));
       
   259 	}
       
   260 
       
   261 //------------------------------------------------------------
       
   262 // Called only in n/w interrupt+ WLAN case from session class
       
   263 // CFMSServer::CheckWlanL
       
   264 //------------------------------------------------------------
       
   265 TBool CFMSServer::CheckWlanL()
       
   266 	{
       
   267 	return iFMSInterruptAob.CheckNetworkL();
       
   268 	}
       
   269 
       
   270 //------------------------------------------------------------
       
   271 // CFMSServer::SetWcdma
       
   272 //------------------------------------------------------------
       
   273 void CFMSServer::SetWcdma()
       
   274 	{
       
   275 	iFMSInterruptAob.SetWcdma();
       
   276 	}
       
   277 
       
   278 // ----------------------------------------------------------------------------------------
       
   279 // CFMSServer::LockSession() 
       
   280 // ----------------------------------------------------------------------------------------
       
   281 void CFMSServer::LockSession()
       
   282 	{
       
   283 	iSessionCount++;
       
   284 	}
       
   285 
       
   286 // ----------------------------------------------------------------------------------------
       
   287 // CFMSServer::WriteToFile() 
       
   288 // ----------------------------------------------------------------------------------------
       
   289 void CFMSServer::WriteToFile(TInt aReason, TInt aBearer,TDriveNumber aDrive,
       
   290 		TInt aSize, TBool aWcdmaBearer )
       
   291 	{
       
   292 	if(iSessionCount == 0)
       
   293 		{
       
   294 		FLOG(_L("CFMSServer::WriteToFile- begin"));
       
   295 		TInt err=iFile.Open(iFs,KFotaInterruptFileName,EFileWrite);
       
   296 		if(err == KErrNone)
       
   297 			{
       
   298 			FLOG(_L("CFMSServer::WriteToFile--passed"));
       
   299 			TBuf8<30> data;//size 30 or 32--as args is 16 bytes
       
   300 			TBuf8<30> temp;
       
   301 			temp.Num(aReason);
       
   302 			data.Append(temp);
       
   303 			data.Append(',');
       
   304 			temp.Num(aBearer);// or use iFMSinterruptAob's iBearer
       
   305 			data.Append(temp);
       
   306 			data.Append(',');
       
   307 			temp.Num((TInt)aDrive);
       
   308 			data.Append(temp);
       
   309 			data.Append(',');
       
   310 			temp.Num(aSize);  
       
   311 			data.Append(temp);
       
   312 			data.Append(',');
       
   313 			temp.Num(aWcdmaBearer);
       
   314 			data.Append(temp);
       
   315 			iFile.Write(data);
       
   316 			iFile.Close();
       
   317 			}
       
   318 		else
       
   319 			FLOG(_L("CFMSServer::WriteToFile- Failed"));
       
   320 		}
       
   321 	else
       
   322 		FLOG(_L("CFMSServer::WriteToFile- not done as another request is there"));
       
   323 	}
       
   324 
       
   325 // ----------------------------------------------------------------------------------------
       
   326 // CFMSServer::ReadFromFile() 
       
   327 // ----------------------------------------------------------------------------------------
       
   328 TBool CFMSServer::ReadFromFile(TInt& aReason, TInt& aBearer, TInt& aDrive, TInt& aSize
       
   329 		, TInt& aWcdmaBearer )
       
   330 	{
       
   331 	TInt err = iFile.Open(iFs,KFotaInterruptFileName,EFileRead);
       
   332 	FLOG(_L("CFMSServer::ReadFromFile() error as %d"),err);
       
   333 	if(err == KErrNone)
       
   334 		{
       
   335 		TInt size = KErrNone;
       
   336 		err = iFile.Size(size);	
       
   337 		if(size == 0) //file empty
       
   338 			{
       
   339 			FLOG(_L("CFMSServer::ReadFromFile() file size is empty"));
       
   340 			iFile.Close();
       
   341 			return EFalse;		
       
   342 			}
       
   343 		TBuf8<30> data;
       
   344 		iFile.Read(data);
       
   345 		iFile.Close();	
       
   346 		TBuf8<30> data1;    
       
   347 		if(data.Length()>0)
       
   348 			{
       
   349 			TInt len =0 ;
       
   350 			if((len=data.LocateF(',')) > 0)
       
   351 				{
       
   352 				TLex8 value( data.Left(len));            
       
   353 				value.Val(aReason);
       
   354 				FLOG(_L("CFMSServer::ReadFromFile() retrieving reason as %d"),aReason);
       
   355 				data1.Insert(0,data.Right(data.Length()-(len+1)));
       
   356 				data.Zero();
       
   357 				//    len=data1.LocateF(',');
       
   358 				if( data1.Length() > 0 && (len=data1.LocateF(',')) > 0)
       
   359 					{
       
   360 					value=data1.Left(len);            
       
   361 					value.Val(aBearer);  
       
   362 					FLOG(_L("CFMSServer::ReadFromFile() retrieving aBearer as %d"),aBearer);
       
   363 					data.Insert(0,data1.Right(data1.Length()-(len+1)));            
       
   364 					data1.Zero();
       
   365 					//  len=data.LocateF(','); 
       
   366 					if(data.Length() > 0 && (  len=data.LocateF(','))> 0)
       
   367 						{
       
   368 						value=data.Left(len);            
       
   369 						value.Val(aDrive);
       
   370 						FLOG(_L("CFMSServer::ReadFromFile() retrieving aDrive as %d"),aDrive);
       
   371 						data1.Insert(0,data.Right(data.Length()-(len+1)));
       
   372 						data.Zero();
       
   373 						if(data1.Length() > 0 && (  len=data1.LocateF(','))> 0 )
       
   374 							{
       
   375 							value=data1.Left(len);
       
   376 							value.Val(aSize);
       
   377 							FLOG(_L("CFMSServer::ReadFromFile() retrieving aSize as %d"),aSize);
       
   378 							data.Insert(0,data1.Right(data1.Length()-len-1));
       
   379 							data1.Zero();
       
   380 							if(data.Length() > 0 )
       
   381 								{
       
   382 								value=data;  
       
   383 								value.Val(aWcdmaBearer);
       
   384 								FLOG(_L("CFMSServer::ReadFromFile() retrieving aWcdmaBearer as %d"),aWcdmaBearer);
       
   385 								}
       
   386 							}
       
   387 						} 
       
   388 					}
       
   389 				}    
       
   390 			}
       
   391 		}
       
   392 	else
       
   393 		{
       
   394 		return EFalse;
       
   395 		}
       
   396 	return ETrue;
       
   397 	}
       
   398 
       
   399 // -----------------------------------------------------------------------------
       
   400 // CFMSServer::DropSession()
       
   401 // -----------------------------------------------------------------------------
       
   402 
       
   403 void CFMSServer::DropSession()
       
   404 	{
       
   405 	// A session is being destroyed	
       
   406 	iSessionCount = 0;	
       
   407 	//Kill the server
       
   408 	CActiveScheduler::Stop();	
       
   409 	}
       
   410 
       
   411 // ----------------------------------------------------------------------------------------
       
   412 // CFMSServer::FindVariation() 
       
   413 // ----------------------------------------------------------------------------------------
       
   414 void CFMSServer::FindVariation()
       
   415 	{
       
   416 	FLOG(_L("CFMSServer::FindVariation()"));
       
   417 	CRepository* centrep = NULL;
       
   418 	TInt variation = 1;
       
   419 	TRAPD( err, centrep = CRepository::NewL( KCRUidFotaServer ) );
       
   420 	if ( centrep )
       
   421 		{
       
   422 		FLOG(_L("CFMSServer::FindVariation()::Inside cenrep if"));
       
   423 		TInt err = centrep->Get( KFotaMonitoryServiceEnabled, variation );                 
       
   424 		if( err == KErrNone)
       
   425 			{ 
       
   426 			FLOG(_L("CFMSServer::FindVariation()::cenrep key found with %d"),variation);
       
   427 			}
       
   428 		delete centrep;
       
   429 		}
       
   430 	if ( err == KErrNone )
       
   431 		{
       
   432 		TBuf<10> var; //32-bit has max of 10 chars in Decimal
       
   433 		var.Num(variation,EBinary);
       
   434 		TInt size = var.Length(), maxlen = 4;
       
   435 		if( size < maxlen)
       
   436 			{
       
   437 			TBuf<4> temp;
       
   438 			temp.AppendFill('0',maxlen-size);
       
   439 			temp.Append(var);
       
   440 			var.Zero();
       
   441 			var.Append(temp);
       
   442 			}
       
   443 		var.AppendFill('0',6);
       
   444 		if( var[0] == '1' )//memory
       
   445 			{
       
   446 			FLOG(_L("CFMSServer::FindVariation():: memory monitor supported"));    		
       
   447 			iMemoryMon = ETrue;
       
   448 			}
       
   449 		if( var[1] == '1' ) //startup
       
   450 			{
       
   451 			FLOG(_L("CFMSServer::FindVariation()::Phone restart monitor supported"));
       
   452 			iPhoneRestartMon = ETrue;
       
   453 			}
       
   454 		if( var[2] == '1' )//user or charger
       
   455 			{			
       
   456 			FLOG(_L("CFMSServer::FindVariation()::charger monitor supported"));    		
       
   457 			iChargerMon = ETrue;
       
   458 			}
       
   459 		if( var[3] == '1' )//newtwork
       
   460 			{
       
   461 			FLOG(_L("CFMSServer::FindVariation()::network monitor supported"));
       
   462 			iNetworkMon = ETrue;
       
   463 			}    	
       
   464 		}	
       
   465 	}
       
   466 
       
   467 // ----------------------------------------------------------------------------------------
       
   468 // CFMSServer::ChargerTobeMonitered() 
       
   469 // ----------------------------------------------------------------------------------------
       
   470 TBool CFMSServer::ChargerTobeMonitered()
       
   471 	{
       
   472 	FLOG(_L("CFMSServer::ChargerTobeMonitered()::charger monitor check"));
       
   473 	return iChargerMon;
       
   474 	}
       
   475 
       
   476 // ----------------------------------------------------------------------------------------
       
   477 // CFMSServer::NetworkTobeMonitered() 
       
   478 // ----------------------------------------------------------------------------------------
       
   479 TBool CFMSServer::NetworkTobeMonitered()
       
   480 	{
       
   481 	FLOG(_L("CFMSServer::NetworkTobeMonitered()::network monitor check"));
       
   482 	return iNetworkMon;
       
   483 	}
       
   484 
       
   485 // ----------------------------------------------------------------------------------------
       
   486 // CFMSServer::MoniterAfterPhoneRestart() 
       
   487 // ----------------------------------------------------------------------------------------
       
   488 TBool CFMSServer::MoniterAfterPhoneRestart()
       
   489 	{
       
   490 	FLOG(_L("CFMSServer::MoniterAfterPhoneRestart()::phonerestart monitor check"));
       
   491 	return iPhoneRestartMon;
       
   492 	}
       
   493 
       
   494 // ----------------------------------------------------------------------------------------
       
   495 // CFMSServer::MemoryTobeMonitered() 
       
   496 // ----------------------------------------------------------------------------------------
       
   497 TBool CFMSServer::MemoryTobeMonitered()
       
   498 	{
       
   499 	FLOG(_L("CFMSServer::MemoryTobeMonitered()::memory monitor check"));
       
   500 	return iMemoryMon;
       
   501 	}
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // CFMSServer::StartMonitoring()
       
   505 // -----------------------------------------------------------------------------
       
   506 void CFMSServer::StartMonitoringL(TFmsIpcCommands aType)
       
   507 	{
       
   508 	// A new session is being created	
       
   509 	FLOG(_L("CFMSServer::StartMonitoringL>>"));
       
   510 	if( iSessionCount == 0 ) 
       
   511 		{
       
   512 		++iSessionCount;		
       
   513 		iFMSInterruptAob.StartL(aType);
       
   514 		}
       
   515 		FLOG(_L("CFMSServer::StartMonitoringL<<"));
       
   516 	}
       
   517 
       
   518 // -----------------------------------------------------------------------------
       
   519 // CFMSServer::DeleteFile()
       
   520 // -----------------------------------------------------------------------------
       
   521 void CFMSServer::DeleteFile(TBool aValue)
       
   522 	{	
       
   523 	iDeleteFile = aValue;
       
   524 	}
       
   525 // ----------------------------------------------------------------------------------------
       
   526 // CFMSServer::~CFMSServer() 
       
   527 // ----------------------------------------------------------------------------------------
       
   528 CFMSServer::~CFMSServer()
       
   529 {
       
   530 FLOG(_L("CFMSServer::~CFMSServer())"));
       
   531 //iFMSInterruptAob.Cancel();
       
   532 if(iDeleteFile)
       
   533 	{
       
   534 	TInt err = iFs.Delete(KFotaInterruptFileName);
       
   535 	FLOG(_L("CFMSServer::~CFMSServer() File Deleted with error as %d"),err);
       
   536 	}
       
   537 if(iLogAsyncRequest)
       
   538 	{
       
   539 	FLOG(_L("CFMSServer::~CFMSServer():-iLogAsyncRequest cancel)"));
       
   540 	iLogAsyncRequest->Cancel();
       
   541 	delete iLogAsyncRequest;
       
   542 	iLogAsyncRequest = NULL;
       
   543 	}
       
   544 iFs.Close();	
       
   545 }
       
   546 
       
   547 // ----------------------------------------------------------------------------------------
       
   548 // CFMSServer::NewSessionL() 
       
   549 // ----------------------------------------------------------------------------------------
       
   550 CSession2* CFMSServer::NewSessionL(const TVersion&,const RMessage2&) const
       
   551 {
       
   552 return new (ELeave) CFMSSession();
       
   553 }
       
   554 
       
   555 // ----------------------------------------------------------------------------------------
       
   556 // CFMSServer::RequestPending() 
       
   557 // Any request pending
       
   558 // ----------------------------------------------------------------------------------------
       
   559 TBool CFMSServer::RequestPending()
       
   560 	{
       
   561 	if( iSessionCount > 0 )
       
   562 		{
       
   563 		return ETrue;
       
   564 		}
       
   565 	return EFalse;
       
   566 	}
       
   567 
       
   568 // ----------------------------------------------------------------------------
       
   569 // CFMSServer::AsyncSessionRequestL() 
       
   570 // Asynchronous request logging
       
   571 // ----------------------------------------------------------------------------
       
   572 void CFMSServer::AsyncSessionRequestL()
       
   573 	{
       
   574 	if(iLogAsyncRequest)
       
   575 		{
       
   576 		FLOG(_L("CFMSServer::AsyncSessionRequestL():-iLogAsyncRequest cancel)"));
       
   577 		iLogAsyncRequest->Cancel();
       
   578 		delete iLogAsyncRequest;
       
   579 		iLogAsyncRequest = NULL;
       
   580 		}
       
   581 	iLogAsyncRequest = CPeriodic::NewL (EPriorityNormal) ;
       
   582 	FLOG(_L("CFMSServer::AsyncSessionRequestL():-iLogAsyncRequest created)"));
       
   583 	iLogAsyncRequest->Start(
       
   584 			TTimeIntervalMicroSeconds32(KRequestTriggerWaitTime*4)
       
   585 			, TTimeIntervalMicroSeconds32(KRequestTriggerWaitTime*4)
       
   586 			, TCallBack(LogNwRequestL,this) ) ;
       
   587 	FLOG(_L("CFMSServer::AsyncSessionRequestL():-Request logged)"));
       
   588 	}
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // CFMSServer::AsyncSessionRequestL() 
       
   592 // Asynchronous request logging
       
   593 // -----------------------------------------------------------------------------
       
   594 void CFMSServer::StopAsyncRequest()
       
   595 	{
       
   596 	FLOG(_L("CFMSServer::StopAsyncRequest():-Begin)"));
       
   597 	if(iLogAsyncRequest)
       
   598 		{
       
   599 		FLOG(_L("CFMSServer::StopAsyncRequest():-cancelling the request)"));
       
   600 		iLogAsyncRequest->Cancel();
       
   601 		delete iLogAsyncRequest;
       
   602 		iLogAsyncRequest = NULL;
       
   603 		}
       
   604 	FLOG(_L("CFMSServer::StopAsyncRequest():-End)"));
       
   605 	}
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CFMSServer::StartBatteryMonitoringL() 
       
   609 // Monitors for the battery
       
   610 // -----------------------------------------------------------------------------
       
   611 void CFMSServer::StartBatteryMonitoringL(TFmsIpcCommands aType, TUint aLevel)
       
   612 	{
       
   613 	// A new session is being created	
       
   614 	FLOG(_L("CFMSServer::StartMonitoringL, level = %d>>"), aLevel);
       
   615 	if( iSessionCount == 0 ) 
       
   616 		{
       
   617 		++iSessionCount;		
       
   618 		iFMSInterruptAob.StartBatteryMonitoringL(aType, aLevel);
       
   619 		}
       
   620 		FLOG(_L("CFMSServer::StartMonitoringL<<"));
       
   621 	}
       
   622 // -----------------------------------------------------------------------------
       
   623 // CFMSServer::StartUpdateInterruptMonitoringL() 
       
   624 // Monitors for the update interrupt type
       
   625 // -----------------------------------------------------------------------------
       
   626 void CFMSServer::StartUpdateInterruptMonitoringL(TFmsIpcCommands aType)
       
   627 	{
       
   628 	// A new session is being created	
       
   629 	FLOG(_L("CFMSServer::StartUpdateInterruptMonitoringL>>"));
       
   630 	if(EUpdMonitorPhoneCallEnd == aType)
       
   631 	    {
       
   632 	    iFMSInterruptAob.StartCallEndMonitoringL(aType);
       
   633 	    }
       
   634 	else
       
   635 	    {
       
   636 	    FLOG(_L("reason unknown"));
       
   637 	    }
       
   638 		FLOG(_L("CFMSServer::StartUpdateInterruptMonitoringL<<"));
       
   639 	}
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 // CFMSServer::CheckPhoneCallActiveL() 
       
   643 // checks any phone call is there or not at this moment
       
   644 // -----------------------------------------------------------------------------
       
   645 void CFMSServer::CheckPhoneCallActiveL(TInt& aStatus)
       
   646     {
       
   647     FLOG(_L("CFMSServer::CheckPhoneCallActiveL>>"));
       
   648     TInt callstatus(KErrNotFound);
       
   649     RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState, callstatus);
       
   650     //check ctsydomainpskeys.h for different combinations, below OR condition holds good
       
   651     if(EPSCTsyCallStateUninitialized == callstatus || 
       
   652             EPSCTsyCallStateNone == callstatus ) // call not active
       
   653         {
       
   654         aStatus = EFalse;
       
   655         }
       
   656     else // call active
       
   657         {
       
   658         aStatus = ETrue;
       
   659         }
       
   660     FLOG(_L("CFMSServer::CheckPhoneCallActiveL status is %d<<"),aStatus);
       
   661     }
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // CFMSServer::MonitorPhoneCallEndL() 
       
   665 // Monitors for active phone call end
       
   666 // -----------------------------------------------------------------------------
       
   667 TBool CFMSServer::MonitorPhoneCallEndL()
       
   668     {
       
   669     TInt CallState = KErrNotFound;
       
   670 
       
   671     CheckPhoneCallActiveL(CallState);
       
   672     if(CallState)
       
   673         {
       
   674         //go for call end montioring
       
   675         LogAsyncCallMonitorL();
       
   676         return EFalse;
       
   677         }
       
   678     else //trigger fota to show install query
       
   679         {
       
   680         return ETrue;
       
   681         }
       
   682     }
       
   683 
       
   684 // -----------------------------------------------------------------------------
       
   685 // CFMSServer::LogAsyncCallMonitorL() 
       
   686 // Async request to monitor active phone call end
       
   687 // -----------------------------------------------------------------------------
       
   688 void CFMSServer::LogAsyncCallMonitorL()
       
   689     {
       
   690     if(iLogAsyncRequest)
       
   691         {
       
   692         FLOG(_L("CFMSServer::LogAsyncCallMonitorL():- cancel)"));
       
   693         iLogAsyncRequest->Cancel();
       
   694         delete iLogAsyncRequest;
       
   695         iLogAsyncRequest = NULL;
       
   696         }
       
   697     iLogAsyncRequest = CPeriodic::NewL (EPriorityNormal) ;
       
   698     FLOG(_L("CFMSServer::LogAsyncCallMonitorL(): created)"));
       
   699     iLogAsyncRequest->Start(
       
   700             TTimeIntervalMicroSeconds32(KRequestTriggerWaitTime*1)
       
   701             , TTimeIntervalMicroSeconds32(KRequestTriggerWaitTime*4)
       
   702             , TCallBack(LogCallEndMonitorRequestL,this) ) ;
       
   703     FLOG(_L("CFMSServer::LogAsyncCallMonitorL():-Request logged)"));
       
   704     }
       
   705 
       
   706 
       
   707 void CFMSServer::CreateScheduledReminderL()
       
   708     {
       
   709     FLOG(_L("CFMSServer::CreateScheduledReminderL ()"));
       
   710     _LIT(KFotaScheduleExe, "Z:\\sys\\bin\\fotaschedulehandler.exe");
       
   711 
       
   712     RScheduler scheduler;
       
   713     TTsTime startTime;
       
   714     TTime time;
       
   715     time.HomeTime();
       
   716     time = time + (TTimeIntervalHours(1));
       
   717     startTime.SetLocalTime(time);
       
   718 
       
   719     User::LeaveIfError(scheduler.Connect());
       
   720     CleanupClosePushL(scheduler);
       
   721     //Creating a persistent daily schedule
       
   722     
       
   723     TSchedulerItemRef persistentScheduleItem;
       
   724     CArrayFixFlat<TScheduleEntryInfo2>* entries = new CArrayFixFlat<TScheduleEntryInfo2> (1);
       
   725     CleanupStack::PushL(entries);
       
   726     persistentScheduleItem.iName = TUid::Uid(KFMSServerUid).Name();
       
   727 
       
   728     //TScheduleEntryInfo2 scentry1(startTime, EDaily, 1, 1);
       
   729     TScheduleEntryInfo2 scentry1;
       
   730     scentry1.SetStartTime(startTime);
       
   731     scentry1.SetInterval(1);
       
   732     scentry1.SetIntervalType(TIntervalType(EHourly));
       
   733     scentry1.SetValidityPeriod((TTimeIntervalMinutes) 1440); //1440 min = 24 hrs or 1 day
       
   734     
       
   735     entries->AppendL(scentry1);
       
   736 
       
   737     scheduler.Register(TFileName( KFotaScheduleExe ), 0 );
       
   738     TInt ret = scheduler.CreatePersistentSchedule(persistentScheduleItem, *entries);
       
   739 
       
   740     FLOG(_L("created schedule %d  %d:%d"), persistentScheduleItem.iHandle,
       
   741             time.DateTime().Hour(), time.DateTime().Minute());
       
   742 
       
   743     if (ret == KErrNone)
       
   744         {
       
   745         TTaskInfo taskInfo;
       
   746         taskInfo.iName = TUid::Uid(KFMSServerUid).Name();
       
   747         taskInfo.iRepeat = 1; //Repeat once
       
   748         taskInfo.iPriority = 1;
       
   749 
       
   750         TFotaScheduledUpdate fotareminder(-1, -1);
       
   751         TPckg<TFotaScheduledUpdate> fotareminderpkg(fotareminder);
       
   752 
       
   753         HBufC* data = HBufC::NewLC(fotareminderpkg.Length());
       
   754         data->Des().Copy(fotareminderpkg);
       
   755 
       
   756         TInt err = scheduler.ScheduleTask(taskInfo, *data,  persistentScheduleItem.iHandle);
       
   757 
       
   758         FLOG(_L("Schedule creation error %d"), err);
       
   759 
       
   760         CleanupStack::PopAndDestroy(data);
       
   761         }
       
   762     CleanupStack::PopAndDestroy(entries);
       
   763     CleanupStack::PopAndDestroy(&scheduler); // xx
       
   764     }
       
   765 
       
   766 
       
   767 void CFMSServer::DeleteScheduledRemindersL()
       
   768     {
       
   769     FLOG(_L("CFMSServer::DeleteScheduledRemindersL >>"));
       
   770     
       
   771     TScheduleEntryInfo2                     ret;
       
   772     TInt                                    err;    
       
   773     RScheduler                              sc;
       
   774     TTime                                   t; 
       
   775     TTsTime                                 time;
       
   776     TSchedulerItemRef                       scitem; 
       
   777     CArrayFixFlat<TSchedulerItemRef>*       aSchRefArray = new CArrayFixFlat <TSchedulerItemRef>(5);
       
   778     TScheduleFilter                         aFilter(EAllSchedules);
       
   779     User::LeaveIfError( sc.Connect() ); 
       
   780     CleanupClosePushL( sc );
       
   781     CleanupStack::PushL(aSchRefArray);
       
   782 
       
   783     User::LeaveIfError( sc.GetScheduleRefsL( *aSchRefArray,aFilter) );
       
   784     FLOG(_L("Schedule items: "));
       
   785     for ( TInt i=0; i<aSchRefArray->Count(); ++i  )
       
   786     {
       
   787     TSchedulerItemRef it = (*aSchRefArray)[i];
       
   788     if ( it.iName == TUid::Uid(KFMSServerUid).Name()  )
       
   789         {
       
   790         TScheduleState2 sc_state;
       
   791         CArrayFixFlat<TScheduleEntryInfo2>*  sc_entries = new CArrayFixFlat <TScheduleEntryInfo2>(5);
       
   792         CArrayFixFlat<TTaskInfo>*            sc_tasks  = new CArrayFixFlat <TTaskInfo>(5);
       
   793         TTsTime                              sc_duetime;
       
   794         CleanupStack::PushL( sc_entries );
       
   795         CleanupStack::PushL( sc_tasks );
       
   796         FLOG (_L("%d. schedule handle: %d name:'%S'"),i,it.iHandle, &(it.iName) );
       
   797 
       
   798         err = sc.GetScheduleL ( it.iHandle , sc_state, *sc_entries,*sc_tasks,sc_duetime ); // xx
       
   799 
       
   800         TDateTime  dtm = sc_duetime.GetLocalTime().DateTime();
       
   801         FLOG(_L("   schedule duetime:%d:%d"), dtm.Hour(), dtm.Minute());
       
   802 
       
   803         if ( err ) FLOG(_L("     schedule  sc get err %d"),err);
       
   804         else 
       
   805             {
       
   806             for ( TInt k=0; k<sc_entries->Count();++k)
       
   807                 {
       
   808                 TScheduleEntryInfo2 sc_entry = (*sc_entries)[k];
       
   809                 ret = sc_entry;
       
   810                 TTime sctime = sc_entry.StartTime().GetLocalTime();
       
   811                 FLOG(_L("         schedule entry %d int-type:%d int:%d start: %d:%d"),k,sc_entry.IntervalType(),sc_entry.Interval(),sctime.DateTime().Hour(),sctime.DateTime().Minute());
       
   812                 }
       
   813 
       
   814             for ( TInt j=0; j<sc_tasks->Count();++j)
       
   815                 {
       
   816                 TTaskInfo sc_task = (*sc_tasks)[j];
       
   817                 FLOG(_L("         schedule task  %d  '%S'"),sc_task.iTaskId,&(sc_task.iName) );
       
   818                 if ( sc_task.iName==TUid::Uid(KFMSServerUid).Name() )
       
   819                     {
       
   820                     FLOG(_L("          schedule DeleteTask %d"),sc_task.iTaskId);
       
   821                     User::LeaveIfError( sc.DeleteTask(sc_task.iTaskId) );
       
   822                     }
       
   823                 }
       
   824             }
       
   825 
       
   826         FLOG(_L("     DeleteSchedule %d"),it.iHandle);
       
   827         err = sc.DeleteSchedule(it.iHandle );
       
   828 		FLOG(_L("Delete status of tasks = %d"), err);
       
   829 
       
   830         CleanupStack::PopAndDestroy( sc_tasks );
       
   831         CleanupStack::PopAndDestroy( sc_entries );
       
   832         }
       
   833     }
       
   834     CleanupStack::PopAndDestroy( aSchRefArray );
       
   835     CleanupStack::PopAndDestroy(&sc);
       
   836     
       
   837     FLOG(_L("CFMSServer::DeleteScheduledRemindersL <<"));
       
   838     }
       
   839 //End of file