homescreenplugins/videochplugin/src/videochiptvserverclient.cpp
branchRCL_3
changeset 10 112a725ff2c2
parent 9 5294c000a26d
child 11 8970fbd719ec
equal deleted inserted replaced
9:5294c000a26d 10:112a725ff2c2
     1 /*
       
     2 * Copyright (c) 2008 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:    CVcxNsChIptvServerClient class definition*
       
    15 */
       
    16 
       
    17 
       
    18 #include <e32cmn.h>
       
    19 #include "videochiptvserverclient.h"
       
    20 #include "videochmcategorylistener.h"
       
    21 #include "CIptvServiceManagementClient.h"
       
    22 #include "videochpublishabledata.h"
       
    23 #include "videochpublisher.h"
       
    24 #include "videoahpluginconstants.h"
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CVcxNsChIptvServerClient::CVcxNsChIptvServerClient
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CVcxNsChIptvServerClient::CVcxNsChIptvServerClient( CVcxNsChPublisher* aPublisher,
       
    31                                                     CVcxNsChPublishableData* aPublishableData ) :
       
    32     iPublishableData( aPublishableData ),
       
    33     iPublisher( aPublisher )                                                    
       
    34     {
       
    35     // No implementation required
       
    36     }
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CVcxNsChIptvServerClient::~CVcxNsChIptvServerClient
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CVcxNsChIptvServerClient::~CVcxNsChIptvServerClient()
       
    43     {
       
    44     delete iSmClient;
       
    45     delete iAhCategoryListener;
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CVcxNsChIptvServerClient::NewL
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 CVcxNsChIptvServerClient* CVcxNsChIptvServerClient::NewL( 
       
    53         CVcxNsChPublisher* aPublisher,
       
    54         CVcxNsChPublishableData* aPublishableData )
       
    55     {
       
    56     CVcxNsChIptvServerClient* self = new (ELeave)CVcxNsChIptvServerClient( aPublisher,
       
    57                                                                            aPublishableData );
       
    58     
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CVcxNsChIptvServerClient::ConstructL
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CVcxNsChIptvServerClient::ConstructL()
       
    70     {
       
    71     TUid domain      = TUid::Uid( KVcxNsAhMediatorDomain );
       
    72     TUid category    = TUid::Uid( KVcxNsAhMediatorCategory );
       
    73     TVersion version = TVersion( KVcxNsAhEventVersion, 0, 0 );
       
    74         
       
    75     iAhCategoryListener = CVcxNsChMCategoryListener::NewL( this,
       
    76                                                            domain,
       
    77                                                            category,
       
    78                                                            version );
       
    79 
       
    80     TInt event = TInt( KVcxNsAhEventSuiteLoaded );
       
    81     iAhCategoryListener->RegisterAndSubscribeL( event );
       
    82         
       
    83     event = TInt( KVcxNsAhEventSuiteUnloaded );
       
    84     iAhCategoryListener->RegisterAndSubscribeL( event );
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CVcxNsChIptvServerClient::HandleSmEvent
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 void CVcxNsChIptvServerClient::HandleSmEvent( CIptvSmEvent& aEvent )
       
    92     {
       
    93     if( aEvent.iEvent == CIptvSmEvent::EServiceDeleted || 
       
    94         aEvent.iEvent == CIptvSmEvent::EServiceAdded )
       
    95         {
       
    96         TInt id( KErrNotFound );
       
    97         
       
    98         TRAPD( err, id = iPublishableData->GetIntDataL( EVCxNsCPContentServiceGroup,
       
    99                                                         TPtrC8( KTvVideoId ) ) );
       
   100         
       
   101         if( err == KErrNone && id == aEvent.iServiceId )
       
   102             {
       
   103             if( aEvent.iEvent == CIptvSmEvent::EServiceDeleted )
       
   104                 {
       
   105                 // hide item:
       
   106                 // first backup then delete content
       
   107                 TRAPD( err, iPublisher->BackupContentL( EVCxNsCPContentServiceGroup ) );
       
   108                 if( err == KErrNone )
       
   109                     {
       
   110                     TRAP_IGNORE( iPublisher->DeleteContentL( EVCxNsCPContentServiceGroup ) );
       
   111                     }
       
   112                 }
       
   113             else 
       
   114                 {
       
   115                 // show item, just restore from backup                
       
   116                 TRAPD( err, iPublisher->RestoreBackupL( EVCxNsCPContentServiceGroup ) );
       
   117                 if( err == KErrNone )
       
   118                     {
       
   119                     TRAP_IGNORE( iPublisher->PublishContentL( EVCxNsCPContentServiceGroup ) );
       
   120                     }
       
   121                 }
       
   122             }        
       
   123         }
       
   124     // other events do not require our attention
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CVcxNsChIptvServerClient::StartIPTVServerInterfaceL
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CVcxNsChIptvServerClient::StartIPTVServerInterfaceL()
       
   132     {
       
   133     if( !iSmClient )
       
   134         {
       
   135         iSmClient = CIptvServiceManagementClient::NewL( *this );
       
   136         }
       
   137     }
       
   138     
       
   139 // -----------------------------------------------------------------------------
       
   140 // CVcxNsChIptvServerClient::StopIPTVServerInterface
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void CVcxNsChIptvServerClient::StopIPTVServerInterface()
       
   144     {
       
   145     if( iSmClient )
       
   146         {
       
   147         delete iSmClient;
       
   148         iSmClient = 0;
       
   149         }
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CVcxNsChIptvServerClient::GetServiceGroupIdL
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 TInt CVcxNsChIptvServerClient::GetServiceGroupIdL( const TDesC& aServiceUri )
       
   157     {
       
   158     User::LeaveIfNull( iSmClient );
       
   159     
       
   160     TInt id( KErrNotFound );
       
   161     if( aServiceUri.Length() <= 0 )
       
   162         {
       
   163         return id;
       
   164         }    
       
   165     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
   166     CDesC8ArraySeg* services = NULL;
       
   167     TInt error = iSmClient->GetServicesL( 0,
       
   168                                           CIptvServiceManagementClient::EDisplayOrderAscending,
       
   169                                           services,
       
   170                                           respStatus );  
       
   171     
       
   172     if ( error == KErrNone && 
       
   173          respStatus == MIptvServiceManagementClientObserver::ESucceeded )
       
   174         {
       
   175         CleanupStack::PushL( services );
       
   176         
       
   177         CIptvService* service = CIptvService::NewL();
       
   178         CleanupStack::PushL( service );
       
   179         TInt count( services->Count() );
       
   180         for ( TInt i = 0; i < count; i++ )
       
   181             {
       
   182             service->SetL( services->MdcaPoint(i) );
       
   183             
       
   184             if( !aServiceUri.CompareF( service->GetAddress() ) )
       
   185                 {
       
   186                 id = service->GetId();  
       
   187                 
       
   188                 // service found, make sure it's subscribed                       
       
   189                 if ( !( service->GetFlags() & CIptvService::ESelected ) )
       
   190                     {
       
   191                     // factory settings changed to point service 
       
   192                     // that is setted as unsubscribed.
       
   193                     // save id, backup data and remove menu content
       
   194                     iPublishableData->SetDataL( EVCxNsCPContentServiceGroup,
       
   195                                                  TPtrC8( KTvVideoId ), id );
       
   196                     iPublisher->BackupContentL( EVCxNsCPContentServiceGroup, EFalse );
       
   197                     iPublisher->DeleteContentL( EVCxNsCPContentServiceGroup );
       
   198                     id = KErrNotFound;
       
   199                     }
       
   200                 break;
       
   201                 }
       
   202             }
       
   203         CleanupStack::PopAndDestroy( service );
       
   204         CleanupStack::PopAndDestroy( services );
       
   205         } 
       
   206 
       
   207     return id;
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CVcxNsChIptvServerClient::MediatorEventL
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CVcxNsChIptvServerClient::MediatorEventL( TUid aDomain,
       
   215                                                TUid aCategory, 
       
   216                                                TInt aEventId, 
       
   217                                                const TDesC8& /* aData */ )
       
   218     {
       
   219     if( aDomain    == TUid::Uid( KVcxNsAhMediatorDomain ) &&
       
   220         aCategory  == TUid::Uid( KVcxNsAhMediatorCategory ) )
       
   221         {
       
   222         if( aEventId == KVcxNsAhEventSuiteLoaded )
       
   223             {
       
   224             StartIPTVServerInterfaceL();
       
   225             }
       
   226         if( aEventId == KVcxNsAhEventSuiteUnloaded )
       
   227             {
       
   228             StopIPTVServerInterface();
       
   229             }
       
   230         }
       
   231     }