mpx/playbackframework/playbackserver/src/mpxplaybackserversession.cpp
changeset 0 a2952bb97e68
child 8 bee149131e4b
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:  Playback server session
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <e32svr.h>
       
    20 #include <CustomCommandUtility.h>
       
    21 #include <mpxcommandgeneraldefs.h>
       
    22 #include <mpxplaybackcommanddefs.h>
       
    23 #include <mpxmedia.h>
       
    24 #include <mpxclientlist.h>
       
    25 #include <mpxcmn.h>
       
    26 #include <mpxcollectionplaylist.h>
       
    27 #include <mpxlog.h>
       
    28 #include <mpxmessagequeue.h>
       
    29 #include "mpxplaybackserver.h"
       
    30 #include "mpxplaybackengine.h"
       
    31 #include "mpxplaybackserversession.h"
       
    32 
       
    33 // ============================ LOCAL FUNCTIONS ==============================
       
    34 
       
    35 // ----------------------------------------------------------------------------
       
    36 // Panic client
       
    37 // ----------------------------------------------------------------------------
       
    38 //
       
    39 LOCAL_C void PanicClient(const RMessage2 &aMessage,TInt aPanic)
       
    40     {
       
    41     _LIT(KTxtServer,"Playback server Session");
       
    42     aMessage.Panic(KTxtServer,aPanic);
       
    43     }
       
    44 
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ==============================
       
    47 // ----------------------------------------------------------------------------
       
    48 // Two-phased constructor.
       
    49 // ----------------------------------------------------------------------------
       
    50 //
       
    51 CMPXPlaybackSession* CMPXPlaybackSession::NewL()
       
    52     {
       
    53     CMPXPlaybackSession* s = new(ELeave)CMPXPlaybackSession();
       
    54     CleanupStack::PushL(s);
       
    55     s->ConstructL();
       
    56     CleanupStack::Pop(s);
       
    57     return s;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // C++ constructor can NOT contain any code that might leave.
       
    62 // ----------------------------------------------------------------------------
       
    63 //
       
    64 CMPXPlaybackSession::CMPXPlaybackSession()
       
    65     {
       
    66     }
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // Symbian 2nd phase constructor can leave.
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 void CMPXPlaybackSession::ConstructL()
       
    73     {
       
    74     MPX_DEBUG2("CMPXPlaybackSession::ConstructL(), this 0x%08x", this);
       
    75     }
       
    76 
       
    77 // ----------------------------------------------------------------------------
       
    78 // Destructor
       
    79 // ----------------------------------------------------------------------------
       
    80 //
       
    81 CMPXPlaybackSession::~CMPXPlaybackSession()
       
    82     {
       
    83     CancelRequests();
       
    84     CMPXPlaybackServer* server = static_cast<CMPXPlaybackServer*>(
       
    85             const_cast<CServer2*>(Server()));
       
    86     if ( iMessageQueue )
       
    87         {
       
    88         server->RemoveClient( *iMessageQueue );
       
    89         }
       
    90     delete iSyncBuffer;
       
    91     delete iAsyncBuffer;
       
    92     delete iMedia;
       
    93     delete iMessageQueue;
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // Service request
       
    98 // ----------------------------------------------------------------------------
       
    99 //
       
   100 void CMPXPlaybackSession::ServiceL(const RMessage2& aMessage)
       
   101     {
       
   102     // by default - change for async in helper methods if required
       
   103     iCompleteRequest=ETrue;
       
   104     TInt r=KErrNone;
       
   105     TRAPD( err, DispatchMessageL( aMessage, r ) );
       
   106     TBool isErr=(err!=KErrNone);
       
   107     // If it's not async, complete now (or an async helper method leaves)
       
   108     if(iCompleteRequest)
       
   109         {
       
   110         if (!aMessage.IsNull())
       
   111             {
       
   112             aMessage.Complete(isErr ? err : r);
       
   113             } // otherwise message already completed DispatchMessageL
       
   114         }
       
   115     else  if (isErr) // Async and error,  remove message from message queue
       
   116         {
       
   117         CompleteAsync(err);
       
   118         }
       
   119     }
       
   120 
       
   121 // ----------------------------------------------------------------------------
       
   122 // Message dispatcher
       
   123 // ----------------------------------------------------------------------------
       
   124 //
       
   125 void CMPXPlaybackSession::DispatchMessageL( const RMessage2& aMessage, TInt& aMsgHandleResult )
       
   126     {
       
   127     aMsgHandleResult = KErrNone;
       
   128     //
       
   129     // All methods apart from the player creation methods, require a player
       
   130     //
       
   131     TInt op=aMessage.Function();
       
   132     if (op != EPbsSetMode)
       
   133         {
       
   134         CheckPlayerL();
       
   135         }
       
   136     MPX_DEBUG3("-->CMPXPlaybackSession::DispatchMessageL %d, this 0x%08x",
       
   137             op, this);
       
   138     switch(op)
       
   139         {
       
   140         case EPbsSetMode:
       
   141             {
       
   142             SetModeL(aMessage);
       
   143             break;
       
   144             }
       
   145         case EPbsGetClients:
       
   146             {
       
   147             RArray<TProcessId> procArray;
       
   148             ::CopyArrayL<TProcessId>(
       
   149                 iPlayer->ClientList()->ClientProcessList(),
       
   150                 procArray );
       
   151             TProcessId lastPid = static_cast<CMPXPlaybackServer*>(
       
   152                          const_cast<CServer2*>(Server()))->LastActiveProcessId();
       
   153 
       
   154             TInt index( procArray.Find( lastPid ));
       
   155             if ( KErrNotFound != index && index )
       
   156                 {
       
   157                 procArray.Remove( index );
       
   158                 procArray.Insert( lastPid, 0 );
       
   159                 }
       
   160             ::CreateBufferL<TProcessId>(
       
   161                             procArray.Array(),
       
   162                             iSyncBuffer);
       
   163             aMsgHandleResult = iSyncBuffer->Size();
       
   164             procArray.Close();
       
   165             break;
       
   166             }
       
   167         case EPbsGetSyncBuffer:
       
   168             {
       
   169             aMessage.WriteL(0,iSyncBuffer->Ptr(0));
       
   170             delete iSyncBuffer;
       
   171             iSyncBuffer = NULL;
       
   172             break;
       
   173             }
       
   174         case EPbsGetAsyncBuffer:
       
   175             {
       
   176             aMessage.WriteL(0,iAsyncBuffer->Ptr(0));
       
   177             delete iAsyncBuffer;
       
   178             iAsyncBuffer = NULL;
       
   179             break;
       
   180             }
       
   181         case EPbsInitFromCollection:
       
   182             {
       
   183             MPXUser::CreateBufferL(aMessage, 0, iSyncBuffer);
       
   184             CMPXCollectionPlaylist* p = NULL;
       
   185             ::NewFromBufferL(*iSyncBuffer, p);
       
   186             delete iSyncBuffer;
       
   187             iSyncBuffer = NULL;
       
   188             CleanupStack::PushL(p);
       
   189             iPlayer->InitL(*p,aMessage.Int1());
       
   190             CleanupStack::PopAndDestroy(p);
       
   191             }
       
   192             break;
       
   193         case EPbsInitFromUri:
       
   194             {
       
   195             CBufBase* buf0(NULL);
       
   196             MPXUser::CreateBufferL(aMessage,0,buf0);
       
   197             CleanupStack::PushL(buf0);
       
   198 
       
   199             // Type parameter is optional
       
   200             if ( aMessage.GetDesLength( 1 ) > 0 )
       
   201                 {
       
   202                 CBufBase* buf1(NULL);
       
   203                 MPXUser::CreateBufferL(aMessage,1,buf1);
       
   204                 CleanupStack::PushL(buf1);
       
   205                 iPlayer->InitL(MPXUser::Ptr(buf0->Ptr(0)), buf1->Ptr(0));
       
   206                 CleanupStack::PopAndDestroy(buf1);
       
   207                 }
       
   208             else
       
   209                 {
       
   210                 MPX_DEBUG2("CMPXPlaybackSession::DispatchMessageL %d: Type is empty", op);
       
   211                 iPlayer->InitL( MPXUser::Ptr( buf0->Ptr(0) ), KNullDesC8 );
       
   212                 }
       
   213             CleanupStack::PopAndDestroy(buf0);
       
   214             }
       
   215             break;
       
   216         case EPbsInitFromFile:
       
   217             {
       
   218             InitFromFileL(aMessage);
       
   219             break;
       
   220             }
       
   221         case EPbsInitStreamingFromUri:
       
   222             {            
       
   223             CBufBase* buf0(NULL);
       
   224             MPXUser::CreateBufferL(aMessage,0,buf0);
       
   225             CleanupStack::PushL(buf0);
       
   226 
       
   227             // Type parameter is optional
       
   228             if ( aMessage.GetDesLength( 1 ) > 0 )
       
   229                 {
       
   230                 CBufBase* buf1(NULL);
       
   231                 MPXUser::CreateBufferL(aMessage,1,buf1);
       
   232                 CleanupStack::PushL(buf1);
       
   233                 iPlayer->InitStreamingL(MPXUser::Ptr(buf0->Ptr(0)), buf1->Ptr(0), aMessage.Int2());
       
   234                 CleanupStack::PopAndDestroy(buf1);
       
   235                 }
       
   236             else
       
   237                 {
       
   238                 MPX_DEBUG2("CMPXPlaybackSession::DispatchMessageL %d: Type is empty", op);
       
   239                 iPlayer->InitStreamingL( MPXUser::Ptr( buf0->Ptr(0) ), KNullDesC8, aMessage.Int2() );
       
   240                 }
       
   241             CleanupStack::PopAndDestroy(buf0);
       
   242             break;                          
       
   243             }
       
   244          case EPbsInitStreamingFromFile:
       
   245             {
       
   246             RFile file;
       
   247             User::LeaveIfError(file.AdoptFromClient(aMessage,0,1));
       
   248             iPlayer->InitStreamingL(file, aMessage.Int2());
       
   249             file.Close();
       
   250             break;
       
   251             }            
       
   252         case EPbsCancelRequest:
       
   253             {
       
   254             CancelRequests();
       
   255             break;
       
   256             }
       
   257         case EPbsGetState:
       
   258             {
       
   259             aMsgHandleResult = iPlayer->State();
       
   260             break;
       
   261             }
       
   262         case EPbsSetProperty:
       
   263             {
       
   264             iPlayer->SetL(static_cast<TMPXPlaybackProperty>(aMessage.Int0()),
       
   265                           aMessage.Int1());
       
   266             break;
       
   267             }
       
   268         case EPbsGetProperty:
       
   269             {
       
   270             SetAsync(aMessage);
       
   271             iPlayer->PropertyL(
       
   272                     static_cast<TMPXPlaybackProperty>(aMessage.Int0()),*this);
       
   273             break;
       
   274             }
       
   275         case EPbsGetPlayerTypes:
       
   276             {
       
   277             RArray<TMPXPlaybackPlayerType> pluginTypes;
       
   278             CleanupClosePushL(pluginTypes);
       
   279             RArray<TInt> types;
       
   280             CleanupClosePushL(types);
       
   281             iPlayer->PluginHandler()->GetPluginTypes(types);
       
   282             for (TInt i=0; i< types.Count(); ++i)
       
   283                 {
       
   284                 pluginTypes.AppendL(
       
   285                         static_cast<TMPXPlaybackPlayerType>(types[i]));
       
   286                 }
       
   287             CleanupStack::PopAndDestroy(&types);
       
   288             ::CreateBufferL<TMPXPlaybackPlayerType>(
       
   289                                     pluginTypes.Array(),
       
   290                                     iSyncBuffer);
       
   291             aMsgHandleResult = iSyncBuffer->Size();
       
   292             CleanupStack::PopAndDestroy(&pluginTypes);
       
   293             break;
       
   294             }
       
   295         case EPbsGetPlayerTypeDisplayName:
       
   296             {
       
   297             const TDesC& playerName = iPlayer->PluginHandler()->PlayerName(
       
   298                         static_cast<TMPXPlaybackPlayerType>(aMessage.Int0()));
       
   299             aMsgHandleResult = 0;
       
   300             if (playerName.Length()>0)
       
   301                 {
       
   302                 MPXUser::CreateBufferL(playerName, iSyncBuffer);
       
   303                 aMsgHandleResult = iSyncBuffer->Size();
       
   304                 }
       
   305             break;
       
   306             }
       
   307         case EPbsGetAllPlayersUids:
       
   308             {
       
   309             RArray<TUid> uids;
       
   310             CleanupClosePushL(uids);
       
   311             iPlayer->PluginHandler()->GetPluginUids(uids);
       
   312 
       
   313             ::CreateBufferL<TUid>(
       
   314                     uids.Array(),
       
   315                     iSyncBuffer);
       
   316             aMsgHandleResult = iSyncBuffer->Size();
       
   317             CleanupStack::PopAndDestroy(&uids);
       
   318             break;
       
   319             }
       
   320         case EPbsGetPlayersUidsForType:
       
   321             {
       
   322             aMsgHandleResult = CreatePlayerUidsBufferL(aMessage);
       
   323             break;
       
   324             }
       
   325         case EPbsGetSubPlayerNamesByUid:
       
   326             {
       
   327             SetAsync(aMessage);
       
   328             iPlayer->SubPlayerNamesL(TUid::Uid(aMessage.Int0()),*this);
       
   329             break;
       
   330             }
       
   331         case EPbsSelectPlayerByType:
       
   332             {
       
   333             iPlayer->PluginHandler()->SelectPlayersL(
       
   334                          static_cast<TMPXPlaybackPlayerType>(aMessage.Int0()));
       
   335             break;
       
   336             }
       
   337         case EPbsSelectPlayerByUid:
       
   338             {
       
   339             iPlayer->PluginHandler()->SelectPlayerL(TUid::Uid(aMessage.Int0()));
       
   340             break;
       
   341             }
       
   342         case EPbsSelectSubPlayer:
       
   343             {
       
   344             iPlayer->PluginHandler()->SelectSubPlayerL(
       
   345                                   TUid::Uid(aMessage.Int0()),aMessage.Int1());
       
   346             break;
       
   347             }
       
   348         case EPbsClearPlayerSelection:
       
   349             {
       
   350             iPlayer->PluginHandler()->ClearSelectPlayersL();
       
   351             break;
       
   352             }
       
   353         case EPbsGetSelection:
       
   354             {
       
   355             GetSelectionL(aMessage);
       
   356             break;
       
   357             }
       
   358         case EPbsPlayerFound:
       
   359             {
       
   360             aMsgHandleResult = iPlayer->PluginHandler()->PlayerFound();
       
   361             break;
       
   362             }
       
   363         case EPbsGetPlayerType:
       
   364             {
       
   365             aMsgHandleResult = iPlayer->PluginHandler()->PluginType();
       
   366             break;
       
   367             }
       
   368         case EPbsGetTypeName:
       
   369             {
       
   370             MPXUser::CreateBufferL(iPlayer->PluginHandler()->PlayerName(),
       
   371                                    iSyncBuffer);
       
   372             aMsgHandleResult = iSyncBuffer->Size();
       
   373             break;
       
   374             }
       
   375         case EPbsGetSubPlayerIndex:
       
   376             {
       
   377             aMsgHandleResult = iPlayer->PluginHandler()->SubPlayer();
       
   378             break;
       
   379             }
       
   380         case EPbsGetPlayerUid:
       
   381             {
       
   382             TPckgC<TInt> uidPkg((iPlayer->PluginHandler()->PluginUid()).iUid);
       
   383             aMessage.Write(0,uidPkg);
       
   384             break;
       
   385             }
       
   386         case EPbsGetCollectionPlaylist:
       
   387             {
       
   388             aMsgHandleResult = 0;
       
   389             if (iPlayer->Playlist())
       
   390                 {
       
   391                 ::CreateBufferL<CMPXCollectionPlaylist>(*(iPlayer->Playlist()),
       
   392                                                         iSyncBuffer);
       
   393                 aMsgHandleResult = iSyncBuffer->Size();
       
   394                 }
       
   395             break;
       
   396             }
       
   397         case EPbsGetFile:
       
   398             {
       
   399             const RFile& file = iPlayer->File();
       
   400             if (file.SubSessionHandle())
       
   401                 {
       
   402                 aMsgHandleResult = file.TransferToClient(aMessage,0); //message completed
       
   403                 }
       
   404             else
       
   405                 {
       
   406                 TPckgC<TInt> handle(KErrNotFound);
       
   407                 aMessage.Write(0, handle);
       
   408                 }
       
   409             break;
       
   410             }
       
   411         case EPbsGetUri:
       
   412             {
       
   413             aMsgHandleResult=0;
       
   414             if (iPlayer->Uri().Length()>0)
       
   415                 {
       
   416                 MPXUser::CreateBufferL(iPlayer->Uri(),iSyncBuffer);
       
   417                 aMsgHandleResult = iSyncBuffer->Size();
       
   418                 }
       
   419             break;
       
   420             }
       
   421         case EPbsGetMedia:
       
   422             {
       
   423             SetAsync( aMessage );
       
   424             CMPXCommand* cmd( CMPXCommand::NewL( aMessage.Int1() ) );
       
   425             CleanupStack::PushL( cmd );
       
   426             iPlayer->MediaL( *this, *cmd );
       
   427             CleanupStack::PopAndDestroy( cmd );
       
   428             break;
       
   429             }
       
   430         case EPbsGetSupportedMimeTypes:
       
   431             {
       
   432             CDesCArray* mimeTypes =
       
   433                iPlayer->PluginHandler()->SupportedMimeTypesL();
       
   434             CleanupStack::PushL(mimeTypes);
       
   435             MPXUser::CreateBufferL((const MDesCArray*)mimeTypes, iSyncBuffer);
       
   436             aMsgHandleResult = iSyncBuffer->Size();
       
   437             CleanupStack::PopAndDestroy(mimeTypes);
       
   438             }
       
   439             break;
       
   440         case EPbsGetSupportedExtensions:
       
   441             {
       
   442             CDesCArray* exts =
       
   443               iPlayer->PluginHandler()->SupportedExtensionsL();
       
   444             CleanupStack::PushL(exts);
       
   445             MPXUser::CreateBufferL((const MDesCArray*)exts, iSyncBuffer);
       
   446             aMsgHandleResult = iSyncBuffer->Size();
       
   447             CleanupStack::PopAndDestroy(exts);
       
   448             }
       
   449             break;
       
   450         case EPbsGetSupportedSchemas:
       
   451             {
       
   452             CDesCArray* schemas =
       
   453                  iPlayer->PluginHandler()->SupportedSchemasL();
       
   454             CleanupStack::PushL(schemas);
       
   455             MPXUser::CreateBufferL((const MDesCArray*)schemas, iSyncBuffer);
       
   456             aMsgHandleResult = iSyncBuffer->Size();
       
   457             CleanupStack::PopAndDestroy(schemas);
       
   458             }
       
   459             break;
       
   460         case EPbsGetNextMessage:
       
   461             {
       
   462             ASSERT(iMessageQueue);
       
   463             iMessageQueue->SendNext(aMessage);
       
   464             iCompleteRequest=EFalse;
       
   465             break;
       
   466             }
       
   467         case EPbsCancelGetMessage:
       
   468             {
       
   469             ASSERT(iMessageQueue);
       
   470             iMessageQueue->Reset();
       
   471             break;
       
   472             }
       
   473         case EPbsCommand:
       
   474             {
       
   475             CMPXCommand* cmd( NULL );
       
   476             ::NewFromMessageL<CMPXMedia>(aMessage, 1, cmd);
       
   477             CleanupStack::PushL(cmd);
       
   478             if (aMessage.Int0())
       
   479                 { // aSync command
       
   480                 SetAsync(aMessage);
       
   481                 } // else sync command
       
   482             iPlayer->CommandL(*cmd, *iMessageQueue);
       
   483             CleanupStack::PopAndDestroy(cmd);
       
   484             break;
       
   485             }
       
   486 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   487         case EPbsInitFromFile64:
       
   488             {
       
   489             RFile64 file;
       
   490             User::LeaveIfError(file.AdoptFromClient(aMessage,0,1));
       
   491             iPlayer->Init64L(file);
       
   492             file.Close();
       
   493             break;
       
   494             }
       
   495         case EPbsInitStreamingFromFile64:
       
   496             {
       
   497             RFile64 file;
       
   498             User::LeaveIfError(file.AdoptFromClient(aMessage,0,1));
       
   499             iPlayer->InitStreaming64L(file, aMessage.Int2());           
       
   500             file.Close();
       
   501             break;
       
   502             }
       
   503         case EPbsGetFile64:
       
   504             {
       
   505             const RFile64& file = iPlayer->File64();
       
   506             if (file.SubSessionHandle())
       
   507                 {
       
   508                 aMsgHandleResult = file.TransferToClient(aMessage,0); //message completed
       
   509                 }
       
   510             else
       
   511                 {
       
   512                 TPckgC<TInt> handle(KErrNotFound);
       
   513                 aMessage.Write(0, handle);
       
   514                 }
       
   515             break;
       
   516             }
       
   517 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   518         default:
       
   519             {
       
   520             PanicClient(aMessage,KErrNotSupported);
       
   521             break;
       
   522             }
       
   523         }
       
   524     MPX_DEBUG1("<---CMPXPlaybackSession::DispatchMessageL");
       
   525     }
       
   526 
       
   527 // ----------------------------------------------------------------------------
       
   528 // Get current selection
       
   529 // ----------------------------------------------------------------------------
       
   530 //
       
   531 void CMPXPlaybackSession::GetSelectionL(const RMessage2& aMessage)
       
   532     {
       
   533     TMPXPlaybackPlayerType type;
       
   534     TUid uid;
       
   535     TInt index;
       
   536     const TInt KMsgSlotZero = 0;
       
   537     const TInt KMsgSlotOne = 1;
       
   538     const TInt KMsgSlotTwo = 2;
       
   539     const TInt KMsgSlotThree = 3;
       
   540     TPtrC subPlayerName(KNullDesC);
       
   541     iPlayer->PluginHandler()->GetSelection(type,uid,index, subPlayerName);
       
   542     TInt size(0);
       
   543     if (subPlayerName != KNullDesC)
       
   544         {
       
   545         MPXUser::CreateBufferL(subPlayerName, iSyncBuffer);
       
   546         size = iSyncBuffer->Size();
       
   547         }
       
   548     ::WriteL<TMPXPlaybackPlayerType>( aMessage, KMsgSlotZero, type );
       
   549     ::WriteL<TUid>( aMessage, KMsgSlotOne, uid );
       
   550     ::WriteL<TInt>( aMessage, KMsgSlotTwo, index );
       
   551     ::WriteL<TInt>( aMessage, KMsgSlotThree, size );
       
   552     }
       
   553 
       
   554 // ----------------------------------------------------------------------------
       
   555 // Queue the message and complete async
       
   556 // ----------------------------------------------------------------------------
       
   557 //
       
   558 void CMPXPlaybackSession::SetAsync(const RMessage2& aMessage)
       
   559     {
       
   560     MPX_FUNC_EX("CMPXPlaybackSession::SetAsync");
       
   561     MPX_ASSERT(iMessage.IsNull() && !aMessage.IsNull());
       
   562     iMessage = aMessage;
       
   563     iCompleteRequest=EFalse;
       
   564     }
       
   565 
       
   566 // ----------------------------------------------------------------------------
       
   567 // Complete queued message
       
   568 // ----------------------------------------------------------------------------
       
   569 //
       
   570 void CMPXPlaybackSession::CompleteAsync(
       
   571     TInt aErr,
       
   572     TInt aSlot1, const TDesC8* aVal1,
       
   573     TInt aSlot2, const TDesC8* aVal2)
       
   574     {
       
   575     MPX_ASSERT(!iMessage.IsNull());
       
   576     TInt err(KErrNone);
       
   577     if (KErrNone==aErr)
       
   578         {
       
   579         err = DoWriteData(aSlot1, aVal1, aSlot2, aVal2);
       
   580         if (err)
       
   581             { // Set to new error
       
   582             aErr = err;
       
   583             }
       
   584         }
       
   585     MPX_DEBUG4("CMPXPlaybackSession::CompleteAsync 0x%08x task %d err %d",
       
   586             this, iMessage.Function(), aErr);
       
   587     iMessage.Complete(aErr);
       
   588     }
       
   589 
       
   590 // ----------------------------------------------------------------------------
       
   591 // Write data back to client
       
   592 // ----------------------------------------------------------------------------
       
   593 //
       
   594 TInt CMPXPlaybackSession::DoWriteData(
       
   595     TInt aSlot1, const TDesC8* aVal1,
       
   596     TInt aSlot2, const TDesC8* aVal2)
       
   597     {
       
   598     TInt ret(KErrNone);
       
   599     if (aVal1)
       
   600         {
       
   601         ret = iMessage.Write(aSlot1,*aVal1);
       
   602         }
       
   603 
       
   604     if (aVal2 && KErrNone==ret)
       
   605         {
       
   606         ret = iMessage.Write(aSlot2,*aVal2);
       
   607         }
       
   608     return ret;
       
   609     }
       
   610 
       
   611 // ----------------------------------------------------------------------------
       
   612 // Init player from file
       
   613 // ----------------------------------------------------------------------------
       
   614 //
       
   615 void CMPXPlaybackSession::InitFromFileL(const RMessage2& aMessage)
       
   616     {
       
   617     RFile file;
       
   618     User::LeaveIfError(file.AdoptFromClient(aMessage,0,1));
       
   619     iPlayer->InitL(file);
       
   620     file.Close();
       
   621     }
       
   622 
       
   623 // ----------------------------------------------------------------------------
       
   624 // Cancel all outstanding requests on this session
       
   625 // ----------------------------------------------------------------------------
       
   626 //
       
   627 void CMPXPlaybackSession::CancelRequests()
       
   628     {
       
   629     MPX_FUNC_EX("CMPXPlaybackSession::CancelRequests");
       
   630     if (!iMessage.IsNull())
       
   631         {
       
   632         iMessage.Complete(KErrCancel);
       
   633         iPlayer->CancelRequests();
       
   634         }
       
   635     }
       
   636 
       
   637 // ----------------------------------------------------------------------------
       
   638 // The thread ID of the client thread
       
   639 // ----------------------------------------------------------------------------
       
   640 //
       
   641 TThreadId CMPXPlaybackSession::ClientIdL(const RMessage2& aMessage)
       
   642     {
       
   643     RThread t;
       
   644     aMessage.ClientL(t);
       
   645     TThreadId tid=t.Id();
       
   646     t.Close();
       
   647     return tid;
       
   648     }
       
   649 
       
   650 // ----------------------------------------------------------------------------
       
   651 // Set playback mode
       
   652 // ----------------------------------------------------------------------------
       
   653 //
       
   654 void CMPXPlaybackSession::SetModeL(const RMessage2& aMessage)
       
   655     {
       
   656     MPX_DEBUG3("-->CMPXPlaybackSession::SetModeL 0x%08x, mode 0x%08x", this, aMessage.Int0());
       
   657     if (iPlayer)
       
   658         {
       
   659         MPX_DEBUG1("CMPXPlaybackSession::SetModeL detach from old player");
       
   660         // swap engine
       
   661         static_cast<CMPXPlaybackServer*>(
       
   662                 const_cast<CServer2*>(Server()))->AddClient();
       
   663         static_cast<CMPXPlaybackServer*>(
       
   664                 const_cast<CServer2*>(Server()))->RemoveClient(*iMessageQueue);
       
   665         iPlayer = NULL;
       
   666         ASSERT(iMessageQueue);
       
   667         iMessageQueue->Reset();
       
   668         }
       
   669     if (!iMessageQueue)
       
   670         {
       
   671         iMessageQueue = CMPXMessageQueue::NewL();
       
   672         }
       
   673     iPlayer=static_cast<CMPXPlaybackServer*>(
       
   674             const_cast<CServer2*>(Server()))->CreatePlayerL(
       
   675                                                 TUid::Uid(aMessage.Int0()),
       
   676                                                 aMessage.Int1(), 
       
   677                                                 ClientIdL(aMessage),
       
   678                                                 iMessageQueue);
       
   679     MPX_DEBUG3("<--CMPXPlaybackSession::SetModeL 0x%08x, engine 0x%08x", this, iPlayer);
       
   680     }
       
   681 
       
   682 // ----------------------------------------------------------------------------
       
   683 // An array must be supplied to receive UIDs, so a temporary one is created
       
   684 // here before being copied into the buffer
       
   685 // ----------------------------------------------------------------------------
       
   686 //
       
   687 TInt CMPXPlaybackSession::CreatePlayerUidsBufferL(const RMessage2& aMessage)
       
   688     {
       
   689     RArray<TUid> players;
       
   690     CleanupClosePushL(players);
       
   691     iPlayer->PluginHandler()->GetPlayerListL(players,
       
   692                         static_cast<TMPXPlaybackPlayerType>(aMessage.Int0()));
       
   693     ::CreateBufferL<TUid>(players.Array(), iSyncBuffer);
       
   694     TInt r = iSyncBuffer->Size();
       
   695     CleanupStack::PopAndDestroy(&players);
       
   696     return r;
       
   697     }
       
   698 
       
   699 // ----------------------------------------------------------------------------
       
   700 // Handle playback property
       
   701 // ----------------------------------------------------------------------------
       
   702 //
       
   703 void CMPXPlaybackSession::HandleProperty(
       
   704     TMPXPlaybackProperty /*aProperty*/,
       
   705     TInt aValue,
       
   706     TInt aError)
       
   707     {
       
   708     MPX_FUNC_EX("CMPXPlaybackSession::HandleProperty");
       
   709     MPX_DEBUG3("CMPXPlaybackSession::HandleProperty(): aValue = %d, aError = %d", aValue, aError);
       
   710     MPX_ASSERT(!iMessage.IsNull() && iMessage.Function() == EPbsGetProperty);
       
   711     TPckgC<TInt> val(aValue);
       
   712     CompleteAsync(aError,1,&val);
       
   713     }
       
   714 
       
   715 // ----------------------------------------------------------------------------
       
   716 // Method is called continously until aComplete=ETrue, signifying that it is
       
   717 // done and there will be no more callbacks.Only new items are passed each time
       
   718 // ----------------------------------------------------------------------------
       
   719 //
       
   720 void CMPXPlaybackSession::HandleSubPlayerNames(
       
   721     TUid /*aPlayer*/,
       
   722     const MDesCArray* aSubPlayers,
       
   723     TBool aComplete,
       
   724     TInt aError)
       
   725     {
       
   726     MPX_FUNC_EX("CMPXPlaybackSession::HandleSubPlayerNames");
       
   727     MPX_ASSERT(!iMessage.IsNull() && iMessage.Function() == EPbsGetSubPlayerNamesByUid);
       
   728     TRAPD(err,MPXUser::CreateBufferL(aSubPlayers, iAsyncBuffer));
       
   729     TInt size(0);
       
   730     if(aSubPlayers && !err)
       
   731         {
       
   732         size = iAsyncBuffer->Size();
       
   733         }
       
   734     else if (err)
       
   735         { // err to create buffer
       
   736         aError = err;
       
   737         }
       
   738     else
       
   739         { // aSubPlayers is NULL
       
   740         aError = KErrNotFound;
       
   741         }
       
   742     TPckgC<TBool> complete(aComplete);
       
   743     TPckgC<TInt> sizePkg(size);
       
   744     CompleteAsync(aError,1,&sizePkg,2,&complete);
       
   745     }
       
   746 
       
   747 // ----------------------------------------------------------------------------
       
   748 // Handle media properties
       
   749 // ----------------------------------------------------------------------------
       
   750 //
       
   751 void CMPXPlaybackSession::HandleMedia(CMPXMedia* aMedia, TInt aError)
       
   752     {
       
   753     MPX_FUNC_EX("CMPXPlaybackSession::HandleMedia");
       
   754     MPX_ASSERT(!iMessage.IsNull() && iMessage.Function() == EPbsGetMedia);
       
   755     TInt size(0);
       
   756     if (KErrNone == aError && aMedia)
       
   757         {
       
   758         delete iMedia;
       
   759         iMedia=NULL;
       
   760         TInt err(KErrNone);
       
   761         TRAP(err, iMedia=CMPXMedia::NewL(*aMedia));
       
   762         if (!err)
       
   763             {
       
   764             TRAP(err, ::CreateBufferL<CMPXMedia>(*iMedia,iAsyncBuffer));
       
   765             }
       
   766         if (!err)
       
   767             {
       
   768             size = iAsyncBuffer->Size();
       
   769             }
       
   770         } // else complete with error
       
   771     TPckgC<TInt> sizePkg(size);
       
   772     CompleteAsync(aError,0,&sizePkg);
       
   773     }
       
   774 
       
   775 // ----------------------------------------------------------------------------
       
   776 // Callback of async CommandL
       
   777 // ----------------------------------------------------------------------------
       
   778 //
       
   779  void CMPXPlaybackSession::HandlePlaybackCommandComplete(
       
   780     CMPXCommand* aCommandResult,
       
   781     TInt aError)
       
   782      {
       
   783      MPX_ASSERT(!iMessage.IsNull() && iMessage.Function() == EPbsCommandExt);
       
   784      TInt size(0);
       
   785      if( aError == KErrNone && aCommandResult)
       
   786          {
       
   787          delete iMedia;
       
   788          iMedia=NULL;
       
   789          TRAP( aError, iMedia = CMPXMedia::NewL( *aCommandResult ) );
       
   790          if ( KErrNone == aError )
       
   791              TRAP( aError, ::CreateBufferL<CMPXMedia>( *iMedia, iAsyncBuffer ) );
       
   792          if ( KErrNone == aError )
       
   793              {
       
   794              size = iAsyncBuffer->Size();
       
   795              }
       
   796          }
       
   797      TPckgC<TInt> sizePkg(size);
       
   798      CompleteAsync(aError, 2, &sizePkg);
       
   799      }
       
   800 
       
   801 // ----------------------------------------------------------------------------
       
   802 // Check if player is valid
       
   803 // ----------------------------------------------------------------------------
       
   804 //
       
   805 void CMPXPlaybackSession::CheckPlayerL()
       
   806     {
       
   807     if (!iPlayer)
       
   808         {
       
   809         User::Leave(KErrNotReady);
       
   810         }
       
   811     }
       
   812 
       
   813 // End of file