videocollection/mpxmyvideoscollection/src/vcxmyvideosmdsdb.cpp
changeset 37 4eb2df7f7cbe
parent 36 8aed59de29f9
child 38 ff53afa8ad05
equal deleted inserted replaced
36:8aed59de29f9 37:4eb2df7f7cbe
    63 _LIT( KVcxHeightPropertyName, "Height" );                     //23
    63 _LIT( KVcxHeightPropertyName, "Height" );                     //23
    64 _LIT( KVcxArtistPropertyName, "Artist" );                     //24
    64 _LIT( KVcxArtistPropertyName, "Artist" );                     //24
    65 
    65 
    66 
    66 
    67 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
       
    68 // CVcxMdsShutdownMonitor::NewL()
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 CVcxMdsShutdownMonitor* CVcxMdsShutdownMonitor::NewL( MVcxMdsShutdownMonitorObserver& aObserver,
       
    72                                                 const TUid& aKeyCategory,
       
    73                                                 const TInt aPropertyKey,
       
    74                                                 TBool aDefineKey)
       
    75     {
       
    76     CVcxMdsShutdownMonitor* self = new( ELeave )CVcxMdsShutdownMonitor( aObserver, 
       
    77                                                                   aKeyCategory,
       
    78                                                                   aPropertyKey,
       
    79                                                                   aDefineKey);
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL();
       
    82     CleanupStack::Pop( self );
       
    83     return self;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CVcxMdsShutdownMonitor::CVcxMdsShutdownMonitor()
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 CVcxMdsShutdownMonitor::CVcxMdsShutdownMonitor( MVcxMdsShutdownMonitorObserver& aObserver,
       
    91                                           const TUid& aKeyCategory,
       
    92                                           const TInt aPropertyKey,
       
    93                                           TBool aDefineKey)
       
    94     : CActive( CActive::EPriorityStandard ), iObserver( aObserver ),
       
    95       iKeyCategory( aKeyCategory ), iPropertyKey(aPropertyKey), iDefineKey( aDefineKey )
       
    96     {   
       
    97     CActiveScheduler::Add( this );
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // CVcxMdsShutdownMonitor::ConstructL()
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CVcxMdsShutdownMonitor::ConstructL()
       
   105     { 
       
   106     // define P&S property types
       
   107     if ( iDefineKey )
       
   108         {
       
   109         RProperty::Define( iKeyCategory, iPropertyKey,
       
   110                           RProperty::EInt, KAllowAllPolicy, KPowerMgmtPolicy );
       
   111         }
       
   112     
       
   113     // attach to the property
       
   114     TInt err = iProperty.Attach( iKeyCategory, iPropertyKey,EOwnerThread );
       
   115     User::LeaveIfError( err );
       
   116     
       
   117     // wait for the previously attached property to be updated
       
   118     iProperty.Subscribe( iStatus );
       
   119     SetActive();
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CVcxMdsShutdownMonitor::~CVcxMdsShutdownMonitor()
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 CVcxMdsShutdownMonitor::~CVcxMdsShutdownMonitor()
       
   127     {
       
   128     Cancel();
       
   129     iProperty.Close();
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // CVcxMdsShutdownMonitor::RunL()
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CVcxMdsShutdownMonitor::RunL()
       
   137     {
       
   138     // resubscribe before processing new value to prevent missing updates
       
   139     iProperty.Subscribe( iStatus );
       
   140     SetActive();
       
   141     
       
   142     // retrieve the value
       
   143     TInt value = 0;
       
   144     TInt err = iProperty.Get( value );
       
   145     MPX_DEBUG2("CVcxMyVideosMdsDb::RunL(): iProperty.Get(value); returns %d", err);
       
   146     
       
   147     User::LeaveIfError( err );
       
   148 
       
   149     iObserver.ShutdownNotification( value );    
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // CVcxMdsShutdownMonitor::DoCancel()
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CVcxMdsShutdownMonitor::DoCancel()
       
   157     {
       
   158     iProperty.Cancel();
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
    68 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------
    69 //
   163 //
    70 CVcxMyVideosMdsDb::CVcxMyVideosMdsDb( MVcxMyVideosMdsDbObserver* aObserver,
   164 CVcxMyVideosMdsDb::CVcxMyVideosMdsDb( MVcxMyVideosMdsDbObserver* aObserver,
    71         MVcxMyVideosMdsAlbumsObserver* aAlbumsObserver, RFs& aFs )
   165         MVcxMyVideosMdsAlbumsObserver* aAlbumsObserver, RFs& aFs )
    72 : iFs( aFs ), iMdsDbObserver(aObserver), iAlbumsObserver(aAlbumsObserver) 
   166 : iFs( aFs ), iMdsDbObserver(aObserver), iAlbumsObserver(aAlbumsObserver) 
    84 
   178 
    85     iActiveSchedulerWait = new (ELeave) CActiveSchedulerWait;
   179     iActiveSchedulerWait = new (ELeave) CActiveSchedulerWait;
    86     
   180     
    87     OpenMdsSessionL();
   181     OpenMdsSessionL();
    88 
   182 
    89     //  Get the schema definitions
       
    90     GetSchemaDefinitionsL();
       
    91         
   183         
    92     iAlbums = CVcxMyVideosMdsAlbums::NewL( *this, iAlbumsObserver );
   184     iAlbums = CVcxMyVideosMdsAlbums::NewL( *this, iAlbumsObserver );
    93     
   185     
    94     TCallBack callBack( AsyncHandleQueryCompleted, this );    
   186     TCallBack callBack( AsyncHandleQueryCompleted, this );    
    95     iAsyncHandleQueryCompleteCaller = new (ELeave) CAsyncCallBack( callBack,
   187     iAsyncHandleQueryCompleteCaller = new (ELeave) CAsyncCallBack( callBack,
    96             CActive::EPriorityStandard );
   188             CActive::EPriorityStandard );
    97 
   189 
       
   190     iMdsShutdownMonitor = CVcxMdsShutdownMonitor::NewL(
       
   191             *this, KHarvesterPSShutdown, KMdSShutdown, EFalse );
       
   192 
    98     MPX_DEBUG1( "CVcxMyVideosMdsDb::ConstructL exit" );
   193     MPX_DEBUG1( "CVcxMyVideosMdsDb::ConstructL exit" );
    99     }
   194     }
   100 
   195 
   101 // ---------------------------------------------------------------------------
   196 // ---------------------------------------------------------------------------
   102 // CVcxMyVideosMdsDb::OpenMdsSessionL
   197 // CVcxMyVideosMdsDb::OpenMdsSessionL
   104 //
   199 //
   105 void CVcxMyVideosMdsDb::OpenMdsSessionL()
   200 void CVcxMyVideosMdsDb::OpenMdsSessionL()
   106     {
   201     {
   107     MPX_DEBUG1( "CVcxMyVideosMdsDb::OpenMdsSessionL() start" );
   202     MPX_DEBUG1( "CVcxMyVideosMdsDb::OpenMdsSessionL() start" );
   108 
   203 
   109     iMdsError = KErrNone;
   204     iMdsSessionError = KErrNone;
   110 
   205 
       
   206     delete iMdsSession;
       
   207     iMdsSession = NULL;
   111     iMdsSession = CMdESession::NewL( *this );
   208     iMdsSession = CMdESession::NewL( *this );
   112     if ( !iMdsSession )
   209     if ( !iMdsSession )
   113         {
   210         {
   114         //  Failed to create session, leave
   211         User::Leave( KErrGeneral );
   115         User::Leave( iMdsError );
   212         }
   116         }
   213     
   117     
       
   118     if ( iMdsError != KErrNone )
       
   119         {
       
   120         MPX_DEBUG2("Failed to create session to MDS: %d", iMdsError);
       
   121         User::LeaveIfError( iMdsError );
       
   122         }
       
   123 
       
   124     //  Wait until session opened
   214     //  Wait until session opened
   125     iActiveSchedulerWait->Start();    
   215     iActiveSchedulerWait->Start();    
   126     MPX_DEBUG1( "CVcxMyVideosMdsDb::ConstructL iActiveSchedulerWait->Start done" );
   216     MPX_DEBUG1( "CVcxMyVideosMdsDb:: iActiveSchedulerWait->Start done" );
   127 
   217 
   128     MPX_DEBUG1( "CVcxMyVideosMdsDb::OpenMdsSessionL Adding observers" );
   218     if ( iMdsSessionError == KErrNone )
   129 
   219         {
   130     // We order all object notifications. If we set video condition, then we wont
   220         MPX_DEBUG1( "CVcxMyVideosMdsDb:: session opened ok, adding observers" );
   131     // receive remove notifications at all (mds feature). Extra notifications
   221 
   132     // do not bother us much since we try to fetch the item from the db
   222         // We order all object notifications. If we set video condition, then we wont
   133     // after the add notification anyways, and then we use video condition.
   223         // receive remove notifications at all (mds feature). Extra notifications
   134     // Eventually extra events are ignored.    
   224         // do not bother us much since we try to fetch the item from the db
   135     iMdsSession->AddObjectObserverL( *this, NULL );
   225         // after the add notification anyways, and then we use video condition.
   136     
   226         // Eventually extra events are ignored.    
   137     iMdsSession->AddObjectPresentObserverL( *this );
   227         iMdsSession->AddObjectObserverL( *this, NULL );
       
   228     
       
   229         iMdsSession->AddObjectPresentObserverL( *this );
       
   230         
       
   231         GetSchemaDefinitionsL();
       
   232         
       
   233         if ( iAlbums )
       
   234             {
       
   235             iAlbums->GetSchemaDefinitionsL();
       
   236             }
       
   237         }
       
   238     else
       
   239         {
       
   240         MPX_DEBUG2( "CVcxMyVideosMdsDb:: session opening failed: %d", iMdsSessionError );
       
   241         iMdsSessionError = KErrGeneral; // this ensures that next time when mds is tried to use, it tries to open session again
       
   242         delete iMdsSession;
       
   243         iMdsSession = NULL;        
       
   244         }
   138 
   245 
   139     MPX_DEBUG1( "CVcxMyVideosMdsDb::OpenMdsSessionL() exit" );
   246     MPX_DEBUG1( "CVcxMyVideosMdsDb::OpenMdsSessionL() exit" );
   140     }
   247     }
   141 
   248 
   142 // ---------------------------------------------------------------------------
   249 // ---------------------------------------------------------------------------
   191 // ---------------------------------------------------------------------------
   298 // ---------------------------------------------------------------------------
   192 // ---------------------------------------------------------------------------
   299 // ---------------------------------------------------------------------------
   193 //
   300 //
   194 CVcxMyVideosMdsDb::~CVcxMyVideosMdsDb()
   301 CVcxMyVideosMdsDb::~CVcxMyVideosMdsDb()
   195     {
   302     {
   196     MPX_FUNC( "CVcxMyVideosMdsDb::~CVcxMyVideosMdsDb()" );
   303     MPX_DEBUG1( "CVcxMyVideosMdsDb::~CVcxMyVideosMdsDb() start" );
   197 
   304 
   198     Cancel( EGetVideoList );
   305     Cancel( EGetVideoList );
   199 
   306 
   200     delete iAlbums;
   307     delete iAlbums;
   201     delete iCmdQueue;    
   308     delete iCmdQueue;
   202 
       
   203     if ( iMdsSession )
       
   204         {
       
   205         TRAP_IGNORE( iMdsSession->RemoveObjectObserverL( *this ) );        
       
   206         }
       
   207 
       
   208     delete iVideoQuery;
   309     delete iVideoQuery;
   209     delete iMdsSession;
   310     delete iMdsSession;
   210     delete iActiveSchedulerWait;
   311     delete iActiveSchedulerWait;
   211     delete iAsyncHandleQueryCompleteCaller;
   312     delete iAsyncHandleQueryCompleteCaller;
       
   313     delete iMdsShutdownMonitor;
       
   314     MPX_DEBUG1( "CVcxMyVideosMdsDb::~CVcxMyVideosMdsDb() exit" );
   212     }
   315     }
   213 
   316 
   214 // ---------------------------------------------------------------------------
   317 // ---------------------------------------------------------------------------
   215 // CVcxMyVideosMdsDb::Cancel
   318 // CVcxMyVideosMdsDb::Cancel
   216 // ---------------------------------------------------------------------------
   319 // ---------------------------------------------------------------------------
   244 //
   347 //
   245 void CVcxMyVideosMdsDb::AddVideoL(
   348 void CVcxMyVideosMdsDb::AddVideoL(
   246         CMPXMedia& aVideo, 
   349         CMPXMedia& aVideo, 
   247         TUint32& aMdsId )
   350         TUint32& aMdsId )
   248     {
   351     {
   249     MPX_FUNC( "CVcxMyVideosMdsDb::AddVideoL" );
   352     MPX_DEBUG1( "CVcxMyVideosMdsDb::AddVideoL() start" );
   250 
       
   251     if ( !iMdsSession )
       
   252         {
       
   253         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session(%d), leaving", iMdsError);
       
   254         User::Leave( iMdsError );
       
   255         }
       
   256          
   353          
   257     CMdEObject* object = iMdsSession->NewObjectLC(
   354     CMdEObject* object = MdsSessionL().NewObjectLC(
   258             *iVideoObjectDef, aVideo.ValueText( KMPXMediaGeneralUri ) ); // 1->
   355             *iVideoObjectDef, aVideo.ValueText( KMPXMediaGeneralUri ) ); // 1->
   259 
   356 
   260     // Value from aVideo is taken in use in Media2ObjectL if aVideo contains creation date
   357     // Value from aVideo is taken in use in Media2ObjectL if aVideo contains creation date
   261     SetCreationAndModifiedDatesL( *object ); // use current time
   358     SetCreationAndModifiedDatesL( *object ); // use current time
   262     
   359     
   280                 aVideo.ValueText( KMPXMediaGeneralMimeType ) );
   377                 aVideo.ValueText( KMPXMediaGeneralMimeType ) );
   281             }
   378             }
   282         }
   379         }
   283 
   380 
   284     Media2ObjectL( aVideo, *object );
   381     Media2ObjectL( aVideo, *object );
   285     TRAPD( err, aMdsId = iMdsSession->AddObjectL( *object ) );
   382     TRAPD( err, aMdsId = MdsSessionL().AddObjectL( *object ) );
   286 
   383 
   287     if ( err != KErrNone )
   384     if ( err != KErrNone )
   288         {
   385         {
   289         MPX_DEBUG2( "CVcxMyVideosMdsDb:: iMdsSession->AddObjectL leaved with error: %d", err );
   386         MPX_DEBUG2( "CVcxMyVideosMdsDb:: MdsSessionL().AddObjectL leaved with error: %d", err );
   290         User::Leave( err );
   387         User::Leave( err );
   291         }
   388         }
   292         
   389         
   293     if ( aMdsId == KNoId )
   390     if ( aMdsId == KNoId )
   294         {
   391         {
   300         MPX_DEBUG2( "CVcxMyVideosMdsDb::AddVideoL video created, mds id: %d", aMdsId );
   397         MPX_DEBUG2( "CVcxMyVideosMdsDb::AddVideoL video created, mds id: %d", aMdsId );
   301         }        
   398         }        
   302 
   399 
   303     CleanupStack::PopAndDestroy( object ); // <-1
   400     CleanupStack::PopAndDestroy( object ); // <-1
   304 
   401 
       
   402     MPX_DEBUG1( "CVcxMyVideosMdsDb::AddVideoL() exit" );
   305     }
   403     }
   306 
   404 
   307 // ---------------------------------------------------------------------------
   405 // ---------------------------------------------------------------------------
   308 // CVcxMyVideosMdsDb::RemoveVideo
   406 // CVcxMyVideosMdsDb::RemoveVideo
   309 // ---------------------------------------------------------------------------
   407 // ---------------------------------------------------------------------------
   310 //
   408 //
   311 TInt CVcxMyVideosMdsDb::RemoveVideo( TUint32 aMdsId )
   409 TInt CVcxMyVideosMdsDb::RemoveVideo( TUint32 aMdsId )
   312     {
   410     {
   313     MPX_FUNC( "CVcxMyVideosMdsDb::RemoveVideoL" );
   411     MPX_DEBUG1( "CVcxMyVideosMdsDb::RemoveVideoL() start" );
   314 
       
   315     if ( !iMdsSession )
       
   316         {
       
   317         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session, returning %d", iMdsError);
       
   318         return iMdsError;
       
   319         }
       
   320 
   412 
   321     TInt retValue( KErrNone );
   413     TInt retValue( KErrNone );
   322     TItemId id( 0 ); //init to avoid warning
   414     TItemId id( 0 ); //init to avoid warning
   323 
   415 
   324     MPX_DEBUG2( "CVcxMyVideosMdsDb:: removing object %d", aMdsId );
   416     MPX_DEBUG2( "CVcxMyVideosMdsDb:: removing object %d", aMdsId );
   325     
   417     
   326     TRAPD( err,  id = iMdsSession->RemoveObjectL( aMdsId ) );
   418     TRAPD( err,  id = MdsSessionL().RemoveObjectL( aMdsId ) );
   327 
   419 
   328     if ( err == KErrNone )
   420     if ( err == KErrNone )
   329         {
   421         {
   330         if ( id == KNoId )
   422         if ( id == KNoId )
   331             {
   423             {
   337             MPX_DEBUG1( "CVcxMyVideosMdsDb:: remove successful" );
   429             MPX_DEBUG1( "CVcxMyVideosMdsDb:: remove successful" );
   338             }
   430             }
   339         }
   431         }
   340     else
   432     else
   341         {
   433         {
   342         MPX_DEBUG2( "CVcxMyVideosMdsDb:: iMdsSession->RemoveObjectL left: %d", err );
   434         MPX_DEBUG2( "CVcxMyVideosMdsDb:: MdsSessionL().RemoveObjectL left: %d", err );
   343         retValue = err;        
   435         retValue = err;        
   344         }
   436         }
   345         
   437         
       
   438     MPX_DEBUG1( "CVcxMyVideosMdsDb::RemoveVideoL() exit" );        
   346     return retValue;
   439     return retValue;
   347     }
   440     }
   348 
   441 
   349 // ---------------------------------------------------------------------------
   442 // ---------------------------------------------------------------------------
   350 // CVcxMyVideosMdsDb::UpdateVideoL
   443 // CVcxMyVideosMdsDb::UpdateVideoL
   351 // ---------------------------------------------------------------------------
   444 // ---------------------------------------------------------------------------
   352 //
   445 //
   353 void CVcxMyVideosMdsDb::UpdateVideoL( CMPXMedia& aVideo )
   446 void CVcxMyVideosMdsDb::UpdateVideoL( CMPXMedia& aVideo )
   354     {
   447     {
   355     MPX_FUNC( "CVcxMyVideosMdsDb::UpdateVideoL" );
   448     MPX_DEBUG1( "CVcxMyVideosMdsDb::UpdateVideoL() start" );
   356 
       
   357     if ( !iMdsSession )
       
   358         {
       
   359         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session(%d), leaving", iMdsError);
       
   360         User::Leave( iMdsError );
       
   361         }
       
   362 
   449 
   363     TMPXItemId mpxId = aVideo.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
   450     TMPXItemId mpxId = aVideo.ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
   364 
   451 
   365     MPX_DEBUG2("CVcxMyVideosMdsDb::UpdateVideoL updating object %d ", mpxId.iId1);
   452     MPX_DEBUG2("CVcxMyVideosMdsDb::UpdateVideoL updating object %d ", mpxId.iId1);
   366     
   453     
   367     CMdEObject* object =
   454     CMdEObject* object =
   368             iMdsSession->OpenObjectL( mpxId.iId1, *iVideoObjectDef );
   455             MdsSessionL().OpenObjectL( mpxId.iId1, *iVideoObjectDef );
   369     if ( !object )
   456     if ( !object )
   370         {
   457         {
   371         // No object with this ID was found!
   458         // No object with this ID was found!
   372         MPX_DEBUG1("CVcxMyVideosMdsDb::UpdateVideoL no object found");
   459         MPX_DEBUG1("CVcxMyVideosMdsDb::UpdateVideoL no object found");
   373         User::Leave( KErrNotFound );
   460         User::Leave( KErrNotFound );
   380             {
   467             {
   381             CleanupStack::PushL( object ); // 1->
   468             CleanupStack::PushL( object ); // 1->
   382             
   469             
   383             Media2ObjectL( aVideo, *object );
   470             Media2ObjectL( aVideo, *object );
   384             
   471             
   385             iMdsSession->CommitObjectL(*object);
   472             MdsSessionL().CommitObjectL(*object);
   386 
   473 
   387             CleanupStack::PopAndDestroy(object);
   474             CleanupStack::PopAndDestroy(object);
   388             }
   475             }
   389         else
   476         else
   390             {
   477             {
   392             MPX_DEBUG1("CVcxMyVideosMdsDb::UpdateVideoL object was locked!");
   479             MPX_DEBUG1("CVcxMyVideosMdsDb::UpdateVideoL object was locked!");
   393             delete object;
   480             delete object;
   394             User::Leave( KErrInUse );
   481             User::Leave( KErrInUse );
   395             }
   482             }
   396         }
   483         }
       
   484     MPX_DEBUG1( "CVcxMyVideosMdsDb::UpdateVideoL() exit" );
   397     }
   485     }
   398 
   486 
   399 // ---------------------------------------------------------------------------
   487 // ---------------------------------------------------------------------------
   400 // CVcxMyVideosMdsDb::CreateVideoListL
   488 // CVcxMyVideosMdsDb::CreateVideoListL
   401 // ---------------------------------------------------------------------------
   489 // ---------------------------------------------------------------------------
   402 //
   490 //
   403 void CVcxMyVideosMdsDb::CreateVideoListL( TVcxMyVideosSortingOrder aSortingOrder,
   491 void CVcxMyVideosMdsDb::CreateVideoListL( TVcxMyVideosSortingOrder aSortingOrder,
   404         TBool aAscending, TBool aFullDetails, CMPXMedia*& aVideoList )
   492         TBool aAscending, TBool aFullDetails, CMPXMedia*& aVideoList )
   405     {
   493     {
   406     MPX_FUNC( "CVcxMyVideosMdsDb::CreateVideoListL" );
   494     MPX_DEBUG1( "CVcxMyVideosMdsDb::CreateVideoListL() start" );
   407     
   495     
   408     CVcxMyVideosMdsCmdGetVideoList* cmd = new (ELeave) CVcxMyVideosMdsCmdGetVideoList;
   496     CVcxMyVideosMdsCmdGetVideoList* cmd = new (ELeave) CVcxMyVideosMdsCmdGetVideoList;
   409     CleanupStack::PushL( cmd ); // 1->
   497     CleanupStack::PushL( cmd ); // 1->
   410     cmd->iCmdType      = CVcxMyVideosMdsDb::EGetVideoList;
   498     cmd->iCmdType      = CVcxMyVideosMdsDb::EGetVideoList;
   411     cmd->iSortingOrder = aSortingOrder;
   499     cmd->iSortingOrder = aSortingOrder;
   423 //
   511 //
   424 void CVcxMyVideosMdsDb::DoCreateVideoListL( TVcxMyVideosSortingOrder aSortingOrder,
   512 void CVcxMyVideosMdsDb::DoCreateVideoListL( TVcxMyVideosSortingOrder aSortingOrder,
   425         TBool aAscending, TBool aFullDetails, CMPXMedia*& aVideoList )
   513         TBool aAscending, TBool aFullDetails, CMPXMedia*& aVideoList )
   426     {
   514     {
   427     MPX_FUNC( "CVcxMyVideosMdsDb::DoCreateVideoListL" );
   515     MPX_FUNC( "CVcxMyVideosMdsDb::DoCreateVideoListL" );
   428 
       
   429     if ( !iMdsSession )
       
   430         {
       
   431         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session(%d), leaving", iMdsError);
       
   432         User::Leave( iMdsError );
       
   433         }
       
   434         
   516         
   435     if ( iVideoListFetchingIsOngoing )
   517     if ( iVideoListFetchingIsOngoing )
   436         {
   518         {
   437         MPX_DEBUG1("CVcxMyVideosMdsDb:: video list fetching already going on, returning current list");
   519         MPX_DEBUG1("CVcxMyVideosMdsDb:: video list fetching already going on, returning current list");
   438         aVideoList = iVideoList;
   520         aVideoList = iVideoList;
   446     CMPXMediaArray* mediaArray = aVideoList->Value<CMPXMediaArray>( KMPXMediaArrayContents );
   528     CMPXMediaArray* mediaArray = aVideoList->Value<CMPXMediaArray>( KMPXMediaArrayContents );
   447     
   529     
   448     delete iVideoQuery;
   530     delete iVideoQuery;
   449     iVideoQuery = NULL;
   531     iVideoQuery = NULL;
   450     
   532     
   451     iVideoQuery = iMdsSession->NewObjectQueryL(
   533     iVideoQuery = MdsSessionL().NewObjectQueryL(
   452             *iNamespaceDef,
   534             *iNamespaceDef,
   453             *iVideoObjectDef,
   535             *iVideoObjectDef,
   454             this);
   536             this);
   455 
   537 
   456     iVideoQuery->SetResultMode( EQueryResultModeItem );
   538     iVideoQuery->SetResultMode( EQueryResultModeItem );
   551         TInt aNewItemCount )
   633         TInt aNewItemCount )
   552 #else
   634 #else
   553         TInt /*aNewItemCount*/ )
   635         TInt /*aNewItemCount*/ )
   554 #endif
   636 #endif
   555     {
   637     {
   556     MPX_FUNC("CVcxMyVideosMdsDb::HandleQueryNewResults()");
   638     MPX_DEBUG1("CVcxMyVideosMdsDb::HandleQueryNewResults() start");
   557     
   639     
   558     if ( !iVideoList )
   640     if ( !iVideoList )
   559         {
   641         {
   560         MPX_DEBUG1("CVcxMyVideosMdsDb:: iVideoList is NULL, should never happen");
   642         MPX_DEBUG1("CVcxMyVideosMdsDb:: iVideoList is NULL, should never happen");
   561         return;
   643         return;
   583         CleanupStack::Pop( media ); // <-1
   665         CleanupStack::Pop( media ); // <-1
   584         }
   666         }
   585     
   667     
   586     iMdsDbObserver->HandleCreateVideoListResp( iVideoList, aFirstNewItemIndex,
   668     iMdsDbObserver->HandleCreateVideoListResp( iVideoList, aFirstNewItemIndex,
   587             EFalse /* not complete yet */);
   669             EFalse /* not complete yet */);
       
   670     MPX_DEBUG1("CVcxMyVideosMdsDb::HandleQueryNewResults() exit");
   588     }
   671     }
   589 
   672 
   590 
   673 
   591             
   674             
   592 // ---------------------------------------------------------------------------
   675 // ---------------------------------------------------------------------------
   642 // CVcxMyVideosMdsDb::CreateVideoL
   725 // CVcxMyVideosMdsDb::CreateVideoL
   643 // ---------------------------------------------------------------------------
   726 // ---------------------------------------------------------------------------
   644 //
   727 //
   645 CMPXMedia* CVcxMyVideosMdsDb::CreateVideoL( TUint32 aId, TBool aFullDetails )
   728 CMPXMedia* CVcxMyVideosMdsDb::CreateVideoL( TUint32 aId, TBool aFullDetails )
   646     {
   729     {
   647     MPX_FUNC( "CVcxMyVideosMdsDb::CreateVideoL" );
   730     MPX_DEBUG1( "CVcxMyVideosMdsDb::CreateVideoL() start" );
   648 
   731 
   649     CMdEObject* object = ObjectL( aId );
   732     CMdEObject* object = ObjectL( aId );
   650 
   733 
   651     if ( !object )
   734     if ( !object )
   652         {
   735         {
   661 
   744 
   662     Object2MediaL( *object, *video, aFullDetails );
   745     Object2MediaL( *object, *video, aFullDetails );
   663 
   746 
   664     CleanupStack::Pop( video );            // <-2
   747     CleanupStack::Pop( video );            // <-2
   665     CleanupStack::PopAndDestroy( object ); // <-1
   748     CleanupStack::PopAndDestroy( object ); // <-1
       
   749     MPX_DEBUG1( "CVcxMyVideosMdsDb::CreateVideoL() exit" );
   666 
   750 
   667     return video;
   751     return video;
   668     }
   752     }
   669 
   753 
   670 // ---------------------------------------------------------------------------
   754 // ---------------------------------------------------------------------------
   673 //
   757 //
   674 void CVcxMyVideosMdsDb::HandleSessionOpened(
   758 void CVcxMyVideosMdsDb::HandleSessionOpened(
   675         CMdESession& /*aSession*/,
   759         CMdESession& /*aSession*/,
   676         TInt aError)
   760         TInt aError)
   677     {
   761     {
   678     MPX_FUNC( "CVcxMyVideosMdsDb::HandleSessionOpened" );
   762     MPX_DEBUG1("CVcxMyVideosMdsDb::HandleSessionOpened() start" );
   679 
   763 
   680     iActiveSchedulerWait->AsyncStop();
   764     iActiveSchedulerWait->AsyncStop();
   681 
   765 
   682     if ( aError != KErrNone )
   766     if ( aError != KErrNone )
   683         {
   767         {
   684         MPX_DEBUG2( "CVcxMyVideosMdsDb::HandleSessionOpened: %d", aError );
   768         MPX_DEBUG2( "CVcxMyVideosMdsDb::HandleSessionOpened: %d", aError );
   685 
   769 
   686         iMdsError = aError;
   770         iMdsSessionError = aError;
   687         delete iMdsSession;
   771         }
   688         iMdsSession = NULL;
   772     MPX_DEBUG1("CVcxMyVideosMdsDb::HandleSessionOpened() exit" );
   689         }
       
   690     }
   773     }
   691 
   774 
   692 // ---------------------------------------------------------------------------
   775 // ---------------------------------------------------------------------------
   693 // From class MMdESessionObserver.
   776 // From class MMdESessionObserver.
   694 // ---------------------------------------------------------------------------
   777 // ---------------------------------------------------------------------------
   695 //
   778 //
   696 void CVcxMyVideosMdsDb::HandleSessionError(
   779 void CVcxMyVideosMdsDb::HandleSessionError(
   697         CMdESession& /*aSession*/,
   780         CMdESession& /*aSession*/,
   698         TInt aError)
   781         TInt aError)
   699     {
   782     {
   700     MPX_FUNC( "CVcxMyVideosMdsDb::HandleSessionError" );
   783     MPX_DEBUG1("CVcxMyVideosMdsDb::HandleSessionError() start" );
   701 
   784 
   702     if (iActiveSchedulerWait->IsStarted())
   785     if (iActiveSchedulerWait->IsStarted())
   703         {
   786         {
   704         MPX_DEBUG1( "CVcxMyVideosMdsDb:: Session opening was going on");
   787         MPX_DEBUG1( "CVcxMyVideosMdsDb:: Session opening was going on");
   705         iActiveSchedulerWait->AsyncStop();
   788         iActiveSchedulerWait->AsyncStop();
   713                 ETrue /* complete */);
   796                 ETrue /* complete */);
   714         }
   797         }
   715         
   798         
   716     MPX_DEBUG2( "CVcxMyVideosMdsDb::HandleSessionError: %d", aError );
   799     MPX_DEBUG2( "CVcxMyVideosMdsDb::HandleSessionError: %d", aError );
   717 
   800 
   718     iMdsError = aError;
   801     iMdsSessionError = aError;
   719     delete iMdsSession;
   802 
   720     iMdsSession = NULL;
   803     MPX_DEBUG1("CVcxMyVideosMdsDb::HandleSessionError() exit" );
   721     }
   804     }
   722 
   805 
   723 // ---------------------------------------------------------------------------
   806 // ---------------------------------------------------------------------------
   724 // CVcxMyVideosMdsDb::HandleObjectNotification
   807 // CVcxMyVideosMdsDb::HandleObjectNotification
   725 // ---------------------------------------------------------------------------
   808 // ---------------------------------------------------------------------------
   727 void CVcxMyVideosMdsDb::HandleObjectNotification(
   810 void CVcxMyVideosMdsDb::HandleObjectNotification(
   728         CMdESession& /*aSession*/,
   811         CMdESession& /*aSession*/,
   729         TObserverNotificationType aType,
   812         TObserverNotificationType aType,
   730         const RArray<TItemId>& aObjectIdArray)
   813         const RArray<TItemId>& aObjectIdArray)
   731     {
   814     {
   732     TRAP( iMdsError, DoHandleObjectNotificationL( aType, aObjectIdArray ));
   815     TRAP_IGNORE( DoHandleObjectNotificationL( aType, aObjectIdArray ));
   733     }
   816     }
   734     
   817     
   735 // ---------------------------------------------------------------------------
   818 // ---------------------------------------------------------------------------
   736 // CVcxMyVideosMdsDb::ObjectL
   819 // CVcxMyVideosMdsDb::ObjectL
   737 // ---------------------------------------------------------------------------
   820 // ---------------------------------------------------------------------------
   738 //
   821 //
   739 CMdEObject* CVcxMyVideosMdsDb::ObjectL( const TItemId aId, TBool aIsVideo )
   822 CMdEObject* CVcxMyVideosMdsDb::ObjectL( const TItemId aId, TBool aIsVideo )
   740     {
   823     {
   741     if ( !iMdsSession )
   824     MPX_DEBUG1("CVcxMyVideosMdsDb::ObjectL start");
   742         {
       
   743         MPX_DEBUG2("CVcxMyVideosMdsDb:: no mds session(%d), leaving", iMdsError);
       
   744         User::Leave( iMdsError );
       
   745         }
       
   746 
       
   747     //  If the id is not valid, just return NULL, because
   825     //  If the id is not valid, just return NULL, because
   748     //  iMdsSession->GetObjectL leaves in that case
   826     //  MdsSessionL().GetObjectL leaves in that case
   749     if ( aId == KNoId )
   827     if ( aId == KNoId )
   750         {
   828         {
   751         return NULL;
   829         return NULL;
   752         }
   830         }
   753 
   831 
   754     CMdEObject* object;
   832     CMdEObject* object;
   755     if ( aIsVideo )
   833     if ( aIsVideo )
   756         {
   834         {
   757         object = iMdsSession->GetObjectL( aId, *iVideoObjectDef );
   835         object = MdsSessionL().GetObjectL( aId, *iVideoObjectDef );
   758         }
   836         }
   759     else
   837     else
   760         {
   838         {
   761         object = iMdsSession->GetObjectL( aId, *iAlbums->iAlbumObjectDef );
   839         object = MdsSessionL().GetObjectL( aId, *iAlbums->iAlbumObjectDef );
   762         }
   840         }
   763     
   841     
   764     if ( object )
   842     if ( object )
   765         {
   843         {
   766         MPX_DEBUG2( "CVcxMyVideosMdsDb::ObjectL found, id: %d", aId );
   844         MPX_DEBUG2( "CVcxMyVideosMdsDb::ObjectL found, id: %d", aId );
   768     else
   846     else
   769         {
   847         {
   770         MPX_DEBUG2( "CVcxMyVideosMdsDb::ObjectL not found, id: %d", aId );
   848         MPX_DEBUG2( "CVcxMyVideosMdsDb::ObjectL not found, id: %d", aId );
   771         }
   849         }
   772 
   850 
       
   851     MPX_DEBUG1("CVcxMyVideosMdsDb::ObjectL exit");
   773     return object;
   852     return object;
   774     }
   853     }
   775 
   854 
   776 // ---------------------------------------------------------------------------
   855 // ---------------------------------------------------------------------------
   777 // CVcxMyVideosMdsDb::Object2MediaL
   856 // CVcxMyVideosMdsDb::Object2MediaL
  1434 void CVcxMyVideosMdsDb::GetSchemaDefinitionsL()
  1513 void CVcxMyVideosMdsDb::GetSchemaDefinitionsL()
  1435     {
  1514     {
  1436     MPX_FUNC( "CVcxMyVideosMdsDb::GetSchemaDefinitionsL" );
  1515     MPX_FUNC( "CVcxMyVideosMdsDb::GetSchemaDefinitionsL" );
  1437 
  1516 
  1438     //  Namespace
  1517     //  Namespace
  1439     iNamespaceDef = &(iMdsSession->GetDefaultNamespaceDefL());
  1518     iNamespaceDef = &(MdsSessionL().GetDefaultNamespaceDefL());
  1440     
  1519     
  1441     //  Default object definitions
  1520     //  Default object definitions
  1442     iVideoObjectDef = &(iNamespaceDef->GetObjectDefL( KVcxVideoObjectName ));
  1521     iVideoObjectDef = &(iNamespaceDef->GetObjectDefL( KVcxVideoObjectName ));
  1443 
  1522 
  1444     //  Base object property definitions
  1523     //  Base object property definitions
  1553     const TInt secondsInMinute( 60 );    
  1632     const TInt secondsInMinute( 60 );    
  1554     aObject.AddTimePropertyL( *iCreationDatePropertyDef, localTime ); 
  1633     aObject.AddTimePropertyL( *iCreationDatePropertyDef, localTime ); 
  1555     aObject.AddInt16PropertyL( *iTimeOffsetPropertyDef, timeOffset.Int() / secondsInMinute );
  1634     aObject.AddInt16PropertyL( *iTimeOffsetPropertyDef, timeOffset.Int() / secondsInMinute );
  1556     aObject.AddTimePropertyL( *iLastModifiedDatePropertyDef, localTime );
  1635     aObject.AddTimePropertyL( *iLastModifiedDatePropertyDef, localTime );
  1557     }
  1636     }
       
  1637 
       
  1638 // ---------------------------------------------------------------------------
       
  1639 // CVcxMyVideosMdsDb::MdsSessionL
       
  1640 // ---------------------------------------------------------------------------
       
  1641 //
       
  1642 CMdESession& CVcxMyVideosMdsDb::MdsSessionL()
       
  1643     {
       
  1644     if ( iMdsSessionError == KErrServerTerminated )
       
  1645         {
       
  1646         // This ensures that the iMdsSessionError KErrServerTerminated
       
  1647         // value does not change, since the user can't access iMdsSession.
       
  1648         // Recovery happens in ShutDownNotification func.
       
  1649         User::Leave( KErrServerTerminated );
       
  1650         }
       
  1651 
       
  1652     if ( !iMdsSession )
       
  1653         {
       
  1654         OpenMdsSessionL();
       
  1655         
       
  1656         if ( !iMdsSession )
       
  1657             {
       
  1658             User::Leave( KErrGeneral );
       
  1659             }
       
  1660         }
       
  1661 
       
  1662     return *iMdsSession;
       
  1663     }
       
  1664 
       
  1665 // ---------------------------------------------------------------------------
       
  1666 // CVcxMyVideosMdsDb::ShutdownNotification
       
  1667 // From MVcxMdsShutDownMonitorObserver
       
  1668 // ---------------------------------------------------------------------------
       
  1669 //    
       
  1670 void CVcxMyVideosMdsDb::ShutdownNotification( TInt aShutdownState )
       
  1671     {
       
  1672     if ( aShutdownState == 0 )
       
  1673         {
       
  1674         // Server has restarted, recreate session.
       
  1675         MPX_DEBUG1("CVcxMyVideosMdsDb:: MDS Server restarted!");
       
  1676         OpenMdsSessionL();
       
  1677         return;
       
  1678         }
       
  1679         
       
  1680     if ( aShutdownState == 1 )
       
  1681         {
       
  1682         MPX_DEBUG1("CVcxMyVideosMdsDb:: MDS Server went down!");
       
  1683         iMdsSessionError = KErrServerTerminated;
       
  1684         }
       
  1685     }