videofeeds/server/IptvEpgManager/src/CIptvEpgManagerImpl.cpp
branchRCL_3
changeset 23 befca0ec475f
parent 0 96612d01cf9f
equal deleted inserted replaced
22:839377eedc2b 23:befca0ec475f
       
     1 /*
       
     2 * Copyright (c) 2004-2005 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 FILES
       
    22 #include <e32base.h>
       
    23 #include <bautils.h>
       
    24 #include "IptvDebug.h"
       
    25 #include "CIptvEpgDatabase.h"
       
    26 #include "CIptvEpgLiveTvCallbackImpl.h"
       
    27 #include "IptvLiveEpgConstants.h"
       
    28 #include "CIptvEpgDb.h"
       
    29 #include "CIptvEpgManagerImpl.h"
       
    30 #include "CIptvServer.h"
       
    31 #include "CIptvEpgSession.h"
       
    32 #include "CIptvServiceManager.h"
       
    33 #include "CIptvEpgVodMsqQueue.h"
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // ---------------------------------------------------------
       
    38 // CIptvEpgManagerImpl::ConstructL
       
    39 // Symbian 2nd phase constructor can leave.
       
    40 // ---------------------------------------------------------
       
    41 //
       
    42 void CIptvEpgManagerImpl::ConstructL()
       
    43     {       
       
    44     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgManagerImpl::ConstructL");
       
    45 
       
    46     User::LeaveIfError( iServer.iServiceManager->RegisterObserver( this ) );
       
    47     User::LeaveIfError( iFs.Connect() );
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CIptvEpgManagerImpl::NewL
       
    52 // Two-phased constructor.
       
    53 // Create instance of concrete interface implementation
       
    54 // ---------------------------------------------------------
       
    55 //
       
    56 CIptvEpgManagerImpl* CIptvEpgManagerImpl::NewL(CIptvServer& aServer)
       
    57     {
       
    58     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgManagerImpl::NewL");  
       
    59 
       
    60     CIptvEpgManagerImpl* self = new(ELeave) CIptvEpgManagerImpl(aServer);
       
    61     CleanupStack::PushL(self);
       
    62 
       
    63     self->ConstructL();
       
    64 
       
    65     CleanupStack::Pop(self);
       
    66     return self;
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------
       
    70 // CIptvEpgManagerImpl::~CIptvEpgManagerImpl
       
    71 // Destructor
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 CIptvEpgManagerImpl::~CIptvEpgManagerImpl()
       
    75     {	
       
    76     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgManagerImpl::~CIptvEpgManagerImpl");  
       
    77 
       
    78     iServer.iServiceManager->DeRegisterObserver(this);
       
    79     iEpgDbArray.ResetAndDestroy();
       
    80     iFs.Close();
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------
       
    84 // CIptvEpgManagerImpl::CIptvEpgManagerImpl
       
    85 // C++ default constructor
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 CIptvEpgManagerImpl::CIptvEpgManagerImpl(CIptvServer& aServer) : 
       
    89     iServer( aServer )
       
    90     {
       
    91     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgManagerImpl::CIptvEpgManagerImpl");
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // CIptvEpgManagerImpl::CreateSession
       
    96 // 
       
    97 // ---------------------------------------------------------
       
    98 // 
       
    99 CIptvEpgSession* CIptvEpgManagerImpl::CreateSessionL(TUint32 aServiceId, CIptvEpgVodMsqQueue* aMsgQueue, TInt& aError, TBool aPluginCanRun)
       
   100     {    
       
   101     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgManagerImpl::CreateSession");  
       
   102   
       
   103     CIptvEpgSession* session = NULL;
       
   104     CIptvService*    service = NULL;
       
   105 
       
   106     service = iServer.iServiceManager->GetServiceL( aServiceId, ETrue /* do open/close */ );
       
   107 
       
   108     if (service)
       
   109         {
       
   110         CIptvService::TServiceType serviceType = service->GetType();
       
   111         delete service;
       
   112 
       
   113         CDbHolder* dbHolder = NULL;
       
   114 
       
   115         switch (serviceType)
       
   116             {
       
   117             case CIptvService::EVod:
       
   118             case CIptvService::EVodCast:
       
   119             case CIptvService::ESearch:
       
   120             case CIptvService::EServiceGroup:
       
   121                 {
       
   122                 dbHolder = GetDatabaseHolderL( aServiceId, ETrue );
       
   123                 session = CIptvEpgSession::NewL(dbHolder->iEpgDb, aServiceId, aMsgQueue, iServer, aPluginCanRun, aError);
       
   124                 }
       
   125                 break;
       
   126             case CIptvService::ELiveTv:
       
   127                 {
       
   128                 dbHolder = GetDatabaseHolderL( aServiceId, EFalse );
       
   129                 session = CIptvEpgSession::NewL(dbHolder->iLiveTvDb, aServiceId, aMsgQueue, iServer, aPluginCanRun, aError);
       
   130                 }
       
   131                 break;                        
       
   132             default:
       
   133                 User::Leave( KErrNotSupported );
       
   134                 break;
       
   135             }
       
   136         }
       
   137     else
       
   138         {
       
   139         User::Leave( KErrNotFound );
       
   140         }
       
   141 
       
   142     return session;
       
   143     }
       
   144 
       
   145 // --------------------------------------------------------------------------
       
   146 // CIptvEpgManagerImpl::GetDatabaseHolderL
       
   147 // 
       
   148 // --------------------------------------------------------------------------
       
   149 // 
       
   150 CIptvEpgManagerImpl::CDbHolder* CIptvEpgManagerImpl::GetDatabaseHolderL(
       
   151     TUint32 aServiceId,
       
   152     TBool aEpgDb )
       
   153     {
       
   154     //  Try to find first
       
   155     for (TInt i = 0; i < iEpgDbArray.Count(); i++)
       
   156         {
       
   157         CIptvEpgManagerImpl::CDbHolder* dbHolder = iEpgDbArray[i];
       
   158         if (dbHolder->iServiceId == aServiceId)
       
   159             {
       
   160             dbHolder->iReferenceCount++;
       
   161             return dbHolder;
       
   162             }
       
   163         }
       
   164 
       
   165     //  Create holder for the db
       
   166     CIptvEpgManagerImpl::CDbHolder* dbHolder = new (ELeave) CDbHolder();
       
   167     CleanupStack::PushL( dbHolder );
       
   168     iEpgDbArray.AppendL( dbHolder );
       
   169     CleanupStack::Pop( dbHolder );
       
   170     dbHolder->iServiceId = aServiceId;
       
   171     dbHolder->iReferenceCount = 1;
       
   172 
       
   173     //  Create db
       
   174     if (aEpgDb)
       
   175         {
       
   176         TBuf<KIptvMaxPath> path;
       
   177         CIptvUtil::GetPathL( iFs, EIptvPathEcg, path );
       
   178         path.Append(KIptvEpgDbName);
       
   179         TBuf<KIptvServiceIdMaxLength> service;
       
   180         service.Num( aServiceId );
       
   181         path.Append( service );
       
   182 
       
   183         dbHolder->iEpgDb = CIptvEpgDb::NewL( path, aServiceId, iServer );
       
   184         }
       
   185     else
       
   186         {
       
   187         TBuf<KIptvMaxPath> path;
       
   188         CIptvUtil::GetPathL( iFs, EIptvPathTmpLive, aServiceId, path );
       
   189         path.Append( KLiveTvEPGDatabaseName );
       
   190         
       
   191         // if path exists delete the file. This is done to make sure
       
   192         // update is done to a clear database.
       
   193         if ( BaflUtils::FileExists( iFs, path ) )
       
   194         	{
       
   195         	TInt error = BaflUtils::DeleteFile( iFs, path );
       
   196 			if ( error != KErrNone )
       
   197 				{
       
   198 				IPTVLOGSTRING2_LOW_LEVEL("Failed to delete live database file: %d", error);  	
       
   199 				}
       
   200 		    
       
   201         	}
       
   202         dbHolder->iLiveTvDb = CIptvEpgDatabase::NewL( path );
       
   203         }
       
   204 
       
   205     return dbHolder;
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------
       
   209 // CIptvEpgManagerImpl::CloseSession
       
   210 // 
       
   211 // ---------------------------------------------------------
       
   212 // 
       
   213 void CIptvEpgManagerImpl::CloseSession(TUint32 aServiceId)
       
   214     {
       
   215     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgManagerImpl::CloseSession");  
       
   216 
       
   217     //  Find the database
       
   218     for (TInt i = 0; i < iEpgDbArray.Count(); i++)
       
   219         {
       
   220         CIptvEpgManagerImpl::CDbHolder* dbHolder = iEpgDbArray[i];
       
   221         if (dbHolder->iServiceId == aServiceId)
       
   222             {
       
   223             //  Decrease ref count and if it goes to zero, delete it
       
   224             dbHolder->iReferenceCount--;
       
   225             if (dbHolder->iReferenceCount < 1)
       
   226                 {
       
   227                 iEpgDbArray.Remove( i );
       
   228                 delete dbHolder;
       
   229                 }
       
   230             }
       
   231         }
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------
       
   235 // CIptvEpgManagerImpl::HandleSmEvent
       
   236 // 
       
   237 // ---------------------------------------------------------
       
   238 // 
       
   239 void CIptvEpgManagerImpl::HandleSmEvent(CIptvSmEvent& aEvent)
       
   240     {
       
   241     IPTVLOGSTRING_LOW_LEVEL("CIptvEpgManagerImpl::ServiceModified");
       
   242 
       
   243     // Delete epg-database. There is no session with aServiceId when this mehtod is called.
       
   244     // -> We can delete database directly.
       
   245 
       
   246     if (aEvent.iEvent == CIptvSmEvent::EServiceModified)
       
   247         {
       
   248         RFs fs;
       
   249         TInt error = fs.Connect();
       
   250         if (error == KErrNone)
       
   251             {        
       
   252             TBuf<KIptvMaxPath> path;
       
   253             TRAP_IGNORE(CIptvUtil::GetPathL(fs, EIptvPathEcg, path, EDriveC, EFalse));
       
   254         
       
   255             path.Append(KIptvEpgDbName);
       
   256         
       
   257             TBuf<KIptvServiceIdMaxLength> service;
       
   258             service.Num(aEvent.iServiceId);
       
   259             path.Append(service);
       
   260         
       
   261             IPTVLOGSTRING2_LOW_LEVEL("CIptvEpgManagerImpl::ServiceModified --> deleting: %S", &path);
       
   262         
       
   263             // If exist, delete epg database
       
   264             if (BaflUtils::FileExists(fs, path))
       
   265                 {    
       
   266                 BaflUtils::DeleteFile(fs, path);
       
   267                 }      
       
   268           
       
   269             fs.Close();
       
   270             }
       
   271         }
       
   272     }
       
   273 
       
   274 CIptvEpgManagerImpl::CDbHolder::~CDbHolder()
       
   275     {
       
   276     delete iEpgDb;
       
   277     delete iLiveTvDb;
       
   278     }