mpx/collectionframework/collectionutility/src/mpxcollectionutilityimpl.cpp
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Collection Utility implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bamdesca.h>
       
    20 #include <s32mem.h>
       
    21 #include <e32math.h>
       
    22 #include <mpxmessagemonitor.h>
       
    23 #include <mpxmedia.h>
       
    24 #include <mpxcollectionobserver.h>
       
    25 #include <mpxcollectionmessage.h>
       
    26 #include <mpxmessagegeneraldefs.h>
       
    27 #include <mpxcmn.h>
       
    28 #include <mpxtaskqueue.h>
       
    29 #include <mpxcollectionpath.h>
       
    30 #include <mpxcollectionplaylist.h>
       
    31 #include <mpxcollectiontype.h>
       
    32 #include <mpxcommandgeneraldefs.h>
       
    33 #include <mpxcollectioncommanddefs.h>
       
    34 #include <mpxsubscription.h>
       
    35 #include <mpxlog.h>
       
    36 
       
    37 #include "mpxcollectionutilityimpl.h"
       
    38 
       
    39 // ============================== MEMBER FUNCTIONS ============================
       
    40  
       
    41 // ----------------------------------------------------------------------------
       
    42 // Two phase constructor
       
    43 // ----------------------------------------------------------------------------
       
    44 // 
       
    45 CMPXCollectionUtility* CMPXCollectionUtility::NewL(
       
    46     const TUid& aModeId,
       
    47     MMPXCollectionObserver* aObs)
       
    48     {
       
    49     CMPXCollectionUtility* p=new(ELeave)CMPXCollectionUtility(aObs);
       
    50     CleanupStack::PushL(p);
       
    51     p->ConstructL(aModeId);
       
    52     CleanupStack::Pop(p);
       
    53     return p;
       
    54     }
       
    55  
       
    56 // ----------------------------------------------------------------------------
       
    57 // Destructor
       
    58 // ----------------------------------------------------------------------------
       
    59 // 
       
    60 CMPXCollectionUtility::~CMPXCollectionUtility()
       
    61     { 
       
    62     Cancel();
       
    63 #ifdef _ENABLE_GUARD_TIMER
       
    64     delete iGuardTimer;
       
    65 #endif
       
    66     if (iTaskQueue)
       
    67         {
       
    68         delete iTaskQueue;
       
    69         }
       
    70  
       
    71     delete iCurrentEntries;
       
    72  
       
    73     if (iMsgMonitor)
       
    74         {
       
    75         delete iMsgMonitor;
       
    76         }
       
    77 
       
    78     iMcs.Close();
       
    79 
       
    80     delete iBuffer;
       
    81     delete iArray;
       
    82     delete iMedia;
       
    83     delete iMediaOnError;
       
    84     }
       
    85 
       
    86 // ----------------------------------------------------------------------------
       
    87 // C++ constructor
       
    88 // Create a unique name out of thread ID and this pointer: no other instance of
       
    89 // this object will have the same name; used to identify this object for
       
    90 // receiving messages 
       
    91 // ----------------------------------------------------------------------------
       
    92 // 
       
    93 CMPXCollectionUtility::CMPXCollectionUtility(MMPXCollectionObserver* aObs)
       
    94 :   CActive(EPriorityStandard),
       
    95     iObserver(aObs),
       
    96     iCallbackOngoing(EFalse)
       
    97     { 
       
    98     CActiveScheduler::Add(this); 
       
    99     TThreadId threadId=RThread().Id(); // this thread id
       
   100     } 
       
   101  
       
   102 // ----------------------------------------------------------------------------
       
   103 // 2nd phase constructor
       
   104 // ----------------------------------------------------------------------------
       
   105 // 
       
   106 void CMPXCollectionUtility::ConstructL(const TUid& aModeId)
       
   107     {
       
   108     MPX_FUNC_EX("CMPXCollectionUtility::ConstructL");
       
   109     iTaskQueue = CMPXTaskQueue::NewL();
       
   110     User::LeaveIfError(
       
   111         iMcs.Connect(KMPXCollectionServerName,
       
   112                      KMPXCollectionServerImg,
       
   113                      TVersion(KMPXCollectionServerMajorVersionNumber,
       
   114                      KMPXCollectionServerMinorVersionNumber,
       
   115                      KMPXCollectionServerBuildVersionNumber)));
       
   116     iMcs.SendReceiveL(EMcsSetMode,TIpcArgs(aModeId.iUid)); 
       
   117     iMsgMonitor = CMPXMessageMonitor::NewL(iMcs,*this);
       
   118     iMediaOnError = CMPXMedia::NewL();
       
   119 #ifdef _ENABLE_GUARD_TIMER
       
   120     iGuardTimer=CPeriodic::NewL(CActive::EPriorityStandard);
       
   121 #endif
       
   122     }
       
   123  
       
   124 // ----------------------------------------------------------------------------
       
   125 // Return reference to collection
       
   126 // ----------------------------------------------------------------------------
       
   127 // 
       
   128 MMPXCollection& CMPXCollectionUtility::Collection()
       
   129     {
       
   130     return *this;
       
   131     }
       
   132 
       
   133 // ----------------------------------------------------------------------------
       
   134 // Retrieves the ID of the collection resolved based on selection criteria
       
   135 // ----------------------------------------------------------------------------
       
   136 // 
       
   137 TUid CMPXCollectionUtility::CollectionIDL(const TArray<TUid>& aUids)
       
   138     {
       
   139     // Buffer to transfer UIDs
       
   140     //
       
   141     CBufBase* buf=CBufFlat::NewL(KMPXBufGranularity);
       
   142     CleanupStack::PushL( buf );
       
   143 
       
   144     RBufWriteStream writeStream( *buf );
       
   145     CleanupClosePushL( writeStream );
       
   146     ::ExternalizeL(aUids, writeStream);
       
   147     writeStream.CommitL();
       
   148     buf->Compress();
       
   149     CleanupStack::PopAndDestroy(&writeStream);
       
   150  
       
   151     // IPC the data
       
   152     //
       
   153     TPtr8 des = buf->Ptr(0);
       
   154     TPckgBuf<TUid> pkg;
       
   155     iMcs.SendReceiveL( EMcsCollectionIdLookup, TIpcArgs(&des, &pkg) );
       
   156     CleanupStack::PopAndDestroy( buf );
       
   157  
       
   158     return pkg();
       
   159     }
       
   160  
       
   161 // ----------------------------------------------------------------------------
       
   162 // CMPXCollectionUtility::AddSubscriptionL
       
   163 // ----------------------------------------------------------------------------
       
   164 // 
       
   165 void CMPXCollectionUtility::AddSubscriptionL(
       
   166     const CMPXSubscription& aSubscription)
       
   167     {
       
   168     const CMPXMediaArray* items = aSubscription.ItemsL();
       
   169  
       
   170     CMPXCommand* cmd = CMPXCommand::NewL();
       
   171     CleanupStack::PushL(cmd);
       
   172     cmd->SetTObjectValueL(KMPXCommandGeneralId, KMPXCommandSubscriptionAdd);
       
   173     cmd->SetCObjectValueL(KMPXCommandSubscriptionAddItems, items);
       
   174     cmd->SetTObjectValueL(KMPXCommandGeneralDoSync, ETrue);
       
   175     CommandL(*cmd);
       
   176     CleanupStack::PopAndDestroy(cmd); 
       
   177     }
       
   178  
       
   179 // ----------------------------------------------------------------------------
       
   180 // CMPXCollectionUtility::RemoveSubscriptionL
       
   181 // ----------------------------------------------------------------------------
       
   182 // 
       
   183 void CMPXCollectionUtility::RemoveSubscriptionL(
       
   184     const CMPXSubscription& aSubscription)
       
   185     {
       
   186     const CMPXMediaArray* items = aSubscription.ItemsL();
       
   187  
       
   188     CMPXCommand* cmd = CMPXCommand::NewL();
       
   189     CleanupStack::PushL(cmd);
       
   190     cmd->SetTObjectValueL(KMPXCommandGeneralId, KMPXCommandSubscriptionRemove);
       
   191     cmd->SetCObjectValueL(KMPXCommandSubscriptionAddItems, items);
       
   192     cmd->SetTObjectValueL(KMPXCommandGeneralDoSync, ETrue);
       
   193     CommandL(*cmd);
       
   194     CleanupStack::PopAndDestroy(cmd); 
       
   195     }
       
   196  
       
   197 // ----------------------------------------------------------------------------
       
   198 // CMPXCollectionUtility::ClearSubscriptionsL
       
   199 // ----------------------------------------------------------------------------
       
   200 // 
       
   201 void CMPXCollectionUtility::ClearSubscriptionsL()
       
   202     {
       
   203     CMPXCommand* cmd = CMPXCommand::NewL();
       
   204     CleanupStack::PushL(cmd);
       
   205     cmd->SetTObjectValueL(KMPXCommandGeneralId, KMPXCommandSubscriptionRemoveAll);
       
   206     cmd->SetTObjectValueL(KMPXCommandGeneralDoSync, ETrue);
       
   207     CommandL(*cmd);
       
   208     CleanupStack::PopAndDestroy(cmd);
       
   209     } 
       
   210 
       
   211 // ----------------------------------------------------------------------------
       
   212 // Destroy this object
       
   213 // ----------------------------------------------------------------------------
       
   214 // 
       
   215 void CMPXCollectionUtility::Close()
       
   216     {
       
   217     MPX_DEBUG2("CMPXCollectionUtility::Close %08x", this);
       
   218     iMsgMonitor->Cancel();
       
   219     delete this;
       
   220     } 
       
   221 
       
   222 // ----------------------------------------------------------------------------
       
   223 //  Open's collection with the mode. Data returned in callback
       
   224 // ----------------------------------------------------------------------------
       
   225 //
       
   226 void CMPXCollectionUtility::OpenL(TMPXOpenMode aMode)
       
   227     {
       
   228     MPX_DEBUG2("CMPXCollectionUtility::OpenL with mode %d", aMode);
       
   229     AddRequestL(EMcsOpen, NULL, aMode);
       
   230     }
       
   231  
       
   232 // ----------------------------------------------------------------------------
       
   233 // Open a collection
       
   234 // ----------------------------------------------------------------------------
       
   235 // 
       
   236 void CMPXCollectionUtility::OpenL(TInt aIndex,TMPXOpenMode aMode)
       
   237     {
       
   238     RArray<TMPXAttribute> dummy;
       
   239     CleanupClosePushL(dummy);
       
   240     OpenL(aIndex, dummy.Array(), aMode);
       
   241     CleanupStack::PopAndDestroy(&dummy); 
       
   242     }
       
   243 
       
   244 // ----------------------------------------------------------------------------
       
   245 // Open a collection by path
       
   246 // ----------------------------------------------------------------------------
       
   247 // 
       
   248 void CMPXCollectionUtility::OpenL(
       
   249     const CMPXCollectionPath& aPath,
       
   250     TMPXOpenMode aMode)
       
   251     {
       
   252     RArray<TMPXAttribute> dummy;
       
   253     CleanupClosePushL(dummy);
       
   254     OpenL(aPath, dummy.Array(), aMode);
       
   255     CleanupStack::PopAndDestroy(&dummy); 
       
   256     }
       
   257 
       
   258 // ----------------------------------------------------------------------------
       
   259 //  Opens the collection at a specific index 
       
   260 // ----------------------------------------------------------------------------
       
   261 //
       
   262 void CMPXCollectionUtility::OpenL(
       
   263     TInt aIndex,
       
   264     const TArray<TMPXAttribute>& aAttrs,
       
   265     TMPXOpenMode aMode)
       
   266     {
       
   267     // Externalize parameters
       
   268     //
       
   269     CBufBase* buf=CBufFlat::NewL(KMPXBufGranularity);
       
   270     CleanupStack::PushL( buf );
       
   271 
       
   272     RBufWriteStream writeStream( *buf );
       
   273     CleanupClosePushL( writeStream );
       
   274     // Mode
       
   275     writeStream.WriteInt32L(aMode); 
       
   276     // externalize attributes array
       
   277     ::ExternalizeL(aAttrs, writeStream);
       
   278     // Close and compress buffer
       
   279     writeStream.CommitL();
       
   280     buf->Compress();
       
   281     CleanupStack::PopAndDestroy(&writeStream);
       
   282  
       
   283     // Async version, Add request to the task queue 
       
   284     AddRequestL(EMcsOpenIndex, NULL, aIndex, buf);
       
   285     CleanupStack::Pop( buf );  // ownership transferred to the queue
       
   286     }
       
   287 
       
   288 // ----------------------------------------------------------------------------
       
   289 //  Opens the collection at a specific level 
       
   290 // ----------------------------------------------------------------------------
       
   291 // 
       
   292 void CMPXCollectionUtility::OpenL(
       
   293     const CMPXCollectionPath& aPath,
       
   294     const TArray<TMPXAttribute>& aAttrs,
       
   295     TMPXOpenMode aMode)
       
   296     {
       
   297     MPX_FUNC("CMPXCollectionUtility::OpenL(const CMPXCollectionPath& aPath)");
       
   298     MPX_DEBUG_PATH(aPath);
       
   299     CBufBase* buffer=CBufFlat::NewL(KMPXBufGranularity);
       
   300     CleanupStack::PushL( buffer );
       
   301     RBufWriteStream writeStream( *buffer );
       
   302     CleanupClosePushL( writeStream );
       
   303     //collection path 
       
   304     writeStream << aPath; 
       
   305     // externalize open mode
       
   306     writeStream.WriteInt32L(aMode);
       
   307     // externalize attributes array
       
   308     ::ExternalizeL(aAttrs, writeStream);
       
   309     writeStream.CommitL();
       
   310     buffer->Compress();
       
   311     CleanupStack::PopAndDestroy(&writeStream);
       
   312     AddRequestL(EMcsOpenPath, NULL, 0, buffer);
       
   313     CleanupStack::Pop(buffer); //buffer ownership transferred
       
   314     }
       
   315 
       
   316 // ----------------------------------------------------------------------------
       
   317 //  Opens the collection in its current state, or if aUids do not
       
   318 //  apply to currently opened collection, then the state will
       
   319 //  revert back to root level
       
   320 // ----------------------------------------------------------------------------
       
   321 // 
       
   322 void CMPXCollectionUtility::OpenL(
       
   323     const TArray<TUid>& aUids,
       
   324     TMPXOpenMode aMode)
       
   325     {
       
   326     MPX_FUNC_EX("CMPXCollectionUtility::OpenL(aUids, aMode)");
       
   327     CBufBase* buf=CBufFlat::NewL(KMPXBufGranularity);
       
   328     CleanupStack::PushL( buf );
       
   329     // Externalize parameters
       
   330     //
       
   331     RArray<TUid> uids;
       
   332     CleanupClosePushL(uids);
       
   333     TInt count(aUids.Count());
       
   334     for (TInt i=0; i<count; ++i)
       
   335         { // sort uids
       
   336         uids.InsertInOrderL(aUids[i], MPXUser::CompareUids);
       
   337         }
       
   338     RBufWriteStream writeStream( *buf );
       
   339     CleanupClosePushL( writeStream );
       
   340     // Mode
       
   341     writeStream.WriteInt32L(aMode); 
       
   342     // Uids
       
   343     ::ExternalizeL(uids.Array(), writeStream);
       
   344     // Close and compress buffer
       
   345     writeStream.CommitL();
       
   346     buf->Compress();
       
   347     CleanupStack::PopAndDestroy(&writeStream);
       
   348  
       
   349     CleanupStack::PopAndDestroy(&uids);
       
   350     // Async version, Add request to the task queue 
       
   351     AddRequestL(EMcsOpenByUids, NULL, 0, buf);
       
   352     CleanupStack::Pop( buf );  // ownership transferred to the queue
       
   353     }
       
   354 
       
   355 // ----------------------------------------------------------------------------
       
   356 //  Opens the collection in its current state, or if aUid does not
       
   357 //  apply to currently opened collection, then the state will
       
   358 //  revert back to root level
       
   359 // ----------------------------------------------------------------------------
       
   360 // 
       
   361 void CMPXCollectionUtility::OpenL(
       
   362     const TUid& aUid,
       
   363     TMPXOpenMode aMode)
       
   364     {
       
   365     RArray<TUid> uids;
       
   366     CleanupClosePushL(uids);
       
   367     uids.AppendL(aUid);
       
   368     OpenL(uids.Array(),aMode);
       
   369     CleanupStack::PopAndDestroy(&uids);
       
   370     }
       
   371 
       
   372 // ----------------------------------------------------------------------------
       
   373 //  Apply a filter to collection browsing; all subsequent calls
       
   374 //  to OpenL() will have this filter applied
       
   375 // ----------------------------------------------------------------------------
       
   376 // 
       
   377 void CMPXCollectionUtility::SetFilterL(CMPXFilter* aFilter)
       
   378     {
       
   379     if (aFilter)
       
   380         { // Send filter to server
       
   381         CBufBase* buf=NULL;
       
   382         ::CreateBufferL<CMPXFilter>(*aFilter,buf);
       
   383         CleanupStack::PushL(buf);
       
   384         TPtr8 ptr=buf->Ptr(0);
       
   385         iMcs.SendReceiveL(EMcsSetFilter,TIpcArgs(&ptr));
       
   386         CleanupStack::PopAndDestroy(buf);
       
   387         }
       
   388     else
       
   389         { // Else send zero length descriptor
       
   390         iMcs.SendReceiveL(EMcsSetFilter,TIpcArgs(&KNullDesC8));
       
   391         }
       
   392     }
       
   393 
       
   394 // ----------------------------------------------------------------------------
       
   395 //  Current filter that is applied to collection browsing
       
   396 // ----------------------------------------------------------------------------
       
   397 // 
       
   398 CMPXFilter* CMPXCollectionUtility::FilterL()
       
   399     {
       
   400     TInt size=iMcs.SendReceiveL(EMcsFilter);
       
   401     // 
       
   402     // Transfer results from server
       
   403     //
       
   404     CMPXMedia* filter=NULL;
       
   405     if (size)
       
   406         {
       
   407         ::TransferBufferFromServerL(iMcs,EMcsGetSyncBuffer,size,iBuffer);
       
   408         ::NewFromBufferL<CMPXFilter>(*iBuffer,filter); 
       
   409         }
       
   410     return filter;
       
   411     }
       
   412 
       
   413 // ----------------------------------------------------------------------------
       
   414 // The UID identifying this collection
       
   415 // ----------------------------------------------------------------------------
       
   416 // 
       
   417 TUid CMPXCollectionUtility::UidL() const
       
   418     {
       
   419     TPckgBuf<TInt> uidPkg; 
       
   420     iMcs.SendReceiveL(EMcsGetUid, TIpcArgs(&uidPkg));
       
   421     return TUid::Uid(uidPkg());
       
   422     }
       
   423  
       
   424 // ----------------------------------------------------------------------------
       
   425 // Return current collection path
       
   426 // ----------------------------------------------------------------------------
       
   427 // 
       
   428 CMPXCollectionPath* CMPXCollectionUtility::PathL()
       
   429     {
       
   430     CMPXCollectionPath* path = NULL;
       
   431     TInt size = iMcs.SendReceiveL(EMcsGetPath);
       
   432     if (size >0)
       
   433         {
       
   434         ::TransferBufferFromServerL(iMcs, EMcsGetSyncBuffer, size, iBuffer);
       
   435         ::NewFromBufferL<CMPXCollectionPath>(*iBuffer, path);
       
   436         }
       
   437     return path;
       
   438     }
       
   439 
       
   440 // ----------------------------------------------------------------------------
       
   441 // Back to upper level
       
   442 // ----------------------------------------------------------------------------
       
   443 // 
       
   444 void CMPXCollectionUtility::BackL()
       
   445     {
       
   446     AddRequestL(EMcsBack, NULL);
       
   447     }
       
   448 
       
   449 // ----------------------------------------------------------------------------
       
   450 // Is remote collection path
       
   451 // ----------------------------------------------------------------------------
       
   452 // 
       
   453 TBool CMPXCollectionUtility::IsRemote(const CMPXCollectionPath& aPath)
       
   454     {
       
   455     (void)aPath; 
       
   456     return EFalse; 
       
   457     }
       
   458 
       
   459 // ----------------------------------------------------------------------------
       
   460 // Remove outstanding requests
       
   461 // ----------------------------------------------------------------------------
       
   462 // 
       
   463 void CMPXCollectionUtility::CancelRequest()
       
   464     {
       
   465     Cancel();
       
   466     iTaskQueue->Reset();
       
   467     }
       
   468 
       
   469 // ----------------------------------------------------------------------------
       
   470 // Add item(s)
       
   471 // ----------------------------------------------------------------------------
       
   472 //
       
   473 void CMPXCollectionUtility::AddL(const CMPXMedia& aNewProperties)
       
   474     {
       
   475     delete iMedia;
       
   476     iMedia=NULL;
       
   477     iMedia=CMPXMedia::NewL(aNewProperties);
       
   478  
       
   479     CBufBase* buf(NULL);
       
   480     ::CreateBufferL<CMPXMedia>( aNewProperties, buf );
       
   481     CleanupStack::PushL( buf );
       
   482     TPtr8 ptr = buf->Ptr(0);
       
   483     iMcs.SendReceiveL( EMcsAddItem, TIpcArgs(&ptr));
       
   484     CleanupStack::PopAndDestroy( buf );
       
   485     }
       
   486 
       
   487 // ----------------------------------------------------------------------------
       
   488 // Remove a single item
       
   489 // ----------------------------------------------------------------------------
       
   490 // 
       
   491 void CMPXCollectionUtility::RemoveL( 
       
   492     const CMPXCollectionPath& aPath,
       
   493     MMPXCollectionRemoveObserver* aObs )
       
   494     {
       
   495     // Serialize the path and send it to the collection
       
   496     //
       
   497     if (aPath.Levels()<=0)
       
   498         {
       
   499         User::Leave(KErrArgument);
       
   500         }
       
   501     CBufBase* buf(NULL);
       
   502     ::CreateBufferL<CMPXCollectionPath>( aPath, buf );
       
   503     CleanupStack::PushL(buf);
       
   504     AddRequestL(EMcsRemovePath, aObs, 0, buf);  // buf ownership transferred
       
   505     CleanupStack::Pop(buf);
       
   506     }
       
   507 
       
   508 // ----------------------------------------------------------------------------
       
   509 // Remove a list of items
       
   510 // ----------------------------------------------------------------------------
       
   511 // 
       
   512 void CMPXCollectionUtility::RemoveL(const CMPXMedia& aProperties)
       
   513     {
       
   514     delete iMedia;
       
   515     iMedia=NULL;
       
   516     iMedia=CMPXMedia::NewL(aProperties);
       
   517  
       
   518     CBufBase* buf(NULL);
       
   519     ::CreateBufferL<CMPXMedia>( aProperties, buf );
       
   520     CleanupStack::PushL( buf );
       
   521     TPtr8 ptr = buf->Ptr(0);
       
   522     iMcs.SendReceiveL( EMcsRemoveItem, TIpcArgs(&ptr));
       
   523     CleanupStack::PopAndDestroy( buf );
       
   524     }
       
   525 
       
   526 // ----------------------------------------------------------------------------
       
   527 // Set properties
       
   528 // ----------------------------------------------------------------------------
       
   529 // 
       
   530 void CMPXCollectionUtility::SetSyncL(const CMPXMedia& aMedia)
       
   531     {
       
   532     delete iMedia;
       
   533     iMedia=NULL;
       
   534     iMedia=CMPXMedia::NewL(aMedia);
       
   535  
       
   536     CBufBase* buf(NULL);
       
   537     ::CreateBufferL<CMPXMedia>( aMedia, buf );
       
   538     CleanupStack::PushL( buf );
       
   539     TPtr8 ptr = buf->Ptr(0);
       
   540     iMcs.SendReceiveL( EMcsSetMedia, TIpcArgs(&ptr));
       
   541     CleanupStack::PopAndDestroy( buf );
       
   542     }
       
   543 
       
   544 // ----------------------------------------------------------------------------
       
   545 // Set properties Asynchronous
       
   546 // ----------------------------------------------------------------------------
       
   547 // 
       
   548 void CMPXCollectionUtility::SetL(const CMPXMedia& /*aMedia*/)
       
   549     {
       
   550     ASSERT(0); // DEPRECATED, please use CommandL(CMPXCommand& aCmd)
       
   551     }
       
   552 
       
   553 // ----------------------------------------------------------------------------
       
   554 // Find media
       
   555 // ----------------------------------------------------------------------------
       
   556 // 
       
   557 void CMPXCollectionUtility::FindAllL(const CMPXMedia& aMedia,
       
   558                                      const TArray<TMPXAttribute>& aAttrs,
       
   559                                      MMPXCollectionFindObserver& aObs)
       
   560     {
       
   561     // Externalize parameters
       
   562     //
       
   563     CBufBase* buf(NULL);
       
   564     ::CreateBufferL(aAttrs, buf);
       
   565     CleanupStack::PushL(buf);
       
   566     // Increase reference count on media ownership transferred
       
   567     CMPXMedia* ref = CMPXMedia::NewL( aMedia ); 
       
   568     CleanupStack::PushL(ref);
       
   569     AddRequestL(EMcsFindAll, &aObs, aMedia.Data(), buf, NULL, ref);
       
   570     // Async version, Add request to the task queue 
       
   571     CleanupStack::Pop(ref);
       
   572     CleanupStack::Pop( buf );  // ownership transferred to the queue
       
   573     }
       
   574 
       
   575 // ----------------------------------------------------------------------------
       
   576 // Find media sync
       
   577 // ----------------------------------------------------------------------------
       
   578 // 
       
   579 CMPXMedia* CMPXCollectionUtility::FindAllL(const CMPXMedia& aMedia,
       
   580                                            const TArray<TMPXAttribute>& aAttrs)
       
   581     {
       
   582     CMPXMedia* media=CMPXMedia::NewL(aMedia); // keep media alive
       
   583     CleanupStack::PushL(media);
       
   584  
       
   585     CBufBase* buf(NULL);
       
   586     ::CreateBufferL(aAttrs, buf);
       
   587     CleanupStack::PushL(buf);
       
   588  
       
   589     // Synchronous version, transfer directly
       
   590     TPtr8 ptr = buf->Ptr(0);
       
   591     TInt size = iMcs.SendReceiveL( EMcsFindAll, 
       
   592                                    TIpcArgs(&ptr, 1, media->Data()) );
       
   593     CleanupStack::PopAndDestroy( buf );
       
   594  
       
   595     // Transfer results from server
       
   596     //
       
   597     CMPXMedia* results(NULL);
       
   598     ::TransferBufferFromServerL( iMcs, EMcsGetSyncBuffer, 
       
   599                                  size, iBuffer );
       
   600     ::NewFromBufferL<CMPXMedia>( *iBuffer, results );
       
   601     CleanupStack::PopAndDestroy(media);
       
   602     return results;
       
   603     }
       
   604 
       
   605 // ----------------------------------------------------------------------------
       
   606 // Issue media request
       
   607 // ----------------------------------------------------------------------------
       
   608 // 
       
   609 void CMPXCollectionUtility::MediaL(
       
   610     const CMPXCollectionPath& aPath,
       
   611     const TArray<TMPXAttribute>& aAttrs,
       
   612     CMPXAttributeSpecs* aSpecs/*=NULL*/,
       
   613     CMPXFilter* aFilter/*=NULL*/)
       
   614     {
       
   615     MPX_FUNC_EX("CMPXCollectionUtility::MediaL()");
       
   616     MPX_DEBUG_PATH(aPath);
       
   617     if (aPath.Levels()<=0)
       
   618         {
       
   619         User::Leave(KErrArgument);
       
   620         }
       
   621     CMPXCommand* cmd = CMPXCommand::NewL();
       
   622     CleanupStack::PushL(cmd);
       
   623 
       
   624     CMPXCollectionPath* path = CMPXCollectionPath::NewL(aPath);
       
   625     CleanupStack::PushL(path);
       
   626     path->Set(aAttrs); // aAttrs should be removed from parameter
       
   627                        // Clients should set attribute before API is called
       
   628  
       
   629     cmd->SetTObjectValueL<TInt>(KMPXCommandGeneralId, KMPXCommandContentIdMedia);
       
   630     cmd->SetCObjectValueL<CMPXCollectionPath>(KMPXCommandGeneralTargetIds, path);
       
   631     CMPXAttributeSpecs* attrSpecs = aSpecs ? 
       
   632             CMPXAttributeSpecs::NewL(*aSpecs) : CMPXAttributeSpecs::NewL();
       
   633     CleanupStack::PushL(attrSpecs);
       
   634     cmd->SetCObjectValueL<CMPXAttributeSpecs>(KMPXCommandMediaAttributeSpecs, attrSpecs);
       
   635     CleanupStack::PopAndDestroy(attrSpecs);
       
   636     CMPXFilter* filter = aFilter ? CMPXFilter::NewL(*aFilter) : CMPXFilter::NewL();
       
   637     CleanupStack::PushL(filter);
       
   638     cmd->SetCObjectValueL<CMPXFilter>(KMPXCommandMediaFilter, filter);
       
   639     CleanupStack::PopAndDestroy(filter);
       
   640     //call CommandL in the future. All APIs will be mapped to CommandL
       
   641     AddRequestL(EMcsMediaByPath, NULL, 0, NULL, (TAny*)cmd, cmd);
       
   642     CleanupStack::PopAndDestroy(path);
       
   643     CleanupStack::Pop(cmd); // Ownership transferred to the task queue
       
   644     }
       
   645 
       
   646 // ----------------------------------------------------------------------------
       
   647 // Add a request to broadcast a message
       
   648 // ----------------------------------------------------------------------------
       
   649 // 
       
   650 void CMPXCollectionUtility::NotifyL( TMPXCollectionBroadCastMsg aMsg, 
       
   651                                      TInt aData )
       
   652     {
       
   653     // Synchronous, for closing server file handles
       
   654     iMcs.SendReceiveL( EMcsNotifyEvent,
       
   655                        TIpcArgs((TInt)aMsg, aData));
       
   656     }
       
   657 
       
   658 // ----------------------------------------------------------------------------
       
   659 // Send a Command to the collection
       
   660 // ----------------------------------------------------------------------------
       
   661 // 
       
   662 void CMPXCollectionUtility::CommandL(TMPXCollectionCommand aCmd, TInt aData )
       
   663     {
       
   664     // Synchronous, send a command to the server
       
   665     iMcs.SendReceiveL( EMcsCommand, TIpcArgs( (TInt)aCmd, aData ) );
       
   666     }
       
   667  
       
   668 // ----------------------------------------------------------------------------
       
   669 // Send a Command to the collection
       
   670 // ----------------------------------------------------------------------------
       
   671 //
       
   672 void CMPXCollectionUtility::CommandL(CMPXCommand& aCmd)
       
   673     {
       
   674     TBool sync(EFalse); // by default command is asynchronous
       
   675     if (aCmd.IsSupported(KMPXCommandGeneralDoSync))
       
   676         { // check if command is sync
       
   677         sync=(aCmd.ValueTObjectL<TBool>(KMPXCommandGeneralDoSync));
       
   678         }
       
   679     if (sync)
       
   680         { // sync request
       
   681         iMcs.SendReceiveL(EMcsCommandExt, TIpcArgs(EFalse, aCmd.Data()));
       
   682         }
       
   683     else
       
   684         { // async request
       
   685         // Increase reference count on command ownership transferred
       
   686         CMPXCommand* ref = CMPXCommand::NewL(aCmd); 
       
   687         // async version, Add request to the task queue 
       
   688         CleanupStack::PushL(ref);
       
   689         AddRequestL(EMcsCommandExt, NULL, ETrue, NULL, (TAny*)ref, ref );
       
   690         CleanupStack::Pop(ref); // Ownership transferred to the task queue
       
   691         }
       
   692     }
       
   693 
       
   694 // ----------------------------------------------------------------------------
       
   695 // Retrieve the list of supported mime types
       
   696 // ----------------------------------------------------------------------------
       
   697 // 
       
   698 void CMPXCollectionUtility::GetSupportedTypesL( 
       
   699     RPointerArray<CMPXCollectionType>& aArray )
       
   700     {
       
   701     TInt size = iMcs.SendReceiveL( EMcsGetSupportedTypes );
       
   702     ::ArrayFromServerL( iMcs, EMcsGetSyncBuffer, size, aArray );
       
   703     }
       
   704 
       
   705 // ----------------------------------------------------------------------------
       
   706 // Retrieve the bitmask of supported capabilities of the collection
       
   707 // ----------------------------------------------------------------------------
       
   708 // 
       
   709 void CMPXCollectionUtility::GetSupportedCapabilitiesL(
       
   710     TCollectionCapability& aCapability)
       
   711     {
       
   712     TPckgBuf<TCollectionCapability> pkg;
       
   713     iMcs.SendReceiveL( EMcsGetCapabilities, TIpcArgs(&pkg) );
       
   714     aCapability = pkg();
       
   715     }
       
   716 
       
   717 // ----------------------------------------------------------------------------
       
   718 // Retrieves the actual collection implementation UID
       
   719 // ----------------------------------------------------------------------------
       
   720 // 
       
   721 TUid CMPXCollectionUtility::CollectionIDL(TUid& aCollection)
       
   722     {
       
   723     TPckgBuf<TUid> pkg( aCollection );
       
   724     iMcs.SendReceiveL( EMcsCollectionID, TIpcArgs(&pkg) );
       
   725  
       
   726     return pkg();
       
   727     }
       
   728 
       
   729 // ----------------------------------------------------------------------------
       
   730 // Message received 
       
   731 // ----------------------------------------------------------------------------
       
   732 // 
       
   733 void CMPXCollectionUtility::MessageReceived(TInt aMsgData, TInt aError)
       
   734     {
       
   735     TRAP_IGNORE(HandleMessageL(aMsgData, aError));
       
   736     }
       
   737 
       
   738 // ----------------------------------------------------------------------------
       
   739 // Handles an active object's request completion event
       
   740 // ----------------------------------------------------------------------------
       
   741 // 
       
   742 void CMPXCollectionUtility::RunL()
       
   743     {
       
   744 #ifdef _ENABLE_GUARD_TIMER
       
   745     iGuardTimer->Cancel();
       
   746 #endif
       
   747     TInt err=iStatus.Int();
       
   748     TInt task = iTaskQueue->Task();
       
   749     MPX_DEBUG4("-->CMPXCollectionUtility::RunL 0x%08x task %d err%d", 
       
   750                this, task, err);
       
   751     if (KErrNotFound == task)
       
   752         {
       
   753         MPX_DEBUG1("CMPXCollectionUtility::RunL no task");
       
   754         return;
       
   755         }
       
   756 
       
   757     // Try again in case server is down for IAD
       
   758     if (err == KErrDied || err == KErrServerTerminated)
       
   759         {
       
   760         MPX_DEBUG3("-->CMPXCollectionUtility::RunL Reconnecting session for IAD 0x%08x task %d",
       
   761                 this, task);
       
   762         
       
   763         // attempt to bring the server back up
       
   764         err = iMcs.Reconnect();
       
   765         
       
   766         if (err != KErrNone)
       
   767             {
       
   768             MPX_DEBUG1("-->CMPXCollectionUtility::RunL Reconnect Failed");
       
   769             }
       
   770         }
       
   771     
       
   772     // If there was an error, callback to observer with error code
       
   773     User::LeaveIfError(err);
       
   774     
       
   775     switch(task)
       
   776         {
       
   777         case EMcsOpen:
       
   778         case EMcsBack:
       
   779         case EMcsOpenIndex:
       
   780         case EMcsOpenPath:
       
   781         case EMcsOpenByUids:
       
   782             {
       
   783             MPX_DEBUG1("CMPXCollectionUtility::RunL handle open");
       
   784             if(err == KMPXCollectionPath && iObserver)
       
   785                 {
       
   786                 CMPXCollectionPath* path = PathL();
       
   787                 CleanupStack::PushL(path);
       
   788                 if (path->OpenNextMode() != EMPXOpenNoPlaylist)
       
   789                     {
       
   790                     CMPXCollectionPlaylist* p=CMPXCollectionPlaylist::NewL(*path);
       
   791                     CleanupStack::PushL(p);
       
   792  
       
   793                     if( path->OpenNextMode() == EMPXOpenPlaylistOnly )
       
   794                         {
       
   795                         p->SetToIndex( KErrNotFound );
       
   796                         }
       
   797  
       
   798                     iCallbackOngoing = ETrue;
       
   799                     iObserver->HandleOpenL(*p, KErrNone);
       
   800                     iCallbackOngoing = EFalse;
       
   801                     CleanupStack::PopAndDestroy(p);
       
   802                     }
       
   803                 CleanupStack::PopAndDestroy(path);
       
   804                 }
       
   805             else if (KMPXCollectionEntries == err && iObserver)
       
   806                 {
       
   807                 MPX_DEBUG2("CMPXCollectionUtility::RunL with KMPXCollectionEntries %d", 
       
   808                             iSizePckg());
       
   809                 if (iSizePckg() >0)
       
   810                     {
       
   811                     ::TransferBufferFromServerL(iMcs,EMcsGetAsyncBuffer, 
       
   812                                                 iSizePckg(), iBuffer);
       
   813                     ::NewFromBufferL<CMPXMedia>(*iBuffer, iCurrentEntries);
       
   814                     }
       
   815                 MPX_DEBUG1("CMPXCollectionUtility::RunL call back client with entries");
       
   816                 iCallbackOngoing = ETrue;
       
   817                 iObserver->HandleOpenL(*iCurrentEntries, 
       
   818                                        iSelectionPckg(), 
       
   819                                        (TBool)iCompletePckg(), 
       
   820                                        KErrNone);
       
   821                 iCallbackOngoing = EFalse;
       
   822                 } // else message will be received which triggers to read buffer
       
   823             break;
       
   824             }
       
   825          case EMcsMediaByPath:
       
   826             {
       
   827             CMPXMedia* props = NULL;
       
   828             if (iObserver)
       
   829                 {
       
   830                 if(iSizePckg() && KMPXCollectionMedia == err)
       
   831                     {
       
   832                     ::TransferBufferFromServerL(iMcs,EMcsGetAsyncBuffer, 
       
   833                                                 iSizePckg(), iBuffer);
       
   834                     ::NewFromBufferL<CMPXMedia>(*iBuffer, props);
       
   835                     err = KErrNone;
       
   836                     CleanupStack::PushL(props);
       
   837                     }
       
   838                 else
       
   839                     {
       
   840                     props = iMediaOnError;
       
   841                     }
       
   842                 iCallbackOngoing = ETrue;
       
   843                 iObserver->HandleCollectionMediaL(*props, err);
       
   844                 iCallbackOngoing = EFalse;
       
   845                 if (props && props != iMediaOnError)
       
   846                     {
       
   847                     CleanupStack::PopAndDestroy(props);
       
   848                     }
       
   849                 }
       
   850             break;
       
   851             }
       
   852         case EMcsRemovePath:
       
   853             {
       
   854             MMPXCollectionRemoveObserver* obs = 
       
   855                      (MMPXCollectionRemoveObserver*) iTaskQueue->Callback();
       
   856  
       
   857             // Optional observer callback
       
   858             CDesCArray* ary(NULL);
       
   859             if( obs && err>0 )
       
   860                 {
       
   861                 ::TransferBufferFromServerL(iMcs,EMcsGetAsyncBuffer, 
       
   862                                             err, iBuffer);
       
   863                 MPXUser::CreateFromBufferL(*iBuffer, ary);
       
   864                 CleanupStack::PushL( ary );
       
   865                 iCallbackOngoing = ETrue;
       
   866                 obs->HandleRemoveL( *ary, KErrNone );
       
   867                 iCallbackOngoing = EFalse;
       
   868                 CleanupStack::PopAndDestroy( ary );
       
   869                 } // else error message will be sent later
       
   870             break;
       
   871             }
       
   872         case EMcsFindAll:
       
   873             {
       
   874             MMPXCollectionFindObserver* obs = 
       
   875                         (MMPXCollectionFindObserver*) iTaskQueue->Callback();
       
   876             CMPXMedia* results(NULL);
       
   877  
       
   878             // Any results?
       
   879             if( err > 0 )
       
   880                 {
       
   881                 if(obs)
       
   882                     {
       
   883                     ::TransferBufferFromServerL( iMcs, EMcsGetAsyncBuffer, 
       
   884                                                  err, iBuffer );
       
   885                     ::NewFromBufferL<CMPXMedia>( *iBuffer, results );
       
   886                     CleanupStack::PushL( results );
       
   887                     iCallbackOngoing = ETrue;
       
   888                     obs->HandleFindAllL( *results, ETrue, KErrNone );
       
   889                     iCallbackOngoing = EFalse;
       
   890                     CleanupStack::PopAndDestroy( results );
       
   891                     }
       
   892                 }
       
   893             break;
       
   894             }
       
   895         case EMcsSetMediaAsync:
       
   896             { // DEPRECATED, please use CommandL(CMPXCommand& aCmd)
       
   897             ASSERT(0);
       
   898             break;
       
   899             }
       
   900         case EMcsCommandExt:
       
   901             {
       
   902             CMPXCommand* result = NULL;
       
   903             if (iObserver && KErrNone == err)
       
   904                 {
       
   905                 if(iSizePckg())
       
   906                     {
       
   907                     ::TransferBufferFromServerL(iMcs,EMcsGetAsyncBuffer, 
       
   908                                                 iSizePckg(), iBuffer);
       
   909                     ::NewFromBufferL<CMPXCommand>(*iBuffer, result);
       
   910                     }
       
   911                 CleanupStack::PushL(result);
       
   912                 iCallbackOngoing = ETrue;
       
   913                 iObserver->HandleCommandComplete(result, KErrNone);
       
   914                 iCallbackOngoing = EFalse;
       
   915                 CleanupStack::PopAndDestroy(result);
       
   916                 }
       
   917             break;
       
   918             }
       
   919         default:
       
   920             ASSERT(0);
       
   921         }
       
   922     iTaskQueue->RemoveTask();
       
   923     ExecuteNextRequest();
       
   924     MPX_DEBUG4("<--CMPXCollectionUtility::RunL 0x%08x task %d err%d", 
       
   925                this, task, err);
       
   926     }
       
   927 
       
   928 // ----------------------------------------------------------------------------
       
   929 // Sends error message to all observers - maybe it should only be to the 
       
   930 // client that calls the async method?
       
   931 // ----------------------------------------------------------------------------
       
   932 // 
       
   933 TInt CMPXCollectionUtility::RunError(TInt aError)
       
   934     {
       
   935     MPX_FUNC_EX("CMPXCollectionUtility::RunError");
       
   936     TRAP_IGNORE(HandleRunErrorL(aError));
       
   937     iCallbackOngoing = EFalse;
       
   938     iTaskQueue->RemoveTask();
       
   939     ExecuteNextRequest();
       
   940     return KErrNone;
       
   941     }
       
   942 
       
   943 // ----------------------------------------------------------------------------
       
   944 // Handle cancelling request
       
   945 // ----------------------------------------------------------------------------
       
   946 // 
       
   947 void CMPXCollectionUtility::DoCancel()
       
   948     {
       
   949 #ifdef _ENABLE_GUARD_TIMER
       
   950     iGuardTimer->Cancel();
       
   951 #endif
       
   952     TRAP_IGNORE(iMcs.SendReceiveL(EMcsCancelRequest));
       
   953     }
       
   954 
       
   955 // ----------------------------------------------------------------------------
       
   956 // Adds a sync request to the queue: if there is no outstanding request,
       
   957 // it will be executed immediately
       
   958 // ----------------------------------------------------------------------------
       
   959 // 
       
   960 void CMPXCollectionUtility::AddRequestL(
       
   961     TMPXCollectionServerOp aFunction,
       
   962     TAny* aObs,
       
   963     TInt aParamData/*=0*/,
       
   964     CBufBase* aBuf/*=NULL*/,
       
   965     TAny* aPtr/*=NULL*/,
       
   966     CBase* aAlivePtr1/*=NULL*/,
       
   967     CBase* aAlivePtr2/*=NULL*/)
       
   968     {
       
   969     iTaskQueue->AddTaskL(aFunction, aObs, aParamData, aBuf, 
       
   970                          aPtr, aAlivePtr1, aAlivePtr2);
       
   971     MPX_DEBUG3("CMPXCollectionUtility::AddRequestL this 0x%08x task=%d", 
       
   972             this, aFunction);
       
   973     if (!IsActive() && !iCallbackOngoing)
       
   974         {
       
   975         ExecuteNextRequest();
       
   976         }
       
   977     }
       
   978  
       
   979 // ----------------------------------------------------------------------------
       
   980 // Executes the next request in the queue. 
       
   981 // ----------------------------------------------------------------------------
       
   982 // 
       
   983 void CMPXCollectionUtility::ExecuteNextRequest()
       
   984     {
       
   985     TInt task = iTaskQueue->Task();
       
   986     if (KErrNotFound != task && !IsActive() &&  !iCallbackOngoing)
       
   987         {
       
   988         switch(task)
       
   989             {
       
   990             case EMcsOpenIndex:
       
   991                 {
       
   992                 iSelectionPckg = (TInt)iTaskQueue->Param();
       
   993                 } // deliberate fall through
       
   994             case EMcsOpenByUids:
       
   995             case EMcsOpenPath:
       
   996                 {
       
   997                 iMcs.SendReceive(task, 
       
   998                                  TIpcArgs(&iSizePckg,   // [out] size of buffer
       
   999                                           &iSelectionPckg, // [in, out] selection index 
       
  1000                                           &iCompletePckg,  // [out] complete
       
  1001                                           &iTaskQueue->BufData()), // index, mode and attr
       
  1002                                  iStatus);
       
  1003                 break;
       
  1004                 }
       
  1005  
       
  1006             case EMcsOpen:
       
  1007                 {
       
  1008                 iMcs.SendReceive(EMcsOpen, 
       
  1009                                  TIpcArgs(&iSizePckg, 
       
  1010                                           &iSelectionPckg, 
       
  1011                                           &iCompletePckg,
       
  1012                                           iTaskQueue->Param()),  // mode
       
  1013                                  iStatus);
       
  1014                 break;
       
  1015                 }
       
  1016             case EMcsMediaByPath:
       
  1017                 {
       
  1018                 iMcs.SendReceive(EMcsMediaByPath, 
       
  1019                                  TIpcArgs(&iSizePckg,
       
  1020                                          ((CMPXCommand*)(iTaskQueue->PtrData()))->Data()), // command handle
       
  1021                                  iStatus);
       
  1022                 break;
       
  1023                 } 
       
  1024             case EMcsBack: 
       
  1025                 {
       
  1026                 iMcs.SendReceive(EMcsBack, 
       
  1027                                  TIpcArgs(&iSizePckg, 
       
  1028                                           &iSelectionPckg, 
       
  1029                                           &iCompletePckg),
       
  1030                                  iStatus);
       
  1031                 break;
       
  1032                 }
       
  1033             case EMcsRemovePath: // deliberate fall through
       
  1034                 {
       
  1035                 iMcs.SendReceive( task, 
       
  1036                                   TIpcArgs(&iTaskQueue->BufData()), 
       
  1037                                   iStatus);
       
  1038                 break; 
       
  1039                 }
       
  1040             case EMcsFindAll:
       
  1041                 {
       
  1042                 iMcs.SendReceive( task, 
       
  1043                                   TIpcArgs(&iTaskQueue->BufData(), // Attrs
       
  1044                                            0,                    // Not sync
       
  1045                                            iTaskQueue->Param()), // Media data handle
       
  1046                                   iStatus );
       
  1047                 break; 
       
  1048                 }
       
  1049             case EMcsCommandExt:
       
  1050                 {
       
  1051                 iMcs.SendReceive(EMcsCommandExt, 
       
  1052                                  TIpcArgs(iTaskQueue->Param(), //[in] Async flag
       
  1053                                           ((CMPXCommand*)(iTaskQueue->PtrData()))->Data(), 
       
  1054                                                                //[in] command handle 
       
  1055                                           &iSizePckg), //[out] size of buffer 
       
  1056                                  iStatus);
       
  1057                 break;
       
  1058                 }
       
  1059             default:
       
  1060                 ASSERT(0);
       
  1061             }
       
  1062     #ifdef _ENABLE_GUARD_TIMER
       
  1063          iGuardTimer->Start(KMPXGuardTimer,KMPXGuardTimer,
       
  1064                             TCallBack(GuardTimerCallback,this)); 
       
  1065     #endif
       
  1066         SetActive(); 
       
  1067         MPX_DEBUG3("CMPXCollectionUtility::ExecuteNextRequest 0x%08x task %d ", 
       
  1068                 this, task);
       
  1069         }
       
  1070     }
       
  1071 
       
  1072 // ----------------------------------------------------------------------------
       
  1073 // CMPXCollectionUtility::HandleMessageL 
       
  1074 // ----------------------------------------------------------------------------
       
  1075 // 
       
  1076 void CMPXCollectionUtility::HandleMessageL(TInt aMsgData, TInt aError)
       
  1077     {
       
  1078     MPX_FUNC_EX("CMPXCollectionUtility::HandleMessageL");
       
  1079     if (iObserver)
       
  1080         {
       
  1081         if (aMsgData>0)
       
  1082             {
       
  1083             CMPXMessage* msg= CMPXMessage::NewL(aMsgData);
       
  1084             CleanupStack::PushL(msg);
       
  1085             MPX_ASSERT(msg->IsSupported(KMPXMessageGeneralId));
       
  1086             iObserver->HandleCollectionMessage(msg, aError);
       
  1087             CleanupStack::PopAndDestroy(msg);
       
  1088             }
       
  1089         else
       
  1090             { // NULL message
       
  1091             iObserver->HandleCollectionMessage(NULL, aError);
       
  1092             }
       
  1093         }
       
  1094     else
       
  1095         {
       
  1096         MPX_DEBUG1("CMPXCollectionUtility::HandleMessageL no observer");
       
  1097         }
       
  1098     iMsgMonitor->GetNextMessage();
       
  1099     }
       
  1100 
       
  1101 
       
  1102 // ----------------------------------------------------------------------------
       
  1103 //  Handle error in RunL
       
  1104 // ----------------------------------------------------------------------------
       
  1105 //
       
  1106 void CMPXCollectionUtility::HandleRunErrorL(TInt aError)
       
  1107     {
       
  1108     TInt task = iTaskQueue->Task();
       
  1109     if (!iCallbackOngoing)
       
  1110         { // Error happens during preparing callback
       
  1111         iCallbackOngoing = ETrue; // will be reset to EFalse in the RunError
       
  1112         switch(task)
       
  1113             {
       
  1114             case EMcsOpen:
       
  1115             case EMcsBack:
       
  1116             case EMcsOpenIndex:
       
  1117             case EMcsOpenPath:
       
  1118             case EMcsOpenByUids:
       
  1119                 {
       
  1120                 if (iObserver)
       
  1121                     {
       
  1122                     iObserver->HandleOpenL(*iMediaOnError, KErrNotFound, 
       
  1123                                            ETrue, aError);
       
  1124                     }
       
  1125                 break;
       
  1126                 }
       
  1127              case EMcsMediaByPath:
       
  1128                 {
       
  1129                 if (iObserver)
       
  1130                     {
       
  1131                     iObserver->HandleCollectionMediaL(*iMediaOnError, aError);
       
  1132                     }
       
  1133                 break;
       
  1134                 }
       
  1135             case EMcsRemovePath:
       
  1136                 {
       
  1137                 MMPXCollectionRemoveObserver* obs = 
       
  1138                          (MMPXCollectionRemoveObserver*) iTaskQueue->Callback();
       
  1139                 if( obs)
       
  1140                     {
       
  1141                     CDesCArray* ary(NULL);
       
  1142                     obs->HandleRemoveL(*ary, aError); // change HandleRemoveL return pointer
       
  1143                     } // else error message will be sent later
       
  1144                 break;
       
  1145                 }
       
  1146             case EMcsFindAll:
       
  1147                 {
       
  1148                 MMPXCollectionFindObserver* obs = 
       
  1149                             (MMPXCollectionFindObserver*) iTaskQueue->Callback();
       
  1150                 if (obs)
       
  1151                     {
       
  1152                     obs->HandleFindAllL( *iMediaOnError, ETrue, aError);
       
  1153                     }
       
  1154                 break;
       
  1155                 }
       
  1156             case EMcsCommandExt:
       
  1157                 {
       
  1158                 if (iObserver)
       
  1159                     {
       
  1160                     iObserver->HandleCommandComplete(iMediaOnError, aError);
       
  1161                     }
       
  1162                 break;
       
  1163                 }
       
  1164             default:
       
  1165                 ASSERT(0);
       
  1166             }
       
  1167         } // do nothing if error happens during client processing callback.
       
  1168           // all callback should be changed into non-leave so that this will
       
  1169           // be never happen.
       
  1170     }
       
  1171 
       
  1172 #ifdef _ENABLE_GUARD_TIMER
       
  1173 // ----------------------------------------------------------------------------
       
  1174 // Guard timer time out
       
  1175 // ----------------------------------------------------------------------------
       
  1176 // 
       
  1177 TInt CMPXCollectionUtility::GuardTimerCallback(TAny* aPtr)
       
  1178     {
       
  1179     CMPXCollectionUtility* cu = static_cast<CMPXCollectionUtility*>(aPtr);
       
  1180     MPX_DEBUG3("CMPXCollectionUtility::GaurdTimerCallback this 0x%08x task=%d", 
       
  1181                cu, cu->iTaskQueue->Task());
       
  1182     cu->iGuardTimer->Cancel();
       
  1183     ASSERT(0); // the function should never be called
       
  1184     return KErrNone;
       
  1185     }
       
  1186 #endif
       
  1187 // End of file