messagingfw/sendas/server/src/csendasactivecontainer.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     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 #include "csendasactivecontainer.h"
       
    17 
       
    18 #include "csendassender.h"
       
    19 #include "csendaseditwatcher.h"
       
    20 #include "csendasserver.h"
       
    21 
       
    22 CSendAsActiveContainer* CSendAsActiveContainer::NewL(CSendAsServer& aServer)
       
    23 	{
       
    24 	CSendAsActiveContainer* self = new(ELeave) CSendAsActiveContainer(aServer);
       
    25 	return self;
       
    26 	}
       
    27 	
       
    28 CSendAsActiveContainer::~CSendAsActiveContainer()
       
    29 	{
       
    30 	// clean up
       
    31 	Cancel();
       
    32 	iActiveList.ResetAndDestroy();
       
    33 	iActiveList.Close();
       
    34 	}
       
    35 
       
    36 CSendAsActiveContainer::CSendAsActiveContainer(CSendAsServer& aServer)
       
    37 : CActive(EPriorityStandard), iServer(aServer)
       
    38 	{
       
    39 	CActiveScheduler::Add(this);
       
    40 	}
       
    41 
       
    42 void CSendAsActiveContainer::AddSenderL(CSendAsSender& aSender)
       
    43 	{
       
    44 	// need to take ownership of the sender - place on cleanup stack.
       
    45 	CleanupStack::PushL(&aSender);
       
    46 	iActiveList.AppendL(&aSender);
       
    47 	CleanupStack::Pop(&aSender);
       
    48 	}
       
    49 	
       
    50 void CSendAsActiveContainer::AddEditWatcherL(CSendAsEditWatcher& aEditWatcher)
       
    51 	{
       
    52 	// need to take ownership of the edit watcher - place on cleanup stack.
       
    53 	CleanupStack::PushL(&aEditWatcher);
       
    54 	iActiveList.AppendL(&aEditWatcher);
       
    55 	CleanupStack::Pop(&aEditWatcher);
       
    56 	}
       
    57 	
       
    58 TBool CSendAsActiveContainer::IsEmpty() const
       
    59 	{
       
    60 	return (iActiveList.Count() == 0);
       
    61 	}
       
    62 	
       
    63 void CSendAsActiveContainer::PurgeInactive()
       
    64 	{
       
    65 	// self-complete if not already active - the RunL will then delete any 
       
    66 	// completed active objects in the list.
       
    67 	if( !IsActive() )
       
    68 		{
       
    69 		TRequestStatus* status=&iStatus;
       
    70 		User::RequestComplete(status, KErrNone);
       
    71 		SetActive();
       
    72 		}
       
    73 	}
       
    74 	
       
    75 /*
       
    76  *	Methods from CActive
       
    77  */
       
    78 
       
    79 void CSendAsActiveContainer::RunL()
       
    80 	{
       
    81 	// remove all completed operations from lists
       
    82 	TInt count = iActiveList.Count();
       
    83 	while( count-- > 0 )
       
    84 		{
       
    85 		if( !iActiveList[count]->IsActive() )
       
    86 			{
       
    87 			delete iActiveList[count];
       
    88 			iActiveList.Remove(count);
       
    89 			}
       
    90 		}
       
    91 	// notify the server if there are no more actions waiting to complete.
       
    92 	if( iActiveList.Count() == 0 )
       
    93 		{
       
    94 		iServer.ContainerEmpty();
       
    95 		}
       
    96 	}
       
    97 	
       
    98 void CSendAsActiveContainer::DoCancel()
       
    99 	{
       
   100 	// nothing to do really...
       
   101 	}
       
   102 
       
   103 /*
       
   104  *	Methods from MSendAsSenderObserver
       
   105  */
       
   106 
       
   107 void CSendAsActiveContainer::SenderComplete(TInt /*aError*/)
       
   108 	{
       
   109 	// self-complete if not already active - the RunL will then delete all 
       
   110 	// completed active objects in the list.
       
   111 	if( !IsActive() )
       
   112 		{
       
   113 		TRequestStatus* status=&iStatus;
       
   114 		User::RequestComplete(status, KErrNone);
       
   115 		SetActive();
       
   116 		}
       
   117 	}
       
   118 	
       
   119 /*
       
   120  *	Methods from MSendAsEditObserver
       
   121  */
       
   122 
       
   123 void CSendAsActiveContainer::EditComplete(TInt /*aError*/)
       
   124 	{
       
   125 	// self-complete if not already active - the RunL will then delete all 
       
   126 	// completed active objects in the list.
       
   127 	if( !IsActive() )
       
   128 		{
       
   129 		TRequestStatus* status=&iStatus;
       
   130 		User::RequestComplete(status, KErrNone);
       
   131 		SetActive();
       
   132 		}
       
   133 	}