browserutilities/feedsengine/FeedsServer/Server/src/FeedsServer.cpp
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2005 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 the License "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:  The FeedsServer main server class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "FeedsDatabase.h"
       
    20 #include "FeedHandler.h"
       
    21 #include "FeedsServer.h"
       
    22 #include "FeedsServerMsg.h"
       
    23 #include "FeedsServerSession.h"
       
    24 #include "OpmlParser.h"
       
    25 #include "OpmlWriter.h"
       
    26 #include "PackedFolder.h"
       
    27 #include "ServerHttpConnection.h"
       
    28 #include "Logger.h"
       
    29 #include "XmlUtils.h"
       
    30 #include "BackRestoreHandler.h"
       
    31 #include "UpdateManager.h" 
       
    32 
       
    33 //  CONSTANTS
       
    34 _LIT(KFeedsServerPanic, "FeedsServer");
       
    35 
       
    36 //_LIT(KFileSchema, "file://c:");
       
    37 _LIT(KDefaultFeed, "default_feeds.xml");
       
    38 
       
    39 _LIT(KDefaultOPMLFileParam, "");
       
    40 
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CFeedsServer::NewL
       
    44 //
       
    45 // Two-phased constructor.
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CFeedsServer* CFeedsServer::NewL()
       
    49     {
       
    50     CFeedsServer* self = new (ELeave) CFeedsServer(EPriorityNormal);
       
    51 
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop();
       
    55     
       
    56     return self;
       
    57     }
       
    58 
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CFeedsServer::NewL
       
    62 //
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CFeedsServer::ConstructL()
       
    67     {
       
    68 		StartL(KFeedsServerName);
       
    69 		iBackRestoreHandler = CBackRestoreHandler::NewL(this);
       
    70 		iBackRestoreHandler->StartListening();
       
    71     }
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CFeedsServer::CFeedsServer
       
    76 //
       
    77 // C++ default constructor can NOT contain any code that
       
    78 // might leave.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CFeedsServer::CFeedsServer(TInt aPriority):
       
    82         CServer2(aPriority), iLeakTracker(CLeakTracker::EFeedsServer), iIsSleeping(ETrue)
       
    83     {
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CFeedsServer::~CFeedsServer
       
    89 //
       
    90 // Destructor
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CFeedsServer::~CFeedsServer()
       
    94     {
       
    95     SleepServer();    
       
    96     delete iBackRestoreHandler;
       
    97     iBackRestoreHandler = NULL;   
       
    98     }
       
    99 
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CFeedsServer::NewSessionL
       
   103 //
       
   104 // Create session(s) to client(s)
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 CSession2* CFeedsServer::NewSessionL(const TVersion& aVersion, 
       
   108         const RMessage2& /*aMessage*/) const
       
   109     {
       
   110     // check we're the right version
       
   111     TVersion srvVersion(KFeedsServerMajorVersionNumber,
       
   112                         KFeedsServerMinorVersionNumber,
       
   113                         KFeedsServerBuildVersionNumber);
       
   114 
       
   115     if (!User::QueryVersionSupported(srvVersion, aVersion))
       
   116         {
       
   117         User::Leave(KErrNotSupported);
       
   118         }
       
   119 
       
   120     // make new session
       
   121     return (CFeedsServerSession::NewL(*(const_cast<CFeedsServer*>(this))));
       
   122     }
       
   123 
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CFeedsServer::RunServerL
       
   127 // 
       
   128 // Runs the server.
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CFeedsServer::RunServerL()
       
   132 	{
       
   133 	CActiveScheduler*  scheduler = NULL;
       
   134 	CFeedsServer*      server = NULL;
       
   135 
       
   136     // Naming the server thread after the server helps to debug panics.
       
   137 	User::LeaveIfError(User::RenameThread(KFeedsServerName));
       
   138 
       
   139 	// Create and install the active scheduler.
       
   140 	scheduler = new (ELeave) CActiveScheduler;
       
   141 	CleanupStack::PushL(scheduler);
       
   142 	CActiveScheduler::Install(scheduler);
       
   143 
       
   144 	// Create the server (leave it on the cleanup stack)
       
   145 	server = CFeedsServer::NewL();
       
   146 	CleanupStack::PushL(server);
       
   147 
       
   148 	// Initialisation complete, now signal the client
       
   149 	RProcess::Rendezvous(KErrNone);
       
   150 
       
   151 	// Ready to run.  This method doesn't return until the server is shutdown.
       
   152 	CActiveScheduler::Start();
       
   153 
       
   154 	// Cleanup.
       
   155 	CleanupStack::PopAndDestroy(server);
       
   156 	CleanupStack::PopAndDestroy(scheduler);
       
   157 	}
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CFeedsServer::PanicClient
       
   161 //
       
   162 // Utility to panic the client.
       
   163 // -----------------------------------------------------------------------------
       
   164 void CFeedsServer::PanicClient(const RMessage2& aMessage, TInt aPanic)
       
   165     {
       
   166     aMessage.Panic(KFeedsServerPanic, aPanic);
       
   167     }
       
   168 
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CFeedsServer::PanicServer
       
   172 //
       
   173 // Utility to panic the server.
       
   174 // -----------------------------------------------------------------------------
       
   175 void CFeedsServer::PanicServer(TInt aPanic)
       
   176     {
       
   177     User::Panic(KFeedsServerPanic, aPanic);
       
   178     }
       
   179 
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CFeedsServer::WakeupServerL
       
   183 //
       
   184 // Ensures the server is ready for processing requests.
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CFeedsServer::WakeupServerL()
       
   188     {
       
   189     if (iIsSleeping)
       
   190         {
       
   191         // Wake up the server.
       
   192         TRAPD(err, WakeupServerHelperL());
       
   193         
       
   194         // If the server didn't fully wake up then sleep it and re-leave the error.
       
   195         if (err != KErrNone)
       
   196             {
       
   197             SleepServer();
       
   198             User::Leave(err);
       
   199             }
       
   200         }
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CFeedsServer::WakeupServerHelperL
       
   205 //
       
   206 // A helper method to ensure the server is fully started.
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 void CFeedsServer::WakeupServerHelperL()
       
   210     {
       
   211     TBool    created;
       
   212 
       
   213     if (iIsSleeping)
       
   214         {            
       
   215         // Create the shared xml utils instance.
       
   216         iXmlUtils = CXmlUtils::NewL();
       
   217 
       
   218         // Create the handlers.
       
   219         iFeedHandler = CFeedHandler::NewL(*iXmlUtils);
       
   220         iFolderHandler = COpmlParser::NewL(*iXmlUtils);
       
   221 
       
   222         // Create the database instance.
       
   223         iFeedsDatabase = CFeedsDatabase::NewL(this,created);
       
   224         
       
   225         // If the database was newly created then load the default feeds into the 
       
   226         // the database.
       
   227         if (created)
       
   228             {
       
   229             RFs                 rfs;
       
   230             TBuf<KMaxFileName>  path;
       
   231             RFile               file;
       
   232             CPackedFolder*      packedFolder = NULL;
       
   233             
       
   234             // Ensure that the default folder file is copied from ROM. 
       
   235             EnsureDefaultFolderFileL();
       
   236             
       
   237             // Get the path to the default folder.
       
   238             User::LeaveIfError(rfs.Connect());
       
   239             CleanupClosePushL(rfs);
       
   240 
       
   241             rfs.PrivatePath(path);
       
   242             path.Append(KDefaultFeed);
       
   243             User::LeaveIfError(file.Open(rfs, path, EFileRead | EFileShareReadersOnly));
       
   244             CleanupClosePushL(file);
       
   245 
       
   246             // Import the default folder file synchronously.
       
   247             packedFolder = ImportFolderL(file, KDefaultOPMLFileParam);
       
   248             
       
   249             CleanupStack::PopAndDestroy(/*file*/);
       
   250             CleanupStack::PopAndDestroy(/*rfs*/);
       
   251 
       
   252             CleanupStack::PushL(packedFolder);
       
   253 
       
   254             // Load it into the database.
       
   255             iFeedsDatabase->ImportFolderL(KDefaultFolderListId, *packedFolder); 
       
   256             CleanupStack::PopAndDestroy(packedFolder);
       
   257             
       
   258             // Compact the database.
       
   259             iFeedsDatabase->Compact();
       
   260 
       
   261             }
       
   262 
       
   263         ScheduleUpdateManagerL(); 
       
   264                 
       
   265         iIsSleeping = EFalse;
       
   266         }
       
   267     }
       
   268 
       
   269 
       
   270 // -----------------------------------------------------------------------------
       
   271 // CFeedsServer::SleepServer
       
   272 //
       
   273 // Put the server in a resource reduced mode.
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CFeedsServer::SleepServer()
       
   277     {
       
   278     iIsSleeping = ETrue;
       
   279     
       
   280     for( int i=0; i<iUpdateManagerList.Count(); i++ )
       
   281         {
       
   282         delete iUpdateManagerList[ i ];
       
   283         }
       
   284     iUpdateManagerList.Reset();
       
   285 
       
   286     delete iFeedHandler;
       
   287     iFeedHandler = NULL;
       
   288     
       
   289     delete iFolderHandler;
       
   290     iFolderHandler = NULL;
       
   291     
       
   292     delete iFeedsDatabase;
       
   293     iFeedsDatabase = NULL;
       
   294     
       
   295     delete iXmlUtils;
       
   296     iXmlUtils = NULL;
       
   297     }
       
   298 
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CFeedsServer::NotifyFolderListChanged
       
   302 //
       
   303 // Notify the open sessions that the given folder-list changed.
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 void CFeedsServer::NotifyFolderListChanged(TInt aFolderListId)
       
   307     {
       
   308     CSession2*  session = NULL;
       
   309 
       
   310     // Notify all of the open sessions.    
       
   311     iSessionIter.SetToFirst();
       
   312     while ((session = iSessionIter++) != NULL)
       
   313         {
       
   314         static_cast<CFeedsServerSession*>(session)->NotifyFolderListChanged(aFolderListId);
       
   315         }
       
   316     }
       
   317 
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // CFeedsServer::NotifySettingsChanged
       
   321 //
       
   322 // Notify the open sessions that the given folder-list changed.
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CFeedsServer::NotifySettingsChanged(TInt aFolderListId)
       
   326     {
       
   327     CSession2*  session = NULL;
       
   328 
       
   329     // Notify all of the open sessions.    
       
   330     iSessionIter.SetToFirst();
       
   331     while ((session = iSessionIter++) != NULL)
       
   332         {
       
   333         static_cast<CFeedsServerSession*>(session)->NotifySettingsChanged(aFolderListId);
       
   334         }
       
   335     }
       
   336     
       
   337     
       
   338 #if 0
       
   339 // -----------------------------------------------------------------------------
       
   340 // CFeedsServer::PurgeOldItems
       
   341 //
       
   342 // A method used to purge old feed-items in the background every so often.
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 TInt CFeedsServer::PurgeOldItems(TAny *aPtr)
       
   346     {
       
   347     CFeedsServer*  self = static_cast<CFeedsServer*>(aPtr);
       
   348     
       
   349     TRAPD(err, self->PurgeOldItemsL());    
       
   350     return err;
       
   351     }
       
   352     
       
   353     
       
   354 // -----------------------------------------------------------------------------
       
   355 // CFeedsServer::PurgeOldItemsL
       
   356 //
       
   357 // A method used to purge old feed-items in the background every so often.
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 void CFeedsServer::PurgeOldItemsL()
       
   361     {
       
   362     WakeupServerL();
       
   363 
       
   364     // Purge any old items.
       
   365     TTime yesterday;
       
   366     
       
   367     yesterday.UniversalTime();
       
   368     yesterday -= TTimeIntervalDays(1);
       
   369     
       
   370     iFeedsDatabase->PurgeOldItemsL(yesterday);
       
   371     }
       
   372 #endif
       
   373     
       
   374     
       
   375 // -----------------------------------------------------------------------------
       
   376 // CFeedsServer::ImportFolderL
       
   377 //
       
   378 // Loads and parsers the folder of feeds at the given path.
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 CPackedFolder* CFeedsServer::ImportFolderL(const RFile aFile, const TDesC& aOPMLFileName)
       
   382     {
       
   383     TInt            size;
       
   384     HBufC8*         buffer = NULL;
       
   385     TPtr8           bufferPtr(NULL, 0);
       
   386     CPackedFolder*  packedFolder = NULL;
       
   387 
       
   388     // Read file
       
   389     User::LeaveIfError(aFile.Size(size));
       
   390 
       
   391     buffer = HBufC8::NewLC(size);
       
   392     bufferPtr.Set(buffer->Des());
       
   393 
       
   394     User::LeaveIfError(aFile.Read(bufferPtr, size));
       
   395 
       
   396     // Parse the buffer
       
   397     packedFolder = iFolderHandler->ParseL(*buffer, KNullDesC, KNullDesC, aOPMLFileName);
       
   398 
       
   399     // Clean up.
       
   400     CleanupStack::PopAndDestroy(buffer);
       
   401 
       
   402     return packedFolder;
       
   403     }
       
   404 
       
   405 void CFeedsServer::ExportFolderL(RArray<TInt> &aEntries, const TDesC& aExportFileName)
       
   406 	{
       
   407     // Export folders to an OPML buffer
       
   408 	OpmlWriter::ExportL(aEntries, aExportFileName);
       
   409 	}
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // CFeedsServer::EnsureDefaultFolderFileL
       
   413 //
       
   414 // If need be copy default folder file from ROM.
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 void CFeedsServer::EnsureDefaultFolderFileL()
       
   418     {
       
   419     TInt                err;
       
   420     RFs                 defaultRfs;
       
   421     TUint               attValue = 0;
       
   422     TBuf<KMaxFileName>  path;
       
   423 
       
   424     // Open a connection to the working drive.
       
   425     User::LeaveIfError(defaultRfs.Connect());
       
   426     CleanupClosePushL(defaultRfs);
       
   427     User::LeaveIfError(defaultRfs.SetSessionPath(_L("c:\\")));
       
   428     
       
   429     // Build the path to the file.
       
   430     defaultRfs.PrivatePath(path);
       
   431     path.Append(KDefaultFeed);
       
   432 
       
   433     // Test whether or not the folder file is present.
       
   434     err = defaultRfs.Att(path, attValue);
       
   435 
       
   436     // The file is there, just return.
       
   437     if (err == KErrNone)
       
   438         {
       
   439         CleanupStack::PopAndDestroy(/*defaultRfs*/);    
       
   440         return;
       
   441         }
       
   442         
       
   443     // If the file is missing copy it from ROM.
       
   444     if ((err == KErrNotFound) || (err == KErrPathNotFound))
       
   445         {
       
   446         RFs      romRfs;
       
   447         RFile    file;
       
   448         RFile    romFile;
       
   449         TInt     size;
       
   450         HBufC8*  buffer = NULL;    
       
   451 
       
   452         // Ensure the private path is defined on the c drive.
       
   453         (void) defaultRfs.CreatePrivatePath(EDriveC);
       
   454         
       
   455         // Open an rfs for the z drive.        
       
   456         User::LeaveIfError(romRfs.Connect());
       
   457         CleanupClosePushL(romRfs);
       
   458         User::LeaveIfError(romRfs.SetSessionPath(_L("z:\\")));
       
   459 
       
   460         // Create the destination file.
       
   461         User::LeaveIfError(file.Create(defaultRfs, path, EFileWrite));
       
   462         CleanupClosePushL(file);
       
   463         
       
   464         // Open the source file.
       
   465         User::LeaveIfError(romFile.Open(romRfs, path, EFileRead));
       
   466         CleanupClosePushL(romFile);
       
   467         
       
   468         // Copy the file.
       
   469         User::LeaveIfError(romFile.Size(size));
       
   470         buffer = HBufC8::NewLC(size);
       
   471         TPtr8 bufferPtr(buffer->Des());
       
   472         
       
   473         User::LeaveIfError(romFile.Read(bufferPtr, size));
       
   474         User::LeaveIfError(file.Write(bufferPtr, size));
       
   475           
       
   476         // Clean up
       
   477         CleanupStack::PopAndDestroy(buffer);
       
   478         CleanupStack::PopAndDestroy(/*romFile*/);
       
   479         CleanupStack::PopAndDestroy(/*file*/);
       
   480         CleanupStack::PopAndDestroy(/*romRfs*/);    
       
   481         CleanupStack::PopAndDestroy(/*defaultRfs*/);    
       
   482         }
       
   483         
       
   484     // Otherwise leave.
       
   485     else
       
   486         {
       
   487         User::LeaveIfError(err);
       
   488         }
       
   489     }
       
   490 
       
   491 // -----------------------------------------------------------------------------
       
   492 // CFeedsServer::SessionOpened
       
   493 //
       
   494 // Called from CFeedsServerSession when a session is opened.
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 void CFeedsServer::SessionOpened()
       
   498     {
       
   499     iSessionCount++;
       
   500     }
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CFeedsServer::SessionClosed
       
   504 //
       
   505 // Called from CFeedsServerSession when a session is closed.
       
   506 // -----------------------------------------------------------------------------
       
   507 //
       
   508 void CFeedsServer::SessionClosed()
       
   509     {
       
   510     iSessionCount--;
       
   511     
       
   512     // If all of the sessions are closed then terminate the server.
       
   513     //
       
   514     // TODO: Create a timer to delay the shutdown for 20 mins or so, in case
       
   515     //       the client crashes.
       
   516     // Don't want to shut down feedsserver to ensure autoupdate can occur
       
   517     if ( iSessionCount <= 0 && !CheckForUpdate() )
       
   518          {
       
   519          CActiveScheduler::Stop();
       
   520          }
       
   521     }
       
   522 
       
   523 // -----------------------------------------------------------------------------
       
   524 // CFeedsServer::SetAutoUpdateSettingsL
       
   525 //
       
   526 // Called from CFeedsServerSession when setting changed.
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 void CFeedsServer::SetAutoUpdateSettingsL( TInt aFolderListId, TBool aAutoUpdate, TInt aAutoUpdateFreq, TUint32 aAutoUpdateAP, TBool aAutoUpdateWhileRoaming ) 
       
   530     {
       
   531     TBool    autoUpdate = EFalse;
       
   532     TInt     autoUpdateFreq = 0;
       
   533     TUint32  autoUpdateAP = 0;
       
   534     TBool	 autoUpdateWhileRoaming = EFalse;
       
   535     
       
   536     TRAPD( err, iFeedsDatabase->ExtractAutoUpdateSettingsL( aFolderListId, autoUpdate, autoUpdateFreq, autoUpdateAP, autoUpdateWhileRoaming ) );
       
   537     if( err != KErrNotFound && err != KErrNone )
       
   538         {
       
   539         User::Leave( err );
       
   540         }
       
   541 
       
   542     // if any setting changed regarding auto update, restart the scheduler
       
   543     if( autoUpdate != aAutoUpdate || autoUpdateFreq != aAutoUpdateFreq || autoUpdateAP != aAutoUpdateAP || autoUpdateWhileRoaming != aAutoUpdateWhileRoaming)
       
   544         {
       
   545         iFeedsDatabase->CommitAutoUpdateSettingsL( aFolderListId, aAutoUpdate, aAutoUpdateFreq, aAutoUpdateAP, aAutoUpdateWhileRoaming );
       
   546                 
       
   547         // notify all clients with the same folderListId about setting changes
       
   548         NotifySettingsChanged( aFolderListId );
       
   549 
       
   550         ScheduleUpdateManagerL( aFolderListId, aAutoUpdate, aAutoUpdateFreq, aAutoUpdateAP, aAutoUpdateWhileRoaming );        
       
   551         }
       
   552     }
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // CFeedsServer::ScheduleUpdateManagerL
       
   556 //
       
   557 // Schedule the update manager for all folder list ID
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 void CFeedsServer::ScheduleUpdateManagerL()
       
   561     {
       
   562     RArray<TInt>     folderListIds;
       
   563     TBool    autoUpdate = EFalse;
       
   564     TInt     autoUpdateFreq = 0;
       
   565     TUint32  autoUpdateAP = 0;
       
   566 	TBool    autoUpdateWhileRoaming = EFalse;
       
   567     
       
   568     TRAPD( err, iFeedsDatabase->ExtractFolderListIdInSettingsL( folderListIds ) );
       
   569     if (err == KErrNone)
       
   570         {               
       
   571         for( int i=0; i < folderListIds.Count(); i++)
       
   572             {
       
   573             // When err is KErrNotFound, autoUpdate will remain false
       
   574             TRAPD( err, iFeedsDatabase->ExtractAutoUpdateSettingsL( folderListIds[i], autoUpdate, autoUpdateFreq, autoUpdateAP, autoUpdateWhileRoaming ) );
       
   575             if (err == KErrNone)
       
   576                 {
       
   577                 ScheduleUpdateManagerL( folderListIds[i], autoUpdate, autoUpdateFreq, autoUpdateAP, autoUpdateWhileRoaming );
       
   578                 }
       
   579             }
       
   580         }
       
   581     }
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // CFeedsServer::ScheduleUpdateManagerL
       
   585 //
       
   586 // Schedule the update manager for all folder list ID
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 void CFeedsServer::ScheduleUpdateManagerL( TInt aFolderListId)
       
   590     {
       
   591     TBool    autoUpdate = EFalse;
       
   592     TInt     autoUpdateFreq = 0;
       
   593     TUint32  autoUpdateAP = 0;
       
   594 	TBool    autoUpdateWhileRoaming = EFalse;
       
   595 
       
   596     // When err is KErrNotFound, autoUpdate will remain false
       
   597     TRAPD( err, iFeedsDatabase->ExtractAutoUpdateSettingsL( aFolderListId, autoUpdate, autoUpdateFreq, autoUpdateAP, autoUpdateWhileRoaming ) );
       
   598     if (err == KErrNone)
       
   599         {
       
   600         ScheduleUpdateManagerL( aFolderListId, autoUpdate, autoUpdateFreq, autoUpdateAP, autoUpdateWhileRoaming );
       
   601         }
       
   602     }
       
   603 
       
   604 // -----------------------------------------------------------------------------
       
   605 // CFeedsServer::ScheduleUpdateManagerL
       
   606 //
       
   607 // Schedule the background update all task for one folder list ID.
       
   608 // -----------------------------------------------------------------------------
       
   609 //
       
   610 void CFeedsServer::ScheduleUpdateManagerL( TInt aFolderListId, TBool /*aAutoUpdate*/, TInt aAutoUpdateFreq, TUint32 aAutoUpdateAP, TBool aAutoUpdateWhileRoaming )
       
   611     {
       
   612     // Clear the old timer.
       
   613 
       
   614     for( int i=0; i < iUpdateManagerList.Count(); i++)
       
   615         {
       
   616         if( iUpdateManagerList[ i ]->FolderListId() == aFolderListId )
       
   617             {
       
   618             delete iUpdateManagerList[ i ];
       
   619             iUpdateManagerList.Remove(i); 
       
   620             break;
       
   621             }
       
   622         }
       
   623     CUpdateManager* updateManager = CUpdateManager::NewL( aFolderListId, aAutoUpdateAP, aAutoUpdateFreq, aAutoUpdateWhileRoaming, *this );
       
   624     updateManager->StartL();
       
   625     iUpdateManagerList.AppendL( updateManager );
       
   626     } 
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // CFeedsServer::ResetXmlUtilsL
       
   630 //
       
   631 // Called from CUpdateFeedTask::LoadCompleted when an error occurs while parsing
       
   632 // the feed.
       
   633 // -----------------------------------------------------------------------------
       
   634 //
       
   635 void CFeedsServer::ResetXmlUtilsL()
       
   636     {
       
   637     if (iFolderHandler != NULL)
       
   638         {
       
   639         delete iFolderHandler;
       
   640         iFolderHandler = NULL;
       
   641         }
       
   642         
       
   643     if (iFeedHandler != NULL)
       
   644         {
       
   645         delete iFeedHandler;
       
   646         iFeedHandler = NULL;
       
   647         }
       
   648         
       
   649     if (iXmlUtils != NULL)
       
   650         {
       
   651         delete iXmlUtils;
       
   652         iXmlUtils = NULL;
       
   653         }
       
   654     
       
   655     iXmlUtils = CXmlUtils::NewL();
       
   656     iFeedHandler = CFeedHandler::NewL(*iXmlUtils);
       
   657     iFolderHandler = COpmlParser::NewL(*iXmlUtils);
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CFeedsServer::CheckForUpdate
       
   662 //
       
   663 // Checks whether update is happening
       
   664 // -----------------------------------------------------------------------------
       
   665 //
       
   666 TBool CFeedsServer::CheckForUpdate()
       
   667     {
       
   668     for(int i = 0;i < iUpdateManagerList.Count();i++)
       
   669         {
       
   670         if(iUpdateManagerList[i]->iQueueArray.Count() > 0)
       
   671             return ETrue;
       
   672         }
       
   673     return EFalse;
       
   674     }
       
   675 
       
   676 // -----------------------------------------------------------------------------
       
   677 // CFeedsServer::UpdateFeedL()
       
   678 //
       
   679 // Update the feed ID in Update manager
       
   680 // -----------------------------------------------------------------------------
       
   681 //
       
   682 void CFeedsServer::UpdateFeedL(TInt aFolderListId, TInt aFeedId, TBool aDeleteFeed)
       
   683     {
       
   684     for( int i=0; i < iUpdateManagerList.Count(); i++)
       
   685         {
       
   686         if( iUpdateManagerList[ i ]->FolderListId() == aFolderListId )
       
   687             {
       
   688             iUpdateManagerList[ i ]->UpdateFeedL(aFeedId,aDeleteFeed);
       
   689             return;
       
   690             }
       
   691          else if(aFolderListId == KNoFolderListId)
       
   692             {
       
   693             iUpdateManagerList[ i ]->UpdateFeedL(aFeedId,aDeleteFeed);
       
   694             }
       
   695         }	
       
   696     }
       
   697