mmplugins/imagingplugins/imagedisplay/plugins/mng/ChunkProcessor.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /** 	@file
       
    17 	@internalTechnology */
       
    18 #include <e32base.h>
       
    19 #include "InputStream.h"
       
    20 
       
    21 #include "ChunkProcessor.h"
       
    22 
       
    23 CChunkProcessor::CChunkProcessor(CMngPlayer& aMngPlayer):
       
    24 								CActive(EPriorityIdle),
       
    25 								iMngPlayer(aMngPlayer)
       
    26 	{
       
    27 	CActiveScheduler::Add(this);
       
    28 	}
       
    29 
       
    30 void CChunkProcessor::DoCancel()
       
    31 	{
       
    32 	if (iCallerRequest != NULL)
       
    33 		{
       
    34 		User::RequestComplete(iCallerRequest, KErrCancel);
       
    35 		}
       
    36 		
       
    37 	if (iStatus.Int() == KRequestPending)
       
    38 		{
       
    39 		TRequestStatus* pReq=&iStatus;
       
    40 		User::RequestComplete(pReq, KErrCancel);
       
    41 		}
       
    42 	}
       
    43 
       
    44 TInt CChunkProcessor::RunError(TInt aError)
       
    45 	{
       
    46 	NotifyCaller(aError);
       
    47 	return KErrNone;
       
    48 	}
       
    49 
       
    50 void CChunkProcessor::RunAgain()
       
    51 	{
       
    52 	if (iIsPaused)
       
    53 		{
       
    54 		ASSERT(EFalse==iNeedRunAfterResume);
       
    55 		iNeedRunAfterResume = ETrue;
       
    56 		}
       
    57 	else
       
    58 		{
       
    59 		iNeedRunAfterResume = EFalse;
       
    60 		SetActive();
       
    61 		TRequestStatus* pReq=&iStatus;
       
    62 		User::RequestComplete(pReq, KErrNone);
       
    63 		}
       
    64 	}
       
    65 
       
    66 void CChunkProcessor::Pause()
       
    67 	{
       
    68 	iIsPaused = ETrue;
       
    69 	if (iSubProcessor)
       
    70 		{
       
    71 		iSubProcessor->Pause();
       
    72 		}
       
    73 	}
       
    74 
       
    75 void CChunkProcessor::Resume()
       
    76 	{
       
    77 	iIsPaused=EFalse;
       
    78 	if (iSubProcessor)
       
    79 		{
       
    80 		iSubProcessor->Resume();
       
    81 		}
       
    82 		
       
    83 	if (iNeedRunAfterResume)
       
    84 		{
       
    85 		RunAgain();
       
    86 		}
       
    87 	}
       
    88 
       
    89 void CChunkProcessor::Stop()
       
    90 	{
       
    91 	if (iInputStream != NULL)
       
    92 		{
       
    93 		iInputStream->Release();
       
    94 		}
       
    95 	iInputStream = NULL;
       
    96 	if (iSubProcessor != NULL)
       
    97 		{
       
    98 		iSubProcessor->Stop();
       
    99 		}
       
   100 	Cancel();
       
   101 	iNeedRunAfterResume = EFalse;
       
   102 	}
       
   103 
       
   104 void CChunkProcessor::NotifyCaller(TInt aErrCode)
       
   105 	{
       
   106 	User::RequestComplete(iCallerRequest, aErrCode);
       
   107 	if (iInputStream != NULL)
       
   108 		{
       
   109 		iInputStream->Release();
       
   110 		}
       
   111 	iInputStream = NULL;
       
   112 	}
       
   113 
       
   114 void CChunkProcessor::RunL()
       
   115 	{
       
   116 	if (iStatus != KErrNone)
       
   117 		{
       
   118 		User::Leave(iStatus.Int());
       
   119 		}
       
   120 	if (iIsPaused)
       
   121 		{
       
   122 		ASSERT(EFalse==iNeedRunAfterResume);
       
   123 		iNeedRunAfterResume = ETrue;
       
   124 		}
       
   125 	else
       
   126 		{
       
   127 		DoRunL();
       
   128 		}
       
   129 	}