fotaapplication/fotaserver/FotaScheduleHandler/src/fotaschedulehandler.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 0 b497e44ab2fc
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:   Handles scheduled update, starts fotaserver and request upd
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <schinfo.h>
       
    21 #include <schtask.h>
       
    22 #include <s32file.h>
       
    23 #include <e32math.h>
       
    24 #include <e32cons.h>
       
    25 
       
    26 #include "FotaSchedDebug.h"
       
    27 #include "fotaengine.h"
       
    28 #include "../../inc/FotaIPCTypes.h"
       
    29 
       
    30 // Constants
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // UpdateFirmwareL
       
    34 //
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 LOCAL_D void UpdateFirmwareL(RFile& aTaskFile)
       
    38 	{
       
    39     FLOG(_L("fotaschedulehandler UpdateFirmwareL(RFile& aTaskFile)"));
       
    40     TInt err;
       
    41     CFileStore*         store;
       
    42     RStoreReadStream    instream;
       
    43     // Get tasks from scheduler's store
       
    44     store = CDirectFileStore::FromLC(aTaskFile);
       
    45     instream.OpenLC(*store,store->Root());
       
    46     TInt count = instream.ReadInt32L();
       
    47     FLOG(_L("fotaschedulehandler  task count  %d"),count );
       
    48 	for (TInt i=0;i<count;i++)
       
    49         {
       
    50 		CScheduledTask* task = CScheduledTask::NewLC(instream);
       
    51         HBufC* b = const_cast<HBufC*>(&(task->Data()));
       
    52         TPtr ptr = b->Des();
       
    53         HBufC8* b8 = HBufC8::NewLC( b->Length() );
       
    54         b8->Des().Copy(ptr);
       
    55         TFotaScheduledUpdate fotareminder(-1,-1);
       
    56         TPckg<TFotaScheduledUpdate>   fotareminderpkg(fotareminder);
       
    57         fotareminderpkg.Copy(b8->Des());
       
    58         CleanupStack::PopAndDestroy( b8 );
       
    59         FLOG(_L("fotaschedulehandler packageid:%d  sched:%d"),fotareminder.iPkgId, fotareminder.iScheduleId);
       
    60         RFotaEngineSession fota;
       
    61         fota.OpenL();
       
    62         CleanupClosePushL( fota );
       
    63         err = fota.ScheduledUpdateL (fotareminder);
       
    64         if(err){} // to remove compiler warning
       
    65         FLOG(_L("fotaschedulehandler       2........ err %d"),err);
       
    66         fota.Close();
       
    67         FLOG(_L("fotaschedulehandler       3 "));
       
    68         CleanupStack::PopAndDestroy( &fota); 
       
    69 		CleanupStack::PopAndDestroy(task);
       
    70         }
       
    71 	CleanupStack::PopAndDestroy( &instream ); 
       
    72 	CleanupStack::PopAndDestroy( store ); 
       
    73 	}
       
    74 
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // ExecuteL
       
    78 //
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 LOCAL_D TInt ExecuteL()
       
    82 	{
       
    83 	TInt err = KErrNoMemory;
       
    84 		
       
    85 	RFile file;
       
    86 		
       
    87 	// Adopt the task file from the Task Scheduler
       
    88 	err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(),
       
    89 									TScheduledTaskFile::FileHandleIndex());
       
    90     FLOG(_L("  err  %d"),err );
       
    91 	User::LeaveIfError(err);
       
    92 	
       
    93 	TRAP(err, UpdateFirmwareL(file));
       
    94 	
       
    95 	file.Close();
       
    96 	
       
    97 	User::LeaveIfError(err);		
       
    98 	return err;
       
    99 	}
       
   100 
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // Execute
       
   104 //
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 LOCAL_D TInt Execute()
       
   108 	{
       
   109     FLOG(_L("fotaschedulehandler Execute()"));
       
   110 	TInt err = KErrNoMemory;
       
   111 	
       
   112 	// construct and install active scheduler
       
   113 	CActiveScheduler* scheduler = new CActiveScheduler;
       
   114 	if (!scheduler)
       
   115 		{
       
   116 		return err;
       
   117 		}
       
   118 	CActiveScheduler::Install(scheduler);
       
   119 	CTrapCleanup* cleanupStack = CTrapCleanup::New();
       
   120 	if (cleanupStack)
       
   121 		{
       
   122         TRAP(err, ExecuteL());
       
   123 		delete cleanupStack;
       
   124 		}
       
   125     delete scheduler;
       
   126 	return err;
       
   127 	}
       
   128 
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // E32Main
       
   132 //
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 GLDEF_C TInt E32Main()
       
   136 	{
       
   137 	return Execute();
       
   138 	}
       
   139 
       
   140 
       
   141