dvrengine/CommonRecordingEngineClient/src/CCRMsgQueueObserver.cpp
branchRCL_3
changeset 47 826cea16efd9
parent 45 798ee5f1972c
child 48 13a33d82ad98
equal deleted inserted replaced
45:798ee5f1972c 47:826cea16efd9
     1 /*
       
     2 * Copyright (c) 2007 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 the License "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:    Offers interface to RMsgQueue in civilized manner.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CCRMsgQueueObserver.h"
       
    22 #include <ipvideo/MCREngineObserver.h>
       
    23 #include <ipvideo/CRTypeDefs.h>
       
    24 #include "videoserviceutilsLogger.h"
       
    25 
       
    26 // CONSTANTS
       
    27 // None
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CCRMsgQueueObserver::NewL
       
    33 // Two-phased constructor.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CCRMsgQueueObserver* CCRMsgQueueObserver::NewL()
       
    37     {
       
    38     CCRMsgQueueObserver* self = new( ELeave ) CCRMsgQueueObserver();
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop( self );
       
    42     return self;
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CCRMsgQueueObserver::CCRMsgQueueObserver()
       
    47 // C++ default constructor can NOT contain any code, that might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CCRMsgQueueObserver::CCRMsgQueueObserver() : CActive( EPriorityAbsoluteHigh )
       
    51     {
       
    52     // Note! CActive's priority must be absolute high for ensure that 
       
    53     // the messages are arrived in right order to VIA.  
       
    54     CActiveScheduler::Add( this );
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CCRMsgQueueObserver::ConstructL()
       
    59 // Symbian 2nd phase constructor can leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CCRMsgQueueObserver::ConstructL()
       
    63     {
       
    64     LOG( "CCRMsgQueueObserver::ConstructL() in" );
       
    65     
       
    66     RProcess process;
       
    67     TInt handleId( process.Handle() );
       
    68     TBuf<KCRQueueNameLength> queueName;
       
    69     queueName.Format(KCRMsgQueueName, handleId);
       
    70     queueName.Trim();
       
    71     TInt err( iQueue.CreateGlobal( queueName, 
       
    72                                    sizeof( SCRQueueEntry ) ) ); 
       
    73     LOG2( "CCRMsgQueueObserver createglobal %S = %d", &queueName, err );
       
    74     err = iQueue.OpenGlobal( queueName ) ;                            
       
    75     LOG1( "CCRMsgQueueObserver openglobal = %d", err );
       
    76     User::LeaveIfError( err );
       
    77     iQueue.NotifyDataAvailable( iStatus ); 
       
    78     LOG1( "CCRMsgQueueObserver queue message size is %d", iQueue.MessageSize() );
       
    79     SetActive(); 
       
    80 
       
    81     LOG( "CCRMsgQueueObserver::ConstructL() out" );
       
    82     }
       
    83     
       
    84 // -----------------------------------------------------------------------------
       
    85 // CCRMsgQueueObserver::~CCRMsgQueueObserver()
       
    86 // Destructor.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CCRMsgQueueObserver::~CCRMsgQueueObserver()
       
    90     {
       
    91     LOG( "CCRMsgQueueObserver::~CCRMsgQueueObserver() in" );
       
    92 
       
    93     Cancel();
       
    94     iQueue.Close(); 
       
    95     iObservers.Reset();     
       
    96     iObservers.Close(); 
       
    97 
       
    98     LOG( "CCRMsgQueueObserver::~CCRMsgQueueObserver() out" );
       
    99     }
       
   100 
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // CCRMsgQueueObserver::RunL()
       
   104 // From CActive
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CCRMsgQueueObserver::RunL()
       
   108     {
       
   109     LOG1( "CCRMsgQueueObserver::RunL() in, iStatus: %d", iStatus.Int() );
       
   110     
       
   111     if ( iStatus.Int() == KErrNone ) 
       
   112         {
       
   113         TInt i( 0 ); 
       
   114         if ( iQueue.Receive( iReceivedMessage ) == KErrNone )
       
   115             {
       
   116             if ( !iReceivedMessage.iSessionId || // or our id has not been set yet
       
   117                   iReceivedMessage.iSessionId == iSessionId ) // if the id matches
       
   118                 {
       
   119                 switch ( iReceivedMessage.iMsg )
       
   120                     {
       
   121                     case ECRMsgQueueAuthenticationNeeded:
       
   122                         LOG( "CCRMsgQueueObserver EAuthenticationFailed" );
       
   123                         SCRObserverMsg authNotify; 
       
   124                         authNotify.iMsg = ECRAuthenticationNeeded;
       
   125                         authNotify.iErr = iReceivedMessage.iErr; 
       
   126                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   127                             {
       
   128                             TRAP_IGNORE( iObservers[i]->NotifyL( authNotify ) );
       
   129                             }                       
       
   130                         
       
   131                         break;
       
   132 
       
   133                     case ECRMsgQueueAttachCompleted:
       
   134                         {
       
   135                         LOG( "CCRMsgQueueObserver ECRMsgQueueAttachCompleted" );
       
   136                         SCRObserverMsg iapNotify; 
       
   137                         iapNotify.iMsg = ECRAttachCompleted;
       
   138                         iapNotify.iErr = iReceivedMessage.iErr; 
       
   139                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   140                             {
       
   141                             TRAP_IGNORE( iObservers[i]->NotifyL( iapNotify ) );
       
   142                             }                       
       
   143                         }
       
   144                         break;
       
   145 
       
   146                     case ECRMsgQueueConnectionError:
       
   147                         {
       
   148                         LOG1( "CCRMsgQueueObserver ECRMsgQueueConnectionError, iReceivedMessage.iErr: %d",
       
   149                                                                                iReceivedMessage.iErr );
       
   150                         SCRObserverMsg iapNotify; 
       
   151                         iapNotify.iMsg = ECRConnectionError;
       
   152                         iapNotify.iErr = iReceivedMessage.iErr; 
       
   153                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   154                             {
       
   155                             TRAP_IGNORE( iObservers[i]->NotifyL( iapNotify ) );
       
   156                             }                       
       
   157                         }
       
   158                         break;
       
   159 
       
   160                     case ECRMsgQueueNotEnoughBandwidth:
       
   161                         {
       
   162                         LOG( "CCRMsgQueueObserver ECRMsgQueueNotEnoughBandwidth" );
       
   163                         SCRObserverMsg iapNotify; 
       
   164                         iapNotify.iMsg = ECRNotEnoughBandwidth;
       
   165                         iapNotify.iErr = iReceivedMessage.iErr; 
       
   166                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   167                             {
       
   168                             TRAP_IGNORE( iObservers[i]->NotifyL( iapNotify ) );
       
   169                             }                       
       
   170                         }
       
   171                         break;
       
   172 
       
   173                     case ECRMsgQueueSwitchingToTcp:
       
   174                         {
       
   175                         LOG( "CCRMsgQueueObserver ECRMsgQueueSwitchingToTcp" );
       
   176                         SCRObserverMsg iapNotify; 
       
   177                         iapNotify.iMsg = ECRSwitchingToTcp;
       
   178                         iapNotify.iErr = iReceivedMessage.iErr; 
       
   179                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   180                             {
       
   181                             TRAP_IGNORE( iObservers[i]->NotifyL( iapNotify ) );
       
   182                             }                       
       
   183                         }
       
   184                         break;
       
   185 
       
   186                     case ECRMsgQueueNormalEndOfStream:
       
   187                         {
       
   188                         LOG( "CCRMsgQueueObserver ECRMsgQueueNormalEndOfStream" );
       
   189                         SCRObserverMsg iapNotify; 
       
   190                         iapNotify.iMsg = ECRNormalEndOfStream;
       
   191                         iapNotify.iErr = iReceivedMessage.iErr; 
       
   192                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   193                             {
       
   194                             TRAP_IGNORE( iObservers[i]->NotifyL( iapNotify ) );
       
   195                             }                       
       
   196                         }
       
   197                         break;
       
   198                                             
       
   199                     case ECRMsgQueueStreamIsLiveStream:
       
   200                         {
       
   201                         LOG( "CCRMsgQueueObserver ECRMsgStreamIsLiveStream" );
       
   202                         SCRObserverMsg liveStreamNotify; 
       
   203                         liveStreamNotify.iMsg = ECRStreamIsLiveStream;
       
   204                         liveStreamNotify.iErr = iReceivedMessage.iErr; 
       
   205                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   206                             {
       
   207                             TRAP_IGNORE( iObservers[i]->NotifyL( liveStreamNotify ) );
       
   208                             }                       
       
   209                         }
       
   210                         break;
       
   211 
       
   212                     case ECRMsgQueueStreamIsRealMedia:
       
   213                         {
       
   214                         LOG( "CCRMsgQueueObserver ECRMsgQueueStreamIsRealMedia" );
       
   215                         SCRObserverMsg realStreamNotify; 
       
   216                         realStreamNotify.iMsg = ECRRealNetworksStream;
       
   217                         realStreamNotify.iErr = iReceivedMessage.iErr; 
       
   218                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   219                             {
       
   220                             TRAP_IGNORE( iObservers[i]->NotifyL( realStreamNotify ) );
       
   221                             }                       
       
   222                         }
       
   223                         break;
       
   224 
       
   225                     case ECRMsgQueueTestSinkData:
       
   226                         {
       
   227                         LOG( "CCRMsgQueueObserver ECRMsgQueueTestSinkData" );
       
   228                         SCRObserverMsg testSinkDataNotify;
       
   229                         testSinkDataNotify.iMsg = ECRTestSinkData;
       
   230                         testSinkDataNotify.iErr = iReceivedMessage.iErr;
       
   231                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   232                             {
       
   233                             TRAP_IGNORE( iObservers[i]->NotifyL( testSinkDataNotify ) );
       
   234                             }
       
   235                         }
       
   236                         break;
       
   237 
       
   238                     case ECRMsgQueueSdpAvailable:
       
   239                         {
       
   240                         LOG( "CCRMsgQueueObserver ECRMsgQueueSdpAvailable" );
       
   241                         SCRObserverMsg sdpAvailableNotify;
       
   242                         sdpAvailableNotify.iMsg = ECRSdpAvailable;
       
   243                         sdpAvailableNotify.iErr = iReceivedMessage.iErr;
       
   244                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   245                             {
       
   246                             TRAP_IGNORE( iObservers[i]->NotifyL( sdpAvailableNotify ) );
       
   247                             }
       
   248                         }
       
   249                         break;
       
   250                         
       
   251                     case ECRMsgQueueReadyToSeek:
       
   252                         {
       
   253                         LOG( "CCRMsgQueueObserver ECRMsgQueueReadyToSeek" );
       
   254                         SCRObserverMsg readyToSeekNotify;
       
   255                         readyToSeekNotify.iMsg = ECRReadyToSeek;
       
   256                         readyToSeekNotify.iErr = iReceivedMessage.iErr;
       
   257                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   258                             {
       
   259                             TRAP_IGNORE( iObservers[i]->NotifyL( readyToSeekNotify ) );
       
   260                             }
       
   261                         }
       
   262                         break;
       
   263                         
       
   264                     case ECRMsgQueueRecordingStarted:
       
   265                         {
       
   266                         LOG( "CCRMsgQueueObserver ECRMsgQueueRecordingStarted" );
       
   267                         SCRObserverMsg realStreamNotify;
       
   268                         realStreamNotify.iMsg = ECRRecordingStarted;
       
   269                         realStreamNotify.iErr = iReceivedMessage.iErr;
       
   270                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   271                             {
       
   272                             TRAP_IGNORE( iObservers[i]->NotifyL( realStreamNotify ) );
       
   273                             }
       
   274                         }
       
   275                         break;
       
   276 
       
   277                     case ECRMsgQueueRecordingPaused:
       
   278                         {
       
   279                         LOG( "CCRMsgQueueObserver ECRMsgQueueRecordingState" );
       
   280                         SCRObserverMsg realStreamNotify;
       
   281                         realStreamNotify.iMsg = ECRRecordingPaused;
       
   282                         realStreamNotify.iErr = iReceivedMessage.iErr;
       
   283                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   284                             {
       
   285                             TRAP_IGNORE( iObservers[i]->NotifyL( realStreamNotify ) );
       
   286                             }
       
   287                         }
       
   288                         break;
       
   289 
       
   290                     case ECRMsgQueueRecordingEnded:
       
   291                         {
       
   292                         LOG( "CCRMsgQueueObserver ECRMsgQueueRecordingState" );
       
   293                         SCRObserverMsg realStreamNotify;
       
   294                         realStreamNotify.iMsg = ECRRecordingEnded;
       
   295                         realStreamNotify.iErr = iReceivedMessage.iErr;
       
   296                         for ( i = 0; i < iObservers.Count(); i ++ )
       
   297                             {
       
   298                             TRAP_IGNORE( iObservers[i]->NotifyL( realStreamNotify ) );
       
   299                             }
       
   300                         }
       
   301                         break;
       
   302 
       
   303                     default:
       
   304                         {
       
   305                         LOG1( "Unknown message: %d", iReceivedMessage.iMsg );
       
   306                         }
       
   307                         break;
       
   308                     }
       
   309                 }
       
   310             else // message belongs to different session
       
   311                 {
       
   312                 LOG2( "Ignoring message: msg.sessionId=%d, iSessionId=%d",
       
   313                        iReceivedMessage.iSessionId, iSessionId );
       
   314                 }
       
   315 	    	}
       
   316         }
       
   317     
       
   318     iQueue.NotifyDataAvailable( iStatus ); 
       
   319     SetActive();    
       
   320     LOG( "CCRMsgQueueObserver::RunL() out" );
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CCRMsgQueueObserver::RunError()
       
   325 // From CActive
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 TInt CCRMsgQueueObserver::RunError( TInt aError )
       
   329     {
       
   330     LOG1( "CCRMsgQueueObserver::RunError(), aError: %d", aError );
       
   331     return aError;
       
   332     }
       
   333 
       
   334 // -----------------------------------------------------------------------------
       
   335 // CCRMsgQueueObserver::DoCancel()
       
   336 // From CActive
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 void CCRMsgQueueObserver::DoCancel()
       
   340     {
       
   341     LOG( "CCRMsgQueueObserver::DoCancel()" );
       
   342     iQueue.CancelDataAvailable();    
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CCRMsgQueueObserver::AddMsgQueueObserverL()
       
   347 // Addes object to observer array
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void CCRMsgQueueObserver::AddMsgQueueObserverL( MCREngineObserver* aObserver ) 
       
   351     {
       
   352     User::LeaveIfError( iObservers.Append( aObserver ) );
       
   353     }
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CCRMsgQueueObserver::SetSessionId()
       
   357 // Sets session id to listen to
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 void CCRMsgQueueObserver::SetSessionId( TInt aSessionId )
       
   361     {
       
   362     iSessionId = aSessionId;
       
   363     }
       
   364 
       
   365 // End of File