homesync/contentmanager/mediaservant/applicationengine/src/msengineao.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2008 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:  CMSEngineAO class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //  Include Files
       
    21 #include "msengineobserver.h"
       
    22 #include "msengineao.h"
       
    23 #include "msengine.h"
       
    24 #include "msdebug.h"
       
    25 
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // CMSEngineAO::CMSEngineAO
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CMSEngineAO::CMSEngineAO( CMSEngine* aEngine )
       
    32             : CActive( CActive::EPriorityStandard ),
       
    33               iEngine( aEngine )
       
    34     {
       
    35     LOG( _L( "[MediaServant ENG]\t CMSEngineAO::CMSEngineAO" ) );
       
    36     }
       
    37 
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CMSEngineAO::NewL
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CMSEngineAO* CMSEngineAO::NewL( CMSEngine* aEngine )
       
    44     {
       
    45     LOG(_L("[MediaServant ENG]\t CMSEngineAO::NewL"));
       
    46 
       
    47     CMSEngineAO* self = new ( ELeave ) CMSEngineAO( aEngine );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop( self );
       
    51     return self;
       
    52     }
       
    53 
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CMSEngineAO::ConstructL
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CMSEngineAO::ConstructL()
       
    60     {
       
    61     LOG( _L("[MediaServant]\t CMSEngineAO::ConstructL") );
       
    62 
       
    63     // Add this active object to the active scheduler.
       
    64     CActiveScheduler::Add( this );
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CMSEngineAO::~CMSEngineAO
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CMSEngineAO::~CMSEngineAO()
       
    72     {
       
    73     LOG( _L("[MediaServant ENG]\t CMSEngineAO::~CMSEngineAO") );
       
    74 
       
    75     // cancel any ongoing operation
       
    76     Cancel();
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // CMSEngineAO::RunL
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CMSEngineAO::RunL()
       
    84     {
       
    85     TRACE( Print( _L("[MediaServant ENG]\t CMSEngineAO::RunL \
       
    86     iStatus = %d" ), iStatus.Int() ) );
       
    87 
       
    88     switch ( iState )
       
    89         {
       
    90         case EMSEngineStore:
       
    91             {
       
    92             // stop if error occurs
       
    93             if ( iStatus.Int() == KErrNone  )
       
    94                 {
       
    95                 LOG(_L("[MediaServant ENG]\t CMSEngineAO::RunL start store"));
       
    96                 // Store ok, continue by executing fill operation.
       
    97                 ExecuteFillL();
       
    98                 }
       
    99             else
       
   100                 {
       
   101                 // Close server session due to error.
       
   102                 CloseServerSession();
       
   103                 // Inform the observer about error.
       
   104                 iObserver->ReadyL( iCurrentService, iStatus.Int() );
       
   105                 }
       
   106             break;
       
   107             }
       
   108         case EMSEngineFill:
       
   109         // fall through
       
   110         case EMSEngineHarvest:
       
   111         // fall through
       
   112         case EMSEngineDeleteFiles:
       
   113         // fall through
       
   114         case EMSEnginePreprocess:
       
   115         // fall through
       
   116         case EMSEngineGetMetadata:
       
   117         // fall through
       
   118         case EMSEnginePreprocessList:
       
   119         // fall through
       
   120         case EMSEngineDeleteMetadata:
       
   121         // fall through
       
   122         case EMSUpdateFillLists:
       
   123             {
       
   124             CloseServerSession();
       
   125             // report for application
       
   126             iObserver->ReadyL( iCurrentService, iStatus.Int() );
       
   127             LOG( _L("[MediaServant ENG]\t CMSEngineAO::RunL close session") );
       
   128             break;
       
   129             }
       
   130         default:
       
   131             {
       
   132             LOG( _L("[MediaServant ENG]\t CMSEngineAO::RunL \
       
   133             not valid state") );
       
   134             break;
       
   135             }
       
   136         }
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CMSEngineAO::DoCancel
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void CMSEngineAO::DoCancel()
       
   144     {
       
   145     LOG( _L( "[MediaServant ENG]\t CMSEngineAO::DoCancel" ) );
       
   146 
       
   147     iContentManager.Cancel();
       
   148     }
       
   149 
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CMSEngineAO::ScanMediaServersL
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 TInt CMSEngineAO::ScanMediaServersL()
       
   156     {
       
   157     LOG( _L( "[MediaServant ENG]\t CMSEngineAO::ScanMediaServersL" ) );
       
   158 
       
   159     // Open content manager session.
       
   160     TInt error = OpenServerSession();
       
   161 
       
   162     if ( !error )
       
   163         {
       
   164         // Session created. Update state variables and execute service.
       
   165         iCurrentService = ECmServiceHarvest;
       
   166         iState = EMSEngineHarvest;
       
   167         iContentManager.ExecuteService( ECmServiceHarvest, iStatus );
       
   168 
       
   169         if ( IsActive() )
       
   170             {
       
   171             User::Leave( KErrInUse );
       
   172             }
       
   173         else
       
   174             {
       
   175             // Enable active object
       
   176             SetActive();
       
   177             }
       
   178         }
       
   179 
       
   180     return error;
       
   181     }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // CMSEngineAO::ExecuteFillL
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 void CMSEngineAO::ExecuteFillL()
       
   188     {
       
   189     LOG( _L("[MediaServant ENG]\t CMSEngineAO::ExecuteFillL") );
       
   190 
       
   191     // Update state variables and execute fill service.
       
   192     iCurrentService = ECmServiceFill;
       
   193     iState = EMSEngineFill;
       
   194     iContentManager.ExecuteService( ECmServiceFill, iStatus );
       
   195 
       
   196     if ( IsActive() )
       
   197         {
       
   198         User::Leave( KErrInUse );
       
   199         }
       
   200     else
       
   201         {
       
   202         // Enable active object
       
   203         SetActive();
       
   204         }
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CMSEngineAO::ExecuteStoreL
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 TInt CMSEngineAO::ExecuteStoreL()
       
   212     {
       
   213     LOG( _L("[MediaServant ENG]\t CMSEngineAO::ExecuteStoreL") );
       
   214 
       
   215     iCurrentService = ECmServiceStore;
       
   216     iState = EMSEngineStore;
       
   217 
       
   218     // Open content manager session.
       
   219     TInt error = OpenServerSession();
       
   220 
       
   221     if ( !error )
       
   222         {
       
   223         iContentManager.ExecuteService( ECmServiceStore, iStatus );
       
   224 
       
   225         if ( IsActive() )
       
   226             {
       
   227             User::Leave( KErrInUse );
       
   228             }
       
   229         else
       
   230             {
       
   231             // Enable active object
       
   232             SetActive();
       
   233             }
       
   234         }
       
   235 
       
   236     return error;
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // CMSEngineAO::DeleteFilledFilesL()
       
   241 // ---------------------------------------------------------------------------
       
   242 //
       
   243 TInt CMSEngineAO::DeleteFilledFilesL()
       
   244     {
       
   245     LOG( _L("[MediaServant ENG]\t CMSEngineAO::DeleteFilledFilesL") );
       
   246 
       
   247     // Open content manager session.
       
   248     TInt error = OpenServerSession();
       
   249     iState = EMSEngineDeleteFiles;
       
   250     if ( !error )
       
   251         {
       
   252         // Session created. Update state variables and execute service.
       
   253         iCurrentService = ECmServiceDeleteFilledFiles;
       
   254         iState = EMSEngineDeleteFiles;
       
   255         error = iContentManager.ExecuteService( ECmServiceDeleteFilledFiles,
       
   256                                                 iStatus );
       
   257 
       
   258         if ( IsActive() )
       
   259             {
       
   260             User::Leave( KErrInUse );
       
   261             }
       
   262         else
       
   263             {
       
   264             // Enable active object
       
   265             SetActive();
       
   266             }
       
   267         }
       
   268 
       
   269     return error;
       
   270     }
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // CMSEngineAO::ExecuteStorePreProcessingL()
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 TInt CMSEngineAO::ExecuteStorePreProcessingL()
       
   277     {
       
   278     LOG( _L("[MediaServant ENG]\t CMSEngineAO::ExecuteStorePreProcessingL") );
       
   279 
       
   280     // Open content manager session.
       
   281     TInt error = OpenServerSession();
       
   282 
       
   283     if ( !error )
       
   284         {
       
   285         iCurrentService = ECmServicePreProcessingStore;
       
   286         iState = EMSEnginePreprocess;
       
   287         error = iContentManager.ExecuteService( ECmServicePreProcessingStore,
       
   288                                                 iStatus );
       
   289 
       
   290         if ( IsActive() )
       
   291             {
       
   292             User::Leave( KErrInUse );
       
   293             }
       
   294         else
       
   295             {
       
   296             // Enable active object
       
   297             SetActive();
       
   298             }
       
   299         }
       
   300     return error;
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // CMSEngineAO::ExecuteFillPreProcessingL()
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 TInt CMSEngineAO::ExecuteFillPreProcessingL()
       
   308     {
       
   309     LOG( _L("[MediaServant ENG]\t CMSEngineAO::ExecuteFillPreProcessingL") );
       
   310 
       
   311     // Open content manager session.
       
   312     TInt error = OpenServerSession();
       
   313 
       
   314     if ( !error )
       
   315         {
       
   316         iCurrentService = ECmServicePreProcessingFill;
       
   317         iState = EMSEnginePreprocess;
       
   318         error = iContentManager.ExecuteService( ECmServicePreProcessingFill,
       
   319                                                 iStatus );
       
   320 
       
   321         if ( IsActive() )
       
   322             {
       
   323             User::Leave( KErrInUse );
       
   324             }
       
   325         else
       
   326             {
       
   327             // Enable active object
       
   328             SetActive();
       
   329             }
       
   330         }
       
   331     return error;
       
   332     }
       
   333 
       
   334 // --------------------------------------------------------------------------
       
   335 // CMSEngine::GetFilteredMetadataL
       
   336 // --------------------------------------------------------------------------
       
   337 //
       
   338 void CMSEngineAO::GetFilteredMetadataL(
       
   339                             CCmSqlPropertyCollector*& aCollector )
       
   340     {
       
   341     LOG(_L("[MediaServant ENG]\t CMSEngine::GetFilteredMetadataL"));
       
   342 
       
   343     // Open content manager session.
       
   344     User::LeaveIfError( OpenServerSession() );
       
   345 
       
   346     iCurrentService = ECmServiceFill;
       
   347     iState = EMSEngineGetMetadata;
       
   348     iContentManager.GetFilteredMetadataL( iCurrentService,
       
   349                                           aCollector,
       
   350                                           iStatus );
       
   351 
       
   352     if ( IsActive() )
       
   353         {
       
   354         User::Leave( KErrInUse );
       
   355         }
       
   356     else
       
   357         {
       
   358         // Enable active object
       
   359         SetActive();
       
   360         }
       
   361     }
       
   362 
       
   363 // --------------------------------------------------------------------------
       
   364 // CMSEngineAO::PreProcessFillList
       
   365 // --------------------------------------------------------------------------
       
   366 //
       
   367 TInt CMSEngineAO::PreProcessFillListL( const TDesC8& aListName )
       
   368     {
       
   369     LOG( _L("[MediaServant ENG]\t CMSEngineAO::PreProcessFillListL") );
       
   370 
       
   371     // Open content manager session.
       
   372     TInt error = OpenServerSession();
       
   373 
       
   374     if ( !error )
       
   375         {
       
   376         iCurrentService = ECmServicePreProcessingFilllist;
       
   377         iState = EMSEnginePreprocessList;
       
   378         error = iContentManager.PreProcessFillList( aListName, iStatus );
       
   379 
       
   380         if ( IsActive() )
       
   381             {
       
   382             User::Leave( KErrInUse );
       
   383             }
       
   384         else
       
   385             {
       
   386             // Enable active object
       
   387             SetActive();
       
   388             }
       
   389         }
       
   390     return error;
       
   391     }
       
   392 
       
   393 // --------------------------------------------------------------------------
       
   394 // CMSEngineAO::UpdateFillListsL
       
   395 // --------------------------------------------------------------------------
       
   396 //
       
   397 void CMSEngineAO::UpdateFillListsL()
       
   398     {
       
   399     LOG( _L("[MediaServant ENG]\t CMSEngineAO::UpdateFillListsL") );
       
   400 
       
   401     // Open content manager session.
       
   402     User::LeaveIfError( OpenServerSession() );
       
   403 
       
   404     iCurrentService = ECmServiceUpdateFillLists;
       
   405     iState = EMSUpdateFillLists;
       
   406     iContentManager.UpdateFillListsL( iStatus );
       
   407 
       
   408     if ( IsActive() )
       
   409         {
       
   410         User::Leave( KErrInUse );
       
   411         }
       
   412     else
       
   413         {
       
   414         // Enable active object
       
   415         SetActive();
       
   416         }
       
   417     }
       
   418 
       
   419 // --------------------------------------------------------------------------
       
   420 // CMSEngineAO::DeleteMetadataL
       
   421 // --------------------------------------------------------------------------
       
   422 //
       
   423 void CMSEngineAO::DeleteMetadataL()
       
   424     {
       
   425     LOG( _L("[MediaServant ENG]\t CMSEngineAO::DeleteMetadataL") );
       
   426 
       
   427     // Open content manager session.
       
   428     User::LeaveIfError( OpenServerSession() );
       
   429 
       
   430     iCurrentService = ECmServiceDeleteMetadata;
       
   431     iState = EMSEngineDeleteMetadata;
       
   432     iContentManager.DeleteMetadataL( iStatus );
       
   433 
       
   434     if ( IsActive() )
       
   435         {
       
   436         User::Leave( KErrInUse );
       
   437         }
       
   438     else
       
   439         {
       
   440         // Enable active object
       
   441         SetActive();
       
   442         }
       
   443     }
       
   444 
       
   445 // ---------------------------------------------------------------------------
       
   446 // CMSEngineAO::OpenServerSession
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 TInt CMSEngineAO::OpenServerSession()
       
   450     {
       
   451     LOG( _L("[MediaServant ENG]\t CMSEngineAO::OpenServerSession") );
       
   452 
       
   453     TInt error( KErrInUse );
       
   454     // Enable active object
       
   455     if ( !IsActive() )
       
   456         {
       
   457         error = iContentManager.Connect();
       
   458         }
       
   459 
       
   460     return error;
       
   461     }
       
   462 
       
   463 // ---------------------------------------------------------------------------
       
   464 // CMSEngineAO::CloseServerSession
       
   465 // ---------------------------------------------------------------------------
       
   466 //
       
   467 TInt CMSEngineAO::CloseServerSession()
       
   468     {
       
   469     LOG( _L("[MediaServant ENG]\t CMSEngineAO::CloseServerSession") );
       
   470 
       
   471     TInt error = KErrNone;
       
   472     iContentManager.Close();
       
   473 
       
   474     return error;
       
   475     }
       
   476 
       
   477 // ---------------------------------------------------------------------------
       
   478 // CMSEngineAO::ApplicationExit
       
   479 // ---------------------------------------------------------------------------
       
   480 //
       
   481 void CMSEngineAO::ApplicationExit()
       
   482     {
       
   483     LOG( _L("[MediaServant ENG]\t CMSEngineAO::ApplicationExit") );
       
   484 
       
   485     if ( !IsActive() )
       
   486         {
       
   487         OpenServerSession();
       
   488         }
       
   489     iContentManager.ApplicationExit();
       
   490     if ( IsActive() || iContentManager.Handle() )
       
   491         {
       
   492         CloseServerSession();
       
   493         }
       
   494     }
       
   495 
       
   496 // ---------------------------------------------------------------------------
       
   497 // CMSEngineAO::StopOperation
       
   498 // ---------------------------------------------------------------------------
       
   499 //
       
   500 void CMSEngineAO::StopOperation()
       
   501     {
       
   502     LOG(_L("[MediaServant ENG]\t CMSEngineAO::StopOperation"));
       
   503 
       
   504     if ( IsActive() )
       
   505         {
       
   506         LOG(_L("[MediaServant ENG]\t CMSEngineAO::StopOperation active \
       
   507         cancelled"));
       
   508         Cancel();
       
   509         }
       
   510     else
       
   511         {
       
   512         LOG( _L("[MediaServant ENG]\t CMSEngineAO::StopOperation \
       
   513         contentmanager cancelled") );
       
   514         // This is used to cancel scheduler initiated operation
       
   515         // Open server session first
       
   516         OpenServerSession();
       
   517         iContentManager.Cancel();
       
   518         }
       
   519 
       
   520     LOG( _L("[MediaServant ENG]\t CMSEngineAO::StopOperation Server \
       
   521     cancelled") );
       
   522     CloseServerSession();
       
   523     }
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // CMSEngineAO::SetObserver
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 void CMSEngineAO::SetObserver( MMSEngineObserver* aObserver )
       
   530     {
       
   531     LOG( _L("[MediaServant ENG]\t CMSEngineAO::SetObserver") );
       
   532 
       
   533     iObserver = aObserver;
       
   534     }
       
   535     
       
   536 // End of file