videofeeds/server/tsrc/IptvTestUtility/src/CIptvTestDlInfo.cpp
branchRCL_3
changeset 57 befca0ec475f
parent 0 96612d01cf9f
equal deleted inserted replaced
56:839377eedc2b 57:befca0ec475f
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:   implements logging functionality of the download information*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CIptvTestDlInfo.h"
       
    22 #include "VCXTestLog.h"
       
    23 #include "CIptvMyVideosGlobalFileId.h"
       
    24 #include "CIptvTestUtilities.h"
       
    25 #include "CIptvMediaContent.h"
       
    26 #include <mmf/common/mmfcontrollerpluginresolver.h>
       
    27 
       
    28 #include "CIptvVodContentContentFullDetails.h"
       
    29 
       
    30 // EXTERNAL DATA STRUCTURES
       
    31 
       
    32 // EXTERNAL FUNCTION PROTOTYPES
       
    33 
       
    34 // CONSTANTS
       
    35 
       
    36 // MACROS
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 
       
    40 // MODULE DATA STRUCTURES
       
    41 
       
    42 // LOCAL FUNCTION PROTOTYPES
       
    43 
       
    44 // FORWARD DECLARATIONS
       
    45 
       
    46 // ============================= LOCAL FUNCTIONS ===============================
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CIptvTestDlInfo::
       
    52 // C++ default constructor can NOT contain any code, that
       
    53 // might leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CIptvTestDlInfo* CIptvTestDlInfo::NewL()
       
    57 	{
       
    58 	VCXLOGLO1(">>>CIptvTestDlInfo::NewL");
       
    59 	CIptvTestDlInfo* self = new (ELeave) CIptvTestDlInfo();
       
    60 	CleanupStack::PushL(self);
       
    61 	self->ConstructL( );
       
    62 	CleanupStack::Pop();
       
    63 	VCXLOGLO1("<<<CIptvTestDlInfo::NewL");
       
    64 	return self;
       
    65 	}
       
    66 // -----------------------------------------------------------------------------
       
    67 // CIptvTestDlInfo::~CIptvTestDlInfo
       
    68 // destructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CIptvTestDlInfo::~CIptvTestDlInfo()
       
    72     {
       
    73 	VCXLOGLO1(">>>CIptvTestDlInfo::~CIptvTestDlInfo");
       
    74 	TUint i=0;
       
    75 	if(iIptvTestUtilities)
       
    76 		{
       
    77 		delete iIptvTestUtilities;
       
    78 		iIptvTestUtilities=NULL;
       
    79 		}
       
    80 
       
    81 	//print and remove remaining file infos
       
    82 	for(i = 0;i < iDlFileInfoArray.Count(); i++)
       
    83 	    {
       
    84 		RemoveDlFileInfoItem(i);
       
    85 		}
       
    86 	iDlFileInfoArray.ResetAndDestroy();
       
    87 
       
    88 	VCXLOGLO1("<<<CIptvTestDlInfo::~CIptvTestDlInfo");
       
    89 	}
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // CIptvTestDlInfo::CIptvTestDlInfo
       
    93 //
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CIptvTestDlInfo::CIptvTestDlInfo()
       
    97 	{
       
    98 	VCXLOGLO1(">>>CIptvTestDlInfo::CIptvTestDlInfo");
       
    99 
       
   100 	VCXLOGLO1("<<<CIptvTestDlInfo::CIptvTestDlInfo");
       
   101 	}
       
   102 // -----------------------------------------------------------------------------
       
   103 // CIptvTestDlInfo::ConstructL()
       
   104 //
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CIptvTestDlInfo::ConstructL( )
       
   108 	{
       
   109 	VCXLOGLO1(">>>CIptvTestDlInfo::ConstructL");
       
   110 	iIptvTestUtilities = CIptvTestUtilities::NewL();
       
   111 
       
   112 	VCXLOGLO1("<<<CIptvTestDlInfo::ConstructL");
       
   113 	}
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CIptvTestDlInfo::DlStop
       
   117 // destructor
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 
       
   121 TBool CIptvTestDlInfo::FindDlFileInfo(TInt& aIndex,TIptvServiceId aServiceId,TIptvContentId aContentId)
       
   122 	{
       
   123 
       
   124 	VCXLOGLO1(">>>CIptvTestDlInfo::FindDlFileInfo");
       
   125 	_LIT(KFindDlFileInfo, "CIptvTestDlInfo::FindDlFileInfo:");
       
   126 	TBool rv = FALSE;
       
   127 	TUint i=0;
       
   128 	for(i = 0;i < iDlFileInfoArray.Count(); i++)
       
   129 			{
       
   130 			if(iDlFileInfoArray[i]->iServiceId == aServiceId && iDlFileInfoArray[i]->iContentId == aContentId)
       
   131 					{
       
   132 					aIndex = i;
       
   133 					rv = TRUE;
       
   134 					break;
       
   135 					}
       
   136 			}
       
   137 	//panic if not found!!
       
   138 	if(!rv)
       
   139 	    {
       
   140 	    VCXLOGLO1("DlFileInfo instance not found, PANICing!!!");
       
   141 	    User::Panic( KFindDlFileInfo, 0 );
       
   142         }
       
   143 
       
   144 	VCXLOGLO1("<<<CIptvTestDlInfo::FindDlFileInfo");
       
   145 	return rv;
       
   146 	}
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CIptvTestDlInfo::RemoveDlFileInfoItem
       
   150 // Removes download information when download has been ended
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 TBool CIptvTestDlInfo::RemoveDlFileInfoItem(TUint32 index)
       
   154 	{
       
   155 	VCXLOGLO1(">>>CIptvTestDlInfo::RemoveDlFileInfoItem");
       
   156 	_LIT(KRemoveDlFileInfo, "CIptvTestDlInfo::RemoveDlFileInfoItem:");
       
   157 
       
   158 	TBool rv = ETrue;
       
   159 	CIptvTestDlFileInfo * p = NULL;
       
   160 	//check that index is not out of range
       
   161 	if(index >= iDlFileInfoArray.Count())
       
   162 		{
       
   163 		rv = EFalse;
       
   164 		VCXLOGLO1("DlFileInfo instance not found, PANICing!!!");
       
   165 	    User::Panic( KRemoveDlFileInfo, 0 );
       
   166 		}
       
   167 	else
       
   168 		{
       
   169 		p = iDlFileInfoArray[index];
       
   170 		iDlFileInfoArray.Remove(index);
       
   171 		if(p)
       
   172 			{
       
   173 			delete p;
       
   174 			p = NULL;
       
   175 			}
       
   176 		}
       
   177 	VCXLOGLO1(">>>CIptvTestDlInfo::RemoveDlFileInfoItem");
       
   178 	return rv;
       
   179 	}
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CIptvTestDlInfo::CreateDlFileInfoItem
       
   183 // Creates new CIptvTestDlFileInfo item when new download has been started
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 CIptvTestDlFileInfo* CreateDlFileInfoItem()
       
   187 	{
       
   188 	VCXLOGLO1(">>>CIptvTestDlInfo::CreateDlFileInfoItem");
       
   189 	CIptvTestDlFileInfo* p = NULL;
       
   190 
       
   191 	p = CIptvTestDlFileInfo::NewL();
       
   192 
       
   193 	VCXLOGLO1("<<<CIptvTestDlInfo::CreateDlFileInfoItem");
       
   194 	return p;
       
   195 	}
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CIptvTestDlInfo::DlStart
       
   199 // Creates new item and stores information about new download
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 EXPORT_C void CIptvTestDlInfo::DlStart(TUint32 aIapId,
       
   203 					TIptvServiceId aServiceId,
       
   204 					TIptvContentId aContentId,
       
   205 					TUint32 aDlContentNum,
       
   206 					TIptvDownloadType aDlType)
       
   207 	{
       
   208 	VCXLOGLO1(">>>CIptvTestDlInfo::DlStart");
       
   209 	CIptvTestDlFileInfo* p = CreateDlFileInfoItem();
       
   210 
       
   211 	HBufC* contentUrl = NULL;
       
   212 
       
   213 	//get Iapname, servicename
       
   214 	TBuf<255> iapName;
       
   215 	TBuf<255> serviceName;
       
   216 
       
   217 	//Get the name of the service
       
   218 
       
   219 	CIptvService* pService = iIptvTestUtilities->GetServiceFromDb(aServiceId);
       
   220 	if(pService)
       
   221     	{
       
   222     	serviceName.Append(pService->GetName());
       
   223     	delete pService;
       
   224     	pService = NULL;
       
   225     	}
       
   226 	else
       
   227     	{
       
   228     	//do nothing
       
   229     	}
       
   230 
       
   231 	//Get the name of the IAP
       
   232 	iIptvTestUtilities->GetIapNameById(iapName, aIapId);
       
   233 
       
   234 	RPointerArray<CIptvMediaContent> CAList;
       
   235 
       
   236 	TInt err = KErrNone, ret = KErrNone;
       
   237 	TRAP(err, ret = iIptvTestUtilities->GetContentAccessListL(aServiceId, aContentId, CAList));
       
   238 
       
   239 	CleanupResetAndDestroyPushL(CAList);
       
   240 
       
   241     if(err != KErrNone)
       
   242     	{
       
   243     	VCXLOGLO2("* ERROR * GetContentAccessListLApiTest leaved !: %d", err);
       
   244     	}
       
   245     else if(ret != KErrNone)
       
   246     	{
       
   247 		VCXLOGLO2("* ERROR * GetContentAccessListLApiTest returned error: %d", ret);
       
   248     	}
       
   249 	else
       
   250 		{
       
   251 	    if(CAList.Count() <= aDlContentNum)
       
   252 	    	{
       
   253 			VCXLOGLO1("* ERROR * Content has not enough media contents. Downloading the first content.");
       
   254 			aDlContentNum = 0;
       
   255 	    	}
       
   256 	    else
       
   257 		if(CAList.Count() == 0)
       
   258 			{
       
   259 			VCXLOGLO1("* ERROR * Content has no media content. Can't start download!");
       
   260 
       
   261 			}
       
   262 		else
       
   263 			{
       
   264 			// Everything ok to start the DL
       
   265 			iDlFileInfoArray.Append(p);
       
   266 
       
   267 			const TPtrC url = CAList[aDlContentNum]->GetMediaContentUrl();
       
   268 
       
   269 			TInt length = url.Length();
       
   270 	        contentUrl = HBufC::NewLC(length);
       
   271 
       
   272 	        TPtr16 pContentUrl = contentUrl->Des();
       
   273 	        pContentUrl.Copy( url );
       
   274 	        CleanupStack::Pop(contentUrl);
       
   275 
       
   276 	        VCXLOGLO2("Content download url = %S", contentUrl);
       
   277 
       
   278 			//store information to item
       
   279 			p->DlStarted(
       
   280 			            aIapId,
       
   281 			            iapName,
       
   282 			            aServiceId,
       
   283 			            serviceName,
       
   284 			            aContentId,
       
   285 			            aDlType,
       
   286 			            contentUrl); //ownership of the pointer moved!!!
       
   287 				}
       
   288 
       
   289 		}
       
   290 
       
   291 
       
   292     CleanupStack::PopAndDestroy(&CAList);
       
   293 
       
   294 	VCXLOGLO1("<<<CIptvTestDlInfo::DlStart");
       
   295 	}
       
   296 // -----------------------------------------------------------------------------
       
   297 // CIptvTestDlInfo::DlStartFailed
       
   298 // stores the error id to download information
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 EXPORT_C void CIptvTestDlInfo::DlStartFailed(TIptvServiceId aServiceId,
       
   302 							TIptvContentId aContentId,
       
   303 							TIptvDlError aError)
       
   304 	{
       
   305 	VCXLOGLO1(">>>CIptvTestDlInfo::DlStartFailed");
       
   306 	TInt index = 0;
       
   307 
       
   308 	//find the actual download information
       
   309 	FindDlFileInfo(index, aServiceId, aContentId);
       
   310 
       
   311 	//store the error id to downloadinformation
       
   312 	iDlFileInfoArray[index]->DlStartFailed(aError);
       
   313 
       
   314 	//print the information to log
       
   315 	iDlFileInfoArray[index]->Print();
       
   316 
       
   317 	//Remove the item which contains information about this download
       
   318 	RemoveDlFileInfoItem(index);
       
   319 	VCXLOGLO1(">>>CIptvTestDlInfo::DlStartFailed");
       
   320 	}
       
   321 // -----------------------------------------------------------------------------
       
   322 // CIptvTestDlInfo::DlGoing
       
   323 // stores name of the file to download information
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 EXPORT_C void CIptvTestDlInfo::DlGoing(TIptvServiceId aServiceId,
       
   327 					TIptvContentId aContentId,
       
   328 					CIptvMyVideosGlobalFileId& aFileId,
       
   329 					TUint32 aState,
       
   330 					TIptvDlError aError )
       
   331 	{
       
   332 	VCXLOGLO1(">>>CIptvTestDlInfo::DlGoing");
       
   333 
       
   334 	TBuf<255> videoName;//created because of the interface, not used
       
   335 	TBuf<255> fullPath;
       
   336 	TInt index = 0;
       
   337 
       
   338     TUint32 serviceId = 0; //created because of the interface, not used
       
   339 
       
   340 	iIptvTestUtilities->GetVideoInfo(aFileId,serviceId,videoName,fullPath);
       
   341 
       
   342 	//find the actual download information
       
   343 	FindDlFileInfo(index, aServiceId, aContentId);
       
   344 
       
   345 	//store the info to download information
       
   346 	iDlFileInfoArray[index]->DlGoing(fullPath, aState, aError);
       
   347 
       
   348 	VCXLOGLO1("<<<CIptvTestDlInfo::DlGoing");
       
   349 	}
       
   350 // -----------------------------------------------------------------------------
       
   351 // CIptvTestDlInfo::DlUpdateState
       
   352 // updates state of the download to download information
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 EXPORT_C void CIptvTestDlInfo::DlUpdateState(TIptvServiceId aServiceId,
       
   356 							TIptvContentId aContentId,
       
   357 							TUint32 aState,
       
   358 							TIptvDlError aError )
       
   359 	{
       
   360 	VCXLOGLO1(">>>CIptvTestDlInfo::DlUpdateState");
       
   361 	TInt index = 0;
       
   362 
       
   363 	//find the actual download information
       
   364 	FindDlFileInfo(index, aServiceId, aContentId);
       
   365 
       
   366 	//update state to download information
       
   367 	iDlFileInfoArray[index]->DlUpdateState( aState, aError);
       
   368 	VCXLOGLO1(">>>CIptvTestDlInfo::DlUpdateState");
       
   369 	}
       
   370 // -----------------------------------------------------------------------------
       
   371 // CIptvTestDlInfo::DlStop
       
   372 // updates state of the download to download information prints the info to log
       
   373 // and removes the item
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 EXPORT_C void CIptvTestDlInfo::DlStop(TIptvServiceId aServiceId,
       
   377 					TIptvContentId aContentId,
       
   378 					TUint32 aState,
       
   379 					TIptvDlError aError )
       
   380 	{
       
   381 	VCXLOGLO1(">>>CIptvTestDlInfo::DlStop");
       
   382 	TInt index = 0;
       
   383 	TUint32 fileSize = 0;
       
   384 	//find the actual download information
       
   385 	FindDlFileInfo(index, aServiceId, aContentId);
       
   386 
       
   387 	//Get the name of the downloaded file
       
   388 	TDesC& fileName = iDlFileInfoArray[index]->GetFileName();
       
   389 
       
   390 	//Get the size of the downloaded file
       
   391 	iIptvTestUtilities->GetFileSize(fileName,fileSize);
       
   392 
       
   393 	//store the information about stopping
       
   394 	iDlFileInfoArray[index]->DlStopped(fileSize, aState, aError);
       
   395 
       
   396 	//print the information to log
       
   397 	iDlFileInfoArray[index]->Print();
       
   398 
       
   399 	//Remove the item which contains information about this download
       
   400 	RemoveDlFileInfoItem(index);
       
   401 	VCXLOGLO1(">>>CIptvTestDlInfo::DlStop");
       
   402 	}
       
   403 // -----------------------------------------------------------------------------
       
   404 // CIptvTestDlInfo::DlTimeout
       
   405 // Prints and removes download information when download didn't get ready in time.
       
   406 //
       
   407 // -----------------------------------------------------------------------------
       
   408 //
       
   409 EXPORT_C void CIptvTestDlInfo::DlTimeOut(TIptvServiceId aServiceId,
       
   410 					TIptvContentId aContentId
       
   411 					 )
       
   412 	{
       
   413 	VCXLOGLO1(">>>CIptvTestDlInfo::DlTimeOut");
       
   414 
       
   415 	TInt index = 0;
       
   416 
       
   417     //find the actual download information
       
   418 	FindDlFileInfo(index, aServiceId, aContentId);
       
   419 
       
   420 	//store the information about timeout
       
   421 	iDlFileInfoArray[index]->DlTimeOut();
       
   422 
       
   423 	//print the information to log
       
   424 	//iDlFileInfoArray[index]->Print();
       
   425 
       
   426 	//Remove the item which contains information about this download
       
   427 	//RemoveDlFileInfoItem(index); changed, waiting for deleted - event
       
   428 
       
   429     VCXLOGLO1("<<<CIptvTestDlInfo::DlTimeOut");
       
   430     }
       
   431 //  End of File