mpx/playbackframework/playbackserver/src/mpxplaybackserver.cpp
branchRCL_3
changeset 15 d240f0a77280
parent 0 a2952bb97e68
child 23 4740b34b83ce
equal deleted inserted replaced
14:05b0d2323768 15:d240f0a77280
   127     iClientMapper = CTspClientMapper::NewL();
   127     iClientMapper = CTspClientMapper::NewL();
   128 #endif
   128 #endif
   129     }
   129     }
   130 
   130 
   131 // ----------------------------------------------------------------------------
   131 // ----------------------------------------------------------------------------
       
   132 // Searches process id for target selector plugin.
       
   133 // When the player has been opened in a mode, which is bound to the same engine
       
   134 // than certain application's engine, then need to fetch its process id.
       
   135 // (As a reference for parameter aMode see MMPXPlaybackUtility modes.)
       
   136 // Otherwise target selector plugin is notified wrongly about client statuses 
       
   137 // and key events are not propagated to correct application.
       
   138 // ----------------------------------------------------------------------------
       
   139 //
       
   140 void CMPXPlaybackServer::FindProcessIdForTsp(
       
   141     const CMPXPlaybackEngine* aEngine,
       
   142     TProcessId& aProcessId )
       
   143     {
       
   144     TBool processFound( EFalse );
       
   145     TFindProcess processFinder;
       
   146     TFullName processName;
       
   147 
       
   148     while ( processFinder.Next( processName ) == KErrNone && !processFound )
       
   149         {
       
   150         RProcess process;
       
   151         TInt err = process.Open( processFinder );
       
   152         if( err == KErrNone )
       
   153             {
       
   154             if( process.SecureId().iId == aEngine->ModeId().iUid && 
       
   155                 process.ExitType() == EExitPending )
       
   156                 {
       
   157                 MPX_DEBUG4("CMPXPlaybackServer::FindProcessIdForTsp(): pid changed from %d to %d (mode 0x%x)",
       
   158                            TUint(aProcessId), TUint(process.Id()), aEngine->ModeId().iUid);
       
   159                 aProcessId = process.Id();
       
   160                 processFound = ETrue;
       
   161                 }
       
   162             process.Close();
       
   163             }
       
   164         }
       
   165     }
       
   166 
       
   167 // ----------------------------------------------------------------------------
   132 // Increments number of sessions this server holds
   168 // Increments number of sessions this server holds
   133 // ----------------------------------------------------------------------------
   169 // ----------------------------------------------------------------------------
   134 //
   170 //
   135 void CMPXPlaybackServer::AddClient()
   171 void CMPXPlaybackServer::AddClient()
   136     {
   172     {
   384     TInt indexOfActive = iPlayers.Find(aEngine);
   420     TInt indexOfActive = iPlayers.Find(aEngine);
   385     ASSERT(KErrNotFound!=indexOfActive);
   421     ASSERT(KErrNotFound!=indexOfActive);
   386     if (!aActive)
   422     if (!aActive)
   387         {
   423         {
   388 #ifdef RD_TSP_CLIENT_MAPPER
   424 #ifdef RD_TSP_CLIENT_MAPPER
       
   425         TProcessId lastPid( aEngine->LastActiveProcessId() ); 
       
   426         FindProcessIdForTsp( aEngine, lastPid );
   389         iClientMapper->SetTspTargetClientToOtherType(
   427         iClientMapper->SetTspTargetClientToOtherType(
   390                 CTspClientMapper::EStoppedClients,
   428                 CTspClientMapper::EStoppedClients,
   391                 aEngine->LastActiveProcessId());
   429                 lastPid);
   392         MPX_DEBUG2("CMPXPlaybackServer::HandleActiveEngineL(): Adding to stopped client %d",
   430         MPX_DEBUG2("CMPXPlaybackServer::HandleActiveEngineL(): Added as stopped client %d",
   393                    TUint( aEngine->LastActiveProcessId()));
   431                    TUint( lastPid));
   394 
       
   395 #endif
   432 #endif
   396         if (EPbStatePaused != aEngine->State())
   433         if (EPbStatePaused != aEngine->State())
   397             {
   434             {
   398             indexOfActive = IndexOfRecentActivePlayer();
   435             indexOfActive = IndexOfRecentActivePlayer();
   399             }
   436             }
   404             }
   441             }
   405         }
   442         }
   406     else
   443     else
   407         {// else aEngine is active player
   444         {// else aEngine is active player
   408 #ifdef RD_TSP_CLIENT_MAPPER
   445 #ifdef RD_TSP_CLIENT_MAPPER
   409         iClientMapper->SetTspTargetClientToOtherType(
   446         TProcessId lastPid( aEngine->LastActiveProcessId() ); 
   410                 CTspClientMapper::EPlayingClients,
   447         FindProcessIdForTsp( aEngine, lastPid );
   411                 aEngine->LastActiveProcessId());
   448         TInt err = iClientMapper->SetTspTargetClientToOtherType( 
   412         MPX_DEBUG2("CMPXPlaybackServer::HandleActiveEngineL(): Adding to playing client %d",
   449             CTspClientMapper::EPlayingClients, lastPid );
   413                    TUint( aEngine->LastActiveProcessId()));
   450         if ( err != KErrNone && (TUint)lastPid != KNullProcessId )
       
   451             {
       
   452             // Setting target type failed probably because client PID could not be found.
       
   453             // As a fallback set client as new playing client.
       
   454             MPX_DEBUG2("CMPXPlaybackServer::HandleActiveEngineL(): Adding to playing client %d", 
       
   455                 (TUint)lastPid );
       
   456             iClientMapper->SetTspTargetClient( CTspClientMapper::EPlayingClients, lastPid );
       
   457             }
       
   458         MPX_DEBUG2("CMPXPlaybackServer::HandleActiveEngineL(): Added as playing client %d", 
       
   459             (TUint)lastPid );
   414 #endif
   460 #endif
   415         }
   461         }
   416 
   462 
   417     if (KErrNotFound != indexOfActive)
   463     if (KErrNotFound != indexOfActive)
   418         {
   464         {
   464     {
   510     {
   465 #ifdef RD_TSP_CLIENT_MAPPER
   511 #ifdef RD_TSP_CLIENT_MAPPER
   466     if (MMPXClientlistObserver::EAdd == aChangeType)
   512     if (MMPXClientlistObserver::EAdd == aChangeType)
   467         {
   513         {
   468         iClientMapper->SetTspTargetClient(
   514         iClientMapper->SetTspTargetClient(
   469                 CTspClientMapper::EPlayingClients,
   515                 CTspClientMapper::ERegisteredClients,
   470                 aPid);
   516                 aPid);
   471         MPX_DEBUG2("CMPXPlaybackServer::HandleClientChange(): Adding to registered client %d",
   517         MPX_DEBUG2("CMPXPlaybackServer::HandleClientChange(): Added as registered client %d",
   472                    TUint( aPid ));
   518                    TUint( aPid ));
   473         }
   519         }
   474     else
   520     else
   475         {
   521         {
   476         iClientMapper->RemoveTspTargetClient(
   522         iClientMapper->RemoveTspTargetClient(
   477                 CTspClientMapper::EPlayingClients,
   523                 CTspClientMapper::EPlayingClients,
   478                 aPid);
   524                 aPid);
   479         MPX_DEBUG2("CMPXPlaybackServer::HandleClientChange(): Adding to EPlayingClients client %d",
   525         MPX_DEBUG2("CMPXPlaybackServer::HandleClientChange(): Removed from EPlayingClients client %d",
   480                    TUint( aPid ));
   526                    TUint( aPid ));
   481         }
   527         }
   482 #else
   528 #else
   483     (void)aPid;
   529     (void)aPid;
   484     (void)aChangeType;
   530     (void)aChangeType;