|
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 // Aggregate.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "agregate.h" |
|
19 |
|
20 |
|
21 //---------------------------------------------------------------------------------------------------------------- |
|
22 // CAggregateItem |
|
23 //---------------------------------------------------------------------------------------------------------------- |
|
24 |
|
25 /** Constructs a new CAggregateItem object. This is private becuase |
|
26 it should only be called from a CAggregateCollection class |
|
27 @param coll a pointer to the collection class |
|
28 @return the newly created item |
|
29 */ |
|
30 CAggregateItem* CAggregateItem::NewL(CAggregateCollection* aColl) |
|
31 { |
|
32 CAggregateItem* ret = new (ELeave) CAggregateItem(aColl); |
|
33 return ret; |
|
34 } |
|
35 |
|
36 /** Constructor for new CAggregateItem. |
|
37 @param coll a pointer to the collection class |
|
38 */ |
|
39 CAggregateItem::CAggregateItem(CAggregateCollection *aColl) : |
|
40 CActive(EPriorityNormal), |
|
41 iCollection(aColl), |
|
42 iIsAdded(EFalse) |
|
43 { |
|
44 } |
|
45 /** Destructor for new CAggregateItem. |
|
46 The destructor is private because only a CAggregateCollection should have the right to delete it |
|
47 */ |
|
48 CAggregateItem::~CAggregateItem() |
|
49 { |
|
50 if (iIsAdded) |
|
51 { |
|
52 Deque(); |
|
53 } |
|
54 } |
|
55 |
|
56 /** Returns what was returned on the completion of the objects iStatus |
|
57 @return the TRequestStatus return value |
|
58 */ |
|
59 TInt CAggregateItem::ReturnCode() |
|
60 { |
|
61 return iStatus.Int(); |
|
62 } |
|
63 |
|
64 /** Places the object on the active scheduler and does all the necessary stuff to allow completion to happen |
|
65 */ |
|
66 void CAggregateItem::Start() |
|
67 { |
|
68 CActiveScheduler::Add(this); |
|
69 iIsAdded = ETrue; |
|
70 SetActive(); |
|
71 } |
|
72 |
|
73 void CAggregateItem::RunL() |
|
74 { |
|
75 Deque(); |
|
76 iIsAdded = EFalse; |
|
77 iCollection->UpdateCompletion(); |
|
78 } |
|
79 |
|
80 void CAggregateItem::DoCancel() |
|
81 { |
|
82 |
|
83 } |
|
84 |
|
85 //---------------------------------------------------------------------------------------------------------------- |
|
86 // CAggregateCollection |
|
87 //---------------------------------------------------------------------------------------------------------------- |
|
88 |
|
89 /** Constructor for a CAggregateCollection class |
|
90 @param status The TRequestStatus that will be completed when either one or all items complete |
|
91 @param type whether the completion of the above status should happen on completion of the first item or |
|
92 whether we need to wait for completion of all items |
|
93 */ |
|
94 CAggregateCollection* CAggregateCollection::NewL(TRequestStatus &aStatus,TType aType) |
|
95 { |
|
96 CAggregateCollection* ret = new (ELeave) CAggregateCollection(aStatus,aType); |
|
97 return ret; |
|
98 } |
|
99 /** Constructor for a CAggregateCollection class |
|
100 @param status The TRequestStatus that will be completed when either one or all items complete |
|
101 @param type whether the completion of the above status should happen on completion of the first item or |
|
102 whether we need to wait for completion of all items |
|
103 */ |
|
104 CAggregateCollection::CAggregateCollection(TRequestStatus &aStatus,TType aType) : |
|
105 iStatusToComplete(aStatus), |
|
106 iType(aType) |
|
107 { |
|
108 } |
|
109 |
|
110 CAggregateCollection::~CAggregateCollection() |
|
111 { |
|
112 while (iNumItems > 0) |
|
113 { |
|
114 delete iItems[--iNumItems]; |
|
115 } |
|
116 } |
|
117 |
|
118 /** Creates a new CAggregateItem and passes the item back to the caller |
|
119 The CAggregateItem has the same lifetime as the CAggregateCollection and cannot be deleted independently |
|
120 @return the new CAggregateItem |
|
121 */ |
|
122 CAggregateItem* CAggregateCollection::GetNewItemL() |
|
123 { |
|
124 CAggregateItem* ret = CAggregateItem::NewL(this); |
|
125 CleanupStack::PushL(ret); |
|
126 if (iNumItems == KMaxNumItems - 1) |
|
127 { |
|
128 User::Leave(KErrOverflow); |
|
129 } |
|
130 iItems[iNumItems++] = ret; |
|
131 CleanupStack::Pop(ret); |
|
132 return ret; |
|
133 } |
|
134 |
|
135 /** This is called everytime a CActiveItem is completed. It is responsible for incrementing the objects completed count |
|
136 as well as completing the TRequestStatus handed to it on construction. |
|
137 The above TRequestStatus is completed on the first completion of one of its item if type = EAny and |
|
138 only after completion of all the items if type = EAll |
|
139 */ |
|
140 void CAggregateCollection::UpdateCompletion() |
|
141 { |
|
142 iNumItemsCompleted++; |
|
143 if (iType == EAny || iNumItemsCompleted == iNumItems) |
|
144 { |
|
145 TRequestStatus* stat = &iStatusToComplete; |
|
146 User::RequestComplete(stat,KErrNone); |
|
147 } |
|
148 } |
|
149 |
|
150 void CAggregateCollection::Kick() |
|
151 { |
|
152 iStatusToComplete = KRequestPending; |
|
153 } |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |