videofeeds/vcnsuiengine/src/vcxnscontentclienthandler.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <bldvariant.hrh>
       
    22 #include "IptvDebug.h"
       
    23 #include "CIptvUtil.h"
       
    24 #include <ipvideo/vcxconnectionutility.h>
       
    25 
       
    26 #include "CIptvVodContentClient.h"
       
    27 #include "vcxnscontentclienthandler.h"
       
    28 #include "vcxnsuiengine.h"
       
    29 #include "vcxnseventrouter.h"
       
    30 #include "vcxnsserviceprovider.h"
       
    31 #include "vcxnsservice.h"
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CVcxNsContentClientHandler::CVcxNsContentClientHandler()
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CVcxNsContentClientHandler::CVcxNsContentClientHandler( 
       
    38     CVcxNsUiEngine& aUiEngine,
       
    39     CVcxConnectionUtility& aConnUtil )
       
    40 :   iUiEngine( aUiEngine ),
       
    41     iConnUtil ( aConnUtil )
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CVcxNsContentClientHandler::NewL()
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CVcxNsContentClientHandler* CVcxNsContentClientHandler::NewL( 
       
    50     CVcxNsUiEngine& aUiEngine,
       
    51     CVcxConnectionUtility& aConnUtil )
       
    52     {
       
    53     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsContentClientHandler::NewL()");
       
    54     
       
    55     CVcxNsContentClientHandler* self = 
       
    56         new (ELeave) CVcxNsContentClientHandler( aUiEngine, aConnUtil );
       
    57 
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL();
       
    60     CleanupStack::Pop( self );
       
    61     
       
    62     return self;    
       
    63     }
       
    64     
       
    65 // -----------------------------------------------------------------------------
       
    66 // CVcxNsContentClientHandler::ConstructL()
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CVcxNsContentClientHandler::ConstructL()
       
    70     {
       
    71     iConnUtil.RegisterObserverL( this );	
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CVcxNsContentClientHandler::~CVcxNsContentClientHandler()
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CVcxNsContentClientHandler::~CVcxNsContentClientHandler()
       
    79     {
       
    80     iVodContentClients.ResetAndDestroy(); 
       
    81     
       
    82     iVodContentClientIds.Reset();
       
    83    
       
    84     iIapAsked.Reset();
       
    85     
       
    86     iConnUtil.RemoveObserver( this );
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CVcxNsContentProvider::GetVodContentClientL()
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 CIptvVodContentClient* CVcxNsContentClientHandler::GetVodContentClientL( TUint32 aServiceId )
       
    94     {
       
    95     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsContentClientHandler::GetVodContentClientL()");
       
    96 
       
    97     CIptvVodContentClient* vodContentClient = NULL;
       
    98 
       
    99     // Check if content client for this service ID already exists.
       
   100     for ( TInt i = 0; i < iVodContentClientIds.Count(); i++ )
       
   101         {
       
   102         if ( iVodContentClientIds[i] == aServiceId )
       
   103             {
       
   104             vodContentClient = iVodContentClients[i];
       
   105             break;
       
   106             }
       
   107         }
       
   108 
       
   109     // Create client if necessary.
       
   110     if ( !vodContentClient )
       
   111         {
       
   112         vodContentClient = CIptvVodContentClient::NewL( aServiceId, *this );
       
   113        
       
   114         iVodContentClients.AppendL( vodContentClient );
       
   115         iVodContentClientIds.AppendL( aServiceId );
       
   116         //Set this to ETrue by default - if user cancels in connection
       
   117         //query, then set to EFalse
       
   118         iIapAsked.AppendL( ETrue );
       
   119         }
       
   120 
       
   121     return vodContentClient;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CVcxNsContentProvider::UpdateEcgL()
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 TInt CVcxNsContentClientHandler::UpdateEcgL( TUint32 aServiceId )
       
   129     {
       
   130     CIptvVodContentClient* client = GetVodContentClientL( aServiceId );
       
   131     
       
   132     if ( !( IapAsked( aServiceId ) ) )
       
   133         {
       
   134         HandleEpgManagerMsgL( KIptvErrorVodNoIap, 0, aServiceId );
       
   135         }
       
   136         
       
   137     return client->UpdateEcgL();
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CVcxNsContentClientHandler::StoreMpxIdToEcgDbL()
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void CVcxNsContentClientHandler::StoreMpxIdToEcgDbL( TUint32 aServiceId,
       
   145                                                      TUint32 aContentId,
       
   146                                                      TUint32 aCaIndex,
       
   147                                                      TUint32 aMpxId )
       
   148     {
       
   149     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentClientHandler::StoreMpxIdToEcgDbL");
       
   150 
       
   151     GetVodContentClientL(aServiceId)->SetMpxIdL( aContentId, aCaIndex, aMpxId );
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CVcxNsContentClientHandler::StoreLastPlayPosL()
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CVcxNsContentClientHandler::StoreLastPlayPosL( TUint32 aServiceId,
       
   159                                                     TUint32 aContentId,
       
   160                                                     TUint32 aCaIndex,
       
   161                                                     TReal32 aPos )
       
   162     {
       
   163     TUint32 pos( aPos );
       
   164     
       
   165     IPTVLOGSTRING2_LOW_LEVEL("CVcxNsContentClientHandler::StoreLastPlayPosL ( %d )", pos );
       
   166 
       
   167     GetVodContentClientL(aServiceId)->SetLastPositionL( aContentId, aCaIndex, pos );
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CVcxNsContentClientHandler::HandleEpgManagerMsgL()
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CVcxNsContentClientHandler::HandleEpgManagerMsgL( 
       
   175     TInt aMsg, 
       
   176     TInt aInfo, 
       
   177     TIptvServiceId aServiceId )
       
   178     {
       
   179     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsContentClientHandler::HandleEpgManagerMsgL()");
       
   180 
       
   181     TInt error( KErrNone );
       
   182     
       
   183     if( aMsg == KIptvErrorVodNoIap || aMsg == KIptvErrorRssSearchNoIap &&
       
   184           ( iUiEngine.VcAppState() == EStateServiceView ||
       
   185             iUiEngine.VcAppState() == EStateCategoryView ||
       
   186             iUiEngine.VcAppState() == EStateContentView ||
       
   187             iUiEngine.VcAppState() == EStateCustomView ) )
       
   188         {
       
   189         TUint32 iap( 0 );
       
   190         error = iConnUtil.GetIap( iap, EFalse );
       
   191 
       
   192         if ( error == KErrNone ) 
       
   193             {
       
   194             GetVodContentClientL( aServiceId )->SetIapL( iap );
       
   195             SetIapAsked( aServiceId, ETrue );
       
   196             }
       
   197         else
       
   198             {
       
   199             GetVodContentClientL( aServiceId )->CancelUpdate();
       
   200             SetIapAsked( aServiceId, EFalse );
       
   201             
       
   202             if ( iUiEngine.ServiceProvider() )
       
   203                 {
       
   204                 CVcxNsService* service = NULL;
       
   205                 
       
   206                 service = iUiEngine.ServiceProvider()->GetServiceDataById( aServiceId );
       
   207                 
       
   208 				if ( service )
       
   209                     {
       
   210                     service->SetUpdateStatus( CVcxNsService::ENotUpdating );
       
   211                     }
       
   212                 
       
   213                 iUiEngine.ServiceProvider()->CancelUpdateQueue();
       
   214                 }
       
   215             }
       
   216         }
       
   217     if( error == KErrNone )
       
   218         {
       
   219         iUiEngine.GetEventRouter()->HandleEpgManagerMsgL( aMsg, aInfo, aServiceId );
       
   220         }
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CVcxNsContentClientHandler::RequestIsRoamingAllowedL()
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 TBool CVcxNsContentClientHandler::RequestIsRoamingAllowedL()
       
   228     {
       
   229     // we accept roaming every time and let the
       
   230     // update decide whether to use new iap or not
       
   231     // when new iap is available
       
   232     return ETrue;
       
   233     }
       
   234     
       
   235 // -----------------------------------------------------------------------------
       
   236 // CVcxNsContentClientHandler::IapChangedL()
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 void CVcxNsContentClientHandler::IapChangedL()
       
   240     {
       
   241     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsContentClientHandler::IapChangedL() enter");
       
   242  
       
   243     // Find out if any of the services is currently updating to make sure
       
   244     // GetIap() is only called when really needed to avoid unnecessary
       
   245     // IAP selection dialog.
       
   246     RPointerArray<CVcxNsService> servicesList =
       
   247         iUiEngine.GetServiceProviderL()->GetSubscribedServicesL();
       
   248 
       
   249     TBool updateOngoing( EFalse );
       
   250     const TInt serviceCount = servicesList.Count();
       
   251 
       
   252     IPTVLOGSTRING2_HIGH_LEVEL("UI Engine ## CVcxNsContentClientHandler::IapChangedL() service count: %d", serviceCount );
       
   253 
       
   254     for ( TInt i=0; i < serviceCount && !updateOngoing; i++ )
       
   255         {
       
   256         if ( servicesList[i]->GetUpdateStatus() == CVcxNsService::EUpdateOngoing )
       
   257             {
       
   258             IPTVLOGSTRING2_HIGH_LEVEL("UI Engine ## CVcxNsContentClientHandler::IapChangedL() service index %d is updating", i );
       
   259             updateOngoing = ETrue;
       
   260             }
       
   261         }
       
   262 
       
   263     IPTVLOGSTRING2_HIGH_LEVEL("UI Engine ## CVcxNsContentClientHandler::IapChangedL() updateOngoing: %d", updateOngoing );
       
   264 
       
   265     if ( updateOngoing )
       
   266         {
       
   267         // connectionutility notifies that iap has changed.
       
   268         // get new iap and save it to all services.
       
   269         // update server decides whether to use new iap or not
       
   270         TInt count( iVodContentClients.Count() );
       
   271         TUint32 iap( 0 );
       
   272         TInt err =  iConnUtil.GetIap( iap, EFalse ); 
       
   273         if( err != KErrNone )
       
   274             {
       
   275             for ( TInt i = 0; i < count; i++ )
       
   276                 {
       
   277                 ( iVodContentClients[i] )->SetIapL( iap );        
       
   278                 }    
       
   279             }
       
   280         }
       
   281 
       
   282     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsContentClientHandler::IapChangedL() return");
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CVcxNsContentClientHandler::IapAsked
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 TBool CVcxNsContentClientHandler::IapAsked( TUint32 aServiceId )
       
   290     {
       
   291     for ( TInt i = 0; i < iVodContentClientIds.Count(); i++ )
       
   292         {
       
   293         if ( iVodContentClientIds[i] == aServiceId )
       
   294             {
       
   295             return iIapAsked[i];
       
   296             }
       
   297         }    
       
   298     
       
   299     return ETrue;
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CVcxNsContentClientHandler::SetIapAsked
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 void CVcxNsContentClientHandler::SetIapAsked( TUint32 aServiceId, TBool aSet )
       
   307     {
       
   308     for ( TInt i = 0; i < iVodContentClientIds.Count(); i++ )
       
   309         {
       
   310         if ( iVodContentClientIds[i] == aServiceId 
       
   311              && iIapAsked.Count() > i )
       
   312             {
       
   313             iIapAsked[i] = aSet;
       
   314             }
       
   315         }    
       
   316     }
       
   317