|
1 // Copyright (c) 2002-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 // Name : DeleteMgr.cpp |
|
15 // Part of : SIPCommon |
|
16 // Version : SIP/3.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "DeleteMgr.h" |
|
22 |
|
23 // ----------------------------------------------------------------------------- |
|
24 // CDeleteMgr::NewL |
|
25 // Start listening for requests |
|
26 // ----------------------------------------------------------------------------- |
|
27 // |
|
28 CDeleteMgr* CDeleteMgr::NewL() |
|
29 { |
|
30 CDeleteMgr* self = new (ELeave) CDeleteMgr; |
|
31 CActiveScheduler::Add(self); |
|
32 self->WaitForRequests(); |
|
33 return self; |
|
34 } |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CDeleteMgr::CDeleteMgr |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CDeleteMgr::CDeleteMgr() : CActive(EPriorityStandard) |
|
41 #ifdef CPPUNIT_TEST |
|
42 //For unit tests the granularity of arrays is set to 1 to cause them to |
|
43 //allocate memory every time an item is appended to array |
|
44 , iDeleteRequests(1) |
|
45 #endif |
|
46 { |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CDeleteMgr::~CDeleteMgr |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CDeleteMgr::~CDeleteMgr() |
|
54 { |
|
55 iDeleteRequests.ResetAndDestroy(); |
|
56 |
|
57 //Make sure CDeleteMgr isn't active anymore |
|
58 Cancel(); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CDeleteMgr::WaitForRequests |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CDeleteMgr::WaitForRequests() |
|
66 { |
|
67 __ASSERT_DEBUG(!IsActive(), |
|
68 User::Panic(_L("CDeleteMgr::WaitForRequests() already active"), |
|
69 EDeleteMgrFncPrecondNotMet)); |
|
70 |
|
71 if (!IsActive()) |
|
72 { |
|
73 iStatus = KRequestPending; |
|
74 SetActive(); |
|
75 } |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CDeleteMgr::AddDeleteRequest |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 TInt CDeleteMgr::AddDeleteRequest(const CBase* aItemToDelete) |
|
83 { |
|
84 if (!aItemToDelete) |
|
85 { |
|
86 return KErrArgument; |
|
87 } |
|
88 |
|
89 //It is not allowed to delete CDeleteMgr itself |
|
90 if (aItemToDelete == this) |
|
91 { |
|
92 return KErrArgument; |
|
93 } |
|
94 |
|
95 //Duplicate entries are not allowed |
|
96 if (iDeleteRequests.Find(aItemToDelete) != KErrNotFound) |
|
97 { |
|
98 return KErrAlreadyExists; |
|
99 } |
|
100 |
|
101 //CActive::iActive won't tell whether User::RequestComplete() has already |
|
102 //been called, so iStatus is inspected to see whether a previous call to |
|
103 //AddDeleteRequestL() has already called User::RequestComplete(). |
|
104 if (iStatus == KRequestPending) |
|
105 { |
|
106 //Wake up to process the request |
|
107 TRequestStatus* status = &iStatus; |
|
108 User::RequestComplete(status, KErrNone); |
|
109 } |
|
110 |
|
111 return iDeleteRequests.Append(aItemToDelete); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CDeleteMgr::DoCancel |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CDeleteMgr::DoCancel() |
|
119 { |
|
120 //Complete the request |
|
121 TRequestStatus* status = &iStatus; |
|
122 User::RequestComplete(status, KErrCancel); |
|
123 } |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CDeleteMgr::RunL |
|
127 // Handle all requests and then start waiting for the next request |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 void CDeleteMgr::RunL() |
|
131 { |
|
132 iDeleteRequests.ResetAndDestroy(); |
|
133 WaitForRequests(); |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CDeleteMgr::RunError |
|
138 // Since RunL() won't leave this shouldn't be called. |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 TInt CDeleteMgr::RunError(TInt aError) |
|
142 { |
|
143 if (aError == KErrNoMemory) |
|
144 { |
|
145 return aError; |
|
146 } |
|
147 |
|
148 return KErrNone; |
|
149 } |